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_visibility
cap.) - 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.