WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use the following code to get a custom BuddyPress Xprofile field:

<?php if($field = bp_get_profile_field_data('field=field_name')) : ?>
<p><?php echo $field; ?></p>
<?php endif; ?>

But how can I check if the current viewer has the permission to view the field (from the visibility setting who the user can set)?

share|improve this question

closed as off-topic by gmazzap, ialocin, birgire, kaiser Aug 1 '14 at 23:32

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 0 down vote accepted

I found the answer to this question with support from the members from the BuddyPress forum. The function that I needed was xprofile_get_field_data().

Here my code:

<?php $hidden_fields = bp_xprofile_get_hidden_fields_for_user(); ?>
<?php if(xprofile_get_field_data('field_name') && !in_array(xprofile_get_field_id_from_name('field_name'), $hidden_fields)) : ?>
<p><?php echo xprofile_get_field_data ('field_name'); ?></p>
<?php endif; ?>
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.