Repository navigation
Commit 21ff64c
committed
REST API: Let routes turn off
Add a `data_processing` option to REST routes and route handlers, so a route can serve its response data as returned. The option is `false` to turn off every feature, or an array with any of the `fields`, `embed` and `links` keys. Every feature is on by default, the handler setting applies over the route setting feature by feature, and turning off `links` also turns off `embed`.
The settings are resolved once, when the request is matched, and stored on the request attributes, the matched handler and the response, where `rest_filter_response_fields()`, `WP_REST_Controller::get_fields_for_response()` and `WP_REST_Server::response_to_data()` read them. They apply to served, enveloped, batched and preloaded requests, and to responses returned by the `rest_pre_dispatch` filter. The index lists the settings of endpoints that turn a feature off.
Response data that is not an array is now served as returned even without the option: `_fields` leaves scalars and objects alone and keeps list items that are not arrays, links are not added to them unless the object implements `ArrayAccess`, and `rest_preload_api_request()` no longer casts preloaded data to an array.
This lets endpoints that own their output schema, such as the abilities run endpoint, return objects, lists and scalar values unchanged.
Props jorgefilipecosta, gziolo.
See #66267.
Fixes #66372.
Built from https://develop.svn.wordpress.org/trunk@64689
git-svn-id: http://core.svn.wordpress.org/trunk@63839 1a063a9b-81f0-0310-95a4-ce76da25c4cd_fields, _embed and response links.1 parent c967518 commit 21ff64c
5 files changed
Lines changed: 246 additions & 41 deletions
File tree
- wp-includes
- rest-api
- endpoints
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
950 | 950 | | |
951 | 951 | | |
952 | 952 | | |
| 953 | + | |
| 954 | + | |
953 | 955 | | |
954 | 956 | | |
955 | 957 | | |
| |||
961 | 963 | | |
962 | 964 | | |
963 | 965 | | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
964 | 971 | | |
965 | 972 | | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
966 | 978 | | |
967 | 979 | | |
968 | 980 | | |
| |||
993 | 1005 | | |
994 | 1006 | | |
995 | 1007 | | |
996 | | - | |
| 1008 | + | |
997 | 1009 | | |
998 | 1010 | | |
999 | 1011 | | |
| |||
3048 | 3060 | | |
3049 | 3061 | | |
3050 | 3062 | | |
3051 | | - | |
| 3063 | + | |
3052 | 3064 | | |
3053 | 3065 | | |
3054 | 3066 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
72 | 86 | | |
73 | 87 | | |
74 | 88 | | |
| |||
249 | 263 | | |
250 | 264 | | |
251 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
252 | 310 | | |
253 | 311 | | |
254 | 312 | | |
| |||
0 commit comments