Filter uncanny-automator-pro

automator_pro_webhook_hooks_data

Filters webhook data before it's processed by Automator Pro, allowing modification of the payload.

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

Description

This filter hook, `automator_pro_webhook_hooks_data`, allows developers to modify the data being prepared for a webhook action before it's sent. It's applied after the webhook data has been gathered and structured, providing an opportunity to add, remove, or alter any aspect of the payload. Use this hook to customize webhook data for specific integrations or advanced logic within Uncanny Automator Pro.


Usage

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

Parameters

$_hooks (mixed)
This parameter contains an array of webhook hooks that are being processed.
$recipe (mixed)
This parameter contains an array of webhook hooks that will be processed.
$data (mixed)
This parameter contains the recipe object that the webhook is associated with.

Return Value

The filtered value.


Examples

<?php

/**
 * Example of how to filter the data passed to the automator_pro_webhook_hooks_data hook.
 * This example demonstrates how to modify the webhook data by adding a custom field
 * or altering an existing one before it's processed by Uncanny Automator Pro.
 *
 * @param array $hooks The current array of webhook hook data.
 * @param object $recipe The recipe object being processed.
 * @param array $data The raw data associated with the webhook trigger.
 *
 * @return array The modified array of webhook hook data.
 */
add_filter( 'automator_pro_webhook_hooks_data', function( $hooks, $recipe, $data ) {

	// Example: Add a custom field to the webhook data if a specific recipe is detected.
	if ( $recipe && $recipe->ID === 123 ) { // Replace 123 with a real recipe ID
		$hooks[] = array(
			'type'       => 'text',
			'format'     => '',
			'meta_key'   => 'custom_webhook_field',
			'meta_value' => 'This is a custom value added by my filter.',
		);
	}

	// Example: Modify an existing field's value.
	// Let's assume there's a field with meta_key 'user_email' in the original $hooks.
	foreach ( $hooks as &$hook_item ) {
		if ( isset( $hook_item['meta_key'] ) && $hook_item['meta_key'] === 'user_email' ) {
			// Append some text to the existing email value.
			$hook_item['meta_value'] .= '_modified';
		}
	}
	unset( $hook_item ); // Unset the reference to avoid unexpected behavior.

	// Always return the modified hooks array.
	return $hooks;

}, 10, 3 ); // Priority 10, accepts 3 arguments.

?>

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-rest-handler.php:423

'type'       => $_field->VALUE_TYPE, //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
				'format'     => '',
				'meta_key'   => $_field->KEY, //phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
				'meta_value' => $value,
			);
		}

		$_hooks = apply_filters( 'automator_pro_webhook_hooks_data', $_hooks, $recipe, $data );
		do_action_deprecated(
			'uncanny_automator_pro_wp_webhook',
			array( $_hooks, $recipe ),
			'3.6',
			'automator_pro_run_webhook'
		);


Scroll to Top