Skip to content

Commit

Permalink
Check for updates once per minute when the user visits Dashboard -> U…
Browse files Browse the repository at this point in the history
…pdates.

This was suggested in #8 as a way to make the custom update checker more consistent with how WP handles plugin updates. Arguably, visiting "Dashboard -> Updates" means that the user wants to check for updates, so it's okay to ignore the configured check interval in this case.

You can still disable automatic checks by setting $checkPeriod to 0, which will also disable this additional check.
  • Loading branch information
YahnisElsts committed Sep 27, 2013
1 parent 2edd17e commit c3a8325
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions plugin-update-checker.php
Expand Up @@ -109,6 +109,9 @@ protected function installHooks(){
//In case Cron is disabled or unreliable, we also manually trigger //In case Cron is disabled or unreliable, we also manually trigger
//the periodic checks while the user is browsing the Dashboard. //the periodic checks while the user is browsing the Dashboard.
add_action( 'admin_init', array($this, 'maybeCheckForUpdates') ); add_action( 'admin_init', array($this, 'maybeCheckForUpdates') );

//Like WordPress itself, we check more often on certain pages.
add_action( 'load-update-core.php', array($this, 'maybeCheckForUpdates') );


} else { } else {
//Periodic checks are disabled. //Periodic checks are disabled.
Expand Down Expand Up @@ -293,7 +296,8 @@ public function checkForUpdates(){
} }


/** /**
* Check for updates only if the configured check interval has already elapsed. * Check for updates if the configured check interval has already elapsed.
* Will use a shorter check interval on certain admin pages like "Dashboard -> Updates".
* *
* @return void * @return void
*/ */
Expand All @@ -303,10 +307,17 @@ public function maybeCheckForUpdates(){
} }
$state = $this->getUpdateState(); $state = $this->getUpdateState();


//Check more often when the user visits Dashboard -> Updates.
if ( current_filter() == 'load-update-core.php' ) {
$timeout = 60;
} else {
$timeout = $this->checkPeriod * 3600;
}

$shouldCheck = $shouldCheck =
empty($state) || empty($state) ||
!isset($state->lastCheck) || !isset($state->lastCheck) ||
( (time() - $state->lastCheck) >= $this->checkPeriod*3600 ); ( (time() - $state->lastCheck) >= $timeout );


if ( $shouldCheck ){ if ( $shouldCheck ){
$this->checkForUpdates(); $this->checkForUpdates();
Expand Down

0 comments on commit c3a8325

Please sign in to comment.