Filter uncanny-automator

automator_outgoing_webhook_value_of_type_text

Filters the value of a specific text field before it's sent in an outgoing webhook.

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

Description

Fires when an outgoing webhook value is of type 'text'. Developers can modify the 'text' value, its type, or key before it's sent. This hook is crucial for sanitizing or transforming plain text data in outgoing webhooks.


Usage

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

Parameters

$type (mixed)
This parameter represents the intended data type of the outgoing webhook value, which is typically 'text' by default.
$key (mixed)
This parameter specifies the expected data type for the outgoing webhook value, defaulting to 'text'.
$value (mixed)
This parameter holds the key or name associated with the webhook data.

Return Value

The filtered value.


Examples

/**
 * Example of how to modify the value of type 'text' for an outgoing webhook.
 *
 * This function demonstrates how you might append some additional information
 * to a text value before it's sent in a webhook, for instance, adding a
 * timestamp or a unique identifier.
 *
 * @param mixed $type  The determined type of the webhook value (in this case, 'text').
 * @param mixed $key   The key associated with the webhook data.
 * @param mixed $value The original text value to be potentially modified.
 *
 * @return mixed The modified or original text value.
 */
add_filter( 'automator_outgoing_webhook_value_of_type_text', function( $type, $key, $value ) {
	// Ensure we are dealing with a text type and the value is a string.
	if ( 'text' === $type && is_string( $value ) ) {
		// Example: Append a custom identifier or a timestamp to the text value.
		// In a real-world scenario, this might be dynamically generated.
		$additional_info = '_processed_' . current_time( 'timestamp' );
		$modified_value = $value . $additional_info;

		// Return the modified value.
		return $modified_value;
	}

	// If it's not a text type or not a string, return the original value.
	return $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

src/core/lib/webhooks/class-automator-send-webhook.php:1110

public static function value_maybe_of_type( $key, $value ) {
		$type = 'text';

		if ( is_array( $value ) || is_object( $value ) ) {
			return apply_filters( 'automator_outgoing_webhook_value_of_type_array', $type, $key, $value );
		}

		if ( is_email( $value ) ) {
			$type = 'email';

			return apply_filters( 'automator_outgoing_webhook_value_of_type_email', $type, $key, $value );
		}

		if ( is_float( $value ) ) {
			$type = 'float';

			return apply_filters( 'automator_outgoing_webhook_value_of_type_float', $type, $key, $value );
		}

		if ( is_numeric( $value ) ) {
			$type = 'int';

			return apply_filters( 'automator_outgoing_webhook_value_of_type_int', $type, $key, $value );
		}

		if ( wp_http_validate_url( $value ) ) {
			$type = 'url';

			return apply_filters( 'automator_outgoing_webhook_value_of_type_url', $type, $key, $value );
		}

		return apply_filters( 'automator_outgoing_webhook_value_of_type_text', $type, $key, $value );
	}


Scroll to Top