源码概述:
由于 WordPress
更新服务器在国外,而国内网络无法顺畅连接上,导致 WordPress
后台更新检测和自动更新功能非常慢。为了解决这个问题,可以在当前主题的functions
.php
文件中添加以下代码,彻底关闭 WordPress
的自动更新和后台更新检查功能,这样在更新时就需要手动进行更新。请在编辑之前记得备份。
代码如下:
// 彻底关闭自动更新
add_filter
('automatic_updater_disabled
', '__
return
_true
');
// 关闭更新检查定时作业
remove_action
('init
', 'wp_schedule_update_checks
');
// 移除已有的版本检查定时作业
wp_clear_scheduled_hook
('wp_version_check
');
// 移除已有的插件更新定时作业
wp_clear_scheduled_hook
('wp_update_
plugin
s
');
// 移除已有的主题更新定时作业
wp_clear_scheduled_hook
('wp_update_themes
');
// 移除已有的自动更新定时作业
wp_clear_scheduled_hook
('wp_maybe_auto_update
');
// 移除后台内核更新检查
remove_action
( 'admin_init
', '_maybe_update_core
' );
// 移除后台插件更新检查
remove_action
( 'load
-plugins
.php
', 'wp_update_plugins
' );
remove_action
( 'load
-update
.php
', 'wp_update_plugins
' );
remove_action
( 'load
-update
-core
.php
', 'wp_update_plugins
' );
remove_action
( 'admin_init
', '_maybe_update_plugins
' );
// 移除后台主题更新检查
remove_action
( 'load
-themes
.php
', 'wp_update_themes
' );
remove_action
( 'load
-update
.php
', 'wp_update_themes
' );
remove_action
( 'load
-update
-core
.php
', 'wp_update_themes
' );
remove_action
( 'admin_init
', '_maybe_update_themes
' );
如果你不需要 WordPress
后台中的某些模块,你可以使用以下代码将它们隐藏起来。只需将下面的代码添加到当前主题的 functions
.php
文件中即可:
屏蔽左侧菜单
删除子菜单
function
remove_submenu
() {
// 删除”设置”下面的子菜单”隐私”
remove_submenu_page
('options
-general
.php
', 'options
-privacy
.php
');
// 删除”外观”下面的子菜单”编辑”
remove_submenu_page
('themes
.php
', 'theme
-editor
.php
');
}
if
(is_admin
()){
//删除子菜单
add_action
('admin_init
','remove_submenu
');
}
屏蔽后台更新模块
function
wp_hide_nag
() {
remove_action
( 'admin_notices
', 'update_nag
', 3 );
}
add_action
('admin_menu
','wp_hide_nag
');
屏蔽 WordPress
后台“显示选项”和“帮助”选项卡
function
remove_screen_options
(){ return
false
;}
add_filter
('screen_options_show_screen
', 'remove_screen_options
');
add_filter
( 'contextual_help
', 'wpse50723_remove_help
', 999, 3 );
function
wpse50723_remove_help
($old_help
, $screen_id
, $screen
){
$screen
->remove_help_tabs
();
return
$old_help
;
}
屏蔽后台仪表盘无用模块
function
example_remove_dashboard_widgets
() {
// Globalize
the
metaboxes
array
, this
holds
all
the
widgets
for
wp
-admin
global
$wp_meta_boxes
;
// 以下这一行代码将删除 "快速发布" 模块
unset
($wp_meta_boxes
['dashboard
']['side
']['core
']['dashboard_quick_press
']);
// 以下这一行代码将删除 "引入链接" 模块
unset
($wp_meta_boxes
['dashboard
']['normal
']['core
']['dashboard_incoming_links
']);
// 以下这一行代码将删除 "插件" 模块
unset
($wp_meta_boxes
['dashboard
']['normal
']['core
']['dashboard_plugins
']);
// 以下这一行代码将删除 "近期评论" 模块
unset
($wp_meta_boxes
['dashboard
']['normal
']['core
']['dashboard_recent_comments
']);
// 以下这一行代码将删除 "近期草稿" 模块
unset
($wp_meta_boxes
['dashboard
']['side
']['core
']['dashboard_recent_drafts
']);
// 以下这一行代码将删除 "[WordPress
](http
://zmingcx
.com
/tag
/wordpress
/) 开发日志" 模块
unset
($wp_meta_boxes
['dashboard
']['side
']['core
']['dashboard_primary
']);
// 以下这一行代码将删除 "其它 WordPress
新闻" 模块
unset
($wp_meta_boxes
['dashboard
']['side
']['core
']['dashboard_secondary
']);
// 以下这一行代码将删除 "概况" 模块
unset
($wp_meta_boxes
['dashboard
']['normal
']['core
']['dashboard_right_now
']);
}
add_action
('wp_dashboard_setup
', 'example_remove_dashboard_widgets
' );
屏蔽后台页脚版本信息
function
change_footer_admin
() {return
'';}
add_filter
('admin_footer_text
', 'change_footer_admin
', 9999);
function
change_footer_version
() {return
'';}
add_filter
( 'update_footer
', 'change_footer_version
', 9999);
屏蔽后台左上 LOGO
function
annointed_admin_bar_remove
() {
global
$wp_admin_bar
;
/* Remove
their
stuff
*/
$wp_admin_bar
->remove_menu
('wp
-logo
');
}
add_action
('wp_before_admin_bar_render
', 'annointed_admin_bar_remove
', 0);
屏蔽后台顶部工具条
//禁用后台顶部 管理条;
if
(!current_user_can
('manage_options
')) {
add_filter
('show_admin_bar
', '__return_false
');
}
结语:
这样,您的后台速度像要飞了起来那么快。
转载请注明:汇站网 » (WordPress
优化与加速)彻底关闭自动更新和去除后台更新检查