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

  1. if ( !function_exists( 'username_exists' ) ) { 
  2. require_once ABSPATH . WPINC . '/user.php'; 
  3.  
  4. // The username. 
  5. $username = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = username_exists($username); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/user.php  
  1. function username_exists( $username ) { 
  2. if ( $user = get_user_by( 'login', $username ) ) { 
  3. return $user->ID; 
  4. return false;