Filter uncanny-automator-pro

automator_pro_loop_entry_initialized

Filters the entry after it has been initialized within the Automator Pro loop for processing.

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

Description

Fires after a loop entry is initialized, providing access to its ID, type, loopable items, recipe structure, and process arguments. Developers can use this filter to modify these values or add custom logic before the entry is added to the database, ensuring accurate loop progression.


Usage

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

Parameters

$this (mixed)
This parameter contains the unique identifier for the current loop.
$this (mixed)
This parameter contains the unique identifier for the current loop.
$loopable_items (mixed)
This parameter contains the current loop type.
$this (mixed)
This parameter contains the collection of items that the current loop will iterate over.
$this (mixed)
This parameter holds the JSON-encoded representation of the actions within the current recipe structure.

Return Value

The filtered value.


Examples

<?php
/**
 * Example callback for the 'automator_pro_loop_entry_initialized' filter.
 * This function might log some information about the initialized loop entry
 * or modify the generated process ID.
 *
 * @param string $loop_id The ID of the loop.
 * @param string $loop_type The type of the loop.
 * @param array  $loopable_items The items that are loopable.
 * @param string $actions_json JSON encoded string of the recipe's actions.
 * @param array  $process_args Arguments passed to the process.
 *
 * @return string|WP_Error The modified process ID or a WP_Error object.
 */
function my_automator_pro_handle_loop_entry_initialized( $loop_id, $loop_type, $loopable_items, $actions_json, $process_args ) {

	// Example: Log some details about the loop initialization.
	// In a real-world scenario, you might use a more robust logging mechanism.
	error_log( sprintf(
		'Automator Pro Loop Initialized: Loop ID: %s, Type: %s, Item Count: %d',
		$loop_id,
		$loop_type,
		count( $loopable_items )
	) );

	// Example: Modify the process ID based on the loop type.
	// This is a simplified example; real logic would be more complex.
	$new_process_id = $loop_id . '_' . sanitize_title( $loop_type );

	// You could also add more context to the ID based on the actions or arguments.
	// For instance, if a specific action is present:
	if ( strpos( $actions_json, '"wordpress_add_tag"' ) !== false ) {
		$new_process_id .= '_with_tag';
	}

	// Return the modified process ID.
	return $new_process_id;
}

// Add the filter callback.
// The last parameter '5' indicates that our callback function accepts 5 arguments.
add_filter( 'automator_pro_loop_entry_initialized', 'my_automator_pro_handle_loop_entry_initialized', 10, 5 );
?>

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

uncanny-automator-pro/src/core/loops/loop/execute.php:326

public function generate_process_id( $loopable_items ) {

		return apply_filters(
			'automator_pro_loop_entry_initialized',
			$this->get_loop_id(),
			$this->get_loop_type(),
			$loopable_items,
			wp_json_encode( $this->recipe_structure->retrieve()->get( 'actions' ) ),
			$this->get_process_args()
		);
	}


Internal Usage

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

add_filter( 'automator_pro_loop_entry_initialized', array( $this, 'add_entry' ), 10, 5 );
Scroll to Top