• You guys might need to clean this up, basically what this does id auto befriend a new user signing up via FB, if any of his FB friends already are users on the blog as well… Please include sometime as a possible feature… you might have to check the BP friends functions to see if they were updated as this was written for BP 1.8.

    $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);
    			bp_core_delete_notifications_by_item_id( $fId, $userId, $bp->friends->id, 'friendship_request' );
    
    		}
    	}

    https://www.ads-software.com/plugins/wordpress-social-login/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter maddogmcewan

    (@maddogmcewan)

    I am trying to get this working for steam logins as well (using STEAM WEB API – u will need an API key)

    https://developer.valvesoftware.com/wiki/Steam_Web_API

    see GetFriendList (v0001)

    $api = "https://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&steamid=".$steamID64."&relationship=friend";
    		$json = file_get_contents($api);
    
    		$decoded = json_decode($json);
    		print_r($decoded);

    this returns a neat array

    {
    	"friendslist": {
    		"friends": [
    			{
    				"steamid": "76561198118150514",
    				"relationship": "friend",
    				"friend_since": 1411898458
    			},
    			{
    				"steamid": "76561198129669246",
    				"relationship": "friend",
    				"friend_since": 1411942139
    			},
    			{
    				"steamid": "76561198137607247",
    				"relationship": "friend",
    				"friend_since": 1412004765
    			},
    			{
    				"steamid": "76561198143001321",
    				"relationship": "friend",
    				"friend_since": 1411898366
    			}
    		]
    
    	}
    }

    anyone want to help?

    Plugin Author Miled

    (@miled)

    first, i advise against querying wsl tables and especially wordpress usermeta, as those can change without notice (ex 2.1.6 and 2.2.2 ain’t compatible in that sense).

    it’s better to create an new function in wsl.user.data.php, and submit it to the project on github. that way you can be sure it will be kept maintained for future wsl versions, at least for a little while.

    now about steam, i think you already have solved the hard part.

    for wsl 2.1.6 you may do something like this :

    add_action( 'wsl_hook_process_login_before_redirect', 'wsl_import_steam_user_contacts_and_autofriend', 10, 3 );
    
    function wsl_import_steam_user_contacts_and_autofriend( $user_id, $provider, $hybridauth_user_profile )
    {
    	global $wpdb;
    
    	$steam_api_key = '';
    	$steam_uid_64  = $hybridauth_user_profile->identifier;
    
    	$data = "https://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=$steam_api_key&steamid=$steam_uid_64&relationship=friend";
    	$data = file_get_contents($data);
    	$data = json_decode($data);
    
    	$user_contacts = ( $data and isset( $data->friendslist ) and isset( $data->friendslist->friends ) ) ? $data->friendslist->friends : array(); 
    
    	foreach( $user_contacts as $contact )
    	{
    		$wpdb->insert(
    			"{$wpdb->prefix}wsluserscontacts",
    				array(
    					"user_id"     => $user_id,
    					"provider"    => $provider,
    					"identifier"  => $contact->steamid,
    					"profile_url" => "https://steamcommunity.com/profiles/" . $contact->steamid
    				)
    			);
    	}
    
    	$sql = "SELECT DISTINCT user_id FROM {$wpdb->base_prefix}wslusersprofiles WHERE provider = 'Steam' AND identifier IN ( SELECT identifier FROM {$wpdb->prefix}wsluserscontacts WHERE provider = 'Steam' AND user_id = '$user_id' )";
    	$contacts_wp_ids = $wpdb->get_results( $sql );
    
    	// that's it.. now we have the contacts wp ids. do like you did with facebook
    }

    obviously, i didn’t test this function so there might be errors. but this the idea.

    Thread Starter maddogmcewan

    (@maddogmcewan)

    aaah tx @miled – will give this a go – let you know – many thanks indeed

    Thread Starter maddogmcewan

    (@maddogmcewan)

    yeppo !!! worked like a charm

    i just had to change

    $steam_uid_64 = $hybridauth_user_profile->identifier;

    to

    $steam_uid_64 = str_replace("https://steamcommunity.com/openid/id/", "", $steam_uid_64);

    will do the buddypress friend thing now and let you know

    It was not working for bp 2.2.1.

    Did anyone have code to auto connect friends from facebook?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Here is code for function to auto befriend BP friends if they exis on blog and t’ is closed to new replies.