Filtering search results based on ActiveMember360 permissions

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Filtering search results based on ActiveMember360 permissions

This topic contains 16 replies, has 2 voices, and was last updated by janebenston53 janebenston53 4 years, 3 months ago.

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #23931
    janebenston53
    janebenston53
    Participant

    Our membership site is built on wordpress and we are using Active Member 360 to manage the membership component of the site.

    I’m wanting Ajax Search to work in conjunction with Active Member so that search results are filtered based on the permission levels a user has. (i.e. if a user doesn’t have permission to a page, this page shouldn’t be displayed in search results).

    Ernest Marcinko advised that if I purchase the pro version of Ajax search (which I have done now), you should be able to assist me to do this.

    I have created a video to explain how our site works… there are two issues explained in the video which I would love your help to resolve.

    https://www.dropbox.com/s/e2ziy54godf2cnh/Ajax%20and%20ActiveMember.mov?dl=0

    #23939
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    Thank you for all the details.

    Can you please also add temporary FTP details? I will try to check the membership plugin API, and construct a custom code within the functions.php if possible.

    Best,
    Ernest Marcinko

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


    #23998
    janebenston53
    janebenston53
    Participant

    Hi Ernest, where do I get FTP codes from?
    Thanks.

    #24002
    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 :)


    #24018
    janebenston53
    janebenston53
    Participant
    You cannot access this content.
    #24034
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Thank you, that worked perfectly.

    So, I inspected the activemember API via their source code, and I may have found the solution. I have placed the following custom code to the functions.php file in your active child-theme directory:

    add_filter('asp_results', 'asp_mbr_filter_posts', 10, 1);
    function asp_mbr_filter_posts( $results ) {
      foreach ( $results as $k => $r ) {
        if ( !mbr_match_user_content($r->id) ) {
          unset($resuls[$k]);
        }
      }           
      
      return $results;
    }

    There was no documentation about this in their API, so I can only hope this is the correct function to use.

    Best,
    Ernest Marcinko

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


    #24044
    janebenston53
    janebenston53
    Participant

    Thanks Ernest, I’ve signed into the membership site as a TLC user… but I can still see the CBD user pages displaying in the dynamic search box… so doesn’t look like this is working…

    Yes, Active Member are terrible with their documentation.

    How could we proceed from here?

    #24048
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    In this case, can you share the TLC user details, so I can use it for testing the functions? Also, can you point me which posts should not be there, when searching when logged in as that user?
    It is more than enough if you give me a test search phrase to use, and tell which posts should not be there. I will try this again with a different approach, but this time I will know if it’s working or not.

    Best,
    Ernest Marcinko

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


    #24051
    janebenston53
    janebenston53
    Participant
    You cannot access this content.
    #24074
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Thank you very much!

    The code was actually fine, I just made a typo on line 11. I have corrected the mistake, it should work now. The final, correct code is:

    add_filter('asp_results', 'asp_mbr_filter_posts', 10, 1);
    function asp_mbr_filter_posts( $results ) {
      foreach ( $results as $k => $r ) {
        if ( !mbr_match_user_content($r->id) ) {
          unset($results[$k]);
        }
      }           
      
      return $results;
    }
    Best,
    Ernest Marcinko

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


    #25090
    janebenston53
    janebenston53
    Participant
    You cannot access this content.
    #25108
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    Thank you for all the details. It indeed does not work, it looks like my previous solution does not work after all. The problem is, that I don’t know what else to try – it would probably take long hours to study their code and somehow get the proper function to integrate with this.

    I have tried a few different solutions, but none of them seem to work. Can you please ask their developer, what is the proper way of checking programatically, if the current user has access to a given post by the post ID?

    Best,
    Ernest Marcinko

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


    #25234
    janebenston53
    janebenston53
    Participant

    Hi Ernest, I’ve gone back to Active Member and asked your question… this is how they responded:

    apply_filters( ‘mbr/match_user_content’, $post_id, MBR_IGNORE_EXCERPT )

    MBR_IGNORE_EXCERPT should be set to true to ignore the excerpt which if defined for the $post_id will be giving the user access to the post albeit the excerpt
    MBR_IGNORE_EXCERPT should be set to false to consider the excerpt which if defined for the $post_id will be giving the user access to the post albeit the excerpt

    The filter will return true for those with access to $post_id and false for those without access.

    Does this help?

    #25235
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Yes, that is very helpful actually. So, based on this API description, this is the right one:

    add_filter('asp_results', 'asp_mbr_filter_posts', 10, 1);
    function asp_mbr_filter_posts( $results ) {
    	foreach ( $results as $k => $r ) {
    		$access = apply_filters( 'mbr/match_user_content', $r->id, true );
    		if ( !$access ) {
    			unset($results[$k]);
    		}
    	}           
    
    	return $results;
    }
    Best,
    Ernest Marcinko

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


    #25240
    janebenston53
    janebenston53
    Participant

    Hi Ernest,

    I’ve gone into the member site but I can still see pages showing up in search that shouldn’t be there.

    Not sure if there’s something you need me to do with the information above?

    Thanks.

Viewing 15 posts - 1 through 15 (of 17 total)

You must be logged in to reply to this topic.