Support » Fixing WordPress » Create Authentication Cookie Outside of WordPress

  • Resolved Cerebral ideas


    Question: Is there official documentation on creating an authentication cookie outside of WP?

    Scenario: I am planning on utilizing WP v.3 as a CMS for a company’s support documentation website. This support CMS is going to be a piece of a larger network of sub-sites. My client does not want to force the user to log-in more than once, so on initial login to the main site (non-WP), we want to create an authentication cookie that WP will recognizes and allows the user to continue on to the site without having to re-log in.

    With all that being said, I have search low and high for “official” documentation on how to do this with no avail. Although, I have found pieces throughout the Net that seem like some-what viable options (or hacks), but I would rather use an “official” method to accomplish this.

    Can anyone out there point me in the right direction?


Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator Samuel Wood (Otto)

    (@otto42) Admin

    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.


    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    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.


    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.


    Thanks for quick response Justin. Look forward to hearing from you soon.

    Thanks and regards,
    Vikalp Jain

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Create Authentication Cookie Outside of WordPress’ is closed to new replies.