Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have created a php page called "test.php" and uploaded this file to the root folder of my wordpress installation.

This file contains only this:

<?php if ( is_user_logged_in() ) { blah..... }  ?>

I need to check if user is logged in and if so, get some details.

So what I need to know is what wp file(s) I need to include in my php file to be able to get the results of this function and also I prob need to check on an id, username.

share|improve this question
add comment

1 Answer

Adding the following code to the top of the PHP file will give you access to the Wordpress functions and global variables.

<?php include_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php' );

You should then be able to run normal Wordpress functions to determine whether or not the user is logged in:

<?php 
global $user_ID; 
get_currentuserinfo();
if ($user_ID) {
    // Do Something 
}
?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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