Converts a response to data to send.
Parameters
$response
WP_REST_Responserequired- Response object.
$embed
bool|string[]required- Whether to embed all links, a filtered list of link relations, or no links.
Source
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;
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.