Repository navigation
Commit 5b2ee49
committed
REST API: Let routes turn off
Replace the `allow_fields`, `allow_embed` and `allow_links` options with
one `response_processing` route and handler option. It is `false` to
serve the response data as returned, or an array with `fields`, `embed`
and `links` keys to turn off single features: the `_fields` parameter
filtering the data, the `_embed` parameter embedding linked resources,
and the response links being added to the data as `_links`. Each
feature resolves on its own, the handler setting over the route
setting, and `embed` is off whenever `links` is off.
The settings are resolved once, when the request is matched, and are
read from the request attributes and the matched handler by the server,
by `rest_filter_response_fields()` and by
`WP_REST_Controller::get_fields_for_response()`. A response returned by
the `rest_pre_dispatch` filter follows the settings of the route it was
returned for. The index lists the settings of an endpoint that turns
off a feature, and `rest_preload_api_request()` no longer casts the
data to an array.
See #66267._fields, _embed and response links.1 parent 7a5e128 commit 5b2ee49
5 files changed
Lines changed: 614 additions & 133 deletions
File tree
- src/wp-includes
- rest-api
- endpoints
- tests/phpunit/tests/rest-api
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
950 | 950 | | |
951 | 951 | | |
952 | 952 | | |
953 | | - | |
| 953 | + | |
954 | 954 | | |
955 | 955 | | |
956 | 956 | | |
| |||
962 | 962 | | |
963 | 963 | | |
964 | 964 | | |
965 | | - | |
966 | | - | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
967 | 971 | | |
968 | 972 | | |
969 | 973 | | |
| |||
3053 | 3057 | | |
3054 | 3058 | | |
3055 | 3059 | | |
3056 | | - | |
| 3060 | + | |
3057 | 3061 | | |
3058 | 3062 | | |
3059 | 3063 | | |
| |||
0 commit comments