Checks whether a username is valid.
Parameters
$username
stringrequired- Username.
Source
function validate_username( $username ) {
$sanitized = sanitize_user( $username, true );
$valid = ( $sanitized === $username && ! empty( $sanitized ) );
/**
* Filters whether the provided username is valid.
*
* @since 2.0.1
*
* @param bool $valid Whether given username is valid.
* @param string $username Username to check.
*/
return apply_filters( 'validate_username', $valid, $username );
}
Hooks
- apply_filters( ‘validate_username’,
bool $valid ,string $username ) Filters whether the provided username is valid.
Example