BuddyDev

Search

[Resolved] Remove 'add friend' button for member type (admins)

Tagged: 

  • Participant
    Level: Enlightened
    Posts: 46
    Kristian Yngve on #23214

    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

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

    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
    Ravi

  • Participant
    Level: Enlightened
    Posts: 46
    Kristian Yngve on #23240

    Hi 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?

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

    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
    Ravi

  • Participant
    Level: Enlightened
    Posts: 46
    Kristian Yngve on #23258

    Hi 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

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

    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

  • Participant
    Level: Enlightened
    Posts: 46
    Kristian Yngve on #23287

    Ravi, this is perfect!

    Thank you so so much. 🙂

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

    Thank for the acknowledgement.

    Regards
    Ravi

The topic ‘ [Resolved] Remove 'add friend' button for member type (admins)’ is closed to new replies.

This topic is: resolved