automator_recipe_process_complete_complete_actions_before_closures
Fires after all recipe actions are completed but before closures are executed for a processed recipe.
add_action( 'automator_recipe_process_complete_complete_actions_before_closures', $callback, 10, 4 );
Description
Fires after all recipe actions have completed but before closure actions are executed. This hook allows developers to run custom logic, log data, or perform final checks on the recipe execution before the next stage. Parameters include recipe ID, user ID, recipe log ID, and additional arguments.
Usage
add_action( 'automator_recipe_process_complete_complete_actions_before_closures', 'your_function_name', 10, 4 );
Parameters
-
$recipe_id(mixed) - This parameter holds the unique identifier of the recipe that has just completed its processing.
-
$user_id(mixed) - This parameter contains the unique identifier of the recipe being processed.
-
$recipe_log_id(mixed) - This parameter holds the ID of the user for whom the recipe is being processed.
-
$args(mixed) - This parameter holds the unique identifier for the specific log entry associated with the recipe's completion.
Examples
/**
* Example function to process additional data before closures are executed.
* This function might, for instance, check for specific conditions or log
* certain parameters before the final processing steps.
*
* @param int $recipe_id The ID of the Uncanny Automator recipe.
* @param int $user_id The ID of the user associated with the recipe execution.
* @param int $recipe_log_id The ID of the log entry for this recipe execution.
* @param array $args Additional arguments passed to the hook.
*/
function my_automator_before_closures_processing( $recipe_id, $user_id, $recipe_log_id, $args ) {
// Example: Log the recipe ID and user ID if a specific argument is present.
if ( isset( $args['process_specific_data'] ) && true === $args['process_specific_data'] ) {
error_log( "Automator: Processing additional data for Recipe ID: {$recipe_id} for User ID: {$user_id} (Log ID: {$recipe_log_id})." );
// Example: Perform some conditional logic based on recipe settings or user meta.
$user_meta_value = get_user_meta( $user_id, 'my_custom_automator_flag', true );
if ( 'enabled' === $user_meta_value ) {
error_log( "Automator: Custom flag is enabled for user {$user_id}. Performing special action." );
// Add your custom logic here, e.g., update another meta field, send a notification, etc.
}
}
// Example: If this were a filter, you would return a modified value.
// For this action hook, no return value is expected.
}
// Hook the custom function to the automator_recipe_process_complete_complete_actions_before_closures action.
// The priority 25 means it will run after functions with lower priorities (e.g., 10, 20).
// The '4' indicates that our function accepts 4 arguments.
add_action( 'automator_recipe_process_complete_complete_actions_before_closures', 'my_automator_before_closures_processing', 25, 4 );
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/process/class-automator-recipe-process-complete.php:317
src/core/lib/process/class-automator-recipe-process-complete.php:353
uncanny-automator-pro/src/core/loops/loop-entry-point.php:264
public function complete_actions( $recipe_id = null, $user_id = null, $recipe_log_id = null, $args = array() ) {
$actions = (array) Automator()->get_recipe_data( AUTOMATOR_POST_TYPE_ACTION, $recipe_id );
// No recipe actions found.
if ( empty( $actions ) ) {
// Check for closures.
$closure_data = (array) Automator()->get_recipe_data( AUTOMATOR_POST_TYPE_CLOSURE, $recipe_id, array(), true );
// No actions and no closures - complete the recipe with errors.
if ( empty( $closure_data ) ) {
Automator()->db->recipe->mark_complete( $recipe_log_id, Automator_Status::COMPLETED_WITH_ERRORS );
return false;
}
// Have closures, complete the recipe.
Automator()->db->recipe->mark_complete( $recipe_log_id, Automator_Status::COMPLETED );
// This action hook is fired just before the closures are run.
do_action( 'automator_recipe_process_complete_complete_actions_before_closures', $recipe_id, $user_id, $recipe_log_id, $args );
$this->closures( $recipe_id, $user_id, $recipe_log_id, $args, $closure_data );
return true;
}
// Recipe actions found - complete them.
$recipe_actions_data = apply_filters(
'automator_process_complete_actions',
$actions,
$recipe_id,
$user_id,
$recipe_log_id,
$args
);
do_action( 'automator_before_process_complete_actions', $recipe_id, $user_id, $recipe_log_id, $actions, $args );
// Run individual action on behalf of the user.
foreach ( $recipe_actions_data as $action_data ) {
$completed = $this->complete_action( $action_data, $recipe_id, $user_id, $recipe_log_id, $args );
if ( false === $completed ) {
Utilities::log(
Automator()->wp_error->get_messages( 'complete_action' ),
'Method complete_action has returned false',
AUTOMATOR_DEBUG_MODE,
'complete_actions'
);
continue;
}
}
// This action hook is fired just before the closures are run.
do_action( 'automator_recipe_process_complete_complete_actions_before_closures', $recipe_id, $user_id, $recipe_log_id, $args );
// Update the count of the recipe
Automator()->db->recipe->update_count( $recipe_id );
$this->closures( $recipe_id, $user_id, $recipe_log_id, $args );
return true;
}