1.禁用 WordPress版本更新
在wp-config.php文件中添加以下代码行来禁用 WordPress 中的自动更新:
define( ‘WP_AUTO_UPDATE_CORE’, false );
2.禁用 WordPress 主题和插件更新
在主题的functions.php文件添加如下代码:
add_filter( ‘auto_update_plugin’, ‘__return_false’ );
add_filter( ‘auto_update_theme’, ‘__return_false’ );
3.禁用WordPress定时检测
不过你有没有访问后台,WordPress 都会定时检测 WordPress 核心,插件和主题是否有更新,这个功能是通过定时作业实现的,一共有三个定时作业:
wp_version_check:检测 WordPress 核心代码是不是最新版本。
wp_update_plugins:检测 WordPress 插件是不是最新版。
wp_update_themes:检测 WordPress 主题是不是最新版。
在主题的functions.php文件添加如下代码:
remove_action(‘init’, ‘wp_schedule_update_checks’);
wp_clear_scheduled_hook(‘wp_version_check’);
wp_clear_scheduled_hook(‘wp_update_plugins’);
wp_clear_scheduled_hook(‘wp_update_themes’);
4.禁用WordPress后台定时检测
如果访问 WordPress 后台,WordPress 会每隔 12 小时,就会检测 WordPress 核心,插件和主题是否有更新。
所以这个每隔 12 小时就检测更新的功能,导致后台变慢:
在主题的functions.php文件添加如下代码:
remove_action(‘admin_init’, ‘_maybe_update_core’);
remove_action(‘admin_init’, ‘_maybe_update_plugins’);
remove_action(‘admin_init’, ‘_maybe_update_themes’);
5.隐藏所有的更新
在主题的functions.php文件添加如下代码:
function remove_core_updates(){
global $wp_version;return(object) array(‘last_checked’=> time(),’version_checked’=> $wp_version,);
}
add_filter(‘pre_site_transient_update_core’,’remove_core_updates’); //WordPress核心
add_filter(‘pre_site_transient_update_plugins’,’remove_core_updates’); //WordPress插件
add_filter(‘pre_site_transient_update_themes’,’remove_core_updates’); //WordPress主题
或隐藏特定插件的更新提示
代码添加到functions.php,仅屏蔽单个插件的更新提示
function remove_update_notifications( $value ) {
if ( isset( $value ) && is_object( $value ) ) {
unset( $value->response[ ‘elementor/elementor.php’ ] ); //替换为禁用的插件文件
}
return $value;
}
add_filter(‘site_transient_update_plugins’, ‘remove_update_notifications’);
或隐藏特定主题的更新提示
代码添加到functions.php,仅屏蔽主题更新提示
function remove_theme_update_notification( $value ) {
if ( isset( $value ) && is_object( $value ) ) {
unset( $value->response[‘astra’] ); //替换为自己的主题名称
}
return $value;
}
add_filter( ‘site_transient_update_themes’, ‘remove_theme_update_notification’ );