Automattic\WooCommerce\Internal\Ucp

UcpDiscovery::maybe_render │ public │ WC 1.0

Send the discovery profile for /.well-known/ucp requests.

Метод класса: UcpDiscovery{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$UcpDiscovery = new UcpDiscovery();
$UcpDiscovery->maybe_render( $wp ): void;
$wp(WP) (обязательный)
Current WordPress environment instance.

Код UcpDiscovery::maybe_render() WC 11.3.0

public function maybe_render( \WP $wp ): void {
	// Check the matched rule, not only the query var: WP also fills public query vars from $_GET/$_POST.
	if ( self::RULE !== $wp->matched_rule || '1' !== ( $wp->query_vars[ self::QUERY_VAR ] ?? '' ) ) {
		return;
	}

	// phpcs:ignore WordPress.Security.ValidatedSanitizedInput
	if ( ! in_array( $_SERVER['REQUEST_METHOD'] ?? '', array( 'GET', 'HEAD' ), true ) ) {
		status_header( 405 );
		exit;
	}

	// UCP requires a publicly cacheable profile with a max-age of at least 60 seconds.
	if ( ! headers_sent() ) {
		header( 'Cache-Control: public, max-age=300' );
	}

	wp_send_json( $this->get_profile() );
}