Filter
uncanny-automator
automator_send_webhook_data_format
Filters the data array before sending a webhook, allowing modification of fields, original data, and data type.
add_filter( 'automator_send_webhook_data_format', $callback, 10, 3 );
Description
Filters the data format before a webhook is sent. Developers can modify the webhook data (e.g., change JSON formatting, alter array structures) for specific integrations or advanced use cases. This hook runs just before the webhook payload is finalized.
Usage
add_filter( 'automator_send_webhook_data_format', 'your_function_name', 10, 3 );
Parameters
-
$fields(mixed) - This parameter contains the data that will be formatted and sent in the webhook.
-
$original(mixed) - This parameter contains the data that will be formatted and sent in the webhook.
-
$data_type(mixed) - This parameter holds the original, unformatted data that was passed to the webhook, allowing for comparison or reversion if needed.
Return Value
The filtered value.
Examples
<?php
/**
* Example: Modify the webhook data format for specific data types.
*
* This example demonstrates how to intercept the webhook data and
* conditionally change its format based on the $data_type.
* In this case, if the data_type is 'user_meta_update', it will
* ensure the output is JSON encoded with pretty printing.
* Otherwise, it falls back to the original data.
*
* @param mixed $fields The webhook data fields.
* @param mixed $original The original webhook data.
* @param mixed $data_type The type of data being sent.
* @return mixed The potentially modified webhook data.
*/
add_filter( 'automator_send_webhook_data_format', function( $fields, $original, $data_type ) {
// Only modify if the data type is specifically 'user_meta_update'
if ( 'user_meta_update' === $data_type ) {
// Ensure the fields are JSON encoded with pretty printing for this specific data type.
// This assumes $fields is an array or object that can be JSON encoded.
if ( is_array( $fields ) || is_object( $fields ) ) {
$fields = wp_json_encode( $fields, JSON_PRETTY_PRINT );
} else {
// If it's not an array or object, fall back to the original.
$fields = $original;
}
}
// For any other data type, the default handling or previous filters will apply.
// We still need to return $fields to allow further filtering or the default action.
return $fields;
}, 10, 3 );
?>
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/core/lib/webhooks/class-automator-send-webhook.php:768
$fields = wp_json_encode( $fields, JSON_PRETTY_PRINT );
} else {
$fields = $original;
}
break;
}
return apply_filters( 'automator_send_webhook_data_format', $fields, $original, $data_type );
}
/**
* Convert comma separated array values in to binary
*
* @param $string
*