Action
uncanny-automator
automator_before_process_complete_actions
Fires before the completion of recipe actions, passing recipe and user data.
add_action( 'automator_before_process_complete_actions', $callback, 10, 5 );
Description
Fires before the Automator plugin completes processing actions for a recipe. Developers can use this hook to modify recipe or user data, inspect pending actions, or perform custom logic before the completion process. It provides access to the recipe ID, user ID, recipe log ID, the actions themselves, and any additional arguments.
Usage
add_action( 'automator_before_process_complete_actions', 'your_function_name', 10, 5 );
Parameters
-
$recipe_id(mixed) - This parameter contains the ID of the recipe that is currently being processed.
-
$user_id(mixed) - This parameter holds the ID of the recipe that is currently being processed.
-
$recipe_log_id(mixed) - This parameter contains the ID of the user for whom the recipe is being processed.
-
$actions(mixed) - The `$recipe_log_id` parameter contains the unique identifier for the current log entry of the recipe being processed.
-
$args(mixed) - This parameter contains an array of additional arguments passed to the hook.
Examples
/**
* Example callback function for the automator_before_process_complete_actions hook.
* This function demonstrates how to intercept and potentially modify actions before they are processed.
* In this example, we'll log the recipe and user IDs if a specific recipe ID is encountered.
*/
function my_automator_log_specific_recipe_before_completion( $recipe_id, $user_id, $recipe_log_id, $actions, $args ) {
// Define a specific recipe ID we want to monitor.
$monitored_recipe_id = 123; // Replace with an actual recipe ID from your Automator recipes.
// Check if the current recipe ID matches our monitored ID.
if ( $recipe_id === $monitored_recipe_id ) {
// Log some information about the impending action processing.
// In a real-world scenario, you might use a more robust logging system like WP_Error or a custom logger.
error_log( sprintf(
'Automator: Before processing actions for recipe ID %d for user ID %d (Recipe Log ID: %d). Actions queued: %s, Args: %s',
$recipe_id,
$user_id,
$recipe_log_id,
print_r( $actions, true ), // Log the actions array in a readable format.
print_r( $args, true ) // Log the arguments array in a readable format.
) );
// You could also potentially modify the $actions array here if needed,
// but be cautious as this might have unintended consequences.
// For example, to skip a specific action:
// unset($actions[0]); // This would remove the first action from the list.
// Note: If you modify $actions, ensure the 'automator_before_process_complete_actions' hook
// is correctly implemented in the source to accept the modified array.
// Based on the source context, this hook is an action, so no return is expected to modify the original $actions.
}
// This is an action hook, so no return value is needed to modify the original parameters.
}
// Add the callback function to the 'automator_before_process_complete_actions' hook.
// We use a priority of 10 (default) and specify 5 accepted arguments, matching the hook's parameters.
add_action( 'automator_before_process_complete_actions', 'my_automator_log_specific_recipe_before_completion', 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/core/lib/process/class-automator-recipe-process-complete.php:334
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;
}