When i create a form to EDIT the USER FIELDS toolset forces me to choose a role at this line:
Role of the user to create/edit:
This is the user role that the user will get after pressing the edit button, correct?
If that is the case, how can i not choose any and maintain the current user role that the user has? It should have that option there "don't change user role".
Thanks
Apparently the Role of the user to create/edit: is applied to the current user we are editing. I just tried to edit the administrator info with the edit user form assigned to "pending approval" user role and returned the error:
This form can not edit users with a role of administrator
1 - I have 5 user roles, so does that means i will have to create an EDIT FORM for each user role, and use ACCESS shortcode to display them conditionally according to their userrole?
2 - Is there a way of after ANYONE editing their profile to move to the user role "Pending Approval"?
I saw Minesh answer in this thread: https://toolset.com/forums/topic/need-to-change-roles-via-creds-there-is-no-role-field-in-toolset-cred/
With the code:
add_action('cred_save_data', 'cred_update_user_role_action',10,2);
function cred_update_user_role_action($user_id, $form_data) {
if ($form_data['id'] == 2320) {
// modify the user role to match the selected option
$role = get_user_meta( $user_id,'wpcf-user_select_role', true );
$u = new WP_User( $user_id );
$u->remove_role( 'pending' ); /// adjust role name here if needed
$u->add_role( $role );
}
}
So for the EDIT USER CRED FORM ID assigned to edit Subscribers it would be:
$u->remove_role( 'Subscriber' );
$u->add_role('Pending Approval');
This would work in this situation?
Thanks
Hello,
Yes, you are right, that option is for is current user we are editing.
Q1) 1 - I have 5 user roles...
Yes, one user form can edit users of one user role, so you will need to setup different user form for each user role.
Q2) Is there a way of after ANYONE editing their profile to move to the user role "Pending Approval"?
Yes, you can try the custom codes you mentioned above, and it needs to user role slug instead of role title, for example:
- subscriber
- pending_approval
My issue is resolved now. Thank you!