Filter
uncanny-automator-pro
automator_pro_webhook_value_of_type_float
Filters webhook float values before saving, allowing modification of the numeric type and content.
add_filter( 'automator_pro_webhook_value_of_type_float', $callback, 10, 3 );
Description
Fires after a webhook value is identified as a float. Developers can filter the `$type`, `$key`, and `$value` parameters to modify the detected type or its associated data before it's processed by Uncanny Automator. This hook is essential for custom handling of float webhook data.
Usage
add_filter( 'automator_pro_webhook_value_of_type_float', 'your_function_name', 10, 3 );
Parameters
-
$type(mixed) - This parameter specifies the data type, defaulting to 'text', which can be filtered by the hook.
-
$key(mixed) - This parameter specifies the initial data type, which defaults to 'text'.
-
$value(mixed) - This parameter contains the key associated with the webhook value.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to filter the 'automator_pro_webhook_value_of_type_float' hook.
*
* This function modifies the value of a float type webhook data if it meets a specific condition.
* For instance, it could ensure that a price is always rounded to two decimal places.
*
* @param string $type The current detected type of the value (will be 'float' when this filter is applied).
* @param string $key The key associated with the webhook value.
* @param float $value The actual float value from the webhook.
* @return float|int The modified float or integer value.
*/
function my_automator_pro_filter_float_webhook_value( $type, $key, $value ) {
// Example: If the key is 'product_price', ensure it's rounded to 2 decimal places.
if ( 'product_price' === $key ) {
return round( $value, 2 );
}
// Example: If the key is 'discount_percentage', ensure it doesn't exceed 100.
if ( 'discount_percentage' === $key ) {
return min( $value, 100.0 );
}
// Return the original value if no specific modification is needed for this key.
return $value;
}
add_filter( 'automator_pro_webhook_value_of_type_float', 'my_automator_pro_filter_float_webhook_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:607
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 );
}