From e6028d9c6ca0aebe969d2da81256284cae52ba6b Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 26 Jul 2017 16:24:15 +0000 Subject: [PATCH] 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 --- src/wp-includes/user.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php index a0e699c2c1..41a83d2422 100644 --- a/src/wp-includes/user.php +++ b/src/wp-includes/user.php @@ -1320,9 +1320,20 @@ function clean_user_cache( $user ) { */ function username_exists( $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 ); } /**