Rest_Api::is_rest_api_blocked( bool $force = false )

Checks if our endpoints are accessible.


Parameters

$force

(bool) (Optional) Force the check, skipping timed option cache.

Default value: false


Top ↑

Return

(bool)


Top ↑

Source

File: src/Events/Admin/Notice/Rest_Api.php

	public function is_rest_api_blocked( bool $force = false ): bool {
		$cache_key     = 'events_is_rest_api_blocked';
		$cache_timeout = 48 * HOUR_IN_SECONDS;
		if ( ! $force && tec_timed_option()->exists( $cache_key, $force ) ) {
			$this->blocked_endpoint = tec_timed_option()->get( $cache_key, null, $force );

			return ! empty( $this->blocked_endpoint );
		}

		// Check multiple endpoints to determine if the REST API is blocked.
		$endpoints = $this->get_routes_to_check();
		foreach ( $endpoints as $endpoint ) {
			$response = wp_safe_remote_get( $endpoint, [ 'timeout' => 3 ] );
			if ( $this->is_response_blocked( $response ) ) {
				$this->blocked_endpoint = $endpoint;
				tec_timed_option()->set( $cache_key, $endpoint, $cache_timeout );

				return true;
			}
		}

		tec_timed_option()->set( $cache_key, false, $cache_timeout );

		return false;
	}

Top ↑

Changelog

Changelog
Version Description
6.5.0 Introduced.