Skip Navigation

[Resolved] “Can Only Edit Users with the Following Roles”

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

Problem:

I have a form set to modify users in the "subscriber" role. However, when submitting the form while logged in as a user in the "subscriber" role, I get the following error message: "You can only edit users with following roles".

Solution:

1) The edit user form needed to have the subscriber role set.

2) The user data was getting corrupted somehow when programmatically changing their role because there was a typo in the role name. This was causing the Toolset form to throw an error even once reverting the user back to the subscriber role.

Relevant Documentation:

This support ticket is created 5 years, 3 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 12 replies, has 2 voices.

Last updated by aaronM-9 5 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#1181017

I have a form set to modify users in the "subscriber" role. However, when submitting the form while logged in as a user in the "subscriber" role, I get the following error message: "You can only edit users with following roles".

The form was previously working but when I changed the user into a different role and then back to the subscriber role, the form stopped working. I'm a little stumped as to what it could be, but I'm sure it's something simple I'm overlooking. Can you offer any assistance? Thanks.

- Aaron

#1181290

Dear Aaron,

Thanks for the details, I am downloading the files, will update here if there is anything found

#1181323
subscriber.JPG

Here are what I found in your duplicator package:

I assume we are talking about the user form "User-Profile-Edit" (ID 250)
Since you did not point out the problem page URL, so I have tried these:
a) Create a new wordpress page, and put above form in the page content
b) Login as a Subscriber user, for example "callousthenics****@gmail.com" (userID 24)
c) Test above page in front-end, but I can not see the Toolset form "User-Profile-Edit", I see another form "Free Membership Options"
d) So I have disabled all other plugins except Toolset plugins, test again
e) I can see the user form "User-Profile-Edit", and submit it, it works fine without the problem you mentioned above, see screenshot subscriber.JPG

So it should be a compatibility problem of your website, since you are using 40+ plugins, you need to try these:
1) Deactivate all other plugins and test again
2) If the problem is fixed, then activate other plugins one by one, locate the problem plugin

If I am right, it is plugin "code-snippets", I have tried to deactivate that plugin, then the form works fine too, there might some custom codes producing the problem. please check it.

#1181469

Sorry, I had meant to include a link to the page I was experiencing the issue on. It is the "Free Membership Options" page, when submitting the form "User-Signup-Partner". I want the user's role to change upon submission of the form, so I had to write some custom code to do this. Perhaps there is something inside of that code. I will take a look. Thanks.

- Aaron

#1181519

I did some more looking into this and am still at a loss. Here are some updates / clarifying information for you:

-- The "User-Signup-Partner" form is not the one in question so please do not test using this one.
-- I tried deactivating Snippets and the problem still occurs.
-- I removed all custom code surrounding the handling of form 188 (the form in question) and the problem still occurs.
-- I removed all custom code surrounding the handling of post 20295 (the page where the form is displayed) and the problem still occurs.
-- I deactivated all plugins except Toolset and the problem still occurs.

Please note the form in question will only display if you have the subscriber role. You can test using username jdoe@fakewebsite.com and the same password I already gave you. Thanks again.

- Aaron

#1182029
subscriber19.JPG
subscriber17.JPG

Thanks for the details, since I am using "User Switching" plugin, so I don't need password to switch user:
https://wordpress.org/plugins/user-switching/

I have tried these with your duplicator package:
1) Deactivate all other plugins
2) Switch to user jdoe@fakewebsite.com, test the user form "User-Profile-Edit" in front-end, I can see the problem as you mentioned above:
You can only edit users with following roles

3) Then I have tried other subscriber users, for example:
****ssascott1220@gmail.com (userID 19)
****iteschner@gmail.com (userID 17)

All works fine, see screenshots, so this problem is only in the user jdoe@fakewebsite.com, the user's data might be broken, this is an exception problem.

I suggest you try to recreate user jdoe@fakewebsite.com, and test again

#1182273

Thanks - I will give that a try. I wonder if it's because I had tried to programmatically change their user role (since then I had manually switched it back to subscriber). Once the user takes a quiz I need it to change their role. Can you comment if this is the most appropriate way to change a user role?

  	$userid = get_current_user_id();
  	$user_info = get_userdata($userid);
  	$user_role = implode(', ', $user_info->roles);
  	if ($user_role == 'no_philosophy') {
	  $user = new WP_User($userid);
	  $user->set_role('subscriber');
	}

I realize this may be outside the scope of your support but thought it might be a quick answer. If I somehow damaged the user's data by trying to force the role change then it sounds like doing it in a more correct fashion would fix my current problem. Thanks.

- Aaron

#1183353

Dear Aaron,

I don't think those PHP codes will break , according to wordpress document:
https://developer.wordpress.org/reference/classes/wp_user/set_role/
WP_User::set_role( string $role )
Will be able to set the role of the user.

There might be other codes problem in your website, for your reference.

#1183735

Thanks for the help. I deleted the jdoe user and recreated their account, but the problem is still occurring. Can you confirm the following two things for me?

1) The "Role of the user to create/edit:" field on the user form sets the user's role upon successful submission.
2) Toolset Access controls whether or not a user in particular role can view the form.

I'm not sure why new users being created are causing this form not to work.

- Aaron

#1183845
User-Profile-Edit.JPG

Yes, both of them should be able to work.

How do you create the jdoe user and recreated their account?
Please provide detail steps for it, have you tried to deactivate plugins and theme?

I have tried your duplicator in my localhost, with below steps, please correct me if there is anything missing:
1) disable all other plugins, switch to wordpress default theme 2019
2) Dashboard-> Users, create a new "subscriber" user
3) Test the "User-Profile-Edit" in front-end,
It works fine, see screenshot User-Profile-Edit.JPG

#1184396
temp.png

Hi Luo,

I had already tried disabling all plugins and the issue was still occurring. I had recreated the John Doe account by deleting the user and then signing up from the front-end of the website. I have now also tried creating a user manually and setting their role to subscriber. The form still gives the same error message.

The screenshot you provided in your reply is not the correct form. Please use the form at /private-page/free-membership-options (see screenshot). Thanks.

- Aaron

#1184804

In the URL "/private-page/free-membership-options", there are two different forms, see your own screenshot:
hidden link

I have tried them both with a new subscriber user:
1) submit the first form "Option 1: Link Me to My Partner's Account"
it redirect me to URL:
hidden link
There isn't the text "You can only edit users with following roles".

2) Submit the second form "Option 2: My Partner Does not Have an Account", I can see below error message:

Your account was not updated because of the following problem:
This form can not edit users with a role of subscriber

Is it the same problem as you mentioned above? can you confirm it?

If it is, please edit above form "user-signup-free-master" in admin side,
hidden link

in section "Role of the user to create/edit", you can enable option "Subscriber", and test again. and it works fine in my localhost.

#1185144

Okay I was able to resolve the issue. There was a combination of issues happening:

1) The edit user form needed to have the subscriber role set.
2) The user data was getting corrupted somehow when programmatically changing their role because there was a typo in the role name. This was causing the Toolset form to throw an error even once reverting the user back to the subscriber role.
3) The only way to get rid of the problem entirely (given points 1 and 2 above) was to delete and recreate the account entirely.

I fixed both issues and now the problems has gone away. Thanks for the help.

- Aaron

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