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