I was approached by an artist in residence to a library in the US, he was developing a novel use of wordpress on a shared host which requested library users to leave comments.
The Problem
Using worcpress he was inviting users to review his artisit blog/site and to leave comments.
The problme was that the shared machine in the library was leaving the comments of previous users visible to the next user. The comments were to be approved before display so seeing un-approved comments was not acceptable,
The problem is that comments are held in a cookie and displayed to the commentor. Because differnt users are using the same machine (and theref0re the same cookie) he data needs to be cleared down somehow.
The solution
No easy fix to this one, it was down and dirty and editing the wordpress code base to fix this one.
A cookie is set in the file wp-comment-post.php, I edited this and added three lines to set the timeout of the cookies. These lines set the timeout to a point in the past. I did it this way rather than removing the cookies as I was unsure how they were used in other parts of the code.
I added the following three lines just before the wp_redirect command at the bottom of the file
setcookie(‘comment_author_’. COOKIEHASH,””, time() – 3600);
setcookie(‘comment_author_email_’. COOKIEHASH,””, time() – 3600);
setcookie(‘comment_author_url_’ . COOKIEHASH, “”, time() -3600 );
Things To Remember
Whenever you update the wordpress code base with the next release of WordPress you will need to update the php file. If the functionaltity I “hacked” is ever changed, a new solution will be required.
Did It Work?
Of course it did, my client was very happy with this neat solution, and I was frankly amazed it worked first time!
4 thoughts on “Cookies But No Millk”
Hi :o)
Your post popped up when I was googling trying to figure out how to fix an ongoing issue with my blog – my comment fields do not ‘remember’ my reader’s information after they leave a comment. I thought it was happening because my blog resided in a subdomain and therefore the cookie was possibly a ‘third-party’ cookie but I have since moved it to the root of my domain and it still doesn’t work.
I’m wondering if you have any idea why this might be happening since you seem to have a much better grasp of the WP cookie.
Thanks for any help you can give…
~Jess
@Jess why not try activating comment moderation to see if this activates the cookies, these cookies are only stored so someone can see what message they left if it is not displayed.
I left a test message which I could see. Hope that helps
@Neil I noticed today that it also does not remember me. I’ve cleared my cookies and added my url on my ‘definitely safe, save a cookie fer cripesakes’ (or whatever it’s officially called in ‘internet settings’) list on both my xp and vista computers with no luck.
@Neil I figured it out, it turned out to be a database issue/plugin issue. I learned this when I installed a test version of WP on a subdomain and tested my new theme. I noticed that it did ‘remember’ me and I then went and turned off all my plugins on my old wp install. I still had a problem, so I decided to export my posts/comments/etc. to the new wp install and database and reinstall my plugins that I *had* to have. It’s still working – and the fix only took me 14 hours from start to finish. ;o) Thanks again for your attention to my first comment!
Comments are closed.