Add a role and give admin priviledges

I am creating a Super Admin role in wordpress Roles.

$capabilities=array();
add_role('Administrator', 'Administrator', $capabilities ); 
add_role('Super Admin', 'Super Admin', $capabilities) ); 

So while adding a new user I got the Role Option Super Admin. So I added a Super User .

Now When I login to wp-admin It gives me error saying:

you do not have sufficient permissions to access this page.

What more I have to do to make it work. I dont want to use any pluggin.

I tried this too

add_role('Super Admin', 'Super Admin', 
array("manage_network","manage_sites","manage_network_users",
"manage_network_plugins","manage_network_themes","manage_network_options",
"read") ); 

and

  add_role('Super Admin', 'Super Admin', array("manage_network"=true,"manage_sites"=true,
"manage_network_users"=true,"manage_network_plugins"=true,
"manage_network_themes"=true,"manage_network_options"=true,"read"=true) );

I want this user to access all stuff in wp-admin panel

Topic user-roles capabilities users Wordpress

Category Web


But you can do all with code without any plugins.

For example, here are my class UserRoles which do that all and a bit more (maybe it's not perfect, but it works well). Just set const arrays with users & them caps (search them here). You can see roles 'dramatist' & 'free' as examples of new roles.


the best solution to change WORDPRESS role and capabilities is to use User Role Editor plugin. It is simple, very efficient and also give you power to add and modify both roles and capabilities.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.