Er.Naved Ali Er.Naved Ali - 1 year ago 91
PHP Question

How to assign Multiple roles to a single user in wordpress

I want to make a plugin which can assign multiple roles to a single user. Some say its not possible to assign multiple roles in wordpress then why wordpress has provided 'roles' in array form.
e.g when i call roles of user it returns array

$user_roles = $current_user->roles;

here $user_roles will be an array return by roles.

Is there any function through which i can assign multiple role to a single user

Answer Source

All thanks to tristan, finally i assigned multiple role to a single user.This code helped me to achieve that.

 $addMemberToGroup = new WP_User($required_id);
 $addMemberToGroup->add_role( $role );

here $required_id is the id of user whom i want to assign role.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download