[ Index ]

PHP Cross Reference of Wordpress 2.9.1

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;
  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 = __('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');
  27      } else {
  28          if ( $current ) {
  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';
  32          } else {
  33              $message =     sprintf(__('You can upgrade to version %s automatically or download the package and install it manually:'), $version_string);
  34          }
  35          $download = sprintf(__('Download %s'), $version_string);
  36      }
  37  
  38      echo '<p>';
  39      echo $message;
  40      echo '</p>';
  41      echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
  42      wp_nonce_field('upgrade-core');
  43      echo '<p>';
  44      echo '<input id="upgrade" class="button" type="submit" value="' . esc_attr($submit) . '" name="upgrade" />&nbsp;';
  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>&nbsp;';
  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" />';
  51          else
  52              echo '<input id="undismiss" class="button" type="submit" value="' . esc_attr__('Bring back this update') . '" name="undismiss" />';
  53      echo '</p>';
  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>';
  58      }
  59      echo '</form>';
  60  
  61  }
  62  
  63  function dismissed_updates() {
  64      $dismissed = get_core_updates( array( 'dismissed' => true, 'available' => false ) );
  65      if ( $dismissed ) {
  66  
  67          $show_text = esc_js(__('Show hidden updates'));
  68          $hide_text = esc_js(__('Hide hidden updates'));
  69      ?>
  70      <script type="text/javascript">
  71  
  72          jQuery(function($) {
  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');});
  76          });
  77      </script>
  78      <?php
  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) {
  82              echo '<li>';
  83              list_core_update( $update );
  84              echo '</li>';
  85          }
  86          echo '</ul>';
  87      }
  88  }
  89  
  90  /**
  91   * Display upgrade WordPress for downloading latest or upgrading automatically form.
  92   *
  93   * @since 2.7
  94   *
  95   * @return null
  96   */
  97  function core_upgrade_preamble() {
  98      global $upgrade_error;
  99  
 100      $updates = get_core_updates();
 101  ?>
 102      <div class="wrap">
 103      <?php screen_icon(); ?>
 104      <h2><?php _e('Upgrade WordPress'); ?></h2>
 105  <?php
 106      if ( $upgrade_error ) {
 107          echo '<div class="error"><p>';
 108          _e('Please select one or more plugins to upgrade.');
 109          echo '</p></div>';
 110      }
 111  
 112      if ( !isset($updates[0]->response) || 'latest' == $updates[0]->response ) {
 113          echo '<h3>';
 114          _e('You have the latest version of WordPress. You do not need to upgrade');
 115          echo '</h3>';
 116      } else {
 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>.');
 119          echo '</p></div>';
 120  
 121          echo '<h3 class="response">';
 122          _e( 'There is a new version of WordPress available for upgrade' );
 123          echo '</h3>';
 124      }
 125  
 126      echo '<ul class="core-updates">';
 127      $alternate = true;
 128      foreach( (array) $updates as $update ) {
 129          $class = $alternate? ' class="alternate"' : '';
 130          $alternate = !$alternate;
 131          echo "<li $class>";
 132          list_core_update( $update );
 133          echo '</li>';
 134      }
 135      echo '</ul>';
 136      dismissed_updates();
 137  
 138      list_plugin_updates();
 139      //list_theme_updates();
 140      do_action('core_upgrade_preamble');
 141      echo '</div>';
 142  }
 143  
 144  function list_plugin_updates() {
 145      global $wp_version;
 146  
 147      $cur_wp_version = preg_replace('/-.*$/', '', $wp_version);
 148  
 149      require_once (ABSPATH . 'wp-admin/includes/plugin-install.php');
 150      $plugins = get_plugin_updates();
 151      if ( empty($plugins) )
 152          return;
 153      $form_action = 'update-core.php?action=do-plugin-upgrade';
 154  
 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;
 158      else
 159          $core_update_version = $core_updates[0]->current;
 160      ?>
 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">
 167      <thead>
 168      <tr>
 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>
 171      </tr>
 172      </thead>
 173  
 174      <tfoot>
 175      <tr>
 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>
 178      </tr>
 179      </tfoot>
 180      <tbody class="plugins">
 181  <?php
 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]);
 190          } else {
 191              $compat = '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $cur_wp_version);
 192          }
 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]);
 198              } else {
 199                  $compat .= '<br />' . sprintf(__('Compatibility with WordPress %1$s: Unknown'), $core_update_version);
 200              }
 201          }
 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);
 205          } else {
 206              $upgrade_notice = '';
 207          }
 208          echo "
 209      <tr class='active'>
 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>
 212      </tr>";
 213      }
 214  ?>
 215      </tbody>
 216  </table>
 217  <p><input id="upgrade-plugins-2" class="button" type="submit" value="<?php esc_attr_e('Upgrade Plugins'); ?>" name="upgrade" /></p>
 218  </form>
 219  <?php
 220  }
 221  
 222  function list_theme_updates() {
 223      $themes = get_theme_updates();
 224      if ( empty($themes) )
 225          return;
 226  ?>
 227  <h3><?php _e('Themes'); ?></h3>
 228  <table class="widefat" cellspacing="0" id="update-themes-table">
 229      <thead>
 230      <tr>
 231          <th scope="col" class="manage-column check-column"><input type="checkbox" /></th>
 232          <th scope="col" class="manage-column"><?php _e('Name'); ?></th>
 233      </tr>
 234      </thead>
 235  
 236      <tfoot>
 237      <tr>
 238          <th scope="col" class="manage-column check-column"><input type="checkbox" /></th>
 239          <th scope="col" class="manage-column"><?php _e('Name'); ?></th>
 240      </tr>
 241      </tfoot>
 242      <tbody class="plugins">
 243  <?php
 244      foreach ( (array) $themes as $stylesheet => $theme_data) {
 245          echo "
 246      <tr class='active'>
 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>
 249      </tr>";
 250      }
 251  ?>
 252      </tbody>
 253  </table>
 254  <?php
 255  }
 256  
 257  /**
 258   * Upgrade WordPress core display.
 259   *
 260   * @since 2.7
 261   *
 262   * @return null
 263   */
 264  function do_core_upgrade( $reinstall = false ) {
 265      global $wp_filesystem;
 266  
 267      if ( $reinstall )
 268          $url = 'update-core.php?action=do-core-reinstall';
 269      else
 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)) )
 273          return;
 274  
 275      $version = isset( $_POST['version'] )? $_POST['version'] : false;
 276      $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US';
 277      $update = find_core_update( $version, $locale );
 278      if ( !$update )
 279          return;
 280  
 281  
 282      if ( ! WP_Filesystem($credentials, ABSPATH) ) {
 283          request_filesystem_credentials($url, '', true, ABSPATH); //Failed to connect, Error and request again
 284          return;
 285      }
 286  ?>
 287      <div class="wrap">
 288      <?php screen_icon(); ?>
 289      <h2><?php _e('Upgrade WordPress'); ?></h2>
 290  <?php
 291      if ( $wp_filesystem->errors->get_error_code() ) {
 292          foreach ( $wp_filesystem->errors->get_error_messages() as $message )
 293              show_message($message);
 294          echo '</div>';
 295          return;
 296      }
 297  
 298      if ( $reinstall )
 299          $update->response = 'reinstall';
 300  
 301      $result = wp_update_core($update, 'show_message');
 302  
 303      if ( is_wp_error($result) ) {
 304          show_message($result);
 305          if ('up_to_date' != $result->get_error_code() )
 306              show_message( __('Installation Failed') );
 307      } else {
 308          show_message( __('WordPress upgraded successfully') );
 309      }
 310      echo '</div>';
 311  }
 312  
 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 );
 317      if ( !$update )
 318          return;
 319      dismiss_core_update( $update );
 320      wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
 321  }
 322  
 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 );
 327      if ( !$update )
 328          return;
 329      undismiss_core_update( $version, $locale );
 330      wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') );
 331  }
 332  
 333  function no_update_actions($actions) {
 334      return '';
 335  }
 336  
 337  function do_plugin_upgrade() {
 338      include_once  ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
 339  
 340      if ( isset($_GET['plugins']) ) {
 341          $plugins = explode(',', $_GET['plugins']);
 342      } elseif ( isset($_POST['checked']) ) {
 343          $plugins = (array) $_POST['checked'];
 344      } else {
 345          // Nothing to do.
 346          return;
 347      }
 348      $url = 'update-core.php?action=do-plugin-upgrade&amp;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);
 353  }
 354  
 355  $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
 356  
 357  $upgrade_error = false;
 358  if ( 'do-plugin-upgrade' == $action && !isset($_GET['plugins']) && !isset($_POST['checked']) ) {
 359      $upgrade_error = true;
 360      $action = 'upgrade-core';
 361  }
 362  
 363  $title = __('Upgrade WordPress');
 364  $parent_file = 'tools.php';
 365  
 366  if ( 'upgrade-core' == $action ) {
 367      wp_version_check();
 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 )
 380          $reinstall = true;
 381      else
 382          $reinstall = false;
 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');
 388      do_plugin_upgrade();
 389  }
 390  
 391  include ('admin-footer.php');


Generated: Fri Jan 8 00:19:48 2010 Cross-referenced by PHPXref 0.7