Make WordPress Core

Opened 4 months ago

Closed 7 weeks ago

#42061 closed enhancement (wontfix)

Add new utility function for checking if the current request is a REST API request.

Reported by: lots.0.logs Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.9
Component: Bootstrap/Load Keywords: has-patch
Focuses: rest-api Cc:

Description (last modified by joehoyle)

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.

Attachments (1)

42061-add-wp-doing-rest-filterable-function.patch (1.7 KB) - added by lots.0.logs 4 months ago.

Download all attachments as: .zip

Change History (3)

#1 @lots.0.logs
4 months ago

  • Keywords has-patch added

#2 @joehoyle
7 weeks ago

  • Description modified (diff)
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

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.

Note: See TracTickets for help on using tickets.