On this page
WP_REST_Server::response_to_data( WP_REST_Response $response, bool|string[] $embed ): array
Converts a response to data to send.
Parameters
$responseWP_REST_Response Required-
Response object.
$embedbool|string[] Required-
Whether to embed all links, a filtered list of link relations, or no links.
Return
array Data with sub-requests embedded.
_linksarrayLinks._embeddedarrayEmbedded objects.
Source
File: wp-includes/rest-api/class-wp-rest-server.php. View all references
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 ) {
$this->embed_cache = array();
// Determine if this is a numeric array.
if ( wp_is_numeric_array( $data ) ) {
foreach ( $data as $key => $item ) {
$data[ $key ] = $this->embed_links( $item, $embed );
}
} else {
$data = $this->embed_links( $data, $embed );
}
$this->embed_cache = array();
}
return $data;
}
Related
Uses
| Uses | Description |
|---|---|
| WP_REST_Server::get_compact_response_links() wp-includes/rest-api/class-wp-rest-server.php | Retrieves the CURIEs (compact URIs) used for relations. |
| WP_REST_Server::embed_links() wp-includes/rest-api/class-wp-rest-server.php | Embeds the links from the data into the request. |
| wp_is_numeric_array() wp-includes/functions.php | Determines if the variable is a numeric-indexed array. |
Used By
| Used By | Description |
|---|---|
| WP_REST_Server::envelope_response() wp-includes/rest-api/class-wp-rest-server.php | Wraps the response in an envelope. |
| WP_REST_Server::serve_request() wp-includes/rest-api/class-wp-rest-server.php | Handles serving a REST API request. |
| WP_REST_Server::embed_links() wp-includes/rest-api/class-wp-rest-server.php | Embeds the links from the data into the request. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_server/response_to_data