WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/12/2018 08:50:22 PM (2 years ago)
Author:
desrosj
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, danielbachhuber.

Merges [43736] to trunk.

Fixes #45099.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php

    r43571 r43986  
    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.