Best way to tell if a comment is from a user?
سؤال
I've got an if ($comment->user_id)
block to pick an default admin comment gravatar (different than a non-user's). But I'd still like this gravatar to be used if a user comments using their registered email, even if they comment while not logged in. What is the best way to test for this?
EDIT
I'm already using
if ($comment->user_id){
//comment by registered user
$avatar = '/images/bird_comments_big.png';
}else{
//comment by none registered user
$avatar = '/images/bird_comments_pink.png';
}
with
<div><?php echo get_avatar($comment, 70, get_bloginfo('template_url').$avatar); ?></div>
If the user is logged in a makes a comments, the if statement is indeed fulfilled. However, if the user uses their registered email (i.e. tied to their login in WP) without bring logged in, user_id
is not present, and the icon for the unregistered user appears. user_id
is only stored if the user is logged in.
I also want to test if the email given matches a registered user, regardless if they are logged-in or not.
المحلول 2
if ($comment->user_id || email_exists($comment->comment_author_email)){
//comment by registered user
$avatar = '/images/registered_user.png';
}else{
//comment by none registered user
$avatar = '/images/non_registered_user.png';
}
with
<div><?php echo get_avatar($comment, 70, get_bloginfo('template_url').$avatar); ?></div>
Seems about as succinct a way I can figure.
نصائح أخرى
You can simplly check
if ($comment->user_id > 0){
//comment by registered user
}else{
//comment by none registered user
}