Action
Since 7.0
uncanny-automator
automator_recipe_{$type}_update_complete
Fires when a specific recipe item type update is complete. Fires after an Automator recipe item of a specific type has been updated, providing item and recipe details.
add_action( 'automator_recipe_{$type}_update_complete', $callback, 10, 5 );
Description
Fires after an API recipe item of a specific type is successfully updated. This hook is ideal for reacting to completed API item updates, allowing developers to trigger further actions, log changes, or synchronize data based on the updated item's ID, code, recipe ID, service return data, and the recipe object itself.
Usage
add_action( 'automator_recipe_{$type}_update_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
/**
* This action hook fires when an Automator recipe item update is complete.
* We can use this to perform custom actions based on the updated item.
* For example, logging the update or triggering another process.
*/
add_action(
'automator_recipe_action_update_complete', // Example type is 'action'
function ( $item_id, $item_code, $recipe_id, $item_data, $recipe ) {
// Log the details of the completed recipe item update.
// This could be useful for debugging or auditing purposes.
if ( ! empty( $item_data ) ) {
$log_message = sprintf(
__( 'Automator recipe item update complete for Recipe ID: %d, Item ID: %s, Item Code: %s. Data: %s', 'your-text-domain' ),
$recipe_id,
$item_id,
$item_code,
print_r( $item_data, true ) // Pretty print the array for better readability in logs.
);
// Use WordPress's built-in logging if available, or a custom logging function.
// For demonstration, we'll use error_log. In a real plugin, consider a more robust logging solution.
error_log( $log_message );
// Example: If the item_code is 'send-email' and a specific field in item_data indicates success,
// you might want to perform another action.
if ( 'send-email' === $item_code && isset( $item_data['status'] ) && 'success' === $item_data['status'] ) {
// Trigger another custom process, e.g., send a notification to an admin.
// wp_mail( '[email protected]', 'Automator Email Sent Successfully', 'A recipe action to send an email was completed successfully.' );
}
}
},
10, // Priority: Default priority.
5 // Accepted args: The number of arguments the callback function 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-update-operations.php:87
protected function dispatch_update_complete_hooks( array $item_data, object $recipe ): void {
$type = $this->get_item_type();
/**
* Fires when a recipe item update is complete.
*
* @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_update_complete',
$this->get_item_id(),
$this->get_item_code(),
$this->get_recipe_id(),
$type,
$item_data,
$recipe
);
/**
* Fires when a specific recipe item type update is complete.
*
* @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}_update_complete",
$this->get_item_id(),
$this->get_item_code(),
$this->get_recipe_id(),
$item_data,
$recipe
);
}