WP_REST_Server::json_error()protectedWP 4.4.0

Retrieves an appropriate error representation in JSON.

Note: This should only be used in WP_REST_Server::serve_request(), as it cannot handle WP_Error internally. All callbacks and other internal methods should instead return a WP_Error with the data set to an array that includes a 'status' key, with the value being the HTTP status to send.

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

Хуков нет.

Возвращает

Строку. JSON representation of the error

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->json_error( $code, $message, $status );
$code(строка) (обязательный)
WP_Error-style code.
$message(строка) (обязательный)
Human-readable message.
$status(int)
HTTP status code to send.
По умолчанию: null

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

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

Код WP_REST_Server::json_error() WP 6.4.3

protected function json_error( $code, $message, $status = null ) {
	if ( $status ) {
		$this->set_status( $status );
	}

	$error = compact( 'code', 'message' );

	return wp_json_encode( $error );
}