BuddyDev

Search

[Resolved] Remove add friend button for member type on members page/members loop

Tagged: 

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #8411

    Hi, I want to remove the ‘add friend’ button for a specific member type in my buddypress site on the members page. I don’t want them to have friend requests from anyone.

    I tried this code provided by @henrywright at the buddypress support forum but it only works for the individual members page and not the members loop. After applying the code to bp-custom.php file the add friend button still shows on the member’s page.

    The idea is that I have a member type called business and it would not make sense to add a business as a friend but you can only follow a business, While other member types like male and female can still add friends.

    function browserco_filter_add_friend_button( $button ) {
    $member_type = bp_get_member_type( bp_displayed_user_id() );
    if ( ‘business’ !== $member_type ) {
    return $button;
    }
    return “”;
    }
    add_filter( ‘bp_get_add_friend_button’, ‘browserco_filter_add_friend_button’ );

    Please can you help with this?

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #8412

    Hello Tosin

    Thank you for posting here. Please try the following code in your bp-custom.php file and let me know if works or not.

    
    function buddydev_hide_add_friend_button( $button ) {
    
    	$displayed_user_id = bp_displayed_user_id();
    
    	$user_id = ( $displayed_user_id ) ? $displayed_user_id : bp_get_member_user_id();
    
    	$member_type = bp_get_member_type( $user_id );
    
    	if ( 'business' !== $member_type ) {
    		return $button;
    	}
    
    	return '';
    
    }
    add_filter('bp_get_add_friend_button', 'buddydev_hide_add_friend_button');
    
    

    Thank You
    Ravi

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #8417

    Thank very very much you are a life saver.

    It worked perfectly, I am indebted to you, you are God sent.

    I would really appreciate it if you can share this code to others on your blog. There might be other people having similar problems.

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #8418

    Is it possible to add more than one member type like business, brand, organization?

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #8420

    Hello Tosin,

    Thank you for your kind words. I am glad that I could help. Replace the above code with this.

    
    function buddydev_hide_add_friend_button( $button ) {
    
    	$displayed_user_id = bp_displayed_user_id();
    
    	$user_id = ( $displayed_user_id ) ? $displayed_user_id : bp_get_member_user_id();
    
    	$member_type = bp_get_member_type( $user_id );
    	
    	// add more member_type if you want
    	$not_in = array( 'business', 'brand', 'organization');
    	
    	if ( ! in_array( $member_type, $not_in, true ) ) {
    		return $button;
    	}
    
    	return '';
    
    }
    add_filter('bp_get_add_friend_button', 'buddydev_hide_add_friend_button');
    
    

    Thank You
    Ravi

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #8556

    This worked perfectly.

    After applying the code I just came to the realization that the problem is solved half way because the button does not show up but the friend tab in the navigation bar still shows. I should have realized this from the begining.

    So what do you think about disableing the actual buddypress friendship component for one or more specific member types.

    Also thank you for tremendous support!!!

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #8562

    Hello Tosin,

    I think it is a really bad idea to disable component based on member type. It can cause many issues. In normal cases, BuddyPress loads components much before registering member type, so even if we disable it somehow, it will have side effects.

    Thank You
    Ravi

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #8565

    Ok thanks

    Alternatively, what about removeing the friend tab in the navigation menu and drop down menu for one or more specific member types. This should solve the problem

  • Participant
    Level: Initiated
    Posts: 10
    Md Sadiqur Rahman on #8584

    Hi Ravi,
    I got a similar problem. In my case, I don’t want any user to send friend request to Admins. So the “Add friend” button will not be shown in admins’ profile. How to solve this problem?

    Thank you
    Md Sadiqur Rahman

  • Keymaster
    (BuddyDev Team)
    Posts: 24636
    Brajesh Singh on #8585

    Hi Sadiqur,
    Please open a new topic and we will post a solution.

    Thank you
    Brajesh

The topic ‘ [Resolved] Remove add friend button for member type on members page/members loop’ is closed to new replies.

This topic is: resolved