Fix (probably) a conflict with the "WP Last Modified Info" plugin, version 1.8.8.

When a plugin update overwrites PUC with a different version of PUC, the hook callbacks registered by the old version can trigger fatal errors when they try to autoload now-deleted PHP files. Normally, PUC avoids this by using an `upgrader_process_complete` hook to check if one of its files still exists, and removing the hooks if the file is missing.  

However, it appears that WP Last Modified Info has its own `upgrader_process_complete` callback that runs earlier. That callback tries to download plugin metadata, which indirectly triggers some PUC hooks, and leads to the fatal error(s) mentioned earlier.

Fixed by extracting the relevant part of  `upgraderProcessComplete` to a separate method and registering that method as a callback for the same hook, but with an earlier priority (1 instead of 11). It appears that WP Last Modified Info uses the default priority: 10.
This commit is contained in:
Yahnis Elsts 2023-11-14 11:52:30 +02:00
parent 0b6bd7cd32
commit 9c1bddcd46
1 changed files with 17 additions and 10 deletions

View File

@ -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'])