Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Filtering search results based on ActiveMember360 permissions
- This topic has 16 replies, 2 voices, and was last updated 6 years, 4 months ago by
janebenston53.
-
AuthorPosts
-
September 12, 2019 at 1:12 am #23931
janebenston53
ParticipantOur 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
September 12, 2019 at 11:54 am #23939Ernest Marcinko
KeymasterHi!
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.
September 17, 2019 at 4:59 am #23998janebenston53
ParticipantHi Ernest, where do I get FTP codes from?
Thanks.September 17, 2019 at 12:42 pm #24002Ernest Marcinko
KeymasterYou cannot access this content.
September 18, 2019 at 4:01 am #24018janebenston53
ParticipantYou cannot access this content.
September 18, 2019 at 2:26 pm #24034Ernest Marcinko
KeymasterThank 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.
September 19, 2019 at 12:26 am #24044janebenston53
ParticipantThanks 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?
September 19, 2019 at 9:27 am #24048Ernest Marcinko
KeymasterHi,
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.September 19, 2019 at 9:36 am #24051janebenston53
ParticipantYou cannot access this content.
September 19, 2019 at 2:19 pm #24074Ernest Marcinko
KeymasterThank 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; }December 19, 2019 at 12:14 am #25090janebenston53
ParticipantYou cannot access this content.
December 19, 2019 at 2:06 pm #25108Ernest Marcinko
KeymasterHi!
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?
January 8, 2020 at 12:25 am #25234janebenston53
ParticipantHi 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 excerptThe filter will return true for those with access to $post_id and false for those without access.
Does this help?
January 8, 2020 at 9:39 am #25235Ernest Marcinko
KeymasterHi,
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; }January 8, 2020 at 11:31 pm #25240janebenston53
ParticipantHi 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.
-
AuthorPosts
- You must be logged in to reply to this topic.