REST API: Fix error in _fields filtering logic where only one of several requested sibling properties would be included.

Props kadamwhite, TimothyBlynJacobs.
Fixes #48266.


git-svn-id: https://develop.svn.wordpress.org/trunk@46456 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
K. Adam White
2019-10-10 17:16:44 +00:00
parent 1bcd41b7c1
commit 70b408c8fe
2 changed files with 102 additions and 2 deletions

View File

@@ -743,8 +743,12 @@ function rest_filter_response_fields( $response, $server, $request ) {
$parts = explode( '.', $field );
$ref = &$fields_as_keyed;
while ( count( $parts ) > 1 ) {
$next = array_shift( $parts );
$ref[ $next ] = array();
$next = array_shift( $parts );
if ( isset( $ref[ $next ] ) && true === $ref[ $next ] ) {
// Skip any sub-properties if their parent prop is already marked for inclusion.
break 2;
}
$ref[ $next ] = isset( $ref[ $next ] ) ? $ref[ $next ] : array();
$ref = &$ref[ $next ];
}
$last = array_shift( $parts );