Расширение плагина класса
Я не могу получить пользовательскую переменную из основного класса, загружающего пример "дочернего класса":
//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();
Это был файл плагина.
//EXTEND CLASS
class child extends father{
function __construct(){
parent::__construct();
}
function user_id(){
echo $this->user->ID;
}
}
Это был класс extend.
//CONFIG FILE (DISPLAYED IN ADMIN PANEL)
$child = new child();
$user_id = $child->user->id;
$child->user_id();
И это была страница конфигурации.
Я не могу получить идентификатор пользователя в расширенном классе, но да в классе отца.
Почему и как я могу это решить?
1
Author: Sein Oxygen, 2011-06-23
1 answers
Это работает для меня:
class father {
var $user;
function __construct() {
add_action( 'init', array( &$this, 'set_user' ) );
}
function set_user() {
$this->user = wp_get_current_user();
}
}
class child extends father {
function __construct() {
parent::__construct();
}
function user_id(){
return $this->user->ID;
}
}
$father = new father();
$child = new child();
add_action( 'admin_notices', 'test_stuff' );
function test_stuff() {
global $child;
print '<pre>Child: ' . print_r( $child->user_id(), true ) . '</pre>';
}
3
Author: mfields, 2011-06-23 14:18:44