Profile field visibility in BP 1.6
Several weeks ago, a series of changesets addressed what is perhaps the most popular request in the history of BuddyPress: profile privacy. (See #3695.) We’re calling it “visibility”, and you can check it out now in BP trunk. Here’s what developers need to know:
- Users can edit their profile field visibility on a field-by-field basis.
- Options available by default under “Who can see this field?” are Anyone, Logged In Users, and My Friends.
- Site administrators can select a default visibility level for each field. Admins can also force a field to maintain the default visibility – for instance, an admin may decide that a field called “Phone Number” should always be limited to Friends. (See the new
bp_xprofile_map_meta_caps(), and thebp_xprofile_change_field_visibilitycap.) - Developers can customize the available options using two new filters:
bp_xprofile_get_privacy_levels– Register or deregister new privacy levels with this filter. The data being filtered here is an array that looks like this:array( 'public' => array( 'id' => 'public' // Canonical, non-translatable name 'label' => __( 'Anyone', 'buddypress' ) // Label visible to users ), // etc )Add or remove items as you see fit.
bp_xprofile_get_hidden_fields_for_user– This is an array of xprofile field ids that should *not* be visible for the current viewer of the current displayed profile.
In the upcoming weeks, I’ll write a short example plugin to demonstrate how to remove existing levels and add custom levels.
- While the visibility filtering does not happen at the template level itself, the markup that allows users to modify profile visibility does require theme-level changes. The two key files are: /members/single/profile/edit.php (see the block beginning
if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) )) and /registration/register.php. In each case, you should be able to simply copy and paste the relevant blocks from bp-default; if you need to support older versions of BP, you may want to wrap it in aif ( function_exists( 'bp_xprofile_get_privacy_levels' ) )check.Note that if your theme does not provide the proper markup for users to customize their profile field visibility, fields will default to the admin-provided visibility level, which itself defaults to Public. Thus, the feature degrades gracefully in the absence of theme support.
Questions or comments? Leave them below, or in a relevant Trac ticket.

slaFFik 10:19 pm on March 16, 2012 Permalink |
Yay! That’s what the whole community wants!
Thanks, Boone, for such news
And what about activity items, profile sub-pages?
Boone B. Gorges 10:38 pm on March 16, 2012 Permalink |
Just xprofile fields for now. Activity items are immensely more complicated and resource intensive. Profile subtabs are handled by the components that register them, so would have to be taken care of in a distributed fashion. Maybe in the future
slaFFik 10:20 pm on March 16, 2012 Permalink |
And can we expect this to be in 1.6?
Boone B. Gorges 10:37 pm on March 16, 2012 Permalink |
Yes, this will be in 1.6.
slaFFik 10:54 pm on March 16, 2012 Permalink
You made my working night
croixhaug 11:10 pm on March 16, 2012 Permalink |
A client just asked about this as a custom feature, awesome that it will be part of core!
hoho 11:34 pm on March 16, 2012 Permalink |
great !!
modemlooper 12:09 am on March 17, 2012 Permalink |
My profile privacy plugin handles sub tab privacy
Sascha 11:29 am on August 6, 2012 Permalink |
Will your plugin still work with 1.6 or will it conflict with the new privacy levels introduced?
Martin 12:24 pm on March 17, 2012 Permalink |
Awesome news! Now BP is on the best way to get the favorite tool to create a social network. I cant wait until the acvtivity stream get its own privacy settings too
Jimmy 3:38 pm on March 18, 2012 Permalink |
So will this change create the ability to have different registration forms/fields depending on what option the users choose when registering?
Boone Gorges 6:30 pm on March 18, 2012 Permalink |
No. These changes allow the user to dictate who gets to see the data he/she enters into profile fields. It does not introduce any logic for profile field dependence.
Thomas 3:32 am on March 19, 2012 Permalink
I have seen this request in the forums is there any discussion in including this in the core in the future? I’m sorry if this is already been brought or is in the tickets newbie with wp and bp..
Boone Gorges 8:07 pm on March 19, 2012 Permalink
There is a ticket for similar functionality at https://buddypress.trac.wordpress.org/ticket/3962, which has been closed as ‘wontfix’ for now, in the hopes that a plugin developer will build it.
Boone Gorges 3:34 pm on March 22, 2012 Permalink |
As promised, here is a sample plugin to show how these visibility levels can be extended: https://github.com/boonebgorges/bbg-custom-bp-field-visibility
That plugin does two things: Removes the ‘friends’ level, and adds a new ‘Admins Only’ level. It should give you the framework needed to add whatever levels your heart desires.
Hamed 6:36 pm on May 18, 2012 Permalink |
Can users create their own privacy groups?
Antony 10:06 am on July 27, 2012 Permalink |
Hi, this is just what I’ve been looking for.
I’ve installed bp 1.6rc1 and I am able to set field visibility using the preset options. However, the fields are not then hidden from the profiles when viewed – and this is before I have attempted to integrate your plugin. Do I need to update my bp theme at all to work with the 1.6 changes?
Many thanks,
Antony
Antony 10:31 am on July 27, 2012 Permalink |
Sry, scrub that! I should have read your text more thoroughly (was in a rush to get this working) – I’ve uploaded the bpress theme changes for 1.6 and Bob’s your uncle! I shall now have a crack at your plugin – thanks again for this, Antony
Sascha 11:28 am on August 6, 2012 Permalink |
Hi there,
this looks great! Is there a way of defining fields that the user cannot choose the visibility of, but which are determined by the administrator? A functionality similar to modemloopers plugin (“let user decide”)…
Bert 6:33 pm on August 9, 2012 Permalink |
Hi there,
Thanx for this. Now i know how to create the extra fields and privacy. Now im only looking for a way to show these fields in the backoffice admin together with the basic account fields.
Any easy way to show them there for the admin?
Hoping for help
Jackie 11:12 pm on November 14, 2012 Permalink |
We loaded the plugin in our test site and yes, it works in so far as the user can dictate during the registration process who sees what. YAY!
However, we want only the Usernames to be visible by “anyone” and the members details and account info to be viewable by the admin only. I tried removing the other options as per the instructions and ended up with a parse error.
I’m obviously a newbie. I don’t believe I am understanding the instructions correctly.
What this plugin doesn’t do is change the visibility on the Name (Primary)(Required) of the Base Group to be viewable by admin only. While we want their real names on the back end for Admin, we don’t want them visible to all members. Is there any way to do that without the member having to go into their account details and change it themselves?
Please advise.
Thank you in advance for your help.
Lucien 1:19 am on February 7, 2013 Permalink |
Dear Boone, we tried your plugin but the option to make the default apply to all users does not work. Only when you let the user change the visibility setting does it have an effect. we are using WP 3.4.1 and BP 1.6.1 with the WP theme twentyeleven (child). You mention theme support but from what I can tell all should work. I am at a loss and any help will be greatly appreciated. Thank you!
Gideon 1:36 am on March 4, 2013 Permalink |
Hey Boone,I love the plugin. Was looking for a way to add the Admins only visisbility option and came across your code on GitHub. Just wondering, should I paste this in the plugin’s functions.php or the theme’s? I figure the latter would be good for consistency in case you do an upgrade but I’m a total newbie at php so I could be one Ctrl+V away from dividing by 0.
grima 12:17 pm on March 22, 2013 Permalink |
Hi,
Thanks a lot for this features. The plugin provided works greate except for one things : it doesn’t operate if default visibility level enforce overs user visibility level.
I’ve managed to patch it with this (from bp-xprofile-functions.php) :
function define_hidden_fields( $hidden_fields, $displayed_user_id, $current_user_id ) {
// Get the displayed user’s visibility settings
$user_visibility_levels = bp_get_user_meta( $displayed_user_id, ‘bp_xprofile_visibility_levels’, true );
// Parse the user-provided visibility levels with the default levels, which may take
// precedence
$default_visibility_levels = BP_XProfile_Group::fetch_default_visibility_levels();
foreach( (array) $default_visibility_levels as $d_field_id => $defaults ) {
// If the admin has forbidden custom visibility levels for this field, replace
// the user-provided setting with the default specified by the admin
if ( isset( $defaults['allow_custom'] ) && isset( $defaults['default'] ) && ‘disabled’ == $defaults['allow_custom'] && isset( $user_visibility_levels[$d_field_id] ) ) {
$user_visibility_levels[$d_field_id] = $defaults['default'];
}
}
$field_ids = array();
// Loop through the user defined levels
foreach( (array)$user_visibility_levels as $field_id => $field_visibility ) {
[...]
Hope this could help someone.
Vaughn 5:40 am on May 7, 2013 Permalink |
Hello Boone,
Not sure if this is the best place to post this, but it is the closest I could find. Considering how often I see your profile picture when looking for help I figured you’re probably one of the best to ask. So, here I go…..
All of my members are able to change the e-mail addresses and pass words for all other members.
They are able to do this by clicking on ‘settings’ while viewing another profile. I have tried disabling my plugins, and mucking around with stuff I should not be touching. But its been over a week now and I’m still lost. I can give you admin access, but would need to do it via e-mail as my sight has sensitive data on it. Please help (insert big cheesy smile here)
Thank you
Vaughn
Boone B. Gorges 11:24 am on May 7, 2013 Permalink |
Please send me an email: boone at gorg dot es.