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


Generated: Tue May 18 01:00:05 2021 Cross-referenced by PHPXref 0.7.1