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 f795eb1..2555696 100644
|
a
|
b
|
class WP_REST_Server { |
| 421 | 421 | */ |
| 422 | 422 | public function response_to_data( $response, $embed ) { |
| 423 | 423 | $data = $response->get_data(); |
| 424 | | $links = $this->get_response_links( $response ); |
| | 424 | $links = $this->get_compact_response_links( $response ); |
| 425 | 425 | |
| 426 | 426 | if ( ! empty( $links ) ) { |
| 427 | 427 | // Convert links to part of the data. |
| … |
… |
class WP_REST_Server { |
| 454 | 454 | */ |
| 455 | 455 | public static function get_response_links( $response ) { |
| 456 | 456 | $links = $response->get_links(); |
| 457 | | |
| 458 | 457 | if ( empty( $links ) ) { |
| 459 | 458 | return array(); |
| 460 | 459 | } |
| 461 | 460 | |
| 462 | 461 | // Convert links to part of the data. |
| 463 | 462 | $data = array(); |
| | 463 | foreach ( $links as $rel => $items ) { |
| | 464 | $data[ $rel ] = array(); |
| | 465 | |
| | 466 | foreach ( $items as $item ) { |
| | 467 | $attributes = $item['attributes']; |
| | 468 | $attributes['href'] = $item['href']; |
| | 469 | $data[ $rel ][] = $attributes; |
| | 470 | } |
| | 471 | } |
| | 472 | |
| | 473 | return $data; |
| | 474 | } |
| | 475 | |
| | 476 | /** |
| | 477 | * Retrieves the CURIEs (compact URIs) used for relations. |
| | 478 | * |
| | 479 | * Extracts the links from a response into a structured hash, suitable for |
| | 480 | * direct output. |
| | 481 | * |
| | 482 | * @since 4.5.0 |
| | 483 | * @access public |
| | 484 | * @static |
| | 485 | * |
| | 486 | * @param WP_REST_Response $response Response to extract links from. |
| | 487 | * @return array Map of link relation to list of link hashes. |
| | 488 | */ |
| | 489 | public static function get_compact_response_links( $response ) { |
| | 490 | $links = self::get_response_links( $response ); |
| | 491 | |
| | 492 | if ( empty( $links ) ) { |
| | 493 | return array(); |
| | 494 | } |
| | 495 | |
| 464 | 496 | $curies = $response->get_curies(); |
| 465 | 497 | $used_curies = array(); |
| 466 | 498 | |
| … |
… |
class WP_REST_Server { |
| 472 | 504 | if ( strpos( $rel, $href_prefix ) !== 0 ) { |
| 473 | 505 | continue; |
| 474 | 506 | } |
| 475 | | $used_curies[ $curie['name'] ] = $curie; |
| 476 | 507 | |
| 477 | 508 | // Relation now changes from '$uri' to '$curie:$relation' |
| 478 | | $rel_regex = str_replace( '\{rel\}', '([\w]+)', preg_quote( $curie['href'], '!' ) ); |
| | 509 | $rel_regex = str_replace( '\{rel\}', '(.+)', preg_quote( $curie['href'], '!' ) ); |
| 479 | 510 | preg_match( '!' . $rel_regex . '!', $rel, $matches ); |
| 480 | 511 | if ( $matches ) { |
| 481 | | $rel = $curie['name'] . ':' . $matches[1]; |
| | 512 | $new_rel = $curie['name'] . ':' . $matches[1]; |
| | 513 | $used_curies[ $curie['name'] ] = $curie; |
| | 514 | $links[ $new_rel ] = $items; |
| | 515 | unset( $links[ $rel ] ); |
| | 516 | break; |
| 482 | 517 | } |
| 483 | | break; |
| 484 | | } |
| 485 | | |
| 486 | | $data[ $rel ] = array(); |
| 487 | | |
| 488 | | foreach ( $items as $item ) { |
| 489 | | $attributes = $item['attributes']; |
| 490 | | $attributes['href'] = $item['href']; |
| 491 | | $data[ $rel ][] = $attributes; |
| 492 | 518 | } |
| 493 | 519 | } |
| 494 | 520 | |
| 495 | 521 | // Push the curies onto the start of the links array. |
| 496 | 522 | if ( $used_curies ) { |
| 497 | | $data = array_merge( array( 'curies' => array_values( $used_curies ) ), $data ); |
| | 523 | $links['curies'] = array_values( $used_curies ); |
| 498 | 524 | } |
| 499 | 525 | |
| 500 | | return $data; |
| | 526 | return $links; |
| 501 | 527 | } |
| 502 | 528 | |
| 503 | 529 | /** |