WordPress.org

Make WordPress Core

Ticket #9568: 9568.diff

File 9568.diff, 7.6 KB (added by Denis-de-Bernardy, 9 years ago)

updated patch, against 10966

  • wp-login.php

     
    205205        $user_email = apply_filters( 'user_registration_email', $user_email );
    206206
    207207        // Check the username
    208         if ( $user_login == '' )
    209                 $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.'));
    210         elseif ( !validate_username( $user_login ) ) {
    211                 $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid.  Please enter a valid username.'));
    212                 $user_login = '';
    213         } elseif ( username_exists( $user_login ) )
    214                 $errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered, please choose another one.'));
     208        if ( !empty($user_login) ) {
     209                if ( !validate_username( $user_login ) ) {
     210                        $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid.  Please enter a valid username.'));
     211                        $user_login = '';
     212                } elseif ( username_exists( $user_login ) )
     213                        $errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered, please choose another one.'));
     214        }
    215215
    216216        // Check the e-mail address
    217217        if ($user_email == '') {
     
    222222        } elseif ( email_exists( $user_email ) )
    223223                $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.'));
    224224
     225        if ( !$errors->get_error_code() && empty($user_login) )
     226                $user_login = $user_email;
     227
    225228        do_action('register_post', $user_login, $user_email, $errors);
    226229
    227230        $errors = apply_filters( 'registration_errors', $errors );
     
    373376
    374377<form name="registerform" id="registerform" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" method="post">
    375378        <p>
    376                 <label><?php _e('Username') ?><br />
     379                <label><?php _e('Username (optional)') ?><br />
    377380                <input type="text" name="user_login" id="user_login" class="input" value="<?php echo attribute_escape(stripslashes($user_login)); ?>" size="20" tabindex="10" /></label>
    378381        </p>
    379382        <p>
     
    466469<?php if ( !isset($_GET['checkemail']) || !in_array( $_GET['checkemail'], array('confirm', 'newpass') ) ) : ?>
    467470<form name="loginform" id="loginform" action="<?php echo site_url('wp-login.php', 'login_post') ?>" method="post">
    468471        <p>
    469                 <label><?php _e('Username') ?><br />
     472                <label><?php _e('Username or E-mail') ?><br />
    470473                <input type="text" name="log" id="user_login" class="input" value="<?php echo $user_login; ?>" size="20" tabindex="10" /></label>
    471474        </p>
    472475        <p>
  • wp-includes/registration.php

     
    176176        if ( empty($user_registered) )
    177177                $user_registered = gmdate('Y-m-d H:i:s');
    178178
    179         $data = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
     179        $data = compact( 'user_login', 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
    180180        $data = stripslashes_deep( $data );
    181181
    182182        if ( $update ) {
    183183                $wpdb->update( $wpdb->users, $data, compact( 'ID' ) );
    184184                $user_id = (int) $ID;
    185185        } else {
    186                 $wpdb->insert( $wpdb->users, $data + compact( 'user_login' ) );
     186                $wpdb->insert( $wpdb->users, $data );
    187187                $user_id = (int) $wpdb->insert_id;
    188188        }
    189189
     
    254254                $userdata['user_pass'] = wp_hash_password($userdata['user_pass']);
    255255        }
    256256
     257        // Keep trace of current user
     258        $current_user = wp_get_current_user();
     259       
    257260        // Merge old and new fields with new fields overwriting old ones.
    258261        $userdata = array_merge($user, $userdata);
    259262        $user_id = wp_insert_user($userdata);
    260263
    261264        // Update the cookies if the password changed.
    262         $current_user = wp_get_current_user();
    263265        if ( $current_user->id == $ID ) {
    264                 if ( isset($plaintext_pass) ) {
     266                if ( isset($plaintext_pass) || $user['user_login'] != $userdata['user_login'] ) {
    265267                        wp_clear_auth_cookie();
    266268                        wp_set_auth_cookie($ID);
    267269                }
  • wp-admin/includes/user.php

     
    129129
    130130        $errors = new WP_Error();
    131131
    132         /* checking that username has been typed */
    133         if ( $user->user_login == '' )
    134                 $errors->add( 'user_login', __( '<strong>ERROR</strong>: Please enter a username.' ));
    135 
    136132        /* checking the password has been typed twice */
    137133        do_action_ref_array( 'check_passwords', array ( $user->user_login, & $pass1, & $pass2 ));
    138134
     
    159155        if (!empty ( $pass1 ))
    160156                $user->user_pass = $pass1;
    161157
    162         if ( !$update && !validate_username( $user->user_login ) )
    163                 $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid. Please enter a valid username.' ));
     158        if ( !$update && !empty($user->user_login) ) {
     159                if ( !validate_username( $user->user_login ) )
     160                        $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid. Please enter a valid username.' ));
     161                if ( username_exists( $user->user_login ) )
     162                        $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ));
     163        }
    164164
    165         if (!$update && username_exists( $user->user_login ))
    166                 $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ));
    167 
    168165        /* checking e-mail address */
    169166        if ( empty ( $user->user_email ) ) {
    170167                $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please enter an e-mail address.' ), array( 'form-field' => 'email' ) );
     
    177174        if ( $errors->get_error_codes() )
    178175                return $errors;
    179176
     177        if ( $update && $userdata->user_login == $userdata->user_email ) {
     178                $user->user_login = $user->user_email;
     179        } elseif ( !$update && empty($user->user_login) ) {
     180                $user->user_login = $user->user_email;
     181        }
     182
    180183        if ( $update ) {
    181184                $user_id = wp_update_user( get_object_vars( $user ));
    182185        } else {
  • wp-admin/user-new.php

     
    8989}
    9090?>
    9191<table class="form-table">
    92         <tr class="form-field form-required">
    93                 <th scope="row"><label for="user_login"><?php _e('Username (required)') ?></label><input name="action" type="hidden" id="action" value="adduser" /></th>
    94                 <td ><input name="user_login" type="text" id="user_login" value="<?php echo $new_user_login; ?>" aria-required="true" /></td>
     92        <tr class="form-field">
     93                <th scope="row"><label for="user_login"><?php _e('Username (optional)') ?></label><input name="action" type="hidden" id="action" value="adduser" /></th>
     94                <td ><input name="user_login" type="text" id="user_login" value="<?php echo $new_user_login; ?>" /></td>
    9595        </tr>
    9696        <tr class="form-field">
    9797                <th scope="row"><label for="first_name"><?php _e('First Name') ?> </label></th>
  • wp-admin/user-edit.php

     
    238238<h3><?php _e('Name') ?></h3>
    239239
    240240<table class="form-table">
     241<?php if ( $profileuser->user_login != $profileuser->user_email ) : ?>
    241242        <tr>
    242243                <th><label for="user_login"><?php _e('Username'); ?></label></th>
    243244                <td><input type="text" name="user_login" id="user_login" value="<?php echo $profileuser->user_login; ?>" disabled="disabled" class="regular-text" /> <?php _e('Your username cannot be changed.'); ?></td>
    244245        </tr>
    245 
     246<?php endif; ?>
    246247<?php if ( !$is_profile_page ): ?>
    247248<tr><th><label for="role"><?php _e('Role:') ?></label></th>
    248249<td><select name="role" id="role">