Remove Subscriber Add Provider

User
if ($user) {
// Set the user's role to "Provider"
$user->set_role('provider');
}
first remove subscriber
Assistant
To remove the "subscriber" role from a user and set it to "provider," you can do it in two steps:

1. **Remove the "subscriber" role** (if it exists).
2. **Assign the "provider" role**.

Here’s how you can modify your code:

if ($user) {
    // Remove the "subscriber" role
    $user->remove_role('subscriber');
    
    // Set the user's role to "Provider"
    $user->add_role('provider');
}

This code ensures that if the user has the "subscriber" role, it will be removed before assigning the "provider" role.

Leave a Comment

Your email address will not be published. Required fields are marked *