Action
Since 5.7
uncanny-automator
automator_recipe_item_deleted
Fires when a recipe item is deleted. Fires when a recipe item is deleted, providing access to the request, recipe ID, and return value for customization.
add_action( 'automator_recipe_item_deleted', $callback, 10, 2 );
Description
Fires after a recipe item is successfully deleted from the database. Developers can use this hook to perform cleanup tasks, clear related data, or trigger subsequent actions based on the deleted item. The hook provides the deleted item's ID, the parent recipe's ID, and a response array.
Usage
add_action( 'automator_recipe_item_deleted', 'your_function_name', 10, 2 );
Parameters
-
$request(mixed) - - **$recipe_id** `mixed`
-
$return(mixed)
Examples
/**
* Example function to handle the 'automator_recipe_item_deleted' action.
* This function logs a message to the WordPress debug log whenever a recipe item is deleted.
*
* @param int $item_id The ID of the deleted recipe item.
* @param int $recipe_id The ID of the recipe to which the item belonged.
* @param array $return_data An array containing additional data related to the deletion process.
*/
function my_automator_log_recipe_item_deletion( $item_id, $recipe_id, $return_data ) {
// Check if WordPress debugging is enabled to avoid unnecessary logging.
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
// Log a message to the debug log indicating the deletion.
error_log( sprintf(
'Recipe item with ID %d has been deleted from recipe ID %d. Additional data: %s',
absint( $item_id ),
absint( $recipe_id ),
print_r( $return_data, true ) // Log the entire return data array for debugging.
) );
}
}
add_action( 'automator_recipe_item_deleted', 'my_automator_log_recipe_item_deletion', 10, 3 );
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/core/automator-post-types/uo-recipe/class-recipe-post-rest-api.php:637
public function delete( WP_REST_Request $request ) {
// Make sure we have a parent post ID
if ( $request->has_param( 'ID' ) && is_numeric( $request->get_param( 'ID' ) ) ) {
// Delete the post
$delete_posts = wp_delete_post( absint( $request->get_param( 'ID' ) ), true );
if ( $delete_posts ) {
$actions_order = $request->has_param( 'actions_order' ) ? $request->get_param( 'actions_order' ) : array();
if ( ! empty( $actions_order ) ) {
foreach ( $actions_order as $index => $__action_id ) {
Automator()->db->action->update_menu_order( $__action_id, ( $index + 1 ) * 10 );
}
}
Automator()->cache->clear_automator_recipe_part_cache( $request->get_param( 'ID' ) );
$recipe_id = absint( $request->get_param( 'recipe_id' ) );
if ( AUTOMATOR_POST_TYPE_RECIPE !== get_post_type( $recipe_id ) ) {
$ancestors = get_post_ancestors( $recipe_id );
$recipe_id = array_pop( $ancestors );
}
$return['message'] = 'Deleted!';
$return['success'] = true;
$return['delete_posts'] = $delete_posts;
$return['action'] = 'deleted-' . $delete_posts->post_type;
$return['recipes_object'] = Automator()->get_recipes_data( true, $recipe_id );
$return['_recipe'] = Automator()->get_recipe_object( absint( $request->get_param( 'recipe_id' ) ) );
/**
* Fires when a recipe item is deleted.
*
* @since 5.7
*/
do_action( 'automator_recipe_item_deleted', $request->get_param( 'ID' ), $recipe_id, $return );
return new WP_REST_Response( $return, 200 );
}
}
$return['message'] = 'The data that was sent was malformed. Please reload the page and trying again.';
$return['success'] = false;
$return['data'] = $request;
$return['post'] = '';
$return['action'] = 'show_error';
return new WP_REST_Response( $return, 200 );
}
Internal Usage
Found in src/core/admin/class-import-recipe.php:88:
add_action( 'automator_recipe_item_deleted', array( $this, 'clear_imported_recipe_warning' ), 10, 3 );