=== Rocket Cloudflare Edge Cache Sync Helper === Contributors: nikolaosgiannopoulos Tags: cloudflare, cache, wp-rocket, edge-caching, performance Requires at least: 5.9 Tested up to: 6.9 Requires PHP: 7.4 Stable tag: 1.0.0 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Automatically sync WP Rocket cache exclusions to Cloudflare Cache Rules for seamless edge caching with WordPress dynamic content protection. == Description == Rocket Cloudflare Edge Cache Sync Helper bridges the gap between WP Rocket's page caching and Cloudflare's edge cache. It automatically generates and deploys Cloudflare Cache Rules based on your WP Rocket exclusion settings, ensuring dynamic content is never cached at the edge. **Key Features:** * **Automatic Sync** — Monitors WP Rocket settings and automatically updates Cloudflare Cache Rules * **Deferred Execution** — API calls run in the background to avoid blocking page loads * **Smart Change Detection** — Only deploys when expression changes, minimizing API calls * **Retry Logic** — Exponential backoff for failed deployments with configurable retry limits * **WooCommerce Integration** — Automatically excludes cart, checkout, and account pages * **WPML Support** — Detects translated pages and excludes all language variants * **Admin Bar Toggle** — Quick enable/disable of the Cloudflare cache rule * **WP-CLI Commands** — Manual sync, status checks, log viewing, and reset operations * **Secure Logging** — File-based logs with secret masking and protected directory **How It Works:** 1. Reads WP Rocket's "Never Cache" settings (URIs, cookies, query parameters) 2. Adds WordPress core exclusions (wp-admin, wp-login, etc.) 3. Detects WooCommerce and WPML pages automatically 4. Builds a Cloudflare Cache Rules expression 5. Deploys to Cloudflare via API (or updates existing rule) 6. Monitors for changes and re-syncs automatically **Requirements:** * WP Rocket plugin (active) * Cloudflare account with Zone ID and API credentials * WordPress 5.9 or higher * PHP 7.4 or higher == Installation == 1. Install and activate WP Rocket 2. Upload this plugin to `/wp-content/plugins/` or install via WordPress admin 3. Activate the plugin 4. Configure Cloudflare credentials in WP Rocket settings or via constants 5. Visit **Tools → CF Edge Cache Sync** to view status and trigger manual sync **Cloudflare Credentials:** Option 1: Use WP Rocket's Cloudflare settings (recommended) Option 2: Define constants in `wp-config.php`: Using API Key: ` define('WP_ROCKET_CF_API_KEY', 'your-global-api-key'); define('CLOUDFLARE_ZONE_ID', 'your-zone-id'); ` Or use an API Token (preferred): ` define('WP_ROCKET_CF_API_TOKEN', 'your-api-token'); define('CLOUDFLARE_ZONE_ID', 'your-zone-id'); ` == Frequently Asked Questions == = Does this work without WP Rocket? = No, WP Rocket is required. This plugin reads WP Rocket's cache exclusion settings and syncs them to Cloudflare. = Will this affect my existing Cloudflare cache rules? = The plugin creates and manages a single "WP Rocket Sync" cache rule. All other rules in your Cloudflare ruleset are preserved. = What happens if the Cloudflare API fails? = The plugin implements exponential backoff retry logic. Failed deployments are retried automatically with increasing delays (5min, 15min, 1hr, 6hr, 24hr). After 5 failures, you'll see an admin notice. = Can I customize the exclusions? = Yes! Use these filters in your theme or plugin: * `wpr_cf_sync_excluded_paths` — Add custom path exclusions * `wpr_cf_sync_excluded_cookies` — Add custom cookie exclusions * `wpr_cf_sync_excluded_query_params` — Add custom query parameter exclusions = How do I manually trigger a sync? = Visit **Tools → CF Edge Cache Sync** and click "Sync Now", or use WP-CLI: `wp wpr-cf sync` = Where are the logs stored? = Logs are stored in `wp-content/uploads/wpr-cloudflare-sync-{hash}/` with `.htaccess` protection. View them via the admin page or WP-CLI: `wp wpr-cf logs --lines=100` == Screenshots == 1. Admin page showing sync status, expression preview, and diff panel 2. Admin bar quick toggle for enabling/disabling the cache rule 3. WP-CLI commands for manual sync and status checks == Changelog == = 1.0.0 = * Initial release * Automatic sync of WP Rocket exclusions to Cloudflare Cache Rules * WooCommerce and WPML integration * Deferred sync with retry logic * Admin page with expression preview and diff * Admin bar toggle * WP-CLI commands * Secure logging with secret masking == Upgrade Notice == = 1.0.0 = Initial release. == Developer Hooks == **Filters:** * `wpr_cf_sync_excluded_paths` — Modify path exclusions * `wpr_cf_sync_excluded_cookies` — Modify cookie exclusions * `wpr_cf_sync_excluded_query_params` — Modify query parameter exclusions **Actions:** * `wpr_cf_sync_deployed` — Fires after successful deployment to Cloudflare * `wpr_cf_sync_failed` — Fires when deployment fails * `wpr_cf_purge_success` — Fires after successful cache purge * `wpr_cf_purge_failed` — Fires when cache purge fails **WP-CLI Commands:** * `wp wpr-cf sync [--force] [--dry-run]` — Run sync pipeline * `wp wpr-cf status` — Show current status * `wp wpr-cf logs [--lines=50]` — View recent logs * `wp wpr-cf reset [--confirm] [--delete-rule]` — Reset state == Privacy Policy == This plugin does not collect or transmit any user data. It communicates only with the Cloudflare API using credentials you provide. Logs are stored locally on your server and contain no personally identifiable information.