Changeset 57312
- Timestamp:
- 01/19/2024 05:37:05 PM (13 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-query.php
r57195 r57312 1028 1028 1029 1029 if ( ! ( $this->is_singular || $this->is_archive || $this->is_search || $this->is_feed 1030 || ( defined( 'REST_REQUEST' ) && REST_REQUEST&& $this->is_main_query() )1030 || ( wp_is_serving_rest_request() && $this->is_main_query() ) 1031 1031 || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_robots || $this->is_favicon ) ) { 1032 1032 $this->is_home = true; -
trunk/src/wp-includes/deprecated.php
r57196 r57312 5437 5437 5438 5438 // If in the editor, add webfonts defined in variations. 5439 if ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST) ) {5439 if ( is_admin() || wp_is_rest_endpoint() ) { 5440 5440 $variations = WP_Theme_JSON_Resolver::get_style_variations(); 5441 5441 foreach ( $variations as $variation ) { -
trunk/src/wp-includes/functions.php
r57279 r57312 3719 3719 */ 3720 3720 $callback = apply_filters( 'wp_die_json_handler', '_json_wp_die_handler' ); 3721 } elseif ( defined( 'REST_REQUEST' ) && REST_REQUEST&& wp_is_jsonp_request() ) {3721 } elseif ( wp_is_serving_rest_request() && wp_is_jsonp_request() ) { 3722 3722 /** 3723 3723 * Filters the callback for killing WordPress execution for JSONP REST requests. … … 4442 4442 */ 4443 4443 function wp_send_json( $response, $status_code = null, $flags = 0 ) { 4444 if ( defined( 'REST_REQUEST' ) && REST_REQUEST) {4444 if ( wp_is_serving_rest_request() ) { 4445 4445 _doing_it_wrong( 4446 4446 __FUNCTION__, … … 4698 4698 } 4699 4699 4700 /** 4701 * Determines whether WordPress is currently serving a REST API request. 4702 * 4703 * The function relies on the 'REST_REQUEST' global. As such, it only returns true when an actual REST _request_ is 4704 * being made. It does not return true when a REST endpoint is hit as part of another request, e.g. for preloading a 4705 * REST response. See {@see wp_is_rest_endpoint()} for that purpose. 4706 * 4707 * This function should not be called until the {@see 'parse_request'} action, as the constant is only defined then, 4708 * even for an actual REST request. 4709 * 4710 * @since 6.5.0 4711 * 4712 * @return bool True if it's a WordPress REST API request, false otherwise. 4713 */ 4714 function wp_is_serving_rest_request() { 4715 return defined( 'REST_REQUEST' ) && REST_REQUEST; 4716 } 4700 4717 4701 4718 /** -
trunk/src/wp-includes/load.php
r56804 r57312 599 599 } 600 600 601 /* 602 * The 'REST_REQUEST' check here is optimistic as the constant is most 603 * likely not set at this point even if it is in fact a REST request. 604 */ 601 605 if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || defined( 'MS_FILES_REQUEST' ) 602 606 || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) -
trunk/src/wp-includes/rest-api.php
r56834 r57312 210 210 */ 211 211 function rest_api_default_filters() { 212 if ( defined( 'REST_REQUEST' ) && REST_REQUEST) {212 if ( wp_is_serving_rest_request() ) { 213 213 // Deprecated reporting. 214 214 add_action( 'deprecated_function_run', 'rest_handle_deprecated_function', 10, 3 ); … … 3390 3390 return new WP_REST_Response( $data, $status ); 3391 3391 } 3392 3393 /** 3394 * Checks whether a REST API endpoint request is currently being handled. 3395 * 3396 * This may be a standalone REST API request, or an internal request dispatched from within a regular page load. 3397 * 3398 * @since 6.5.0 3399 * 3400 * @global WP_REST_Server $wp_rest_server REST server instance. 3401 * 3402 * @return bool True if a REST endpoint request is currently being handled, false otherwise. 3403 */ 3404 function wp_is_rest_endpoint() { 3405 /* @var WP_REST_Server $wp_rest_server */ 3406 global $wp_rest_server; 3407 3408 // Check whether this is a standalone REST request. 3409 $is_rest_endpoint = wp_is_serving_rest_request(); 3410 if ( ! $is_rest_endpoint ) { 3411 // Otherwise, check whether an internal REST request is currently being handled. 3412 $is_rest_endpoint = isset( $wp_rest_server ) 3413 && $wp_rest_server->is_dispatching(); 3414 } 3415 3416 /** 3417 * Filters whether a REST endpoint request is currently being handled. 3418 * 3419 * This may be a standalone REST API request, or an internal request dispatched from within a regular page load. 3420 * 3421 * @since 6.5.0 3422 * 3423 * @param bool $is_request_endpoint Whether a REST endpoint request is currently being handled. 3424 */ 3425 return (bool) apply_filters( 'wp_is_rest_endpoint', $is_rest_endpoint ); 3426 } -
trunk/src/wp-includes/rest-api/class-wp-rest-server.php
r57147 r57312 87 87 */ 88 88 protected $embed_cache = array(); 89 90 /** 91 * Stores request objects that are currently being handled. 92 * 93 * @since 6.5.0 94 * @var array 95 */ 96 protected $dispatching_requests = array(); 89 97 90 98 /** … … 984 992 */ 985 993 public function dispatch( $request ) { 994 $this->dispatching_requests[] = $request; 995 986 996 /** 987 997 * Filters the pre-calculated result of a REST API dispatch request. … … 1009 1019 } 1010 1020 1021 array_pop( $this->dispatching_requests ); 1011 1022 return $result; 1012 1023 } … … 1016 1027 1017 1028 if ( is_wp_error( $matched ) ) { 1018 return $this->error_to_response( $matched ); 1029 $response = $this->error_to_response( $matched ); 1030 array_pop( $this->dispatching_requests ); 1031 return $response; 1019 1032 } 1020 1033 … … 1041 1054 } 1042 1055 1043 return $this->respond_to_request( $request, $route, $handler, $error ); 1056 $response = $this->respond_to_request( $request, $route, $handler, $error ); 1057 array_pop( $this->dispatching_requests ); 1058 return $response; 1059 } 1060 1061 /** 1062 * Returns whether the REST server is currently dispatching / responding to a request. 1063 * 1064 * This may be a standalone REST API request, or an internal request dispatched from within a regular page load. 1065 * 1066 * @since 6.5.0 1067 * 1068 * @return bool Whether the REST server is currently handling a request. 1069 */ 1070 public function is_dispatching() { 1071 return (bool) $this->dispatching_requests; 1044 1072 } 1045 1073 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
r56586 r57312 202 202 wp_after_insert_post( $attachment, false, null ); 203 203 204 if ( defined( 'REST_REQUEST' ) && REST_REQUEST) {204 if ( wp_is_serving_rest_request() ) { 205 205 /* 206 206 * Set a custom header with the attachment_id. … … 631 631 } 632 632 633 if ( defined( 'REST_REQUEST' ) && REST_REQUEST) {633 if ( wp_is_serving_rest_request() ) { 634 634 /* 635 635 * Set a custom header with the attachment_id. -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php
r53455 r57312 129 129 * @since 5.9.0 130 130 * 131 * @param WP_REST_R EQUEST$request Full details about the request.131 * @param WP_REST_Request $request Full details about the request. 132 132 * @return WP_REST_Response|WP_Error The parsed details as a response object. WP_Error if there are errors. 133 133 */ -
trunk/src/wp-includes/script-loader.php
r57204 r57312 2587 2587 */ 2588 2588 function wp_should_load_separate_core_block_assets() { 2589 if ( is_admin() || is_feed() || ( defined( 'REST_REQUEST' ) && REST_REQUEST) ) {2589 if ( is_admin() || is_feed() || wp_is_rest_endpoint() ) { 2590 2590 return false; 2591 2591 } -
trunk/src/wp-includes/user.php
r57226 r57312 334 334 } 335 335 336 // The 'REST_REQUEST' check here may happen too early for the constant to be available. 336 337 $is_api_request = ( ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ); 337 338
Note: See TracChangeset
for help on using the changeset viewer.