wppaste
WordPress

WP_REST_Server::get_compact_response_links( WP_REST_Response $response ): array

Since
4.5.0
Source
wp-includes/rest-api/class-wp-rest-server.php:725
Retrieves the CURIEs (compact URIs) used for relations.

Description

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

Parameters

$responseWP_REST_Response
Response to extract links from.

Return

array
Map of link relation to list of link hashes.

Uses · 2

Used by · 1

Source

	public static function get_compact_response_links( $response ) {		$links = self::get_response_links( $response ); 		if ( empty( $links ) ) {			return array();		} 		$curies      = $response->get_curies();		$used_curies = array(); 		foreach ( $links as $rel => $items ) { 			// Convert $rel URIs to their compact versions if they exist.			foreach ( $curies as $curie ) {				$href_prefix = substr( $curie['href'], 0, strpos( $curie['href'], '{rel}' ) );				if ( ! str_starts_with( $rel, $href_prefix ) ) {					continue;				} 				// Relation now changes from '$uri' to '$curie:$relation'.				$rel_regex = str_replace( '\{rel\}', '(.+)', preg_quote( $curie['href'], '!' ) );				preg_match( '!' . $rel_regex . '!', $rel, $matches );				if ( $matches ) {					$new_rel                       = $curie['name'] . ':' . $matches[1];					$used_curies[ $curie['name'] ] = $curie;					$links[ $new_rel ]             = $items;					unset( $links[ $rel ] );					break;				}			}		} 		// Push the curies onto the start of the links array.		if ( $used_curies ) {			$links['curies'] = array_values( $used_curies );		} 		return $links;	}

History

Introduced in 4.5.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/rest-api/class-wp-rest-server.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.