Question

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

Was it helpful?

Solution 2

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)...

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top