Cron API: Add a new `wp_doing_cron()` helper function.
This replaces `DOING_CRON` checks via the constant. Props tfrommen. Fixes #39591. Built from https://develop.svn.wordpress.org/trunk@40575 git-svn-id: http://core.svn.wordpress.org/trunk@40445 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e1d5fd1c6b
commit
064e62cbea
|
@ -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'] : '';
|
||||
|
|
|
@ -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' ) );
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue