PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.14.0
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.14.0
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 / Integration.php
nitropack / classes Last commit date
Integration 2 years ago WordPress 2 years ago Integration.php 2 years ago PluginStateHandler.php 3 years ago
Integration.php
208 lines
1 <?php
2
3 namespace NitroPack;
4
5 class Integration {
6 const CRITICAL_INIT_ACTION = "nitropack_integration_critical_init";
7 public static $criticalInitSemaphore = 0;
8
9 private static $instance = NULL;
10 private static $purgeAllPending = false;
11 private static $purgeUrlPending = [];
12 private static $isInitialized = false;
13 private static $isInitializedStage = [];
14 private static $shutdownCallbacks = [];
15 private static $modules = [
16 "NitroPack/Integration/Hosting/Cloudways",
17 "NitroPack/Integration/Hosting/Flywheel",
18 "NitroPack/Integration/Hosting/WPEngine",
19 "NitroPack/Integration/Hosting/SiteGround",
20 "NitroPack/Integration/Hosting/GoDaddyWPaaS",
21 "NitroPack/Integration/Hosting/Kinsta",
22 "NitroPack/Integration/Hosting/Pagely",
23 "NitroPack/Integration/Hosting/Vimexx",
24 "NitroPack/Integration/Hosting/Pressable",
25 "NitroPack/Integration/Hosting/RocketNet",
26 "NitroPack/Integration/Hosting/Savvii",
27 "NitroPack/Integration/Hosting/DreamHost",
28 "NitroPack/Integration/Hosting/WPX",
29 "NitroPack/Integration/Hosting/WPmudev",
30 "NitroPack/Integration/Hosting/Raidboxes",
31 "NitroPack/Integration/Hosting/Pantheon",
32 "NitroPack/Integration/Hosting/SpinupWp",
33 "NitroPack/Integration/Server/LiteSpeed",
34 "NitroPack/Integration/Server/Fastly",
35 "NitroPack/Integration/Server/Cloudflare",
36 "NitroPack/Integration/Server/Sucuri",
37 "NitroPack/Integration/Server/NginxFastCgi",
38 "NitroPack/Integration/Plugin/NginxHelper",
39 "NitroPack/Integration/Plugin/Cloudflare",
40 "NitroPack/Integration/Plugin/ShortPixel",
41 "NitroPack/Integration/Plugin/WPCacheHelper",
42 "NitroPack/Integration/Plugin/CookieNotice",
43 "NitroPack/Integration/Plugin/BeaverBuilder",
44 "NitroPack/Integration/Plugin/FusionBuilder",
45 "NitroPack/Integration/Plugin/ThriveTheme",
46 "NitroPack/Integration/Plugin/AeliaCurrencySwitcher",
47 "NitroPack/Integration/Plugin/Woocommerce",
48 "NitroPack/Integration/Plugin/WoocommerceCacheHandler",
49 "NitroPack/Integration/Plugin/AdvancedMathCaptcha",
50 "NitroPack/Integration/Plugin/TheEventsCalendar",
51 "NitroPack/Integration/Plugin/WCML",
52 "NitroPack/Integration/Plugin/YoastSEO",
53 "NitroPack/Integration/Plugin/JetPackNP",
54 "NitroPack/Integration/Plugin/SquirrlySEO",
55 "NitroPack/Integration/Plugin/RankMathNP",
56 "NitroPack/Integration/Plugin/WPBakeryNP",
57 //"NitroPack/Integration/Plugin/GravityForms",
58 "NitroPack/Integration/Plugin/Elementor",
59 "NitroPack/Integration/Plugin/WPForms",
60 "NitroPack/Integration/Plugin/GeoTargetingWP",
61 ];
62 private static $loadedModules = [];
63 private static $stage = "very_early";
64 private $siteConfig = [];
65 private $purgeUrls = [];
66 private $fullPurge = false;
67
68 public static function getInstance() {
69 if (!self::$instance) {
70 self::$instance = new Integration();
71 }
72 return self::$instance;
73 }
74
75 public static function onCriticalInit($callback) {
76 if (!did_action(self::CRITICAL_INIT_ACTION)) {
77 add_action(self::CRITICAL_INIT_ACTION, $callback);
78 } else {
79 $callback();
80 }
81 }
82
83 public static function onShutdown($callback) {
84 self::$shutdownCallbacks[] = $callback;
85 }
86
87 public static function initSemAcquire() {
88 self::$criticalInitSemaphore++;
89 }
90
91 public static function initSemRelease() {
92 if (--self::$criticalInitSemaphore < 0) {
93 self::$criticalInitSemaphore = 0;
94 }
95 }
96
97 public function __construct() {
98 $this->siteConfig = nitropack_get_site_config();
99 }
100
101 public function getHosting() {
102 return $this->siteConfig && !empty($this->siteConfig["hosting"]) ? $this->siteConfig["hosting"] : "unknown";
103 }
104
105 public function init() {
106 if (self::$isInitialized) return true;
107
108 add_action( 'nitropack_integration_purge_url', [$this, "logUrlPurge"] );
109 add_action( 'nitropack_integration_purge_all', [$this, "logFullPurge"] );
110 self::onShutdown([$this, 'executeIntegrationPurges']);
111 register_shutdown_function(function() {
112 foreach (self::$shutdownCallbacks as $callback) {
113 $callback();
114 }
115 });
116
117 if ($this->siteConfig && !empty($this->siteConfig["isLateIntegrationInitRequired"])) {
118 self::initSemAcquire();
119 }
120
121 $this->initModules(); // very_early init
122
123 $action = $this->getSetupAction(); // can be muplugins_loaded or plugins_loaded
124 if (did_action($action)) {
125 $this->initModules();
126 } else {
127 add_action($action, [$this, 'initModules']);
128 }
129
130 if (did_action('plugins_loaded')) {
131 $this->lateInitModules();
132 } else {
133 add_action('plugins_loaded', [$this, 'lateInitModules']);
134 }
135
136 self::$isInitialized = true;
137 }
138
139 public function logUrlPurge($url) {
140 $this->purgeUrls[] = $url;
141 }
142
143 public function logFullPurge() {
144 $this->fullPurge = true;
145 }
146
147 public function initModules() {
148 if (!empty(self::$isInitializedStage[self::$stage])) return true;
149
150 foreach (self::$modules as $moduleName) {
151 $module = $this->loadModule($moduleName);
152 if ($module && $module->init(self::$stage)) {
153 // Modules which need to be initialized only once return NULL so they don't end up in this array
154 // This array holds only modules which need to have their init method called for each stage
155 self::$loadedModules[$moduleName] = $module;
156 }
157 }
158
159 self::$isInitializedStage[self::$stage] = true;
160
161 if (self::$criticalInitSemaphore < 1 && !did_action(self::CRITICAL_INIT_ACTION)) {
162 do_action(self::CRITICAL_INIT_ACTION);
163 }
164
165 if (self::$stage == "very_early") {
166 self::$stage = "early";
167 }
168 }
169
170 public function lateInitModules() {
171 self::$stage = "late";
172 if ($this->siteConfig && !empty($this->siteConfig["isLateIntegrationInitRequired"])) {
173 self::initSemRelease();
174 }
175 $this->initModules();
176 }
177
178 public function executeIntegrationPurges() {
179 if ($this->fullPurge) {
180 do_action("nitropack_execute_purge_all");
181 } else {
182 foreach (array_unique($this->purgeUrls) as $url) {
183 do_action("nitropack_execute_purge_url", $url);
184 }
185 }
186 }
187
188 private function loadModule($name) {
189 if (isset(self::$loadedModules[$name])) return self::$loadedModules[$name];
190
191 $class = str_replace("/", "\\", $name);
192 if ($class::STAGE == self::$stage) {
193 $module = new $class();
194 return $module;
195 } else {
196 return NULL;
197 }
198 }
199
200 private function getSetupAction() {
201 if ($this->siteConfig && !empty($this->siteConfig["isLateIntegrationInitRequired"])) {
202 return "plugins_loaded";
203 }
204
205 return "muplugins_loaded";
206 }
207 }
208