Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created February 19, 2016 15:13
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 billerickson/30fa3bda007930f4955f to your computer and use it in GitHub Desktop.
Save billerickson/30fa3bda007930f4955f to your computer and use it in GitHub Desktop.
<?php
function be_gravatar_filter($avatar, $id_or_email, $size, $default, $alt) {
// If provided an email and it doesn’t exist as WP user, return avatar since there can’t be a custom avatar
$email = is_object( $id_or_email ) ? $id_or_email->comment_author_email : $id_or_email;
if( is_email( $email ) && ! email_exists( $email ) )
return $avatar;
$avatar_field = ‘ihc_avatar’; //<$avatar_field);
$custom_avatar = get_the_author_meta($avatar_field); //GET CUSTOM AVATAR FOR POST-AUTHOR
$avatarurl = wp_get_attachment_url($custom_avatar);
if ($email_avatar){ //IF CUSTOM AVATAR FOR THIS EMAIL IS FOUND, RETURN. EX. FOR COMMENTS OR BBPRESS FORUM
$return = ”;
}
elseif ($custom_avatar) { //ELSE IF RETURN CUSTOM AVATAR FOR THE POST-AUTHOR
$return = ”;
}
elseif ($avatar) {
$return = $avatar;
}else {
$return = ”;
}
return $return;
}
add_filter(‘get_avatar’, ‘be_gravatar_filter’, 10, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment