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 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.
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:
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.