Filter uncanny-automator

automator_option_text_field

Filters the value of a text field option before it's saved or displayed in the Automator.

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

Description

Filters an array of text field options before they are rendered for recipe creation. Developers can use this hook to modify field attributes, such as enabling or disabling TinyMCE support, setting default values, or adding custom validation rules, allowing for dynamic and flexible form field configurations.


Usage

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

Parameters

$option (mixed)
This parameter holds an array of arguments used to configure the text field, including its code, input type, label, and placeholder.

Return Value

The filtered value.


Examples

/**
 * Example function to modify the 'automator_option_text_field' filter.
 * This function demonstrates how to conditionally add a new key to the $option array
 * based on the field type. In this case, it adds 'supports_mentions' for 'textarea' fields.
 *
 * @param array $option The option array being filtered.
 * @return array The modified option array.
 */
function my_automator_modify_text_field( $option ) {
    // Check if the 'type' key exists and is 'textarea'
    if ( isset( $option['type'] ) && 'textarea' === $option['type'] ) {
        // Add a new key to support mentions within the textarea
        $option['supports_mentions'] = true;
    }

    // Always return the (potentially modified) $option array
    return $option;
}

// Add the filter to WordPress
// The priority is 10, and it accepts 1 argument ($option).
add_filter( 'automator_option_text_field', 'my_automator_modify_text_field', 10, 1 );

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

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

		$defaults = array(
			'option_code'               => 'TEXT',
			'input_type'                => 'text',
			'label'                     => esc_attr__( 'Text', 'uncanny-automator' ),
			'placeholder'               => '',
			'description'               => '',
			'required'                  => true,
			'show_label_in_sentence'    => true,
			'tokens'                    => true,
			'default'                   => null,
			'min_number'                => null,
			'max_number'                => null,
			'supports_tinymce'          => null,
			'supports_markdown'         => null,
			'supports_fullpage_editing' => null,
			'token_name'                => '',
			'read_only'                 => false,
			'is_hidden'                 => false,
			'exclude_default_token'     => false,
		);

		$args                      = wp_parse_args( $args, $defaults );
		$option_code               = $args['option_code'];
		$label                     = $args['label'];
		$show_label_in_sentence    = $args['show_label_in_sentence'];
		$description               = $args['description'];
		$placeholder               = $args['placeholder'];
		$tokens                    = $args['tokens'];
		$type                      = $args['input_type'];
		$default                   = $args['default'];
		$required                  = $args['required'];
		$supports_tinymce          = $args['supports_tinymce'];
		$supports_markdown         = $args['supports_markdown'];
		$supports_fullpage_editing = $args['supports_fullpage_editing'];
		$token_name                = $args['token_name'];
		$min_number                = $args['min_number'];
		$max_number                = $args['max_number'];
		$read_only                 = $args['read_only'];
		$is_hidden                 = $args['is_hidden'];
		$exclude_default_token     = $args['exclude_default_token'];

		$option = array(
			'option_code'               => $option_code,
			'label'                     => $label,
			'description'               => $description,
			'placeholder'               => $placeholder,
			'input_type'                => $type,
			'supports_tokens'           => $tokens,
			'required'                  => $required,
			'default_value'             => $default,
			'supports_tinymce'          => $supports_tinymce,
			'supports_markdown'         => $supports_markdown,
			'supports_fullpage_editing' => $supports_fullpage_editing,
			'token_name'                => $token_name,
			'min_number'                => $min_number,
			'max_number'                => $max_number,
			'show_label_in_sentence'    => $show_label_in_sentence,
			'read_only'                 => $read_only,
			'is_hidden'                 => $is_hidden,
			'exclude_default_token'     => $exclude_default_token,
		);

		// Enable TinyMCE by default for all textarea fields unless other specified
		if ( is_null( $option['supports_tinymce'] ) && 'textarea' === $type ) {
			$option['supports_tinymce'] = true;
		}

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

Internal Usage

Found in src/integrations/mailchimp/actions/campaign-createandsend.php:31:

add_filter( 'automator_option_text_field', array( $this, 'add_supports_fullpage_editing' ), 10, 1 );
Scroll to Top