Wordpress - Remove update nags for non-admins
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="%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 );
@bravokeyl is the probably the best answer to your immediate problem.
But to address the following:
Is there a way to hook into an action or filter and remove ALL the update nag messages for non-admin users?
No. Nag messages in WordPress are just a callback to added to the admin_notices
hook which print some HTML to the page. They are practically the same as error or success messages, or any other 'notice' from WordPress or any other plug-in or theme for that matter.
Hiding the nags via CSS is hacky. It's also liable to some false positives as some plugins/themes will, incorrectly, use the .update-nag
class to provide the desired styling to their own notices.
A much less hacky way is to explicitly remove each callback that you don't want printing notices (for non-admins). But this comes at a (probably very low cost) of maintaining that list and ensuring there are no notices that 'slip the net'.
here is complete code, which seems to work at this moment:
add_action('admin_head', function() {
if(!current_user_can('manage_options')){
remove_action( 'admin_notices', 'update_nag', 3 );
remove_action( 'admin_notices', 'maintenance_nag', 10 );
}
});