Login and Registration: Introduce a username_exists filter, which allows for control over registration of usernames.

Props shamim51

Fixes #39320


git-svn-id: https://develop.svn.wordpress.org/trunk@41158 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2017-07-26 16:24:15 +00:00
parent f3368725ac
commit e6028d9c6c

View File

@ -1320,9 +1320,20 @@ function clean_user_cache( $user ) {
*/ */
function username_exists( $username ) { function username_exists( $username ) {
if ( $user = get_user_by( 'login', $username ) ) { if ( $user = get_user_by( 'login', $username ) ) {
return $user->ID; $user_id = $user->ID;
} else {
$user_id = false;
} }
return false;
/**
* Filters whether the given username exists or not.
*
* @since 4.9.0
*
* @param int|false $user_id The user's ID on success, and false on failure.
* @param string $username Username to check.
*/
return apply_filters( 'username_exists', $user_id, $username );
} }
/** /**