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
(@khav)
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
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
(@khav)
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
(@khav)
Seems like i wrongly read your post
When can i expect a fix ?
Thanks a lot for the great work
Kind Regards
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.