Title: Adding multiple roles
Last modified: August 30, 2016

---

# Adding multiple roles

 *  Resolved [khav](https://wordpress.org/support/users/khav/)
 * (@khav)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/adding-multiple-roles/)
 * I want to add multiple roles for a user with a snippet.I already have user role
   editor activate
 * $user = GFUserData::get_user_by_entry_id( $entry[‘id’] );
    $user->remove_role(‘
   sks_member’);
 * remove_roles will remove all other roles for that user
 * $user->add_role(‘sks_member’) will remove any other roles and assign him sks_member
 * What function do i need to use to add multiple roles ?
 * [https://wordpress.org/plugins/user-role-editor/](https://wordpress.org/plugins/user-role-editor/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [Vladimir Garagulya](https://wordpress.org/support/users/shinephp/)
 * (@shinephp)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/adding-multiple-roles/#post-6637628)
 * WordPress built-in WP_USER::add_role() method (wp-includes/capabilities.php) 
   does not remove itself any other role. It just adds new role to the user:
 *     ```
       public function add_role( $role ) {
       	$this->caps[$role] = true;
       	update_user_meta( $this->ID, $this->cap_key, $this->caps );
       	$this->get_role_caps();
       	$this->update_user_level_from_caps();
   
       	/**
       	 * Fires immediately after the user has been given a new role.
       	 *
       	 * @since 4.3.0
       	 *
       	 * @param int    $user_id The user ID.
       	 * @param string $role    The new role.
       	 */
       	do_action( 'add_user_role', $this->ID, $role );
       }
       ```
   
 *  Thread Starter [khav](https://wordpress.org/support/users/khav/)
 * (@khav)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/adding-multiple-roles/#post-6637631)
 * Hi Vladimir
 * Thanks for replying…
 * What do you think could be causing the issue i am having.Any user can have only
   1 role at any time
 *  Plugin Author [Vladimir Garagulya](https://wordpress.org/support/users/shinephp/)
 * (@shinephp)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/adding-multiple-roles/#post-6637632)
 * Some other code could overwrite user’s roles.
    For example if you update user
   profile user will lose all roles except a primary one. I should add workaround
   for this in User Role Editor.
 *  Thread Starter [khav](https://wordpress.org/support/users/khav/)
 * (@khav)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/adding-multiple-roles/#post-6637633)
 * Vladimir could you guide me on how to do that
 * I am using the following hooks to add or remove a role(hopefully it will help
   you)
 * add_action( ‘gform_subscription_canceled’, ‘canceled_remove_user_role’, 10, 1);
 * add_action( ‘gform_post_payment_completed’, ‘process_order_roles’, 10, 2 );
 * Kind Regards
 *  Thread Starter [khav](https://wordpress.org/support/users/khav/)
 * (@khav)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/adding-multiple-roles/#post-6637752)
 * Seems like i wrongly read your post
 * When can i expect a fix ?
 * Thanks a lot for the great work
 * Kind Regards
 *  Plugin Author [Vladimir Garagulya](https://wordpress.org/support/users/shinephp/)
 * (@shinephp)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/adding-multiple-roles/#post-6637770)
 * No, you understood right. I meant that I added such workaround to the User Role
   Editor already. May be you need something similar.
    Try to trace your code step
   by step, check that 2nd role is really added and then find where it is removed.
 * Hooks you showed does not belong to WordPress. I can tell you nothing about them,
   except that they may be added by some Gravity Forms add-on.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Adding multiple roles’ is closed to new replies.

 * ![](https://ps.w.org/user-role-editor/assets/icon-256x256.jpg?rev=1020390)
 * [User Role Editor](https://wordpress.org/plugins/user-role-editor/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/user-role-editor/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/user-role-editor/)
 * [Active Topics](https://wordpress.org/support/plugin/user-role-editor/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/user-role-editor/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/user-role-editor/reviews/)

## Tags

 * [multiple](https://wordpress.org/support/topic-tag/multiple/)
 * [role](https://wordpress.org/support/topic-tag/role/)

 * 6 replies
 * 2 participants
 * Last reply from: [Vladimir Garagulya](https://wordpress.org/support/users/shinephp/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/adding-multiple-roles/#post-6637770)
 * Status: resolved