diff --git src/wp-includes/rest-api.php src/wp-includes/rest-api.php
index c397bdc116..52a6e62dce 100644
|
|
function rest_filter_response_fields( $response, $server, $request ) { |
744 | 744 | $ref = &$fields_as_keyed; |
745 | 745 | while ( count( $parts ) > 1 ) { |
746 | 746 | $next = array_shift( $parts ); |
747 | | $ref[ $next ] = array(); |
| 747 | $ref[ $next ] = isset( $ref[ $next ] ) ? $ref[ $next ] : array(); |
748 | 748 | $ref = &$ref[ $next ]; |
749 | 749 | } |
750 | 750 | $last = array_shift( $parts ); |
751 | | $ref[ $last ] = true; |
| 751 | $ref[ $last ] = array(); |
752 | 752 | } |
753 | 753 | |
754 | 754 | if ( wp_is_numeric_array( $data ) ) { |
diff --git tests/phpunit/tests/rest-api.php tests/phpunit/tests/rest-api.php
index 2b8310f168..0a28108d47 100644
|
|
class Tests_REST_API extends WP_UnitTestCase { |
560 | 560 | ); |
561 | 561 | } |
562 | 562 | |
| 563 | /** |
| 564 | * Ensure that specifying two sibling properties in _fields causes both to be included. |
| 565 | * |
| 566 | * @ticket 42094 |
| 567 | */ |
| 568 | public function test_rest_filter_response_fields_include_all_specified_siblings() { |
| 569 | $response = new WP_REST_Response(); |
| 570 | |
| 571 | $response->set_data( |
| 572 | array( |
| 573 | 'meta' => array( |
| 574 | 'key1' => 1, |
| 575 | 'key2' => 2, |
| 576 | ), |
| 577 | ) |
| 578 | ); |
| 579 | $request = array( |
| 580 | '_fields' => 'meta.key1,meta.key2', |
| 581 | ); |
| 582 | |
| 583 | $response = rest_filter_response_fields( $response, null, $request ); |
| 584 | $this->assertEquals( |
| 585 | array( |
| 586 | 'meta' => array( |
| 587 | 'key1' => 1, |
| 588 | 'key2' => 2, |
| 589 | ), |
| 590 | ), |
| 591 | $response->get_data() |
| 592 | ); |
| 593 | } |
| 594 | |
563 | 595 | /** |
564 | 596 | * @ticket 42094 |
565 | 597 | */ |