WP_REST_Server::response_to_data
Converts a response to data to send.
Метод класса: WP_REST_Server{}
Хуков нет.
Возвращает
Массив. Data with sub-requests embedded.
Использование
$WP_REST_Server = new WP_REST_Server(); $WP_REST_Server->response_to_data( $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 | Введена. |
| С версии 5.4.0 | The $embed parameter can now contain a list of link relations to include. |
Код WP_REST_Server::response_to_data() WP REST Server::response to data WP 6.8.3
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;
}