Last active
December 2, 2020 10:00
-
-
Save UltraSimplified/2465362c4fd0fc69163a9ad3d6487528 to your computer and use it in GitHub Desktop.
Restrict access to WordPress Site Health notices
This file contains hidden or 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
add_action('wp_dashboard_setup', 'restrict_site_health_dashboard_widget' ); | |
/** | |
* Restrict access to Site Health Dashboard Widget | |
* | |
*/ | |
function restrict_site_health_dashboard_widget() { | |
// permitted users | |
$permitted_users = []; // Array of permitted user ids | |
$user = wp_get_current_user(); | |
if ( ! in_array ($user->ID, $permitted_users)) { | |
remove_meta_box('dashboard_site_health', 'dashboard', 'normal'); | |
} | |
} | |
add_action( 'admin_menu', 'restrict_site_health_menu' ); | |
/** | |
* Restrict access to Site Health Sub Menu Item | |
*/ | |
function restrict_site_health_menu(){ | |
// permitted users | |
$permitted_users = []; // Array of permitted user ids | |
$user = wp_get_current_user(); | |
if ( ! in_array ( $user->ID, $permitted_users)) { | |
remove_submenu_page('tools.php', 'site-health.php'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WordPress site health can be really useful for developers, admins and sysadmins but can also create distress and headaches for ordinary users, particularly in cases where a minor point release version of PHP behind the current release triggers a critical "out of date" warning.
This snippet allows you to restrict the Site Health display to specific users.