Groups and hide products

This topic contains 6 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 5 years, 2 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #21196
    Optec
    Optec
    Participant

    hi Ernest,

    Firstly – loving the plugin, it has unlocked so many more features than i had expected and I am spending WAY to long on getting the perfect search!! 🙂

    Question, I have tried the below and added the code to my functions.php on my child theme:

    https://wp-dreams.com/knowledge-base/restricting-results-by-user-groups-using-the-groups-plugin-by-itthinx/

    I see no change though and products keep popping up that shouldn’t.. The plugin is restricting access to theproducts as expected – I just need them to stop showing up unless part of the user group!

    #21199
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    Thank you for your kind words, I really appreciate them!

    I tried to log-in with the details, but it says, that the password is incorrect. Can you please check that? If you are using the Groups plugin, and it’s not working, then can you please also add temporary FTP access as well? I would like to debug through that custom code to see what exactly is happening there.

    Best,
    Ernest Marcinko

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


    #21200
    Optec
    Optec
    Participant
    You cannot access this content.
    #21201
    Optec
    Optec
    Participant
    You cannot access this content.
    #21202
    Ernest Marcinko
    Ernest 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!

    Best,
    Ernest Marcinko

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


    #21203
    Optec
    Optec
    Participant

    I literally just logged on to test something and saw it was working!

    You sir are a genius 🙂

    #21204
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

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


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

You must be logged in to reply to this topic.