mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-02 11:44:33 +00:00
Bootstrap/Load: Introduce functions to check whether WordPress is serving a REST API request.
This changeset introduces two functions: * `wp_is_serving_rest_request()` returns a boolean for whether WordPress is serving an actual REST API request. * `wp_is_rest_endpoint()` returns a boolean for whether a WordPress REST API endpoint is currently being used. While this is always the case if `wp_is_serving_rest_request()` returns `true`, the function additionally covers the scenario of internal REST API requests, i.e. where WordPress calls a REST API endpoint within the same request. Both functions should only be used after the `parse_request` action. All relevant manual checks have been adjusted to use one of the new functions, depending on the use-case. They were all using the same constant check so far, while in fact some of them were intending to check for an actual REST API request while others were intending to check for REST endpoint usage. A new filter `wp_is_rest_endpoint` can be used to alter the return value of the `wp_is_rest_endpoint()` function. Props lots.0.logs, TimothyBlynJacobs, flixos90, joehoyle, peterwilsoncc, swissspidy, SergeyBiryukov, pento, mikejolley, iandunn, hellofromTonya, Cybr, petitphp. Fixes #42061. git-svn-id: https://develop.svn.wordpress.org/trunk@57312 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -598,6 +598,10 @@ function wp_debug_mode() {
|
||||
error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR );
|
||||
}
|
||||
|
||||
/*
|
||||
* The 'REST_REQUEST' check here is optimistic as the constant is most
|
||||
* likely not set at this point even if it is in fact a REST request.
|
||||
*/
|
||||
if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || defined( 'MS_FILES_REQUEST' )
|
||||
|| ( defined( 'WP_INSTALLING' ) && WP_INSTALLING )
|
||||
|| wp_doing_ajax() || wp_is_json_request()
|
||||
|
||||
Reference in New Issue
Block a user