“Invalid key” on Subscriber roles in wordpress

Disclaimer
I apologize that this issue is so closely related to another. I would have commented on the original post, but I don’t have enough reputation, and I don’t have enough programming experience to grind reputation by answering questions.

The Question
I’ve used the following code to force users to log into my wordpress site:

Read More
    // Force user to login on welcome
function forceLogin() {
global $post;

    if ( ( is_single() || is_front_page() || is_page() || is_archive() || is_post() ) 
           && !is_page('login') && !is_user_logged_in()){ 
        auth_redirect(); 
    }  
}

I then included that function in my header.php file for my child theme. So far everything works great.

The problem I have is that when a user with the “subscriber” role is logged in and tries to access my posts page, which is also set as my static home page, they get redirected to the “lost password” page with a “invalid key” error (ie: www.domain.com/lostpassword/?error=invalidkey).

It should be noted that I’m using the Theme My Login plugin (http://wordpress.org/plugins/theme-my-login/) to style my login page.

Thank you so much, and be gentle.

Original Post
WordPress force user to login before view any site content

Related posts

Leave a Reply

1 comment

  1. Do you just want to redirect all of your website’s logged-out visitors to the login page? Just add this to your theme’s functions.php file and remove the code you’ve added to your header.php file.

    function redirect_to_login_page() {
        if ( ! is_user_logged_in() && ! is_admin() ) {
            wp_redirect( home_url() . '/login/' );
            exit();
        }
    }
    add_action( 'template_redirect', 'redirect_to_login_page' );
    

    Notes: This assumes your login page is accessed via example.com/login/