How WordPress webhooks trigger Magento cache purges
The OCMLabs Content Bridge for Magento plugin sends signed HTTP POST requests to Magento whenever WordPress content changes. Magento uses these webhooks to purge only the affected cache entries, in both the module’s data cache and the full page cache (built-in or Varnish), so an edit in WordPress shows on the storefront on the next page load without a full cache flush.
WordPress Hooks That Trigger Webhooks
| WordPress Hook | Event Sent | Object Type |
|---|---|---|
save_ | post_ or post_ | post or page |
delete_ | post_ | post or page |
wp_ | menu_ | nav_ |
edited_ | term_ | category or post_ |
delete_ | term_ | category or post_ |
Post revisions and autosaves do not trigger webhooks.
Webhook Payload
{
"event": "post_updated",
"object_type": "post",
"object_id": 42,
"slug": "my-post-slug",
"timestamp": 1700000000
} HMAC-SHA256 Signing
Each webhook is signed with HMAC-SHA256 using the Webhook Secret from the plugin settings, or the API key when no Webhook Secret is set. The signature is sent in the X-OC-Bridge-Signature header:
X-OC-Bridge-Signature: abc123def456...On the Magento side, Controller/Webhook/CachePurge.php verifies the signature by computing the HMAC-SHA256 of the raw request body using the Magento Webhook Secret (or the API key when it is empty) and comparing with hash_equals(). The secret must match on both sides. An invalid signature returns 401; a webhook received while Enable Webhook Cache Purge is set to No returns 403.
Magento Webhook Endpoint
The Magento webhook controller listens at:
POST /wordpress/webhook/cachepurgeEnter this URL in the WordPress plugin settings as the Magento Webhook URL.
Non-Blocking Delivery
Webhooks are sent using wp_remote_post() with blocking: false. This means the webhook is dispatched asynchronously - WordPress does not wait for Magento’s response before continuing. The webhook timeout is 10 seconds.
Cache Tag Mapping
After verifying the webhook signature, Magento maps the object_type to cache tags and purges them from the module’s data cache. Since 2.0.3 it then dispatches clean_cache_by_tags with the same tags, which purges every full page cache entry that carries them: blog pages, the blog sidebar, the blog widgets and the WordPress menu. See Cache Tags.
object_type | Cache Tags Purged |
|---|---|
post | WORDPRESS_, WORDPRESS_ |
page | WORDPRESS_, WORDPRESS_ |
category | WORDPRESS_ |
post_ | WORDPRESS_ |
nav_ | WORDPRESS_ |
See also
Related pages
- Enable webhook cache purge in Magento
- Cache tags and how they map to webhook object types
- Webhook purge returns 403