I have a PHP page at the same level as the template/theme on WordPress. I need to be able to get the current logged in user details from this page.
I have tried this:
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
global $current_user;
$current_user = wp_get_current_user();
var_dump( $current_user );
But it's returning nothing. 0 as user_id and nothing on the other fields. Am I missing something?
UPDATE:
This is the result of the var_dump:
object Object]1object(WP_User)#79 (10) {
["data"] => NULL
["ID"] => int(0)
["id"] => int(0)
["caps"] => array(0) {}
["cap_key"] => NULL
["roles"] => array(0) {}
["allcaps"] => array(0) {}
["first_name"] => string(0) ""
["last_name"] => string(0) ""
["filter"] => NULL
}