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<string|int, mixed>
Wrapper for self::request().
load()  : mixed
Load
post()  : array<string|int, mixed>
Wrapper for self::request().
put()  : array<string|int, mixed>
Wrapper for self::request().
request()  : array<string|int, mixed>|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<string|int, mixed> $args = array() ]) : array<string|int, mixed>
Parameters
$endpoint : string

The helper API endpoint to request.

$args : array<string|int, mixed> = array()

Arguments passed to wp_remote_request().

Return values
array<string|int, mixed>The 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<string|int, mixed> $args = array() ]) : array<string|int, mixed>
Parameters
$endpoint : string

The helper API endpoint to request.

$args : array<string|int, mixed> = array()

Arguments passed to wp_remote_request().

Return values
array<string|int, mixed>The response object from wp_safe_remote_request().

put()

Wrapper for self::request().

public static put(string $endpoint[, array<string|int, mixed> $args = array() ]) : array<string|int, mixed>
Parameters
$endpoint : string

The helper API endpoint to request.

$args : array<string|int, mixed> = array()

Arguments passed to wp_remote_request().

Return values
array<string|int, mixed>The response object from wp_safe_remote_request().

request()

Perform an HTTP request to the Helper API.

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

The endpoint to request.

$args : array<string|int, mixed> = array()

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

Return values
array<string|int, mixed>|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 $query_string = '' ]) : string
Parameters
$endpoint : string

The endpoint to request.

$query_string : string = ''

Optional query string to append to the URL.

Return values
stringThe absolute endpoint URL.

_authenticate()

Adds authentication headers to an HTTP request.

private static _authenticate(string &$url, array<string|int, mixed> &$args) : bool
Parameters
$url : string

The request URI.

$args : array<string|int, mixed>

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

Return values
boolWere the headers added?