【问题标题】:How to create a User Role that behaves like customer role in Woocommcers如何在 Woocommerce 中创建一个行为类似于客户角色的用户角色
【发布时间】:2017-09-28 00:30:28
【问题描述】:

我在 woocommcers 网站中创建了一个“卖家”角色,我希望它在“客户”角色中拥有相同的权限

目前当我使用此代码时

add_role('seller', 'Seller', array(
    'read' => false,
    'edit_posts' => false,
    'create_posts' => false, 
    'delete_posts' => false,
));

创建的用户可以访问我不想要的受限 Wordpress 管理后端

我还尝试了这个功能来删除 Wordrpess 管理员后端访问它有点工作但仍然在顶部有管理员标题

function wpse23007_redirect(){
  if ( is_admin() && !defined('DOING_AJAX') && ( current_user_can('seller') ) ){
    wp_redirect(home_url());
    exit;
  }
}
add_action('init','wpse23007_redirect');

有没有办法在 Woocommcers 中创建一个新的“客户”角色?

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    您可以通过

    将客户角色功能添加到卖方角色
    $wp_roles = wp_roles();
    
    $customerRole = $wp_roles->get_role( 'customer' ); // Copy customer role capabilities
    
    $role = 'seller';    
    $display_name = 'Seller';
    add_role( $role , $display_name , $customerRole->capabilities );
    

    【讨论】:

    • 这比我的代码效果更好,但是当客户角色从不显示任何 wp 管理仪表板内容时,它对管理员后端的访问权限相同,而且当我创建卖家帐户角色时它也没有让我登录,但用户在数据库中
    • 我们已根据要求为卖方角色提供了与客户角色类似的功能。不允许客户访问 WordPress 仪表板,因此卖家将自动无法访问该仪表板。如果您希望卖家能够访问 WordPress 仪表板,那么您必须为卖家分配其他角色权限。
    • 您的答案是正确的,编辑用户角色不会在进行更改时刷新权限,您需要 remove_role('seller');并重新开始。在我删除角色并重新添加它工作的角色之后
    猜你喜欢
    • 1970-01-01
    • 2012-04-04
    • 1970-01-01
    • 2023-01-03
    • 2013-04-06
    • 1970-01-01
    • 2017-02-17
    • 2019-04-11
    • 1970-01-01
    相关资源
    最近更新 更多