WC_Helper_API::request()public staticWC 1.0

Perform an HTTP request to the Helper API.

Method of the class: WC_Helper_API{}

Hooks from the method

Return

Array|WP_Error. The response from wp_safe_remote_request()

Usage

$result = WC_Helper_API::request( $endpoint, $args );
$endpoint(string) (required)
The endpoint to request.
$args(array)
Additional data for the request. Set authenticated to a truthy value to enable auth.
Default: array()

WC_Helper_API::request() code WC 8.9.0

public static function request( $endpoint, $args = array() ) {
	if ( ! isset( $args['query_string'] ) ) {
		$args['query_string'] = '';
	}
	$url = self::url( $endpoint, $args['query_string'] );

	if ( ! empty( $args['authenticated'] ) ) {
		if ( ! self::_authenticate( $url, $args ) ) {
			return new WP_Error( 'authentication', 'Authentication failed.' );
		}
	}

	if ( ! isset( $args['user-agent'] ) ) {
		$args['user-agent'] = 'WooCommerce/' . WC()->version . '; ' . get_bloginfo( 'url' );
	}

	/**
	 * Allow developers to filter the request args passed to wp_safe_remote_request().
	 * Useful to remove sslverify when working on a local api dev environment.
	 */
	$args = apply_filters( 'woocommerce_helper_api_request_args', $args, $endpoint );

	// TODO: Check response signatures on certain endpoints.
	return wp_safe_remote_request( $url, $args );
}