Skip Navigation

[Resolved] Need to change roles via CREDs. There is no ROLE field in Toolset CRED.

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

Problem:
Need to change roles via CREDs. There is no ROLE field in Toolset CRED.

Solution:
Yes - you can use 'cred_save_data' hook to assign a role to created user using Toolset CRED user form.

You can find proposed solution, in this case, with the following reply:
=> 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 6 years, 6 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Author
Posts
#920143

Tell us what you are trying to do?

Hello, I'm developing a site for members with different hierarchical levels, each level aprove other people's inputs and change their roles via CRED. I created several custom roles with Toolset Access. I've created a custom role for people who subscribe to the website. The manager (one Role) needs to approve the people who have signed up for the site.
The manager enters a page and accesses a view that filters all users with intermediate paper and can edit the data of those users. The editing of all the data is perfect, with the exception of ROLE.

My problem is to make available the edition of the ROLE in the CRED that the manager accesses. I have seen that there is a solution in this link.

https://toolset.com/forums/topic/create-two-roles/

But I'm not creating a new user, just making a page with a view for the Manager edit through a CRED other user.

Tentei o seguinte código, mas não funcionou.

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data) {

if ($form_data['id']==2320) {
$current_user = wp_get_current_user();
$user_id = $current_user->ID;
wp_update_user ( array ( $user_id, 'role' => 'condomino_port_trouville' ));
}
}

I liked this solution and made a field that only the manager accesses and defines the new ROLE of the user.
// Modify new user role based on custom field selection in CRED
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'] == 19872)
{
// modify the user role to match the selected option
$role = $_REQUEST['user_select_role'];
$u = new WP_User( $user_id );
$u->remove_role( 'pending' );
$u->add_role( $role );
}
}

But I'm not creating a new user.

Would you have a solution to this problem?

Is there any documentation that you are following?
https://toolset.com/forums/topic/create-two-roles/
https://toolset.com/forums/topic/edit-roles-cred/
https://toolset.com/forums/topic/allow-users-to-select-a-role-when-registeringediting-profile-with-cred-beta-3/

Is there a similar example that we can see?
No.
What is the link to your site?

#920293

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - so when manger logged in and edit certain post - does manager have options to select the desired role to which manager wants to change to? If yes:

Then as you say manager is editing the specific user - we just need to get the ID of the user for which manager is making edit and catch the ID and role value and assign it to that user.

Both of the solution should work with some code adjustments. If you can share more details with problem URLs I would be happy to assist you further.

#920310

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - what if you try to add following code to your current theme's functions.php file:

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 );
}
}
#920341

Thanks a lot! It´s working! Great and fast support.