Thanks for the thorough and speedy response!
Well, the form is a user registration form for my multivendor ecommerce store that allows the user to either become a customer, or a vendor. I currently have it set up to redirect to another form if the user declares that they’d like to become an advocate for the site for beta testing, etc… This redirect only works if they check a certain box. this second form will add an additional user role to the first forms registration. So the 4 options for a user after registration are customer, vendor, customer + advocate, or vendor + advocate
In the interest of simplifying the workflow, I’d like to automatically the add the advocate role in addition to one of the other roles if the user opts for it.
No worries if not, and thanks again for the speedy response.
PS: for reference, here’s the most recent iteration of the code
// Hook into Forminator user registration
add_action(‘forminator_cform_user_registered’, ‘customize_user_roles_on_user_registration’, 10, 3);
function customize_user_roles_on_user_registration($user_id, $entry_id, $form_id) {
// Check if the registered form is the one with the specified ID
if ($form_id == 3684) {
// Add ‘om-advocate’ role
$user = get_user_by(‘ID’, $user_id);
if ($user && !user_has_role($user_id, ‘om-advocate’)) {
$user->add_role(‘om-advocate’);
}
}
}
// Function to check if a user has a specific role
function user_has_role($user_id, $role) {
$user = get_userdata($user_id);
return in_array($role, (array)$user->roles);
}