Home / admin / Expire protected post cookie with session
  • How to Expire protected post cookie with session

    expire-protected-post-cookie-with-session

    Adding this snippet to the functions.php of your wordpress theme with a time of 0 in setcookie() forces the cookie to expire with the session. Great little snippet by Drew Jaynes thanks for submitting.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    add_action( 'wp', 'post_pw_sess_expire' );
        function post_pw_sess_expire() {
        if ( isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) )
        // Setting a time of 0 in setcookie() forces the cookie to expire with the session
        setcookie('wp-postpass_' . COOKIEHASH, '', 0, COOKIEPATH);
    }
    

    ( WordPress codex functions, hooks, in this snippet. )

    add_action, _e, _ex, wp,
  • This code fucked up the rest of my site!! I removed it and now the passwords are not accepted!!

    • when you enter a password what happens ?

      • Nothing, keeps asking again the password. Does this script also modify some other pages.php or files.php automatically ?

        • str

          this is the correct one

          setcookie(‘wp-postpass_’ . COOKIEHASH, $_COOKIE[‘wp-postpass_’ . COOKIEHASH], 0, COOKIEPATH);