views
1 week ago
BlockSettings.php
1 week ago
Notice.php
1 week ago
PluginCompatibility.php
1 week ago
PluginCompatibilityChecker.php
1 week ago
PluginDetails.php
1 week ago
PluginDetails.php
94 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Class Plugin Details |
| 5 | * |
| 6 | * @package WPDesk\FS\Compatibility |
| 7 | */ |
| 8 | namespace FSVendor\WPDesk\FS\Compatibility; |
| 9 | |
| 10 | /** |
| 11 | * Class PluginDetails |
| 12 | * |
| 13 | * @package WPDesk\FS\Compatibility |
| 14 | */ |
| 15 | class PluginDetails |
| 16 | { |
| 17 | /** |
| 18 | * @var string . |
| 19 | */ |
| 20 | private $plugin_file; |
| 21 | /** |
| 22 | * @var string|null . |
| 23 | */ |
| 24 | private $version_constant_name; |
| 25 | /** |
| 26 | * @var string . |
| 27 | */ |
| 28 | private $required_version; |
| 29 | /** |
| 30 | * PluginChecker constructor. |
| 31 | * |
| 32 | * @param string $plugin_file . |
| 33 | * @param string $version_constant_name . |
| 34 | * @param string $required_version . |
| 35 | */ |
| 36 | public function __construct($plugin_file, $version_constant_name, $required_version) |
| 37 | { |
| 38 | $this->plugin_file = $plugin_file; |
| 39 | $this->version_constant_name = $version_constant_name; |
| 40 | $this->required_version = $required_version; |
| 41 | } |
| 42 | /** |
| 43 | * @return bool |
| 44 | */ |
| 45 | public function is_active() |
| 46 | { |
| 47 | return $this->is_plugin_activate($this->plugin_file); |
| 48 | } |
| 49 | /** |
| 50 | * @return string |
| 51 | */ |
| 52 | public function get_version() |
| 53 | { |
| 54 | return defined($this->version_constant_name) ? constant($this->version_constant_name) : '0.0.0'; |
| 55 | } |
| 56 | /** |
| 57 | * @return string |
| 58 | */ |
| 59 | public function get_required_version() |
| 60 | { |
| 61 | return $this->required_version; |
| 62 | } |
| 63 | /** |
| 64 | * @return bool |
| 65 | */ |
| 66 | public function is_compatible() |
| 67 | { |
| 68 | return $this->compare_version($this->required_version, '>='); |
| 69 | } |
| 70 | /** |
| 71 | * @param string $version . |
| 72 | * @param string $operator . |
| 73 | * |
| 74 | * @return bool |
| 75 | */ |
| 76 | private function compare_version($version, $operator = null) |
| 77 | { |
| 78 | return version_compare($this->get_version(), $version, $operator); |
| 79 | } |
| 80 | /** |
| 81 | * @param string $plugin_file . |
| 82 | * |
| 83 | * @return bool |
| 84 | */ |
| 85 | private function is_plugin_activate($plugin_file) |
| 86 | { |
| 87 | $active_plugins = (array) get_option('active_plugins', []); |
| 88 | if (is_multisite()) { |
| 89 | $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', [])); |
| 90 | } |
| 91 | return in_array($plugin_file, $active_plugins) || array_key_exists($plugin_file, $active_plugins); |
| 92 | } |
| 93 | } |
| 94 |