【问题标题】:show custom plugin menu for custom user role user in wordpress在 wordpress 中为自定义用户角色用户显示自定义插件菜单
【发布时间】:2016-11-13 10:25:55
【问题描述】:

我正在创建新用户角色“test_client”,它正在工作,但我的问题是我只想在仪表板中显示我的自定义插件页面菜单,但在此代码中,“manage_options”为“true”,然后所有插件菜单显示,如果“ manage_options" 是 'false' 不显示任何插件菜单..

$result = add_role('test_client', 'Test_client', 
    array(
    // Dashboard
    'read' => true, // true allows this capability
    'edit_posts' => true, // Allows user to edit their own posts
    'edit_pages' => true, // Allows user to edit pages
    'edit_others_posts' => false, // Allows user to edit others posts not just their own
    'create_posts' => false, // Allows user to create new posts
    'manage_categories' => false, // Allows user to manage post categories
    'publish_posts' => false, // Allows the user to publish, otherwise posts stays in draft mode
    'manage_options' => true,
    )
    );

那么如何在 wordpress 仪表板中仅显示自定义插件菜单

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    为您的插件菜单添加自定义功能

    $result = add_role('test_client', 'Test_client', 
        array(
        // Dashboard
        'read' => true, // True allows this capability
        'edit_posts' => true, // Allows user to edit their own posts
        'edit_pages' => true, // Allows user to edit pages
        'edit_others_posts' => false, // Allows user to edit others posts not just their own
        'create_posts' => false, // Allows user to create new posts
        'manage_categories' => false, // Allows user to manage post categories
        'publish_posts' => false, // Allows the user to publish, otherwise posts stays in draft mode
        'manage_options' => false,
    'custom_capability_name'=>true,
        )
        );
    

    之后添加

    $role= get_role('test_client');
    $role->add_cap('custom_capability_name');
    

    最后将您的管理菜单“manage_option”更改为“custom_capability_name”

    【讨论】:

    • 如果我更改 mangae_option 功能,而不是在管理员角色中显示
    • 您可以使用 wordpress 角色功能检查您的角色,并可以访问您的菜单中的角色访问权限
    猜你喜欢
    • 2021-02-02
    • 1970-01-01
    • 2019-11-20
    • 2014-10-12
    • 2019-03-25
    • 2021-06-09
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    相关资源
    最近更新 更多