Action uncanny-automator-pro

automator_pro_actions_conditions_evaluated

Fires after all Automator Pro action conditions have been evaluated for a specific action.

add_action( 'automator_pro_actions_conditions_evaluated', $callback, 10, 3 );

Description

Fires after conditions for an Uncanny Automator action have been evaluated. Developers can use this hook to access the evaluated condition results and the action object. This allows for custom modification or logging of condition outcomes before the action proceeds, but be cautious when altering the flow as it can impact the automation.


Usage

add_action( 'automator_pro_actions_conditions_evaluated', 'your_function_name', 10, 3 );

Parameters

$evaluated_conditions (mixed)
This parameter contains an array of all conditions that have been evaluated for the current action.
$conditions (mixed)
This parameter contains an array of all conditions that have been evaluated for the current action.
$action (mixed)
This parameter contains all the conditions that were evaluated for the specific action.

Examples

<?php
/**
 * Example of how to hook into the 'automator_pro_actions_conditions_evaluated' action.
 * This function demonstrates how to log the results of evaluated conditions
 * for a specific action, perhaps for debugging or auditing purposes.
 *
 * @param array $evaluated_conditions An array containing the results of each evaluated condition.
 *                                     The keys are the condition IDs and the values are their status ('succeeded' or 'failed').
 * @param array $conditions           An array representing the conditions being evaluated for the action.
 * @param array $action               An array representing the Uncanny Automator action.
 */
function my_automator_log_evaluated_conditions( $evaluated_conditions, $conditions, $action ) {

	// Log a message if the action has a specific ID we want to monitor.
	// In a real-world scenario, you might use a more robust logging mechanism.
	if ( isset( $action['ID'] ) && $action['ID'] == 123 ) { // Replace 123 with a real action ID if known.
		error_log( sprintf(
			'Uncanny Automator Pro: Conditions evaluated for Action ID %d. Results: %s',
			$action['ID'],
			print_r( $evaluated_conditions, true )
		) );
	}

	// You could also add more complex logic here, for example:
	// - Check if any condition failed and perform a different action.
	// - Store custom data related to the condition evaluation.
	$all_conditions_succeeded = true;
	foreach ( $evaluated_conditions as $status ) {
		if ( 'failed' === $status ) {
			$all_conditions_succeeded = false;
			break;
		}
	}

	if ( ! $all_conditions_succeeded ) {
		error_log( sprintf(
			'Uncanny Automator Pro: One or more conditions failed for Action ID %d.',
			$action['ID']
		) );
		// Potentially trigger a notification or a fallback process if conditions fail.
	}

}

// Add the function to the 'automator_pro_actions_conditions_evaluated' hook.
// The '3' indicates the priority, and '3' is the number of arguments our callback function accepts.
add_action( 'automator_pro_actions_conditions_evaluated', 'my_automator_log_evaluated_conditions', 10, 3 );

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/classes/actions-conditions.php:688
uncanny-automator-pro/src/core/classes/actions-conditions.php:706

public function find_first( $action, $conditions, $result_to_catch ) {

		$evaluated_conditions = array();
		$condition_result     = array();

		foreach ( $conditions['conditions'] as $condition ) {

			// Collect all conditions that has been evaluated.
			$evaluated_conditions[] = $condition;

			$action = apply_filters( 'automator_pro_evaluate_actions_conditions', $action, $condition );

			if ( isset( $action['process_further'] ) ) {

				$condition_result[ $condition['id'] ] = 'failed';

				// If the results to catch is false and process further is true, this means the current condition succeeds.
				if ( false === $result_to_catch && true === $action['process_further'] ) {
					$condition_result[ $condition['id'] ] = 'succeeded';
				}

				// Break from the loop if one of the conditions meets the result we are searching for
				if ( $result_to_catch === $action['process_further'] ) {
					$condition_result[ $condition['id'] ] = 'succeeded';
					// The 'All' conditions has set $result_to_catch to false.
					// If process further is false consider this condition as failed.
					if ( false === $action['process_further'] ) {
						$condition_result[ $condition['id'] ] = 'failed';
					}
					// Pass all collected evaluated conditions before returning the $action.
					do_action( 'automator_pro_actions_conditions_evaluated', $evaluated_conditions, $conditions, $action );
					do_action( 'automator_pro_actions_conditions_result', $condition_result, $conditions, $action );

					$this->store_condition_results( $conditions['id'], $condition_result );
					$this->evaluated_conditions[ $conditions['id'] ] = $condition_result;

					return $action;
				}
			}
		}

		// If we were looking for a true, and haven't found one above, consider this as failed
		if ( $result_to_catch ) {
			$action['process_further'] = false;
		}

		do_action( 'automator_pro_actions_conditions_result', $condition_result, $conditions, $action );
		// Pass all collected evaluated conditions.
		do_action( 'automator_pro_actions_conditions_evaluated', $evaluated_conditions, $conditions, $action );

		$this->store_condition_results( $conditions['id'], $condition_result );

		return $action;
	}


Scroll to Top