On this page
username_exists( string $username ): int|false
Determines whether the given username exists.
Description
For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.
Parameters
$usernamestring Required-
The username to check for existence.
Return
int|false The user ID on success, false on failure.
Source
File: wp-includes/user.php. View all references
function username_exists( $username ) {
$user = get_user_by( 'login', $username );
if ( $user ) {
$user_id = $user->ID;
} else {
$user_id = false;
}
/**
* Filters whether the given username exists.
*
* @since 4.9.0
*
* @param int|false $user_id The user ID associated with the username,
* or false if the username does not exist.
* @param string $username The username to check for existence.
*/
return apply_filters( 'username_exists', $user_id, $username );
}
Hooks
- apply_filters( 'username_exists',
int|false $user_id ,string $username ) -
Filters whether the given username exists.
Related
Uses
| Uses | Description |
|---|---|
| get_user_by() wp-includes/pluggable.php | Retrieves user info by a given field. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| wp_install() wp-admin/includes/upgrade.php | Installs the site. |
| edit_user() wp-admin/includes/user.php | Edit user settings based on contents of $_POST |
| WP_Importer::set_user() wp-admin/includes/class-wp-importer.php | |
| register_new_user() wp-includes/user.php | Handles registering a new user. |
| wp_insert_user() wp-includes/user.php | Inserts a user into the database. |
| wpmu_activate_signup() wp-includes/ms-functions.php | Activates a signup. |
| wpmu_validate_user_signup() wp-includes/ms-functions.php | Sanitizes and validates data required for a user sign-up. |
| wpmu_validate_blog_signup() wp-includes/ms-functions.php | Processes new site registrations. |
Changelog
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/username_exists