Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter carson7634

    (@carson7634)

    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 . ',';
    	}
    
    }
    Plugin Author Jacob Schweitzer

    (@primetimejas)

    Hi carson7634,
    Thank you for the contribution, however I’m sorry I wasn’t able to get this in the latest version. I will look at it for a future version, reason being I don’t want to add another database call in there if it is not necessary so probably the best way would be to add an option that says “Do not show empty tabs” which is not enabled by default to keep the plugin fast. If the option is enabled then it would use code similar to something you provided here to look for empty tabs then not include them. What do you think?

    Hi there guys, sorry to jump in here. Been looking for a solution to this riddle. @carson7634 thanks for taking the time to write out that code mate, really appreciate it.

    I tried inserting it between:
    $member_type = bp_get_member_type( $current_user_id ); and
    if ( ! empty( $member_type ) ) {

    however it does not seem to hide the empty Tabs. Any assistance here would be much appreciated

    Thread Starter carson7634

    (@carson7634)

    Hello Jacob,

    I totally understand not wanting another database call. I am new to wordpress and php (more of a c++/Java guy) so these are the things I should learn about. Fortunately this did work for me, but I agree that it might not be the best solution. I feel like the implementation that you described would be excellent.

    Thavaz,

    I am sorry, I think I posted that without fully testing it. I actually see the loop in a different location in my installation. It needed to be placed earlier. Use with caution, and if Jacob implements this feature, burn my code with fire! ??

    In my installation it is between:
    ‘$this->groups_list = $wpdb->get_results( $profile_field_groups_query );’
    and
    ‘$current_user_id = get_current_user_id();’

    @carson7634
    Mate, you are too awesome! Thank you for the patch, it worked fantastically ?? After placing the code in and uploading I initially had an error, however this was due to a caching plugin, after clearing it, all worked like a charm.

    Thanks again gentleman, especially @ you carson7634! Thumbs up.

    Thread Starter carson7634

    (@carson7634)

    You are welcome, but credit goes to Jake for creating the plug-in to begin with. Buddy press really should pay the man and add this as a stock feature!

    @carson7634 very true. +100 to your comment above mate. What a powerful plugin, it completely adds versatility to that lacking dimension of BP’s customization of independent profiles.
    Fantastic work @jacob Schweitzer! and most of all, thank you for making it freely available ??

    Thank you all for your contributions. I am having trouble finding either of these locations to insert the code. Can you help?
    Thanks!
    Anna

    hey there Anna, how far did you get?
    Did you perhaps locate the files that you need to insert the above into? Or are you having tough time finding the segment of code to dissect and inject carson7634’s bit of code?

    Hi there Thavaz.
    Thank you for your reply. I am not able to find this location in the file: In my installation it is between:
    ‘$this->groups_list = $wpdb->get_results( $profile_field_groups_query );’
    and
    ‘$current_user_id = get_current_user_id();’

    Thread Starter carson7634

    (@carson7634)

    What editor are you using to modify the file?

    Hi there – I am using text edit in the mac.
    Actually I did find it near the end of the file, but uploaded it and everything went white, so I had to revert back to original.
    Anyone else have that happen?

    Hi there – anyone else have any luck hiding empty field groups?
    Thanks
    Anna

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Hide empty field groups’ is closed to new replies.