• Resolved The Open Market

    (@jhutson323)


    Hello again,

    I’m playing with the User registration > User meta mapping > User role: conditional role assignment and it appears that I am not able to assign multiple user roles to a single user.

    I’ve tried a couple iterations here, but this is my verdict.

    Is there a workaround for this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @jhutson323,

    I’m afraid, what you have mentioned is the expected behaviour. At the moment, the plugin can only assign one role to registered users.

    We do have plans to improve this workflow down the plugin’s roadmap, but at the moment there isn’t any exact time frame we could provide as it’s still in the pipeline.

    Could we know what is the condition on how you are looking to assign the roles? If you are looking for a custom workflow, you can check whether using forminator_cform_user_registered action hook would help in such instances.

    Kind Regards,

    Nithin

    Thread Starter The Open Market

    (@jhutson323)

    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);
    }

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @jhutson323,

    Thanks for explaining further, I’m afraid, there isn’t such a feature at the moment, the plugin only helps with adding one role. So you could assign only one role based on the “Assign Role Conditionally” setting:

    https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#user-role

    Just to be sure, does the custom code you have shared work? or are you still looking for further assistance with making it work?

    Please advise if you still have any further queries.

    Best Regards,

    Nithin

    Plugin Support Dmytro – WPMU DEV Support

    (@wpmudevsupport16)

    Hello @jhutson323,

    Hope you’re doing good today!

    We haven’t heard from you for a while, so I’m marking this thread as resolved. Please feel free to ref-open it, if you need further assistance.

    Best Regards,
    Dmytro

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘assign multiple user roles from a single registration submission?’ is closed to new replies.