Strange behaviour of is_user_logged_in()

Question

I have an issue where is_user_logged_in() appears to alternate between being true and false. Here’s my code:

.htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]

RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^wp-content/uploads/(.*)$ file-access.php?file=$1 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

file-access.php:

require_once('wp-load.php');

if ( is_user_logged_in() ) {
    // User is logged in, proceed.
} else {
    // User is a guest, block.
}

I’ve verified the alternating status using some error logging in the file-access.php conditionals.

Do I need to call something other than wp-load.php perhaps? Just seems strange to me that it alternates between true and false, rather than always being false…

0
, , warm__tape 9 months 0 Answers 58 views 0

Leave an answer