Filter
uncanny-automator-pro
automator_pre_wrap_webhook_body
Filters webhook body before it's wrapped, allowing modification of pieces and parsed tokens.
add_filter( 'automator_pre_wrap_webhook_body', $callback, 10, 2 );
Description
Fires before wrapping webhook body content in `
` tags. Allows developers to modify the webhook body's presentation. This hook is useful for conditionally preventing HTML wrapping or altering the body's format before it's sent. The filter receives the current wrap status, pieces, and token parsing data.
Usage
add_filter( 'automator_pre_wrap_webhook_body', 'your_function_name', 10, 2 );
Parameters
-
$pieces(mixed) - This parameter is a boolean that determines whether the webhook body should be wrapped.
-
$parse_tokens(mixed) - This parameter contains an array of pieces that represent the different parts of the webhook body to be processed.
Return Value
The filtered value.
Examples
/**
* Example of using the automator_pre_wrap_webhook_body filter.
* This filter allows developers to modify the webhook body before it's wrapped in <pre> tags.
* In this example, we'll conditionally prevent the <pre> wrapping if a specific custom token is present.
*
* @param bool $should_wrap The current value of whether to wrap the webhook body in <pre> tags.
* @param array $pieces An array of pieces of the webhook body being processed.
* @param array $parse_tokens An array of tokens being parsed.
*
* @return bool Returns false to prevent <pre> wrapping if the custom token 'NO_PRE_WRAP' is found, otherwise returns the original value.
*/
add_filter( 'automator_pre_wrap_webhook_body', function( $should_wrap, $pieces, $parse_tokens ) {
// Check if the $pieces array contains 'WEBHOOK_BODY' which signifies we're dealing with the webhook body.
if ( in_array( 'WEBHOOK_BODY', $pieces, true ) ) {
// Get the meta value for the 'WEBHOOK_BODY' token.
$meta_value = Automator()->db->trigger->get_token_meta( 'WEBHOOK_BODY', $parse_tokens );
// If a custom token 'NO_PRE_WRAP' exists within the webhook body content,
// and it evaluates to a truthy value after parsing.
if ( ! empty( $meta_value ) && strpos( $meta_value, '{NO_PRE_WRAP}' ) !== false ) {
// Remove the conditional wrapping in <pre> tags.
return false;
}
}
// Return the original value if the condition is not met.
return $should_wrap;
}, 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
uncanny-automator-pro/src/core/webhook/webhook-common-options.php:683
return '';
}
if ( in_array( 'WEBHOOK_BODY', $pieces, true ) ) {
$meta_value = Automator()->db->trigger->get_token_meta( 'WEBHOOK_BODY', $parse_tokens );
if ( ! empty( $meta_value ) ) {
if ( true === apply_filters( 'automator_pre_wrap_webhook_body', true, $pieces, $parse_tokens ) ) {
return sprintf( '<pre>%s</pre>', maybe_unserialize( $meta_value ) );
}
return maybe_unserialize( $meta_value );
}
}