automator_pro_actions_conditions_legacy_flow
If the `$current_action_conditions` is empty, we need to run the first action to trigger the conditions check. We only need to evaluate the conditions once for the whole group, since all action in the group will have the same conditions. We don't need to evaluate the conditions again & again for each action in the group, which accidentally will cause the action to be skipped. Filters legacy action conditions for a group, ensuring they are evaluated only once to prevent actions from being skipped.
add_filter( 'automator_pro_actions_conditions_legacy_flow', $callback, 10, 1 );
Description
Fires to determine if action conditions should be evaluated for a group. Developers can use this to prevent duplicate condition checks for grouped actions, ensuring actions aren't skipped. By default, conditions are evaluated once per group.
Usage
add_filter( 'automator_pro_actions_conditions_legacy_flow', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the 'automator_pro_actions_conditions_legacy_flow' filter.
*
* This filter allows modification of the logic that determines whether legacy
* flow conditions should be evaluated. In this example, we'll add a custom
* condition that bypasses the legacy flow if a specific meta key is present
* on the post associated with the action.
*
* @param bool $should_bypass_legacy_flow The current value of whether to bypass legacy flow.
* @return bool The modified value, potentially bypassing the legacy flow.
*/
function my_automator_pro_custom_legacy_flow_logic( $should_bypass_legacy_flow ) {
// Assume we have access to the current action object or relevant data
// For demonstration purposes, let's simulate having an action object.
// In a real scenario, you'd likely pass this data via another filter or have it accessible globally.
global $post; // Access the global post object if relevant
// Check if we are on a post editing screen and if a specific meta key is set.
// This is a hypothetical example. Adjust the meta key and conditions as needed.
if ( is_admin() && $post && get_post_meta( $post->ID, 'my_custom_automator_legacy_bypass', true ) ) {
return true; // Bypass the legacy flow
}
// If the custom condition isn't met, return the original value.
return $should_bypass_legacy_flow;
}
add_filter( 'automator_pro_actions_conditions_legacy_flow', 'my_automator_pro_custom_legacy_flow_logic', 10, 1 );
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:558
uncanny-automator-pro/src/core/classes/actions-conditions.php:565
public function maybe_process_further( $action, $actions_conditions ) {
$actions_conditions = json_decode( $actions_conditions, true );
if ( ! $actions_conditions ) {
throw new Exception( 'Something is wrong with the conditions json string' );
}
if ( ! isset( $action['action_data'] ) || ! isset( $action['action_data']['ID'] ) ) {
throw new Exception( 'Missing action ID' );
}
$current_action_conditions = null;
// We need to loop through all conditions until we find the first that includes the current action
foreach ( $actions_conditions as $condition_group ) {
if ( ! $this->is_correct_parent_recipe( $condition_group ) ) {
continue;
}
$condition_group_actions = array_map( 'absint', $condition_group['actions'] );
if ( in_array( absint( $action['action_data']['ID'] ), $condition_group_actions, true ) ) {
$current_action_conditions = $condition_group;
break;
}
}
if ( null === $current_action_conditions || empty( $current_action_conditions['conditions'] ) ) {
throw new Exception( 'There were no conditions for this action' );
}
if ( ! isset( $current_action_conditions['mode'] ) ) {
throw new Exception( 'Missing condition mode' );
}
// Check if all actions in the condition block are delayed, then postpone the evaluation of the condition block.
if ( ! isset( $action['action_data']['postponing_evaluation'] ) && true === $this->maybe_all_actions_in_condition_block_delayed( $current_action_conditions, $action ) ) {
$action['action_data']['postponing_evaluation'] = true;
return $action;
}
$running_in_loop = $this->maybe_running_in_loop( $action );
/**
* If the `$current_action_conditions` is empty, we need to run the first action to trigger the conditions check.
* We only need to evaluate the conditions once for the whole group, since all action in the group will have the same conditions.
* We don't need to evaluate the conditions again & again for each action in the group, which accidentally will cause the action to be skipped.
*/
if ( true === apply_filters( 'automator_pro_actions_conditions_legacy_flow', false ) || empty( $this->get_condition_results( $current_action_conditions['id'] ) ) || true === $running_in_loop ) {
$result_to_catch = 'any' === $current_action_conditions['mode'];
$action = $this->find_first( $action, $current_action_conditions, $result_to_catch );
}
// If any condition mode was selected and some of the actions failed while some didn't, need to remove the failed_actions_conditions flag to make sure the action status doesn't switch to Skipped.
if ( true === apply_filters( 'automator_pro_actions_conditions_legacy_flow', false ) || true === $running_in_loop ) {
if ( 'any' === $current_action_conditions['mode'] && $action['process_further'] ) {
$action['action_data']['failed_actions_conditions'] = false;
}
} else {
// Since the conditions are evaluated once for the whole group, we need to update the results.
if ( $this->maybe_evaluate_condition_block( $current_action_conditions ) ) {
$action['action_data']['failed_actions_conditions'] = false;
$action['process_further'] = true;
} else {
$action['action_data']['failed_actions_conditions'] = true;
$action['process_further'] = false;
}
}
return $action;
}