PluginProbe
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN / 1.3.4
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN v1.3.4
1.3.4 1.3.3 1.3.2 1.3.1 1.3.0 1.2.4 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 All 30 releases
← All changes | includes/class-plugin.php +173 -13 1.1.71.3.4 View file →
@@ -76,13 +76,34 @@
76 76 // Per-post cache rules (Phase 3.4) — registers postmeta with
77 77 // REST + meta box on edit screens.
78 78 Cache_Meta_Box::boot();
79 79
80 + // Single-URL purge entry points — row actions, the edit-screen
81 + // button and the admin-post handler the admin-bar item also uses.
82 + Purge_Ui::boot();
83 +
80 84 // Phase 0 architecture — managers + Free modules. v1 services
81 85 // (Cache/Minifier/Gzip) are NOT yet Modules; they'll be refactored
82 86 // in a follow-up PR with parity tests.
83 87 Conflict_Registry::boot();
84 88
89 + // Read-only page-cache ownership evidence, behind the same
90 + // activation/deactivation invalidation as the conflict matrix.
91 + Page_Cache_Detector::boot();
92 +
93 + // Integrations that clear OTHER plugins' caches of rendered output
94 + // (Elementor's element cache + generated CSS). Registers a listener
95 + // only; nothing runs until Cache::purge_render_caches() asks.
96 + Render_Caches::boot();
97 + // Server_Caches needs no boot(): Cache::dispatch_purge_event() calls it
98 + // directly so a throwing third-party listener cannot skip it.
99 +
100 + // Forward a full purge to a full-page cache owned by the WEB SERVER
101 + // (nginx FastCGI, via the host's Nginx Helper install). Registers a
102 + // listener on xspeed_after_purge_all only; it stands down unless
103 + // that cache is actually configured.
104 + Host_Page_Caches::boot();
105 +
85 106 // Register Free modules via the same action xspeed-pro uses, so
86 107 // the bootstrap path is symmetric across tiers.
87 108 add_action( 'xspeed_register_modules', array( $this, 'register_free_modules' ) );
88 109
@@ -150,8 +171,63 @@
150 171 * Runs at plugins_loaded(20) so every add-on that hooks at any
151 172 * priority < 20 has time to register first.
152 173 */
153 174 public function fire_module_lifecycle(): void {
175 + $this->ensure_modules_registered();
176 +
177 + Module_Registry::boot_all();
178 + }
179 +
180 + /**
181 + * Fire `xspeed_register_modules` if this request has not yet, hooking
182 + * Free's own registration first when init() never got the chance.
183 + *
184 + * The activation request is the case that matters. activate_plugin()
185 + * includes the plugin file long after `plugins_loaded` has fired, so the
186 + * `plugins_loaded` callback init() would have added never runs, and
187 + * neither does the add_action() inside it that puts register_free_modules
188 + * on the action. Firing the action from activate() then registered
189 + * nothing: Settings::conflict_safe_profile() composed from an empty
190 + * registry, and a site with WP Super Cache came up with lazy-load,
191 + * resource hints, font swapping and preloading switched on — only the
192 + * four settings the registry-independent fallback names were held down
193 + * (PR #295 review). Module_Registry::activate_all() has been a no-op on
194 + * the same request for the same reason.
195 + *
196 + * On the activation request that means Free only: an add-on cannot have
197 + * hooked yet, because xspeed-pro bails when Free's classes are absent and
198 + * only hooks the action (at priority 20, from plugins_loaded(15)) once
199 + * Free is active. On an ordinary request fire_module_lifecycle() reaches
200 + * this at plugins_loaded(20) with every add-on already hooked. Do not
201 + * call this from anything that can run in between: the action fires
202 + * once, and an add-on that has not hooked yet stays unregistered for the
203 + * whole request.
204 + * did_action() keeps the action to one firing per request, so an
205 + * activation that ran first does not make plugins_loaded(20) register
206 + * every module a second time.
207 + */
208 + public function ensure_modules_registered(): void {
209 + if ( did_action( 'xspeed_register_modules' ) ) {
210 + return;
211 + }
212 +
213 + /*
214 + * register_free_modules() does an unconditional `new` on every module
215 + * class. On an ordinary request xspeed.php's integrity check refuses
216 + * to boot before that can fatal and explains itself in an admin
217 + * notice; the activation hook is registered outside that check, so
218 + * an install missing a module file (truncated zip, a security
219 + * plugin's quarantine, a half-applied update) would fatal here with
220 + * no notice and no active plugin. Same answer as boot: do nothing.
221 + */
222 + if ( function_exists( 'xspeed_missing_core_classes' ) && ! empty( xspeed_missing_core_classes() ) ) {
223 + return;
224 + }
225 +
226 + if ( ! has_action( 'xspeed_register_modules', array( $this, 'register_free_modules' ) ) ) {
227 + add_action( 'xspeed_register_modules', array( $this, 'register_free_modules' ) );
228 + }
229 +
154 230 /**
155 231 * Action: xspeed_register_modules
156 232 *
157 233 * Free modules register at priority 10; xspeed-pro at priority
@@ -158,10 +234,8 @@
158 234 * 20; site code can hook in between to inject custom modules.
159 235 * Fires exactly once per request.
160 236 */
161 237 do_action( 'xspeed_register_modules' );
162 -
163 - Module_Registry::boot_all();
164 238 }
165 239
166 240 /**
167 241 * Register the Free Modules shipped in this plugin. Add new module
@@ -194,8 +268,9 @@
194 268 // cache-coverage features (404 / search / feed / REST / rules /
195 269 // maintenance) into one sidebar sub-item (FBS-83633).
196 270 Module_Registry::register( new \XSpeed\Modules\CacheCoverage\CacheCoverageModule() );
197 271 Module_Registry::register( new \XSpeed\Modules\Fonts\FontsModule() );
272 + Module_Registry::register( new \XSpeed\Modules\RenderSkip\RenderSkipModule() );
198 273 Module_Registry::register( new \XSpeed\Modules\ResourceHints\ResourceHintsModule() );
199 274 // AI Privacy (GDPR off-switch) ships in Free even though every AI
200 275 // *feature* is Pro — privacy is a right, not a paid tier. FEATURES.md
201 276 // §AI row 6 mandates it. Without this registration the module was dead
@@ -212,8 +287,12 @@
212 287 // snapshot is onboarding/diagnostics, not a paid value-add, so every
213 288 // user gets it. The snapshot degrades gracefully without Pro (Pro
214 289 // version/license fields fall back to defaults via defined()/get_option).
215 290 Module_Registry::register( new \XSpeed\Modules\Support\SupportModule() );
291 + // The dashboard control for usage-analytics consent. Consent used to
292 + // be collectable only in the wizard and withdrawable nowhere, while
293 + // the wizard and readme both promised a dashboard switch. (#437)
294 + Module_Registry::register( new \XSpeed\Modules\Privacy\PrivacyModule() );
216 295 // MCP remote control (AI assistants) — Free. The plugin serves the
217 296 // MCP protocol at the site's own /xspeed/mcp URL; the only gate is
218 297 // the per-site connection token an admin mints via Connect. No
219 298 // license, no hosted infra. See IMPLEMENTATION.md §17.
@@ -244,10 +323,16 @@
244 323 return $this->usage_tracker;
245 324 }
246 325
247 326 public static function activate() {
248 - Settings::set_defaults();
327 + // Nothing below can see a module the registry does not hold — the
328 + // conflict-safe profile Settings::set_defaults() may pick is composed
329 + // from it, and activate_all() walks it. See ensure_modules_registered()
330 + // for why the registry is empty on this request without this call.
331 + self::instance()->ensure_modules_registered();
249 332
333 + $profile = Settings::set_defaults();
334 +
250 335 // Score history table. Also called on admin_init (see init()) because
251 336 // activation does not fire for a site added to a multisite network
252 337 // later, nor after an update that ships a new schema version.
253 338 Score_Store::maybe_install();
@@ -256,12 +341,62 @@
256 341 wp_mkdir_p( XSPEED_CACHE_DIR );
257 342 }
258 343 Cache::write_silence( XSPEED_CACHE_DIR );
259 344
260 - // Caching is only ever ENABLED from the admin UI — see Cache::toggle()
261 - // and Rest_Api::toggle_cache(). A fresh install therefore gets no
262 - // drop-in and no wp-config.php edit here: cache_enabled is unset, so
263 - // the call below is a no-op.
345 + /*
346 + * One exception to "caching is only ever enabled from the admin UI":
347 + * a fresh install another plugin performed on the user's behalf.
348 + *
349 + * That plugin asked the user for site performance and installed us to
350 + * provide it; making them go and find a second switch afterwards is
351 + * a step nobody wants. It is also what the copy-vendored Setup::finish()
352 + * did, so hosts migrating off it keep the behaviour they have.
353 + *
354 + * PROFILE_HOST_PAGE_CACHE is the whole condition, and it means three
355 + * things at once: the install was genuinely fresh, nothing else owns
356 + * the page cache, and another plugin claimed the install. Every other
357 + * fresh install — including a user's own on a clear site — waits for
358 + * the wizard. Every OTHER feature is off in this profile; the cache is
359 + * the one thing a host may assume, because it is what it installed us
360 + * for. And toggle() runs its own ownership transaction, so a
361 + * competitor appearing between the two checks loses the race rather
362 + * than being overwritten.
363 + */
364 + if ( Settings::PROFILE_HOST_PAGE_CACHE === $profile ) {
365 + $state = Cache::toggle( true );
366 + if ( ! empty( $state['blocked'] ) ) {
367 + /*
368 + * Refused after all — a competitor that appeared between the
369 + * profile decision and the write, or a drop-in we could not
370 + * install. The settings are identical either way (everything
371 + * off), so the honest record is the one that does not claim a
372 + * cache: conflict-safe is what the site actually got.
373 + */
374 + $profile = Settings::PROFILE_CONFLICT_SAFE;
375 + update_option( 'xspeed_install_profile', $profile, false );
376 + }
377 + }
378 +
379 + /*
380 + * Read the claim BEFORE spending it. consume_installed_by() records
381 + * the installer only for a FRESH install — on a re-activation over
382 + * settings that are already there it deletes the arming option and
383 + * keeps nothing — so asking again afterwards answered "the user did
384 + * it" about an install a host had just claimed, and the wizard opened
385 + * over the host's own flow. The claim decides who to tell and whether
386 + * to open the wizard; whether it is worth RECORDING is a separate
387 + * question, and only the recording depends on the install being fresh.
388 + */
389 + $installed_by = Settings::installed_by();
390 +
391 + // Spend the arming option now the profile is settled. It changes what
392 + // activation does, so it may not survive into the next one.
393 + Settings::consume_installed_by( $profile );
394 +
395 + // Caching is otherwise only ENABLED from the admin UI — see
396 + // Cache::toggle() and Rest_Api::toggle_cache(). A fresh install
397 + // therefore gets no drop-in and no wp-config.php edit here:
398 + // cache_enabled is unset, so the call below is a no-op.
264 399 //
265 400 // It is NOT a no-op during an upgrade. WordPress runs an update as
266 401 // deactivate → wipe files → install → activate, which deletes
267 402 // advanced-cache.php while cache_enabled stays true. Restoring it
@@ -268,16 +403,41 @@
268 403 // here closes the window in which the site silently serves uncached
269 404 // (auto_heal() alone only fires on the next wp-admin page load).
270 405 Cache::restore_dropin_if_enabled();
271 406
272 - // First-run wizard: flag a one-time redirect for the activating user.
273 - // Suppressed for bulk activations / already-completed sites in
274 - // Onboarding::maybe_redirect().
275 - Onboarding::flag_redirect();
407 + /*
408 + * First-run wizard: flag a one-time redirect for the activating user.
409 + * Suppressed for bulk activations / already-completed sites in
410 + * Onboarding::maybe_redirect() — and here for an install another plugin
411 + * performed, which has an onboarding flow of its own. The install runs
412 + * over AJAX, so our redirect would fire on that admin's NEXT page load
413 + * and pull them out of the middle of the host's wizard; finishing ours
414 + * would then overwrite the deliberately all-off profile they never
415 + * asked to change.
416 + */
417 + if ( '' === $installed_by ) {
418 + Onboarding::flag_redirect();
419 + }
276 420
277 - // Propagate activation to every registered Module. Activation
278 - // happens after plugins_loaded → modules are already registered.
421 + // Propagate activation to every registered Module — registered by
422 + // ensure_modules_registered() at the top, not by plugins_loaded,
423 + // which fired before this file was even included.
279 424 Module_Registry::activate_all();
425 +
426 + /**
427 + * Fires at the end of activation, once the settings profile is decided.
428 + *
429 + * The other half of the host-plugin contract: a plugin that installed
430 + * xSpeed for the user writes `xspeed_installed_by` before activating
431 + * and listens here to find out how it came up. It carries no return
432 + * value and nothing branches on it — a host that ignores it changes
433 + * nothing about the install.
434 + *
435 + * @param string $installed_by Host slug, or '' when the user did it.
436 + * @param string $profile Settings::PROFILE_* — which profile a fresh
437 + * install came up with, '' if not fresh.
438 + */
439 + do_action( 'xspeed_activated', $installed_by, $profile );
280 440 }
281 441
282 442 /**
283 443 * Restore the cache drop-in right after THIS plugin is updated.