WordPress.org

Make WordPress Core

Ticket #44921: 44921.2.diff

File 44921.2.diff, 1.9 KB (added by spacedmonkey, 3 years ago)
  • src/wp-includes/user.php

     
    14191419}
    14201420
    14211421/**
     1422 * Determines whether the given user_nicename exists.
     1423 *
     1424 * For more information on this and similar theme functions, check out
     1425 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
     1426 * Conditional Tags} article in the Theme Developer Handbook.
     1427 *
     1428 * @since 5.1.0
     1429 *
     1430 * @param string $nicename Nicename.
     1431 * @param string $login (Optional) User login to compare against.
     1432 * @return int|false The user's ID on success, and false on failure.
     1433 */
     1434function nicename_exists( $nicename, $login = false ) {
     1435        $user_id = false;
     1436        if ( $user = get_user_by( 'slug', $user_nicename ) ) {
     1437                if ( $login !== $user->user_login ){
     1438                        $user_id = $user->ID;
     1439                }
     1440        }
     1441
     1442        return $user_id;
     1443}
     1444
     1445
     1446/**
    14221447 * Checks whether a username is valid.
    14231448 *
    14241449 * @since 2.0.1
     
    17101735
    17111736        $meta['locale'] = isset( $userdata['locale'] ) ? $userdata['locale'] : '';
    17121737
    1713         $user_nicename_check = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $user_nicename, $user_login ) );
     1738        $user_nicename_check = nicename_exists( $user_nicename, $user_login );
    17141739
    17151740        if ( $user_nicename_check ) {
    17161741                $suffix = 2;
     
    17181743                        // user_nicename allows 50 chars. Subtract one for a hyphen, plus the length of the suffix.
    17191744                        $base_length         = 49 - mb_strlen( $suffix );
    17201745                        $alt_user_nicename   = mb_substr( $user_nicename, 0, $base_length ) . "-$suffix";
    1721                         $user_nicename_check = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $alt_user_nicename, $user_login ) );
     1746                        $user_nicename_check = nicename_exists( $alt_user_nicename, $user_login );
    17221747                        $suffix++;
    17231748                }
    17241749                $user_nicename = $alt_user_nicename;