=== Anti-Cache Kit ===
Contributors: fernandot, ayudawp
Tags: cache, debug, development, maintenance, troubleshooting
Requires at least: 5.5
Tested up to: 7.2
Requires PHP: 7.4
Stable tag: 4.3.0
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Flushes and deactivates cache and optimization plugins, enables debug mode, and provides maintenance mode for WordPress development.

== Description ==

**Anti-Cache Kit** is a development tool for WordPress developers and designers who need to bypass all caching and optimization mechanisms during development, testing, or troubleshooting.

**Development tool only. Do not leave active on production sites.**

= Key features =

**Cache and optimization management**

* Detects and deactivates 20+ cache plugins, flushing their cache first when the plugin offers a way to do it
* Removes the object-cache.php drop-in of Object Cache 4 Everyone, which keeps caching after the plugin is deactivated
* On a network, leaves cache plugins that are active for the whole network to a network administrator, and says so
* Deactivates optimization plugins that interfere with debugging (Perfmatters, FlyingPress, WP Asset CleanUp, and more)
* Never deactivates Query Monitor, the debugging tool you need while troubleshooting
* Clears object cache (Redis, Memcached) and OPcache
* Clears hosting caches (SiteGround, Cloudflare, Kinsta, WP Engine, Pantheon, Batcache on Pressable, and Varnish on demand) and tells you which ones it purged
* Prevents browser caching for administrators

**Server-level cache prevention**

* Injects .htaccess rules via the WordPress markers API, no backup file needed
* Disables SiteGround cache via environment variables
* Sets no-cache, no-store headers at server level for all visitors
* Disables ETags and mod_expires to prevent conditional caching
* Sends CDN/proxy bypass headers (X-Accel-Expires, Surrogate-Control)
* Detects nginx and Caddy and skips rules that would not apply there, offering an equivalent nginx snippet to copy instead
* Cleanly removes only its own rules on deactivation, leaving the rest of .htaccess untouched

**Debug mode activation**

* Enables WP_DEBUG, WP_DEBUG_LOG, and SCRIPT_DEBUG (errors go to wp-content/debug.log)
* Sets WP_DEBUG_DISPLAY to false so errors are logged, not shown on screen
* Disables WordPress cache (WP_CACHE = false)
* Comments out conflicting definitions with visible markers instead of deleting them
* Wraps its own definitions in markers and reverts them on deactivation, leaving wp-config.php exactly as it was
* Tells you when a debug constant is defined outside wp-config.php (a file it includes, or your host), so the kit could not change it
* Modifies wp-config.php with the WordPress Filesystem API, validates the result before writing, keeps its permissions and symbolic links, and never keeps a copy of your credentials on disk

**Developer workflow**

* WP-CLI commands: wp anticache status, flush, maintenance, on, off and expire
* Auto-deactivation after 2, 6, 12 or 24 hours, reverting everything
* Debug log viewer with the last 200 lines of debug.log and a button to empty it
* Optional debug constants: SAVEQUERIES, CONCATENATE_SCRIPTS off, WP_DEBUG_DISPLAY on, WP_DISABLE_FATAL_ERROR_HANDLER

**Maintenance mode**

* Optional status page for visitors and for logged-in users who cannot edit content, such as customers and subscribers
* Anyone who can edit content keeps seeing the site
* The REST API and XML-RPC stay available, so payment webhooks and forms keep working
* Quick toggle from admin bar
* Customizable via filter hook
* Self-contained output with aggressive cache prevention headers (503, no-store, Surrogate-Control)

**Safety and environment**

* Detects production sites with wp_get_environment_type() and shows a dismissible warning, plus a red dot in the admin bar
* Status panel reflects the real state: debug constants, server rules, detected environment, and whether wp-config.php is writable
* Removes its options and any leftover backup directory from older versions on uninstall

= Supported cache plugins =

* WP Rocket
* W3 Total Cache
* WP Super Cache
* WP Fastest Cache
* LiteSpeed Cache
* SiteGround Optimizer
* WP Optimize
* Hummingbird (WPMU DEV)
* Breeze (Cloudways)
* Autoptimize
* Cache Enabler
* Surge
* Redis Object Cache
* Powered Cache
* Comet Cache
* Swift Performance
* Nginx Helper
* NitroPack
* SpinupWP
* Docket Cache
* Object Cache Pro

= Supported optimization plugins =

* Perfmatters
* FlyingPress
* WP Asset CleanUp
* Object Cache 4 Everyone
* DietPress (WPO Tweaks)
* Clearfy Cache
* EWWW Image Optimizer
* ShortPixel Image Optimizer

= Supported hosting caches =

* SiteGround (via .htaccess environment variables and plugin API)
* Cloudflare (both new and legacy namespaces)
* Kinsta
* Varnish (opt-in, best-effort PURGE/BAN when detected)
* WP Engine
* Pantheon
* Batcache (Pressable)

== Installation ==

