Filter uncanny-automator

automator_triggers_completed_run_flow_type

Filters the type of flow completed after an Automator run, allowing modification of the run's flow type.

add_filter( 'automator_triggers_completed_run_flow_type', $callback, 10, 5 );

Description

Filters the determined flow type for a completed recipe run. Developers can use this to modify whether a recipe is considered "linear" (sequential triggers only) or not, potentially altering how the recipe's flow is interpreted after all triggers are finished.


Usage

add_filter( 'automator_triggers_completed_run_flow_type', 'your_function_name', 10, 5 );

Parameters

$recipe_id (mixed)
This parameter is a boolean value that indicates whether the recipe contains only linear triggers.
$user_id (mixed)
The ID of the recipe that has completed its run.
$recipe_log_id (mixed)
This parameter contains the ID of the user for whom the recipe is currently running or has run.
$args (mixed)
This parameter is a flexible array or object that can contain various arguments related to the recipe's triggers, including potentially modified trigger data.
$this (mixed)
This parameter represents the current instance of the `Automator_Recipe_Process_Complete` class.

Return Value

The filtered value.


Examples

/**
 * Example of filtering the flow type for a completed recipe run.
 *
 * This function demonstrates how to modify the default 'linear' flow type
 * if a recipe has a more complex structure (e.g., branching logic).
 *
 * @param string  $flow_type     The current flow type (defaults to 'linear').
 * @param int     $recipe_id     The ID of the recipe that just completed.
 * @param int     $user_id       The ID of the user associated with the recipe run.
 * @param int     $recipe_log_id The ID of the log entry for this recipe run.
 * @param array   $args          Additional arguments passed to the filter.
 * @param object  $object        The instance of the Automator Recipe Process Complete object.
 *
 * @return string The modified flow type.
 */
function my_automator_custom_flow_type( $flow_type, $recipe_id, $user_id, $recipe_log_id, $args, $object ) {

	// In a real-world scenario, you might inspect $args or $recipe_id
	// to determine if this recipe has custom flow logic.
	// For this example, let's assume recipes with ID 10 and 20
	// have a 'parallel' flow type if they are not already 'linear'.
	if ( in_array( $recipe_id, array( 10, 20 ) ) && 'linear' === $flow_type ) {
		// Check if the recipe has any actions that are marked as 'parallel'.
		// This is a hypothetical check, the actual structure of $args
		// or how to determine this would depend on your plugin's internal data.
		// For demonstration, we'll just hardcode it.
		$has_parallel_actions = false;
		if ( isset( $args['actions'] ) && is_array( $args['actions'] ) ) {
			foreach ( $args['actions'] as $action ) {
				if ( isset( $action['flow_type'] ) && 'parallel' === $action['flow_type'] ) {
					$has_parallel_actions = true;
					break;
				}
			}
		}

		if ( $has_parallel_actions ) {
			return 'parallel'; // Override to 'parallel' for these specific recipes
		}
	}

	// If no custom logic applies, return the original flow type.
	return $flow_type;
}

// Add the filter with the correct number of arguments the filter expects.
// The Automator plugin passes 6 arguments: 'linear', $recipe_id, $user_id, $recipe_log_id, $args, $this.
add_filter( 'automator_triggers_completed_run_flow_type', 'my_automator_custom_flow_type', 10, 6 );

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

// Store the historical count of a recipe
			$this->add_recipe_count( $recipe_id );

			// All triggers are completed. Now fix the $args. See function.
			$args = $this->maybe_get_triggers_of_a_recipe( $args );

			// Flow type determines if the recipe contains linear only.
			$flow_type = apply_filters( 'automator_triggers_completed_run_flow_type', 'linear', $recipe_id, $user_id, $recipe_log_id, $args, $this );

			if ( 'linear' === $flow_type ) {
				// If it does, run all actions that are 'linear'.
				$this->complete_actions( $recipe_id, $user_id, $recipe_log_id, $args );
			}

			// Support custom flow types.


Scroll to Top