Action
uncanny-automator
automator_after_process_action
Fires after an Automator action has been processed, allowing for post-action modifications or logging.
add_action( 'automator_after_process_action', $callback, 10, 5 );
Description
Fires after an Automator action has been processed. Developers can use this hook to perform custom tasks, log action outcomes, or integrate with other systems after an action has completed its execution within a recipe. It provides access to the user ID, processed action data, and the recipe ID.
Usage
add_action( 'automator_after_process_action', 'your_function_name', 10, 5 );
Parameters
-
$this(mixed) - This parameter holds the user ID for whom the action is being processed.
-
$this(mixed) - This parameter represents the current user ID for whom the action is being processed.
-
$this(mixed) - This parameter contains the data specific to the action being processed.
-
$this(mixed) - The `$recipe_id` parameter contains the unique identifier of the recipe that the action is a part of.
-
$this(mixed) - This parameter contains additional arguments passed to the action.
Examples
add_action( 'automator_after_process_action', 'my_automator_log_action_completion', 10, 5 );
/**
* Logs details about a completed Automator action.
*
* This function is triggered after an Automator action has been processed.
* It logs the user ID, action data, recipe ID, arguments, and parsed data
* for debugging and monitoring purposes.
*
* @param int $user_id The ID of the user associated with the action.
* @param array $action_data An array containing the data processed by the action.
* @param int $recipe_id The ID of the Automator recipe.
* @param array $args The arguments passed to the action.
* @param mixed $maybe_parsed Potentially parsed data related to the action.
*/
function my_automator_log_action_completion( $user_id, $action_data, $recipe_id, $args, $maybe_parsed ) {
// Log the completion of the Automator action.
// In a real-world scenario, you might use WordPress's error logging functions
// or a custom logging solution.
error_log( sprintf(
'Automator Action Completed: User ID: %d, Recipe ID: %d, Action Data: %s, Args: %s, Parsed Data: %s',
$user_id,
$recipe_id,
print_r( $action_data, true ),
print_r( $args, true ),
print_r( $maybe_parsed, true )
) );
// Example: If you wanted to conditionally trigger something else based on action data
if ( ! empty( $action_data['custom_field_updated'] ) && true === $action_data['custom_field_updated'] ) {
// Potentially send a notification or update another piece of metadata
// based on this specific action's success.
// For example:
// my_send_custom_notification( $user_id, $recipe_id );
}
}
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/recipe-parts/actions/abstract-action.php:379
src/core/lib/recipe-parts/trait-actions.php:67
public function do_action( $user_id, $action_data, $recipe_id, $args ) {
// Clear errors in case there are some left from a previous action.
$this->errors = array();
$this->user_id = $user_id;
$this->action_data = $action_data;
$this->recipe_id = $recipe_id;
$this->args = $args;
do_action( 'automator_before_process_action', $this->user_id, $this->action_data, $this->recipe_id, $this->args );
$this->maybe_parsed = $this->maybe_parse_tokens( $this->user_id, $this->action_data, $this->recipe_id, $this->args );
$this->action_data['maybe_parsed'] = $this->maybe_parsed;
$error = null;
try {
$result = $this->process_action( $this->user_id, $this->action_data, $this->recipe_id, $this->args, $this->maybe_parsed );
} catch ( Error $e ) {
$result = false;
$this->add_log_error( $e->getMessage() );
} catch ( Exception $e ) {
$result = false;
$this->add_log_error( $e->getMessage() );
}
if ( false === $result ) {
$this->action_data['complete_with_errors'] = true;
$error = $this->get_log_errors();
}
if ( null === $result && ! $this->is_complete_with_notice() ) {
$action_data['do_nothing'] = true;
$this->action_data['complete_with_errors'] = true;
$error = $this->get_log_errors();
}
if ( null === $result && $this->is_complete_with_notice() ) {
$this->action_data['complete_with_notice'] = true;
$error = $this->get_log_errors();
}
Automator()->complete->action( $this->user_id, $this->action_data, $this->recipe_id, $error );
do_action( 'automator_after_process_action', $this->user_id, $this->action_data, $this->recipe_id, $this->args, $this->maybe_parsed );
}