X

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.


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);
}

Comments  Leave a Reply

  1. Sergio Manetta April 11, 2013 at 9:06 am

    This code fucked up the rest of my site!! I removed it and now the passwords are not accepted!!

    1. when you enter a password what happens ?

      1. Sergio Manetta April 11, 2013 at 9:45 am

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

        1. this is the correct one

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

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!