Skip Navigation

[Resolved] Role of the user to create/edit – CRED EDIR USER FORM

This thread is resolved. Here is a description of the problem and solution.

Problem:

Change user role after submit the editing user form.

Solution:

You can try cred_save_data action hook, for example:

https://toolset.com/forums/topic/need-to-change-roles-via-creds-there-is-no-role-field-in-toolset-cred/#post-920310

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 3 years, 9 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/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by pedro.S 3 years, 9 months ago.

Assisted by: Luo Yang.

Author
Posts
#1668551

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

#1668577

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

#1669171

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

#1670031

My issue is resolved now. Thank you!

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