Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mtnerd

    (@mtnerd)

    Let’s add some more information because I keep running into the same problem, no matter which privacy plug-in I try. I’ve tried to install Force User Login, Private! wordpress Access Control Manager, and Private Only. The index.php is in an odd root directory with the following –

    define('WP_USE_THEMES', true);
    
    /** Loads the WordPress Environment and Template */
    require('./wp/wp-blog-header.php');
    ?>

    And the rest of the wordpress installation is in /wp.

    I think the reason these privacy plug-ins aren’t working is because wordpress is installed in the /wp directory. Force User appears to be the simplest system and I’ve tried all sorts of modifications to the redirect but nothing works properly. Here’s the code –

    add_action( 'template_redirect', 'force_login' );
    
    	function force_login() {
    		$redirect_to = $_SERVER['REQUEST_URI']; // Change this line to change to where logging in redirects the user, i.e. '/', '/wp-admin', etc.
    
    		if ( ! is_user_logged_in() ) {
    			if ( is_feed() ) {
    				$credentials = array();
    				$credentials['user_login'] = $_SERVER['PHP_AUTH_USER'];
    				$credentials['user_password'] = $_SERVER['PHP_AUTH_PW'];
    
    				$user = wp_signon( $credentials );
    
    				if ( is_wp_error( $user ) ) {
    					header( 'WWW-Authenticate: Basic realm="' . $_SERVER['SERVER_NAME'] . '"' );
    					header( 'HTTP/1.0 401 Unauthorized' );
    					die();
    				}
    			}
    			else {
    		  		header( 'Location: ' . get_site_url() . '/wp-login.php?redirect_to=' . $redirect_to );
    				die();
    			}
    	  	}
    	}

    I have a lot more experience modifying Joomla systems and I’m feeling pretty lost with this problem, even though it should be really simple to fix.

    Suggestions? I’ll be happy with a “Hey, dummy – here’s the solution…” (I am so tired of fiddling with this!!)

    Thanks, Deb

    Thread Starter mtnerd

    (@mtnerd)

    Just in case someone else has a similar looping problems with mandatory user login plug-ins, I found a solution. I was able to modify Protected Site and it’s working. I had to change the redirect. To find the problem, I set up an echo for the two pieces of the redirect. When I saw how the combination of the two redirect functions were causing the problem, it was simple to fix. Now, I think I probably could have done the same with Force User Login but maybe not. Protected Site has a two page login process and that have helped fix the problem.

    OK, next on the list!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Force User Login] Keeps Looping to Login Page’ is closed to new replies.