WordPress at a glance

username_exists() WP 1.0

Checks whether the given username exists.

Works based on: get_user_by()
Hooks from function:
Return

Int/false. The user's ID on success, and false on failure.

Usage

username_exists( $username );
$username(string) (required)
Username.

Code of username_exists: wp-includes/user.php VER 4.9.8

<?php
function username_exists( $username ) {
	if ( $user = get_user_by( 'login', $username ) ) {
		$user_id = $user->ID;
	} else {
		$user_id = 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 );
}

Related Functions

From category: Other

No comments
    Hello, !     Log In . Register