26

I got on the list to test a private beta of a plugin I'm using on a multisite network.

The plugin authors have code in there to add a custom role. They have a bug that removes the ability to give a user any role except their one custom role.

When I visit ../wp-admin/network/site-users.php, the "Add User" role pulldowns only show the one role this plugin added. The change role pulldown menu shows all the WP default roles, plus a few extra roles this and other plugins have added. If I attempt to change a user to one of these roles, I get a "You can't give users that role" error page.

I've been discussing this with the developer, and they seem baffled.

I've been looking through my database and the codex, and I can't find where the valid roles are defined.

2 Answers 2

46

User roles are stored in wp_options table.

search for option name wp_user_roles in the wp_options table.

3
  • 2
    Please note that the option_name may contain your DB prefix instead of wp_. This was the case for my database.
    – Eric K
    Jan 7, 2021 at 23:02
  • 1
    Might also have a blog id if you're on multisite, eg "wp_37_user_roles". Jul 1, 2021 at 13:55
  • 1
    Yes, if you're on multisite and have a blog ID, the table AND the option_name would include the blog ID. So use e.g. this query: select * from wp_37_options where option_name = 'wp_37_user_roles'; Nov 2, 2021 at 20:43
25

User Roles are stored in table wp_user_meta

To check user roles, first, check out the user id in the table wp_users (Column name ID)

Now Go to table wp_usermeta and search where column user_id is equal to the ID that matches ID from wp_users table.

You will get a list of rows with metadata of the chosen user, the row with meta_key as wp_capabilities defines the user role.

The Value of wp_capabilities for

  • Admin : a:1:{s:13:"administrator";b:1;}
  • Woo Commerce Customer : a:1:{s:8:"customer";b:1;}
4
  • 3
    Your answer relates to the assignment of a role to a user. The OP was asking about the role definitions themselves, which are stored in wp_options. Oct 1, 2019 at 3:06
  • 2
    that a:1:{s:13:"administrator";b:1;} is kind of a messy string, what's all the fluff numbers around the meat? May 31, 2021 at 13:37
  • 2
    @Johnny Rockex That is serialised data a way to store more than one value in a database cell... often frowned upon to an extent, as it can make life more difficult. The "s" stands for "string" (of 13 character) the "b" is for Boolean - Google Data Serialisation in MySQL for details. Jul 27, 2021 at 16:42
  • @mayersdesign I can understand the frowns, my gut would lean towards restructuring the tables to have single values in each field, but who knows, it works. Jul 28, 2021 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.