• Here is the scenario:
    We have 4 roles.
    1. Administrator > Works as usual admin role
    2. Shop_manager > WooCommerce Default
    3. shop_associate > 1 level lesser than shop_manager, manages customer, cannot manage shop_manager
    4. Customer > usual WC default

    Question: shop_associate > can only access orders and edit and manage customers.
    now problem is , When I am giving edit_users and delete_users capability to it. It can delete shop_manager also. However, I would like to only give edit and delete rights for customer role only to shop associate.
    How can I achieve this ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Vladimir Garagulya

    (@shinephp)

    Try to add this code to the active theme functions.php file or set it as a Must Use plugin:

    
    add_filter('editable_roles', 'exclude_shop_manager_for_associate', 10, 1);
    function exclude_shop_manager_for_associate( $roles ) {
        $user = wp_get_current_user();
        if ( in_array( 'shop_associate', $user->roles ) ) {
            if ( isset( $roles['shop_manager'] ) ) {
                unset( $roles['shop_manager'] );
            }
        }
    
        return $roles;
    }
    
    Thread Starter Vineet Talwar

    (@vineettalwar)

    Hello @shinephp ,
    It is not working for me.

    Please confirm if the following capabilities are correct.
    1. shop_associate: delete_users, edit_users, list_users
    2. shop_manager: delete_users, edit_users, list_users

    Plugin Author Vladimir Garagulya

    (@shinephp)

    Capabilities are correct for the editing users purpose.

    Yes, piece of code above does not allow to assign ‘shop_manager’ role to any user.
    Yes it does not restrict a deletion of user with ‘shop_manager’ role.

    URE realizes a protection similar to one you need for WordPress built-in administrator user. So if you are PHP developer you can take it for the starting point – user-role-editor/includes/classes/protect-admin.php.

    URE Pro includes “Other roles access” add-on, which allows for selected role to block access to the other roles and all users, which have blocked roles.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Restrict custom role to not edit/delete shop_manager but customer’ is closed to new replies.