When I manually triggered WordPress auto update using the wp_maybe_auto_update()function, after the auto update process completes the plugins are getting deactivated.
I was experiencing the same problem, and digging into the code revealed the cause.
The Automatic_Upgrader uses the Plugin_Upgrader to update the plugins. The plugin upgrader has a method, deactivate_plugin_before_upgrade(), that is used to deactivate the plugin before upgrade, but only in specific cases. It contains these lines:
// When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it
if ( wp_doing_cron() )
return $return;
So when the updates are being run by a cron job, the plugins don't get deactivated. The automatic updates normally are run via cron, and so the code has made an assumption that they always will be. If the automatic updates get triggered outside of cron (as when you are manually calling wp_maybe_auto_update(), then the plugins will get deactivated, but they won't automatically get reactivated.
One solution would be to trick the upgrader into thinking that cron was running, by hooking into the 'wp_doing_cron' filter before you call wp_maybe_auto_update():
add_filter( 'wp_doing_cron', '__return_true' );
wp_maybe_auto_update();
remove_filter( 'wp_doing_cron', '__return_true' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With