Addon
8 years ago
Admin
8 years ago
Column
8 years ago
Helper
8 years ago
ListScreen
8 years ago
Meta
8 years ago
Notice
8 years ago
Settings
8 years ago
ThirdParty
8 years ago
API.php
8 years ago
Addon.php
8 years ago
Addons.php
8 years ago
Admin.php
8 years ago
Autoloader.php
8 years ago
Collection.php
8 years ago
Column.php
8 years ago
Groups.php
8 years ago
Helper.php
8 years ago
ListScreen.php
8 years ago
ListScreenPost.php
8 years ago
PluginInformation.php
8 years ago
TableScreen.php
8 years ago
View.php
8 years ago
ViewInterface.php
8 years ago
PluginInformation.php
98 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | class AC_PluginInformation { |
| 8 | |
| 9 | /** |
| 10 | * @var string |
| 11 | */ |
| 12 | private $plugin_dirname; |
| 13 | |
| 14 | /** |
| 15 | * AC_Helper_Plugin constructor. |
| 16 | * |
| 17 | * @param string $plugin_dirname |
| 18 | */ |
| 19 | public function __construct( $plugin_dirname ) { |
| 20 | $this->plugin_dirname = sanitize_key( $plugin_dirname ); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * @return string |
| 25 | */ |
| 26 | public function get_dirname() { |
| 27 | return $this->plugin_dirname; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @return bool |
| 32 | */ |
| 33 | public function is_installed() { |
| 34 | return $this->get_plugin_info() ? true : false; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @return bool |
| 39 | */ |
| 40 | public function is_active() { |
| 41 | return is_plugin_active( $this->get_plugin_var( 'Basename' ) ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @return string|false Returns the plugin version if the plugin is installed, false otherwise |
| 46 | */ |
| 47 | public function get_version() { |
| 48 | return $this->get_plugin_var( 'Version' ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @return string Basename |
| 53 | */ |
| 54 | public function get_basename() { |
| 55 | return $this->get_plugin_var( 'Basename' ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @return string Name |
| 60 | */ |
| 61 | public function get_name() { |
| 62 | return $this->get_plugin_var( 'Name' ); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @return array|false |
| 67 | */ |
| 68 | public function get_plugin_info() { |
| 69 | $plugins = (array) get_plugins(); |
| 70 | |
| 71 | foreach ( $plugins as $basename => $info ) { |
| 72 | if ( $this->plugin_dirname === dirname( $basename ) ) { |
| 73 | $info['Basename'] = $basename; |
| 74 | |
| 75 | return $info; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * @param string $var |
| 84 | * |
| 85 | * @return string|false |
| 86 | */ |
| 87 | public function get_plugin_var( $var ) { |
| 88 | $info = $this->get_plugin_info(); |
| 89 | |
| 90 | if ( ! isset( $info[ $var ] ) ) { |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | return $info[ $var ]; |
| 95 | } |
| 96 | |
| 97 | } |
| 98 |