Building a plugin that I need to get the users info, more especially the userID
Class userinfo {
public function __construct() {
add_action( 'plugins_loaded', array( $this, 'get_user_info' ) );
}
public function get_user_info() {
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
if ( ! ($current_user instanceof WP_User) )
return;
}
return $current_user->user_info;
}
}
$user = new userinfo();
echo $user->current_user; #echo for testing purposes
PHP comes back with the undefined notice and the whole thing breaks, so what am I doing wrong?
Notice Undefined property: userinfo::$current_user
EDIT Found a mistaken when I logged out of the site so updating here
Class userinfo {
public function __construct() {
add_action( 'plugins_loaded', array( $this, 'get_user_info' ) );
}
public function get_user_info() {
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
if ( ! ($current_user instanceof WP_User) )
return;
return $current_user->user_info;
}
}
}
$user = new userinfo();
echo $user->current_user; #echo for testing purposes