| @@ -14,13 +14,23 @@ | ||
| 14 | 14 | const PAGE_SLUG = 'xspeed'; |
| 15 | 15 | |
| 16 | 16 | const THEME_COOKIE = 'xspeed_theme'; |
| 17 | 17 | |
| 18 | + /** | |
| 19 | + * The dashboard's sidebar offer reads a module's `purchase_needed` before | |
| 20 | + * its `status_label`. An add-on checks for this constant before it labels | |
| 21 | + * a setup step, which an older dashboard would read as "still for sale". | |
| 22 | + */ | |
| 23 | + const OFFER_READS_PURCHASE_NEEDED = true; | |
| 24 | + | |
| 18 | 25 | public function __construct() { |
| 19 | 26 | add_action( 'admin_menu', array( $this, 'register_menu' ) ); |
| 20 | 27 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) ); |
| 21 | 28 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_menu_styles' ) ); |
| 22 | 29 | add_filter( 'admin_body_class', array( __CLASS__, 'admin_body_class' ) ); |
| 30 | + // Add a "Settings" shortcut to the plugin's row on the Plugins screen, | |
| 31 | + // deep-linking straight to the xSpeed dashboard. (FBS-83234) | |
| 32 | + add_filter( 'plugin_action_links_' . plugin_basename( XSPEED_FILE ), array( __CLASS__, 'plugin_action_links' ) ); | |
| 23 | 33 | // Strip third-party admin notices on our screens only. Fires in |
| 24 | 34 | // `in_admin_header` (after `get_current_screen()` is populated |
| 25 | 35 | // but before notices render) so the screen check is reliable. |
| 26 | 36 | add_action( 'in_admin_header', array( __CLASS__, 'suppress_foreign_notices' ), 0 ); |
| @@ -114,8 +124,18 @@ | ||
| 114 | 124 | if ( ! self::is_plugin_page() ) { |
| 115 | 125 | return $classes; |
| 116 | 126 | } |
| 117 | 127 | $classes .= ' xspeed-page'; |
| 128 | + // Dashboard-only marker (NOT the onboarding wizard, which shares | |
| 129 | + // `xspeed-page` + the same admin.css but must scroll as a normal | |
| 130 | + // centered card). Layout rules that reshape the WP admin chrome — the | |
| 131 | + // sticky content column that pins the fixed-height dashboard while a | |
| 132 | + // tall admin menu scrolls — are scoped to `.xspeed-dashboard` so they | |
| 133 | + // never touch the wizard. Keyed on the ?page= slug (brand-independent). | |
| 134 | + $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only screen gate. | |
| 135 | + if ( self::PAGE_SLUG === $page ) { | |
| 136 | + $classes .= ' xspeed-dashboard'; | |
| 137 | + } | |
| 118 | 138 | if ( 'dark' === self::user_theme() ) { |
| 119 | 139 | $classes .= ' xspeed-dark'; |
| 120 | 140 | } |
| 121 | 141 | return $classes; |
| @@ -120,8 +140,32 @@ | ||
| 120 | 140 | } |
| 121 | 141 | return $classes; |
| 122 | 142 | } |
| 123 | 143 | |
| 144 | + /** | |
| 145 | + * Prepend a "Settings" link to the plugin's action links on the Plugins | |
| 146 | + * screen, deep-linking to the xSpeed dashboard. Only users who can reach | |
| 147 | + * the settings page (`manage_options`, the same cap the menu uses) see it. | |
| 148 | + * | |
| 149 | + * @param array $links Existing action links (Deactivate, etc.). | |
| 150 | + * @return array | |
| 151 | + */ | |
| 152 | + public static function plugin_action_links( $links ) { | |
| 153 | + if ( ! current_user_can( 'manage_options' ) ) { | |
| 154 | + return $links; | |
| 155 | + } | |
| 156 | + | |
| 157 | + $settings_link = sprintf( | |
| 158 | + '<a href="%1$s">%2$s</a>', | |
| 159 | + esc_url( admin_url( 'admin.php?page=' . self::PAGE_SLUG ) ), | |
| 160 | + esc_html__( 'Settings', 'xspeed' ) | |
| 161 | + ); | |
| 162 | + | |
| 163 | + array_unshift( $links, $settings_link ); | |
| 164 | + | |
| 165 | + return $links; | |
| 166 | + } | |
| 167 | + | |
| 124 | 168 | public function register_menu() { |
| 125 | 169 | $brand = self::branding(); |
| 126 | 170 | // Use the white-label logo for the admin menu icon when set, so the |
| 127 | 171 | // rebrand carries to the menu mark too — not just the title. Falls |
| @@ -126,16 +170,22 @@ | ||
| 126 | 170 | // Use the white-label logo for the admin menu icon when set, so the |
| 127 | 171 | // rebrand carries to the menu mark too — not just the title. Falls |
| 128 | 172 | // back to the built-in xSpeed SVG. (FBS-82222) |
| 129 | 173 | $menu_icon = ! empty( $brand['logo_svg'] ) ? $brand['logo_svg'] : self::menu_icon(); |
| 174 | + // Menu label + page <title> both read the resolved brand name | |
| 175 | + // ("xSpeed Cache" by default; a white-label brand is used verbatim). | |
| 176 | + // Positioned just after Appearance | |
| 177 | + // (WP core slot 60) — up with the site-management group, not buried | |
| 178 | + // down by Settings and not pinned to the very top. | |
| 179 | + $menu_label = self::menu_label( $brand ); | |
| 130 | 180 | add_menu_page( |
| 131 | 181 | $brand['name'], |
| 132 | - $brand['name'], | |
| 182 | + $menu_label, | |
| 133 | 183 | 'manage_options', |
| 134 | 184 | self::PAGE_SLUG, |
| 135 | 185 | array( $this, 'render' ), |
| 136 | 186 | $menu_icon, |
| 137 | - 80 | |
| 187 | + 61 | |
| 138 | 188 | ); |
| 139 | 189 | |
| 140 | 190 | // Drop WP's auto-generated duplicate first submenu (which |
| 141 | 191 | // inherits the toplevel "xSpeed" title). The group deep-links |
| @@ -164,39 +214,41 @@ | ||
| 164 | 214 | } |
| 165 | 215 | } |
| 166 | 216 | |
| 167 | 217 | /** |
| 168 | - * Section deep-links rendered under the xSpeed menu. Mirrors the | |
| 169 | - * React sidebar's group manifest (see src/components/sidebarGroups.ts) | |
| 170 | - * so the WP admin rail reads as the same map as the in-app sidebar. | |
| 171 | - * Each entry points at the first module slug in that group; the | |
| 172 | - * React app's hash router lands the user on that module, which is | |
| 173 | - * the first row of that group's sidebar section — no manual scrolling. | |
| 218 | + * Section deep-links rendered under the xSpeed menu. | |
| 174 | 219 | * |
| 175 | - * If you add a group to React's SIDEBAR_GROUPS, add it here too. The | |
| 176 | - * two arrays are intentionally co-located in PR review (same change | |
| 177 | - * touches both) rather than DRY'd through a generated config file — | |
| 178 | - * this is the only PHP↔TS coupling and it's tiny. | |
| 220 | + * This is deliberately a SHORT LIST, not a mirror of React's | |
| 221 | + * SIDEBAR_GROUPS. It used to mirror all eight groups 1:1, which made the | |
| 222 | + * WP admin rail a second, competing copy of the in-app sidebar — the same | |
| 223 | + * map rendered twice, one of them permanently expanded and pushing every | |
| 224 | + * other plugin's menu down the page. | |
| 179 | 225 | * |
| 180 | - * @return array<string,string> map of first-module-hash → group label. | |
| 226 | + * What stays are the entry points a user navigates to from OUTSIDE the | |
| 227 | + * app: the dashboard itself, the two areas people arrive at with a | |
| 228 | + * specific errand (AI & agents to connect an assistant, Settings), and the | |
| 229 | + * wizard. Everything else — Cache, Optimization, Network, Health & | |
| 230 | + * insights, Tools — is one click away in the app's own sidebar, which is | |
| 231 | + * where in-app navigation belongs. | |
| 232 | + * | |
| 233 | + * So adding a group to React's SIDEBAR_GROUPS no longer means adding it | |
| 234 | + * here. The two lists are intentionally different lengths now. | |
| 235 | + * | |
| 236 | + * Setup Wizard is NOT in this array — it's a real submenu page registered | |
| 237 | + * by Onboarding::register_menu() on `admin_menu` at priority 20, so it | |
| 238 | + * lands after these entries. | |
| 239 | + * | |
| 240 | + * @return array<string,string> map of route hash → menu label. | |
| 181 | 241 | */ |
| 182 | 242 | private static function deep_link_items() { |
| 183 | - // Mirrors the dashboard sidebar groups (SIDEBAR_GROUPS in | |
| 184 | - // sidebarGroups.ts) 1:1, in the same order. Each key is the first | |
| 185 | - // module slug of that group (the anchor the submenu deep-links to). | |
| 186 | - // Keep these two lists in sync — they're the only PHP↔TS coupling. | |
| 187 | - // Anchors must be Free, always-visible module slugs so the submenu | |
| 188 | - // works without Pro: 'ai-privacy' (AI group) and 'multisite' (the | |
| 189 | - // Pro Add-ons group placeholder; resolves to the real module on a | |
| 190 | - // licensed multisite). (FBS-82096) | |
| 243 | + // Keys are route hashes (`/<group-id>`); the submenu loop prepends '#'. | |
| 244 | + // React (nav.ts parseRoute) resolves `#/<group-id>` to that landing; | |
| 245 | + // legacy `#slug` links still redirect, so old bookmarks keep working — | |
| 246 | + // including bookmarks to the groups no longer listed here. | |
| 191 | 247 | return array( |
| 192 | - 'cache' => __( 'Cache', 'xspeed' ), | |
| 193 | - 'minify' => __( 'Performance', 'xspeed' ), | |
| 194 | - 'cdn' => __( 'Network', 'xspeed' ), | |
| 195 | - 'health' => __( 'Insights', 'xspeed' ), | |
| 196 | - 'database' => __( 'Tools', 'xspeed' ), | |
| 197 | - 'ai-privacy' => __( 'AI', 'xspeed' ), | |
| 198 | - 'multisite' => __( 'Pro Add-ons', 'xspeed' ), | |
| 248 | + '/overview' => __( 'Overview', 'xspeed' ), | |
| 249 | + '/ai-agents' => __( 'AI & agents', 'xspeed' ), | |
| 250 | + '/settings' => __( 'Settings', 'xspeed' ), | |
| 199 | 251 | ); |
| 200 | 252 | } |
| 201 | 253 | |
| 202 | 254 | /** |
| @@ -208,9 +260,9 @@ | ||
| 208 | 260 | * @since 1.5.0 |
| 209 | 261 | */ |
| 210 | 262 | public static function branding() { |
| 211 | 263 | $defaults = array( |
| 212 | - 'name' => 'xSpeed', | |
| 264 | + 'name' => 'xSpeed Cache', | |
| 213 | 265 | 'footer_credit' => null, // null = show the default WPDeveloper credit. |
| 214 | 266 | 'hide_help_links' => false, |
| 215 | 267 | 'logo_svg' => null, // null = use the built-in brand mark. |
| 216 | 268 | ); |
| @@ -221,8 +273,19 @@ | ||
| 221 | 273 | return array_merge( $defaults, $out ); |
| 222 | 274 | } |
| 223 | 275 | |
| 224 | 276 | /** |
| 277 | + * Label for the WordPress admin sidebar menu entry — the resolved brand | |
| 278 | + * name verbatim ("xSpeed Cache" by default, or the white-label name). | |
| 279 | + * | |
| 280 | + * @param array{name:string} $brand Resolved branding array. | |
| 281 | + * @return string | |
| 282 | + */ | |
| 283 | + private static function menu_label( array $brand ) { | |
| 284 | + return isset( $brand['name'] ) ? (string) $brand['name'] : 'xSpeed Cache'; | |
| 285 | + } | |
| 286 | + | |
| 287 | + /** | |
| 225 | 288 | * URL of the SVG menu icon — the official xSpeed brand mark. Uses |
| 226 | 289 | * fill="currentColor" which renders black in <img> context; the inline |
| 227 | 290 | * style below recolors it via CSS filter for the WP admin menu states. |
| 228 | 291 | */ |
| @@ -231,9 +294,23 @@ | ||
| 231 | 294 | } |
| 232 | 295 | |
| 233 | 296 | public function render() { |
| 234 | 297 | $dark = 'dark' === self::user_theme() ? ' dark' : ''; |
| 235 | - printf( '<div id="xspeed-app" class="xspeed-root%s"></div>', esc_attr( $dark ) ); | |
| 298 | + // Pre-mount skeleton: the React bundle executes a beat after the page | |
| 299 | + // paints, so without this the mount div is an empty dark void while it | |
| 300 | + // loads. We render the xSpeed brand mark (pulsing) straight into the | |
| 301 | + // mount node in PHP; createRoot().render() REPLACES these children the | |
| 302 | + // instant React boots, so the skeleton disappears with no JS wiring. | |
| 303 | + // The mark is the bundled icon.svg; `dark:invert` (scoped in | |
| 304 | + // styles.css) keeps the currentColor mark visible on the dark shell. | |
| 305 | + printf( | |
| 306 | + '<div id="xspeed-app" class="xspeed-root%1$s"><div class="xspeed-boot" role="status" aria-label="%2$s"><img class="xspeed-boot-mark" src="%3$s" alt="%4$s" width="48" height="48" /><span class="screen-reader-text">%5$s</span></div></div>', | |
| 307 | + esc_attr( $dark ), | |
| 308 | + esc_attr__( 'Loading', 'xspeed' ), | |
| 309 | + esc_url( XSPEED_URL . 'assets/icon.svg' ), | |
| 310 | + esc_attr__( 'xSpeed', 'xspeed' ), | |
| 311 | + esc_html__( 'Loading…', 'xspeed' ) | |
| 312 | + ); | |
| 236 | 313 | } |
| 237 | 314 | |
| 238 | 315 | /** |
| 239 | 316 | * Enqueue the stylesheet that recolors the menu icon to match the WP |
| @@ -294,13 +371,25 @@ | ||
| 294 | 371 | ); |
| 295 | 372 | } |
| 296 | 373 | } |
| 297 | 374 | |
| 375 | + // Redesign v2 design tokens + self-hosted fonts. Hand-written (not | |
| 376 | + // Vite-bundled) so the @font-face url('./fonts/…') resolve relative to | |
| 377 | + // assets/. admin.css depends on it so the CSS vars are defined first. | |
| 378 | + $theme_css = XSPEED_DIR . 'assets/theme.css'; | |
| 379 | + if ( file_exists( $theme_css ) ) { | |
| 380 | + wp_enqueue_style( | |
| 381 | + 'xspeed-theme', | |
| 382 | + XSPEED_URL . 'assets/theme.css', | |
| 383 | + array(), | |
| 384 | + XSPEED_VERSION . '.' . filemtime( $theme_css ) | |
| 385 | + ); | |
| 386 | + } | |
| 298 | 387 | if ( file_exists( $asset_css ) ) { |
| 299 | 388 | wp_enqueue_style( |
| 300 | 389 | 'xspeed-admin', |
| 301 | 390 | XSPEED_URL . 'assets/admin.css', |
| 302 | - array(), | |
| 391 | + array( 'xspeed-theme' ), | |
| 303 | 392 | XSPEED_VERSION . '.' . filemtime( $asset_css ) |
| 304 | 393 | ); |
| 305 | 394 | } |
| 306 | 395 | |
| @@ -314,10 +403,23 @@ | ||
| 314 | 403 | * @since 1.5.0 |
| 315 | 404 | */ |
| 316 | 405 | do_action( 'xspeed_admin_enqueue', $hook ); |
| 317 | 406 | |
| 318 | - wp_localize_script( | |
| 319 | - 'xspeed-admin', | |
| 407 | + // NOT wp_localize_script(). WP_Scripts::localize() casts every scalar | |
| 408 | + // to a string (wp-includes/class-wp-scripts.php: `(string) $value`), | |
| 409 | + // so an int arrives in JS as "21600" and a bool as "1" or "". | |
| 410 | + // | |
| 411 | + // That silently broke the Pro prewarm scheduler: it guards with | |
| 412 | + // `typeof gmtOffset === 'number'`, which a string fails, so the site's | |
| 413 | + // UTC offset was treated as 0 and every one-off warm was scheduled | |
| 414 | + // against UTC instead of site time — hours late on any non-UTC site, | |
| 415 | + // under a label that confidently read "Site time (UTC)". | |
| 416 | + // | |
| 417 | + // wp_add_inline_script() with wp_json_encode() preserves types, so | |
| 418 | + // numbers stay numbers and booleans stay booleans. Worth doing beyond | |
| 419 | + // the one field: every future numeric or boolean config value would | |
| 420 | + // hit the same trap. (#105) | |
| 421 | + self::print_config( | |
| 320 | 422 | 'XSpeedConfig', |
| 321 | 423 | array( |
| 322 | 424 | 'restUrl' => esc_url_raw( rest_url( Rest_Api::NAMESPACE_V1 ) ), |
| 323 | 425 | 'nonce' => wp_create_nonce( 'wp_rest' ), |
| @@ -322,12 +424,31 @@ | ||
| 322 | 424 | 'restUrl' => esc_url_raw( rest_url( Rest_Api::NAMESPACE_V1 ) ), |
| 323 | 425 | 'nonce' => wp_create_nonce( 'wp_rest' ), |
| 324 | 426 | 'version' => XSPEED_VERSION, |
| 325 | 427 | 'branding' => self::branding(), |
| 428 | + // Site's UTC offset in seconds — so datetime pickers (e.g. the | |
| 429 | + // Pro prewarm scheduler) align with WP's own post-scheduling, | |
| 430 | + // which is site-time, not the admin's browser-local time. | |
| 431 | + 'gmtOffset' => (int) round( (float) get_option( 'gmt_offset', 0 ) * HOUR_IN_SECONDS ), | |
| 326 | 432 | // 'pro' when xspeed-pro is active + speaks our API |
| 327 | 433 | // version (see Tier_Registry); 'free' otherwise. |
| 328 | 434 | // 'trial' reserved for future license-server work. |
| 329 | 435 | 'tier' => class_exists( '\\XSpeed\\Tier_Registry' ) && Tier_Registry::pro_active() ? 'pro' : 'free', |
| 436 | + // Three-state Pro status so gated UI can show the RIGHT message: | |
| 437 | + // 'not_installed' — Pro plugin not active → "Upgrade to Pro" | |
| 438 | + // 'unlicensed' — Pro active, no valid license → "Activate license" | |
| 439 | + // 'active' — Pro active + licensed → (modules unlocked) | |
| 440 | + // Free can't read Pro's license directly (Free never references | |
| 441 | + // Pro), so Pro filters this via `xspeed_pro_state`. Default: | |
| 442 | + // not_installed when Pro is absent; 'active' when Pro is present | |
| 443 | + // (Pro downgrades to 'unlicensed' when its license isn't valid). | |
| 444 | + 'proState' => self::pro_state(), | |
| 445 | + // The xCloud purge plugin is here: the site already has | |
| 446 | + // Cloudflare Enterprise from its host, so the dashboard does | |
| 447 | + // not offer the add-on. | |
| 448 | + 'xcloudPurgePlugin' => Managed_Edge_Purge::installed(), | |
| 449 | + // Setup Wizard URL, surfaced in the sidebar profile popover. | |
| 450 | + 'wizardUrl' => admin_url( 'admin.php?page=' . Onboarding::PAGE_SLUG ), | |
| 330 | 451 | 'bootstrap' => self::bootstrap_payload(), |
| 331 | 452 | ) |
| 332 | 453 | ); |
| 333 | 454 | } |
| @@ -332,12 +453,68 @@ | ||
| 332 | 453 | ); |
| 333 | 454 | } |
| 334 | 455 | |
| 335 | 456 | /** |
| 457 | + * Emit a JS global for the admin bundle with types intact. | |
| 458 | + * | |
| 459 | + * The type-preserving replacement for wp_localize_script(), which | |
| 460 | + * stringifies every scalar. Attached to the `xspeed-admin` handle as a | |
| 461 | + * `before` script so it is defined by the time the bundle executes — | |
| 462 | + * exactly the ordering guarantee localize gave us. | |
| 463 | + * | |
| 464 | + * Shared by the dashboard and the onboarding wizard so neither can drift | |
| 465 | + * back to the stringifying path. | |
| 466 | + * | |
| 467 | + * @param string $var_name JS global to define. | |
| 468 | + * @param array $data Payload; encoded with wp_json_encode(). | |
| 469 | + */ | |
| 470 | + public static function print_config( string $var_name, array $data ): void { | |
| 471 | + $json = wp_json_encode( $data ); | |
| 472 | + if ( false === $json ) { | |
| 473 | + // Never emit a broken assignment — the bundle reads this global | |
| 474 | + // on mount and a syntax error here blanks the whole screen. | |
| 475 | + $json = '{}'; | |
| 476 | + } | |
| 477 | + wp_add_inline_script( | |
| 478 | + 'xspeed-admin', | |
| 479 | + 'var ' . $var_name . ' = ' . $json . ';', | |
| 480 | + 'before' | |
| 481 | + ); | |
| 482 | + } | |
| 483 | + | |
| 484 | + /** | |
| 336 | 485 | * Pre-rendered settings + status payload, baked into the page so the |
| 337 | 486 | * React app can mount with real values instead of showing a loading state |
| 338 | 487 | * while it waits for /settings and /status REST calls. |
| 339 | 488 | */ |
| 489 | + /** | |
| 490 | + * Three-state Pro status for the gated UI ('not_installed' | 'unlicensed' | |
| 491 | + * | 'active'). Free cannot read Pro's license (it never references Pro), | |
| 492 | + * so the authoritative value comes from the `xspeed_pro_state` filter that | |
| 493 | + * xspeed-pro hooks. The default here only distinguishes installed vs not — | |
| 494 | + * when Pro is active, Pro itself downgrades the value to 'unlicensed' if | |
| 495 | + * its license isn't valid. | |
| 496 | + * | |
| 497 | + * @return string | |
| 498 | + */ | |
| 499 | + private static function pro_state(): string { | |
| 500 | + $pro_present = class_exists( '\\XSpeed\\Tier_Registry' ) && Tier_Registry::pro_active(); | |
| 501 | + $default = $pro_present ? 'active' : 'not_installed'; | |
| 502 | + | |
| 503 | + /** | |
| 504 | + * Filter: xspeed_pro_state | |
| 505 | + * | |
| 506 | + * Lets the Pro plugin report its real license state so Free's gated | |
| 507 | + * panels can show "Activate license" (Pro installed, unlicensed) vs | |
| 508 | + * "Upgrade to Pro" (Pro not installed). | |
| 509 | + * | |
| 510 | + * @param string $state One of 'not_installed' | 'unlicensed' | 'active'. | |
| 511 | + */ | |
| 512 | + $state = (string) apply_filters( 'xspeed_pro_state', $default ); | |
| 513 | + | |
| 514 | + return in_array( $state, array( 'not_installed', 'unlicensed', 'active' ), true ) ? $state : $default; | |
| 515 | + } | |
| 516 | + | |
| 340 | 517 | private static function bootstrap_payload() { |
| 341 | 518 | $opts = Settings::get(); |
| 342 | 519 | $stats = Cache::get_stats(); |
| 343 | 520 | // Static-rewrite probe state shipped to the React side so the |
| @@ -365,8 +542,13 @@ | ||
| 365 | 542 | // means the request-terminating nginx isn't user-editable on this |
| 366 | 543 | // host — the banner uses this to switch to honest messaging |
| 367 | 544 | // instead of dangling a snippet the user can't apply. |
| 368 | 545 | 'behind_proxy' => Server::is_behind_proxy(), |
| 546 | + // Mirrors /status (see the note there). On first paint the | |
| 547 | + // probe is whatever was last cached, so this is usually | |
| 548 | + // `unknown` until the Health tab runs a live probe — the | |
| 549 | + // dashboard needs the key present either way. | |
| 550 | + 'rules' => Cache::rules_state( $probe ), | |
| 369 | 551 | ); |
| 370 | 552 | } |
| 371 | 553 | |
| 372 | 554 | return array( |
| @@ -380,8 +562,25 @@ | ||
| 380 | 562 | 'gzip_active' => Gzip::probe_active(), |
| 381 | 563 | 'nginx_snippet' => Gzip::nginx_snippet(), |
| 382 | 564 | ), |
| 383 | 565 | 'rewrite_probe' => $rewrite_probe, |
| 566 | + // Separate Mobile Cache visibility (FBS-83145) — mirrors the | |
| 567 | + // /status block so the dashboard callout renders on first paint | |
| 568 | + // without waiting for a status re-fetch. | |
| 569 | + 'mobile_separate' => array( | |
| 570 | + 'enabled' => (bool) ( $opts['cache_enabled'] ? ( Settings_Manager::get( 'cache' )['mobile_separate'] ?? false ) : false ), | |
| 571 | + // Gated to servers that HAVE a static fast path — on IIS or | |
| 572 | + // an undetected server block_reason still falls through to | |
| 573 | + // mobile_separate, and reporting that as "blocking" would | |
| 574 | + // nag about a rewrite that does not exist there (#108). | |
| 575 | + // LiteSpeed joined the capable set with the Static Fast | |
| 576 | + // Path opt-in (#509); its own refusal (litespeed_dropin) | |
| 577 | + // outranks mobile_separate, so this stays false there | |
| 578 | + // until the opt-in is on. | |
| 579 | + 'blocking' => ( $rewrite_capable || Server::LITESPEED === $server_type ) | |
| 580 | + && 'mobile_separate' === Cache::static_rewrite_block_reason(), | |
| 581 | + 'needs_review' => Cache::mobile_separate_needs_review(), | |
| 582 | + ), | |
| 384 | 583 | // One consolidated nginx server-block snippet aggregating |
| 385 | 584 | // every enabled module's directives (Cache static-rewrite, |
| 386 | 585 | // BrowserCache headers, GZIP, …). Null on non-nginx hosts |
| 387 | 586 | // or when no module contributes directives. Replaces the |
| @@ -386,17 +585,41 @@ | ||
| 386 | 585 | // BrowserCache headers, GZIP, …). Null on non-nginx hosts |
| 387 | 586 | // or when no module contributes directives. Replaces the |
| 388 | 587 | // per-module "paste this snippet" notices. |
| 389 | 588 | 'nginx_server_block' => Cache::full_nginx_server_block(), |
| 589 | + // Mirrors the /status block so the enable-time disclosure is | |
| 590 | + // correct on FIRST PAINT. Without it the top-bar switch can be | |
| 591 | + // clicked before a status fetch lands, and the one moment the | |
| 592 | + // warning exists for — a leftover drop-in about to be | |
| 593 | + // replaced — is exactly when it would be missing. | |
| 594 | + 'dropin' => Page_Cache_Detector::dropin_disclosure(), | |
| 390 | 595 | ), |
| 391 | 596 | // Registered Modules (Free + Pro). The React app discovers them |
| 392 | 597 | // here and renders one sidebar item + one panel per module that |
| 393 | 598 | // declares a settings schema. Hidden modules are filtered. |
| 394 | 599 | 'modules' => self::modules_payload(), |
| 600 | + // xSpeed Hub connection snapshot so the Account panel + header chip | |
| 601 | + // render the correct connected/not-connected state on FIRST PAINT — | |
| 602 | + // no fetch, no "not connected → connected" flash. Null when the MCP | |
| 603 | + // module is unavailable (the panel then falls back to /mcp/hub). | |
| 604 | + 'hub' => self::hub_payload(), | |
| 395 | 605 | ); |
| 396 | 606 | } |
| 397 | 607 | |
| 398 | 608 | /** |
| 609 | + * xSpeed Hub connection snapshot for the dashboard bootstrap. Guarded so the | |
| 610 | + * dashboard never hard-depends on the MCP module. Same shape as GET /mcp/hub. | |
| 611 | + * | |
| 612 | + * @return array<string,mixed>|null | |
| 613 | + */ | |
| 614 | + private static function hub_payload() { | |
| 615 | + if ( ! class_exists( '\XSpeed\Modules\Mcp\Mcp_Hub' ) ) { | |
| 616 | + return null; | |
| 617 | + } | |
| 618 | + return \XSpeed\Modules\Mcp\Mcp_Hub::public_status(); | |
| 619 | + } | |
| 620 | + | |
| 621 | + /** | |
| 399 | 622 | * Serialize every available Module for the React dashboard. Each entry |
| 400 | 623 | * carries enough to render: identity (slug + tier), UI metadata (label, |
| 401 | 624 | * icon, optional description), current settings, and the typed schema |
| 402 | 625 | * the panel uses to render controls. |
| @@ -420,19 +643,83 @@ | ||
| 420 | 643 | // panel — i.e., truly nothing to render in the dashboard. |
| 421 | 644 | if ( empty( $schema ) && empty( $custom_panel ) ) { |
| 422 | 645 | continue; |
| 423 | 646 | } |
| 647 | + $settings = Settings_Manager::get_public( $slug ); | |
| 648 | + // Something else on the site has taken over this module's job. It | |
| 649 | + // stands down whatever its own switch says, so it is reported off, | |
| 650 | + // with the reason in place of its usual one. | |
| 651 | + $blocked = $module->blocked_by(); | |
| 652 | + $active = $module->is_active(); | |
| 653 | + | |
| 424 | 654 | $entry = array( |
| 425 | 655 | 'slug' => $slug, |
| 426 | 656 | 'tier' => $module->tier(), |
| 427 | 657 | 'version' => $module->version(), |
| 658 | + // Promoted from inside `settings` so the payload is | |
| 659 | + // self-describing. Consumers kept tripping on this — the Hub | |
| 660 | + // rendered every module "Inactive" until it learned to look | |
| 661 | + // inside the settings bag. `settings.enabled` is kept below | |
| 662 | + // for back-compat; this is the same value, not a second | |
| 663 | + // source of truth. Modules with no `enabled` key (status | |
| 664 | + // panels like Health) report null rather than a misleading | |
| 665 | + // false. (#146) | |
| 666 | + 'enabled' => array_key_exists( 'enabled', $settings ) | |
| 667 | + ? (bool) $settings['enabled'] | |
| 668 | + : null, | |
| 669 | + // Whether the module is actually DOING something, which is not | |
| 670 | + // the same question as `enabled` above. "On" has several shapes | |
| 671 | + // -- page caching lives in the global option, Minify and Lazy | |
| 672 | + // are on when any flag is set, MCP when it is connected -- so | |
| 673 | + // each module answers for itself via is_active(). Consumers | |
| 674 | + // that want "what is switched on?" (the sidebar's "N on" badge) | |
| 675 | + // must read THIS, not `enabled`, which only ever described the | |
| 676 | + // modules that happen to store that one key. null means the | |
| 677 | + // module has no meaningful on/off and should be excluded from | |
| 678 | + // any count rather than treated as off. (#363) | |
| 679 | + 'active' => ( null !== $blocked && true === $active ) ? false : $active, | |
| 680 | + // One sentence explaining the line above, computed next to it | |
| 681 | + // so the two cannot disagree. The UI shows it behind an (i) | |
| 682 | + // beside the status pill: "On" is a bare assertion otherwise, | |
| 683 | + // and least obvious exactly where it matters -- Media | |
| 684 | + // Optimization reads On while its two most prominent switches | |
| 685 | + // are off, because three other flags are on. (#363) | |
| 686 | + 'active_reason' => null !== $blocked ? $blocked : $module->active_reason(), | |
| 687 | + // A purchase or licence the module still waits on. Shown in the | |
| 688 | + // page header in place of the On/Off pill. Not while another | |
| 689 | + // module has taken over: that reason is the one to show. | |
| 690 | + 'status_label' => null !== $blocked ? null : $module->status_label(), | |
| 428 | 691 | 'label' => $meta['label'] ?? ucfirst( $slug ), |
| 429 | 692 | 'icon' => $meta['icon'] ?? 'Square', |
| 430 | 693 | 'description' => $meta['description'] ?? '', |
| 431 | - 'settings' => Settings_Manager::get( $slug ), | |
| 694 | + // The dashboard group the module belongs to (cache, performance, | |
| 695 | + // network, insights, tools, ai-agents, settings), declared by the | |
| 696 | + // module itself. The Hub kept its own copy of this map, so every | |
| 697 | + // new module landed in its "Other" bucket until the Hub shipped. | |
| 698 | + // Must agree with src/components/sidebarGroups.ts; a unit test | |
| 699 | + // holds the two together. | |
| 700 | + 'group' => $meta['group'] ?? null, | |
| 701 | + // Short label for the module's own tab when it hosts a tabbed | |
| 702 | + // page (FBS-83633). Only set on host modules. | |
| 703 | + 'tab_label' => $meta['tab_label'] ?? null, | |
| 704 | + // Public view: real values except secret fields, which are masked. | |
| 705 | + // The dashboard bundle localizes this into page HTML, so a raw | |
| 706 | + // credential here would be readable from view-source. (#115) | |
| 707 | + 'settings' => $settings, | |
| 708 | + // Where each value actually came from: a wp-config.php constant, | |
| 709 | + // the option row, or the schema default. The panel renders a | |
| 710 | + // constant-sourced field read-only and names the constant, so it | |
| 711 | + // can never present an editable box over a value the site is not | |
| 712 | + // using. Every module gets this, not just the ones that declare | |
| 713 | + // constants today. (#398) | |
| 714 | + 'setting_origins' => Settings_Manager::origins( $slug ), | |
| 432 | 715 | 'schema' => $schema, |
| 433 | 716 | 'notices' => $module->ui_notices(), |
| 434 | 717 | 'custom_panel' => $meta['custom_panel'] ?? null, |
| 718 | + // Why this module may not be switched on, when something else | |
| 719 | + // on the site has taken over from it. Null for almost every | |
| 720 | + // module almost always — Free never blocks anything itself. | |
| 721 | + 'blocked_by' => $blocked, | |
| 435 | 722 | ); |
| 436 | 723 | |
| 437 | 724 | /** |
| 438 | 725 | * Last-mile descriptor filter. Lets Pro (or third-party |