Filter
uncanny-automator
automator_before_action_created
Filters the arguments passed before an action is created in Automator to allow modification or validation.
add_filter( 'automator_before_action_created', $callback, 10, 6 );
Description
Fired before an action is officially created and processed. Developers can use this filter to modify action data, prevent creation, or add custom logic before an action is committed to the system, influencing the entire workflow.
Usage
add_filter( 'automator_before_action_created', 'your_function_name', 10, 6 );
Parameters
-
$user_id(mixed) - This parameter represents a boolean value that indicates whether the action creation process should proceed.
-
$action_data(mixed) - This parameter contains the ID of the user associated with the recipe being processed.
-
$recipe_id(mixed) - This parameter contains the data associated with the action being created or processed within the Automator recipe.
-
$error_message(mixed) - This parameter contains the unique identifier of the recipe being processed.
-
$recipe_log_id(mixed) - This parameter contains the ID of the log entry for the current recipe execution.
-
$args(mixed) - This parameter contains an array of any additional arguments passed to the action.
Return Value
The filtered value.
Examples
<?php
/**
* Example of using the 'automator_before_action_created' filter hook.
* This function checks if an action should be skipped based on certain conditions
* and potentially modifies the processing flow.
*
* @param bool $process_further Whether to proceed with action creation.
* @param int $user_id The ID of the user associated with the recipe.
* @param array $action_data An array containing the data for the action.
* @param int $recipe_id The ID of the recipe being processed.
* @param string $error_message An error message if one occurred.
* @param int $recipe_log_id The ID of the recipe log entry.
* @param array $args Additional arguments passed to the filter.
*
* @return bool Modified value of $process_further.
*/
add_filter( 'automator_before_action_created', 'my_custom_automator_action_processing', 10, 7 );
function my_custom_automator_action_processing( $process_further, $user_id, $action_data, $recipe_id, $error_message, $recipe_log_id, $args ) {
// Example: Prevent a specific action from being created if a certain condition is met.
// Let's say we want to skip 'send_email' actions if the user has a specific meta key.
if ( isset( $action_data['type'] ) && $action_data['type'] === 'send_email' ) {
$user_meta = get_user_meta( $user_id, 'do_not_send_emails', true );
if ( ! empty( $user_meta ) && $user_meta === 'yes' ) {
// If the user has the meta key set to 'yes', we want to prevent further processing of this action.
// We can also log this event for debugging.
error_log( sprintf(
'Skipping creation of action "%s" for user ID %d in recipe ID %d due to ' .
'user meta "do_not_send_emails" being set to "yes".',
$action_data['type'],
$user_id,
$recipe_id
) );
return false; // Stop further processing of this action.
}
}
// Example: Modify an argument before the action is created.
// Let's say we want to add a prefix to a specific field in the action data.
if ( isset( $action_data['tokens'] ) && is_array( $action_data['tokens'] ) ) {
foreach ( $action_data['tokens'] as $key => &$token ) {
// This is a simplified example; real token handling would be more complex.
if ( strpos( $token['value'], '{' ) === 0 && strpos( $token['value'], '}' ) === strlen( $token['value'] ) - 1 ) {
$token['value'] = 'PRE_' . $token['value'];
}
}
unset($token); // Unset the reference to avoid unexpected behavior.
}
// If no conditions were met to stop processing, return the original or modified $process_further value.
// In this example, we are always returning true unless specifically set to false above.
return $process_further;
}
?>
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-complete.php:603
'args' => $args,
);
do_action( 'automator_before_action_completed', $do_action_args );
$error_message = $this->get_action_error_message( $user_id, $action_data, $recipe_id, $error_message, $recipe_log_id, $args );
$process_further = apply_filters( 'automator_before_action_created', true, $user_id, $action_data, $recipe_id, $error_message, $recipe_log_id, $args );
do_action( 'automator_before_action_completed_after_message_and_process_further', $do_action_args, $error_message, $process_further );
if ( ! $process_further ) {
return;
}
Internal Usage
Found in uncanny-automator-pro/src/core/classes/async-actions.php:34:
add_filter( 'automator_before_action_created', array( $this, 'maybe_complete_async_action' ), 10, 7 );