WC_WCCOM_Site
in package
WC_WCCOM_Site Class
Main class for WooCommerce.com connected site.
Table of Contents
- AUTH_ERROR_FILTER_NAME = 'wccom_auth_error'
- authenticate_wccom() : int|WP_User|false
- Authenticate a WooCommerce.com request to the wccom-site REST API.
- authentication_fallback() : WP_Error|null|bool
- Authenticate a WooCommerce.com request once WordPress has resolved its REST route.
- load() : mixed
- Load the WCCOM site class.
- register_rest_namespace() : array<string|int, mixed>
- Register wccom-site REST namespace.
- get_authorization_header() : string
- Get the authorization header.
- includes() : mixed
- Include support files.
- is_request_to_wccom_site_rest_api() : bool
- Check if this is a request to WCCOM Site REST API.
- verify_wccom_request() : bool
- Verify WooCommerce.com request from a given body and signature request.
Constants
AUTH_ERROR_FILTER_NAME
public
mixed
AUTH_ERROR_FILTER_NAME
= 'wccom_auth_error'
Methods
authenticate_wccom()
Authenticate a WooCommerce.com request to the wccom-site REST API.
public
static authenticate_wccom(int|false $user_id) : int|WP_User|false
Called from authentication_fallback() once WordPress has resolved the route. Returns the connected user, or false with the reason added to the wccom_auth_error filter.
Parameters
- $user_id : int|false
-
Current user id if already set; always false from the only caller.
Tags
Return values
int|WP_User|false —authentication_fallback()
Authenticate a WooCommerce.com request once WordPress has resolved its REST route.
public
static authentication_fallback(WP_Error|null|bool $error) : WP_Error|null|bool
Only requests WordPress dispatches to the wccom-site namespace are authenticated, whatever the URL looked like.
Parameters
- $error : WP_Error|null|bool
-
Error from another authentication handler, null if none.
Tags
Return values
WP_Error|null|bool —load()
Load the WCCOM site class.
public
static load() : mixed
Tags
Return values
mixed —register_rest_namespace()
Register wccom-site REST namespace.
public
static register_rest_namespace(array<string|int, mixed> $namespaces) : array<string|int, mixed>
Parameters
- $namespaces : array<string|int, mixed>
-
List of registered namespaces.
Tags
Return values
array<string|int, mixed> — Registered namespaces.get_authorization_header()
Get the authorization header.
protected
static get_authorization_header() : string
On certain systems and configurations, the Authorization header will be
stripped out by the server or PHP. Typically this is then used to
generate PHP_AUTH_USER/PHP_AUTH_PASS but not passed on. We use
getallheaders here to try and grab it out instead.
Tags
Return values
string — Authorization header if set.includes()
Include support files.
protected
static includes() : mixed
Tags
Return values
mixed —is_request_to_wccom_site_rest_api()
Check if this is a request to WCCOM Site REST API.
protected
static is_request_to_wccom_site_rest_api() : bool
Only the route WordPress resolved counts, so this is false until WordPress is dispatching the request as REST.
Tags
Return values
bool —verify_wccom_request()
Verify WooCommerce.com request from a given body and signature request.
protected
static verify_wccom_request(string $body, string $signature, string $access_token_secret) : bool
Only what follows the first "?" of the request URI is treated as its query string.
Parameters
- $body : string
-
Request body.
- $signature : string
-
Request signature found in X-Woo-Signature header.
- $access_token_secret : string
-
Access token secret for this site.
