Filter uncanny-automator-pro

uap_option_list_base_profile_fields

Filters the list of base profile fields used by BuddyBoss within the Ultimate Affiliate Pro system.

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

Description

Filter `uap_option_list_base_profile_fields` to customize the list of base profile fields available for BuddyBoss integration within Uncanny Automator. Modify options, add custom fields, or alter existing ones to tailor automations precisely to your BuddyBoss setup.


Usage

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

Parameters

$option (mixed)
This parameter holds the current list of profile fields to be filtered.

Return Value

The filtered value.


Examples

add_filter( 'uap_option_list_base_profile_fields', 'my_custom_uap_profile_fields', 10, 1 );

/**
 * Add or modify profile fields for Uncanny Automator's BuddyBoss/BuddyPress integration.
 *
 * This function demonstrates how to add a new profile field option or modify an existing one
 * that Uncanny Automator uses for its BuddyBoss/BuddyPress triggers and actions.
 *
 * @param array $option The current array of field options.
 * @return array The modified array of field options.
 */
function my_custom_uap_profile_fields( $option ) {

	// Let's assume we want to add a new option to select a specific BuddyBoss group
	// if the current field is related to BuddyBoss group selection.
	// The original code snippet implies the hook is applied to a field configuration
	// that might look something like this before the filter:
	//
	// $option = array(
	//     'label' => 'Select BuddyBoss Group',
	//     'input_type' => 'select',
	//     'required' => true,
	//     'options' => array(), // This is where we might add our custom groups
	//     'custom_value_description' => esc_attr_x( 'BuddyBoss Group ID', 'Buddyboss', 'uncanny-automator' ),
	// );
	//
	// We'll simulate adding a custom BuddyBoss group if one isn't already present
	// in the 'options' array.

	// Check if the current option is related to BuddyBoss group selection.
	// This is a hypothetical check based on how Uncanny Automator might structure its fields.
	// In a real scenario, you'd inspect $option['label'] or $option['custom_value_description'].
	if ( isset( $option['custom_value_description'] ) && $option['custom_value_description'] === esc_attr_x( 'BuddyBoss Group ID', 'Buddyboss', 'uncanny-automator' ) ) {

		// Get existing options if any
		$current_options = isset( $option['options'] ) ? $option['options'] : array();

		// Let's add a custom BuddyBoss group with ID 123 and name "Developers"
		// This would typically involve querying BuddyBoss/BuddyPress functions to get real group data.
		$custom_group_id = 123;
		$custom_group_name = 'Developers';

		// Add our custom group to the options array if it doesn't already exist.
		// We'll use the group ID as the key and the group name as the value.
		if ( ! array_key_exists( $custom_group_id, $current_options ) ) {
			$current_options[ $custom_group_id ] = $custom_group_name;
		}

		// Update the options in the $option array
		$option['options'] = $current_options;

		// Optionally, you could also change the label or other properties.
		// $option['label'] = 'Select a BuddyBoss Group (Custom)';
	}

	// Always return the modified (or original) $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

uncanny-automator-pro/src/integrations/buddyboss/helpers/buddyboss-pro-helpers.php:156
uncanny-automator-pro/src/integrations/buddypress/helpers/buddypress-pro-helpers.php:87

public function list_base_profile_fields(
		$label = null,
		$option_code = 'BDBFIELD',
		$args = array()
	) {

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

		$args = wp_parse_args(
			$args,
			array(
				'uo_include_any' => false,
				'uo_any_label'   => esc_attr_x( 'Any field', 'Buddyboss', 'uncanny-automator' ),
			)
		);

		$options = array();

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

			global $wpdb;
			$fields_table    = $wpdb->base_prefix . 'bp_xprofile_fields';
			$xprofile_fields = $wpdb->get_results( "SELECT * FROM {$fields_table} WHERE parent_id = 0 AND group_id = '{$base_group_id}' ORDER BY field_order ASC" );
			if ( ! empty( $xprofile_fields ) ) {
				foreach ( $xprofile_fields as $xprofile_field ) {
					$options[ $xprofile_field->id ] = $xprofile_field->name;
				}
			}
		}

		$option = array(
			'option_code'              => $option_code,
			'label'                    => $label,
			'input_type'               => 'select',
			'required'                 => true,
			'options'                  => $options,
			'custom_value_description' => esc_attr_x( 'User ID', 'Buddyboss', 'uncanny-automator' ),
		);

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

Scroll to Top