彻底关闭WordPress自动更新和后台更新检查

WordPress 的后台更新检测和自动更新功能,由于WordPress更新服务器在国外,而国内的网络由于总总原因总是无法顺畅得连接上WordPress的更新服务器,所以一直卡在那里,造成WordPress后台非常慢!

在当前主题的functions.php文件添加如下代码,就可以彻底关闭 WordPress 自动更新和后台更新检查,这样更新的时候,就要手动来更新了

注:编辑之前记得备份哦

 
  1. // 彻底关闭自动更新
  2. add_filter('automatic_updater_disabled', '__return_true');
  3. // 关闭更新检查定时作业
  4. remove_action('init', 'wp_schedule_update_checks');
  5. // 移除已有的版本检查定时作业
  6. wp_clear_scheduled_hook('wp_version_check');
  7. // 移除已有的插件更新定时作业
  8. wp_clear_scheduled_hook('wp_update_plugins');
  9. // 移除已有的主题更新定时作业
  10. wp_clear_scheduled_hook('wp_update_themes');
  11. // 移除已有的自动更新定时作业
  12. wp_clear_scheduled_hook('wp_maybe_auto_update');
  13. // 移除后台内核更新检查
  14. remove_action( 'admin_init', '_maybe_update_core' );
  15. // 移除后台插件更新检查
  16. remove_action( 'load-plugins.php', 'wp_update_plugins' );
  17. remove_action( 'load-update.php', 'wp_update_plugins' );
  18. remove_action( 'load-update-core.php', 'wp_update_plugins' );
  19. remove_action( 'admin_init', '_maybe_update_plugins' );
  20. // 移除后台主题更新检查
  21. remove_action( 'load-themes.php', 'wp_update_themes' );
  22. remove_action( 'load-update.php', 'wp_update_themes' );
  23. remove_action( 'load-update-core.php', 'wp_update_themes' );
  24. remove_action( 'admin_init', '_maybe_update_themes' );

后台管理界面修改

WordPress后台很多模块有时并不需要,使用下面的代码可以将它们屏蔽掉。
根据需要,将下面代码添加到当前主题functions.php模板文件中:

屏蔽左侧菜单

 
  1. function remove_menus() {
  2. global $menu;
  3. $restricted = array(
  4. __('Dashboard'),
  5. __('Posts'),
  6. __('Media'),
  7. __('Links'),
  8. __('Pages'),
  9. __('Appearance'),
  10. __('Tools'),
  11. __('Users'),
  12. __('Settings'),
  13. __('Comments'),
  14. __('Plugins')
  15. );
  16. end ($menu);
  17. while (prev($menu)){
  18. $value = explode(' ',$menu[key($menu)][0]);
  19. if(strpos($value[0], '<') === FALSE) {
  20. if(in_array($value[0] != NULL ? $value[0]:"" , $restricted)){
  21. unset($menu[key($menu)]);
  22. }
  23. }else {
  24. $value2 = explode('<', $value[0]);
  25. if(in_array($value2[0] != NULL ? $value2[0]:"" , $restricted)){
  26. unset($menu[key($menu)]);
  27. }
  28. }
  29. }
  30. }
  31. if (is_admin()){
  32. // 屏蔽左侧菜单
  33. add_action('admin_menu', 'remove_menus');
  34. }

删除子菜单

 
  1. function remove_submenu() {
  2. // 删除”设置”下面的子菜单”隐私”
  3. remove_submenu_page('options-general.php', 'options-privacy.php');
  4. // 删除”外观”下面的子菜单”编辑”
  5. remove_submenu_page('themes.php', 'theme-editor.php');
  6. }
  7. if (is_admin()){
  8. //删除子菜单
  9. add_action('admin_init','remove_submenu');
  10. }

屏蔽后台更新模块

 
  1. function wp_hide_nag() {
  2. remove_action( 'admin_notices', 'update_nag', 3 );
  3. }
  4. add_action('admin_menu','wp_hide_nag');

屏蔽 WordPress 后台“显示选项”和“帮助”选项卡

 
  1. function remove_screen_options(){ return false;}
  2. add_filter('screen_options_show_screen', 'remove_screen_options');
  3. add_filter( 'contextual_help', 'wpse50723_remove_help', 999, 3 );
  4. function wpse50723_remove_help($old_help, $screen_id, $screen){
  5. $screen->remove_help_tabs();
  6. return $old_help;
  7. }

屏蔽后台仪表盘无用模块

 
  1. function example_remove_dashboard_widgets() {
  2. // Globalize the metaboxes array, this holds all the widgets for wp-admin
  3. global $wp_meta_boxes;
  4. // 以下这一行代码将删除 "快速发布" 模块
  5. unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
  6. // 以下这一行代码将删除 "引入链接" 模块
  7. unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
  8. // 以下这一行代码将删除 "插件" 模块
  9. unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
  10. // 以下这一行代码将删除 "近期评论" 模块
  11. unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
  12. // 以下这一行代码将删除 "近期草稿" 模块
  13. unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
  14. // 以下这一行代码将删除 "[WordPress](http://zmingcx.com/tag/wordpress/) 开发日志" 模块
  15. unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
  16. // 以下这一行代码将删除 "其它 WordPress 新闻" 模块
  17. unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
  18. // 以下这一行代码将删除 "概况" 模块
  19. unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
  20. }
  21. add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets' );

屏蔽后台页脚版本信息

 
  1. function change_footer_admin () {return '';}
  2. add_filter('admin_footer_text', 'change_footer_admin', 9999);
  3. function change_footer_version() {return '';}
  4. add_filter( 'update_footer', 'change_footer_version', 9999);

屏蔽后台左上LOGO

 
  1. function annointed_admin_bar_remove() {
  2. global $wp_admin_bar;
  3. /* Remove their stuff */
  4. $wp_admin_bar->remove_menu('wp-logo');
  5. }
  6. add_action('wp_before_admin_bar_render', 'annointed_admin_bar_remove', 0);

屏蔽后台顶部工具条

 
  1. //禁用后台顶部 管理条;
  2. if (!current_user_can('manage_options')) {
  3. add_filter('show_admin_bar', '__return_false');
  4. }
 

posted on 2021-04-07 16:05  剩余价值  阅读(550)  评论(0编辑  收藏  举报

导航