Tagged: auto friendship pro
I purchased a full membership today and I’m migrating a full Buddypress site to Buddyboss – inclusive of forums and over 3,000 active community members. Hoping to get some clarity on a few things…
I’d like to have Auto Friendship Pro set up so that anyone who has an email domain of @companyX.com is automatically friends.
OR
I’d like to have a rule for AFP that says anyone with the same Profile Type (memberpress pro) is automatically friends. (versus using Role)
AND
I’d like to have whichever of these rules that can be implemented to work backward – meaning that existing members that meet these criteria will be friended rather than waiting on new registrations.Is this possible? Or am I looking for a completely different plugin?
Hi Chris,
Thank you for joining our membership.The BuddyPress Auto Friendship Pro addd the new User to a list of predefined users. In other words, the list of users who will be added is preset.
What you are looking for is finding a match between the users and add them as friend. The plugin does not do that.
Yes, It is doable with some code(will that work for you?). If I put the custom code, It will only apply to new users.
If you need it for existing users, it will need searching all users and managing a queue for adding friendship relationship(which will be ajax based to avoid timeouts). This will be beyond the scope and will need custom service.
Regards
BrajeshHi Chris,
Yes. It is your choice. Whichever you prefer(email domain based or member type based), Please let me know and I will post the code.Regards
BrajeshHi Chris,
I will be sharing the code in next 3-4 working days. Need some time to put it.I won’t be able to share it for existing users. To be honest, For existing users or larger number of users, this needs to be done as plugin where we move the processing of search/adding in background queue and need to manage multiple queues(for existing users).
Due to time constraint, I will share the code which won’t be using background processing. Should work fine for smaller number of users though.
Regards
BrajeshHi Chris,
Thank you for the patience.Here is the code to add all users from same domain as friend. It adds them as friend when a user account is activated.
/** * Add users from same domain as friend on account activation. * * @param int $user_id user id. */ function buddydev_add_friends_on_activation_by_email_domain( $user_id ) { $user = get_user_by( 'id', $user_id ); if ( ! $user ) { return; } $email_parts = explode( '@', $user->user_email ); if ( count( $email_parts ) !== 2 ) { return; } $domain = $email_parts[1]; $potential_friend_ids = buddydev_get_users_with_email_domain( $domain ); if ( empty( $potential_friend_ids ) ) { return; } foreach ( $potential_friend_ids as $potential_friend_id ) { if ( $potential_friend_id == $user_id || friends_check_friendship( $user_id, $potential_friend_id ) ) { continue; } friends_add_friend( $potential_friend_id, $user_id, true ); } } add_action( 'bp_core_activated_user', 'buddydev_add_friends_on_activation_by_email_domain' ); /** * Get all users who have given email domain. * * @param string $domain domain name. * * @return array */ function buddydev_get_users_with_email_domain( $domain ) { global $wpdb; $pattern = '%@' . trim( $domain ); $sql_statement = $wpdb->prepare( "SELECT ID FROM {$wpdb->users} WHERE user_email LIKE %s", esc_sql( $pattern ) ); return $wpdb->get_col( $sql_statement ); }
I am not sharing the code for the member type since BuddyPress does not set member type on activation and BuddyBoss does set it but that is not straight forward(or guaranteed and depends on settings).
Regards
BrajeshGreat, thanks.
Sorry for delay – was off for a week.A few questions…
Will this auto-friend for users that already are in the site?
Is there a way that I can define the domains or at least set up domains to NOT be matched? For instance, I would not want everyone with a gmail.com address to be friended together – just people with work-related emails.
You must be logged in to reply to this topic.