• Resolved mikesafh

    (@mikesafh)


    Using the Login with Ajax plugin, is it possible to have a conditional redirect? As in, only redirect to the specified URL if the referrer URL is a specific one (or in a list of defined ones)? For example, I don’t want the redirect to occur if they log in from some parts of the site, but I do want the redirect to occur if they log in from the home page.

    Thanks.

    Michael

Viewing 4 replies - 1 through 4 (of 4 total)
  • I have just solved this for myself. I didn’t want a redirect from the plugin on event pages but did for password resets and logins from …/wp-login.php

    Spent a good few hours trawling and cobbled this together and it works great. Added it to Snippets.

    function my_login_redirect( $redirect_to, $request, $user ) {
    
    if($host = "https://www.mysite.co.uk/wp-login.php") {
    
    $redirect_to = home_url();
    
    return $redirect_to;
    }
    }
    
    add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );

    Thread Starter mikesafh

    (@mikesafh)

    Thanks for that. Looks like you’re just adding custom PHP code to WordPress, not modifying functionality of the Login with Ajax plugin, though, correct? (I’m not sure what you are referring to by ‘Snippets.’)

    I could also modify the login-with-ajax.php file to put a check for current URL, but that would just get overwritten by the next update, which I’m trying to avoid having to deal with.

    • This reply was modified 2 years, 1 month ago by mikesafh.

    Yes I’m just adding a function for said functionality.

    Login with Ajax gives the option to redirect by user not by specific URLs.

    I wanted all logins by users from the pages with the LWA widget to refresh at the same URL.

    But not when they were logging in, usually after a password reset, from …/wp-login.php where instead of them being redirected by LWA back to …/wp-login.php I wanted them to go to the home page.

    Snippets is just a plugin where you can add bits PHP code and keep them organised. This is the method recommended by Marcus’ other project team – Events Manager to modify the functionality of that plugin. The function doesn’t have to rely on any LWA code.

    Exactly as you note, if you added it to the LWA plugin code every time it updated you’d loose you custom code.



    Thread Starter mikesafh

    (@mikesafh)

    Just to close the loop on this, I implemented that and it works great, thanks. I’m going to try and put some extra logic in there to handle role-based redirects, once I find time to slice out possible downtime given that I’m not sure what information is available as context. I’ve got a PHP snippet running under another plugin (XYZ Plugin) on the home page that does what I want, I’m just trying to bypass the need to have to do a client-side redirect when I don’t need to.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Conditional login redirect, Login with Ajax plugin’ is closed to new replies.