Filter
uncanny-automator-pro
automator_pro_evaluate_actions_conditions
Filters the actions and conditions during the evaluation process to allow modification before execution.
add_filter( 'automator_pro_evaluate_actions_conditions', $callback, 10, 2 );
Description
Fires during the evaluation of conditions for Uncanny Automator Pro actions. Developers can modify the action and condition data to influence the evaluation outcome. Use this to conditionally skip or alter how conditions are processed before the final result is determined.
Usage
add_filter( 'automator_pro_evaluate_actions_conditions', 'your_function_name', 10, 2 );
Parameters
-
$action(mixed) - This parameter contains the action object that is currently being evaluated against the conditions.
-
$condition(mixed) - This parameter contains information about the specific action being evaluated.
Return Value
The filtered value.
Examples
/**
* Example callback for the 'automator_pro_evaluate_actions_conditions' filter.
*
* This function demonstrates how to modify the 'process_further' flag
* for a specific condition based on custom logic.
*
* @param array $action The current action being processed.
* @param array $condition The current condition being evaluated.
*
* @return array The modified $action array.
*/
add_filter( 'automator_pro_evaluate_actions_conditions', function( $action, $condition ) {
// Example: If the condition is of type 'user_role' and the user has a specific role,
// we might want to prevent further processing of this condition.
if ( isset( $condition['type'] ) && $condition['type'] === 'user_role' ) {
$user_id = get_current_user_id();
if ( $user_id ) {
$user = wp_get_current_user();
$allowed_roles = array( 'administrator', 'editor' ); // Define roles that should bypass this condition's logic.
// Check if the current user has any of the allowed roles.
$has_allowed_role = false;
foreach ( $user->roles as $role ) {
if ( in_array( $role, $allowed_roles, true ) ) {
$has_allowed_role = true;
break;
}
}
// If the user has an allowed role, mark this condition as 'failed' by setting 'process_further' to true.
// This effectively bypasses the actual condition evaluation for this specific user and role type.
if ( $has_allowed_role ) {
$action['process_further'] = true;
}
}
}
return $action;
}, 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/classes/actions-conditions.php:668
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;
}
Internal Usage
Found in uncanny-automator-pro/src/core/classes/action-condition.php:150:
add_filter( 'automator_pro_evaluate_actions_conditions', array( $this, 'maybe_evaluate_condition' ), 10, 2 );