Filter
uncanny-automator
automator_action_{$action_code}_tokens_renderable
Filters the available tokens that can be rendered for a specific AutomatorWP action.
add_filter( 'automator_action_{$action_code}_tokens_renderable', $callback, 10, 3 );
Description
Allows developers to add or modify tokens available for an action when building recipes. This filter fires after default action tokens are set, enabling dynamic token insertion for specific action codes, action IDs, and recipe IDs. Use this to provide custom data or options as tokens for your actions.
Usage
add_filter( 'automator_action_{$action_code}_tokens_renderable', 'your_function_name', 10, 3 );
Parameters
-
$default_action_tokens(mixed) - This parameter contains an array of action tokens that are currently available to be rendered for the given action.
-
$action_id(mixed) - This parameter contains an array of default action tokens that are available for rendering.
-
$recipe_id(mixed) - This parameter contains the unique identifier for the specific action within the recipe that is currently being processed.
Return Value
The filtered value.
Examples
add_filter( 'automator_action_db_query_tokens_renderable', function( $default_action_tokens, $action_id, $recipe_id ) {
// In this example, we'll add a custom token that shows the number of rows affected
// by the DB query action, but only if the action code is 'db_query' and the recipe
// is for a specific user role.
if ( $action_id && $recipe_id ) { // Ensure we have valid IDs
// Let's assume we have a helper function or method to get action data
// Replace this with your actual logic to retrieve action data.
$action_data = automator_get_action_data( $action_id );
if ( $action_data && isset( $action_data['meta']['custom_user_role_check'] ) && $action_data['meta']['custom_user_role_check'] === 'yes' ) {
// Create a new token entity for the affected rows
$affected_rows_token = Automator()->action_tokens()->entity();
$affected_rows_token->set_id( 'DB_QUERY_AFFECTED_ROWS' );
$affected_rows_token->set_name( _x( 'Number of Rows Affected', 'Action token', 'uncanny-automator' ) );
$affected_rows_token->set_type( 'integer' ); // Or 'string' depending on how you'll use it
// Add the new token to the array of renderable tokens
$default_action_tokens[] = $affected_rows_token->toArray();
}
}
// Always return the modified (or unmodified) array of tokens
return $default_action_tokens;
}, 10, 3 );
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/services/recipe/structure/actions/item/loop/loop-db.php:159
private function loops_action_tokens_renderable( $action_code, $action_id, $recipe_id ) {
$default_action_tokens = array();
$status = Automator()->action_tokens()->entity();
$status->set_id( 'ACTION_RUN_STATUS' );
$status->set_name( _x( 'Completion status', 'Action token', 'uncanny-automator' ) );
$status->set_type( 'string' );
$default_action_tokens[] = $status->toArray();
return apply_filters( "automator_action_{$action_code}_tokens_renderable", $default_action_tokens, $action_id, $recipe_id );
}