If you use protected posts on your WordPress blog you may have noticed that WP-Cache doesn’t cache those password protected posts properly. I didn’t know this, but James Farmer did so I went looking and found a fix.
In the plugins/wp-cache/ directory, open wp-cache-phase1.php in your favourite text editor and look for the following line:
if (preg_match(“/^wordpress|^comment_author_email_/”, $key)) {
Replace that line with this one:
if (preg_match(“/^wp-postpass|^wordpress|^comment_author_email_/”, $key)) {
Save and upload the file if necessary and clear your cache. Password protect posts should be cached properly now!
Ironically, this post wasn’t being cached by WP-Cache because the url contains the string “wp-”. Here’s how to fix that bug. Open wp-cache-phase2.php and look for the following line:
if (strlen($expr) > 0 && strstr($uri, $expr))
Change it to read:
if (strlen($expr) > 0 && substr( $uri, 1, strlen($expr) ) == $expr )
Phew. This post is now cached.

16 Comments
sir.peterson (1 comments.) on October 18, 2007 at 1:04 pm.
Thank you for the tip. I’ll try it out.
Mushu on October 18, 2007 at 4:11 pm.
Hi! I use Wp-Cache and some posts are password protected and this fixed really worked! I applied both of them, to phrase 1 and 2.
Thanks.
Sean (1 comments.) on October 18, 2007 at 4:22 pm.
What version of WP-Cache are you running? There was a 2.1.2 release a couple weeks ago, so just wondering if that was the version you did this fix too.
If so, it might also be good measure to let the plugin author know about your wonderful fix.
Thanks for the information… I’m now off to fix mine
Donncha (1707 comments.) on October 18, 2007 at 4:31 pm.
Sean – it’s for version 2.1.2, I will be contacting Ricardo, although he says he wants to pass the baton on because he doesn’t have much time to maintain wp-cache any more unfortunately.
Adam Kayce : Monk At Work (1 comments.) on October 18, 2007 at 6:47 pm.
That totally broke my site.
I tried changing it back, and it broke even worse… so I re-downloaded the original, uploaded it, and my site is back.
Caveat emptor.
Donncha (1707 comments.) on October 18, 2007 at 7:07 pm.
Adam – did you check your error log? Anything obvious there? The small changes above shouldn’t cause your site to die. Sounds like a syntax error!
James (1 comments.) on October 18, 2007 at 7:15 pm.
I don’t know what you’ve got happening on your blog here but your single page posts are missing the background making them impossible to read.
Donncha (1707 comments.) on October 18, 2007 at 7:56 pm.
James – thanks, I saw that happen once but couldn’t repeat it and there wasn’t an error in my error log. Not sure what causes that.
Mushu on October 19, 2007 at 12:14 am.
@Adam and Donncha:
Donnacha: Thanks for your nice modification, some of my friends have said they can now visit the pages with WP-Cache on (2.1.2 version).
Adam: Have you’ve cleared the cached pages and expired pages?
Pingback: links for 2007-10-19 | Ge Xiaofei
Doniek (1 comments.) on October 19, 2007 at 2:28 pm.
Thanks James. I have this problem.
Donncha (1707 comments.) on October 23, 2007 at 5:00 pm.
Just found a bug with the second modification – if your blog isn’t installed in the root of your server then it’ll never return true. The solution probably is to add all the wp-* files that in the index directory of your install. That’ll be files like wp-cron.php, wp-login.php, etc. Or don’t use “wp-” in your posts
Lloyd Budd (5 comments.) on October 26, 2007 at 4:40 pm.
How important can it really be to cache protected posts?
Pingback: WordPress Super Cache 0.1 at Holy Shmoly!
Pingback: WP Super Cache ç¼“å˜æ’件汉化版 - Wordpressæ’件䏿–‡ç«™ - Wordpress 广告 Rss 常用 éŸ³ä¹ æ‘˜è¦ è®¢é˜… wiki 陿€ æ’ä»¶
www.anhblog.net (1 comments.) on January 17, 2009 at 9:23 am.
How i can control time out on Cache, i always meet time wait so long to it automatic clear old cache. Customer feel sad