=== 404ops Cache Tester ===
Contributors: spwhite
Tags: cache, caching, debug, development, diagnostics
Requires at least: 7.0
Tested up to: 7.1
Requires PHP: 8.0
Stable tag: 1.6.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Diagnose whether WordPress pages and AJAX responses are being cached, and by what.

== Description ==

404ops Cache Tester answers "is my caching actually working?" and says what to do when it is not. Its admin screen reports:

* **PHP OPcache**: on or off, memory, cached scripts, hits and misses.
* **Object cache**: whether a persistent cache (Redis, Memcached) is active and this request's hit rate; the `object-cache.php` drop-in, its version and whether its plugin is active; a timed set/get/delete round trip; and, where the drop-in exposes its client, the server's version, memory, evictions and hit rate (read-only `INFO`/stats).
* **HTTP cache headers** of any page on your site, including `Age`, `X-Cache`, `Cf-Cache-Status` and any `Set-Cookie`, and the caching layer they identify (Cloudflare, LiteSpeed Cache, WP Rocket and others).
* **Cache fragmentation probe**: does a tracking link (`?utm_source=`), an analytics cookie or a phone get the cached page, a copy of its own, or no cache at all?
* **Static asset audit**: the `Cache-Control`, `Expires` and validators of the stylesheets, scripts, fonts and images the page loads from your site, with a verdict per file.
* **Debug constants** such as `WP_DEBUG_DISPLAY`.

Every finding comes with a plain-language fix. The two probes run only when you press their buttons, make a small bounded number of requests to your own site, and never request a file on another host.

A live test fires five AJAX requests and compares their responses, and administrators see a small front-end indicator with the page generation time. Results are kept in a short history and folded into a diagnostic report you can copy into a support ticket. `wp cache-tester` offers the same from WP-CLI. Optional scheduled monitoring emails you when a result changes. Network activation adds a cache health dashboard and email digests for sites in that network.

The diagnostic checks do not change how your pages are cached or set cache headers. The optional **Flush Caches** button clears a persistent object cache and OPcache when available, and requests a page-cache flush from a compatible integration. The page-cache integration does not confirm that its cache was cleared; rerun the checks to verify the result.

== Installation ==

1. Upload the plugin through `Plugins > Add New > Upload Plugin`, or copy it to `wp-content/plugins/`.
2. Activate 404ops Cache Tester through the `Plugins` screen.
3. Open the Cache Tester menu item to view cache status and run a live test.

== Frequently Asked Questions ==

= Will this plugin affect caching on my live site? =

The diagnostic checks register no `send_headers` hook and send no cache headers of their own, so they do not change cache behaviour. If you press **Flush Caches**, the plugin clears available object and opcode caches and requests a page-cache flush from a compatible integration. Earlier development builds did force `no-cache` on every front-end request; that was removed, both because it made an entire site uncacheable for as long as a read-only diagnostic stayed active, and because it destroyed the plugin's own measurement -- a cached page is recognised by its generation timestamp *not* changing between reloads, which forcing `no-store` makes impossible.

= Who can see the front-end cache indicator? =

Only logged-in users with the `manage_options` capability (typically administrators). It is not shown to other visitors.

= Does this plugin talk to an external service? =

Only if you connect an AI provider yourself and press the AI diagnosis button; see External services below. Otherwise it contacts no third-party service and transmits none of your site's data anywhere. The checks that make HTTP requests make them to your own site only. To report the cache headers a visitor receives, the plugin fetches a page of your own site over HTTP the way WordPress's own Site Health loopback checks do, and caches the result for five minutes. The page is the front page unless you name another one in the "Page to measure" box on the admin screen; only a page on your site's own host, scheme and port is ever fetched, and anything else -- another host, another port, a user name and password, a `..` path -- is refused with the reason shown on the screen instead of being requested. A redirect is reported with its status and target and never followed, so no other host is ever requested. If that request cannot complete, it retries once against `127.0.0.1` with your site's hostname in the `Host` header, and the screen then labels the result as measured at your server rather than as a visitor sees it. The two probes run only when you press their buttons (or run their WP-CLI commands), through the same rules, and follow no redirect: the fragmentation probe requests the measured page at most eight times (with a `utm_source` value, an `_ga` analytics cookie and a phone User-Agent), and the asset audit reads that page and sends a HEAD request for at most 20 of the stylesheets, scripts, fonts and images it loads from your own site, falling back to a GET with a 4 KB cap only when HEAD is refused. Files on any other host are listed and never requested. Each probe stops after 25 seconds and keeps its result for an hour. The object-cache readings ask your own cache server for its statistics (Redis `INFO` or Memcached stats) through the connection WordPress already has, and time five store/read/delete cycles of one short-lived key. Every other check -- OPcache, object cache, debug constants and the AJAX round-trip test -- reads the current PHP process and WordPress installation directly.

The copy button puts the diagnostic report on your clipboard and nowhere else. The report is sent anywhere only when you ask for an AI diagnosis, and then only to the AI provider you connected yourself (see External services).

