Filter uncanny-automator-pro

uap_option_get_groups_types

Filters the group types available for display within BuddyBoss integrations, allowing customization of group creation options.

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

Description

Filters the available group types for the BuddyBoss integration in Uncanny Automator Pro. Developers can use this hook to add, remove, or modify the list of group types displayed in automation options, allowing for custom group integrations or filtering based on specific criteria.


Usage

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

Parameters

$option (mixed)
This parameter is an array of arguments used to configure the retrieval of BuddyBoss group types.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to filter the 'uap_option_get_groups_types' hook to modify the available BuddyBoss group types.
 *
 * This example demonstrates how to remove a specific group type from the list of available options.
 *
 * @param array $option The array of options for the group types select field.
 * @return array The modified array of options.
 */
function my_uncanny_automator_pro_filter_buddyboss_group_types( $option ) {
    // Define the group type ID you want to remove.
    $group_type_to_remove = 'private_group_id'; // Replace with the actual ID of the group type you want to exclude.

    // Check if 'options' key exists and is an array.
    if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {
        // Iterate through the options and remove the unwanted group type.
        foreach ( $option['options'] as $key => $group_type ) {
            if ( $key === $group_type_to_remove ) {
                unset( $option['options'][ $key ] );
                break; // Exit the loop once the group type is found and removed.
            }
        }
        // Re-index the array if necessary after unsetting elements.
        $option['options'] = array_values( $option['options'] );
    }

    return $option;
}
add_filter( 'uap_option_get_groups_types', 'my_uncanny_automator_pro_filter_buddyboss_group_types', 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/buddyboss/helpers/buddyboss-pro-helpers.php:355

public function get_groups_types( $label = null, $option_code = 'BDBGROUPTYPES', $args = array() ) {

		$args = wp_parse_args(
			$args,
			array(
				'uo_include_any' => false,
				'required'       => true,
				'uo_any_label'   => esc_attr_x( 'Any group type', 'Buddyboss', 'uncanny-automator-pro' ),
			)
		);

		if ( ! $label ) {
			$label = esc_attr_x( 'Group type', 'Buddyboss', 'uncanny-automator-pro' );
		}

		$options = array();

		if ( Automator()->helpers->recipe->load_helpers ) {
			if ( $args['uo_include_any'] ) {
				$options[- 1] = $args['uo_any_label'];
			}
			if ( function_exists( 'bp_groups_get_group_types' ) ) {
				$types = bp_groups_get_group_types( array(), 'objects' );

				if ( $types ) {
					foreach ( $types as $type ) {
						$options[ esc_attr( $type->name ) ] = esc_html( $type->labels['singular_name'] );
					}
				}
			}
		}
		$option = array(
			'option_code'              => $option_code,
			'label'                    => $label,
			'input_type'               => 'select',
			'required'                 => $args['required'],
			'options'                  => $options,
			'relevant_tokens'          => ( isset( $args['relevant_tokens'] ) ) ? $args['relevant_tokens'] : array(),
			'custom_value_description' => esc_html_x( 'Group Type ID', 'BuddyBoss', 'uncanny-automator-pro' ),
		);

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

Scroll to Top