Filter
uncanny-automator-pro
automator_pro_webhook_value_of_type_array
Filters webhook values of type array before they are processed by Automator Pro.
add_filter( 'automator_pro_webhook_value_of_type_array', $callback, 10, 3 );
Description
Fires when a webhook value is detected as an array or object. Developers can filter to change the detected type or modify the key and value before it's processed. This hook allows for custom handling of complex webhook data structures.
Usage
add_filter( 'automator_pro_webhook_value_of_type_array', 'your_function_name', 10, 3 );
Parameters
-
$type(mixed) - This parameter specifies the initial type, defaulting to 'text', which may be modified by the filter.
-
$key(mixed) - The type of the webhook value, defaulting to 'text' but can be 'email' if the value is detected as an email address.
-
$value(mixed) - This parameter represents the key or identifier associated with the webhook value.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to filter the 'automator_pro_webhook_value_of_type_array' hook.
*
* This function intercepts webhook values that are arrays or objects and modifies
* the 'type' parameter based on certain conditions.
*
* @param string $type The default type, usually 'text'.
* @param string $key The key of the webhook data.
* @param array $value The array or object value from the webhook.
*
* @return string The modified or original type.
*/
function my_automator_webhook_array_type_filter( $type, $key, $value ) {
// If the key is 'user_data' and the value is an array,
// we want to treat it specifically as a 'json' type for better handling later.
if ( 'user_data' === $key && is_array( $value ) ) {
return 'json';
}
// If any of the values within the array contain a specific identifier,
// let's mark the whole array as 'complex_data'.
foreach ( $value as $item ) {
if ( is_array( $item ) && isset( $item['special_flag'] ) && true === $item['special_flag'] ) {
return 'complex_data';
}
}
// Otherwise, return the original type.
return $type;
}
// Add the filter to WordPress.
// We are accepting all 3 parameters ($type, $key, $value) that the hook provides.
add_filter( 'automator_pro_webhook_value_of_type_array', 'my_automator_webhook_array_type_filter', 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:595
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 );
}