/** * Request plugin info and output it. */ public function ajaxRequestInfo() { if ($_POST['slug'] !== $this->updateChecker->slug) { return; } $this->preAjaxReqest(); $info = $this->updateChecker->requestInfo(); if ($info !== null) { echo 'Successfully retrieved plugin info from the metadata URL:'; echo '<pre>', htmlentities(print_r($info, true)), '</pre>'; } else { echo 'Failed to retrieve plugin info from the metadata URL.'; } exit; }
public function __construct($repositoryUrl, $pluginFile, $branch = 'master', $checkPeriod = 12, $optionName = '', $muPluginFile = '') { $this->repositoryUrl = $repositoryUrl; $this->branch = empty($branch) ? 'master' : $branch; $path = @parse_url($repositoryUrl, PHP_URL_PATH); if (preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches)) { $this->userName = $matches['username']; $this->repositoryName = $matches['repository']; } else { throw new InvalidArgumentException('Invalid GitHub repository URL: "' . $repositoryUrl . '"'); } parent::__construct($repositoryUrl, $pluginFile, '', $checkPeriod, $optionName, $muPluginFile); }
/** * Check for updates if the configured check interval has already elapsed. * Will use a shorter check interval on certain admin pages like "Dashboard -> Updates" or when doing cron. * * You can override the default behaviour by using the "puc_check_now-$slug" filter. * The filter callback will be passed three parameters: * - Current decision. TRUE = check updates now, FALSE = don't check now. * - Last check time as a Unix timestamp. * - Configured check period in hours. * Return TRUE to check for updates immediately, or FALSE to cancel. * * This method is declared public because it's a hook callback. Calling it directly is not recommended. */ public function maybeCheckForUpdates() { if (empty($this->checkPeriod)) { return; } $currentFilter = current_filter(); if (in_array($currentFilter, array('load-update-core.php', 'upgrader_process_complete'))) { //Check more often when the user visits "Dashboard -> Updates" or does a bulk update. $timeout = 60; } else { if (in_array($currentFilter, array('load-plugins.php', 'load-update.php'))) { //Also check more often on the "Plugins" page and /wp-admin/update.php. $timeout = 3600; } else { if ($this->throttleRedundantChecks && $this->updateChecker->getUpdate() !== null) { //Check less frequently if it's already known that an update is available. $timeout = $this->throttledCheckPeriod * 3600; } else { if (defined('DOING_CRON') && constant('DOING_CRON')) { //WordPress cron schedules are not exact, so lets do an update check even //if slightly less than $checkPeriod hours have elapsed since the last check. $cronFuzziness = 20 * 60; $timeout = $this->checkPeriod * 3600 - $cronFuzziness; } else { $timeout = $this->checkPeriod * 3600; } } } } $state = $this->updateChecker->getUpdateState(); $shouldCheck = empty($state) || !isset($state->lastCheck) || time() - $state->lastCheck >= $timeout; //Let plugin authors substitute their own algorithm. $shouldCheck = apply_filters('puc_check_now-' . $this->updateChecker->slug, $shouldCheck, !empty($state) && isset($state->lastCheck) ? $state->lastCheck : 0, $this->checkPeriod); if ($shouldCheck) { $this->updateChecker->checkForUpdates(); } }
/** * Calculate the actual check period based on the current status and environment. * * @return int Check period in seconds. */ protected function getEffectiveCheckPeriod() { $currentFilter = current_filter(); if (in_array($currentFilter, array('load-update-core.php', 'upgrader_process_complete'))) { //Check more often when the user visits "Dashboard -> Updates" or does a bulk update. $period = 60; } else { if (in_array($currentFilter, array('load-plugins.php', 'load-update.php'))) { //Also check more often on the "Plugins" page and /wp-admin/update.php. $period = 3600; } else { if ($this->throttleRedundantChecks && $this->updateChecker->getUpdate() !== null) { //Check less frequently if it's already known that an update is available. $period = $this->throttledCheckPeriod * 3600; } else { if (defined('DOING_CRON') && constant('DOING_CRON')) { //WordPress cron schedules are not exact, so lets do an update check even //if slightly less than $checkPeriod hours have elapsed since the last check. $cronFuzziness = 20 * 60; $period = $this->checkPeriod * 3600 - $cronFuzziness; } else { $period = $this->checkPeriod * 3600; } } } } return $period; }