Make WordPress Core

Changeset 40575


Ignore:
Timestamp:
05/06/2017 02:29:01 PM (9 years ago)
Author:
swissspidy
Message:

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

This replaces DOING_CRON checks via the constant.

Props tfrommen.
Fixes #39591.

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-plugin-upgrader.php

    r39211 r40575  
    407407
    408408                // When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it
    409                 if ( defined( 'DOING_CRON' ) && DOING_CRON )
     409                if ( wp_doing_cron() )
    410410                        return $return;
    411411
  • trunk/src/wp-admin/includes/file.php

    r39656 r40575  
    664664         * Require we have enough space to unzip the file and copy its contents, with a 10% buffer.
    665665         */
    666         if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
     666        if ( wp_doing_cron() ) {
    667667                $available_space = @disk_free_space( WP_CONTENT_DIR );
    668668                if ( $available_space && ( $uncompressed_size * 2.1 ) > $available_space )
     
    770770         * Require we have enough space to unzip the file and copy its contents, with a 10% buffer.
    771771         */
    772         if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
     772        if ( wp_doing_cron() ) {
    773773                $available_space = @disk_free_space( WP_CONTENT_DIR );
    774774                if ( $available_space && ( $uncompressed_size * 2.1 ) > $available_space )
  • trunk/src/wp-admin/includes/update.php

    r39325 r40575  
    108108
    109109        $options = array(
    110                 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ),
     110                'timeout' => wp_doing_cron() ? 30 : 3,
    111111        );
    112112
  • trunk/src/wp-includes/load.php

    r40394 r40575  
    10611061
    10621062/**
     1063 * Determines whether the current request is a WordPress cron request.
     1064 *
     1065 * @since 4.8.0
     1066 *
     1067 * @return bool True if it's a WordPress cron request, false otherwise.
     1068 */
     1069function wp_doing_cron() {
     1070        /**
     1071         * Filters whether the current request is a WordPress cron request.
     1072         *
     1073         * @since 4.8.0
     1074         *
     1075         * @param bool $wp_doing_cron Whether the current request is a WordPress cron request.
     1076         */
     1077        return apply_filters( 'wp_doing_cron', defined( 'DOING_CRON' ) && DOING_CRON );
     1078}
     1079
     1080/**
    10631081 * Check whether variable is a WordPress Error.
    10641082 *
  • trunk/src/wp-includes/update.php

    r39326 r40575  
    109109                $url = set_url_scheme( $url, 'https' );
    110110
     111        $doing_cron = wp_doing_cron();
     112
    111113        $options = array(
    112                 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ),
     114                'timeout' => $doing_cron ? 30 : 3,
    113115                'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
    114116                'headers' => array(
     
    178180
    179181        // Trigger background updates if running non-interactively, and we weren't called from the update handler.
    180         if ( defined( 'DOING_CRON' ) && DOING_CRON && ! doing_action( 'wp_maybe_auto_update' ) ) {
     182        if ( $doing_cron && ! doing_action( 'wp_maybe_auto_update' ) ) {
    181183                do_action( 'wp_maybe_auto_update' );
    182184        }
     
    217219        $new_option = new stdClass;
    218220        $new_option->last_checked = time();
     221
     222        $doing_cron = wp_doing_cron();
    219223
    220224        // Check for update on a different schedule, depending on the page.
     
    231235                        break;
    232236                default :
    233                         if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
     237                        if ( $doing_cron ) {
    234238                                $timeout = 0;
    235239                        } else {
     
    283287        $locales = array_unique( $locales );
    284288
    285         if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
     289        if ( $doing_cron ) {
    286290                $timeout = 30;
    287291        } else {
     
    400404                );
    401405        }
     406
     407        $doing_cron = wp_doing_cron();
    402408
    403409        // Check for update on a different schedule, depending on the page.
     
    414420                        break;
    415421                default :
    416                         if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
    417                                 $timeout = 0;
    418                         } else {
    419                                 $timeout = 12 * HOUR_IN_SECONDS;
    420                         }
     422                        $timeout = $doing_cron ? 0 : 12 * HOUR_IN_SECONDS;
    421423        }
    422424
     
    464466        $locales = array_unique( $locales );
    465467
    466         if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
     468        if ( $doing_cron ) {
    467469                $timeout = 30;
    468470        } else {
Note: See TracChangeset for help on using the changeset viewer.