WP_REST_Users_Controller::check_username()publicWP 4.7.0

Check a username for the REST API.

Performs a couple of checks like edit_user() in wp-admin/includes/user.php.

Метод класса: WP_REST_Users_Controller{}

Хуки из метода

Возвращает

Строку|WP_Error. The sanitized username, if valid, otherwise an error.

Использование

$WP_REST_Users_Controller = new WP_REST_Users_Controller();
$WP_REST_Users_Controller->check_username( $value, $request, $param );
$value(строка) (обязательный)
The username submitted in the request.
$request(WP_REST_Request) (обязательный)
Full details about the request.
$param(строка) (обязательный)
The parameter name.

Список изменений

С версии 4.7.0 Введена.

Код WP_REST_Users_Controller::check_username() WP 6.5.2

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;
}