I’m trying to remove or hide the update nags for non-admin users. As an admin, I see:
The popular answer I’ve seen to handle this says to use:
function hide_update_nag() {
if ( !current_user_can('update_core') ) {
remove_action( 'admin_notices', 'update_nag', 3 );
}
}
add_action( 'admin_head', 'hide_update_nag', 1 );
This works fine for removing the first message (WordPress 4.5.3 is available! Please update now) but leaves the second one visible to non-admins:
Both messages are wrapped in a <div class="update-nag">
, so one option is to modify the above chunk of code to use CSS to hide the nag with:
echo '<style>.update-nag {display: none}</style>';
But this feels kludgy to me. Is there a way to hook into an action or filter and remove ALL the update nag messages for non-admin users? No third-party plugin recommendations please.
In wp-admin/includes/update.php
file
if ( current_user_can('update_core') )
$msg = sprintf( __('An automated WordPress update has failed to complete - <a href="https://wordpress.stackexchange.com/questions/231010/%s">please attempt the update again now</a>.'), 'update-core.php' );
else
$msg = __('An automated WordPress update has failed to complete! Please notify the site administrator.');
We can see that messages are different based on the current user role and this is maintenance_nag
.
Basically we have two update nags and can be found in admin-filters.php
add_action( 'admin_notices', 'update_nag', 3 );
add_action( 'admin_notices', 'maintenance_nag', 10 );
So to remove second message we can use(also check for current user role if you want this only for non-admins)
remove_action( 'admin_notices', 'maintenance_nag', 10 );
For multi-site use
remove_action( 'network_admin_notices', 'maintenance_nag', 10 );