I'm making a login form for my site, and I've this section:

if (is_user_logged_in()) {
    echo 'Hello, ', $user_login, '. <a href="', wp_logout_url(), '" title="Logout">Logout</a>';
} else {

And after loggin in, it returns to the page with no indication of logging in.
I suspect is_user_logged_in() isn'tw orking, but I don't know how to debug this problem.

EDIT: Whenever I do this:

global $current_user;


I always get:

ect(WP_User)#3 (7) { ["data"]=> NULL ["ID"]=> int(0) ["caps"]=> array(0) { } ["cap_key"]=> NULL ["roles"]=> array(0) { } ["allcaps"]=> array(0) { } ["filter"]=> NULL }

No matter if i"ve 'logged' in with the above form.

  • Disable all caching plugins and your browser cache. Does it still happen? – fuxia Jul 18 '12 at 10:49
  • Yeah, I tried deleting the cache. I should mention that I'm trying to implement wordpress into an existing website. So I don't really want to use any plugins or anything. – Adola Jul 18 '12 at 10:52

There's nothing wrong with the function, it's the fact that you aren't actually being logged in!

You say you're making your own login form? Does this post to the standard wp-login.php, or do you handle the request yourself?

Does the path/domain of the form differ from WordPress? If you inspect your cookies, are any being set?

  • I'm using wp_login_form() And as for path/domain, I'm not really sure. I'm using chrome, and according to the debugging profile thing, it suggests: Domain:localhost Path:/ Date:Fri, 10 Aug 2012 11:14:30 GMT Size:70 – Adola Jul 18 '12 at 11:08
  • And for the form, it's stored in: http://localhost/newgameplus/TEST/scripts/php/testWP.php And the wordpress install is: http://localhost/newgameplus/wordpress/ – Adola Jul 18 '12 at 11:09
  • 1
    I think that's the issue - WordPress will set a cookie with the path /newgameplus/wordpress/, which won't be read under /newgameplus/TEST/scripts/php/testWP.php. Try define( 'COOKIEPATH', '/' ); in your wp-config.php – TheDeadMedic Jul 18 '12 at 11:53
  • By the way, I'd highly recommend using virtual hosts to develop on: wordpress.stackexchange.com/questions/32331/… – TheDeadMedic Jul 18 '12 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.