[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
Wed Oct 18 17:21:10 UTC 2023
#42061: Add new utility function for checking if the current request is a REST API
request.
------------------------------------+------------------------------------
Reporter: lots.0.logs | Owner: TimothyBlynJacobs
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, performance
------------------------------------+------------------------------------
Comment (by flixos90):
Reviving this ticket, as the lack of this function also prevents proper
testing to discover bugs like that fixed in https://github.com/WordPress
/wordpress-develop/pull/5514.
@TimothyBlynJacobs I wonder whether we should circle back here. I'm not
sure we really need to go down the rewrite rules rabbit hole. What about
simply having a function that applies a filter instead of being forced to
check `defined( 'REST_REQUEST' ) && REST_REQUEST`? It would make code
paths testable that were previously not testable. The filter could be used
to set the value temporarily to `true` for preloaded REST requests (i.e.
those where REST routes are called without actually triggering a REST
request).
To some degree, that would achieve a different goal, and we could consider
reflecting that in the function's and filter's name accordingly. But I
think it's worth considering that approach, as it would be much simpler
and would bring immediate benefits to testability of core.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42061#comment:26>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list