I can’t get the user variable from the main class loading a “child class” example:
//PLUGIN FILE
class father{
var $user;
function __construct() {
add_action('plugins_loaded', array(&$this, 'loaded'));
}
function plugins_loaded(){
global $wp_get_current_user;
$this->user = wp_get_current_user();
}
}
$plugin = new parent();
That was the plugin file.
//EXTEND CLASS
class child extends father{
function __construct(){
parent::__construct();
}
function user_id(){
echo $this->user->ID;
}
}
That was the extend class.
//CONFIG FILE (DISPLAYED IN ADMIN PANEL)
$child = new child();
$user_id = $child->user->id;
$child->user_id();
And that was the config page.
I can’t get the user id in the extended class, but yes in the father class.
Why and how i can solve it?
This works for me: