Make WordPress Core


Ignore:
Timestamp:
05/28/2015 03:28:10 PM (10 years ago)
Author:
wonderboymusic
Message:

Add missing doc blocks to update.php:

  • wp_version_check(), wp_update_plugins(), and wp_update_themes() do not return meaningful responses, and their responses are never handled by core. As such, they shouldn't alternately return void or false. "Returning" in those functions is just "bailing"
  • In the same functions, version.php doesn't need to load if WP_INSTALLING is defined - the function will immediately bail, the values will never be read, and the globals won't be reset. I have unified the approach in all 3 functions.
  • When returning filtered $locale, there is no need to set the variable twice.
  • In _maybe_update_core(), isset() can take multiple values to bail before the call to time(), if necessary. This is a micro-optimization to prevent PHP from hitting the OS unnecessarily.

See #32444.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/update.php

    r31825 r32635  
    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         return;
    26 
    27     global $wpdb, $wp_local_package;
    28     include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
     25    if ( defined( 'WP_INSTALLING' ) ) {
     26        return;
     27    }
     28
     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
     
    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;
    52 
    53     $locale = get_locale();
     53    if ( ! $force_check && $time_not_changed ) {
     54        return;
     55    }
     56
    5457    /**
    5558     * Filter the locale requested for WordPress core translations.
     
    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
     
    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'];
     
    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
    187 
    188     if ( defined('WP_INSTALLING') )
    189         return false;
     190    if ( defined( 'WP_INSTALLING' ) ) {
     191        return;
     192    }
     193
     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
     
    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
     
    255263    $to_send = compact( 'plugins', 'active' );
    256264
    257     $locales = array( get_locale() );
    258265    /**
    259266     * Filter the locales requested for plugin translations.
     
    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 ) {
     
    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 );
     
    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
    341 
    342     if ( defined( 'WP_INSTALLING' ) )
    343         return false;
     347    if ( defined( 'WP_INSTALLING' ) ) {
     348        return;
     349    }
     350    global $wp_version;
     351    // include an unmodified $wp_version
     352    include( ABSPATH . WPINC . '/version.php' );
    344353
    345354    $installed_themes = wp_get_themes();
     
    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
     
    418428    $request['themes'] = $themes;
    419429
    420     $locales = array( get_locale() );
    421430    /**
    422431     * Filter the locales requested for theme translations.
     
    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 ) {
     
    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;
     
    493503 *
    494504 * @since 3.7.0
     505 *
     506 * @return array
    495507 */
    496508function wp_get_translation_updates() {
     
    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 ) )
     
    507518        }
    508519    }
    509 
    510520    return $updates;
    511521}
     
    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 )
    583         return;
    584 
     595        $current->version_checked == $wp_version ) {
     596        return;
     597    }
    585598    wp_version_check();
    586599}
     
    615628    if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) )
    616629        return;
    617 
    618630    wp_update_themes();
    619631}
Note: See TracChangeset for help on using the changeset viewer.