0

I'm trying to show my plugin menu / options page for the "Editor" role, but it's not showing up. How to solve this ? Thank you.

Here's my code :

function jowct_add_plugin_for_editors(){  
  if (!current_user_can('manage_options')) {
    add_menu_page(
   'Menu Page Title', 
   'Menu Title',
   'delete_others_pages',
   'jowct-wpplugin-menu',
   'jowct_menu_option_page',
   'dashicons-admin-generic',
   '3',
  ); 
  }  
} 
if(is_admin()) {  
  add_action( 'admin_menu', 'jowct_add_plugin_for_editors' );  
}
jojoi
  • 23
  • 1
  • 10

2 Answers2

0

You can remove the if entirely. (both of them) You don't need too check for manage_options as you are already checking delete_others_pages
More info https://codex.wordpress.org/Roles_and_Capabilities

function jowct_add_plugin_for_editors(){  
    add_menu_page(
            'Menu Page Title', 
            'Menu Title',
            'delete_others_pages', //this will restrict access
            'jowct-wpplugin-menu',
            'jowct_menu_option_page',
            'dashicons-admin-generic',
            '3'  // this comma was incorrect syntax
        );
} 
// action admin_menu will only trigger in the admin, no need for the if.
add_action( 'admin_menu', 'jowct_add_plugin_for_editors' );
janw
  • 6,672
  • 6
  • 26
  • 45
  • Thanks for taking time to look my code and for your feedback. I tried to implement your code but it did not work. when I remove the if, it created a new menu on the administrator role admin area. And the menu still does not show up on the editor role admin area. – jojoi Jul 17 '17 at 23:53
0

Thanks everyone, I just solved this issue. On this case, I want to show the plugin main menu & sub menu to the administrator role. While the editor role only have access to the main menu. The key is to set the main menu capability to editor capability such as "moderate_comments", this way both administrator and editor can access this main menu.

For the sub menu, set the capability to "manage_options". This way, only administrator will be able to see this sub menu. Check out this table : https://codex.wordpress.org/Roles_and_Capabilities

jojoi
  • 23
  • 1
  • 10