• Resolved stevec0023

    (@stevec0023)


    Hi

    I have Youzify installed and it’s working great!

    I am trying to add some additional user roles when someone registers at my site. I have written the code and it works just fine when using the normal WordPress registration process. However, when I use the same code but the Youzify registration page, the new roles are not added to the new user.

    Here is my code:

    function my_additional_roles( $user_id ) {
    $new_user = get_user_by( 'ID', $user_id );

    ////Add additional user roles
    if ( in_array( 'subscriber', (array)$new_user->roles ) ) {
    $new_user->add_role( 'wpas_user' ); //Support User
    $new_user->add_role( 'academy_student' ); //Academy LMS Student
    }
    }


    add_action( 'user_register', 'my_additional_roles' );

    I suspect that Youzify may be using a different function to ‘user_register’ that I am trying to add my action to but I cannot seem to find in your code any references.

    Could someone please point me in the right direction.

    Thanks so much!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Youzify

    (@kainelabsteam)

    Hi @stevec0023

    Please clarify – do you want the user can select a role on the registration process or do you just want to add a new role on the back-end so the admin can assign it to the user?

    Best Regards, KaineLabs Team.

    Thread Starter stevec0023

    (@stevec0023)

    Hi

    Thanks for responding! To clarify, when a user creates an account from the Youzify register page on the front end, they are creating an account with the user role ‘subscriber’.

    Want I am aiming to achieve is at that same moment, when the user is created as a subscriber, I want to also assign that user with the additional user roles ‘wpa_user’ and ‘academy_student’.

    This should happen automatically when the new user account is created.

    Thanks

    Plugin Support Youzify

    (@kainelabsteam)

    Hello @stevec0023

    Please clarify – so when people register via the Youzify registration form, do you want the default role for them to be ‘wpa_user’ and ‘academy_student’?

    Best Regards, KaineLabs Team.

    Thread Starter stevec0023

    (@stevec0023)

    No. The default role will be ‘subscriber’. Additional roles will be ‘wpa_user’ and ‘academy_student’

    The question is what function to hook to. Normally I would hook to ‘user_register’. Does Youzify use this or another function when registering a new user?

    Plugin Support Youzify

    (@kainelabsteam)

    Hi @stevec0023

    Unfortunately, Youzify has no this kind of hook. But if your goal is, you want to add new roles, you may try the User Role Editor plugin. Based on our experiences, it works fine with Youzify.

    Best Regards, KaineLabs Team.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add additional user roles at Registration’ is closed to new replies.