Filter uncanny-automator-pro

automator_pro_webhook_value_of_type_int

Filters the value of an integer type webhook field to modify or sanitize it before processing.

add_filter( 'automator_pro_webhook_value_of_type_int', $callback, 10, 3 );

Description

Fires when a webhook value is identified as an integer. Developers can use this hook to modify the detected type or the integer value before it's processed. This filter provides granular control over how numeric webhook data is interpreted and used by Uncanny Automator.


Usage

add_filter( 'automator_pro_webhook_value_of_type_int', 'your_function_name', 10, 3 );

Parameters

$type (mixed)
This parameter represents the data type of the webhook value.
$key (mixed)
This parameter specifies the desired data type for the webhook value, defaulting to 'text'.
$value (mixed)
This parameter represents the unique identifier or name associated with the webhook data.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to use the automator_pro_webhook_value_of_type_int filter.
 *
 * This filter allows you to modify the detected type and value when Uncanny Automator Pro
 * identifies a webhook value as an integer. For instance, you might want to ensure
 * that certain values are always treated as strings, or perhaps perform some
 * sanitization on the integer value itself.
 *
 * @param mixed $type The detected type of the webhook value (will be 'int' in this context).
 * @param mixed $key The key associated with the webhook value.
 * @param mixed $value The actual webhook value, which is numeric.
 *
 * @return mixed The modified type and/or value.
 */
add_filter(
	'automator_pro_webhook_value_of_type_int',
	function ( $type, $key, $value ) {
		// Example: If a specific key ('user_id') is detected as an integer,
		// and its value is negative, perhaps we should log an issue or
		// treat it as a string to avoid unexpected behavior in subsequent steps.
		if ( 'user_id' === $key && $value < 0 ) {
			// Log a warning for negative user IDs, as this might be erroneous.
			error_log(
				sprintf(
					'Uncanny Automator Pro: Detected negative user_id (%s) via webhook. Treating as string.',
					$value
				)
			);
			// Force the type to string if the user ID is negative.
			return array( 'string', (string) $value );
		}

		// Example: For any other integer value, we might want to ensure it's a standard PHP integer.
		// The default logic should handle this, but this shows how you could modify it.
		// If you don't want to change the type or value, simply return them as they are.
		return array( $type, (int) $value );
	},
	10, // Priority
	3   // Accepted args
);

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:613

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 );
	}


Scroll to Top