PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / trunk
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization vtrunk
1.19.8 1.19.7 1.19.6 1.19.5 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.12.0 1.13.0 1.14.0 1.15.0 1.15.1 1.15.2 1.15.3 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.16.7 1.16.8 1.17.0 1.17.6 1.17.7 1.17.8 1.17.9 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.18.5 1.18.6 1.18.7 1.18.8 1.18.9 1.19.0 1.19.1 1.19.2 1.19.3 1.19.4 1.3.19 1.3.20 1.4.0 1.4.1 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.8.1 1.8.3 1.9.0 1.9.1 1.9.2
nitropack / classes / PluginStateHandler.php
nitropack / classes Last commit date
Feature 3 months ago Integration 2 weeks ago Interfaces 1 year ago Util 1 year ago WordPress 3 days ago ModuleHandler.php 4 months ago PageSpeedBoost.php 2 weeks ago PluginStateHandler.php 11 months ago
PluginStateHandler.php
53 lines
1 <?php
2
3 namespace NitroPack;
4
5 use NitroPack\Integration\Plugin\AeliaCurrencySwitcher;
6
7 class PluginStateHandler {
8 const eventHandlersMap = [
9 // 'woocommerce-aelia-currencyswitcher/woocommerce-aelia-currencyswitcher.php' => [
10 // 'activateCallback' => 'HandleAeliaCurrencyActivation',
11 // 'deactivateCallback' => 'HandleAeliaCurrencyDeactivation',
12 // ],
13 ];
14 private static $instance;
15
16 public static function getInstance() {
17 if (!self::$instance) {
18 self::$instance = new PluginStateHandler();
19 }
20 return self::$instance;
21 }
22
23 public static function init() {
24 add_action('activated_plugin', [self::getInstance(), 'handleActivation'], 10, 1);
25 add_action('deactivated_plugin', [self::getInstance(), 'handleDeactivation'], 10, 1);
26 add_action('update_option_active_plugins', [self::getInstance(), 'onUpdatedActivePluginsList'], 10, 3);
27 }
28
29 public function handleActivation($plugin) {
30 if (array_key_exists($plugin, self::eventHandlersMap) && !empty(self::eventHandlersMap[$plugin]['activateCallback'])) {
31 self::{self::eventHandlersMap[$plugin]['activateCallback']}();
32 }
33 }
34
35 public function handleDeactivation($plugin) {
36 if (array_key_exists($plugin, self::eventHandlersMap) && !empty(self::eventHandlersMap[$plugin]['deactivateCallback'])) {
37 self::{self::eventHandlersMap[$plugin]['deactivateCallback']}();
38 }
39 }
40 public function onUpdatedActivePluginsList($old_value, $value, $option) {
41 if ($old_value === $value) return;
42
43 $activated_plugins = array_diff($value, $old_value);
44 $deactivated_plugins = array_diff($old_value, $value);
45
46 if (in_array('woocommerce/woocommerce.php', $activated_plugins)) {
47 nitropack_event("platform_change", null, array("platform" => 'WooCommerce'));
48 } else if (in_array('woocommerce/woocommerce.php', $deactivated_plugins)) {
49 nitropack_event("platform_change", null, array("platform" => 'WordPress'));
50 }
51 }
52 }
53