0

So, I just created a new plugin and i've added capabilities, a new role, linked them all together, etc.. etc.. but for some reason I'm unable to access my own backend.

Error message is the generic

You do not have sufficient permissions to access this page.

Code to create the Menu on the backend

add_menu_page(
    'FOO Profile',                // Link Text
    'Manage your FOO profile',    // Title
    'foo-profile',                // Capability (rights)
    'foo-profile',                // Slug
    [$this, 'renderFooProfile']   // Callback for Link
);

This link is VISIABLE to me inside the admin area. I did the following check just to verify on top of this:

var_dump(current_user_can('foo-profile')) => int(1)

Now once i click the link i get the above-mentioned error message.

The rendering is a simple hello world echo, so I doubt the error is to be found there either :S

public function renderFooProfile() { echo "Hello World"; }

Any pointers as to where I'd have to look would be greatly appreciated.

Gist of the whole class > https://gist.github.com/anonymous/b4f69e203630f447677b

2

1 Answer 1

1

You're using the admin_init hook to add menus - use admin_menu instead.

The init hook runs early enough for wp-admin/menu.php to add it to the sidebar menu, but not for the plugin page loading in wp-admin/admin.php

In other words, when you actually try to load the plugin page, your menu code hasn't fired and WordPress fails with that rather generic error.

2
  • Too simple Xx Thank you a lot. Could you elaborate as to why the menu is still displayed using admin_init but then being inaccessible?
    – Sam
    Commented Mar 2, 2015 at 12:30
  • 1
    Check revision. Commented Mar 2, 2015 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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