Tutorials WordPress How to validate user Gravatar for specific email id

How to validate user Gravatar for specific email id

Gravatar is one of the most common service used widely on WordPress blogging platform. Gravatar is used for providing globally unique avatar for a specific email. During advance WordPress development, you may want to check if Gravatar is available for a users email, to display image or avatar from alternative source.

The following PHP snippet can be used to determine if Gravatar is available for specified email. It returns TRUE for valid gravatar otherwise it returns false.

function validateGravatar($email) {
	$hash = md5(strtolower(trim($email)));
	$uri = 'http://www.gravatar.com/avatar/' . $hash . '?d=404';
	$headers = @get_headers($uri);
	if (!preg_match("|200|", $headers[0])) {
		$has_valid_avatar = FALSE;
	} else {
		$has_valid_avatar = TRUE;
	}
	return $has_valid_avatar;
}
Total
0
Shares
guest
0 Comments
Inline Feedbacks
View all comments
Previous Post

How to filter posts from WordPress home page archive

Next Post
Mobile Frameworks HTML, CSS

Best Mobile App Frameworks That Use JavaScript, HTML & CSS

Related Posts
By clicking “Allow All”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookie Notice
Allow All
0
Would love your thoughts, please comment.x
()
x