• Resolved renegate123

    (@renegate123)


    Hi,
    I`m using Relevanssi and WP-Members and want to excluding protected pages in my search results for not logged in users. The pages, protectes by WP-Members, should only include in search results for logged in users. Is this possible?

    I tried this Code from you, but it does not work:

    `add_filter( ‘relevanssi_post_ok’, ‘rlv_search_exclude_protected’, 10, 2 );
    function rlv_search_exclude_protected( $allow, $post_id ) {
    $post = get_post( $post_id );
    if ( ! empty( $post->post_password ) ) {
    $allow = false;
    if ( is_user_logged_in() ) {
    $allow = true;
    }
    }
    return $allow;
    }

    Some idea to solve this problem? It would be glad!! And me too ??

    Thanks a lot
    Renegate

    The page I need help with: [log in to see the link]

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

    (@msaari)

    That function only works for password-protected posts. Try this:

    add_filter( 'relevanssi_post_ok', 'rlv_wp_members', 10, 2 );
    function rlv_wp_members( $post_ok, $post_id ) {
      $post_ok = wpmem_is_blocked( $post_id );
      return $post_ok;
    }

    Does this work?

    Thread Starter renegate123

    (@renegate123)

    Hi Mikko,

    thanks for your feedback. Unfortunately it doesn`t work.
    There are no search results anymore, independently if I′m logged in or not.
    Any other idea?

    Thanks, Renegate

    Plugin Author Mikko Saari

    (@msaari)

    This is actually tested and should work:

    add_filter( 'relevanssi_post_ok', 'rlv_wp_members', 10, 2 );
    function rlv_wp_members( $post_ok, $post_id ) {
        global $wpmem;
    
        if ( is_user_logged_in() ) {
            return $post_ok;
        }
    
        $post_meta = get_post_meta( $post_id, '_wpmem_block', true );
        $post_type = $wpmem->block[ relevanssi_get_post_type( $post_id ) ];
    
        if ( '1' === $post_meta ) {
            $post_ok = false;
        } elseif ( '1' === $post_type && '0' !== $post_meta ) {
            $post_ok = false;
        }
    
        return $post_ok;
    }

    If it doesn’t, you’ve set up WP-Members different from how I have it, so in case this doesn’t work, please explain what you’re doing with the plugin.

    Thread Starter renegate123

    (@renegate123)

    Hi Mikko,

    the good message: your code works for all pages blocked with wp-members.
    Great! Thanks a lot for that!

    The bad one: it doesn`t works for pdf-files.

    My pdf-files are managed by “download monitor”, blocked with “wp-members” and should only shown for logged in users, too. Actually, they are still shown in search results for both.

    Is it possible to solve this problem?

    Thanks and regards!
    Renegate

    Plugin Author Mikko Saari

    (@msaari)

    Is the post type for PDF files dlm_download? Relevanssi is set to index that post type and it’s marked as blocked in WP-Members settings? The code above should cover the downloads as well, since it doesn’t care about the post type, it should all work the same way.

    add_filter( 'relevanssi_post_ok', 'rlv_block_pdfs', 11, 2 );
    function rlv_block_pdfs( $post_ok, $post_id ) {
      $post_type = relevanssi_get_post_type( $post_id );
      if ( 'dlm_download' === $post_type && ! is_user_logged_in() ) {
        $post_ok = false;
      }
      return $post_ok;
    }

    You can try adding this one too, this should explicitly block all dlm_download posts from the search for users that aren’t logged in.

    Thread Starter renegate123

    (@renegate123)

    Great, it works!
    Thank you very much, Mikko.

    You save my day!

    Manny regards,
    Renegate

    Plugin Author Mikko Saari

    (@msaari)

    Good, I’ll add in the basic WP-Members support to Relevanssi in the next version, which will make the first function obsolete at that point.

    If you’re happy with Relevanssi and the support you’ve received, please consider leaving a review.

    Thread Starter renegate123

    (@renegate123)

    Hi Mikko,

    sorry it is me again. I figured out, it is not working properly yet. So I try it again, with my horrible english. I am sorry for that.

    I am using blocked pdf-files and none-blocked pdf-files on my website. Using plugins WP-Members and Download Monitor. What I want to achieve is this:
    1. Getting none-blocked pdf-files in search results for not logged in users
    AND
    2. Getting blocked and none-blocked pdf-files for logged in users.

    With your Code, the second point works fine. Using Relevanssi as looked in user, I am getting both, blocked and none-blocked files. That is right.

    But using Relevanssi as none looked in user, I am getting none pdf-files. That`s wrong. If I am not logged in I want to get just none-blocked pdf-files in search results.

    Is it possible to solve this problem?

    Thanks a lot and many regards!
    Renegate

    • This reply was modified 3 years, 5 months ago by renegate123.
    • This reply was modified 3 years, 5 months ago by renegate123.
    • This reply was modified 3 years, 5 months ago by renegate123.
    • This reply was modified 3 years, 5 months ago by renegate123.
    • This reply was modified 3 years, 5 months ago by renegate123.
    Plugin Author Mikko Saari

    (@msaari)

    This function

    add_filter( 'relevanssi_post_ok', 'rlv_block_pdfs', 11, 2 );
    function rlv_block_pdfs( $post_ok, $post_id ) {
      $post_type = relevanssi_get_post_type( $post_id );
      if ( 'dlm_download' === $post_type && ! is_user_logged_in() ) {
        $post_ok = false;
      }
      return $post_ok;
    }

    blocks ALL downloads from non-logged in users. Remove this function, and non-logged-in users will see downloads. Does this solve the problem, or do the non-logged-in users now see too many files?

    Thread Starter renegate123

    (@renegate123)

    Hi Mikko,
    it doesn`t solve the problem.
    Non-logged-in users see too many files.
    Many regards,
    Renegate

    Plugin Author Mikko Saari

    (@msaari)

    What kind of controls you have in WP Members for the downloads, exactly? If I wanted to copy your setup on my site, what would I do?

    Thread Starter renegate123

    (@renegate123)

    I`m not sure what you exactly mean.
    Does it help to send you some screenshot of my wp-members options?
    Or some access to backend of my site?

    Plugin Author Mikko Saari

    (@msaari)

    Simple: if I wanted to setup a test site I have the same way yours is, what kind of settings would I use? How are your downloads protected by WP Members?

    Thread Starter renegate123

    (@renegate123)

    Ok. I try my best:

    I doesnt set many options in WP-Members. There is no site for users to register herself. Post and pages are blocked by default. I am using WP-Members for some member area, filled with pdf-files just for members.

    The pdf-files itself were blocked by Download Monitor.

    If I dont use any additionally Code. Non-logged-in Users can see in search results all blocked-pdf-files, but it`s not possible to open it. What I need is, that non-logged-in-users, dont see any blocked files. They should only see non-blocked files in search results.

    Does this help?

    Plugin Author Mikko Saari

    (@msaari)

    Yes, that will help. I’m on vacation now, so I’ll get back to this later; might take a week or two.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Excluding protected posts by WP-Members’ is closed to new replies.