WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_REST_Server::error_to_response() protected WP 4.4.0

Converts an error to a response object.

This iterates over all error codes and messages to change it into a flat array. This enables simpler client behaviour, as it is represented as a list in JSON rather than an object/map.

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

Хуков нет.

Возвращает

WP_REST_Response. List of associative arrays with code and message keys.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->error_to_response( $error );
$error(WP_Error) (обязательный)
WP_Error instance.

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

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

Код WP_REST_Server::error_to_response() WP 5.5.1

wp-includes/rest-api/class-wp-rest-server.php
<?php
protected function error_to_response( $error ) {
	$error_data = $error->get_error_data();

	if ( is_array( $error_data ) && isset( $error_data['status'] ) ) {
		$status = $error_data['status'];
	} else {
		$status = 500;
	}

	$errors = array();

	foreach ( (array) $error->errors as $code => $messages ) {
		foreach ( (array) $messages as $message ) {
			$errors[] = array(
				'code'    => $code,
				'message' => $message,
				'data'    => $error->get_error_data( $code ),
			);
		}
	}

	$data = $errors[0];
	if ( count( $errors ) > 1 ) {
		// Remove the primary error.
		array_shift( $errors );
		$data['additional_errors'] = $errors;
	}

	$response = new WP_REST_Response( $data, $status );

	return $response;
}