Filter Dynamic uncanny-automator-pro

automator_pro_full_webhook_response_{$recipe['ID']}

> **Note:** This is a dynamic hook. The actual hook name is constructed at runtime. Filters the full webhook response before it's sent, allowing modification of the WordPress REST API response.

add_filter( 'automator_pro_full_webhook_response_{$recipe['ID']}', $callback, 10, 4 );

Description

Filters the complete WP_REST_Response object before it's sent for a specific webhook recipe. Developers can modify the response body, status code, or headers. This hook fires after the response is initially generated and before it's returned to the client. The recipe ID is dynamically appended to the hook name.


Usage

add_filter( 'automator_pro_full_webhook_response_{$recipe['ID']}', 'your_function_name', 10, 4 );

Parameters

$wp_rest_response (mixed)
This parameter contains the `WP_REST_Response` object that will be sent back to the webhook sender.
$_hooks (mixed)
This parameter holds the `WP_REST_Response` object that will be returned by the webhook endpoint, allowing for modification of its data, status code, and headers.
$recipe (mixed)
This parameter contains information about the hooks that are being processed for the current recipe.
$data (mixed)
This parameter contains an array representing the specific Uncanny Automator Pro recipe that triggered the webhook, including its ID and other configuration details.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to filter the full webhook response for a specific Uncanny Automator Pro recipe.
 * This example demonstrates how to add custom data to the response and modify the status code.
 *
 * @param WP_REST_Response $wp_rest_response The current WP_REST_Response object.
 * @param array            $_hooks           An array of hooks associated with the recipe.
 * @param array            $recipe           The recipe data.
 * @param array            $data             The data passed to the webhook.
 *
 * @return WP_REST_Response The modified WP_REST_Response object.
 */
add_filter( 'automator_pro_full_webhook_response_123', function ( $wp_rest_response, $_hooks, $recipe, $data ) {

	// Get the existing response data.
	$response_data = $wp_rest_response->get_data();

	// Add custom data to the response.
	$response_data['custom_info'] = 'This is custom data added by the filter.';
	$response_data['received_payload_count'] = count( $data );

	// Potentially modify the status code based on some condition.
	// For example, if the 'user_id' is present in the data and is a specific value.
	if ( isset( $data['user_id'] ) && $data['user_id'] === 999 ) {
		$wp_rest_response->set_status( 201 ); // Created
		$response_data['message'] = 'User specific action taken.';
	} else {
		$wp_rest_response->set_status( 200 ); // OK
		$response_data['message'] = 'Webhook processed successfully.';
	}

	// Update the response with modified data and status.
	$wp_rest_response->set_data( $response_data );

	// Return the modified response.
	return $wp_rest_response;

}, 10, 4 );

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

$response_headers,
			$_hooks,
			$recipe,
			$data
		);

		$wp_rest_response = new WP_REST_Response( $response_data, $response_status_code, $response_headers );
		$wp_rest_response = apply_filters(
			"automator_pro_full_webhook_response_{$recipe['ID']}",
			$wp_rest_response,
			$_hooks,
			$recipe,
			$data
		);


Scroll to Top