• Resolved wpress123

    (@wpress123)


    Hi, I know this has been answered before and done but I can’t seem to get it to work.

    I am trying to automatically add multiple user roles created outside of UM to a specific user role created in UM.

    If user registers as role “member” that I set in UM, I am trying to make them automatically to be added the following user roles as well: “vendor”, “seller”, “organizer”, etc.

    I use multi-vendor from Dokan and also some other plugins that require specific user roles. I want to make users as those other roles automatically when they register with the UM registration page without them having to go through another registration or verification process for the other plugins.

    If this something I can do via functions.php? or somewhere in UM?

    Thank you!

    • This topic was modified 1 year ago by wpress123. Reason: better clarification
    • This topic was modified 1 year ago by wpress123. Reason: better clarification
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter wpress123

    (@wpress123)

    Never mind I sent in a support ticket.

    Thread Starter wpress123

    (@wpress123)

    Suppoprt doesn’t want to help with this so putting it out there for any guidance.

    To clarify a bit further, in UM the role is the role ID, not the role name: e.g. member = um_member

    The other plugins are the same names as the role ID’s. e.g. vendor = vendor

    missveronica

    (@missveronicatv)

    @wpress123

    How do you know at Registration that a new UM “member”
    is a “vendor” or a “seller” or an “organizer”?

    Thread Starter wpress123

    (@wpress123)

    @missveronicatv I figured it out on my own.

    At registration I set the UM Role through the form.

    UM Role is set as a single role by default. You cannot assign additional roles automatically via UM admin panel. You can manually set additional roles via WordPress user management after registration with a plugin but I wanted it automated and without more plugins.

    Upon registration, I add additional Role ID’s “vendor”, “seller”, etc. through functions.php.

    I use “um_registration_set_extra_data” hook from UM to accomplish this: https://docs.ultimatemember.com/article/1235-umregistrationsetextradata

    You can find all the Role ID’s in UM user roles admin panel. You have to use the Role ID, not the Role Title.

    Here’s the code if anyone else needs to do the same thing. This also checks if the roles exist so there are no errors.

    Replace [MY_UM_ROLE_ID] with the um_role_ID (no brackets).

    You can change the role priority here too (“10, 2” in example below) but that’s a different topic.

    // Automatically add additional roles to specific UM Role ID upon registration
    
    add_action( 'um_registration_set_extra_data', 'add_roles_to_[MY_UM_ROLE_ID]_users', 10, 2 );
    
    function add_roles_to_[MY_UM_ROLE_ID]_users( $user_id, $query_args ) {
    
    ????if ( isset( $query_args['role'] ) && $query_args['role'] === '[MY_UM_ROLE_ID]' ) {
    
    ????????$user = get_user_by( 'id', $user_id );
    
    ????????if ( $user ) {
    
    ????????????// The additional roles you want to add
    
    $user->add_role( '[ADDITIONAL_ROLE_ID_1]' );
    $user->add_role( '[ADDITIONAL_ROLE_ID_2]' );
    
    ????????}
    
    ????}
    
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Multiple user roles for specific UM user role upon registration’ is closed to new replies.