I'm trying to add an additional role for a user when they register if they register as a specific role.
Here is my function:
function add_secondary_role( $user_id ) {
$current_user = wp_get_current_user();
if ( in_array( 'um_dueling-pianist', (array) $current_user->roles ) ) {
$user = get_user_by('id', $user_id);
$user->add_role('pianist');
}
}
It doesn't work. I have registered a test account with the role 'um_dueling-pianist' and it does not add the other role of 'pianist.' Those are both the meta values for the user roles and not the display name of the user roles.
Any idea what's wrong with my function?