Skip Navigation

[Resolved] Change user role using Toolset Form

This support ticket is created 2 years, 10 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by annaB-7 2 years, 10 months ago.

Assisted by: Waqar.

Author
Posts
#2095943

Hello, I'm trying to create a form that allows a particular user role (Moderator) to modify the role of other users (from Visitors to Creators).

I've been reading the threads:
https://toolset.com/forums/topic/how-to-allow-a-user-to-edit-a-different-user-vis-front-end-user-form/
https://toolset.com/forums/topic/cred-edit-user-form-only-allowing-me-to-edit-my-own-profile/
https://toolset.com/forums/topic/is-it-possible-to-change-user-role-using-front-end-form/

However I still can't find a specific answer, only pieces of code that I don't know how to put together or if they really work to do what I am trying to do.

I created a form to edit users and the Moderators have permission to use this form to edit other users, but I don't know how to create a view in the front end that shows a list of users of the same role (Visitors) so that I can choose one of them and then use the form to change its role.

I'm also struggling with adding a field in the form that lets me change the user's role.

Thank you.

#2096539

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

It is not possible to create a user view using the blocks editor, so this will require working with the classic/legacy view editor.

1. The classic/legacy view can be created from WP Admin -> Toolset -> Views.

If you don't see this "Views" option, please select the "Show both the legacy and Blocks interface and let me choose which to use for each item I build" option for the editing experience at WP Admin -> Toolset -> Settings -> General.

Note: you'll find the guides on using the classic/legacy views at:
https://toolset.com/documentation/legacy-features/views-plugin/

2. Once your user view is ready to show the list of users with the Visitors role, you can include your user edit form in the loop of this view, using the shortcode:


[cred_user_form form='user-form' user='[wpv-user field="ID"]']

Note: You'll replace 'user-form' with the actual slug of your form.

As a result, in the list of the users, you'll see the user form to edit each user.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2097205

Hello Waqar,

Thank you for the reply, I managed to show the list of users with the forms.

Now I'm struggling with using the form to change the user role. I guess I have to do something like this: https://toolset.com/forums/topic/is-it-possible-to-change-user-role-using-front-end-form/ but I don't know where to add this code.

Thank you for the assistance.

#2099193

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for the update and glad that the list with the form is ready.

Your observation is correct and the custom snippet from Minesh's reply can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

Note: You'll replace the user role to remove from 'pending' with 'visitors' and the user role to add from 'custom_role_slug' to 'creators'. And in place of 9999, you'll add the actual ID of your user edit form.

#2100097

Thank you for the help ! It works perfectly now

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