Want to auto-update WordPress? Here’s some handy code
Updating your website is vital in maintaining a secure site, so it was welcomed in 2013 when WordPress introduced a new feature which automatically installed any minor version updates to WordPress core.
Despite this, Developers still need to update things like plugins, themes and WordPress core major updates manually. On large sites, or for a company which manages a lot of sites, this can be increasingly time consuming.
Here are a couple of handy snippets of code which may help you improve the management of updates a little bit better.
Major WordPress Core Updates
define( 'WP_AUTO_UPDATE_CORE', true );
Add this line into your website’s wp-config.php file, and WordPress will do all updates to core, including major updates.
define( 'AUTOMATIC_UPDATER_DISABLED', true );
Add this line into your website’s wp-config.php file, and WordPress won’t do any updates. This might be useful for a developer who is using a version control system and wants to manually do their updates themselves.
Enabling Plugin and Theme Updates
add_filter( 'auto_update_plugin', '__return_true' );
add_filter( 'auto_update_theme', '__return_true' );
Add either of the lines above into your theme’s functions.php file, and WordPress will automatically update plugins and themes.
Problems with Updating
Recently, we noticed that some of the websites that we manage here at Home hadn’t automatically updated core. Stranger still was that a few of the sites we managed had updated, meaning there was no consistency in what we were seeing.
We compared multiple website’s wp-config.php and theme’s functions.php files, some of which had updated, some of which hadn’t. All the files were the same (bar the database configuration options) and none of them contained the code above which disables the WordPress automatic updates.
Digging around the folder structure for some of these websites, we noticed that the difference between the websites was that some of them were in a version controlled folder (Git, SVN, etc.) and some of them weren’t.
Following a quick search, we found that if WordPress detects that your website is in a version controlled folder, it will disable automatic updates for you.
Add these lines of code to your theme’s functions.php file to enable automatic updates on websites inside a version controlled folder.
add_filter( 'allow_minor_auto_core_updates', '__return_true' ); add_filter( 'automatic_updates_is_vcs_checkout', '__return_false', 1 );
At Home, we recommend enabling automatic updates for minor core versions, even if using a version control system, so that your website gets the latest security updates automatically.
If you want to know more about managing your website updates, tweet us @homeagencyuk or give us a call on 0844 576 8976.