From 6ffe93ee09035fdad8ea7c609c17d9616e167ce3 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Wed, 6 Jan 2016 13:24:33 +0000 Subject: [PATCH] Background Updates: Remove the 7am/7pm background update check. This changeset is a more basic version of [36180], clearing the extra now redundant schedule. As the functionality for this was introduced in 3.9, [28129] has been backported to 3.7/3.8, allowing the API TTL to be respected by those versions. See #27772. Fixes #35323. Built from https://develop.svn.wordpress.org/trunk@36184 git-svn-id: http://core.svn.wordpress.org/branches/3.7@36151 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/update.php | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/wp-includes/update.php b/wp-includes/update.php index de335a04c9..746de70e4a 100644 --- a/wp-includes/update.php +++ b/wp-includes/update.php @@ -146,7 +146,20 @@ function wp_version_check( $extra_stats = array() ) { if ( isset( $body['translations'] ) ) $updates->translations = $body['translations']; - set_site_transient( 'update_core', $updates); + set_site_transient( 'update_core', $updates ); + + if ( ! empty( $body['ttl'] ) ) { + $ttl = (int) $body['ttl']; + if ( $ttl && ( time() + $ttl < wp_next_scheduled( 'wp_version_check' ) ) ) { + // Queue an event to re-run the update check in $ttl seconds. + wp_schedule_single_event( time() + $ttl, 'wp_version_check' ); + } + } + + // Trigger background updates if running non-interactively, and we weren't called from the update handler. + if ( defined( 'DOING_CRON' ) && DOING_CRON && 'wp_maybe_auto_update' != current_filter() ) { + do_action( 'wp_maybe_auto_update' ); + } } /** @@ -197,7 +210,11 @@ function wp_update_plugins( $extra_stats = array() ) { $timeout = HOUR_IN_SECONDS; break; default : - $timeout = 12 * HOUR_IN_SECONDS; + if ( defined( 'DOING_CRON' ) && DOING_CRON ) { + $timeout = 0; + } else { + $timeout = 12 * HOUR_IN_SECONDS; + } } $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked ); @@ -344,7 +361,11 @@ function wp_update_themes( $extra_stats = array() ) { $timeout = HOUR_IN_SECONDS; break; default : - $timeout = 12 * HOUR_IN_SECONDS; + if ( defined( 'DOING_CRON' ) && DOING_CRON ) { + $timeout = 0; + } else { + $timeout = 12 * HOUR_IN_SECONDS; + } } $time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time() - $last_update->last_checked ); @@ -585,19 +606,8 @@ function wp_schedule_update_checks() { if ( !wp_next_scheduled('wp_update_themes') && !defined('WP_INSTALLING') ) wp_schedule_event(time(), 'twicedaily', 'wp_update_themes'); - if ( ! wp_next_scheduled( 'wp_maybe_auto_update' ) && ! defined( 'WP_INSTALLING' ) ) { - // Schedule auto updates for 7 a.m. and 7 p.m. in the timezone of the site. - $next = strtotime( 'today 7am' ); - $now = time(); - // Find the next instance of 7 a.m. or 7 p.m., but skip it if it is within 3 hours from now. - while ( ( $now + 3 * HOUR_IN_SECONDS ) > $next ) { - $next += 12 * HOUR_IN_SECONDS; - } - $next = $next - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS; - // Add a random number of minutes, so we don't have all sites trying to update exactly on the hour - $next = $next + rand( 0, 59 ) * MINUTE_IN_SECONDS; - wp_schedule_event( $next, 'twicedaily', 'wp_maybe_auto_update' ); - } + if ( ( wp_next_scheduled( 'wp_maybe_auto_update' ) > ( time() + HOUR_IN_SECONDS ) ) && ! defined('WP_INSTALLING') ) + wp_clear_scheduled_hook( 'wp_maybe_auto_update' ); } if ( ( ! is_main_site() && ! is_network_admin() ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) )