diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 94be0399cb16f..874c2591e4995 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -4702,26 +4702,14 @@ function _mce_set_direction( $mce_init ) { * being made. It does not return true when a REST endpoint is hit as part of another request, e.g. for preloading a * REST response. See {@see wp_is_rest_endpoint()} for that purpose. * - * This function must not be called until the {@see 'parse_request'} action. + * This function should not be called until the {@see 'parse_request'} action, as the constant is only defined then, + * even for an actual REST request. * * @since 6.5.0 * * @return bool True if it's a WordPress REST API request, false otherwise. */ function wp_is_rest_request(): bool { - if ( ! defined( 'REST_REQUEST' ) && ! did_action( 'parse_request' ) ) { - _doing_it_wrong( - __FUNCTION__, - sprintf( - /* translators: %s: parse_request */ - __( 'Detecting whether the current request is a REST API request is not possible until the %s hook.' ), - 'parse_request' - ), - '6.5.0' - ); - return false; - } - return defined( 'REST_REQUEST' ) && REST_REQUEST; } diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 4bdc0734e084e..52d87f4a95475 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -3405,13 +3405,8 @@ function wp_is_rest_endpoint(): bool { /* @var WP_REST_Server $wp_rest_server */ global $wp_rest_server; - /* - * Check whether this is a standalone REST request. - * This check is not using the `wp_is_rest_request()` function as it may be called before the constant is actually - * available. Since this is only one way of determining whether a REST endpoint is being handled, there is no need - * to be as strict here as in the check for whether this is an actual standalone REST request. - */ - $is_rest_endpoint = defined( 'REST_REQUEST' ) && REST_REQUEST; + // Check whether this is a standalone REST request. + $is_rest_endpoint = wp_is_rest_request(); if ( ! $is_rest_endpoint ) { // Otherwise, check whether an internal REST request is currently being handled. $is_rest_endpoint = isset( $wp_rest_server )