Disable WordPress Updates for Specific Users

Why would you ever want to disable WordPress updates? It is extremely important that you keep WordPress and your themes and plugins up-to-date!

Yes, but it may be a good idea to disable WordPress updates in some situations. Running an update routine in WordPress is pretty reliable, but it is prudent to take some steps to make sure things don’t break. For starters, you’ll want to be sure you’ve backed up the site’s files and database for when you need to rollback.

With great power comes great responsibility.

— Uncle Ben

If you have clients that have the power to run WordPress updates, they also have the power to potentially damage the site. If you are running automated backups and can give them the ability to quickly and easily restore the site, then it probably isn’t a big deal. Otherwise, the responsibility of properly backing up the site before an update falls on them.

If you choose to disable WordPress updates, here’s how:

/**
 * Disable WordPress updates
 *
 * @return object
 */
function disable_updates() {
    global $wp_version;
    return (object) array( 'last_checked' => time(), 'version_checked' => $wp_version, );
}

add_action( 'init', function () {
    if ( ! current_user_can( 'administrator' ) ) {
        add_filter( 'pre_site_transient_update_core', 'disable_updates' );     // Disable WordPress core updates
        add_filter( 'pre_site_transient_update_plugins', 'disable_updates' );  // Disable WordPress plugin updates
        add_filter( 'pre_site_transient_update_themes', 'disable_updates' );   // Disable WordPress theme updates
    }
} );

In this example, only administrators can see the update notifications and update a plugin. However, you may need to adapt the criteria to meet your own needs.

Note: If you go down this path, then be sure to actually login and update the client’s site!


Featured image by GotCredit

Advertisements

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Up Next:

Easily Check if Multiple Array Keys Exist in PHP

Easily Check if Multiple Array Keys Exist in PHP