automator_pro_loop_batch_completed
Fires after a batch of automator items has been processed and completed.
add_action( 'automator_pro_loop_batch_completed', $callback, 10, 2 );
Description
Fires after a batch of loop items has been processed in Uncanny Automator Pro. Developers can use this hook to perform actions after a specific batch of loop items has been completed, such as logging or triggering further automations based on the batch's outcome. This hook provides access to the loop item and the process transient identifier.
Usage
add_action( 'automator_pro_loop_batch_completed', 'your_function_name', 10, 2 );
Parameters
-
$process_transient(mixed) - This parameter holds the process transient object, which contains information about the current background process.
-
$value(mixed) - This parameter contains the transient object that stores the state and results of the background process's batch.
Examples
/**
* Example callback for the 'automator_pro_loop_batch_completed' action.
* This function demonstrates how to access the loop item and process transient
* when a batch of loop items has been completed.
*
* @param object $loop_item The current loop item object.
* @param string $process_transient_key The transient key for the process.
*/
function my_automator_pro_batch_completed_handler( $loop_item, $process_transient_key ) {
// In a real-world scenario, you might want to perform some cleanup,
// logging, or further processing based on the completed batch.
// For demonstration, we'll log a message indicating the batch completion.
// In a real plugin, you'd likely use a more robust logging mechanism.
error_log( sprintf(
'Uncanny Automator Pro: Batch completed for loop item ID %d using process transient key "%s".',
$loop_item->ID, // Assuming $loop_item is an object with an ID property.
$process_transient_key
) );
// You could also check if this is the final batch for a process.
// This would require retrieving the full process transient data if available.
// Example (hypothetical access, might need to adjust based on actual data structure):
// $process_data = get_transient( $process_transient_key );
// if ( isset( $process_data['batches_completed'] ) && $process_data['batches_completed'] >= $process_data['total_batches'] ) {
// error_log( 'This was the final batch for process: ' . $process_transient_key );
// // Perform final process completion actions here.
// }
}
// Hook the custom function to the 'automator_pro_loop_batch_completed' action.
// The '10' is the priority, and '2' is the number of arguments the callback accepts.
add_action( 'automator_pro_loop_batch_completed', 'my_automator_pro_batch_completed_handler', 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:445
public function loop_batch_completed( 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_completed',
$process_transient['loop_item'],
$value['process_transient']
);
}
Internal Usage
Found in src/core/services/logger-auto-remove.php:69:
add_action( 'automator_pro_loop_batch_completed', array( $this, 'log_loops_remove' ), 10, 3 );
Found in uncanny-automator-pro/src/core/loops/process-hooks-callbacks.php:38:
add_action( 'automator_pro_loop_batch_completed', array( $this, 'complete_entry' ), 10, 2 );