BuddyDev

Search

[Resolved] Xrofile field visibility change by php function

  • Participant
    Level: Initiated
    Posts: 14
    Abhist on #43043

    Hi
    I am using xprofile custom field type plugin.

    I want to know how can how can change profile visibility setting of perticular user id from “me only” to “all members” using any php function in bp-custom.php

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #43054

    Hi Abhist,
    Welcome to BuddyDev forums.

    Thank you for the question. Here are my answers.

    1. The profile field visibility is a BuddyPress core feature and has nothing to do with teh xprofile cusotm field types plugin.

    2. You can not change the visibility for a user. It is saved for each field of the user. So, if you have 20 fields, you will need to update it for all the 20 fields.

    Here is the function which is used to set it

    
    xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
    

    Where $field_id is the numeric xprofile field id.
    $user_id is the numric id of the user in context.
    $visibility_level is a string which is one of the registered visibility levels(e.g ‘loggedin’).

    Hope that helps.

    PS:- The visibility setting is stored in user meta, so if you wnat to avoid too many queries, you can directly update the user meta key ‘bp_xprofile_visibility_levels’ with an associative array containing field id as key and its visibility as the value.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 14
    Abhist on #43618

    Thankyou so much

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #43638

    You are welcome.

The topic ‘ [Resolved] Xrofile field visibility change by php function’ is closed to new replies.

This topic is: resolved