there are two kinds of user-roles I want to set in a plugin. First there is the role 'kunde', that's no problem. It is the default role for a new user.
The second one doesn't work. It is the role 'vermittler' and I don't know how to add this role.
My Code for insert:` $user_data = array( 'ID' => '',
'user_pass' => $_POST['vermittlerpasswort'],
'user_login' => $_POST['vermittlername'],
'user_nicename' => $_POST['vermittlername'],
'user_email' => $_POST['email'],
'last_name' => $nachname,
'first_name' => $vorname,
'user_registered' => $datum,
'role' => get_option('default_role')
$user_id = wp_insert_user( $user_data );`
The code inserts a user with 'Kunde'-role. For 'Vermittler'-role I tested:
'role' => get_option('Vermittler_role') 'role' => get_option('Vermittler')
nothing works. Si I tried first to set 'Kunde'-role and then change. // die Rolle auf Vermittler ändern
$u = new WP_User( $user_id );
// Remove role
$u->remove_role( 'Kunde' );
// Add role
$u->add_role( 'Vermittler' );`
doesn't work, too.
Please excuse my very bad English, I hope You can undestand what I mean.