- Timestamp:
- 05/04/2020 02:44:44 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
r47511 r47758 289 289 * @since 4.7.0 290 290 * 291 * @param array $data Response data to fi ter.291 * @param array $data Response data to filter. 292 292 * @param string $context Context defined in the schema. 293 293 * @return array Filtered response. … … 297 297 $schema = $this->get_item_schema(); 298 298 299 foreach ( $data as $key => $value ) { 300 if ( empty( $schema['properties'][ $key ] ) || empty( $schema['properties'][ $key ]['context'] ) ) { 301 continue; 302 } 303 304 if ( ! in_array( $context, $schema['properties'][ $key ]['context'], true ) ) { 305 unset( $data[ $key ] ); 306 continue; 307 } 308 309 if ( 'object' === $schema['properties'][ $key ]['type'] && ! empty( $schema['properties'][ $key ]['properties'] ) ) { 310 foreach ( $schema['properties'][ $key ]['properties'] as $attribute => $details ) { 311 if ( empty( $details['context'] ) ) { 312 continue; 313 } 314 315 if ( ! in_array( $context, $details['context'], true ) ) { 316 if ( isset( $data[ $key ][ $attribute ] ) ) { 317 unset( $data[ $key ][ $attribute ] ); 318 } 319 } 320 } 321 } 322 } 323 324 return $data; 299 return rest_filter_response_by_context( $data, $schema, $context ); 325 300 } 326 301
Note: See TracChangeset
for help on using the changeset viewer.