Action uncanny-automator-pro

automator_pro_actions_conditions_result

Fires after Automator Pro evaluates conditions for an action, providing access to results and conditional data.

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

Description

Fired after all conditions for an Uncanny Automator action have been evaluated. Developers can use this hook to modify the final condition result or perform custom logic based on whether the action should proceed. It receives the evaluated condition results, the full condition array, and the action details.


Usage

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

Parameters

$condition_result (mixed)
This parameter holds the evaluation result of the current condition being processed within the loop.
$conditions (mixed)
This parameter contains the results of evaluating each individual condition within the set of conditions being processed.
$action (mixed)
This parameter contains an array of all the conditions that have been evaluated for the current action.

Examples

<?php
/**
 * Example of how to use the 'automator_pro_actions_conditions_result' hook.
 * This example logs the condition results for a specific action if a certain condition is met.
 */
add_action(
	'automator_pro_actions_conditions_result',
	function ( $condition_result, $conditions, $action ) {
		// Example: Check if the action is for a specific user role or has a particular tag.
		// Replace 'your_specific_action_id' with the actual ID of the action you want to target.
		if ( isset( $action['id'] ) && 'your_specific_action_id' === $action['id'] ) {

			// Log the condition results for debugging or further processing.
			error_log(
				sprintf(
					'Uncanny Automator Pro - Condition Results for Action "%s" (%s): %s',
					esc_html( $action['name'] ),
					esc_html( $action['id'] ),
					json_encode( $condition_result )
				)
			);

			// Example: Modify the condition result if a specific condition failed.
			// This is a hypothetical example; actual modification logic would depend on your needs.
			if ( isset( $condition_result['some_condition_id'] ) && 'failed' === $condition_result['some_condition_id'] ) {
				// Potentially set another condition to 'skipped' or log a specific warning.
				// $condition_result['another_condition_id'] = 'skipped';
				error_log( 'A critical condition failed for this action.' );
			}
		}
	},
	10, // Priority
	3  // Accepted args count
);
?>

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

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