WC_WCCOM_Site_Installer::get_plugin_info()public staticWC 3.9.0

Get plugin info

Method of the class: WC_WCCOM_Site_Installer{}

No Hooks.

Return

true|false|Array.

Usage

$result = WC_WCCOM_Site_Installer::get_plugin_info( $dir );
$dir(string) (required)
Directory name of the plugin.

Changelog

Since 3.9.0 Introduced.

WC_WCCOM_Site_Installer::get_plugin_info() code WC 9.4.2

public static function get_plugin_info( $dir ) {
	$plugin_folder = basename( $dir );

	if ( ! function_exists( 'get_plugins' ) ) {
		require_once ABSPATH . 'wp-admin/includes/plugin.php';
	}

	$plugins = get_plugins();

	$related_plugins = array_filter(
		$plugins,
		function( $key ) use ( $plugin_folder ) {
			return strpos( $key, $plugin_folder . '/' ) === 0;
		},
		ARRAY_FILTER_USE_KEY
	);

	if ( 1 === count( $related_plugins ) ) {
		$plugin_key  = array_keys( $related_plugins )[0];
		$plugin_data = $plugins[ $plugin_key ];
		return array(
			'name'    => $plugin_data['Name'],
			'version' => $plugin_data['Version'],
			'active'  => is_plugin_active( $plugin_key ),
		);
	}
	return false;
}