Changeset 47224 for trunk/src/wp-includes/rest-api/class-wp-rest-server.php
- Timestamp:
- 02/09/2020 08:52:06 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/class-wp-rest-server.php
r47138 r47224 399 399 400 400 // Embed links inside the request. 401 $result = $this->response_to_data( $result, isset( $_GET['_embed'] ) ); 401 $embed = isset( $_GET['_embed'] ) ? rest_parse_embed_param( $_GET['_embed'] ) : false; 402 $result = $this->response_to_data( $result, $embed ); 402 403 403 404 /** … … 451 452 * 452 453 * @since 4.4.0 454 * @since 5.4.0 The $embed parameter can now contain a list of link relations to include. 453 455 * 454 456 * @param WP_REST_Response $response Response object. 455 * @param bool $embed Whether links should be embedded.457 * @param bool|string[] $embed Whether to embed all links, a filtered list of link relations, or no links. 456 458 * @return array { 457 459 * Data with sub-requests embedded. … … 474 476 // Determine if this is a numeric array. 475 477 if ( wp_is_numeric_array( $data ) ) { 476 $data = array_map( array( $this, 'embed_links' ), $data ); 478 foreach ( $data as $key => $item ) { 479 $data[ $key ] = $this->embed_links( $item, $embed ); 480 } 477 481 } else { 478 $data = $this->embed_links( $data );482 $data = $this->embed_links( $data, $embed ); 479 483 } 480 484 $this->embed_cache = array(); … … 572 576 * 573 577 * @since 4.4.0 574 * 575 * @param array $data Data from the request. 578 * @since 5.4.0 The $embed parameter can now contain a list of link relations to include. 579 * 580 * @param array $data Data from the request. 581 * @param bool|string[] $embed Whether to embed all links or a filtered list of link relations. 576 582 * @return array { 577 583 * Data with sub-requests embedded. … … 581 587 * } 582 588 */ 583 protected function embed_links( $data ) {589 protected function embed_links( $data, $embed = true ) { 584 590 if ( empty( $data['_links'] ) ) { 585 591 return $data; … … 589 595 590 596 foreach ( $data['_links'] as $rel => $links ) { 597 // If a list of relations was specified, and the link relation is not in the whitelist, don't process the link. 598 if ( is_array( $embed ) && ! in_array( $rel, $embed, true ) ) { 599 continue; 600 } 601 591 602 $embeds = array(); 592 603
Note: See TracChangeset
for help on using the changeset viewer.