Thread Starter
jossi
(@jossi)
Any ideas how to solve this, I have looked everywhere and cannot find a solution for this.
It should display whatever the commenter put into the name box in the comments form. If you are logged in then it uses your display name. Wouldn’t that do?
Thread Starter
jossi
(@jossi)
My blog requires registration, so all users have a username which is displayed in the comment.
What I need, is that instead of the user name, the first name of the user is displayed. (I am forcing users to register with first name and last name.)
I have been checking the docs, and I can see that this information is not stored on the wp_comments table, so I will need to:
a. Get the ID of the commenter
b. Use the ID to retrieve the first name using get_usermeta
<?php $commenter_name = get_usermeta($commenter_ID,'first_name'); ?>
The question is how do I get the user_ID of the commenter?
Thread Starter
jossi
(@jossi)
I can see that wp-comments-post.php uses the display name:
$comment_author = $wpdb->escape($user->display_name);
I could change this to
$comment_author = $wpdb->escape($user->fist_name);
But I just do not want to change that and mess with core files…. and also this will mean that only new comments will have the first name displayed, and I need to be able to make it work with existing comments.
Thread Starter
jossi
(@jossi)
Got it.
Changed my comments template to use this:
<?php
$commenter_id = $comment->user_id;
$commenter_name = get_usermeta($commenter_id,'first_name');
?>
<cite><?php echo $commenter_name; ?></cite> Says:
Thread Starter
jossi
(@jossi)
This will display the first name, the first letter of the last name, nicely formatted:
<?php
$commenter_id = $comment->user_id;
$commenter_fname = get_usermeta($commenter_id,'first_name');
$commenter_lname = substr(get_usermeta($commenter_id,'last_name'), 0, 1);
$commenter_name = ucwords(strtolower($commenter_fname . " " . $commenter_lname . "."));
?>