BuddyDev

Search

[Resolved] Remove "add friend" button from admins' profile

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

    Hi,
    I want to restrict my users from sending friend request to my admins. So, I want to remove the “add friend” button from admins’ profile.
    Here I see a similar topic though, could not modify to satisfy my case. (https://buddydev.com/support/forums/topic/remove-add-friend-button-for-member-type-on-members-pagemembers-loop/)

    I will be greatly helped, if someone can help me out.

    Thank you,
    Md Sadiqur Rahman

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #8593

    Hi,
    Please use the following code in bp-custom.php

    
    
    /**
     * Disable add friends button fro admin users
     *
     * it is an example and not recommended. It can cause n extra queries due to capability checking on the members loop.
     *
     * @param $button
     *
     * @return mixed
     */
    function buddydev_hide_admin_friends_button( $button ) {
    
    	if( ! isset( $button['id'] ) || $button['id'] != 'not_friends' ) {
    		return $button;
    	}
    
    	$user_id = absint( str_replace( 'friend-','', $button['link_id'] ) );
    	if ( ! $user_id ) {
    		return $button ;
    	}
    
    	//we can check using is_super_admin( $user_id ) || user_can( $user_id, 'cap' )
    
    	if ( user_can( $user_id, 'manage_options' ) ) {
    		$button['id'] = false;
    	}
    
    	return $button;
    }
    add_filter( 'bp_get_add_friend_button', 'buddydev_hide_admin_friends_button' );
    
    

    Please do note that it will cause n extra queries on the members loop.

    Regards
    Brajesh

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

    Worked perfectly! Thank you so much.

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #8610

    You are most welcome!

The topic ‘ [Resolved] Remove "add friend" button from admins' profile’ is closed to new replies.

This topic is: resolved