Creating the WP cookies is painful and difficult.
A better way would be to create a WordPress plugin that recognizes the authentication from your other site’s cookie, if you have one.
This is actually quite easy to do, really. The authenticate filter makes it simple:
add_filter('authenticate','custom_login_check', 100);
function custom_login_check($user) {
// check if user is already logged in and just return if he is
if ( is_a($user, 'WP_User') ) { return $user; }
// do whatever you have to do to check for authentication here
// in the end, you need to determine which WP user is logged in
// then return a WP_user object.
// example: say you figured out that it was user number 123
$user = new WP_User(123);
// always return the $user from the function argument
// even if you didn't change it
return $user;
}
That’s all there is to it, really. How you implement the authentication check is up to you.
Hey Otto, thank you very much for helping me out. You make it seem so easy 😉 Would you happen to know if there is a plugin that already does this? I have seen a couple of plugins that deal with authentication, but I am never sure if they handle it in the manner in which I need it.
If you don’t mind, I am going to keep this thread open. This will actually be a teammate of mine’s responsibility (I am a front-end developer, so this kind of programming gets over my head), and he might have to ask you a question if you wouldn’t mind.
Thanks again for your wisdom and assistance. Have a good day.
Justin
Sure, my own Simple Facebook Connect and Simple Twitter Connect plugins use this same basic method to let you login using Facebook or Twitter credentials.
Awesome, thank you Otto! We will look into this very soon. You’re a life-saver.
Justin
Hi Justin,
I have exactly the same scenario as you described. Were you able to find a solution to this ? If so please let me know. Will really help me.
Thanks and regards,
Vikalp Jain
Hey Vikalp, we have not started production yet on this portion of development. The developers on my team feel it is very doable, but I will report back once it is done. Talk to you soon.
Justin
Thanks for quick response Justin. Look forward to hearing from you soon.
Thanks and regards,
Vikalp Jain