• Resolved dainiuv

    (@dainiuv)


    Hello,

    I like this plugin and used it before, but I have problem with one website. Search not working with simple membership plugin and Partial Protection add-on. I use it to protect some content in post with shortcodes. But search should work with protected content and show the excerpt as it does not for protected content. Can you help me with this?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Relevanssi doesn’t know how some random membership plugin protects posts. It can handle s2member out of the box, and Groups from the latest version on, but it can also be taught how to support other plugins.

    Simple Membership is easy to support and will be included in the next version. If you want support for Simple Membership now, you can use this: https://gist.github.com/msaari/daa1c9bdceacdfe61e130bbbf42409c2

    But that doesn’t cover Partial Protection. Are you sure the Partial Protection doesn’t already work? Since it’s done with a shortcode, it’s possible that it would just work with Relevanssi, as Relevanssi runs the shortcodes before creating the content to excerpt.

    If you’re logged in, you should see the protected content in excerpts, but if you’re logged out, you shouldn’t. Please double check. If it really doesn’t work and you can see protected content in excerpts even when you’re logged out, then something can be done – the easiest solution is to simply remove all protected content to all users.

    Do note that Relevanssi will index all partially protected content and will return posts if someone searches for the protected content, even if it can’t show it in excerpts. If that’s a problem, then it’s possible to make Relevanssi not index the partially protected content, but in that case nobody can find the posts with that content, even those with permissions to see it.

    Thread Starter dainiuv

    (@dainiuv)

    Hello Mikko,

    I have tried change with your function but no luck.
    I use this simple membership addon: https://simple-membership-plugin.com/apply-partial-section-protection/
    My posts content looks like:

    Content visible to all members.
    [swpm_protected for="2-3-4"]
    Whatever content goes here is only visible to members who belong to the specific membership level(s) specified in the shortcode.
    [/swpm_protected]

    Relevanssi index posts but excludes these shortcodes content. If I search for “membership” it returns 0 results (nothing found). For all post membership protection is not set, only with partial protection shortcodes.

    Can I do something with these shortcodes that Relevanssi could index content?

    Plugin Author Mikko Saari

    (@msaari)

    So the problem is that the protected content is not being indexed? And you want it to be indexed?

    In that case I think the problem is that when Relevanssi applies the shortcodes, there’s no user specified, which means that Simple Membership thinks the protected content should not be shown.

    Try this:

    add_filter('pre_option_relevanssi_disable_shortcodes', 'rlv_swpm_protected');
    function rlv_swpm_protected($shortcodes) {
        $shortcodes = "swpm_protected," . $shortcodes;
        return $shortcodes;
    }

    Add this to the theme functions.php and rebuild the index. This should get the protected content in the index. Does that work? And if it works, does the protected content get in the excerpts if you’re logged in or logged out?

    Thread Starter dainiuv

    (@dainiuv)

    Yes, it works now. Thank you!
    If logged in: shows content and highlights search
    If logged out: search works but results is only from beginning of posts, doesn’t highlight and protected content is not shown.

    Is it possible to highlight content for all users (logged in and logged out)? Or this part is for simple membership that part is protected and couldn’t be shown in search excerpt?

    Plugin Author Mikko Saari

    (@msaari)

    That’s the protected content – Relevanssi is not allowed to show the protected content to users that don’t have the permission to see it.

    If you want the protected content visible in excerpts to all users, you can try this:

    add_filter('relevanssi_disable_shortcodes_excerpt', 'rlv_swpm_protected_excerpts');
    function rlv_swpm_protected_excerpts($shortcodes) {
        $shortcodes[] = "swpm_protected";
        return $shortcodes;
    }

    This will disable the protection shortcode in excerpts as well, so Relevanssi will use all content for excerpts.

    Thread Starter dainiuv

    (@dainiuv)

    It works, but there is one little problem, in excerpt beginning shows ending of another shortcode

    …id=’darbo-uzmokestis’ target=“/]
    is it possible to remove this?

    Thread Starter dainiuv

    (@dainiuv)

    After index rebuild it’s not working. No problem it will be fine with protected content.
    Thank you for your help Mikko!

    Thread Starter dainiuv

    (@dainiuv)

    My client said that it have to show protected content for all users. How can I make your last function work? As I said: after rebuild index it’s not working.

    Edit: Now everything works. Now I need to hide shortcode at beginning.

    …id=’darbo-uzmokestis’ target=“/]

    • This reply was modified 6 years, 6 months ago by dainiuv.
    Plugin Author Mikko Saari

    (@msaari)

    Is that the [swmp_protected] shortcode or some other shortcode?

    Thread Starter dainiuv

    (@dainiuv)

    It’s some other shortcode, [ps2id id=’some-id’ target=”/]

    Plugin Author Mikko Saari

    (@msaari)

    Does adding this to theme functions.php help:

    add_filter('relevanssi_pre_excerpt_content', 'rlv_trim_shortcodes');
    function rlv_trim_shortcodes($content) {
        $content = preg_replace('/\[\/?ps2id.*?\]/', '', $content);
        return $content;
    }
    Thread Starter dainiuv

    (@dainiuv)

    Now everything is fine, thank you Mikko!

    Thread Starter dainiuv

    (@dainiuv)

    Hello,

    I have modified function to:

    
    add_filter('relevanssi_pre_excerpt_content', 'rlv_trim_shortcodes');
    function rlv_trim_shortcodes($content) {
        $content = preg_replace('/\[\/?ps2id.*?\]/', '', $content);
        $content = preg_replace('/\[\/?swpm_protected.*?\]/', '', $content);
        return $content;
    }

    But still there is shortcode in excerpt with [swpm_protected …] shortcode. Can you suggest modifications?

    Website: http://www.nav-skatt.lt/page/2/?s=i%C5%A1mokos

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Search not working with simple membership plugin and Partial Protection add-on’ is closed to new replies.