Skip to:
Content
Pages
Categories
Search
Top
Bottom

Xprofile check if user can view field

  • @remcob00

    Participant

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

    (Is also asked this question on WordPress Answers but I didn’t get a answer there)

Viewing 4 replies - 1 through 4 (of 4 total)
  • @r-a-y

    Keymaster

    Hmm, I think xprofile_get_field_data() might need to be altered in order to add logged-in visibility level checks.

    Can you create a ticket at https://trac.buddypress.org/newticket so someone can take a look at this later on?

    @shanebp

    Moderator

    @r-a-y
    Any reason not to use bp_xprofile_get_hidden_fields_for_user() ?

    @remcob00

    Participant

    Thanks guys. bp_xprofile_get_hidden_fields_for_user() was the thing that I needed! This is 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; ?>

    @martyn_

    Participant

    I have a slightly related question – the above works in terms of displaying a field, but it doesn’t help if you just want to know the specific level of privacy a user has attached to a field.

    For example I want a user to be able to trigger an action themselves (ie they are the logged in user), which would provide only their xprofile data which is set to ‘public’. It would be really useful to be able to directly query the profile visibility, not to the current user, but get the actual value.

    get_profile_field_visibility('The Field Label', $the_user_id )

    Is this possible?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Xprofile check if user can view field’ is closed to new replies.
Skip to toolbar