WP_REST_Server::response_to_data( WP_REST_Response $response, bool|string[] $embed )
Converts a response to data to send.
Parameters
- $response
-
(Required) Response object.
- $embed
-
(Required) Whether to embed all links, a filtered list of link relations, or no links.
Return
(array) Data with sub-requests embedded.<br>
- '_links'
(array) Links.<br> - '_embedded'
(array) Embedded objects.<br>
Source
File: wp-includes/rest-api/class-wp-rest-server.php
public function response_to_data( $response, $embed ) {
$data = $response->get_data();
$links = $this->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;
}
Changelog
Version | Description |
---|---|
5.4.0 | The $embed parameter can now contain a list of link relations to include. |
4.4.0 | Introduced. |