我试图在注册过程中添加多个角色,除了添加多个用户角色外,一切正常。我使用的代码:$roles = array('wholesale_customer', 'retail_customer');$userdata = array( 'user_login' => $username, 'user_email' => $email, 'user_pass' => $password, 'user_url' => $website, 'first_name' => $first_name, 'last_name' => $last_name, 'nickname' => $nickname, 'description' => $bio, 'role' => $roles // want to add multiple roles such as editor,retailer);$user = wp_insert_user( $userdata );
1 回答
慕妹3146593
TA贡献1820条经验 获得超9个赞
你试过这种方法吗?
$userdata = array(
'user_login' => $username,
'user_email' => $email,
'user_pass' => $password,
'user_url' => $website,
'first_name' => $first_name,
'last_name' => $last_name,
'nickname' => $nickname,
'description' => $bio,
'role' => 'editor' // default
);
$userid = wp_insert_user( $userdata );
$user = new WP_User( $userid );
$user->add_role('retailer');
$user->add_role('customer');
// etc..
- 1 回答
- 0 关注
- 122 浏览
添加回答
举报
0/150
提交
取消