Filter uncanny-automator

automator_supports_custom_value

Filters whether custom values are supported for automator actions, firing before the action is executed.

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

Description

Filters whether a specific field type supports custom value input. Allows developers to conditionally enable custom value entry for select fields and other input types within Uncanny Automator recipes, enhancing flexibility for dynamic content selection.


Usage

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

Parameters

$args (mixed)
This parameter indicates whether the field supports custom values.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to use the 'automator_supports_custom_value' filter hook.
 *
 * This example demonstrates how to programmatically enable or disable the
 * 'supports_custom_value' option for a specific field within Uncanny Automator recipes.
 *
 * We'll assume '$args' contains information about the field being processed,
 * and we want to enable custom values only for a specific type of input field,
 * for instance, a 'textarea' or a field related to 'email'.
 */
add_filter( 'automator_supports_custom_value', function( $supports_custom_value, $args ) {

	// Check if $args is an array and if it contains the 'input_type' key.
	if ( is_array( $args ) && isset( $args['input_type'] ) ) {

		// Define the input types for which we want to enable custom values.
		$enabled_input_types = array( 'textarea', 'email', 'text' );

		// If the current field's input type is in our allowed list, enable custom value support.
		if ( in_array( $args['input_type'], $enabled_input_types, true ) ) {
			return true; // Enable custom value support
		}

		// For any other input type not explicitly listed above, disable custom value support.
		return false; // Disable custom value support
	}

	// If $args is not in the expected format, return the original value.
	return $supports_custom_value;

}, 10, 2 ); // Priority 10, accepts 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:426
src/core/lib/helpers/class-automator-recipe-helpers-field.php:639
src/core/lib/helpers/class-automator-recipe-helpers-field.php:642
src/core/lib/helpers/class-automator-recipe-helpers-field.php:645

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 );
	}


Scroll to Top