• Using 1.10.5. Apologies if this is fixed in a later version.

    In wpDirAuth’s “Add Dir Auth User” page on the network admin panel, you are presented with a list of all of the network’s blogs and the default user role to give to the user. This list appears to use the default WordPress user roles, and shows them even for sites without these roles. The list should instead show the available user roles per-blog, and pre-select the default user role for each blog (defined in its options).

    Currently I guess the tool will try to put the user into non-existent roles on blogs where these roles don’t exist. I don’t know if this actually works, or throws an error, but it’s definitely wrong.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Paul Gilzow

    (@gilzow)

    The plugin uses the WordPress function wp_dropdown_roles to display the list of roles in that screen, so in your case, WordPress isn’t seeing your custom roles, or roles you have removed.

    Are you using a plugin to modify roles, or code inside a theme’s function file?

    Selecting the default role from a site isn’t a bad idea, though it’s a bit more complex in a mulsite instance. Might add that to a future release.

    Thread Starter Sean Leavey

    (@seanleavey)

    Hmm, but isn’t that function just listing the roles available on the primary site, not the site being listed? Don’t you have to call e.g. set_current_blog before each call to wp_dropdown_roles?

    Yes I’m using a plugin which has modified roles on one blog on my network. This network does not have the default “Admin”, “Editor”, “Author”, etc., yet these are still shown in the dropdown box for that blog.

    Plugin Author Paul Gilzow

    (@gilzow)

    Hhhhhmmmm…. good point. I see what you’re saying now. Though, running switch_current_blog for every site in a large multisite in the edit screen and then in the save section is going to introduce a distinct performance issue… The WP_Roles class takes a siteid as a parameter in its constructor, and has a for_site method but both of those are available only as of version 4.9. So I could do it for sites that are on 4.9 or later. For versions before v4.9 I’d essentially have to recreate what they added to WP_Roles. And doing it this way won’t fire the editable_roles filter for that child site.

    Actually, can you do me a favor? For the site that has roles removed, can you get the option_value for the key wp_<blog_id>_user_roles from the table <wp_prefix>_<blog_id>_options (e.g. wp_2_options) ?

    I’m betting it will contain _all_ of the roles, including the ones you have removed for that site.

    Thread Starter Sean Leavey

    (@seanleavey)

    It only contains the new ones:

    print_r(array_keys(get_option('wp_22_user_roles')));

    gives

    Array ( [0] => administrator [1] => subscriber [2] => researcher [3] => intern [4] => excluded )

    Some plugins remove the default roles and replace them with their own. WordPress does not enforce that the default ones are kept; indeed it looks up the database to get the current roles and the default since they can change.

    Plugin Author Paul Gilzow

    (@gilzow)

    Some plugins remove the default roles and replace them with their own.

    Right, which is where the editable_roles filter comes into play. I can update the plugin to include all of the roles assigned for a child site (or whatever currently exists in the options table for the site) but I won’t be able to trigger a child site’s plugins to apply the editable_roles filter.

    I can adjust the plugin so it shows all of the available roles for a child site (and now that I know about this issue, I will), but I don’t know of a good way to have it show a limited set of roles that are affected via a plugin. Does that make sense?

    Thread Starter Sean Leavey

    (@seanleavey)

    Seems like showing all available roles makes the most sense. It’s up to site admins to ensure they add users to the intended group when they add a directory user.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Available user roles are not respected when adding new user’ is closed to new replies.