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


Generated: Mon Nov 11 01:00:04 2019 Cross-referenced by PHPXref 0.7.1