[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/ -> install.php (source)

   1  <?php
   2  /**
   3   * WordPress Installer
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  // Confidence check.
  10  if ( false ) {
  11      ?>
  12  <!DOCTYPE html>
  13  <html lang="en-US">
  14  <head>
  15      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  16      <title>Error: PHP is not running</title>
  17  </head>
  18  <body class="wp-core-ui admin-color-modern">
  19      <h1>Error: PHP is not running</h1>
  20      <p>WordPress requires that your web server is running PHP. Your server does not have PHP installed, or PHP is turned off.</p>
  21  </body>
  22  </html>
  23      <?php
  24  }
  25  
  26  /**
  27   * We are installing WordPress.
  28   *
  29   * @since 1.5.1
  30   * @var bool
  31   */
  32  define( 'WP_INSTALLING', true );
  33  
  34  /** Load WordPress Bootstrap */
  35  require_once dirname( __DIR__ ) . '/wp-load.php';
  36  
  37  /** Load WordPress Administration Upgrade API */
  38  require_once  ABSPATH . 'wp-admin/includes/upgrade.php';
  39  
  40  /** Load WordPress Translation Install API */
  41  require_once  ABSPATH . 'wp-admin/includes/translation-install.php';
  42  
  43  /** Load wpdb */
  44  require_once  ABSPATH . WPINC . '/class-wpdb.php';
  45  
  46  nocache_headers();
  47  
  48  $step = isset( $_GET['step'] ) ? (int) $_GET['step'] : 0;
  49  
  50  /**
  51   * Display installation header.
  52   *
  53   * @since 2.5.0
  54   *
  55   * @param string $body_classes Class attribute values for the body tag.
  56   */
  57  function display_header( $body_classes = '' ) {
  58      header( 'Content-Type: text/html; charset=utf-8' );
  59      if ( is_rtl() ) {
  60          $body_classes .= 'rtl';
  61      }
  62      if ( $body_classes ) {
  63          $body_classes = ' ' . $body_classes;
  64      }
  65      ?>
  66  <!DOCTYPE html>
  67  <html <?php language_attributes(); ?>>
  68  <head>
  69      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  70      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  71      <meta name="robots" content="noindex,nofollow" />
  72      <title><?php _e( 'WordPress &rsaquo; Installation' ); ?></title>
  73      <?php wp_admin_css( 'install', true ); ?>
  74  </head>
  75  <body class="wp-core-ui admin-color-modern<?php echo $body_classes; ?>">
  76  <p id="logo"><?php _e( 'WordPress' ); ?></p>
  77  
  78      <?php
  79  } // End display_header().
  80  
  81  /**
  82   * Displays installer setup form.
  83   *
  84   * @since 2.8.0
  85   *
  86   * @global wpdb $wpdb WordPress database abstraction object.
  87   *
  88   * @param string|null $error Error message to display, if any.
  89   */
  90  function display_setup_form( $error = null ) {
  91      global $wpdb;
  92  
  93      $user_table = ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->users ) ) ) !== null );
  94  
  95      // Ensure that sites appear in search engines by default.
  96      $blog_public = 1;
  97      if ( isset( $_POST['weblog_title'] ) ) {
  98          $blog_public = isset( $_POST['blog_public'] ) ? (int) $_POST['blog_public'] : $blog_public;
  99      }
 100  
 101      $weblog_title = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) : '';
 102      $user_name    = isset( $_POST['user_name'] ) ? trim( wp_unslash( $_POST['user_name'] ) ) : '';
 103      $admin_email  = isset( $_POST['admin_email'] ) ? trim( wp_unslash( $_POST['admin_email'] ) ) : '';
 104  
 105      if ( ! is_null( $error ) ) {
 106          ?>
 107  <h1><?php _ex( 'Welcome', 'Howdy' ); ?></h1>
 108  <p class="message"><?php echo $error; ?></p>
 109  <?php } ?>
 110  <form id="setup" method="post" action="install.php?step=2" novalidate="novalidate">
 111      <table class="form-table" role="presentation">
 112          <tr>
 113              <th scope="row"><label for="weblog_title"><?php _e( 'Site Title' ); ?></label></th>
 114              <td><input name="weblog_title" type="text" id="weblog_title" size="25" value="<?php echo esc_attr( $weblog_title ); ?>" /></td>
 115          </tr>
 116          <tr>
 117              <?php if ( $user_table ) : ?>
 118                  <th scope="row"><?php _e( 'Username' ); ?></th>
 119                  <td>
 120                      <?php _e( 'User(s) already exists.' ); ?>
 121                      <input name="user_name" type="hidden" value="admin" />
 122                  </td>
 123              <?php else : ?>
 124                  <th scope="row"><label for="user_login"><?php _e( 'Username' ); ?></label></th>
 125                  <td>
 126                      <input name="user_name" type="text" id="user_login" size="25" aria-describedby="user-name-desc" value="<?php echo esc_attr( sanitize_user( $user_name, true ) ); ?>" />
 127                      <p id="user-name-desc"><?php _e( 'Usernames can have only alphanumeric characters, spaces, underscores, hyphens, periods, and the @ symbol.' ); ?></p>
 128                  </td>
 129              <?php endif; ?>
 130          </tr>
 131          <?php if ( ! $user_table ) : ?>
 132          <tr class="form-field form-required user-pass1-wrap">
 133              <th scope="row">
 134                  <label for="pass1">
 135                      <?php _e( 'Password' ); ?>
 136                  </label>
 137              </th>
 138              <td>
 139                  <div class="wp-pwd">
 140                      <?php $initial_password = isset( $_POST['admin_password'] ) ? stripslashes( $_POST['admin_password'] ) : wp_generate_password( 18 ); ?>
 141                      <div class="password-input-wrapper">
 142                          <input type="password" name="admin_password" id="pass1" class="regular-text" autocomplete="new-password" spellcheck="false" data-reveal="1" data-pw="<?php echo esc_attr( $initial_password ); ?>" aria-describedby="pass-strength-result admin-password-desc" />
 143                          <div id="pass-strength-result" aria-live="polite"></div>
 144                      </div>
 145                      <button type="button" class="button wp-hide-pw user-new-password-toggle hide-if-no-js" data-start-masked="<?php echo (int) isset( $_POST['admin_password'] ); ?>" data-toggle="0" aria-label="<?php esc_attr_e( 'Hide password' ); ?>">
 146                          <span class="dashicons dashicons-hidden"></span>
 147                          <span class="text"><?php _e( 'Hide' ); ?></span>
 148                      </button>
 149                  </div>
 150                  <p id="admin-password-desc"><span class="description important hide-if-no-js">
 151                  <strong><?php _e( 'Important:' ); ?></strong>
 152                  <?php /* translators: The non-breaking space prevents 1Password from thinking the text "log in" should trigger a password save prompt. */ ?>
 153                  <?php _e( 'You will need this password to log&nbsp;in. Please store it in a secure location.' ); ?></span></p>
 154              </td>
 155          </tr>
 156          <tr class="form-field form-required user-pass2-wrap hide-if-js">
 157              <th scope="row">
 158                  <label for="pass2"><?php _e( 'Repeat Password' ); ?>
 159                      <span class="description"><?php _e( '(required)' ); ?></span>
 160                  </label>
 161              </th>
 162              <td>
 163                  <input type="password" name="admin_password2" id="pass2" autocomplete="new-password" spellcheck="false" />
 164              </td>
 165          </tr>
 166          <tr class="pw-weak">
 167              <th scope="row"><?php _e( 'Confirm Password' ); ?></th>
 168              <td>
 169                  <label>
 170                      <input type="checkbox" name="pw_weak" class="pw-checkbox" />
 171                      <?php _e( 'Confirm use of weak password' ); ?>
 172                  </label>
 173              </td>
 174          </tr>
 175          <?php endif; ?>
 176          <tr>
 177              <th scope="row"><label for="admin_email"><?php _e( 'Your Email' ); ?></label></th>
 178              <td><input name="admin_email" type="email" id="admin_email" size="25" aria-describedby="admin-email-desc" value="<?php echo esc_attr( $admin_email ); ?>" />
 179              <p id="admin-email-desc"><?php _e( 'Double-check your email address before continuing.' ); ?></p></td>
 180          </tr>
 181          <?php
 182              $has_action_blog_privacy_selector = has_action( 'blog_privacy_selector' );
 183              $blog_privacy_selector_title      = $has_action_blog_privacy_selector ? __( 'Site visibility' ) : __( 'Search engine visibility' );
 184              $fieldset_aria_describedby        = $has_action_blog_privacy_selector ? ' aria-describedby="options-site-visibility-description"' : '';
 185          ?>
 186          <tr>
 187              <th scope="row"><?php echo esc_html( $blog_privacy_selector_title ); ?></th>
 188              <td>
 189                  <fieldset<?php echo $fieldset_aria_describedby; ?>>
 190                      <legend class="screen-reader-text"><?php echo esc_html( $blog_privacy_selector_title ); ?></legend>
 191                      <?php
 192                      if ( $has_action_blog_privacy_selector ) {
 193                          ?>
 194                          <input id="blog-public" type="radio" name="blog_public" value="1" <?php checked( 1, $blog_public ); ?> />
 195                          <label for="blog-public"><?php _e( 'Allow search engines to index this site' ); ?></label><br />
 196                          <input id="blog-norobots" type="radio" name="blog_public" value="0" <?php checked( 0, $blog_public ); ?> />
 197                          <label for="blog-norobots"><?php _e( 'Discourage search engines from indexing this site' ); ?></label>
 198                          <p id="options-site-visibility-description" class="description"><?php _e( 'Note: Discouraging search engines does not block access to your site &mdash; it is up to search engines to honor your request.' ); ?></p>
 199                          <?php
 200                          /** This action is documented in wp-admin/options-reading.php */
 201                          do_action( 'blog_privacy_selector' );
 202                      } else {
 203                          ?>
 204                          <input name="blog_public" type="checkbox" id="blog_public" aria-describedby="options-site-visibility-description" value="0" <?php checked( 0, $blog_public ); ?> />
 205                          <label for="blog_public"><?php _e( 'Discourage search engines from indexing this site' ); ?></label>
 206                          <p id="options-site-visibility-description" class="description"><?php _e( 'It is up to search engines to honor this request.' ); ?></p>
 207                      <?php } ?>
 208                  </fieldset>
 209              </td>
 210          </tr>
 211      </table>
 212      <p class="step"><?php submit_button( __( 'Install WordPress' ), 'large', 'Submit', false, array( 'id' => 'submit' ) ); ?></p>
 213      <input type="hidden" name="language" value="<?php echo isset( $_REQUEST['language'] ) ? esc_attr( $_REQUEST['language'] ) : ''; ?>" />
 214  </form>
 215      <?php
 216  } // End display_setup_form().
 217  
 218  // Let's check to make sure WP isn't already installed.
 219  if ( is_blog_installed() ) {
 220      display_header();
 221      die(
 222          '<h1>' . __( 'Already Installed' ) . '</h1>' .
 223          '<p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p>' .
 224          '<p class="step"><a href="' . esc_url( wp_login_url() ) . '">' . __( 'Log In' ) . '</a></p>' .
 225          '</body></html>'
 226      );
 227  }
 228  
 229  /**
 230   * @global string   $wp_version              The WordPress version string.
 231   * @global string   $required_php_version    The minimum required PHP version string.
 232   * @global string[] $required_php_extensions The names of required PHP extensions.
 233   * @global string   $required_mysql_version  The minimum required MySQL version string.
 234   * @global wpdb     $wpdb                    WordPress database abstraction object.
 235   */
 236  global $wp_version, $required_php_version, $required_php_extensions, $required_mysql_version, $wpdb;
 237  
 238  $php_version   = PHP_VERSION;
 239  $mysql_version = $wpdb->db_version();
 240  $php_compat    = version_compare( $php_version, $required_php_version, '>=' );
 241  $mysql_compat  = version_compare( $mysql_version, $required_mysql_version, '>=' ) || file_exists( WP_CONTENT_DIR . '/db.php' );
 242  
 243  $version_url = sprintf(
 244      /* translators: %s: WordPress version. */
 245      esc_url( __( 'https://wordpress.org/documentation/wordpress-version/version-%s/' ) ),
 246      sanitize_title( $wp_version )
 247  );
 248  
 249  $php_update_message = '</p><p>' . sprintf(
 250      /* translators: %s: URL to Update PHP page. */
 251      __( '<a href="%s">Learn more about updating PHP</a>.' ),
 252      esc_url( wp_get_update_php_url() )
 253  );
 254  
 255  $annotation = wp_get_update_php_annotation();
 256  
 257  if ( $annotation ) {
 258      $php_update_message .= '</p><p><em>' . $annotation . '</em>';
 259  }
 260  
 261  if ( ! $mysql_compat && ! $php_compat ) {
 262      $compat = sprintf(
 263          /* 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. */
 264          __( 'You cannot install 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.' ),
 265          $version_url,
 266          $wp_version,
 267          $required_php_version,
 268          $required_mysql_version,
 269          $php_version,
 270          $mysql_version
 271      ) . $php_update_message;
 272  } elseif ( ! $php_compat ) {
 273      $compat = sprintf(
 274          /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Current PHP version number. */
 275          __( 'You cannot install because <a href="%1$s">WordPress %2$s</a> requires PHP version %3$s or higher. You are running version %4$s.' ),
 276          $version_url,
 277          $wp_version,
 278          $required_php_version,
 279          $php_version
 280      ) . $php_update_message;
 281  } elseif ( ! $mysql_compat ) {
 282      $compat = sprintf(
 283          /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required MySQL version number, 4: Current MySQL version number. */
 284          __( 'You cannot install because <a href="%1$s">WordPress %2$s</a> requires MySQL version %3$s or higher. You are running version %4$s.' ),
 285          $version_url,
 286          $wp_version,
 287          $required_mysql_version,
 288          $mysql_version
 289      );
 290  }
 291  
 292  if ( ! $mysql_compat || ! $php_compat ) {
 293      display_header();
 294      die( '<h1>' . __( 'Requirements Not Met' ) . '</h1><p>' . $compat . '</p></body></html>' );
 295  }
 296  
 297  if ( isset( $required_php_extensions ) && is_array( $required_php_extensions ) ) {
 298      $missing_extensions = array();
 299  
 300      foreach ( $required_php_extensions as $extension ) {
 301          if ( extension_loaded( $extension ) ) {
 302              continue;
 303          }
 304  
 305          $missing_extensions[] = sprintf(
 306              /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: The PHP extension name needed. */
 307              __( 'You cannot install because <a href="%1$s">WordPress %2$s</a> requires the %3$s PHP extension.' ),
 308              $version_url,
 309              $wp_version,
 310              $extension
 311          );
 312      }
 313  
 314      if ( count( $missing_extensions ) > 0 ) {
 315          display_header();
 316          die( '<h1>' . __( 'Requirements Not Met' ) . '</h1><p>' . implode( '</p><p>', $missing_extensions ) . '</p></body></html>' );
 317      }
 318  }
 319  
 320  if ( ! is_string( $wpdb->base_prefix ) || '' === $wpdb->base_prefix ) {
 321      display_header();
 322      die(
 323          '<h1>' . __( 'Configuration Error' ) . '</h1>' .
 324          '<p>' . sprintf(
 325              /* translators: %s: wp-config.php */
 326              __( 'Your %s file has an empty database table prefix, which is not supported.' ),
 327              '<code>wp-config.php</code>'
 328          ) . '</p></body></html>'
 329      );
 330  }
 331  
 332  // Set error message if DO_NOT_UPGRADE_GLOBAL_TABLES isn't set as it will break install.
 333  if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
 334      display_header();
 335      die(
 336          '<h1>' . __( 'Configuration Error' ) . '</h1>' .
 337          '<p>' . sprintf(
 338              /* translators: %s: DO_NOT_UPGRADE_GLOBAL_TABLES */
 339              __( 'The constant %s cannot be defined when installing WordPress.' ),
 340              '<code>DO_NOT_UPGRADE_GLOBAL_TABLES</code>'
 341          ) . '</p></body></html>'
 342      );
 343  }
 344  
 345  /**
 346   * @global string    $wp_local_package Locale code of the package.
 347   * @global WP_Locale $wp_locale        WordPress date and time locale object.
 348   * @global wpdb      $wpdb             WordPress database abstraction object.
 349   */
 350  $language = '';
 351  if ( ! empty( $_REQUEST['language'] ) ) {
 352      $language = sanitize_locale_name( $_REQUEST['language'] );
 353  } elseif ( isset( $GLOBALS['wp_local_package'] ) ) {
 354      $language = $GLOBALS['wp_local_package'];
 355  }
 356  
 357  $scripts_to_print = array( 'jquery' );
 358  
 359  switch ( $step ) {
 360      case 0: // Step 0.
 361          if ( wp_can_install_language_pack() && empty( $language ) ) {
 362              $languages = wp_get_available_translations();
 363              if ( $languages ) {
 364                  $scripts_to_print[] = 'language-chooser';
 365                  display_header( 'language-chooser' );
 366                  echo '<form id="setup" method="post" action="?step=1">';
 367                  wp_install_language_form( $languages );
 368                  echo '</form>';
 369                  break;
 370              }
 371          }
 372  
 373          // Deliberately fall through if we can't reach the translations API.
 374  
 375      case 1: // Step 1, direct link or from language chooser.
 376          if ( ! empty( $language ) ) {
 377              $loaded_language = wp_download_language_pack( $language );
 378              if ( $loaded_language ) {
 379                  load_default_textdomain( $loaded_language );
 380                  $GLOBALS['wp_locale'] = new WP_Locale();
 381              }
 382          }
 383  
 384          $scripts_to_print[] = 'user-profile';
 385  
 386          display_header();
 387          ?>
 388  <h1><?php _ex( 'Welcome', 'Howdy' ); ?></h1>
 389  <p><?php _e( 'Welcome to the famous five-minute WordPress installation process! Just fill in the information below and you&#8217;ll be on your way to using the most extendable and powerful personal publishing platform in the world.' ); ?></p>
 390  
 391  <h2><?php _e( 'Information needed' ); ?></h2>
 392  <p><?php _e( 'Please provide the following information. Do not worry, you can always change these settings later.' ); ?></p>
 393  
 394          <?php
 395          display_setup_form();
 396          break;
 397      case 2:
 398          if ( ! empty( $language ) && load_default_textdomain( $language ) ) {
 399              $loaded_language      = $language;
 400              $GLOBALS['wp_locale'] = new WP_Locale();
 401          } else {
 402              $loaded_language = 'en_US';
 403          }
 404  
 405          if ( ! empty( $wpdb->error ) ) {
 406              wp_die( $wpdb->error->get_error_message() );
 407          }
 408  
 409          $scripts_to_print[] = 'user-profile';
 410  
 411          display_header();
 412          // Fill in the data we gathered.
 413          $weblog_title         = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) : '';
 414          $user_name            = isset( $_POST['user_name'] ) ? trim( wp_unslash( $_POST['user_name'] ) ) : '';
 415          $admin_password       = isset( $_POST['admin_password'] ) ? wp_unslash( $_POST['admin_password'] ) : '';
 416          $admin_password_check = isset( $_POST['admin_password2'] ) ? wp_unslash( $_POST['admin_password2'] ) : '';
 417          $admin_email          = isset( $_POST['admin_email'] ) ? trim( wp_unslash( $_POST['admin_email'] ) ) : '';
 418          $public               = isset( $_POST['blog_public'] ) ? (int) $_POST['blog_public'] : 1;
 419  
 420          // Check email address.
 421          $error = false;
 422          if ( empty( $user_name ) ) {
 423              // TODO: Poka-yoke.
 424              display_setup_form( __( 'Please provide a valid username.' ) );
 425              $error = true;
 426          } elseif ( sanitize_user( $user_name, true ) !== $user_name ) {
 427              display_setup_form( __( 'The username you provided has invalid characters.' ) );
 428              $error = true;
 429          } elseif ( $admin_password !== $admin_password_check ) {
 430              // TODO: Poka-yoke.
 431              display_setup_form( __( 'Your passwords do not match. Please try again.' ) );
 432              $error = true;
 433          } elseif ( empty( $admin_email ) ) {
 434              // TODO: Poka-yoke.
 435              display_setup_form( __( 'You must provide an email address.' ) );
 436              $error = true;
 437          } elseif ( ! is_email( $admin_email ) ) {
 438              // TODO: Poka-yoke.
 439              display_setup_form( __( 'Sorry, that is not a valid email address. Email addresses look like <code>username@example.com</code>.' ) );
 440              $error = true;
 441          }
 442  
 443          if ( false === $error ) {
 444              $wpdb->show_errors();
 445              $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loaded_language );
 446              ?>
 447  
 448  <h1><?php _e( 'Success!' ); ?></h1>
 449  
 450  <p><?php _e( 'WordPress has been installed. Thank you, and enjoy!' ); ?></p>
 451  
 452  <table class="form-table install-success">
 453      <tr>
 454          <th><?php _e( 'Username' ); ?></th>
 455          <td><?php echo esc_html( sanitize_user( $user_name, true ) ); ?></td>
 456      </tr>
 457      <tr>
 458          <th><?php _e( 'Password' ); ?></th>
 459          <td>
 460              <?php if ( ! empty( $result['password'] ) && empty( $admin_password_check ) ) : ?>
 461                  <code><?php echo esc_html( $result['password'] ); ?></code><br />
 462              <?php endif; ?>
 463              <p><?php echo $result['password_message']; ?></p>
 464          </td>
 465      </tr>
 466  </table>
 467  
 468  <p class="step"><a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log In' ); ?></a></p>
 469  
 470              <?php
 471          }
 472          break;
 473  }
 474  
 475  if ( ! wp_is_mobile() ) {
 476      wp_print_inline_script_tag(
 477          <<<'JS'
 478          const t = document.getElementById( 'weblog_title' );
 479          if ( t ) {
 480              t.focus();
 481          }
 482          JS
 483      );
 484  }
 485  
 486  wp_print_scripts( $scripts_to_print );
 487  
 488  wp_print_inline_script_tag(
 489      <<<'JS'
 490      /**
 491       * Shows the content intended only for browsers with JS enabled.
 492       *
 493       * @param {JQueryStatic} $ The jQuery object.
 494       */
 495      jQuery( function ( $ ) {
 496          $( '.hide-if-no-js' ).removeClass( 'hide-if-no-js' );
 497      } );
 498      JS
 499  );
 500  ?>
 501  </body>
 502  </html>


Generated : Fri Sep 25 08:20:31 2026 Cross-referenced by PHPXref