Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

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

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:

Published at DZone with permission of Paul Underwood, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}