Action
Since 7.0
uncanny-automator
automator_recipe_{$type}_delete_complete
Fires after a specific item type is deleted. Fires after a specific item type within a recipe is successfully deleted.
add_action( 'automator_recipe_{$type}_delete_complete', $callback, 10, 4 );
Description
Fires after a specific API item type is deleted. Developers can use this hook to perform post-deletion actions, such as logging, updating related data, or triggering further automations, using the item's ID, code, recipe ID, and the recipe object.
Usage
add_action( 'automator_recipe_{$type}_delete_complete', 'your_function_name', 10, 4 );
Parameters
-
$item_id(int|string) - The item ID.
-
$item_code(string) - The item code.
-
$recipe_id(int) - The recipe ID.
-
$recipe(object) - Recipe aggregate object.
Examples
// Example: Log the deletion of an automation recipe item and potentially trigger a cleanup process.
add_action(
'automator_recipe_action_delete_complete', // Assuming $type is 'action' for this example
'my_custom_automator_recipe_action_deletion_handler',
10,
4 // Explicitly state the number of arguments the callback accepts
);
/**
* Handles the completion of an automator recipe action deletion.
*
* @param int|string $item_id The ID of the deleted recipe item.
* @param string $item_code The code of the deleted recipe item.
* @param int $recipe_id The ID of the recipe to which the item belonged.
* @param object $recipe The recipe aggregate object.
*/
function my_custom_automator_recipe_action_deletion_handler( $item_id, $item_code, $recipe_id, $recipe ) {
// Log the deletion for debugging purposes.
error_log( sprintf(
'Automator Recipe Action Deleted: Item ID %s (%s) from Recipe ID %d. Recipe object: %s',
$item_id,
$item_code,
$recipe_id,
print_r( $recipe, true ) // Log the recipe object for more context
) );
// Example: If the deleted item is a specific type, you might want to perform further cleanup.
// For instance, if $item_code represents a user deletion trigger,
// you might want to ensure all associated user meta is also removed.
if ( 'user_deleted' === $item_code ) {
// Assume a function exists to clean up user-related data from the database.
// This is a placeholder; the actual implementation would depend on your needs.
cleanup_automator_user_data( $item_id );
error_log( sprintf(
'Cleanup initiated for user data associated with deleted recipe item %s (%s) from Recipe ID %d.',
$item_id,
$item_code,
$recipe_id
) );
}
}
// Placeholder function for cleanup - replace with your actual implementation.
function cleanup_automator_user_data( $user_id ) {
// Example: Delete custom options or meta related to this user and automator.
// delete_user_meta( $user_id, 'automator_tracking_data' );
// delete_option( 'automator_user_specific_settings_' . $user_id );
return true;
}
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-delete-operations.php:90
protected function dispatch_delete_complete_hooks( object $recipe ): void {
$type = $this->get_item_type();
/**
* Fires after any recipe item is deleted.
*
* @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 object $recipe Recipe aggregate object.
*/
do_action(
'automator_recipe_item_delete_complete',
$this->get_item_id(),
$this->get_item_code(),
$this->get_recipe_id(),
$type,
$recipe
);
/**
* Fires after a specific item type is deleted.
*
* @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 object $recipe Recipe aggregate object.
*/
do_action(
"automator_recipe_{$type}_delete_complete",
$this->get_item_id(),
$this->get_item_code(),
$this->get_recipe_id(),
$recipe
);
}