Remembering personal details in WordPress

| 3 Comments | No TrackBacks

One of the minor advantages MT has over WordPress is that the former gives a commenter the option of having the computer store his personal details (his name, email address and web URL) after he submits the comment. WordPress, on the other hand, does this automatically, so you can't turn it off - so if you submit a comment on a public computer, such as at the cyber-cafe or the Apple Store, you leave your email address open for all to see.

Well, not on my blog anymore! I've hacked the theme and the comment submission PHP script so that you can choose whether to let the computer remember your details.

Here's how.

First, you need to open the file comments.php in your theme directory. Search for "leave a comment" and you should find the HTML comment form.

You need to insert a checkbox, which I've done after the URL field and before the actual comment box.

<p>
<input type="checkbox" name="remember" value="remember" tabindex="4" />
<label for="remember">Remember details?</label>
</p>

I adjusted the "tabindex" on the next two fields as well, to 5 and 6 where they were 4 and 5 before.

Then, you need to open up the PHP script wp-comments-post, which you'll find in the main blog directory.

You'll find the following code:

setcookie('comment_author_' . COOKIEHASH, stripslashes($comment_author), 
   time() + 30000000, COOKIEPATH);
setcookie('comment_author_email_' . COOKIEHASH, stripslashes($comment_author_email), 
   time() + 30000000, COOKIEPATH);
setcookie('comment_author_url_' . COOKIEHASH, stripslashes($comment_author_url), 
   time() + 30000000, COOKIEPATH);

You need to enclose that with the following:

if( $remember ) { 
(insert the setcookie code here)
}

And that's it! So now you can comment here on a public computer, and nobody will be able to get your address.

No TrackBacks

TrackBack URL: http://www.blogistan.co.uk/mt4/mt-tb.cgi/3836

3 Comments

Asslamu Alakum, thanks for this information, I had a problem with a public computer at the university for saving my e-mail address on it when I once commented.

Asslamu Alakum, thanks for this information, I had a problem with a public computer at the university for saving my e-mail address on it when I once commented.

Hey, thanks for this code! The one thing I had to change was using this for the beginning of the if statement:
if($_POST['remember'] == 'remember') {
Maybe the method changed to POST with Wordpress 1.5 or something...
Anyways, good work, it was very helpful.

Leave a comment

Archives

OpenID accepted here Learn more about OpenID
Brass Crescent, European blog winner 2008