3

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')) {
0

4 Answers 4

3

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>';
    }
}
4
  • add_action and current_user_can won't work in functions.php; however, just hiding the elements with CSS seems to be the best way to do it so far. +1
    – bozdoz
    Oct 12, 2012 at 3:24
  • add_action and current_user_can does work in your theme's functions.php - I have used this exact code in over 30 sites with not a drama?
    – Clearmedia
    Oct 12, 2012 at 3:39
  • Glad to help! Feel free to share my question - unresolved after many months, I've nearly lost all my hair over it!
    – Clearmedia
    Oct 15, 2012 at 1:56
  • 4
    This is not really a good answer at all.
    – Wyck
    Oct 15, 2012 at 22:33
9

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');
12
  • Thanks @Wyck. Where would I put this info? Into wp-config?
    – bozdoz
    Oct 11, 2012 at 22:12
  • No these functions would go in your theme's functions.php or a plugin.
    – Wyck
    Oct 11, 2012 at 22:13
  • At the bottom? Top? Doesn't matter? @Wyck
    – bozdoz
    Oct 11, 2012 at 22:15
  • Not working in functions.php, says the functions are undefined: current_user_can
    – bozdoz
    Oct 11, 2012 at 22:24
  • That function will only work on WordPress 3.0 and above and must be called after functions.php loads, see here, wordpress.stackexchange.com/questions/14041/…
    – Wyck
    Oct 11, 2012 at 22:35
1

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' );
    }
}
0
0

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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.