5

It should be simple, but I tried some codes, none does the trick. Searched on Google, nothing there either. Simply check if the comment author is a registered user (so I can add some code for it), if it's not registered show nothing.

This should do the trick if( empty($comment_author_nickname) && empty($comment_author_email) ) but I don't know how to get that information

thank you

  • updated the question with the code. I searched for 'Check If comment author is registered' and variations. no result gets me what I need – whitelord Jan 1 '15 at 15:17
4

I wonder if you mean this kind of check:

if( $comment->user_id > 0 ) {
    // Registered comment author
} 

in your comment's template callback.

This is determined in the the wp-comments-post.php file:

$commentdata = compact('comment_post_ID', ..., 'user_ID' );
$comment_id = wp_new_comment( $commentdata );

but it's not obvious where the user_ID variable comes from, since this variable is not defined in that file.

So this is actually picking up the global variable $user_ID or $GLOBALS['user_ID'] behind our back ;-)

  • yes indeed, as simple as that, just a simple check. it works. thank you – whitelord Jan 1 '15 at 15:53
  • Great answer. Did not think about that. – Pieter Goosen Jan 1 '15 at 16:05
  • 2
    I finally found the origin of that value, "hidden" as a global variable in the wp-comments-post.php file ;-) @PieterGoosen – birgire Jan 1 '15 at 16:27
1

I don't think there is any safe and reliable method to do this. In my honest opinion, this is also something that I would discourage

My biggest concerns here are

  • Anyone can enter a fake email or nickname that can match the details of an already registered member

  • By doing this, an unregistered user might be able to get access to a registered member's details

  • What method are you going to use to match info entered into the comment form against info from all your registered members

SOLUTION

Your best and safest method to achieve this would be to prompt a user to login if they are an already registered member. Apart from this, as I said, I cannot see any other safe and reliable method to achieve this

  • I see. But I simply use this condition just to show a field for registered user, and nothing for unregistered. User rank from a plugin. – whitelord Jan 1 '15 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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