Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › membership and content access
- This topic has 9 replies, 2 voices, and was last updated 5 years, 7 months ago by
Ernest Marcinko.
-
AuthorPosts
-
October 8, 2020 at 6:14 pm #29697
qpractice43
ParticipantWe are wanting to know if it is possible for content that is not available to Members (restricted via Memberships plugin) can be excluded automatically?
Right now there is content that is behind a membership pay wall that shows up.
Currently we are using an index table, wondering if switching to the normal engine may allow the content restrictions to be applied to the search query?-
This topic was modified 5 years, 7 months ago by
qpractice43.
October 9, 2020 at 8:27 am #29707Ernest Marcinko
KeymasterHi,
I’m sure it is doable, but definitely requires some custom code to remove the results from the list. Does the plugin have an API documentation? If so, do you know where I can access it? If there is a function to check if the current user has access to a certain post, then it should not be an issue.
October 9, 2020 at 5:56 pm #29723qpractice43
ParticipantHi Ernest,
It looks like WooCommerce Memberships uses the pre_get_posts query filtering to adjust what content is shown to members.
Does the index table use pre_get_posts? If we switch back to the default search engine option instead of index table would that allow the pre_get_posts filtering (from Memberships) to apply?
October 10, 2020 at 10:42 am #29729Ernest Marcinko
KeymasterHi,
The pre_get_posts does not apply to either of the queries, as it would not work – the plugin has a different query structure (an own query).
However if I can take a look at what the function looks like they apply on the pre_get_posts query filter, then I can probably convert it to our query as well.October 10, 2020 at 4:14 pm #29732qpractice43
ParticipantWooCommerce Memberships is pretty complicated but this is a key file where pre_get_posts filters are used
https://gist.github.com/jondcampbell/07f0e7e80be91cb94c0c2be0ca304f0aOctober 12, 2020 at 8:45 am #29736Ernest Marcinko
KeymasterThank you very much, this was extremely helpful. Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!
add_filter( 'asp_query_args', 'asp_exclude_restricted_posts', 10, 1 ); function asp_exclude_restricted_posts( $args ) { if ( ! current_user_can( 'wc_memberships_access_all_restricted_content' ) ) { if ( wc_memberships()->get_restrictions_instance()->hiding_restricted_products() ) { $conditions = wc_memberships()->get_restrictions_instance()->get_user_content_access_conditions(); if ( isset( $conditions['restricted']['posts']['product'] ) ) { $args['post_not_in'] = array_unique(array_merge($args['post_not_in'], $conditions['restricted']['posts']['product'])); } } } return $args; }In theory, this should be it – I was not able to test this, so please be carefuly.
October 13, 2020 at 4:17 pm #29767qpractice43
ParticipantAnd this should work with index table engine or the regular engine?
October 14, 2020 at 7:48 am #29778Ernest Marcinko
KeymasterIt should work with both.
October 14, 2020 at 11:19 pm #29802qpractice43
ParticipantThank you for all your efforts Ernest.
Sadly that particular function from Memberships doesn’t get all the restricted post ids, only some of them. Memberships has a lot of different ways to tag content as restricted.I ended up using some of your code though and applying a list of post ids of all our Sensei lessons we want to exclude.
October 15, 2020 at 12:20 pm #29813Ernest Marcinko
KeymasterYou are very welcome. Let me know if you need any more help.
-
This topic was modified 5 years, 7 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.