Filter uncanny-automator

uap_option_get_list_tags

Filters the list of tags retrieved for Mailchimp integration before they are used.

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

Description

Filter the list of Mailchimp tags for user profile fields. Developers can modify the tag options, including their descriptions, support for custom or multiple values, and visibility of actions. This hook allows for dynamic customization of Mailchimp tag integrations within the user profile plugin.


Usage

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

Parameters

$option (mixed)
This parameter, `$option`, is intended to hold the data related to the Mailchimp list tags that are being retrieved or processed by the hook.

Return Value

The filtered value.


Examples

// Example of how to modify the list of tags returned by the uap_option_get_list_tags filter.
// This function will append a new custom tag to the list if it's not already present.
add_filter( 'uap_option_get_list_tags', 'my_custom_uap_tags_list', 10, 1 );

function my_custom_uap_tags_list( $option ) {

    // Check if the '$option' is an array and contains 'options' key which is also an array.
    if ( is_array( $option ) && isset( $option['options'] ) && is_array( $option['options'] ) ) {

        // Define the custom tag we want to add.
        $new_tag = array(
            'tag_id'   => 'my_custom_tag_' . time(), // Use a unique ID, timestamp is a simple way.
            'tag_name' => 'My Custom Tag',
            'tag_color'=> '#FF0000', // Example color
        );

        // Check if a tag with the same name already exists to avoid duplicates.
        $tag_exists = false;
        foreach ( $option['options'] as $existing_tag ) {
            if ( isset( $existing_tag['tag_name'] ) && $existing_tag['tag_name'] === $new_tag['tag_name'] ) {
                $tag_exists = true;
                break;
            }
        }

        // If the custom tag doesn't exist, add it to the beginning of the options array.
        if ( ! $tag_exists ) {
            array_unshift( $option['options'], $new_tag );
        }
    }

    // Always return the modified (or unmodified) $option array.
    return $option;
}

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/integrations/mailchimp/helpers/mailchimp-helpers.php:367

public function get_list_tags( $label = null, $option_code = 'MCLISTTAGS', $args = array() ) {

		if ( ! $label ) {
			$label = esc_html_x( 'Tags', 'Mailchimp', 'uncanny-automator' );
		}

		$args = wp_parse_args(
			$args,
			array(
				'uo_include_any' => false,
				'uo_any_label'   => esc_html_x( 'Any tag', 'Mailchimp', 'uncanny-automator' ),
			)
		);

		$token                    = key_exists( 'token', $args ) ? $args['token'] : false;
		$is_ajax                  = key_exists( 'is_ajax', $args ) ? $args['is_ajax'] : false;
		$target_field             = key_exists( 'target_field', $args ) ? $args['target_field'] : '';
		$end_point                = key_exists( 'endpoint', $args ) ? $args['endpoint'] : '';
		$supports_multiple_values = key_exists( 'supports_multiple_values', $args ) ? $args['supports_multiple_values'] : false;
		$custom_value_description = key_exists( 'custom_value_description', $args ) ? $args['custom_value_description'] : '';
		$required                 = key_exists( 'required', $args ) ? $args['required'] : true;
		$options                  = array();

		$option = array(
			'option_code'              => $option_code,
			'label'                    => $label,
			'input_type'               => 'select',
			'required'                 => $required,
			'supports_tokens'          => $token,
			'is_ajax'                  => $is_ajax,
			'fill_values_in'           => $target_field,
			'endpoint'                 => $end_point,
			'custom_value_description' => $custom_value_description,
			'supports_custom_value'    => true,
			'supports_multiple_values' => $supports_multiple_values,
			'options'                  => $options,
			'hide_actions'             => isset( $args['hide_actions'] ) ? $args['hide_actions'] : false,
		);

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

Scroll to Top