From 5aee0d7b8b9ee7de992111551f3846ebcf591f6f Mon Sep 17 00:00:00 2001 From: Yahnis Elsts Date: Fri, 22 Feb 2013 09:40:15 -0800 Subject: [PATCH] Add a workaround for a bug in BackupBuddy that would cause this library to run a new update check every few seconds. This affects BackupBuddy 3.2.0.2 and possibly multiple other versions. Analysis: - PluginUpdateChecker creates a custom cron schedule by using the cron_schedules filter. This schedule is used to run periodic update checks. - BackupBuddy also creates a number of custom schedules using the same filter. However, its filter callback throws away any schedules defined by other filters/plugins and re-initializes $schedules with an empty array(). - As a result, if the filter that was added by BackupBuddy runs *after* the filter added by PluginUpdateChecker, our custom schedule is destroyed. - When WordPress tries to re-schedule our event after a successful Cron run, it discovers that the required schedule no longer exists, and fails. On the next page load, the library detects that the event is not scheduled and schedules it again. Hence infinite loop. - Fixed by moving our cron_schedules filter to a later priority. Notes: This is the *second* time I have to add a workaround for some arrogant oversight perpetrated by BackupBuddy developers. (The first one was the "plugins_api" thing, IIRC). --- plugin-update-checker.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/plugin-update-checker.php b/plugin-update-checker.php index 17978584..143cdb34 100644 --- a/plugin-update-checker.php +++ b/plugin-update-checker.php @@ -84,7 +84,7 @@ protected function installHooks(){ if ( $this->checkPeriod > 0 ){ //Trigger the check via Cron - add_filter('cron_schedules', array($this, '_addCustomSchedule')); + add_filter('cron_schedules', array($this, '_addCustomSchedule'), 20); if ( !wp_next_scheduled($this->cronHook) && !defined('WP_INSTALLING') ) { $scheduleName = 'every' . $this->checkPeriod . 'hours'; wp_schedule_event(time(), $scheduleName, $this->cronHook); @@ -118,7 +118,7 @@ public function _addCustomSchedule($schedules){ 'interval' => $this->checkPeriod * 3600, 'display' => sprintf('Every %d hours', $this->checkPeriod), ); - } + } return $schedules; } @@ -193,12 +193,12 @@ public function requestInfo($queryArgs = array()){ $pluginInfo = apply_filters('puc_request_info_result-'.$this->slug, $pluginInfo, $result); return $pluginInfo; } - + /** * Retrieve the latest update (if any) from the configured API endpoint. - * + * * @uses PluginUpdateChecker::requestInfo() - * + * * @return PluginUpdate An instance of PluginUpdate, or NULL when no updates are available. */ public function requestUpdate(){ @@ -237,11 +237,11 @@ public function getInstalledVersion(){ return null; } } - + /** - * Check for plugin updates. + * Check for plugin updates. * The results are stored in the DB option specified in $optionName. - * + * * @return PluginUpdate|null */ public function checkForUpdates(){ @@ -285,12 +285,12 @@ public function maybeCheckForUpdates(){ return; } $state = $this->getUpdateState(); - + $shouldCheck = empty($state) || - !isset($state->lastCheck) || + !isset($state->lastCheck) || ( (time() - $state->lastCheck) >= $this->checkPeriod*3600 ); - + if ( $shouldCheck ){ $this->checkForUpdates(); }