I’ve searched high and low for an extension which displays a link that deletes this cookie, but nothing turned up. So I simply modified “wp_pass.php” a little and wrote a small function.
First, create a file named “wp_passexpire.php” with the following:
<?php
require( dirname(__FILE__) . ‘/wp-config.php’);// Expire
setcookie(’wp-postpass_’ . COOKIEHASH, ”, time() - 864000, COOKIEPATH);wp_cache_delete($blog_id);
wp_safe_redirect(wp_get_referer());
?>
Second, put the following in “function.php” of your theme:
function pass_expire($before=”", $text=”Delete”, $after=”") {
global $post;
if (!empty($post->post_password)) { // if there’s a password
if ($_COOKIE['wp-postpass_' . COOKIEHASH] == $post->post_password) { // and it matches the cookie
echo $before . ‘<a href=”/wp-passexpire.php”>’ . $text . ‘</a>’ . $after;
}
}
}
And lastly, call it with:
<?php pass_expire(’ | ‘, ‘Delete Cookie’, ‘ | ‘); ?>
Test it out, password is “test”. ![]()
Related Posts:
- Private entries revisited...
- Upgrade Your WordPress...
- Private entry hack...
- New b2comments hack...
- Word Count Patch...









George said:
Hello Michael,
I have an error in the functions.php with your script:
Parse error: parse error, unexpected T_STRING, expecting ‘,’ or ‘;’ in D:\EasyPHP20\www\wordpress\wp-content\themes\default\functions.php on line xx
Plz help…
February 2, 2008, 12:41 AMMichael said:
George, I don’t see anything wrong with my code… contact me.
February 2, 2008, 11:21 AMNathan said:
I’m getting the say error when putting that block of code into functions.php
did you figure out what was wrong?
thanks for this work around
March 28, 2008, 12:02 PMMichael said:
WP was converting single quotes into ticks. Be sure to check for this.
March 28, 2008, 12:31 PMAnja said:
Hi, can this fix my problem - That public computers will have access to my password-protected posts because of the cookie?
I’d just like the cookie to be deleted when the browser is closed I guess.
Cheers =)
September 1, 2008, 2:49 PMMichael said:
Anja » That can only be done on the client side unless WP use session cookies.
September 1, 2008, 3:32 PMAnja said:
I found my solution a few minutes ago. In wp-pass.php, i just set the seconds to “600″, 10 minutes, which works fine for me. I guess it was so simple that no one had bothered to mention it anywhere! But that’s all I needed =)
September 1, 2008, 4:57 PMMichael said:
Anja » The downside of doing that is your friends will have to memorize the password. But it works.
September 1, 2008, 5:20 PM