Filter uncanny-automator

automator_recipe_has_loop_running

Filters if a recipe's loop is currently running, allowing modification of the default true/false boolean value.

add_filter( 'automator_recipe_has_loop_running', $callback, 10, 2 );

Description

Fires when Uncanny Automator checks if a recipe's loop is currently active. Developers can filter this to manually indicate if a loop is running, useful for complex custom loop logic or for overriding the default behavior. The recipe ID is passed for context.


Usage

add_filter( 'automator_recipe_has_loop_running', 'your_function_name', 10, 2 );

Parameters

$this (mixed)
This parameter contains the current status of whether a loop is currently running for the recipe.
$recipe (mixed)
This parameter contains the current status of whether a loop is running within the recipe.

Return Value

The filtered value.


Examples

add_filter( 'automator_recipe_has_loop_running', 'my_custom_automator_loop_check', 10, 2 );

/**
 * Custom filter to conditionally prevent loops from running for specific recipes.
 *
 * This function checks if the recipe ID passed to the filter is in a predefined list
 * of recipes that should not have their loops running.
 *
 * @param bool  $has_loop_running The original value indicating if the loop is running.
 * @param int   $recipe_id        The ID of the current recipe being checked.
 * @return bool                  Returns false if the recipe ID is in the exclude list, otherwise returns the original value.
 */
function my_custom_automator_loop_check( $has_loop_running, $recipe_id ) {

	// Define a list of recipe IDs that should never run loops.
	$excluded_recipe_ids = array( 123, 456, 789 ); // Replace with actual recipe IDs

	// If the current recipe ID is in our exclusion list, prevent the loop from running.
	if ( in_array( $recipe_id, $excluded_recipe_ids, true ) ) {
		return false;
	}

	// Otherwise, return the original value.
	return $has_loop_running;
}

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/services/recipe/structure/miscellaneous.php:128

public function has_loop_running() {

		return apply_filters(
			'automator_recipe_has_loop_running',
			$this->has_loop_running,
			absint( self::$recipe->get_recipe_id() )
		);
	}

Internal Usage

Found in uncanny-automator-pro/src/core/loops/process-hooks-callbacks.php:47:

add_filter( 'automator_recipe_has_loop_running', array( $this, 'has_loop_running' ), 10, 2 );
Scroll to Top