Action
uncanny-automator
automator_before_action_completed_after_message_and_process_further
Fires before an action is marked completed, allowing modifications to arguments, error messages, or processing flow.
add_action( 'automator_before_action_completed_after_message_and_process_further', $callback, 10, 3 );
Description
Fires after an action's error message is generated and before deciding whether to process further. Developers can use this to modify the error message, influence the `process_further` decision, or perform custom logging before the action is marked as completed or failed. Access action arguments, error message, and the process further flag.
Usage
add_action( 'automator_before_action_completed_after_message_and_process_further', 'your_function_name', 10, 3 );
Parameters
-
$do_action_args(mixed) - This parameter contains the arguments that were passed to the action during its execution.
-
$error_message(mixed) - This parameter contains the arguments passed to the action when it was initially executed.
-
$process_further(mixed) - This parameter contains any error message generated during the action's execution.
Examples
<?php
/**
* Example usage of the automator_before_action_completed_after_message_and_process_further hook.
*
* This callback function demonstrates how to intercept the action completion process
* before it's marked as complete. It checks for errors and the 'process_further' flag.
* If there's an error message, it might log it or perform some other action.
* If 'process_further' is false, it prevents the action from being marked as complete.
*
* @param mixed $do_action_args The arguments passed to the 'automator_before_action_completed' action.
* @param mixed $error_message The error message generated for the action, if any.
* @param mixed $process_further A boolean indicating whether the action should be processed further.
*/
add_action( 'automator_before_action_completed_after_message_and_process_further', function( $do_action_args, $error_message, $process_further ) {
// Example: Log the error message if one exists
if ( ! empty( $error_message ) ) {
// In a real scenario, you might use a more sophisticated logging mechanism
error_log( sprintf( 'Automator Action Error: %s', $error_message ) );
}
// Example: If $process_further is false, prevent the action from being marked as complete.
// This logic is already handled in the core code, but this shows how you might interact.
if ( false === $process_further ) {
// You could add additional logic here if needed, e.g., send a notification
// to the site admin about this failed action.
// For this example, we'll just acknowledge that further processing is stopped.
// The core code will handle the return.
}
// In a real scenario, you might also want to access $do_action_args to retrieve
// details about the action that was about to be completed.
// For example, if $do_action_args contains an 'action_id':
if ( is_array( $do_action_args ) && isset( $do_action_args['action_id'] ) ) {
$action_id = $do_action_args['action_id'];
// You could log this for debugging purposes.
// error_log( sprintf( 'About to complete action ID: %d', $action_id ) );
}
}, 10, 3 ); // Priority 10, accepts 3 arguments
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:605
do_action( 'automator_before_action_completed', $do_action_args );
$error_message = $this->get_action_error_message( $user_id, $action_data, $recipe_id, $error_message, $recipe_log_id, $args );
$process_further = apply_filters( 'automator_before_action_created', true, $user_id, $action_data, $recipe_id, $error_message, $recipe_log_id, $args );
do_action( 'automator_before_action_completed_after_message_and_process_further', $do_action_args, $error_message, $process_further );
if ( ! $process_further ) {
return;
}
Automator()->db->action->mark_complete( $action_id, $recipe_log_id, $action_data['completed'], $error_message );