Created
March 6, 2024 15:13
-
-
Save renventura/11199b9d6c8d8da900f412eda6906f97 to your computer and use it in GitHub Desktop.
Avoid deactivated plugins when manually calling wp_maybe_auto_update() function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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