Filter Dynamic uncanny-automator

automator_option_{dynamic}_select_field_token_name

> **Note:** This is a dynamic hook. The actual hook name is constructed at runtime. Filters the name of dynamic select field tokens when building automation options.

add_filter( 'automator_option_{dynamic}_select_field_token_name', $callback, 10, 2 );

Description

This dynamic filter hook, `automator_option_{dynamic}_select_field_token_name`, allows developers to modify the token name displayed for dynamic select fields within the Automator plugin. It's triggered when generating the token name for a select field option, enabling customization of how tokens are presented to users for selection. Developers can intercept and alter the `$token_name` based on the provided `$args`.


Usage

add_filter( 'automator_option_{dynamic}_select_field_token_name', 'your_function_name', 10, 2 );

Parameters

$token_name (mixed)
This parameter holds the name of the token that will be used to populate the select field's options dynamically.
$args (mixed)
This parameter holds the name of the token being generated or modified for a dynamic select field.

Return Value

The filtered value.


Examples

<?php
/**
 * Modify the token name for a specific select field option in the Automator plugin.
 * This example prepends a prefix to the token name to make it more specific.
 *
 * @param mixed $token_name The original token name.
 * @param mixed $args       The arguments passed to the function.
 * @return string The modified token name.
 */
add_filter( 'automator_option_my_custom_select_field_token_name', function( $token_name, $args ) {

	// Assume $args contains information about the option,
	// and we want to append a prefix based on its type.
	// For demonstration, let's say we have an option with 'option_code' = 'my_custom_select_field'
	// and we want to add a prefix to its token name.

	// You can inspect $args to make more dynamic decisions if needed.
	// For example, you might check $args['some_other_key'] to alter the token name.

	// In this realistic example, we're always prepending 'automator_custom_'.
	$prefix = 'automator_custom_';

	// Ensure $token_name is a string before prepending.
	if ( is_string( $token_name ) ) {
		return $prefix . $token_name;
	}

	// If $token_name is not a string, return it as is or handle as appropriate.
	// For this example, we'll return a default string if it's not a string.
	return $prefix . 'default_token';

}, 10, 2 ); // Priority 10, accepting 2 arguments

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/helpers/class-automator-recipe-helpers-field.php:601

public function select_field_ajax( $option_code = 'SELECT', $label = null, $options = array(), $default = null, $placeholder = '', $supports_token = false, $is_ajax = false, $args = array(), $relevant_tokens = array() ) {

		// TODO this function should be the main way to create select fields
		// TODO chained values should be introduced using the format in function "list_gravity_forms"
		// TODO the following function should use this function to create selections
		// -- less_or_greater_than
		// -- all_posts
		// -- all_pages
		// -- all_ld_courses
		// -- all_ld_lessons
		// -- all_ld_topics
		// -- all_ld_groups
		// -- all_ld_quiz
		// -- all_buddypress_groups
		// -- all_wc_products
		// -- list_contact_form7_forms
		// -- list_bbpress_forums
		// -- wc_order_statuses
		// -- wp_user_roles
		// -- list_gravity_forms
		// -- all_ec_events
		// -- all_lp_courses
		// -- all_lp_lessons
		// -- all_lf_courses
		// -- all_lf_lessons

		if ( ! $label ) {
			$label = esc_attr__( 'Option', 'uncanny-automator' );
		}
		$token_name               = isset( $args['token_name'] ) ? $args['token_name'] : '';
		$target_field             = key_exists( 'target_field', $args ) ? $args['target_field'] : '';
		$end_point                = key_exists( 'endpoint', $args ) ? $args['endpoint'] : '';
		$description              = key_exists( 'description', $args ) ? $args['description'] : null;
		$custom_value_description = key_exists( 'custom_value_description', $args ) ? $args['custom_value_description'] : null;
		// default true
		$supports_custom_value = $this->supports_custom_value( $args );
		$supports_tokens       = key_exists( 'supports_tokens', $args ) ? $args['supports_tokens'] : null;
		$supports_tokens       = apply_filters_deprecated( 'uap_option_' . $option_code . '_select_field', array( $supports_tokens ), '3.0', 'automator_option_' . $option_code . '_select_field' );
		$supports_tokens       = apply_filters( 'automator_option_' . $option_code . '_select_field', $supports_tokens );
		$token_name            = apply_filters( 'automator_option_' . $option_code . '_select_field_token_name', $token_name, $args );
		$options_show_id       = empty( $args['options_show_id'] ) ? true : $args['options_show_id'];
		$options_show_id       = apply_filters( 'automator_options_show_id', $options_show_id, $this );
		$option                = array(
			'option_code'              => $option_code,
			'label'                    => $label,
			'description'              => $description,
			'input_type'               => 'select',
			'supports_tokens'          => $supports_tokens,
			'required'                 => true,
			'default_value'            => $default,
			'options'                  => $options,
			'custom_value_description' => $custom_value_description,
			'supports_custom_value'    => $supports_custom_value,
			'is_ajax'                  => $is_ajax,
			'fill_values_in'           => $target_field,
			'integration'              => 'GF',
			'endpoint'                 => $end_point,
			'placeholder'              => $placeholder,
			'token_name'               => $token_name,
			'options_show_id'          => $options_show_id,
		);
		if ( ! empty( $relevant_tokens ) ) {
			$option['relevant_tokens'] = $relevant_tokens;
		}

		$option = apply_filters_deprecated( 'uap_option_select_field_ajax', array( $option ), '3.0', 'automator_option_select_field_ajax' );

		return apply_filters( 'automator_option_select_field_ajax', $option );
	}


Scroll to Top