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 global $wp_local_package;
17 $version_string = ('en_US' == $update->locale && 'en_US' == get_locale() ) ?
18 $update->current : sprintf("%s–<strong>%s</strong>", $update->current, $update->locale);
20 if ( !isset($update->response) || 'latest' == $update->response )
22 $submit = __('Upgrade Automatically');
23 $form_action = 'update-core.php?action=do-core-upgrade';
24 if ( 'development' == $update->response ) {
25 $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:');
26 $download = __('Download nightly build');
29 $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);
30 $submit = __('Re-install Automatically');
31 $form_action = 'update-core.php?action=do-core-reinstall';
33 $message = sprintf(__('You can upgrade to version %s automatically or download the package and install it manually:'), $version_string);
35 $download = sprintf(__('Download %s'), $version_string);
41 echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
42 wp_nonce_field('upgrade-core');
44 echo '<input id="upgrade" class="button" type="submit" value="' . esc_attr($submit) . '" name="upgrade" /> ';
45 echo '<input name="version" value="'. esc_attr($update->current) .'" type="hidden"/>';
46 echo '<input name="locale" value="'. esc_attr($update->locale) .'" type="hidden"/>';
47 echo '<a href="' . esc_url($update->package) . '" class="button">' . $download . '</a> ';
48 if ( 'en_US' != $update->locale )
49 if ( !isset( $update->dismissed ) || !$update->dismissed )
50 echo '<input id="dismiss" class="button" type="submit" value="' . esc_attr__('Hide this update') . '" name="dismiss" />';
52 echo '<input id="undismiss" class="button" type="submit" value="' . esc_attr__('Bring back this update') . '" name="undismiss" />';
54 if ( 'en_US' != $update->locale && ( !isset($wp_local_package) || $wp_local_package != $update->locale ) )
55 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>';
56 else if ( 'en_US' == $update->locale && get_locale() != 'en_US' ) {
57 echo '<p class="hint">'.sprintf( __('You are about to install WordPress %s <strong>in English.</strong> There is a chance this upgrade will break your translation. You may prefer to wait for the localized version to be released.'), $update->current ).'</p>';
63 function dismissed_updates() {
64 $dismissed = get_core_updates( array( 'dismissed' => true, 'available' => false ) );
67 $show_text = esc_js(__('Show hidden updates'));
68 $hide_text = esc_js(__('Hide hidden updates'));
70 <script type="text/javascript">
73 $('dismissed-updates').show();
74 $('#show-dismissed').toggle(function(){$(this).text('<?php echo $hide_text; ?>');}, function() {$(this).text('<?php echo $show_text; ?>')});
75 $('#show-dismissed').click(function() { $('#dismissed-updates').toggle('slow');});
79 echo '<p class="hide-if-no-js"><a id="show-dismissed" href="#">'.__('Show hidden updates').'</a></p>';
80 echo '<ul id="dismissed-updates" class="core-updates dismissed">';
81 foreach( (array) $dismissed as $update) {
83 list_core_update( $update );
91 * Display upgrade WordPress for downloading latest or upgrading automatically form.
97 function core_upgrade_preamble() {
98 global $upgrade_error;
100 $updates = get_core_updates();
103 <?php screen_icon(); ?>
104 <h2><?php _e('Upgrade WordPress'); ?></h2>
106 if ( $upgrade_error ) {
107 echo '<div class="error"><p>';
108 _e('Please select one or more plugins to upgrade.');
112 if ( !isset($updates[0]->response) || 'latest' == $updates[0]->response ) {
114 _e('You have the latest version of WordPress. You do not need to upgrade');
117 echo '<div class="updated fade"><p>';
118 _e('<strong>Important:</strong> before upgrading, please <a href="http://codex.wordpress.org/WordPress_Backups">backup your database and files</a>.');
121 echo '<h3 class="response">';
122 _e( 'There is a new version of WordPress available for upgrade' );
126 echo '<ul class="core-updates">';
128 foreach( (array) $updates as $update ) {
129 $class = $alternate? ' class="alternate"' : '';
130 $alternate = !$alternate;
132 list_core_update( $update );
138 list_plugin_updates();
139 //list_theme_updates();
140 do_action('core_upgrade_preamble');
144 function list_plugin_updates() {
147 $cur_wp_version = preg_replace('/-.*$/', '', $wp_version);
149 require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
150 $plugins = get_plugin_updates();
151 if ( empty($plugins) )
153 $form_action = 'update-core.php?action=do-plugin-upgrade';
155 $core_updates = get_core_updates();
156 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, '=') )
157 $core_update_version = false;
159 $core_update_version = $core_updates[0]->current;
161 <h3><?php _e('Plugins'); ?></h3>
162 <p><?php _e('The following plugins have new versions available. Check the ones you want to upgrade and then click "Upgrade Plugins".'); ?></p>
163 <form method="post" action="<?php echo $form_action; ?>" name="upgrade-plugins" class="upgrade">
164 <?php wp_nonce_field('upgrade-core'); ?>
165 <p><input id="upgrade-plugins" class="button" type="submit" value="<?php esc_attr_e('Upgrade Plugins'); ?>" name="upgrade" /></p>
166 <table class="widefat" cellspacing="0" id="update-plugins-table">
169 <th scope="col" class="manage-column check-column"><input type="checkbox" /></th>
170 <th scope="col" class="manage-column"><?php _e('Select All'); ?></th>
176 <th scope="col" class="manage-column check-column"><input type="checkbox" /></th>
177 <th scope="col" class="manage-column"><?php _e('Select All'); ?></th>
180 <tbody class="plugins">
182 foreach ( (array) $plugins as $plugin_file => $plugin_data) {
183 $info = plugins_api('plugin_information', array('slug' => $plugin_data->update->slug ));
184 // Get plugin compat for running version of WordPress.
185 if ( isset($info->tested) && version_compare($info->tested, $cur_wp_version, '>=') ) {
186 $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: 100%% (according to its author)'), $cur_wp_version);
187 } elseif ( isset($info->compatibility[$cur_wp_version][$plugin_data->update->new_version]) ) {
188 $compat = $info->compatibility[$cur_wp_version][$plugin_data->update->new_version];
189 $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]);
191 $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $cur_wp_version);
193 // Get plugin compat for updated version of WordPress.
194 if ( $core_update_version ) {
195 if ( isset($info->compatibility[$core_update_version][$plugin_data->update->new_version]) ) {
196 $update_compat = $info->compatibility[$core_update_version][$plugin_data->update->new_version];
197 $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]);
199 $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $core_update_version);
202 // Get the upgrade notice for the new plugin version.
203 if ( isset($plugin_data->update->upgrade_notice) ) {
204 $upgrade_notice = '<br />' . strip_tags($plugin_data->update->upgrade_notice);
206 $upgrade_notice = '';
210 <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' /></th>
211 <td class='plugin-title'><strong>{$plugin_data->Name}</strong>" . sprintf(__('You are running version %1$s. Upgrade to %2$s.'), $plugin_data->Version, $plugin_data->update->new_version) . $compat . $upgrade_notice . "</td>
217 <p><input id="upgrade-plugins-2" class="button" type="submit" value="<?php esc_attr_e('Upgrade Plugins'); ?>" name="upgrade" /></p>
222 function list_theme_updates() {
223 $themes = get_theme_updates();
224 if ( empty($themes) )
227 <h3><?php _e('Themes'); ?></h3>
228 <table class="widefat" cellspacing="0" id="update-themes-table">
231 <th scope="col" class="manage-column check-column"><input type="checkbox" /></th>
232 <th scope="col" class="manage-column"><?php _e('Name'); ?></th>
238 <th scope="col" class="manage-column check-column"><input type="checkbox" /></th>
239 <th scope="col" class="manage-column"><?php _e('Name'); ?></th>
242 <tbody class="plugins">
244 foreach ( (array) $themes as $stylesheet => $theme_data) {
247 <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . esc_attr($stylesheet) . "' /></th>
248 <td class='plugin-title'><strong>{$theme_data->Name}</strong></td>
258 * Upgrade WordPress core display.
264 function do_core_upgrade( $reinstall = false ) {
265 global $wp_filesystem;
268 $url = 'update-core.php?action=do-core-reinstall';
270 $url = 'update-core.php?action=do-core-upgrade';
271 $url = wp_nonce_url($url, 'upgrade-core');
272 if ( false === ($credentials = request_filesystem_credentials($url, '', false, ABSPATH)) )
275 $version = isset( $_POST['version'] )? $_POST['version'] : false;
276 $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
277 $update = find_core_update( $version, $locale );
282 if ( ! WP_Filesystem($credentials, ABSPATH) ) {
283 request_filesystem_credentials($url, '', true, ABSPATH); //Failed to connect, Error and request again
288 <?php screen_icon(); ?>
289 <h2><?php _e('Upgrade WordPress'); ?></h2>
291 if ( $wp_filesystem->errors->get_error_code() ) {
292 foreach ( $wp_filesystem->errors->get_error_messages() as $message )
293 show_message($message);
299 $update->response = 'reinstall';
301 $result = wp_update_core($update, 'show_message');
303 if ( is_wp_error($result) ) {
304 show_message($result);
305 if ('up_to_date' != $result->get_error_code() )
306 show_message( __('Installation Failed') );
308 show_message( __('WordPress upgraded successfully') );
313 function do_dismiss_core_update() {
314 $version = isset( $_POST['version'] )? $_POST['version'] : false;
315 $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
316 $update = find_core_update( $version, $locale );
319 dismiss_core_update( $update );
320 wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
323 function do_undismiss_core_update() {
324 $version = isset( $_POST['version'] )? $_POST['version'] : false;
325 $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
326 $update = find_core_update( $version, $locale );
329 undismiss_core_update( $version, $locale );
330 wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
333 function no_update_actions($actions) {
337 function do_plugin_upgrade() {
338 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
340 if ( isset($_GET['plugins']) ) {
341 $plugins = explode(',', $_GET['plugins']);
342 } elseif ( isset($_POST['checked']) ) {
343 $plugins = (array) $_POST['checked'];
348 $url = 'update-core.php?action=do-plugin-upgrade&plugins=' . urlencode(join(',', $plugins));
349 $title = __('Upgrade Plugins');
350 $nonce = 'upgrade-core';
351 $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) );
352 $upgrader->bulk_upgrade($plugins);
355 $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
357 $upgrade_error = false;
358 if ( 'do-plugin-upgrade' == $action && !isset($_GET['plugins']) && !isset($_POST['checked']) ) {
359 $upgrade_error = true;
360 $action = 'upgrade-core';
363 $title = __('Upgrade WordPress');
364 $parent_file = 'tools.php';
366 if ( 'upgrade-core' == $action ) {
368 require_once('admin-header.php');
369 core_upgrade_preamble();
370 } elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
371 check_admin_referer('upgrade-core');
372 // do the (un)dismiss actions before headers,
373 // so that they can redirect
374 if ( isset( $_POST['dismiss'] ) )
375 do_dismiss_core_update();
376 elseif ( isset( $_POST['undismiss'] ) )
377 do_undismiss_core_update();
378 require_once('admin-header.php');
379 if ( 'do-core-reinstall' == $action )
383 if ( isset( $_POST['upgrade'] ) )
384 do_core_upgrade($reinstall);
385 } elseif ( 'do-plugin-upgrade' == $action ) {
386 check_admin_referer('upgrade-core');
387 require_once('admin-header.php');
391 include('admin-footer.php');