Action
Since 7.0
uncanny-automator
automator_recipe_{$type}_delete_before
Fires before a specific item type is deleted. Fires before an integration API item of a specific type is deleted, providing access to the REST request.
add_action( 'automator_recipe_{$type}_delete_before', $callback, 10, 1 );
Description
Fires just before a specific Automator recipe item of a given type is deleted via the API. Developers can use this hook to perform cleanup, logging, or custom actions related to the deletion process, before the item is permanently removed. The full REST request object is provided for context.
Usage
add_action( 'automator_recipe_{$type}_delete_before', 'your_function_name', 10, 1 );
Parameters
-
$request(WP_REST_Request) - The REST request object.
Examples
add_action( 'automator_recipe_action_delete_before', 'my_plugin_before_recipe_action_delete', 10, 1 );
/**
* Logs a message before an action is deleted from a recipe.
*
* This function is hooked into the 'automator_recipe_action_delete_before'
* action hook. It receives the WP_REST_Request object containing information
* about the delete request.
*
* @param WP_REST_Request $request The REST request object.
*/
function my_plugin_before_recipe_action_delete( WP_REST_Request $request ) {
// Get the recipe ID and the action ID from the request parameters.
$recipe_id = $request->get_param( 'recipe_id' );
$action_id = $request->get_param( 'id' ); // Assuming 'id' is the parameter for the action's ID.
// Log a message to the WordPress debug log indicating the deletion is about to happen.
// This is useful for debugging and monitoring recipe modifications.
if ( ! empty( $recipe_id ) && ! empty( $action_id ) ) {
error_log(
sprintf(
'About to delete action ID %1$s from recipe ID %2$s. Request params: %3$s',
$action_id,
$recipe_id,
json_encode( $request->get_params() )
)
);
}
// In a real-world scenario, you might also perform other actions here,
// such as:
// - Checking if the current user has permission to delete this action.
// - Performing a backup of the recipe data before deletion.
// - Triggering other related cleanup tasks.
// No return value is needed for actions.
}
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:44
protected function dispatch_before_delete_hooks(): void {
$type = $this->get_item_type();
/**
* Fires before any recipe item is deleted.
*
* @since 7.0
*
* @param WP_REST_Request $request The REST request object.
* @param string $type The item type.
*/
do_action(
'automator_recipe_item_delete_before',
$this->get_request(),
$type
);
/**
* Fires before a specific item type is deleted.
*
* @since 7.0
*
* @param WP_REST_Request $request The REST request object.
*/
do_action(
"automator_recipe_{$type}_delete_before",
$this->get_request()
);
}