Skip to content

Commit

Permalink
Get rid of unnecessarily strict _doing_it_wrong().
Browse files Browse the repository at this point in the history
  • Loading branch information
felixarntz committed Nov 10, 2023
1 parent 63d9e57 commit e251d98
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
16 changes: 2 additions & 14 deletions src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 2 additions & 7 deletions src/wp-includes/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down

0 comments on commit e251d98

Please sign in to comment.