Filter uncanny-automator-pro

automator_pre_wrap_webhook_sample

Filters webhook sample data before it's wrapped, allowing modification of webhook content.

add_filter( 'automator_pre_wrap_webhook_sample', $callback, 10, 2 );

Description

Filters whether to wrap webhook sample data in `

` tags. Use this to prevent wrapping for specific data types or conditions, ensuring raw output where needed. This hook fires before the sample data is potentially formatted for display.


Usage

add_filter( 'automator_pre_wrap_webhook_sample', 'your_function_name', 10, 2 );

Parameters

$pieces (mixed)
This parameter is a boolean value that determines whether the webhook sample should be wrapped in a `<pre>` tag.
$parse_tokens (mixed)
This parameter is an array containing different pieces or parts of data related to the webhook, used to determine specific actions.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to filter the automator_pre_wrap_webhook_sample hook.
 * This example conditionally prevents the webhook sample from being wrapped in a <pre> tag
 * if a specific condition is met.
 */
add_filter(
	'automator_pre_wrap_webhook_sample',
	function ( $should_wrap, $pieces, $parse_tokens ) {
		// Let's say we want to disable wrapping if the webhook sample data contains a specific key.
		// In a real scenario, $pieces might contain information about the current trigger or action.
		// And $parse_tokens might contain data that has been parsed and replaced.

		// For demonstration, let's assume we can inspect the unserialized value before it's wrapped.
		// The original code snippet provided doesn't directly expose the unserialized value to this filter.
		// However, we can infer that if the filter returns false, wrapping is prevented.

		// A more realistic scenario might involve checking a meta key or a global variable.
		// For this example, let's simulate a condition based on $pieces.
		// If $pieces includes a specific identifier, we'll prevent wrapping.
		$specific_identifier = 'DO_NOT_WRAP_WEBHOOK';

		if ( in_array( $specific_identifier, $pieces, true ) ) {
			// If the specific identifier is found in $pieces, return false to prevent wrapping.
			return false;
		}

		// Otherwise, return the original value, which by default is true, allowing wrapping.
		return $should_wrap;
	},
	10, // Priority
	3   // Accepted arguments: $should_wrap, $pieces, $parse_tokens
);

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

}

			if ( in_array( 'WEBHOOK_SAMPLE', $pieces, true ) ) {
				$meta_value = get_post_meta( $trigger_id, 'WEBHOOK_SAMPLE', true );
				if ( ! empty( $meta_value ) ) {
					$unserialized_value = maybe_unserialize( $meta_value );
					// Wrap the value in a pre tag unless filtered.
					if ( true === apply_filters( 'automator_pre_wrap_webhook_sample', true, $pieces, $parse_tokens ) ) {
						$unserialized_value = is_array( $unserialized_value ) || is_object( $unserialized_value )
							? wp_json_encode( $unserialized_value, JSON_PRETTY_PRINT ) // encode for sprintf
							: $unserialized_value;
						return sprintf( '<pre>%s</pre>', $unserialized_value );
					}
					return $unserialized_value;
				}


Scroll to Top