This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Groups and hide products

#21202
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

Thank you very much!

I think I managed to find a solution based on the plugin API. The category based exclusions seem to have a different API, so the code needs to be extended. The final solution is:

add_filter('asp_results', 'asp_fix_groups_exclusions', 10, 1);
function asp_fix_groups_exclusions($results) {
	// Group based exclusions
	if ( class_exists('Groups_Post_Access') ) {
		foreach ($results as $k => &$r) {
			if ( isset($r->post_type) && !Groups_Post_Access::user_can_read_post($r->id) )
				unset($results[$k]);
		}
	}
	// Category based exclusions
	if ( class_exists('Groups_Restrict_Categories') ) {
		foreach ($results as $k => &$r) {
			if ( isset($r->post_type) && !Groups_Restrict_Categories::user_can_read($r->id) )
				unset($results[$k]);
		}
	}
	return $results;
}

Please check if this is correct. Thanks!