Automattic\WooCommerce\Admin

PluginsHelper::get_active_plugin_slugspublic staticWC 1.0

Get an array of active plugin slugs.

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

Method of the class: PluginsHelper{}

No Hooks.

Returns

Array. The list of active plugin slugs.

Usage

$result = PluginsHelper::get_active_plugin_slugs();

PluginsHelper::get_active_plugin_slugs() code WC 10.3.5

public static function get_active_plugin_slugs() {
	return array_unique(
		array_map(
			function ( $absolute_path ) {
				// Make the path relative to the plugins directory.
				$plugin_path = str_replace( WP_PLUGIN_DIR . '/', '', $absolute_path );

				// Split the path to get the plugin slug (aka the directory name).
				$path_parts = explode( '/', $plugin_path );

				return $path_parts[0];
			},
			// Use this method as it is the most bulletproof way to get the active plugins.
			wc_get_container()->get( PluginUtil::class )->get_all_active_valid_plugins()
		)
	);
}