I need to be able to tell if an admin is logged in ouside of the loop.
This is needed for some php files that are part of a WP site but do not use require( '../wp-load.php );
What I need to do is keep the Google Analytics tracker JS from firing for logged in admins, but track everyone else.
How do I find out if an admin is logged in outside of the loop? Checking the WP logged in cookie? Or must I use wp-load.php
?
You can use current_user_can() to determine if an admin user is logged and load your Google tracking code using wp_enqueue_script with an if statement in functions.php
Either use wp-load.php (performance taxing) or do the following:
Just read the comments in the code. I tried to describe the entire logic behind it there.
It’s pretty safe and the special Cookie is bound to the IP/User-Agent. With a proper salt you should not have problems unless a very 1337 hacker targets you 🙂 Also it’s a start for you to tweak on.
Regards.
PS: For any other clarifications, don’t hesitate to ask.