WP Webhooks / Docs / fswa_webhook_payload
Filter since v1.0.0

fswa_webhook_payload

Filters the per-webhook outgoing payload after field mapping, immediately before HTTP dispatch.

$

/ Signature

apply_filters( 'fswa_webhook_payload', $payload, $webhook_id, $trigger, $original_payload )

/ When it fires

Fires once per webhook delivery, after field mapping and type casting but before the HTTP request is sent. Also fires during synchronous dispatch and queue job execution.

/ Parameters

NameInTypeReqDescription
$payloadparamarrayyesThe mapped payload about to be dispatched.
$webhook_idparamintyesWebhook configuration ID.
$triggerparamstringyesThe WordPress action name.
$original_payloadparamarray|nullPre-mapping payload, or `null` if no mapping was applied.

/ Returns

array Modified payload. Must remain an array.

/ Examples

Inject site URL and current time into every delivery

add_filter( 'fswa_webhook_payload', function ( $payload, $webhook_id, $trigger, $original ) {
    $payload['_meta'] = [
        'site'      => home_url(),
        'sent_at'   => gmdate( 'c' ),
        'webhook'   => $webhook_id,
    ];
    return $payload;
}, 10, 4 );

Modify payload only for a specific webhook

add_filter( 'fswa_webhook_payload', function ( $payload, $webhook_id, $trigger, $original ) {
    if ( $webhook_id !== 42 ) return $payload;
    // Rename a field for this webhook only
    $payload['contact_email'] = $payload['billing_email'] ?? '';
    unset( $payload['billing_email'] );
    return $payload;
}, 10, 4 );

/ Related

Ready

Stop losing webhooks.
Start logging them.

$ wp plugin install flowsystems-webhook-actions --activate