【问题标题】:How to Show WP Plugin Menu for Editor User Roles in WordPress如何在 WordPress 中显示编辑器用户角色的 WP 插件菜单
【发布时间】:2017-07-18 13:01:53
【问题描述】:

我正在尝试为“编辑”角色显示我的插件菜单/选项页面, 但它没有出现。如何解决这个问题?谢谢。

这是我的代码:

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' );  
}

【问题讨论】:

    标签: wordpress user-roles


    【解决方案1】:

    您可以完全删除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' );
    

    【讨论】:

    • 感谢您花时间查看我的代码并提供反馈。我试图实现你的代码,但没有奏效。当我删除 if 时,它在管理员角色管理区域创建了一个新菜单。并且菜单仍然没有显示在编辑角色管理区域。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2016-11-13
      • 2014-07-14
      • 2021-10-22
      • 2013-04-13
      • 1970-01-01
      • 2016-01-10
      • 2011-08-19
      • 2018-11-28
      • 2012-09-06
      相关资源
      最近更新 更多