CDN Integration
Using action hooks to integrate Picture Optimizer with CDN and caching systems.
Overview
Picture Optimizer fires WordPress action hooks after image replacement and revert operations. These hooks allow CDN plugins, caching systems, and custom integrations to respond to image changes automatically.
Available Hooks
After Image Replacement
Parameters:
| Parameter | Type | Description |
|---|---|---|
$attachment_id | int | WordPress attachment post ID |
$old_url | string | The original image URL before replacement |
$new_url | string | The new image URL after replacement |
$backup_path | string | Relative path to the backup file in image-forge-originals/ |
After Image Revert
Parameters:
| Parameter | Type | Description |
|---|---|---|
$attachment_id | int | WordPress attachment post ID |
$restored_url | string | The restored original image URL |
Example: CDN Cache Purge
Cloudflare
WP Super Cache
W3 Total Cache
Example: Custom Logging
Where to Add Hook Code
Add your hook code to one of these locations:
- Theme's
functions.php— Simple but lost on theme change - Custom plugin — Recommended for production
- Code Snippets plugin — Easy to manage without file editing
Hooks fire synchronously during the AJAX request. Keep hook callbacks fast to avoid slowing down the image replacement process. For heavy operations (like external API calls), consider using wp_schedule_single_event() to defer the work.
