Changeset 59032 for trunk/src/wp-includes/rest-api/class-wp-rest-server.php
- Timestamp:
- 09/17/2024 09:50:38 PM (8 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/class-wp-rest-server.php
r58688 r59032 637 637 $attributes = $item['attributes']; 638 638 $attributes['href'] = $item['href']; 639 $data[ $rel ][] = $attributes; 639 640 if ( 'self' !== $rel ) { 641 $data[ $rel ][] = $attributes; 642 continue; 643 } 644 645 $target_hints = self::get_target_hints_for_link( $attributes ); 646 if ( $target_hints ) { 647 $attributes['targetHints'] = $target_hints; 648 } 649 650 $data[ $rel ][] = $attributes; 640 651 } 641 652 } 642 653 643 654 return $data; 655 } 656 657 /** 658 * Gets the target links for a REST API Link. 659 * 660 * @since 6.7.0 661 * 662 * @param array $link 663 * 664 * @return array|null 665 */ 666 protected static function get_target_hints_for_link( $link ) { 667 // Prefer targetHints that were specifically designated by the developer. 668 if ( isset( $link['targetHints']['allow'] ) ) { 669 return null; 670 } 671 672 $request = WP_REST_Request::from_url( $link['href'] ); 673 if ( ! $request ) { 674 return null; 675 } 676 677 $server = rest_get_server(); 678 $match = $server->match_request_to_handler( $request ); 679 680 if ( is_wp_error( $match ) ) { 681 return null; 682 } 683 684 if ( is_wp_error( $request->has_valid_params() ) ) { 685 return null; 686 } 687 688 if ( is_wp_error( $request->sanitize_params() ) ) { 689 return null; 690 } 691 692 $target_hints = array(); 693 694 $response = new WP_REST_Response(); 695 $response->set_matched_route( $match[0] ); 696 $response->set_matched_handler( $match[1] ); 697 $headers = rest_send_allow_header( $response, $server, $request )->get_headers(); 698 699 foreach ( $headers as $name => $value ) { 700 $name = WP_REST_Request::canonicalize_header_name( $name ); 701 702 $target_hints[ $name ] = array_map( 'trim', explode( ',', $value ) ); 703 } 704 705 return $target_hints; 644 706 } 645 707
Note: See TracChangeset
for help on using the changeset viewer.