Ticket #1626: 1626.patch

File 1626.patch, 2.0 KB (added by pishmishy, 5 years ago)

Modifies username_exists() and adds get_user_by_nicename()

  • wp-includes/pluggable.php

     
    230230} 
    231231endif; 
    232232 
     233if ( !function_exists('get_user_by_nicename') ) : 
     234/** 
     235 * get_user_by_nicename() - Retrieve user info by nicename 
     236 * 
     237 * @since 2.5 
     238 * 
     239 * @param string $email User's nicename 
     240 * @return bool|object False on failure, User DB row object 
     241 */ 
     242function get_user_by_nicename($nicename) { 
     243        global $wpdb; 
     244 
     245        $user_id = wp_cache_get($nicename, 'usernicename'); 
     246 
     247        if ( '0' === $user_id ) 
     248                return false; 
     249 
     250        $user = false; 
     251        if ( false !== $user_id ) 
     252                $user = wp_cache_get($user_id, 'users'); 
     253 
     254        if ( false !== $user ) 
     255                return $user; 
     256 
     257        if ( !$user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_nicename = %s", $nicename)) ) { 
     258                wp_cache_add($nicename, 0, 'useremail'); 
     259                return false; 
     260        } 
     261 
     262        _fill_user($user); 
     263 
     264        return $user; 
     265} 
     266endif; 
     267 
     268 
    233269if ( !function_exists( 'wp_mail' ) ) : 
    234270/** 
    235271 * wp_mail() - Function to send mail, similar to PHP's mail 
  • wp-includes/registration.php

     
    66 */ 
    77 
    88/** 
    9  * username_exists() - Checks whether the given username exists. 
     9 * username_exists() - Checks whether the given username exists and that it's nicename is unique 
    1010 * 
    1111 * @since 2.0.0 
    1212 * 
    1313 * @param string $username Username. 
    1414 * @return null|int The user's ID on success, and null on failure. 
    1515 */ 
     16 
    1617function username_exists( $username ) { 
    17         if ( $user = get_userdatabylogin( $username ) ) { 
     18        $user_nicename = sanitize_title($username); 
     19        $user_nicename = apply_filters('pre_user_nicename', $user_nicename); 
     20        if ( $user = get_userdatabylogin( $username ) ) {  
    1821                return $user->ID; 
     22        } elseif ($user = get_user_by_nicename($user_nicename)) { 
     23                        return $user->ID;                        
    1924        } else { 
    2025                return null; 
    2126        }