Permalink
Browse files

Check for updates once per minute when the user visits Dashboard -> U…

…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 c3a8325c2d81be96c795aaf955aed44e1873f251
Showing with 13 additions and 2 deletions.
  1. +13 −2 plugin-update-checker.php
@@ -109,6 +109,9 @@ protected function installHooks(){
//In case Cron is disabled or unreliable, we also manually trigger
//the periodic checks while the user is browsing the Dashboard.
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 {
//Periodic checks are disabled.
@@ -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
*/
@@ -303,10 +307,17 @@ public function maybeCheckForUpdates(){
}
$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 =
empty($state) ||
!isset($state->lastCheck) ||
( (time() - $state->lastCheck) >= $this->checkPeriod*3600 );
( (time() - $state->lastCheck) >= $timeout );
if ( $shouldCheck ){
$this->checkForUpdates();

0 comments on commit c3a8325

Please sign in to comment.