Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
Ah.. I see, thanks. Makes more sense now –  Baig May 14 at 12:27
1  
In practice capability checks (current_user_can()) in WP accept roles too. The actual issue here is case sensitivity, administrator would work. –  Rarst May 14 at 15:05

While WP commonly accepts roles in capability checks (notably often recommended against) it is case-sensitive and should be in lowercase:

var_dump( current_user_can( 'administrator' ) ); // bool(true)
var_dump( current_user_can( 'Administrator' ) ); // bool(false)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.