wp_is_rest_endpoint(): bool

In this article

Checks whether a REST API endpoint request is currently being handled.

Description

This may be a standalone REST API request, or an internal request dispatched from within a regular page load.

Return

bool True if a REST endpoint request is currently being handled, false otherwise.

Source

	}

	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 ) {

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.