Skip Navigation

[Resolved] Is it possible to change User role using front-end form?

This thread is resolved. Here is a description of the problem and solution.

Problem:
Is it possible to change User role using front-end form?

Solution:
You can use the Toolset Form hook "cred_save_data" in order to update the user role for the current user you are editing or creating.

You can find the proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/is-it-possible-to-change-user-role-using-front-end-form/#post-1503479

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 4 years, 2 months 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by steveH-15 4 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#1503213

We would like to change User role of some users from 'Member' to 'Verified Member', without needing administrator access to the website. Is this achievable using a front-end form?

#1503479

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Normally, You can use the Toolset Form hook cred_save_data in order to update the user role for the current user you are editing or creating.

For example - following is the sample code:

add_action('cred_save_data', 'func_update_user_role_action',10,2);
function func_update_user_role_action($user_id, $form_data) {
 
if ($form_data['id'] == 9999) {
// modify the user role to match the selected option
$u = new WP_User( $user_id );
$u->remove_role( 'pending' );   /// adjust role name here if needed
$u->add_role( 'custom_role_slug' );
}
}

Where:
- Replace 9999 with your original User form ID.
- replace custom_role_slug with your role slug

More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#1508839

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.