How do I disable dashboard update notifications for subscribers?

The question:

For registered users to my blog, if they click on the dashboard, they get an alert suggesting that they tell the site administrator (me) that the new version of WordPress is available.

All I want is to hide dashboard alerts from the subscribers. Where can I find the code to change this?

I found a site here that suggests that I’m looking for the code:

add_action('admin_head','addDashboardAlert');

But I don’t know where to look for it.

UPDATE

I found some more relevant code to make the alerts conditional on user role, here:

if (!current_user_can('delete_posts')) {

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

you can include some custom css in your functions.php that hides the update_nag (notifications) element dependent on user capability:

add_action('admin_head','admin_css');
function admin_css()
{
if(!current_user_can('administrator'))//not and admin
{
    echo '<style>';
        echo '.update_nag{display:none}';
        echo '</style>';
    }
}

Method 2

Updating this answer the original code below will remove the nag screen but it will ping the server for updates on every load, thanks to @ El Yobo, see update below.

This will disable the core updates and the nag screen to everyone but superadmins.

add_action( 'after_setup_theme', 'remove_core_updates' );
function remove_core_updates()
{
    if ( ! current_user_can( 'update_core' ) ) {
        return;
    }
    add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
    add_filter( 'pre_option_update_core', '__return_null' );
    add_filter( 'pre_site_transient_update_core', '__return_null' ); 
}  

To disable all plugin notifications;

remove_action( 'load-update-core.php', 'wp_update_plugins' );
add_filter( 'pre_site_transient_update_plugins', '__return_null' );

To remove a specific plugin you can try this but it is not 100% going to work depending on the plugin;

function ya_remove_plugin_update($value) {
     $plugin_relative_path = "plugin_relative_path"; // change this to your plugin
     unset( $value->response[ $plugin_relative_path ] );
     return $value;
}
add_filter( 'site_transient_update_plugins', 'ya_remove_plugin_update' );

Updated

This disable updates completely (I cannot get it to work based on user roles) AND stop pinging for updates (It will throw a PHP warning not sure how to fix this without altering core).

function remove_core_updates(){

        global $wp_version;
        return (object) array(
            'last_checked' => time(),
            'version_checked' => $wp_version,
            );
}
add_filter('pre_site_transient_update_core', 'remove_core_updates');
add_filter('pre_site_transient_update_plugins', 'remove_core_updates');
add_filter('pre_site_transient_update_themes', 'remove_core_updates');

Method 3

I didn’t manage to work with those scripts above so I researched a bit more and found this:

//Remove update notifications from sub-users
add_action('admin_head','admin_css');
function admin_css()
{
    // Choose the correct role where you need to block update nag
    if( current_user_can('YOUR_SELECTED_ROLE')) {
        add_filter( 'pre_site_transient_update_core', '__return_null' );
    }
}

Method 4

Deriving from @wyck’s answer, all update notices and PHP warnings are now hidden using the script below. Just place this in your functions.php

function remove_core_updates() {
  global $wp_version;
  return (object) array(
    'last_checked' => time(),
    'version_checked' => $wp_version,
  );
}
add_filter('pre_site_transient_update_core', 'remove_core_updates');
add_filter('pre_site_transient_update_plugins', 'remove_core_updates');
add_filter('pre_site_transient_update_themes', 'remove_core_updates');


function remove_menu() {
  global $submenu;
  if (isset($submenu['index.php'][10]))
    unset($submenu['index.php'][10]); // Removes 'Updates'.
}
add_action('admin_menu', 'remove_menu');


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment