how to Assign Multiple Roles for a user in wordpre

2020-08-11 04:43发布

I know how to assign a single role for a user. But coming to the multiple roles for a user is not working...Is wordpress gives this facility or not.Thanks in advance.

标签: wordpress
3条回答
Rolldiameter
2楼-- · 2020-08-11 05:22

Yes, WordPress allows this. You can do it in your code:

    $someone = new WP_User( $user_id );
    $someone->add_role( 'role-1' );
    $someone->add_role( 'role-2' );

You can also use a plugin such as Multiple Roles. The plugin will transform the select dropdown into checkboxes.

WordPress — Role selection checkboxes

查看更多
beautiful°
3楼-- · 2020-08-11 05:38

For completeness, this is possible!

 $theUser = new WP_User($userId);
 $theUser->add_role( $role );
查看更多
一夜七次
4楼-- · 2020-08-11 05:42

This is not possible in Wordpress currently, as this is how the core role mapping is designed. You can however create "combination" roles, but this might lead to a large number of roles when you have a lot of core roles to combine.

Another option would be using a plugin such as User Role Editor, which can help you giving more control of Wordpress' role mapping.

查看更多
登录 后发表回答