[ 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">
 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' ); ?></label>
 159              </th>
 160              <td>
 161                  <input type="password" name="admin_password2" id="pass2" autocomplete="new-password" spellcheck="false" aria-describedby="admin-repeat-password-desc" />
 162                  <p id="admin-repeat-password-desc">
 163                      <span class="description important hide-if-js">
 164                      <?php _e( 'You can leave both password fields empty and one will be auto-generated for you.' ); ?>
 165                      </span>
 166                  </p>
 167              </td>
 168          </tr>
 169          <tr class="pw-weak">
 170              <th scope="row"><?php _e( 'Confirm Password' ); ?></th>
 171              <td>
 172                  <label>
 173                      <input type="checkbox" name="pw_weak" class="pw-checkbox" />
 174                      <?php _e( 'Confirm use of weak password' ); ?>
 175                  </label>
 176              </td>
 177          </tr>
 178          <?php endif; ?>
 179          <tr>
 180              <th scope="row"><label for="admin_email"><?php _e( 'Your Email' ); ?></label></th>
 181              <td><input name="admin_email" type="email" id="admin_email" size="25" aria-describedby="admin-email-desc" value="<?php echo esc_attr( $admin_email ); ?>" />
 182              <p id="admin-email-desc"><?php _e( 'Double-check your email address before continuing.' ); ?></p></td>
 183          </tr>
 184          <?php
 185              $has_action_blog_privacy_selector = has_action( 'blog_privacy_selector' );
 186              $blog_privacy_selector_title      = $has_action_blog_privacy_selector ? __( 'Site visibility' ) : __( 'Search engine visibility' );
 187              $fieldset_aria_describedby        = $has_action_blog_privacy_selector ? ' aria-describedby="options-site-visibility-description"' : '';
 188          ?>
 189          <tr>
 190              <th scope="row"><?php echo esc_html( $blog_privacy_selector_title ); ?></th>
 191              <td>
 192                  <fieldset<?php echo $fieldset_aria_describedby; ?>>
 193                      <legend class="screen-reader-text"><?php echo esc_html( $blog_privacy_selector_title ); ?></legend>
 194                      <?php
 195                      if ( $has_action_blog_privacy_selector ) {
 196                          ?>
 197                          <input id="blog-public" type="radio" name="blog_public" value="1" <?php checked( 1, $blog_public ); ?> />
 198                          <label for="blog-public"><?php _e( 'Allow search engines to index this site' ); ?></label><br />
 199                          <input id="blog-norobots" type="radio" name="blog_public" value="0" <?php checked( 0, $blog_public ); ?> />
 200                          <label for="blog-norobots"><?php _e( 'Discourage search engines from indexing this site' ); ?></label>
 201                          <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>
 202                          <?php
 203                          /** This action is documented in wp-admin/options-reading.php */
 204                          do_action( 'blog_privacy_selector' );
 205                      } else {
 206                          ?>
 207                          <input name="blog_public" type="checkbox" id="blog_public" aria-describedby="options-site-visibility-description" value="0" <?php checked( 0, $blog_public ); ?> />
 208                          <label for="blog_public"><?php _e( 'Discourage search engines from indexing this site' ); ?></label>
 209                          <p id="options-site-visibility-description" class="description"><?php _e( 'It is up to search engines to honor this request.' ); ?></p>
 210                      <?php } ?>
 211                  </fieldset>
 212              </td>
 213          </tr>
 214      </table>
 215      <p class="step"><?php submit_button( __( 'Install WordPress' ), 'large', 'Submit', false, array( 'id' => 'submit' ) ); ?></p>
 216      <input type="hidden" name="language" value="<?php echo isset( $_REQUEST['language'] ) ? esc_attr( $_REQUEST['language'] ) : ''; ?>" />
 217  </form>
 218      <?php
 219  } // End display_setup_form().
 220  
 221  // Let's check to make sure WP isn't already installed.
 222  if ( is_blog_installed() ) {
 223      display_header();
 224      die(
 225          '<h1>' . __( 'Already Installed' ) . '</h1>' .
 226          '<p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p>' .
 227          '<p class="step"><a href="' . esc_url( wp_login_url() ) . '">' . __( 'Log In' ) . '</a></p>' .
 228          '</body></html>'
 229      );
 230  }
 231  
 232  /**
 233   * @global string   $wp_version              The WordPress version string.
 234   * @global string   $required_php_version    The minimum required PHP version string.
 235   * @global string[] $required_php_extensions The names of required PHP extensions.
 236   * @global string   $required_mysql_version  The minimum required MySQL version string.
 237   * @global wpdb     $wpdb                    WordPress database abstraction object.
 238   */
 239  global $wp_version, $required_php_version, $required_php_extensions, $required_mysql_version, $wpdb;
 240  
 241  $php_version   = PHP_VERSION;
 242  $mysql_version = $wpdb->db_version();
 243  $php_compat    = version_compare( $php_version, $required_php_version, '>=' );
 244  $mysql_compat  = version_compare( $mysql_version, $required_mysql_version, '>=' ) || file_exists( WP_CONTENT_DIR . '/db.php' );
 245  
 246  $version_url = sprintf(
 247      /* translators: %s: WordPress version. */
 248      esc_url( __( 'https://wordpress.org/documentation/wordpress-version/version-%s/' ) ),
 249      sanitize_title( $wp_version )
 250  );
 251  
 252  $php_update_message = '</p><p>' . sprintf(
 253      /* translators: %s: URL to Update PHP page. */
 254      __( '<a href="%s">Learn more about updating PHP</a>.' ),
 255      esc_url( wp_get_update_php_url() )
 256  );
 257  
 258  $annotation = wp_get_update_php_annotation();
 259  
 260  if ( $annotation ) {
 261      $php_update_message .= '</p><p><em>' . $annotation . '</em>';
 262  }
 263  
 264  if ( ! $mysql_compat && ! $php_compat ) {
 265      $compat = sprintf(
 266          /* 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. */
 267          __( '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.' ),
 268          $version_url,
 269          $wp_version,
 270          $required_php_version,
 271          $required_mysql_version,
 272          $php_version,
 273          $mysql_version
 274      ) . $php_update_message;
 275  } elseif ( ! $php_compat ) {
 276      $compat = sprintf(
 277          /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required PHP version number, 4: Current PHP version number. */
 278          __( '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.' ),
 279          $version_url,
 280          $wp_version,
 281          $required_php_version,
 282          $php_version
 283      ) . $php_update_message;
 284  } elseif ( ! $mysql_compat ) {
 285      $compat = sprintf(
 286          /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: Minimum required MySQL version number, 4: Current MySQL version number. */
 287          __( '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.' ),
 288          $version_url,
 289          $wp_version,
 290          $required_mysql_version,
 291          $mysql_version
 292      );
 293  }
 294  
 295  if ( ! $mysql_compat || ! $php_compat ) {
 296      display_header();
 297      die( '<h1>' . __( 'Requirements Not Met' ) . '</h1><p>' . $compat . '</p></body></html>' );
 298  }
 299  
 300  if ( isset( $required_php_extensions ) && is_array( $required_php_extensions ) ) {
 301      $missing_extensions = array();
 302  
 303      foreach ( $required_php_extensions as $extension ) {
 304          if ( extension_loaded( $extension ) ) {
 305              continue;
 306          }
 307  
 308          $missing_extensions[] = sprintf(
 309              /* translators: 1: URL to WordPress release notes, 2: WordPress version number, 3: The PHP extension name needed. */
 310              __( 'You cannot install because <a href="%1$s">WordPress %2$s</a> requires the %3$s PHP extension.' ),
 311              $version_url,
 312              $wp_version,
 313              $extension
 314          );
 315      }
 316  
 317      if ( count( $missing_extensions ) > 0 ) {
 318          display_header();
 319          die( '<h1>' . __( 'Requirements Not Met' ) . '</h1><p>' . implode( '</p><p>', $missing_extensions ) . '</p></body></html>' );
 320      }
 321  }
 322  
 323  if ( ! is_string( $wpdb->base_prefix ) || '' === $wpdb->base_prefix ) {
 324      display_header();
 325      die(
 326          '<h1>' . __( 'Configuration Error' ) . '</h1>' .
 327          '<p>' . sprintf(
 328              /* translators: %s: wp-config.php */
 329              __( 'Your %s file has an empty database table prefix, which is not supported.' ),
 330              '<code>wp-config.php</code>'
 331          ) . '</p></body></html>'
 332      );
 333  }
 334  
 335  // Set error message if DO_NOT_UPGRADE_GLOBAL_TABLES isn't set as it will break install.
 336  if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
 337      display_header();
 338      die(
 339          '<h1>' . __( 'Configuration Error' ) . '</h1>' .
 340          '<p>' . sprintf(
 341              /* translators: %s: DO_NOT_UPGRADE_GLOBAL_TABLES */
 342              __( 'The constant %s cannot be defined when installing WordPress.' ),
 343              '<code>DO_NOT_UPGRADE_GLOBAL_TABLES</code>'
 344          ) . '</p></body></html>'
 345      );
 346  }
 347  
 348  /**
 349   * @global string    $wp_local_package Locale code of the package.
 350   * @global WP_Locale $wp_locale        WordPress date and time locale object.
 351   * @global wpdb      $wpdb             WordPress database abstraction object.
 352   */
 353  $language = '';
 354  if ( ! empty( $_REQUEST['language'] ) ) {
 355      $language = sanitize_locale_name( $_REQUEST['language'] );
 356  } elseif ( isset( $GLOBALS['wp_local_package'] ) ) {
 357      $language = $GLOBALS['wp_local_package'];
 358  }
 359  
 360  $scripts_to_print = array( 'jquery' );
 361  
 362  switch ( $step ) {
 363      case 0: // Step 0.
 364          if ( wp_can_install_language_pack() && empty( $language ) ) {
 365              $languages = wp_get_available_translations();
 366              if ( $languages ) {
 367                  $scripts_to_print[] = 'language-chooser';
 368                  display_header( 'language-chooser' );
 369                  echo '<form id="setup" method="post" action="?step=1">';
 370                  wp_install_language_form( $languages );
 371                  echo '</form>';
 372                  break;
 373              }
 374          }
 375  
 376          // Deliberately fall through if we can't reach the translations API.
 377  
 378      case 1: // Step 1, direct link or from language chooser.
 379          if ( ! empty( $language ) ) {
 380              $loaded_language = wp_download_language_pack( $language );
 381              if ( $loaded_language ) {
 382                  load_default_textdomain( $loaded_language );
 383                  $GLOBALS['wp_locale'] = new WP_Locale();
 384              }
 385          }
 386  
 387          $scripts_to_print[] = 'user-profile';
 388  
 389          display_header();
 390          ?>
 391  <h1><?php _ex( 'Welcome', 'Howdy' ); ?></h1>
 392  <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>
 393  
 394  <h2><?php _e( 'Information needed' ); ?></h2>
 395  <p><?php _e( 'Please provide the following information. Do not worry, you can always change these settings later.' ); ?></p>
 396  
 397          <?php
 398          display_setup_form();
 399          break;
 400      case 2:
 401          if ( ! empty( $language ) && load_default_textdomain( $language ) ) {
 402              $loaded_language      = $language;
 403              $GLOBALS['wp_locale'] = new WP_Locale();
 404          } else {
 405              $loaded_language = 'en_US';
 406          }
 407  
 408          if ( ! empty( $wpdb->error ) ) {
 409              wp_die( $wpdb->error->get_error_message() );
 410          }
 411  
 412          $scripts_to_print[] = 'user-profile';
 413  
 414          display_header();
 415          // Fill in the data we gathered.
 416          $weblog_title         = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) : '';
 417          $user_name            = isset( $_POST['user_name'] ) ? trim( wp_unslash( $_POST['user_name'] ) ) : '';
 418          $admin_password       = isset( $_POST['admin_password'] ) ? wp_unslash( $_POST['admin_password'] ) : '';
 419          $admin_password_check = isset( $_POST['admin_password2'] ) ? wp_unslash( $_POST['admin_password2'] ) : '';
 420          $admin_email          = isset( $_POST['admin_email'] ) ? trim( wp_unslash( $_POST['admin_email'] ) ) : '';
 421          $public               = isset( $_POST['blog_public'] ) ? (int) $_POST['blog_public'] : 1;
 422  
 423          // Check email address.
 424          $error = false;
 425          if ( empty( $user_name ) ) {
 426              // TODO: Poka-yoke.
 427              display_setup_form( __( 'Please provide a valid username.' ) );
 428              $error = true;
 429          } elseif ( sanitize_user( $user_name, true ) !== $user_name ) {
 430              display_setup_form( __( 'The username you provided has invalid characters.' ) );
 431              $error = true;
 432          } elseif ( $admin_password !== $admin_password_check ) {
 433              // TODO: Poka-yoke.
 434              display_setup_form( __( 'Your passwords do not match. Please try again.' ) );
 435              $error = true;
 436          } elseif ( empty( $admin_email ) ) {
 437              // TODO: Poka-yoke.
 438              display_setup_form( __( 'You must provide an email address.' ) );
 439              $error = true;
 440          } elseif ( ! is_email( $admin_email ) ) {
 441              // TODO: Poka-yoke.
 442              display_setup_form( __( 'Sorry, that is not a valid email address. Email addresses look like <code>username@example.com</code>.' ) );
 443              $error = true;
 444          }
 445  
 446          if ( false === $error ) {
 447              $wpdb->show_errors();
 448              $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loaded_language );
 449              ?>
 450  
 451  <h1><?php _e( 'Success!' ); ?></h1>
 452  
 453  <p><?php _e( 'WordPress has been installed. Thank you, and enjoy!' ); ?></p>
 454  
 455  <table class="form-table install-success">
 456      <tr>
 457          <th><?php _e( 'Username' ); ?></th>
 458          <td><?php echo esc_html( sanitize_user( $user_name, true ) ); ?></td>
 459      </tr>
 460      <tr>
 461          <th><?php _e( 'Password' ); ?></th>
 462          <td>
 463              <?php if ( ! empty( $result['password'] ) && empty( $admin_password_check ) ) : ?>
 464                  <code><?php echo esc_html( $result['password'] ); ?></code><br />
 465              <?php endif; ?>
 466              <p><?php echo $result['password_message']; ?></p>
 467          </td>
 468      </tr>
 469  </table>
 470  
 471  <p class="step"><a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log In' ); ?></a></p>
 472  
 473              <?php
 474          }
 475          break;
 476  }
 477  
 478  if ( ! wp_is_mobile() ) {
 479      wp_print_inline_script_tag(
 480          <<<'JS'
 481          const t = document.getElementById( 'weblog_title' );
 482          if ( t ) {
 483              t.focus();
 484          }
 485          JS
 486      );
 487  }
 488  
 489  wp_print_scripts( $scripts_to_print );
 490  
 491  wp_print_inline_script_tag(
 492      <<<'JS'
 493      /**
 494       * Shows the content intended only for browsers with JS enabled.
 495       *
 496       * @param {JQueryStatic} $ The jQuery object.
 497       */
 498      jQuery( function ( $ ) {
 499          $( '.hide-if-no-js' ).removeClass( 'hide-if-no-js' );
 500      } );
 501      JS
 502  );
 503  ?>
 504  </body>
 505  </html>


Generated : Sun Oct 25 08:20:35 2026 Cross-referenced by PHPXref