Check a username for the REST API.
Description
Performs a couple of checks like edit_user() in wp-admin/includes/user.php.
Parameters
$value
stringrequired- The username submitted in the request.
$request
WP_REST_Requestrequired- Full details about the request.
$param
stringrequired- The parameter name.
Source
public function check_username( $value, $request, $param ) {
$username = (string) $value;
if ( ! validate_username( $username ) ) {
return new WP_Error(
'rest_user_invalid_username',
__( 'This username is invalid because it uses illegal characters. Please enter a valid username.' ),
array( 'status' => 400 )
);
}
/** This filter is documented in wp-includes/user.php */
$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
if ( in_array( strtolower( $username ), array_map( 'strtolower', $illegal_logins ), true ) ) {
return new WP_Error(
'rest_user_invalid_username',
__( 'Sorry, that username is not allowed.' ),
array( 'status' => 400 )
);
}
return $username;
}
Hooks
- apply_filters( ‘illegal_user_logins’,
array $usernames ) Filters the list of disallowed usernames.
Changelog
Version | Description |
---|---|
4.7.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.