Hiding Profile Groups In BuddyPress
Recently for a BuddyPress project, I’ve been looking into the various ways to hide profile groups from a members public profile. There seems to be a few solutions out there. I could set the groups class to display: none in the CSS. That would certainly work in some cases, but in my case the users data would still be viewable in the source code, so it’s hardly the most secure solution.
Another solution would be to use a third party plugin, which would be nice, but I couldn’t find any that were still supported. So finally I came to the conclusion that the best solution for me (at the time of writing) was to edit the profile loop in the child theme directly.
Providing your using a child theme, you’ll find your profile loop in /wp-content/themes/your-theme-folder-name/members/single/profile/profile-loop.php. All you need to do add in a simple if statement that skips the profile group ids that you don’t want to display.
Here is my modified loop:
<?php while ( bp_profile_groups() ) : bp_the_profile_group();
//dont show profile group 5 as it's private
if(bp_get_the_profile_group_id() != 5) :
?>
<?php if ( bp_profile_group_has_fields() ) : ?>
<?php do_action( 'bp_before_profile_field_content' ); ?>
<div class="bp-widget <?php bp_the_profile_group_slug(); ?>">
<h4><?php bp_the_profile_group_name(); ?></h4>
<table class="profile-fields">
<?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
<?php if ( bp_field_has_data() ) : ?>
<tr<?php bp_field_css_class(); ?>>
<td class="label"><?php bp_the_profile_field_name(); ?></td>
<td class="data"><?php bp_the_profile_field_value(); ?></td>
</tr>
<?php endif; ?>
<?php do_action( 'bp_profile_field_item' ); ?>
<?php endwhile; ?>
</table>
</div>
<?php do_action( 'bp_after_profile_field_content' ); ?>
<?php endif; ?>
<?php endif; ?>
<?php endwhile; ?>
The good news is that in BuddyPress 1.6, it looks like a profile privacy feature might be included. Fingers crossed!
