This is referring to a discussion I had on stack exchange
I was told
add_submenu_page('slug_of_your_parent_menu', 'my title', 'your menu title','<strong>administrator</strong>', 'submenu_slug', 'function_to_display_this_submenu');
was incorrect because I used a role ( ‘administrator’ ) instead of a Capability.
I referenced the codex examples which at the time used ‘administrator’ in place of $capability.
I was told that the codex was incorrect and that he changed it.
I am asking because I am working on plugin which uses ‘administrator’ and it is working without error thus far. Can someone confirm that it is improper to use a role?
Controlling access to functions by Role defeats the whole purpose of even having Capabilities. It is poor security practice.
Let’s say your plugin allows access to certain options to Administrators only. If a site owner needed his Editors to be able to change these options for some reason, he would be forced to make all Editors Administrators, causing all sorts of security issues with escalation of privilege.
If you instead allowed access to the same options to those with ‘Manage Options’ capabilities, the site owner could simply assign the capability to his Editors without compromising other security considerations.
Forget whether it’s proper or improper, or what other’s do, or if administrator works, even if it’s not supposed to; it’s simply good, responsible, adaptable coding to use capabilities instead of roles to control access to particular functions.
But you dont have to make it ‘administrator’ you can make it ‘subscriber’ or ‘editor’ so how does it make it insecure?
Also if that’s the case how do you give access to something for a subscriber but not an editor?
There are endless variations. I was just trying to illustrate why capabilities give site owners more flexibility in managing user privileges. As you can create any capability or role, or remove capability from any role, anything is possible, see the ‘Members’ plugin for an example.
Go ahead and use roles where you should be using capabilities if you want. While it currently works, it’s unsupported and can stop working with any update.
- The topic ‘Correct use of Roles and Capabilities with add_submenu_page()’ is closed to new replies.