WordPress.org

Make WordPress Core

Ticket #25688: update-core.diff

File update-core.diff, 26.6 KB (added by rmcrober, 6 years ago)
  • update-core.php

     
    1 <?php
    2 /**
    3  * Update Core administration panel.
    4  *
    5  * @package WordPress
    6  * @subpackage Administration
    7  */
    8 
    9 /** WordPress Administration Bootstrap */
    10 require_once( dirname( __FILE__ ) . '/admin.php' );
    11 
    12 wp_enqueue_style( 'plugin-install' );
    13 wp_enqueue_script( 'plugin-install' );
    14 add_thickbox();
    15 
    16 if ( is_multisite() && ! is_network_admin() ) {
    17         wp_redirect( network_admin_url( 'update-core.php' ) );
    18         exit();
    19 }
    20 
    21 if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_themes' ) && ! current_user_can( 'update_plugins' ) )
    22         wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
    23 
    24 function list_core_update( $update ) {
    25         global $wp_local_package, $wpdb, $wp_version;
    26         static $first_pass = true;
    27 
    28         if ( 'en_US' == $update->locale && 'en_US' == get_locale() )
    29                 $version_string = $update->current;
    30         // If the only available update is a partial builds, it doesn't need a language-specific version string.
    31         elseif ( 'en_US' == $update->locale && $update->packages->partial && $wp_version == $update->partial_version && ( $updates = get_core_updates() ) && 1 == count( $updates ) )
    32                 $version_string = $update->current;
    33         else
    34                 $version_string = sprintf( "%s&ndash;<strong>%s</strong>", $update->current, $update->locale );
    35 
    36         $current = false;
    37         if ( !isset($update->response) || 'latest' == $update->response )
    38                 $current = true;
    39         $submit = __('Update Now');
    40         $form_action = 'update-core.php?action=do-core-upgrade';
    41         $php_version    = phpversion();
    42         $mysql_version  = $wpdb->db_version();
    43         $show_buttons = true;
    44         if ( 'development' == $update->response ) {
    45                 $message = __('You are using a development version of WordPress. You can update to the latest nightly build automatically or download the nightly build and install it manually:');
    46                 $download = __('Download nightly build');
    47         } else {
    48                 if ( $current ) {
    49                         $message = sprintf( __( 'If you need to re-install version %s, you can do so here or download the package and re-install manually:' ), $version_string );
    50                         $submit = __('Re-install Now');
    51                         $form_action = 'update-core.php?action=do-core-reinstall';
    52                 } else {
    53                         $php_compat     = version_compare( $php_version, $update->php_version, '>=' );
    54                         if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) )
    55                                 $mysql_compat = true;
    56                         else
    57                                 $mysql_compat = version_compare( $mysql_version, $update->mysql_version, '>=' );
    58 
    59                         if ( !$mysql_compat && !$php_compat )
    60                                 $message = sprintf( __('You cannot update because <a href="http://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 );
    61                         elseif ( !$php_compat )
    62                                 $message = sprintf( __('You cannot update because <a href="http://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 );
    63                         elseif ( !$mysql_compat )
    64                                 $message = sprintf( __('You cannot update because <a href="http://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 );
    65                         else
    66                                 $message =      sprintf(__('You can update to <a href="http://codex.wordpress.org/Version_%1$s">WordPress %2$s</a> automatically or download the package and install it manually:'), $update->current, $version_string);
    67                         if ( !$mysql_compat || !$php_compat )
    68                                 $show_buttons = false;
    69                 }
    70                 $download = sprintf(__('Download %s'), $version_string);
    71         }
    72 
    73         echo '<p>';
    74         echo $message;
    75         echo '</p>';
    76         echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
    77         wp_nonce_field('upgrade-core');
    78         echo '<p>';
    79         echo '<input name="version" value="'. esc_attr($update->current) .'" type="hidden"/>';
    80         echo '<input name="locale" value="'. esc_attr($update->locale) .'" type="hidden"/>';
    81         if ( $show_buttons ) {
    82                 if ( $first_pass ) {
    83                         submit_button( $submit, $current ? 'button' : 'primary regular', 'upgrade', false );
    84                         $first_pass = false;
    85                 } else {
    86                         submit_button( $submit, 'button', 'upgrade', false );
    87                 }
    88                 echo '&nbsp;<a href="' . esc_url( $update->download ) . '" class="button">' . $download . '</a>&nbsp;';
    89         }
    90         if ( 'en_US' != $update->locale )
    91                 if ( !isset( $update->dismissed ) || !$update->dismissed )
    92                         submit_button( __('Hide this update'), 'button', 'dismiss', false );
    93                 else
    94                         submit_button( __('Bring back this update'), 'button', 'undismiss', false );
    95         echo '</p>';
    96         if ( 'en_US' != $update->locale && ( !isset($wp_local_package) || $wp_local_package != $update->locale ) )
    97             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>';
    98         // Partial builds don't need language-specific warnings.
    99         elseif ( 'en_US' == $update->locale && get_locale() != 'en_US' && ( ! $update->packages->partial && $wp_version == $update->partial_version ) ) {
    100             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>';
    101         }
    102         echo '</form>';
    103 
    104 }
    105 
    106 function dismissed_updates() {
    107         $dismissed = get_core_updates( array( 'dismissed' => true, 'available' => false ) );
    108         if ( $dismissed ) {
    109 
    110                 $show_text = esc_js(__('Show hidden updates'));
    111                 $hide_text = esc_js(__('Hide hidden updates'));
    112         ?>
    113         <script type="text/javascript">
    114 
    115                 jQuery(function($) {
    116                         $('dismissed-updates').show();
    117                         $('#show-dismissed').toggle(function(){$(this).text('<?php echo $hide_text; ?>');}, function() {$(this).text('<?php echo $show_text; ?>')});
    118                         $('#show-dismissed').click(function() { $('#dismissed-updates').toggle('slow');});
    119                 });
    120         </script>
    121         <?php
    122                 echo '<p class="hide-if-no-js"><a id="show-dismissed" href="#">'.__('Show hidden updates').'</a></p>';
    123                 echo '<ul id="dismissed-updates" class="core-updates dismissed">';
    124                 foreach( (array) $dismissed as $update) {
    125                         echo '<li>';
    126                         list_core_update( $update );
    127                         echo '</li>';
    128                 }
    129                 echo '</ul>';
    130         }
    131 }
    132 
    133 /**
    134  * Display upgrade WordPress for downloading latest or upgrading automatically form.
    135  *
    136  * @since 2.7
    137  *
    138  * @return null
    139  */
    140 function core_upgrade_preamble() {
    141         global $wp_version, $required_php_version, $required_mysql_version;
    142 
    143         $updates = get_core_updates();
    144 
    145         if ( !isset($updates[0]->response) || 'latest' == $updates[0]->response ) {
    146                 echo '<h3>';
    147                 _e('You have the latest version of WordPress.');
    148 
    149                 if ( wp_http_supports( 'ssl' ) ) {
    150                         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    151                         $upgrader = new WP_Automatic_Updater;
    152                         $future_minor_update = (object) array(
    153                                 'current'       => $wp_version . '.1.next.minor',
    154                                 'version'       => $wp_version . '.1.next.minor',
    155                                 'php_version'   => $required_php_version,
    156                                 'mysql_version' => $required_mysql_version,
    157                         );
    158                         $should_auto_update = $upgrader->should_update( 'core', $future_minor_update, ABSPATH );
    159                         if ( $should_auto_update )
    160                                 echo ' ' . __( 'Future security updates will be applied automatically.' );
    161                 }
    162                 echo '</h3>';
    163         } else {
    164                 echo '<div class="updated inline"><p>';
    165                 _e('<strong>Important:</strong> before updating, please <a href="http://codex.wordpress.org/WordPress_Backups">back up your database and files</a>. For help with updates, visit the <a href="http://codex.wordpress.org/Updating_WordPress">Updating WordPress</a> Codex page.');
    166                 echo '</p></div>';
    167 
    168                 echo '<h3 class="response">';
    169                 _e( 'An updated version of WordPress is available.' );
    170                 echo '</h3>';
    171         }
    172 
    173         if ( isset( $updates[0] ) && $updates[0]->response == 'development' ) {
    174                 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    175                 $upgrader = new WP_Automatic_Updater;
    176                 if ( wp_http_supports( 'ssl' ) && $upgrader->should_update( 'core', $updates[0], ABSPATH ) )
    177                         echo '<div class="updated inline"><p><strong>BETA TESTERS:</strong> This site is set up to install updates of future beta versions automatically.</p></div>';
    178         }
    179 
    180         echo '<ul class="core-updates">';
    181         $alternate = true;
    182         foreach( (array) $updates as $update ) {
    183                 echo '<li>';
    184                 list_core_update( $update );
    185                 echo '</li>';
    186         }
    187         echo '</ul>';
    188         // Don't show the maintenance mode notice when we are only showing a single re-install option.
    189         if ( $updates && ( count( $updates ) > 1 || $updates[0]->response != 'latest' ) ) {
    190                 echo '<p>' . __( 'While your site is being updated, it will be in maintenance mode. As soon as your updates are complete, your site will return to normal.' ) . '</p>';
    191         } elseif ( ! $updates ) {
    192                 list( $normalized_version ) = explode( '-', $wp_version );
    193                 echo '<p>' . sprintf( __( '<a href="%s">Learn more about WordPress %s</a>.' ), esc_url( self_admin_url( 'about.php' ) ), $normalized_version ) . '</p>';
    194         }
    195         dismissed_updates();
    196 }
    197 
    198 function list_plugin_updates() {
    199         global $wp_version;
    200 
    201         $cur_wp_version = preg_replace('/-.*$/', '', $wp_version);
    202 
    203         require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
    204         $plugins = get_plugin_updates();
    205         if ( empty( $plugins ) ) {
    206                 echo '<h3>' . __( 'Plugins' ) . '</h3>';
    207                 echo '<p>' . __( 'Your plugins are all up to date.' ) . '</p>';
    208                 return;
    209         }
    210         $form_action = 'update-core.php?action=do-plugin-upgrade';
    211 
    212         $core_updates = get_core_updates();
    213         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, '=') )
    214                 $core_update_version = false;
    215         else
    216                 $core_update_version = $core_updates[0]->current;
    217         ?>
    218 <h3><?php _e( 'Plugins' ); ?></h3>
    219 <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>
    220 <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-plugins" class="upgrade">
    221 <?php wp_nonce_field('upgrade-core'); ?>
    222 <p><input id="upgrade-plugins" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
    223 <table class="widefat" cellspacing="0" id="update-plugins-table">
    224         <thead>
    225         <tr>
    226                 <th scope="col" class="manage-column check-column"><input type="checkbox" id="plugins-select-all" /></th>
    227                 <th scope="col" class="manage-column"><label for="plugins-select-all"><?php _e('Select All'); ?></label></th>
    228         </tr>
    229         </thead>
    230 
    231         <tfoot>
    232         <tr>
    233                 <th scope="col" class="manage-column check-column"><input type="checkbox" id="plugins-select-all-2" /></th>
    234                 <th scope="col" class="manage-column"><label for="plugins-select-all-2"><?php _e('Select All'); ?></label></th>
    235         </tr>
    236         </tfoot>
    237         <tbody class="plugins">
    238 <?php
    239         foreach ( (array) $plugins as $plugin_file => $plugin_data) {
    240                 $info = plugins_api('plugin_information', array('slug' => $plugin_data->update->slug ));
    241                 // Get plugin compat for running version of WordPress.
    242                 if ( isset($info->tested) && version_compare($info->tested, $cur_wp_version, '>=') ) {
    243                         $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: 100%% (according to its author)'), $cur_wp_version);
    244                 } elseif ( isset($info->compatibility[$cur_wp_version][$plugin_data->update->new_version]) ) {
    245                         $compat = $info->compatibility[$cur_wp_version][$plugin_data->update->new_version];
    246                         $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)'), $cur_wp_version, $compat[0], $compat[2], $compat[1]);
    247                 } else {
    248                         $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $cur_wp_version);
    249                 }
    250                 // Get plugin compat for updated version of WordPress.
    251                 if ( $core_update_version ) {
    252                         if ( isset($info->compatibility[$core_update_version][$plugin_data->update->new_version]) ) {
    253                                 $update_compat = $info->compatibility[$core_update_version][$plugin_data->update->new_version];
    254                                 $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)'), $core_update_version, $update_compat[0], $update_compat[2], $update_compat[1]);
    255                         } else {
    256                                 $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $core_update_version);
    257                         }
    258                 }
    259                 // Get the upgrade notice for the new plugin version.
    260                 if ( isset($plugin_data->update->upgrade_notice) ) {
    261                         $upgrade_notice = '<br />' . strip_tags($plugin_data->update->upgrade_notice);
    262                 } else {
    263                         $upgrade_notice = '';
    264                 }
    265 
    266                 $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');
    267                 $details_text = sprintf(__('View version %1$s details'), $plugin_data->update->new_version);
    268                 $details = sprintf('<a href="%1$s" class="thickbox" title="%2$s">%3$s</a>.', esc_url($details_url), esc_attr($plugin_data->Name), $details_text);
    269 
    270                 echo "
    271         <tr class='active'>
    272                 <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' /></th>
    273                 <td><p><strong>{$plugin_data->Name}</strong><br />" . sprintf(__('You have version %1$s installed. Update to %2$s.'), $plugin_data->Version, $plugin_data->update->new_version) . ' ' . $details . $compat . $upgrade_notice . "</p></td>
    274         </tr>";
    275         }
    276 ?>
    277         </tbody>
    278 </table>
    279 <p><input id="upgrade-plugins-2" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
    280 </form>
    281 <?php
    282 }
    283 
    284 function list_theme_updates() {
    285         $themes = get_theme_updates();
    286         if ( empty( $themes ) ) {
    287                 echo '<h3>' . __( 'Themes' ) . '</h3>';
    288                 echo '<p>' . __( 'Your themes are all up to date.' ) . '</p>';
    289                 return;
    290         }
    291 
    292         $form_action = 'update-core.php?action=do-theme-upgrade';
    293 
    294 ?>
    295 <h3><?php _e( 'Themes' ); ?></h3>
    296 <p><?php _e( 'The following themes have new versions available. Check the ones you want to update and then click &#8220;Update Themes&#8221;.' ); ?></p>
    297 <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.' ), __( 'http://codex.wordpress.org/Child_Themes' ) ); ?></p>
    298 <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-themes" class="upgrade">
    299 <?php wp_nonce_field('upgrade-core'); ?>
    300 <p><input id="upgrade-themes" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
    301 <table class="widefat" cellspacing="0" id="update-themes-table">
    302         <thead>
    303         <tr>
    304                 <th scope="col" class="manage-column check-column"><input type="checkbox" id="themes-select-all" /></th>
    305                 <th scope="col" class="manage-column"><label for="themes-select-all"><?php _e('Select All'); ?></label></th>
    306         </tr>
    307         </thead>
    308 
    309         <tfoot>
    310         <tr>
    311                 <th scope="col" class="manage-column check-column"><input type="checkbox" id="themes-select-all-2" /></th>
    312                 <th scope="col" class="manage-column"><label for="themes-select-all-2"><?php _e('Select All'); ?></label></th>
    313         </tr>
    314         </tfoot>
    315         <tbody class="plugins">
    316 <?php
    317         foreach ( $themes as $stylesheet => $theme ) {
    318                 echo "
    319         <tr class='active'>
    320                 <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . esc_attr( $stylesheet ) . "' /></th>
    321                 <td class='plugin-title'><img src='" . esc_url( $theme->get_screenshot() ) . "' width='85' height='64' style='float:left; padding: 0 5px 5px' /><strong>" . $theme->display('Name') . '</strong> ' . sprintf( __( 'You have version %1$s installed. Update to %2$s.' ), $theme->display('Version'), $theme->update['new_version'] ) . "</td>
    322         </tr>";
    323         }
    324 ?>
    325         </tbody>
    326 </table>
    327 <p><input id="upgrade-themes-2" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
    328 </form>
    329 <?php
    330 }
    331 
    332 function list_translation_updates() {
    333         $updates = wp_get_translation_updates();
    334         if ( ! $updates ) {
    335                 if ( 'en_US' != get_locale() ) {
    336                         echo '<h3>' . __( 'Translations' ) . '</h3>';
    337                         echo '<p>' . __( 'Your translations are all up to date.' ) . '</p>';
    338                 }
    339                 return;
    340         }
    341 
    342         $form_action = 'update-core.php?action=do-translation-upgrade';
    343         ?>
    344         <h3><?php _e( 'Translations' ); ?></h3>
    345         <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-themes" class="upgrade">
    346                 <p><?php _e( 'Some of your translations are out of date.' ); ?></p>
    347                 <?php wp_nonce_field('upgrade-translations'); ?>
    348                 <p><input class="button" type="submit" value="<?php esc_attr_e( 'Update Translations' ); ?>" name="upgrade" /></p>
    349         </form>
    350         <?php
    351 }
    352 
    353 /**
    354  * Upgrade WordPress core display.
    355  *
    356  * @since 2.7
    357  *
    358  * @return null
    359  */
    360 function do_core_upgrade( $reinstall = false ) {
    361         global $wp_filesystem;
    362 
    363         include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    364 
    365         if ( $reinstall )
    366                 $url = 'update-core.php?action=do-core-reinstall';
    367         else
    368                 $url = 'update-core.php?action=do-core-upgrade';
    369         $url = wp_nonce_url($url, 'upgrade-core');
    370 
    371         $version = isset( $_POST['version'] )? $_POST['version'] : false;
    372         $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
    373         $update = find_core_update( $version, $locale );
    374         if ( !$update )
    375                 return;
    376 
    377 ?>
    378         <div class="wrap">
    379         <?php screen_icon('tools'); ?>
    380         <h2><?php _e('Update WordPress'); ?></h2>
    381 <?php
    382 
    383         if ( false === ( $credentials = request_filesystem_credentials( $url, '', false, ABSPATH ) ) ) {
    384                 echo '</div>';
    385                 return;
    386         }
    387 
    388         if ( ! WP_Filesystem( $credentials, ABSPATH ) ) {
    389                 // Failed to connect, Error and request again
    390                 request_filesystem_credentials( $url, '', true, ABSPATH );
    391                 echo '</div>';
    392                 return;
    393         }
    394 
    395         if ( $wp_filesystem->errors->get_error_code() ) {
    396                 foreach ( $wp_filesystem->errors->get_error_messages() as $message )
    397                         show_message($message);
    398                 echo '</div>';
    399                 return;
    400         }
    401 
    402         if ( $reinstall )
    403                 $update->response = 'reinstall';
    404 
    405         add_filter( 'update_feedback', 'show_message' );
    406 
    407         $upgrader = new Core_Upgrader();
    408         $result = $upgrader->upgrade( $update );
    409 
    410         if ( is_wp_error($result) ) {
    411                 show_message($result);
    412                 if ('up_to_date' != $result->get_error_code() )
    413                         show_message( __('Installation Failed') );
    414                 echo '</div>';
    415                 return;
    416         }
    417 
    418         show_message( __('WordPress updated successfully') );
    419         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>' );
    420         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>' );
    421         ?>
    422         </div>
    423         <script type="text/javascript">
    424         window.location = '<?php echo self_admin_url( 'about.php?updated' ); ?>';
    425         </script>
    426         <?php
    427 }
    428 
    429 function do_dismiss_core_update() {
    430         $version = isset( $_POST['version'] )? $_POST['version'] : false;
    431         $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
    432         $update = find_core_update( $version, $locale );
    433         if ( !$update )
    434                 return;
    435         dismiss_core_update( $update );
    436         wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
    437         exit;
    438 }
    439 
    440 function do_undismiss_core_update() {
    441         $version = isset( $_POST['version'] )? $_POST['version'] : false;
    442         $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
    443         $update = find_core_update( $version, $locale );
    444         if ( !$update )
    445                 return;
    446         undismiss_core_update( $version, $locale );
    447         wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
    448         exit;
    449 }
    450 
    451 function no_update_actions($actions) {
    452         return '';
    453 }
    454 
    455 $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
    456 
    457 $upgrade_error = false;
    458 if ( ( 'do-theme-upgrade' == $action || ( 'do-plugin-upgrade' == $action && ! isset( $_GET['plugins'] ) ) )
    459         && ! isset( $_POST['checked'] ) ) {
    460         $upgrade_error = $action == 'do-theme-upgrade' ? 'themes' : 'plugins';
    461         $action = 'upgrade-core';
    462 }
    463 
    464 $title = __('WordPress Updates');
    465 $parent_file = 'tools.php';
    466 
    467 get_current_screen()->add_help_tab( array(
    468 'id'            => 'overview',
    469 'title'         => __('Overview'),
    470 'content'       =>
    471         '<p>' . __('This screen lets you update to the latest version of WordPress as well as update your themes and plugins from the WordPress.org repository. When updates are available, the number of available updates will appear in a bubble on the left hand menu as a notification.') . '</p>' .
    472         '<p>' . __('It is very important to keep your WordPress installation up to date for security reasons, so when you see a number appear, make sure you take the time to update, which is an easy process.') . '</p>'
    473 ) );
    474 
    475 get_current_screen()->add_help_tab( array(
    476 'id'            => 'how-to-update',
    477 'title'         => __('How to Update'),
    478 'content'       =>
    479         '<p>' . __('Updating your WordPress installation is a simple one-click procedure; just click on the Update button when it says a new version is available.') . '</p>' .
    480         '<p>' . __('To update themes or plugins from this screen, use the checkboxes to make your selection and click on the appropriate Update button. Check the box at the top of the Themes or Plugins section to select all and update them all at once.') . '</p>'
    481 ) );
    482 
    483 get_current_screen()->set_help_sidebar(
    484         '<p><strong>' . __('For more information:') . '</strong></p>' .
    485         '<p>' . __('<a href="http://codex.wordpress.org/Dashboard_Updates_Screen" target="_blank">Documentation on Updating WordPress</a>') . '</p>' .
    486         '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
    487 );
    488 
    489 if ( 'upgrade-core' == $action ) {
    490 
    491         wp_version_check();
    492         require_once(ABSPATH . 'wp-admin/admin-header.php');
    493         ?>
    494         <div class="wrap">
    495         <?php screen_icon('tools'); ?>
    496         <h2><?php _e('WordPress Updates'); ?></h2>
    497         <?php
    498         if ( $upgrade_error ) {
    499                 echo '<div class="error"><p>';
    500                 if ( $upgrade_error == 'themes' )
    501                         _e('Please select one or more themes to update.');
    502                 else
    503                         _e('Please select one or more plugins to update.');
    504                 echo '</p></div>';
    505         }
    506 
    507         echo '<p>';
    508         /* translators: %1 date, %2 time. */
    509         printf( __('Last checked on %1$s at %2$s.'), date_i18n( get_option( 'date_format' ) ), date_i18n( get_option( 'time_format' ) ) );
    510         echo ' &nbsp; <a class="button" href="' . esc_url( self_admin_url('update-core.php') ) . '">' . __( 'Check Again' ) . '</a>';
    511         echo '</p>';
    512 
    513         if ( $core = current_user_can( 'update_core' ) )
    514                 core_upgrade_preamble();
    515         if ( $plugins = current_user_can( 'update_plugins' ) )
    516                 list_plugin_updates();
    517         if ( $themes = current_user_can( 'update_themes' ) )
    518                 list_theme_updates();
    519         if ( $core || $plugins || $themes )
    520                 list_translation_updates();
    521         unset( $core, $plugins, $themes );
    522         do_action('core_upgrade_preamble');
    523         echo '</div>';
    524         include(ABSPATH . 'wp-admin/admin-footer.php');
    525 
    526 } elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
    527 
    528         if ( ! current_user_can( 'update_core' ) )
    529                 wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
    530 
    531         check_admin_referer('upgrade-core');
    532 
    533         // do the (un)dismiss actions before headers,
    534         // so that they can redirect
    535         if ( isset( $_POST['dismiss'] ) )
    536                 do_dismiss_core_update();
    537         elseif ( isset( $_POST['undismiss'] ) )
    538                 do_undismiss_core_update();
    539 
    540         require_once(ABSPATH . 'wp-admin/admin-header.php');
    541         if ( 'do-core-reinstall' == $action )
    542                 $reinstall = true;
    543         else
    544                 $reinstall = false;
    545 
    546         if ( isset( $_POST['upgrade'] ) )
    547                 do_core_upgrade($reinstall);
    548 
    549         include(ABSPATH . 'wp-admin/admin-footer.php');
    550 
    551 } elseif ( 'do-plugin-upgrade' == $action ) {
    552 
    553         if ( ! current_user_can( 'update_plugins' ) )
    554                 wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
    555 
    556         check_admin_referer('upgrade-core');
    557 
    558         if ( isset( $_GET['plugins'] ) ) {
    559                 $plugins = explode( ',', $_GET['plugins'] );
    560         } elseif ( isset( $_POST['checked'] ) ) {
    561                 $plugins = (array) $_POST['checked'];
    562         } else {
    563                 wp_redirect( admin_url('update-core.php') );
    564                 exit;
    565         }
    566 
    567         $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
    568         $url = wp_nonce_url($url, 'bulk-update-plugins');
    569 
    570         $title = __('Update Plugins');
    571 
    572         require_once(ABSPATH . 'wp-admin/admin-header.php');
    573         echo '<div class="wrap">';
    574         screen_icon('plugins');
    575         echo '<h2>' . esc_html__('Update Plugins') . '</h2>';
    576         echo "<iframe src='$url' style='width: 100%; height: 100%; min-height: 750px;' frameborder='0'></iframe>";
    577         echo '</div>';
    578         include(ABSPATH . 'wp-admin/admin-footer.php');
    579 
    580 } elseif ( 'do-theme-upgrade' == $action ) {
    581 
    582         if ( ! current_user_can( 'update_themes' ) )
    583                 wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
    584 
    585         check_admin_referer('upgrade-core');
    586 
    587         if ( isset( $_GET['themes'] ) ) {
    588                 $themes = explode( ',', $_GET['themes'] );
    589         } elseif ( isset( $_POST['checked'] ) ) {
    590                 $themes = (array) $_POST['checked'];
    591         } else {
    592                 wp_redirect( admin_url('update-core.php') );
    593                 exit;
    594         }
    595 
    596         $url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes));
    597         $url = wp_nonce_url($url, 'bulk-update-themes');
    598 
    599         $title = __('Update Themes');
    600 
    601         require_once(ABSPATH . 'wp-admin/admin-header.php');
    602         echo '<div class="wrap">';
    603         screen_icon('themes');
    604         echo '<h2>' . esc_html__('Update Themes') . '</h2>';
    605         echo "<iframe src='$url' style='width: 100%; height: 100%; min-height: 750px;' frameborder='0'></iframe>";
    606         echo '</div>';
    607         include(ABSPATH . 'wp-admin/admin-footer.php');
    608 
    609 } elseif ( 'do-translation-upgrade' == $action ) {
    610 
    611         if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_plugins' ) && ! current_user_can( 'update_themes' ) )
    612                 wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
    613 
    614         check_admin_referer( 'upgrade-translations' );
    615 
    616         require_once( ABSPATH . 'wp-admin/admin-header.php' );
    617         include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
    618 
    619         $url = 'update-core.php?action=do-translation-upgrade';
    620         $nonce = 'upgrade-translations';
    621         $title = __( 'Update Translations' );
    622         $context = WP_LANG_DIR;
    623 
    624         $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
    625         $result = $upgrader->bulk_upgrade();
    626 
    627         require_once( ABSPATH . 'wp-admin/admin-footer.php' );
    628 
    629 } else {
    630         do_action('update-core-custom_' . $action);
    631 }