When I post something on Wordpress, it's posted with my display name. However if I change my display name, posts posted by me will be updated with the new author. Comments will stay with the old name.
Since in my wordpress site comments are available only for registered users, and the display name field is hidden - they have custom profiles, I would like to overwrite the display_name used (it should always match first_name + last_name). So I've tried the the_author hook with no luck.
Looking at the source code, I found that the name of the author in author_link is generated as follows:
function get_comment_author( $comment_ID = 0 ) {
$comment = get_comment( $comment_ID );
if ( empty($comment->comment_author) ) {
if (!empty($comment->user_id)){
$user=get_userdata($comment->user_id);
$author=$user->user_login;
} else {
$author = __('Anonymous');
}
} else {
$author = $comment->comment_author;
}
return apply_filters('get_comment_author', $author);
}
This means that if the comment_author is written to the database, I cannot use it in any way. If not - the current user_login of the comment author will be passed to the get_comment_author hook, where I could query the DB to get the row and hence the first and last name. I don't like that new query will be needed, but I can live with this if it's the only way. But what steps I should perform to get it working. Right now the comment_author is always written to the database.