[wp-trac] [WordPress Trac] #42061: Add new utility function for checking if the current request is a REST API request.
WordPress Trac
noreply at wordpress.org
Tue Mar 10 19:59:05 UTC 2020
#42061: Add new utility function for checking if the current request is a REST API
request.
------------------------------------+-----------------------------
Reporter: lots.0.logs | Owner: flixos90
Type: enhancement | Status: assigned
Priority: normal | Milestone: Future Release
Component: Bootstrap/Load | Version: 4.9
Severity: normal | Resolution:
Keywords: has-patch dev-feedback | Focuses: rest-api
------------------------------------+-----------------------------
Comment (by iandunn):
Replying to [comment:7 flixos90]:
> REST is controlled by a query variable...
> It is therefore impossible to detect a REST request before the
`parse_request` action, at least with the means currently in place...
> We could find a way to detect a REST request through another way and aim
for making the process similar to AJAX and Cron so that it can be detected
really early.
I think that'd be ideal. One benefit would be that `WP_USE_THEMES` could
be set to `false` for REST API requests, and `wp_using_themes()` could be
used to [https://wordpress.stackexchange.com/questions/332854/detect-
front-end-pages-only-in-init-hook detect the front end] before
`template_redirect` executes.
One way to do that might be something like
[https://github.com/woocommerce/woocommerce/pull/21090/files#diff-
7a990aa0f401ec3e7e8a62c6b23d8b3eR230 the solution that Woo experiment
with]. I haven't looked deeply to see if there are cases where that
wouldn't work, though.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42061#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list