admin管理员组文章数量:1319483
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
本文标签: trying to get user info in plugin
版权声明:本文标题:trying to get user info in plugin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742059341a2418485.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论