Filter
uncanny-automator
automator_send_webhook_remote_headers
Filters webhook headers before sending, allowing modification of request details and data.
add_filter( 'automator_send_webhook_remote_headers', $callback, 10, 3 );
Description
Fires before remote webhook headers are sent, allowing developers to modify or add custom headers. This hook receives the current headers, webhook data, and the webhook object. Use it to control authentication, content types, or other request-specific headers for your outgoing webhooks.
Usage
add_filter( 'automator_send_webhook_remote_headers', 'your_function_name', 10, 3 );
Parameters
-
$headers(mixed) - This parameter contains the headers that will be sent with the webhook request.
-
$data(mixed) - This parameter contains the headers that will be sent with the webhook request.
-
$this(mixed) - This parameter contains the data that will be sent in the webhook request.
Return Value
The filtered value.
Examples
/**
* Example of how to modify webhook headers.
* This function will add a custom header to outgoing webhook requests.
*
* @param array $headers The existing headers for the webhook request.
* @param array $data The data being sent in the webhook request.
* @param object $automator_instance The instance of the Automator class making the request.
*
* @return array Modified headers.
*/
add_filter(
'automator_send_webhook_remote_headers',
function ( $headers, $data, $automator_instance ) {
// Ensure $headers is an array before attempting to add to it.
if ( ! is_array( $headers ) ) {
$headers = array();
}
// Add a custom authentication token if it exists in the trigger/recipe settings.
// This is a hypothetical example; the actual way to retrieve such a token
// would depend on how your plugin stores and accesses this information.
$api_token = get_post_meta( $automator_instance->get_recipe_id(), '_my_custom_api_token', true );
if ( ! empty( $api_token ) ) {
$headers['X-My-Custom-Auth'] = 'Bearer ' . $api_token;
}
// Add another custom header, perhaps to identify the source of the webhook.
$headers['X-Automator-Source'] = 'WordPress-' . get_bloginfo( 'name' );
return $headers;
},
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/recipe-parts/trait-webhooks.php:135
'timeout' => '30',
),
$data,
$this
);
if ( ! empty( $headers ) ) {
$args['headers'] = apply_filters( 'automator_send_webhook_remote_headers', $headers, $data, $this );
}
try {
// Get response header
$response = Automator_Send_Webhook::call_webhook( $webhook_url, $args, $request_type );