WordPress从 5.2 版开启增加了一个站点健康功能,其实没啥用,直接删除 WordPress 站点健康状态面板和菜单项,将下面4项代码添加到当前主题函数模板functions.php中就可以干掉他们。
1、删除站点健康菜单项
- add_action( 'admin_menu', 'remove_site_health_menu' );
- function remove_site_health_menu(){
- remove_submenu_page( 'tools.php','site-health.php' );
- }
2、删除仪表盘站点健康状态面板
- add_action('wp_dashboard_setup', 'remove_site_health_dashboard_widget');
- function remove_site_health_dashboard_widget()
- {
- remove_meta_box('dashboard_site_health', 'dashboard', 'normal');
- }
3、阻止站点运行站点健康检查页
- add_action( 'current_screen', 'block_site_health_access' );
- function block_site_health_access() {
- if ( is_admin() ) {
- $screen = get_current_screen();
- if ( 'site-health' == $screen->id ) {
- wp_redirect( admin_url() );
- exit;
- }
- }
- }
4、禁用站点健康电子邮件通知
- add_filter( 'wp_fatal_error_handler_enabled', '__return_false' );
上述方法并不能禁止站点健康功能在后台偷偷运行,如果想彻底禁止站点健康检测,请添加下方代码
- add_filter( 'site_status_tests', 'prefix_remove_site_health', 100 );
- function prefix_remove_site_health( $tests ) {
- $hidden_tests = array(
- 'php_version' => 'direct', //PHP 版本
- 'wordpress_version' => 'direct', //WordPress 版本
- 'plugin_version' => 'direct', //插件版本
- 'theme_version' => 'direct', //主题版本
- 'sql_server' => 'direct', //数据库服务器版本
- 'php_extensions' => 'direct', //PHP 扩展
- 'php_default_timezone' => 'direct', //PHP 默认时区
- 'php_sessions' => 'direct', //PHP Sessions
- 'utf8mb4_support' => 'direct', //MySQL utf8mb4 支持
- 'https_status' => 'direct', //HTTPS 状态
- 'ssl_support' => 'direct', //安全通讯
- 'scheduled_events' => 'direct', //计划的事件
- 'http_requests' => 'direct', //HTTP请求
- 'debug_enabled' => 'direct', //启用调试
- 'file_uploads' => 'direct', //文件上传
- 'plugin_theme_auto_updates' => 'direct', //插件和主题自动更新
- 'dotorg_communication' => 'async', //与WordPress.org联通状态
- 'background_updates' => 'async', //后台更新
- 'loopback_requests' => 'async', //Loopback request
- 'authorization_header' => 'async', //Authorization header
- 'rest_availability' => 'direct', //REST API 可用性
- );
- foreach ( $hidden_tests as $test=>$type ) {
- unset( $tests[$type][$test] );
- }
- return $tests;
- }