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!
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?
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...