Auto Be-Friend Buddypress users who are also FB users
-
We were playing with code to do the following…
a> New user signs up
b> It checks his list of FB Friends
c> It checks to see which of those friends are already buddypress users
d> It then auto befriends those found in c> in buddypress.The idea is to make buddypress a less lonely place by auto adding any FB friends of the new user who happens to be already signed up to that buddypress site. What we also do is update wp_usermeta with some of the extracted fb info eg birthdate
It works fine, but having some issues in that (and only seems to be affecting some old users who were friends already in BP, and then login with WP Social Login) – it wont remove the friends request notification
We added the code to a custom functions plugin we have, but i guess you could add it to bp-custom.php too? I am sharing this hoping to get some ideas going on how we could enhance this
function greg_update_social_facebook($user) { global $wpdb, $bp; $userId = $user; $udate = get_user_meta($userId, 'DOB', true); if ( !isset($udate) || empty($udate) ) { $sql4 = "SELECT * FROM wp_wslusersprofiles WHERE user_id = {$userId} AND provider='Facebook'"; $rs4 = $wpdb->get_results( $sql4 ); if ( !isset($rs4) || empty($rs4) ) return; foreach( $rs4 as $items4 ) { $identifier = $items4->identifier; $gender = $items4->gender; $birthday = (int)$items4->birthday; $birthyear = (int)$items4->birthyear ; $birthmonth = (int)$items4->birthmonth; $dob = $birthmonth . '/' . $birthday . '/' . $birthyear; $udate = $birthyear . '-' . $birthmonth . '-' . $birthday; $profileurl= $items4->profileurl; update_user_meta($userId, 'facebook_uid', $identifier); update_user_meta($userId, 'facebook', $identifier); update_user_meta($userId, 'fb_url', $profileurl); update_user_meta($userId, 'facebook_id', $profileurl); update_user_meta($userId, 'gender', $gender); update_user_meta($userId, 'DOB', $dob); } } $friendsSql = "SELECT <code>identifier</code> FROM <code>{$wpdb->base_prefix}wsluserscontacts</code> WHERE user_id = {$userId} AND <code>provider</code> = 'Facebook'"; $friendsSql = $wpdb->get_col( $friendsSql,0 ); $friends_list = implode(',',$friendsSql); $friendIds = "SELECT DISTINCT <code>user_id</code> FROM <code>wp_usermeta</code> WHERE (<code>meta_key</code> = 'facebook' AND <code>meta_value</code> IN ({$friends_list}) ) OR (<code>meta_key</code> = 'facebook_uid' AND <code>meta_value</code> IN ({$friends_list}) ) OR (<code>meta_key</code> = 'Facebook' AND <code>meta_value</code> IN ({$friends_list}) )"; $friendIds = $wpdb->get_col($friendIds, 0); echo '1111'; foreach ( $friendIds as $fId ) { $friendship_status = BP_Friends_Friendship::check_is_friend( $userId, $fId ); if ( 'not_friends' == $friendship_status ) { friends_add_friend($userId, $fId, false); } } wp_redirect( 'activity/') ; exit; } add_action( "wsl_hook_process_login_before_redirect", 'greg_update_social_facebook' );
[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]
- The topic ‘Auto Be-Friend Buddypress users who are also FB users’ is closed to new replies.