Support » Plugins » Hacks » Clear cookie of posts password protected

  • I’m sorry if this isn’t the right section of the forum to publish this topic.

    I’d like to create a page just to reset cookie.
    I tried to create a page: unset.php, I put the page inside the wp-content\themes\mytheme\, with this code:

    <?php setcookie("wp-postpass_", "", time()-3600);
    unset($_COOKIE["wp-postpass_"]); ?>

    Then, I would like to call this way:

    <form method="post" action="unset.php">
      <input type="submit" value="logout"/>

    Or even
    <a href="/unset.php">Logout</a>

    But it’s not working. Any ideias? Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • esmi


    Forum Moderator

    I want to clear the posts protected pass. How does that help? How can I call that function in button?



    Forum Moderator

    I appreciate your try to help, but it’s in vain.
    Your first link, it doesn’t say where to put that code, for example.
    The second link a guy in comments said this:

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

    And, again, I would prefer to have a button, or sort of, so I could redirect to another page and log off.

    I know the code to delete the cookie, I don’t know where to put it. I would like to create a custom page (unset.php), like I said in the first it possible or not? Because, whenever I create the page, if I go to it automatically redirects to 404 error page.

    I must say that this custom page I put into the same directory as 404 error that the problem?

    I have currently this:

    add_shortcode('clear__', 'clear__cookies');
    function clear__cookies() {
      setcookie('wp-postpass_' . COOKIEHASH, '', time()-3600);

    And, in the form, I call this way:
    [clear__ foo="clear it"]Some text input[/clear__]
    But I’m getting:
    Warning: Cannot modify header information – headers already sent by

    Moderator bcworkz


    setcookie() uses the PHP header() function, so calling from a short code callback is way too late.

    Put your setcookie() code on the separate unset.php file. Require once the wp-load.php file first thing. You probably want to call auth_redirect() next. The separate file will get rid of the headers sent issue.

    If it still does not work, the problem would be the COOKIEHASH constant was re-defined between calls.

    I managed to get this working yesterday, but I forgot to put here.
    My only problem was the location of the page “unset.php”.

    1 – So, I created the file unset.php and I copy into the root directory of the website (not wp-content\themes..etc)
    2 – Coded a function to get all cookies wordpress was using
    3 – Match the cookie to “wp-postpass_”
    4 – If the cookie was found, I delete it and redirect to index.php

    To call everything, I just needed to call the page unset.php by ahref.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Clear cookie of posts password protected’ is closed to new replies.