• Resolved zchristian

    (@zchristian)


    Thanks a lot for this very good plugin. Does exactly what I need, with one exception:
    I try to avoid the standard WordPress login form in case a restriction applies. So I used the custom url (page (php) with embedded login form). Unfortuantely the plugin does not append the current url when redirecting, so I don’t know where to go after a successful login.
    Would be good to have an additional option like “Custom url & back”.

    For now I changed the Restriction.php file starting at line 80 and misused the “login” option:

    		switch ( $restriction['redirect_type'] ) {
    			case 'login':
    //				$redirect = wp_login_url( static::current_url() );
    				$redirect = $restriction['redirect_url'].'?dest='.urlencode(static::current_url());
    				break;
    
    

    Cheers
    Christian

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hamilton-Brown

    (@hamiltonbrownfarringdon)

    I’m having the same issue, I agree this would be a great feature to have.

    Can I ask what the solution above does? Does this take the user to initial URL they were trying to access?

    Many thanks

    Plugin Author Daniel Iser

    (@danieliser)

    @zchristian I don’t see how this could be done reliably. To clarify no two plugins that offer custom login forms do redirects in the same way. It would be more manageable for us to simply add a filter there so that you can add whatever you like to the urls. Either way due to the variety of possible url structures it would require we won’t be adding this as a feature. That said why not just filter the login url itself. That would be the most reliable and make sure users never see WP-login.php.

    Hope that helps. Take care.

    Thread Starter zchristian

    (@zchristian)

    @hamiltonbrownfarringdon
    Sorry for the late response!
    The above solution just appends a parameter “dest” to the custom url. The value is the currently accesed page, which is protected.
    On your custom login page you need to use the value of “dest” to redirect after successful login. E.g. fill the “redirect_to” value of the wp_login_form() call with this value.

    Hope that helps.

    Christian

    Thread Starter zchristian

    (@zchristian)

    @danieliser yes, I see the problem, that this will not work for most plugins providing custom login pages.

    I use now the wp_redirect hook to add the redirect url

    // add current url as parameter "redirect_to". Only if NOT logged in and current url != "wp-login.php"
    function add_referrer($url) {
    	return (wp_validate_auth_cookie('','logged_in')!==false || strpos($_SERVER["REQUEST_URI"],"wp-login.php")!== false) ? $url : add_query_arg( 'redirect_to', urlencode($_SERVER["REQUEST_URI"]),$url);
    }
    add_filter( 'wp_redirect', 'add_referrer'); 
    

    Christian

    Hamilton-Brown

    (@hamiltonbrownfarringdon)

    Hi

    Can I ask where in restrictions.php you put the above code?

    If I can get this to work will be a huge help to me.

    Many thanks

    Thread Starter zchristian

    (@zchristian)

    @hamiltonbrownfarringdon: you mean the “wp_redirect” filter code?
    This has nothing to do with the plugin, but is an independent filter. Just add the code snipped to functions.php of the theme, or better create a child theme and a corresponding functions.php for the child.
    Once activated, add_referrer() is called whenever a redirect happens within WordPress.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Feature request: Redirect to custom url and back’ is closed to new replies.