Filter uncanny-automator

uap_option_all_buddyboss_groups

Filters the BuddyBoss groups option, allowing modification of the group list retrieved by the plugin.

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

Description

Filters the BuddyBoss group options array before it's used in Uncanny Automator. Developers can modify the group ID, label, input type, options, and custom value description. Use this to customize how BuddyBoss groups are presented within Uncanny Automator's settings.


Usage

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

Parameters

$option (mixed)
This parameter contains the label for the BuddyBoss groups option.

Return Value

The filtered value.


Examples

<?php
/**
 * Filter the BuddyBoss groups options to only include groups
 * that are not archived.
 *
 * @param array $option The current option array for the BuddyBoss groups select field.
 * @return array The modified option array.
 */
add_filter( 'uap_option_all_buddyboss_groups', function( $option ) {
	// Check if $option is an array and has the 'options' key.
	if ( ! is_array( $option ) || ! isset( $option['options'] ) || ! is_array( $option['options'] ) ) {
		return $option;
	}

	$buddyboss_groups = $option['options'];
	$filtered_groups  = [];

	// Assume BuddyBoss group objects have an 'is_archived' property or method.
	// You might need to adjust this based on the actual BuddyBoss group object structure.
	foreach ( $buddyboss_groups as $group_id => $group_data ) {
		// Example: Check for an 'is_archived' property. If your BuddyBoss version
		// uses a method, you'd call $group_data->isArchived() or similar.
		// For simplicity, we'll assume it's a direct property for this example.
		// If the group data is an object, you might access it like:
		// if ( isset( $group_data->is_archived ) && ! $group_data->is_archived ) { ... }
		// Or if it's an array:
		// if ( isset( $group_data['is_archived'] ) && ! $group_data['is_archived'] ) { ... }

		// For this example, let's assume $group_data is an object with an 'is_archived' property.
		// If the actual structure is different, adjust this condition accordingly.
		// A common pattern is that the $options are an array of objects or arrays where
		// the key is the ID and the value contains group details.
		// Let's assume $group_data is an array for this example, as is common in WordPress.
		if ( isset( $group_data['status'] ) && 'archived' !== $group_data['status'] ) {
			$filtered_groups[ $group_id ] = $group_data;
		}
		// If BuddyBoss uses a boolean 'is_archived' property, the logic would be:
		// if ( ! isset( $group_data['is_archived'] ) || true !== $group_data['is_archived'] ) {
		//     $filtered_groups[ $group_id ] = $group_data;
		// }
	}

	// Update the options in the original $option array.
	$option['options'] = $filtered_groups;

	return $option;
}, 10, 1 ); // Priority 10, accepts 1 argument.
?>

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/buddyboss/helpers/buddyboss-helpers.php:109

public function all_buddyboss_groups( $label = null, $option_code = 'BDBGROUPS', $args = array() ) {

		$args = wp_parse_args(
			$args,
			array(
				'uo_include_any' => false,
				'uo_any_label'   => esc_attr__( 'Any group', 'uncanny-automator' ),
				'status'         => array( 'public', 'private', 'hidden' ),
			)
		);

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

		global $wpdb;
		$qry     = "SHOW TABLES LIKE '{$wpdb->prefix}bp_groups';";
		$options = array();

		if ( Automator()->helpers->recipe->load_helpers ) {
			if ( $args['uo_include_any'] ) {
				$options[- 1] = $args['uo_any_label'];
			}

			if ( $wpdb->query( $qry ) ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared

				// previous solution was not preparing correct query
				$in_str_arr = array_fill( 0, count( $args['status'] ), '%s' );
				$in_str     = join( ',', $in_str_arr );

				$results = $wpdb->get_results(
					$wpdb->prepare(
						"SELECT * FROM {$wpdb->prefix}bp_groups WHERE status IN ($in_str)", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
						$args['status']
					)
				);

				if ( $results ) {
					foreach ( $results as $result ) {
						$options[ $result->id ] = $result->name;
					}
				}
			}
		}

		$option = array(
			'option_code'              => $option_code,
			'label'                    => $label,
			'input_type'               => 'select',
			'required'                 => true,
			'options'                  => $options,
			'custom_value_description' => _x( 'Group ID', 'BuddyBoss', 'uncanny-automator' ),
		);

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

Scroll to Top