WP_REST_Server::response_to_data( WP_REST_Response $response, bool $embed )

Converts a response to data to send.


Description Description


Parameters Parameters

$response

(WP_REST_Response) (Required) Response object.

$embed

(bool) (Required) Whether links should be embedded.


Top ↑

Return Return

(array) Data with sub-requests embedded.

  • '[$_links]'
    (array) Links.
  • '[$_embedded]'
    (array) Embeddeds.

Top ↑

Source Source

File: wp-includes/rest-api/class-wp-rest-server.php

	public function response_to_data( $response, $embed ) {
		$data  = $response->get_data();
		$links = self::get_compact_response_links( $response );

		if ( ! empty( $links ) ) {
			// Convert links to part of the data.
			$data['_links'] = $links;
		}
		if ( $embed ) {
			// Determine if this is a numeric array.
			if ( wp_is_numeric_array( $data ) ) {
				$data = array_map( array( $this, 'embed_links' ), $data );
			} else {
				$data = $this->embed_links( $data );
			}
		}

		return $data;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
4.4.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.