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.

1 Answer 1


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;
  • 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
    Commented Dec 8, 2012 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 protected]'));" 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
    Commented Dec 9, 2012 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
    Commented Dec 9, 2012 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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