[ Index ]

PHP Cross Reference of WordPress

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( dirname( __FILE__ ) . '/admin.php' );
  11  
  12  wp_enqueue_style( 'plugin-install' );
  13  wp_enqueue_script( 'plugin-install' );
  14  wp_enqueue_script( 'updates' );
  15  add_thickbox();
  16  
  17  if ( is_multisite() && ! is_network_admin() ) {
  18      wp_redirect( network_admin_url( 'update-core.php' ) );
  19      exit();
  20  }
  21  
  22  if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_themes' ) && ! current_user_can( 'update_plugins' ) && ! current_user_can( 'update_languages' ) ) {
  23      wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
  24  }
  25  
  26  /**
  27   * @global string $wp_local_package
  28   * @global wpdb   $wpdb
  29   *
  30   * @staticvar bool $first_pass
  31   *
  32   * @param object $update
  33   */
  34  function list_core_update( $update ) {
  35      global $wp_local_package, $wpdb;
  36      static $first_pass = true;
  37  
  38      $wp_version     = get_bloginfo( 'version' );
  39      $version_string = sprintf( '%s&ndash;<strong>%s</strong>', $update->current, $update->locale );
  40  
  41      if ( 'en_US' == $update->locale && 'en_US' == get_locale() ) {
  42          $version_string = $update->current;
  43      } elseif ( 'en_US' == $update->locale && $update->packages->partial && $wp_version == $update->partial_version ) {
  44          $updates = get_core_updates();
  45          if ( $updates && 1 == count( $updates ) ) {
  46              // If the only available update is a partial builds, it doesn't need a language-specific version string.
  47              $version_string = $update->current;
  48          }
  49      }
  50  
  51      $current = false;
  52      if ( ! isset( $update->response ) || 'latest' == $update->response ) {
  53          $current = true;
  54      }
  55      $submit        = __( 'Update Now' );
  56      $form_action   = 'update-core.php?action=do-core-upgrade';
  57      $php_version   = phpversion();
  58      $mysql_version = $wpdb->db_version();
  59      $show_buttons  = true;
  60      if ( 'development' == $update->response ) {
  61          $message = __( 'You are using a development version of WordPress. You can update to the latest nightly build automatically:' );
  62      } else {
  63          if ( $current ) {
  64              $message     = sprintf( __( 'If you need to re-install version %s, you can do so here:' ), $version_string );
  65              $submit      = __( 'Re-install Now' );
  66              $form_action = 'update-core.php?action=do-core-reinstall';
  67          } else {
  68              $php_compat = version_compare( $php_version, $update->php_version, '>=' );
  69              if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) {
  70                  $mysql_compat = true;
  71              } else {
  72                  $mysql_compat = version_compare( $mysql_version, $update->mysql_version, '>=' );
  73              }
  74  
  75              $version_url = sprintf(
  76                  /* translators: %s: WordPress version */
  77                  esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
  78                  sanitize_title( $update->current )
  79              );
  80  
  81              /* translators: %s: Update PHP page URL */
  82              $php_update_message = '</p><p>' . sprintf( __( '<a href="%s">Learn more about updating PHP</a>.' ), esc_url( wp_get_update_php_url() ) );
  83  
  84              $annotation = wp_get_update_php_annotation();
  85              if ( $annotation ) {
  86                  $php_update_message .= '</p><p><em>' . $annotation . '</em>';
  87              }
  88  
  89              if ( ! $mysql_compat && ! $php_compat ) {
  90                  /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Minimum required MySQL version number, 5: Current PHP version number, 6: Current MySQL version number */
  91                  $message = sprintf( __( 'You cannot update because <a href="%1$s">WordPress %2$s</a> requires PHP version %3$s or higher and MySQL version %4$s or higher. You are running PHP version %5$s and MySQL version %6$s.' ), $version_url, $update->current, $update->php_version, $update->mysql_version, $php_version, $mysql_version ) . $php_update_message;
  92              } elseif ( ! $php_compat ) {
  93                  /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Current PHP version number */
  94                  $message = sprintf( __( 'You cannot update because <a href="%1$s">WordPress %2$s</a> requires PHP version %3$s or higher. You are running version %4$s.' ), $version_url, $update->current, $update->php_version, $php_version ) . $php_update_message;
  95              } elseif ( ! $mysql_compat ) {
  96                  /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required MySQL version number, 4: Current MySQL version number */
  97                  $message = sprintf( __( 'You cannot update because <a href="%1$s">WordPress %2$s</a> requires MySQL version %3$s or higher. You are running version %4$s.' ), $version_url, $update->current, $update->mysql_version, $mysql_version );
  98              } else {
  99                  /* translators: 1: URL to WordPress release notes, 2: WordPress version number including locale if necessary */
 100                  $message = sprintf( __( 'You can update to <a href="%1$s">WordPress %2$s</a> automatically:' ), $version_url, $version_string );
 101              }
 102              if ( ! $mysql_compat || ! $php_compat ) {
 103                  $show_buttons = false;
 104              }
 105          }
 106      }
 107  
 108      echo '<p>';
 109      echo $message;
 110      echo '</p>';
 111      echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">';
 112      wp_nonce_field( 'upgrade-core' );
 113      echo '<p>';
 114      echo '<input name="version" value="' . esc_attr( $update->current ) . '" type="hidden"/>';
 115      echo '<input name="locale" value="' . esc_attr( $update->locale ) . '" type="hidden"/>';
 116      if ( $show_buttons ) {
 117          if ( $first_pass ) {
 118              submit_button( $submit, $current ? '' : 'primary regular', 'upgrade', false );
 119              $first_pass = false;
 120          } else {
 121              submit_button( $submit, '', 'upgrade', false );
 122          }
 123      }
 124      if ( 'en_US' != $update->locale ) {
 125          if ( ! isset( $update->dismissed ) || ! $update->dismissed ) {
 126              submit_button( __( 'Hide this update' ), '', 'dismiss', false );
 127          } else {
 128              submit_button( __( 'Bring back this update' ), '', 'undismiss', false );
 129          }
 130      }
 131      echo '</p>';
 132      if ( 'en_US' != $update->locale && ( ! isset( $wp_local_package ) || $wp_local_package != $update->locale ) ) {
 133          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>';
 134      } elseif ( 'en_US' == $update->locale && get_locale() != 'en_US' && ( ! $update->packages->partial && $wp_version == $update->partial_version ) ) {
 135          // Partial builds don't need language-specific warnings.
 136          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>';
 137      }
 138      echo '</form>';
 139  
 140  }
 141  
 142  /**
 143   * @since 2.7.0
 144   */
 145  function dismissed_updates() {
 146      $dismissed = get_core_updates(
 147          array(
 148              'dismissed' => true,
 149              'available' => false,
 150          )
 151      );
 152      if ( $dismissed ) {
 153  
 154          $show_text = esc_js( __( 'Show hidden updates' ) );
 155          $hide_text = esc_js( __( 'Hide hidden updates' ) );
 156          ?>
 157      <script type="text/javascript">
 158          jQuery(function( $ ) {
 159              $( 'dismissed-updates' ).show();
 160              $( '#show-dismissed' ).toggle( function() { $( this ).text( '<?php echo $hide_text; ?>' ).attr( 'aria-expanded', 'true' ); }, function() { $( this ).text( '<?php echo $show_text; ?>' ).attr( 'aria-expanded', 'false' ); } );
 161              $( '#show-dismissed' ).click( function() { $( '#dismissed-updates' ).toggle( 'fast' ); } );
 162          });
 163      </script>
 164          <?php
 165          echo '<p class="hide-if-no-js"><button type="button" class="button" id="show-dismissed" aria-expanded="false">' . __( 'Show hidden updates' ) . '</button></p>';
 166          echo '<ul id="dismissed-updates" class="core-updates dismissed">';
 167          foreach ( (array) $dismissed as $update ) {
 168              echo '<li>';
 169              list_core_update( $update );
 170              echo '</li>';
 171          }
 172          echo '</ul>';
 173      }
 174  }
 175  
 176  /**
 177   * Display upgrade WordPress for downloading latest or upgrading automatically form.
 178   *
 179   * @since 2.7.0
 180   *
 181   * @global string $required_php_version
 182   * @global string $required_mysql_version
 183   */
 184  function core_upgrade_preamble() {
 185      global $required_php_version, $required_mysql_version;
 186  
 187      $wp_version = get_bloginfo( 'version' );
 188      $updates    = get_core_updates();
 189  
 190      if ( ! isset( $updates[0]->response ) || 'latest' == $updates[0]->response ) {
 191          echo '<h2>';
 192          _e( 'You have the latest version of WordPress.' );
 193  
 194          if ( wp_http_supports( array( 'ssl' ) ) ) {
 195              require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
 196              $upgrader            = new WP_Automatic_Updater;
 197              $future_minor_update = (object) array(
 198                  'current'       => $wp_version . '.1.next.minor',
 199                  'version'       => $wp_version . '.1.next.minor',
 200                  'php_version'   => $required_php_version,
 201                  'mysql_version' => $required_mysql_version,
 202              );
 203              $should_auto_update  = $upgrader->should_update( 'core', $future_minor_update, ABSPATH );
 204              if ( $should_auto_update ) {
 205                  echo ' ' . __( 'Future security updates will be applied automatically.' );
 206              }
 207          }
 208          echo '</h2>';
 209      }
 210  
 211      if ( isset( $updates[0]->version ) && version_compare( $updates[0]->version, $wp_version, '>' ) ) {
 212          echo '<div class="notice notice-warning"><p>';
 213          _e( '<strong>Important:</strong> Before updating, please <a href="https://codex.wordpress.org/WordPress_Backups">back up your database and files</a>. For help with updates, visit the <a href="https://codex.wordpress.org/Updating_WordPress">Updating WordPress</a> Codex page.' );
 214          echo '</p></div>';
 215  
 216          echo '<h2 class="response">';
 217          _e( 'An updated version of WordPress is available.' );
 218          echo '</h2>';
 219      }
 220  
 221      if ( isset( $updates[0] ) && $updates[0]->response == 'development' ) {
 222          require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
 223          $upgrader = new WP_Automatic_Updater;
 224          if ( wp_http_supports( 'ssl' ) && $upgrader->should_update( 'core', $updates[0], ABSPATH ) ) {
 225              echo '<div class="updated inline"><p>';
 226              echo '<strong>' . __( 'BETA TESTERS:' ) . '</strong> ' . __( 'This site is set up to install updates of future beta versions automatically.' );
 227              echo '</p></div>';
 228          }
 229      }
 230  
 231      echo '<ul class="core-updates">';
 232      foreach ( (array) $updates as $update ) {
 233          echo '<li>';
 234          list_core_update( $update );
 235          echo '</li>';
 236      }
 237      echo '</ul>';
 238      // Don't show the maintenance mode notice when we are only showing a single re-install option.
 239      if ( $updates && ( count( $updates ) > 1 || $updates[0]->response != 'latest' ) ) {
 240          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>';
 241      } elseif ( ! $updates ) {
 242          list( $normalized_version ) = explode( '-', $wp_version );
 243          echo '<p>' . sprintf( __( '<a href="%1$s">Learn more about WordPress %2$s</a>.' ), esc_url( self_admin_url( 'about.php' ) ), $normalized_version ) . '</p>';
 244      }
 245      dismissed_updates();
 246  }
 247  
 248  /**
 249   * Display the upgrade plugins form.
 250   *
 251   * @since 2.7.0
 252   */
 253  function list_plugin_updates() {
 254      $wp_version     = get_bloginfo( 'version' );
 255      $cur_wp_version = preg_replace( '/-.*$/', '', $wp_version );
 256  
 257      require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
 258      $plugins = get_plugin_updates();
 259      if ( empty( $plugins ) ) {
 260          echo '<h2>' . __( 'Plugins' ) . '</h2>';
 261          echo '<p>' . __( 'Your plugins are all up to date.' ) . '</p>';
 262          return;
 263      }
 264      $form_action = 'update-core.php?action=do-plugin-upgrade';
 265  
 266      $core_updates = get_core_updates();
 267      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, '=' ) ) {
 268          $core_update_version = false;
 269      } else {
 270          $core_update_version = $core_updates[0]->current;
 271      }
 272      ?>
 273  <h2><?php _e( 'Plugins' ); ?></h2>
 274  <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>
 275  <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-plugins" class="upgrade">
 276      <?php wp_nonce_field( 'upgrade-core' ); ?>
 277  <p><input id="upgrade-plugins" class="button" type="submit" value="<?php esc_attr_e( 'Update Plugins' ); ?>" name="upgrade" /></p>
 278  <table class="widefat updates-table" id="update-plugins-table">
 279      <thead>
 280      <tr>
 281          <td class="manage-column check-column"><input type="checkbox" id="plugins-select-all" /></td>
 282          <td class="manage-column"><label for="plugins-select-all"><?php _e( 'Select All' ); ?></label></td>
 283      </tr>
 284      </thead>
 285  
 286      <tbody class="plugins">
 287      <?php
 288      foreach ( (array) $plugins as $plugin_file => $plugin_data ) {
 289          $plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file, (array) $plugin_data, false, true );
 290  
 291          $icon            = '<span class="dashicons dashicons-admin-plugins"></span>';
 292          $preferred_icons = array( 'svg', '2x', '1x', 'default' );
 293          foreach ( $preferred_icons as $preferred_icon ) {
 294              if ( ! empty( $plugin_data->update->icons[ $preferred_icon ] ) ) {
 295                  $icon = '<img src="' . esc_url( $plugin_data->update->icons[ $preferred_icon ] ) . '" alt="" />';
 296                  break;
 297              }
 298          }
 299  
 300          // Get plugin compat for running version of WordPress.
 301          if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $cur_wp_version, '>=' ) ) {
 302              $compat = '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: 100%% (according to its author)' ), $cur_wp_version );
 303          } else {
 304              $compat = '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: Unknown' ), $cur_wp_version );
 305          }
 306          // Get plugin compat for updated version of WordPress.
 307          if ( $core_update_version ) {
 308              if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $core_update_version, '>=' ) ) {
 309                  $compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: 100%% (according to its author)' ), $core_update_version );
 310              } else {
 311                  $compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: Unknown' ), $core_update_version );
 312              }
 313          }
 314  
 315          $requires_php   = isset( $plugin_data->update->requires_php ) ? $plugin_data->update->requires_php : null;
 316          $compatible_php = is_php_version_compatible( $requires_php );
 317  
 318          if ( ! $compatible_php && current_user_can( 'update_php' ) ) {
 319              $compat .= '<br>' . __( 'This update doesn&#8217;t work with your version of PHP.' ) . '&nbsp;';
 320              /* translators: %s: Update PHP page URL */
 321              $compat .= sprintf(
 322                  __( '<a href="%s">Learn more about updating PHP</a>.' ),
 323                  esc_url( wp_get_update_php_url() )
 324              );
 325  
 326              $annotation = wp_get_update_php_annotation();
 327  
 328              if ( $annotation ) {
 329                  $compat .= '</p><p><em>' . $annotation . '</em>';
 330              }
 331          }
 332  
 333          // Get the upgrade notice for the new plugin version.
 334          if ( isset( $plugin_data->update->upgrade_notice ) ) {
 335              $upgrade_notice = '<br />' . strip_tags( $plugin_data->update->upgrade_notice );
 336          } else {
 337              $upgrade_notice = '';
 338          }
 339  
 340          $details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_data->update->slug . '&section=changelog&TB_iframe=true&width=640&height=662' );
 341          $details     = sprintf(
 342              '<a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>',
 343              esc_url( $details_url ),
 344              /* translators: 1: plugin name, 2: version number */
 345              esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_data->Name, $plugin_data->update->new_version ) ),
 346              /* translators: %s: plugin version */
 347              sprintf( __( 'View version %s details.' ), $plugin_data->update->new_version )
 348          );
 349  
 350          $checkbox_id = 'checkbox_' . md5( $plugin_data->Name );
 351          ?>
 352      <tr>
 353          <td class="check-column">
 354          <?php if ( $compatible_php ) : ?>
 355              <input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $plugin_file ); ?>" />
 356              <label for="<?php echo $checkbox_id; ?>" class="screen-reader-text">
 357              <?php
 358                  /* translators: %s: plugin name */
 359                  printf(
 360                      __( 'Select %s' ),
 361                      $plugin_data->Name
 362                  );
 363              ?>
 364              </label>
 365          <?php endif; ?>
 366          </td>
 367          <td class="plugin-title"><p>
 368              <?php echo $icon; ?>
 369              <strong><?php echo $plugin_data->Name; ?></strong>
 370              <?php
 371              /* translators: 1: plugin version, 2: new version */
 372              printf(
 373                  __( 'You have version %1$s installed. Update to %2$s.' ),
 374                  $plugin_data->Version,
 375                  $plugin_data->update->new_version
 376              );
 377              echo ' ' . $details . $compat . $upgrade_notice;
 378              ?>
 379          </p></td>
 380      </tr>
 381          <?php
 382      }
 383      ?>
 384      </tbody>
 385  
 386      <tfoot>
 387      <tr>
 388          <td class="manage-column check-column"><input type="checkbox" id="plugins-select-all-2" /></td>
 389          <td class="manage-column"><label for="plugins-select-all-2"><?php _e( 'Select All' ); ?></label></td>
 390      </tr>
 391      </tfoot>
 392  </table>
 393  <p><input id="upgrade-plugins-2" class="button" type="submit" value="<?php esc_attr_e( 'Update Plugins' ); ?>" name="upgrade" /></p>
 394  </form>
 395      <?php
 396  }
 397  
 398  /**
 399   * @since 2.9.0
 400   */
 401  function list_theme_updates() {
 402      $themes = get_theme_updates();
 403      if ( empty( $themes ) ) {
 404          echo '<h2>' . __( 'Themes' ) . '</h2>';
 405          echo '<p>' . __( 'Your themes are all up to date.' ) . '</p>';
 406          return;
 407      }
 408  
 409      $form_action = 'update-core.php?action=do-theme-upgrade';
 410      ?>
 411  <h2><?php _e( 'Themes' ); ?></h2>
 412  <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>
 413  <p>
 414      <?php
 415      printf(
 416          /* translators: %s: link to documentation on child themes */
 417          __( '<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.' ),
 418          __( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' )
 419      );
 420      ?>
 421  </p>
 422  <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-themes" class="upgrade">
 423      <?php wp_nonce_field( 'upgrade-core' ); ?>
 424  <p><input id="upgrade-themes" class="button" type="submit" value="<?php esc_attr_e( 'Update Themes' ); ?>" name="upgrade" /></p>
 425  <table class="widefat updates-table" id="update-themes-table">
 426      <thead>
 427      <tr>
 428          <td class="manage-column check-column"><input type="checkbox" id="themes-select-all" /></td>
 429          <td class="manage-column"><label for="themes-select-all"><?php _e( 'Select All' ); ?></label></td>
 430      </tr>
 431      </thead>
 432  
 433      <tbody class="plugins">
 434      <?php
 435      foreach ( $themes as $stylesheet => $theme ) {
 436          $checkbox_id = 'checkbox_' . md5( $theme->get( 'Name' ) );
 437          ?>
 438      <tr>
 439          <td class="check-column">
 440              <input type="checkbox" name="checked[]" id="<?php echo $checkbox_id; ?>" value="<?php echo esc_attr( $stylesheet ); ?>" />
 441              <label for="<?php echo $checkbox_id; ?>" class="screen-reader-text">
 442              <?php
 443                  /* translators: %s: theme name */
 444                  printf(
 445                      __( 'Select %s' ),
 446                      $theme->display( 'Name' )
 447                  );
 448              ?>
 449              </label>
 450          </td>
 451          <td class="plugin-title"><p>
 452              <img src="<?php echo esc_url( $theme->get_screenshot() ); ?>" width="85" height="64" class="updates-table-screenshot" alt="" />
 453              <strong><?php echo $theme->display( 'Name' ); ?></strong>
 454              <?php
 455              /* translators: 1: theme version, 2: new version */
 456              printf(
 457                  __( 'You have version %1$s installed. Update to %2$s.' ),
 458                  $theme->display( 'Version' ),
 459                  $theme->update['new_version']
 460              );
 461              ?>
 462          </p></td>
 463      </tr>
 464              <?php
 465      }
 466      ?>
 467      </tbody>
 468  
 469      <tfoot>
 470      <tr>
 471          <td class="manage-column check-column"><input type="checkbox" id="themes-select-all-2" /></td>
 472          <td class="manage-column"><label for="themes-select-all-2"><?php _e( 'Select All' ); ?></label></td>
 473      </tr>
 474      </tfoot>
 475  </table>
 476  <p><input id="upgrade-themes-2" class="button" type="submit" value="<?php esc_attr_e( 'Update Themes' ); ?>" name="upgrade" /></p>
 477  </form>
 478      <?php
 479  }
 480  
 481  /**
 482   * @since 3.7.0
 483   */
 484  function list_translation_updates() {
 485      $updates = wp_get_translation_updates();
 486      if ( ! $updates ) {
 487          if ( 'en_US' != get_locale() ) {
 488              echo '<h2>' . __( 'Translations' ) . '</h2>';
 489              echo '<p>' . __( 'Your translations are all up to date.' ) . '</p>';
 490          }
 491          return;
 492      }
 493  
 494      $form_action = 'update-core.php?action=do-translation-upgrade';
 495      ?>
 496      <h2><?php _e( 'Translations' ); ?></h2>
 497      <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-translations" class="upgrade">
 498          <p><?php _e( 'New translations are available.' ); ?></p>
 499          <?php wp_nonce_field( 'upgrade-translations' ); ?>
 500          <p><input class="button" type="submit" value="<?php esc_attr_e( 'Update Translations' ); ?>" name="upgrade" /></p>
 501      </form>
 502      <?php
 503  }
 504  
 505  /**
 506   * Upgrade WordPress core display.
 507   *
 508   * @since 2.7.0
 509   *
 510   * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
 511   *
 512   * @param bool $reinstall
 513   */
 514  function do_core_upgrade( $reinstall = false ) {
 515      global $wp_filesystem;
 516  
 517      include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
 518  
 519      if ( $reinstall ) {
 520          $url = 'update-core.php?action=do-core-reinstall';
 521      } else {
 522          $url = 'update-core.php?action=do-core-upgrade';
 523      }
 524      $url = wp_nonce_url( $url, 'upgrade-core' );
 525  
 526      $version = isset( $_POST['version'] ) ? $_POST['version'] : false;
 527      $locale  = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
 528      $update  = find_core_update( $version, $locale );
 529      if ( ! $update ) {
 530          return;
 531      }
 532  
 533      // Allow relaxed file ownership writes for User-initiated upgrades when the API specifies
 534      // that it's safe to do so. This only happens when there are no new files to create.
 535      $allow_relaxed_file_ownership = ! $reinstall && isset( $update->new_files ) && ! $update->new_files;
 536  
 537      ?>
 538      <div class="wrap">
 539      <h1><?php _e( 'Update WordPress' ); ?></h1>
 540      <?php
 541  
 542      $credentials = request_filesystem_credentials( $url, '', false, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership );
 543      if ( false === $credentials ) {
 544          echo '</div>';
 545          return;
 546      }
 547  
 548      if ( ! WP_Filesystem( $credentials, ABSPATH, $allow_relaxed_file_ownership ) ) {
 549          // Failed to connect, Error and request again
 550          request_filesystem_credentials( $url, '', true, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership );
 551          echo '</div>';
 552          return;
 553      }
 554  
 555      if ( $wp_filesystem->errors->has_errors() ) {
 556          foreach ( $wp_filesystem->errors->get_error_messages() as $message ) {
 557              show_message( $message );
 558          }
 559          echo '</div>';
 560          return;
 561      }
 562  
 563      if ( $reinstall ) {
 564          $update->response = 'reinstall';
 565      }
 566  
 567      add_filter( 'update_feedback', 'show_message' );
 568  
 569      $upgrader = new Core_Upgrader();
 570      $result   = $upgrader->upgrade(
 571          $update,
 572          array(
 573              'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership,
 574          )
 575      );
 576  
 577      if ( is_wp_error( $result ) ) {
 578          show_message( $result );
 579          if ( 'up_to_date' != $result->get_error_code() && 'locked' != $result->get_error_code() ) {
 580              show_message( __( 'Installation Failed' ) );
 581          }
 582          echo '</div>';
 583          return;
 584      }
 585  
 586      show_message( __( 'WordPress updated successfully' ) );
 587      show_message( '<span class="hide-if-no-js">' . sprintf( __( 'Welcome to WordPress %1$s. You will be redirected to the About WordPress screen. If not, click <a href="%2$s">here</a>.' ), $result, esc_url( self_admin_url( 'about.php?updated' ) ) ) . '</span>' );
 588      show_message( '<span class="hide-if-js">' . sprintf( __( 'Welcome to WordPress %1$s. <a href="%2$s">Learn more</a>.' ), $result, esc_url( self_admin_url( 'about.php?updated' ) ) ) . '</span>' );
 589      ?>
 590      </div>
 591      <script type="text/javascript">
 592      window.location = '<?php echo self_admin_url( 'about.php?updated' ); ?>';
 593      </script>
 594      <?php
 595  }
 596  
 597  /**
 598   * @since 2.7.0
 599   */
 600  function do_dismiss_core_update() {
 601      $version = isset( $_POST['version'] ) ? $_POST['version'] : false;
 602      $locale  = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
 603      $update  = find_core_update( $version, $locale );
 604      if ( ! $update ) {
 605          return;
 606      }
 607      dismiss_core_update( $update );
 608      wp_redirect( wp_nonce_url( 'update-core.php?action=upgrade-core', 'upgrade-core' ) );
 609      exit;
 610  }
 611  
 612  /**
 613   * @since 2.7.0
 614   */
 615  function do_undismiss_core_update() {
 616      $version = isset( $_POST['version'] ) ? $_POST['version'] : false;
 617      $locale  = isset( $_POST['locale'] ) ? $_POST['locale'] : 'en_US';
 618      $update  = find_core_update( $version, $locale );
 619      if ( ! $update ) {
 620          return;
 621      }
 622      undismiss_core_update( $version, $locale );
 623      wp_redirect( wp_nonce_url( 'update-core.php?action=upgrade-core', 'upgrade-core' ) );
 624      exit;
 625  }
 626  
 627  $action = isset( $_GET['action'] ) ? $_GET['action'] : 'upgrade-core';
 628  
 629  $upgrade_error = false;
 630  if ( ( 'do-theme-upgrade' == $action || ( 'do-plugin-upgrade' == $action && ! isset( $_GET['plugins'] ) ) )
 631      && ! isset( $_POST['checked'] ) ) {
 632      $upgrade_error = $action == 'do-theme-upgrade' ? 'themes' : 'plugins';
 633      $action        = 'upgrade-core';
 634  }
 635  
 636  $title       = __( 'WordPress Updates' );
 637  $parent_file = 'index.php';
 638  
 639  $updates_overview  = '<p>' . __( 'On this screen, you can update to the latest version of WordPress, as well as update your themes, plugins, and translations from the WordPress.org repositories.' ) . '</p>';
 640  $updates_overview .= '<p>' . __( 'If an update is available, you&#8127;ll see a notification appear in the Toolbar and navigation menu.' ) . ' ' . __( 'Keeping your site updated is important for security. It also makes the internet a safer place for you and your readers.' ) . '</p>';
 641  
 642  get_current_screen()->add_help_tab(
 643      array(
 644          'id'      => 'overview',
 645          'title'   => __( 'Overview' ),
 646          'content' => $updates_overview,
 647      )
 648  );
 649  
 650  $updates_howto  = '<p>' . __( '<strong>WordPress</strong> &mdash; Updating your WordPress installation is a simple one-click procedure: just <strong>click on the &#8220;Update Now&#8221; button</strong> when you are notified that a new version is available.' ) . ' ' . __( 'In most cases, WordPress will automatically apply maintenance and security updates in the background for you.' ) . '</p>';
 651  $updates_howto .= '<p>' . __( '<strong>Themes and Plugins</strong> &mdash; To update individual themes or plugins from this screen, use the checkboxes to make your selection, then <strong>click on the appropriate &#8220;Update&#8221; button</strong>. To update all of your themes or plugins at once, you can check the box at the top of the section to select all before clicking the update button.' ) . '</p>';
 652  
 653  if ( 'en_US' != get_locale() ) {
 654      $updates_howto .= '<p>' . __( '<strong>Translations</strong> &mdash; The files translating WordPress into your language are updated for you whenever any other updates occur. But if these files are out of date, you can <strong>click the &#8220;Update Translations&#8221;</strong> button.' ) . '</p>';
 655  }
 656  
 657  get_current_screen()->add_help_tab(
 658      array(
 659          'id'      => 'how-to-update',
 660          'title'   => __( 'How to Update' ),
 661          'content' => $updates_howto,
 662      )
 663  );
 664  
 665  get_current_screen()->set_help_sidebar(
 666      '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
 667      '<p>' . __( '<a href="https://codex.wordpress.org/Dashboard_Updates_Screen">Documentation on Updating WordPress</a>' ) . '</p>' .
 668      '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
 669  );
 670  
 671  if ( 'upgrade-core' == $action ) {
 672      // Force a update check when requested
 673      $force_check = ! empty( $_GET['force-check'] );
 674      wp_version_check( array(), $force_check );
 675  
 676      require_once( ABSPATH . 'wp-admin/admin-header.php' );
 677      ?>
 678      <div class="wrap">
 679      <h1><?php _e( 'WordPress Updates' ); ?></h1>
 680      <?php
 681      if ( $upgrade_error ) {
 682          echo '<div class="error"><p>';
 683          if ( $upgrade_error == 'themes' ) {
 684              _e( 'Please select one or more themes to update.' );
 685          } else {
 686              _e( 'Please select one or more plugins to update.' );
 687          }
 688          echo '</p></div>';
 689      }
 690  
 691      $last_update_check = false;
 692      $current           = get_site_transient( 'update_core' );
 693  
 694      if ( $current && isset( $current->last_checked ) ) {
 695          $last_update_check = $current->last_checked + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
 696      }
 697  
 698      echo '<p>';
 699      /* translators: 1: date, 2: time */
 700      printf( __( 'Last checked on %1$s at %2$s.' ), date_i18n( __( 'F j, Y' ), $last_update_check ), date_i18n( __( 'g:i a' ), $last_update_check ) );
 701      echo ' &nbsp; <a class="button" href="' . esc_url( self_admin_url( 'update-core.php?force-check=1' ) ) . '">' . __( 'Check Again' ) . '</a>';
 702      echo '</p>';
 703  
 704      if ( current_user_can( 'update_core' ) ) {
 705          core_upgrade_preamble();
 706      }
 707      if ( current_user_can( 'update_plugins' ) ) {
 708          list_plugin_updates();
 709      }
 710      if ( current_user_can( 'update_themes' ) ) {
 711          list_theme_updates();
 712      }
 713      if ( current_user_can( 'update_languages' ) ) {
 714          list_translation_updates();
 715      }
 716  
 717      /**
 718       * Fires after the core, plugin, and theme update tables.
 719       *
 720       * @since 2.9.0
 721       */
 722      do_action( 'core_upgrade_preamble' );
 723      echo '</div>';
 724  
 725      wp_localize_script(
 726          'updates',
 727          '_wpUpdatesItemCounts',
 728          array(
 729              'totals' => wp_get_update_data(),
 730          )
 731      );
 732  
 733      include( ABSPATH . 'wp-admin/admin-footer.php' );
 734  
 735  } elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) {
 736  
 737      if ( ! current_user_can( 'update_core' ) ) {
 738          wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
 739      }
 740  
 741      check_admin_referer( 'upgrade-core' );
 742  
 743      // Do the (un)dismiss actions before headers, so that they can redirect.
 744      if ( isset( $_POST['dismiss'] ) ) {
 745          do_dismiss_core_update();
 746      } elseif ( isset( $_POST['undismiss'] ) ) {
 747          do_undismiss_core_update();
 748      }
 749  
 750      require_once( ABSPATH . 'wp-admin/admin-header.php' );
 751      if ( 'do-core-reinstall' == $action ) {
 752          $reinstall = true;
 753      } else {
 754          $reinstall = false;
 755      }
 756  
 757      if ( isset( $_POST['upgrade'] ) ) {
 758          do_core_upgrade( $reinstall );
 759      }
 760  
 761      wp_localize_script(
 762          'updates',
 763          '_wpUpdatesItemCounts',
 764          array(
 765              'totals' => wp_get_update_data(),
 766          )
 767      );
 768  
 769      include( ABSPATH . 'wp-admin/admin-footer.php' );
 770  
 771  } elseif ( 'do-plugin-upgrade' == $action ) {
 772  
 773      if ( ! current_user_can( 'update_plugins' ) ) {
 774          wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
 775      }
 776  
 777      check_admin_referer( 'upgrade-core' );
 778  
 779      if ( isset( $_GET['plugins'] ) ) {
 780          $plugins = explode( ',', $_GET['plugins'] );
 781      } elseif ( isset( $_POST['checked'] ) ) {
 782          $plugins = (array) $_POST['checked'];
 783      } else {
 784          wp_redirect( admin_url( 'update-core.php' ) );
 785          exit;
 786      }
 787  
 788      $url = 'update.php?action=update-selected&plugins=' . urlencode( implode( ',', $plugins ) );
 789      $url = wp_nonce_url( $url, 'bulk-update-plugins' );
 790  
 791      $title = __( 'Update Plugins' );
 792  
 793      require_once( ABSPATH . 'wp-admin/admin-header.php' );
 794      echo '<div class="wrap">';
 795      echo '<h1>' . __( 'Update Plugins' ) . '</h1>';
 796      echo '<iframe src="', $url, '" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="' . esc_attr__( 'Update progress' ) . '"></iframe>';
 797      echo '</div>';
 798  
 799      wp_localize_script(
 800          'updates',
 801          '_wpUpdatesItemCounts',
 802          array(
 803              'totals' => wp_get_update_data(),
 804          )
 805      );
 806  
 807      include( ABSPATH . 'wp-admin/admin-footer.php' );
 808  
 809  } elseif ( 'do-theme-upgrade' == $action ) {
 810  
 811      if ( ! current_user_can( 'update_themes' ) ) {
 812          wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
 813      }
 814  
 815      check_admin_referer( 'upgrade-core' );
 816  
 817      if ( isset( $_GET['themes'] ) ) {
 818          $themes = explode( ',', $_GET['themes'] );
 819      } elseif ( isset( $_POST['checked'] ) ) {
 820          $themes = (array) $_POST['checked'];
 821      } else {
 822          wp_redirect( admin_url( 'update-core.php' ) );
 823          exit;
 824      }
 825  
 826      $url = 'update.php?action=update-selected-themes&themes=' . urlencode( implode( ',', $themes ) );
 827      $url = wp_nonce_url( $url, 'bulk-update-themes' );
 828  
 829      $title = __( 'Update Themes' );
 830  
 831      require_once( ABSPATH . 'wp-admin/admin-header.php' );
 832      ?>
 833      <div class="wrap">
 834          <h1><?php _e( 'Update Themes' ); ?></h1>
 835          <iframe src="<?php echo $url; ?>" style="width: 100%; height: 100%; min-height: 750px;" frameborder="0" title="<?php esc_attr_e( 'Update progress' ); ?>"></iframe>
 836      </div>
 837      <?php
 838  
 839      wp_localize_script(
 840          'updates',
 841          '_wpUpdatesItemCounts',
 842          array(
 843              'totals' => wp_get_update_data(),
 844          )
 845      );
 846  
 847      include( ABSPATH . 'wp-admin/admin-footer.php' );
 848  
 849  } elseif ( 'do-translation-upgrade' == $action ) {
 850  
 851      if ( ! current_user_can( 'update_languages' ) ) {
 852          wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
 853      }
 854  
 855      check_admin_referer( 'upgrade-translations' );
 856  
 857      require_once( ABSPATH . 'wp-admin/admin-header.php' );
 858      include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
 859  
 860      $url     = 'update-core.php?action=do-translation-upgrade';
 861      $nonce   = 'upgrade-translations';
 862      $title   = __( 'Update Translations' );
 863      $context = WP_LANG_DIR;
 864  
 865      $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
 866      $result   = $upgrader->bulk_upgrade();
 867  
 868      wp_localize_script(
 869          'updates',
 870          '_wpUpdatesItemCounts',
 871          array(
 872              'totals' => wp_get_update_data(),
 873          )
 874      );
 875  
 876      require_once( ABSPATH . 'wp-admin/admin-footer.php' );
 877  
 878  } else {
 879      /**
 880       * Fires for each custom update action on the WordPress Updates screen.
 881       *
 882       * The dynamic portion of the hook name, `$action`, refers to the
 883       * passed update action. The hook fires in lieu of all available
 884       * default update actions.
 885       *
 886       * @since 3.2.0
 887       */
 888      do_action( "update-core-custom_{$action}" );  // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 889  }


Generated: Wed Jul 24 01:00:02 2019 Cross-referenced by PHPXref 0.7.1