]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/update-core.php
Wordpress 3.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('./admin.php');
11
12 if ( is_multisite() && ! is_network_admin() ) {
13         wp_redirect( network_admin_url( 'update-core.php' ) );
14         exit();
15 }
16
17 if ( ! current_user_can( 'update_core' ) )
18         wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
19
20 function list_core_update( $update ) {
21         global $wp_local_package, $wpdb;
22         static $first_pass = true;
23
24         $version_string = ('en_US' == $update->locale && 'en_US' == get_locale() ) ?
25                         $update->current : sprintf("%s&ndash;<strong>%s</strong>", $update->current, $update->locale);
26         $current = false;
27         if ( !isset($update->response) || 'latest' == $update->response )
28                 $current = true;
29         $submit = __('Update Now');
30         $form_action = 'update-core.php?action=do-core-upgrade';
31         $php_version    = phpversion();
32         $mysql_version  = $wpdb->db_version();
33         $show_buttons = true;
34         if ( 'development' == $update->response ) {
35                 $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:');
36                 $download = __('Download nightly build');
37         } else {
38                 if ( $current ) {
39                         $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);
40                         $submit = __('Re-install Now');
41                         $form_action = 'update-core.php?action=do-core-reinstall';
42                 } else {
43                         $php_compat     = version_compare( $php_version, $update->php_version, '>=' );
44                         $mysql_compat   = version_compare( $mysql_version, $update->mysql_version, '>=' ) || file_exists( WP_CONTENT_DIR . '/db.php' );
45                         if ( !$mysql_compat && !$php_compat )
46                                 $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 );
47                         elseif ( !$php_compat )
48                                 $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 );
49                         elseif ( !$mysql_compat )
50                                 $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 );
51                         else
52                                 $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);
53                         if ( !$mysql_compat || !$php_compat )
54                                 $show_buttons = false;
55                 }
56                 $download = sprintf(__('Download %s'), $version_string);
57         }
58
59         echo '<p>';
60         echo $message;
61         echo '</p>';
62         echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
63         wp_nonce_field('upgrade-core');
64         echo '<p>';
65         echo '<input name="version" value="'. esc_attr($update->current) .'" type="hidden"/>';
66         echo '<input name="locale" value="'. esc_attr($update->locale) .'" type="hidden"/>';
67         if ( $show_buttons ) {
68                 if ( $first_pass ) {
69                         submit_button( $submit, 'button button-primary', 'upgrade', false );
70                         $first_pass = false;
71                 } else {
72                         submit_button( $submit, 'button', 'upgrade', false );
73                 }
74                 echo '&nbsp;<a href="' . esc_url( $update->download ) . '" class="button">' . $download . '</a>&nbsp;';
75         }
76         if ( 'en_US' != $update->locale )
77                 if ( !isset( $update->dismissed ) || !$update->dismissed )
78                         submit_button( __('Hide this update'), 'button', 'dismiss', false );
79                 else
80                         submit_button( __('Bring back this update'), 'button', 'undismiss', false );
81         echo '</p>';
82         if ( 'en_US' != $update->locale && ( !isset($wp_local_package) || $wp_local_package != $update->locale ) )
83             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>';
84         else if ( 'en_US' == $update->locale && get_locale() != 'en_US' ) {
85             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>';
86         }
87         echo '</form>';
88
89 }
90
91 function dismissed_updates() {
92         $dismissed = get_core_updates( array( 'dismissed' => true, 'available' => false ) );
93         if ( $dismissed ) {
94
95                 $show_text = esc_js(__('Show hidden updates'));
96                 $hide_text = esc_js(__('Hide hidden updates'));
97         ?>
98         <script type="text/javascript">
99
100                 jQuery(function($) {
101                         $('dismissed-updates').show();
102                         $('#show-dismissed').toggle(function(){$(this).text('<?php echo $hide_text; ?>');}, function() {$(this).text('<?php echo $show_text; ?>')});
103                         $('#show-dismissed').click(function() { $('#dismissed-updates').toggle('slow');});
104                 });
105         </script>
106         <?php
107                 echo '<p class="hide-if-no-js"><a id="show-dismissed" href="#">'.__('Show hidden updates').'</a></p>';
108                 echo '<ul id="dismissed-updates" class="core-updates dismissed">';
109                 foreach( (array) $dismissed as $update) {
110                         echo '<li>';
111                         list_core_update( $update );
112                         echo '</li>';
113                 }
114                 echo '</ul>';
115         }
116 }
117
118 /**
119  * Display upgrade WordPress for downloading latest or upgrading automatically form.
120  *
121  * @since 2.7
122  *
123  * @return null
124  */
125 function core_upgrade_preamble() {
126         global $upgrade_error;
127
128         $updates = get_core_updates();
129 ?>
130         <div class="wrap">
131         <?php screen_icon('tools'); ?>
132         <h2><?php _e('WordPress Updates'); ?></h2>
133 <?php
134         if ( $upgrade_error ) {
135                 echo '<div class="error"><p>';
136                 if ( $upgrade_error == 'themes' )
137                         _e('Please select one or more themes to update.');
138                 else
139                         _e('Please select one or more plugins to update.');
140                 echo '</p></div>';
141         }
142
143         echo '<p>';
144         /* translators: %1 date, %2 time. */
145         printf( __('Last checked on %1$s at %2$s.'), date_i18n( get_option( 'date_format' ) ), date_i18n( get_option( 'time_format' ) ) );
146         echo ' &nbsp; <a class="button" href="' . esc_url( self_admin_url('update-core.php') ) . '">' . __( 'Check Again' ) . '</a>';
147         echo '</p>';
148
149         if ( !isset($updates[0]->response) || 'latest' == $updates[0]->response ) {
150                 echo '<h3>';
151                 _e('You have the latest version of WordPress.');
152                 echo '</h3>';
153         } else {
154                 echo '<div class="updated inline"><p>';
155                 _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.');
156                 echo '</p></div>';
157
158                 echo '<h3 class="response">';
159                 _e( 'An updated version of WordPress is available.' );
160                 echo '</h3>';
161         }
162
163         echo '<ul class="core-updates">';
164         $alternate = true;
165         foreach( (array) $updates as $update ) {
166                 echo '<li>';
167                 list_core_update( $update );
168                 echo '</li>';
169         }
170         echo '</ul>';
171         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>';
172         dismissed_updates();
173
174         if ( current_user_can( 'update_plugins' ) )
175                 list_plugin_updates();
176         if ( current_user_can( 'update_themes' ) )
177                 list_theme_updates();
178         do_action('core_upgrade_preamble');
179         echo '</div>';
180 }
181
182 function list_plugin_updates() {
183         global $wp_version;
184
185         $cur_wp_version = preg_replace('/-.*$/', '', $wp_version);
186
187         require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
188         $plugins = get_plugin_updates();
189         if ( empty( $plugins ) ) {
190                 echo '<h3>' . __( 'Plugins' ) . '</h3>';
191                 echo '<p>' . __( 'Your plugins are all up to date.' ) . '</p>';
192                 return;
193         }
194         $form_action = 'update-core.php?action=do-plugin-upgrade';
195
196         $core_updates = get_core_updates();
197         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, '=') )
198                 $core_update_version = false;
199         else
200                 $core_update_version = $core_updates[0]->current;
201         ?>
202 <h3><?php _e( 'Plugins' ); ?></h3>
203 <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>
204 <form method="post" action="<?php echo $form_action; ?>" name="upgrade-plugins" class="upgrade">
205 <?php wp_nonce_field('upgrade-core'); ?>
206 <p><input id="upgrade-plugins" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
207 <table class="widefat" cellspacing="0" id="update-plugins-table">
208         <thead>
209         <tr>
210                 <th scope="col" class="manage-column check-column"><input type="checkbox" id="plugins-select-all" /></th>
211                 <th scope="col" class="manage-column"><label for="plugins-select-all"><?php _e('Select All'); ?></label></th>
212         </tr>
213         </thead>
214
215         <tfoot>
216         <tr>
217                 <th scope="col" class="manage-column check-column"><input type="checkbox" id="plugins-select-all-2" /></th>
218                 <th scope="col" class="manage-column"><label for="plugins-select-all-2"><?php _e('Select All'); ?></label></th>
219         </tr>
220         </tfoot>
221         <tbody class="plugins">
222 <?php
223         foreach ( (array) $plugins as $plugin_file => $plugin_data) {
224                 $info = plugins_api('plugin_information', array('slug' => $plugin_data->update->slug ));
225                 // Get plugin compat for running version of WordPress.
226                 if ( isset($info->tested) && version_compare($info->tested, $cur_wp_version, '>=') ) {
227                         $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: 100%% (according to its author)'), $cur_wp_version);
228                 } elseif ( isset($info->compatibility[$cur_wp_version][$plugin_data->update->new_version]) ) {
229                         $compat = $info->compatibility[$cur_wp_version][$plugin_data->update->new_version];
230                         $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]);
231                 } else {
232                         $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $cur_wp_version);
233                 }
234                 // Get plugin compat for updated version of WordPress.
235                 if ( $core_update_version ) {
236                         if ( isset($info->compatibility[$core_update_version][$plugin_data->update->new_version]) ) {
237                                 $update_compat = $info->compatibility[$core_update_version][$plugin_data->update->new_version];
238                                 $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]);
239                         } else {
240                                 $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $core_update_version);
241                         }
242                 }
243                 // Get the upgrade notice for the new plugin version.
244                 if ( isset($plugin_data->update->upgrade_notice) ) {
245                         $upgrade_notice = '<br />' . strip_tags($plugin_data->update->upgrade_notice);
246                 } else {
247                         $upgrade_notice = '';
248                 }
249                 echo "
250         <tr class='active'>
251                 <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' /></th>
252                 <td><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) . $compat . $upgrade_notice . "</td>
253         </tr>";
254         }
255 ?>
256         </tbody>
257 </table>
258 <p><input id="upgrade-plugins-2" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
259 </form>
260 <?php
261 }
262
263 function list_theme_updates() {
264         $themes = get_theme_updates();
265         if ( empty( $themes ) ) {
266                 echo '<h3>' . __( 'Themes' ) . '</h3>';
267                 echo '<p>' . __( 'Your themes are all up to date.' ) . '</p>';
268                 return;
269         }
270
271         $form_action = 'update-core.php?action=do-theme-upgrade';
272
273 ?>
274 <h3><?php _e( 'Themes' ); ?></h3>
275 <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>
276 <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>
277 <form method="post" action="<?php echo $form_action; ?>" name="upgrade-themes" class="upgrade">
278 <?php wp_nonce_field('upgrade-core'); ?>
279 <p><input id="upgrade-themes" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
280 <table class="widefat" cellspacing="0" id="update-themes-table">
281         <thead>
282         <tr>
283                 <th scope="col" class="manage-column check-column"><input type="checkbox" id="themes-select-all" /></th>
284                 <th scope="col" class="manage-column"><label for="themes-select-all"><?php _e('Select All'); ?></label></th>
285         </tr>
286         </thead>
287
288         <tfoot>
289         <tr>
290                 <th scope="col" class="manage-column check-column"><input type="checkbox" id="themes-select-all-2" /></th>
291                 <th scope="col" class="manage-column"><label for="themes-select-all-2"><?php _e('Select All'); ?></label></th>
292         </tr>
293         </tfoot>
294         <tbody class="plugins">
295 <?php
296         foreach ( (array) $themes as $stylesheet => $theme_data) {
297                 $screenshot = $theme_data->{'Theme Root URI'} . '/' . $stylesheet . '/' . $theme_data->Screenshot;
298
299                 echo "
300         <tr class='active'>
301                 <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . esc_attr($stylesheet) . "' /></th>
302                 <td class='plugin-title'><img src='$screenshot' width='64' height='64' style='float:left; padding: 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>
303         </tr>";
304         }
305 ?>
306         </tbody>
307 </table>
308 <p><input id="upgrade-themes-2" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
309 </form>
310 <?php
311 }
312
313 /**
314  * Upgrade WordPress core display.
315  *
316  * @since 2.7
317  *
318  * @return null
319  */
320 function do_core_upgrade( $reinstall = false ) {
321         global $wp_filesystem;
322
323         if ( $reinstall )
324                 $url = 'update-core.php?action=do-core-reinstall';
325         else
326                 $url = 'update-core.php?action=do-core-upgrade';
327         $url = wp_nonce_url($url, 'upgrade-core');
328         if ( false === ($credentials = request_filesystem_credentials($url, '', false, ABSPATH)) )
329                 return;
330
331         $version = isset( $_POST['version'] )? $_POST['version'] : false;
332         $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
333         $update = find_core_update( $version, $locale );
334         if ( !$update )
335                 return;
336
337
338         if ( ! WP_Filesystem($credentials, ABSPATH) ) {
339                 request_filesystem_credentials($url, '', true, ABSPATH); //Failed to connect, Error and request again
340                 return;
341         }
342 ?>
343         <div class="wrap">
344         <?php screen_icon('tools'); ?>
345         <h2><?php _e('Update WordPress'); ?></h2>
346 <?php
347         if ( $wp_filesystem->errors->get_error_code() ) {
348                 foreach ( $wp_filesystem->errors->get_error_messages() as $message )
349                         show_message($message);
350                 echo '</div>';
351                 return;
352         }
353
354         if ( $reinstall )
355                 $update->response = 'reinstall';
356
357         $result = wp_update_core($update, 'show_message');
358
359         if ( is_wp_error($result) ) {
360                 show_message($result);
361                 if ('up_to_date' != $result->get_error_code() )
362                         show_message( __('Installation Failed') );
363         } else {
364                 show_message( __('WordPress updated successfully') );
365                 show_message( '<a href="' . esc_url( self_admin_url() ) . '">' . __('Go to Dashboard') . '</a>' );
366         }
367         echo '</div>';
368 }
369
370 function do_dismiss_core_update() {
371         $version = isset( $_POST['version'] )? $_POST['version'] : false;
372         $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
373         $update = find_core_update( $version, $locale );
374         if ( !$update )
375                 return;
376         dismiss_core_update( $update );
377         wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
378         exit;
379 }
380
381 function do_undismiss_core_update() {
382         $version = isset( $_POST['version'] )? $_POST['version'] : false;
383         $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
384         $update = find_core_update( $version, $locale );
385         if ( !$update )
386                 return;
387         undismiss_core_update( $version, $locale );
388         wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
389         exit;
390 }
391
392 function no_update_actions($actions) {
393         return '';
394 }
395
396 $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
397
398 $upgrade_error = false;
399 if ( ( 'do-theme-upgrade' == $action || ( 'do-plugin-upgrade' == $action && ! isset( $_GET['plugins'] ) ) )
400         && ! isset( $_POST['checked'] ) ) {
401         $upgrade_error = $action == 'do-theme-upgrade' ? 'themes' : 'plugins';
402         $action = 'upgrade-core';
403 }
404
405 $title = __('WordPress Updates');
406 $parent_file = 'tools.php';
407
408 add_contextual_help($current_screen,
409         '<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. 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>' .
410         '<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>' .
411         '<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>' .
412         '<p><strong>' . __('For more information:') . '</strong></p>' .
413         '<p>' . __('<a href="http://codex.wordpress.org/Dashboard_Updates_Screen" target="_blank">Documentation on Updating WordPress</a>') . '</p>' .
414         '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
415 );
416
417 if ( 'upgrade-core' == $action ) {
418
419         wp_version_check();
420         require_once(ABSPATH . 'wp-admin/admin-header.php');
421         core_upgrade_preamble();
422         include(ABSPATH . 'wp-admin/admin-footer.php');
423
424 } elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
425         check_admin_referer('upgrade-core');
426
427         // do the (un)dismiss actions before headers,
428         // so that they can redirect
429         if ( isset( $_POST['dismiss'] ) )
430                 do_dismiss_core_update();
431         elseif ( isset( $_POST['undismiss'] ) )
432                 do_undismiss_core_update();
433
434         require_once(ABSPATH . 'wp-admin/admin-header.php');
435         if ( 'do-core-reinstall' == $action )
436                 $reinstall = true;
437         else
438                 $reinstall = false;
439
440         if ( isset( $_POST['upgrade'] ) )
441                 do_core_upgrade($reinstall);
442
443         include(ABSPATH . 'wp-admin/admin-footer.php');
444
445 } elseif ( 'do-plugin-upgrade' == $action ) {
446
447         if ( ! current_user_can( 'update_plugins' ) )
448                 wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
449
450         check_admin_referer('upgrade-core');
451
452         if ( isset( $_GET['plugins'] ) ) {
453                 $plugins = explode( ',', $_GET['plugins'] );
454         } elseif ( isset( $_POST['checked'] ) ) {
455                 $plugins = (array) $_POST['checked'];
456         } else {
457                 wp_redirect( admin_url('update-core.php') );
458                 exit;
459         }
460
461         $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
462         $url = wp_nonce_url($url, 'bulk-update-plugins');
463
464         $title = __('Update Plugins');
465
466         require_once(ABSPATH . 'wp-admin/admin-header.php');
467         echo '<div class="wrap">';
468         screen_icon('plugins');
469         echo '<h2>' . esc_html__('Update Plugins') . '</h2>';
470         echo "<iframe src='$url' style='width: 100%; height: 100%; min-height: 750px;' frameborder='0'></iframe>";
471         echo '</div>';
472         include(ABSPATH . 'wp-admin/admin-footer.php');
473
474 } elseif ( 'do-theme-upgrade' == $action ) {
475
476         if ( ! current_user_can( 'update_themes' ) )
477                 wp_die( __( 'You do not have sufficient permissions to update this site.' ) );
478
479         check_admin_referer('upgrade-core');
480
481         if ( isset( $_GET['themes'] ) ) {
482                 $themes = explode( ',', $_GET['themes'] );
483         } elseif ( isset( $_POST['checked'] ) ) {
484                 $themes = (array) $_POST['checked'];
485         } else {
486                 wp_redirect( admin_url('update-core.php') );
487                 exit;
488         }
489
490         $url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes));
491         $url = wp_nonce_url($url, 'bulk-update-themes');
492
493         $title = __('Update Themes');
494
495         require_once(ABSPATH . 'wp-admin/admin-header.php');
496         echo '<div class="wrap">';
497         screen_icon('themes');
498         echo '<h2>' . esc_html__('Update Themes') . '</h2>';
499         echo "<iframe src='$url' style='width: 100%; height: 100%; min-height: 750px;' frameborder='0'></iframe>";
500         echo '</div>';
501         include(ABSPATH . 'wp-admin/admin-footer.php');
502
503 } else {
504         do_action('update-core-custom_' . $action);
505 }