Support » Plugins » cannot use is_user_logged_in() outside of plugins

  • Resolved randomparanoid


    On my old webhost, wordpress was in a subdirectory, and everything worked fine. On my new webhost (hostgator), wordpress is installed in the root directory, and now this code outputs bool(false) even when I am signed in when placed in a php file, also in the root directory.

    require "wp-blog-header.php";
    var_dump( is_user_logged_in());

    What is different? What is going on?

Viewing 1 replies (of 1 total)
  • I discovered what the issue is. The is_user_logged_in() function checks cookies. WordPress redirected request to wordpress into http://www.the_domain, whereas to access my code I was doing the_domain, without the www. Because there was no www, the cookie origins did not match.

Viewing 1 replies (of 1 total)
  • The topic ‘cannot use is_user_logged_in() outside of plugins’ is closed to new replies.