Action uncanny-automator

automator_recipe_completed_with_errors

Fires when an Automator recipe completes with one or more errors, providing details about the failed recipe and its execution.

add_action( 'automator_recipe_completed_with_errors', $callback, 10, 4 );

Description

Fired when a recipe finishes execution with errors. Developers can use this hook to perform custom actions, such as logging additional details, sending notifications, or triggering alternative workflows based on the specific errors encountered during recipe completion. It provides recipe ID, user ID, log ID, and arguments including error messages.


Usage

add_action( 'automator_recipe_completed_with_errors', 'your_function_name', 10, 4 );

Parameters

$recipe_id (mixed)
The ID of the recipe that completed with errors.
$user_id (mixed)
This parameter contains the unique identifier for the specific recipe that has completed with errors.
$recipe_log_id (mixed)
The ID of the user whose recipe execution resulted in errors.
$args (mixed)
This parameter contains the ID of the recipe log entry associated with the completed recipe.

Examples

<?php
/**
 * Log recipe completion with errors to a custom error log.
 *
 * @param int $recipe_id      The ID of the recipe that completed with errors.
 * @param int $user_id        The ID of the user for whom the recipe ran.
 * @param int $recipe_log_id  The ID of the specific recipe log entry.
 * @param array $args         Additional arguments passed to the hook, including error message.
 */
function my_automator_log_recipe_errors( $recipe_id, $user_id, $recipe_log_id, $args ) {
    // Ensure the error arguments are present
    if ( ! isset( $args['message'] ) || empty( $args['message'] ) ) {
        return; // Nothing to log if there's no specific error message
    }

    $user_info = get_user_by( 'id', $user_id );
    $user_login = $user_info ? $user_info->user_login : 'N/A';

    $log_message = sprintf(
        '[Automator Recipe Error] Recipe ID: %d, User: %s (ID: %d), Log ID: %d, Error: %s',
        absint( $recipe_id ),
        esc_html( $user_login ),
        absint( $user_id ),
        absint( $recipe_log_id ),
        esc_html( $args['message'] )
    );

    // Use WordPress's built-in error logging if available, otherwise a simple file log.
    if ( function_exists( 'error_log' ) ) {
        error_log( $log_message );
    } else {
        // Fallback to a custom log file if error_log is not configured or available.
        $log_file = WP_CONTENT_DIR . '/automator-recipe-errors.log';
        file_put_contents( $log_file, current_time( 'mysql' ) . ' - ' . $log_message . PHP_EOL, FILE_APPEND );
    }
}

// Hook into the 'automator_recipe_completed_with_errors' action.
// The '4' indicates that this callback function accepts 4 arguments.
add_action( 'automator_recipe_completed_with_errors', 'my_automator_log_recipe_errors', 10, 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:972

Automator()->db->recipe->mark_complete_with_error( $recipe_id, $recipe_log_id, $comp );

			$args['message']   = $actionable_error->error_message;
			$args['completed'] = $actionable_error->completed;

			if ( Automator_Status::COMPLETED_WITH_ERRORS === absint( $comp ) ) {
				do_action( 'automator_recipe_completed_with_errors', $recipe_id, $user_id, $recipe_log_id, $args );
			}
		}

		do_action_deprecated(
			'uap_recipe_completed',
			array(
				$recipe_id,


Internal Usage

Found in src/integrations/uncanny-automator/triggers/uoa-user-recipe-completed-with-errors.php:35:

$this->add_action( 'automator_recipe_completed_with_errors', 99, 4 );
Scroll to Top