Cookies But No Millk

Photo by inajeep
Photo by inajeep

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!

Get A No Obligation Quote

Do You Need Help With Your WooCommerce Site?

Click through to the next page and complete the form to get a free no obligation quote to fix any issue you are having with your WooCommerce site.