6

I was just adding a custom role by using the add_role() function. Here is the code below:

add_role('user', 'User', array('read'));

I figured this would give the same level of access as the subscribers role. Technically I want them to be the same but I don't want to use the subscribers as a role for certain users because there will be different access between the two.

However, although, from what I read on the wordpress codex site, the subscribers has only one capability and that is to 'read' it has access to the dashboard and can edit their own profile. My custom role cannot. I get the following message when going to the admin panel.

You do not have sufficient permissions to access this page.

Why is that? Hoe do get the right permissions to do this?

Thanks, Joe

1 Answer 1

12

You have to give the capability a true or false, like this:

add_role('user', 'User', array( 'read' => true ));

To fix it, first remove the role and than re-add it again.

remove_role('user');
add_role('user', 'User', array('read' => true));

http://codex.wordpress.org/Function_Reference/add_role

2
  • Thanks Rob. Sorry I actually did set the capability to true on my second attempt at trying to resolve the issue. I just edited it a few times and went back to how I had it before. I guess because I screwed up the first time I had to remove the role and re-add it for it to register. Before when I changed 'real' => true, I guess it wasn't saving because the role was already created as array('real') from a previous attempt.
    – JoeMoe1984
    May 9, 2013 at 16:55
  • The addition of remove_role was the fix for me - it must cache the capabilities. After confirming it all works, I was able to remove it.
    – Smithee
    Mar 27 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.