WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 22 months ago

#45099 closed defect (bug) (fixed)

REST API: Render only additional fields specific to request when _fields= is used

Reported by: dlh Owned by: danielbachhuber
Milestone: 5.0 Priority: normal
Severity: normal Version: 4.9.8
Component: REST API Keywords: has-patch has-unit-tests fixed-5.0
Focuses: rest-api Cc:

Description

Follow-up to #43874.

#43874 caused only requested _fields to be processed within the core REST controllers' prepare_item_for_response().

However, callbacks added with register_rest_field() still fire during WP_REST_Controller::add_additional_fields_to_object() regardless of the requested _fields.

The attached patch would add a check for the requested fields to add_additional_fields_to_object() before firing the callbacks.

As suggested in Slack, I'm setting the milestone for this ticket to 5.0: https://wordpress.slack.com/archives/C02RQC26G/p1539604416000100.

Attachments (1)

45099.diff (3.6 KB) - added by dlh 2 years ago.

Download all attachments as: .zip

Change History (4)

@dlh
2 years ago

#1 @danielbachhuber
2 years ago

  • Owner set to danielbachhuber
  • Resolution set to fixed
  • Status changed from new to closed

In 43736:

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.

#2 @danielbachhuber
2 years ago

  • Focuses rest-api added
  • Keywords fixed-5.0 added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for merge to trunk.

#3 @desrosj
22 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 43986:

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.

Note: See TracTickets for help on using tickets.