Automattic\WooCommerce\Api\Infrastructure

GraphQLControllerBase::is_debug_modeprivateWC 1.0

Check if debug mode is active.

Debug mode is gated on _debug=1 being set on the request: when absent, debug mode is off regardless of any other signal. When present, the principal opts in via a can_use_debug_mode(): bool method (principals that don't declare it are denied by default), and the decision is then passed through the woocommerce_graphql_can_use_debug_mode filter.

Fail-closed contract: the principal must be non-null (principal-resolution failures deny outright, before the filter is consulted), the principal method's return value is treated with === true, and any throw from either the principal method or the filter callback denies. The filter must likewise return strictly true to allow; any other value denies.

Method of the class: GraphQLControllerBase{}

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->is_debug_mode( ?object $principal, $request ): bool;
?object $principal(required)
.
$request(WP_REST_Request) (required)
The REST request.

GraphQLControllerBase::is_debug_mode() code WC 10.9.1

private function is_debug_mode( ?object $principal, \WP_REST_Request $request ): bool {
	if ( '1' !== $request->get_param( '_debug' ) ) {
		return false;
	}
	if ( is_null( $principal ) ) {
		return false;
	}

	try {
		$can_debug = method_exists( $principal, 'can_use_debug_mode' )
			&& true === $principal->can_use_debug_mode();

		/**
		 * Filters whether the current principal may activate GraphQL debug mode.
		 *
		 * Only invoked when the request carries `_debug=1` and a principal was
		 * resolved successfully, so the filter is not called on every GraphQL
		 * request. The filter receives the principal-derived decision (false
		 * when the principal doesn't declare `can_use_debug_mode()` or its
		 * `can_use_debug_mode()` doesn't return strictly `true`) and must
		 * return strictly `true` to grant access; any other return value denies.
		 *
		 * @since 10.9.0
		 *
		 * @internal
		 *
		 * @param bool             $can_debug Whether the principal can use debug mode, derived from `$principal->can_use_debug_mode()`.
		 * @param object           $principal The resolved principal.
		 * @param \WP_REST_Request $request   The REST request being processed.
		 */
		$can_debug = apply_filters( 'woocommerce_graphql_can_use_debug_mode', $can_debug, $principal, $request );
	} catch ( \Throwable $e ) {
		return false;
	}

	return true === $can_debug;
}