Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r41289 r42343  
    1414function get_preferred_from_update_core() {
    1515        $updates = get_core_updates();
    16         if ( ! is_array( $updates ) )
    17                 return false;
    18         if ( empty( $updates ) )
     16        if ( ! is_array( $updates ) ) {
     17                return false;
     18        }
     19        if ( empty( $updates ) ) {
    1920                return (object) array( 'response' => 'latest' );
     21        }
    2022        return $updates[0];
    2123}
    … …  
    2527 *
    2628 * @param array $options Set $options['dismissed'] to true to show dismissed upgrades too,
    27  *                           set $options['available'] to false to skip not-dismissed updates.
     29 *                       set $options['available'] to false to skip not-dismissed updates.
    2830 * @return array|false Array of the update objects on success, false on failure.
    2931 */
    3032function get_core_updates( $options = array() ) {
    31         $options = array_merge( array( 'available' => true, 'dismissed' => false ), $options );
     33        $options   = array_merge(
     34                array(
     35                        'available' => true,
     36                        'dismissed' => false,
     37                ), $options
     38        );
    3239        $dismissed = get_site_option( 'dismissed_update_core' );
    3340
    34         if ( ! is_array( $dismissed ) )
     41        if ( ! is_array( $dismissed ) ) {
    3542                $dismissed = array();
     43        }
    3644
    3745        $from_api = get_site_transient( 'update_core' );
    3846
    39         if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) )
    40                 return false;
     47        if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
     48                return false;
     49        }
    4150
    4251        $updates = $from_api->updates;
    43         $result = array();
     52        $result  = array();
    4453        foreach ( $updates as $update ) {
    45                 if ( $update->response == 'autoupdate' )
     54                if ( $update->response == 'autoupdate' ) {
    4655                        continue;
     56                }
    4757
    4858                if ( array_key_exists( $update->current . '|' . $update->locale, $dismissed ) ) {
    4959                        if ( $options['dismissed'] ) {
    5060                                $update->dismissed = true;
    51                                 $result[] = $update;
     61                                $result[]          = $update;
    5262                        }
    5363                } else {
    5464                        if ( $options['available'] ) {
    5565                                $update->dismissed = false;
    56                                 $result[] = $update;
     66                                $result[]          = $update;
    5767                        }
    5868                }
    … …  
    7282function find_core_auto_update() {
    7383        $updates = get_site_transient( 'update_core' );
    74         if ( ! $updates || empty( $updates->updates ) )
    75                 return false;
     84        if ( ! $updates || empty( $updates->updates ) ) {
     85                return false;
     86        }
    7687
    7788        include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
    7889
    7990        $auto_update = false;
    80         $upgrader = new WP_Automatic_Updater;
     91        $upgrader    = new WP_Automatic_Updater;
    8192        foreach ( $updates->updates as $update ) {
    82                 if ( 'autoupdate' != $update->response )
     93                if ( 'autoupdate' != $update->response ) {
    8394                        continue;
    84 
    85                 if ( ! $upgrader->should_update( 'core', $update, ABSPATH ) )
     95                }
     96
     97                if ( ! $upgrader->should_update( 'core', $update, ABSPATH ) ) {
    8698                        continue;
    87 
    88                 if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) )
     99                }
     100
     101                if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) ) {
    89102                        $auto_update = $update;
     103                }
    90104        }
    91105        return $auto_update;
    … …  
    104118        $url = $http_url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( compact( 'version', 'locale' ), null, '&' );
    105119
    106         if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
     120        if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
    107121                $url = set_url_scheme( $url, 'https' );
     122        }
    108123
    109124        $options = array(
    … …  
    124139        }
    125140
    126         if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
    127                 return false;
     141        if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
     142                return false;
     143        }
    128144
    129145        $body = trim( wp_remote_retrieve_body( $response ) );
    130146        $body = json_decode( $body, true );
    131147
    132         if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) )
    133                 return false;
     148        if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) ) {
     149                return false;
     150        }
    134151
    135152        return $body['checksums'];
    … …  
    137154
    138155/**
    139  *
    140156 * @param object $update
    141157 * @return bool
    … …  
    148164
    149165/**
    150  *
    151166 * @param string $version
    152167 * @param string $locale
    … …  
    155170function undismiss_core_update( $version, $locale ) {
    156171        $dismissed = get_site_option( 'dismissed_update_core' );
    157         $key = $version . '|' . $locale;
    158 
    159         if ( ! isset( $dismissed[$key] ) )
    160                 return false;
    161 
    162         unset( $dismissed[$key] );
     172        $key       = $version . '|' . $locale;
     173
     174        if ( ! isset( $dismissed[ $key ] ) ) {
     175                return false;
     176        }
     177
     178        unset( $dismissed[ $key ] );
    163179        return update_site_option( 'dismissed_update_core', $dismissed );
    164180}
    165181
    166182/**
    167  *
    168183 * @param string $version
    169184 * @param string $locale
    … …  
    173188        $from_api = get_site_transient( 'update_core' );
    174189
    175         if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) )
    176                 return false;
     190        if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
     191                return false;
     192        }
    177193
    178194        $updates = $from_api->updates;
    179195        foreach ( $updates as $update ) {
    180                 if ( $update->current == $version && $update->locale == $locale )
     196                if ( $update->current == $version && $update->locale == $locale ) {
    181197                        return $update;
     198                }
    182199        }
    183200        return false;
    … …  
    185202
    186203/**
    187  *
    188204 * @param string $msg
    189205 * @return string
    190206 */
    191207function core_update_footer( $msg = '' ) {
    192         if ( !current_user_can('update_core') )
     208        if ( ! current_user_can( 'update_core' ) ) {
    193209                return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
     210        }
    194211
    195212        $cur = get_preferred_from_update_core();
    196         if ( ! is_object( $cur ) )
     213        if ( ! is_object( $cur ) ) {
    197214                $cur = new stdClass;
    198 
    199         if ( ! isset( $cur->current ) )
     215        }
     216
     217        if ( ! isset( $cur->current ) ) {
    200218                $cur->current = '';
    201 
    202         if ( ! isset( $cur->url ) )
     219        }
     220
     221        if ( ! isset( $cur->url ) ) {
    203222                $cur->url = '';
    204 
    205         if ( ! isset( $cur->response ) )
     223        }
     224
     225        if ( ! isset( $cur->response ) ) {
    206226                $cur->response = '';
     227        }
    207228
    208229        switch ( $cur->response ) {
    209         case 'development' :
    210                 /* translators: 1: WordPress version number, 2: WordPress updates admin screen URL */
    211                 return sprintf( __( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ), get_bloginfo( 'version', 'display' ), network_admin_url( 'update-core.php' ) );
    212 
    213         case 'upgrade' :
    214                 return '<strong><a href="' . network_admin_url( 'update-core.php' ) . '">' . sprintf( __( 'Get Version %s' ), $cur->current ) . '</a></strong>';
    215 
    216         case 'latest' :
    217         default :
    218                 return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
    219         }
    220 }
    221 
    222 /**
    223  *
     230                case 'development':
     231                        /* translators: 1: WordPress version number, 2: WordPress updates admin screen URL */
     232                        return sprintf( __( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ), get_bloginfo( 'version', 'display' ), network_admin_url( 'update-core.php' ) );
     233
     234                case 'upgrade':
     235                        return '<strong><a href="' . network_admin_url( 'update-core.php' ) . '">' . sprintf( __( 'Get Version %s' ), $cur->current ) . '</a></strong>';
     236
     237                case 'latest':
     238                default:
     239                        return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
     240        }
     241}
     242
     243/**
    224244 * @global string $pagenow
    225245 * @return false|void
    226246 */
    227247function update_nag() {
    228         if ( is_multisite() && !current_user_can('update_core') )
    229                 return false;
     248        if ( is_multisite() && ! current_user_can( 'update_core' ) ) {
     249                return false;
     250        }
    230251
    231252        global $pagenow;
    232253
    233         if ( 'update-core.php' == $pagenow )
     254        if ( 'update-core.php' == $pagenow ) {
    234255                return;
     256        }
    235257
    236258        $cur = get_preferred_from_update_core();
    237259
    238         if ( ! isset( $cur->response ) || $cur->response != 'upgrade' )
    239                 return false;
     260        if ( ! isset( $cur->response ) || $cur->response != 'upgrade' ) {
     261                return false;
     262        }
    240263
    241264        if ( current_user_can( 'update_core' ) ) {
    … …  
    276299        $msg = '';
    277300
    278         if ( current_user_can('update_core') ) {
     301        if ( current_user_can( 'update_core' ) ) {
    279302                $cur = get_preferred_from_update_core();
    280303
    281                 if ( isset( $cur->response ) && $cur->response == 'upgrade' )
     304                if ( isset( $cur->response ) && $cur->response == 'upgrade' ) {
    282305                        $msg .= '<a href="' . network_admin_url( 'update-core.php' ) . '" class="button" aria-describedby="wp-version">' . sprintf( __( 'Update to %s' ), $cur->current ? $cur->current : __( 'Latest' ) ) . '</a> ';
     306                }
    283307        }
    284308
    … …  
    308332 */
    309333function get_plugin_updates() {
    310         $all_plugins = get_plugins();
     334        $all_plugins     = get_plugins();
    311335        $upgrade_plugins = array();
    312         $current = get_site_transient( 'update_plugins' );
    313         foreach ( (array)$all_plugins as $plugin_file => $plugin_data) {
     336        $current         = get_site_transient( 'update_plugins' );
     337        foreach ( (array) $all_plugins as $plugin_file => $plugin_data ) {
    314338                if ( isset( $current->response[ $plugin_file ] ) ) {
    315                         $upgrade_plugins[ $plugin_file ] = (object) $plugin_data;
     339                        $upgrade_plugins[ $plugin_file ]         = (object) $plugin_data;
    316340                        $upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ];
    317341                }
    … …  
    325349 */
    326350function wp_plugin_update_rows() {
    327         if ( !current_user_can('update_plugins' ) )
     351        if ( ! current_user_can( 'update_plugins' ) ) {
    328352                return;
     353        }
    329354
    330355        $plugins = get_site_transient( 'update_plugins' );
    331         if ( isset($plugins->response) && is_array($plugins->response) ) {
     356        if ( isset( $plugins->response ) && is_array( $plugins->response ) ) {
    332357                $plugins = array_keys( $plugins->response );
    333358                foreach ( $plugins as $plugin_file ) {
    … …  
    353378
    354379        $plugins_allowedtags = array(
    355                 'a'       => array( 'href' => array(), 'title' => array() ),
     380                'a'       => array(
     381                        'href'  => array(),
     382                        'title' => array(),
     383                ),
    356384                'abbr'    => array( 'title' => array() ),
    357385                'acronym' => array( 'title' => array() ),
    … …  
    361389        );
    362390
    363         $plugin_name   = wp_kses( $plugin_data['Name'], $plugins_allowedtags );
    364         $details_url   = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $response->slug . '&section=changelog&TB_iframe=true&width=600&height=800' );
     391        $plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags );
     392        $details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $response->slug . '&section=changelog&TB_iframe=true&width=600&height=800' );
    365393
    366394        /** @var WP_Plugins_List_Table $wp_list_table */
    … …  
    378406                if ( ! current_user_can( 'update_plugins' ) ) {
    379407                        /* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number */
    380                         printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
     408                        printf(
     409                                __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
    381410                                $plugin_name,
    382411                                esc_url( $details_url ),
    383                                 sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
     412                                sprintf(
     413                                        'class="thickbox open-plugin-details-modal" aria-label="%s"',
    384414                                        /* translators: 1: plugin name, 2: version number */
    385415                                        esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
    … …  
    389419                } elseif ( empty( $response->package ) ) {
    390420                        /* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number */
    391                         printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this plugin.</em>' ),
     421                        printf(
     422                                __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this plugin.</em>' ),
    392423                                $plugin_name,
    393424                                esc_url( $details_url ),
    394                                 sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
     425                                sprintf(
     426                                        'class="thickbox open-plugin-details-modal" aria-label="%s"',
    395427                                        /* translators: 1: plugin name, 2: version number */
    396428                                        esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
    … …  
    400432                } else {
    401433                        /* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */
    402                         printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ),
     434                        printf(
     435                                __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ),
    403436                                $plugin_name,
    404437                                esc_url( $details_url ),
    405                                 sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
     438                                sprintf(
     439                                        'class="thickbox open-plugin-details-modal" aria-label="%s"',
    406440                                        /* translators: 1: plugin name, 2: version number */
    407441                                        esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
    … …  
    409443                                $response->new_version,
    410444                                wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $file, 'upgrade-plugin_' . $file ),
    411                                 sprintf( 'class="update-link" aria-label="%s"',
     445                                sprintf(
     446                                        'class="update-link" aria-label="%s"',
    412447                                        /* translators: %s: plugin name */
    413448                                        esc_attr( sprintf( __( 'Update %s now' ), $plugin_name ) )
    … …  
    458493
    459494/**
    460  *
    461495 * @return array
    462496 */
    463497function get_theme_updates() {
    464         $current = get_site_transient('update_themes');
    465 
    466         if ( ! isset( $current->response ) )
     498        $current = get_site_transient( 'update_themes' );
     499
     500        if ( ! isset( $current->response ) ) {
    467501                return array();
     502        }
    468503
    469504        $update_themes = array();
    470505        foreach ( $current->response as $stylesheet => $data ) {
    471                 $update_themes[ $stylesheet ] = wp_get_theme( $stylesheet );
     506                $update_themes[ $stylesheet ]         = wp_get_theme( $stylesheet );
    472507                $update_themes[ $stylesheet ]->update = $data;
    473508        }
    … …  
    480515 */
    481516function wp_theme_update_rows() {
    482         if ( !current_user_can('update_themes' ) )
     517        if ( ! current_user_can( 'update_themes' ) ) {
    483518                return;
     519        }
    484520
    485521        $themes = get_site_transient( 'update_themes' );
    486         if ( isset($themes->response) && is_array($themes->response) ) {
     522        if ( isset( $themes->response ) && is_array( $themes->response ) ) {
    487523                $themes = array_keys( $themes->response );
    488524
    … …  
    509545        $response = $current->response[ $theme_key ];
    510546
    511         $details_url = add_query_arg( array(
    512                 'TB_iframe' => 'true',
    513                 'width'     => 1024,
    514                 'height'    => 800,
    515         ), $current->response[ $theme_key ]['url'] );
     547        $details_url = add_query_arg(
     548                array(
     549                        'TB_iframe' => 'true',
     550                        'width'     => 1024,
     551                        'height'    => 800,
     552                ), $current->response[ $theme_key ]['url']
     553        );
    516554
    517555        /** @var WP_MS_Themes_List_Table $wp_list_table */
    … …  
    523561        if ( ! current_user_can( 'update_themes' ) ) {
    524562                /* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number */
    525                 printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.'),
     563                printf(
     564                        __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
    526565                        $theme['Name'],
    527566                        esc_url( $details_url ),
    528                         sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
     567                        sprintf(
     568                                'class="thickbox open-plugin-details-modal" aria-label="%s"',
    529569                                /* translators: 1: theme name, 2: version number */
    530570                                esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
    … …  
    534574        } elseif ( empty( $response['package'] ) ) {
    535575                /* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number */
    536                 printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ),
     576                printf(
     577                        __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ),
    537578                        $theme['Name'],
    538579                        esc_url( $details_url ),
    539                         sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
     580                        sprintf(
     581                                'class="thickbox open-plugin-details-modal" aria-label="%s"',
    540582                                /* translators: 1: theme name, 2: version number */
    541583                                esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
    … …  
    545587        } else {
    546588                /* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */
    547                 printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ),
     589                printf(
     590                        __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ),
    548591                        $theme['Name'],
    549592                        esc_url( $details_url ),
    550                         sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
     593                        sprintf(
     594                                'class="thickbox open-plugin-details-modal" aria-label="%s"',
    551595                                /* translators: 1: theme name, 2: version number */
    552596                                esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
    … …  
    554598                        $response['new_version'],
    555599                        wp_nonce_url( self_admin_url( 'update.php?action=upgrade-theme&theme=' ) . $theme_key, 'upgrade-theme_' . $theme_key ),
    556                         sprintf( 'class="update-link" aria-label="%s"',
     600                        sprintf(
     601                                'class="update-link" aria-label="%s"',
    557602                                /* translators: %s: theme name */
    558603                                esc_attr( sprintf( __( 'Update %s now' ), $theme['Name'] ) )
    … …  
    585630
    586631/**
    587  *
    588632 * @global int $upgrading
    589633 * @return false|void
    … …  
    606650                 */
    607651                $comparison = ! empty( $failed['critical'] ) ? '>=' : '>';
    608                 if ( version_compare( $failed['attempted'], $wp_version, $comparison ) )
     652                if ( version_compare( $failed['attempted'], $wp_version, $comparison ) ) {
    609653                        $nag = true;
    610         }
    611 
    612         if ( ! $nag )
    613                 return false;
    614 
    615         if ( current_user_can('update_core') )
    616                 $msg = sprintf( __('An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.'), 'update-core.php' );
    617         else
    618                 $msg = __('An automated WordPress update has failed to complete! Please notify the site administrator.');
     654                }
     655        }
     656
     657        if ( ! $nag ) {
     658                return false;
     659        }
     660
     661        if ( current_user_can( 'update_core' ) ) {
     662                $msg = sprintf( __( 'An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.' ), 'update-core.php' );
     663        } else {
     664                $msg = __( 'An automated WordPress update has failed to complete! Please notify the site administrator.' );
     665        }
    619666
    620667        echo "<div class='update-nag'>$msg</div>";
Note: See TracChangeset for help on using the changeset viewer.