$current_user var returns NULL

You need to globalize $current_user, and then populate it via get_currentuserinfo(). See the Codex entry for get_currentuserinfo(). In the Codex-example usage:

<?php
global $current_user;
get_currentuserinfo();
?>

So, try adapting your code accordingly; e.g.:

class My_plugin_class{

    var $user;

    function __construct() 
    {      
        //Set the current user
        global $current_user;
        get_currentuserinfo();
        $this->user = $current_user;

        print_r($this->user);

    }     
}

Leave a Comment