Cron API: Add a new wp_doing_cron() helper function.

This replaces `DOING_CRON` checks via the constant.

Props tfrommen.
Fixes #39591.


git-svn-id: https://develop.svn.wordpress.org/trunk@40575 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
swissspidy
2017-05-06 14:29:01 +00:00
parent 9a2188dd56
commit fd211c9a2e
5 changed files with 34 additions and 14 deletions

View File

@@ -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'] : '';

View File

@@ -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' ) );

View File

@@ -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 );