Skip Navigation

[Resolved] Error when using user edit form

This support ticket is created 4 years, 7 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Waqar 4 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#1571289
Edit_User_Error.png
Edit_User.png
all_user_types.png

Tell us what you are trying to do?

I've created a form to edit non-admin users with a drop down to select a user role (uses a view to populate a generic field). I'm then using a custom function to update the user role when the form is submitted, but I'm getting the error in the attached image. It looks to be a permissions issue, but as you'll see in the screens the form is set for all user roles to be able to access it (for testing).


add_action('cred_save_data', 'yls_update_user_profile',10,2);

function yls_update_user_profile($user_id,$form_data) {
    // if a specific form
    if ($form_data['id']==1016)
    {
        $user_role = $_POST['user-role'];   
     
    wp_update_user( array( 'ID' => $user_id, 'role' => $user_role ) ); 
    }
}

Is there any documentation that you are following?

What is the link to your site?

I can provide the dev site address and toolset login via secure message.

#1571635

Hi Matt,

Thank you for contacting us and I'd be happy to assist.

The code snippet that you've shared seems to be correct, but to troubleshoot this, I'll suggest the following steps:

1. Please make sure that WordPress, active theme and plugins are all updated to the latest versions.

2. It would be interesting to test if this is happening only for a specific user, or its the same for a newly created user as well.

3. In case the issue still persists, you're welcome to share temporary admin login details, along with the link to the form page.

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

regards,
Waqar

#1576577

Hi Matt,

Thank you for sharing further details.

During testing on my own website with a similar form and custom code, I was able to note the following points:

1. First, I noticed that the "user-role" field slug, is missing "wpcf-" prefix in the code snippet:

The updated code snippet should be:


add_action('cred_save_data', 'yls_update_user_profile',10,2);

function yls_update_user_profile($user_id,$form_data) {
    // if a specific form
    if ($form_data['id']==1016)
    {
        $user_role = $_POST['wpcf-user-role'];   
     
    wp_update_user( array( 'ID' => $user_id, 'role' => $user_role ) ); 
    }
}

2. The roles of the slugs of the custom roles will need to be updated, in the "User Role" field's settings, so they match what is saved in the backend:

Screenshot: hidden link


Old values  ---> New values
BackOffice  ---> backoffice
DispatcherL1  ---> dispatcherl1
Customer  ---> customer

3. Even after making the above changes, while editing some specific users through this form, you'll see this error message:
"This form can not edit users with a role of"

It means that an incorrect user role has been assigned to that user already and you'll need to delete that user and add him/her again, to fix this.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar