BuddyDev

Search

[Resolved] Set default visibility for new profile field programmatically

Tagged: 


  • Participant
    Level: Initiated
    Posts: 1
    Matt Hart on #11779

    I’m adding new fields programmatically. How do I set the default visibility?

    $field_id = xprofile_insert_field([
        'field_group_id'    => $group->id,
        'type'              => 'textbox',
        'name'              => 'Admins Only Field',
        'is_required'       => false,
        'can_delete'        => true,
        'field_order'       => 3,
        'description'       => "Enter something in this field that only you can see."
    ]);

    After getting the $field_id, I can load all the users and set their individual visibility to adminsonly using xprofile_set_field_visibility_level — but that doesn’t change it on the Edit Field info.


  • Keymaster
    (BuddyDev Team)
    Posts: 15556
    Brajesh Singh on #11781

    Hi Matt,
    Welcome to BuddyDev.
    You are setting the visibility for the data using the ‘xprofile_set_field_visibility_level’. Please try setting it for field using the following

    
    
    bp_xprofile_update_field_meta( $field_id, 'default_visibility', 'adminsonly' );
    bp_xprofile_update_field_meta( $field_id, 'allow_custom_visibility', 'disabled' );
    
    

    After you get the field id. That should do it.
    Regards
    Brajesh


  • Participant
    Level: Initiated
    Posts: 1
    Matt Hart on #11804

    Worked great, thanks!


  • Keymaster
    (BuddyDev Team)
    Posts: 15556
    Brajesh Singh on #11805

    I am glad it did! You are welcome 🙂

The topic ‘ [Resolved] Set default visibility for new profile field programmatically’ is closed to new replies.

This topic is: resolved
Subscribe