Admin
5 years ago
Ajax
5 years ago
Asset
5 years ago
Autoloader
5 years ago
Capabilities
5 years ago
Check
5 years ago
Column
5 years ago
ColumnRepository
5 years ago
Controller
5 years ago
Deprecated
5 years ago
Exception
5 years ago
Form
5 years ago
Helper
5 years ago
Integration
5 years ago
ListScreen
5 years ago
ListScreenRepository
5 years ago
ListTable
5 years ago
Message
5 years ago
Meta
5 years ago
Plugin
5 years ago
Preferences
5 years ago
Promo
5 years ago
Relation
5 years ago
Request
5 years ago
Response
5 years ago
Sanitize
5 years ago
Screen
5 years ago
Settings
5 years ago
Storage
5 years ago
Table
5 years ago
ThirdParty
5 years ago
Transient
5 years ago
Type
5 years ago
Addon.php
5 years ago
AdminColumns.php
5 years ago
AdminFactoryInterface.php
5 years ago
ApplyFilter.php
5 years ago
ArrayIterator.php
5 years ago
Autoloader.php
5 years ago
Builder.php
5 years ago
Capabilities.php
5 years ago
Collection.php
5 years ago
Column.php
5 years ago
ColumnGroups.php
5 years ago
ColumnRepository.php
5 years ago
Config.php
5 years ago
DefaultColumnsRepository.php
5 years ago
Dependencies.php
5 years ago
EncodedListScreenData.php
5 years ago
EncodedListScreenDataFactory.php
5 years ago
Expirable.php
5 years ago
Groups.php
5 years ago
Helper.php
5 years ago
Installer.php
5 years ago
Integration.php
5 years ago
Integrations.php
5 years ago
ListScreen.php
5 years ago
ListScreenCollection.php
5 years ago
ListScreenFactory.php
5 years ago
ListScreenGroups.php
5 years ago
ListScreenPost.php
5 years ago
ListScreenRepository.php
5 years ago
ListScreenRepositoryWritable.php
5 years ago
ListScreenTypes.php
5 years ago
ListScreenWP.php
5 years ago
ListScreens.php
5 years ago
ListTable.php
5 years ago
ListTableFactory.php
5 years ago
Message.php
5 years ago
MetaType.php
5 years ago
Middleware.php
5 years ago
NoticeChecks.php
5 years ago
OpCacheInvalidateTrait.php
5 years ago
PermissionChecker.php
5 years ago
Plugin.php
5 years ago
PluginActionLinks.php
5 years ago
PluginInformation.php
5 years ago
Preferences.php
5 years ago
Promo.php
5 years ago
PromoCollection.php
5 years ago
Registrable.php
5 years ago
Relation.php
5 years ago
Renderable.php
5 years ago
Request.php
5 years ago
Sanitize.php
5 years ago
Screen.php
5 years ago
ScreenController.php
5 years ago
Transient.php
5 years ago
TypedArrayIterator.php
5 years ago
View.php
5 years ago
WpListTableFactory.php
5 years ago
PluginInformation.php
119 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC; |
| 4 | |
| 5 | class PluginInformation { |
| 6 | |
| 7 | /** |
| 8 | * @var string |
| 9 | */ |
| 10 | private $basename; |
| 11 | |
| 12 | public function __construct( $basename ) { |
| 13 | $this->basename = $basename; |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * @return string |
| 18 | */ |
| 19 | public function get_dirname() { |
| 20 | return dirname( $this->basename ); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * @return bool |
| 25 | */ |
| 26 | public function is_installed() { |
| 27 | return null !== $this->get_plugin_info(); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @return bool |
| 32 | */ |
| 33 | public function is_active() { |
| 34 | return is_plugin_active( $this->basename ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @return bool |
| 39 | */ |
| 40 | public function is_network_active() { |
| 41 | return is_plugin_active_for_network( $this->basename ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @return string|null |
| 46 | */ |
| 47 | public function get_version() { |
| 48 | return $this->get_plugin_var( 'Version' ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @return string |
| 53 | */ |
| 54 | public function get_basename() { |
| 55 | return $this->basename; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @return string |
| 60 | */ |
| 61 | public function get_name() { |
| 62 | return $this->get_plugin_var( 'Name' ); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @return array|null |
| 67 | */ |
| 68 | private function get_plugin_info() { |
| 69 | $plugins = (array) get_plugins(); |
| 70 | |
| 71 | if ( ! array_key_exists( $this->basename, $plugins ) ) { |
| 72 | return null; |
| 73 | } |
| 74 | |
| 75 | return $plugins[ $this->basename ]; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @param string $var |
| 80 | * |
| 81 | * @return string|null |
| 82 | */ |
| 83 | private function get_plugin_var( $var ) { |
| 84 | $info = $this->get_plugin_info(); |
| 85 | |
| 86 | if ( ! $info || ! isset( $info[ $var ] ) ) { |
| 87 | return null; |
| 88 | } |
| 89 | |
| 90 | return $info[ $var ]; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @param string $action 'activate' or 'deactivate' |
| 95 | * @param string $basename |
| 96 | * |
| 97 | * @return string |
| 98 | */ |
| 99 | public function get_plugin_action_url( $action ) { |
| 100 | return add_query_arg( [ |
| 101 | 'action' => $action, |
| 102 | 'plugin' => $this->basename, |
| 103 | ], wp_nonce_url( admin_url( 'plugins.php' ), $action . '-plugin_' . $this->basename ) ); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @param string $action 'activate' or 'deactivate' |
| 108 | * @param string $basename |
| 109 | * |
| 110 | * @return string |
| 111 | */ |
| 112 | public function get_plugin_network_action_url( $action ) { |
| 113 | return add_query_arg( [ |
| 114 | 'action' => $action, |
| 115 | 'plugin' => $this->basename, |
| 116 | ], wp_nonce_url( network_admin_url( 'plugins.php' ), $action . '-plugin_' . $this->basename ) ); |
| 117 | } |
| 118 | |
| 119 | } |