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?

2 Answers
2

Your understanding is incorrect. The third parameter to the add_options_page() function is Capability, not Role.

This is made clear by the function’s prototype:

function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = '' )

manage_options is a Capability. Administrator is not.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *