Last active
January 10, 2024 14:54
-
-
Save dmhendricks/2d2c51da8a17d7a47b41bcfd26c3314d to your computer and use it in GitHub Desktop.
Plugin to disable WordPress Site Health, because that's what logs are for and users shouldn't be bothered with them. Copy to your MU or plugins directory and activate.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Disable Site Health | |
* Description: Disables WordPress Site Health notifications, dashboard widget and PHP update notice | |
* Version: 1.1.0 | |
* Author: Daniel M. Hendricks | |
* Author URI: https://daniel.hn/ | |
* Plugin URI: https://gist.github.com/dmhendricks/2d2c51da8a17d7a47b41bcfd26c3314d | |
*/ | |
namespace MU_Plugins; | |
class Disable_Site_Health { | |
private static $instance; | |
public static function init() { | |
if ( !isset( self::$instance ) && !( self::$instance instanceof Disable_Site_Health ) ) { | |
self::$instance = new Disable_Site_Health; | |
if( is_admin() ) { | |
// Remove Site Health Dashboard Widget | |
add_action( 'wp_dashboard_setup', array( self::$instance, 'remove_dashboard_widgets' ) ); | |
// Remove Site Health Menu Item | |
add_action( 'admin_menu', array( self::$instance, 'remove_site_health_menu' ) ); | |
// Block site health page | |
add_action( 'current_screen', array( self::$instance, 'block_site_health_page' ) ); | |
} | |
// Disable Site Health Email Notifications | |
add_filter( 'wp_fatal_error_handler_enabled', '__return_false' ); | |
} | |
return self::$instance; | |
} | |
/** | |
* Remove Site Health Dashboard Widget | |
* | |
* @since 1.0.0 | |
*/ | |
public static function remove_dashboard_widgets() { | |
remove_meta_box( 'dashboard_site_health', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_php_nag', 'dashboard', 'normal' ); | |
} | |
/** | |
* Remove Site Health Menu Item | |
* | |
* @since 1.0.0 | |
*/ | |
public static function remove_site_health_menu() { | |
remove_submenu_page( 'tools.php', 'site-health.php' ); | |
} | |
/** | |
* Block site health page | |
* | |
* @since 1.1.0 | |
*/ | |
public static function block_site_health_page() { | |
$screen = get_current_screen(); | |
if( $screen->id == 'site-health' ) { | |
http_response_code( 403 ); | |
die( 'Access to this page is forbidden.' ); | |
} | |
} | |
} | |
Disable_Site_Health::init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello! This gist disables viewing Site Health.
This MU plugin removes capabilities and disables functionality.
https://github.com/szepeviktor/wordpress-website-lifecycle/blob/master/mu-plugins/_core-disallow-site-health.php