Filter Dynamic uncanny-automator

uap_option_{dynamic}_select_field

> **Note:** This is a dynamic hook. The actual hook name is constructed at runtime. Filters the value of a dynamic select field option before it is saved, allowing for custom modifications.

add_filter( 'uap_option_{dynamic}_select_field', $callback, 10, 1 );

Description

This dynamic filter hook, uap_option_{dynamic}_select_field, allows developers to modify the label, description, or other attributes of select fields within Uncanny Automator recipes. It's primarily used for customizing the output of options presented to users when building automations, ensuring flexibility in how choices are displayed and interpreted.


Usage

add_filter( 'uap_option_{dynamic}_select_field', 'your_function_name', 10, 1 );

Parameters

$option_code (mixed)
This parameter represents the version of the plugin or integration using the hook.

Return Value

The filtered value.


Examples

add_filter( 'uap_option_user_role_select_field', 'my_custom_user_role_option_label', 10, 3 );

/**
 * Customizes the label for the 'User role' select field in Uncanny Automator.
 *
 * This filter allows developers to modify the default label displayed for a specific
 * option type (in this case, 'user_role') within the Uncanny Automator plugin.
 * It demonstrates how to dynamically change the label based on the $option_code
 * and potentially other passed arguments.
 *
 * @param array  $value The default value. In this context, it's usually an array containing a boolean false.
 * @param string $version The current version of the plugin or the specific feature.
 * @param string $option_code The unique code identifying the option being processed.
 *
 * @return array The modified value. We are returning the original value here,
 *               but the filter's purpose is to demonstrate how you *could*
 *               modify it or perform actions.
 */
function my_custom_user_role_option_label( $value, $version, $option_code ) {
    // Check if the current option code is for the user role field.
    if ( 'user_role' === $option_code ) {
        // In a real-world scenario, you might want to adjust the label based on the $version
        // or even other arguments passed through the $args array if it were available here.
        // For this example, we'll just ensure the label remains "User Role" but show
        // how you'd interact with the filter.

        // If $value was an array of options, you might modify them here.
        // Since this filter appears to be about the *field definition* rather than the options themselves,
        // we'll focus on demonstrating interaction.

        // Example: If you wanted to add a tooltip or modify internal flags (if they were exposed).
        // For demonstration purposes, we'll just log that we've hooked into it.
        // error_log( "Hooked into uap_option_user_role_select_field for option code: {$option_code}" );
    }

    // Always return the value, even if it's the original one, to prevent breaking the plugin.
    return $value;
}

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:521
src/integrations/mailchimp/helpers/mailchimp-helpers.php:194
src/integrations/mailchimp/helpers/mailchimp-helpers.php:726

public function select_field( $option_code = 'SELECT', $label = null, $options = array(), $default = null, $is_ajax = false, $fill_values_in = '', $relevant_tokens = array(), $args = array() ) {
		if ( defined( 'AUTOMATOR_DEBUG_MODE' ) && true === AUTOMATOR_DEBUG_MODE ) {
			_doing_it_wrong( 'Automator()->helpers->recipe->field->select_field()', 'Use Automator()->helpers->recipe->field->select() instead.', '3.0' );
		}

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

		$custom_value_description = key_exists( 'custom_value_description', $args ) ? $args['custom_value_description'] : null;
		$supports_custom_value    = $this->supports_custom_value( $args );
		$supports_tokens          = key_exists( 'supports_tokens', $args ) ? $args['supports_tokens'] : null;
		$support_token            = apply_filters( 'uap_option_' . $option_code . '_select_field', array( false ), '3.0', 'automator_option_' . $option_code . '_select_field' );
		$support_token            = apply_filters( 'automator_option_' . $option_code . '_select_field', $support_token );
		$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,
			'input_type'               => 'select',
			'supports_tokens'          => $support_token,
			'required'                 => true,
			'default_value'            => $default,
			'options'                  => $options,
			'custom_value_description' => $custom_value_description,
			'supports_custom_value'    => $supports_custom_value,
			'options_show_id'          => $options_show_id,
		);

		if ( ! empty( $relevant_tokens ) ) {
			$option['relevant_tokens'] = $relevant_tokens;
		}

		//$option = $this->select( $option );
		$option = apply_filters_deprecated( 'uap_option_select_field', array( $option ), '3.0', 'automator_option_select_field' );

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


Scroll to Top