Hi Emanuele,
Thank you for the patience. It seems @ravisharma was not available and could not assist you today. Either He or I will be providing you the code within next 24 hours.Regards
BrajeshHello Emanuele,
Please try the following code. It will add all other users with the same member type add as friends.
/** * Add as friend other user with same member type on user member change. */ add_action( 'bp_set_member_type', function ( $user_id, $member_type ) { $users = new BP_User_Query( array( 'member_type' => $member_type, 'populate_extras' => false, ) ); if ( ! $users->total_users ) { return; } foreach ( $users->user_ids as $id ) { if ( $id == $user_id ) { return; } if ( ! friends_check_friendship( $user_id, $id ) ) { friends_add_friend( $id, $user_id, true ); } } }, 10, 2 );
Please do let me know if it works or not.
Regards
RaviHi guys,
Does this code become friends with all the members of the same type right?
Because I would only need it for a specific type of member called “partner”.thanks
- This reply was modified 3 years, 1 month ago by Emanuele Maria Esposito.
Hi Emanuele,
You are right. It would do so for all member types.Here is the code that only targets the ‘partner’ member type
/** * Add as friend other user with same member type on user member change. */ add_action( 'bp_set_member_type', function ( $user_id, $member_type ) { if ( 'partner' !== $member_type ) { return; } $users = new BP_User_Query( array( 'member_type' => $member_type, 'populate_extras' => false, ) ); if ( ! $users->total_users ) { return; } foreach ( $users->user_ids as $id ) { if ( $id == $user_id ) { return; } if ( ! friends_check_friendship( $user_id, $id ) ) { friends_add_friend( $id, $user_id, true ); } } }, 10, 2 );
Regards
BrajeshHi Brajesh,
I tried the code but it doesn’t seem to work.How should I best set the plugin?
This is currently the case
https://snipboard.io/JPKx4l.jpgThanks
Hi Emanuele,
Thank you for the reply.1. Please use the updated code. There was a bug in the previous snippet.
/** * Add as friend other user with same member type on user member change. */ add_action( 'bp_set_member_type', function ( $user_id, $member_type ) { if ( 'partner' !== $member_type ) { return; } $users = new BP_User_Query( array( 'member_type' => $member_type, '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 );
2. The above code is independent of the Friendship Pro plugin. It will work with any rules.
Regards
BrajeshHi Brajesh,
unfortunately, it still doesn’t work.
As you can see in the image the friend’s list remains at 0.
https://snipboard.io/AKMzyu.jpgI also tried to manually re-enter users in the plugin but it doesn’t work.
Hi Emanuele,
Did you try to change a user’s member type after puttin the code from my last update?Regards
Brajesh
The topic ‘ [Resolved] Problem to Setting Auto Friendship’ is closed to new replies.