Make WordPress Core


Ignore:
Timestamp:
10/17/2018 02:40:23 AM (6 years ago)
Author:
danielbachhuber
Message:

REST API: Don't add fields to object when not included in ?_fields=.

In [43087], we improved REST API performance by only rendering the fields specified in the request. Similarly, any fields registered with register_rest_field() should only be rendered when included in ?_fields=.

Props dlh.
Fixes #45099.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php

    r43445 r43736  
    386386        $additional_fields = $this->get_additional_fields();
    387387
     388        $requested_fields = $this->get_fields_for_response( $request );
     389
    388390        foreach ( $additional_fields as $field_name => $field_options ) {
    389391
    390392            if ( ! $field_options['get_callback'] ) {
     393                continue;
     394            }
     395
     396            if ( ! in_array( $field_name, $requested_fields, true ) ) {
    391397                continue;
    392398            }
Note: See TracChangeset for help on using the changeset viewer.