• Resolved mrizwanghuman

    (@mrizwanghuman)


    Hi Heateor Team,

    Can I add extra permission to get user location in Facebook login and added to wordpress database?

    Thanks

    Muhammad

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Heateor Support

    (@heateor)

    Hi,

    Yes, but it would require custom coding.
    You need to use the desired scopes (corresponding to the profile data you want to fetch) in “wp-content/plugins/super-socializer/js/front/social_login/facebook.js” file. To preserve your custom changes, you can dequeue the original facebook.js file and enqueue the one with custom changes.
    After that, you can use the following filter defined at line number 489 in “wp-content/plugins/super-socializer/inc/social_login.php” file, to pass the new profile fields requested from user in $temp array:

    apply_filters('the_champ_hook_format_profile_data', $temp, $profileData, $provider);

    Finally, you need to use following action defined at line number 284 in the same file social_login.php to save the new profile fields in user_meta on new user creation:

    do_action('the_champ_user_successfully_created', $userId, $userdata, $profileData);

    You can display this saved information from usermeta, wherever you want to show to user.

    Thread Starter mrizwanghuman

    (@mrizwanghuman)

    Hi Team,

    Thanks for your quick reply. I submitted my app for facebook review so I could get user location. I will try your suggestion and update you.
    Thanks

    Plugin Author Heateor Support

    (@heateor)

    Sure.

    Thread Starter mrizwanghuman

    (@mrizwanghuman)

    Hi Team,
    I just got permission from Facebook to use the user location.

    I edited the plugin directly by adding

    $temp[‘location’] = isset($temp[‘location’][0]) && ctype_upper($temp[‘location’][0]) ? ucfirst(sanitize_user($temp[‘location’], true)) : sanitize_user($temp[‘location’], true);
    on line 495, and then on line 248 i added if(!empty($profileData[‘location’])){
    update_user_meta($userId, ‘thechamp_location’, $profileData[‘location’]);
    }
    I also added a line on 227
    ‘location’ => $profileData[‘location’][‘name’].

    I am not seeing any field with location.

    I am getting user $current_user = wp_get_current_user();
    and then displaying echo ‘

    ';
      var_dump( $current_user);
      echo '

    ‘;

    Plugin Author Heateor Support

    (@heateor)

    Try following:

    /**
     * Format user profile data (check for location)
     */
    function heateor_ss_format_profile_data( $temp, $profileData, $provider ) {
    	// location
            $temp['location'] = isset( $profileData['location'] ) ? sanitize_text_field( $profileData['location'] ) : '';
    	return $temp;
    }
    add_filter( 'the_champ_hook_format_profile_data', 'heateor_ss_format_profile_data', 10, 3 );
    
    /**
     * Save location on new user registration
     */
    function heateor_ss_save_location( $userId, $userdata, $profileData ) {
    	if ( isset( $profileData['location'] ) ) {
    		update_user_meta( $userId, 'heateor_ss_user_location', $profileData['location'] );
    	}
    }
    add_action( 'the_champ_user_successfully_created', 'heateor_ss_save_location', 10, 3 );

    P.S.: You should first try logging the profile data returned from Facebook, in facebook.js file to see how location field is being returned. We are assuming (in the code posted above) it is being returned as string.

    Thank you so much for your help. I followed your way. I can see heateor_ss_save_location user meta but it’s blank. I notice that I am not getting location from facebook,/**/ FB.__globalCallbacks.f2bba0d155a8d74({“id”:”1616480775048686″,”name”:”Muhammad Rizwan”,”link”:”https:\/\/www.facebook.com\/app_scoped_user_id\/1616480775048686\/”,”email”:”iamfine76\u0040hotmail.com”,”first_name”:”Muhammad”,”last_name”:”Rizwan”});
    I have added location field function theChampFBLoginUser(){FB.api(“/me?fields=id,name,about,link,email,first_name,last_name,location” me?/wp-content/plugins/super-socializer/js/front/social_login/facebook.js.
    Do I suppose to add somewhere else aswell?

    I really appreciate your patience and reply.

    • This reply was modified 7 years, 2 months ago by mrizwantech.
    Plugin Author Heateor Support

    (@heateor)

    Did you included the appropriate scope in facebook.js file?
    You need to change {scope:theChampFacebookScope} in facebook.js to {scope:theChampFacebookScope+",user_location"}

    Yes I did, On facebook login popup its shows, your public profile, email address and current city. but I am not getting location back.

    Plugin Author Heateor Support

    (@heateor)

    Might be related to privacy of the Facebook account you are trying to login with. Make sure that location field of that Facebook account is public.

    I tried with different accounts.Do I need to change something in the combined.js file? I used developer facbook tools and I was able to get location data.
    {
    “id”: “964524616910975”,
    “email”: “iamfine76@hotmail.com”,
    “name”: “Muhammad Rizwan”,
    “location”: {
    “id”: “112635242084973”,
    “name”: “Danbury, Connecticut”
    }
    }

    Plugin Author Heateor Support

    (@heateor)

    If you have enabled Load all Javascript files in single file option at Super Socializer > General Options page in admin area, you need to make changes in facebook.js code in combined.js file.
    And according to the profile data you have posted above, you need to change $temp['location'] = isset( $profileData['location'] ) ? sanitize_text_field( $profileData['location'] ) : ''; to $temp['location'] = isset( $profileData['location']['name'] ) ? sanitize_text_field( $profileData['location']['name'] ) : '';

    you were right. It’s working now. Thank you so much. You are Awesome

    Plugin Author Heateor Support

    (@heateor)

    Cool 🙂
    You’re welcome.

    Hi, sorry to wake a dead thread here… But I’m stuck on the same idea.

    I’m attempting to retrieve some extra data from linkedin (location) and add it to the user-profile.

    I’ve added the following to my functions:

    /**
     * Format user profile data (check for location)
     */
    function heateor_ss_format_profile_data( $temp, $profileData, $provider ) {
      // echo'<hr>';var_dump([$temp, $profileData, $provider]);exit;
      // location
      $temp['location'] = isset( $profileData['location']['name'] ) ? sanitize_text_field( $profileData['location']['name'] ) : '';
      return $temp;
    }
    add_filter( 'the_champ_hook_format_profile_data', 'heateor_ss_format_profile_data', 10, 3 );
    
    /**
     * Save location on new user registration
     */
    function heateor_ss_save_location( $userId, $userdata, $profileData ) {
      if ( isset( $profileData['location'] ) ) {
        update_user_meta( $userId, 'heateor_ss_user_location', $profileData['location'] );
      }
    }
    add_action( 'the_champ_user_successfully_created', 'heateor_ss_save_location', 10, 3 );

    And the edited theChampLinkedInOnLoad to request location (which it returns)

    function theChampLinkedInOnLoad() {
        theChampDisplayLoginIcon(document, ["theChampLinkedinButton", "theChampLinkedinLogin"])
    }
    typeof IN != "undefined" && IN.Event.on(IN, "auth", function() {
        theChampLoadingIcon();
        IN.API.Profile("me").fields(["email-address", "id", "picture-urls::(original)", "first-name", "last-name", "headline", "picture-url", "public-profile-url", "num-connections", "location"]).result(function(e) {
            if (e.values[0].id && e.values[0].id != "") {
                theChampCallAjax(function() {
                    if (heateorMSEnabled == 1) {
                        e.values[0].mc_subscribe = 1;
                    }
                    theChampAjaxUserAuth(e.values[0], "linkedin")
                })
            }
        })
    })

    The problem is that when I apply the filter, the user isn’t registered or logged in.

    I’ve tried adding the following directly to social_login.php but it didn’t seem to help: $temp['location'] = isset( $profileData['location']['name'] ) ? sanitize_text_field( $profileData['location']['name'] ) : '';

    I’ll continue debugging this one, any tips you have on how to debug that section of the plugin… Or links to resources regarding adding & saving additional profile data… Are hugely appreciated.

    And thanks very much for building this, it’s very useful.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Extra facebook permission to user location’ is closed to new replies.