= Can I check a fleet of sites from a script? =

Yes, with WP-CLI. `wp cache-tester status` prints every finding the admin screen shows (OPcache, the object cache and its hit rate, the cache headers measured on the page chosen, the caching layers identified, the debug constants) as a table, CSV, JSON or YAML; `status` and `report` both take `--page=/some/path/` to measure a page other than the front page (the flag is `--page` rather than `--url` because `--url` is one of WP-CLI's own global parameters); `wp cache-tester report` prints the diagnostic report the screen offers to copy; `wp cache-tester history` lists the recent live tests; `wp cache-tester fragmentation` and `wp cache-tester assets` run the two probes, and `report --run-probes` runs both before printing the report. They only measure and report, like the screen. The live test itself is run from the screen, in a browser.

= Where can I get help? =
Visit https://supportminer.404ops.com to open a support request.

== External services ==

Nothing is sent to 404ops or to any third party on activation, and the plugin reports no usage statistics.

**Your own site.** The cache-header measurement, the fragmentation probe and the asset audit request pages and files of your own site only (see the FAQ). On a multisite network with the network rollup switched on, the plugin fetches each site's front page in that network on the schedule you choose; only public addresses on ports 80 and 443 are requested.

**AI provider (optional).** Configure a compatible AI provider in WordPress Settings → Connectors. Only when an administrator presses the AI diagnosis button does the WordPress AI Client send the provider the diagnostic report: your site's URL; WordPress, PHP and plugin versions; OPcache and object-cache status and hit counts; the measured page URL and cache headers; caching layers, drop-in and server statistics; probe results and asset URLs; debug constants; and recent live-test results. Review the report before sending it. WordPress chooses a compatible provider among those configured, and that choice can change as providers change. The chosen provider's terms apply. Existing 404ops AI Connection credentials are not copied; configure a WordPress provider to use this feature after updating.

* **OpenAI** - api.openai.com. [Terms of use](https://openai.com/policies/terms-of-use) - [Privacy policy](https://openai.com/policies/privacy-policy).
* **Anthropic (Claude)** - api.anthropic.com. [Commercial terms](https://www.anthropic.com/legal/commercial-terms) - [Privacy policy](https://www.anthropic.com/legal/privacy).
* **Google Gemini** - generativelanguage.googleapis.com. [Gemini API terms](https://ai.google.dev/gemini-api/terms) - [Privacy policy](https://policies.google.com/privacy).
For any other provider available through WordPress, review that provider's terms and privacy policy before sending a diagnosis.

== Privacy and Data Retention ==

404ops Cache Tester has no telemetry. You can give it email addresses for scheduled alerts. WordPress sends alerts through your configured mail transport. Network digests include site names and cache findings. The optional AI diagnosis sends the report through your configured WordPress AI provider when an administrator requests it (see External services).

The plugin stores the ten most recent live-test summaries in the `cse_cache_tester_history` WordPress option. Each summary contains the test time, pass or fail result, unique-response counts, request count, and duration; it contains no response body, IP address, account identifier, or diagnostic-report text. Measured headers are cached for five minutes: the front page in the `cse_cache_tester_measured_headers` transient, and any other page in `cse_cache_tester_measured_headers_` followed by a hash of that page's URL. Probe results are cached for an hour in `cse_cache_tester_fragmentation_` and `cse_cache_tester_assets_` transients, likewise keyed by a hash of the page's URL. The object-cache round trip writes one key in the `cse_cache_tester` cache group with a 60-second lifetime and deletes it straight away.

Deactivation preserves settings and history. Dismissing the footer that names other 404ops tools stores a flag in your user's `cse_cache_tester_cross_promo_dismissed` user meta. On a single-site installation, deleting the plugin removes its options, transients, scheduled events and that user meta. On Multisite, use the matching removal tool from the [Cache Tester page](https://404ops.com/plugins/404ops-cache-tester) during a host maintenance window. It checks that the plugin is inactive across the installation before removing its data and shared files. The shared AI configuration is retained.

Multisite updates keep the pre-1.6 network results and pending alerts in a database archive. New sweeps build a baseline for the current network. Review any existing per-site monitoring override before restoring custom recipients.

== Support ==

After the plugin is listed, use the Support tab on its WordPress.org directory page. Include the copied diagnostic report when it is relevant; review it first and remove any site details you do not want to share publicly.

== Screenshots ==

1. The Cache Tester admin screen showing OPcache, object cache, HTTP header, and debug-constant status.
2. Live cache test results after running five consecutive AJAX requests.
3. Network cache health with results and findings for sites in that network.

== Changelog ==

= 1.6.0 =
* Scope Multisite results, alerts and cleanup to their originating network. Retain old shared results in a database archive.
* Keep cache diagnostics available when saved live-test history contains invalid entries. Preserve unreadable history on save.
* Use supervised removal for Multisite installations to protect shared files and data during uninstall.

= 1.5.1 =
* Keep Cache Tester available if an AI provider fails while checking its configuration.

= 1.5.0 =
* AI diagnosis uses the WordPress AI Client and WordPress Connectors. Configure a compatible provider before requesting a diagnosis; existing 404ops AI credentials are not copied.

= 1.4.4 =
* Corrected page-cache flush reporting to distinguish a request from a confirmed flush.
* Preserved network results for unavailable sites without querying missing site tables.

= 1.4.3 =
* Updated: bundled shared AI client 0.4.3 with hardened connection nonce handling.
* Fixed: normalize network and site action nonces before verification.

= 1.4.2 =
* Added: guarded read-only administrative status interfaces.
* Added: five bundled draft language catalogs with checked WordPress loading.
* Improved: development test-session and catalog packaging checks.

= 1.4.1 =
* Code quality: the multisite results table is queried with `%i` identifier placeholders and the alert-clear update is split over lines, for a cleaner Plugin Check report. No behaviour change.

= 1.4.0 =
* New: **cache fragmentation probe**. One button compares the measured page with the same page carrying a tracking parameter (`utm_source`), an analytics cookie (`_ga`) and a phone User-Agent, and says for each whether it shares the cached copy, gets a copy of its own (fragmentation) or bypasses the cache, with the fix. At most eight requests to your own site, on demand only.
* New: **static asset cache policy audit**. Reads the stylesheets, scripts, fonts and images the page loads from your site (up to 20, HEAD requests) and reports each one's Cache-Control, Expires and validators with a verdict (good, short, missing) and the server setting to change. Files on other hosts are listed, never requested.
* New: **object-cache server diagnostics** on the Object Cache card: drop-in identity and validity (fell back, plugin inactive or missing, version mismatch), a timed set/get/delete round trip, and read-only server facts (version, memory, evictions, hit rate) where the drop-in exposes its Redis or Memcached client.
* All three are in the diagnostic report and in WP-CLI (`wp cache-tester fragmentation`, `wp cache-tester assets`, `report --run-probes`, and new `status` rows).
* Changed: the cache-header measurement no longer follows redirects; a redirect is reported with its status and target, so a request to your own site can never end up on another host.
* New: a one-line, dismissible footer naming the other free 404ops tools that are not installed (dismissal is remembered per user; the `cse_cache_tester_show_cross_promo` filter hides it for everyone).
* Fixed: the privacy section said deleting the plugin keeps its history; uninstall has removed it since 1.2.0.

= 1.3.6 =
* Readme: External services section for the optional AI diagnosis and the network rollup. No code change.

= 1.3.0 - 1.3.5 =
* Requires WordPress 7.0 (tested up to 7.1); the plugin bundles its own prefixed UI kit and updated libraries; an early-translation notice is fixed; wording, menu labels, contributors and the support link refreshed.

= 1.2.0 =
* New: multisite network rollup. Network-activated, a Network Admin screen grades every site's front page A-F (hit/miss, time to first byte, named findings) with a bounded, resumable sweep, per-site overrides and one email digest per cycle. Every site request is checked to be a public address on port 80 or 443, pinned, and re-checked at every redirect.

= 1.1.0 - 1.1.1 =
* New: scheduled monitoring (hourly, twice daily or daily) that emails you only when a result changes. AI features moved to a private copy of the AI client.

= 1.0.0 - 1.0.2 =
* Submission-ready release with privacy, retention and support documentation; the cache-header check can measure any page on your own site (a "Page to measure" box, and `--page=` in WP-CLI), and anything on another host, scheme or port is refused without a request.

== Upgrade Notice ==

= 1.6.0 =
On Multisite, drain Cache Tester cron and PHP workers before upgrading. The next sweep creates a fresh baseline. Review per-site alert overrides before restoring custom recipients. Use the matching removal tool for a complete Multisite uninstall.

= 1.4.2 =
Includes checked draft translations and administrative status reporting. Human linguistic review is separate.

= 1.4.1 =
Code-quality update, no behaviour change. Safe to update.

= 1.4.0 =
Adds a cache fragmentation probe, a static asset cache audit and object-cache server diagnostics. Safe to update.

= 1.3.6 =
Readme-only update: external services disclosure. No code change.

= 1.3.3 =
Listing text only. Safe to update.

= 1.3.2 =
Bundled libraries updated. Safe to update.

= 1.3.1 =
Maintenance release: requires WordPress 7.0 or newer. Safe to update.

= 1.3.0 =
Fixes an early-translation notice, requires WordPress 6.9 or newer, and bundles its own prefixed copy of the 404ops UI kit. Safe to update.

= 1.2.0 =
Adds a multisite network rollup. Single sites are unchanged. Safe to update.

= 1.1.1 =
Maintenance release: AI features use a private copy of the AI client; re-enter your AI connection once. Safe to update.

= 1.0.1 =
Completes the public listing package and refreshes versioned admin assets without changing or removing stored diagnostic history.

= 1.0.0 =
Initial submission-ready release with hardened live-test input handling.
