Repository navigation
REST API: Allow routes to disable _fields, _embed and response links - #14671
jorgefilipecosta wants to merge 1 commit into
Conversation
…nks. Add the `allow_fields`, `allow_embed` and `allow_links` route and handler options. When an option is false, the `_fields` parameter does not filter the response data, the `_embed` parameter does not embed linked resources, or the response links are not added to the response data as `_links`. A handler option takes precedence over the route option, as with `allow_batch`. This lets a route serve its response data as returned, for example data that follows a schema of its own or that is not an array. See #66267.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Follow up to #14547 (comment).
This PR adds three route and handler options that let a route opt out of the global response processing:
allow_fields: when false, the_fieldsparameter does not filter the response data.allow_embed: when false, the_embedparameter does not embed linked resources. The links are still added as_links.allow_links: when false, the response links are not added to the response data as_links.All three default to true. A handler option takes precedence over the route option of the same name, as with
allow_batch. The newWP_REST_Server::is_response_option_enabled()method reads them from the matched route and handler. The options apply to served, enveloped and preloaded requests.This lets a route return its data unchanged, e.g. the abilities run endpoint, whose result follows the ability's output schema and can be an object, a list or a scalar value. #14547 uses these options for that endpoint.
Drafted with AI assistance and reviewed by me.
Trac ticket: https://core.trac.wordpress.org/ticket/66267
Testing
Verify unit tests are passing: