Automattic\WooCommerce\Internal\Utilities
LegacyRestApiStub::maybe_process_wc_api_query_var()
Process a "wc-api" variable if present in the query, by triggering the appropriate hooks.
Method of the class: LegacyRestApiStub{}
Hooks from the method
Return
null
. Nothing (null).
Usage
$result = LegacyRestApiStub::maybe_process_wc_api_query_var();
LegacyRestApiStub::maybe_process_wc_api_query_var() LegacyRestApiStub::maybe process wc api query var code WC 9.3.3
private static function maybe_process_wc_api_query_var() { global $wp; // phpcs:disable WordPress.Security.NonceVerification.Recommended if ( ! empty( $_GET['wc-api'] ) ) { $wp->query_vars['wc-api'] = sanitize_key( wp_unslash( $_GET['wc-api'] ) ); } // phpcs:enable WordPress.Security.NonceVerification.Recommended // wc-api endpoint requests. if ( ! empty( $wp->query_vars['wc-api'] ) ) { // Buffer, we won't want any output here. ob_start(); // No cache headers. wc_nocache_headers(); // Clean the API request. $api_request = strtolower( wc_clean( $wp->query_vars['wc-api'] ) ); // Make sure gateways are available for request. WC()->payment_gateways(); // phpcs:disable WooCommerce.Commenting.CommentHooks.HookCommentWrongStyle // Trigger generic action before request hook. do_action( 'woocommerce_api_request', $api_request ); // Is there actually something hooked into this API request? If not trigger 400 - Bad request. status_header( has_action( 'woocommerce_api_' . $api_request ) ? 200 : 400 ); // Trigger an action which plugins can hook into to fulfill the request. do_action( 'woocommerce_api_' . $api_request ); // phpcs:enable WooCommerce.Commenting.CommentHooks.HookCommentWrongStyle // Done, clear buffer and exit. ob_end_clean(); die( '-1' ); } }