Security PHP Beginner

Turn On Automatic Plugin Updates

Install plugin updates automatically, so security fixes are applied within hours, with an option to update only the plugins you choose.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 8 lines
// Update every plugin automatically.
add_filter( 'auto_update_plugin', '__return_true' );

// Or only some plugins, by folder name. Use this instead of the line above.
// add_filter( 'auto_update_plugin', function ( $update, $item ) {
// 	$slugs = [ 'woocommerce', 'nahnu-login-shield' ];
// 	return in_array( $item->slug ?? '', $slugs, true ) ? true : $update;
// }, 10, 2 );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

Most hacked WordPress sites run an outdated plugin with a known security hole. Automatic updates close those holes without waiting for someone to log in and click Update.

How it works

WordPress’s background updater checks each plugin through the auto_update_plugin filter. Returning true updates every plugin when a new version is available. The commented-out version updates only the plugins you list, by folder name, and leaves the rest to the per-plugin setting on the Plugins screen.

Updates run through WP-Cron, roughly twice a day, and WordPress emails the admin address with the results.

Things to watch

  • Automatic updates can occasionally break things. Keep backups, and leave plugins that control payments or core features on manual if you’d rather test first.
  • If DISALLOW_FILE_MODS is set, no automatic updates happen.
  • For themes, use the auto_update_theme filter the same way.

How to test it

Open the Plugins screen. The Automatic updates column should show “Auto-updates enabled” for each plugin.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only