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..02c58a6 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/{rel}', |
| | 270 | 'templated' => true, |
| | 271 | ), |
| | 272 | ); |
| | 273 | } |
| 259 | 274 | } |
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..cd0473b 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 ) { |
| | 467 | |
| | 468 | // Convert $rel URIs to their compact versions if they exist. |
| | 469 | foreach ( $curies as $curi ) { |
| | 470 | $href_prefix = substr( $curi['href'], 0, strpos( $curi['href'], '{rel}' ) ); |
| | 471 | if ( strpos( $rel, $href_prefix ) === 0 ) { |
| | 472 | $used_curies[ $curi['name'] ] = $curi; |
| | 473 | |
| | 474 | // Relation now changes from '$uri' to '$curie:$relation' |
| | 475 | $rel_regex = str_replace( '\{rel\}', '([\w]+)', preg_quote( $curi['href'], '!' ) ); |
| | 476 | preg_match( '!' . $rel_regex . '!', $rel, $matches ); |
| | 477 | if ( $matches ) { |
| | 478 | $rel = $curi['name'] . ':' . $matches[1]; |
| | 479 | } |
| | 480 | break; |
| | 481 | } |
| | 482 | } |
| | 483 | |
| 464 | 484 | $data[ $rel ] = array(); |
| 465 | 485 | |
| 466 | 486 | foreach ( $items as $item ) { |
| … |
… |
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 | |