Action
Since 6.7.0
uncanny-automator
automator_action_completion_status_changed
Manually edited by support team — custom description.
add_action( 'automator_action_completion_status_changed', $callback, 10, 5 );
Description
Fires when an Automator action's completion status is updated. This core hook enables custom logic to execute after an action is marked complete, with or without errors. Developers can leverage this to log status changes, send notifications, or trigger further workflows based on the provided action ID, recipe log ID, recipe details, completion status, and any error messages.
Usage
add_action( 'automator_action_completion_status_changed', 'your_function_name', 10, 5 );
Parameters
-
$action_id(int) - The action ID that was marked complete.
-
$recipe_log_id(int) - The recipe log ID associated with the action.
-
$recipe_details(array) - The recipe details associated with the action.
-
$completed(int) - The completion status (see Automator_Status constants).
-
$error_message(string) - Error message if the action failed, empty string if successful.
Examples
// Log a specific action completion to a custom log file when it's marked as completed with errors
add_action( 'automator_action_completion_status_changed', 'log_failed_automator_action', 10, 5 );
function log_failed_automator_action( $action_id, $recipe_log_id, $recipe_details, $completed, $error_message ) {
// Check if the action completed with errors
if ( Automator_Status::COMPLETED_WITH_ERRORS === $completed ) {
// Define the path to your custom log file
$log_file_path = WP_CONTENT_DIR . '/logs/automator-failed-actions.log';
// Ensure the log directory exists
if ( ! file_exists( dirname( $log_file_path ) ) ) {
wp_mkdir_p( dirname( $log_file_path ) );
}
// Format the log entry
$log_entry = sprintf(
"[%s] Action ID: %d, Recipe Log ID: %d, Error: %sn",
current_time( 'mysql' ),
$action_id,
$recipe_log_id,
$error_message
);
// Append the log entry to the custom log file
file_put_contents( $log_file_path, $log_entry, FILE_APPEND );
}
}
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/utilities/db/class-automator-db-handler-actions.php:376
public function mark_complete( $action_id, $recipe_log_id, $completed = 1, $error_message = '' ) {
$data = array(
'completed' => $completed,
'date_time' => current_time( 'mysql' ),
'error_message' => $error_message,
);
$where = array(
'automator_action_id' => $action_id,
'automator_recipe_log_id' => $recipe_log_id,
);
$updated = $this->update( $data, $where );
$recipe_details = Automator()->db->recipe->get_by( 'ID', $recipe_log_id );
if ( $updated ) {
/**
* Fires after an action has been successfully marked as complete in the database.
*
* This hook allows developers to perform additional operations when an action
* is marked complete, such as logging, notifications, or triggering other processes.
*
* @since 6.7.0
*
* @param int $action_id The action ID that was marked complete.
* @param int $recipe_log_id The recipe log ID associated with the action.
* @param array $recipe_details The recipe details associated with the action.
* @param int $completed The completion status (see Automator_Status constants).
* @param string $error_message Error message if the action failed, empty string if successful.
*
* @example
* // Hook into the action completion event
* add_action( 'automator_action_completion_status_changed', 'my_custom_action_complete_handler', 10, 5 );
*
* function my_custom_action_complete_handler( $action_id, $recipe_log_id, $recipe_details, $completed, $error_message ) {
* if ( Automator_Status::COMPLETED === $completed ) {
* // Action completed successfully
* error_log( "Action {$action_id} completed successfully for recipe log {$recipe_log_id}" );
* } elseif ( Automator_Status::COMPLETED_WITH_ERRORS === $completed ) {
* // Action completed with errors
* error_log( "Action {$action_id} completed with errors: {$error_message}" );
* }
* }
*/
do_action( 'automator_action_completion_status_changed', $action_id, $recipe_log_id, $recipe_details, $completed, $error_message );
// Fire specific hooks based on completion status
$all_statuses = Automator_Status::get_all_statuses();
if ( array_key_exists( $completed, $all_statuses ) ) {
// Convert status constant to hook-friendly name
$status_name = Automator_Status::get_class_name( $completed );
$status_name = str_replace( '-', '_', $status_name );
/**
* Fires after an action has been marked with a specific status.
*
* Dynamic hook name based on the completion status. This allows developers
* to hook into specific status changes for more targeted functionality.
*
* @since 6.7.0
*
* @param int $action_id The action ID that was marked with the status.
* @param int $recipe_log_id The recipe log ID associated with the action.
* @param array $recipe_details Details of the recipe log associated with the action.
* @param int $completed The completion status constant.
* @param string $error_message Error message if applicable, empty string otherwise.
*
* @example
* // Hook into specific status events
* add_action( 'automator_action_marked_completed_with_errors', 'handle_action_errors', 10, 5 );
* add_action( 'automator_action_marked_failed', 'handle_action_failure', 10, 5 );
* add_action( 'automator_action_marked_completed', 'handle_action_success', 10, 5 );
*/
do_action( "automator_action_marked_{$status_name}", $action_id, $recipe_log_id, $recipe_details, $completed, $error_message );
}
}
}
Internal Usage
Found in src/core/lib/utilities/db/class-automator-db-handler-actions.php:364:
* add_action( 'automator_action_completion_status_changed', 'my_custom_action_complete_handler', 10, 5 );