1

Just trying to create a simple plugin with some Theme Options so I can practice. When I try to access the Theme Options page under Settings... I get the: You do not have sufficient permissions to access this page.

This is all I have in the plugin:

add_action( 'admin_menu', function(){
    add_options_page( 'Theme Options', 'Theme Options', 'administrator', __FILE__, function(){
        echo 'Hello';
    });
});

Here are the parameters from the WordPress codex:

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

I am the admin. Tried creating another admin account, same result. Tried setting the slug parameter to a different slug, same result. I'm using WAMP on my local machine.

Any ideas? I came up short when trying to search for this issue when using WAMP on a local machine. Any help would be great.

0

administrator isn't a capability, it is a role, so the reason you get that error is because WordPress doesn't recognizes the capability you gave.

If you look up the capabilities of the administrator role, you can see that the administrator is the only one with the capability manage_options. This is the one you should use.

So what you can do is change the capability to manage_options:

add_options_page( __( 'Theme Options' ), __( 'Theme Options' ), 'manage_options', __FILE__, function() {
    echo 'Hello';
} );

Hope it helps!

2
  • manage_options also didn't work. I believe it has something to do with setting FILE as the slug. When I change it to js_options.php ... it works. I'm still curious as to why FILE wouldn't work though? – Josh Dec 18 '12 at 14:47
  • I think because the menu-slug has to be unique, when you use __FILE__, it never will be an unique filename, because it already exists. – Mike Madern Dec 18 '12 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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