summaryrefslogtreecommitdiffstats
path: root/wp-includes/rest-api.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--wp-includes/rest-api.php43
1 files changed, 41 insertions, 2 deletions
diff --git a/wp-includes/rest-api.php b/wp-includes/rest-api.php
index 61e324e..5bf4887 100644
--- a/wp-includes/rest-api.php
+++ b/wp-includes/rest-api.php
@@ -209,7 +209,7 @@ function rest_api_register_rewrites() {
* @since 4.4.0
*/
function rest_api_default_filters() {
- if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
+ if ( wp_is_serving_rest_request() ) {
// Deprecated reporting.
add_action( 'deprecated_function_run', 'rest_handle_deprecated_function', 10, 3 );
add_filter( 'deprecated_function_trigger_error', '__return_false' );
@@ -391,6 +391,10 @@ function create_initial_rest_routes() {
// Navigation Fallback.
$controller = new WP_REST_Navigation_Fallback_Controller();
$controller->register_routes();
+
+ // Font Collections.
+ $font_collections_controller = new WP_REST_Font_Collections_Controller();
+ $font_collections_controller->register_routes();
}
/**
@@ -876,7 +880,7 @@ function _rest_array_intersect_key_recursive( $array1, $array2 ) {
}
/**
- * Filters the REST API response to include only a white-listed set of response object fields.
+ * Filters the REST API response to include only an allow-listed set of response object fields.
*
* @since 4.8.0
*
@@ -3389,3 +3393,38 @@ function rest_convert_error_to_response( $error ) {
return new WP_REST_Response( $data, $status );
}
+
+/**
+ * Checks whether a REST API endpoint request is currently being handled.
+ *
+ * This may be a standalone REST API request, or an internal request dispatched from within a regular page load.
+ *
+ * @since 6.5.0
+ *
+ * @global WP_REST_Server $wp_rest_server REST server instance.
+ *
+ * @return bool True if a REST endpoint request is currently being handled, false otherwise.
+ */
+function wp_is_rest_endpoint() {
+ /* @var WP_REST_Server $wp_rest_server */
+ global $wp_rest_server;
+
+ // Check whether this is a standalone REST request.
+ $is_rest_endpoint = wp_is_serving_rest_request();
+ if ( ! $is_rest_endpoint ) {
+ // Otherwise, check whether an internal REST request is currently being handled.
+ $is_rest_endpoint = isset( $wp_rest_server )
+ && $wp_rest_server->is_dispatching();
+ }
+
+ /**
+ * Filters whether a REST endpoint request is currently being handled.
+ *
+ * This may be a standalone REST API request, or an internal request dispatched from within a regular page load.
+ *
+ * @since 6.5.0
+ *
+ * @param bool $is_request_endpoint Whether a REST endpoint request is currently being handled.
+ */
+ return (bool) apply_filters( 'wp_is_rest_endpoint', $is_rest_endpoint );
+}