Over a million developers have joined DZone.

Hide WordPress Update Notice To All But Admins

DZone's Guide to

Hide WordPress Update Notice To All But Admins

· Web Dev Zone ·
Free Resource

Access over 20 APIs and mobile SDKs, up to 250k transactions free with no credit card required

When you have built your site on an open source project like WordPress, one of the benefits you get is continuous updates and improvements to the core code.

WordPress aims to release a couple of versions per year. When there is a new version of WordPress available to download, there will be a notification bar at the top of your admin area. This notification bar will let you know that your WordPress version is out of date and that you need to update the core code.

WordPress Releases

It is highly recommended that whenever there is a stable release of WordPress, you update as soon as possible, just so you are always running the latest code with the latest security updates.

The problem with this is updating on a live site without knowing the affects of the update. With each release, WordPress is trying to improve its codebase. This could mean that it will improve on old functions of code, or even remove old functions of code.

If you have a plugin or theme that is using any of these old deprecated functions then it could break the functionality of your site or even bring down your entire site. For this reason you should always have a development site with the same plugins and themes where you can update WordPress to make sure that the new release will not break your site.

WordPress Update Notification

The WordPress update notification is shown to all users, but there is a different message depending on your access rights.

WordPress admin users have a capability called update_core, which allows them to run the update. Therefore, only admin users can actually update the core WordPress code, but other users will get a message which says that a new version is available and to contact the site administrator.

Depending on how your site is set up, you might not want to show all users that you are running an out of date WordPress version and want to hide the fact that an update is available.

Use the following code to hide the update message to all users except Admin users.

function hide_update_notice_to_all_but_admin_users() 
    if (!current_user_can('update_core')) {
        remove_action( 'admin_notices', 'update_nag', 3 );
add_action( 'admin_notices', 'hide_update_notice_to_all_but_admin_users', 1 );

#1 for location developers in quality, price and choice, switch to HERE.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}