3 * Update Core administration panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('admin.php');
12 if ( ! current_user_can('update_plugins') )
13 wp_die(__('You do not have sufficient permissions to update plugins for this blog.'));
15 function list_core_update( $update ) {
16 $version_string = 'en_US' == $update->locale ?
17 $update->current : sprintf("%s–<strong>%s</strong>", $update->current, $update->locale);
19 if ( !isset($update->response) || 'latest' == $update->response )
21 $submit = __('Upgrade Automatically');
22 $form_action = 'update-core.php?action=do-core-upgrade';
23 if ( 'development' == $update->response ) {
24 $message = __('You are using a development version of WordPress. You can upgrade to the latest nightly build automatically or download the nightly build and install it manually:');
25 $download = __('Download nightly build');
28 $message = sprintf(__('You have the latest version of WordPress. You do not need to upgrade. However, if you want to re-install version %s, you can do so automatically or download the package and re-install manually:'), $version_string);
29 $submit = __('Re-install Automatically');
30 $form_action = 'update-core.php?action=do-core-reinstall';
32 $message = sprintf(__('You can upgrade to version %s automatically or download the package and install it manually:'), $version_string);
34 $download = sprintf(__('Download %s'), $version_string);
40 echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
41 wp_nonce_field('upgrade-core');
43 echo '<input id="upgrade" class="button" type="submit" value="' . $submit . '" name="upgrade" /> ';
44 echo '<input name="version" value="'.$update->current.'" type="hidden"/>';
45 echo '<input name="locale" value="'.$update->locale.'" type="hidden"/>';
46 echo '<a href="' . $update->package . '" class="button">' . $download . '</a> ';
47 if ( 'en_US' != $update->locale )
48 if ( !isset( $update->dismissed ) || !$update->dismissed )
49 echo '<input id="dismiss" class="button" type="submit" value="' . attribute_escape(__('Hide this update')) . '" name="dismiss" />';
51 echo '<input id="undismiss" class="button" type="submit" value="' . attribute_escape(__('Bring back this update')) . '" name="undismiss" />';
57 function dismissed_updates() {
58 $dismissed = get_core_updates( array( 'dismissed' => true, 'available' => false ) );
61 $show_text = js_escape(__('Show hidden updates'));
62 $hide_text = js_escape(__('Hide hidden updates'));
64 <script type="text/javascript">
67 $('dismissed-updates').show();
68 $('#show-dismissed').toggle(function(){$(this).text('<?php echo $hide_text; ?>');}, function() {$(this).text('<?php echo $show_text; ?>')});
69 $('#show-dismissed').click(function() { $('#dismissed-updates').toggle('slow');});
73 echo '<p class="hide-if-no-js"><a id="show-dismissed" href="#">'.__('Show hidden updates').'</a></p>';
74 echo '<ul id="dismissed-updates" class="core-updates dismissed">';
75 foreach( (array) $dismissed as $update) {
77 list_core_update( $update );
85 * Display upgrade WordPress for downloading latest or upgrading automatically form.
91 function core_upgrade_preamble() {
92 $updates = get_core_updates();
95 <?php screen_icon(); ?>
96 <h2><?php _e('Upgrade WordPress'); ?></h2>
98 if ( !isset($updates[0]->response) || 'latest' == $updates[0]->response ) {
100 _e('You have the latest version of WordPress. You do not need to upgrade');
103 echo '<div class="updated fade"><p>';
104 _e('<strong>Important:</strong> before upgrading, please <a href="http://codex.wordpress.org/WordPress_Backups">backup your database and files</a>.');
107 echo '<h3 class="response">';
108 _e( 'There is a new version of WordPress available for upgrade' );
112 echo '<ul class="core-updates">';
114 foreach( (array) $updates as $update ) {
115 $class = $alternate? ' class="alternate"' : '';
116 $alternate = !$alternate;
118 list_core_update( $update );
128 * Upgrade WordPress core display.
134 function do_core_upgrade( $reinstall = false ) {
135 global $wp_filesystem;
138 $url = 'update-core.php?action=do-core-reinstall';
140 $url = 'update-core.php?action=do-core-upgrade';
141 $url = wp_nonce_url($url, 'upgrade-core');
142 if ( false === ($credentials = request_filesystem_credentials($url)) )
145 $version = isset( $_POST['version'] )? $_POST['version'] : false;
146 $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
147 $update = find_core_update( $version, $locale );
152 if ( ! WP_Filesystem($credentials) ) {
153 request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again
158 <?php screen_icon(); ?>
159 <h2><?php _e('Upgrade WordPress'); ?></h2>
161 if ( $wp_filesystem->errors->get_error_code() ) {
162 foreach ( $wp_filesystem->errors->get_error_messages() as $message )
163 show_message($message);
169 $update->response = 'reinstall';
171 $result = wp_update_core($update, 'show_message');
173 if ( is_wp_error($result) ) {
174 show_message($result);
175 if ('up_to_date' != $result->get_error_code() )
176 show_message( __('Installation Failed') );
178 show_message( __('WordPress upgraded successfully') );
183 function do_dismiss_core_update() {
184 $version = isset( $_POST['version'] )? $_POST['version'] : false;
185 $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
186 $update = find_core_update( $version, $locale );
189 dismiss_core_update( $update );
190 wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
193 function do_undismiss_core_update() {
194 $version = isset( $_POST['version'] )? $_POST['version'] : false;
195 $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
196 $update = find_core_update( $version, $locale );
199 undismiss_core_update( $version, $locale );
200 wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
203 $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
205 if ( 'upgrade-core' == $action ) {
206 $title = __('Upgrade WordPress');
207 $parent_file = 'tools.php';
208 require_once('admin-header.php');
209 core_upgrade_preamble();
210 include('admin-footer.php');
211 } elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
212 check_admin_referer('upgrade-core');
213 $title = __('Upgrade WordPress');
214 $parent_file = 'tools.php';
215 // do the (un)dismiss actions before headers,
216 // so that they can redirect
217 if ( isset( $_POST['dismiss'] ) )
218 do_dismiss_core_update();
219 elseif ( isset( $_POST['undismiss'] ) )
220 do_undismiss_core_update();
221 require_once('admin-header.php');
222 if ( 'do-core-reinstall' == $action )
226 if ( isset( $_POST['upgrade'] ) )
227 do_core_upgrade($reinstall);
228 include('admin-footer.php');