Ticket #15001: 15001.diff
File 15001.diff, 6.4 KB (added by , 12 years ago) |
---|
-
wp-includes/user.php
diff --git wp-includes/user.php wp-includes/user.php index be11b73..2fa5f2a 100644
function wp_insert_user( $userdata ) { 1295 1295 extract( $userdata, EXTR_SKIP ); 1296 1296 1297 1297 // Are we updating or creating? 1298 if ( ! empty($ID) ) {1298 if ( ! empty( $ID ) ) { 1299 1299 $ID = (int) $ID; 1300 1300 $update = true; 1301 1301 $old_user_data = WP_User::get_data_by( 'id', $ID ); … … function wp_insert_user( $userdata ) { 1305 1305 $user_pass = wp_hash_password($user_pass); 1306 1306 } 1307 1307 1308 $user_login = sanitize_user($user_login, true); 1309 $user_login = apply_filters('pre_user_login', $user_login); 1308 $data = check_user_for_errors( $user_login, $user_email, $update ); 1309 // yields $errors, $user_login, $user_email 1310 extract( $data ); 1310 1311 1311 //Remove any non-printable chars from the login string to see if we have ended up with an empty username 1312 $user_login = trim($user_login); 1313 1314 if ( empty($user_login) ) 1315 return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.') ); 1316 1317 if ( !$update && username_exists( $user_login ) ) 1318 return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) ); 1312 if ( $errors->get_error_code() ) 1313 return $errors; 1319 1314 1320 1315 if ( empty($user_nicename) ) 1321 1316 $user_nicename = sanitize_title( $user_login ); … … function wp_insert_user( $userdata ) { 1325 1320 $user_url = ''; 1326 1321 $user_url = apply_filters('pre_user_url', $user_url); 1327 1322 1328 if ( empty($user_email) )1329 $user_email = '';1330 $user_email = apply_filters('pre_user_email', $user_email);1331 1332 if ( !$update && ! defined( 'WP_IMPORTING' ) && email_exists($user_email) )1333 return new WP_Error( 'existing_user_email', __( 'Sorry, that email address is already used!' ) );1334 1335 1323 if ( empty($nickname) ) 1336 1324 $nickname = $user_login; 1337 1325 $nickname = apply_filters('pre_user_nickname', $nickname); … … function wp_create_user($username, $password, $email = '') { 1515 1503 } 1516 1504 1517 1505 /** 1506 * Combines error_checking code from wp_insert_user and register_new_user 1507 * 1508 * @since 3.7.0 1509 * 1510 * @param string $user_login The user's login 1511 * @param string $user_email The user's email address 1512 * @param bool $update Whether the data is part of an update for an existing user 1513 * @return array Data is meant to have extract() called on it 1514 */ 1515 function check_user_for_errors( $user_login, $user_email, $update = false ) { 1516 $errors = new WP_Error(); 1517 1518 $user_login = apply_filters( 'pre_user_login', sanitize_user( $user_login, true ) ); 1519 $user_email = apply_filters( 'user_registration_email', $user_email ); 1520 1521 $sanitized_user_login = trim( $user_login ); 1522 1523 // Check the username 1524 if ( empty( $sanitized_user_login ) ) { 1525 $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.' ) ); 1526 } elseif ( ! validate_username( $user_login ) ) { 1527 $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) ); 1528 $sanitized_user_login = ''; 1529 } elseif ( ! $update && username_exists( $sanitized_user_login ) ) { 1530 $errors->add( 'username_exists', __( '<strong>ERROR</strong>: This username is already registered, please choose another one.' ) ); 1531 } 1532 1533 $sanitized_user_email = apply_filters( 'pre_user_email', $user_email ); 1534 // Check the e-mail address 1535 if ( empty( $sanitized_user_email ) ) { 1536 $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your e-mail address.' ) ); 1537 } elseif ( ! is_email( $sanitized_user_email ) ) { 1538 $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn’t correct.' ) ); 1539 $user_email = ''; 1540 } elseif ( ! $update && ! defined( 'WP_IMPORTING' ) && email_exists( $sanitized_user_email ) ) { 1541 $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) ); 1542 } 1543 1544 return array( 'errors' => $errors, 'user_email' => $sanitized_user_email, 'user_login' => $sanitized_user_login ); 1545 } 1546 1547 /** 1518 1548 * Return a list of meta keys that wp_insert_user() is supposed to set. 1519 1549 * 1520 1550 * @since 3.3.0 -
wp-login.php
diff --git wp-login.php wp-login.php index 532ffd9..56aff90 100644
function reset_password($user, $new_pass) { 319 319 * @return int|WP_Error Either user's ID or error on failure. 320 320 */ 321 321 function register_new_user( $user_login, $user_email ) { 322 $errors = new WP_Error(); 323 324 $sanitized_user_login = sanitize_user( $user_login ); 325 $user_email = apply_filters( 'user_registration_email', $user_email ); 326 327 // Check the username 328 if ( $sanitized_user_login == '' ) { 329 $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.' ) ); 330 } elseif ( ! validate_username( $user_login ) ) { 331 $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) ); 332 $sanitized_user_login = ''; 333 } elseif ( username_exists( $sanitized_user_login ) ) { 334 $errors->add( 'username_exists', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ) ); 335 } 336 337 // Check the e-mail address 338 if ( $user_email == '' ) { 339 $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your e-mail address.' ) ); 340 } elseif ( ! is_email( $user_email ) ) { 341 $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn’t correct.' ) ); 342 $user_email = ''; 343 } elseif ( email_exists( $user_email ) ) { 344 $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) ); 345 } 346 347 do_action( 'register_post', $sanitized_user_login, $user_email, $errors ); 322 $data = check_user_for_errors( $user_login, $user_email ); 323 // yields $errors, $user_login, $user_email 324 extract( $data ); 348 325 349 $errors = apply_filters( 'registration_errors', $errors, $ sanitized_user_login, $user_email );326 $errors = apply_filters( 'registration_errors', $errors, $user_login, $user_email ); 350 327 351 328 if ( $errors->get_error_code() ) 352 329 return $errors; 353 330 354 331 $user_pass = wp_generate_password( 12, false); 355 $user_id = wp_create_user( $ sanitized_user_login, $user_pass, $user_email );332 $user_id = wp_create_user( $user_login, $user_pass, $user_email ); 356 333 if ( ! $user_id ) { 357 334 $errors->add( 'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn’t register you… please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ) ); 358 335 return $errors;