WooCommerce Code Reference

PluginsHelper
in package

Class PluginsHelper

Table of Contents

DISMISS_CONNECT_NOTICE  = 'woo_connect_notice_dismiss'
Meta key for dismissing connected notice
DISMISS_DISCONNECT_NOTICE  = 'woo_disconnect_notice_dismiss'
Meta key for dismissing disconnected notice
DISMISS_EXPIRED_SUBS_NOTICE  = 'woo_subscription_expired_notice_dismiss'
Meta key for dismissing expired subscription notices.
DISMISS_EXPIRING_SUBS_NOTICE  = 'woo_subscription_expiring_notice_dismiss'
Meta key for dismissing expiring subscription notices
DISMISS_MISSING_SUBS_NOTICE  = 'woo_subscription_missing_notice_dismiss'
Meta key for dismissing missing subscription notices
WOO_ADD_PAYMENT_METHOD_URL  = 'https://woocommerce.com/my-account/add-payment-method/'
The URL for the WooCommerce.com add payment method page.
WOO_CART_PAGE_URL  = 'https://woocommerce.com/cart/'
The URL for the WooCommerce.com cart page.
WOO_SUBSCRIPTION_PAGE_URL  = 'https://woocommerce.com/my-account/my-subscriptions/'
The URL for the WooCommerce subscription page.
$subscription_usage_notices_already_shown  : bool
Subscription notices in Woo screens are shown in clear priority order, first expired, and if those don't exist, expiring, and finally if none of those exist, then missing. This keeps track of whether we can show the next set of notices.
activate_plugins()  : WP_Error|array<string|int, mixed>
Activate the requested plugins.
get_action_data()  : array<string|int, mixed>
Gets the plugin data for the first action.
get_activation_status()  : array<string|int, mixed>
Activation status.
get_active_plugin_slugs()  : array<string|int, mixed>
Get an array of active plugin slugs.
get_expired_subscription_notice()  : array<string|int, mixed>
Get formatted notice information for expired subscription.
get_expiring_subscription_notice()  : array<string|int, mixed>
Get formatted notice information for expiring subscription.
get_installation_status()  : array<string|int, mixed>
Installation status.
get_installed_plugin_slugs()  : array<string|int, mixed>
Get an array of installed plugin slugs.
get_installed_plugins_paths()  : array<string|int, mixed>
Get an array of installed plugins with their file paths as a key value pair.
get_missing_payment_method_notice()  : array<string|int, mixed>
Get the notice data for missing payment method.
get_missing_subscription_notice()  : array<string|int, mixed>
Get formatted notice information for missing subscription.
get_plugin_data()  : array<string|int, mixed>|false
Get plugin data.
get_plugin_path_from_slug()  : string|false
Get the path to the plugin file relative to the plugins directory from the plugin slug.
get_subscriptions_notice_data()  : array<string|int, mixed>
Construct the subscription notice data based on user subscriptions data.
get_wccom_connected_notice()  : string
Get the connected status notice message.
get_wccom_disconnected_notice()  : string
Get notice information when WCCOM connection is disconnected.
init()  : mixed
Initialize hooks.
install_and_activate_plugins_async_callback()  : bool
Callback registered by OnboardingPlugins::install_and_activate_async.
install_plugins()  : array<string|int, mixed>
Install an array of plugins.
is_plugin_active()  : bool
Checks if a plugin is active.
is_plugin_installed()  : bool
Checks if a plugin is installed.
maybe_enqueue_scripts_for_connect_notice()  : void
Enqueue scripts for connect notice in WooCommerce settings page.
maybe_enqueue_scripts_for_notices_in_plugins()  : void
Enqueue scripts for notices in plugin list page.
maybe_enqueue_scripts_for_subscription_notice()  : void
Enqueue scripts for woo subscription notice.
maybe_show_connect_notice_in_plugin_list()  : void
Show notices to connect to woocommerce.com for unconnected store in the plugin list.
maybe_show_expired_subscriptions_notice()  : void
Show notice about to expired subscription on WC settings page.
maybe_show_expiring_subscriptions_notice()  : void
Show notice about to expiring subscription on WC settings page.
schedule_activate_plugins()  : string
Schedule plugin activation.
schedule_install_plugins()  : string
Schedule plugin installation.
should_show_notice()  : bool
Determine whether a specific notice should be shown to the current user.

Constants

DISMISS_CONNECT_NOTICE

Meta key for dismissing connected notice

public mixed DISMISS_CONNECT_NOTICE = 'woo_connect_notice_dismiss'

DISMISS_DISCONNECT_NOTICE

Meta key for dismissing disconnected notice

public mixed DISMISS_DISCONNECT_NOTICE = 'woo_disconnect_notice_dismiss'

