PluginUtil
in package
A class of utilities for dealing with plugins.
Table of Contents
- $plugins_excluded_from_compatibility_ui : array<string|int, string>
- List of plugins excluded from feature compatibility warnings in UI.
- $proxy : LegacyProxy
- The LegacyProxy instance to use.
- $woocommerce_aware_active_plugins : null|array<string|int, mixed>
- The cached list of enabled WooCommerce aware plugin ids.
- $woocommerce_aware_plugins : null|array<string|int, mixed>
- The cached list of WooCommerce aware plugin ids.
- __construct() : mixed
- Creates a new instance of the class.
- generate_incompatible_plugin_feature_warning() : string
- Utility method to generate warning string for incompatible features based on active plugins.
- get_all_active_valid_plugins() : array<string|int, string>
- Wrapper for WP's private `wp_get_active_and_valid_plugins` and `wp_get_active_network_plugins` functions.
- get_items_considered_incompatible() : array<string|int, mixed>
- Filter plugin/feature compatibility info, returning the names of the plugins/features that are considered incompatible.
- get_plugin_name() : string
- Get the printable name of a plugin.
- get_plugins_excluded_from_compatibility_ui() : array<string|int, string>
- Get the names of the plugins that are excluded from the feature compatibility UI.
- get_woocommerce_aware_plugins() : array<string|int, string>
- Get a list with the names of the WordPress plugins that are WooCommerce aware (they have a "WC tested up to" header).
- get_wp_plugin_id() : string|false
- Match plugin identifier passed as a parameter with the output from `get_plugins()`.
- is_woocommerce_aware_plugin() : bool
- Check if a plugin is WooCommerce aware.
Properties
$plugins_excluded_from_compatibility_ui
List of plugins excluded from feature compatibility warnings in UI.
private
array<string|int, string>
$plugins_excluded_from_compatibility_ui
$proxy
The LegacyProxy instance to use.
private
LegacyProxy
$proxy
$woocommerce_aware_active_plugins
The cached list of enabled WooCommerce aware plugin ids.
private
null|array<string|int, mixed>
$woocommerce_aware_active_plugins
= null
$woocommerce_aware_plugins
The cached list of WooCommerce aware plugin ids.
private
null|array<string|int, mixed>
$woocommerce_aware_plugins
= null
Methods
__construct()
Creates a new instance of the class.
public
__construct() : mixed
Return values
mixed —generate_incompatible_plugin_feature_warning()
Utility method to generate warning string for incompatible features based on active plugins.
public
generate_incompatible_plugin_feature_warning(string $feature_id, array<string|int, mixed> $plugin_feature_info) : string
Additionally, this method will manually print a warning message on the HPOS feature if both the Legacy REST API and HPOS are active.
Parameters
- $feature_id : string
-
Feature id.
- $plugin_feature_info : array<string|int, mixed>
-
Array of plugin feature info, as provided by FeaturesController->get_compatible_plugins_for_feature().
Return values
string — Warning string.get_all_active_valid_plugins()
Wrapper for WP's private `wp_get_active_and_valid_plugins` and `wp_get_active_network_plugins` functions.
public
get_all_active_valid_plugins() : array<string|int, string>
This combines the results of the two functions to get a list of all plugins that are active within a site. It's more useful than just retrieving the option values because it also validates that the plugin files exist. This wrapper is also a hedge against backward-incompatible changes since both of the WP methods are marked as being "@access private", so if need be we can update our methods here to preserve functionality.
Note that the doc block for wp_get_active_and_valid_plugins
says it returns "Array of paths to plugin files
relative to the plugins directory", but it actually returns absolute paths.
Return values
array<string|int, string> — Array of plugin basenames (paths relative to the plugin directory).get_items_considered_incompatible()
Filter plugin/feature compatibility info, returning the names of the plugins/features that are considered incompatible.
public
get_items_considered_incompatible(string $feature_id, array<string|int, mixed> $compatibility_info) : array<string|int, mixed>
"Uncertain" information will be included or not depending on the value of the value of the 'plugins_are_incompatible_by_default' flag in the feature definition (default is true).
Parameters
- $feature_id : string
-
Feature id.
- $compatibility_info : array<string|int, mixed>
-
Array containing "compatible', 'incompatible' and 'uncertain' keys.
Return values
array<string|int, mixed> — Items in 'incompatible' and 'uncertain' if plugins are incompatible by default with the feature; only items in 'incompatible' otherwise.get_plugin_name()
Get the printable name of a plugin.
public
get_plugin_name(string $plugin_id) : string
Parameters
- $plugin_id : string
-
Plugin id (path/file.php).
Return values
string — Printable plugin name, or the plugin id itself if printable name is not available.get_plugins_excluded_from_compatibility_ui()
Get the names of the plugins that are excluded from the feature compatibility UI.
public
get_plugins_excluded_from_compatibility_ui() : array<string|int, string>
These plugins won't be considered as incompatible with any existing feature for the purposes of displaying compatibility warning in UI, even if they declare incompatibilities explicitly.
Return values
array<string|int, string> — Plugin names relative to the root plugins directory.get_woocommerce_aware_plugins()
Get a list with the names of the WordPress plugins that are WooCommerce aware (they have a "WC tested up to" header).
public
get_woocommerce_aware_plugins([bool $active_only = false ]) : array<string|int, string>
Parameters
- $active_only : bool = false
-
True to return only active plugins, false to return all the active plugins.
Return values
array<string|int, string> — A list of plugin ids (path/file.php).get_wp_plugin_id()
Match plugin identifier passed as a parameter with the output from `get_plugins()`.
public
get_wp_plugin_id(string $plugin_file) : string|false
Parameters
- $plugin_file : string
-
Plugin identifier, either 'my-plugin/my-plugin.php', or output from FILE.
Return values
string|false — Key from the array returned by `get_plugins` if matched. False if no match.is_woocommerce_aware_plugin()
Check if a plugin is WooCommerce aware.
public
is_woocommerce_aware_plugin(string|array<string|int, mixed> $plugin_file_or_data) : bool
Parameters
- $plugin_file_or_data : string|array<string|int, mixed>
-
Plugin id (path/file.php) or plugin data (as returned by get_plugins).