3 * Update Core administration panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('./admin.php');
12 wp_enqueue_style( 'plugin-install' );
13 wp_enqueue_script( 'plugin-install' );
16 if ( is_multisite() && ! is_network_admin() ) {
17 wp_redirect( network_admin_url( 'update-core.php' ) );
21 if ( ! current_user_can( 'update_core' ) )
22 wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
24 function list_core_update( $update ) {
25 global $wp_local_package, $wpdb;
26 static $first_pass = true;
28 $version_string = ('en_US' == $update->locale && 'en_US' == get_locale() ) ?
29 $update->current : sprintf("%s–<strong>%s</strong>", $update->current, $update->locale);
31 if ( !isset($update->response) || 'latest' == $update->response )
33 $submit = __('Update Now');
34 $form_action = 'update-core.php?action=do-core-upgrade';
35 $php_version = phpversion();
36 $mysql_version = $wpdb->db_version();
38 if ( 'development' == $update->response ) {
39 $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:');
40 $download = __('Download nightly build');
43 $message = sprintf(__('You have the latest version of WordPress. You do not need to update. However, if you want to re-install version %s, you can do so automatically or download the package and re-install manually:'), $version_string);
44 $submit = __('Re-install Now');
45 $form_action = 'update-core.php?action=do-core-reinstall';
47 $php_compat = version_compare( $php_version, $update->php_version, '>=' );
48 if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) )
51 $mysql_compat = version_compare( $mysql_version, $update->mysql_version, '>=' );
53 if ( !$mysql_compat && !$php_compat )
54 $message = sprintf( __('You cannot update because <a href="http://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires PHP version %2$s or higher and MySQL version %3$s or higher. You are running PHP version %4$s and MySQL version %5$s.'), $update->current, $update->php_version, $update->mysql_version, $php_version, $mysql_version );
55 elseif ( !$php_compat )
56 $message = sprintf( __('You cannot update because <a href="http://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires PHP version %2$s or higher. You are running version %3$s.'), $update->current, $update->php_version, $php_version );
57 elseif ( !$mysql_compat )
58 $message = sprintf( __('You cannot update because <a href="http://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> requires MySQL version %2$s or higher. You are running version %3$s.'), $update->current, $update->mysql_version, $mysql_version );
60 $message = sprintf(__('You can update to <a href="http://codex.wordpress.org/Version_%1$s">WordPress %2$s</a> automatically or download the package and install it manually:'), $update->current, $version_string);
61 if ( !$mysql_compat || !$php_compat )
62 $show_buttons = false;
64 $download = sprintf(__('Download %s'), $version_string);
70 echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
71 wp_nonce_field('upgrade-core');
73 echo '<input name="version" value="'. esc_attr($update->current) .'" type="hidden"/>';
74 echo '<input name="locale" value="'. esc_attr($update->locale) .'" type="hidden"/>';
75 if ( $show_buttons ) {
77 submit_button( $submit, $current ? 'button' : 'primary', 'upgrade', false );
80 submit_button( $submit, 'button', 'upgrade', false );
82 echo ' <a href="' . esc_url( $update->download ) . '" class="button">' . $download . '</a> ';
84 if ( 'en_US' != $update->locale )
85 if ( !isset( $update->dismissed ) || !$update->dismissed )
86 submit_button( __('Hide this update'), 'button', 'dismiss', false );
88 submit_button( __('Bring back this update'), 'button', 'undismiss', false );
90 if ( 'en_US' != $update->locale && ( !isset($wp_local_package) || $wp_local_package != $update->locale ) )
91 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>';
92 else if ( 'en_US' == $update->locale && get_locale() != 'en_US' ) {
93 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>';
99 function dismissed_updates() {
100 $dismissed = get_core_updates( array( 'dismissed' => true, 'available' => false ) );
103 $show_text = esc_js(__('Show hidden updates'));
104 $hide_text = esc_js(__('Hide hidden updates'));
106 <script type="text/javascript">
109 $('dismissed-updates').show();
110 $('#show-dismissed').toggle(function(){$(this).text('<?php echo $hide_text; ?>');}, function() {$(this).text('<?php echo $show_text; ?>')});
111 $('#show-dismissed').click(function() { $('#dismissed-updates').toggle('slow');});
115 echo '<p class="hide-if-no-js"><a id="show-dismissed" href="#">'.__('Show hidden updates').'</a></p>';
116 echo '<ul id="dismissed-updates" class="core-updates dismissed">';
117 foreach( (array) $dismissed as $update) {
119 list_core_update( $update );
127 * Display upgrade WordPress for downloading latest or upgrading automatically form.
133 function core_upgrade_preamble() {
134 global $upgrade_error, $wp_version;
136 $updates = get_core_updates();
139 <?php screen_icon('tools'); ?>
140 <h2><?php _e('WordPress Updates'); ?></h2>
142 if ( $upgrade_error ) {
143 echo '<div class="error"><p>';
144 if ( $upgrade_error == 'themes' )
145 _e('Please select one or more themes to update.');
147 _e('Please select one or more plugins to update.');
152 /* translators: %1 date, %2 time. */
153 printf( __('Last checked on %1$s at %2$s.'), date_i18n( get_option( 'date_format' ) ), date_i18n( get_option( 'time_format' ) ) );
154 echo ' <a class="button" href="' . esc_url( self_admin_url('update-core.php') ) . '">' . __( 'Check Again' ) . '</a>';
157 if ( !isset($updates[0]->response) || 'latest' == $updates[0]->response ) {
159 _e('You have the latest version of WordPress.');
162 echo '<div class="updated inline"><p>';
163 _e('<strong>Important:</strong> before updating, please <a href="http://codex.wordpress.org/WordPress_Backups">back up your database and files</a>. For help with updates, visit the <a href="http://codex.wordpress.org/Updating_WordPress">Updating WordPress</a> Codex page.');
166 echo '<h3 class="response">';
167 _e( 'An updated version of WordPress is available.' );
171 echo '<ul class="core-updates">';
173 foreach( (array) $updates as $update ) {
175 list_core_update( $update );
180 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>';
182 list( $normalized_version ) = explode( '-', $wp_version );
183 echo '<p>' . sprintf( __( '<a href="%s">Learn more about WordPress %s</a>.' ), esc_url( admin_url( 'about.php' ) ), $normalized_version ) . '</p>';
187 if ( current_user_can( 'update_plugins' ) )
188 list_plugin_updates();
189 if ( current_user_can( 'update_themes' ) )
190 list_theme_updates();
191 do_action('core_upgrade_preamble');
195 function list_plugin_updates() {
198 $cur_wp_version = preg_replace('/-.*$/', '', $wp_version);
200 require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
201 $plugins = get_plugin_updates();
202 if ( empty( $plugins ) ) {
203 echo '<h3>' . __( 'Plugins' ) . '</h3>';
204 echo '<p>' . __( 'Your plugins are all up to date.' ) . '</p>';
207 $form_action = 'update-core.php?action=do-plugin-upgrade';
209 $core_updates = get_core_updates();
210 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, '=') )
211 $core_update_version = false;
213 $core_update_version = $core_updates[0]->current;
215 <h3><?php _e( 'Plugins' ); ?></h3>
216 <p><?php _e( 'The following plugins have new versions available. Check the ones you want to update and then click “Update Plugins”.' ); ?></p>
217 <form method="post" action="<?php echo $form_action; ?>" name="upgrade-plugins" class="upgrade">
218 <?php wp_nonce_field('upgrade-core'); ?>
219 <p><input id="upgrade-plugins" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
220 <table class="widefat" cellspacing="0" id="update-plugins-table">
223 <th scope="col" class="manage-column check-column"><input type="checkbox" id="plugins-select-all" /></th>
224 <th scope="col" class="manage-column"><label for="plugins-select-all"><?php _e('Select All'); ?></label></th>
230 <th scope="col" class="manage-column check-column"><input type="checkbox" id="plugins-select-all-2" /></th>
231 <th scope="col" class="manage-column"><label for="plugins-select-all-2"><?php _e('Select All'); ?></label></th>
234 <tbody class="plugins">
236 foreach ( (array) $plugins as $plugin_file => $plugin_data) {
237 $info = plugins_api('plugin_information', array('slug' => $plugin_data->update->slug ));
238 // Get plugin compat for running version of WordPress.
239 if ( isset($info->tested) && version_compare($info->tested, $cur_wp_version, '>=') ) {
240 $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: 100%% (according to its author)'), $cur_wp_version);
241 } elseif ( isset($info->compatibility[$cur_wp_version][$plugin_data->update->new_version]) ) {
242 $compat = $info->compatibility[$cur_wp_version][$plugin_data->update->new_version];
243 $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]);
245 $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $cur_wp_version);
247 // Get plugin compat for updated version of WordPress.
248 if ( $core_update_version ) {
249 if ( isset($info->compatibility[$core_update_version][$plugin_data->update->new_version]) ) {
250 $update_compat = $info->compatibility[$core_update_version][$plugin_data->update->new_version];
251 $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]);
253 $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $core_update_version);
256 // Get the upgrade notice for the new plugin version.
257 if ( isset($plugin_data->update->upgrade_notice) ) {
258 $upgrade_notice = '<br />' . strip_tags($plugin_data->update->upgrade_notice);
260 $upgrade_notice = '';
263 $details_url = self_admin_url('plugin-install.php?tab=plugin-information&plugin=' . $plugin_data->update->slug . '&TB_iframe=true&width=640&height=662');
264 $details_text = sprintf(__('View version %1$s details'), $plugin_data->update->new_version);
265 $details = sprintf('<a href="%1$s" class="thickbox" title="%2$s">%3$s</a>.', esc_url($details_url), esc_attr($plugin_data->Name), $details_text);
269 <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' /></th>
270 <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>
276 <p><input id="upgrade-plugins-2" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
281 function list_theme_updates() {
282 $themes = get_theme_updates();
283 if ( empty( $themes ) ) {
284 echo '<h3>' . __( 'Themes' ) . '</h3>';
285 echo '<p>' . __( 'Your themes are all up to date.' ) . '</p>';
289 $form_action = 'update-core.php?action=do-theme-upgrade';
292 <h3><?php _e( 'Themes' ); ?></h3>
293 <p><?php _e( 'The following themes have new versions available. Check the ones you want to update and then click “Update Themes”.' ); ?></p>
294 <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.'), _x('http://codex.wordpress.org/Child_Themes', 'Link used in suggestion to use child themes in GUU') ); ?></p>
295 <form method="post" action="<?php echo $form_action; ?>" name="upgrade-themes" class="upgrade">
296 <?php wp_nonce_field('upgrade-core'); ?>
297 <p><input id="upgrade-themes" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
298 <table class="widefat" cellspacing="0" id="update-themes-table">
301 <th scope="col" class="manage-column check-column"><input type="checkbox" id="themes-select-all" /></th>
302 <th scope="col" class="manage-column"><label for="themes-select-all"><?php _e('Select All'); ?></label></th>
308 <th scope="col" class="manage-column check-column"><input type="checkbox" id="themes-select-all-2" /></th>
309 <th scope="col" class="manage-column"><label for="themes-select-all-2"><?php _e('Select All'); ?></label></th>
312 <tbody class="plugins">
314 foreach ( (array) $themes as $stylesheet => $theme_data) {
315 $screenshot = $theme_data->{'Theme Root URI'} . '/' . $stylesheet . '/' . $theme_data->Screenshot;
319 <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . esc_attr($stylesheet) . "' /></th>
320 <td class='plugin-title'><img src='$screenshot' width='64' height='64' style='float:left; padding: 0 5px 5px' /><strong>{$theme_data->Name}</strong>" . sprintf(__('You have version %1$s installed. Update to %2$s.'), $theme_data->Version, $theme_data->update['new_version']) . "</td>
326 <p><input id="upgrade-themes-2" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
332 * Upgrade WordPress core display.
338 function do_core_upgrade( $reinstall = false ) {
339 global $wp_filesystem;
342 $url = 'update-core.php?action=do-core-reinstall';
344 $url = 'update-core.php?action=do-core-upgrade';
345 $url = wp_nonce_url($url, 'upgrade-core');
346 if ( false === ($credentials = request_filesystem_credentials($url, '', false, ABSPATH)) )
349 $version = isset( $_POST['version'] )? $_POST['version'] : false;
350 $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
351 $update = find_core_update( $version, $locale );
356 if ( ! WP_Filesystem($credentials, ABSPATH) ) {
357 request_filesystem_credentials($url, '', true, ABSPATH); //Failed to connect, Error and request again
362 <?php screen_icon('tools'); ?>
363 <h2><?php _e('Update WordPress'); ?></h2>
365 if ( $wp_filesystem->errors->get_error_code() ) {
366 foreach ( $wp_filesystem->errors->get_error_messages() as $message )
367 show_message($message);
373 $update->response = 'reinstall';
375 $result = wp_update_core($update, 'show_message');
377 if ( is_wp_error($result) ) {
378 show_message($result);
379 if ('up_to_date' != $result->get_error_code() )
380 show_message( __('Installation Failed') );
385 show_message( __('WordPress updated successfully') );
386 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="%s">here</a>.' ), $result, esc_url( admin_url( 'about.php?updated' ) ) ) . '</span>' );
387 show_message( '<span class="hide-if-js">' . sprintf( __( 'Welcome to WordPress %1$s. <a href="%2$s">Learn more</a>.' ), $result, esc_url( admin_url( 'about.php?updated' ) ) ) . '</span>' );
390 <script type="text/javascript">
391 window.location = '<?php echo admin_url( 'about.php?upgraded' ); ?>';
396 function do_dismiss_core_update() {
397 $version = isset( $_POST['version'] )? $_POST['version'] : false;
398 $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
399 $update = find_core_update( $version, $locale );
402 dismiss_core_update( $update );
403 wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
407 function do_undismiss_core_update() {
408 $version = isset( $_POST['version'] )? $_POST['version'] : false;
409 $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
410 $update = find_core_update( $version, $locale );
413 undismiss_core_update( $version, $locale );
414 wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
418 function no_update_actions($actions) {
422 $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
424 $upgrade_error = false;
425 if ( ( 'do-theme-upgrade' == $action || ( 'do-plugin-upgrade' == $action && ! isset( $_GET['plugins'] ) ) )
426 && ! isset( $_POST['checked'] ) ) {
427 $upgrade_error = $action == 'do-theme-upgrade' ? 'themes' : 'plugins';
428 $action = 'upgrade-core';
431 $title = __('WordPress Updates');
432 $parent_file = 'tools.php';
434 get_current_screen()->add_help_tab( array(
436 'title' => __('Overview'),
438 '<p>' . __('This screen lets you update to the latest version of WordPress as well as update your themes and plugins from the WordPress.org repository. When updates are available, the number of available updates will appear in a bubble on the left hand menu as a notification.') . '</p>' .
439 '<p>' . __('It is very important to keep your WordPress installation up to date for security reasons, so when you see a number appear, make sure you take the time to update, which is an easy process.') . '</p>'
442 get_current_screen()->add_help_tab( array(
443 'id' => 'how-to-update',
444 'title' => __('How to Update'),
446 '<p>' . __('Updating your WordPress installation is a simple one-click procedure; just click on the Update button when it says a new version is available.') . '</p>' .
447 '<p>' . __('To update themes or plugins from this screen, use the checkboxes to make your selection and click on the appropriate Update button. Check the box at the top of the Themes or Plugins section to select all and update them all at once.') . '</p>'
451 get_current_screen()->set_help_sidebar(
452 '<p><strong>' . __('For more information:') . '</strong></p>' .
453 '<p>' . __('<a href="http://codex.wordpress.org/Dashboard_Updates_Screen" target="_blank">Documentation on Updating WordPress</a>') . '</p>' .
454 '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
457 if ( 'upgrade-core' == $action ) {
460 require_once(ABSPATH . 'wp-admin/admin-header.php');
461 core_upgrade_preamble();
462 include(ABSPATH . 'wp-admin/admin-footer.php');
464 } elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
465 check_admin_referer('upgrade-core');
467 // do the (un)dismiss actions before headers,
468 // so that they can redirect
469 if ( isset( $_POST['dismiss'] ) )
470 do_dismiss_core_update();
471 elseif ( isset( $_POST['undismiss'] ) )
472 do_undismiss_core_update();
474 require_once(ABSPATH . 'wp-admin/admin-header.php');
475 if ( 'do-core-reinstall' == $action )
480 if ( isset( $_POST['upgrade'] ) )
481 do_core_upgrade($reinstall);
483 include(ABSPATH . 'wp-admin/admin-footer.php');
485 } elseif ( 'do-plugin-upgrade' == $action ) {
487 if ( ! current_user_can( 'update_plugins' ) )
488 wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
490 check_admin_referer('upgrade-core');
492 if ( isset( $_GET['plugins'] ) ) {
493 $plugins = explode( ',', $_GET['plugins'] );
494 } elseif ( isset( $_POST['checked'] ) ) {
495 $plugins = (array) $_POST['checked'];
497 wp_redirect( admin_url('update-core.php') );
501 $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
502 $url = wp_nonce_url($url, 'bulk-update-plugins');
504 $title = __('Update Plugins');
506 require_once(ABSPATH . 'wp-admin/admin-header.php');
507 echo '<div class="wrap">';
508 screen_icon('plugins');
509 echo '<h2>' . esc_html__('Update Plugins') . '</h2>';
510 echo "<iframe src='$url' style='width: 100%; height: 100%; min-height: 750px;' frameborder='0'></iframe>";
512 include(ABSPATH . 'wp-admin/admin-footer.php');
514 } elseif ( 'do-theme-upgrade' == $action ) {
516 if ( ! current_user_can( 'update_themes' ) )
517 wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
519 check_admin_referer('upgrade-core');
521 if ( isset( $_GET['themes'] ) ) {
522 $themes = explode( ',', $_GET['themes'] );
523 } elseif ( isset( $_POST['checked'] ) ) {
524 $themes = (array) $_POST['checked'];
526 wp_redirect( admin_url('update-core.php') );
530 $url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes));
531 $url = wp_nonce_url($url, 'bulk-update-themes');
533 $title = __('Update Themes');
535 require_once(ABSPATH . 'wp-admin/admin-header.php');
536 echo '<div class="wrap">';
537 screen_icon('themes');
538 echo '<h2>' . esc_html__('Update Themes') . '</h2>';
539 echo "<iframe src='$url' style='width: 100%; height: 100%; min-height: 750px;' frameborder='0'></iframe>";
541 include(ABSPATH . 'wp-admin/admin-footer.php');
544 do_action('update-core-custom_' . $action);