• One issue I had with this plugin that after logging in, the user was directed to the homepage rather than the page s/he signed up from. Here’s what I did to redirect:

    In /includes/lib/PkliLogin.php, somewhere around line 115:

        // This function displays the login button on the default WP login page
        public function display_login_button() {
    
            // User is not logged in, display login button
            echo "<p><a rel='nofollow' href='" . $this->get_auth_url() . "'>
                                                <img alt='LinkedIn' src='" . PKLI_URL . "includes/assets/img/linkedin-button.png' />
            </a></p>";
    
        }

    Becomes:

        // This function displays the login button on the default WP login page
        public function display_login_button() {
    
    	$currentURL = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    	setcookie('li_redirect', $currentURL, 0, COOKIEPATH, COOKIE_DOMAIN, false);
    
            // User is not logged in, display login button
            echo "<p><a rel='nofollow' href='" . $this->get_auth_url() . "'>
                                                <img alt='LinkedIn' src='" . PKLI_URL . "includes/assets/img/linkedin-button.png' />
            </a></p>";
    
        }

    Around line 406, change:

            // Default fields
            return "<a href='" . $auth_url . "' class='$class'><img src='" . $img . "' /></a>";        
        }

    to:

            // Default fields
    	$currentURL = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    	setcookie('li_redirect', $currentURL, 0, COOKIEPATH, COOKIE_DOMAIN, false);
            return "<a href='" . $auth_url . "' class='$class'><img src='" . $img . "' /></a>";        
        }

    This sets a cookie called “li_redirect” with the page URL of the page that they last saw the login button on.

    Under Ultimate LinkedIn Integration Plugin Settings, set the Login Redirect URL and Sign-Up Redirect URL to https://www.yourdomain.com/?li=1

    Modify your child theme’s header.php to include a hook to look for the ‘li’ variable in the URL and that the ‘li_redirect’ cookie is set:

    <?php
    if((isset($_COOKIE['li_redirect'])) && ($_GET['li'])) {
    $li_redirect = $_COOKIE['li_redirect'];
    unset($_COOKIE['li_redirect']);
    header("Location: ". $li_redirect);
    }
    ?>

    (Make sure any caching you have in place excludes https://www.yourdomain.com/?li=1)

    • This topic was modified 5 years, 9 months ago by gdfwilliams.
Viewing 1 replies (of 1 total)
  • Thread Starter gdfwilliams

    (@gdfwilliams)

    The header.php change above should include an additional line to properly expire the cookie. Also, I was experiencing some issues with getting stuck on wp-login if that was my referring URL, so we push them to wp-admin and let WP decide what to do with them:

    <?php
    if((isset($_COOKIE['li_redirect'])) && ($_GET['li']) &&  is_home()) {
    $li_redirect = $_COOKIE['li_redirect'];
    unset($_COOKIE['li_redirect']);
    setcookie('li_redirect', '', time() - ( 15 * 60 ) );
    if (strpos($li_redirect, 'wp-login') !== false) {
    $li_redirect = admin_url();
    }
    header("Location: ". $li_redirect);
    }
    ?>
    • This reply was modified 5 years, 9 months ago by gdfwilliams.
Viewing 1 replies (of 1 total)
  • The topic ‘Redirect After Login’ is closed to new replies.