Filter uncanny-automator-pro

automator_pro_action_condition_should_evaluate

Filter to override whether a condition should be evaluated. Filters whether a specific action condition should be evaluated before its logic runs.

add_filter( 'automator_pro_action_condition_should_evaluate', $callback, 10, 6 );

Description

Filter to override whether a specific condition should be evaluated by Uncanny Automator Pro. This hook fires before a condition's logic is processed. Developers can return `false` to skip evaluation entirely based on custom logic, providing granular control over automation flow.


Usage

add_filter( 'automator_pro_action_condition_should_evaluate', 'your_function_name', 10, 6 );

Parameters

$should_evaluate (bool)
Whether the condition should be evaluated.
$integration (string)
The integration code.
$code (string)
The condition code.
$condition (object)
The condition instance.
$action (array)
The action data.
$condition_data (array)
The condition data.

Return Value

The filtered value.


Examples

add_filter( 'automator_pro_action_condition_should_evaluate', 'my_custom_automator_condition_check', 10, 6 );

/**
 * Conditionally prevent an Uncanny Automator action condition from evaluating.
 *
 * This example demonstrates how to prevent a specific condition from being
 * evaluated if a certain user meta key is present and has a specific value.
 *
 * @param bool   $should_evaluate Whether the condition should be evaluated.
 * @param string $integration The integration code.
 * @param string $code The condition code.
 * @param object $condition The condition instance.
 * @param array  $action The action data.
 * @param array  $condition_data The condition data.
 *
 * @return bool The modified evaluation status.
 */
function my_custom_automator_condition_check( $should_evaluate, $integration, $code, $condition, $action, $condition_data ) {

    // Only apply this logic to a specific integration and condition code
    if ( 'woocommerce' === $integration && 'product_purchased' === $code ) {

        // Get the current user ID if available
        $user_id = get_current_user_id();

        // Check if the user is logged in and has the meta key 'disable_automator_woocommerce_checks' set to 'yes'
        if ( $user_id && get_user_meta( $user_id, 'disable_automator_woocommerce_checks', true ) === 'yes' ) {
            // Prevent this condition from being evaluated
            $should_evaluate = false;
        }
    }

    return $should_evaluate;
}

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/action-condition.php:240

final public function maybe_evaluate_condition( $action, $condition ) {

		$hydrated = false;

		try {
			// Check if dependencies are active before evaluating
			$should_evaluate = $this->is_dependency_active();

			/**
			 * Filter to override whether a condition should be evaluated.
			 *
			 * @param bool   $should_evaluate Whether the condition should be evaluated.
			 * @param string $integration The integration code.
			 * @param string $code The condition code.
			 * @param object $condition The condition instance.
			 * @param array  $action The action data.
			 * @param array  $condition_data The condition data.
			 */
			$should_evaluate = apply_filters( 'automator_pro_action_condition_should_evaluate', $should_evaluate, $this->integration, $this->code, $this, $action, $condition );

			if ( ! $should_evaluate ) {
				throw new Exception( sprintf( 'Condition %s (%s) cannot be evaluated because dependencies are not active', $this->code, $this->integration ) );
			}

			$this->hydrate( $action, $condition );
			$hydrated = true;
			$this->evaluate_condition();
		} catch ( Exception $e ) {
			automator_log( $e->getMessage() );

			if ( $hydrated ) {
				// evaluate_condition() threw — treat as condition failure.
				// This ensures errors (like date parsing failures) are properly
				// reflected in the action status (Skipped) instead of showing as Completed.
				$this->condition_failed( $e->getMessage() );
			} else {
				// hydrate() threw or dependencies inactive — this handler does not
				// own the condition. Pass through the original action data unchanged.
				$this->action = $action;
			}
		}

		return $this->action;
	}

Scroll to Top