2

Is it possible to specify two usergroups (e.g. admins and editors) into the admin menu capability field ? I tried the following but it doesnt work:

add_submenu_page(
     'my-top-level-handle',
     'Page title',
     'Sub-menu title',
      array('administrator', 'editor'),
     'my-submenu-handle',
     'my_magic_function'
);

error message:

Warning: Illegal offset type in isset or empty in C:\wamp\www\wordpress\wp-includes\capabilities.php on line 712

  • 2
    You're not suppose to pass a role(or roles) to the capability parameter. Give it a capability only editors(or above) have and the page will be available to both admins and editors. – t31os Mar 30 '11 at 15:57
  • @t31os Please stop posting your answers into comments or I cannot give you the rep that you deserve. :) – fuxia Mar 30 '11 at 22:12
  • @toscho - Sometimes i just intend to comment and answer without even realising, i'm just too impatient to think before i click that button... sorry.. :) – t31os Mar 30 '11 at 22:28
5

Capability parameter of add_submenu_page() function can only take a single capability, so if you are using the built in roles you can select a capability fro the long list that both administrators and editors have any of these (use any of these freely):

  • moderate_comments
  • manage_categories
  • manage_links
  • unfiltered_html
  • edit_others_posts
  • edit_pages
  • edit_others_pages
  • edit_published_pages
  • publish_pages
  • delete_pages
  • delete_others_pages
  • delete_published_pages
  • delete_others_posts
  • delete_private_posts
  • edit_private_posts
  • read_private_posts
  • delete_private_pages
  • edit_private_pages
  • read_private_pages
1

As t31os said, you can use capabilities instead of roles there. One way to do this is to use core capabilities. (A more advanced method is to add a custom capability to the roles of your choice.) The default caps are in wp-admin/includes/schema.php in the functions called by populate_roles().

If you are using standard roles/caps, you can specify only admins and editors by the cap level_7 or edit_others_posts or several others.

  • level is deprecated for years. It may be dropped in the near future. – fuxia Mar 30 '11 at 22:14

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.