WPDKUser::set_role PHP Method

set_role() public method

This will remove the previous roles of the user and assign the user the new one. You can set the role to an empty string and it will remove all of the roles from the user.
Since: 1.5.6
public set_role ( string $role )
$role string Role name.
    public function set_role($role)
    {
        // Before remove all previous
        $this->remove_all_caps();
        parent::set_role($role);
        // Flush user cache
        wp_cache_delete($this->ID, 'users');
        // Destroy the global
        global $current_user;
        unset($current_user);
        unset($GLOBALS['current_user']);
        // Reset as current
        wp_set_current_user($this->ID);
    }