Filter uncanny-automator-pro

uap_option_all_wp_taxonomy

Filters the list of all WordPress taxonomies available for selection, allowing modification before display.

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

Description

Filters the array of options for selecting WordPress taxonomies within Uncanny Automator Pro. Developers can modify the $option array to customize the displayed taxonomy options, their relevant tokens, or add custom data before they are presented in the Automator interface for use in recipes.


Usage

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

Parameters

$option (mixed)
This parameter is an associative array containing arguments that modify the behavior of the `all_wp_taxonomy` function.

Return Value

The filtered value.


Examples

// Filter to modify the array of WordPress taxonomy options for Uncanny Automator Pro.
// This example adds a new taxonomy ('custom_event_type') to the available options
// if it exists and is registered.
add_filter( 'uap_option_all_wp_taxonomy', function( $option ) {

    // Check if the taxonomy 'custom_event_type' is registered.
    if ( taxonomy_exists( 'custom_event_type' ) ) {

        // Get all terms for the 'custom_event_type' taxonomy.
        $terms = get_terms( array(
            'taxonomy'   => 'custom_event_type',
            'hide_empty' => false, // Include terms that have no posts.
        ) );

        // If terms are found, add them to the 'options' array.
        if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
            foreach ( $terms as $term ) {
                $option['options'][ $term->term_id ] = $term->name;
            }
        }
    }

    // Return the modified or original $option array.
    return $option;
}, 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

uncanny-automator-pro/src/integrations/wp/helpers/wp-pro-helpers.php:428

public function all_wp_taxonomy( $label = null, $option_code = 'WPTAXONOMIES', $args = array() ) {

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

		$token        = key_exists( 'token', $args ) ? $args['token'] : false;
		$is_ajax      = key_exists( 'is_ajax', $args ) ? $args['is_ajax'] : false;
		$is_any       = key_exists( 'is_any', $args ) ? $args['is_any'] : false;
		$is_all       = key_exists( 'is_all', $args ) ? $args['is_all'] : false;
		$target_field = key_exists( 'target_field', $args ) ? $args['target_field'] : '';
		$end_point    = key_exists( 'endpoint', $args ) ? $args['endpoint'] : '';
		$placeholder  = key_exists( 'placeholder', $args ) ? $args['placeholder'] : '';
		$options      = array();

		if ( $is_any && ! $is_all ) {
			$options['-1'] = __( 'Any taxonomy', 'uncanny-automator-pro' );
		} elseif ( $is_all ) {
			$options['-1'] = __( 'All taxonomies', 'uncanny-automator-pro' );
		}

		// now get regular post types.
		$args = array(
			'public'   => true,
			'_builtin' => true,
		);

		$output   = 'object';
		$operator = 'and';

		$taxonomies = get_taxonomies( $args, $output, $operator );

		if ( ! empty( $taxonomies ) ) {
			foreach ( $taxonomies as $taxonomy ) {
				$options[ $taxonomy->name ] = esc_html( $taxonomy->labels->singular_name );
			}
		}

		// get all custom post types
		$args = array(
			'public'   => true,
			'_builtin' => false,
		);

		$output   = 'object';
		$operator = 'and';

		$custom_taxonomies = get_taxonomies( $args, $output, $operator );

		if ( ! empty( $custom_taxonomies ) ) {
			foreach ( $custom_taxonomies as $custom_taxonomy ) {
				$options[ $custom_taxonomy->name ] = esc_html( $custom_taxonomy->labels->singular_name );
			}
		}

		$type = 'select';

		$option = array(
			'placeholder'     => $placeholder,
			'option_code'     => $option_code,
			'label'           => $label,
			'input_type'      => $type,
			'required'        => true,
			'supports_tokens' => $token,
			'is_ajax'         => $is_ajax,
			'fill_values_in'  => $target_field,
			'endpoint'        => $end_point,
			'options'         => $options,
			'relevant_tokens' => array(
				$option_code => __( 'Taxonomy', 'uncanny-automator-pro' ),
			),
		);

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

Scroll to Top