Why are my roles not visible in a Multi-site/Network?

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.

Read More

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

Related posts

Leave a Reply

7 comments

    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.

  1. 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/>";
    }
    
  3. 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();
      }
    
  4. 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.

  5. 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.