1. Upload the plugin files to `/wp-content/plugins/anticache/` directory
2. Activate the plugin through the 'Plugins' menu in WordPress
3. The plugin will automatically flush caches, enable debug mode, and inject .htaccess rules
4. Visit Tools > Anti-Cache Kit to manage options
5. **Important**: Deactivate when finished developing

== Frequently Asked Questions ==

= Is this safe to use on a live website? =

Yes, with caveats. PHP-level anti-cache measures only affect administrators. However, the .htaccess rules affect all visitors to ensure complete cache bypass. Use maintenance mode to show a status page to visitors during development. On production sites the plugin shows a clear warning so you do not forget it is active. Always deactivate when finished.

= Why does it deactivate optimization plugins? =

Optimization plugins like Perfmatters, FlyingPress, and WP Asset CleanUp modify how CSS, JS, and other assets are loaded. During debugging, you need to see the unmodified output to identify issues. These plugins are temporarily deactivated. Reactivate them manually from the Plugins page when you are done.

= What happens to my wp-config.php and .htaccess? =

The plugin edits both files in place. It wraps its own changes in clearly marked blocks and comments out (never deletes) any of your settings that conflict. On deactivation it removes only its own block and restores your original lines, so your own definitions are preserved. It never keeps a copy of wp-config.php on disk, so your database credentials are never exposed.

= Why don't I see the maintenance page? =

If you are logged in and can edit content, you see the site, not the page. Open a private window to see what visitors get.

If a private window still shows the normal site, a cache in front of WordPress is serving an old copy. The kit sends no-cache headers and server rules to get past hosting caches, proxies and CDNs, but some CDNs need a manual purge.

= Does it work on multisite? =

Yes, activated on each site. wp-config.php and .htaccess are shared by the whole network, so:

* Only a network administrator can make the kit change them.
* They go back as they were when the last site that changed them deactivates the kit.
* Cache plugins active for the whole network have to be deactivated by a network administrator.

= Can I use it from the terminal? =

Yes, with WP-CLI:

* `wp anticache status` shows what the kit changed.
* `wp anticache flush` empties every cache it knows.
* `wp anticache maintenance on` or `off` switches maintenance mode.
* `wp anticache off` deactivates the kit and reverts everything.
* `wp anticache expire 6` deactivates it by itself in 6 hours.

= What if I forget to deactivate it? =

Set an auto-deactivation time in the settings page (2, 6, 12 or 24 hours). The kit then deactivates itself and reverts its changes. It runs on WP-Cron, so on a site with no visits it waits for the next one.

= Can I customize the maintenance page? =

Yes. Use the `ayudawp_anticache_maintenance_data` filter to customize heading, status text, message, and retry text.

= Can I add support for custom cache plugins? =

Yes. Use the `ayudawp_anticache_cache_plugins` filter to add entries to the plugin list.

= The .htaccess rules show as "N/A" - why? =

Your server (nginx or Caddy) does not read .htaccess files, so the rules would have no effect and the kit does not write them. The settings panel shows an equivalent nginx snippet you can add to your server configuration and reload.

= How do I purge a Varnish cache? =

Enable "Purge Varnish" in the settings panel. When you flush caches, the kit detects Varnish from the response headers and sends a best-effort PURGE/BAN to your site root. It is off by default and never runs on servers without Varnish.

== Screenshots ==

1. Admin dashboard with status overview and quick actions
2. Detailed activation notice showing all changes made
3. Professional maintenance page for visitors
4. Unified admin bar indicator with maintenance toggle
5. Disabled plugins information panel

== Changelog ==

= 4.3.0 =
New: WP-CLI commands, an auto-deactivation timer, a debug.log viewer and optional debug constants. Also safer wp-config.php writes, exact reverts, working SiteGround, LiteSpeed, Cloudflare and Kinsta purges.

