Changeset 53760
- Timestamp:
- 07/22/2022 01:58:46 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php
r53724 r53760 611 611 } 612 612 613 $fields = $this->get_fields_for_response( $request ); 614 613 615 $prepared = array( 614 616 'uuid' => $item['uuid'], … … 628 630 629 631 $response = new WP_REST_Response( $prepared ); 630 $response->add_links( $this->prepare_links( $user, $item ) ); 632 633 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 634 $response->add_links( $this->prepare_links( $user, $item ) ); 635 } 631 636 632 637 /** -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php
r53315 r53760 119 119 // Restores the more descriptive, specific name for use within this method. 120 120 $plugin = $item; 121 122 $fields = $this->get_fields_for_response( $request ); 121 123 122 124 // There might be multiple blocks in a plugin. Only the first block is mapped. … … 147 149 148 150 $response = new WP_REST_Response( $block ); 149 $response->add_links( $this->prepare_links( $plugin ) ); 151 152 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 153 $response->add_links( $this->prepare_links( $plugin ) ); 154 } 150 155 151 156 return $response; -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php
r53724 r53760 307 307 $response = rest_ensure_response( $data ); 308 308 309 $response->add_links( $this->prepare_links( $block_type ) ); 309 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 310 $response->add_links( $this->prepare_links( $block_type ) ); 311 } 310 312 311 313 /** -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
r53729 r53760 1120 1120 $response = rest_ensure_response( $data ); 1121 1121 1122 $response->add_links( $this->prepare_links( $comment ) ); 1122 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 1123 $response->add_links( $this->prepare_links( $comment ) ); 1124 } 1123 1125 1124 1126 /** -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
r51657 r53760 582 582 $fields = array_keys( $properties ); 583 583 584 /* 585 * '_links' and '_embedded' are not typically part of the item schema, 586 * but they can be specified in '_fields', so they are added here as a 587 * convenience for checking with rest_is_field_included(). 588 */ 589 $fields[] = '_links'; 590 if ( $request->has_param( '_embed' ) ) { 591 $fields[] = '_embedded'; 592 } 593 594 $fields = array_unique( $fields ); 595 584 596 if ( ! isset( $request['_fields'] ) ) { 585 597 return $fields; -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php
r53724 r53760 393 393 $response = rest_ensure_response( $data ); 394 394 395 $links = $this->prepare_links( $post->ID ); 396 $response->add_links( $links ); 397 if ( ! empty( $links['self']['href'] ) ) { 398 $actions = $this->get_available_actions(); 399 $self = $links['self']['href']; 400 foreach ( $actions as $rel ) { 401 $response->add_link( $rel, $self ); 395 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 396 $links = $this->prepare_links( $post->ID ); 397 $response->add_links( $links ); 398 if ( ! empty( $links['self']['href'] ) ) { 399 $actions = $this->get_available_actions(); 400 $self = $links['self']['href']; 401 foreach ( $actions as $rel ) { 402 $response->add_link( $rel, $self ); 403 } 402 404 } 403 405 } … … 591 593 $response = rest_ensure_response( $data ); 592 594 593 $links = array( 594 'self' => array( 595 'href' => rest_url( sprintf( '%s/%s/themes/%s', $this->namespace, $this->rest_base, $request['stylesheet'] ) ), 596 ), 597 ); 598 599 $response->add_links( $links ); 595 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 596 $links = array( 597 'self' => array( 598 'href' => rest_url( sprintf( '%s/%s/themes/%s', $this->namespace, $this->rest_base, $request['stylesheet'] ) ), 599 ), 600 ); 601 $response->add_links( $links ); 602 } 600 603 601 604 return $response; -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php
r53679 r53760 611 611 $response = rest_ensure_response( $data ); 612 612 613 $links = $this->prepare_links( $item ); 614 $response->add_links( $links ); 615 616 if ( ! empty( $links['self']['href'] ) ) { 617 $actions = $this->get_available_actions( $item, $request ); 618 619 $self = $links['self']['href']; 620 621 foreach ( $actions as $rel ) { 622 $response->add_link( $rel, $self ); 613 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 614 $links = $this->prepare_links( $item ); 615 $response->add_links( $links ); 616 617 if ( ! empty( $links['self']['href'] ) ) { 618 $actions = $this->get_available_actions( $item, $request ); 619 620 $self = $links['self']['href']; 621 622 foreach ( $actions as $rel ) { 623 $response->add_link( $rel, $self ); 624 } 623 625 } 624 626 } -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-locations-controller.php
r53724 r53760 194 194 $response = rest_ensure_response( $data ); 195 195 196 $response->add_links( $this->prepare_links( $location ) ); 196 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 197 $response->add_links( $this->prepare_links( $location ) ); 198 } 197 199 198 200 /** -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php
r52079 r53760 135 135 136 136 $response = rest_ensure_response( $data ); 137 $response->add_links( $this->prepare_links( $term ) ); 137 138 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 139 $response->add_links( $this->prepare_links( $term ) ); 140 } 138 141 139 142 /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php */ -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php
r53724 r53760 577 577 */ 578 578 public function prepare_item_for_response( $item, $request ) { 579 $fields = $this->get_fields_for_response( $request ); 580 579 581 $item = _get_plugin_data_markup_translate( $item['_file'], $item, false ); 580 582 $marked = _get_plugin_data_markup_translate( $item['_file'], $item, true ); … … 601 603 602 604 $response = new WP_REST_Response( $data ); 603 $response->add_links( $this->prepare_links( $item ) ); 605 606 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 607 $response->add_links( $this->prepare_links( $item ) ); 608 } 604 609 605 610 /** -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php
r53724 r53760 245 245 $response = rest_ensure_response( $data ); 246 246 247 $response->add_links( $this->prepare_links( $post_type ) ); 247 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 248 $response->add_links( $this->prepare_links( $post_type ) ); 249 } 248 250 249 251 /** -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r53759 r53760 1934 1934 $response = rest_ensure_response( $data ); 1935 1935 1936 $links = $this->prepare_links( $post ); 1937 $response->add_links( $links ); 1938 1939 if ( ! empty( $links['self']['href'] ) ) { 1940 $actions = $this->get_available_actions( $post, $request ); 1941 1942 $self = $links['self']['href']; 1943 1944 foreach ( $actions as $rel ) { 1945 $response->add_link( $rel, $self ); 1936 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 1937 $links = $this->prepare_links( $post ); 1938 $response->add_links( $links ); 1939 1940 if ( ! empty( $links['self']['href'] ) ) { 1941 $actions = $this->get_available_actions( $post, $request ); 1942 1943 $self = $links['self']['href']; 1944 1945 foreach ( $actions as $rel ) { 1946 $response->add_link( $rel, $self ); 1947 } 1946 1948 } 1947 1949 } -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php
r51786 r53760 211 211 $response = rest_ensure_response( $data ); 212 212 213 $links = $handler->prepare_item_links( $item_id ); 214 $links['collection'] = array( 215 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), 216 ); 217 $response->add_links( $links ); 213 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 214 $links = $handler->prepare_item_links( $item_id ); 215 $links['collection'] = array( 216 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), 217 ); 218 $response->add_links( $links ); 219 } 218 220 219 221 return $response; -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php
r52362 r53760 369 369 $response = rest_ensure_response( $data ); 370 370 371 $response->add_links( $this->prepare_links( $sidebar ) ); 371 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 372 $response->add_links( $this->prepare_links( $sidebar ) ); 373 } 372 374 373 375 /** -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php
r53724 r53760 273 273 $response = rest_ensure_response( $data ); 274 274 275 $response->add_links( $this->prepare_links( $taxonomy ) ); 275 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 276 $response->add_links( $this->prepare_links( $taxonomy ) ); 277 } 276 278 277 279 /** -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
r52434 r53760 663 663 $response = rest_ensure_response( $data ); 664 664 665 $links = $this->prepare_links( $template->id ); 666 $response->add_links( $links ); 667 if ( ! empty( $links['self']['href'] ) ) { 668 $actions = $this->get_available_actions(); 669 $self = $links['self']['href']; 670 foreach ( $actions as $rel ) { 671 $response->add_link( $rel, $self ); 665 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 666 $links = $this->prepare_links( $template->id ); 667 $response->add_links( $links ); 668 if ( ! empty( $links['self']['href'] ) ) { 669 $actions = $this->get_available_actions(); 670 $self = $links['self']['href']; 671 foreach ( $actions as $rel ) { 672 $response->add_link( $rel, $self ); 673 } 672 674 } 673 675 } -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
r52068 r53760 860 860 $response = rest_ensure_response( $data ); 861 861 862 $response->add_links( $this->prepare_links( $item ) ); 862 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 863 $response->add_links( $this->prepare_links( $item ) ); 864 } 863 865 864 866 /** -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php
r53544 r53760 332 332 $response = rest_ensure_response( $data ); 333 333 334 $response->add_links( $this->prepare_links( $theme ) ); 334 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 335 $response->add_links( $this->prepare_links( $theme ) ); 336 } 335 337 336 338 /** -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
r52978 r53760 1073 1073 $response = rest_ensure_response( $data ); 1074 1074 1075 $response->add_links( $this->prepare_links( $user ) ); 1075 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 1076 $response->add_links( $this->prepare_links( $user ) ); 1077 } 1076 1078 1077 1079 /** -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php
r52278 r53760 336 336 $response = rest_ensure_response( $data ); 337 337 338 $response->add_links( $this->prepare_links( $widget_type ) ); 338 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 339 $response->add_links( $this->prepare_links( $widget_type ) ); 340 } 339 341 340 342 /** -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php
r52362 r53760 727 727 $response = rest_ensure_response( $prepared ); 728 728 729 $response->add_links( $this->prepare_links( $prepared ) ); 729 if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { 730 $response->add_links( $this->prepare_links( $prepared ) ); 731 } 730 732 731 733 /** -
trunk/tests/phpunit/tests/rest-api/rest-controller.php
r51908 r53760 387 387 'somearray', 388 388 'someobject', 389 '_links', 389 390 ), 390 391 $fields … … 422 423 'somearray', 423 424 'someobject', 424 ), 425 ), 426 ); 425 '_links', 426 ), 427 ), 428 ); 429 } 430 431 public function test_get_fields_for_response_respects_embed() { 432 $controller = new WP_REST_Test_Controller(); 433 $request = new WP_REST_Request( 'GET', '/wp/v2/testroute' ); 434 435 $this->assertNotContains( '_embedded', $controller->get_fields_for_response( $request ) ); 436 437 $request->set_param( '_embed', 1 ); 438 439 $this->assertContains( '_embedded', $controller->get_fields_for_response( $request ) ); 427 440 } 428 441 -
trunk/tests/phpunit/tests/rest-api/rest-search-controller.php
r53485 r53760 444 444 'id', 445 445 'title', 446 '_links',447 446 ), 448 447 array_keys( $data[0] )
Note: See TracChangeset
for help on using the changeset viewer.