Deny Access Based On Group

If a user belongs to a group, I would like to restrict them from all posts associated with that group.
Essentially, this is an inverse of the standard functionality. Instead of Read, I need a Cannot Read.

How can I accomplish this?

9 Responses to Deny Access Based On Group

  1. George December 1, 2023 at 2:45 pm #

    Hey Brad,

    FYI, we have updated the addon and also added support for HPOS. I would recommend you to remove your existing version and install the new one.
    Also, the hook

    add_filter( ‘groups_wc_not_purchasable_filter_visibility’, ‘my_groups_wc_not_purchasable_filter_visibility’, 10, 3 );
    function my_groups_wc_not_purchasable_filter_visibility( $filter_visibility, $visible, $product_id ) {
    return true;
    }

    must return true for the products to be not visible.

    Kind regards,
    George

  2. George November 28, 2023 at 12:07 pm #

    Hey Brad,

    Let me have a look at the addon and I’ll follow-up here.

    Cheers

  3. Brad November 14, 2023 at 5:27 pm #

    Thank you for the reply.

    I’d like this functionality for a specific group. The rest I need to operate as normal.
    It needs to affect more than just the post content. I am applying it to WooCommerce products.

    So, I’m looking for to function like this:
    In these cases group B will be the negative/deny group.

    Scenario 1
    – User is in group A
    – Product is associated with group A
    – User CAN see product in the listings, search, and access the product directly.

    Scenario 2
    – User is in group A and in group B
    – Product is associated with group A and B
    – User CANNOT see product in the listings, search, or can access the product directly.

    Scenario 3
    – User is in group B
    – Product is associated with group A
    – User CANNOT see product in the listings, search, or can access the product directly.

    Scenario 4
    – User is in group B
    – Product is associated no groups
    – User CAN see product in the listings, search, and access the product directly.

    Scenario 5
    – User is in group B
    – Product is associated group B
    – User CANNOT see product in the listings, search, or access the product directly.

    • Kento November 15, 2023 at 8:50 pm #

      Hi Brad,

      Many thanks for providing the details, just to let you know we’re looking into it to see what we can suggest. Ideally a logical approach might help you without the need to use customized inverse logic on groups, but we’ll need to pick our brains to see if that’s viable.

      We’ll follow up as soon as we have given it a little more thought …

      Cheers

      • Brad November 15, 2023 at 10:28 pm #

        Thank you.

        For some added context, I have more than just Group A that is in the positive bucket.

        In reality I have Group A, C, D, E that are all positive. And some of them are granting access at a category level.

        Then there is Group B that I need to use to ensure that users in that group cannot see or access any products associated with Group B.

      • Brad November 21, 2023 at 4:05 pm #

        Just wanted to check back in on this to see what direction you can provide.

        • Kento November 22, 2023 at 8:27 pm #

          Hi Brad,

          Thanks for bearing with us, it took a bit to look into it and this is what I would suggest based on my understanding of what you require:

          Our groups-wc-not-purchasable repository contains a plugin that does what you need. If you check the description, you can use it to make products not purchasable and not visible for members of certain groups.

          You will need to implement the groups_wc_not_purchasable_category_to_group as shown there, and use a category for those products that should not be purchasable/visible for members of the specific group.

          Please give that a try and let us know if you have any questions.

          Cheers!

          • Brad November 28, 2023 at 6:16 am #

            I have installed and implemented it, and it looks like it will do the trick.
            I’ve successfully hidden the ability to purchase the products I want, but I also want the items to be hidden from the library completely for that group.

            I tried adding this code (from the instructions) to take care of that, but it isn’t working. The items are still visible in the library. Is there something else I need to do?

            add_filter( ‘groups_wc_not_purchasable_filter_visibility’, ‘my_groups_wc_not_purchasable_filter_visibility’, 10, 3 );
            function my_groups_wc_not_purchasable_filter_visibility( $filter_visibility, $visible, $product_id ) {
            return false;
            }

  4. George November 14, 2023 at 5:17 pm #

    Hi Brad,

    Welcome to our support forum and many thanks for using our access restriction software on your site.

    As you can imagine, the first approach would be to revert the whole functionality of the plugin and do the opposite of what applies at the moment.
    However, I think that it would be better if you could provide some further details just in case there is an easier way to do it.
    For example, do you wish that feature to apply for all groups, new and existing, or for a specific group only.
    As for the rest of the users and visitors, should they have access to that content or not.

    Last but not least, if you wish the restriction to apply only to the post content, instead of the whole post, then you can restrict that easily with a custom template. The post(s) will still be found in search results but the content itself will be restricted.

    Please let me know what is the approach you’re looking for to use on your site.

    Kind regards,
    George

We use cookies to optimize your experience on our site and assume you're OK with that if you stay.
OK, hide this message.

Affiliates · Contact · Jobs · Terms & Conditions · Privacy Policy · Documentation · Downloads · Useful Plugins · My Account

Share