WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/14/2010 03:07:47 AM (10 years ago)
Author:
dd32
Message:

First pass at allowing username/password selection upon install. Includes some extra cleanup of the patch. Props dancole. See #10396

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/install.php

    r13124 r13134  
    2020/** Load WordPress Administration Upgrade API */
    2121require_once( dirname( __FILE__ ) . '/includes/upgrade.php' );
     22
     23/** Load wpdb */
     24require_once(dirname(dirname(__FILE__)) . '/wp-includes/wp-db.php');
    2225
    2326$step = isset( $_GET['step'] ) ? $_GET['step'] : 0;
     
    5457 */
    5558function display_setup_form( $error = null ) {
     59    global $wpdb;
     60    $user_table = ( $wpdb->get_var("SHOW TABLES LIKE '$wpdb->users'") != null ) ? true : false;
     61
    5662    // Ensure that Blogs appear in search engines by default
    5763    $blog_public = 1;
     
    5965        $blog_public = isset( $_POST['blog_public'] );
    6066
     67    $weblog_title = isset( $_POST['weblog_title'] ) ? trim( stripslashes( $_POST['weblog_title'] ) ) : '';
     68    $user_name = isset($_POST['user_name']) ? trim( stripslashes( $_POST['user_name'] ) ) : 'admin';
     69    $admin_password = isset($_POST['admin_password']) ? trim( stripslashes( $_POST['admin_password'] ) ) : '';
     70    $admin_email  = isset( $_POST['admin_email']  ) ? trim( stripslashes( $_POST['admin_email'] ) ) : '';
     71
    6172    if ( ! is_null( $error ) ) {
    6273?>
     
    6778        <tr>
    6879            <th scope="row"><label for="weblog_title"><?php _e( 'Blog Title' ); ?></label></th>
    69             <td><input name="weblog_title" type="text" id="weblog_title" size="25" value="<?php echo ( isset( $_POST['weblog_title'] ) ? esc_attr( $_POST['weblog_title'] ) : '' ); ?>" /></td>
    70         </tr>
     80            <td><input name="weblog_title" type="text" id="weblog_title" size="25" value="<?php echo esc_attr( $weblog_title ); ?>" /></td>
     81        </tr>
     82        <tr>
     83            <th scope="row"><label for="user_name"><?php _e('User Name'); ?></label></th>
     84            <td>
     85            <?php
     86            if ( $user_table ) {
     87                _e('User(s) already exists.');
     88            } else {
     89                ?><input name="user_name" type="text" id="user_login" size="25" value="<?php echo esc_attr( $user_name ); ?>" /><?php
     90            } ?>
     91            </td>
     92        </tr>
     93        <?php if ( ! $user_table ) : ?>
     94        <tr>
     95            <th scope="row"><label for="admin_password"><?php _e('Password'); ?></label></th>
     96            <td>
     97                <input name="admin_password" type="password" id="pass1" size="25" value="<?php  echo esc_attr( $admin_password ); ?>" />
     98                <br /><?php _e('A password will be automatically generated for you if you leave this field blank.'); ?>
     99                <br /><div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
     100                <p class="description indicator-hint"><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).'); ?></p>
     101            </td>
     102        </tr>
     103        <?php endif; ?>
    71104        <tr>
    72105            <th scope="row"><label for="admin_email"><?php _e( 'Your E-mail' ); ?></label></th>
    73             <td><input name="admin_email" type="text" id="admin_email" size="25" value="<?php echo ( isset( $_POST['admin_email'] ) ? esc_attr( $_POST['admin_email'] ) : '' ); ?>" /><br />
     106            <td><input name="admin_email" type="text" id="admin_email" size="25" value="<?php  echo esc_attr( $admin_email ); ?>" /><br />
    74107            <?php _e( 'Double-check your email address before continuing.' ); ?></td>
    75108        </tr>
     
    126159        display_header();
    127160        // Fill in the data we gathered
    128         $weblog_title = isset( $_POST['weblog_title'] ) ? stripslashes( $_POST['weblog_title'] ) : '';
    129         $admin_email  = isset( $_POST['admin_email']  ) ? stripslashes( $_POST['admin_email'] ) : '';
     161        $weblog_title = isset( $_POST['weblog_title'] ) ? trim( stripslashes( $_POST['weblog_title'] ) ) : '';
     162        $user_name = isset($_POST['user_name']) ? trim( stripslashes( $_POST['user_name'] ) ) : 'admin';
     163        $admin_password = isset($_POST['admin_password']) ? trim( stripslashes( $_POST['admin_password'] ) ) : '';
     164        $admin_email  = isset( $_POST['admin_email']  ) ?trim( stripslashes( $_POST['admin_email'] ) ) : '';
    130165        $public       = isset( $_POST['blog_public']  ) ? (int) $_POST['blog_public'] : 0;
    131166        // check e-mail address
    132167        $error = false;
    133         if ( empty( $admin_email ) ) {
     168        if ( empty( $user_name ) ) {
     169            // TODO: poka-yoke
     170            display_setup_form( __('you must provide a valid user name.') );
     171            $error = true;
     172        } else if ( empty( $admin_email ) ) {
    134173            // TODO: poka-yoke
    135174            display_setup_form( __( 'you must provide an e-mail address.' ) );
     
    143182        if ( $error === false ) {
    144183            $wpdb->show_errors();
    145             $result = wp_install( $weblog_title, 'admin', $admin_email, $public );
     184            $result = wp_install($weblog_title, $user_name, $admin_email, $public, '', $admin_password);
    146185            extract( $result, EXTR_SKIP );
    147186?>
     
    154193    <tr>
    155194        <th><?php _e( 'Username' ); ?></th>
    156         <td><code>admin</code></td>
     195        <td><code><?php echo esc_html($user_name); ?></code></td>
    157196    </tr>
    158197    <tr>
     
    160199        <td><?php
    161200        if ( ! empty( $password ) )
    162             echo "<code>$password</code><br />";
     201            echo '<code>'. esc_html($password) .'</code><br />';
    163202        echo "<p>$password_message</p>"; ?>
    164203        </td>
     
    174213?>
    175214<script type="text/javascript">var t = document.getElementById('weblog_title'); if (t){ t.focus(); }</script>
     215<script type="text/javascript" src="../wp-includes/js/jquery/jquery.js"></script>
     216<script type="text/javascript" src="js/password-strength-meter.js"></script>
     217<script type="text/javascript" src="js/user-profile.js"></script>
     218<script type="text/javascript" src="js/utils.js"></script>
     219<script type='text/javascript'>
     220/* <![CDATA[ */
     221try{convertEntities(commonL10n);}catch(e){};
     222var pwsL10n = {
     223 empty: "Strength indicator",
     224 short: "Very weak",
     225 bad: "Weak",
     226 good: "Medium",
     227 strong: "Strong"
     228};
     229try{convertEntities(pwsL10n);}catch(e){};
     230/* ]]> */
     231</script>
    176232</body>
    177233</html>
Note: See TracChangeset for help on using the changeset viewer.