0

For example, I want to use add_menu_page() function to add a menu item to the dashboard. To control which users will be able to access it, I'm supposed to use capabilities...

<?php add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); ?> 

So, if I want to grant access to that menu page to - superadmin, admin, editor and author so that all users with one of these roles could access it, what am I supposed to put as $capability?

I'm looking at this table and as far as I figure, I should put one of these four as $capability:

  • edit_published_posts
  • upload_files
  • publish_posts
  • delete_published_posts

So if roles&capabilities haven't been altered via some plugin, picking one of these four should grant access to all the four roles just like I want it?

Is this the usual practise, or am I supposed to do it in some other way? Am I supposed to somehow add more than one capability into $capability, or is just one enough? If only one is enough, which one of these four would be the best choice, or it does not matter as long as roles are not altered to be different than default?

thank you

2 Answers 2

1

Not sure is that a rule or just something that happens to work that way, but most of function that take capability as argument also accept roles in same argument.

If I am not mistaken passing lowest role you want to grant access ('author') should work for that role and upwards. Please test before use.

2
  • if I do that the menu item is gone (for other roles), or if I try to manualy get to that admin page - I get "You do not have sufficient permissions to access this page." (in v3.0.3)
    – tkit
    Commented Dec 25, 2010 at 19:44
  • Hmm... I tried to create admin page with 'author' for capability and can access it just fine as admin. Don't have other roles set up to test at moment.
    – Rarst
    Commented Dec 25, 2010 at 20:45
0

In case someone needs a sollution - I just put 'publish_posts' as $capability parameter and it works as I thought it would - it gives you all the capabilitis that are below the one used (below publish_posts in my case)...

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.