ThemeForest

User Roles and Capabilities

204 posts Bold WordPress Theme Development
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Interviewed on the Envato Notes blog
  • Exclusive Author
  • Sold between 250 000 and 1 000 000 dollars
  • Elite Author
  • Bought between 1 and 9 items
  • Europe
  • Referred between 200 and 499 users
srhnbr says

Hey everyone. I’m working on displaying certain (WordPress) custom admin pages to certain WordPress users based on their roles (Admin, Editor etc)

So I assigned submenu 1 to the Admin and submenus 2 and 3 to the Editor.

add_submenu_page( $parent_slug, $page_title, 'submenu 1', 'administrator', $menu_slug, $function ); 

add_submenu_page( $parent_slug, $page_title, 'submenu 2', 'editor', $menu_slug, $function ); 

add_submenu_page( $parent_slug, $page_title, 'submenu 3', 'editor', $menu_slug, $function ); 

Well, this is what happens: The Editor sees submenus 2 and 3 so that’s good but the admin sees only submenu 1! I thought that the admin would be able to see submenus 1, 2 and 3! It looks I was wrong in thinking this.

What would you suggest I do so that the admin sees all 3 submenus while the editor sees only those menus assigned to him?

1 year ago
2389 posts Put a Donk On It
  • Has been a member for 2-3 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Tutorial to a Tuts+ Site
  • Interviewed on the Envato Notes blog
  • Beta Tester
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 10 and 49 items
  • United Kingdom
  • Referred between 50 and 99 users
ThemeProvince says

Use conditionals like so:


if (current_user_can('manage_options')) :

add_submenu_page( $parent_slug, $page_title, 'submenu 1', 'level_7', $menu_slug, $function ); 

add_submenu_page( $parent_slug, $page_title, 'submenu 2', 'level_8', $menu_slug, $function ); 

add_submenu_page( $parent_slug, $page_title, 'submenu 3', 'level_9', $menu_slug, $function ); 

else:

add_submenu_page( $parent_slug, $page_title, 'submenu 2', 'level_8', $menu_slug, $function ); 

add_submenu_page( $parent_slug, $page_title, 'submenu 3', 'level_9', $menu_slug, $function );

endif;

If that doesn’t work change level_7, level_8 & level_9 to something else like level_10.

1 year ago
246 posts
  • Has been a member for 1-2 years
  • Exclusive Author
  • Bought between 1 and 9 items
  • Austria
  • Referred between 1 and 9 users
infuse01 says

@ThemeProvince are you sure that conditionals are needed? wouldn’t it work like this:

add_submenu_page( $parent_slug, $page_title, 'submenu 2', 'manage_options', $menu_slug, $function ); add_submenu_page( $parent_slug, $page_title, 'submenu 2', 'edit_posts', $menu_slug, $function );
1 year ago
2389 posts Put a Donk On It
  • Has been a member for 2-3 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Tutorial to a Tuts+ Site
  • Interviewed on the Envato Notes blog
  • Beta Tester
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 10 and 49 items
  • United Kingdom
  • Referred between 50 and 99 users
ThemeProvince says

@infuse01 – Your method is what I first thought of. But its kinda too similar to her code hence i just gave the next best thing.

1 year ago
246 posts
  • Has been a member for 1-2 years
  • Exclusive Author
  • Bought between 1 and 9 items
  • Austria
  • Referred between 1 and 9 users
infuse01 says

Hm ok, maybe its due to the old user roles (administrator, editor)...however I just tried it out and both attempts working perfect – possibly only a matter of taste which attempt to choose of

1 year ago
204 posts Bold WordPress Theme Development
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Interviewed on the Envato Notes blog
  • Exclusive Author
  • Sold between 250 000 and 1 000 000 dollars
  • Elite Author
  • Bought between 1 and 9 items
  • Europe
  • Referred between 200 and 499 users
srhnbr says

Thanks guys! So you would suggest not to use the “roles” (administrator, editor, etc) but rather the “capabilities” (manage_options, etc), right? I’ll give it a go and update this thread

@ThemeProvince: I think I’ll stay away from level_8 etc because of this: http://codex.wordpress.org/User_Levels don’t you think?

1 year ago
653 posts
  • Has been a member for 3-4 years
  • Bought between 1000 and 4999 items
  • Canada
  • Referred between 1 and 9 users
chrismccoy says

Hey everyone. I’m working on displaying certain (WordPress) custom admin pages to certain WordPress users based on their roles (Admin, Editor etc)

So I assigned submenu 1 to the Admin and submenus 2 and 3 to the Editor.

add_submenu_page( $parent_slug, $page_title, 'submenu 1', 'administrator', $menu_slug, $function ); 

add_submenu_page( $parent_slug, $page_title, 'submenu 2', 'editor', $menu_slug, $function ); 

add_submenu_page( $parent_slug, $page_title, 'submenu 3', 'editor', $menu_slug, $function ); 

Well, this is what happens: The Editor sees submenus 2 and 3 so that’s good but the admin sees only submenu 1! I thought that the admin would be able to see submenus 1, 2 and 3! It looks I was wrong in thinking this.

What would you suggest I do so that the admin sees all 3 submenus while the editor sees only those menus assigned to him?

have a look at this

http://sethstevenson.net/customize-the-wordpress-admin-menu-based-on-user-roles/

1 year ago
by
by
by
by
by