Action Since 6.7.0 uncanny-automator

automator_recipe_marked_complete_with_error

Fires after a recipe has been successfully marked as complete with error in the database. This hook allows developers to perform additional operations when a recipe is marked complete with error status, such as error logging, notifications, or cleanup. Fires when a recipe is marked complete with an error, providing recipe and log IDs for further actions.

add_action( 'automator_recipe_marked_complete_with_error', $callback, 10, 3 );

Description

This action hook fires when a recipe in AutomatorWP is marked as "complete with error". Developers can use this hook to perform custom actions like detailed error logging, sending immediate notifications about recipe failures, or initiating cleanup tasks when a recipe execution encounters issues. It provides the recipe ID, log ID, and completion status for context.


Usage

add_action( 'automator_recipe_marked_complete_with_error', 'your_function_name', 10, 3 );

Parameters

$recipe_id (int)
The recipe ID that was marked complete with error.
$recipe_log_id (int)
The recipe log ID that was marked complete with error.
$complete (int)
The completion status.

Examples

/**
 * Handle recipes that completed with errors by sending a notification to the site administrator.
 */
add_action( 'automator_recipe_marked_complete_with_error', 'notify_admin_on_recipe_error', 10, 3 );
function notify_admin_on_recipe_error( $recipe_id, $recipe_log_id, $complete ) {
    // The hook fires for any completion status, but we only care about errors.
    // According to the source, $complete === 2 indicates completion with errors.
    if ( 2 === $complete ) {
        $admin_email = get_option( 'admin_email' );
        if ( $admin_email ) {
            $recipe = AutomatorWP_DB_Recipes::get_recipe( $recipe_id );
            $recipe_title = $recipe ? $recipe->title : 'Unknown Recipe';

            $subject = sprintf( 'WordPress Automator: Recipe "%s" Completed with Errors', $recipe_title );
            $body = sprintf(
                'A recipe has completed with errors. <br><br>' .
                'Recipe ID: %d<br>' .
                'Recipe Title: %s<br>' .
                'Recipe Log ID: %d<br>' .
                'You can view the recipe log for more details: <a href="%s">View Log</a>',
                $recipe_id,
                $recipe_title,
                $recipe_log_id,
                admin_url( "edit.php?post_type=recipe&page=automatorwp-logs&recipe_id={$recipe_id}&log_id={$recipe_log_id}" )
            );

            wp_mail( $admin_email, $subject, $body );
        }
    }
}

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-recipes.php:239

public function mark_complete_with_error( $recipe_id, $recipe_log_id, $complete ) {
		$updated = $this->update(
			array(
				'completed' => $complete,
			),
			array(
				'ID'                  => $recipe_log_id,
				'automator_recipe_id' => $recipe_id,
			),
			array(
				'%d',
			),
			array(
				'%d',
				'%d',
			)
		);

		if ( $updated ) {
			/**
			 * Fires after a recipe has been successfully marked as complete with error in the database.
			 *
			 * This hook allows developers to perform additional operations when a recipe
			 * is marked complete with error status, such as error logging, notifications, or cleanup.
			 *
			 * @since 6.7.0
			 *
			 * @param int $recipe_id     The recipe ID that was marked complete with error.
			 * @param int $recipe_log_id The recipe log ID that was marked complete with error.
			 * @param int $complete      The completion status.
			 *
			 * @example
			 * // Hook into the recipe completion with error event
			 * add_action( 'automator_recipe_marked_complete_with_error', 'my_custom_recipe_error_handler', 10, 3 );
			 *
			 * function my_custom_recipe_error_handler( $recipe_id, $recipe_log_id, $complete ) {
			 *     if ( 2 === $complete ) {
			 *         // Recipe completed with errors
			 *         error_log( "Recipe {$recipe_id} (log {$recipe_log_id}) completed with errors" );
			 *     }
			 * }
			 */
			do_action( 'automator_recipe_marked_complete_with_error', $recipe_id, $recipe_log_id, $complete );
		}
	}

Internal Usage

Found in src/core/lib/utilities/db/class-automator-db-handler-recipes.php:230:

* add_action( 'automator_recipe_marked_complete_with_error', 'my_custom_recipe_error_handler', 10, 3 );
Scroll to Top