Ticket #9568: 9568.5.diff
File 9568.5.diff, 9.8 KB (added by , 16 years ago) |
---|
-
wp-login.php
206 206 $user_email = apply_filters( 'user_registration_email', $user_email ); 207 207 208 208 // Check the username 209 if ( $user_login == '' ) 210 $errors->add('empty_username', __('<strong>ERROR</strong>: Please enter a username.')); 211 elseif ( !validate_username( $user_login ) ) { 212 $errors->add('invalid_username', __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.')); 213 $user_login = ''; 214 } elseif ( username_exists( $user_login ) ) 215 $errors->add('username_exists', __('<strong>ERROR</strong>: This username is already registered, please choose another one.')); 209 if ( !empty($user_login) ) { 210 if ( !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.')); 215 } 216 } 216 217 217 218 // Check the e-mail address 218 219 if ($user_email == '') { … … 223 224 } elseif ( email_exists( $user_email ) ) 224 225 $errors->add('email_exists', __('<strong>ERROR</strong>: This email is already registered, please choose another one.')); 225 226 227 if ( !$errors->get_error_code() && empty($user_login) ) 228 $user_login = $user_email; 229 226 230 do_action('register_post', $user_login, $user_email, $errors); 227 231 228 232 $errors = apply_filters( 'registration_errors', $errors ); … … 374 378 375 379 <form name="registerform" id="registerform" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" method="post"> 376 380 <p> 377 <label><?php _e('Username ') ?><br />381 <label><?php _e('Username (optional)') ?><br /> 378 382 <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr(stripslashes($user_login)); ?>" size="20" tabindex="10" /></label> 379 383 </p> 380 384 <p> … … 468 472 <?php if ( !isset($_GET['checkemail']) || !in_array( $_GET['checkemail'], array('confirm', 'newpass') ) ) : ?> 469 473 <form name="loginform" id="loginform" action="<?php echo site_url('wp-login.php', 'login_post') ?>" method="post"> 470 474 <p> 471 <label><?php _e('Username ') ?><br />475 <label><?php _e('Username or Email') ?><br /> 472 476 <input type="text" name="log" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" tabindex="10" /></label> 473 477 </p> 474 478 <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 ID != %d LIMIT 1" , $user_nicename, (int) $ID));185 $user_nicename = wp_unique_user_nicename($user_nicename, $ID); 180 186 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 ID != %d LIMIT 1" , $alt_user_nicename, (int) $ID)); 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' ); 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 … … 266 262 $userdata['user_pass'] = wp_hash_password($userdata['user_pass']); 267 263 } 268 264 265 // Keep trace of current user 266 $current_user = wp_get_current_user(); 267 269 268 // Merge old and new fields with new fields overwriting old ones. 270 269 $userdata = array_merge($user, $userdata); 271 270 $user_id = wp_insert_user($userdata); 272 271 273 272 // Update the cookies if the password changed. 274 $current_user = wp_get_current_user();275 273 if ( $current_user->id == $ID ) { 276 if ( isset($plaintext_pass) ) {274 if ( isset($plaintext_pass) || $user['user_login'] != $userdata['user_login'] ) { 277 275 wp_clear_auth_cookie(); 278 276 wp_set_auth_cookie($ID); 279 277 } … … 308 306 return wp_insert_user($userdata); 309 307 } 310 308 311 ?> 309 /** 310 * Returns a unique nicename for a user 311 * 312 * @since 2.8 313 * @see wp_insert_user() 314 * 315 * @param string $user_nicename The user's nicename. 316 * @param string $user_id The user's ID. 317 * @return string The user's nicename. 318 */ 319 320 function wp_unique_user_nicename($user_nicename, $user_id) { 321 global $wpdb; 322 323 $user_id = (int) $user_id; 324 $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)); 325 326 if ( $user_nicename_check ) { 327 $suffix = 2; 328 while ( $user_nicename_check ) { 329 $alt_user_nicename = $user_nicename . "-$suffix"; 330 $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)); 331 $suffix++; 332 } 333 $user_nicename = $alt_user_nicename; 334 } 335 336 return $user_nicename; 337 } 338 ?> 339 No newline at end of file -
wp-admin/includes/user.php
129 129 130 130 $errors = new WP_Error(); 131 131 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 136 132 /* checking the password has been typed twice */ 137 133 do_action_ref_array( 'check_passwords', array ( $user->user_login, & $pass1, & $pass2 )); 138 134 … … 159 155 if (!empty ( $pass1 )) 160 156 $user->user_pass = $pass1; 161 157 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 } 164 164 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 168 165 /* checking e-mail address */ 169 166 if ( empty ( $user->user_email ) ) { 170 167 $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please enter an e-mail address.' ), array( 'form-field' => 'email' ) ); … … 179 176 if ( $errors->get_error_codes() ) 180 177 return $errors; 181 178 179 if ( $update && $userdata->user_login == $userdata->user_email ) { 180 $user->user_login = $user->user_email; 181 } elseif ( !$update && empty($user->user_login) ) { 182 $user->user_login = $user->user_email; 183 } 184 182 185 if ( $update ) { 183 186 $user_id = wp_update_user( get_object_vars( $user )); 184 187 } else { -
wp-admin/user-new.php
89 89 } 90 90 ?> 91 91 <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 esc_attr($new_user_login); ?>" aria-required="true"/></td>92 <tr class="form-field"> 93 <th scope="row"><label for="user_login"><?php _e('Username') ?></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 esc_attr($new_user_login); ?>" /></td> 95 95 </tr> 96 96 <tr class="form-field"> 97 97 <th scope="row"><label for="first_name"><?php _e('First Name') ?> </label></th> -
wp-admin/user-edit.php
246 246 <h3><?php _e('Name') ?></h3> 247 247 248 248 <table class="form-table"> 249 <?php if ( $profileuser->user_login != $profileuser->user_email ) : ?> 249 250 <tr> 250 251 <th><label for="user_login"><?php _e('Username'); ?></label></th> 251 252 <td><input type="text" name="user_login" id="user_login" value="<?php echo esc_attr($profileuser->user_login); ?>" disabled="disabled" class="regular-text" /> <?php _e('Your username cannot be changed.'); ?></td> 252 253 </tr> 254 <?php endif; ?> 253 255 254 256 <?php if ( !$is_profile_page ): ?> 255 257 <tr><th><label for="role"><?php _e('Role:') ?></label></th>