WC_Helper
in package
WC_Helper Class
The main entry-point for all things related to the Helper.
Table of Contents
- $log : mixed
- A log object returned by wc_get_logger().
- _flush_authentication_cache() : mixed
- Flush auth cache.
- _flush_subscriptions_cache() : mixed
- Flush subscriptions cache.
- _sort_by_name() : int
- Sort subscriptions by the Name.
- _sort_by_product_name() : int
- Sort subscriptions by the product_name.
- activated_plugin() : mixed
- Runs when any plugin is activated.
- add_utm_params_to_url_for_subscription_link() : string
- Add tracking parameters to buttons (Renew, Purchase, etc.) on subscriptions page
- admin_enqueue_scripts() : mixed
- Enqueue admin scripts and styles.
- admin_notices() : mixed
- Various Helper-related admin notices.
- connect_with_password() : void|WP_Error
- Allows to connect with WCCOM using application password. used it to connect via CLI
- current_screen() : mixed
- Various early-phase actions with possible redirects.
- deactivated_plugin() : mixed
- Runs when any plugin is deactivated.
- disconnect() : void
- Handles WC Helper disconnect tasks.
- get_current_filter() : string
- Get current filter.
- get_filters() : array<string|int, mixed>
- Get available subscriptions filters.
- get_filters_counts() : array<string|int, mixed>
- Get counts data for the filters array.
- get_local_woo_plugins() : mixed
- Obtain a list of data about locally installed Woo extensions.
- get_local_woo_themes() : mixed
- Get locally installed Woo themes.
- get_subscriptions() : array<string|int, mixed>
- Get the connected user's subscriptions.
- get_view_filename() : string
- Get an absolute path to the requested helper view.
- has_product_subscription() : bool
- Checks whether current site has product subscription of a given ID.
- is_site_connected() : bool
- Checks if `access_token` exists in `auth` option.
- load() : mixed
- Loads the helper class, runs on init.
- log() : mixed
- Log a helper event.
- render_helper_output() : mixed
- Render the helper section content based on context.
- update_auth_option() : void
- Updates auth options and flushes cache
- includes() : mixed
- Include supporting helper classes.
- _filter() : mixed
- Filter an array of subscriptions by $filter.
- _flush_updates_cache() : mixed
- Flush updates cache.
- _get_extensions_update_notice() : string|null
- Get an update notice if one or more Woo extensions has an update available.
- _get_local_from_product_id() : array<string|int, mixed>|bool
- Get a local plugin/theme entry from product_id.
- _get_return_notices() : array<string|int, mixed>
- Various success/error notices.
- _get_subscriptions_from_product_id() : array<string|int, mixed>|bool
- Get a subscription entry from product_id. If multiple subscriptions are found with the same product id and $single is set to true, will return the first one in the list, so you can use this method to get things like extension name, version, etc.
- _helper_auth_connect() : mixed
- Initiate a new OAuth connection.
- _helper_auth_disconnect() : mixed
- Disconnect from WooCommerce.com, clear OAuth tokens.
- _helper_auth_refresh() : mixed
- User hit the Refresh button, clear all caches.
- _helper_auth_return() : mixed
- Return from WooCommerce.com OAuth flow.
- _helper_plugin_deactivate() : mixed
- Deactivate a plugin.
- _helper_subscription_activate() : mixed
- Active a product subscription.
- _helper_subscription_deactivate() : mixed
- Deactivate a product subscription.
- _woo_core_update_available() : bool
- Whether WooCommerce has an update available.
Properties
$log
A log object returned by wc_get_logger().
public
static mixed
$log
Methods
_flush_authentication_cache()
Flush auth cache.
public
static _flush_authentication_cache() : mixed
Return values
mixed —_flush_subscriptions_cache()
Flush subscriptions cache.
public
static _flush_subscriptions_cache() : mixed
Return values
mixed —_sort_by_name()
Sort subscriptions by the Name.
public
static _sort_by_name(array<string|int, mixed> $a, array<string|int, mixed> $b) : int
Parameters
- $a : array<string|int, mixed>
-
Product array.
- $b : array<string|int, mixed>
-
Product array.
Return values
int —_sort_by_product_name()
Sort subscriptions by the product_name.
public
static _sort_by_product_name(array<string|int, mixed> $a, array<string|int, mixed> $b) : int
Parameters
- $a : array<string|int, mixed>
-
Subscription array.
- $b : array<string|int, mixed>
-
Subscription array.
Return values
int —activated_plugin()
Runs when any plugin is activated.
public
static activated_plugin(string $filename) : mixed
Depending on the activated plugin attempts to look through available subscriptions and auto-activate one if possible, so the user does not need to visit the Helper UI at all after installing a new extension.
Parameters
- $filename : string
-
The filename of the activated plugin.
Return values
mixed —add_utm_params_to_url_for_subscription_link()
Add tracking parameters to buttons (Renew, Purchase, etc.) on subscriptions page
public
static add_utm_params_to_url_for_subscription_link(string $url, string $utm_content) : string
Parameters
- $url : string
-
URL to product page or to https://woocommerce.com/my-account/my-subscriptions/
- $utm_content : string
-
value of utm_content query parameter used for tracking
Return values
string — URL including utm parameters for trackingadmin_enqueue_scripts()
Enqueue admin scripts and styles.
public
static admin_enqueue_scripts() : mixed
Return values
mixed —admin_notices()
Various Helper-related admin notices.
public
static admin_notices() : mixed
Return values
mixed —connect_with_password()
Allows to connect with WCCOM using application password. used it to connect via CLI
public
static connect_with_password(string $password) : void|WP_Error
Parameters
- $password : string
-
The application password.
Return values
void|WP_Error —current_screen()
Various early-phase actions with possible redirects.
public
static current_screen(object $screen) : mixed
Parameters
- $screen : object
-
WP screen object.
Return values
mixed —deactivated_plugin()
Runs when any plugin is deactivated.
public
static deactivated_plugin(string $filename) : mixed
When a user deactivates a plugin, attempt to deactivate any subscriptions associated with the extension.
Parameters
- $filename : string
-
The filename of the deactivated plugin.
Return values
mixed —disconnect()
Handles WC Helper disconnect tasks.
public
static disconnect() : void
Return values
void —get_current_filter()
Get current filter.
public
static get_current_filter() : string
Return values
string — The current filter.get_filters()
Get available subscriptions filters.
public
static get_filters() : array<string|int, mixed>
Return values
array<string|int, mixed> — An array of filter keys and labels.get_filters_counts()
Get counts data for the filters array.
public
static get_filters_counts([array<string|int, mixed> $subscriptions = null ]) : array<string|int, mixed>
Parameters
- $subscriptions : array<string|int, mixed> = null
-
The array of all available subscriptions.
Return values
array<string|int, mixed> — Filter counts (filter => count).get_local_woo_plugins()
Obtain a list of data about locally installed Woo extensions.
public
static get_local_woo_plugins() : mixed
Return values
mixed —get_local_woo_themes()
Get locally installed Woo themes.
public
static get_local_woo_themes() : mixed
Return values
mixed —get_subscriptions()
Get the connected user's subscriptions.
public
static get_subscriptions() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_view_filename()
Get an absolute path to the requested helper view.
public
static get_view_filename(string $view) : string
Parameters
- $view : string
-
The requested view file.
Return values
string — The absolute path to the view file.has_product_subscription()
Checks whether current site has product subscription of a given ID.
public
static has_product_subscription(int $product_id) : bool
Parameters
- $product_id : int
-
The product id.
Tags
Return values
bool — Returns true if product subscription exists, false otherwise.is_site_connected()
Checks if `access_token` exists in `auth` option.
public
static is_site_connected() : bool
Return values
bool —load()
Loads the helper class, runs on init.
public
static load() : mixed
Return values
mixed —log()
Log a helper event.
public
static log(string $message[, string $level = 'info' ]) : mixed
Parameters
- $message : string
-
Log message.
- $level : string = 'info'
-
Optional, defaults to info, valid levels: emergency|alert|critical|error|warning|notice|info|debug.
Return values
mixed —render_helper_output()
Render the helper section content based on context.
public
static render_helper_output() : mixed
Return values
mixed —update_auth_option()
Updates auth options and flushes cache
public
static update_auth_option(string $access_token, string $access_token_secret, int $site_id) : void
Parameters
- $access_token : string
-
The access token.
- $access_token_secret : string
-
The secret access token.
- $site_id : int
-
The site id returned by the API.
Return values
void —includes()
Include supporting helper classes.
protected
static includes() : mixed
Return values
mixed —_filter()
Filter an array of subscriptions by $filter.
private
static _filter(array<string|int, mixed> &$subscriptions, string $filter) : mixed
Parameters
- $subscriptions : array<string|int, mixed>
-
The subscriptions array, passed by ref.
- $filter : string
-
The filter.
Return values
mixed —_flush_updates_cache()
Flush updates cache.
private
static _flush_updates_cache() : mixed
Return values
mixed —_get_extensions_update_notice()
Get an update notice if one or more Woo extensions has an update available.
private
static _get_extensions_update_notice() : string|null
Return values
string|null — The update notice or null if everything is up to date._get_local_from_product_id()
Get a local plugin/theme entry from product_id.
private
static _get_local_from_product_id(int $product_id) : array<string|int, mixed>|bool
Parameters
- $product_id : int
-
The product id.
Return values
array<string|int, mixed>|bool — The array containing the local plugin/theme data or false._get_return_notices()
Various success/error notices.
private
static _get_return_notices() : array<string|int, mixed>
Runs during admin page render, so no headers/redirects here.
Return values
array<string|int, mixed> — Array pairs of message/type strings with notices._get_subscriptions_from_product_id()
Get a subscription entry from product_id. If multiple subscriptions are found with the same product id and $single is set to true, will return the first one in the list, so you can use this method to get things like extension name, version, etc.
private
static _get_subscriptions_from_product_id(int $product_id[, bool $single = true ]) : array<string|int, mixed>|bool
Parameters
- $product_id : int
-
The product id.
- $single : bool = true
-
Whether to return a single subscription or all matching a product id.
Return values
array<string|int, mixed>|bool — The array containing sub data or false._helper_auth_connect()
Initiate a new OAuth connection.
private
static _helper_auth_connect() : mixed
Return values
mixed —_helper_auth_disconnect()
Disconnect from WooCommerce.com, clear OAuth tokens.
private
static _helper_auth_disconnect() : mixed
Return values
mixed —_helper_auth_refresh()
User hit the Refresh button, clear all caches.
private
static _helper_auth_refresh() : mixed
Return values
mixed —_helper_auth_return()
Return from WooCommerce.com OAuth flow.
private
static _helper_auth_return() : mixed
Return values
mixed —_helper_plugin_deactivate()
Deactivate a plugin.
private
static _helper_plugin_deactivate() : mixed
Return values
mixed —_helper_subscription_activate()
Active a product subscription.
private
static _helper_subscription_activate() : mixed
Return values
mixed —_helper_subscription_deactivate()
Deactivate a product subscription.
private
static _helper_subscription_deactivate() : mixed
Return values
mixed —_woo_core_update_available()
Whether WooCommerce has an update available.
private
static _woo_core_update_available() : bool