#2998
Vladimir
Keymaster

Hi Brian,

I made an assumption that user select a secondary role from the business type radio list. So I added role IDs as the option values for its options: hospice, hospital, surgury_center.
You have to create roles with the same IDs. This interface element is available as the $entry[11] at the GF ‘gform_user_registered’ filter. So PHP code will be:

add_action( 'gform_user_registered', 'frontend_register_add_2nd_user_role', 10, 4);

function frontend_register_add_2nd_user_role($user_id, $user_config, $entry, $user_pass) {

    global $wp_roles;
    
    $user = new WP_User($user_id);
    
    $role = $entry[11];
    
    // secondary role
    if (empty($role)) {
        return;
    }
    
    if (!isset($wp_roles->roles[$role])) {
        return;
    }
    
    $user->add_role($role);
    
}