Skip to content

Instantly share code, notes, and snippets.

@Viper007Bond
Created May 23, 2012 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Viper007Bond/2778130 to your computer and use it in GitHub Desktop.
Save Viper007Bond/2778130 to your computer and use it in GitHub Desktop.
Check to see if an e-mail address has a Gravatar or not
<?php
function sunset_has_gravatar( $email ) {
$hash = md5( strtolower( trim( $email ) ) );
// If not in the cache, check again
if ( false === $has_gravatar = wp_cache_get( $hash, 'sunset_has_gravatar' ) ) {
$request = wp_remote_head( 'http://0.gravatar.com/avatar/' . $hash . '?d=404' );
$has_gravatar = ( 404 == wp_remote_retrieve_response_code( $request ) ) ? 0 : 1;
wp_cache_set( $hash, $has_gravatar, 'sunset_has_gravatar', 86400 ); // Check daily
}
return (bool) $has_gravatar;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment