BuddyDev

Search

[Resolved] Change order of visibility options.

  • Participant
    Level: Initiated
    Posts: 14
    Mark on #13024

    Hello, I have asked these questions at buddypress but I can’t seem to get an answer.

    I have your premium plugins that come with your support package. I would like to match the visibility options order of buddypress to the order in your plugins.

    Buddypress – Everyone, Only me, Friends Only, All Members

    Your plugins – Everyone, Logged In Users Only, Friends Only, Only Me

    I would also like to add followers to the options positioned after Logged In Users.

    Thankyou for your help.

  • Keymaster
    (BuddyDev Team)
    Posts: 21814
    Brajesh Singh on #13025

    Hi Mark,
    Thank you for asking.

    Here is the code that you can put in your bp-custom.php to change the order

    
    /**
     * Update profile visibility option for BuddyPress.
     */
    function buddydev_update_profile_field_privacy_options() {
    	$levels = buddypress()->profile->visibility_levels;
    
    	// and now we will override it's order.
    	buddypress()->profile->visibility_levels = array(
    		'public'     => $levels['public'],
    		'loggedin'   => $levels['loggedin'],
    		'friends'    => $levels['friends'],
    		'adminsonly' => $levels['adminsonly'],
    	);
    }
    
    add_action( 'bp_xprofile_setup_globals', 'buddydev_update_profile_field_privacy_options' );
    
    

    I am just reusing BuddyPress’s default values in the above code and reordering them.

    I am not sure if the follower option is supported by BuddyPress. To add that to profile visibility level, you will need to add a new visibility level and a handler for it.

    I wrote a post a few years about the same here
    https://buddydev.com/buddypress/extending-buddypress-profile-field-visibility/

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 14
    Mark on #13030

    Thankyou for responding, the above code works for friends and admins only, however loggedin is still last in the order. Any ideas?

    I will give your tutorial a go and let you know how it goes.

    Thanks again

  • Keymaster
    (BuddyDev Team)
    Posts: 21814
    Brajesh Singh on #13031

    Hi Mark,
    Here is how it looks to me

    https://i.imgur.com/mnQbNDk.png

    Are you seeing a different order?

    If yes, most probably another plugin is updating the order too.

    A solution might be to change the priority of the function that we are using to reorder.

    For example

    
    add_action( 'bp_xprofile_setup_globals', 'buddydev_update_profile_field_privacy_options' );
    

    Can be changed to this

    
    add_action( 'bp_xprofile_setup_globals', 'buddydev_update_profile_field_privacy_options', 1001 );
    

    and should most probably work.

  • Participant
    Level: Initiated
    Posts: 14
    Mark on #13032

    Sorry, I found the issue…my bad!

  • Participant
    Level: Initiated
    Posts: 14
    Mark on #13033

    Yes it was another plugin. (not one of yours) Thanks for your help, much appreciated.

  • Keymaster
    (BuddyDev Team)
    Posts: 21814
    Brajesh Singh on #13034

    No problem. Sometimes, overriding is only option. For example, the above code will have issues(If any plugin adds new visibility level, they will be hidden).

    So, Please keep that in perspective while adding new visibility level.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 14
    Mark on #13036

    Ok good to know, thankyou. 🙂

  • Participant
    Level: Initiated
    Posts: 14
    Mark on #13041

    Hello Brajesh, sorry to bother you again with this, I am having difficulties adding the visibility option for my followers. I have managed to add the selector but I cannot figure out how to control the data.

    Any advice you have is much appreciated.

  • Keymaster
    (BuddyDev Team)
    Posts: 21814
    Brajesh Singh on #13053

    Hi Mark,
    Please post your code here using backticks(`) or link me to the code on pastebin or any other place.

    I will update it as needed.

    Thank you
    Brajesh

You must be logged in to reply to this topic.

This topic is: resolved