username_exists
Checks whether the given username exists.
Description
(int|false) username_exists( (string) $username );
Returns (int|false)
The user's ID on success, and false on failure.
Parameters (1)
- 0. $username (string)
- The username.
Usage
if ( !function_exists( 'username_exists' ) ) { require_once ABSPATH . WPINC . '/user.php'; } // The username. $username = ''; // NOTICE! Understand what this does before running. $result = username_exists($username);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/user.php
- function username_exists( $username ) {
- if ( $user = get_user_by( 'login', $username ) ) {
- return $user->ID;
- }
- return false;
- }