为自定义用户角色创建管理员菜单和页面

时间:2015-12-02 02:54:20

标签: php wordpress user-roles

我正在制作一个具有自定义用户角色的自定义插件:

add_role('lln_assessor', 'LLN Assessor', array(

'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' => true, // Allows user to edit others posts not just their own
'create_posts' => true, // Allows user to create new posts
'manage_categories' => true, // Allows user to manage post categories
'publish_posts' => true, // Allows the user to publish, otherwise posts stays in draft mode
));

当我激活自定义插件时,将创建此角色。

现在,在记录的wp-admin或其仪表板中,如何创建自己的菜单和页面?

1 个答案:

答案 0 :(得分:0)

此处,custom_cap是添加到新角色的自定义功能,在添加新管理菜单时,会添加此功能。

  add_role('lln_assessor', 'LLN Assessor', array(

    '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' => true, // Allows user to edit others posts not just their own
    'create_posts' => true, // Allows user to create new posts
    'manage_categories' => true, // Allows user to manage post categories
    'publish_posts' => true, // Allows the user to publish, otherwise posts stays in draft mode
    'custom_cap'=>true
    ));

        add_menu_page( 'Custom Menu', 'Custom Menu', 'custom_cap', 'menu-slug', 'menu_function', plugins_url( 'icon.png' ), '1.0' );

    function menu_function(){

      // do code for menu here

    }

   }