Automattic\WooCommerce\Admin
PluginsHelper::get_plugin_path_from_slug
Get the path to the plugin file relative to the plugins directory from the plugin slug.
E.g. 'woocommerce' returns 'woocommerce/woocommerce.php'
Method of the class: PluginsHelper{}
No Hooks.
Returns
String|false. The plugin path or false if the plugin is not installed.
Usage
$result = PluginsHelper::get_plugin_path_from_slug( $slug );
- $slug(string) (required)
- Plugin slug to get path for.
PluginsHelper::get_plugin_path_from_slug() PluginsHelper::get plugin path from slug code WC 10.7.0
public static function get_plugin_path_from_slug( $slug ) {
$plugins = get_plugins();
if ( strstr( $slug, '/' ) ) {
// The slug is already a plugin path.
return $slug;
}
foreach ( $plugins as $plugin_path => $data ) {
$path_parts = explode( '/', $plugin_path );
if ( $path_parts[0] === $slug ) {
return $plugin_path;
}
}
return false;
}