Action
uncanny-automator
automator_cache_reset_recipes_after_completion
Fires after a recipe completes, allowing for cache resets related to that specific recipe and user.
add_action( 'automator_cache_reset_recipes_after_completion', $callback, 10, 4 );
Description
Fires after a recipe's completion, triggered by the Automator core. Developers can use this hook to clear any cached data related to the completed recipe, its user, or the recipe log, ensuring fresh data for subsequent operations. The hook passes the recipe ID, user ID, recipe log ID, and additional arguments.
Usage
add_action( 'automator_cache_reset_recipes_after_completion', 'your_function_name', 10, 4 );
Parameters
-
$recipe_id(mixed) - The ID of the recipe that has just been completed.
-
$user_id(mixed) - This parameter contains the ID of the recipe that has just completed its execution.
-
$recipe_log_id(mixed) - This parameter contains the ID of the user for whom the recipe has been completed.
-
$args(mixed) - This parameter contains the ID of the recipe log entry for the completed recipe.
Examples
add_action( 'automator_cache_reset_recipes_after_completion', 'my_custom_recipe_cache_reset_handler', 10, 4 );
/**
* Custom handler for resetting recipe cache after completion.
*
* This function demonstrates how to hook into the 'automator_cache_reset_recipes_after_completion'
* action to perform additional cache clearing or logging when a recipe completes.
*
* @param int|string $recipe_id The ID of the completed recipe.
* @param int|string $user_id The ID of the user for whom the recipe completed.
* @param int|string $recipe_log_id The ID of the log entry for this recipe execution.
* @param array $args Additional arguments passed during recipe completion.
*/
function my_custom_recipe_cache_reset_handler( $recipe_id, $user_id, $recipe_log_id, $args ) {
// Example: Log the completion of a specific recipe for debugging purposes.
// In a real-world scenario, you might want to clear a more specific cache
// related to this user's interaction with this recipe, or trigger other
// downstream processes.
// Check if the recipe is a critical one we want to monitor closely.
$critical_recipe_ids = array( 123, 456 ); // Replace with actual critical recipe IDs.
if ( in_array( $recipe_id, $critical_recipe_ids, true ) ) {
error_log( sprintf(
'Critical Automator Recipe Completion: Recipe ID %s completed for User ID %s (Log ID: %s). Args: %s',
$recipe_id,
$user_id,
$recipe_log_id,
print_r( $args, true ) // Use print_r for better array readability in logs.
) );
}
// Example: If there's a user-specific cache related to this recipe, clear it.
// This is a hypothetical example, as the actual cache keys would depend on
// how the Automator plugin structures its user-specific caches.
$user_specific_cache_key = 'automator_user_data_' . $user_id . '_recipe_' . $recipe_id;
// Assuming a global cache handler or a method like `automator_cache()->remove()` is available.
// If not, you'd use WordPress's Transients API or Object Cache API.
if ( function_exists( 'automator_cache' ) && method_exists( automator_cache(), 'remove' ) ) {
automator_cache()->remove( $user_specific_cache_key );
} elseif ( function_exists( 'delete_transient' ) ) {
delete_transient( $user_specific_cache_key );
}
}
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/lib/helpers/class-automator-cache-handler.php:291
public function reset_recipes_after_completion( $recipe_id, $user_id, $recipe_log_id, $args ) {
// Reset recipe ID cache
$key = 'automator_recipe_data_of_' . $recipe_id;
$this->remove( $key );
// Clear recipes data cache
$this->remove( $this->recipes_data );
do_action( 'automator_cache_reset_recipes_after_completion', $recipe_id, $user_id, $recipe_log_id, $args );
}