0

Just a quick question to see if anyone has done this before, is there a function that I can use to add a custom message to the "Wordpress XX is available"

Update Notice Image

Recently, I've had clients updating their own site and making a right mess of things, especially with third party plugins.

I just want to throw a notification on saying how updating could cause issues, please contact me first.

0

Why not just remove it completely?

You can add this to your themes functions.php file:

// Hide update notice for everyone except admins
function wps_hide_update_notice() {
            if ( !current_user_can( 'manage_options' ) ) {
                remove_action( 'admin_notices', 'update_nag', 3 );
            }
        }

add_action('admin_menu','wps_hide_update_notice');
|improve this answer|||||
  • Because it's nice to have the client aware that their site needs updating. I just want to give them the ability to tell me, rather than update it themselves. I've had a client recently press update on all plugins, and one in particular (woocommerce) has rewritten its core files, so the template had broken and needed to be fixed. – Andrew Lazarus May 23 '14 at 10:16
0

Because there is no filter to customize the message for available updates, you need first to remove that message and display yours:

  • Remove actions that will display the update notifications:

    function hide_original_update_notice() 
    {
            remove_action( 'admin_notices', 'update_nag', 3 );
            remove_action( 'network_admin_notices', 'update_nag', 3 );
    }
    add_action( 'admin_head', 'hide_original_update_notice', 1 );
    
  • Create your notification action:

    function my_custom_update_nag() {
            if ( is_multisite() && !current_user_can('update_core') )
                    return false;
    
            global $pagenow;
    
            if ( 'update-core.php' == $pagenow )
                    return;
    
            $cur = get_preferred_from_update_core();
    
            if ( ! isset( $cur->response ) || $cur->response != 'upgrade' )
                    return false;
    
            if ( current_user_can('update_core') ) {
                    $msg = sprintf( __('<a href="http://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> is available! <a href="%2$s">Please update now</a>.'), $cur->current, network_admin_url( 'update-core.php' ) );
            } else {
                    $msg = sprintf( __('<a href="http://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> is available! Please notify the site administrator.'), $cur->current );
            }
            echo "<div class='update-nag'>$msg</div>";
    }
    add_action( 'admin_notices', 'my_custom_update_nag', 3 );
    add_action( 'network_admin_notices', 'my_custom_update_nag', 3 );
    
|improve this answer|||||
  • This is fantastic, However, it doesn't seem to want to remove the previous message, no matter how I use remove_action. Is it being removed when you do it on 3.9.1? – Andrew Lazarus May 23 '14 at 10:17
  • @AndrewLazarus i have updated my answer with the complete solution – Alexandru Furculita May 23 '14 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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