Plugins & Themes

Private site

7 Replies ·

  1. Hello,

    I want to setup a private site, including private feed, where all but 3 pages are locked. For this simple a need, I’m not sure which Member plugin I need. Really all I want is an Exclusion option under Private Site, where I can list the three URLs. What do you suggest? Thank you for this great plugin!

    I anticipate more complex needs later, but for now I just want to minimize code on my site.

    Thank you!

  2. Justin Tadlock

    If you can list the page slugs or IDs, I’ll post some code to do this in the morning when I’m back on the computer.

  3. Damon Schechter

    Thanks for the kind reply! Below are the four posts I’m trying to exclude. If this is a hack, perhaps you can provide the php snippet so I can edit it in the future without having to bother you again?

    Also, I have my account password saved in my browser, so I can’t login anywhere else. And no lost password feature on your login. Can you send a password reset, so I can at least store it in my password keeper?

    Thank you Justin!

    https://legacy.co/wp-admin/post.php?post=1662&action=edit

    https://legacy.co/wp-admin/post.php?post=2214&action=edit

    https://legacy.co/wp-admin/post.php?post=2264&action=edit

    https://legacy.co/wp-admin/post.php?post=2167&action=edit

  4. Justin Tadlock

    If these are posts, use the following code. You can drop it into a custom plugin file or your theme’s functions.php file.

    If these are pages, change is_single to is_page in the code.

    add_filter( 'members_is_private_page', function( $is_private ) {
    
        if ( is_single( [ 1662, 2214, 2264, 2167 ] ) ) {
    
            $is_private = false;
        }
    
        return $is_private;
    } );
    

    Also, I have my account password saved in my browser, so I can’t login anywhere else. And no lost password feature on your login. Can you send a password reset, so I can at least store it in my password keeper?

    Are you referring to here at ThemeHybrid.com? If so, you can find the password reset page here: https://themehybrid.com/blog/wp-login.php?action=lostpassword

    You can also control your password from your profile page in the admin: https://themehybrid.com/blog/wp-admin/profile.php

  5. Damon Schechter

    Thank you for the quick and thoughtful answer! Is there code that would also limit these “outside pages” to “logged out” users only?

    And when I log out, I end up back at the login screen. Is there a way to redirect logged out users to the home page (ID 1662)?

    Thank you again!

  6. Justin Tadlock

    Thank you for the quick and thoughtful answer! Is there code that would also limit these “outside pages” to “logged out” users only?

    It’s possible. However, what’s the point, really? If a user can’t see the page when logged in, they can simply log out to see it. You’re not really blocking it from them.

    This isn’t a part of Members, but you could do a redirect to another page for logged-in users with the following code:

    add_action( 'template_redirect', function() {
    
        if ( is_user_logged_in() && is_single( [ 1662, 2214, 2264, 2167 ] ) ) {
    
            // Change URL to where you want to redirect:
            wp_redirect( 'https://example.com' );
    
            exit();
        }
    } );
    

    And when I log out, I end up back at the login screen. Is there a way to redirect logged out users to the home page (ID 1662)?

    The basic code for this would be:

    add_action( 'wp_logout', function() {
    
        wp_redirect( esc_url_raw( home_url() ) );
    
        exit();
    } );
    

    There is a plugin for that here that will handle some edge case stuff better than the above bit of code: https://wordpress.org/plugins/login-and-logout-redirect/

  7. Damon Schechter

    Thank you for this amazing help! I really appreciate it. The login/logout redirect plugin was a really good suggestion as well. I’m trying the redirect code you have above, and am not able to get it to do anything. Am wondering if I’m mistyping something. Might you be able to eyeball it?

    add_action( 'template_redirect', function() {
        if ( is_user_logged_in() && is_single( [ 1662, 2214, 2264, 2167 ] ) ) {
    
            // Change URL to where you want to redirect:
            wp_redirect( 'https://legacy.co/activity' );
    
            exit();
        }
    } );
    
  8. Justin Tadlock

    I tested the code as a logged-in user on my install, and it works (redirected to the URL that you have). Just remember that is_single is only going to work with posts. If these are page IDs, you’ll need to change that to is_page.

    The only other issues would be if you’re on an older version of PHP than version 5.5. But, you should see an error on the screen if that’s the case.