WordPress.org

Make WordPress Core

Ticket #32444: 32444.6.diff

File 32444.6.diff, 8.1 KB (added by wonderboymusic, 6 years ago)
  • src/wp-includes/update.php

     
    1414 * isn't installing.
    1515 *
    1616 * @since 2.3.0
    17  * @uses $wp_version Used to check against the newest WordPress version.
     17 * @global string $wp_version Used to check against the newest WordPress version.
     18 * @global wpdb   $wpdb
     19 * @global string $wp_local_package
    1820 *
    1921 * @param array $extra_stats Extra statistics to report to the WordPress.org API.
    20  * @param bool $force_check Whether to bypass the transient cache and force a fresh update check. Defaults to false, true if $extra_stats is set.
    21  * @return null|false Returns null if update is unsupported. Returns false if check is too soon.
     22 * @param bool  $force_check Whether to bypass the transient cache and force a fresh update check. Defaults to false, true if $extra_stats is set.
    2223 */
    2324function wp_version_check( $extra_stats = array(), $force_check = false ) {
    24         if ( defined('WP_INSTALLING') )
     25        if ( defined( 'WP_INSTALLING' ) ) {
    2526                return;
     27        }
    2628
    27         global $wpdb, $wp_local_package;
    28         include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
     29        global $wp_version, $wpdb, $wp_local_package;
     30        // include an unmodified $wp_version
     31        include( ABSPATH . WPINC . '/version.php' );
    2932        $php_version = phpversion();
    3033
    3134        $current = get_site_transient( 'update_core' );
     
    4750        // Wait 60 seconds between multiple version check requests
    4851        $timeout = 60;
    4952        $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );
    50         if ( ! $force_check && $time_not_changed )
    51                 return false;
     53        if ( ! $force_check && $time_not_changed ) {
     54                return;
     55        }
    5256
    53         $locale = get_locale();
    5457        /**
    5558         * Filter the locale requested for WordPress core translations.
    5659         *
     
    5861         *
    5962         * @param string $locale Current locale.
    6063         */
    61         $locale = apply_filters( 'core_version_check_locale', $locale );
     64        $locale = apply_filters( 'core_version_check_locale', get_locale() );
    6265
    6366        // Update last_checked for current to prevent multiple blocking requests if request hangs
    6467        $current->last_checked = time();
     
    120123                $response = wp_remote_post( $http_url, $options );
    121124        }
    122125
    123         if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
    124                 return false;
     126        if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
     127                return;
     128        }
    125129
    126130        $body = trim( wp_remote_retrieve_body( $response ) );
    127131        $body = json_decode( $body, true );
    128132
    129         if ( ! is_array( $body ) || ! isset( $body['offers'] ) )
    130                 return false;
     133        if ( ! is_array( $body ) || ! isset( $body['offers'] ) ) {
     134                return;
     135        }
    131136
    132137        $offers = $body['offers'];
    133138
     
    177182 * api.wordpress.org. Will only check if WordPress isn't installing.
    178183 *
    179184 * @since 2.3.0
    180  * @uses $wp_version Used to notify the WordPress version.
     185 * @global string $wp_version Used to notify the WordPress version.
    181186 *
    182187 * @param array $extra_stats Extra statistics to report to the WordPress.org API.
    183  * @return false|null Returns null if update is unsupported. Returns false if check is too soon.
    184188 */
    185189function wp_update_plugins( $extra_stats = array() ) {
    186         include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
     190        if ( defined( 'WP_INSTALLING' ) ) {
     191                return;
     192        }
    187193
    188         if ( defined('WP_INSTALLING') )
    189                 return false;
     194        global $wp_version;
     195        // include an unmodified $wp_version
     196        include( ABSPATH . WPINC . '/version.php' );
    190197
    191198        // If running blog-side, bail unless we've not checked in the last 12 hours
    192199        if ( !function_exists( 'get_plugins' ) )
     
    244251                }
    245252
    246253                // Bail if we've checked recently and if nothing has changed
    247                 if ( ! $plugin_changed )
    248                         return false;
     254                if ( ! $plugin_changed ) {
     255                        return;
     256                }
    249257        }
    250258
    251259        // Update last_checked for current to prevent multiple blocking requests if request hangs
     
    254262
    255263        $to_send = compact( 'plugins', 'active' );
    256264
    257         $locales = array( get_locale() );
    258265        /**
    259266         * Filter the locales requested for plugin translations.
    260267         *
     
    262269         *
    263270         * @param array $locales Plugin locale. Default is current locale of the site.
    264271         */
    265         $locales = apply_filters( 'plugins_update_check_locales', $locales );
     272        $locales = apply_filters( 'plugins_update_check_locales', array( get_locale() ) );
    266273
    267274        if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
    268275                $timeout = 30;
     
    296303                $raw_response = wp_remote_post( $http_url, $options );
    297304        }
    298305
    299         if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )
    300                 return false;
     306        if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
     307                return;
     308        }
    301309
    302310        $response = json_decode( wp_remote_retrieve_body( $raw_response ), true );
    303311        foreach ( $response['plugins'] as &$plugin ) {
     
    334342 * @uses $wp_version Used to notify the WordPress version.
    335343 *
    336344 * @param array $extra_stats Extra statistics to report to the WordPress.org API.
    337  * @return false|null Returns null if update is unsupported. Returns false if check is too soon.
    338345 */
    339346function wp_update_themes( $extra_stats = array() ) {
    340         include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
     347        if ( defined( 'WP_INSTALLING' ) ) {
     348                return;
     349        }
     350        global $wp_version;
     351        // include an unmodified $wp_version
     352        include( ABSPATH . WPINC . '/version.php' );
    341353
    342         if ( defined( 'WP_INSTALLING' ) )
    343                 return false;
    344 
    345354        $installed_themes = wp_get_themes();
    346355        $translations = wp_get_installed_translations( 'themes' );
    347356
     
    407416                }
    408417
    409418                // Bail if we've checked recently and if nothing has changed
    410                 if ( ! $theme_changed )
    411                         return false;
     419                if ( ! $theme_changed ) {
     420                        return;
     421                }
    412422        }
    413423
    414424        // Update last_checked for current to prevent multiple blocking requests if request hangs
     
    417427
    418428        $request['themes'] = $themes;
    419429
    420         $locales = array( get_locale() );
    421430        /**
    422431         * Filter the locales requested for theme translations.
    423432         *
     
    425434         *
    426435         * @param array $locales Theme locale. Default is current locale of the site.
    427436         */
    428         $locales = apply_filters( 'themes_update_check_locales', $locales );
     437        $locales = apply_filters( 'themes_update_check_locales', array( get_locale() ) );
    429438
    430439        if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
    431440                $timeout = 30;
     
    458467                $raw_response = wp_remote_post( $http_url, $options );
    459468        }
    460469
    461         if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )
    462                 return false;
     470        if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
     471                return;
     472        }
    463473
    464474        $new_update = new stdClass;
    465475        $new_update->last_checked = time();
     
    492502 * Retrieves a list of all language updates available.
    493503 *
    494504 * @since 3.7.0
     505 *
     506 * @return array
    495507 */
    496508function wp_get_translation_updates() {
    497509        $updates = array();
    498510        $transients = array( 'update_core' => 'core', 'update_plugins' => 'plugin', 'update_themes' => 'theme' );
    499511        foreach ( $transients as $transient => $type ) {
    500 
    501512                $transient = get_site_transient( $transient );
    502513                if ( empty( $transient->translations ) )
    503514                        continue;
     
    506517                        $updates[] = (object) $translation;
    507518                }
    508519        }
    509 
    510520        return $updates;
    511521}
    512522
     
    571581        return apply_filters( 'wp_get_update_data', $update_data, $titles );
    572582}
    573583
     584/**
     585 * @global string $wp_version
     586 */
    574587function _maybe_update_core() {
     588        global $wp_version;
    575589        include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
    576590
    577591        $current = get_site_transient( 'update_core' );
    578592
    579         if ( isset( $current->last_checked ) &&
     593        if ( isset( $current->last_checked, $current->version_checked ) &&
    580594                12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) &&
    581                 isset( $current->version_checked ) &&
    582                 $current->version_checked == $wp_version )
     595                $current->version_checked == $wp_version ) {
    583596                return;
    584 
     597        }
    585598        wp_version_check();
    586599}
    587600/**
     
    614627        $current = get_site_transient( 'update_themes' );
    615628        if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) )
    616629                return;
    617 
    618630        wp_update_themes();
    619631}
    620632