BuddyDev

Search

[Resolved] BuddyPress Profile Visibility Manager- Hidden profile shows in navigation

  • Participant
    Level: Initiated
    Posts: 7
    Cathy on #7440

    Hi,

    I’ve searched but couldn’t find anything on this; sorry if it’s been dealt with already.

    I really like this plugin but it’s not hiding my profile in the Next/Previous profile navigation used by the KLEO theme. When the navigation is enabled, a user on his/her BP profile can click to move through the other users’ profiles one by one. My hidden profile with my name and avatar is still displayed in the navigation. Even though the redirect is working, I don’t want the profile included in the navigation. I don’t want to disable the navigation either because I would lose it for my other post types and plus I think it’s useful for profiles too.

    Can you tell me how to take hidden profiles out of this navigation? Or if that won’t work could you let me know how to substitute “Private Profile” and the default avatar for my name and avatar?

    There is one post in the KLEO support forums from someone with the same issue and he mentioned the way to exclude the profile may lie in kleo/buddypress/buddypress-functions.php. In that file, it mentions “Functions of BuddyPress’s Legacy theme” at the top. There is a bunch of stuff for “get next profile link” and “get previous profile links.” As you can tell, I’m a newbie so I can’t figure this out by myself.

    Thanks for your help with this issue

    Cathy

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #7441

    Hi Cathy,
    Welcome to BuddyDev.

    I looked at the kleo theme and I see that they have a function

    
    bp_next_profile()
    
    

    which they use for fetching next profile.
    The problem is this function does not use any standar WordPress/BuddyPress API functions. It queries using raw sql.

    It does provide one entry point

    
    bp_pre_user_query_construct
    
    

    That we can use for excluding but that will be inefficient. The problem is we need to fetch the complete list of users who have hidden profile and then specify in the ‘exclude’ parameter in the above if we want to hide it from the next. this approach is fine for smaller network but will cause issue on the large network.

    If you want, I can provide the code to remove hidden profile (I will still be avoiding to add that to the plugin as it may cause problem for our existing users).

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 7
    Cathy on #7453

    Hi Brajesh,

    Thanks for the quick reply and for the help! My site is not public yet, and once it is there may not be many people who keep their profile private. So, I’d like to implement any code you suggest, and if it becomes problematic I’ll deal with that when the time comes.

    If it will be easier and more efficient, I’d be happy to implement a code that does not exclude hidden profiles but rather just substitutes “Private Profile” for the user’s name and shows a default avatar instead of the users real avatar.

    Regards,

    Cathy

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #7455

    Hi Cathy,
    Please put this code in your bp-custom.php

    
    
    function buddydev_exclude_users_in_bp_user_query( $query ) {
    
    	if ( ! function_exists( 'bp_profile_visibility_manager' ) ) {
    		return;
    	}
    
    	$excluded = bp_profile_visibility_manager()->get_users( 'bp_profile_visibility', 'self' );
    	//should we exclude friends only profile too?
    	$excluded = array_merge( $excluded, bp_profile_visibility_manager()->get_users( 'bp_profile_visibility', 'friends' ) );
    
    	$pre_excluded = empty( $query->query_vars['exclude'] ) ? array() : wp_parse_id_list( $query->query_vars['exclude'] );
    
    	if ( ! empty( $pre_excluded ) ) {
    		$excluded = array_merge( $excluded, $pre_excluded );
    	}
    
    	$query->query_vars['exclude'] = $excluded;
    
    }
    
    add_action( 'bp_pre_user_query_construct', 'buddydev_exclude_users_in_bp_user_query' );
    
    

    Please do let me know if it works or not?

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 7
    Cathy on #7456

    Hi Brajesh,

    Thanks for getting back to me so quickly! I tried the code and unfortunately it doesn’t work. I get the following error:
    Parse error: syntax error, unexpected ‘return’ (T_RETURN) in /home/xxxxx/public_html/wp-content/plugins/bp-custom.php on line 150

    Line 150 is the third line of code (return;).

    Regards,

    Cathy

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #7457

    Hi Cathy,
    Is there any chance that you copied the code from the notification email. The code might have been entity encoded.
    can you please post it on pastebin and link me?

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 7
    Cathy on #7458

    Hi Brajesh,

    That was the problem; when I pasted it as plain text no error pops up. But the code didn’t seem to change anything. My name and avatar are still showing on the navigation when I’m logged in as test non-admin user.

    Cathy

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #7520

    Hi Cathy,
    Apologies for the delayed reply.

    I am going to test it with the theme today and will report back with updated code.

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 7
    Cathy on #7521

    Great- thanks for the continued help!

    Cathy

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #7532

    Hi Cathy,
    Please give the following code try one more time

    
    
    function buddydev_exclude_users_in_bp_user_query( $query ) {
    
    	if ( ! function_exists( 'bp_profile_visibility_manager' ) ) {
    		return;
    	}
    
    	$excluded = bp_profile_visibility_manager()->get_users( 'bp_profile_visibility', 'self' );
    	//should we exclude friends only profile too?
    	$excluded = array_merge( $excluded, bp_profile_visibility_manager()->get_users( 'bp_profile_visibility', 'friends' ) );
    
    	$pre_excluded = empty( $query->query_vars['exclude'] ) ? array() : wp_parse_id_list( $query->query_vars['exclude'] );
    
    	if ( ! empty( $pre_excluded ) ) {
    		$excluded = array_merge( $excluded, $pre_excluded );
    	}
    
    	if ( ! empty( $excluded ) ) {
    		$query->query_vars['exclude'] = $excluded;
    	}
    
    }
    
    add_action( 'bp_pre_user_query_construct', 'buddydev_exclude_users_in_bp_user_query' , 100);
    
    

    All I have changed here is the priority and the checkl if there is something to exclude.

    Even the first code worked for me. When you set a profile as Only me(private) It is not visible in part of the previous/next navigation.

    It is possible that some other is overriding the exclude too, so changing the priority might work.

    Thank you
    Brajesh

The topic ‘ [Resolved] BuddyPress Profile Visibility Manager- Hidden profile shows in navigation’ is closed to new replies.

This topic is: resolved