Ticket #44921: 44921.2.diff
File 44921.2.diff, 1.9 KB (added by , 6 years ago) |
---|
-
src/wp-includes/user.php
1419 1419 } 1420 1420 1421 1421 /** 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 */ 1434 function 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 /** 1422 1447 * Checks whether a username is valid. 1423 1448 * 1424 1449 * @since 2.0.1 … … 1710 1735 1711 1736 $meta['locale'] = isset( $userdata['locale'] ) ? $userdata['locale'] : ''; 1712 1737 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 ); 1714 1739 1715 1740 if ( $user_nicename_check ) { 1716 1741 $suffix = 2; … … 1718 1743 // user_nicename allows 50 chars. Subtract one for a hyphen, plus the length of the suffix. 1719 1744 $base_length = 49 - mb_strlen( $suffix ); 1720 1745 $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 ); 1722 1747 $suffix++; 1723 1748 } 1724 1749 $user_nicename = $alt_user_nicename;