2

If I add a custom page to the wordpress backend menu via

add_menu_page('My Custom Page', 'My Custom page', 'editor', 'custom_page','add_custom_page','dashicons-admin-comments',8);

only a user with editor privileges can see the page in its menu. How can I make this menu entry also available for users with administrator privileges? Have I to use add_menu_page() for every user role seperately?

1 Answer 1

6

Let's take a look at Codex page for add_menu_page...

Third param is:

$capability (string) (Required) The capability required for this menu to be displayed to the user.

And later on in Notes section:

This function takes a ‘capability’ (see Roles and Capabilities) which will be used to determine whether or not a page is included in the menu. The function which is hooked in to handle the output of the page must check that the user has the required ‘capability’ as well.

As you can see, you should use capability (for example manage_options, publish_posts) and not user role (editor, subscriber) as that param.

So if you'll pass publish_pages as third param, only Editor, Administrator, and Super Admin will get access to that page.

Here you can find list of default capabilities for default user roles.

1
  • Can I pass multiple capabilities?
    – Ravi Soni
    Commented May 19, 2023 at 5:52

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.