BuddyDev

Search

[Resolved] Hide "Add friend" Button after rejecting the friendship (only at the sender end

  • Participant
    Level: Initiated
    Posts: 14
    swati on #9008

    Hi,
    As the user reject the friendship. The button changed into “Add friend” for both users. I want to hide this button after rejecting the friendship at the sender end (which initiate or who send the friend request). The person who reject the friendship should see the “Add friend” Button only.

    Please help.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2908
    Ravi on #9010

    Hello Swati,

    Try the following code in your bp-custom.php file and let me know if it works or not

    
    function buddydev_custom_send_notification_on_friendship_rejection( $friendship_id, BP_Friends_Friendship $friendship ) {
    	add_user_meta( $friendship->initiator_user_id, '_rejected_by', $friendship->friend_user_id );
    }
    add_action( 'friends_friendship_rejected',  'buddydev_custom_send_notification_on_friendship_rejection', 10, 2 );
    
    function buddydev_hide_add_friend_button( $button ) {
    
    	$displayed_user_id = bp_displayed_user_id();
    	$user_id = ( $displayed_user_id ) ? $displayed_user_id : bp_get_member_user_id();
    
    	$rejected_by = get_user_meta( bp_loggedin_user_id(), '_rejected_by' );
    	
    	if ( in_array( $user_id, $rejected_by ) ) {
    		return '';
    	}
    
    	return $button;
    }
    add_filter('bp_get_add_friend_button', 'buddydev_hide_add_friend_button');
    
    

    Thank You
    Ravi

  • Participant
    Level: Initiated
    Posts: 14
    swati on #9013

    Hi Ravi Ji,
    Thank you so mcuh for the response.
    It is not working.
    as I have already used the function “buddydev_custom_send_notification_on_friendship_rejection” as suggested by Brajesh Ji in query #8743, So the error showing that you cann’t redeclare this function again.

    #8743 code is given below (It is working for sending the email message after rejection of friendship)
    function buddydev_custom_send_notification_on_friendship_rejection( $friendship_id, BP_Friends_Friendship $friendship ) {

    $initiator_user = get_user_by(‘id’, $friendship->initiator_user_id );
    $rejected_by_user = get_user_by( ‘id’, $friendship->friend_user_id );

    $message =<<<‘EOT’
    Hi %1$s,
    %2$s has rejected your friendship request.

    Team
    Xyz Site
    EOT;
    $message = sprintf( $message, $initiator_user->display_name, $rejected_by_user->display_name );
    wp_mail($initiator_user->user_email, “Friendship Rejection”, $message );

    }
    add_action( ‘friends_friendship_rejected’, ‘buddydev_custom_send_notification_on_friendship_rejection’, 10, 2 );

    Please look in this code again. Looking for your help.
    Thank you so much

  • Participant
    Level: Initiated
    Posts: 14
    swati on #9014

    Your code worked. Now Resolved… Thanks a lot Ravi Ji

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2908
    Ravi on #9015

    You are welcome. I am glad that you resolved by your own.

    Regards
    Ravi

The topic ‘ [Resolved] Hide "Add friend" Button after rejecting the friendship (only at the sender end’ is closed to new replies.

This topic is: resolved