I’m running a site on WP, and it won’t let me access information from the global variable $current_user, after I run get_currentuserinfor().
I have a php file in my theme (not a wordpress-specific file), and in that file, have the following:
<?php
define('WP_USE_THEMES', false);
require('../../../wp-blog-header.php');
print_r ($current_user);
?>
Then, in wp-blog-header, I have the following:
<?php
/**
* Loads the WordPress environment and template.
*
* @package WordPress
*/
if ( !isset($wp_did_header) ) {
$wp_did_header = true;
require_once( dirname(__FILE__) . '/wp-load.php' );
wp();
require_once( ABSPATH . WPINC . '/template-loader.php' );
global $current_user;
get_currentuserinfo();
}
?>
When I try to access my php file in a browser, I get the following:
WP_User Object ( [data] => [ID] => 0 [id] => 0 [caps] => Array ( ) [cap_key] => [roles] => Array ( ) [allcaps] => Array ( ) [first_name] => [last_name] => [filter] => )
I would appreciate any help you all have!
Edit
When I am accessing the file in Safari & Firefox, after I have logged in, it’s working correctly. But not in Chrome for some reason (which is what I develop in). I tried clearing all of my browser data in Chrome, and still no luck.
In your own PHP file ensure that $current_user is defined as global.