Write Comments Under a Different WordPress User and Gravatar Photo
We manage some of our clients' blogs and ghostwrite for them, and occasionally, we respond to comments that those posts recieve.
Unfortunately some WordPress installs won't let us comment on behalf of another user. It will use our WordPress gravatar, even if we set our name and email to match the user that we want to comment as.
Thankfully, this handy little functions.php snippet fixes that:
/* Allow admin creation of comments under a different email and Gravatar */
function custom_gravatar_force_comment_email( $avatar, $id_or_email, $size, $default, $alt, $args ) {
if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) {
$comment = get_comment( $id_or_email->comment_ID );
if ( $comment ) {
$grav_url = "https://www.gravatar.com/avatar/" . md5(strtolower(trim($comment->comment_author_email))) . "?s=" . $size . "&d=mm";
$avatar = "<img alt='{$alt}' src='{$grav_url}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
}
}
return $avatar;
}
add_filter( 'get_avatar', 'custom_gravatar_force_comment_email', 9999, 6 );
Simply plop this into your functions.php file in your theme, and you can now change the email (and cooresponding gravatar) of any comment!
Comments