IsActive.php
4 years ago
IsInstalled.php
4 years ago
IsNotActive.php
4 years ago
IsPluginActive.php
4 years ago
IsPluginNotActive.php
4 years ago
IsActive.php
43 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Integration\Filter; |
| 4 | |
| 5 | use AC\Integration; |
| 6 | use AC\Integration\Filter; |
| 7 | use AC\Integrations; |
| 8 | use AC\PluginInformation; |
| 9 | |
| 10 | class IsActive implements Filter { |
| 11 | |
| 12 | /** |
| 13 | * @var bool |
| 14 | */ |
| 15 | private $is_multisite; |
| 16 | |
| 17 | /** |
| 18 | * @var bool |
| 19 | */ |
| 20 | private $is_network_admin; |
| 21 | |
| 22 | public function __construct( $is_multisite, $is_network_admin ) { |
| 23 | $this->is_multisite = (bool) $is_multisite; |
| 24 | $this->is_network_admin = (bool) $is_network_admin; |
| 25 | } |
| 26 | |
| 27 | public function filter( Integrations $integrations ) { |
| 28 | return new Integrations( array_filter( $integrations->all(), [ $this, 'is_active' ] ) ); |
| 29 | } |
| 30 | |
| 31 | public function is_active( Integration $integration ) { |
| 32 | $plugin = new PluginInformation( $integration->get_basename() ); |
| 33 | |
| 34 | $is_active = $plugin->is_network_active() |
| 35 | || ( ! $this->is_multisite && $plugin->is_active() ) |
| 36 | || ( $this->is_multisite && ! $this->is_network_admin && $plugin->is_active() ); |
| 37 | |
| 38 | // The installed check is required, because it is possible for a plugin to be active without being installed. |
| 39 | // For example, when a plugin is removed from the file system without visiting the plugin's page. |
| 40 | return $plugin->is_installed() && $is_active; |
| 41 | } |
| 42 | |
| 43 | } |