[ Index ]

PHP Cross Reference of WordPress 3.0 beta 1

[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/wp-admin/ -> update-core.php (source)

   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 blog.'));
  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&ndash;<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" />&nbsp;';
  62          echo '<a href="' . esc_url($update->package) . '" class="button">' . $download . '</a>&nbsp;';
  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. You do not need to update');
 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 Codex page</a>.');
 135          echo '</p></div>';
 136  
 137          echo '<h3 class="response">';
 138          _e( 'There is a new version of WordPress available for update' );
 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      dismissed_updates();
 153  
 154      list_plugin_updates();
 155      list_theme_updates();
 156      do_action('core_upgrade_preamble');
 157      echo '</div>';
 158  }
 159  
 160  function list_plugin_updates() {
 161      global $wp_version;
 162  
 163      $cur_wp_version = preg_replace('/-.*$/', '', $wp_version);
 164  
 165      require_once (ABSPATH . 'wp-admin/includes/plugin-install.php');
 166      $plugins = get_plugin_updates();
 167      if ( empty($plugins) )
 168          return;
 169      $form_action = 'update-core.php?action=do-plugin-upgrade';
 170  
 171      $core_updates = get_core_updates();
 172      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, '=') )
 173          $core_update_version = false;
 174      else
 175          $core_update_version = $core_updates[0]->current;
 176      ?>
 177  <h3><?php _e('Plugins'); ?></h3>
 178  <p><?php _e('The following plugins have new versions available. Check the ones you want to update and then click "Update Plugins".'); ?></p>
 179  <form method="post" action="<?php echo $form_action; ?>" name="upgrade-plugins" class="upgrade">
 180  <?php wp_nonce_field('upgrade-core'); ?>
 181  <p><input id="upgrade-plugins" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
 182  <table class="widefat" cellspacing="0" id="update-plugins-table">
 183      <thead>
 184      <tr>
 185          <th scope="col" class="manage-column check-column"><input type="checkbox" /></th>
 186          <th scope="col" class="manage-column"><?php _e('Select All'); ?></th>
 187      </tr>
 188      </thead>
 189  
 190      <tfoot>
 191      <tr>
 192          <th scope="col" class="manage-column check-column"><input type="checkbox" /></th>
 193          <th scope="col" class="manage-column"><?php _e('Select All'); ?></th>
 194      </tr>
 195      </tfoot>
 196      <tbody class="plugins">
 197  <?php
 198      foreach ( (array) $plugins as $plugin_file => $plugin_data) {
 199          $info = plugins_api('plugin_information', array('slug' => $plugin_data->update->slug ));
 200          // Get plugin compat for running version of WordPress.
 201          if ( isset($info->tested) && version_compare($info->tested, $cur_wp_version, '>=') ) {
 202              $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: 100%% (according to its author)'), $cur_wp_version);
 203          } elseif ( isset($info->compatibility[$cur_wp_version][$plugin_data->update->new_version]) ) {
 204              $compat = $info->compatibility[$cur_wp_version][$plugin_data->update->new_version];
 205              $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]);
 206          } else {
 207              $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $cur_wp_version);
 208          }
 209          // Get plugin compat for updated version of WordPress.
 210          if ( $core_update_version ) {
 211              if ( isset($info->compatibility[$core_update_version][$plugin_data->update->new_version]) ) {
 212                  $update_compat = $info->compatibility[$core_update_version][$plugin_data->update->new_version];
 213                  $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]);
 214              } else {
 215                  $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $core_update_version);
 216              }
 217          }
 218          // Get the upgrade notice for the new plugin version.
 219          if ( isset($plugin_data->update->upgrade_notice) ) {
 220              $upgrade_notice = '<br />' . strip_tags($plugin_data->update->upgrade_notice);
 221          } else {
 222              $upgrade_notice = '';
 223          }
 224          echo "
 225      <tr class='active'>
 226          <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' /></th>
 227          <td class='plugin-title'><strong>{$plugin_data->Name}</strong>" . sprintf(__('You are running version %1$s. Update to %2$s.'), $plugin_data->Version, $plugin_data->update->new_version) . $compat . $upgrade_notice . "</td>
 228      </tr>";
 229      }
 230  ?>
 231      </tbody>
 232  </table>
 233  <p><input id="upgrade-plugins-2" class="button" type="submit" value="<?php esc_attr_e('Update Plugins'); ?>" name="upgrade" /></p>
 234  </form>
 235  <?php
 236  }
 237  
 238  function list_theme_updates() {
 239      $themes = get_theme_updates();
 240      if ( empty($themes) )
 241          return;
 242  
 243      $form_action = 'update-core.php?action=do-theme-upgrade';
 244  
 245  ?>
 246  <h3><?php _e('Themes'); ?></h3>
 247  <p><?php _e('The following themes have new versions available. Check the ones you want to update and then click "Update Themes".'); ?></p>
 248  <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.'), 'http://codex.wordpress.org/Theme_Development#Child_Themes_style.css' ); ?></p>
 249  <form method="post" action="<?php echo $form_action; ?>" name="upgrade-themes" class="upgrade">
 250  <?php wp_nonce_field('upgrade-core'); ?>
 251  <p><input id="upgrade-themes" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
 252  <table class="widefat" cellspacing="0" id="update-themes-table">
 253      <thead>
 254      <tr>
 255          <th scope="col" class="manage-column check-column"><input type="checkbox" /></th>
 256          <th scope="col" class="manage-column"><?php _e('Theme'); ?></th>
 257      </tr>
 258      </thead>
 259  
 260      <tfoot>
 261      <tr>
 262          <th scope="col" class="manage-column check-column"><input type="checkbox" /></th>
 263          <th scope="col" class="manage-column"><?php _e('Theme'); ?></th>
 264      </tr>
 265      </tfoot>
 266      <tbody class="plugins">
 267  <?php
 268      foreach ( (array) $themes as $stylesheet => $theme_data) {
 269          $screenshot = $theme_data->{'Theme Root URI'} . '/' . $stylesheet . '/' . $theme_data->Screenshot;
 270  
 271          echo "
 272      <tr class='active'>
 273          <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . esc_attr($stylesheet) . "' /></th>
 274          <td class='plugin-title'><img src='$screenshot' width='64' height='64' style='float:left; padding: 5px' /><strong>{$theme_data->Name}</strong>" .  sprintf(__('You are running version %1$s. Update to %2$s.'), $theme_data->Version, $theme_data->update['new_version']) . "</td>
 275      </tr>";
 276      }
 277  ?>
 278      </tbody>
 279  </table>
 280  <p><input id="upgrade-themes-2" class="button" type="submit" value="<?php esc_attr_e('Update Themes'); ?>" name="upgrade" /></p>
 281  </form>
 282  <?php
 283  }
 284  
 285  /**
 286   * Upgrade WordPress core display.
 287   *
 288   * @since 2.7
 289   *
 290   * @return null
 291   */
 292  function do_core_upgrade( $reinstall = false ) {
 293      global $wp_filesystem;
 294  
 295      if ( $reinstall )
 296          $url = 'update-core.php?action=do-core-reinstall';
 297      else
 298          $url = 'update-core.php?action=do-core-upgrade';
 299      $url = wp_nonce_url($url, 'upgrade-core');
 300      if ( false === ($credentials = request_filesystem_credentials($url, '', false, ABSPATH)) )
 301          return;
 302  
 303      $version = isset( $_POST['version'] )? $_POST['version'] : false;
 304      $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
 305      $update = find_core_update( $version, $locale );
 306      if ( !$update )
 307          return;
 308  
 309  
 310      if ( ! WP_Filesystem($credentials, ABSPATH) ) {
 311          request_filesystem_credentials($url, '', true, ABSPATH); //Failed to connect, Error and request again
 312          return;
 313      }
 314  ?>
 315      <div class="wrap">
 316      <?php screen_icon(); ?>
 317      <h2><?php _e('Update WordPress'); ?></h2>
 318  <?php
 319      if ( $wp_filesystem->errors->get_error_code() ) {
 320          foreach ( $wp_filesystem->errors->get_error_messages() as $message )
 321              show_message($message);
 322          echo '</div>';
 323          return;
 324      }
 325  
 326      if ( $reinstall )
 327          $update->response = 'reinstall';
 328  
 329      $result = wp_update_core($update, 'show_message');
 330  
 331      if ( is_wp_error($result) ) {
 332          show_message($result);
 333          if ('up_to_date' != $result->get_error_code() )
 334              show_message( __('Installation Failed') );
 335      } else {
 336          show_message( __('WordPress updated successfully') );
 337          show_message( '<strong>' . __('Actions:') . '</strong> <a href="' . esc_url( admin_url() ) . '">' . __('Go to Dashboard') . '</a>' );
 338      }
 339      echo '</div>';
 340  }
 341  
 342  function do_dismiss_core_update() {
 343      $version = isset( $_POST['version'] )? $_POST['version'] : false;
 344      $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
 345      $update = find_core_update( $version, $locale );
 346      if ( !$update )
 347          return;
 348      dismiss_core_update( $update );
 349      wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
 350  }
 351  
 352  function do_undismiss_core_update() {
 353      $version = isset( $_POST['version'] )? $_POST['version'] : false;
 354      $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
 355      $update = find_core_update( $version, $locale );
 356      if ( !$update )
 357          return;
 358      undismiss_core_update( $version, $locale );
 359      wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
 360  }
 361  
 362  function no_update_actions($actions) {
 363      return '';
 364  }
 365  
 366  $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
 367  
 368  $upgrade_error = false;
 369  if ( 'do-plugin-upgrade' == $action && !isset($_GET['plugins']) && !isset($_POST['checked']) ) {
 370      $upgrade_error = true;
 371      $action = 'upgrade-core';
 372  }
 373  
 374  $title = __('WordPress Updates');
 375  $parent_file = 'tools.php';
 376  
 377  if ( 'upgrade-core' == $action ) {
 378      wp_version_check();
 379      require_once ('admin-header.php');
 380      core_upgrade_preamble();
 381  } elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
 382      check_admin_referer('upgrade-core');
 383  
 384      // do the (un)dismiss actions before headers,
 385      // so that they can redirect
 386      if ( isset( $_POST['dismiss'] ) )
 387          do_dismiss_core_update();
 388      elseif ( isset( $_POST['undismiss'] ) )
 389          do_undismiss_core_update();
 390  
 391      require_once ('admin-header.php');
 392      if ( 'do-core-reinstall' == $action )
 393          $reinstall = true;
 394      else
 395          $reinstall = false;
 396  
 397      if ( isset( $_POST['upgrade'] ) )
 398          do_core_upgrade($reinstall);
 399  
 400  } elseif ( 'do-plugin-upgrade' == $action ) {
 401      check_admin_referer('upgrade-core');
 402  
 403      if ( isset( $_GET['plugins'] ) ) {
 404          $plugins = explode( ',', $_GET['plugins'] );
 405      } elseif ( isset( $_POST['checked'] ) ) {
 406          $plugins = (array) $_POST['checked'];
 407      } else {
 408          wp_redirect('update-core.php');
 409          exit;
 410      }
 411  
 412      $url = 'update.php?action=update-selected&plugins=' . urlencode(implode(',', $plugins));
 413      $url = wp_nonce_url($url, 'bulk-update-plugins');
 414  
 415      $title = __('Update Plugins');
 416  
 417      require_once ('admin-header.php');
 418      echo '<div class="wrap">';
 419      screen_icon('plugins');
 420      echo '<h2>' . esc_html__('Update Plugins') . '</h2>';
 421      echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
 422      echo '</div>';
 423  } elseif ( 'do-theme-upgrade' == $action ) {
 424      check_admin_referer('upgrade-core');
 425  
 426      if ( isset( $_GET['themes'] ) ) {
 427          $themes = explode( ',', $_GET['themes'] );
 428      } elseif ( isset( $_POST['checked'] ) ) {
 429          $themes = (array) $_POST['checked'];
 430      } else {
 431          wp_redirect('update-core.php');
 432          exit;
 433      }
 434  
 435      $url = 'update.php?action=update-selected-themes&themes=' . urlencode(implode(',', $themes));
 436      $url = wp_nonce_url($url, 'bulk-update-themes');
 437  
 438      $title = __('Update Themes');
 439  
 440      require_once ('admin-header.php');
 441      echo '<div class="wrap">';
 442      screen_icon('themes');
 443      echo '<h2>' . esc_html__('Update Themes') . '</h2>';
 444      echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
 445      echo '</div>';
 446  }
 447  
 448  include ('admin-footer.php');


Generated: Mon Apr 5 14:26:09 2010 Cross-referenced by PHPXref 0.7