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


Generated: Wed Dec 2 01:00:04 2020 Cross-referenced by PHPXref 0.7.1