BuddyDev

Search

[Resolved] How to use code for allocating user role upon registration

  • Participant
    Level: Enlightened
    Posts: 23
    Stephanie on #52741

    Hello

    I have a question about using this code here:
    https://buddydev.com/assign-user-roles-based-on-buddypress-profile-field-data-on-user-registration/

    On line 19, in red, it says “Membership Type”. The comment says “Change this with actual field id or Name”.

    My question is, what is the field “name”: is it the human readable name I set when creating a field in the wordpress dashboard -> users -> profile field, such as “Author Bio” or “Home Town”, or is the machine code ID found in the HTML? For example, I have a field called “Member Type” but when you mouse over the “edit” button in the dashboard, it says “field_id=2”, and when I right click and select “inspect”, it says “id=”field_2” name=”field_2. So can I use the human readable format field name, or should I use the machine allocated “name”, which in this case, is “field_2”?

    I’ve already tested it with the human readable format field name of “Member Type” and it works but I just wanted to make sure it wasn’t a coincidence that it worked and confirm the correct use of the code.

    Thank you.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3047
    Ravi on #52743

    Hello Stephanie,

    Thank you for posting. Yes, you are right it is the field name we give while creating a new field from Dashboard > User > Profile Fields > Add New Field.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 23
    Stephanie on #52744

    Thank you Ravi for the clarification, I will close this support thread now.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3047
    Ravi on #52746

    You’re welcome! and thank you for marking it as resolved.

    Regards
    Ravi

The topic ‘ [Resolved] How to use code for allocating user role upon registration’ is closed to new replies.

This topic is: resolved