DISMISS_EXPIRED_SUBS_NOTICE

Meta key for dismissing expired subscription notices.

public mixed DISMISS_EXPIRED_SUBS_NOTICE = 'woo_subscription_expired_notice_dismiss'

DISMISS_EXPIRING_SUBS_NOTICE

Meta key for dismissing expiring subscription notices

public mixed DISMISS_EXPIRING_SUBS_NOTICE = 'woo_subscription_expiring_notice_dismiss'

DISMISS_MISSING_SUBS_NOTICE

Meta key for dismissing missing subscription notices

public mixed DISMISS_MISSING_SUBS_NOTICE = 'woo_subscription_missing_notice_dismiss'

WOO_ADD_PAYMENT_METHOD_URL

The URL for the WooCommerce.com add payment method page.

public mixed WOO_ADD_PAYMENT_METHOD_URL = 'https://woocommerce.com/my-account/add-payment-method/'

WOO_CART_PAGE_URL

The URL for the WooCommerce.com cart page.

public mixed WOO_CART_PAGE_URL = 'https://woocommerce.com/cart/'

WOO_SUBSCRIPTION_PAGE_URL

The URL for the WooCommerce subscription page.

public mixed WOO_SUBSCRIPTION_PAGE_URL = 'https://woocommerce.com/my-account/my-subscriptions/'

Properties

$subscription_usage_notices_already_shown

Subscription notices in Woo screens are shown in clear priority order, first expired, and if those don't exist, expiring, and finally if none of those exist, then missing. This keeps track of whether we can show the next set of notices.

public static bool $subscription_usage_notices_already_shown = false

Methods

activate_plugins()

Activate the requested plugins.

public static activate_plugins(array<string|int, mixed> $plugins[, PluginsInstallLogger|null $logger = null ]) : WP_Error|array<string|int, mixed>
Parameters
$plugins : array<string|int, mixed>

Plugins.

$logger : PluginsInstallLogger|null = null

Logger.

Return values
WP_Error|array<string|int, mixed>Plugin Status

get_action_data()

Gets the plugin data for the first action.

public static get_action_data(array<string|int, mixed> $actions) : array<string|int, mixed>
Parameters
$actions : array<string|int, mixed>

Array of AS actions.

Return values
array<string|int, mixed>Array of action data.

get_activation_status()

Activation status.

public static get_activation_status([int $job_id = null ]) : array<string|int, mixed>
Parameters
$job_id : int = null

Job ID.

Return values
array<string|int, mixed>Array of action data.

get_active_plugin_slugs()

Get an array of active plugin slugs.

public static get_active_plugin_slugs() : array<string|int, mixed>

The list will include both network active and site active plugins.

Return values
array<string|int, mixed>The list of active plugin slugs.

get_expired_subscription_notice()

Get formatted notice information for expired subscription.

public static get_expired_subscription_notice([bool $allowed_link = true ]) : array<string|int, mixed>
Parameters
$allowed_link : bool = true

whether the notice description should include a link.

Return values
array<string|int, mixed>notice information.

get_expiring_subscription_notice()

Get formatted notice information for expiring subscription.

public static get_expiring_subscription_notice([bool $allowed_link = true ]) : array<string|int, mixed>
Parameters
$allowed_link : bool = true

whether the notice description should include a link.

Return values
array<string|int, mixed>notice information.

get_installation_status()

Installation status.

public static get_installation_status([int $job_id = null ]) : array<string|int, mixed>
Parameters
$job_id : int = null

Job ID.

Return values
array<string|int, mixed>Job data.

get_installed_plugin_slugs()

Get an array of installed plugin slugs.

public static get_installed_plugin_slugs() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_installed_plugins_paths()

Get an array of installed plugins with their file paths as a key value pair.

public static get_installed_plugins_paths() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_missing_payment_method_notice()

Get the notice data for missing payment method.

public static get_missing_payment_method_notice([bool $allowed_link = true ][, int $total_expiring_subscriptions = 1 ]) : array<string|int, mixed>
Parameters
$allowed_link : bool = true

whether should show link on the notice or not.

$total_expiring_subscriptions : int = 1

total expiring subscriptions.

Return values
array<string|int, mixed>the notices data.

get_missing_subscription_notice()

Get formatted notice information for missing subscription.

public static get_missing_subscription_notice() : array<string|int, mixed>
Return values
array<string|int, mixed>notice information.

get_plugin_data()

Get plugin data.

public static get_plugin_data(string $plugin) : array<string|int, mixed>|false
Parameters
$plugin : string

Path to the plugin file relative to the plugins directory or the plugin directory name.

Return values
array<string|int, mixed>|false

get_plugin_path_from_slug()

Get the path to the plugin file relative to the plugins directory from the plugin slug.

