Tagged: auto friendship pro
Hi Chris,
No issues.1. No, It will not have any effect on existing users. If you need that, please use our BuddyPress Custom development services. The time taken is beyond what we offer as forum support.
Here is the update code for excluding some domains. Please feel free to add more.
/** * 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]; // Lis of excluded domains. $excluded_domain = array( 'gmail.com', 'outlook.com', 'yahoo.com', ); // skip if in the excluded domain list. if ( in_array( $domain, $excluded_domain ) ) { return; } $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 ); }
Regards
BrajeshP.S:- Please do not copy this code from the forum notification mail. Instead use it form the support page here.
You are welcome.
I am glad it worked.Regards
Brajesh
You must be logged in to reply to this topic.
This topic is: resolved