Filter uncanny-automator

automator_get_action_completed_status

Filters the completion status of a recipe action, allowing modification of the success or failure outcome.

add_filter( 'automator_get_action_completed_status', $callback, 10, 7 );

Description

Filters the completion status of an action within an automation recipe. Developers can use this hook to customize or override the default completion status based on various parameters like user ID, action data, recipe ID, error messages, and log IDs. This allows for dynamic determination of whether an action was successfully completed.


Usage

add_filter( 'automator_get_action_completed_status', 'your_function_name', 10, 7 );

Parameters

$completed (mixed)
This parameter holds the completion status of the action, where 0 means not completed, 1 means completed, and 2 means completed with errors.
$user_id (mixed)
This parameter indicates whether the action has been completed (1), not completed (0), or completed with errors (2).
$action_data (mixed)
This parameter contains the ID of the user for whom the action is being completed.
$recipe_id (mixed)
This parameter contains the data associated with the specific action being processed within the recipe.
$error_message (mixed)
This parameter contains the error message if the action completed with errors.
$recipe_log_id (mixed)
This parameter holds the ID of the recipe log entry that corresponds to the current action's execution.
$args (mixed)
This parameter is an array that can contain additional arguments passed to the function.

Return Value

The filtered value.


Examples

<?php
/**
 * Custom filter to modify the action completion status.
 *
 * This function demonstrates how to hook into the 'automator_get_action_completed_status'
 * filter to potentially change the status of an automator action based on specific conditions.
 * For example, we might want to mark an action as 'RETRY' if it failed due to a temporary
 * external service issue, allowing the recipe to be retried later.
 *
 * @param mixed $completed       The current completion status (e.g., Automator_Status::COMPLETED, Automator_Status::FAILED).
 * @param int   $user_id         The ID of the user for whom the action is being processed.
 * @param array $action_data     An array containing the data for the action being processed.
 * @param int   $recipe_id       The ID of the recipe the action belongs to.
 * @param string $error_message  An error message if the action has failed.
 * @param int   $recipe_log_id   The ID of the log entry for this recipe execution.
 * @param array $args            An array of additional arguments passed to the filter.
 *
 * @return mixed The potentially modified completion status.
 */
add_filter( 'automator_get_action_completed_status', function ( $completed, $user_id, $action_data, $recipe_id, $error_message, $recipe_log_id, $args ) {

    // Example: If the error message indicates a specific external service timeout,
    // we might want to mark it for retry instead of a hard failure.
    // In a real scenario, you'd have more robust checks here.
    if ( $completed === Automator_Status::FAILED && ! empty( $error_message ) ) {
        if ( strpos( $error_message, 'External API timeout' ) !== false ) {
            // Assuming Automator_Status::RETRY is a valid status within the plugin.
            // You might need to define this or use a custom status.
            return Automator_Status::RETRY;
        }
    }

    // If no special conditions are met, return the original status.
    return $completed;

}, 10, 7 );

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:789

public function get_action_completed_status( $user_id = null, $action_data = null, $recipe_id = null, $error_message = '', $recipe_log_id = null, $args = array() ) {

		/**
		 * @var $completed
		 * Meaning of each number
		 *
		 * 0 = not completed
		 * 1 = completed
		 * 2 = completed with errors, error message provided
		 * 5 = scheduled
		 * 7 = cancelled
		 * 8 = skipped
		 * 9 = completed, do nothing
		 * 11 = completed with notice
		 */
		$completed = Automator_Status::NOT_COMPLETED;

		// Completed with notice.
		if ( is_array( $action_data ) && ! empty( $error_message ) && key_exists( 'complete_with_notice', $action_data ) ) {
			$completed = Automator_Status::COMPLETED_WITH_NOTICE;
		}

		// Completed with errors.
		if ( is_array( $action_data ) && ! empty( $error_message ) && key_exists( 'complete_with_errors', $action_data ) ) {
			$completed = Automator_Status::COMPLETED_WITH_ERRORS;
		}

		// Completed, do nothing.
		if ( is_array( $action_data ) && key_exists( 'do-nothing', $action_data ) ) {
			$completed = Automator_Status::DID_NOTHING;
		}

		// Completed.
		if ( empty( $error_message ) ) {
			$completed = Automator_Status::COMPLETED;
		}

		return apply_filters( 'automator_get_action_completed_status', $completed, $user_id, $action_data, $recipe_id, $error_message, $recipe_log_id, $args );
	}


Internal Usage

Found in src/integrations/linkedin/helpers/linkedin-scheduled-posts-manager.php:96:

add_filter( 'automator_get_action_completed_status', array( $this, 'filter_action_status' ), 10, 7 );

Found in src/integrations/whatsapp/actions/whatsapp-send-message-template.php:25:

add_filter( 'automator_get_action_completed_status', array( $this, 'set_completed_status' ), 10, 7 );

Found in src/integrations/whatsapp/actions/whatsapp-send-message.php:24:

add_filter( 'automator_get_action_completed_status', array( $this, 'set_completed_status' ), 10, 7 );

Found in src/integrations/instagram/traits/trait-instagram-publish-retry.php:59:

add_filter( 'automator_get_action_completed_status', array( $this, 'retry_set_completed_status' ), 10, 7 );

Found in uncanny-automator-pro/src/core/classes/actions-conditions.php:89:

add_filter( 'automator_get_action_completed_status', array( $this, 'change_action_completed_status' ), 10, 7 );

Found in uncanny-automator-pro/src/core/classes/async-actions.php:32:

add_filter( 'automator_get_action_completed_status', array( $this, 'change_action_completed_status' ), 10, 7 );
Scroll to Top