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