Arrowcatch
Arrowcatch

Reputation: 1652

Wordpress - get_comment_author() returns "Anonymous" as author name

Note

I know there is another post on this topic. Unfortunately I could not find a solution for my usecase there. So I'm asking this question again.

Situation

Comments made by users that are not logged in return "Anonymous" as the Author Name. Even if the corresponding field in the comment-form was filled.

Code

This is how the authors name is displayed (from the functions.php)

<?php
    /* translators: 1: comment author url, 2: comment author name, 3: comment permalink, 4: comment date/timestamp*/
    printf( __( '%2$s schrieb am %4$s', 'buddypress' ), get_comment_author_url(), get_comment_author(), get_comment_link(), get_comment_date() );
?>

Files that might be helpful:

I'm really not sure how to even find the issue. My guess from reading similar questions on StackOverflow is, that I have to pass the comment ID to get_comment_author(). But I have no idea how to do this in this case.

Any help is much appreciated! Thanks!

Upvotes: 2

Views: 1417

Answers (1)

Spartacus
Spartacus

Reputation: 1508

get_comment_author() returns "Anonymous" if $comment->comment_author is empty, or if the comment ID is not passed to the function (defaults to 0).

In your functions.php, try explicitly setting the ID:

$cID = $comment->comment_ID;
printf( __( '%2$s schrieb am %4$s', 'buddypress' ), get_comment_author_url($cID), get_comment_author($cID), get_comment_link($cID), get_comment_date('',$cID) );

If this doesn't work, then the name isn't being stored in $comment->comment_author

Upvotes: 1

Related Questions