Skip to main content

Mutate or block outgoing webhook payloads per event

Free Intermediate Since v1.0.0

The outbound webhook system POSTs subscription/token events with a sha256= HMAC header. benecaster_webhook_payload runs once per event after the dispatcher assembles the payload, before signing. Add custom keys, redact fields, or return null to skip dispatch entirely. The signature is computed over whatever your filter returns, so receivers verify against the post-filter body. Webhook events: subscription.activated, subscription.cancelled, subscription.tier_changed, subscription.payment_failed, token.generated, token.reset. Raw token strings are never included in token.generated payloads — only token_id.

Code

<?php
// Add a tenant identifier to every outbound webhook.
add_filter( 'benecaster_webhook_payload', function ( ?array $payload, string $event ): ?array {
    if ( null === $payload ) {
        return null;
    }
    $payload['tenant'] = get_option( 'my_tenant_id' );
    return $payload;
}, 10, 2 );

// Skip webhook dispatch for a specific show.
add_filter( 'benecaster_webhook_payload', function ( ?array $payload ): ?array {
    if ( null === $payload || ( $payload['show_id'] ?? 0 ) === 42 ) {
        return null;
    }
    return $payload;
} );

View on GitHub →

Hooks Used

  • benecaster_webhook_payload