PluginsProvider.php
75 lines
| 1 | <?php |
| 2 | /** |
| 3 | * A provider for getting access to plugin queries. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Admin\PluginsProvider; |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit; |
| 9 | |
| 10 | use Automattic\WooCommerce\Admin\PluginsProvider\PluginsProviderInterface; |
| 11 | use Automattic\WooCommerce\Admin\PluginsHelper; |
| 12 | |
| 13 | /** |
| 14 | * Plugins Provider. |
| 15 | * |
| 16 | * Uses the live PluginsHelper. |
| 17 | */ |
| 18 | class PluginsProvider implements PluginsProviderInterface { |
| 19 | /** |
| 20 | * The deactivated plugin slug. |
| 21 | * |
| 22 | * @var string |
| 23 | */ |
| 24 | private static $deactivated_plugin_slug = ''; |
| 25 | |
| 26 | /** |
| 27 | * Get an array of active plugin slugs. |
| 28 | * |
| 29 | * @return array |
| 30 | */ |
| 31 | public function get_active_plugin_slugs() { |
| 32 | return array_filter( |
| 33 | PluginsHelper::get_active_plugin_slugs(), |
| 34 | function( $p ) { |
| 35 | return $p !== self::$deactivated_plugin_slug; |
| 36 | } |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Set the deactivated plugin. This is needed because the deactivated_plugin |
| 42 | * hook happens before the option is updated which means that getting the |
| 43 | * active plugins includes the deactivated plugin. |
| 44 | * |
| 45 | * @param string $plugin_path The path to the plugin being deactivated. |
| 46 | */ |
| 47 | public static function set_deactivated_plugin( $plugin_path ) { |
| 48 | self::$deactivated_plugin_slug = explode( '/', $plugin_path )[0]; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Get plugin data. |
| 53 | * |
| 54 | * @param string $plugin Path to the plugin file relative to the plugins directory or the plugin directory name. |
| 55 | * |
| 56 | * @return array|false |
| 57 | */ |
| 58 | public function get_plugin_data( $plugin ) { |
| 59 | return PluginsHelper::get_plugin_data( $plugin ); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Get the path to the plugin file relative to the plugins directory from the plugin slug. |
| 64 | * |
| 65 | * E.g. 'woocommerce' returns 'woocommerce/woocommerce.php' |
| 66 | * |
| 67 | * @param string $slug Plugin slug to get path for. |
| 68 | * |
| 69 | * @return string|false |
| 70 | */ |
| 71 | public function get_plugin_path_from_slug( $slug ) { |
| 72 | return PluginsHelper::get_plugin_path_from_slug( $slug ); |
| 73 | } |
| 74 | } |
| 75 |