Filter
uncanny-automator
automator_outgoing_webhook_value_of_type_url
Filters the value of a URL field for outgoing webhooks, allowing modification before it's sent.
add_filter( 'automator_outgoing_webhook_value_of_type_url', $callback, 10, 3 );
Description
Fires when an outgoing webhook value is identified as a URL. Developers can filter the detected type, key, and the URL value itself before it's sent. This allows for modification or validation of URL data in outgoing webhooks.
Usage
add_filter( 'automator_outgoing_webhook_value_of_type_url', 'your_function_name', 10, 3 );
Parameters
-
$type(mixed) - This parameter specifies the determined data type of the webhook value, defaulting to 'text'.
-
$key(mixed) - This parameter specifies the data type of the webhook value, defaulting to 'text'.
-
$value(mixed) - This parameter represents the key associated with the webhook value.
Return Value
The filtered value.
Examples
/**
* Modify outgoing webhook URL values to append a UTM parameter for tracking.
*
* This filter hook allows developers to manipulate the value of an outgoing webhook
* when the value is identified as a URL. In this example, we're adding a specific
* UTM parameter to help track the source of the request originating from this webhook.
*/
add_filter( 'automator_outgoing_webhook_value_of_type_url', function( $type, $key, $value ) {
// Ensure the value is indeed a URL and not empty before attempting to modify.
if ( ! empty( $value ) && wp_http_validate_url( $value ) ) {
// Define the UTM parameters to append.
$utm_source = 'automator';
$utm_medium = 'webhook';
$utm_campaign = 'lead_generation';
// Build the query string for the UTM parameters.
$utm_query = http_build_query( array(
'utm_source' => $utm_source,
'utm_medium' => $utm_medium,
'utm_campaign' => $utm_campaign,
) );
// Append the UTM parameters to the existing URL.
// Use '?' if the URL has no existing query string, '&' otherwise.
$separator = ( strpos( $value, '?' ) === false ) ? '?' : '&';
$value .= $separator . $utm_query;
}
// Always return the modified or original value.
return $value;
}, 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:1107
public static function value_maybe_of_type( $key, $value ) {
$type = 'text';
if ( is_array( $value ) || is_object( $value ) ) {
return apply_filters( 'automator_outgoing_webhook_value_of_type_array', $type, $key, $value );
}
if ( is_email( $value ) ) {
$type = 'email';
return apply_filters( 'automator_outgoing_webhook_value_of_type_email', $type, $key, $value );
}
if ( is_float( $value ) ) {
$type = 'float';
return apply_filters( 'automator_outgoing_webhook_value_of_type_float', $type, $key, $value );
}
if ( is_numeric( $value ) ) {
$type = 'int';
return apply_filters( 'automator_outgoing_webhook_value_of_type_int', $type, $key, $value );
}
if ( wp_http_validate_url( $value ) ) {
$type = 'url';
return apply_filters( 'automator_outgoing_webhook_value_of_type_url', $type, $key, $value );
}
return apply_filters( 'automator_outgoing_webhook_value_of_type_text', $type, $key, $value );
}