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