I have something like this, it removes all capabilities before adding a new role. You can modify this to achieve what you want when changing roles on frontend.
add_action('frm_after_update_entry', 'update_user_role', 10, 2); function update_user_role($entry_id, $form_id){ if ( $form_id == 2 ) { $userid = $_POST['item_meta'][19];// ID of the userID field $role = $_POST['item_meta'][236];// ID of the role dropdown $accesslevel = $_POST['item_meta'][270];// ID of the role dropdown if ( $userid && $role ) { $user = get_userdata( $userid ); if ( $user && ! $user->has_cap('administrator') ) { $user->remove_all_caps(); $user->set_role( $role ); $user->add_cap( 'access_level' , $accesslevel); } } } }
Please login or Register to submit your answer
Not sure I can help, but do have a question. Is the edit form the same form with the action that creates a user?
Yes as it stands currently
Q: You have an admin View that lets you change the role, or maybe a param to ghange via link (URL)?