Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
You can use get_ avatar codex.wordpress.org/Function_Reference/get_avatar –  Bainternet Apr 8 '11 at 3:09
    
@Bainternet Yes, I do eventually use this function, but I'm trying to have a default user avatar that is different than the default commenter avatar. So I need a way to determine which default to pass to get_avatar(). –  two7s_clash Apr 8 '11 at 12:32
    
get_avatar() accepts email so you can pass the comment email –  Bainternet Apr 8 '11 at 12:42

2 Answers 2

up vote 0 down vote accepted
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.

share|improve this answer
    
I guess, the $comment->user_id is a string. ('0' / '1'), So the way you're using it in if statement is wrong. –  amit Aug 21 '12 at 21:25
    
It does what I want it to do. You find this semantically wrong? –  two7s_clash Sep 4 '12 at 22:27

You can simplly check

if ($comment->user_id > 0){
//comment by registered user
}else{
//comment by none registered user
}
share|improve this answer
    
I don't think you're understanding.... I already posited this part in my question. I'm going to try and rephrase... –  two7s_clash Apr 8 '11 at 13:24
1  
@two7s_clash When a non user comments, his $comment->user_id values is set to 0 So @Bainternet provided simple way to distinguish registered user's comments. –  amit Aug 21 '12 at 21:28
    
I totally get that and I was already doing a version on that in my example. –  two7s_clash Sep 4 '12 at 22:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.