WP_REST_Users_Controller::check_username PHP Method

check_username() public method

Performs a couple of checks like edit_user() in wp-admin/includes/user.php.
Since: 4.7.0
public check_username ( mixed $value, WP_REST_Request $request, string $param ) : WP_Error | string
$value mixed The username submitted in the request.
$request WP_REST_Request Full details about the request.
$param string The parameter name.
return WP_Error | string The sanitized username, if valid, otherwise an error.
    public function check_username($value, $request, $param)
    {
        $username = (string) $value;
        if (!validate_username($username)) {
            return new WP_Error('rest_user_invalid_username', __('Username contains invalid characters.'), 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))) {
            return new WP_Error('rest_user_invalid_username', __('Sorry, that username is not allowed.'), array('status' => 400));
        }
        return $username;
    }