Action
Since 7.0
uncanny-automator
automator_recipe_item_delete_complete
Fires after any recipe item is deleted. Fires after a recipe item is deleted, providing its ID, code, type, and associated recipe.
add_action( 'automator_recipe_item_delete_complete', $callback, 10, 5 );
Description
Fires after a recipe item is successfully deleted. Use this hook to perform cleanup or logging operations related to the deleted item, utilizing its ID, code, type, and the associated recipe object.
Usage
add_action( 'automator_recipe_item_delete_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_type(string) - The item type (trigger, action, closure, filter_condition).
-
$recipe(object) - Recipe aggregate object.
Examples
/**
* Example function to log recipe item deletion.
*
* This function demonstrates how to hook into the 'automator_recipe_item_delete_complete'
* action hook to log information about a deleted recipe item.
*/
function my_automator_log_recipe_item_deletion( $item_id, $item_code, $recipe_id, $item_type, $recipe ) {
// Ensure the WordPress logging function is available (or use a custom logger).
if ( function_exists( 'wp_log' ) ) {
wp_log(
sprintf(
'Automator recipe item deleted: ID %s, Code %s, Recipe ID %d, Type %s.',
$item_id,
$item_code,
$recipe_id,
$item_type
),
'automator_deletion_log' // Custom log file name or category.
);
// Optionally, log details from the recipe object if it's useful.
// This is a simplified example; real logic might involve checking $recipe->get_title() or other properties.
if ( $recipe && is_object( $recipe ) ) {
// Example: Log the recipe title if available.
if ( method_exists( $recipe, 'get_title' ) ) {
wp_log(
sprintf(
'Recipe associated with deletion: "%s".',
$recipe->get_title()
),
'automator_deletion_log'
);
}
}
} else {
// Fallback for environments where wp_log might not be available.
error_log(
sprintf(
'Automator recipe item deleted: ID %s, Code %s, Recipe ID %d, Type %s.',
$item_id,
$item_code,
$recipe_id,
$item_type
)
);
}
}
add_action( 'automator_recipe_item_delete_complete', 'my_automator_log_recipe_item_deletion', 10, 5 );
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:71
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
);
}