Make WordPress Core

Ticket #27772: 27772.2.diff

File 27772.2.diff, 4.3 KB (added by dd32, 11 years ago)
  • src/wp-includes/update.php

     
    141141                        else
    142142                                $offer[ $offer_key ] = esc_html( $value );
    143143                }
    144144                $offer = (object) array_intersect_key( $offer, array_fill_keys( array( 'response', 'download', 'locale',
    145145                        'packages', 'current', 'version', 'php_version', 'mysql_version', 'new_bundled', 'partial_version', 'notify_email' ), '' ) );
    146146        }
    147147
    148148        $updates = new stdClass();
    149149        $updates->updates = $offers;
    150150        $updates->last_checked = time();
    151151        $updates->version_checked = $wp_version;
    152152
    153153        if ( isset( $body['translations'] ) )
    154154                $updates->translations = $body['translations'];
    155155
    156         set_site_transient( 'update_core',  $updates);
     156        set_site_transient( 'update_core', $updates );
     157
     158// Testing only, causes an update cron task to be run every 90seconds
     159$body['ttl'] = 90;
     160
     161        if ( !empty( $body['ttl'] ) ) {
     162                $ttl = (int) $body['ttl'];
     163                if ( $ttl && ( time() + $ttl < wp_next_scheduled( 'wp_version_check' ) ) ) {
     164                        // Queue an event to re-run the update check in $ttl seconds
     165                        wp_schedule_single_event( time() + $ttl, 'wp_version_check' );
     166                }
     167        }
     168
     169        // Trigger a Background Updates check if running non-interactively, and we weren't called from the update handler
     170        if ( defined( 'DOING_CRON' ) && DOING_CRON && ! doing_action( 'wp_maybe_auto_update' ) ) {
     171                do_action( 'wp_maybe_auto_update' );
     172        }
    157173}
    158174
    159175/**
    160176 * Check plugin versions against the latest versions hosted on WordPress.org.
    161177 *
    162178 * The WordPress version, PHP version, and Locale is sent along with a list of
    163179 * all plugins installed. Checks against the WordPress server at
    164180 * api.wordpress.org. Will only check if WordPress isn't installing.
    165181 *
    166182 * @since 2.3.0
    167183 * @uses $wp_version Used to notify the WordPress version.
    168184 *
    169185 * @param array $extra_stats Extra statistics to report to the WordPress.org API.
    170186 * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
    171187 */
     
    191207        $new_option->last_checked = time();
    192208
    193209        // Check for update on a different schedule, depending on the page.
    194210        switch ( current_filter() ) {
    195211                case 'upgrader_process_complete' :
    196212                        $timeout = 0;
    197213                        break;
    198214                case 'load-update-core.php' :
    199215                        $timeout = MINUTE_IN_SECONDS;
    200216                        break;
    201217                case 'load-plugins.php' :
    202218                case 'load-update.php' :
    203219                        $timeout = HOUR_IN_SECONDS;
    204220                        break;
    205221                default :
    206                         $timeout = 12 * HOUR_IN_SECONDS;
     222                        if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
     223                                $timeout = 0;
     224                        } else {
     225                                $timeout = 12 * HOUR_IN_SECONDS;
     226                        }
    207227        }
    208228
    209229        $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );
    210230
    211231        if ( $time_not_changed && ! $extra_stats ) {
    212232                $plugin_changed = false;
    213233                foreach ( $plugins as $file => $p ) {
    214234                        $new_option->checked[ $file ] = $p['Version'];
    215235
    216236                        if ( !isset( $current->checked[ $file ] ) || strval($current->checked[ $file ]) !== strval($p['Version']) )
    217237                                $plugin_changed = true;
    218238                }
    219239
    220240                if ( isset ( $current->response ) && is_array( $current->response ) ) {
    221241                        foreach ( $current->response as $plugin_file => $update_details ) {
     
    337357        }
    338358
    339359        // Check for update on a different schedule, depending on the page.
    340360        switch ( current_filter() ) {
    341361                case 'upgrader_process_complete' :
    342362                        $timeout = 0;
    343363                        break;
    344364                case 'load-update-core.php' :
    345365                        $timeout = MINUTE_IN_SECONDS;
    346366                        break;
    347367                case 'load-themes.php' :
    348368                case 'load-update.php' :
    349369                        $timeout = HOUR_IN_SECONDS;
    350370                        break;
    351371                default :
    352                         $timeout = 12 * HOUR_IN_SECONDS;
     372                        if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
     373                                $timeout = 0;
     374                        } else {
     375                                $timeout = 12 * HOUR_IN_SECONDS;
     376                        }
    353377        }
    354378
    355379        $time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time() - $last_update->last_checked );
    356380
    357381        if ( $time_not_changed && ! $extra_stats ) {
    358382                $theme_changed = false;
    359383                foreach ( $checked as $slug => $v ) {
    360384                        if ( !isset( $last_update->checked[ $slug ] ) || strval($last_update->checked[ $slug ]) !== strval($v) )
    361385                                $theme_changed = true;
    362386                }
    363387
    364388                if ( isset ( $last_update->response ) && is_array( $last_update->response ) ) {
    365389                        foreach ( $last_update->response as $slug => $update_details ) {
    366390                                if ( ! isset($checked[ $slug ]) ) {
    367391                                        $theme_changed = true;