[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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


Generated : Sat Jun 6 08:20:01 2020 Cross-referenced by PHPXref