16

My network is showing roles in some sites and not in others.

For some reason that I can't explain, when I add a new user, I have no roles to choose from in the drop down box of a sub-site in my network. Also, my new user assigned to a site is not showing on my list of users for that site.

Is this something fixable?

Below an image of the current situation.

Roles not Showing

Below is the picture showing the main site with the roles properly there, but the sub-sites of the network don't.

Roles showing

0

7 Answers 7

33
  1. Determine your Multisite Blog ID. I will use 99 as an example
  2. Go into the database
  3. Go to this table: wp_##_options (wp_99_options) — you will have a table for each blog
  4. Find the record where option_name = wp_user_roles
  5. Change the text wp_user_roles to wp_##_user_roles ("wp_99_user_roles")

The table you are editing will have option_id, blog_id, option_name, option_value, autoload. However, DO NOT CHANGE ANY RECORD except the record where option_name = wp_user_roles. There will only be a single record in this table like this.

wp_user_roles is used when there is no Multisite install, and here, it appears as though it was just a bug when the table was created.

7
  • Thank you! Life-saving advice here. This is EXACTLY the right answer.
    – ZaMoose
    Commented Sep 17, 2011 at 16:48
  • 1
    I had NO "wp_user_roles" in my table, what I did was copying the content of wp_4_options>wp_user_roles (a large json object or a serialized array, I dunnow) to a new record called wp_5_options (this was the blog missing roles) and it fixed my problem. Voted +1 nonetheless because it put me on the right track
    – Xananax
    Commented Dec 15, 2011 at 15:09
  • I resolved also REMOVING the record "wp_##_user_roles" from the main wp_options table, because it seems to override the one from wp_##_options.
    – Paolo
    Commented Feb 19, 2013 at 9:36
  • 1
    Brilliant answer!
    – jnthnclrk
    Commented Aug 26, 2013 at 15:36
  • 7
    For people who have migrated your site and changed prefixes, the error could be a "wp_##_user_roles" instead of "{new_prefix}_##_user_roles"
    – Xhynk
    Commented Nov 17, 2014 at 21:59
4

I had this problem with a Multisite installation after reinstalling WordPress and restoring from an Updraft Plus backup.

When I checked the user_roles record, the option_name was still set to the original four character prefix, such as pre1_user_roles, whereas the prefix for the second installation was something like pre2_user_roles.

I updated this to pre2_user_roles and the options immediately reappeared in the user options page.

2

If this is the problem I know so well, you are running a memcache setup behind your MU install? I've found that there's apparently a cache issue (witnessed in 2.9) for the options object where something good (like the wp_user_roles key) gets stuck in the "notoptions" memcache array.

If you do run atop memcache, and this sounds like a possiblity, try telnetting into the machine via 11211. Type delete blogid:options:notoptions, where the blogid is the id of the blog on which you see the issue. Refresh the admin panel and see if there are roles in the dropdown. If so, you've found your problem.

UPDATE: OK, so you did not find your problem -- you weren't running memcache. I would still check out the roles object, looking for a corrupt or non-existant one. I believe it's your best lead. You can use this code to dump the options table:

global $wpdb;
$array = $wpdb->get_col("SELECT option_name FROM $wpdb->options");
foreach ($array as $key) {
    echo $key . ": <code>";
    var_dump(get_option($key), true));
            echo "</code><br/>";
}
2
  • Editor. I don't know how memcache got into my server. I am not using it at all. Maybe because I installed w3 cache. I tried the delete it gave me a message saying not_found. I went ahead and disabled the memcache, since I am not using it. I am still having the issue.
    – Geo
    Commented Mar 11, 2011 at 2:50
  • I'm sorry that wasn't a solution to your problem. I run into this one a lot so it was my best guess. I would keep looking into the roles object for that blog. Does it exist? Updated my answer above in hopes it will help.
    – editor
    Commented Mar 11, 2011 at 18:24
2

THANK YOU. This issue represents a solid 10 hours of debugging. This was a real bear for me.

To expand on this a bit, I added a function to my site that will allow you to resolve this issue if you're creating sites programmatically.

Basically, this will check to see if wp_user_roles was set in the specified blog. If it is, the function will use wp_user_roles to set a new option in the correct manner.

  /**
   * Sometimes, user roles do not properly get set when a new site is set up
   * To fix this issue, we check to make sure the data is added properly and update if not
   * See https://wordpress.stackexchange.com/questions/11725/why-are-my-roles-not-visible-in-a-multi-site-network
   */
function maybeAddUserRoles($blog_id){
    switch_to_blog($blog_id);
    if(get_option('wp_user_roles')){
      update_option('wp_'.$blog_id.'_user_roles', get_option('wp_user_roles'));
      delete_option('wp_user_roles');
    }
    restore_current_blog();
  }
0

I just wanted to say thank you for this article because I've been searching for a solution to this problem for a long time.

It was simply because I had used a plugin to clone my sites and it never updated the wp_##_user_roles properly. When the site copied over from wp_13... it was cloned over to a new site wp_81... but this entry was still stuck at wp_13.

0

I just want to point out that some people may still have an empty site users table—specifically for their root site. If this problem occurs, the way to fix it issue is by doing the following:

  1. Go to the table wp_usermeta
  2. Find any entries with the meta_key wp_capabilities
  3. Change the meta_key from wp_capabilities to wp_1_capabilities

I believe "1" is always the ID of the root site.

Cheers.

1
  • The wp_ prefix is set sinde wp-config.php and just defaults to wp_. The 1 indeed is the root site. But it does not have to be 1 as this is a unique and incrementing ID that is auto generated.
    – kaiser
    Commented Jul 21, 2016 at 19:05
0

Install this plugin: https://wordpress.org/plugins/capability-manager-enhanced/

Go into your site > Capabilities > Settings > Backup > Reset Roles, click "Reset to WordPress Defaults" and it will fix your site.

Nothing else worked for me.

Your Answer

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

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