Reputation: 5255
I referer to this code which I'm trying to use to log a facebook user as a wordpress user. However the while the user is registered the is_user_logged_in() would repeatedly state false. Can anyone give me some insight as to what I might be doing wrong?
Upvotes: 0
Views: 275
Reputation: 30217
I wrote a wordpress loginas.php page, hence, a really big security hole :) :
require_once(dirname(__FILE__) . '/wp-load.php');
function auto_login( $username ) {
// log in automatically
$user = get_userdatabylogin( $username );
$user_id = $user->ID;
wp_set_current_user( $user_id, $user_login );
wp_set_auth_cookie( $user_id );
}
if (!is_user_logged_in()) {
echo "Logging in as: ".$_GET['username'];
auto_login($_GET['username']);
}
else
echo "You are already logged in.";
And, after I delete all cookies, it is working very well. So, I suppose you could have a problem with something that is executed before your code.
Actually I'm still unable to figure out what's happening in your code, could you try to change priority of execution of your init
hook and move at very first position.
Please pay attention, in order to execute your correctly your programmatically authentication, WordPress requests should be always done on same domain where the cookie is created.
Upvotes: 2
Reputation: 2136
Why dont you give this plugin a shot http://ottopress.com/wordpress-plugins/simple-facebook-connect/
Ive used this and it works! It has a feature that would let a user to login into your site using their fb account.
Upvotes: 1
Reputation: 506
Please try This,
First you have to create a new application in facebook. Here you have enter the your domain name of site and get the below two value.
1) Application ID
2) Secrate ID
And put below code within your function connect_to_facebook()
:
define('APP_ID', 'Copy Facebook Application ID');
define('APP_SECRET', 'Copy Facebook Secrate ID');
Upvotes: 0