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)?

closed as off-topic by gmazzap, Nicolai, 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.


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; ?>

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