diff --git a/src/wp-includes/rest-api/class-wp-rest-response.php b/src/wp-includes/rest-api/class-wp-rest-response.php
index db80029..af50c0c 100644
a
|
b
|
class WP_REST_Response extends WP_HTTP_Response { |
256 | 256 | |
257 | 257 | return $error; |
258 | 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Get the CURIEs (compact URIs) used for relations. |
| 262 | * |
| 263 | * @return array |
| 264 | */ |
| 265 | public function get_curies() { |
| 266 | return array( |
| 267 | array( |
| 268 | 'name' => 'wp', |
| 269 | 'href' => 'https://api.w.org/', |
| 270 | ), |
| 271 | ); |
| 272 | } |
259 | 273 | } |
diff --git a/src/wp-includes/rest-api/class-wp-rest-server.php b/src/wp-includes/rest-api/class-wp-rest-server.php
index dad4070..e84acbe 100644
a
|
b
|
class WP_REST_Server { |
460 | 460 | |
461 | 461 | // Convert links to part of the data. |
462 | 462 | $data = array(); |
| 463 | $curies = $response->get_curies(); |
| 464 | $used_curies = array(); |
| 465 | |
463 | 466 | foreach ( $links as $rel => $items ) { |
464 | 467 | $data[ $rel ] = array(); |
465 | 468 | |
| 469 | $matched_curi = null; |
| 470 | |
| 471 | // Convert $rel URIs to their compact versions if they exist. |
| 472 | foreach ( $curies as $curi ) { |
| 473 | if ( strpos( $rel, $curi['href'] ) === 0 ) { |
| 474 | $matched_curi = $curi; |
| 475 | $used_curies[ $curi['name'] ] = array( |
| 476 | 'name' => $curi['name'], |
| 477 | 'href' => $curi['href'] . '{rel}', |
| 478 | 'templated' => true, |
| 479 | ); |
| 480 | |
| 481 | // Relation now changes from '$uri' to '$curie:$relation' |
| 482 | $rel = $curi['name'] . ':' . substr( $rel, strlen( $curi['href'] ) ); |
| 483 | break; |
| 484 | } |
| 485 | } |
466 | 486 | foreach ( $items as $item ) { |
467 | 487 | $attributes = $item['attributes']; |
468 | 488 | $attributes['href'] = $item['href']; |
… |
… |
class WP_REST_Server { |
470 | 490 | } |
471 | 491 | } |
472 | 492 | |
| 493 | // Push the curies onto the start of the links array. |
| 494 | if ( $used_curies ) { |
| 495 | $data = array_merge( array( 'curies' => array_values( $used_curies ) ), $data ); |
| 496 | } |
| 497 | |
473 | 498 | return $data; |
474 | 499 | } |
475 | 500 | |