manifest / unclassified / wp-torwald45-purgegate
Czyszczenie Cache Strony
WP mu-plugin: purge nginx FastCGI cache and Cloudflare cache by hostname from the admin bar
by synchronicity.one · github.com/synchronicity-one/wp-torwald45-purgegate
★ 0stars
0forks
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/synchronicity-one/wp-torwald45-purgegate/archive/refs/heads/main.zipMust-use plugin for WP sites served by nginx with FastCGI cache and optionally proxied by Cloudflare. Adds a "Wyczysc cache" button to the admin bar and WP-CLI commands that purge:
- the nginx FastCGI cache of the site (files are deleted, directories kept),
- the Cloudflare cache of the site hostname(s) - by hostname, never "purge everything", so other sites in the same zone are untouched.
nginx is purged first, then Cloudflare, so Cloudflare refetches pages that are already fresh at the origin.
Requirements
- The nginx cache directory is shared with the PHP container (for example a named volume mounted in both) and its files are owned by the PHP user.
- Cloudflare (optional): an API token with the single permission Zone > Cache Purge, limited to the zone of the site. Never a Global API Key.
Installation
Copy torwald45-purgegate.php to wp-content/mu-plugins/ and add to wp-config.php:
define( 'TORWALD45_PURGEGATE_NGINX_DIR', '/var/cache/nginx/fastcgi' );
// Optional - Cloudflare:
define( 'TORWALD45_PURGEGATE_CF_ZONE', 'ZONE_ID' );
define( 'TORWALD45_PURGEGATE_CF_TOKEN', 'API_TOKEN' );
// Optional - default is the host of home_url():
define( 'TORWALD45_PURGEGATE_CF_HOSTS', 'HOST1,HOST2' );
// Optional - default is manage_options:
define( 'TORWALD45_PURGEGATE_CAP', 'manage_options' );
WP-CLI
wp torwald45-purgegate status # configuration check, Cloudflare token verify
wp torwald45-purgegate purge # full purge
Safety
- Only users with the configured capability see the button; the request is protected by a nonce and rate limited (one purge per 10 seconds).
- The cache directory is resolved with realpath and refused when it points to a system directory or to the WP installation itself. Symlinks are not followed.
- Every purge is written to the PHP error log with the marker [torwald45-purgegate], including the user and the result.
- Action torwald45_purgegate_done fires after every purge with the result.
License
GPL-2.0-or-later