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


Generated : Fri Feb 21 08:20:01 2025 Cross-referenced by PHPXref