Filter uncanny-automator-pro

automator_pro_webhook_value_of_type_text

Filters the value of a text type webhook field before it's processed, allowing modification of its content.

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

Description

Fires when a webhook value is determined to be of type 'text'. Allows developers to modify the detected type, key, or value before it's processed. Useful for custom type detection or value manipulation for non-URL text data.


Usage

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

Parameters

$type (mixed)
This parameter represents the data type of the webhook value, defaulting to 'text' but can be changed to 'email' or 'array' based on the value's format.
$key (mixed)
This parameter specifies the intended data type for the webhook value, defaulting to 'text'.
$value (mixed)
This parameter represents the key or identifier for the webhook data.

Return Value

The filtered value.


Examples

add_filter( 'automator_pro_webhook_value_of_type_text', 'my_automator_pro_webhook_text_handler', 10, 3 );

/**
 * Example handler for the automator_pro_webhook_value_of_type_text filter.
 * This function demonstrates how to modify or process text-based webhook values.
 *
 * @param mixed $type  The current determined type of the value. Expected to be 'text' in this context.
 * @param mixed $key   The key associated with the webhook value.
 * @param mixed $value The actual text value from the webhook.
 *
 * @return mixed The potentially modified text value.
 */
function my_automator_pro_webhook_text_handler( $type, $key, $value ) {

	// Example: Sanitize the text value to prevent potential XSS issues.
	// In a real-world scenario, you might also want to trim whitespace or
	// convert to a specific case depending on your needs.
	$sanitized_value = sanitize_text_field( $value );

	// Example: If the key is 'user_comment', append a prefix to it.
	if ( 'user_comment' === $key ) {
		$sanitized_value = 'User Submitted: ' . $sanitized_value;
	}

	// It's crucial to return the (potentially modified) value.
	// The original $type parameter is unlikely to be changed here, as this hook
	// is specifically for 'text' types, but we pass it along as per the hook definition.
	return $sanitized_value;
}

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

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