【问题标题】:How to create custom users to manage group of users in WordPress?如何创建自定义用户来管理 WordPress 中的用户组?
【发布时间】:2020-03-25 17:40:43
【问题描述】:

我正在开发一个拥有管理员用户和许多供应商用户的 woocommerce wordpress 网站。我想创建另一个可以管理一组供应商用户的用户类型(供应商经理)。只有管​​理员可以将供应商用户分配给这种新的用户类型。 有点像,

管理员 -> 经理 -> 供应商组。

通过管理,我的意思是添加、编辑、删除分配的供应商用户的产品,还可以添加供应商角色的新用户。

编辑-我已经将自定义用户定义为“vendor_manager”类型,具有“列表用户”、“添加用户”、“删除用户”功能。但它列出了“vendor_manager”仪表板中的所有用户。我想要的是仅列出管理员分配给“vendor_manager”的那些用户(仅限供应商类型)。为了分配,我在管理员的仪表板中创建了一个带有 acf 字段的菜单,在其中我将一组供应商用户分配给这个“vendor_manager”。我只想限制“vendor_manager”用户只管理分配的用户。 希望有意义。

供应商经理角色-

add_role( 
  'vendor_manager', 
  __( 'Vendor Manager', 'yourtextdomain' ), 
  array(
    'read' => true,
    'edit_posts' => true,
    'create_users'=> true,
    'delete_users'=> true,
    'edit_users'=> true,
    'list_users'=> true,
    'promote_users'=> true,
    'remove_users'=> true,
    'assign_product_terms'=> true,
    'delete_others_products'=> true,
    'delete_private_products'=> true,
    'delete_product'=> true,
    'delete_product_terms'=> true,
    'delete_products'=> true,
    'delete_published_products'=> true,
    'edit_others_products'=> true,
    'edit_private_products'=> true,
    'edit_product'=> true,
    'edit_product_terms'=> true,
    'edit_products'=> true,
    'edit_published_products'=> true,
    'manage_product_terms'=> true,
    'publish_products'=> true,
    'read_private_products'=> true,
    'read_product'=> true,
));

将供应商分配给经理的 ACF 选项页面-

if( function_exists('acf_add_options_page') ) {

    acf_add_options_page(array(
        'page_title'    => 'Groups',
        'menu_title'    => 'Groups',
        'menu_slug'     => 'groups',
        'capability'    => 'edit_posts',
        'redirect'      => false
    ));
}

将供应商分配给经理-

有什么帮助吗??

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    您可以通过以下代码创建此自定义角色(供应商经理)并为其添加权限:

    add_role( 
      'vendor_manager', 
      __( 'Vendor manager', 'yourtextdomain' ), 
      array(
        'read' => true,
        'edit_posts' => true,
        // Various Capabilities
    ));
    

    还可以查看以下 2 个链接以获取完整引用:

    https://www.cloudways.com/blog/add-custom-user-roles-in-wordpress/

    https://www.ibenic.com/manage-wordpress-user-roles-capabilities-code/

    【讨论】:

    • 我已经这样做了。用更多信息重新编辑了我的问题。请检查。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 2018-11-13
    • 2019-01-25
    • 1970-01-01
    • 2019-09-26
    相关资源
    最近更新 更多