Make WordPress Core

Ticket #15001: 15001.diff

File 15001.diff, 6.4 KB (added by wonderboymusic, 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 ) { 
    12951295        extract( $userdata, EXTR_SKIP );
    12961296
    12971297        // Are we updating or creating?
    1298         if ( !empty($ID) ) {
     1298        if ( ! empty( $ID ) ) {
    12991299                $ID = (int) $ID;
    13001300                $update = true;
    13011301                $old_user_data = WP_User::get_data_by( 'id', $ID );
    function wp_insert_user( $userdata ) { 
    13051305                $user_pass = wp_hash_password($user_pass);
    13061306        }
    13071307
    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 );
    13101311
    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;
    13191314
    13201315        if ( empty($user_nicename) )
    13211316                $user_nicename = sanitize_title( $user_login );
    function wp_insert_user( $userdata ) { 
    13251320                $user_url = '';
    13261321        $user_url = apply_filters('pre_user_url', $user_url);
    13271322
    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 
    13351323        if ( empty($nickname) )
    13361324                $nickname = $user_login;
    13371325        $nickname = apply_filters('pre_user_nickname', $nickname);
    function wp_create_user($username, $password, $email = '') { 
    15151503}
    15161504
    15171505/**
     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 */
     1515function 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&#8217;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/**
    15181548 * Return a list of meta keys that wp_insert_user() is supposed to set.
    15191549 *
    15201550 * @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) { 
    319319 * @return int|WP_Error Either user's ID or error on failure.
    320320 */
    321321function 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&#8217;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 );
    348325
    349         $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );
     326        $errors = apply_filters( 'registration_errors', $errors, $user_login, $user_email );
    350327
    351328        if ( $errors->get_error_code() )
    352329                return $errors;
    353330
    354331        $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 );
    356333        if ( ! $user_id ) {
    357334                $errors->add( 'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn&#8217;t register you&hellip; please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ) );
    358335                return $errors;