最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How do I disable dashboard update notifications for subscribers?

programmeradmin0浏览0评论

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

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')) {
Share Improve this question edited Oct 12, 2012 at 0:37 kaiser 50.9k27 gold badges150 silver badges245 bronze badges asked Oct 11, 2012 at 21:03 bozdozbozdoz 1351 gold badge1 silver badge7 bronze badges 0
Add a comment  | 

4 Answers 4

Reset to default 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>';
    }
}

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

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

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');
发布评论

评论列表(0)

  1. 暂无评论