How to Update WordPress Plugins and Themes Automatically in Code

This is a question that I have often read on most WordPress forums and to be honest I never really paid attention until I recently found myself in need of a permanent solution for this menace. WordPress has made huge strides in ensuring that their platform is secure and always up to date. However, this is not the case for external user-developed and third-party  WordPress themes and plugins.

If you are a web designer like myself, maintaining your clients’ websites and making sure that they are in good shape at all times is a huge part of the job. In as much as most people would assume that updating a plugin or a theme is a few second’s of work, the case is completely different if you have tens of websites to work on.  Thanks to WordPress’s own “pluggable” nature, with just a couple of lines of code you can configure automatic updates for all your websites.



Why should you configure Automatic updates for WordPress Plugins and themes

If you were wondering how to update WordPress version automatically, then that is no longer an issue as from WP 3.7. By default, the WP system updates itself automatically for all minor security and functional releases. Only for major build updates like WP version 5.2, 5.1, 5.0, 4.9 and so on will you be asked to update the system manually. Here are some of the reasons why you should configure auto-updates for WP Plugins and themes.

  1. Security

Basically, the reason you should keep your plugins and themes updated is to keep your website secure. Although some updates may break your website, almost 98% of the time an update will do your website more benefit than damage. To stay on the safe side always make sure you use plugins and themes from trusted publishers.

2.  Boost Functionality

Automattic, the guys behind the WP system are always updating the system to make it more versatile. This explains the recent GutenbergWordPresss update which has forced very many plugins to be restructured in order to become fully compatible with the system. By ensuring your plugins are up to date all the time, you rid yourself of surprises. Automatic updates guarantee that your plugins are working on the latest system.



3. Fix Bugs Automatically

This is not exactly an issue especially if you are using plugins from trusted publishers. WP moderators are very keen when adding developer software in their repositories. Nevertheless, once in a while you can find a couple of buggy plugins and themes in your collection. Some of these third-party systems are too awesome to uninstall them. Therefore by configuring automatic updates for all plugins you are certain that all bugs will be fixed automatically if the developer releases an update.

You can read more reasons on why it’s important to keep your WordPress website updated, in our next article. Now back to our topic, how do you make your website receive plugin and theme updates automatically? Well, there are two ways to do this.

  1. Use code to update wp plugins automatically.
  2. Use a plugin.



Which method is better for enabling Automatic updates for WordPress Plugins and Themes

I like the first method more. Using a plugin to update your plugins automatically has a number of disadvantages. First, plugins tend to slow your website a touch and the more you have the more likely you are to slow your website. Secondly, some of the plugins that claim to do this particular function have since been discontinued by WordPress. The thing is, updates are at the core of the WordPress system and trusting a plugin to carry them out for you is too risky a dare.

Of course, you don’t want to compromise your website over something you can do with one line of code. Lucky for you, all you need is a valid functions.php file for your WP theme or plugin and you are good to go.  Earlier on, in the era of WordPress 4.8, there was a plugin known as Automatic-plugin-updates. This plugin allowed you to configure automatic updates for WP plugins selectively. However, it was discontinued by the moderators over Guideline violations and to talk the truth, its ratings weren’t that convincing.



I cannot emphasize enough on the need to have a solid backup system for your WordPress website. It makes sense to set up a good backup of your website before enabling auto-updates for your plugins and themes. Unless you trust your gut feeling so much, do backup your website in case any automatic update of a plugin or theme breaks your website. It helps you know where to start the recovery process, just in case things go wrong.  You can use plugin-based solutions for this task. I’d suggest UpdraftPlus WordPress Backup Plugin or WP Rollback. for any non-techy person.

Step by step guide to activate automatic updates for WordPress plugins

Method1: Configuring plugin Auto-updates without a Plugin (Using Code)
    1. Open your WP-Admin dashboard
    2. Scroll down to Appearance and click Editor as shown below



  1. Once in the editor page, at the far right end of the page, you can see a panel labeled Theme Files. Scroll it and locate a file labeled Theme Functions (functions.php).
  2. Click the file to open it.
  3. Scroll down the page and paste this code:

For Auto plugin updates

1
add_filter( 'auto_update_plugin', '__return_true' );

For theme Auto Updates

1
add_filter( 'auto_update_theme', '__return_true' );

 

  • Finally scroll down and click “Update File” to save changes



Note: These codes will update all incoming theme and plugin updates automatically as from the instance you saved the changes. Any updates that were pending before the changes to the functions file might not be processed immediately and therefore you must update them manually if there were any. Also, to configure auto-updates selectively for certain plugins using code requires you to open the specific plugin and edit it manually.

Basically, all you have to do is

  1. open the plugin editor, as shown below.
  2. select the plugin you want to configure auto updates for.
  3. Locate it functions.php file and then paste this code inside its functions file.
1
add_filter( 'auto_update_plugin', '__return_true' );



Additional Tips

In case your plugin has no functions file you can create one for it and paste the code there. The recommended way to do this is to use a “must-use” plugin or if you like mu-plugin. Codex WP outlines why mu-plugins are the best way to add such custom functions. However, this could be a bit technical for any person who isn’t familiar with WordPress coding and development.

Method2: Configuring WordPress Automatic updates with a Plugin

Well, as we mentioned earlier, one of the most popular plugins for performing this task was discontinued by the WordPress moderators over violation of their guideline. Nevertheless, apart from the automatic-plugin-updates plugin, there are a couple of trustworthy auto-update plugins for WP. Some top-rated options include:

  1. Easy Updates Manager
  2. Companion Auto Update
  3. Auto Updates

Keep in touch for our upcoming blogs where we are planning to revisit each of these plugins in detail.  Meanwhile, the code solution might be a simpler option to this issue. Good Luck!





Leave a Reply
Your email address will not be published.
*
*

BACK TO TOP