Skip to content

How to Auto-Update WordPress Plugins and Themes (in Code)

Keeping WordPress core up-to-date has become so easy in the last few years that I barely even thing about it. Keeping WordPress plugins and themes up-to-date is currently still a more complex task. There are plugin-based solutions for it, but in this video we cover the method that’d be more favored by those who love writing PHP: the code that makes WordPress auto-update your plugins and themes.

There is some need for obvious provisos here: don’t auto-update plugins and themes that you don’t trust to keep working. Don’t enable auto-updates this way if you don’t have a solid backup system in place. Don’t use this solution of PHP-based auto-updates if your site looking weird when a plugin update doesn’t work will cause you (or someone else) to get fired.

With all those reasons why not, there’s one really good reason to do it: an updated WordPress plugin is more secure well over 95% of the time than an un-updated one. That means that while this isn’t an unquestionable win, it usually is one. Here’s how to do it on video:

How to Enable WordPress Plugin Auto-Updates in PHP Code

  1. Create your plugin or theme functions.php file. The Codex recommends that you use an mu-plugin  to do that — that is a “must-use” plugin that WordPress always has on. But WordPress will honor this code if it’s in an enable plugin or theme as well.
  2. Put in the line of code: add_filter( 'auto_update_plugin', '__return_true' );
  3. Put in the line of code: add_filter( 'auto_update_theme', '__return_true' );
  4. Make sure this code is somewhere it will run. If you’ve created this as a new plugin in the mu-plugins directory, it will. If you’ve enabled the (normal) plugin, it will. If you have it in functions.php of your currently running theme, it will.
Yay! πŸŽ‰ You made it to the end of the article!
David Hayes

2 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Mike
August 8, 2019 7:36 pm

Great video, thanks.
Your two lines update plugins and themes.
How do you recommend we set up WP to auto-update any major or minor WordPress release?

Mick
November 3, 2017 11:29 am

FYI: You link for “are plugin-based solutions for it,” is.. wrong πŸ˜‰ if you know what I am saying.

Please fix.

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!

2
0
Would love your thoughts, please comment.x