* New: WP-CLI commands to drive the kit from the terminal: wp anticache status, flush, maintenance on|off|status, on, off and expire
* New: auto-deactivation timer. Choose 2, 6, 12 or 24 hours and the kit deactivates itself and reverts everything, so it is not left active by mistake. It runs on WP-Cron
* New: debug log viewer on the settings page, with the last 200 lines of debug.log and a button to empty it. On a network only network administrators see it, because the log holds errors from every site
* New: optional debug constants, all off by default: SAVEQUERIES for Query Monitor, CONCATENATE_SCRIPTS off, WP_DEBUG_DISPLAY on and WP_DISABLE_FATAL_ERROR_HANDLER
* New: purges the page caches of WP Engine, Pantheon and Batcache (Pressable), and says which hosting caches it purged
* Improved: maintenance mode now lets anyone who can edit content see the site, so editors, authors and contributors can keep working. Customers, subscribers and visitors see the maintenance page. The settings page and the readme now say that the REST API and XML-RPC stay available during maintenance
* Improved: on a network, wp-config.php and the .htaccess go back as they were when the last site that changed them deactivates the kit, whoever deactivates it. Before, a subsite administrator deactivating the kit left WP_DEBUG and the no-cache rules on the whole network, and a network administrator deactivating it on one site undid them for the other sites still using it
* Improved: the settings page now says when WP_DEBUG, WP_CACHE or another debug constant is defined outside wp-config.php and the kit could not change it, and the kit's own definitions no longer raise a "Constant already defined" warning in that case
* Improved: the Varnish setting has its own Save button. Before, it was only saved along with another action
* Improved: the kit no longer spends a database query on every request on settings that did not exist yet, and deactivating or deleting it on a network cleans its settings on every site
* Fix: the SiteGround Optimizer, LiteSpeed Cache, Cloudflare and Kinsta purges did nothing, because those APIs had changed. They use the current ones now, and the WP Fastest Cache purge no longer starts a second copy of that plugin
* Fix: on a network, a cache plugin active for the whole network was left half deactivated: its deactivation routine ran while it stayed active. The kit now leaves it alone and says a network administrator has to deactivate it
* Fix: writing wp-config.php reset hardened permissions such as 0600 or 0640 to 0644, and replaced a symbolic link with a regular file. Both are kept now
* Fix: if writing wp-config.php failed halfway, for example with a full disk, the temporary copy with the database credentials could stay in the site root. It is always deleted now
* Fix: deactivating the kit changed blank lines in wp-config.php and the .htaccess outside its own block. Both files now go back exactly as they were, and a .htaccess the kit created on a site that had none is removed again
* Fix: the confirmation after Flush now or switching maintenance mode from the settings page never showed
* Fix: the status card showed WP_CACHE as ENABLED when it was not set at all
* Fix: on the settings page, admin notices landed inside the header, squeezed into narrow columns next to the title
* Fix: closing the red warning shown on production sites was not remembered, so it came back on the next screen. It is now remembered for each user, and the warning shows again when the kit is activated again, or after the site has run as another environment and returns to production. The red admin bar dot and the status card stay as they were
* Fix: removed the Tested up to line from the plugin file header, which Plugin Check reports as an error. The value stays in readme.txt
* Fix: the readme and the activation notice promised more than the kit does: not every cache plugin is flushed before it is deactivated, only the Object Cache 4 Everyone drop-in is removed, and deactivated plugins stay off after the kit is deactivated

For older changelog entries, please check the [changelog.txt](https://plugins.svn.wordpress.org/anticache/trunk/changelog.txt) file

== Upgrade Notice ==

= 4.3.0 =
New: WP-CLI commands, an auto-deactivation timer, a debug.log viewer and optional debug constants. Also safer wp-config.php writes, exact reverts, working SiteGround, LiteSpeed, Cloudflare and Kinsta purges.

== Developer Information ==

= Hooks and Filters =

* `ayudawp_anticache_maintenance_data` - Filter to customize maintenance page data (heading, status, message, retry)
* `ayudawp_anticache_cache_plugins` - Filter to modify the list of supported cache and optimization plugins
* `ayudawp_anticache_purge_varnish` - Filter to force the opt-in Varnish purge on or off (return true or false)

= Constants =

* `AYUDAWP_ANTICACHE_VERSION` - Plugin version
* `AYUDAWP_ANTICACHE_PLUGIN_DIR` - Plugin directory path
* `AYUDAWP_ANTICACHE_PLUGIN_URL` - Plugin directory URL
* `AYUDAWP_ANTICACHE_PLUGIN_BASENAME` - Plugin basename for hooks

= Code examples =

Customize maintenance page:

`add_filter( 'ayudawp_anticache_maintenance_data', function( $data ) {
    $data['heading'] = 'My Site Name';
    $data['status'] = 'Updating...';
    $data['message'] = 'We are deploying a new version. Back in a few minutes.';
    return $data;
} );`

Add a custom cache plugin:

`add_filter( 'ayudawp_anticache_cache_plugins', function( $plugins ) {
    $plugins['my-cache/my-cache.php'] = array(
        'name' => 'My Cache Plugin',
        'type' => 'cache',
    );
    return $plugins;
} );`

== Support ==

= Need private support or custom development? =
Do you need one-on-one help, priority troubleshooting, or a custom feature, integration, or tweak built specifically for your site? I offer private support and custom development. Just [contact me](mailto:anticache@ayudawp.com) and tell me what you need.

= Need help or have suggestions? =
* [Official website](https://servicios.ayudawp.com/)
* [WordPress support forum](https://wordpress.org/support/plugin/anticache/)
* [YouTube channel](https://www.youtube.com/AyudaWordPressES)
* [Documentation and tutorials](https://ayudawp.com/)

**Love the plugin?** Please leave us a 5-star review and help spread the word!

== About AyudaWP ==

We are specialists in WordPress security, SEO, and performance optimization plugins. We create tools that solve real problems for WordPress site owners while maintaining the highest coding standards and accessibility requirements.
