Skip to content

Commit

Permalink
Use default cron schedules when possible.
Browse files Browse the repository at this point in the history
This makes the library more resilient and less likely to break due to cron-related bugs in other plugins. See this commit for an analysis of one such bug: 5aee0d7
  • Loading branch information
YahnisElsts committed Jun 26, 2013
1 parent 5aee0d7 commit f757517
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions plugin-update-checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,23 @@ protected function installHooks(){
$this->cronHook = 'check_plugin_updates-' . $this->slug;
if ( $this->checkPeriod > 0 ){

//Trigger the check via Cron
add_filter('cron_schedules', array($this, '_addCustomSchedule'), 20);
if ( !wp_next_scheduled($this->cronHook) && !defined('WP_INSTALLING') ) {
//Trigger the check via Cron.
//Try to use one of the default schedules if possible as it's less likely to conflict
//with other plugins and their custom schedules.
$defaultSchedules = array(
1 => 'hourly',
12 => 'twicedaily',
24 => 'daily',
);
if ( array_key_exists($this->checkPeriod, $defaultSchedules) ) {
$scheduleName = $defaultSchedules[$this->checkPeriod];
} else {
//Use a custom cron schedule.
$scheduleName = 'every' . $this->checkPeriod . 'hours';
add_filter('cron_schedules', array($this, '_addCustomSchedule'));
}

if ( !wp_next_scheduled($this->cronHook) && !defined('WP_INSTALLING') ) {
wp_schedule_event(time(), $scheduleName, $this->cronHook);
}
add_action($this->cronHook, array($this, 'checkForUpdates'));
Expand Down

0 comments on commit f757517

Please sign in to comment.