BuddyDev

Search

Remove Friendship Button

  • Participant
    Level: Guru
    Posts: 995
    calu on #37666

    Hi there, I have added this code to remove the friendship button, but apparently it has no effect?

    //remove friendship button on Single User profile
    add_action('bp_init','bp_custom_remove_friendship_btn_on_profile');
    function bp_custom_remove_friendship_btn_on_profile(){
        if ( has_action( 'bp_member_header_actions', 'bp_add_friend_button' ) ) {
                remove_action( 'bp_member_header_actions', 'bp_add_friend_button', 5 );
        }
    }

    https://buddydev.com/snippets/?s=Remove+Friendship+Button&stype=all

    Could you supply me with corresponding code for removing the friendship button in members directory?

    Thanks!

    Regards
    Carsten

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2461
    Ravi on #37705

    Hello Carsten,

    Thank you for posting. Please try the following code to hide add friend button in the member’s directory

    
    
    add_filter( 'bp_get_add_friend_button', function ( $button ) {
    
    	if ( bp_is_members_directory() ) {
    		$button = array();
    	}
    
    	return $button;
    } );
    
    

    Please do let me know if it works or not.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 995
    calu on #37725

    Hello Ravi, thank you very much for your help, much appreciated, it’s working perfectly.

    I can use the code for hiding the button in members header actions as well, but the only function I can find in BP documentation is bp_is_user_profile()which removes the friend button from all of the profile page. Is there a function for the member header action?

    I can see that there are many approaches to hiding buttons, add_action . remove_action or add_filter, return $button; ,'__return_false', $display = false;

    Is there any systematic approach when choosing method?

    Thanks again.

    Regards
    Carsten

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2461
    Ravi on #37778

    Hello Carsten,

    Thank you for the acknowledgment. Please try the ‘bp_is_user’ function it will be true when you are on a BuddyPress User Profile.

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: not resolved