Support » Plugin: Clean Login » [Redirection] Return to page viewed when login activated

Viewing 15 replies - 1 through 15 (of 15 total)
  • With the above code the behavior is to stay on the login-page with options to edit profile or logout.

    It seems this piece of code

    
    // Sets the redirect url to the current page
    $url = clean_login_url_cleaner( wp_get_referer() );
    

    is returning the actual login page instead the page the user came from.

    I would expect the $url variable to hold the previous page – which it does not and it so does.

    My scenario is:
    Navigate to a protected document.
    The document holds a shortcode indicating if the arriving user is logged in or not.
    If the user is not logged in a message is shown with a login link.
    Clicking the login link opens the login page.
    User logs in and stays on the login page.
    The shortcode link to login and the sidebar link to login is identical

    • This reply was modified 1 year, 5 months ago by  fhundewadt.
    • This reply was modified 1 year, 5 months ago by  fhundewadt.
    Plugin Author Alberto Hornero

    (@hornero)

    One idea could be to redirect to this page (where the document is placed) and there in this page you can hide the content to non-logged users, with e.g. this plugin: https://es.wordpress.org/plugins/hide-this/

    Does it help?

    The content is hidden if user is not logged in.

    What I am trying to achieve is what your plugin seems to be coded for but does not do.

    I have been doing some experiments learning a about php on the way

    // Sets the redirect url to the current page
    $url = clean_login_url_cleaner( wp_get_referer() );

    On first round it works as expected – the $url variable contains the page where the user clicked the login-link.

    However after filling in credentials and clcking login launches the same code – a second roundtrip – and the $url variable now holds a link to the login-page since it was the login page which triggered roundtrip two.

    It must be possible to create a session variable to hold the first referring uri and use it in the next roundtrip.

    • This reply was modified 1 year, 5 months ago by  fhundewadt.
    • This reply was modified 1 year, 5 months ago by  fhundewadt.

    Have I been typing too fast? I am a fast typist but why suddenly moderate in the middle of thread?

    Solution:

    Install WP Session Manager
    https://github.com/ericmann/wp-session-manager

    Modify clean-login.php

    
    function clean_login_load_before_headers() {
    	global $wp_query; 
    	if ( is_singular() ) { 
    		$post = $wp_query->get_queried_object();
    		
    		// If contains any shortcode of our ones
    		if ( $post && strpos($post->post_content, 'clean-login' ) !== false ) {
    			// Sets the redirect url to the current page 
    			$url = clean_login_url_cleaner( wp_get_referer() );
    
                            // Add redir variable - to the session
    			$wp_session = WP_Session::get_instance();
    			if ($wp_session['redir'] == '') {
    				$wp_session['redir'] = $url;
    			}
    
    			// LOGIN
    			if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'login' ) {
    				$url = $wp_session['redir'] == '' ? clean_login_get_translated_option_page( 'cl_login_url','') : $wp_session['redir'];                
    				$user = wp_signon();
    				if ( is_wp_error( $user ) )
    					$url = esc_url( add_query_arg( 'authentication', 'failed', $url ) );
    				else {
    					// if the user is disabled
    					if( empty($user->roles) ) {
    						wp_logout();
    						$url = esc_url( add_query_arg( 'authentication', 'disabled', $url ) );
    					}
    					else 
    						// reset the redir variable
    						$wp_session['redir'] = '';

    If you do not want to rely on the WP Session Manager plugin you can include it and use a wrapper like this guy
    https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/master/includes/class-edd-session.php

    • This reply was modified 1 year, 5 months ago by  fhundewadt.
    • This reply was modified 1 year, 5 months ago by  fhundewadt.

    solved by op

    Plugin Author Alberto Hornero

    (@hornero)

    Good to know. Please, remember that any update in the plugin will overwrite this modification.

    🙂 I know – which is why I copied your plugin as clean-login-ex

    Is there anything I should know on how?

    Is the approach similiar to creating a child-theme?

    Plugin Author Alberto Hornero

    (@hornero)

    That’s OK. This is the only way to keep your own modifications in the code. Many people have requested a kind of “child-plugin”, but nowadays it does not exist; that one is the only approach.

    Regards.

    I’m having this same issue now and the solution isn’t entirely clear….
    OP, @fhundewadt, would you mind sharing your new version of clean-login.php in its entirety? Thanks for giving back to the community!

    I have added the mods to the most recent version of clean-login and added it to Github. The modded version requires the WP Session Manager to work.

    https://github.com/fhdk/clean-login-ex

    https://github.com/fhdk/clean-login

    • This reply was modified 1 year, 1 month ago by  fhundewadt.
    • This reply was modified 1 year, 1 month ago by  fhundewadt.

    @fhundewadt that is very cool! Do we need both clean-login and clean-login-ex installed?

    @butchewing

    Only clean-login-ex and WP Session Manager

    And if the original author make updates to the plugin those will not be reflected in the -ex version.

    • This reply was modified 1 year, 1 month ago by  fhundewadt.
    Plugin Author Alberto Hornero

    (@hornero)

    That was a brilliant idea! I really enjoy having mods and forks of the original one 🙂

    Hola Alberto,

    Just wanted to drop by here because we had a similar problem with the plugin (the user not being redirected to the referrer page), @fhundewadt almost got the bottom of it when mentioning that it seemed that the plugin made a second roundtrip to the login, although the issue is simpler than that. Seems it is just that the plugin is killing its own referrer variable.

    Basically this line at line 277 (version 1.9.3):

    // Sets the redirect url to the current page
    $url = clean_login_url_cleaner( wp_get_referer() );

    that variable is being overridden right after with the next lines, right when the “login” action is detected:

    $url = clean_login_get_translated_option_page( 'cl_login_url','');

    I’m wondering why would you want to override the referrer this way? Might it be better just to check “if $url is empty” then use the default login page url.

    So, as because with that variable declaration you’re basically killing the referred and forcing users to go to the login url, commenting it out solves the original issue, regardless of if the page is protected, private, public or whatever.

    Hope it helps!

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘[Redirection] Return to page viewed when login activated’ is closed to new replies.