admin管理员组文章数量:1122846
I am doing custom registration and logging and assigning a custom user
role.
I register like this:
$user_id = wp_create_user($username, $password, $email);
if (!is_wp_error($user_id)) {
$user = new WP_User($user_id);
$user->set_role('user');
echo __('Registration successful.', 'vk-add-and-review');
} else {
echo __('Registration failed.', 'vk-add-and-review');
}
In wp_usermeta
wp_capabilities
I have this: a:1:{s:4:"user";b:1;}
Still, when I check for the user after logging in it is empty:
if (is_user_logged_in()) {
$current_user = wp_get_current_user();
if (in_array('user', (array) $current_user->roles)) {
return '<p>' . __('You are logged in as a user.', 'vk-add-and-review') . '</p>';
} else {
return '<p>' . __('You are logged in, but not as a user.', 'vk-add-and-review') . '</p>';
}
}
$current_user->roles
is an empty array
本文标签: User has empty instead of custom role when logged in
版权声明:本文标题:User has empty instead of custom role when logged in 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736300112a1930700.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论