1

I have update the template_redirect hook so that I am able to get the referrer url and save it to session.

function redirect_url() {
    if (! is_user_logged_in()) {
        $_SESSION['referer_url'] = wp_get_referer();
    } else {
        session_destroy();
    }
}
add_action( 'template_redirect', 'redirect_url' );

I am however now getting a persistent PHP warning that I am unable to get past.

PHP message: PHP Warning: session_destroy(): Trying to destroy uninitialized session in functions.php on line 399" while reading response header from upstream.

Any suggestions here would be great.

designmode
  • 143
  • 2
  • 12
  • The hook `template_redirect` is called before pretty much every page load, is that what you want? **Every** page? Further, your code reads "if someone isn't logged in, do something, otherwise destroy the session" which amounts to "If someone is logged in destroy the session". Is that what you want? Also, WordPress doesn't use sessions natively, so are you manually starting one on your own or using a plugin that does this? If this is really what you want, you could [check the session status first before destroying it](https://stackoverflow.com/a/65958907/231316). – Chris Haas Jul 18 '22 at 19:47

0 Answers0