Skip Navigation

[Resolved] Setting a user role based on form submission

This support ticket is created 5 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by leeG-5 5 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#1605387

Tell us what you are trying to do?
First off, thank you for Toolset. This plugin has made my experience with wordpress amazing and I have found answers to all of my questions through your support documentation, which is incredibly thorough and impressive. So thank you.

I am updating the current user role when they submit a post form. Here is where I am at currently:
add_action('update_role_action', 'update_role',10,1);

function update_role($form_data)
{
if ( is_user_logged_in() ) {
if ($form_data['id']=='495')
{
$current_user = wp_get_current_user();
$current_user->set_role('editor');
}
} else { }
}
do_action('update_role_action', 495);

I am currently learning PHP so any advice is much appreciated.

Is there any documentation that you are following?
I am using this thread as a starting point: https://toolset.com/forums/topic/change-user-role-on-cpt-form-submission/

Is there a similar example that we can see?

What is the link to your site?
This is the form: hidden link

#1605823

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Lee,

Thank you for getting in touch.

Everything seems to be fine with your code except that you need to use the Hook that is specific to our Forms plugin.

add_action('cred_before_save_data', 'update_role',10,1);
function update_role($form_data)
{
if ( is_user_logged_in() ) {
if ($form_data['id']=='495')
{
$current_user = wp_get_current_user();
$current_user->set_role('editor');
}
} else { }
}

Please let me know if this helps.
Thanks,
Shane

#1606245

My issue is resolved now. Thank you so very much, Shane!