Filter
uncanny-automator
automator_outgoing_webhook_value_of_type_email
Filters the value of an outgoing webhook when the type is specifically email, allowing for custom modification before sending.
add_filter( 'automator_outgoing_webhook_value_of_type_email', $callback, 10, 3 );
Description
Fires when an email value is being prepared for an outgoing webhook. Developers can use this filter to modify or sanitize email values before they are sent in the webhook payload. This ensures data integrity and allows for custom email formatting or validation.
Usage
add_filter( 'automator_outgoing_webhook_value_of_type_email', 'your_function_name', 10, 3 );
Parameters
-
$type(mixed) - This parameter, `$type`, is used to define the data type of the webhook value.
-
$key(mixed) - This parameter indicates the data type determined for the webhook value, defaulting to 'text' and potentially changing to 'email' if the value is recognized as a valid email address.
-
$value(mixed) - The `$key` parameter represents the identifier or name of the data field being processed.
Return Value
The filtered value.
Examples
/**
* Example: Modify the email value before it's sent in an outgoing webhook.
*
* This filter allows you to modify or sanitize an email address
* when it's being processed for an outgoing webhook.
*
* @param mixed $type The identified type of the value (expected to be 'email' here).
* @param mixed $key The key associated with the value in the webhook payload.
* @param mixed $value The email value to be processed.
*
* @return mixed The modified or original email value.
*/
add_filter(
'automator_outgoing_webhook_value_of_type_email',
function ( $type, $key, $value ) {
// Example: If the email key is 'admin_email', append a specific tag.
// This is a hypothetical scenario for demonstration.
if ( 'admin_email' === $key ) {
// Ensure $value is still a valid email after potential modifications
if ( is_email( $value ) ) {
$value = substr( $value, 0, strpos( $value, '@' ) ) . '+automator_processed@' . substr( $value, strpos( $value, '@' ) + 1 );
// You might want to re-validate after modification if needed.
if ( ! is_email( $value ) ) {
// Handle invalid email after modification, e.g., log an error or revert.
return false; // Or return the original value if preferred.
}
}
}
// Example: Sanitize the email address to ensure it's a valid format
// and potentially remove leading/trailing whitespace.
if ( is_email( $value ) ) {
$value = sanitize_email( $value );
}
// Always return the value, modified or original.
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:1089
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 );
}