strangerstudios / paid-memberships-pro

WordPress membership plugin to restrict access to content and charge recurring subscriptions using Stripe, PayPal, and more. Fully open source. 100% GPL.
https://www.paidmembershipspro.com
Other
457 stars 357 forks source link

Searches / Archives hiding posts that members should have access to. #1073

Open andrewlimaza opened 5 years ago

andrewlimaza commented 5 years ago

Describe the bug If you are showing search/archive content to members only it is hidden to members if the content belongs to more than one category.

To Reproduce

Please enable filter archives and search to "YES" under the Advanced Settings options in PMPro.

  1. Create 2 membership levels that have access to only one category.
  2. Assign a membership level to a user.
  3. Create a post that belongs to both categories from step 1 and a post that only belongs to one category for membership level 1.
  4. Go to "Categories" and view "Categories" and view the category for level 1.
  5. When viewing the categories page, it will only show the post with 1 category.

Expected behavior Posts should show for users if they have access.

Isolating the problem (mark completed items with an [x]):

dparker1005 commented 4 years ago

Just took another look into this... the problematic line is $query->set( 'category__not_in', $hidden_cat_ids ); in paid-memberships-pro/includes/content.php: https://github.com/strangerstudios/paid-memberships-pro/blob/fb736a936914b1baf1f267fe553f57636b8b1eae/includes/content.php#L251

Right now, what we're saying is "Don't get posts who have categories that are restricted by a different membership level", whereas what we need to say is "Don't get posts who have categories that are restricted by a different membership level UNLESS they are also restricted by a membership level that the user has", which isn't currently possible with our current approach for restricting by category.

To resolve this, we'd likely need to do manual queries to get a list of posts to add to the 'post__not_in' WP_Query argument similar to what we are doing with posts restricted directly by membership level. This would require rewriting that whole section of code that deals with restricting by category.

ideadude commented 3 years ago

FYI Updated this code here to preserve existing settings when filtering, but the main issue here still stands.

https://github.com/strangerstudios/paid-memberships-pro/commit/179f556ecb4ad8ec004f99d885c8a2ba8adf3aa1