Filter uncanny-automator-pro

automator_pro_webhook_value_of_type_email

Filters the value for an email field when processing a webhook, allowing modification of the email data.

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

Description

Fires when a webhook value is identified as an email. Developers can filter this hook to modify or sanitize email values before they are processed by Uncanny Automator. The `$value` parameter contains the detected email address.


Usage

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

Parameters

$type (mixed)
This parameter contains the data type of the webhook value being processed, which is 'email' in this specific context.
$key (mixed)
This parameter is used to determine the expected data type of the webhook value.
$value (mixed)
This parameter holds the unique identifier or name associated with the webhook data.

Return Value

The filtered value.


Examples

<?php
/**
 * Example function to modify the email value before it's sent through a webhook.
 *
 * This function checks if the provided value is a valid email address and, if so,
 * can be used to prepend or append a string to the email address, or to completely
 * replace it with a default if it's deemed invalid by custom logic.
 *
 * @param mixed $type  The current type of the value (should be 'email' when this filter is applied).
 * @param mixed $key   The key associated with the value in the webhook data.
 * @param mixed $value The email value itself.
 * @return mixed The modified or original email value.
 */
add_filter(
	'automator_pro_webhook_value_of_type_email',
	function( $type, $key, $value ) {
		// Example: Prepend a string to the email address for a specific key.
		if ( 'user_email' === $key ) {
			$value = 'processed_' . $value;
		}

		// Example: Append a string to the email address for a different key.
		if ( 'admin_notification_email' === $key ) {
			$value = $value . '_sent';
		}

		// Example: If a specific key's email is empty or invalid according to custom rules,
		// return a default safe email. This would require more robust validation than is_email().
		// For demonstration, we'll just check if it's empty.
		if ( 'recipient_email' === $key && empty( $value ) ) {
			$value = '[email protected]';
		}

		// Always return the value, whether modified or not.
		return $value;
	},
	10, // Priority
	3  // Number of accepted arguments
);

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

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