BuddyDev

Search

[Resolved] Problem to Setting Auto Friendship

  • Participant
    Level: Initiated
    Posts: 16
    Emanuele Maria Esposito on #36738

    Yes, I tried to change the type of member and then put back the correct one but it doesn’t work

    if you want I can also provide you with FTP access

  • Keymaster
    (BuddyDev Team)
    Posts: 24237
    Brajesh Singh on #36739

    Hi Emanuele,
    Thank you.

    Please do. That will help us check and update the code as needed.

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 16
    Emanuele Maria Esposito on #36740
    This reply has been marked as private.
  • Participant
    Level: Initiated
    Posts: 16
    Emanuele Maria Esposito on #36741
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24237
    Brajesh Singh on #36752

    Hi Emanuele,
    Thank you for the patience.

    There was a minor update needed in the code.

    Here it is

    
    
    /**
     * Add as friend other user with same member type on user member change.
     */
    add_action( 'bp_set_member_type', function ( $user_id, $member_type ) {
    
    	$member_type = (array) $member_type;
    	if ( ! in_array( 'partner', $member_type ) ) {
    		return;
    	}
    
    	$users = new BP_User_Query(
    		array(
    			'member_type'     => 'partner',
    			'populate_extras' => false,
    		)
    	);
    	if ( ! $users->total_users ) {
    		return;
    	}
    
    	foreach ( $users->user_ids as $id ) {
    
    		if ( $id == $user_id ) {
    			continue;
    		}
    
    		if ( ! friends_check_friendship( $user_id, $id ) ) {
    			friends_add_friend( $id, $user_id, true );
    		}
    	}
    }, 10, 2 );
    

    It is working on the staging site now. I have put ti in the child theme’s functions.php

    Regards
    Brajesh

    PS:- I tested by changing a user’s member type, Please revert them.

  • Participant
    Level: Initiated
    Posts: 16
    Emanuele Maria Esposito on #36759

    Hi Brajesh,
    I try to change a member and they became friends correctly.
    But now, if I rechange the member types, the friendship remains … I don’t want that to happen.

    I would like only the “partners” to remain friends.
    thanks for support

  • Keymaster
    (BuddyDev Team)
    Posts: 24237
    Brajesh Singh on #36763

    Hi Emanuele,
    Thank you for confirming.

    I am sorry, there is no way to know in BuddyPress when a specific member type was removed. If you remove a member types, it uses set member type action. So,m we don’t have access to previous member type to determine if we should remove all friends.

    If you want, we can add the code for a condition like this. If a user’s member type is set to None(”), we remove all friends. It will apply for all member type though.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 16
    Emanuele Maria Esposito on #36772

    Ah, I understand.
    For now, thanks Brajesh.
    We will try to pay attention to the assignment of users

    Thanks for the support.

  • Keymaster
    (BuddyDev Team)
    Posts: 24237
    Brajesh Singh on #36799

    Hi Emanuele ,
    Thank you for the understanding.

    Regards
    Brajesh

The topic ‘ [Resolved] Problem to Setting Auto Friendship’ is closed to new replies.

This topic is: resolved