WP_REST_Server::get_response_links()
Retrieves links from a response.
Extracts the links from a response into a structured hash, suitable for direct output.
Method of the class: WP_REST_Server{}
No Hooks.
Return
Array
. Map of link relation to list of link hashes.
Usage
$result = WP_REST_Server::get_response_links( $response );
- $response(WP_REST_Response) (required)
- Response to extract links from.
Changelog
Since 4.4.0 | Introduced. |
WP_REST_Server::get_response_links() WP REST Server::get response links code WP 6.7.1
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']; if ( 'self' !== $rel ) { $data[ $rel ][] = $attributes; continue; } $target_hints = self::get_target_hints_for_link( $attributes ); if ( $target_hints ) { $attributes['targetHints'] = $target_hints; } $data[ $rel ][] = $attributes; } } return $data; }