public static get_plugin_path_from_slug(string $slug) : string|false

E.g. 'woocommerce' returns 'woocommerce/woocommerce.php'

Parameters
$slug : string

Plugin slug to get path for.

Return values
string|falseThe plugin path or false if the plugin is not installed.

get_subscriptions_notice_data()

Construct the subscription notice data based on user subscriptions data.

public static get_subscriptions_notice_data(array<string|int, mixed> $all_subs, array<string|int, mixed> $subs_to_show, int $total, array<string|int, mixed> $messages, string $type) : array<string|int, mixed>
Parameters
$all_subs : array<string|int, mixed>

all subscription data.

$subs_to_show : array<string|int, mixed>

filtered subscriptions as condition.

$total : int

total subscription count.

$messages : array<string|int, mixed>

message.

$type : string

type of notice, whether it is for expiring or expired subscription.

Return values
array<string|int, mixed>notice data to return. Contains type, parsed_message and product_id.

get_wccom_connected_notice()

Get the connected status notice message.

public static get_wccom_connected_notice(string $user_email) : string
Parameters
$user_email : string

the user email.

Return values
stringthe connected notice message.

get_wccom_disconnected_notice()

Get notice information when WCCOM connection is disconnected.

public static get_wccom_disconnected_notice() : string
Return values
stringdisconnect notice.

install_and_activate_plugins_async_callback()

Callback registered by OnboardingPlugins::install_and_activate_async.

public static install_and_activate_plugins_async_callback(array<string|int, mixed> $plugins, string $job_id[, string|null $source = null ]) : bool

It is used to call install_plugins and activate_plugins with a custom logger.

Parameters
$plugins : array<string|int, mixed>

A list of plugins to install.

$job_id : string

An unique job I.D.

$source : string|null = null

The source of the request.

Return values
bool

install_plugins()

Install an array of plugins.

public static install_plugins(array<string|int, mixed> $plugins[, PluginsInstallLogger|null $logger = null ][, string|null $source = null ]) : array<string|int, mixed>
Parameters
$plugins : array<string|int, mixed>

Plugins to install.

$logger : PluginsInstallLogger|null = null

an optional logger.

$source : string|null = null

place where the request is coming from.

Return values
array<string|int, mixed>

is_plugin_active()

Checks if a plugin is active.

public static is_plugin_active(string $plugin) : bool
Parameters
$plugin : string

Path to the plugin file relative to the plugins directory or the plugin directory name.

Return values
bool

is_plugin_installed()

Checks if a plugin is installed.

public static is_plugin_installed(string $plugin) : bool
Parameters
$plugin : string

Path to the plugin file relative to the plugins directory or the plugin directory name.

Return values
bool

maybe_enqueue_scripts_for_connect_notice()

Enqueue scripts for connect notice in WooCommerce settings page.

public static maybe_enqueue_scripts_for_connect_notice() : void
Return values
void

maybe_enqueue_scripts_for_notices_in_plugins()

Enqueue scripts for notices in plugin list page.

public static maybe_enqueue_scripts_for_notices_in_plugins() : void
Return values
void

maybe_enqueue_scripts_for_subscription_notice()

Enqueue scripts for woo subscription notice.

public static maybe_enqueue_scripts_for_subscription_notice() : void
Return values
void

maybe_show_connect_notice_in_plugin_list()

Show notices to connect to woocommerce.com for unconnected store in the plugin list.

public static maybe_show_connect_notice_in_plugin_list() : void
Return values
void

maybe_show_expired_subscriptions_notice()

Show notice about to expired subscription on WC settings page.

public static maybe_show_expired_subscriptions_notice() : void
Return values
void

maybe_show_expiring_subscriptions_notice()

Show notice about to expiring subscription on WC settings page.

public static maybe_show_expiring_subscriptions_notice() : void
Return values
void

schedule_activate_plugins()

Schedule plugin activation.

public static schedule_activate_plugins(array<string|int, mixed> $plugins) : string
Parameters
$plugins : array<string|int, mixed>

Plugins to activate.

Return values
stringJob ID.

schedule_install_plugins()

Schedule plugin installation.

public static schedule_install_plugins(array<string|int, mixed> $plugins) : string
Parameters
$plugins : array<string|int, mixed>

Plugins to install.

Return values
stringJob ID.

should_show_notice()

Determine whether a specific notice should be shown to the current user.

public static should_show_notice(string $dismiss_notice_meta[, bool $show_after_one_month = true ]) : bool
Parameters
$dismiss_notice_meta : string

User meta that includes the timestamp when a store notice was dismissed.

$show_after_one_month : bool = true

Show the notices dismissed earlier than one month.

Return values
boolTrue if the notice should be shown, false otherwise.