[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
Sun Dec 3 21:01:25 UTC 2017


#42061: Add new utility function for checking if the current request is a REST API
request.
----------------------------+-----------------------
 Reporter:  lots.0.logs     |       Owner:
     Type:  enhancement     |      Status:  closed
 Priority:  normal          |   Milestone:
Component:  Bootstrap/Load  |     Version:  4.9
 Severity:  normal          |  Resolution:  wontfix
 Keywords:  has-patch       |     Focuses:  rest-api
----------------------------+-----------------------
Changes (by joehoyle):

 * status:  new => closed
 * resolution:   => wontfix
 * milestone:  Awaiting Review =>


Old description:

> This patch adds a new function: `wp_doing_rest()` and filter by the same
> name that work exactly like the current `wp_doing_ajax/cron()` functions
> but for Rest API requests.

New description:

 This patch adds a new function: `wp_doing_rest()` and filter by the same
 name that work exactly like the current `wp_doing_ajax/cron()` functions
 but for Rest API requests.

--

Comment:

 See https://github.com/WP-API/WP-API/issues/926 for the previous story on
 this.

 Though we want to discourage use of global state functions like these,
 there _is_ a REST_REQUEST constant for this purpose. As mentioned in that
 ticket, the idea of "the current request is a REST one" breaks down for
 things like `_embed` requests, and internal `rest_do_request` calls,
 therefore we don't want to encourage the use of "is the current request a
 REST one" as it's not always in that context.

 @lots.0.logs perhaps you could define why you need such a function?
 `wp_doing_ajax/cron()` are inherently process-level functions, but the
 REST API callback methods are not intended to scoped to the whole "page
 load" request.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42061#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list