Force auto update for a plugin using php
On June 3, 2021 In Wordpress Tips and Tricks
In this post we will see how we can force auto update for a plugin using php. Auto updates in wordpress is a wonderful feature. This feature frees us from constantly checking for updates. It updates our themes and plugins automatically thus reduces the mundane tasks in life.
Enabling auto updates is as simple as clicking on the required option in plugins screen though, sometimes we may need to do this using php script.
Force auto updates for all the plugins
We can use following snippet as mentioned in wordpress documentation
// Automatic updates for All plugins add_filter( 'auto_update_plugin', '__return_true' ); //Automatic updates for All themes: add_filter( 'auto_update_theme', '__return_true' );
Force auto updates for a particular plugin
add_filter( 'auto_update_plugin', 'aoc_force_auto_update', 10, 2 ); function aoc_force_auto_update( $update, $item ) { if ( $item->id === '<plugin-slug>' ) { // always enable auto update return true; } // return original value for other plugins return $update; }