WordPress.org

Make WordPress Core

Ticket #9568: 9568.7.diff

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

refreshed patch

  • wp-login.php

     
    504504<?php if ( !isset($_GET['checkemail']) || !in_array( $_GET['checkemail'], array('confirm', 'newpass') ) ) : ?>
    505505<form name="loginform" id="loginform" action="<?php echo site_url('wp-login.php', 'login_post') ?>" method="post">
    506506        <p>
    507                 <label><?php _e('Username') ?><br />
     507                <label><?php _e('Username or Email') ?><br />
    508508                <input type="text" name="log" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" tabindex="10" /></label>
    509509        </p>
    510510        <p>
  • wp-includes/registration.php

     
    119119        $user_login = sanitize_user($user_login, true);
    120120        $user_login = apply_filters('pre_user_login', $user_login);
    121121
    122         if ( empty($user_nicename) )
    123                 $user_nicename = sanitize_title( $user_login );
     122        if ( empty($user_nicename) ) {
     123                if ( $user_login == $user_email ) {
     124                        $user_nicename = preg_replace("/@.*/", '', $user_email);
     125                } else {
     126                        $user_nicename = $user_login;
     127                }
     128                $user_nicename = sanitize_title( $user_nicename );
     129        }
    124130        $user_nicename = apply_filters('pre_user_nicename', $user_nicename);
    125131
    126132        if ( empty($user_url) )
     
    131137                $user_email = '';
    132138        $user_email = apply_filters('pre_user_email', $user_email);
    133139
    134         if ( empty($display_name) )
    135                 $display_name = $user_login;
     140        if ( empty($display_name) ) {
     141                $display_name = $user_login != $user_email ? $user_login : $user_nicename;
     142        }
    136143        $display_name = apply_filters('pre_user_display_name', $display_name);
    137144
    138145        if ( empty($nickname) )
    139                 $nickname = $user_login;
     146                $nickname = $user_login != $user_email ? $user_login : $user_nicename;
    140147        $nickname = apply_filters('pre_user_nickname', $nickname);
    141148
    142149        if ( empty($first_name) )
     
    167174        if ( empty($user_registered) )
    168175                $user_registered = gmdate('Y-m-d H:i:s');
    169176
    170         $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $user_nicename, $user_login));
    171 
    172         if ($user_nicename_check) {
    173                 $suffix = 2;
    174                 while ($user_nicename_check) {
    175                         $alt_user_nicename = $user_nicename . "-$suffix";
    176                         $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1" , $alt_user_nicename, $user_login));
    177                         $suffix++;
    178                 }
    179                 $user_nicename = $alt_user_nicename;
    180         }
    181 
    182         $data = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
     177        $user_nicename = wp_unique_user_nicename($user_nicename, $ID);
     178       
     179        $data = compact( 'user_login', 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
    183180        $data = stripslashes_deep( $data );
    184181
    185182        if ( $update ) {
    186183                $wpdb->update( $wpdb->users, $data, compact( 'ID' ) );
    187184                $user_id = (int) $ID;
    188185        } else {
    189                 $wpdb->insert( $wpdb->users, $data + compact( 'user_login' ) );
     186                $wpdb->insert( $wpdb->users, $data );
    190187                $user_id = (int) $wpdb->insert_id;
    191188        }
    192189
     
    258255                $userdata['user_pass'] = wp_hash_password($userdata['user_pass']);
    259256        }
    260257
     258        // Keep trace of current user
     259        $current_user = wp_get_current_user();
     260       
    261261        // Merge old and new fields with new fields overwriting old ones.
    262262        $userdata = array_merge($user, $userdata);
    263263        $user_id = wp_insert_user($userdata);
    264264
    265         // Update the cookies if the password changed.
    266         $current_user = wp_get_current_user();
     265        // Update the cookies if the password or login changed.
    267266        if ( $current_user->id == $ID ) {
    268                 if ( isset($plaintext_pass) ) {
     267                if ( isset($plaintext_pass) || $user['user_login'] != $userdata['user_login'] ) {
    269268                        wp_clear_auth_cookie();
    270269                        wp_set_auth_cookie($ID);
    271270                }
     
    318317        return apply_filters('user_contactmethods',$user_contactmethods);
    319318}
    320319
    321 ?>
     320/**
     321 * Returns a unique nicename for a user
     322 *
     323 * @since 2.9
     324 * @see wp_insert_user()
     325 *
     326 * @param string $user_nicename The user's nicename.
     327 * @param string $user_id The user's ID.
     328 * @return string The user's nicename.
     329 */
     330
     331function wp_unique_user_nicename($user_nicename, $user_id) {
     332        global $wpdb;
     333
     334        $user_id = (int) $user_id;
     335        $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND ID != %d LIMIT 1" , $user_nicename, $user_id));
     336
     337        if ( $user_nicename_check ) {
     338                $suffix = 2;
     339                while ( $user_nicename_check ) {
     340                        $alt_user_nicename = $user_nicename . "-$suffix";
     341                        $user_nicename_check = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND ID != %d LIMIT 1" , $alt_user_nicename, $user_id));
     342                        $suffix++;
     343                }
     344                $user_nicename = $alt_user_nicename;
     345        }
     346
     347        return $user_nicename;
     348}
     349?>
     350 No newline at end of file
  • wp-includes/user.php

     
    8484        }
    8585
    8686        $userdata = get_userdatabylogin($username);
    87 
     87       
     88        if ( !$userdata )
     89                $userdata = get_user_by_email($username);
     90       
    8891        if ( !$userdata ) {
    8992                return new WP_Error('invalid_username', sprintf(__('<strong>ERROR</strong>: Invalid username. <a href="%s" title="Password Lost and Found">Lost your password</a>?'), site_url('wp-login.php?action=lostpassword', 'login')));
    9093        }
  • wp-admin/includes/user.php

     
    131131                $user->admin_color = 'fresh';
    132132
    133133        $errors = new WP_Error();
    134 
     134       
    135135        /* checking that username has been typed */
    136         if ( $user->user_login == '' )
     136        if ( !$update && empty($user->user_login) ) {
     137                $user->user_login = $user->user_email;
     138        } elseif ( $user->user_login == '' )
    137139                $errors->add( 'user_login', __( '<strong>ERROR</strong>: Please enter a username.' ));
    138140
    139141        /* checking the password has been typed twice */
     
    162164        if (!empty ( $pass1 ))
    163165                $user->user_pass = $pass1;
    164166
    165         if ( !$update && !validate_username( $user->user_login ) )
    166                 $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid. Please enter a valid username.' ));
     167        if ( !validate_username( $user->user_login ) )
     168                $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid. Please enter a valid username.' ));
     169        if ( !$update && username_exists( $user->user_login ) )
     170                $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ));
    167171
    168         if (!$update && username_exists( $user->user_login ))
    169                 $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ));
    170 
    171172        /* checking e-mail address */
    172173        if ( empty ( $user->user_email ) ) {
    173174                $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please enter an e-mail address.' ), array( 'form-field' => 'email' ) );
  • wp-admin/user-new.php

     
    9292$new_user_send_password = !$_POST || isset($_POST['send_password']);
    9393?>
    9494<table class="form-table">
    95         <tr class="form-field form-required">
    96                 <th scope="row"><label for="user_login"><?php _e('Username'); ?> <span class="description"><?php _e('(required)'); ?></span></label>
     95        <tr class="form-field">
     96                <th scope="row"><label for="user_login"><?php _e('Username'); ?> <span class="description"></span></label>
    9797                <input name="action" type="hidden" id="action" value="adduser" /></th>
    98                 <td><input name="user_login" type="text" id="user_login" value="<?php echo esc_attr($new_user_login); ?>" aria-required="true" /></td>
     98                <td><input name="user_login" type="text" id="user_login" value="<?php echo esc_attr($new_user_login); ?>" /></td>
    9999        </tr>
    100100        <tr class="form-field">
    101101                <th scope="row"><label for="first_name"><?php _e('First Name') ?> </label></th>
  • wp-admin/user-edit.php

     
    183183<h3><?php _e('Name') ?></h3>
    184184
    185185<table class="form-table">
     186<?php if ( $profileuser->user_login != $profileuser->user_email ) : ?>
    186187        <tr>
    187188                <th><label for="user_login"><?php _e('Username'); ?></label></th>
    188189                <td><input type="text" name="user_login" id="user_login" value="<?php echo esc_attr($profileuser->user_login); ?>" disabled="disabled" class="regular-text" /> <span class="description"><?php _e('Your username cannot be changed.'); ?></span></td>
    189190        </tr>
     191<?php else : ?>
     192        <tr>
     193                <th><label for="user_login"><?php _e('Username'); ?></label></th>
     194                <td><input type="text" name="user_login" id="user_login" value="" class="regular-text" /> <span class="description"><?php _e('Your username cannot be changed once set.'); ?></span></td>
     195        </tr>
     196<?php endif; ?>
    190197
    191198<?php if ( !IS_PROFILE_PAGE ): ?>
    192199<tr><th><label for="role"><?php _e('Role:') ?></label></th>