WP_REST_Server::get_response_links( WP_REST_Response $response )

Retrieves links from a response.


Description Description

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


Top ↑

Parameters Parameters

$response

(WP_REST_Response) (Required) Response to extract links from.


Top ↑

Return Return

(array) Map of link relation to list of link hashes.


Top ↑

Source Source

File: wp-includes/rest-api/class-wp-rest-server.php

	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;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.4.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.