WordPress add_options_page() function not considering role

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

Read More
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?

Related posts

Leave a Reply

1 comment

  1. Actually the third parameter of the add_options_page() function is a capability which is different than a role.

    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.

    <?php
    add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function);
    ?>
    

    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 build ct_admin_settings_page to do.