Filter
uncanny-automator
automator_get_trigger_log_id_process_recipe
Filters the trigger log ID for processing recipes to allow for custom logic.
add_filter( 'automator_get_trigger_log_id_process_recipe', $callback, 10, 5 );
Description
Allows developers to filter the `recipe_log_id` before a recipe's trigger log entry is created or retrieved. This is useful for custom logic to determine or modify the log ID based on user, trigger, or recipe data, especially when overriding default behavior.
Usage
add_filter( 'automator_get_trigger_log_id_process_recipe', 'your_function_name', 10, 5 );
Parameters
-
$user_id(mixed) - This parameter is a placeholder for a boolean value, likely indicating whether the trigger log ID should be processed.
-
$trigger_id(mixed) - This parameter represents the ID of the user for whom the recipe is being processed.
-
$recipe_id(mixed) - This parameter represents the unique identifier of the trigger that initiated the recipe process.
-
$recipe_log_id(mixed) - This parameter represents the unique identifier for a specific log entry of a recipe execution.
-
$args(mixed) - This parameter contains any additional arguments passed to the trigger process.
Return Value
The filtered value.
Examples
/**
* Modify the process_recipe flag based on specific conditions.
*
* This filter can be used to prevent a recipe from processing further
* under certain circumstances, for example, if the trigger has specific
* requirements that are not met, or if it's a recurring trigger and
* already processed recently.
*
* @param bool $process_recipe The default value of the flag (false in the source context).
* @param int $user_id The ID of the user.
* @param int $trigger_id The ID of the trigger.
* @param int $recipe_id The ID of the recipe.
* @param int $recipe_log_id The ID of the recipe log entry.
* @param array $args Additional arguments passed to the filter.
*
* @return bool Returns `false` to continue processing, or `true` to stop processing.
*/
add_filter( 'automator_get_trigger_log_id_process_recipe', function( $process_recipe, $user_id, $trigger_id, $recipe_id, $recipe_log_id, $args ) {
// Example: Prevent processing if the recipe is in a 'pending review' state for a specific user.
// This is a hypothetical scenario; you'd replace this with actual logic.
if ( $recipe_id === 123 && $user_id === 456 ) {
// In a real scenario, you'd likely query a custom post meta or another data source
// to determine if the recipe is in 'pending review' for this user.
$is_pending_review = true; // Simulated condition
if ( $is_pending_review ) {
// If the recipe is pending review for this user, stop processing.
return true;
}
}
// Example: Prevent processing if a specific argument indicates to skip.
if ( isset( $args['skip_processing'] ) && $args['skip_processing'] === true ) {
return true;
}
// If no specific conditions are met to stop processing, return the original value
// or `false` to indicate that processing should continue.
return $process_recipe;
}, 10, 6 );
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
src/core/lib/process/class-automator-recipe-process-user.php:581
src/core/lib/process/class-automator-recipe-process-user.php:739
public function maybe_validate_trigger_without_postid( $args = array(), $trigger = null, $recipe_id = null, $recipe_log_id = null ) {
if ( empty( $args ) || null === $trigger || null === $recipe_id ) {
return array(
'result' => false,
'error' => esc_html__( 'One of the required field is missing.', 'uncanny-automator' ),
);
}
$check_trigger_code = $args['code'];
$trigger_meta = $args['meta'];
$user_id = $args['user_id'];
$matched_recipe_id = $args['recipe_to_match'];
$matched_trigger_id = $args['trigger_to_match'];
$trigger_id = is_numeric( $matched_trigger_id ) ? (int) $matched_trigger_id : $trigger['ID'];
$trigger_code = $trigger['meta']['code'];
$trigger_integration = $trigger['meta']['integration'];
// Skip completion if the plugin is not active
if ( 0 === $this->get_plugin_status( $trigger_integration ) ) {
// The plugin for this trigger is NOT active
Automator()->wp_error->add_error( 'uap_do_trigger_log', 'ERROR: You are trying to complete ' . $trigger['meta']['code'] . ' and the plugin ' . $trigger_integration . ' is not active. ', $this );
return array(
'result' => false,
'error' => esc_html__( 'Plugin is not active.', 'uncanny-automator' ),
);
}
/*if ( is_null( $recipe_log_id ) || ! is_numeric( $recipe_log_id ) ) {
$recipe_log_id = $this->maybe_create_recipe_log_entry( $recipe_id, $user_id, true );
}*/
// Stop here if the trigger was already completed
$process_recipe = apply_filters( 'automator_get_trigger_log_id_process_recipe', false, $user_id, $trigger_id, $recipe_id, $recipe_log_id, $args );
$is_trigger_completed = $this->is_trigger_completed( $user_id, $trigger_id, $recipe_id, $recipe_log_id, $process_recipe, $args );
if ( $is_trigger_completed ) {
return array(
'result' => false,
'error' => esc_html__( 'Trigger is completed.', 'uncanny-automator' ),
);
}
// Skip if the executed trigger doesn't match
if ( (string) $check_trigger_code !== (string) $trigger_code ) {
return array(
'result' => false,
'error' => sprintf( '%s AND %s triggers not matched.', $check_trigger_code, $trigger_code ),
);
}
if ( 0 !== (int) $matched_recipe_id && (int) $recipe_id !== (int) $matched_recipe_id ) {
return array(
'result' => false,
'error' => esc_html__( 'Recipe not matched.', 'uncanny-automator' ),
);
} elseif ( (int) $recipe_id === (int) $matched_recipe_id ) {
/**
* Added second part of code to check for MAGICBUTTON
* since trigger meta of MAGICBUTTON is saved by
* `code` instead of `meta`
*
* @version 2.1.6
* @author Saad
*/
$is_trigger_meta_and_trigger_meta_code_empty = ! isset( $trigger['meta'][ $trigger_meta ] ) && ! isset( $trigger['meta'][ $args['code'] ] );
if ( $is_trigger_meta_and_trigger_meta_code_empty || $trigger['meta']['code'] !== $args['code'] ) {
return array(
'result' => false,
'error' => esc_html__( 'Trigger meta not found.', 'uncanny-automator' ),
);
}
}
return $this->maybe_get_trigger_id( $user_id, $trigger_id, $recipe_id, $recipe_log_id );
}