After staring at the code for a few hours, I came up with this. Works like a charm for me. Even uses the ‘error_log()’ function to tell you what fields are found to be “not empty.” I found that the URL field type always comes back not empty. I’m sure this could be corrected with a tweak, but I don’t need it to work this way.
Paste this code into the “class-bp-profile-tabs.php” file located in “wp-content/plugins/buddypress-profile-tabs/public”
Paste it just below
$member_type = bp_get_member_type( $current_user_id );
but above
if ( ! empty( $member_type ) )
// Loop removing empty groups
foreach ( $this->groups_list as $tab_group_index => $tab_group )
{
/* SQL Query for profile fields */
$profile_fields_query = 'SELECT id, group_id, name FROM '.$wpdb->prefix.'bp_xprofile_fields WHERE group_id='.$tab_group->id;
/* Gets profile fields from database */
$this->fields_list = $wpdb->get_results( $profile_fields_query );
/* flag for non empty fields within group */
$tab_group_is_empty = true;
/* Check if each field is empty, if one is found to not be empty, set flag to false and break */
foreach( $this->fields_list as $field_index => $profile_field )
{
// Args for getting profile field data
$field_args = array('field' => $profile_field->id, 'user_id' => bp_displayed_user_id());
// Get profile field data
$field_value = bp_get_profile_field_data($field_args);
// Check if empty
if(!empty($field_value))
{
error_log('Value Found: '.$tab_group->name.' - '.$profile_field->name);
// If not empty, set flag to false and break out of loop.
$tab_group_is_empty = false;
break;
}
}
// Remove tab group if it is empty
if($tab_group_is_empty)
{
unset( $this->groups_list[ $tab_group_index ] );
$this->tabs_to_filter .= $tab_group->id . ',';
}
}