Add custom role across network in multisite

Maybe this is a duplicate of Add role across network in multisite, but the answers there are not conclusive so I’m asking again. Any help would be deeply appreciated.

I’m trying to add two new custom roles on a multisite installation. I have written a plugin, installed it and enabled it across the whole network, and the new roles are added by this plugin’s activation hook.

Read More

There, I simply do

add_role('x', 'Description of X', $capabilities_array);
add_role('y', 'Description of Y', $capabilities_array);

Then, I try to create a new “child” site, add a new user to it, and then apply one of the custom roles to that new user. The custom role appears at the roles dropdown list, but when I try to apply the role to the user, I get an error saying “You can’t give users that role”.

I searched a lot over the internet and found that the roles and capabilities are stored under the user_roles option in the options table. However, I noticed only the options table of the root site has the custom roles I added. I suspect this is the cause of the error I get.

But then, how do I go around this? Is there a way of creating new custom roles which are visible and can be applied to every “child” site, even to the new ones I possibly add in the future?

My ultimate intention is to customize the dashboard and menu options of each site/user based on its custom role.

Ideally, I’m looking for a solution without any extra plugins involved, as this is going to be part of a services platform I’m willing to provide.

Thanks in advance.
Arnaldo

Related posts

Leave a Reply