diff --git a/Puc/v5p3/Scheduler.php b/Puc/v5p3/Scheduler.php index 98f2e93..05d743e 100644 --- a/Puc/v5p3/Scheduler.php +++ b/Puc/v5p3/Scheduler.php @@ -87,6 +87,7 @@ if ( !class_exists(Scheduler::class, false) ): add_action($hook, array($this, 'maybeCheckForUpdates')); } //This hook fires after a bulk update is complete. + add_action('upgrader_process_complete', array($this, 'removeHooksIfLibraryGone'), 1, 0); add_action('upgrader_process_complete', array($this, 'upgraderProcessComplete'), 11, 2); } else { @@ -95,6 +96,22 @@ if ( !class_exists(Scheduler::class, false) ): } } + /** + * Remove all hooks if this version of PUC has been deleted or overwritten. + * + * Callback for the "upgrader_process_complete" action. + */ + public function removeHooksIfLibraryGone() { + //Cancel all further actions if the current version of PUC has been deleted or overwritten + //by a different version during the upgrade. If we try to do anything more in that situation, + //we could trigger a fatal error by trying to autoload a deleted class. + clearstatcache(); + if ( !file_exists(__FILE__) ) { + $this->removeHooks(); + $this->updateChecker->removeHooks(); + } + } + /** * Runs upon the WP action upgrader_process_complete. * @@ -108,16 +125,6 @@ if ( !class_exists(Scheduler::class, false) ): /** @noinspection PhpUnusedParameterInspection */ $upgrader, $upgradeInfo ) { - //Cancel all further actions if the current version of PUC has been deleted or overwritten - //by a different version during the upgrade. If we try to do anything more in that situation, - //we could trigger a fatal error by trying to autoload a deleted class. - clearstatcache(); - if ( !file_exists(__FILE__) ) { - $this->removeHooks(); - $this->updateChecker->removeHooks(); - return; - } - //Sanity check and limitation to relevant types. if ( !is_array($upgradeInfo) || !isset($upgradeInfo['type'], $upgradeInfo['action'])