关于php:在wordpress中为自定义用户角色用户显示自定义插件菜单

show custom plugin menu for custom user role user in wordpress

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

1
2
3
4
5
6
7
8
9
10
11
12
13
$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 仪表板中只显示自定义插件菜单


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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$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,
    )
    );

在那之后添加

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

最后将您的管理菜单 \\'manage_option\\' 更改为您的 \\'cusotom_capability_name\\'