• Resolved Kurt Junker

    (@kjunker)


    Hi again,

    sry to bother you again. I still have a challenge to redirect a user not to the default site (homepage) but to the path which was given with the uri.

    I tried your hooks but they do what they have to do ( damn ?? ).
    I think it is a good idea to have also a hook which could be called before the redirect from database is called.

    So you have the possibility request the following url:

    https://mysite.com/calender/events/?rest_route=/jwt/v1/autologin&jwt=JWT

    With the hook you can do something like this:

    
    add_action(
        'simple_jwt_login_redirect_hook',
        function(WP_User $user) {
            $requestUrl = $_SERVER['REQUEST_URI'];
            $redirectUrl = get_site_url() . strtok($requestUrl, '?');
            wp_redirect($redirectUrl);
        }
    );
    

    Is it possible to add this option?!

    Thanks a lot.

    Kurt

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Nicu Micle

    (@nicu_m)

    Hello Kurt,

    Yes, it is possible. I will add this hook just before the redirect.

    I will release this in a couple of hours and I will come back with an example on how you can use it.

    Plugin Author Nicu Micle

    (@nicu_m)

    Hello,

    Please update the plugin to version 1.6.3 and you will find the hook simple_jwt_login_redirect_hook.

    This hook is called before the user is redirected to the page he specified in the login section.

    Example of usage:

    
    add_action(
        'simple_jwt_login_redirect_hook',
        function($url) {
            $redirectUrl = $url . '?something=123'
            wp_redirect($redirectUrl);
        }
    );
    

    PS: $url is the URL where the user is redirected after auto-login.

    Best regards.

    • This reply was modified 4 years, 9 months ago by Nicu Micle.
    Thread Starter Kurt Junker

    (@kjunker)

    Hi,

    it works!

    Thanks a lot for your fast support.

    Best Regards.

    Plugin Author Nicu Micle

    (@nicu_m)

    Hello Kurt,

    Thank you for donating to this plugin.

    Have a nice weekend.

    Best regards,
    Nicu.

    Hi @nicu_m , was this tested with the latest WP version? My plugin login setting is set to redirect to homepage, enabling the hook & calling this on functions.php:

    add_action(
        'simple_jwt_login_redirect_hook',
        function($url) {
            $redirectUrl = $url . '/page';
            wp_redirect($redirectUrl);
        }
    );

    $url therefore should be the homepage, so I should get to homedomain.com/page right? It Seems to just redirect to regular homepage, whatever I put at the $redirectUrl, wether it’s ‘/page’, ‘page’, ‘?something=123’, etc, still just plain homepage. Any idea why?

    Ilya

    Plugin Author Nicu Micle

    (@nicu_m)

    Hello @igurman,

    Yes. It is tested with the latest WordPress version.

    Please make sure you have enabled the hook from Plugins Settings-> Hooks and save the settings.

    In the code, I make a verification if the hook is enabled, and only then the action is triggered.

    Also, this function has 2 arguments. Here is a sample how you should call it:

    
    add_action(
        'simple_jwt_login_redirect_hook',
        function($ur, $requestl) {
            $redirectUrl = $url . '?something=123';
            wp_redirect($redirectUrl);
        }
        ,10
        ,2
    );
    

    Best regards,
    Nicu.

    Hi @nicu_m Nicue thanks for the quick reply. Yes that’s how I’m using it and the hook is enabled. Could it be something to do with the install being a multisite? (Even though this is attempted for a single subsite)

    Plugin Author Nicu Micle

    (@nicu_m)

    I’ve just checked this o the latest WordPress version, in a site from my multisite network.

    Try to add this code in wp_config.php or at the bottom of routes.php (wp-content/plugins/simple-jwt-login/routes.php’).

    My guess is that the file where you wrote the code, it is not included.

    Let me know if this works for you.

    Best regards,
    Nicu.

    @nicu_m appreciate your reply but doesn’t seem to matter where I add it, the hook isn’t called.
    I even created my own plugin, and activated on that subsite:
    https://ibb.co/gjQnrQR

    The hook is enabled:
    https://ibb.co/C2mtK5f

    It just redirects to whatever is mentioned on the ‘login’ tab of the plugin (homepage, dashboard..) and ignores the hook.

    Not sure what I’m doing wrong and sorry for the constant bothering here.

    Ilya

    • This reply was modified 4 years, 5 months ago by igurman.
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Redirect Hook’ is closed to new replies.