WordPress at Your Fingertips
function is not described

WC_Legacy_API::handle_rest_api_requests() public WC 2.2

Deprecated from version 2.6.0. It is no longer supported and can be removed in future releases. It is recommended to replace this function with the same one.

Handle REST API requests.

{} It's a method of the class: WC_Legacy_API{}

No Hooks.

Return

null. Nothing.

Usage

$WC_Legacy_API = new WC_Legacy_API();
$WC_Legacy_API->handle_rest_api_requests();

Changelog

Since 2.2 Introduced.
Deprecated 2.6.0

Code of WC_Legacy_API::handle_rest_api_requests() WC 5.6.0

public function handle_rest_api_requests() {
	global $wp;

	if ( ! empty( $_GET['wc-api-version'] ) ) {
		$wp->query_vars['wc-api-version'] = $_GET['wc-api-version'];
	}

	if ( ! empty( $_GET['wc-api-route'] ) ) {
		$wp->query_vars['wc-api-route'] = $_GET['wc-api-route'];
	}

	// REST API request.
	if ( ! empty( $wp->query_vars['wc-api-version'] ) && ! empty( $wp->query_vars['wc-api-route'] ) ) {

		wc_maybe_define_constant( 'WC_API_REQUEST', true );
		wc_maybe_define_constant( 'WC_API_REQUEST_VERSION', absint( $wp->query_vars['wc-api-version'] ) );

		// Legacy v1 API request.
		if ( 1 === WC_API_REQUEST_VERSION ) {
			$this->handle_v1_rest_api_request();
		} elseif ( 2 === WC_API_REQUEST_VERSION ) {
			$this->handle_v2_rest_api_request();
		} else {
			$this->includes();

			$this->server = new WC_API_Server( $wp->query_vars['wc-api-route'] );

			// load API resource classes.
			$this->register_resources( $this->server );

			// Fire off the request.
			$this->server->serve_request();
		}

		exit;
	}
}