Filter uncanny-automator

automator_loop_logs_resources_status

Filters the status of automator logs resources before they are displayed in the backend.

add_filter( 'automator_loop_logs_resources_status', $callback, 10, 4 );

Description

Filters the status array for loop log entries before they are returned by the REST API. Developers can modify the status ID, message, and other details to customize how loop execution status is reported. This hook fires within the core REST API endpoint for fetching loop logs.


Usage

add_filter( 'automator_loop_logs_resources_status', 'your_function_name', 10, 4 );

Parameters

$log (mixed)
This parameter contains information about a specific log entry within the automator's loop processing.
$params (mixed)
This parameter represents the log entry for a specific loop execution.
$loop_id (mixed)
This parameter contains an array of parameters passed to the loop log resource endpoint.
$flow (mixed)
This parameter contains the ID of the current loop being processed.

Return Value

The filtered value.


Examples

add_filter( 'automator_loop_logs_resources_status', 'my_custom_automator_loop_status', 10, 4 );

/**
 * Custom filter to modify the status array for automator loop logs.
 *
 * This example demonstrates how to add extra information to the status array,
 * such as a user-friendly status name based on the status_id.
 *
 * @param array $status       The original status array.
 * @param array $log          The log entry data.
 * @param int   $loop_id      The ID of the loop.
 * @param object $flow       The flow object.
 *
 * @return array The modified status array.
 */
function my_custom_automator_loop_status( $status, $log, $loop_id, $flow ) {

	// Example: Add a user-friendly status name.
	$status_mapping = array(
		'1' => __( 'Pending', 'your-text-domain' ),
		'2' => __( 'In Progress', 'your-text-domain' ),
		'3' => __( 'Completed', 'your-text-domain' ),
		'4' => __( 'Failed', 'your-text-domain' ),
		'5' => __( 'Skipped', 'your-text-domain' ),
	);

	if ( isset( $status_mapping[ $status['status_id'] ] ) ) {
		$status['status_name'] = $status_mapping[ $status['status_id'] ];
	} else {
		$status['status_name'] = __( 'Unknown Status', 'your-text-domain' );
	}

	// Example: Add context from the flow object if available.
	if ( $flow && isset( $flow->title ) ) {
		$status['flow_title'] = $flow->title;
	}

	// Example: Convert elements_completed to a percentage.
	if ( $status['elements_total'] > 0 ) {
		$percentage_completed = ( $status['elements_completed'] / $status['elements_total'] ) * 100;
		$status['percentage_completed'] = round( $percentage_completed, 2 );
	} else {
		$status['percentage_completed'] = 0;
	}

	return $status;
}

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/rest/endpoint/log-endpoint/resources/loop-logs-resources.php:210

$datetime_ended = $utils::unix_timestamp_to_date( time() );
			}

			$date_next_process = $this->get_next_process( $log['process_id'] );

			$loop_id = absint( $log['loop_id'] );

			$status = apply_filters(
				'automator_loop_logs_resources_status',
				array(
					'status_id'          => $log['status'],
					'message'            => $log['message'],
					'elements_total'     => absint( $log['num_entities'] ),
					'elements_completed' => $elements_completed,
				),

Internal Usage

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

add_filter( 'automator_loop_logs_resources_status', array( $this, 'replace_status' ), 10, 4 );
Scroll to Top