Make WordPress Core

Changeset 47778


Ignore:
Timestamp:
05/09/2020 12:50:43 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Fix WPCS issues in wp-includes/update.php.

Props mukesh27.
Fixes #50130.

File:
1 edited

Legend:

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

    r47550 r47778  
    2323 */
    2424function wp_version_check( $extra_stats = array(), $force_check = false ) {
     25    global $wpdb, $wp_local_package;
     26
    2527    if ( wp_installing() ) {
    2628        return;
    2729    }
    2830
    29     global $wpdb, $wp_local_package;
    3031    // Include an unmodified $wp_version.
    3132    require ABSPATH . WPINC . '/version.php';
     
    3637
    3738    // Invalidate the transient when $wp_version changes.
    38     if ( is_object( $current ) && $wp_version != $current->version_checked ) {
     39    if ( is_object( $current ) && $wp_version !== $current->version_checked ) {
    3940        $current = false;
    4041    }
     
    5354    $timeout          = MINUTE_IN_SECONDS;
    5455    $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );
     56
    5557    if ( ! $force_check && $time_not_changed ) {
    5658        return;
     
    136138    $http_url = $url;
    137139    $ssl      = wp_http_supports( array( 'ssl' ) );
     140
    138141    if ( $ssl ) {
    139142        $url = set_url_scheme( $url, 'https' );
     
    153156
    154157    $response = wp_remote_post( $url, $options );
     158
    155159    if ( $ssl && is_wp_error( $response ) ) {
    156160        trigger_error(
     
    165169    }
    166170
    167     if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
     171    if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
    168172        return;
    169173    }
     
    180184    foreach ( $offers as &$offer ) {
    181185        foreach ( $offer as $offer_key => $value ) {
    182             if ( 'packages' == $offer_key ) {
     186            if ( 'packages' === $offer_key ) {
    183187                $offer['packages'] = (object) array_intersect_key(
    184188                    array_map( 'esc_url', $offer['packages'] ),
    185189                    array_fill_keys( array( 'full', 'no_content', 'new_bundled', 'partial', 'rollback' ), '' )
    186190                );
    187             } elseif ( 'download' == $offer_key ) {
     191            } elseif ( 'download' === $offer_key ) {
    188192                $offer['download'] = esc_url( $value );
    189193            } else {
     
    227231    if ( ! empty( $body['ttl'] ) ) {
    228232        $ttl = (int) $body['ttl'];
     233
    229234        if ( $ttl && ( time() + $ttl < wp_next_scheduled( 'wp_version_check' ) ) ) {
    230235            // Queue an event to re-run the update check in $ttl seconds.
     
    274279    $active  = get_option( 'active_plugins', array() );
    275280    $current = get_site_transient( 'update_plugins' );
     281
    276282    if ( ! is_object( $current ) ) {
    277283        $current = new stdClass;
     
    307313    if ( $time_not_changed && ! $extra_stats ) {
    308314        $plugin_changed = false;
     315
    309316        foreach ( $plugins as $file => $p ) {
    310317            $new_option->checked[ $file ] = $p['Version'];
     
    374381    $http_url = $url;
    375382    $ssl      = wp_http_supports( array( 'ssl' ) );
     383
    376384    if ( $ssl ) {
    377385        $url = set_url_scheme( $url, 'https' );
     
    379387
    380388    $raw_response = wp_remote_post( $url, $options );
     389
    381390    if ( $ssl && is_wp_error( $raw_response ) ) {
    382391        trigger_error(
     
    391400    }
    392401
    393     if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
     402    if ( is_wp_error( $raw_response ) || 200 !== wp_remote_retrieve_response_code( $raw_response ) ) {
    394403        return;
    395404    }
    396405
    397406    $response = json_decode( wp_remote_retrieve_body( $raw_response ), true );
     407
    398408    foreach ( $response['plugins'] as &$plugin ) {
    399409        $plugin = (object) $plugin;
     410
    400411        if ( isset( $plugin->compatibility ) ) {
    401412            $plugin->compatibility = (object) $plugin->compatibility;
     413
    402414            foreach ( $plugin->compatibility as &$data ) {
    403415                $data = (object) $data;
     
    405417        }
    406418    }
     419
    407420    unset( $plugin, $data );
     421
    408422    foreach ( $response['no_update'] as &$plugin ) {
    409423        $plugin = (object) $plugin;
    410424    }
     425
    411426    unset( $plugin );
    412427
     
    449464
    450465    $last_update = get_site_transient( 'update_themes' );
     466
    451467    if ( ! is_object( $last_update ) ) {
    452468        $last_update = new stdClass;
     
    500516    if ( $time_not_changed && ! $extra_stats ) {
    501517        $theme_changed = false;
     518
    502519        foreach ( $checked as $slug => $v ) {
    503520            if ( ! isset( $last_update->checked[ $slug ] ) || strval( $last_update->checked[ $slug ] ) !== strval( $v ) ) {
     
    564581    $http_url = $url;
    565582    $ssl      = wp_http_supports( array( 'ssl' ) );
     583
    566584    if ( $ssl ) {
    567585        $url = set_url_scheme( $url, 'https' );
     
    569587
    570588    $raw_response = wp_remote_post( $url, $options );
     589
    571590    if ( $ssl && is_wp_error( $raw_response ) ) {
    572591        trigger_error(
     
    581600    }
    582601
    583     if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
     602    if ( is_wp_error( $raw_response ) || 200 !== wp_remote_retrieve_response_code( $raw_response ) ) {
    584603        return;
    585604    }
     
    626645        'update_themes'  => 'theme',
    627646    );
     647
    628648    foreach ( $transients as $transient => $type ) {
    629649        $transient = get_site_transient( $transient );
     650
    630651        if ( empty( $transient->translations ) ) {
    631652            continue;
     
    636657        }
    637658    }
     659
    638660    return $updates;
    639661}
     
    655677
    656678    $plugins = current_user_can( 'update_plugins' );
     679
    657680    if ( $plugins ) {
    658681        $update_plugins = get_site_transient( 'update_plugins' );
     682
    659683        if ( ! empty( $update_plugins->response ) ) {
    660684            $counts['plugins'] = count( $update_plugins->response );
     
    663687
    664688    $themes = current_user_can( 'update_themes' );
     689
    665690    if ( $themes ) {
    666691        $update_themes = get_site_transient( 'update_themes' );
     692
    667693        if ( ! empty( $update_themes->response ) ) {
    668694            $counts['themes'] = count( $update_themes->response );
     
    671697
    672698    $core = current_user_can( 'update_core' );
     699
    673700    if ( $core && function_exists( 'get_core_updates' ) ) {
    674701        $update_wordpress = get_core_updates( array( 'dismissed' => false ) );
     702
    675703        if ( ! empty( $update_wordpress )
    676704            && ! in_array( $update_wordpress[0]->response, array( 'development', 'latest' ), true )
     
    687715    $counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress'] + $counts['translations'];
    688716    $titles          = array();
     717
    689718    if ( $counts['wordpress'] ) {
    690719        /* translators: %d: Number of available WordPress updates. */
    691720        $titles['wordpress'] = sprintf( __( '%d WordPress Update' ), $counts['wordpress'] );
    692721    }
     722
    693723    if ( $counts['plugins'] ) {
    694724        /* translators: %d: Number of available plugin updates. */
    695725        $titles['plugins'] = sprintf( _n( '%d Plugin Update', '%d Plugin Updates', $counts['plugins'] ), $counts['plugins'] );
    696726    }
     727
    697728    if ( $counts['themes'] ) {
    698729        /* translators: %d: Number of available theme updates. */
    699730        $titles['themes'] = sprintf( _n( '%d Theme Update', '%d Theme Updates', $counts['themes'] ), $counts['themes'] );
    700731    }
     732
    701733    if ( $counts['translations'] ) {
    702734        $titles['translations'] = __( 'Translation Updates' );
     
    738770    $current = get_site_transient( 'update_core' );
    739771
    740     if ( isset( $current->last_checked, $current->version_checked ) &&
    741         12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) &&
    742         $current->version_checked == $wp_version ) {
    743         return;
    744     }
     772    if ( isset( $current->last_checked, $current->version_checked )
     773        && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked )
     774        && $current->version_checked === $wp_version
     775    ) {
     776        return;
     777    }
     778
    745779    wp_version_check();
    746780}
     
    757791function _maybe_update_plugins() {
    758792    $current = get_site_transient( 'update_plugins' );
    759     if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) ) {
    760         return;
    761     }
     793
     794    if ( isset( $current->last_checked )
     795        && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked )
     796    ) {
     797        return;
     798    }
     799
    762800    wp_update_plugins();
    763801}
     
    774812function _maybe_update_themes() {
    775813    $current = get_site_transient( 'update_themes' );
    776     if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) ) {
    777         return;
    778     }
     814
     815    if ( isset( $current->last_checked )
     816        && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked )
     817    ) {
     818        return;
     819    }
     820
    779821    wp_update_themes();
    780822}
     
    810852        delete_site_transient( 'update_plugins' );
    811853    }
     854
    812855    wp_clean_themes_cache();
     856
    813857    delete_site_transient( 'update_core' );
    814858}
Note: See TracChangeset for help on using the changeset viewer.