Settings';
array_unshift( $links, $settings_link );
return $links;
}
$plugin = plugin_basename(__FILE__);
add_filter( "plugin_action_links_$plugin", 'aiomh_plugin_settings_link' );
//Include
include('inc/translate.php');
//add style admin
if(isset($_GET['page']) && strpos('1'.$_GET['page'],'all-in-one-must-have')) add_action( 'admin_enqueue_scripts', 'aiomh_load_admin_style' );
function aiomh_load_admin_style() {
wp_register_style( 'all-in-one-must-have_admin',plugins_url( 'css/admin.css',__FILE__ ), false,AIOMH_VERSION );
wp_enqueue_style( 'all-in-one-must-have_admin' );
wp_enqueue_script('custom_admin_script', plugins_url( 'js/admin.js',__FILE__ ), array('jquery') ,AIOMH_VERSION);
}
// Function
function aiomh_check_exits_txt_file($str,$file=AIOMH_FWPCF){
$content = file_get_contents($file);
return strpos('1'.$content,$str)?true:false;
}
function aiomh_FileCheckPermissions($file=AIOMH_FWPCF)
{
if (!is_writable($file)) {
return false;
}
if (!function_exists('file') || !function_exists('file_get_contents') || !function_exists('file_put_contents'))
{
return false;
}
return true;
}
function aiomh_check_exits_textarea($textarea,$string){
$textarea = explode("\n", $textarea);
$return = 0;
foreach ($textarea as $value)
{
if(strpos('1'.$string,trim($value))) $return = 1;
}
return ($return==0)?false:true;
}
function aiomh_return_array_texrarea($text){
if(strpos('1'.$text,',')) $array = str_replace(',', "\n", $text);
$array = explode("\n", $text."\n");
array_pop($array);
foreach ($array as $key => $val) {
$array[$key] = trim($val);
}
return $array;
}
//Check if wp-admin
$admins = array(
home_url( 'wp-admin', 'relative' ),
home_url( 'dashboard', 'relative' ),
home_url( 'admin', 'relative' ),
site_url( 'dashboard', 'relative' ),
site_url( 'admin', 'relative' ),
home_url( 'wp-login.php', 'relative' ),
home_url( 'login', 'relative' ),
site_url( 'login', 'relative' ),
);
if ( is_admin() || $GLOBALS['pagenow'] === 'wp-login.php' || in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $admins ) )
define( 'AIOMH_IFADMIN', 1 );
else
define( 'AIOMH_IFADMIN', 0 );
function aiomh_register_settings() {
register_setting( 'aiomh-setting', 'aiomh_translate' );
if(get_option('aiomh_translate')=='') {if(get_locale()!='vi') update_option( 'aiomh_translate', 'en' ); else update_option( 'aiomh_translate', 'vi' );}
register_setting( 'aiomh-setting', 'aiomh_ascii_file_name' );
if(get_option('aiomh_ascii_file_name')=='') update_option( 'aiomh_ascii_file_name', 1 );
register_setting( 'aiomh-setting', 'aiomh_jpeg_quality' );
if(get_option('aiomh_jpeg_quality')=='') update_option( 'aiomh_jpeg_quality', 1 );
register_setting( 'aiomh-setting', 'aiomh_jpeg_quality_value' );
if(get_option('aiomh_jpeg_quality_value')=='') update_option( 'aiomh_jpeg_quality_value', 75 );
register_setting( 'aiomh-setting', 'aiomh_auto_upload_and_set_thumb' );
if(get_option('aiomh_auto_upload_and_set_thumb')=='') update_option( 'aiomh_auto_upload_and_set_thumb', 1 );
register_setting( 'aiomh-setting', 'aiomh_post_views' );
if(get_option('aiomh_post_views')=='') update_option( 'aiomh_post_views', 1 );
register_setting( 'aiomh-setting', 'aiomh_check_duplicate_title' );
if(get_option('aiomh_check_duplicate_title')=='') update_option( 'aiomh_check_duplicate_title', 1 );
register_setting( 'aiomh-setting', 'aiomh_remove_emoji' );
if(get_option('aiomh_remove_emoji')=='') update_option( 'aiomh_remove_emoji', 1 );
register_setting( 'aiomh-setting', 'aiomh_remove_menu_class' );
if(get_option('aiomh_remove_menu_class')=='') update_option( 'aiomh_remove_menu_class', 1 );
register_setting( 'aiomh-setting', 'aiomh_remove_menu_class_value' );
if(get_option('aiomh_remove_menu_class_value')=='') update_option( 'aiomh_remove_menu_class_value', "menu-item\ncurrent-menu-item\nmenu-item-has-children\ncurrent-menu-parent" );
register_setting( 'aiomh-setting', 'aiomh_disable_comments' );
register_setting( 'aiomh-setting', 'aiomh_remove_jquery' );
register_setting( 'aiomh-setting', 'aiomh_remove_plugin_jscss' );
register_setting( 'aiomh-setting', 'aiomh_remove_plugin_jscss_all' );
register_setting( 'aiomh-setting', 'aiomh_remove_plugin_jscss_home' );
register_setting( 'aiomh-setting', 'aiomh_remove_plugin_jscss_single' );
register_setting( 'aiomh-setting', 'aiomh_remove_plugin_jscss_category' );
register_setting( 'aiomh-setting', 'aiomh_move_js_to_footer' );
register_setting( 'aiomh-setting', 'aiomh_move_css_to_footer' );
register_setting( 'aiomh-setting', 'aiomh_add_js_defer' );
register_setting( 'aiomh-setting', 'aiomh_add_js_defer_value' );
register_setting( 'aiomh-setting', 'aiomh_add_js_async' );
register_setting( 'aiomh-setting', 'aiomh_add_js_async_value' );
register_setting( 'aiomh-setting', 'aiomh_html_minify' );
register_setting( 'aiomh-setting', 'aiomh_html_minify_home_url' );
register_setting( 'aiomh-setting', 'aiomh_html_minify_slash_end' );
//Defence
register_setting( 'aiomh-setting', 'aiomh_change_dir_admin' );
register_setting( 'aiomh-setting', 'aiomh_change_dir_admin_value' );
if(get_option('aiomh_change_dir_admin_value')=='') update_option( 'aiomh_change_dir_admin_value', 'aiomh-login' );
register_setting( 'aiomh-setting', 'aiomh_lock_wpadmin' );
register_setting( 'aiomh-setting', 'aiomh_lock_wpadmin_user' );
register_setting( 'aiomh-setting', 'aiomh_lock_wpadmin_pass' );
register_setting( 'aiomh-setting', 'aiomh_disable_xmlrpc' );
register_setting( 'aiomh-setting', 'aiomh_hidden_verwp' );
register_setting( 'aiomh-setting', 'aiomh_change_key_salt' );
register_setting( 'aiomh-setting', 'aiomh_change_key_salt_n' );
register_setting( 'aiomh-setting', 'aiomh_change_key_salt_value' );
register_setting( 'aiomh-setting', 'aiomh_change_key_salt_value_time' );
if(get_option('aiomh_change_key_salt_value_time')=='') update_option( 'aiomh_change_key_salt_value_time', 1 );
register_setting( 'aiomh-setting', 'aiomh_disallow_file_edit' );
if(aiomh_check_exits_txt_file('DISALLOW_FILE_EDIT')==true) update_option( 'aiomh_disallow_file_edit', 1 );
else update_option( 'aiomh_disallow_file_edit', 0 );
register_setting( 'aiomh-setting', 'aiomh_disallow_file_mods' );
if(aiomh_check_exits_txt_file('DISALLOW_FILE_MODS')==true) update_option( 'aiomh_disallow_file_mods', 1 );
else update_option( 'aiomh_disallow_file_mods', 0 );
//wp cache
register_setting( 'aiomh-setting', 'aiomh_cache' );
register_setting( 'aiomh-setting', 'aiomh_cache_time' );
register_setting( 'aiomh-setting', 'aiomh_cache_not' );
if(get_option('aiomh_cache_not')=='') update_option( 'aiomh_cache_not', "wp-login.php\n/my-account/\n/cart/\n/checkout/\n/tai-khoan/\n/gio-hang/\n/thanh-toan/" );
register_setting( 'aiomh-setting', 'aiomh_cache_accepted' );
register_setting( 'aiomh-setting', 'aiomh_cache_bot' );
if(get_option('aiomh_cache_bot')=='') update_option( 'aiomh_cache_bot', "bot\nia_archive\nslurp\ncrawl\nspider\nYandex" );
register_setting( 'aiomh-setting', 'aiomh_cache_not_home' );
register_setting( 'aiomh-setting', 'aiomh_cache_not_single' );
register_setting( 'aiomh-setting', 'aiomh_cache_not_page' );
register_setting( 'aiomh-setting', 'aiomh_cache_not_archive' );
register_setting( 'aiomh-setting', 'aiomh_cache_not_tag' );
register_setting( 'aiomh-setting', 'aiomh_cache_not_category' );
register_setting( 'aiomh-setting', 'aiomh_cache_not_feed' );
register_setting( 'aiomh-setting', 'aiomh_cache_not_search' );
register_setting( 'aiomh-setting', 'aiomh_cache_not_author' );
register_setting( 'aiomh-setting', 'aiomh_cache_mobile' );
register_setting( 'aiomh-setting', 'aiomh_cache_views' );
if(get_option('aiomh_cache_views')=='') update_option( 'aiomh_cache_views', 1 );
register_setting( 'aiomh-setting', 'aiomh_cache_login_not' );
}
function aiomh_create_menu(){
add_menu_page('All In One Must Have Settings', 'AIOMH Settings', 'administrator', __FILE__, 'aiomh_settings_page',plugins_url('/images/favicon.gif', __FILE__), 1);
add_submenu_page(__FILE__, aiomh_translate('Rút gọn html'), aiomh_translate('Rút gọn html'), 'administrator', __FILE__.'#cleanhtml', 'aiomh_settings_cleanhtml');
add_submenu_page(__FILE__, aiomh_translate('Bảo mật website'), aiomh_translate('Bảo mật website'), 'administrator', __FILE__.'#security', 'aiomh_settings_security');
add_submenu_page(__FILE__, aiomh_translate('Cài đặt cache'), aiomh_translate('Cài đặt cache'), 'administrator', __FILE__.'#cache', 'aiomh_settings_cache');
if(get_option('aiomh_cache')==1) add_submenu_page(__FILE__, aiomh_translate('Xóa toàn bộ cache'), aiomh_translate('Xóa toàn bộ cache'), 'administrator', __FILE__.'&removecached=1', 'aiomh_settings_cache_remove');
add_action( 'admin_init', 'aiomh_register_settings' );
}
add_action('admin_menu', 'aiomh_create_menu');
$aiomh_ascii_file_name = get_option('aiomh_ascii_file_name');
function create_aiomh_menu() {
global $wp_admin_bar;
$menu_id = 'aiomh';
$wp_admin_bar->add_menu(array('id' => $menu_id, 'title' => '
'.aiomh_translate('AIOMH Settings'), 'href' => 'admin.php?page=all-in-one-must-have%2Findex.php'));
$wp_admin_bar->add_menu(array('parent' => $menu_id, 'title' => aiomh_translate('Rút gọn html'), 'id' => 'aiomh-clean', 'href' => 'admin.php?page=all-in-one-must-have%2Findex.php#cleanhtml'));
$wp_admin_bar->add_menu(array('parent' => $menu_id, 'title' => aiomh_translate('Bảo mật website'), 'id' => 'aiomh-security', 'href' => 'admin.php?page=all-in-one-must-have%2Findex.php#security'));
$wp_admin_bar->add_menu(array('parent' => $menu_id, 'title' => aiomh_translate('Cài đặt cache'), 'id' => 'aiomh-cache', 'href' => 'admin.php?page=all-in-one-must-have%2Findex.php#cache'));
if(get_option('aiomh_cache')==1) $wp_admin_bar->add_menu(array('parent' => $menu_id, 'title' => aiomh_translate('Xóa toàn bộ cache'), 'id' => 'aiomh-cache-remove', 'href' => 'admin.php?page=all-in-one-must-have%2Findex.php&removecached=1'));
}
add_action('admin_bar_menu', 'create_aiomh_menu', 2000);
function aiomh_settings_page() {
?>
'-',
'%20' => '-',
'_' => '-',
);
$sanitized_filename = str_replace( array_keys( $invalid ), array_values( $invalid ), $sanitized_filename );
$sanitized_filename = preg_replace('/[^A-Za-z0-9-\. ]/', '', $sanitized_filename); // Remove all non-alphanumeric except .
$sanitized_filename = preg_replace('/\.(?=.*\.)/', '', $sanitized_filename); // Remove all but last .
$sanitized_filename = preg_replace('/-+/', '-', $sanitized_filename); // Replace any more than one - in a row
$sanitized_filename = str_replace('-.', '.', $sanitized_filename); // Remove last - if at the end
$sanitized_filename = strtolower( $sanitized_filename ); // Lowercase
return $sanitized_filename;
}
if(get_option('aiomh_ascii_file_name')==1) add_filter( 'sanitize_file_name', 'aiomh_sanitize_file_name', 10, 1 );
// Nén ảnh
if(get_option('aiomh_jpeg_quality')==1) add_filter('jpeg_quality', function($arg){
$aiomh_jpeg_quality_value = get_option('aiomh_jpeg_quality_value')==''?75:get_option('aiomh_jpeg_quality_value');
return $aiomh_jpeg_quality_value;
});
// Tự thêm thumbnail
if(get_option('aiomh_auto_upload_and_set_thumb')==1)
{
function aiomh_sb_get_first_image_url_from_text($content) {
$doc = new DOMDocument();
@$doc->loadHTML($content);
$xpath = new DOMXPath($doc);
$src = $xpath->evaluate('string(//img/@src)');
return $src;
}
function aiomh_sb_get_image_attachments($post_id) {
return get_children(array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image'));
}
function aiomh_sb_get_first_image_attachment($post_id) {
$attach_images = aiomh_sb_get_image_attachments($post_id);
$result = null;
if(count($attach_images) > 0) {
$result = array_shift($attach_images);
}
return $result;
}
function aiomh_sb_create_folder($file_path) {
if(!file_exists($file_path)) {
mkdir($file_path);
}
}
function aiomh_sb_copy($source, $destination) {
if(@fclose(@fopen($source, 'r'))) {
copy($source, $destination);
return true;
}
return false;
}
function aiomh_sb_set_post_thumbnail($post_id) {
if(current_theme_supports('post-thumbnails') && !has_post_thumbnail($post_id)) {
$first_image = aiomh_sb_get_first_image_attachment($post_id);
if($first_image) {
set_post_thumbnail($post_id, $first_image->ID);
return true;
} else {
$post = get_post($post_id);
if($post) {
$first_image = aiomh_sb_get_first_image_url_from_text($post->post_content);
$attach_id = aiomh_sb_fetch_media($first_image);
if($attach_id > 0) {
set_post_thumbnail($post_id, $attach_id);
return true;
}
}
}
}
return false;
}
function aiomh_sb_auto_set_thumbnail($post_id) {
if (wp_is_post_revision($post_id)) {
return;
}
aiomh_sb_set_post_thumbnail($post_id);
}
add_action('save_post', 'aiomh_sb_auto_set_thumbnail');
function aiomh_sb_fetch_media($image_url) {
$attach_id = 0;
$wp_upload_dir = wp_upload_dir();
$base_dir = trailingslashit($wp_upload_dir['basedir']) . 'aiomh-img';
$base_url = trailingslashit($wp_upload_dir['url']) . 'aiomh-img';
aiomh_sb_create_folder($base_dir);
$parts = pathinfo($image_url);
$random = rand();
$random = md5($random);
$file_name = 'aiomh-img-' . $parts['filename'] . '-' . $random . '.' . $parts['extension'];
$file_path = trailingslashit($base_dir) . $file_name;
$file_url = trailingslashit($base_url) . $file_name;
if(aiomh_sb_copy($image_url, $file_path)) {
$attachment = array(
'guid' => $file_url
);
$attach_id = aiomh_sb_insert_attachment($attachment, $file_path);
}
return $attach_id;
}
function aiomh_sb_insert_attachment($attachment, $file_path) {
if(!file_exists($file_path)) {
return 0;
}
$file_type = wp_check_filetype(basename($file_path), null);
$attachment['post_mime_type'] = $file_type['type'];
if(!isset($attachment['guid'])) {
return 0;
}
$attachment['post_status'] = isset($attachment['post_status']) ? $attachment['post_status'] : 'inherit';
if(!isset($attachment['post_title'])) {
$attachment['post_title'] = preg_replace('/\.[^.]+$/', '', basename($file_path));
}
$attach_id = wp_insert_attachment($attachment, $file_path);
if($attach_id > 0) {
aiomh_sb_update_attachment_meta($attach_id, $file_path);
}
return $attach_id;
}
function aiomh_sb_update_attachment_meta($attach_id, $file_path) {
if(!function_exists('wp_generate_attachment_metadata')) {
require_once(ABSPATH . 'wp-admin/includes/image.php');
}
$attach_data = wp_generate_attachment_metadata($attach_id, $file_path);
wp_update_attachment_metadata($attach_id, $attach_data);
}
}
// Đếm lượt xem
if(get_option('aiomh_post_views')==1)
{
add_action('wp_loaded', 'aiomh_auto_set_post_view2');
function aiomh_auto_set_post_view2() {
if (!function_exists('getPostViews'))
{
function getPostViews($postID){ // hàm này dùng để lấy số người đã xem qua bài viết
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){ // Nếu như lượt xem không có
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0"; // giá trị trả về bằng 0
}
return $count; // Trả về giá trị lượt xem
}
}
if(!function_exists('setPostViews'))
{
function setPostViews($postID) {// hàm này dùng để set và update số lượt người xem bài viết.
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
}else{
$count++; // cộng đồn view
update_post_meta($postID, $count_key, $count); // update count
}
}
}
add_action('wp_enqueue_scripts', 'aiomh_auto_set_post_view');
function aiomh_auto_set_post_view() {
if(is_single())
{
global $post;
setPostViews($post->ID);
}
}
}
}
// Kiểm tra tiêu đề trùng
if(get_option('aiomh_check_duplicate_title')==1)
{
function aiomh_add_my_admin_script(){
wp_enqueue_script('admin_script', plugins_url( 'all-in-one-must-have/js/check_duplicate_title.js' ), array('jquery'),AIOMH_VERSION);
wp_localize_script( 'admin_script', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'we_value' => 1234 ) );
}
add_action('admin_enqueue_scripts', 'aiomh_add_my_admin_script');
add_action( 'wp_ajax_my_action', 'aiomh_my_action_callback' );
function aiomh_my_action_callback() {
global $wpdb;
$title_exists = $wpdb->get_results(
"
SELECT ID
FROM $wpdb->posts
WHERE
post_title LIKE '" . $_POST['this_convidado_title'] . "'
AND
post_type = '" . $_POST['post_type'] . "'
"
);
if($_POST['post_ID'] != ""){
foreach ($title_exists as $key => $this_id) {
if($_POST['post_ID'] == $this_id->ID){
$this_is_the_post = $this_id->ID;
}
}
}
if($this_is_the_post){
echo (count($title_exists)-1);
} else {
echo count($title_exists);
}
die();
}
}
// REMOVE WP EMOJI
if(get_option('aiomh_remove_emoji')==1)
{
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
}
// Remove nav id + class menu
if(get_option('aiomh_remove_menu_class')==1)
{
add_filter('nav_menu_css_class', 'aiomh_css_attributes_filter', 100, 1);
add_filter('nav_menu_item_id', 'aiomh_css_attributes_filter', 100, 1);
add_filter('page_css_class', 'aiomh_css_attributes_filter', 100, 1);
function aiomh_css_attributes_filter($var) {
$keep_menu_class = aiomh_return_array_texrarea(get_option('aiomh_remove_menu_class_value'));
return is_array($var) ? array_intersect($var, $keep_menu_class) : '';
}
}
// Disable comments
if(get_option('aiomh_disable_comments')==1)
{
// Disable support for comments and trackbacks in post types
function aiomh_disable_comments_post_types_support() {
$post_types = get_post_types();
foreach ($post_types as $post_type) {
if(post_type_supports($post_type, 'comments')) {
remove_post_type_support($post_type, 'comments');
remove_post_type_support($post_type, 'trackbacks');
}
}
}
add_action('admin_init', 'aiomh_disable_comments_post_types_support');
// Close comments on the front-end
function aiomh_disable_comments_status() {
return false;
}
add_filter('comments_open', 'aiomh_disable_comments_status', 20, 2);
add_filter('pings_open', 'aiomh_disable_comments_status', 20, 2);
// Hide existing comments
function aiomh_disable_comments_hide_existing_comments($comments) {
$comments = array();
return $comments;
}
add_filter('comments_array', 'aiomh_disable_comments_hide_existing_comments', 10, 2);
// Remove comments page in menu
function aiomh_disable_comments_admin_menu() {
remove_menu_page('edit-comments.php');
}
add_action('admin_menu', 'aiomh_disable_comments_admin_menu');
// Redirect any user trying to access comments page
function aiomh_disable_comments_admin_menu_redirect() {
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url()); exit;
}
}
add_action('admin_init', 'aiomh_disable_comments_admin_menu_redirect');
// Remove comments metabox from dashboard
function aiomh_disable_comments_dashboard() {
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
}
add_action('admin_init', 'aiomh_disable_comments_dashboard');
// Remove comments links from admin bar
function aiomh_disable_comments_admin_bar() {
if (is_admin_bar_showing()) {
remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
}
}
add_action('init', 'aiomh_disable_comments_admin_bar');
}
//Change dir wp-admin
if(get_option('aiomh_change_dir_admin')==1)
{
function aiomh_add_rule_change_dir_admin() {
$dir_admin = get_option('aiomh_change_dir_admin_value');
add_rewrite_rule($dir_admin.'?', 'wp-login.php?ok='.$dir_admin, 'top');
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
add_action('init', 'aiomh_add_rule_change_dir_admin');
if ( AIOMH_IFADMIN == 1) {
$dir_admin = get_option('aiomh_change_dir_admin_value');
session_start();
$pass_level1 = $dir_admin;
if(isset($_GET["ok"])){$ok = $_GET["ok"];$_SESSION["ok"] = $ok;}
$ok = isset($_SESSION["ok"])?$_SESSION["ok"]:0;
if($ok!==$pass_level1){exit();}
}
}
if(get_option('aiomh_lock_wpadmin')==1)
{
if (AIOMH_IFADMIN == 1) {
$config['user_aiomh'] = get_option('aiomh_lock_wpadmin_user');
$config['pass_aiomh'] = get_option('aiomh_lock_wpadmin_pass');
if ($_SERVER['PHP_AUTH_USER'] !== $config['user_aiomh'] || $_SERVER['PHP_AUTH_PW'] !== $config['pass_aiomh']){
header('WWW-Authenticate: Basic realm="Login?"');
header('HTTP/1.0 401 Unauthorized');
echo 'Wrong !';
exit();
}
}
}
// Disable xmlrpc
if(get_option('aiomh_disable_xmlrpc')==1)
{
add_filter('xmlrpc_enabled', '__return_false');
}
// Hidden verwp
if(get_option('aiomh_hidden_verwp')==1)
{
remove_action('wp_head', 'wp_generator');
}
// Remove jquery
if(get_option('aiomh_remove_jquery')==1)
{
function aiomh_remove_jquery() {
wp_deregister_script('jquery');
wp_register_script('jquery', false);
wp_deregister_script( 'wp-embed' );
}
if (!is_admin()) {
add_action('init', 'aiomh_remove_jquery');
}
// add_filter( 'wp_default_scripts', 'aiomh_remove_jquery_migrate' );
// function aiomh_remove_jquery_migrate( &$scripts){
// if(!is_admin()){
// $scripts->remove( 'jquery');
// }
// }
}
// Remove js,css plugins
if(get_option('aiomh_remove_plugin_jscss')==1)
{
function aiomh_dequeue_my_css_fun($id) {
if($id!='')
{
// $id = str_replace(array(', ',', ',', '),',',$id);
// $remove_js_css = explode(',', $id.',');
// $count_remove_js_css = count($remove_js_css);
// for($i=0;$i<$count_remove_js_css-1;$i++)
// {
$array = aiomh_return_array_texrarea($id);
foreach($array as $value) {
wp_dequeue_style($value);
wp_deregister_style($value);
wp_dequeue_script($value);
wp_deregister_script($value);
add_action('wp_footer', 'wp_print_scripts', 5);
}
}
}
function aiomh_dequeue_my_css() {
aiomh_dequeue_my_css_fun(get_option('aiomh_remove_plugin_jscss_all'));
if(is_home() || is_front_page()) aiomh_dequeue_my_css_fun(get_option('aiomh_remove_plugin_jscss_home'));
if(is_category() || is_archive()) aiomh_dequeue_my_css_fun(get_option('aiomh_remove_plugin_jscss_category'));
if(is_single()) aiomh_dequeue_my_css_fun(get_option('aiomh_remove_plugin_jscss_single'));
}
add_action( 'wp_enqueue_scripts', 'aiomh_dequeue_my_css', 9999 );
}
// Change salt in wp-config
function aiomh_change_key_salt_func(){
if(aiomh_FileCheckPermissions()==true)
{
include_once(ABSPATH.'wp-includes/pluggable.php');
$wpconfig_content = file_get_contents(AIOMH_FWPCF);
if (!empty($wpconfig_content)){
$wpconfig_content = str_replace(AUTH_KEY,wp_generate_password( 64, true, true ),$wpconfig_content);
$wpconfig_content = str_replace(SECURE_AUTH_KEY,wp_generate_password( 64, true, true ),$wpconfig_content);
$wpconfig_content = str_replace(LOGGED_IN_KEY,wp_generate_password( 64, true, true ),$wpconfig_content);
$wpconfig_content = str_replace(NONCE_KEY,wp_generate_password( 64, true, true ),$wpconfig_content);
$wpconfig_content = str_replace(AUTH_SALT,wp_generate_password( 64, true, true ),$wpconfig_content);
$wpconfig_content = str_replace(SECURE_AUTH_SALT,wp_generate_password( 64, true, true ),$wpconfig_content);
$wpconfig_content = str_replace(LOGGED_IN_SALT,wp_generate_password( 64, true, true ),$wpconfig_content);
$wpconfig_content = str_replace(NONCE_SALT,wp_generate_password( 64, true, true ),$wpconfig_content);
$result = file_put_contents(AIOMH_FWPCF, $wpconfig_content);
}
update_option( 'aiomh_change_key_salt_value_time', time() );
}
}
if($GLOBALS['pagenow'] === 'wp-login.php' && get_option('aiomh_change_key_salt')==1){
$salt_value = get_option('aiomh_change_key_salt_value');
$salt_value_time = get_option('aiomh_change_key_salt_value_time');
if(time()-($salt_value*86400)>$salt_value_time) aiomh_change_key_salt_func();
}
// Move script to wp_footer()
if(get_option('aiomh_move_js_to_footer')==1)
{
function aiomh_footer_enqueue_scripts() {
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
remove_action('wp_head', 'wp_enqueue_scripts', 1);
add_action('wp_footer', 'wp_print_scripts', 5);
add_action('wp_footer', 'wp_enqueue_scripts', 5);
add_action('wp_footer', 'wp_print_head_scripts', 5);
}
if(get_option('aiomh_move_css_to_footer')==1)
add_action('after_setup_theme', 'aiomh_footer_enqueue_scripts');
else
add_action('wp_enqueue_scripts', 'aiomh_footer_enqueue_scripts');
}
// Add async script
if(get_option('aiomh_add_js_async')==1)
{
function aiomh_add_async_attribute($tag, $handle) {
$scripts_to_async = aiomh_return_array_texrarea(get_option('aiomh_add_js_async_value'));
foreach($scripts_to_async as $async_script) {
if ($async_script === $handle) {
$tag = str_replace('defer="defer" ', '', $tag);
$tag = str_replace(' src', ' async="async" src', $tag);
return $tag;
}
}
return $tag;
}
add_filter('script_loader_tag', 'aiomh_add_async_attribute', 10, 2);
}
// Add defer script
if(get_option('aiomh_add_js_defer')==1)
{
function aiomh_add_defer_attribute($tag, $handle) {
$scripts_to_defer = aiomh_return_array_texrarea(get_option('aiomh_add_js_defer_value'));
foreach($scripts_to_defer as $defer_script) {
if ($defer_script === $handle) {
$tag = str_replace('async="async" ', '', $tag);
$tag = str_replace(' src', ' defer="defer" src', $tag);
return $tag;
}
}
return $tag;
}
add_filter('script_loader_tag', 'aiomh_add_defer_attribute', 10, 2);
}
// Minify html
if(get_option('aiomh_html_minify')==1 && !is_admin() && AIOMH_IFADMIN != 1)
{
add_action( 'wp_loaded','my_minify_html', 10 );
function my_minify_html() {
ob_start('aiomh_html_compress');
}
}
function aiomh_html_compress( $html ) {
// $html = preg_replace(array("/[\n\r\t]/","","/<>/"),"",$html);
// $html = preg_replace("/ /"," ",$html);
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\/', // strip whitespaces before tags, except space
'/(\s)+/s', // shorten multiple whitespace sequences
'//'
);
$replace = array(
'>',
'<',
'/>',
'\\1',
''
);
$html = preg_replace($search, $replace, $html);
if(get_option('aiomh_html_minify_home_url')==1) $html = str_replace(home_url('/'),'/',$html);
if(get_option('aiomh_html_minify_slash_end')==1) $html = str_replace('/>','>',$html);
return $html;
}
//cache
add_action('wp_login', function(){
update_option('aiomh_logged', 1);
});
add_action('wp_logout', function(){
update_option('aiomh_logged', 0);
});
//detele file cache
function aiomh_cache_delete_file($post_id){
$post_url = get_permalink( $post_id );
$post_url = str_replace(home_url('/'),'',$post_url);
$post_url = (substr($post_url, -1)=='/')?$post_url.'index.c':$post_url.'.c';
$file_del = CFOLDER.$post_url;
if(file_exists($file_del)) unlink($file_del);
if(get_option('aiomh_cache_mobile')==1){
$file_del = CFOLDER.'/m/'.$post_url;
if(file_exists($file_del)) unlink($file_del);
}
}
function aiomh_cache_delete_folder($dir='') {
if($dir=='') $dir = CFOLDER;
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir")
aiomh_cache_delete_folder($dir."/".$object);
else unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}
// function aiomh_cache_delete_folder($dir=''){
// if($dir=='') $dir = ABSPATH.'wp-content/aiomh-cache/';
// echo '@@@@@@@@@@@@@@@@';
// $files = array_diff(scandir($dir), array('.','..'));
// foreach ($files as $file) {
// (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
// }
// return rmdir($dir);
// }
// rrmdir();
// Delete cache if update post
function aiomh_action_edit_post( $post_id, $post ) {
aiomh_cache_delete_file($post_id);
};
add_action( 'edit_post', 'aiomh_action_edit_post', 10, 2 );
if ( get_option('aiomh_cache')==1 )
{
add_filter('show_admin_bar', '__return_false');
add_action('after_setup_theme', 'aiomh_remove_admin_bar');
function aiomh_remove_admin_bar() {
show_admin_bar(false);
}
}
if ( get_option('aiomh_cache')==1 && AIOMH_IFADMIN==0) {
$aiomh_cache = 1;
if(get_option('aiomh_cache_login_not')==1 && get_option('aiomh_logged')==1) $aiomh_cache = 0;
if(get_option('aiomh_cache_not_home')==1 && (is_home() || is_front_page())) $aiomh_cache = 0;
if(get_option('aiomh_cache_not_single')==1 && is_single()) $aiomh_cache = 0;
if(get_option('aiomh_cache_not_page')==1 && is_page()) $aiomh_cache = 0;
if(get_option('aiomh_cache_not_archive')==1 && is_archive()) $aiomh_cache = 0;
if(get_option('aiomh_cache_not_tag')==1 && is_tag()) $aiomh_cache = 0;
if(get_option('aiomh_cache_not_category')==1 && is_category()) $aiomh_cache = 0;
if(get_option('aiomh_cache_not_feed')==1 && is_feed()) $aiomh_cache = 0;
if(get_option('aiomh_cache_not_search')==1 && is_search()) $aiomh_cache = 0;
if(get_option('aiomh_cache_not_author')==1 && is_author()) $aiomh_cache = 0;
if(aiomh_check_exits_textarea(get_option('aiomh_cache_not'),$_SERVER['REQUEST_URI'])==true) $aiomh_cache = 0;
if(get_option('aiomh_cache_accepted') != '')
{
if(aiomh_check_exits_textarea(get_option('aiomh_cache_accepted'),$_SERVER['REQUEST_URI'])==true) $aiomh_cache = 1;
}
if($aiomh_cache==1) add_action('init', 'aiomh_cache_head');
function aiomh_cache_head(){
// Tính toán name cho file cache
$script_name = $_SERVER["REQUEST_URI"];
$a = explode('/', $script_name);
if(substr($script_name, -1)=='/')
{
$tenfile = 'index';
$catfolder = $script_name;
}
else
{
$tenfile = end($a);
$catfolder = str_replace($tenfile,'',$script_name);
}
if(get_option('aiomh_cache_mobile')==1 && wp_is_mobile()) $catfolder = '/m/'.$catfolder;
$cachetime = (get_option('aiomh_cache_mobile')==0)?99999999999999:get_option('aiomh_cache_mobile');
define('CFOLDER',ABSPATH.'wp-content/aiomh-cache/');
define('CATFOLDER',CFOLDER.$catfolder);
define('CATFILE',CATFOLDER.$tenfile.'.c');
// Xuất file cache ra, với 2 điều kiện: có cache và chưa vượt quá cachetime
if (file_exists(CATFILE) && (time() - $cachetime > filemtime(CATFILE))){
if(get_option('aiomh_cache_views')==1)
{
$postid = url_to_postid( $_SERVER["REQUEST_URI"] );
if($postid > 0) setPostViews($postid);
}
include(CATFILE);
echo "\n";
exit;
}
ob_start(aiomh_cache_foot2); // Bật buffer cho output
}
// add_action( 'wp_loaded','aiomh_cache_foot',20 );
// function aiomh_cache_foot() {
// ob_start('aiomh_cache_foot2');
// }
function aiomh_cache_foot2( $html ) {
//if (!preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT']))
if(aiomh_check_exits_textarea(get_option('aiomh_cache_bot'),$_SERVER['HTTP_USER_AGENT'])!=true)
{
// Lưu nội dung sau khi file php chạy xong vào file cache
if (!file_exists(CATFOLDER)) {
mkdir(CATFOLDER, 0777, true);
}
$cache = fopen(CATFILE, 'w');
fwrite($cache, $html);
fclose($cache);
//ob_end_flush();
}
return $html;
}
}
//Submit
if(isset($_GET['settings-updated']) && $_GET['settings-updated']=='true')
{
// Hidden verwp
if(get_option('aiomh_hidden_verwp')==1)
{
//Remove file readme.html
$file_readme = ABSPATH.'readme.html';
if(file_exists($file_readme)) unlink($file_readme);
}
// Change salt in wp-config
if(get_option('aiomh_change_key_salt_now')==1)
{
aiomh_change_key_salt_func();
update_option( 'aiomh_change_key_salt_now', 0 );
}
// Disallow edit files on themes,plugins in wp-admin
if(get_option('aiomh_disallow_file_edit')==1 && aiomh_FileCheckPermissions()==true && aiomh_check_exits_txt_file('DISALLOW_FILE_EDIT')!=true)
{
$wpconfig_content = file_get_contents(AIOMH_FWPCF);
$wpconfig_content = preg_replace( '/(<\?(?:php)?)/', "