A Deep Dive Into Automatic Updates for WordPress

In this article, you’ll learn about the time saving tips to simplify automatic updates feature of WordPress. Background Automatic Updates was introduced in WordPress 3.7. This feature is introduced to provide enhanced security as well as better and streamlined overall update experience.

4 ways to simplify Automatic Updates

  1. Core Updates
  2. Plugin Updates
  3. Theme Updates
  4. Translation File Updates

Core Updates will let you enable or disable WordPress Core Updates. This updates are very critical as well as provides new features or updates to WordPress Core.

Plugin Updates will let you enable or disable automatic updates of the plugins installed on your WordPress instance. This updates are critical, if your plugin is vulnerable to attacks.

Theme Updates will let you enable or disable automatic updates of the theme installed. Enabling automatic updates for themes might break your website on update. So, it is recommended to check the updates on your development server first and then update the same to your LIVE server.

Translation File Updates will let you enable or disable automatic updates for translation file which will help you to translate your website in multiple languages.

2 ways to implement and configure Automatic Updates:

  1. Defining constants in wp-config.php, and
  2. Adding filters using a WordPress Plugin

Defining constants in WordPress config file

You can completely enable/disable background automatic updates using wp-config.php:

// Enable Automatic Updates
define( 'AUTOMATIC_UPDATER_DISABLED', true );
// Disable Automatic Updates
define( 'AUTOMATIC_UPDATER_DISABLED', false );

You can enable/disable only the background automatic updates of WordPress Core via wp-config.php:

// Enable Core Updates
define( 'WP_AUTO_UPDATE_CORE', true );
// Disable Core Updates
define( 'WP_AUTO_UPDATE_CORE', false );

WP_AUTO_UPDATE_CORE can be defined with one of the three values, each value having a different behaviour:

  • true – Development, minor, and major updates are all enabled
  • false – Development, minor, and major updates are all disabled
  • minor – Minor updates are enabled, development, and major updates are disabled

Note:

  1. Only sites already running a development version will receive development updates.
  2. For development sites, the default value of WP_AUTO_UPDATE_CORE is true.
  3. For other sites, the default value of WP_AUTO_UPDATE_CORE is minor.

Adding filters using a WordPress Plugin

You can enable or disable all automatic updates using the following filter,

// Enable all update
add_filter( 'automatic_updater_disabled', '__return_true' );
// Disable all updates
add_filter( 'automatic_updater_disabled', '__return_false' );

To enable/disable all core-type updates only, use the following filter,

add_filter( 'auto_update_core', '__return_true' );  # Enable Core Updates
add_filter( 'auto_update_core', '__return_false' );  # Disable Core Updates

Rather than enabling or disabling all three types of core updates. You can selectively enable or disable them. Here are the few hooks available to enable or disable core updates:

  • allow_dev_auto_core_updates,
  • allow_minor_auto_core_updates, and
  • allow_major_auto_core_updates

Also, there are two shorthand functions available in WordPress which will allow you to enable or disable specific types of core updates with single lines of code. They are __return_true and __return_false.

To specifically enable them individually,

add_filter( 'allow_dev_auto_core_updates', '__return_true' ); # Enable development updates 
add_filter( 'allow_minor_auto_core_updates', '__return_true' ); # Enable minor updates
add_filter( 'allow_major_auto_core_updates', '__return_true' ); # Enable major updates

Note for Developers: To enable automatic updates even if a VCS folder (.git, .hg, .svn etc) was found in the WordPress directory,

add_filter( 'automatic_updates_is_vcs_checkout', '__return_false', 1 );

You can enable or disable automatic updates for all plugins,

add_filter( 'auto_update_plugin', '__return_true' );

You can enable or disable automatic updates for all themes,

add_filter( 'auto_update_theme', '__return_true' );

The auto_update_$type filters also allow you to fine-grain the filter control, as we can pass the specific item to update in the filter.

For Example, If you want to enable auto-updates for specific plugins only, then you could use code like this:

function auto_update_specific_plugins ( $update, $item ) {
    // Array of plugin slugs to always auto-update
    $plugins = array ( 
        'akismet',
        'buddypress',
    );
    if ( in_array( $item->slug, $plugins ) ) {
        return true; // Always update plugins in this array
    } else {
        return $update; // Else, use the normal API response to decide whether to update or not
    }
}
add_filter( 'auto_update_plugin', 'auto_update_specific_plugins', 10, 2 );

You can enable or disable Translation File Updates using filters,

add_filter( 'auto_update_translation', '__return_false' ); # Disable Translation File Updates
add_filter( 'auto_update_translation', '__return_true' ); # Enable Translation File Updates

You can also enable or disable Emails using filters,

// Disable update emails
add_filter( 'auto_core_update_send_email', '__return_false' );
// Enable update emails
add_filter( 'auto_core_update_send_email', '__return_true' );

You can use below mentioned filter to manipulate update emails according to the email $type (success, fail, critical), update type object $core_update, or $result:

/* @param bool   $send        Whether to send the email. Default true.
 * @param string $type        The type of email to send.
 *                            Can be one of 'success', 'fail', 'critical'.
 * @param object $core_update The update offer that was attempted.
 * @param mixed  $result      The result for the core update. Can be WP_Error.
 */
apply_filters( 'auto_core_update_send_email', true, $type, $core_update, $result );

Conclusion

This tutorial will help you manipulate all the types of automatic updates which will benefit you to demystify automatic updates of WordPress in any manner.

Please provide you views or suggestions on this tutorial which will help us to improve in a much better and efficient way.

Get instant free access to my monthly developer friendly newsletter where I'll share my best informative tips about WordPress and my Life Experiences.

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.