Filter uncanny-automator

automator_option_select_field

Filters the options available for a select field within the Automator plugin's core functionalities.

add_filter( 'automator_option_select_field', $callback, 10, 1 );

Description

Filters the arguments used to generate a select field for Uncanny Automator recipes. Developers can modify the field's label, options, or other attributes before it's displayed. This is useful for customizing how users select options within recipe triggers and actions, especially for integrations.


Usage

add_filter( 'automator_option_select_field', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

/**
 * Example: Conditionally disable token support for a specific select field.
 *
 * This filter hook allows you to modify the 'supports_tokens' argument
 * for the 'select' field type in Uncanny Automator.
 *
 * In this example, we'll disable token support for any select field
 * where the 'option_code' is 'WOOCOMMERCE_PRODUCT_ID'. This might be useful
 * if you only want users to select a product from a predefined list and
 * not input a custom product ID via tokens.
 *
 * @param bool|mixed $supports_tokens The current value of 'supports_tokens'.
 * @param array      $args            The arguments passed to the select field.
 *
 * @return bool|mixed The modified 'supports_tokens' value.
 */
add_filter(
	'automator_option_select_field',
	function( $supports_tokens, $args ) {
		// Check if the current field is a WooCommerce Product ID select field.
		if ( isset( $args['option_code'] ) && 'WOOCOMMERCE_PRODUCT_ID' === $args['option_code'] ) {
			// Disable token support for this specific field.
			return false;
		}

		// For all other select fields, keep the original 'supports_tokens' value.
		return $supports_tokens;
	},
	10, // Priority
	2   // Accepted args count
);

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:421
src/core/lib/helpers/class-automator-recipe-helpers-field.php:471
src/core/lib/helpers/class-automator-recipe-helpers-field.php:546

public function select( $args = array() ) {

		$defaults                 = array(
			'option_code'              => 'SELECT',
			'label'                    => esc_attr__( 'Option', 'uncanny-automator' ),
			'input_type'               => 'select',
			'supports_tokens'          => apply_filters( 'automator_option_select_field', false ),
			'required'                 => true,
			'default_value'            => null,
			'options'                  => array(),
			'custom_value_description' => '',
			'supports_custom_value'    => apply_filters( 'automator_supports_custom_value', true, $args ),
			'relevant_tokens'          => null,
			'is_ajax'                  => false,
			'chained_to'               => null,
			'endpoint'                 => null,
			'token_name'               => '',
			'options_show_id'          => apply_filters( 'automator_options_show_id', true, $this ),
			'exclude_default_token'    => false,
		);
		$args                     = wp_parse_args( $args, $defaults );
		$option_code              = $args['option_code'];
		$input_type               = $args['input_type'];
		$label                    = $args['label'];
		$required                 = $args['required'];
		$default                  = $args['default_value'];
		$options                  = $args['options'];
		$custom_value_description = $args['custom_value_description'];
		$supports_custom_value    = $args['supports_custom_value'];
		$supports_tokens          = $args['supports_tokens'];
		$relevant_tokens          = $args['relevant_tokens'];
		$token_name               = $args['token_name'];
		$options_show_id          = $args['options_show_id'];
		$exclude_default_token    = $args['exclude_default_token'];

		$option = array(
			'option_code'              => $option_code,
			'label'                    => $label,
			'input_type'               => $input_type,
			'supports_tokens'          => $supports_tokens,
			'required'                 => $required,
			'default_value'            => $default,
			'options'                  => $options,
			'custom_value_description' => $custom_value_description,
			'supports_custom_value'    => $supports_custom_value,
			'relevant_tokens'          => $relevant_tokens,
			'token_name'               => $token_name,
			'options_show_id'          => $options_show_id,
			'exclude_default_token'    => $exclude_default_token,
		);

		// TODO:: add keys optionally
		//      'is_ajax'                  => false,
		//          'chained_to'               => null,
		//          'endpoint'                 => null,

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


Internal Usage

Found in uncanny-automator-pro/src/integrations/woocommerce/helpers/woocommerce-pro-helpers.php:92:

add_filter( 'automator_option_select_field', array( $this, 'remove_rel_tokens_from_dd' ) );
Scroll to Top