Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am working on a plugin with 6 submenu pages. I want 5 of them to be accessible by Administrators only and 1 of them to be accessible by Subscribers only.

Both user roles will have different features available on their respective pages.

Is it possible to do that? If yes, how? If no, what are the alternatives?

Thanks for your time!

share|improve this question

3 Answers 3

up vote 1 down vote accepted

Is this right:
First 5 pages - Administrators ONLY, NO subscribers
Sixth page - Subscriber ONLY, NO Administrator ?

If this is correct than you only have to add the capability type as 'administrator' when creating the first 5, and 'subscriber' for creating the sixth. That should work. Or add a new capability for admin, use it while adding the first 5, and a new capability for subscriber, use it while adding the sixth.

share|improve this answer

You should use capabilities in add_menu_page and add_submenu_page, for add_menu_page user read capability, for Administrators only sub-pages use manage_options cap and for Subscribers sub-page you can user read cap too or add new cap if you don't want administrators see that page ( for capabilities easy management use Members Plugin )

share|improve this answer

I may be late but here goes:

function your_function_for_menus() { 

add_submenu_page('slug_of_your_parent_menu', 'my title', 'your menu title','administrator', 'submenu_slug', 'function_to_display_this_submenu');

add_submenu_page('slug_of_your_parent_menu', 'my title', 'your menu title','administrator', 'submenu_slug', 'function_to_display_this_submenu');

add_submenu_page('slug_of_your_parent_menu', 'my title', 'your menu title','administrator', 'submenu_slug', 'function_to_display_this_submenu');

add_submenu_page('slug_of_your_parent_menu', 'my title', 'your menu title','administrator', 'submenu_slug', 'function_to_display_this_submenu');

add_submenu_page('slug_of_your_parent_menu', 'my title', 'your menu title','administrator', 'submenu_slug', 'function_to_display_this_submenu');

add_submenu_page('slug_of_your_parent_menu', 'my title', 'your menu title','subscriber', 'submenu_slug', 'function_to_display_this_submenu');
}

This will create 6 submenus. Notice in the 6th one we have 'subscriber' instead of 'administrator' this will show that menu for subscribers ONLY not admins.

you then use:

add_action('admin_menu', 'your_function_for_menus');

this will run the function to create the submenus.

References: I was unable to post links due to anti-spam :(.

so google wordpress capabilities wordpress add_action wordpress add_submenu_page

they should explain everything.

share|improve this answer
    
Your answer is wrong. The add menu and submenu page functions use capabilities not roles. Administrator is a role manage-options, edit-posts etc are capabilities. –  Chris_O May 27 '12 at 8:37
    
Chris, it is perfectly valid and you can use roles, with-in the codex they even give an example using roles. codex.wordpress.org/Function_Reference/add_menu_page#Examples –  Kirill Fuchs Jun 7 '12 at 17:30
    
The codex was wrong! I just updated it. –  Chris_O Jun 7 '12 at 18:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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