Hi Ravi,
I’m hoping to make a slight change to the functionality of the code snippet you kindly supplied. As below.
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 ); } );
The reason: the code hides the Add Friend buttons when userA is viewing the friends list of userB. All good, as intended.
But when userA views his own friends list, the buttons are also hidden, which hides the Cancel Friendship button next to all friends in his list. This makes it awkward for him to cancel friendships, he has to visit the profiles to do so.
So I want the same functionality, but not when a user is viewing their own friends list.
I have made changes, shown below. Sorry, I am not a coder, so these are guesses really. This code seems to work as intended on my test site.
Please could you confirm this is correct code. Only then will I use it on my live site.
Thanks.
add_action( 'bp_before_friends_loop', function() { if (bp_is_my_profile() ){ return true; } add_filter( 'bp_get_add_friend_button', '__return_empty_array' ); } ); add_action( 'bp_after_friends_loop', function () { if (bp_is_my_profile() ){ return true; } remove_filter( 'bp_get_add_friend_button', '__return_empty_array', 10 ); } );
Hi Michael,
I am sorry, Ravi has been away due to some personal emergencies. I was waiting for him to take a look and assist you.Your code is fine and will work fine.
Regards
Brajesh
The topic ‘ [Resolved] Reopened topic – Can I hide “Add Friend” buttons when viewing friends list ?’ is closed to new replies.