Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Grégory Viguier

    (@greglone)

    Hello.

    it sends them away from the page they logged in from.

    I don’t think it’s related to my plugin. If it redirects people after they log in it must be because something told it so. So maybe the redirection information is transmitted the wrong way.
    Do you know if they have the same behavior without my plugin?

    Greg

    Thread Starter dananourie

    (@dananourie)

    Ok, I’ll dig into this more. To isolate the problem, do I just disable sf-move-login, or do I also need to remove what it wrote to .htaccess? This plugin has worked great for brute force issues and bogus registrations. I just want to disable temporarily.

    Thank you!

    Plugin Author Grégory Viguier

    (@greglone)

    It won’t be necessary, you just need to disable the plugin the time being.

    Thread Starter dananourie

    (@dananourie)

    By logging in through an article at the bottom of the page to comment, the user logs in as expected. I use mingle forum, and it’s login won’t work at all with this plugin, as the forum is looking for wp-login.php. So I disabled mingle’s login, and thought I could hardcode the login url, and while it logs the user in, it redirects to the admin or profile.

    So at the bottom of this page: https://secularbuddhism.org/2015/08/02/episode-228-bj-leiderman-npr-music-meditation-and-moving-from-sound-to-silence/ when I log in, I stay on that page as expected.

    But when I try to login from the discussions forum, where I hard-coded the login, it doesn’t work correctly. https://secularbuddhism.org/forum/

    I’m not sure how to hardcode the login link so it stays in discussions.

    Ideas? Thank you!

    Plugin Author Grégory Viguier

    (@greglone)

    Hello.

    If you take a look at the login link from “Episode 228”:

    https://secularbuddhism.org/frontdoor?redirect_to=http%3A%2F%2Fsecularbuddhism.org%2F2015%2F08%2F02%2Fepisode-228-bj-leiderman-npr-music-meditation-and-moving-from-sound-to-silence%2F

    There is a redirect_to parameter containing the current post’s URL. This is the part missing in your forum page.

    Now, how to make properly a link to the login page:
    First, there is a function for that, wp_login_url().
    To use it, we must catch the current page’s URL.

    We could try to get the permalink on the current page with get_permalink( get_queried_object_id() ) but the forum adds a bunch of other parameters (mingleforumaction, f, t, id…) so we must know them all to add them one by one. Not an easy task.

    Instead, we’ll use a function I created that returns the current page’s URL:

    if ( ! function_exists( 'sf_get_current_url' ) ) :
    function sf_get_current_url( $mode = 'base' ) {
    	$mode = (string) $mode;
    	$url  = ! empty( $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'] ) ? $GLOBALS['HTTP_SERVER_VARS']['REQUEST_URI'] : ( ! empty( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '' );
    	$url  = 'http' . ( is_ssl() ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST'] . $url;
    
    	switch( $mode ) :
    		case 'raw' :
    			return $url;
    		case 'uri' :
    			$url = reset( ( explode( '?', $url ) ) );
    			$url = reset( ( explode( '&', $url ) ) );
    			return trim( str_replace( home_url(), '', $url ), '/' );
    		default :
    			$url = reset( ( explode( '?', $url ) ) );
    			return reset( ( explode( '&', $url ) ) );
    	endswitch;
    }
    endif;

    And then, create the login URL is easy:

    echo '<a href="' . esc_url( wp_login_url( sf_get_current_url( 'raw' ) ) ) . '">' . __( 'Log In' ) . '</a>';

    For the registration URL there is also a function: wp_registration_url(), but it doesn’t need any parameter.

    echo '<a href="' . esc_url( wp_registration_url() ) . '">' . __( 'Register' ) . '</a>';

    I hope it will solve your problem.

    PS: don’t forget esc_url() around the URL, it’s an important security part.

    Plugin Author Grégory Viguier

    (@greglone)

    Hello.
    Nothing new?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Keep user on the page they login on’ is closed to new replies.