Make WordPress Core

Opened 6 days ago

Closed 5 days ago

#64844 closed defect (bug) (fixed)

REST API: Support nested _fields in revisions controller

Reported by: ellatrix's profile ellatrix Owned by: ellatrix's profile ellatrix
Milestone: 7.0 Priority: normal
Severity: normal Version:
Component: REST API Keywords: has-patch
Focuses: Cc:

Description

WP_REST_Revisions_Controller::prepare_item_for_response() uses in_array() for content, title, excerpt, and guid fields, which doesn't support nested _fields syntax (e.g. _fields=content.raw).

PR: https://github.com/WordPress/wordpress-develop/pull/11230

Change History (3)

This ticket was mentioned in PR #11230 on WordPress/wordpress-develop by @ellatrix.


6 days ago
#1

https://core.trac.wordpress.org/ticket/64844

Use rest_is_field_included() instead of in_array() for content, title, excerpt, and guid fields in WP_REST_Revisions_Controller. This lets clients request specific sub-fields (e.g. _fields=content.raw) and skip expensive the_content rendering.

The REST API `_fields` documentation states that nested fields are supported using dot notation. However, the revisions controller uses in_array() which doesn't match nested keys like content.raw.

Several other controllers already use rest_is_field_included() for raw/rendered sub-fields:

Related Gutenberg PR: https://github.com/WordPress/gutenberg/pull/76347

@ellatrix commented on PR #11230:


5 days ago
#2

Thanks for the review! I'm going to leave it as-is since we're close to Beta 5.

#3 @ellatrix
5 days ago

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

In 61987:

REST API: Support nested _fields in revisions controller.

Use rest_is_field_included() instead of in_array() for content, title, excerpt, and guid fields in WP_REST_Revisions_Controller. This lets clients request specific sub-fields (e.g. _fields=content.raw) and skip expensive the_content rendering.

The [REST API _fields documentation](https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/#_fields) states that nested fields are supported using dot notation. However, the revisions controller uses in_array() which doesn't match nested keys like content.raw.

Developed in: https://github.com/WordPress/wordpress-develop/pull/11230.

Props ellatrix, andrewserong, mukeshpanchal27.
Fixes #64844.

Note: See TracTickets for help on using tickets.