Automattic\WooCommerce\Utilities

PluginUtil::get_woocommerce_aware_plugins()publicWC 1.0

Get a list with the names of the WordPress plugins that are WooCommerce aware (they have a "WC tested up to" header).

Метод класса: PluginUtil{}

Хуков нет.

Возвращает

Строку[]. A list of plugin ids (path/file.php).

Использование

$PluginUtil = new PluginUtil();
$PluginUtil->get_woocommerce_aware_plugins( $active_only ): array;
$active_only(true|false)
True to return only active plugins, false to return all the active plugins.
По умолчанию: false

Код PluginUtil::get_woocommerce_aware_plugins() WC 9.3.3

public function get_woocommerce_aware_plugins( bool $active_only = false ): array {
	if ( is_null( $this->woocommerce_aware_plugins ) ) {
		// In case `get_plugins` was called much earlier in the request (before our headers could be injected), we
		// invalidate the plugin cache list.
		wp_cache_delete( 'plugins', 'plugins' );
		$all_plugins = $this->proxy->call_function( 'get_plugins' );

		$this->woocommerce_aware_plugins =
			array_keys(
				array_filter(
					$all_plugins,
					array( $this, 'is_woocommerce_aware_plugin' )
				)
			);

		$this->woocommerce_aware_active_plugins =
			array_values(
				array_filter(
					$this->woocommerce_aware_plugins,
					function ( $plugin_name ) {
						return $this->proxy->call_function( 'is_plugin_active', $plugin_name );
					}
				)
			);
	}

	return $active_only ? $this->woocommerce_aware_active_plugins : $this->woocommerce_aware_plugins;
}