Filter
uncanny-automator-pro
automator_pro_webhook_value_of_type_url
Filters the value of a webhook field specifically for the URL type.
add_filter( 'automator_pro_webhook_value_of_type_url', $callback, 10, 3 );
Description
Fires after a webhook value is identified as a URL. Developers can use this filter to modify the determined type (though it will always be 'url' here) or the value itself before it's processed further. This hook is useful for sanitizing or transforming URL data received from webhooks.
Usage
add_filter( 'automator_pro_webhook_value_of_type_url', 'your_function_name', 10, 3 );
Parameters
-
$type(mixed) - This parameter specifies the data type of the webhook value being processed.
-
$key(mixed) - This parameter specifies the data type of the webhook value being processed.
-
$value(mixed) - This parameter represents the key or identifier associated with the webhook value.
Return Value
The filtered value.
Examples
/**
* Example: Modify the URL value when it's identified as a URL type by Uncanny Automator Pro.
*
* This filter allows you to alter the URL before it's processed or sent.
* For instance, you might want to prepend a protocol if it's missing or
* append a query parameter for tracking purposes.
*
* @param mixed $type The detected type, which will be 'url' in this case.
* @param mixed $key The key associated with the webhook value.
* @param mixed $value The actual URL value.
*
* @return mixed The potentially modified URL value.
*/
add_filter( 'automator_pro_webhook_value_of_type_url', function( $type, $key, $value ) {
// Only proceed if the value is indeed a string and looks like a URL.
if ( is_string( $value ) && filter_var( $value, FILTER_VALIDATE_URL ) ) {
// Example: Ensure the URL has a protocol (e.g., prepend 'https://' if missing).
if ( ! preg_match( '/^https?:///i', $value ) ) {
$value = 'https://' . $value;
}
// Example: Append a dummy tracking parameter for demonstration.
// In a real-world scenario, this might be a unique identifier or a date.
$tracking_param = 'utm_source=automator';
$value = add_query_arg( $tracking_param, null, $value );
}
// Always return the value (potentially modified) to allow Uncanny Automator Pro to use it.
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
uncanny-automator-pro/src/core/webhook/webhook-common-options.php:619
public static function value_maybe_of_type( $key, $value ) {
$type = 'text';
if ( is_array( $value ) || is_object( $value ) ) {
return apply_filters( 'automator_pro_webhook_value_of_type_array', $type, $key, $value );
}
if ( is_email( $value ) ) {
$type = 'email';
return apply_filters( 'automator_pro_webhook_value_of_type_email', $type, $key, $value );
}
if ( is_float( $value ) ) {
$type = 'float';
return apply_filters( 'automator_pro_webhook_value_of_type_float', $type, $key, $value );
}
if ( is_numeric( $value ) ) {
$type = 'int';
return apply_filters( 'automator_pro_webhook_value_of_type_int', $type, $key, $value );
}
if ( wp_http_validate_url( $value ) ) {
$type = 'url';
return apply_filters( 'automator_pro_webhook_value_of_type_url', $type, $key, $value );
}
return apply_filters( 'automator_pro_webhook_value_of_type_text', $type, $key, $value );
}