WordPress.org

Make WordPress Core

Ticket #9393: 9393-registration.diff

File 9393-registration.diff, 1.6 KB (added by sivel, 6 years ago)

Only check for unique user_nicename when updating since a user_id hasn't been created for a new user yet

  • wp-includes/registration.php

     
    176176        if ( empty($user_registered) ) 
    177177                $user_registered = gmdate('Y-m-d H:i:s'); 
    178178 
    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)); 
     179        // Only check for unique user_nicename when updating since a user_id hasn't been created for a new user yet 
     180        if ( $update === true ) { 
     181                $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)); 
    180182 
    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++; 
     183                if ($user_nicename_check) { 
     184                        $suffix = 2; 
     185                        while ($user_nicename_check) { 
     186                                $alt_user_nicename = $user_nicename . "-$suffix"; 
     187                                $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)); 
     188                                $suffix++; 
     189                        } 
     190                        $user_nicename = $alt_user_nicename; 
    187191                } 
    188                 $user_nicename = $alt_user_nicename; 
    189192        } 
    190193 
    191194        $data = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );