| @@ -425,8 +425,13 @@ | ||
| 425 | 425 | 'nginx_snippet' => Gzip::nginx_snippet(), |
| 426 | 426 | ), |
| 427 | 427 | 'rewrite_probe' => $rewrite_probe, |
| 428 | 428 | 'nginx_server_block' => Cache::full_nginx_server_block(), |
| 429 | + // What enabling the page cache would do to | |
| 430 | + // wp-content/advanced-cache.php. The dashboard discloses the | |
| 431 | + // replacement BEFORE the write when a leftover drop-in is | |
| 432 | + // already there; see Page_Cache_Detector::dropin_disclosure(). | |
| 433 | + 'dropin' => Page_Cache_Detector::dropin_disclosure(), | |
| 429 | 434 | // Separate Mobile Cache visibility (FBS-83145). `blocking` is |
| 430 | 435 | // true when mobile_separate is what's keeping the device-blind |
| 431 | 436 | // static fast path from installing on a rewrite-capable server; |
| 432 | 437 | // `needs_review` is true when a migration turned it on for us and |
| @@ -459,10 +464,19 @@ | ||
| 459 | 464 | return rest_ensure_response( $updated ); |
| 460 | 465 | } |
| 461 | 466 | |
| 462 | 467 | public function purge() { |
| 463 | - Cache::purge_all( __( 'dashboard', 'xspeed' ) ); | |
| 464 | - return rest_ensure_response( array( 'stats' => Cache::get_stats() ) ); | |
| 468 | + // The same core function `wp xspeed purge` runs, so the dashboard | |
| 469 | + // button and the CLI cannot clear different sets of stores — and the | |
| 470 | + // per-store report is available here for the UI to surface a store | |
| 471 | + // that was skipped or refused rather than flashing "cache cleared". | |
| 472 | + $report = Purge_Runner::run( array( 'all' ), __( 'dashboard', 'xspeed' ) ); | |
| 473 | + return rest_ensure_response( | |
| 474 | + array( | |
| 475 | + 'stats' => Cache::get_stats(), | |
| 476 | + 'report' => $report, | |
| 477 | + ) | |
| 478 | + ); | |
| 465 | 479 | } |
| 466 | 480 | |
| 467 | 481 | /** |
| 468 | 482 | * The "Cached Pages" drill-down: which pages are cached and how old they |
| @@ -540,9 +554,9 @@ | ||
| 540 | 554 | // permission_callback above already enforced current_user_can( |
| 541 | 555 | // 'manage_options' ); the REST nonce is verified by core via the |
| 542 | 556 | // X-WP-Nonce header. |
| 543 | 557 | $state = Cache::toggle( $enabled ); |
| 544 | - $updated = Settings::update( array( 'cache_enabled' => $state['enabled'] ) ); | |
| 558 | + $updated = Settings::get(); | |
| 545 | 559 | |
| 546 | 560 | // Recompute the unified nginx block AFTER cache_enabled is persisted. |
| 547 | 561 | // Cache::toggle() computes it inline, but cache_enabled isn't written |
| 548 | 562 | // until the Settings::update() above — so the block inside $state |
| @@ -552,11 +566,17 @@ | ||
| 552 | 566 | $state['nginx_server_block'] = Cache::full_nginx_server_block(); |
| 553 | 567 | |
| 554 | 568 | return rest_ensure_response( |
| 555 | 569 | array( |
| 556 | - 'enabled' => $updated['cache_enabled'], | |
| 557 | - 'stats' => Cache::get_stats(), | |
| 558 | - 'install_state' => $state, | |
| 570 | + 'enabled' => $updated['cache_enabled'], | |
| 571 | + // Surfaced at the top level so the dashboard can explain a | |
| 572 | + // refusal rather than silently snapping the toggle back: | |
| 573 | + // Cache::toggle() writes nothing when another plugin owns the | |
| 574 | + // drop-in or WP_CACHE is in a shape we must not rewrite. | |
| 575 | + 'blocked' => ! empty( $state['blocked'] ), | |
| 576 | + 'blocked_reason' => $state['blocked_reason'] ?? null, | |
| 577 | + 'stats' => Cache::get_stats(), | |
| 578 | + 'install_state' => $state, | |
| 559 | 579 | ) |
| 560 | 580 | ); |
| 561 | 581 | } |
| 562 | 582 | } |