1

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

1

3 Answers 3

0

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.

0

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.

0

If you want to create a role with the exact same capabilities as an admin you can do the following:

$admin_capabilities = get_role('administrator')->capabilities;

add_role('custom_administrator', 'Custom Admin', $admin_capabilities);

Or inline:

add_role('custom_administrator', 'Custom Admin', get_role('administrator')->capabilities);

Some Notes:

  • If you don't modify these copied capabilities from this custom user I would recommend you to just use the standard built-in role.
  • Ideally you would put this in a hook to be executed once; like in your plugin activate hook or something similar. (Even though the add_role() function only adds the role if does not already exists, no matter if the passed capabilities are different).
  • "I want this user to access all stuff in wp-admin panel". If you meant that you want the new role to be able to do anything to do with the administrator screen then I would copy the capabilities of the super admin role instead.

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.