OCMLABS/MODULE-WORDPRESS · WEBHOOK SYSTEM

How WordPress webhooks trigger Magento cache purges

  • Magento
  • Adobe Commerce
  • Hyvä

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 HookEvent SentObject Type
save_postpost_created or post_updatedpost or page
delete_postpost_deletedpost or page
wp_update_nav_menumenu_updatednav_menu
edited_termterm_updatedcategory or post_tag
delete_termterm_deletedcategory or post_tag

Post revisions and autosaves do not trigger webhooks.

Webhook Payload

JSON
{
  "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...
CAUTION /

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/cachepurge

Enter 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_typeCache Tags Purged
postWORDPRESS_POST, WORDPRESS_POST_{object_id}
pageWORDPRESS_POST, WORDPRESS_POST_{object_id}
categoryWORDPRESS_CATEGORY
post_tagWORDPRESS_TAG
nav_menuWORDPRESS_MENU

See also

Related pages

In this module