[resolved] cannot use is_user_logged_in() outside of plugins (2 posts)

  1. randomparanoid
    Posted 2 years ago #

    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?

  2. randomparanoid
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic