Categories
Pro Tips

How to Selectively Disable Automatic Updates for Plugins and Themes in WordPress

Codeable.io

As a WordPress site administrator, keeping your plugins and themes updated is crucial for security and functionality. However, there are scenarios where you might want to have more control over these updates, especially with automatic updates introduced in WordPress. Today, I’m going to show you a simple way to selectively disable automatic updates for specific plugins and themes.

Understanding the Need for Controlled Updates

Automatic updates are a double-edged sword. While they ensure that your site is running the latest software without manual intervention, they can sometimes cause compatibility issues or disrupt your site’s functionality, particularly when using custom or highly tailored plugins and themes.

Disabling Automatic Updates for a Specific Plugin

To prevent a specific plugin from updating automatically, you can use the following code snippet:

add_filter( 'auto_update_plugin', 'edd_sample_disable_plugin_autoupdates', 10, 2 );
function edd_sample_disable_plugin_autoupdates( $update, $plugin ) {
    if ( 'my-plugin/my-plugin.php' === $plugin->plugin ) {
        return false;
    }

    return $update;
}

In this code:

  • We hook into the auto_update_plugin filter.
  • Our function checks if the plugin in question matches our specified plugin (my-plugin/my-plugin.php).
  • If it matches, the function returns false, effectively disabling automatic updates for that plugin.

Disabling Automatic Updates for a Specific Theme

Similarly, to disable automatic updates for a particular theme, use this snippet:

add_filter( 'auto_update_theme', 'edd_sample_disable_theme_autoupdates', 10, 2 );
function edd_sample_disable_theme_autoupdates( $update, $theme ) {
    if ( 'my-theme' === $theme->theme ) {
        return false;
    }

    return $update;
}

Here’s what happens in this code:

  • We utilize the auto_update_theme filter.
  • Our function checks if the theme currently being updated matches our specified theme (my-theme).
  • If there’s a match, the function returns false, thus disabling automatic updates for that theme.

How to Implement These Snippets

To use these snippets:

  1. Access Your Theme’s functions.php File: You can do this via FTP or through your WordPress dashboard under Appearance > Theme Editor.
  2. Insert the Snippet: Choose the relevant snippet (for a plugin or theme) and insert it into your functions.php file.
  3. Customize the Code: Replace my-plugin/my-plugin.php or my-theme with the actual directory name and filename of your plugin or the slug of your theme.

Why Be Selective with Updates?

  1. Stability: Disabling automatic updates for certain plugins or themes can prevent unexpected changes or conflicts on your site, ensuring stability.
  2. Compatibility: This is particularly useful if you have custom code or specific configurations that may not be compatible with the latest updates.
  3. Testing: It allows you to manually test updates in a staging environment before applying them to your live site.

While automatic updates are beneficial for maintaining the health and security of your WordPress site, having the ability to selectively disable them for certain plugins and themes offers you greater control and peace of mind. This approach ensures that your site remains stable and functions exactly as you intend.

Remember to always backup your site before making any changes to your theme’s functions.php file or consider using a child theme to prevent losing your changes during a theme update.

Happy WordPressing!

Leave a Reply

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