Created
May 23, 2012 22:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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