0

My WordPress site has gone through several membership plugins over the years and with each change I've created new custom user roles. I found out this morning through troubleshooting another problem (Thanks, Prasad K), that even though I delete a role and reassign the user to a new role that the capabilities of the prior role may remain.

For example, one of my users shows this in their wp_usermeta : 'a:2:{s:10:"subscriber";b:1;s:8:"new_lead";b:1;}'

I have not had a subscriber role for at least 4 years. Other users have many more additions that don't exist.

What’s best practice for removing these excess capabilities from users when the roles no longer exist?

Edit:

Unfortunately User Role Editor is not able to see the roles/capabilities. Both the free and paid version do not help. Any other suggestions?

Thanks

Brad

1 Answers1

0

Update

Download User Role Editor

Add the Subscriber role. Then goto users and update the users with subscriber to the role that you want to change them too.

Refer to this link for a detailed way to change the user roles.

Alternatively

You can edit the roles via phpmyadmin. Have a look at this link, specifically the answer to getting the sql query for modifying the role and then we just have to make a foreach() loop via funtions or a more advanced SQL query to run in phpmyadmin for each user with the capability of "subscriber" to your desired alternate role. Note: A backup of the database should be done before any changes!

Aliqua
  • 723
  • 7
  • 21
  • HI @Aliqua, Unfortunately remove_role() doesn't work. When I display all roles with something like the code below. Subscriber etc does not appear. `global $wp_roles; $roles = $wp_roles->roles; // print it to the screen echo '
    ' . print_r( $roles, true ) . '
    ';`
    – Brad_Clarke Aug 08 '20 at 10:42
  • Hey @Aliqua. I've reached out to User Role Editor and I'm waiting on a reply. I'm skeptical, I don't think the plugin is going to recognize the roles as they don't show up in the footer.php script above. I'll follow up when I've received a reply. – Brad_Clarke Aug 08 '20 at 14:51
  • Hey @Aliqua, User Role Editor got back to and said all versions of the plugin are capable of showing and deleting unused roles. Thanks for your help. – Brad_Clarke Aug 08 '20 at 19:16
  • My pleasure. Glad to have helped. Happy coding! – Aliqua Aug 08 '20 at 22:28
  • Hey @Aliqua. I tried both the free and licensed version of User Role Editor and neither are able to help. Any other suggestions? – Brad_Clarke Aug 09 '20 at 19:20
  • Hey @Aliqua, User Role Editor followed up with me. He said "If a role is deleted from the array before it is revoked from the user, that wordpress looks at it as a capability granted to the user directly, and not via role". That explains it, cause that's what I did. I thought deleting the role would also remove capabilities from the user. He said user role editor will remove the capability, but I'll need to go user by user. Luckily I only have to do it 1300* times :) . I follow up later this morning after I've tested a single user. Thanks! – Brad_Clarke Aug 10 '20 at 09:32
  • Cheers mate. I'd refer to my updated answer re: do an SQL query, find the generated query line to edit the 'subscriber', then ask a new question re how to bulk edit. Wish you all the best! – Aliqua Aug 10 '20 at 10:30
  • Thanks @Aliqua, I appreciate the help! – Brad_Clarke Aug 10 '20 at 10:41
  • Have a look at https://stackoverflow.com/questions/14290857/sql-select-where-field-contains-words – Aliqua Aug 10 '20 at 12:17