Filter uncanny-automator-pro

uap_option_all_flsupport_ticket_products

Filters ticket product display options for Fluent Support integration, allowing modification of the list of products shown.

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

Description

Filters the options for selecting Fluent Support ticket products within Uncanny Automator. Developers can use this hook to modify or add to the available product choices for ticket creation automations, allowing for custom product filtering or dynamic option generation before the options are presented to the user.


Usage

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

Parameters

$option (mixed)
This parameter is the value of the option being filtered.

Return Value

The filtered value.


Examples

add_filter(
	'uap_option_all_flsupport_ticket_products',
	'my_custom_flsupport_ticket_products',
	10,
	1
);

/**
 * Filters the list of Fluent Support ticket products to conditionally exclude certain products.
 *
 * This function checks if the current WordPress user has a specific capability.
 * If they do, it removes products with IDs '101' and '105' from the options list.
 *
 * @param array $option The original array of options for the Fluent Support ticket product field.
 * @return array The modified array of options.
 */
function my_custom_flsupport_ticket_products( $option ) {

	// Check if the current user has the capability to see all products.
	if ( current_user_can( 'manage_options' ) ) {
		// If the user can manage options, they should see all products, so return the original.
		return $option;
	}

	// Define product IDs to exclude for users without 'manage_options' capability.
	$excluded_product_ids = array( '101', '105' );

	// Filter out the excluded products from the options.
	if ( ! empty( $option['options'] ) && is_array( $option['options'] ) ) {
		$option['options'] = array_filter(
			$option['options'],
			function( $product ) use ( $excluded_product_ids ) {
				// Ensure $product is an array and has an 'value' key before checking.
				return ! ( isset( $product['value'] ) && in_array( $product['value'], $excluded_product_ids, true ) );
			}
		);
	}

	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

uncanny-automator-pro/src/integrations/fluent-support/helpers/flsupport-pro-helpers.php:218

public function all_products( $label, $option_code, $args = array() ) {

		if ( ! $label ) {
			$label = esc_attr__( 'Product', 'uncanny-automator-pro' );
		}

		$args = wp_parse_args(
			$args,
			array(
				'uo_include_any' => false,
				'uo_any_label'   => esc_attr__( 'Any product', 'uncanny-automator-pro' ),
			)
		);

		$options = array();

		if ( $args['uo_include_any'] ) {
			$options[-1] = $args['uo_any_label'];
		}

		$option = array(
			'option_code'     => $option_code,
			'label'           => $label,
			'input_type'      => 'select',
			'required'        => true,
			'options'         => $this->get_all_product_options( $options ),
			'relevant_tokens' => array(),
		);

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

Scroll to Top