WP_REST_Server::envelope_response()publicWP 4.4.0

Wraps the response in an envelope.

The enveloping technique is used to work around browser/client compatibility issues. Essentially, it converts the full HTTP response to data instead.

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

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


WP_REST_Response. New response with wrapped data


$WP_REST_Server = new WP_REST_Server();
$WP_REST_Server->envelope_response( $response, $embed );
$response(WP_REST_Response) (обязательный)
Response object.
$embed(true|false|string[]) (обязательный)
Whether to embed all links, a filtered list of link relations, or no links.

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

С версии 4.4.0 Введена.
С версии 6.0.0 The $embed parameter can now contain a list of link relations to include.

Код WP_REST_Server::envelope_response() WP 6.4.3

public function envelope_response( $response, $embed ) {
	$envelope = array(
		'body'    => $this->response_to_data( $response, $embed ),
		'status'  => $response->get_status(),
		'headers' => $response->get_headers(),

	 * Filters the enveloped form of a REST API response.
	 * @since 4.4.0
	 * @param array            $envelope {
	 *     Envelope data.
	 *     @type array $body    Response data.
	 *     @type int   $status  The 3-digit HTTP status code.
	 *     @type array $headers Map of header name to header value.
	 * }
	 * @param WP_REST_Response $response Original response data.
	$envelope = apply_filters( 'rest_envelope_response', $envelope, $response );

	// Ensure it's still a response and return.
	return rest_ensure_response( $envelope );