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!
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.
You should use capabilities in
add_menu_page
andadd_submenu_page
, foradd_menu_page
userread
capability, for Administrators only sub-pages usemanage_options
cap and for Subscribers sub-page you can userread
cap too or add new cap if you don’t want administrators see that page ( for capabilities easy management use Members Plugin )The correct way is to use capabilities, for example i have added one called “my_plugin” and check into the client role, so the client will see the menu with my_plugin capabilitie…for example:
So then you go to Users->Roles, edit your role and check the my_plugin option, and those users will see the menu.
This is correct way and will be easy to use and update.
I may be late but here goes:
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:
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.