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


Generated: Sat Sep 19 01:00:03 2020 Cross-referenced by PHPXref 0.7.1