Problem:
Can we change a user role thru a Toolset Form?
If so, how?
Solution:
You can, but only using Custom Code.
You can see a cred_save_data() hook to fire your custom code when the Form saves the users' data in the database.
Inside that hook, you can use wp_update_user() WordPress API to update the user to any role you desire.
For example, you can add a Generic Field to the form where the user can choose his role to which to update, and then you can read it from the $_POST - so to update the user to the desired role with wp_update_user()
Be careful with this as users will be able to eventually change their role.
Be sure to grant access to these forms only to whom you trust.
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://developer.wordpress.org/reference/functions/wp_update_user/
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 |
---|---|---|---|---|---|---|
- | - | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 |
- | - | - | - | - | - | - |
Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)
This topic contains 10 replies, has 2 voices.
Last updated by 4 years, 9 months ago.
Assisted by: Beda.