I am new to WordPress plugin development and i am stuck at why the wordpress function add_options_page()
is not accepting role.
This is my code which is not working
add_action('admin_menu', 'ct_admin_settings_page');
function ct_admin_settings_page()
{
add_options_page(
'CT Settings',
'CT Settings',
'Administrator',
'ct_admin_settings',
'ct_admin_settings_page'
);
}
but if i try the following, the menu appears (changing Administrator to manage_options),
add_action('admin_menu', 'ct_admin_settings_page');
function ct_admin_settings_page()
{
add_options_page(
'CT Settings',
'CT Settings',
'manage_options',
'ct_admin_settings',
'ct_admin_settings_page'
);
}
It is my understanding that the third parameter in function add_options_page
is ROLE so why Administrator which is a ROLE not being accepted?
Actually the third parameter of the
add_options_page()
function is acapability
which is different than arole
.Another way to think of it is to say, “A role can do these X number of things called capabilities. Some capabilities are ‘doable’ by several roles.”
Taking a look at the function signature from the documentation we can see they’ve defined the parameter name to be
capability
.I would take a look at this chart of Roles & Capabilities and choose a capability that only an Administrator would have (preferably one closely related to the feature you’re building in your plugin).
For example, I might choose
manage_options
(just as you’ve done) as it reflects fairly closely what you’re trying to buildct_admin_settings_page
to do.