Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm writing a plugin to PPK encrypt non-public comment data as a second line of defence against crackers (one of my sites was recently compromised, so I have been rather spurred into action!). To achieve this, I am writing a meta comment value containing the encrypted email/IP for each comment, and once everything has been tested, the admin will be able to click a button and safely null the plaintext email/IP fields.

Unfortunately this means that Gravatars will stop working, since this requires a plaintext email field. So, I believe I can register on the get_avatar filter, but as far as I can tell I'll need to replicate all of the get_avatar() function in pluggable.php. Obviously that would means any subsequent core updates to this function will have to be manually patched into my copy, which is rather inelegant.

Or is there something I may have missed in which I can supply a MD5 hash and get all the other goodness in core Gravatar functionality automatically? I do love WP, but the dev docs are a touch on the sparse side for this :)

If that's not possible, I might try to ask the core team if they would consider adding a new filter. I should think blogs wanting to store personal data only for a limited time would appreciate a way of still being able to use Gravatars on much older comments.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

From Gravatar.com:

All URLs on Gravatar are based on the use of the hashed value of an email address (link)

Instead of storing an email adress in the comment data, you can store the md5-hash of that email adress. The email adress is encrypted and you can use gravatars. Use the filter add_filter( 'preprocess_comment', 'email_to_md5' ) to modify the email adress and do not null it later.

function email_to_md5( $commentdata ){
  if( ! empty( $commentdata['comment_author_email'] ) )
    $commentdata['comment_author_email'] = md5( strtolower( $commentdata['comment_author_email'] ) );

  return $commentdata;
}
share|improve this answer
    
That would be ideal - I will give it a go tomorrow! Many thanks indeed, I'll let you know how I get on. I hadn't noticed in get_avatar it would skip hashing for something that's already hashed. –  halfer Dec 8 '12 at 17:26
    
Ah right, that approach doesn't quite work. To test it, I've taken the email address in one of my comments, run it through php -r "echo md5(strtolower('email@example.com'));" and swapped in the resulting hash for the email address in the comment browser. Upon refreshing the page, the gravatar is replaced with the default one, rather than the user's usual one. I expect this is because get_avatar() is trying to rehash the hash. Any elegant approaches to fixing that, or do I have to replace that pluggable function as I originally suspected? Thanks. –  halfer Dec 9 '12 at 13:48
    
Sometimes I had to read the core files before write an answer. That's right, get_avatar rehash the email adress if it is not numeric. It seems you have to replace that function. –  Ralf912 Dec 9 '12 at 14:43
    
Alright, thanks Ralf; +1 for your time. –  halfer Dec 9 '12 at 15:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.