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.
- activate_helper_subscription() : bool
- Activate helper subscription.
- 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.
- deactivate_helper_subscription() : bool
- Deactivate a product subscription.
- 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_install_base_url() : string
- Get base URL for plugin auto installer.
- get_local_plugins() : array<string|int, mixed>
- Get locally installed plugins
- get_local_themes() : array<string|int, mixed>
- Get locally installed themes.
- 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_notices() : array<string|int, mixed>
- Retrieve notice for connected store.
- get_subscription() : array<string|int, mixed>|bool
- Get subscription data for a given product key.
- get_subscription_install_url() : string
- Get a subscriptions install URL.
- get_subscription_list_data() : array<string|int, mixed>
- Get the connected user's subscription list data. Here, we merge connected subscriptions with locally installed Woo plugins and themes. We also add in information about available updates.
- get_subscription_local_data() : array<string|int, mixed>
- Add local data to a subscription.
- 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.
- is_subscription_available() : bool
- Check if a subscription is available to use.
- is_subscription_installed() : bool
- Check if product relating to a subscription is installed.
- load() : mixed
- Loads the helper class, runs on init.
- log() : mixed
- Log a helper event.
- refresh_helper_subscriptions() : mixed
- Flush helper authentication cache.
- 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.
- _woo_core_update_available() : bool
- Whether WooCommerce has an update available.
- get_helper_redirect_url() : string
- Get helper redirect URL.
- helper_subscription_deactivate() : mixed
- Deactivate a product subscription.
- maybe_redirect_to_new_marketplace_installer() : mixed
- Maybe redirect to the new Marketplace installer.
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 —activate_helper_subscription()
Activate helper subscription.
public
static activate_helper_subscription(string $product_key) : bool
Parameters
- $product_key : string
-
Subscription product key.
Tags
Return values
bool — True if activated, false otherwise.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 —deactivate_helper_subscription()
Deactivate a product subscription.
public
static deactivate_helper_subscription(string $product_key) : bool
Parameters
- $product_key : string
-
Subscription product key.
Tags
Return values
bool — True if deactivated, false otherwise.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_install_base_url()
Get base URL for plugin auto installer.
public
static get_install_base_url() : string
Return values
string —get_local_plugins()
Get locally installed plugins
public
static get_local_plugins() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_local_themes()
Get locally installed themes.
public
static get_local_themes() : array<string|int, mixed>
Return values
array<string|int, mixed> —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_notices()
Retrieve notice for connected store.
public
static get_notices() : array<string|int, mixed>
Return values
array<string|int, mixed> — An array containing notice data.get_subscription()
Get subscription data for a given product key.
public
static get_subscription(string $product_key) : array<string|int, mixed>|bool
Parameters
- $product_key : string
-
Subscription product key.
Return values
array<string|int, mixed>|bool — The array containing sub data or false.get_subscription_install_url()
Get a subscriptions install URL.
public
static get_subscription_install_url(string $product_key, string $product_slug) : string
Parameters
- $product_key : string
-
Subscription product key.
- $product_slug : string
-
Subscription product slug.
Return values
string —get_subscription_list_data()
Get the connected user's subscription list data. Here, we merge connected subscriptions with locally installed Woo plugins and themes. We also add in information about available updates.
public
static get_subscription_list_data() : array<string|int, mixed>
Used by the My Subscriptions page.
Return values
array<string|int, mixed> —get_subscription_local_data()
Add local data to a subscription.
public
static get_subscription_local_data(array<string|int, mixed> $subscription) : array<string|int, mixed>
Parameters
- $subscription : array<string|int, mixed>
-
The subscription data.
Return values
array<string|int, mixed> — The subscription data with local data added.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 —is_subscription_available()
Check if a subscription is available to use.
public
static is_subscription_available(array<string|int, mixed> $subscription, array<string|int, mixed> $subscriptions) : bool
That is, is not already active and hasn't expired, and there are no other subscriptions for this product already active on this site.
Parameters
- $subscription : array<string|int, mixed>
-
The subscription we're checking.
- $subscriptions : array<string|int, mixed>
-
The list of all the user's subscriptions.
Return values
bool — True if multiple licenses exist, false otherwise.is_subscription_installed()
Check if product relating to a subscription is installed.
public
static is_subscription_installed(array<string|int, mixed> $subscription, array<string|int, mixed> $subscriptions) : bool
This method will return true if the product is installed, but will exclude subscriptions for the same product that are not in use. If a product is installed and inactive, this will ensure that one subscription is marked as installed.
Parameters
- $subscription : array<string|int, mixed>
-
The subscription we're checking.
- $subscriptions : array<string|int, mixed>
-
The list of all the user's subscriptions.
Return values
bool — True if installed, false otherwise.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 —refresh_helper_subscriptions()
Flush helper authentication cache.
public
static refresh_helper_subscriptions() : mixed
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 —_woo_core_update_available()
Whether WooCommerce has an update available.
private
static _woo_core_update_available() : bool
Return values
bool — True if a Woo core update is available.get_helper_redirect_url()
Get helper redirect URL.
private
static get_helper_redirect_url([array<string|int, mixed> $args = array() ]) : string
Parameters
- $args : array<string|int, mixed> = array()
-
Query args.
Return values
string —helper_subscription_deactivate()
Deactivate a product subscription.
private
static helper_subscription_deactivate() : mixed
Return values
mixed —maybe_redirect_to_new_marketplace_installer()
Maybe redirect to the new Marketplace installer.
private
static maybe_redirect_to_new_marketplace_installer() : mixed