BuddyDev

Search

Can I hide “Add Friend” buttons when viewing Buddypress Profile>Friends?

  • Participant
    Level: Enlightened
    Posts: 22
    Michael on #44308

    Hi!
    As part of moderating new members of my site, the Add Friend/Private Message buttons are hidden on profiles. Simple code snippets used, all good. (I can not code unfortunately)

    But when visiting a profile, and then viewing the Friends of that user, each member in the list has an “Add Friend” button displayed.

    I need to completely hide these buttons, for all users, admin included, permanently.

    Is it possible?

    Any advice greatly appreciated!

  • Participant
    Level: Enlightened
    Posts: 22
    Michael on #44309

    Sorry, this post should be in Buddypress not Themes.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2986
    Ravi on #44315

    Hello Michael,

    Welcome to the BuddyDev Forums. Please share the code you are using to hide Buttons so that I can help you.

    Do you want to complete hide this button only or do want to disable the friends and message feature also?.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 22
    Michael on #44322

    Thanks Ravi,

    – Add Friend/Private Message buttons are hidden on profile page using “BP Registration Options” plugin, for new members only, once ‘approved’ those buttons become visible to the user.

    – Add Friend button is hidden on members page (for all users) using code snippet:

     /**
     * Hide "Add Friend" button on members list & search results list
     */
    add_filter( 'bp_get_add_friend_button', function ( $button ) {
    
    	if ( bp_is_members_directory() ) {
    		$button = array();
    	}
    
    	return $button;
    } ); 

    – So I need the similar functionality as the snippet above; simply hide the Add Friend buttons in the Friends list (for all users), but the friends feature is not disabled.

    Thanks!

  • Participant
    Level: Enlightened
    Posts: 22
    Michael on #44324

    I tried changing the above to:

    
    if ( bp_is_members_directory() || bp_is_friends_component() )
    

    which does hide the Add Friend buttons in the user’s Friends list (which I want), but also unfortunately hides the Add Friend button at the top of the profile (which I don’t want).

    Could this be improved on?

    Thankyou!

    • This reply was modified 2 years, 1 month ago by Michael.
    • This reply was modified 2 years, 1 month ago by Michael.
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2986
    Ravi on #44327

    Hello Micael,

    Thank you for sharing the code. Please try the following code for hiding Add Friend button in the friends list.

    
    add_action( 'bp_before_friends_loop', function() {
    	add_filter( 'bp_get_add_friend_button', '__return_empty_array' );
    } );
    
    add_action( 'bp_after_friends_loop', function () {
    	remove_filter( 'bp_get_add_friend_button', '__return_empty_array', 10 );
    } );
    
    

    Please check.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 22
    Michael on #44328

    Ravi,
    That works perfectly.
    And is exactly what I wanted to achieve.
    I appreciate your help very much indeed.
    Thankyou sir!

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2986
    Ravi on #44345

    Hello Michael,

    Thank you for the acknowledgement. I am glad that I could help you.

    Regards
    Ravi

The topic ‘Can I hide “Add Friend” buttons when viewing Buddypress Profile>Friends?’ is closed to new replies.

This topic is: not resolved