diff --git a/wp-admin/includes/class-plugin-upgrader.php b/wp-admin/includes/class-plugin-upgrader.php index 1327d28c11..a2924c6ca5 100644 --- a/wp-admin/includes/class-plugin-upgrader.php +++ b/wp-admin/includes/class-plugin-upgrader.php @@ -406,7 +406,7 @@ class Plugin_Upgrader extends WP_Upgrader { return $return; // When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it - if ( defined( 'DOING_CRON' ) && DOING_CRON ) + if ( wp_doing_cron() ) return $return; $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : ''; diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 4a5d24a1f9..1f32c9728d 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -663,7 +663,7 @@ function _unzip_file_ziparchive($file, $to, $needed_dirs = array() ) { * A disk that has zero free bytes has bigger problems. * Require we have enough space to unzip the file and copy its contents, with a 10% buffer. */ - if ( defined( 'DOING_CRON' ) && DOING_CRON ) { + if ( wp_doing_cron() ) { $available_space = @disk_free_space( WP_CONTENT_DIR ); if ( $available_space && ( $uncompressed_size * 2.1 ) > $available_space ) return new WP_Error( 'disk_full_unzip_file', __( 'Could not copy files. You may have run out of disk space.' ), compact( 'uncompressed_size', 'available_space' ) ); @@ -769,7 +769,7 @@ function _unzip_file_pclzip($file, $to, $needed_dirs = array()) { * A disk that has zero free bytes has bigger problems. * Require we have enough space to unzip the file and copy its contents, with a 10% buffer. */ - if ( defined( 'DOING_CRON' ) && DOING_CRON ) { + if ( wp_doing_cron() ) { $available_space = @disk_free_space( WP_CONTENT_DIR ); if ( $available_space && ( $uncompressed_size * 2.1 ) > $available_space ) return new WP_Error( 'disk_full_unzip_file', __( 'Could not copy files. You may have run out of disk space.' ), compact( 'uncompressed_size', 'available_space' ) ); diff --git a/wp-admin/includes/update.php b/wp-admin/includes/update.php index e7a8b5e755..9ff810d1a8 100644 --- a/wp-admin/includes/update.php +++ b/wp-admin/includes/update.php @@ -107,7 +107,7 @@ function get_core_checksums( $version, $locale ) { $url = set_url_scheme( $url, 'https' ); $options = array( - 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ), + 'timeout' => wp_doing_cron() ? 30 : 3, ); $response = wp_remote_get( $url, $options ); diff --git a/wp-includes/load.php b/wp-includes/load.php index a8f730ec9c..2b375b3727 100644 --- a/wp-includes/load.php +++ b/wp-includes/load.php @@ -1059,6 +1059,24 @@ function wp_doing_ajax() { return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ); } +/** + * Determines whether the current request is a WordPress cron request. + * + * @since 4.8.0 + * + * @return bool True if it's a WordPress cron request, false otherwise. + */ +function wp_doing_cron() { + /** + * Filters whether the current request is a WordPress cron request. + * + * @since 4.8.0 + * + * @param bool $wp_doing_cron Whether the current request is a WordPress cron request. + */ + return apply_filters( 'wp_doing_cron', defined( 'DOING_CRON' ) && DOING_CRON ); +} + /** * Check whether variable is a WordPress Error. * diff --git a/wp-includes/update.php b/wp-includes/update.php index f0b999a4cc..f25e644d62 100644 --- a/wp-includes/update.php +++ b/wp-includes/update.php @@ -108,8 +108,10 @@ function wp_version_check( $extra_stats = array(), $force_check = false ) { if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) $url = set_url_scheme( $url, 'https' ); + $doing_cron = wp_doing_cron(); + $options = array( - 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ), + 'timeout' => $doing_cron ? 30 : 3, 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), 'headers' => array( 'wp_install' => $wp_install, @@ -177,7 +179,7 @@ function wp_version_check( $extra_stats = array(), $force_check = false ) { } // Trigger background updates if running non-interactively, and we weren't called from the update handler. - if ( defined( 'DOING_CRON' ) && DOING_CRON && ! doing_action( 'wp_maybe_auto_update' ) ) { + if ( $doing_cron && ! doing_action( 'wp_maybe_auto_update' ) ) { do_action( 'wp_maybe_auto_update' ); } } @@ -217,6 +219,8 @@ function wp_update_plugins( $extra_stats = array() ) { $new_option = new stdClass; $new_option->last_checked = time(); + $doing_cron = wp_doing_cron(); + // Check for update on a different schedule, depending on the page. switch ( current_filter() ) { case 'upgrader_process_complete' : @@ -230,7 +234,7 @@ function wp_update_plugins( $extra_stats = array() ) { $timeout = HOUR_IN_SECONDS; break; default : - if ( defined( 'DOING_CRON' ) && DOING_CRON ) { + if ( $doing_cron ) { $timeout = 0; } else { $timeout = 12 * HOUR_IN_SECONDS; @@ -282,7 +286,7 @@ function wp_update_plugins( $extra_stats = array() ) { $locales = apply_filters( 'plugins_update_check_locales', $locales ); $locales = array_unique( $locales ); - if ( defined( 'DOING_CRON' ) && DOING_CRON ) { + if ( $doing_cron ) { $timeout = 30; } else { // Three seconds, plus one extra second for every 10 plugins @@ -400,6 +404,8 @@ function wp_update_themes( $extra_stats = array() ) { ); } + $doing_cron = wp_doing_cron(); + // Check for update on a different schedule, depending on the page. switch ( current_filter() ) { case 'upgrader_process_complete' : @@ -413,11 +419,7 @@ function wp_update_themes( $extra_stats = array() ) { $timeout = HOUR_IN_SECONDS; break; default : - if ( defined( 'DOING_CRON' ) && DOING_CRON ) { - $timeout = 0; - } else { - $timeout = 12 * HOUR_IN_SECONDS; - } + $timeout = $doing_cron ? 0 : 12 * HOUR_IN_SECONDS; } $time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time() - $last_update->last_checked ); @@ -463,7 +465,7 @@ function wp_update_themes( $extra_stats = array() ) { $locales = apply_filters( 'themes_update_check_locales', $locales ); $locales = array_unique( $locales ); - if ( defined( 'DOING_CRON' ) && DOING_CRON ) { + if ( $doing_cron ) { $timeout = 30; } else { // Three seconds, plus one extra second for every 10 themes diff --git a/wp-includes/version.php b/wp-includes/version.php index 51c19eda73..81cf72bb70 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.8-alpha-40574'; +$wp_version = '4.8-alpha-40575'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.