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


Generated: Thu Jul 2 01:00:04 2020 Cross-referenced by PHPXref 0.7.1