membership and content access

Home Forums Product Support Forums Ajax Search Pro for WordPress Support membership and content access

This topic contains 9 replies, has 2 voices, and was last updated by

 
Keymaster
1 year, 3 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #29697

    Participant

    We 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 1 year, 3 months ago by  qpractice43.
    #29707

    Hi,

    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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #29723

    Participant

    Hi 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?

    #29729

    Hi,

    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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #29732

    Participant

    WooCommerce Memberships is pretty complicated but this is a key file where pre_get_posts filters are used
    https://gist.github.com/jondcampbell/07f0e7e80be91cb94c0c2be0ca304f0a

    #29736

    Thank 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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #29767

    Participant

    And this should work with index table engine or the regular engine?

    #29778

    It should work with both.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #29802

    Participant

    Thank 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.

    #29813

    You are very welcome. Let me know if you need any more help.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.