Support » Plugin: Add Link to Facebook » automatically login after facebook registration

  • Resolved Peidong Hu


    Current registration won’t automatically login, add the following code in function static function Facebook_registration() will do the work, (after this piece of code,
    // Redirect
    if ($user_ID) {
    update_user_meta($user_ID, c_al2fb_meta_facebook_id, $me->id);
    $url = get_user_meta($user_ID, c_al2fb_meta_reg_success, true);
    if (empty($url))
    //phu fix bug of multisite wrong meta facebook id
    $c_al2fb_meta_facebook_id = c_al2fb_meta_facebook_id;

    if (is_multisite()) {
    global $blog_id;
    $c_al2fb_meta_facebook_id = “blog_”.$blog_id.”_”.$c_al2fb_meta_facebook_id;

    // Workaround if no e-mail present
    if (!empty($me) && empty($me->email)) {
    $users = get_users(array(
    ‘meta_key’ => $c_al2fb_meta_facebook_id,
    ‘meta_value’ => $me->id
    if (count($users) == 0) {
    $regurl = get_user_meta($_REQUEST[‘user’], c_al2fb_meta_login_regurl, true);
    if (!empty($regurl))
    else if (count($users) == 1)
    $me->email = $users[0]->user_email;

    // Check Facebook user
    if (!empty($me) && !empty($me->id)) {
    // Find user by Facebook ID
    $users = get_users(array(
    ‘meta_key’ => $c_al2fb_meta_facebook_id,
    ‘meta_value’ => $me->id

    // Check if found one
    if (count($users) == 1) {
    // Try to login
    $user = WPAL2Int::Login_by_email($users[0]->user_email, true);

    // Check login
    if ($user) {
    // Persist token
    update_user_meta($user->ID, c_al2fb_meta_facebook_token, $_REQUEST[‘token’]);
    update_user_meta($user->ID, c_al2fb_meta_facebook_token_time, time());

    // Redirect
    $self = (is_ssl() ? ‘https://’ : ‘http://’) . $_SERVER[‘HTTP_HOST’] . $_REQUEST[‘uri’];
    $redir = get_user_meta($_REQUEST[‘user’], c_al2fb_meta_login_redir, true);
    $url = $redir ? $redir : $self;
    } else {
    $url = get_home_url();

Viewing 7 replies - 1 through 7 (of 7 total)
  • This should not be necessary, look in add-link-to-facebook.php and you’ll see the meta names for multi-sites are filtered.

    marcel, r u talking about the meta name issue or auto login issue?

    I was talking about the meta name issue.
    Logging in after registration is not desirable, since the Facebook session timeout is quite short.

    As I tested, Facebook session WON’T timeout after even 7 hours. How come do you say it’s short?

    Did you test with an access token acquired using the Facebook Client-side Login flow? These tokens are short living for security reasons, in contrary to tokens acquired with the Facebook Server-side Login flow.

    oh. I c. you were taking about the auth token. However, I was testing it from a end user view point. The user account registered through Add Link to Facebook plugin will keeps alive on both sites for long time actually even the auth access token is short-live.

    And it’s really user-friendly with this feature.

    You can try on which has been modified to directly Login after facebook-registeration work flow.


    Send me a patch based on the latest version through this contact form and I will include this in the next release.

    How to make a patch:
    – install subversion
    – svn co
    – make/test your changes
    – svn diff

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘automatically login after facebook registration’ is closed to new replies.