Last active
June 21, 2016 05:40
-
-
Save Venugopal155/eb57543129ea033878865e3f37719176 to your computer and use it in GitHub Desktop.
Checking gravatar is there or not in wordpress
This file contains hidden or 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 for check gravatar */ | |
function check_avatar($user_email_id) { | |
$hash = md5(strtolower(trim($user_email_id))); | |
$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; | |
} | |
/* Getting user_id and email */ | |
$current_user_id = get_current_user_id(); | |
$user_info = get_userdata($current_user_id); | |
$user_email_id = $user_info->user_email; | |
/* Getting User first name and last name */ | |
$u_first_name = $user_info->user_firstname; | |
$u_last_name = $user_info->user_lastname; | |
/* If true displays gravatar else display defaut imag */ | |
if (check_avatar($user_email_id) == "TRUE") { | |
echo get_avatar($user_email_id, 32); | |
} else { | |
?> | |
<!-- Genarating Name text avatar --> | |
<div class="name"><?php echo $u_first_name; ?> <?php echo $u_last_name; ?></div> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment