Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 G. M., ialocin, birgire, kaiser Aug 1 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.

1 Answer 1

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.