Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renventura/11199b9d6c8d8da900f412eda6906f97 to your computer and use it in GitHub Desktop.
Save renventura/11199b9d6c8d8da900f412eda6906f97 to your computer and use it in GitHub Desktop.
Avoid deactivated plugins when manually calling wp_maybe_auto_update() function
<?php
/**
* Manually calling wp_maybe_auto_update() results in plugins getting deactivated during the update process.
* WP assumes this function is run during cron, and it neither deactivates nor reactivates plugins during cron.
* When run outside of cron, it will deactivate plugins, but it assumes the browser will refresh and reactivate them.
* To prevent deactivated plugins when calling this function, we can trick the upgrader into thinking it's called during cron.
*
* @link https://stackoverflow.com/questions/41541968/plugins-are-getting-deactivated-after-automatic-plugin-update-in-wordpress
*/
add_filter( 'wp_doing_cron', '__return_true' );
wp_maybe_auto_update();
remove_filter( 'wp_doing_cron', '__return_true' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment