]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/update-core.php
WordPress 4.5
[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( __( 'You do not have sufficient permissions 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                 // Get plugin compat for running version of WordPress.
257                 if ( isset($plugin_data->update->tested) && version_compare($plugin_data->update->tested, $cur_wp_version, '>=') ) {
258                         $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: 100%% (according to its author)'), $cur_wp_version);
259                 } elseif ( isset($plugin_data->update->compatibility->{$cur_wp_version}) ) {
260                         $compat = $plugin_data->update->compatibility->{$cur_wp_version};
261                         $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);
262                 } else {
263                         $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $cur_wp_version);
264                 }
265                 // Get plugin compat for updated version of WordPress.
266                 if ( $core_update_version ) {
267                         if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $core_update_version, '>=' ) ) {
268                                 $compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: 100%% (according to its author)' ), $core_update_version );
269                         } elseif ( isset( $plugin_data->update->compatibility->{$core_update_version} ) ) {
270                                 $update_compat = $plugin_data->update->compatibility->{$core_update_version};
271                                 $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);
272                         } else {
273                                 $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $core_update_version);
274                         }
275                 }
276                 // Get the upgrade notice for the new plugin version.
277                 if ( isset($plugin_data->update->upgrade_notice) ) {
278                         $upgrade_notice = '<br />' . strip_tags($plugin_data->update->upgrade_notice);
279                 } else {
280                         $upgrade_notice = '';
281                 }
282
283                 $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');
284                 $details = sprintf(
285                         '<a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>',
286                         esc_url( $details_url ),
287                         /* translators: 1: plugin name, 2: version number */
288                         esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_data->Name, $plugin_data->update->new_version ) ),
289                         /* translators: %s: plugin version */
290                         sprintf( __( 'View version %s details.' ), $plugin_data->update->new_version )
291                 );
292
293                 $checkbox_id = "checkbox_" . md5( $plugin_data->Name );
294                 ?>
295                 <tr>
296                         <td class="check-column">
297                                 <input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $plugin_file ); ?>" />
298                                 <label for="<?php echo $checkbox_id; ?>" class="screen-reader-text"><?php
299                                         /* translators: %s: plugin name */
300                                         printf( __( 'Select %s' ),
301                                                 $plugin_data->Name
302                                         );
303                                 ?></label>
304                         </td>
305                         <td class="plugin-title"><p>
306                                 <strong><?php echo $plugin_data->Name; ?></strong>
307                                 <?php
308                                         /* translators: 1: plugin version, 2: new version */
309                                         printf( __( 'You have version %1$s installed. Update to %2$s.' ),
310                                                 $plugin_data->Version,
311                                                 $plugin_data->update->new_version
312                                         );
313                                         echo ' ' . $details . $compat . $upgrade_notice;
314                                 ?>
315                         </p></td>
316                 </tr>
317                 <?php
318         }
319 ?>
320         </tbody>
321
322         <tfoot>
323         <tr>
324                 <td class="manage-column check-column"><input type="checkbox" id="plugins-select-all-2" /></td>
325                 <td class="manage-column"><label for="plugins-select-all-2"><?php _e( 'Select All' ); ?></label></td>
326         </tr>
327         </tfoot>
328 </table>
329 <p><input id="upgrade-plugins-2" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
330 </form>
331 <?php
332 }
333
334 /**
335  * @since 2.9.0
336  */
337 function list_theme_updates() {
338         $themes = get_theme_updates();
339         if ( empty( $themes ) ) {
340                 echo '<h2>' . __( 'Themes' ) . '</h2>';
341                 echo '<p>' . __( 'Your themes are all up to date.' ) . '</p>';
342                 return;
343         }
344
345         $form_action = 'update-core.php?action=do-theme-upgrade';
346 ?>
347 <h2><?php _e( 'Themes' ); ?></h2>
348 <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>
349 <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>
350 <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-themes" class="upgrade">
351 <?php wp_nonce_field('upgrade-core'); ?>
352 <p><input id="upgrade-themes" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
353 <table class="widefat updates-table" id="update-themes-table">
354         <thead>
355         <tr>
356                 <td class="manage-column check-column"><input type="checkbox" id="themes-select-all" /></td>
357                 <td class="manage-column"><label for="themes-select-all"><?php _e( 'Select All' ); ?></label></td>
358         </tr>
359         </thead>
360
361         <tbody class="plugins">
362 <?php
363         foreach ( $themes as $stylesheet => $theme ) {
364                 $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
365                 ?>
366                 <tr>
367                         <td class="check-column">
368                                 <input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $stylesheet ); ?>" />
369                                 <label for="<?php echo $checkbox_id; ?>" class="screen-reader-text"><?php
370                                         /* translators: %s: theme name */
371                                         printf( __( 'Select %s' ),
372                                                 $theme->display( 'Name' )
373                                         );
374                                 ?></label>
375                         </td>
376                         <td class="plugin-title"><p>
377                                 <img src="<?php echo esc_url( $theme->get_screenshot() ); ?>" width="85" height="64" class="updates-table-screenshot" alt="" />
378                                 <strong><?php echo $theme->display( 'Name' ); ?></strong>
379                                 <?php
380                                         /* translators: 1: theme version, 2: new version */
381                                         printf( __( 'You have version %1$s installed. Update to %2$s.' ),
382                                                 $theme->display( 'Version' ),
383                                                 $theme->update['new_version']
384                                         );
385                                 ?>
386                         </p></td>
387                 </tr>
388                 <?php
389         }
390 ?>
391         </tbody>
392
393         <tfoot>
394         <tr>
395                 <td class="manage-column check-column"><input type="checkbox" id="themes-select-all-2" /></td>
396                 <td class="manage-column"><label for="themes-select-all-2"><?php _e( 'Select All' ); ?></label></td>
397         </tr>
398         </tfoot>
399 </table>
400 <p><input id="upgrade-themes-2" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
401 </form>
402 <?php
403 }
404
405 /**
406  * @since 3.7.0
407  */
408 function list_translation_updates() {
409         $updates = wp_get_translation_updates();
410         if ( ! $updates ) {
411                 if ( 'en_US' != get_locale() ) {
412                         echo '<h2>' . __( 'Translations' ) . '</h2>';
413                         echo '<p>' . __( 'Your translations are all up to date.' ) . '</p>';
414                 }
415                 return;
416         }
417
418         $form_action = 'update-core.php?action=do-translation-upgrade';
419         ?>
420         <h2><?php _e( 'Translations' ); ?></h2>
421         <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-translations" class="upgrade">
422                 <p><?php _e( 'New translations are available.' ); ?></p>
423                 <?php wp_nonce_field( 'upgrade-translations' ); ?>
424                 <p><input class="button" type="submit" value="<?php esc_attr_e( 'Update Translations' ); ?>" name="upgrade" /></p>
425         </form>
426         <?php
427 }
428
429 /**
430  * Upgrade WordPress core display.
431  *
432  * @since 2.7.0
433  *
434  * @global WP_Filesystem_Base $wp_filesystem Subclass
435  *
436  * @param bool $reinstall
437  */
438 function do_core_upgrade( $reinstall = false ) {
439         global $wp_filesystem;
440
441         include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
442
443         if ( $reinstall )
444                 $url = 'update-core.php?action=do-core-reinstall';
445         else
446                 $url = 'update-core.php?action=do-core-upgrade';
447         $url = wp_nonce_url($url, 'upgrade-core');
448
449         $version = isset( $_POST['version'] )? $_POST['version'] : false;
450         $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
451         $update = find_core_update( $version, $locale );
452         if ( !$update )
453                 return;
454
455         // Allow relaxed file ownership writes for User-initiated upgrades when the API specifies
456         // that it's safe to do so. This only happens when there are no new files to create.
457         $allow_relaxed_file_ownership = ! $reinstall && isset( $update->new_files ) && ! $update->new_files;
458
459 ?>
460         <div class="wrap">
461         <h1><?php _e( 'Update WordPress' ); ?></h1>
462 <?php
463
464         if ( false === ( $credentials = request_filesystem_credentials( $url, '', false, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership ) ) ) {
465                 echo '</div>';
466                 return;
467         }
468
469         if ( ! WP_Filesystem( $credentials, ABSPATH, $allow_relaxed_file_ownership ) ) {
470                 // Failed to connect, Error and request again
471                 request_filesystem_credentials( $url, '', true, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership );
472                 echo '</div>';
473                 return;
474         }
475
476         if ( $wp_filesystem->errors->get_error_code() ) {
477                 foreach ( $wp_filesystem->errors->get_error_messages() as $message )
478                         show_message($message);
479                 echo '</div>';
480                 return;
481         }
482
483         if ( $reinstall )
484                 $update->response = 'reinstall';
485
486         add_filter( 'update_feedback', 'show_message' );
487
488         $upgrader = new Core_Upgrader();
489         $result = $upgrader->upgrade( $update, array(
490                 'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership
491         ) );
492
493         if ( is_wp_error($result) ) {
494                 show_message($result);
495                 if ( 'up_to_date' != $result->get_error_code() && 'locked' != $result->get_error_code() )
496                         show_message( __('Installation Failed') );
497                 echo '</div>';
498                 return;
499         }
500
501         show_message( __('WordPress updated successfully') );
502         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>' );
503         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>' );
504         ?>
505         </div>
506         <script type="text/javascript">
507         window.location = '<?php echo self_admin_url( 'about.php?updated' ); ?>';
508         </script>
509         <?php
510 }
511
512 /**
513  * @since 2.7.0
514  */
515 function do_dismiss_core_update() {
516         $version = isset( $_POST['version'] )? $_POST['version'] : false;
517         $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
518         $update = find_core_update( $version, $locale );
519         if ( !$update )
520                 return;
521         dismiss_core_update( $update );
522         wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
523         exit;
524 }
525
526 /**
527  * @since 2.7.0
528  */
529 function do_undismiss_core_update() {
530         $version = isset( $_POST['version'] )? $_POST['version'] : false;
531         $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
532         $update = find_core_update( $version, $locale );
533         if ( !$update )
534                 return;
535         undismiss_core_update( $version, $locale );
536         wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
537         exit;
538 }
539
540 $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
541
542 $upgrade_error = false;
543 if ( ( 'do-theme-upgrade' == $action || ( 'do-plugin-upgrade' == $action && ! isset( $_GET['plugins'] ) ) )
544         && ! isset( $_POST['checked'] ) ) {
545         $upgrade_error = $action == 'do-theme-upgrade' ? 'themes' : 'plugins';
546         $action = 'upgrade-core';
547 }
548
549 $title = __('WordPress Updates');
550 $parent_file = 'index.php';
551
552 $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>';
553 $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>';
554
555 get_current_screen()->add_help_tab( array(
556         'id'      => 'overview',
557         'title'   => __( 'Overview' ),
558         'content' => $updates_overview
559 ) );
560
561 $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>';
562 $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>';
563
564 if ( 'en_US' != get_locale() ) {
565         $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>';
566 }
567
568 get_current_screen()->add_help_tab( array(
569         'id'      => 'how-to-update',
570         'title'   => __( 'How to Update' ),
571         'content' => $updates_howto
572 ) );
573
574 get_current_screen()->set_help_sidebar(
575         '<p><strong>' . __('For more information:') . '</strong></p>' .
576         '<p>' . __( '<a href="https://codex.wordpress.org/Dashboard_Updates_Screen" target="_blank">Documentation on Updating WordPress</a>' ) . '</p>' .
577         '<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
578 );
579
580 if ( 'upgrade-core' == $action ) {
581         // Force a update check when requested
582         $force_check = ! empty( $_GET['force-check'] );
583         wp_version_check( array(), $force_check );
584
585         require_once(ABSPATH . 'wp-admin/admin-header.php');
586         ?>
587         <div class="wrap">
588         <h1><?php _e( 'WordPress Updates' ); ?></h1>
589         <?php
590         if ( $upgrade_error ) {
591                 echo '<div class="error"><p>';
592                 if ( $upgrade_error == 'themes' )
593                         _e('Please select one or more themes to update.');
594                 else
595                         _e('Please select one or more plugins to update.');
596                 echo '</p></div>';
597         }
598
599         echo '<p>';
600         /* translators: %1 date, %2 time. */
601         printf( __( 'Last checked on %1$s at %2$s.' ), date_i18n( __( 'F j, Y' ) ), date_i18n( __( 'g:i a' ) ) );
602         echo ' &nbsp; <a class="button" href="' . esc_url( self_admin_url('update-core.php?force-check=1') ) . '">' . __( 'Check Again' ) . '</a>';
603         echo '</p>';
604
605         if ( $core = current_user_can( 'update_core' ) )
606                 core_upgrade_preamble();
607         if ( $plugins = current_user_can( 'update_plugins' ) )
608                 list_plugin_updates();
609         if ( $themes = current_user_can( 'update_themes' ) )
610                 list_theme_updates();
611         if ( $core || $plugins || $themes )
612                 list_translation_updates();
613         unset( $core, $plugins, $themes );
614         /**
615          * Fires after the core, plugin, and theme update tables.
616          *
617          * @since 2.9.0
618          */
619         do_action( 'core_upgrade_preamble' );
620         echo '</div>';
621         include(ABSPATH . 'wp-admin/admin-footer.php');
622
623 } elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
624
625         if ( ! current_user_can( 'update_core' ) )
626                 wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
627
628         check_admin_referer('upgrade-core');
629
630         // Do the (un)dismiss actions before headers, so that they can redirect.
631         if ( isset( $_POST['dismiss'] ) )
632                 do_dismiss_core_update();
633         elseif ( isset( $_POST['undismiss'] ) )
634                 do_undismiss_core_update();
635
636         require_once(ABSPATH . 'wp-admin/admin-header.php');
637         if ( 'do-core-reinstall' == $action )
638                 $reinstall = true;
639         else
640                 $reinstall = false;
641
642         if ( isset( $_POST['upgrade'] ) )
643                 do_core_upgrade($reinstall);
644
645         include(ABSPATH . 'wp-admin/admin-footer.php');
646
647 } elseif ( 'do-plugin-upgrade' == $action ) {
648
649         if ( ! current_user_can( 'update_plugins' ) )
650                 wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
651
652         check_admin_referer('upgrade-core');
653
654         if ( isset( $_GET['plugins'] ) ) {
655                 $plugins = explode( ',', $_GET['plugins'] );
656         } elseif ( isset( $_POST['checked'] ) ) {
657                 $plugins = (array) $_POST['checked'];
658         } else {
659                 wp_redirect( admin_url('update-core.php') );
660                 exit;
661         }
662
663         $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
664         $url = wp_nonce_url($url, 'bulk-update-plugins');
665
666         $title = __('Update Plugins');
667
668         require_once(ABSPATH . 'wp-admin/admin-header.php');
669         echo '<div class="wrap">';
670         echo '<h1>' . __( 'Update Plugins' ) . '</h1>';
671         echo '<iframe src="', $url, '" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="' . esc_attr__( 'Update progress' ) . '"></iframe>';
672         echo '</div>';
673         include(ABSPATH . 'wp-admin/admin-footer.php');
674
675 } elseif ( 'do-theme-upgrade' == $action ) {
676
677         if ( ! current_user_can( 'update_themes' ) )
678                 wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
679
680         check_admin_referer('upgrade-core');
681
682         if ( isset( $_GET['themes'] ) ) {
683                 $themes = explode( ',', $_GET['themes'] );
684         } elseif ( isset( $_POST['checked'] ) ) {
685                 $themes = (array) $_POST['checked'];
686         } else {
687                 wp_redirect( admin_url('update-core.php') );
688                 exit;
689         }
690
691         $url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes));
692         $url = wp_nonce_url($url, 'bulk-update-themes');
693
694         $title = __('Update Themes');
695
696         require_once(ABSPATH . 'wp-admin/admin-header.php');
697         ?>
698         <div class="wrap">
699                 <h1><?php _e( 'Update Themes' ); ?></h1>
700                 <iframe src="<?php echo $url ?>" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php esc_attr_e( 'Update progress' ); ?>"></iframe>
701         </div>
702         <?php
703         include(ABSPATH . 'wp-admin/admin-footer.php');
704
705 } elseif ( 'do-translation-upgrade' == $action ) {
706
707         if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_plugins' ) && ! current_user_can( 'update_themes' ) )
708                 wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
709
710         check_admin_referer( 'upgrade-translations' );
711
712         require_once( ABSPATH . 'wp-admin/admin-header.php' );
713         include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
714
715         $url = 'update-core.php?action=do-translation-upgrade';
716         $nonce = 'upgrade-translations';
717         $title = __( 'Update Translations' );
718         $context = WP_LANG_DIR;
719
720         $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
721         $result = $upgrader->bulk_upgrade();
722
723         require_once( ABSPATH . 'wp-admin/admin-footer.php' );
724
725 } else {
726         /**
727          * Fires for each custom update action on the WordPress Updates screen.
728          *
729          * The dynamic portion of the hook name, `$action`, refers to the
730          * passed update action. The hook fires in lieu of all available
731          * default update actions.
732          *
733          * @since 3.2.0
734          */
735         do_action( "update-core-custom_{$action}" );
736 }