uap_option_list_all_profile_fields
Filters all profile fields available within the BuddyBoss platform for customization.
add_filter( 'uap_option_list_all_profile_fields', $callback, 10, 1 );
Description
Filters the list of all profile fields available for selection within Uncanny Automator's BuddyBoss integration. Developers can use this hook to add, remove, or modify profile field options presented to users when creating automations. The `$option` parameter contains the current array of field options.
Usage
add_filter( 'uap_option_list_all_profile_fields', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter contains the current value of the option being filtered.
Return Value
The filtered value.
Examples
add_filter( 'uap_option_list_all_profile_fields', 'my_custom_uap_profile_fields', 10, 1 );
/**
* Custom function to filter and potentially add/modify profile fields returned by Uncanny Automator Pro for BuddyBoss/BuddyPress.
*
* This example demonstrates how to add a custom field to the list of available profile fields
* that Uncanny Automator Pro can use. In this case, we're adding a hypothetical 'custom_member_level' field.
*
* @param array $option The array of profile fields currently being processed by Uncanny Automator Pro.
* @return array The modified array of profile fields.
*/
function my_custom_uap_profile_fields( $option ) {
// Let's assume $option is an array of profile field definitions.
// We'll add a new custom field to this array.
// This new field might represent a custom user role or membership level not natively
// supported by BuddyBoss/BuddyPress but managed by another plugin.
$custom_field_definition = array(
'label' => esc_html__( 'Custom Member Level', 'my-text-domain' ),
'input_type' => 'select',
'required' => false,
'options' => array(
'' => esc_html__( 'Select a level', 'my-text-domain' ),
'bronze' => esc_html__( 'Bronze Member', 'my-text-domain' ),
'silver' => esc_html__( 'Silver Member', 'my-text-domain' ),
'gold' => esc_html__( 'Gold Member', 'my-text-domain' ),
'platinum' => esc_html__( 'Platinum Member', 'my-text-domain' ),
),
'custom_value_description' => esc_attr_x( 'Member Level', 'Buddyboss', 'uncanny-automator' ),
// Add any other specific arguments needed by Uncanny Automator Pro for this field type.
// For example, if this field needs to interact with a custom post type or taxonomy.
'meta_key' => 'my_custom_member_level', // A unique key to identify this field's data
);
// You can either merge this with the existing array or replace it depending on your needs.
// Here, we're adding it to the end.
$option[] = $custom_field_definition;
// Alternatively, if you wanted to modify an existing field or add it at a specific position,
// you would iterate through the $option array and make changes.
// For example, to add it before the 'display_name' field if it existed:
/*
$new_option = array();
foreach ( $option as $key => $value ) {
if ( isset( $value['meta_key'] ) && $value['meta_key'] === 'display_name' ) {
$new_option[] = $custom_field_definition;
}
$new_option[] = $value;
}
$option = $new_option;
*/
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:269
uncanny-automator-pro/src/integrations/buddypress/helpers/buddypress-pro-helpers.php:221
public function list_all_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' ),
'is_repeater' => false,
)
);
$options = array();
if ( Automator()->helpers->recipe->load_helpers ) {
if ( $args['uo_include_any'] ) {
$options[- 1] = $args['uo_any_label'];
}
global $wpdb;
$fields_table = $wpdb->base_prefix . 'bp_xprofile_fields';
$xprofile_fields = $wpdb->get_results( "SELECT * FROM {$fields_table} WHERE parent_id = 0 ORDER BY field_order ASC" );
if ( ! empty( $xprofile_fields ) ) {
foreach ( $xprofile_fields as $xprofile_field ) {
if ( $args['is_repeater'] ) {
$options[] = array(
'value' => $xprofile_field->id,
'text' => $xprofile_field->name,
);
} else {
$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_all_profile_fields', $option );
}