Programmatically Purging Cached Images from Cloudflare - Another Janky Wordpress Plugin
In which we participate in The Purge
On 75CentralPhotography, we use Cloudflare caching to serve our photos fast and efficiently with reduced strain/traffic on our origin server.
This works great until we make a small edit to an existing photo and replace the original on the site with the edited version. When this happens, Cloudflare doesn't immediately know about the change and will continue to server their cached version instead of the new version. To ameliorate this, Cloudflare does allow you to either completely purge your cache (not great) or purge individual assets (better, but still requires manual intervention on your Cloudflare dashboard).
To make the experience even easier, we developed a Wordpress plugin that automatically handles the purging for you.
Introducing Cloudflare Purger: Advanced WordPress Cache Management Plugin
Why We Built This Plugin
Traditional WordPress cache management falls short when dealing with image-heavy content and CDN integration. Content creators and developers often face:
- Stale image content after uploading new media
- Manual cache purging workflows that slow down publishing
- Complex API integrations requiring technical expertise
- Limited visibility into cache operations and failures
Cloudflare Purger solves these challenges with intelligent automation and an intuitive interface that works for both technical and non-technical users.
Key Features
Intelligent Image Detection & Purging
- Automatic detection of all images in posts (Block Editor & Classic Editor)
- Complete size variant purging (thumbnails, medium, large, custom sizes)
- Attached media processing for galleries and featured images
- Asynchronous operations to prevent site slowdown
Professional Admin Interface
- Secure credential management for Cloudflare Zone ID and API Token
- Real-time connection testing with detailed feedback
- Bulk URL purging with copy-paste functionality
- Manual cache management tools for immediate control
Enterprise-Grade Monitoring
- Comprehensive logging system tracking all purge operations
- Success/failure status tracking with detailed error messages
- Admin dashboard showing recent activity and statistics
- Debug-friendly output for troubleshooting
Flexible Integration Options
- WordPress hook system integration for custom post types
- WooCommerce compatibility for product image management
- Advanced Custom Fields (ACF) support for custom image fields
- Developer-friendly API for programmatic control
Real-World Use Cases
Content Publishers
- Blog posts with multiple images automatically purged on publish
- Featured image updates immediately reflected across all CDN nodes
- Gallery updates trigger intelligent cache invalidation
E-Commerce Sites
- Product image updates instantly visible to customers
- Inventory photo changes reflected without manual intervention
- Bulk product updates with automated cache management
Development Teams
- Staging-to-production deployments with automated cache clearing
- Custom post type integration for specialized content
- API-driven cache management for headless WordPress setups
Performance Impact
Our testing shows significant improvements in content freshness:
- Zero manual cache operations needed for standard workflows
- Instant visibility of content changes across global CDN
- Background processing maintains site performance during purge operations
Getting Started
Installation
- Download the latest release from Github
- Upload the plugin to
/wp-content/plugins/ - Activate through the WordPress admin
- Navigate to Settings → Cloudflare Purger
- Configure your Cloudflare Zone ID and API Token (see section below on how to get these)
- Save!
Getting Your Cloudflare Credentials
Zone ID
- Log into your Cloudflare dashboard
- Select your domain
- Scroll down to the "API" section on the right sidebar
- Copy the "Zone ID"
API Token
- Go to Cloudflare → My Profile → API Tokens
- Click "Create Token"
- Use the "Custom token" template
- Configure permissions:
- Zone:Zone:Read (to verify the zone)
- Zone:Cache Purge:Edit (to purge cache)
- Set Zone Resources to include your specific zone
- Create the token and copy it immediately
Advanced Usage
For developers, the plugin provides extensive programmatic control:
<?php
// Manual purge for custom scenarios
$purger = CloudflarePurger::get_instance();
$purger->purge_cloudflare_cache($image_urls, 'custom_operation');
// Integration with custom post types
add_action('save_post', function($post_id) {
if (get_post_type($post_id) === 'portfolio') {
$purger->purge_post_images($post_id);
}
});Feel free to make improvements and submit PRs at the repository for inclusion in future releases.