Action Since 7.0 uncanny-automator

automator_recipe_{$type}_add_complete

Fires after a specific item type is added. Fires after a specific item type is successfully added via the API integration for a recipe.

add_action( 'automator_recipe_{$type}_add_complete', $callback, 10, 5 );

Description

Fires after an item is successfully added via the API. Developers can use this hook to perform custom actions, log the addition, or trigger further processes based on the added item's details. It provides the item ID, code, recipe ID, service return data, and the recipe object.


Usage

add_action( 'automator_recipe_{$type}_add_complete', 'your_function_name', 10, 5 );

Parameters

$item_id (int|string)
The item ID.
$item_code (string)
The item code.
$recipe_id (int)
The recipe ID.
$item_data (array)
Service return data.
$recipe (object)
Recipe aggregate object.

Examples

/**
 * Log details when an action item is successfully added to a recipe.
 *
 * This function is triggered after an action item has been successfully
 * added as part of a WordPress Automator recipe execution. It logs
 * key information about the item, recipe, and the service's response.
 *
 * @param int|string $item_id   The ID of the added action item.
 * @param string     $item_code The unique code identifying the action item's type.
 * @param int        $recipe_id The ID of the recipe this item belongs to.
 * @param array      $item_data The data returned by the service after the action was performed.
 * @param object     $recipe    The aggregate object representing the recipe.
 */
add_action(
	'automator_recipe_action_add_complete',
	function ( $item_id, $item_code, $recipe_id, $item_data, $recipe ) {
		// Example: Log the details to the debug log.
		// In a real-world scenario, you might want to check the $item_code
		// to perform specific actions based on the type of action.
		if ( WP_DEBUG === true ) {
			error_log(
				sprintf(
					'Automator: Action item added complete. Item ID: %s, Item Code: %s, Recipe ID: %d. Service Data: %s',
					print_r( $item_id, true ),
					$item_code,
					$recipe_id,
					print_r( $item_data, true )
				)
			);

			// Example: Conditionally update a post meta if the item code is 'send-email'
			if ( 'send-email' === $item_code && isset( $item_data['email_sent'] ) && true === $item_data['email_sent'] ) {
				// Assuming the recipe is related to a specific post or user,
				// you'd need to access that context. For this example, we'll
				// just log that we would have updated meta.
				error_log(
					sprintf(
						'Automator: Email sent successfully for recipe %d. Would update post meta here.',
						$recipe_id
					)
				);
			}
		}
	},
	10, // Priority: Default priority
	5  // Accepted Args: Number of arguments the callback accepts
);

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/api/transports/restful/recipe/items/traits/hooks/trait-hook-add-operations.php:94

protected function dispatch_add_complete_hooks( array $item_data, object $recipe ): void {
		$type = $this->get_item_type();

		/**
		 * Fires after any recipe item is added.
		 *
		 * @since 7.0
		 *
		 * @param int|string $item_id   The item ID.
		 * @param string     $item_code The item code.
		 * @param int        $recipe_id The recipe ID.
		 * @param string     $item_type The item type (trigger, action, closure, filter_condition).
		 * @param array      $item_data Service return data.
		 * @param object     $recipe    Recipe aggregate object.
		 */
		do_action(
			'automator_recipe_item_add_complete',
			$this->get_item_id(),
			$this->get_item_code(),
			$this->get_recipe_id(),
			$type,
			$item_data,
			$recipe
		);

		/**
		 * Fires after a specific item type is added.
		 *
		 * @since 7.0
		 *
		 * @param int|string $item_id   The item ID.
		 * @param string     $item_code The item code.
		 * @param int        $recipe_id The recipe ID.
		 * @param array      $item_data Service return data.
		 * @param object     $recipe    Recipe aggregate object.
		 */
		do_action(
			"automator_recipe_{$type}_add_complete",
			$this->get_item_id(),
			$this->get_item_code(),
			$this->get_recipe_id(),
			$item_data,
			$recipe
		);
	}


Scroll to Top