【问题标题】:show only custom plugin menu for custom user role user using add role hooks使用添加角色挂钩仅显示自定义用户角色用户的自定义插件菜单
【发布时间】:2021-02-02 08:21:02
【问题描述】:

我在 functions.php 中为新用户创建了一个自定义用户角色,如下代码:

add_action( 'admin_init', 'add_custom_roles' );

function add_custom_roles() {

    $student = add_role( 'student', 'Student', array(
        'read' => false,
        'assignments' => true,
    ));

    if( null !== $student ) {
        $role->add_cap( 'assignments', true);
   }

} 

只允许访问student 角色以查看我的自定义插件页面:assignments 但它不起作用。自定义插件由add_menu_page hook 创建。

【问题讨论】:

    标签: wordpress plugins user-roles


    【解决方案1】:

    您正在接近您的目标,为了帮助您自己,您可以安装这个 (https://it.wordpress.org/plugins/members/),这使得功能处理更容易,然后调整设置以获得您想要的菜单可见性。

    您应该“克隆”进入后端所需的最低 WP 用户角色(如果我记得不错,应该是贡献者),然后添加您的自定义权限以访问插件页面

    【讨论】:

    • 但在这些插件中我无法获得我的插件功能。我想要这些通过使用函数代码而不是任何其他插件谢谢
    猜你喜欢
    • 2016-11-13
    • 1970-01-01
    • 1970-01-01
    • 2014-08-08
    • 1970-01-01
    • 1970-01-01
    • 2021-07-15
    • 2014-10-12
    • 1970-01-01
    相关资源
    最近更新 更多