• I’ve been using this plugin for some time, but something has changed I think. When a user selected a page marked as restricted, they are redirected to a login page (as expected). However, once they enter their info, they are now directed to the wp-admin login page, rather than returning to the page they want to view.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Yes, Can somebody help us with this issue? When user is logging in i want him to be redirected to the same page. Can it be done?

    Yes i have a patch.

    This is the patched file, based on version 2.2.6. Please compare with original file to see the differences.

    pagerestrict.php.txt

    I had a closer look, and essentially it is only the following addition at the end of the pagrestrict.php file that does the trick:

    
    // The redirect from the login form fails sometimes.
    // We save the target page url in a transient, and redirect very late (at action 'template_redirect') if we are not on the target page
    function pr_save_url() {
    	
    	$url = ( is_ssl() ? 'https://' : 'https://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    	
    	set_transient( 'pr_' . $_SERVER['REMOTE_ADDR'], $url, 300 );
    }
    
    // After any other redirect (i hope)
    add_action( 'template_redirect', 'pr_redirect' );
    
    function pr_redirect() {
    
    	$url = get_transient( 'pr_' . $_SERVER['REMOTE_ADDR'] );
    	
    	if ( $url ) {
    		
    		// Housekeeping
    		delete_transient( 'pr_' . $_SERVER['REMOTE_ADDR'] );
    		
    		// Only if login succeeded
    		if ( is_user_logged_in() ) {
    			
    			$cur = ( is_ssl() ? 'https://' : 'https://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    			if ( $url != $cur ) {
    				wp_redirect( $url );
    				exit();
    			}
    		}
    	}
    }
    

    The other changes i made are only to make it more readable and i use function

    
    wp_login_form( array( 'echo' => false, 'value_username' => $user_login ) )
    

    I left the 'redirect' => $any_url out, because it does not work like it does not work in the original login form.
    So, essentially it looks like a wp bug to me…

    Just add my additional code.

    Correction

    Just add my additional code.

    and 2 calls to pr_save_url()

    Jacob,

    You mention that you added 2 calls to pr_save_url(). Where did you add these to your solution?

    I’m having the same issue on a site and could use the help! Thank you in advance!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘After Login, user not returned to restricted page’ is closed to new replies.