2017-07-17 75 views
0

我试图为“编辑器”角色显示我的插件菜单/选项页面,但它不显示。如何解决这个问题?谢谢。如何在WordPress中显示编辑器用户角色的WP插件菜单

这里是我的代码:

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

回答

0

可以删除if完全。 (双方) 你不需要太多检查manage_options因为你已经检查delete_others_pages
更多信息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'); 
+0

感谢您花时间查看我的代码和您的反馈意见。我试图实现你的代码,但它没有奏效。当我删除if时,它在管理员角色admin区域创建了一个新菜单。菜单仍然不显示在编辑角色管理区域中。 – jojoi

0

谢谢大家,我只是解决了这个问题。 在这种情况下,我想将插件主菜单&子菜单显示为管理员角色。编辑角色只能访问主菜单。 关键是将主菜单功能设置为编辑功能,例如“moderate_comments”,这样管理员和编辑人员都可以访问此主菜单。

对于子菜单,将能力设置为“manage_options”。这样,只有管理员才能看到这个子菜单。 查看此表格: https://codex.wordpress.org/Roles_and_Capabilities

相关问题