WP_REST_Server::get_response_links()public staticWP 4.4.0

Retrieves links from a response.

Extracts the links from a response into a structured hash, suitable for direct output.

Метод класса: WP_REST_Server{}

Хуков нет.

Возвращает

Массив. Map of link relation to list of link hashes.

Использование

$result = WP_REST_Server::get_response_links( $response );
$response(WP_REST_Response) (обязательный)
Response to extract links from.

Список изменений

С версии 4.4.0 Введена.

Код WP_REST_Server::get_response_links() WP 6.5.2

public static function get_response_links( $response ) {
	$links = $response->get_links();

	if ( empty( $links ) ) {
		return array();
	}

	// Convert links to part of the data.
	$data = array();
	foreach ( $links as $rel => $items ) {
		$data[ $rel ] = array();

		foreach ( $items as $item ) {
			$attributes         = $item['attributes'];
			$attributes['href'] = $item['href'];
			$data[ $rel ][]     = $attributes;
		}
	}

	return $data;
}