WordPress.org

Ready to get started?Download WordPress

Forums

Facebook Connect
Bug (76 posts)

  1. rwestergren05
    Member
    Posted 3 years ago #

    Extremely difficult to submit bugs around here, despite it being designed to be "simple." Could not find your listing in trac.

    Nevertheless, line 78 of your plugin should be
    if ( !is_user_logged_in() || !$cookie) { ?>

    as users who ARE authenticated, but not registered should still be provided the link to login and allow FB access.

    Overall, fantastic plugin. Thanks for the contribution!

    http://wordpress.org/extend/plugins/wp-facebook-connect/

  2. jelpesao
    Member
    Posted 3 years ago #

    I want to try the plugin but got a few errors for example once activated and if I am already register it tells me it cannot find my email. The line you change is it the one that says:
    <span class="fb_button_text">
    Change it to:
    if ( !is_user_logged_in() || !$cookie) { ?>

    Sorry not good at all in coding.

  3. rwestergren05
    Member
    Posted 3 years ago #

    You may have set your Facebook privacy settings in a way that doesn't share your email account.

  4. valentinas
    Member
    Plugin Author

    Posted 3 years ago #

    I've just uploaded version 1.1 to svn. Should fix this issue, and also lots of other improvements. Please upgrade and let me know what do you think about new version. Should be much more robust.

  5. jelpesao
    Member
    Posted 3 years ago #

    Looks like the issue is if I am already authenticated to facebook I get the following error "Error: failed to get your email from Facebook!" I went to facebook and logout and I was able to get back into my website and then click on connect. version 1.1 gave me the same error.

  6. Felzor
    Member
    Posted 3 years ago #

    Nice. I just installed this plug-in today for my buddy press site. I was able to connect with my Facebook email and password and it even created a new user in the backend using my Facebook name. Only problem is the avatar didn't sync with Facebook. It would be great if the Avatar (and other info like location and birthday) synced. Is this a theme related issue, or just not coded into the plug-in? Thanks for this great plug-in!

  7. valentinas
    Member
    Plugin Author

    Posted 3 years ago #

    So far its very vanilla and will only get Name and Last name from FB. There are hooks to add more information if you are a programmer. If not - you can watch this plugin and update when new version is available. We will extend it for BuddyPress to include all that additional information. I think this will happen some time in Jan 2011.

  8. donatien
    Member
    Posted 3 years ago #

    Seems to work here - except for an annoying thing - after a user logged in - the page went blank. This is due to wp_get_referer() returning false. Changed the redirect from assuming wp_get_referer() returns something to:

    if (wp_get_referer()) {
    	wp_redirect(wp_get_referer());
    } else {
    	wp_redirect( $_SERVER['REQUEST_URI'] );
    }

    That seemed to fix it for me.

  9. valentinas
    Member
    Plugin Author

    Posted 3 years ago #

    Thanks, donatien, will implement that to next version!

  10. donatien
    Member
    Posted 3 years ago #

    Good stuff. I tried to find a better function for fetching the current page, but the best candidate seemed to be get_permalink(), but that only works for posts. In a note named "Link to current page" on http://codex.wordpress.org/Function_Reference/get_permalink they use the same code, so it seems right.

  11. donatien
    Member
    Posted 3 years ago #

    Another thing, please remove the style declaration in the widget and replace with a class or id for styling. The text-align: center; just about drove me nuts :-)

  12. valentinas
    Member
    Plugin Author

    Posted 3 years ago #

    Sorry for that :) Will be removed in next tag.

  13. markhuot
    Member
    Posted 3 years ago #

    You mention grabbing it from SVN, is that public and something you can share? I have a version that seems to work great if you're already logged in but fails if you're not. If you're not logged in it just refreshes the login form (in the popup window).

    Thanks!

  14. valentinas
    Member
    Plugin Author

    Posted 3 years ago #

    Newest development version available at http://plugins.svn.wordpress.org/wp-facebook-connect/trunk/
    Seems more like fb issue. Look for any script errors.

  15. markhuot
    Member
    Posted 3 years ago #

    Thanks Valentinas, I updated just to be safe, but it seems to have been an issue with Safari's Private Browsing refusing to reset/release/create cookies.

  16. valentinas
    Member
    Plugin Author

    Posted 3 years ago #

    Just tested - works for me. To make it clear: cookies are required for FB connect to work (not only for this plugin, but for fb connect API in general). So if cookies are disabled facebook connect will not work.

    By the way, are you on Mac, Windows or Linux? Im on Windows, so things can be a little different on other OS.

  17. markhuot
    Member
    Posted 3 years ago #

    Valentinas, you're absolutely right. I'm pretty sure this is an issue in the latest version of Safari on OS X 10.6.5. When you sign into a service with Private Browsing on, then later disable it, it won't let you sign out (or for that matter back in if your session times out). Nothing to do with your plugin, which is awesome by the way. I can't wait to see how it evolves (hopefully with avatar support ;-).

  18. valentinas
    Member
    Plugin Author

    Posted 3 years ago #

    markhuot, I just tagged new version (1.2, should show up online soon) with avatar support, check it out!

  19. markhuot
    Member
    Posted 3 years ago #

    Woo! Just tested it and it works great so far. Thanks Valentinas!

  20. Felzor
    Member
    Posted 3 years ago #

    Thanks for the speedy updates. I tested the new version on my BuddyPress site but unfortunately the Avatar still didn't transfer over. The Logout seemed to work correctly this time, but the avatar didn't make the cut. Are there any settings in Facebook that must first be changed by the user before permission is granted to transfer the avatar? Any other ideas why this would work for markhuot and not me? Theme specific? Thanks.

  21. valentinas
    Member
    Plugin Author

    Posted 3 years ago #

    Felzor, avatars only works for regular WP, but not for BP (for now). This is because BP usually has bigger avatars (like in profile page you usually have 100x200 or something) and i haven't found a way to fetch them from FB nicely. If you are interested in testing I could make a beta version with BP avatars, it's pretty easy, about 20 lines of code.

  22. Felzor
    Member
    Posted 3 years ago #

    Valentinas: I would be grateful if you could make a beta version with BP avatars. I'd be happy to test out this feature after the Holidays. As long as I can deactivate the plug-in if things don't work (i.e. it won't crash the site), since I don't have backend server access, I don't mind being your guinea pig in this case. Overall, wonderful work on your part with this plug-in and looking forward to watching it evolve.

  23. zoran100
    Member
    Posted 3 years ago #

    First of valentines, thank you for this plugin. I have latest versions of wordpress and buddypress and just installed your plugin and initially it worked but...I run with couple of errors that I think are all related to the same issue:

    Profile Settings Not AvailableUser who’s login for the 1st time with facebook can not ever access his profile settings. User who makes his account via normal buddypress registration form is able to do so.

    Password Can Not Be ChangedFacebook user can not change his password. Actually he can, but then the new password does not work. From the moment he 1st time use facebook login, he will only be able to login via facebook. Even users who 1st created account using buddypress registration will not be able to successfully change passwords once they login via facebook.

    Add Photo Redirection ErrorI use BP-Album+ for photo album. Users who login with facebook, once they add photo are rederected to site main page in the stead back to album.

    There could be more errors related to the this. I assumed that all of them has something to do with the way your plugin creates names from facebook accounts. WordPress ( thus buddypress ) does not allow capital letters and spaces for account names. Your plugin does. Your plugin should make sure that facebook names are adjusted to wordpress standard: Steve Richardson should be renamed steverichardson before his account is created in word/buddypress.

    I am not sure that’s the problem and solution, this was just my wild guess and i decided to let you know. Again thanks for the plugin but right now I can not use it on my live site due to above. I also don’t know to code PHP so this was the best I could help you with. Looking forward to hear from you and to see the updated version clear from this errors. Also, like she said above, it will be great to fetch users avatars but that’s way down the road, I guess.

    Regards,
    Zoran

  24. valentinas
    Member
    Plugin Author

    Posted 3 years ago #

    Thanks for feedback, zoran100. It's very valuable, since the bug related to account names is critical. I was naughty this year and took raw FB name for a user name, when i should've sanitized it first. This will be done in next version which will be released in few days.

    Avatars: showstopper here is Facebook (or their lack of documentation on avatars). I will include avatars in next beta release, so you could see for yourself, that will explain better than me.

    Password, profile settings, other stuff is probably related to the username issue. I will let you know once this fixed, so you could test it out.

  25. zoran100
    Member
    Posted 3 years ago #

    Glad I could point to it. I value people who are share their hard work. I wish I could be of more help but like I said, I don’t know how to code in PHP :(

    I’m also almost sure that all other problems are related to that same issue and I can’t wait to test your new version.

    If you wish to go fancy about that, you can give the admin couple of options on how the names will be pulled from the facebook into buddypress. For example 1st option will be that first and last name from facebook becomes one word and that word becomes account name in buddypress. 2nd option that first name from facebook becomes account name and last name from facebook becomes profile name...and vice versa.

    I think that will be of help for different people who setup different web sites on different ways and with different themas but that could be perhaps something for your next version I guess.

    For now, as long as your plugin starts working, I am sure many people will have a great usage for it. Avatar can come even later. If you want me and others to test, just let us know when you post that beta...All the best and Merry Christmas!

  26. zoran100
    Member
    Posted 3 years ago #

    Just one note, maybe important. I just realized that Capital letters are no problem for wordpress...you can enter them anyway if you manually add new users from your admin panel. Why they prohibited new users from doing that on registration is beyond my understanding because all people names start with capital letters. I will se if I can manage to correct that on my site. Anyway, so, you don’t have to change facebook capital letters in your plugin, what messes up wordpress and buddypress are only blank spaces.

  27. valentinas
    Member
    Plugin Author

    Posted 3 years ago #

    zoran100, turns out that username was good (i did sanitized it before passing to insert_user(); ), but $user->nicename was with a space, so buddypress freaked out. I already fixed that in trunk, will include in next release (next version coming out today or tomorrow)

  28. valentinas
    Member
    Plugin Author

    Posted 3 years ago #

    zoran100, 1.3 is out and the nicename bug is fixed. If you could try it and let me know if it fixes all the problems you've been experiencing, that would be great. Avatars for buddypress coming soon.

  29. zoran100
    Member
    Posted 3 years ago #

    Hello Valentinas, just got the message...I am testing right now will let you know results asap

  30. zoran100
    Member
    Posted 3 years ago #

    OK...It took some time but here are results:

    1st yes! it works! Great job fixing the bug. All errors related to that bug are gone! But there are 2 issues I found that you should know about:

    One: this one is easy. Just like donatien I run into white blank page after upgrade so I changed functions.php to this:

    <?php
    /**
    * facebook_header()
    *
    * @package fb-connect
    * @since 1.0
    *
    * javascript for header
    * taken from here: http://developers.facebook.com/docs/guides/web
    *
    */
    function facebook_header(){
    ?>
    <script src="http://connect.facebook.net/en_US/all.js"></script>
    <script>
    jQuery(document).ready(function(){
    FB.init({appId: '<?php echo FACEBOOK_APP_ID; ?>', status: true,
    cookie: true, xfbml: true});
    FB.Event.subscribe('auth.sessionChange', function(response) {
    if (response.session) {
    jQuery('body').html('');
    window.location.href=window.location.href;
    } else {
    jQuery('body').html('');
    window.location.href=window.location.href;
    }
    });
    });
    </script>
    <?php
    }

    /**
    * fb_logout_url()
    *
    * @package fb-connect
    * @since 1.0
    *
    * logout url for people who are logged in with FB
    *
    */
    function fb_logout_url($url){
    $cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);
    if($cookie)
    return "javascript:FB.logout(function(){location.href='" . $url . "'})";
    else
    return $url;
    }

    /**
    * fb_footer()
    *
    * @package fb-connect
    * @since 1.0
    *
    * markup for footer
    * taken from here: http://developers.facebook.com/docs/guides/web
    *
    */
    function fb_footer(){
    ?> <div id="fb-root"></div> <?php
    }

    /**
    * get_facebook_cookie()
    *
    * @package fb-connect
    * @since 1.0
    *
    * gets facebook cookie (yummy thing that is created when user is authenticated with FB in your website)
    * taken from here: http://developers.facebook.com/docs/guides/web
    *
    * @return array|null
    *
    */
    function get_facebook_cookie($app_id, $application_secret) {
    $args = array();
    parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
    ksort($args);
    $payload = '';
    foreach ($args as $key => $value) {
    if ($key != 'sig') {
    $payload .= $key . '=' . $value;
    }
    }
    if (md5($payload . $application_secret) != $args['sig']) {
    return null;
    }
    return $args;
    }

    /**
    * fb_login_user()
    *
    * @package fb-connect
    * @since 1.0
    *
    * this is the main function that performs the login or user creation process
    *
    * @return true
    */
    function fb_login_user(){
    global $wpdb;
    //@todo: investigate: does this gets included doing regular request?
    require_once( ABSPATH . 'wp-includes/registration.php' );
    //mmmm, cookie
    $cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);
    //if we have cookie, then try to get user data
    if ($cookie) {
    //get user data
    $user = json_decode(@file_get_contents('https://graph.facebook.com/me?access_token=' . $cookie['access_token']));
    //if user data is empty, then nothing will happen
    if( !empty($user) ){
    //this should never happen, since email address is required to register in FB
    //I put it here just in case of API changes or some other disaster, like wrong API key or secret
    if( !isset($user->email) || empty($user->email) ){
    do_action('fb_connect_get_email_error');
    //do not use wp_die here, because it adds styles which can mess up the whole looks of the site
    die("Error: failed to get your email from Facebook!");
    }

    //if user is logged in, then we just need to associate FB account with WordPress account
    if( is_user_logged_in() ){
    global $current_user;
    get_currentuserinfo();
    $fb_uid = get_user_meta($current_user->ID, 'fb_uid', true);

    if($fb_uid == $user->id)
    return true;

    if( $user->email == $current_user->user_email ) {
    //if FB email is the same as WP email we don't need to do anything.
    do_action('fb_connect_wp_fb_same_email');
    $fb_uid = get_user_meta($current_user->ID, 'fb_uid', true);
    if( !$fb_uid )
    update_user_meta( $current_user->ID, 'fb_uid', $user->id );
    return true;
    } else {
    //else we need to set fb_uid in user meta, this will be used to identify this user
    do_action('fb_connect_wp_fb_different_email');
    $fb_uid = get_user_meta($current_user->ID, 'fb_uid', true);
    if( !$fb_uid )
    update_user_meta( $current_user->ID, 'fb_uid', $user->id );
    $fb_email = get_user_meta($current_user->ID, 'fb_email', true);
    if( !$fb_uid )
    update_user_meta( $current_user->ID, 'fb_email', $user->email );
    //that's it, we don't need to do anything else, because the user is already logged in.
    return true;
    }
    }else{
    //check if user has account in the website. get id
    $existing_user = $wpdb->get_var( 'SELECT DISTINCT u.ID FROM ' . $wpdb->users . ' u JOIN ' . $wpdb->usermeta . ' m ON u.ID = m.user_id WHERE (m.meta_key = "fb_uid" AND m.meta_value = "' . $user->id . '" ) OR user_email = "' . $user->email . '" OR (m.meta_key = "fb_email" AND m.meta_value = "' . $user->email . '" ) LIMIT 1 ' );
    //if the user exists - set cookie, do wp_login, redirect and exit
    if( $existing_user > 0 ){
    $fb_uid = get_user_meta($existing_user, 'fb_uid', true);
    if( !$fb_uid )
    update_user_meta( $new_user, 'fb_uid', $user->id );
    $user_info = get_userdata($existing_user);
    do_action('fb_connect_fb_same_email');
    wp_set_auth_cookie($existing_user, true, false);
    do_action('wp_login', $user_info->user_login);
    if (wp_get_referer()) {
    wp_redirect(wp_get_referer());
    } else {
    wp_redirect( $_SERVER['REQUEST_URI'] );
    }
    exit();
    //if user don't exist - create one and do all the same stuff: cookie, wp_login, redirect, exit
    } else {
    do_action('fb_connect_fb_new_email');
    //sanitize username
    $username = sanitize_user($user->first_name, true);

    //check if username is taken
    //if so - add something in the end and check again
    $i='';
    while(username_exists($username . $i)){
    $i=absint($i);
    $i++;
    }

    //this will be new user login name
    $username = $username . $i;

    //put everything in nice array
    $userdata = array(
    'user_pass' => wp_generate_password(),
    'user_login' => $username,
    'user_nicename' => $username,
    'user_email' => $user->email,
    'display_name' => $user->name,
    'nickname' => $username,
    'first_name' => $user->first_name,
    'last_name' => $user->last_name,
    'role' => 'subscriber'
    );
    $userdata = apply_filters('fb_connect_new_userdata', $userdata, $user);
    //create new user
    $new_user = absint(wp_insert_user($userdata));
    do_action('fb_connect_new_user', $new_user);
    //if user created succesfully - log in and reload
    if( $new_user > 0 ){
    update_user_meta( $new_user, 'fb_uid', $user->id );
    $user_info = get_userdata($new_user);
    wp_set_auth_cookie($new_user, true, false);
    do_action('wp_login', $user_info->user_login);
    wp_redirect(wp_get_referer());
    exit();
    } else {
    wp_die('Facebook Connect: Error creating new user!');
    }
    }
    }
    }
    }
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic