Install plugin updates automatically, so security fixes are applied within hours, with an option to update only the plugins you choose.
// 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 );
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.
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.
DISALLOW_FILE_MODS is set, no automatic updates happen.auto_update_theme filter the same way.Open the Plugins screen. The Automatic updates column should show “Auto-updates enabled” for each plugin.