Action uncanny-automator-pro

automator_pro_loop_batch_item_process_terminated

Fires when a batch item process in Automator Pro is terminated unexpectedly, providing access to process transient data and the value causing termination.

add_action( 'automator_pro_loop_batch_item_process_terminated', $callback, 10, 2 );

Description

Fires when a single item's processing within a batch loop has ended. Developers can hook into this to perform cleanup or log specific item termination details. This hook passes the loop item and its corresponding process transient name. Ensure your callback handles potential missing transient data.


Usage

add_action( 'automator_pro_loop_batch_item_process_terminated', 'your_function_name', 10, 2 );

Parameters

$process_transient (mixed)
This parameter holds the transient key used to store the background process information for the loop item.
$value (mixed)
This parameter contains the transient key that stores information about the terminated batch process.

Examples

<?php
/**
 * Example callback function for the 'automator_pro_loop_batch_item_process_terminated' hook.
 * This function logs the termination of a loop batch item process.
 *
 * @param array $loop_item The data associated with the terminated loop item.
 * @param string $process_transient The transient key for the terminated process.
 */
function my_automator_log_loop_termination( $loop_item, $process_transient ) {
	// Ensure we have valid data before proceeding.
	if ( ! is_array( $loop_item ) || empty( $loop_item['ID'] ) || empty( $process_transient ) ) {
		return;
	}

	// Log the event for debugging purposes.
	error_log( sprintf(
		'Automator Pro: Loop batch item process terminated. Loop Item ID: %1$d, Process Transient: %2$s',
		absint( $loop_item['ID'] ),
		esc_html( $process_transient )
	) );

	// Potentially perform other actions here, like updating an entry status
	// or cleaning up related temporary data, if the core function doesn't already.
	// For demonstration, we'll just log.
}
add_action( 'automator_pro_loop_batch_item_process_terminated', 'my_automator_log_loop_termination', 10, 2 );

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/background-process/entity-actions.php:467

public function loop_terminated( array $value ): void {

		if ( ! isset( $value ) || ! isset( $value['process_transient'] ) ) {
			return;
		}

		$process_transient = Registry::get_process_transient( $value['process_transient'] );

		do_action(
			'automator_pro_loop_batch_item_process_terminated',
			$process_transient['loop_item'],
			$value['process_transient']
		);
	}


Internal Usage

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

add_action( 'automator_pro_loop_batch_item_process_terminated', array( $this, 'complete_entry_on_exit' ), 10, 2 );
Scroll to Top