Ticket #9568: 9568.6.diff
File 9568.6.diff, 9.8 KB (added by , 16 years ago) |
---|
-
wp-login.php
232 232 $user_email = apply_filters( 'user_registration_email', $user_email ); 233 233 234 234 // Check the username 235 if ( $user_login == '' ) 236 $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.')); 237 elseif ( !validate_username( $user_login ) ) { 238 $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.')); 239 $user_login = ''; 240 } elseif ( username_exists( $user_login ) ) 241 $errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered, please choose another one.')); 235 if ( !empty($user_login) ) { 236 if ( !validate_username( $user_login ) ) { 237 $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.')); 238 $user_login = ''; 239 } elseif ( username_exists( $user_login ) ) { 240 $errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered, please choose another one.')); 241 } 242 } 242 243 243 244 // Check the e-mail address 244 245 if ($user_email == '') { … … 249 250 } elseif ( email_exists( $user_email ) ) 250 251 $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.')); 251 252 253 if ( !$errors->get_error_code() && empty($user_login) ) 254 $user_login = $user_email; 255 252 256 do_action('register_post', $user_login, $user_email, $errors); 253 257 254 258 $errors = apply_filters( 'registration_errors', $errors ); … … 407 411 408 412 <form name="registerform" id="registerform" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" method="post"> 409 413 <p> 410 <label><?php _e('Username ') ?><br />414 <label><?php _e('Username (optional)') ?><br /> 411 415 <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr(stripslashes($user_login)); ?>" size="20" tabindex="10" /></label> 412 416 </p> 413 417 <p> … … 501 505 <?php if ( !isset($_GET['checkemail']) || !in_array( $_GET['checkemail'], array('confirm', 'newpass') ) ) : ?> 502 506 <form name="loginform" id="loginform" action="<?php echo site_url('wp-login.php', 'login_post') ?>" method="post"> 503 507 <p> 504 <label><?php _e('Username ') ?><br />508 <label><?php _e('Username or Email') ?><br /> 505 509 <input type="text" name="log" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" tabindex="10" /></label> 506 510 </p> 507 511 <p> -
wp-includes/registration.php
119 119 $user_login = sanitize_user($user_login, true); 120 120 $user_login = apply_filters('pre_user_login', $user_login); 121 121 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 } 124 130 $user_nicename = apply_filters('pre_user_nicename', $user_nicename); 125 131 126 132 if ( empty($user_url) ) … … 176 182 if ( empty($user_registered) ) 177 183 $user_registered = gmdate('Y-m-d H:i:s'); 178 184 179 $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)); 180 181 if ($user_nicename_check) { 182 $suffix = 2; 183 while ($user_nicename_check) { 184 $alt_user_nicename = $user_nicename . "-$suffix"; 185 $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)); 186 $suffix++; 187 } 188 $user_nicename = $alt_user_nicename; 189 } 190 191 $data = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' ); 185 $user_nicename = wp_unique_user_nicename($user_nicename, $ID); 186 187 $data = compact( 'user_login', 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' ); 192 188 $data = stripslashes_deep( $data ); 193 189 194 190 if ( $update ) { 195 191 $wpdb->update( $wpdb->users, $data, compact( 'ID' ) ); 196 192 $user_id = (int) $ID; 197 193 } else { 198 $wpdb->insert( $wpdb->users, $data + compact( 'user_login' ));194 $wpdb->insert( $wpdb->users, $data ); 199 195 $user_id = (int) $wpdb->insert_id; 200 196 } 201 197 … … 264 260 $userdata['user_pass'] = wp_hash_password($userdata['user_pass']); 265 261 } 266 262 263 // Keep trace of current user 264 $current_user = wp_get_current_user(); 265 267 266 // Merge old and new fields with new fields overwriting old ones. 268 267 $userdata = array_merge($user, $userdata); 269 268 $user_id = wp_insert_user($userdata); 270 269 271 270 // Update the cookies if the password changed. 272 $current_user = wp_get_current_user();273 271 if ( $current_user->id == $ID ) { 274 if ( isset($plaintext_pass) ) {272 if ( isset($plaintext_pass) || $user['user_login'] != $userdata['user_login'] ) { 275 273 wp_clear_auth_cookie(); 276 274 wp_set_auth_cookie($ID); 277 275 } … … 306 304 return wp_insert_user($userdata); 307 305 } 308 306 309 ?> 307 /** 308 * Returns a unique nicename for a user 309 * 310 * @since 2.8 311 * @see wp_insert_user() 312 * 313 * @param string $user_nicename The user's nicename. 314 * @param string $user_id The user's ID. 315 * @return string The user's nicename. 316 */ 317 318 function wp_unique_user_nicename($user_nicename, $user_id) { 319 global $wpdb; 320 321 $user_id = (int) $user_id; 322 $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)); 323 324 if ( $user_nicename_check ) { 325 $suffix = 2; 326 while ( $user_nicename_check ) { 327 $alt_user_nicename = $user_nicename . "-$suffix"; 328 $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)); 329 $suffix++; 330 } 331 $user_nicename = $alt_user_nicename; 332 } 333 334 return $user_nicename; 335 } 336 ?> 337 No newline at end of file -
wp-admin/includes/user.php
133 133 134 134 $errors = new WP_Error(); 135 135 136 /* checking that username has been typed */137 if ( $user->user_login == '' )138 $errors->add( 'user_login', __( '<strong>ERROR</strong>: Please enter a username.' ));139 140 136 /* checking the password has been typed twice */ 141 137 do_action_ref_array( 'check_passwords', array ( $user->user_login, & $pass1, & $pass2 )); 142 138 … … 163 159 if (!empty ( $pass1 )) 164 160 $user->user_pass = $pass1; 165 161 166 if ( !$update && !validate_username( $user->user_login ) ) 167 $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid. Please enter a valid username.' )); 162 if ( !$update && !empty($user->user_login) ) { 163 if ( !validate_username( $user->user_login ) ) 164 $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid. Please enter a valid username.' )); 165 if ( username_exists( $user->user_login ) ) 166 $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' )); 167 } 168 168 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.' ));171 172 169 /* checking e-mail address */ 173 170 if ( empty ( $user->user_email ) ) { 174 171 $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please enter an e-mail address.' ), array( 'form-field' => 'email' ) ); … … 184 181 if ( $errors->get_error_codes() ) 185 182 return $errors; 186 183 184 if ( $update && $userdata->user_login == $userdata->user_email ) { 185 $user->user_login = $user->user_email; 186 } elseif ( !$update && empty($user->user_login) ) { 187 $user->user_login = $user->user_email; 188 } 189 187 190 if ( $update ) { 188 191 $user_id = wp_update_user( get_object_vars( $user )); 189 192 } else { -
wp-admin/user-new.php
93 93 ?> 94 94 <table class="form-table"> 95 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>96 <th scope="row"><label for="user_login"><?php _e('Username'); ?></label> 97 97 <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> 99 99 </tr> 100 100 <tr class="form-field"> 101 101 <th scope="row"><label for="first_name"><?php _e('First Name') ?> </label></th> -
wp-admin/user-edit.php
183 183 <h3><?php _e('Name') ?></h3> 184 184 185 185 <table class="form-table"> 186 <?php if ( $profileuser->user_login != $profileuser->user_email ) : ?> 186 187 <tr> 187 188 <th><label for="user_login"><?php _e('Username'); ?></label></th> 188 189 <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> 189 190 </tr> 191 <?php endif; ?> 190 192 191 193 <?php if ( !IS_PROFILE_PAGE ): ?> 192 194 <tr><th><label for="role"><?php _e('Role:') ?></label></th>