• I’m making a plugin that accesses the WP database externally (not on the main page or in the loop or anything), and I want it to do a quick check just to see if the user is logged in.

    I tried using “if ($user_ID != ”)” but it looks like $user_ID isn’t defined.

    I tried using the line “global $user_ID” but that didn’t seem to solve the problem. Should I try including something? Or should I use alternate code?

    I briefly tried running my own cookie-check but I failed miserably ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter weasello

    (@weasello)

    The code looks great and I tried it out, but $user_login variable continues to be empty no matter what the login state. I’m not sure if it’s behaving the same as the other thread, because this process does not (currently) include any WP libraries.

    Thread Starter weasello

    (@weasello)

    I might just need to say “include X” to fix this, but I’m not sure what ?? Code I used:

    global $user_login;

    get_currentuserinfo();
    if($user_login) {

    weasello, first I’d suggest reading the whole thread moshu links to. There are several ways of testing on user info that’s mentioned.

    Second, you want to scope $user_ID to global:

    global $user_ID;

    before calling get_currentuserinfo() and using it ($user_ID) in your code.

    Thread Starter weasello

    (@weasello)

    Yep, I read through the whole post, found the above code works best for my needs. I’ve adjusted it to this for maximum testing flexibility:

    global $user_login, $user_ID;
    get_currentuserinfo();
    if($user_ID != ” || $user_login) {

    … Never triggers ??

    Returning to square one, you say you’re doing this in a plugin? What version of WP are you testing it on?

    You can try this bit of code, which is a mod of something I do in a plugin of mine:

    $user_login = $_COOKIE['wordpressuser_' . COOKIEHASH];
    if($user_login) {

    Thread Starter weasello

    (@weasello)

    Yep, I’m making myself a little plugin for this, in WP 1.5.2. That cookie code you posted there is something similar to what I had several hours ago before I abandoned that path, but it is probably the cleanest solution for me. Now that I know you got it to work I should keep hacking at it ??

    Of course, just to be difficult, the code doesn’t work ?? $user_login always returns null. I used an exact cut n paste of the one above. :/

    Thread Starter weasello

    (@weasello)

    OK, I found the problem with that last chunk of code. The cookie is registered as valid only in directory /wordpress/, but the file I’m using is in the root dir of /

    Can I safely change the wordpress cookie to run off of /?

    I am also trying to do a similar check. (ie: If an admin is logged into wordpress, I would like for the admin to be able to access a standalone php file in the plugins folder).

    For the code below to work (to get the COOKIEHASH), what should I include from wp?

    $user_login = $_COOKIE[‘wordpressuser_’ . COOKIEHASH];
    if($user_login) {

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘External logged-in check’ is closed to new replies.