Tagged: code
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?
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
RaviHello 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
RaviThis 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!!!
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
RaviHi 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 RahmanHi 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.