Automattic\WooCommerce\Internal\Utilities
LegacyRestApiStub::parse_legacy_rest_api_request()
Process an incoming request for the Legacy REST API.
If the dedicated Legacy REST API extension is installed and active, this method does nothing. Otherwise it returns a "The WooCommerce API is disabled on this site" error, unless the request contains a "wc-api" variable and the appropriate "woocommerce_api_*" hook is set.
Method of the class: LegacyRestApiStub{}
No Hooks.
Return
null
. Nothing (null).
Usage
$result = LegacyRestApiStub::parse_legacy_rest_api_request();
LegacyRestApiStub::parse_legacy_rest_api_request() LegacyRestApiStub::parse legacy rest api request code WC 9.3.3
private static function parse_legacy_rest_api_request() { global $wp; // The WC_Legacy_REST_API_Plugin class existence means that the Legacy REST API extension is installed and active. if ( class_exists( 'WC_Legacy_REST_API_Plugin' ) ) { return; } self::maybe_process_wc_api_query_var(); // phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput 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']; } if ( ! empty( $wp->query_vars['wc-api-version'] ) && ! empty( $wp->query_vars['wc-api-route'] ) ) { header( sprintf( 'Content-Type: %s; charset=%s', isset( $_GET['_jsonp'] ) ? 'application/javascript' : 'application/json', get_option( 'blog_charset' ) ) ); status_header( 404 ); echo wp_json_encode( array( 'errors' => array( 'code' => 'woocommerce_api_disabled', 'message' => 'The WooCommerce API is disabled on this site', ), ) ); exit; } // phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput }