Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Aurélien Denis

    (@maigret)

    I’ve finally solved my problem with wp_redirect in a template page. But I’m opened to another approach. ??

    Plugin Author Robert D Payne

    (@rpayne7264)

    The built-in supported method for redirects is JavaScript coding.

    In the following example, all links with class rdp_jb_must_sign_in are assigned an event listener that sets a cookie, with the cookie value derived from the link’s href attribute. A 30 second expiration is added to the cookie, as well. The cookie name must always be rdp_ll_login_redirect.

    When the pop-up log-in window executes its close script, the function rdp_ll_login_onClose is called, and it reloads the page to show that the visitor is logged in. In the document.ready() function, the cookie is read, then deleted, and the parent window is redirected to the appropriate URL.

    = Code in custom sign-in JavaScript file =

    var $j=jQuery.noConflict();
    // Use jQuery via $j(...)
    
    $j(document).ready(rdp_sign_in_onLoad);
    
    function rdp_sign_in_onLoad(){
        var redirectPath = Cookies.get('rdp_ll_login_redirect');
        var loggedIn = $j('body').hasClass('logged-in');
        if(loggedIn && redirectPath && redirectPath != 'undefined'){
            Cookies.remove('rdp_ll_login_redirect', { path: '/' });
            window.location.href = redirectPath;
        }
    
        $j('#rdp-jb-main').on( "click", '.title.rdp_jb_must_sign_in' , function(event){
            event.preventDefault();
            var redirectURL = $j(this).attr('href');
            var date = new Date();
            date.setTime(date.getTime()+(30*1000));
            Cookies.set('rdp_ll_login_redirect', redirectURL, {expires: date, path: '/' })
        });
    }//rdp_sign_in_onLoad
    
    function rdp_ll_login_onClose(redirect_url){
        //reload page and cause redirect to occur
        window.location.reload();
    }//rdp_ll_login_onClose
    Thread Starter Aurélien Denis

    (@maigret)

    Thanks for this piece of code, I’ll try it soon! ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Redirect after login’ is closed to new replies.