Skip to content

Instantly share code, notes, and snippets.

@UltraSimplified
Last active December 2, 2020 10:00
Show Gist options
  • Save UltraSimplified/2465362c4fd0fc69163a9ad3d6487528 to your computer and use it in GitHub Desktop.
Save UltraSimplified/2465362c4fd0fc69163a9ad3d6487528 to your computer and use it in GitHub Desktop.
Restrict access to WordPress Site Health notices
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');
}
}
@UltraSimplified
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment