# User Registration (User Update Feed) - Let the Form determine the Role, not the Feed \[RESOLVED\]

**URL:** <https://community.gravityforms.com/t/user-registration-user-update-feed-let-the-form-determine-the-role-not-the-feed-resolved/1706>\
**Category:** Get Help\
**Tags:** user-registration\
**Created:** [April 26, 2019, 10:23pm UTC](https://community.gravityforms.com/t/user-registration-user-update-feed-let-the-form-determine-the-role-not-the-feed-resolved/1706 "2019-04-26T22:23:45Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcgsa](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/tcgsa/32/1057_2.png) [@tcgsa](https://community.gravityforms.com/u/tcgsa)\
**Post date:** [April 26, 2019, 10:23pm UTC](https://community.gravityforms.com/t/user-registration-user-update-feed-let-the-form-determine-the-role-not-the-feed-resolved/1706/1 "2019-04-26T22:23:46Z")

</div>

Hi guys!

I have a form that updates user meta upon submission (via the User Update Feed of the User Registration add-on). One of the values it updates is the role assigned to the user. My problem is that I want the form to assign one of two roles to the user, depending on a choice field selection in the form.

Would it work if I set Role to “Preserve current role” under User Settings and then, under User Meta, select wp\_user\_level or role to be updated by the choice field in question (the options of which correspond with existing roles)? Is wp\_user\_level or role the correct meta to use, or should I create a role meta? And won’t the “Preserve current role” setting prevent the role from being updated?

Looking forward to hearing the awesome wisdom of the community! 😁

Cheers,  
Phil

---

<div class="post-metadata">

**Author:** ![sacom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sacom/32/53_2.png) [@sacom](https://community.gravityforms.com/u/sacom)\
**Post date:** [April 27, 2019, 12:09am UTC](https://community.gravityforms.com/t/user-registration-user-update-feed-let-the-form-determine-the-role-not-the-feed-resolved/1706/2 "2019-04-27T00:09:04Z")

</div>

You can use [a little snippet](https://docs.gravityforms.com/gform_user_registered/#set-user-role) to set the role based on the user selection (e.g. using a drop down field).

What you select in the feed settings for the role doesn’t matter, because the snippet will override the role with the selected one in the form field.

---

<div class="post-metadata">

**Author:** ![tcgsa](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/tcgsa/32/1057_2.png) [@tcgsa](https://community.gravityforms.com/u/tcgsa)\
**Post date:** [April 27, 2019, 12:24am UTC](https://community.gravityforms.com/t/user-registration-user-update-feed-let-the-form-determine-the-role-not-the-feed-resolved/1706/3 "2019-04-27T00:24:35Z")

</div>

Hey Samuel, I mentioned awesome wisdom and I wasn’t disappointed! 😄👍 Thanks so much for that, I’ll give it a whirl.

Best,  
Phil

---

<div class="post-metadata">

**Author:** ![tcgsa](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/tcgsa/32/1057_2.png) [@tcgsa](https://community.gravityforms.com/u/tcgsa)\
**Post date:** [April 27, 2019, 12:29am UTC](https://community.gravityforms.com/t/user-registration-user-update-feed-let-the-form-determine-the-role-not-the-feed-resolved/1706/4 "2019-04-27T00:29:24Z")

</div>

Two questions, if you don’t mind… is there a way to specify the form ID in that snippet, and will this actually _update_ the current role to the new one? I.e. it’s NOT a new user but an existing one?

---

<div class="post-metadata">

**Author:** ![sacom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sacom/32/53_2.png) [@sacom](https://community.gravityforms.com/u/sacom)\
**Post date:** [April 27, 2019, 12:56am UTC](https://community.gravityforms.com/t/user-registration-user-update-feed-let-the-form-determine-the-role-not-the-feed-resolved/1706/5 "2019-04-27T00:56:00Z")

</div>

Oops! I sent you the filter for the new user registration by mistake 😊

The same thing can be done with the gform\_user\_updated filter that runs only for existing users updates, there’s also an example in this filter doc page: [https://docs.gravityforms.com/gform\_user\_updated/#update-user-role](https://docs.gravityforms.com/gform_user_updated/#update-user-role)

You can limit the snippets to a concrete form only by checking the form id at the start of the function, for example:

```
// Run only for form id 1
$form = GFAPI::get_form( $entry['form_id'] );
if ( $form['id'] != 1 ) {
   return;
}

```

---

<div class="post-metadata">

**Author:** ![tcgsa](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/tcgsa/32/1057_2.png) [@tcgsa](https://community.gravityforms.com/u/tcgsa)\
**Post date:** [April 27, 2019, 12:58am UTC](https://community.gravityforms.com/t/user-registration-user-update-feed-let-the-form-determine-the-role-not-the-feed-resolved/1706/6 "2019-04-27T00:58:43Z")

</div>

Great, thanks Samuel - I’ll give it a go. Appreciate the effort!

---

<div class="post-metadata">

**Author:** ![tcgsa](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/tcgsa/32/1057_2.png) [@tcgsa](https://community.gravityforms.com/u/tcgsa)\
**Post date:** [April 27, 2019, 1:01am UTC](https://community.gravityforms.com/t/user-registration-user-update-feed-let-the-form-determine-the-role-not-the-feed-resolved/1706/7 "2019-04-27T01:01:32Z")

</div>

Sorry for bugging you again - I’m having a dunce moment here - how would I add the “Run only for form id …” bit to the rest of the snippet?

---

<div class="post-metadata">

**Author:** ![sacom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sacom/32/53_2.png) [@sacom](https://community.gravityforms.com/u/sacom)\
**Post date:** [April 27, 2019, 1:02am UTC](https://community.gravityforms.com/t/user-registration-user-update-feed-let-the-form-determine-the-role-not-the-feed-resolved/1706/8 "2019-04-27T01:02:24Z")

</div>

You’re welcome Phil, by the way, I forgot to add a line to the above snippet to get $form first, sorry it’s 3:00 AM here)…

I have edited the snippet now.

---

<div class="post-metadata">

**Author:** ![tcgsa](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/tcgsa/32/1057_2.png) [@tcgsa](https://community.gravityforms.com/u/tcgsa)\
**Post date:** [April 27, 2019, 1:04am UTC](https://community.gravityforms.com/t/user-registration-user-update-feed-let-the-form-determine-the-role-not-the-feed-resolved/1706/9 "2019-04-27T01:04:25Z")

</div>

LOL… I’m sitting at 04:00 AM, so I’m not focusing much.

So sorry, but I still don’t really know where to add the above snippet… 😅

In relation to the `gform_user_updated` snippet, that is…

---

<div class="post-metadata">

**Author:** ![sacom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sacom/32/53_2.png) [@sacom](https://community.gravityforms.com/u/sacom)\
**Post date:** [April 27, 2019, 1:08am UTC](https://community.gravityforms.com/t/user-registration-user-update-feed-let-the-form-determine-the-role-not-the-feed-resolved/1706/10 "2019-04-27T01:08:06Z")

</div>

At the start of the function:

```
add_action( 'gform_user_updated', 'change_role', 10, 4 );
function change_role( $user_id, $feed, $entry, $user_pass ) {

// Run only for form id 1
$form = GFAPI::get_form( $entry['form_id'] );
if ( $form['id'] != 1 ) {
   return;
}

// Any other code goes below this line...
```

---

<div class="post-metadata">

**Author:** ![tcgsa](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/tcgsa/32/1057_2.png) [@tcgsa](https://community.gravityforms.com/u/tcgsa)\
**Post date:** [April 27, 2019, 1:09am UTC](https://community.gravityforms.com/t/user-registration-user-update-feed-let-the-form-determine-the-role-not-the-feed-resolved/1706/11 "2019-04-27T01:09:26Z")

</div>

Aah - thanks a bunch Samuel, much appreciated!

Now I’m off to bed! 😴

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [April 27, 2019, 1:45am UTC](https://community.gravityforms.com/t/user-registration-user-update-feed-let-the-form-determine-the-role-not-the-feed-resolved/1706/12 "2019-04-27T01:45:38Z")

</div>



---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [April 27, 2019, 1:45am UTC](https://community.gravityforms.com/t/user-registration-user-update-feed-let-the-form-determine-the-role-not-the-feed-resolved/1706/13 "2019-04-27T01:45:44Z")

</div>


