WooCommerce Code Reference

WC_Helper_API
in package

WC_Helper_API Class

Provides a communication interface with the WooCommerce.com Helper API.

Table of Contents

$api_base  : mixed
Base path for API routes.
get()  : array
Wrapper for self::request().
load()  : mixed
Load
post()  : array
Wrapper for self::request().
put()  : array
Wrapper for self::request().
request()  : array|WP_Error
Perform an HTTP request to the Helper API.
url()  : string
Using the API base, form a request URL from a given endpoint.
_authenticate()  : bool
Adds authentication headers to an HTTP request.

Properties

Methods

get()

Wrapper for self::request().

public static get(string $endpoint[, array $args = array() ]) : array
Parameters
$endpoint : string

The helper API endpoint to request.

$args : array = array()

Arguments passed to wp_remote_request().

Return values
arrayThe response object from wp_safe_remote_request().

load()

Load

public static load() : mixed

Allow devs to point the API base to a local API development or staging server. Note that sslverify will be turned off for the woocommerce.dev + WP_DEBUG combination. The URL can be changed on plugins_loaded before priority 10.

Return values
mixed

post()

Wrapper for self::request().

public static post(string $endpoint[, array $args = array() ]) : array
Parameters
$endpoint : string

The helper API endpoint to request.

$args : array = array()

Arguments passed to wp_remote_request().

Return values
arrayThe response object from wp_safe_remote_request().

put()

Wrapper for self::request().

public static put(string $endpoint[, array $args = array() ]) : array
Parameters
$endpoint : string

The helper API endpoint to request.

$args : array = array()

Arguments passed to wp_remote_request().

Return values
arrayThe response object from wp_safe_remote_request().

request()

Perform an HTTP request to the Helper API.

public static request(string $endpoint[, array $args = array() ]) : array|WP_Error
Parameters
$endpoint : string

The endpoint to request.

$args : array = array()

Additional data for the request. Set authenticated to a truthy value to enable auth.

Return values
array|WP_ErrorThe response from wp_safe_remote_request()

url()

Using the API base, form a request URL from a given endpoint.

public static url(string $endpoint) : string
Parameters
$endpoint : string

The endpoint to request.

Return values
stringThe absolute endpoint URL.

_authenticate()

Adds authentication headers to an HTTP request.

private static _authenticate(string &$url, array &$args) : bool
Parameters
$url : string

The request URI.

$args : array

By-ref, the args that will be passed to wp_remote_request().

Return values
boolWere the headers added?