Tagged: add friend
Hi there,
I want to remove the ‘add friend’ button for admin members in my buddypress site. I don’t want them to have friend requests from anyone.
I found this, but it doesn’t work – I also see it maybe for business type users, but even when I replace it for admin, it doesn’t work:
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' );
Thank you so much, and looking forward for your kind reply
Kristian
Hello Kristian,
Thank you for posting. Please try the following code. It will allows certain member types to be excluded from sending friendship.
function buddydev_filter_add_friend_button( $button ) { $user_id = bp_is_user() ? bp_displayed_user_id() : bp_get_member_user_id(); $member_types = bp_get_member_type( $user_id, false ); if ( ! $member_types ) { return $button; } // Comma separated list of member types to be excluded. $excluded_member_types = array( 'business', 'admin' ); $has_excluded_member_type = array_intersect( $excluded_member_types, $member_types ); if ( ! empty( $has_excluded_member_type ) ) { return ''; } return $button; } add_filter( 'bp_get_add_friend_button', 'buddydev_filter_add_friend_button' );
Please let me know if it works or not.
Regards
RaviHi Ravi,
Thank you so much for getting back to me. Sadly, it doesn’t work.
I put it in my BP custom file. is that alright, or must this go in the functions?
Any other suggestions?
Hello Kristian,
Thank you for the acknowledgement. It seems you are looking for a solution to site admins. If it is the case use the following code to hide “Add Friend” button for site admins.
function buddydev_hide_add_friend_button( $button ) { $user_id = bp_is_user() ? bp_displayed_user_id() : bp_get_member_user_id(); if ( is_super_admin( $user_id ) ) { $button = ''; } return $button; } add_filter( 'bp_get_add_friend_button', 'buddydev_hide_add_friend_button' );
Please let me know if it works or not. If not please do let me know what is “admin” in your case.
Regards
RaviHi again Ravi,
thank you so much for getting back to me. Your code is amazing, but one small issue:
As I worked on this all evening and found after a while that it looks like I need that in user IDs rather than admins.
I have Admins hidden, and redirect rules if you try to access them.
so actually this all would work if your code would require specific user IDs
The user ID i need for this is 340
kind regards to you, sir.
Kristian
Hello Kristian,
Remove all previous code and Try the following code based on user ids.
function buddydev_hide_add_friend_button( $button ) { $user_id = bp_is_user() ? bp_displayed_user_id() : bp_get_member_user_id(); $excluded_user_ids = array( 340 ); // Enter comma separated list of ids you want to exclude. if ( in_array( $user_id, $excluded_user_ids ) ) { $button = ''; } return $button; } add_filter( 'bp_get_add_friend_button', 'buddydev_hide_add_friend_button' );
Regards
Ravi
The topic ‘ [Resolved] Remove 'add friend' button for member type (admins)’ is closed to new replies.