WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (3 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/update-core.php

    r41755 r42343  
    2020}
    2121
    22 if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_themes' ) && ! current_user_can( 'update_plugins' ) && ! current_user_can( 'update_languages' ) )
     22if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_themes' ) && ! current_user_can( 'update_plugins' ) && ! current_user_can( 'update_languages' ) ) {
    2323    wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
     24}
    2425
    2526/**
    26  *
    2727 * @global string $wp_local_package
    2828 * @global wpdb   $wpdb
     
    3333 */
    3434function list_core_update( $update ) {
    35     global $wp_local_package, $wpdb;
    36     static $first_pass = true;
     35    global $wp_local_package, $wpdb;
     36    static $first_pass = true;
    3737
    3838    $wp_version = get_bloginfo( 'version' );
    3939
    40     if ( 'en_US' == $update->locale && 'en_US' == get_locale() )
    41         $version_string = $update->current;
    42     // If the only available update is a partial builds, it doesn't need a language-specific version string.
    43     elseif ( 'en_US' == $update->locale && $update->packages->partial && $wp_version == $update->partial_version && ( $updates = get_core_updates() ) && 1 == count( $updates ) )
    44         $version_string = $update->current;
    45     else
    46         $version_string = sprintf( "%s&ndash;<strong>%s</strong>", $update->current, $update->locale );
     40    if ( 'en_US' == $update->locale && 'en_US' == get_locale() ) {
     41        $version_string = $update->current;
     42    } // If the only available update is a partial builds, it doesn't need a language-specific version string.
     43    elseif ( 'en_US' == $update->locale && $update->packages->partial && $wp_version == $update->partial_version && ( $updates = get_core_updates() ) && 1 == count( $updates ) ) {
     44        $version_string = $update->current;
     45    } else {
     46        $version_string = sprintf( '%s&ndash;<strong>%s</strong>', $update->current, $update->locale );
     47    }
    4748
    4849    $current = false;
    49     if ( !isset($update->response) || 'latest' == $update->response )
     50    if ( ! isset( $update->response ) || 'latest' == $update->response ) {
    5051        $current = true;
    51     $submit = __('Update Now');
    52     $form_action = 'update-core.php?action=do-core-upgrade';
    53     $php_version    = phpversion();
    54     $mysql_version  = $wpdb->db_version();
    55     $show_buttons = true;
     52    }
     53    $submit        = __( 'Update Now' );
     54    $form_action   = 'update-core.php?action=do-core-upgrade';
     55    $php_version   = phpversion();
     56    $mysql_version = $wpdb->db_version();
     57    $show_buttons  = true;
    5658    if ( 'development' == $update->response ) {
    57         $message = __('You are using a development version of WordPress. You can update to the latest nightly build automatically:');
     59        $message = __( 'You are using a development version of WordPress. You can update to the latest nightly build automatically:' );
    5860    } else {
    5961        if ( $current ) {
    60             $message = sprintf( __( 'If you need to re-install version %s, you can do so here:' ), $version_string );
    61             $submit = __('Re-install Now');
     62            $message     = sprintf( __( 'If you need to re-install version %s, you can do so here:' ), $version_string );
     63            $submit      = __( 'Re-install Now' );
    6264            $form_action = 'update-core.php?action=do-core-reinstall';
    6365        } else {
    64             $php_compat     = version_compare( $php_version, $update->php_version, '>=' );
    65             if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) )
     66            $php_compat = version_compare( $php_version, $update->php_version, '>=' );
     67            if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) {
    6668                $mysql_compat = true;
    67             else
     69            } else {
    6870                $mysql_compat = version_compare( $mysql_version, $update->mysql_version, '>=' );
    69 
    70             if ( !$mysql_compat && !$php_compat )
     71            }
     72
     73            if ( ! $mysql_compat && ! $php_compat ) {
    7174                /* translators: 1: WordPress version number, 2: Minimum required PHP version number, 3: Minimum required MySQL version number, 4: Current PHP version number, 5: Current MySQL version number */
    72                 $message = sprintf( __('You cannot update because <a href="https://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires PHP version %2$s or higher and MySQL version %3$s or higher. You are running PHP version %4$s and MySQL version %5$s.'), $update->current, $update->php_version, $update->mysql_version, $php_version, $mysql_version );
    73             elseif ( !$php_compat )
     75                $message = sprintf( __( 'You cannot update because <a href="https://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires PHP version %2$s or higher and MySQL version %3$s or higher. You are running PHP version %4$s and MySQL version %5$s.' ), $update->current, $update->php_version, $update->mysql_version, $php_version, $mysql_version );
     76            } elseif ( ! $php_compat ) {
    7477                /* translators: 1: WordPress version number, 2: Minimum required PHP version number, 3: Current PHP version number */
    75                 $message = sprintf( __('You cannot update because <a href="https://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires PHP version %2$s or higher. You are running version %3$s.'), $update->current, $update->php_version, $php_version );
    76             elseif ( !$mysql_compat )
     78                $message = sprintf( __( 'You cannot update because <a href="https://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires PHP version %2$s or higher. You are running version %3$s.' ), $update->current, $update->php_version, $php_version );
     79            } elseif ( ! $mysql_compat ) {
    7780                /* translators: 1: WordPress version number, 2: Minimum required MySQL version number, 3: Current MySQL version number */
    78                 $message = sprintf( __('You cannot update because <a href="https://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires MySQL version %2$s or higher. You are running version %3$s.'), $update->current, $update->mysql_version, $mysql_version );
    79             else
    80                 /* translators: 1: WordPress version number, 2: WordPress version number including locale if necessary */
    81                 $message =  sprintf(__('You can update to <a href="https://codex.wordpress.org/Version_%1$s">WordPress %2$s</a> automatically:'), $update->current, $version_string);
    82             if ( !$mysql_compat || !$php_compat )
     81                $message = sprintf( __( 'You cannot update because <a href="https://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires MySQL version %2$s or higher. You are running version %3$s.' ), $update->current, $update->mysql_version, $mysql_version );
     82            } else {              /* translators: 1: WordPress version number, 2: WordPress version number including locale if necessary */
     83                $message = sprintf( __( 'You can update to <a href="https://codex.wordpress.org/Version_%1$s">WordPress %2$s</a> automatically:' ), $update->current, $version_string );
     84            }
     85            if ( ! $mysql_compat || ! $php_compat ) {
    8386                $show_buttons = false;
     87            }
    8488        }
    8589    }
     
    8993    echo '</p>';
    9094    echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
    91     wp_nonce_field('upgrade-core');
     95    wp_nonce_field( 'upgrade-core' );
    9296    echo '<p>';
    93     echo '<input name="version" value="'. esc_attr($update->current) .'" type="hidden"/>';
    94     echo '<input name="locale" value="'. esc_attr($update->locale) .'" type="hidden"/>';
     97    echo '<input name="version" value="' . esc_attr( $update->current ) . '" type="hidden"/>';
     98    echo '<input name="locale" value="' . esc_attr( $update->locale ) . '" type="hidden"/>';
    9599    if ( $show_buttons ) {
    96100        if ( $first_pass ) {
     
    101105        }
    102106    }
    103     if ( 'en_US' != $update->locale )
    104         if ( !isset( $update->dismissed ) || !$update->dismissed )
     107    if ( 'en_US' != $update->locale ) {
     108        if ( ! isset( $update->dismissed ) || ! $update->dismissed ) {
    105109            submit_button( __( 'Hide this update' ), '', 'dismiss', false );
    106         else
     110        } else {
    107111            submit_button( __( 'Bring back this update' ), '', 'undismiss', false );
     112        }
     113    }
    108114    echo '</p>';
    109     if ( 'en_US' != $update->locale && ( !isset($wp_local_package) || $wp_local_package != $update->locale ) )
    110         echo '<p class="hint">'.__('This localized version contains both the translation and various other localization fixes. You can skip upgrading if you want to keep your current translation.').'</p>';
    111     // Partial builds don't need language-specific warnings.
     115    if ( 'en_US' != $update->locale && ( ! isset( $wp_local_package ) || $wp_local_package != $update->locale ) ) {
     116        echo '<p class="hint">' . __( 'This localized version contains both the translation and various other localization fixes. You can skip upgrading if you want to keep your current translation.' ) . '</p>';
     117    } // Partial builds don't need language-specific warnings.
    112118    elseif ( 'en_US' == $update->locale && get_locale() != 'en_US' && ( ! $update->packages->partial && $wp_version == $update->partial_version ) ) {
    113         echo '<p class="hint">'.sprintf( __('You are about to install WordPress %s <strong>in English (US).</strong> There is a chance this update will break your translation. You may prefer to wait for the localized version to be released.'), $update->response != 'development' ? $update->current : '' ).'</p>';
     119        echo '<p class="hint">' . sprintf( __( 'You are about to install WordPress %s <strong>in English (US).</strong> There is a chance this update will break your translation. You may prefer to wait for the localized version to be released.' ), $update->response != 'development' ? $update->current : '' ) . '</p>';
    114120    }
    115121    echo '</form>';
     
    121127 */
    122128function dismissed_updates() {
    123     $dismissed = get_core_updates( array( 'dismissed' => true, 'available' => false ) );
     129    $dismissed = get_core_updates(
     130        array(
     131            'dismissed' => true,
     132            'available' => false,
     133        )
     134    );
    124135    if ( $dismissed ) {
    125136
    126         $show_text = esc_js(__('Show hidden updates'));
    127         $hide_text = esc_js(__('Hide hidden updates'));
     137        $show_text = esc_js( __( 'Show hidden updates' ) );
     138        $hide_text = esc_js( __( 'Hide hidden updates' ) );
    128139    ?>
    129140    <script type="text/javascript">
     
    136147    </script>
    137148    <?php
    138         echo '<p class="hide-if-no-js"><a id="show-dismissed" href="#">'.__('Show hidden updates').'</a></p>';
     149        echo '<p class="hide-if-no-js"><a id="show-dismissed" href="#">' . __( 'Show hidden updates' ) . '</a></p>';
    139150        echo '<ul id="dismissed-updates" class="core-updates dismissed">';
    140         foreach ( (array) $dismissed as $update) {
    141             echo '<li>';
    142             list_core_update( $update );
    143             echo '</li>';
    144         }
     151    foreach ( (array) $dismissed as $update ) {
     152        echo '<li>';
     153        list_core_update( $update );
     154        echo '</li>';
     155    }
    145156        echo '</ul>';
    146157    }
     
    159170
    160171    $wp_version = get_bloginfo( 'version' );
    161     $updates = get_core_updates();
    162 
    163     if ( !isset($updates[0]->response) || 'latest' == $updates[0]->response ) {
     172    $updates    = get_core_updates();
     173
     174    if ( ! isset( $updates[0]->response ) || 'latest' == $updates[0]->response ) {
    164175        echo '<h2>';
    165         _e('You have the latest version of WordPress.');
     176        _e( 'You have the latest version of WordPress.' );
    166177
    167178        if ( wp_http_supports( array( 'ssl' ) ) ) {
    168179            require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    169             $upgrader = new WP_Automatic_Updater;
     180            $upgrader            = new WP_Automatic_Updater;
    170181            $future_minor_update = (object) array(
    171182                'current'       => $wp_version . '.1.next.minor',
     
    174185                'mysql_version' => $required_mysql_version,
    175186            );
    176             $should_auto_update = $upgrader->should_update( 'core', $future_minor_update, ABSPATH );
    177             if ( $should_auto_update )
     187            $should_auto_update  = $upgrader->should_update( 'core', $future_minor_update, ABSPATH );
     188            if ( $should_auto_update ) {
    178189                echo ' ' . __( 'Future security updates will be applied automatically.' );
     190            }
    179191        }
    180192        echo '</h2>';
    181193    } else {
    182194        echo '<div class="notice notice-warning"><p>';
    183         _e('<strong>Important:</strong> before updating, please <a href="https://codex.wordpress.org/WordPress_Backups">back up your database and files</a>. For help with updates, visit the <a href="https://codex.wordpress.org/Updating_WordPress">Updating WordPress</a> Codex page.');
     195        _e( '<strong>Important:</strong> before updating, please <a href="https://codex.wordpress.org/WordPress_Backups">back up your database and files</a>. For help with updates, visit the <a href="https://codex.wordpress.org/Updating_WordPress">Updating WordPress</a> Codex page.' );
    184196        echo '</p></div>';
    185197
     
    211223    } elseif ( ! $updates ) {
    212224        list( $normalized_version ) = explode( '-', $wp_version );
    213         echo '<p>' . sprintf( __( '<a href="%s">Learn more about WordPress %s</a>.' ), esc_url( self_admin_url( 'about.php' ) ), $normalized_version ) . '</p>';
     225        echo '<p>' . sprintf( __( '<a href="%1$s">Learn more about WordPress %2$s</a>.' ), esc_url( self_admin_url( 'about.php' ) ), $normalized_version ) . '</p>';
    214226    }
    215227    dismissed_updates();
     
    217229
    218230function list_plugin_updates() {
    219     $wp_version = get_bloginfo( 'version' );
     231    $wp_version     = get_bloginfo( 'version' );
    220232    $cur_wp_version = preg_replace( '/-.*$/', '', $wp_version );
    221233
    222     require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
     234    require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
    223235    $plugins = get_plugin_updates();
    224236    if ( empty( $plugins ) ) {
     
    230242
    231243    $core_updates = get_core_updates();
    232     if ( !isset($core_updates[0]->response) || 'latest' == $core_updates[0]->response || 'development' == $core_updates[0]->response || version_compare( $core_updates[0]->current, $cur_wp_version, '=') )
     244    if ( ! isset( $core_updates[0]->response ) || 'latest' == $core_updates[0]->response || 'development' == $core_updates[0]->response || version_compare( $core_updates[0]->current, $cur_wp_version, '=' ) ) {
    233245        $core_update_version = false;
    234     else
     246    } else {
    235247        $core_update_version = $core_updates[0]->current;
     248    }
    236249    ?>
    237250<h2><?php _e( 'Plugins' ); ?></h2>
    238251<p><?php _e( 'The following plugins have new versions available. Check the ones you want to update and then click &#8220;Update Plugins&#8221;.' ); ?></p>
    239252<form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-plugins" class="upgrade">
    240 <?php wp_nonce_field('upgrade-core'); ?>
    241 <p><input id="upgrade-plugins" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
     253<?php wp_nonce_field( 'upgrade-core' ); ?>
     254<p><input id="upgrade-plugins" class="button" type="submit" value="<?php esc_attr_e( 'Update Plugins' ); ?>" name="upgrade" /></p>
    242255<table class="widefat updates-table" id="update-plugins-table">
    243256    <thead>
     
    250263    <tbody class="plugins">
    251264<?php
    252     foreach ( (array) $plugins as $plugin_file => $plugin_data ) {
    253         $plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file, (array) $plugin_data, false, true );
    254 
    255         $icon = '<span class="dashicons dashicons-admin-plugins"></span>';
    256         $preferred_icons = array( 'svg', '1x', '2x', 'default' );
    257         foreach ( $preferred_icons as $preferred_icon ) {
    258             if ( ! empty( $plugin_data->update->icons[ $preferred_icon ] ) ) {
    259                 $icon = '<img src="' . esc_url( $plugin_data->update->icons[ $preferred_icon ] ) . '" alt="" />';
    260                 break;
    261             }           
     265foreach ( (array) $plugins as $plugin_file => $plugin_data ) {
     266    $plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file, (array) $plugin_data, false, true );
     267
     268    $icon            = '<span class="dashicons dashicons-admin-plugins"></span>';
     269    $preferred_icons = array( 'svg', '1x', '2x', 'default' );
     270    foreach ( $preferred_icons as $preferred_icon ) {
     271        if ( ! empty( $plugin_data->update->icons[ $preferred_icon ] ) ) {
     272            $icon = '<img src="' . esc_url( $plugin_data->update->icons[ $preferred_icon ] ) . '" alt="" />';
     273            break;
    262274        }
    263 
    264         // Get plugin compat for running version of WordPress.
    265         if ( isset($plugin_data->update->tested) && version_compare($plugin_data->update->tested, $cur_wp_version, '>=') ) {
    266             $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: 100%% (according to its author)'), $cur_wp_version);
    267         } elseif ( isset($plugin_data->update->compatibility->{$cur_wp_version}) ) {
    268             $compat = $plugin_data->update->compatibility->{$cur_wp_version};
    269             $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)'), $cur_wp_version, $compat->percent, $compat->votes, $compat->total_votes);
     275    }
     276
     277    // Get plugin compat for running version of WordPress.
     278    if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $cur_wp_version, '>=' ) ) {
     279        $compat = '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: 100%% (according to its author)' ), $cur_wp_version );
     280    } elseif ( isset( $plugin_data->update->compatibility->{$cur_wp_version} ) ) {
     281        $compat = $plugin_data->update->compatibility->{$cur_wp_version};
     282        $compat = '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)' ), $cur_wp_version, $compat->percent, $compat->votes, $compat->total_votes );
     283    } else {
     284        $compat = '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: Unknown' ), $cur_wp_version );
     285    }
     286    // Get plugin compat for updated version of WordPress.
     287    if ( $core_update_version ) {
     288        if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $core_update_version, '>=' ) ) {
     289            $compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: 100%% (according to its author)' ), $core_update_version );
     290        } elseif ( isset( $plugin_data->update->compatibility->{$core_update_version} ) ) {
     291            $update_compat = $plugin_data->update->compatibility->{$core_update_version};
     292            $compat       .= '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)' ), $core_update_version, $update_compat->percent, $update_compat->votes, $update_compat->total_votes );
    270293        } else {
    271             $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $cur_wp_version);
     294            $compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: Unknown' ), $core_update_version );
    272295        }
    273         // Get plugin compat for updated version of WordPress.
    274         if ( $core_update_version ) {
    275             if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $core_update_version, '>=' ) ) {
    276                 $compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: 100%% (according to its author)' ), $core_update_version );
    277             } elseif ( isset( $plugin_data->update->compatibility->{$core_update_version} ) ) {
    278                 $update_compat = $plugin_data->update->compatibility->{$core_update_version};
    279                 $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)'), $core_update_version, $update_compat->percent, $update_compat->votes, $update_compat->total_votes);
    280             } else {
    281                 $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $core_update_version);
    282             }
    283         }
    284         // Get the upgrade notice for the new plugin version.
    285         if ( isset($plugin_data->update->upgrade_notice) ) {
    286             $upgrade_notice = '<br />' . strip_tags($plugin_data->update->upgrade_notice);
    287         } else {
    288             $upgrade_notice = '';
    289         }
    290 
    291         $details_url = self_admin_url('plugin-install.php?tab=plugin-information&plugin=' . $plugin_data->update->slug . '&section=changelog&TB_iframe=true&width=640&height=662');
    292         $details = sprintf(
    293             '<a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>',
    294             esc_url( $details_url ),
    295             /* translators: 1: plugin name, 2: version number */
    296             esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_data->Name, $plugin_data->update->new_version ) ),
    297             /* translators: %s: plugin version */
    298             sprintf( __( 'View version %s details.' ), $plugin_data->update->new_version )
    299         );
    300 
    301         $checkbox_id = "checkbox_" . md5( $plugin_data->Name );
    302         ?>
    303         <tr>
    304             <td class="check-column">
    305                 <input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $plugin_file ); ?>" />
    306                 <label for="<?php echo $checkbox_id; ?>" class="screen-reader-text"><?php
    307                     /* translators: %s: plugin name */
    308                     printf( __( 'Select %s' ),
    309                         $plugin_data->Name
    310                     );
    311                 ?></label>
     296    }
     297    // Get the upgrade notice for the new plugin version.
     298    if ( isset( $plugin_data->update->upgrade_notice ) ) {
     299        $upgrade_notice = '<br />' . strip_tags( $plugin_data->update->upgrade_notice );
     300    } else {
     301        $upgrade_notice = '';
     302    }
     303
     304    $details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data->update->slug . '&section=changelog&TB_iframe=true&width=640&height=662' );
     305    $details     = sprintf(
     306        '<a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>',
     307        esc_url( $details_url ),
     308        /* translators: 1: plugin name, 2: version number */
     309        esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_data->Name, $plugin_data->update->new_version ) ),
     310        /* translators: %s: plugin version */
     311        sprintf( __( 'View version %s details.' ), $plugin_data->update->new_version )
     312    );
     313
     314    $checkbox_id = 'checkbox_' . md5( $plugin_data->Name );
     315    ?>
     316    <tr>
     317        <td class="check-column">
     318            <input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $plugin_file ); ?>" />
     319            <label for="<?php echo $checkbox_id; ?>" class="screen-reader-text">
     320                                        <?php
     321                                        /* translators: %s: plugin name */
     322                                        printf(
     323                                            __( 'Select %s' ),
     324                                            $plugin_data->Name
     325                                        );
     326                ?>
     327                </label>
    312328            </td>
    313329            <td class="plugin-title"><p>
     
    315331                <strong><?php echo $plugin_data->Name; ?></strong>
    316332                <?php
    317                     /* translators: 1: plugin version, 2: new version */
    318                     printf( __( 'You have version %1$s installed. Update to %2$s.' ),
    319                         $plugin_data->Version,
    320                         $plugin_data->update->new_version
    321                     );
    322                     echo ' ' . $details . $compat . $upgrade_notice;
    323                 ?>
     333                /* translators: 1: plugin version, 2: new version */
     334                printf(
     335                    __( 'You have version %1$s installed. Update to %2$s.' ),
     336                    $plugin_data->Version,
     337                    $plugin_data->update->new_version
     338                );
     339                echo ' ' . $details . $compat . $upgrade_notice;
     340            ?>
    324341            </p></td>
    325342        </tr>
    326343        <?php
    327     }
     344}
    328345?>
    329346    </tbody>
     
    336353    </tfoot>
    337354</table>
    338 <p><input id="upgrade-plugins-2" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
     355<p><input id="upgrade-plugins-2" class="button" type="submit" value="<?php esc_attr_e( 'Update Plugins' ); ?>" name="upgrade" /></p>
    339356</form>
    340357<?php
     
    358375<p><?php printf( __( '<strong>Please Note:</strong> Any customizations you have made to theme files will be lost. Please consider using <a href="%s">child themes</a> for modifications.' ), __( 'https://codex.wordpress.org/Child_Themes' ) ); ?></p>
    359376<form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-themes" class="upgrade">
    360 <?php wp_nonce_field('upgrade-core'); ?>
    361 <p><input id="upgrade-themes" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
     377<?php wp_nonce_field( 'upgrade-core' ); ?>
     378<p><input id="upgrade-themes" class="button" type="submit" value="<?php esc_attr_e( 'Update Themes' ); ?>" name="upgrade" /></p>
    362379<table class="widefat updates-table" id="update-themes-table">
    363380    <thead>
     
    370387    <tbody class="plugins">
    371388<?php
    372     foreach ( $themes as $stylesheet => $theme ) {
    373         $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
    374         ?>
    375         <tr>
    376             <td class="check-column">
    377                 <input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $stylesheet ); ?>" />
    378                 <label for="<?php echo $checkbox_id; ?>" class="screen-reader-text"><?php
    379                     /* translators: %s: theme name */
    380                     printf( __( 'Select %s' ),
    381                         $theme->display( 'Name' )
    382                     );
    383                 ?></label>
     389foreach ( $themes as $stylesheet => $theme ) {
     390    $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
     391    ?>
     392    <tr>
     393        <td class="check-column">
     394            <input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $stylesheet ); ?>" />
     395            <label for="<?php echo $checkbox_id; ?>" class="screen-reader-text">
     396                                        <?php
     397                                        /* translators: %s: theme name */
     398                                        printf(
     399                                            __( 'Select %s' ),
     400                                            $theme->display( 'Name' )
     401                                        );
     402                ?>
     403                </label>
    384404            </td>
    385405            <td class="plugin-title"><p>
     
    387407                <strong><?php echo $theme->display( 'Name' ); ?></strong>
    388408                <?php
    389                     /* translators: 1: theme version, 2: new version */
    390                     printf( __( 'You have version %1$s installed. Update to %2$s.' ),
    391                         $theme->display( 'Version' ),
    392                         $theme->update['new_version']
    393                     );
    394                 ?>
     409                /* translators: 1: theme version, 2: new version */
     410                printf(
     411                    __( 'You have version %1$s installed. Update to %2$s.' ),
     412                    $theme->display( 'Version' ),
     413                    $theme->update['new_version']
     414                );
     415            ?>
    395416            </p></td>
    396417        </tr>
    397418        <?php
    398     }
     419}
    399420?>
    400421    </tbody>
     
    407428    </tfoot>
    408429</table>
    409 <p><input id="upgrade-themes-2" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
     430<p><input id="upgrade-themes-2" class="button" type="submit" value="<?php esc_attr_e( 'Update Themes' ); ?>" name="upgrade" /></p>
    410431</form>
    411432<?php
     
    450471    include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
    451472
    452     if ( $reinstall )
     473    if ( $reinstall ) {
    453474        $url = 'update-core.php?action=do-core-reinstall';
    454     else
     475    } else {
    455476        $url = 'update-core.php?action=do-core-upgrade';
    456     $url = wp_nonce_url($url, 'upgrade-core');
    457 
    458     $version = isset( $_POST['version'] )? $_POST['version'] : false;
    459     $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
    460     $update = find_core_update( $version, $locale );
    461     if ( !$update )
     477    }
     478    $url = wp_nonce_url( $url, 'upgrade-core' );
     479
     480    $version = isset( $_POST['version'] ) ? $_POST['version'] : false;
     481    $locale  = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
     482    $update  = find_core_update( $version, $locale );
     483    if ( ! $update ) {
    462484        return;
     485    }
    463486
    464487    // Allow relaxed file ownership writes for User-initiated upgrades when the API specifies
     
    471494<?php
    472495
    473     if ( false === ( $credentials = request_filesystem_credentials( $url, '', false, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership ) ) ) {
    474         echo '</div>';
    475         return;
    476     }
    477 
    478     if ( ! WP_Filesystem( $credentials, ABSPATH, $allow_relaxed_file_ownership ) ) {
    479         // Failed to connect, Error and request again
    480         request_filesystem_credentials( $url, '', true, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership );
    481         echo '</div>';
    482         return;
    483     }
    484 
    485     if ( $wp_filesystem->errors->get_error_code() ) {
    486         foreach ( $wp_filesystem->errors->get_error_messages() as $message )
    487             show_message($message);
    488         echo '</div>';
    489         return;
    490     }
    491 
    492     if ( $reinstall )
    493         $update->response = 'reinstall';
     496if ( false === ( $credentials = request_filesystem_credentials( $url, '', false, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership ) ) ) {
     497    echo '</div>';
     498    return;
     499}
     500
     501if ( ! WP_Filesystem( $credentials, ABSPATH, $allow_relaxed_file_ownership ) ) {
     502    // Failed to connect, Error and request again
     503    request_filesystem_credentials( $url, '', true, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership );
     504    echo '</div>';
     505    return;
     506}
     507
     508if ( $wp_filesystem->errors->get_error_code() ) {
     509    foreach ( $wp_filesystem->errors->get_error_messages() as $message ) {
     510        show_message( $message );
     511    }
     512    echo '</div>';
     513    return;
     514}
     515
     516if ( $reinstall ) {
     517    $update->response = 'reinstall';
     518}
    494519
    495520    add_filter( 'update_feedback', 'show_message' );
    496521
    497522    $upgrader = new Core_Upgrader();
    498     $result = $upgrader->upgrade( $update, array(
    499         'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership
    500     ) );
    501 
    502     if ( is_wp_error($result) ) {
    503         show_message($result);
    504         if ( 'up_to_date' != $result->get_error_code() && 'locked' != $result->get_error_code() )
    505             show_message( __('Installation Failed') );
    506         echo '</div>';
    507         return;
    508     }
    509 
    510     show_message( __('WordPress updated successfully') );
     523    $result   = $upgrader->upgrade(
     524        $update, array(
     525            'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership,
     526        )
     527    );
     528
     529if ( is_wp_error( $result ) ) {
     530    show_message( $result );
     531    if ( 'up_to_date' != $result->get_error_code() && 'locked' != $result->get_error_code() ) {
     532        show_message( __( 'Installation Failed' ) );
     533    }
     534    echo '</div>';
     535    return;
     536}
     537
     538    show_message( __( 'WordPress updated successfully' ) );
    511539    show_message( '<span class="hide-if-no-js">' . sprintf( __( 'Welcome to WordPress %1$s. You will be redirected to the About WordPress screen. If not, click <a href="%2$s">here</a>.' ), $result, esc_url( self_admin_url( 'about.php?updated' ) ) ) . '</span>' );
    512540    show_message( '<span class="hide-if-js">' . sprintf( __( 'Welcome to WordPress %1$s. <a href="%2$s">Learn more</a>.' ), $result, esc_url( self_admin_url( 'about.php?updated' ) ) ) . '</span>' );
     
    523551 */
    524552function do_dismiss_core_update() {
    525     $version = isset( $_POST['version'] )? $_POST['version'] : false;
    526     $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
    527     $update = find_core_update( $version, $locale );
    528     if ( !$update )
     553    $version = isset( $_POST['version'] ) ? $_POST['version'] : false;
     554    $locale  = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
     555    $update  = find_core_update( $version, $locale );
     556    if ( ! $update ) {
    529557        return;
     558    }
    530559    dismiss_core_update( $update );
    531     wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
     560    wp_redirect( wp_nonce_url( 'update-core.php?action=upgrade-core', 'upgrade-core' ) );
    532561    exit;
    533562}
     
    537566 */
    538567function do_undismiss_core_update() {
    539     $version = isset( $_POST['version'] )? $_POST['version'] : false;
    540     $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
    541     $update = find_core_update( $version, $locale );
    542     if ( !$update )
     568    $version = isset( $_POST['version'] ) ? $_POST['version'] : false;
     569    $locale  = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
     570    $update  = find_core_update( $version, $locale );
     571    if ( ! $update ) {
    543572        return;
     573    }
    544574    undismiss_core_update( $version, $locale );
    545     wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
     575    wp_redirect( wp_nonce_url( 'update-core.php?action=upgrade-core', 'upgrade-core' ) );
    546576    exit;
    547577}
    548578
    549 $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
     579$action = isset( $_GET['action'] ) ? $_GET['action'] : 'upgrade-core';
    550580
    551581$upgrade_error = false;
     
    553583    && ! isset( $_POST['checked'] ) ) {
    554584    $upgrade_error = $action == 'do-theme-upgrade' ? 'themes' : 'plugins';
    555     $action = 'upgrade-core';
    556 }
    557 
    558 $title = __('WordPress Updates');
     585    $action        = 'upgrade-core';
     586}
     587
     588$title       = __( 'WordPress Updates' );
    559589$parent_file = 'index.php';
    560590
     
    562592$updates_overview .= '<p>' . __( 'If an update is available, you&#8127;ll see a notification appear in the Toolbar and navigation menu.' ) . ' ' . __( 'Keeping your site updated is important for security. It also makes the internet a safer place for you and your readers.' ) . '</p>';
    563593
    564 get_current_screen()->add_help_tab( array(
    565     'id'      => 'overview',
    566     'title'   => __( 'Overview' ),
    567     'content' => $updates_overview
    568 ) );
     594get_current_screen()->add_help_tab(
     595    array(
     596        'id'      => 'overview',
     597        'title'   => __( 'Overview' ),
     598        'content' => $updates_overview,
     599    )
     600);
    569601
    570602$updates_howto  = '<p>' . __( '<strong>WordPress</strong> &mdash; Updating your WordPress installation is a simple one-click procedure: just <strong>click on the &#8220;Update Now&#8221; button</strong> when you are notified that a new version is available.' ) . ' ' . __( 'In most cases, WordPress will automatically apply maintenance and security updates in the background for you.' ) . '</p>';
     
    575607}
    576608
    577 get_current_screen()->add_help_tab( array(
    578     'id'      => 'how-to-update',
    579     'title'   => __( 'How to Update' ),
    580     'content' => $updates_howto
    581 ) );
     609get_current_screen()->add_help_tab(
     610    array(
     611        'id'      => 'how-to-update',
     612        'title'   => __( 'How to Update' ),
     613        'content' => $updates_howto,
     614    )
     615);
    582616
    583617get_current_screen()->set_help_sidebar(
    584     '<p><strong>' . __('For more information:') . '</strong></p>' .
     618    '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    585619    '<p>' . __( '<a href="https://codex.wordpress.org/Dashboard_Updates_Screen">Documentation on Updating WordPress</a>' ) . '</p>' .
    586620    '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>'
     
    592626    wp_version_check( array(), $force_check );
    593627
    594     require_once(ABSPATH . 'wp-admin/admin-header.php');
     628    require_once( ABSPATH . 'wp-admin/admin-header.php' );
    595629    ?>
    596630    <div class="wrap">
     
    599633    if ( $upgrade_error ) {
    600634        echo '<div class="error"><p>';
    601         if ( $upgrade_error == 'themes' )
    602             _e('Please select one or more themes to update.');
    603         else
    604             _e('Please select one or more plugins to update.');
     635        if ( $upgrade_error == 'themes' ) {
     636            _e( 'Please select one or more themes to update.' );
     637        } else {
     638            _e( 'Please select one or more plugins to update.' );
     639        }
    605640        echo '</p></div>';
    606641    }
    607642
    608643    $last_update_check = false;
    609     $current = get_site_transient( 'update_core' );
    610 
    611     if ( $current && isset ( $current->last_checked ) ) {
     644    $current           = get_site_transient( 'update_core' );
     645
     646    if ( $current && isset( $current->last_checked ) ) {
    612647        $last_update_check = $current->last_checked + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
    613648    }
     
    616651    /* translators: %1 date, %2 time. */
    617652    printf( __( 'Last checked on %1$s at %2$s.' ), date_i18n( __( 'F j, Y' ), $last_update_check ), date_i18n( __( 'g:i a' ), $last_update_check ) );
    618     echo ' &nbsp; <a class="button" href="' . esc_url( self_admin_url('update-core.php?force-check=1') ) . '">' . __( 'Check Again' ) . '</a>';
     653    echo ' &nbsp; <a class="button" href="' . esc_url( self_admin_url( 'update-core.php?force-check=1' ) ) . '">' . __( 'Check Again' ) . '</a>';
    619654    echo '</p>';
    620655
     
    640675    echo '</div>';
    641676
    642     wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
    643         'totals'  => wp_get_update_data(),
    644     ) );
    645 
    646     include(ABSPATH . 'wp-admin/admin-footer.php');
     677    wp_localize_script(
     678        'updates', '_wpUpdatesItemCounts', array(
     679            'totals' => wp_get_update_data(),
     680        )
     681    );
     682
     683    include( ABSPATH . 'wp-admin/admin-footer.php' );
    647684
    648685} elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
    649686
    650     if ( ! current_user_can( 'update_core' ) )
     687    if ( ! current_user_can( 'update_core' ) ) {
    651688        wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
    652 
    653     check_admin_referer('upgrade-core');
     689    }
     690
     691    check_admin_referer( 'upgrade-core' );
    654692
    655693    // Do the (un)dismiss actions before headers, so that they can redirect.
    656     if ( isset( $_POST['dismiss'] ) )
     694    if ( isset( $_POST['dismiss'] ) ) {
    657695        do_dismiss_core_update();
    658     elseif ( isset( $_POST['undismiss'] ) )
     696    } elseif ( isset( $_POST['undismiss'] ) ) {
    659697        do_undismiss_core_update();
    660 
    661     require_once(ABSPATH . 'wp-admin/admin-header.php');
    662     if ( 'do-core-reinstall' == $action )
     698    }
     699
     700    require_once( ABSPATH . 'wp-admin/admin-header.php' );
     701    if ( 'do-core-reinstall' == $action ) {
    663702        $reinstall = true;
    664     else
     703    } else {
    665704        $reinstall = false;
    666 
    667     if ( isset( $_POST['upgrade'] ) )
    668         do_core_upgrade($reinstall);
    669 
    670     wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
    671         'totals'  => wp_get_update_data(),
    672     ) );
    673 
    674     include(ABSPATH . 'wp-admin/admin-footer.php');
     705    }
     706
     707    if ( isset( $_POST['upgrade'] ) ) {
     708        do_core_upgrade( $reinstall );
     709    }
     710
     711    wp_localize_script(
     712        'updates', '_wpUpdatesItemCounts', array(
     713            'totals' => wp_get_update_data(),
     714        )
     715    );
     716
     717    include( ABSPATH . 'wp-admin/admin-footer.php' );
    675718
    676719} elseif ( 'do-plugin-upgrade' == $action ) {
    677720
    678     if ( ! current_user_can( 'update_plugins' ) )
     721    if ( ! current_user_can( 'update_plugins' ) ) {
    679722        wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
    680 
    681     check_admin_referer('upgrade-core');
     723    }
     724
     725    check_admin_referer( 'upgrade-core' );
    682726
    683727    if ( isset( $_GET['plugins'] ) ) {
     
    686730        $plugins = (array) $_POST['checked'];
    687731    } else {
    688         wp_redirect( admin_url('update-core.php') );
     732        wp_redirect( admin_url( 'update-core.php' ) );
    689733        exit;
    690734    }
    691735
    692     $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
    693     $url = wp_nonce_url($url, 'bulk-update-plugins');
    694 
    695     $title = __('Update Plugins');
    696 
    697     require_once(ABSPATH . 'wp-admin/admin-header.php');
     736    $url = 'update.php?action=update-selected&plugins=' . urlencode( implode( ',', $plugins ) );
     737    $url = wp_nonce_url( $url, 'bulk-update-plugins' );
     738
     739    $title = __( 'Update Plugins' );
     740
     741    require_once( ABSPATH . 'wp-admin/admin-header.php' );
    698742    echo '<div class="wrap">';
    699743    echo '<h1>' . __( 'Update Plugins' ) . '</h1>';
     
    701745    echo '</div>';
    702746
    703     wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
    704         'totals'  => wp_get_update_data(),
    705     ) );
    706 
    707     include(ABSPATH . 'wp-admin/admin-footer.php');
     747    wp_localize_script(
     748        'updates', '_wpUpdatesItemCounts', array(
     749            'totals' => wp_get_update_data(),
     750        )
     751    );
     752
     753    include( ABSPATH . 'wp-admin/admin-footer.php' );
    708754
    709755} elseif ( 'do-theme-upgrade' == $action ) {
    710756
    711     if ( ! current_user_can( 'update_themes' ) )
     757    if ( ! current_user_can( 'update_themes' ) ) {
    712758        wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
    713 
    714     check_admin_referer('upgrade-core');
     759    }
     760
     761    check_admin_referer( 'upgrade-core' );
    715762
    716763    if ( isset( $_GET['themes'] ) ) {
     
    719766        $themes = (array) $_POST['checked'];
    720767    } else {
    721         wp_redirect( admin_url('update-core.php') );
     768        wp_redirect( admin_url( 'update-core.php' ) );
    722769        exit;
    723770    }
    724771
    725     $url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes));
    726     $url = wp_nonce_url($url, 'bulk-update-themes');
    727 
    728     $title = __('Update Themes');
    729 
    730     require_once(ABSPATH . 'wp-admin/admin-header.php');
     772    $url = 'update.php?action=update-selected-themes&themes=' . urlencode( implode( ',', $themes ) );
     773    $url = wp_nonce_url( $url, 'bulk-update-themes' );
     774
     775    $title = __( 'Update Themes' );
     776
     777    require_once( ABSPATH . 'wp-admin/admin-header.php' );
    731778    ?>
    732779    <div class="wrap">
    733780        <h1><?php _e( 'Update Themes' ); ?></h1>
    734         <iframe src="<?php echo $url ?>" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php esc_attr_e( 'Update progress' ); ?>"></iframe>
     781        <iframe src="<?php echo $url; ?>" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php esc_attr_e( 'Update progress' ); ?>"></iframe>
    735782    </div>
    736783    <?php
    737784
    738     wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
    739         'totals'  => wp_get_update_data(),
    740     ) );
    741 
    742     include(ABSPATH . 'wp-admin/admin-footer.php');
     785    wp_localize_script(
     786        'updates', '_wpUpdatesItemCounts', array(
     787            'totals' => wp_get_update_data(),
     788        )
     789    );
     790
     791    include( ABSPATH . 'wp-admin/admin-footer.php' );
    743792
    744793} elseif ( 'do-translation-upgrade' == $action ) {
    745794
    746     if ( ! current_user_can( 'update_languages' ) )
     795    if ( ! current_user_can( 'update_languages' ) ) {
    747796        wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
     797    }
    748798
    749799    check_admin_referer( 'upgrade-translations' );
     
    752802    include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
    753803
    754     $url = 'update-core.php?action=do-translation-upgrade';
    755     $nonce = 'upgrade-translations';
    756     $title = __( 'Update Translations' );
     804    $url     = 'update-core.php?action=do-translation-upgrade';
     805    $nonce   = 'upgrade-translations';
     806    $title   = __( 'Update Translations' );
    757807    $context = WP_LANG_DIR;
    758808
    759809    $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
    760     $result = $upgrader->bulk_upgrade();
    761 
    762     wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
    763         'totals'  => wp_get_update_data(),
    764     ) );
     810    $result   = $upgrader->bulk_upgrade();
     811
     812    wp_localize_script(
     813        'updates', '_wpUpdatesItemCounts', array(
     814            'totals' => wp_get_update_data(),
     815        )
     816    );
    765817
    766818    require_once( ABSPATH . 'wp-admin/admin-footer.php' );
Note: See TracChangeset for help on using the changeset viewer.