The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Login to WordPress with Facebook via open graph api (1 post)

  1. David C
    Posted 5 years ago #

    Hi all-

    I've been trying to figure out how to login a WordPress user after validating their login via Facebook.

    I got the Facebook validation part working which sets the cookie and I can read the values fine but just can't figure out how to login the user into WordPress without their password.

    I've dug through many Facebook WP plugins to try and find an answer but they all use the old api.

    Here's how it works: User clicks the FB login button on the wp-login.php page. They login to FB and then the WordPress login page reloads and executes the code below.

    $fbuid = $facebook->getUser(); // gets the FB user id
    $wp_user_id = $wpdb->get_var("SELECT user_id FROM $wpdb->usermeta WHERE meta_value = '$fbuid' AND meta_key = 'facebook_uid' LIMIT 1" );
    if ($wp_user_id) {
        // must be an existing user so let's auto log them in
        $user = get_userdata($wp_user_id);
        require_once(ABSPATH . 'wp-blog-header.php');
        do_action('wp_login', $user->user_login);
    } else {
        // no user found 

    This part doesn't work for some reason:

    `require_once(ABSPATH . 'wp-blog-header.php');
    do_action('wp_login', $user->user_login);`

    Does anyone have experience with the new Facebook open graph api or have the minimum code to automatically login a WP user with just their user id and/or username?

    Much appreciated!


Topic Closed

This topic has been closed to new replies.

About this Topic