]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/update-core.php
WordPress 4.6.2-scripts
[autoinstalls/wordpress.git] / wp-admin / 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 wp_enqueue_script( 'updates' );
15 add_thickbox();
16
17 if ( is_multisite() && ! is_network_admin() ) {
18         wp_redirect( network_admin_url( 'update-core.php' ) );
19         exit();
20 }
21
22 if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_themes' ) && ! current_user_can( 'update_plugins' ) )
23         wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
24
25 /**
26  *
27  * @global string $wp_local_package
28  * @global wpdb   $wpdb
29  * @global string $wp_version
30  *
31  * @staticvar bool $first_pass
32  *
33  * @param object $update
34  */
35 function list_core_update( $update ) {
36         global $wp_local_package, $wpdb, $wp_version;
37         static $first_pass = true;
38
39         if ( 'en_US' == $update->locale && 'en_US' == get_locale() )
40                 $version_string = $update->current;
41         // If the only available update is a partial builds, it doesn't need a language-specific version string.
42         elseif ( 'en_US' == $update->locale && $update->packages->partial && $wp_version == $update->partial_version && ( $updates = get_core_updates() ) && 1 == count( $updates ) )
43                 $version_string = $update->current;
44         else
45                 $version_string = sprintf( "%s&ndash;<strong>%s</strong>", $update->current, $update->locale );
46
47         $current = false;
48         if ( !isset($update->response) || 'latest' == $update->response )
49                 $current = true;
50         $submit = __('Update Now');
51         $form_action = 'update-core.php?action=do-core-upgrade';
52         $php_version    = phpversion();
53         $mysql_version  = $wpdb->db_version();
54         $show_buttons = true;
55         if ( 'development' == $update->response ) {
56                 $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:');
57                 $download = __('Download nightly build');
58         } else {
59                 if ( $current ) {
60                         $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 );
61                         $submit = __('Re-install Now');
62                         $form_action = 'update-core.php?action=do-core-reinstall';
63                 } 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                                 $mysql_compat = true;
67                         else
68                                 $mysql_compat = version_compare( $mysql_version, $update->mysql_version, '>=' );
69
70                         if ( !$mysql_compat && !$php_compat )
71                                 $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 );
72                         elseif ( !$php_compat )
73                                 $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 );
74                         elseif ( !$mysql_compat )
75                                 $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 );
76                         else
77                                 $message =      sprintf(__('You can update to <a href="https://codex.wordpress.org/Version_%1$s">WordPress %2$s</a> automatically or download the package and install it manually:'), $update->current, $version_string);
78                         if ( !$mysql_compat || !$php_compat )
79                                 $show_buttons = false;
80                 }
81                 $download = sprintf(__('Download %s'), $version_string);
82         }
83
84         echo '<p>';
85         echo $message;
86         echo '</p>';
87         echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
88         wp_nonce_field('upgrade-core');
89         echo '<p>';
90         echo '<input name="version" value="'. esc_attr($update->current) .'" type="hidden"/>';
91         echo '<input name="locale" value="'. esc_attr($update->locale) .'" type="hidden"/>';
92         if ( $show_buttons ) {
93                 if ( $first_pass ) {
94                         submit_button( $submit, $current ? 'button' : 'primary regular', 'upgrade', false );
95                         $first_pass = false;
96                 } else {
97                         submit_button( $submit, 'button', 'upgrade', false );
98                 }
99                 echo '&nbsp;<a href="' . esc_url( $update->download ) . '" class="button">' . $download . '</a>&nbsp;';
100         }
101         if ( 'en_US' != $update->locale )
102                 if ( !isset( $update->dismissed ) || !$update->dismissed )
103                         submit_button( __('Hide this update'), 'button', 'dismiss', false );
104                 else
105                         submit_button( __('Bring back this update'), 'button', 'undismiss', false );
106         echo '</p>';
107         if ( 'en_US' != $update->locale && ( !isset($wp_local_package) || $wp_local_package != $update->locale ) )
108             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>';
109         // Partial builds don't need language-specific warnings.
110         elseif ( 'en_US' == $update->locale && get_locale() != 'en_US' && ( ! $update->packages->partial && $wp_version == $update->partial_version ) ) {
111             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>';
112         }
113         echo '</form>';
114
115 }
116
117 /**
118  * @since 2.7.0
119  */
120 function dismissed_updates() {
121         $dismissed = get_core_updates( array( 'dismissed' => true, 'available' => false ) );
122         if ( $dismissed ) {
123
124                 $show_text = esc_js(__('Show hidden updates'));
125                 $hide_text = esc_js(__('Hide hidden updates'));
126         ?>
127         <script type="text/javascript">
128
129                 jQuery(function($) {
130                         $('dismissed-updates').show();
131                         $('#show-dismissed').toggle(function(){$(this).text('<?php echo $hide_text; ?>');}, function() {$(this).text('<?php echo $show_text; ?>')});
132                         $('#show-dismissed').click(function() { $('#dismissed-updates').toggle('slow');});
133                 });
134         </script>
135         <?php
136                 echo '<p class="hide-if-no-js"><a id="show-dismissed" href="#">'.__('Show hidden updates').'</a></p>';
137                 echo '<ul id="dismissed-updates" class="core-updates dismissed">';
138                 foreach ( (array) $dismissed as $update) {
139                         echo '<li>';
140                         list_core_update( $update );
141                         echo '</li>';
142                 }
143                 echo '</ul>';
144         }
145 }
146
147 /**
148  * Display upgrade WordPress for downloading latest or upgrading automatically form.
149  *
150  * @since 2.7.0
151  *
152  * @global string $wp_version
153  * @global string $required_php_version
154  * @global string $required_mysql_version
155  */
156 function core_upgrade_preamble() {
157         global $wp_version, $required_php_version, $required_mysql_version;
158
159         $updates = get_core_updates();
160
161         if ( !isset($updates[0]->response) || 'latest' == $updates[0]->response ) {
162                 echo '<h2>';
163                 _e('You have the latest version of WordPress.');
164
165                 if ( wp_http_supports( array( 'ssl' ) ) ) {
166                         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
167                         $upgrader = new WP_Automatic_Updater;
168                         $future_minor_update = (object) array(
169                                 'current'       => $wp_version . '.1.next.minor',
170                                 'version'       => $wp_version . '.1.next.minor',
171                                 'php_version'   => $required_php_version,
172                                 'mysql_version' => $required_mysql_version,
173                         );
174                         $should_auto_update = $upgrader->should_update( 'core', $future_minor_update, ABSPATH );
175                         if ( $should_auto_update )
176                                 echo ' ' . __( 'Future security updates will be applied automatically.' );
177                 }
178                 echo '</h2>';
179         } else {
180                 echo '<div class="notice notice-warning"><p>';
181                 _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.');
182                 echo '</p></div>';
183
184                 echo '<h2 class="response">';
185                 _e( 'An updated version of WordPress is available.' );
186                 echo '</h2>';
187         }
188
189         if ( isset( $updates[0] ) && $updates[0]->response == 'development' ) {
190                 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
191                 $upgrader = new WP_Automatic_Updater;
192                 if ( wp_http_supports( 'ssl' ) && $upgrader->should_update( 'core', $updates[0], ABSPATH ) ) {
193                         echo '<div class="updated inline"><p>';
194                         echo '<strong>' . __( 'BETA TESTERS:' ) . '</strong> ' . __( 'This site is set up to install updates of future beta versions automatically.' );
195                         echo '</p></div>';
196                 }
197         }
198
199         echo '<ul class="core-updates">';
200         foreach ( (array) $updates as $update ) {
201                 echo '<li>';
202                 list_core_update( $update );
203                 echo '</li>';
204         }
205         echo '</ul>';
206         // Don't show the maintenance mode notice when we are only showing a single re-install option.
207         if ( $updates && ( count( $updates ) > 1 || $updates[0]->response != 'latest' ) ) {
208                 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>';
209         } elseif ( ! $updates ) {
210                 list( $normalized_version ) = explode( '-', $wp_version );
211                 echo '<p>' . sprintf( __( '<a href="%s">Learn more about WordPress %s</a>.' ), esc_url( self_admin_url( 'about.php' ) ), $normalized_version ) . '</p>';
212         }
213         dismissed_updates();
214 }
215
216 /**
217  *
218  * @global string $wp_version
219  */
220 function list_plugin_updates() {
221         global $wp_version;
222
223         $cur_wp_version = preg_replace('/-.*$/', '', $wp_version);
224
225         require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
226         $plugins = get_plugin_updates();
227         if ( empty( $plugins ) ) {
228                 echo '<h2>' . __( 'Plugins' ) . '</h2>';
229                 echo '<p>' . __( 'Your plugins are all up to date.' ) . '</p>';
230                 return;
231         }
232         $form_action = 'update-core.php?action=do-plugin-upgrade';
233
234         $core_updates = get_core_updates();
235         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, '=') )
236                 $core_update_version = false;
237         else
238                 $core_update_version = $core_updates[0]->current;
239         ?>
240 <h2><?php _e( 'Plugins' ); ?></h2>
241 <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>
242 <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-plugins" class="upgrade">
243 <?php wp_nonce_field('upgrade-core'); ?>
244 <p><input id="upgrade-plugins" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
245 <table class="widefat updates-table" id="update-plugins-table">
246         <thead>
247         <tr>
248                 <td class="manage-column check-column"><input type="checkbox" id="plugins-select-all" /></td>
249                 <td class="manage-column"><label for="plugins-select-all"><?php _e( 'Select All' ); ?></label></td>
250         </tr>
251         </thead>
252
253         <tbody class="plugins">
254 <?php
255         foreach ( (array) $plugins as $plugin_file => $plugin_data ) {
256                 $plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file, (array) $plugin_data, false, true );
257
258                 // Get plugin compat for running version of WordPress.
259                 if ( isset($plugin_data->update->tested) && version_compare($plugin_data->update->tested, $cur_wp_version, '>=') ) {
260                         $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: 100%% (according to its author)'), $cur_wp_version);
261                 } elseif ( isset($plugin_data->update->compatibility->{$cur_wp_version}) ) {
262                         $compat = $plugin_data->update->compatibility->{$cur_wp_version};
263                         $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);
264                 } else {
265                         $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $cur_wp_version);
266                 }
267                 // Get plugin compat for updated version of WordPress.
268                 if ( $core_update_version ) {
269                         if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $core_update_version, '>=' ) ) {
270                                 $compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: 100%% (according to its author)' ), $core_update_version );
271                         } elseif ( isset( $plugin_data->update->compatibility->{$core_update_version} ) ) {
272                                 $update_compat = $plugin_data->update->compatibility->{$core_update_version};
273                                 $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);
274                         } else {
275                                 $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $core_update_version);
276                         }
277                 }
278                 // Get the upgrade notice for the new plugin version.
279                 if ( isset($plugin_data->update->upgrade_notice) ) {
280                         $upgrade_notice = '<br />' . strip_tags($plugin_data->update->upgrade_notice);
281                 } else {
282                         $upgrade_notice = '';
283                 }
284
285                 $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');
286                 $details = sprintf(
287                         '<a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>',
288                         esc_url( $details_url ),
289                         /* translators: 1: plugin name, 2: version number */
290                         esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_data->Name, $plugin_data->update->new_version ) ),
291                         /* translators: %s: plugin version */
292                         sprintf( __( 'View version %s details.' ), $plugin_data->update->new_version )
293                 );
294
295                 $checkbox_id = "checkbox_" . md5( $plugin_data->Name );
296                 ?>
297                 <tr>
298                         <td class="check-column">
299                                 <input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $plugin_file ); ?>" />
300                                 <label for="<?php echo $checkbox_id; ?>" class="screen-reader-text"><?php
301                                         /* translators: %s: plugin name */
302                                         printf( __( 'Select %s' ),
303                                                 $plugin_data->Name
304                                         );
305                                 ?></label>
306                         </td>
307                         <td class="plugin-title"><p>
308                                 <strong><?php echo $plugin_data->Name; ?></strong>
309                                 <?php
310                                         /* translators: 1: plugin version, 2: new version */
311                                         printf( __( 'You have version %1$s installed. Update to %2$s.' ),
312                                                 $plugin_data->Version,
313                                                 $plugin_data->update->new_version
314                                         );
315                                         echo ' ' . $details . $compat . $upgrade_notice;
316                                 ?>
317                         </p></td>
318                 </tr>
319                 <?php
320         }
321 ?>
322         </tbody>
323
324         <tfoot>
325         <tr>
326                 <td class="manage-column check-column"><input type="checkbox" id="plugins-select-all-2" /></td>
327                 <td class="manage-column"><label for="plugins-select-all-2"><?php _e( 'Select All' ); ?></label></td>
328         </tr>
329         </tfoot>
330 </table>
331 <p><input id="upgrade-plugins-2" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
332 </form>
333 <?php
334 }
335
336 /**
337  * @since 2.9.0
338  */
339 function list_theme_updates() {
340         $themes = get_theme_updates();
341         if ( empty( $themes ) ) {
342                 echo '<h2>' . __( 'Themes' ) . '</h2>';
343                 echo '<p>' . __( 'Your themes are all up to date.' ) . '</p>';
344                 return;
345         }
346
347         $form_action = 'update-core.php?action=do-theme-upgrade';
348 ?>
349 <h2><?php _e( 'Themes' ); ?></h2>
350 <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>
351 <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>
352 <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-themes" class="upgrade">
353 <?php wp_nonce_field('upgrade-core'); ?>
354 <p><input id="upgrade-themes" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
355 <table class="widefat updates-table" id="update-themes-table">
356         <thead>
357         <tr>
358                 <td class="manage-column check-column"><input type="checkbox" id="themes-select-all" /></td>
359                 <td class="manage-column"><label for="themes-select-all"><?php _e( 'Select All' ); ?></label></td>
360         </tr>
361         </thead>
362
363         <tbody class="plugins">
364 <?php
365         foreach ( $themes as $stylesheet => $theme ) {
366                 $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
367                 ?>
368                 <tr>
369                         <td class="check-column">
370                                 <input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $stylesheet ); ?>" />
371                                 <label for="<?php echo $checkbox_id; ?>" class="screen-reader-text"><?php
372                                         /* translators: %s: theme name */
373                                         printf( __( 'Select %s' ),
374                                                 $theme->display( 'Name' )
375                                         );
376                                 ?></label>
377                         </td>
378                         <td class="plugin-title"><p>
379                                 <img src="<?php echo esc_url( $theme->get_screenshot() ); ?>" width="85" height="64" class="updates-table-screenshot" alt="" />
380                                 <strong><?php echo $theme->display( 'Name' ); ?></strong>
381                                 <?php
382                                         /* translators: 1: theme version, 2: new version */
383                                         printf( __( 'You have version %1$s installed. Update to %2$s.' ),
384                                                 $theme->display( 'Version' ),
385                                                 $theme->update['new_version']
386                                         );
387                                 ?>
388                         </p></td>
389                 </tr>
390                 <?php
391         }
392 ?>
393         </tbody>
394
395         <tfoot>
396         <tr>
397                 <td class="manage-column check-column"><input type="checkbox" id="themes-select-all-2" /></td>
398                 <td class="manage-column"><label for="themes-select-all-2"><?php _e( 'Select All' ); ?></label></td>
399         </tr>
400         </tfoot>
401 </table>
402 <p><input id="upgrade-themes-2" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
403 </form>
404 <?php
405 }
406
407 /**
408  * @since 3.7.0
409  */
410 function list_translation_updates() {
411         $updates = wp_get_translation_updates();
412         if ( ! $updates ) {
413                 if ( 'en_US' != get_locale() ) {
414                         echo '<h2>' . __( 'Translations' ) . '</h2>';
415                         echo '<p>' . __( 'Your translations are all up to date.' ) . '</p>';
416                 }
417                 return;
418         }
419
420         $form_action = 'update-core.php?action=do-translation-upgrade';
421         ?>
422         <h2><?php _e( 'Translations' ); ?></h2>
423         <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-translations" class="upgrade">
424                 <p><?php _e( 'New translations are available.' ); ?></p>
425                 <?php wp_nonce_field( 'upgrade-translations' ); ?>
426                 <p><input class="button" type="submit" value="<?php esc_attr_e( 'Update Translations' ); ?>" name="upgrade" /></p>
427         </form>
428         <?php
429 }
430
431 /**
432  * Upgrade WordPress core display.
433  *
434  * @since 2.7.0
435  *
436  * @global WP_Filesystem_Base $wp_filesystem Subclass
437  *
438  * @param bool $reinstall
439  */
440 function do_core_upgrade( $reinstall = false ) {
441         global $wp_filesystem;
442
443         include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
444
445         if ( $reinstall )
446                 $url = 'update-core.php?action=do-core-reinstall';
447         else
448                 $url = 'update-core.php?action=do-core-upgrade';
449         $url = wp_nonce_url($url, 'upgrade-core');
450
451         $version = isset( $_POST['version'] )? $_POST['version'] : false;
452         $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
453         $update = find_core_update( $version, $locale );
454         if ( !$update )
455                 return;
456
457         // Allow relaxed file ownership writes for User-initiated upgrades when the API specifies
458         // that it's safe to do so. This only happens when there are no new files to create.
459         $allow_relaxed_file_ownership = ! $reinstall && isset( $update->new_files ) && ! $update->new_files;
460
461 ?>
462         <div class="wrap">
463         <h1><?php _e( 'Update WordPress' ); ?></h1>
464 <?php
465
466         if ( false === ( $credentials = request_filesystem_credentials( $url, '', false, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership ) ) ) {
467                 echo '</div>';
468                 return;
469         }
470
471         if ( ! WP_Filesystem( $credentials, ABSPATH, $allow_relaxed_file_ownership ) ) {
472                 // Failed to connect, Error and request again
473                 request_filesystem_credentials( $url, '', true, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership );
474                 echo '</div>';
475                 return;
476         }
477
478         if ( $wp_filesystem->errors->get_error_code() ) {
479                 foreach ( $wp_filesystem->errors->get_error_messages() as $message )
480                         show_message($message);
481                 echo '</div>';
482                 return;
483         }
484
485         if ( $reinstall )
486                 $update->response = 'reinstall';
487
488         add_filter( 'update_feedback', 'show_message' );
489
490         $upgrader = new Core_Upgrader();
491         $result = $upgrader->upgrade( $update, array(
492                 'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership
493         ) );
494
495         if ( is_wp_error($result) ) {
496                 show_message($result);
497                 if ( 'up_to_date' != $result->get_error_code() && 'locked' != $result->get_error_code() )
498                         show_message( __('Installation Failed') );
499                 echo '</div>';
500                 return;
501         }
502
503         show_message( __('WordPress updated successfully') );
504         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>' );
505         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>' );
506         ?>
507         </div>
508         <script type="text/javascript">
509         window.location = '<?php echo self_admin_url( 'about.php?updated' ); ?>';
510         </script>
511         <?php
512 }
513
514 /**
515  * @since 2.7.0
516  */
517 function do_dismiss_core_update() {
518         $version = isset( $_POST['version'] )? $_POST['version'] : false;
519         $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
520         $update = find_core_update( $version, $locale );
521         if ( !$update )
522                 return;
523         dismiss_core_update( $update );
524         wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
525         exit;
526 }
527
528 /**
529  * @since 2.7.0
530  */
531 function do_undismiss_core_update() {
532         $version = isset( $_POST['version'] )? $_POST['version'] : false;
533         $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
534         $update = find_core_update( $version, $locale );
535         if ( !$update )
536                 return;
537         undismiss_core_update( $version, $locale );
538         wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
539         exit;
540 }
541
542 $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
543
544 $upgrade_error = false;
545 if ( ( 'do-theme-upgrade' == $action || ( 'do-plugin-upgrade' == $action && ! isset( $_GET['plugins'] ) ) )
546         && ! isset( $_POST['checked'] ) ) {
547         $upgrade_error = $action == 'do-theme-upgrade' ? 'themes' : 'plugins';
548         $action = 'upgrade-core';
549 }
550
551 $title = __('WordPress Updates');
552 $parent_file = 'index.php';
553
554 $updates_overview  = '<p>' . __( 'On this screen, you can update to the latest version of WordPress, as well as update your themes, plugins, and translations from the WordPress.org repositories.' ) . '</p>';
555 $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>';
556
557 get_current_screen()->add_help_tab( array(
558         'id'      => 'overview',
559         'title'   => __( 'Overview' ),
560         'content' => $updates_overview
561 ) );
562
563 $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>';
564 $updates_howto .= '<p>' . __( '<strong>Themes and Plugins</strong> &mdash; To update individual themes or plugins from this screen, use the checkboxes to make your selection, then <strong>click on the appropriate &#8220;Update&#8221; button</strong>. To update all of your themes or plugins at once, you can check the box at the top of the section to select all before clicking the update button.' ) . '</p>';
565
566 if ( 'en_US' != get_locale() ) {
567         $updates_howto .= '<p>' . __( '<strong>Translations</strong> &mdash; The files translating WordPress into your language are updated for you whenever any other updates occur. But if these files are out of date, you can <strong>click the &#8220;Update Translations&#8221;</strong> button.' ) . '</p>';
568 }
569
570 get_current_screen()->add_help_tab( array(
571         'id'      => 'how-to-update',
572         'title'   => __( 'How to Update' ),
573         'content' => $updates_howto
574 ) );
575
576 get_current_screen()->set_help_sidebar(
577         '<p><strong>' . __('For more information:') . '</strong></p>' .
578         '<p>' . __( '<a href="https://codex.wordpress.org/Dashboard_Updates_Screen" target="_blank">Documentation on Updating WordPress</a>' ) . '</p>' .
579         '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
580 );
581
582 if ( 'upgrade-core' == $action ) {
583         // Force a update check when requested
584         $force_check = ! empty( $_GET['force-check'] );
585         wp_version_check( array(), $force_check );
586
587         require_once(ABSPATH . 'wp-admin/admin-header.php');
588         ?>
589         <div class="wrap">
590         <h1><?php _e( 'WordPress Updates' ); ?></h1>
591         <?php
592         if ( $upgrade_error ) {
593                 echo '<div class="error"><p>';
594                 if ( $upgrade_error == 'themes' )
595                         _e('Please select one or more themes to update.');
596                 else
597                         _e('Please select one or more plugins to update.');
598                 echo '</p></div>';
599         }
600
601         echo '<p>';
602         /* translators: %1 date, %2 time. */
603         printf( __( 'Last checked on %1$s at %2$s.' ), date_i18n( __( 'F j, Y' ) ), date_i18n( __( 'g:i a' ) ) );
604         echo ' &nbsp; <a class="button" href="' . esc_url( self_admin_url('update-core.php?force-check=1') ) . '">' . __( 'Check Again' ) . '</a>';
605         echo '</p>';
606
607         if ( $core = current_user_can( 'update_core' ) )
608                 core_upgrade_preamble();
609         if ( $plugins = current_user_can( 'update_plugins' ) )
610                 list_plugin_updates();
611         if ( $themes = current_user_can( 'update_themes' ) )
612                 list_theme_updates();
613         if ( $core || $plugins || $themes )
614                 list_translation_updates();
615         unset( $core, $plugins, $themes );
616         /**
617          * Fires after the core, plugin, and theme update tables.
618          *
619          * @since 2.9.0
620          */
621         do_action( 'core_upgrade_preamble' );
622         echo '</div>';
623         include(ABSPATH . 'wp-admin/admin-footer.php');
624
625 } elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
626
627         if ( ! current_user_can( 'update_core' ) )
628                 wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
629
630         check_admin_referer('upgrade-core');
631
632         // Do the (un)dismiss actions before headers, so that they can redirect.
633         if ( isset( $_POST['dismiss'] ) )
634                 do_dismiss_core_update();
635         elseif ( isset( $_POST['undismiss'] ) )
636                 do_undismiss_core_update();
637
638         require_once(ABSPATH . 'wp-admin/admin-header.php');
639         if ( 'do-core-reinstall' == $action )
640                 $reinstall = true;
641         else
642                 $reinstall = false;
643
644         if ( isset( $_POST['upgrade'] ) )
645                 do_core_upgrade($reinstall);
646
647         include(ABSPATH . 'wp-admin/admin-footer.php');
648
649 } elseif ( 'do-plugin-upgrade' == $action ) {
650
651         if ( ! current_user_can( 'update_plugins' ) )
652                 wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
653
654         check_admin_referer('upgrade-core');
655
656         if ( isset( $_GET['plugins'] ) ) {
657                 $plugins = explode( ',', $_GET['plugins'] );
658         } elseif ( isset( $_POST['checked'] ) ) {
659                 $plugins = (array) $_POST['checked'];
660         } else {
661                 wp_redirect( admin_url('update-core.php') );
662                 exit;
663         }
664
665         $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
666         $url = wp_nonce_url($url, 'bulk-update-plugins');
667
668         $title = __('Update Plugins');
669
670         require_once(ABSPATH . 'wp-admin/admin-header.php');
671         echo '<div class="wrap">';
672         echo '<h1>' . __( 'Update Plugins' ) . '</h1>';
673         echo '<iframe src="', $url, '" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="' . esc_attr__( 'Update progress' ) . '"></iframe>';
674         echo '</div>';
675         include(ABSPATH . 'wp-admin/admin-footer.php');
676
677 } elseif ( 'do-theme-upgrade' == $action ) {
678
679         if ( ! current_user_can( 'update_themes' ) )
680                 wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
681
682         check_admin_referer('upgrade-core');
683
684         if ( isset( $_GET['themes'] ) ) {
685                 $themes = explode( ',', $_GET['themes'] );
686         } elseif ( isset( $_POST['checked'] ) ) {
687                 $themes = (array) $_POST['checked'];
688         } else {
689                 wp_redirect( admin_url('update-core.php') );
690                 exit;
691         }
692
693         $url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes));
694         $url = wp_nonce_url($url, 'bulk-update-themes');
695
696         $title = __('Update Themes');
697
698         require_once(ABSPATH . 'wp-admin/admin-header.php');
699         ?>
700         <div class="wrap">
701                 <h1><?php _e( 'Update Themes' ); ?></h1>
702                 <iframe src="<?php echo $url ?>" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php esc_attr_e( 'Update progress' ); ?>"></iframe>
703         </div>
704         <?php
705         include(ABSPATH . 'wp-admin/admin-footer.php');
706
707 } elseif ( 'do-translation-upgrade' == $action ) {
708
709         if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_plugins' ) && ! current_user_can( 'update_themes' ) )
710                 wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
711
712         check_admin_referer( 'upgrade-translations' );
713
714         require_once( ABSPATH . 'wp-admin/admin-header.php' );
715         include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
716
717         $url = 'update-core.php?action=do-translation-upgrade';
718         $nonce = 'upgrade-translations';
719         $title = __( 'Update Translations' );
720         $context = WP_LANG_DIR;
721
722         $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
723         $result = $upgrader->bulk_upgrade();
724
725         require_once( ABSPATH . 'wp-admin/admin-footer.php' );
726
727 } else {
728         /**
729          * Fires for each custom update action on the WordPress Updates screen.
730          *
731          * The dynamic portion of the hook name, `$action`, refers to the
732          * passed update action. The hook fires in lieu of all available
733          * default update actions.
734          *
735          * @since 3.2.0
736          */
737         do_action( "update-core-custom_{$action}" );
738 }