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


create admin menu and page for a custom user role

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

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管理员或其面板中,当它登录时,我如何创建自己的菜单和页面?

这里,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
    }
   }