Support » Plugin: WP-Members Membership Plugin » Private page, but content searchable

  • Resolved adejones


    Hi, I have a page on a website which is set to private as it contains email addresses of registered members, it is to be only accessed by registered/logged in users. However, if I enter a surname of a person in the website search field, the page content is displayed in the results – the only way to prevent this is to set the page to hidden. The only downfall of this is that registered users who aren’t yet logged in will see a 404 instead of being directed to the login page.
    Is this a bug?? Why is private content searchable?


Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Chad Butler


    If you want something to be non-searchable, then marking the post as “hidden” is what you want (instead of “blocked”).

    Regarding the 404, if you’re using the standard WP search, I believe you may be misinterpreting the search results (or the theme doesn’t account for an empty search result). What you get (or should be getting) if the search term does not exist in any posts (which would be the case if the term only exists in the post that is hidden) would be an empty result, such as “Sorry, but nothing matched your search terms.”

    This would be because for the logged out user, this content does not exist. You can’t redirect them to a login for something that isn’t there.

    If what you want is for the user to search for something, find it, but need to log in to view it, then what you want is “blocked.”

    Blocked content will require the user to log in when the visit the single post/page. When is shows on an archive template (which includes search results), if you have the plugin configured appropriately, the content will be excerpted. When they click through to get the full result, they will need to log in.

    If you’re showing the full content in the search results, then the content is not excerpted which means you haven’t either included a “read more” tag in the content or set the plugin for auto excerpt. See the following FAQ on this topic:

    Some of this is discussed visually in the “initial setup video” here:

    Thread Starter adejones


    Hi Chad, thanks for the reply.

    Regarding the 404, I meant that if a user who is not logged in tries to access the restricted page when it is set to hidden, they get faced with a 404, where as if it is set to private they get sent to the log in page, not when they use the search term.

    I am just thinking in cases where registered users may have the direct URL for the members directory page bookmarked, if they go to their bookmark now that it’s hidden they’ll get a 404 where before they were directed to the log in page, so hidden isn’t ideal for us but we really need the content to be unsearchable so it sounds like the only option.

    Kind regards

    Plugin Author Chad Butler


    If you’re concerned about users who might hit the URL directly but not be logged in, you could set up a redirect to the login. There are a couple of useful functions in the API you can use – wpmem_redirect_to_login() and Use the latter to check if the current page is your directory, and if so and the user is not logged in, redirect to the login (with a redirect_to parameter to return the user back to the original page):

    add_action( 'template_redirect', function() {
    	$url = ''; // alternative: $url = home_url( 'my-page' );
    	if ( ! is_user_logged_in() && $url == wpmem_current_url( true, false ) ) {
    		wpmem_redirect_to_login( $url );
    Thread Starter adejones


    Perfect thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Private page, but content searchable’ is closed to new replies.