| 25 | | $comment = get_comment( $comment_id ); |
| 26 | | |
| 27 | | if ( ! empty( $comment->comment_ID ) ) { |
| 28 | | $comment_id = $comment->comment_ID; |
| 29 | | } elseif ( is_scalar( $comment_id ) ) { |
| 30 | | $comment_id = (string) $comment_id; |
| 31 | | } else { |
| 32 | | $comment_id = ''; |
| 33 | | } |
| 34 | | |
| 35 | | if ( empty( $comment->comment_author ) ) { |
| 36 | | $user = ! empty( $comment->user_id ) ? get_userdata( $comment->user_id ) : false; |
| 37 | | if ( $user ) { |
| 38 | | $comment_author = $user->display_name; |
| 39 | | } else { |
| 40 | | $comment_author = __( 'Anonymous' ); |
| 41 | | } |
| 42 | | } else { |
| 43 | | $comment_author = $comment->comment_author; |
| 44 | | } |
| 45 | | |
| 46 | | /** |
| 47 | | * Filters the returned comment author name. |
| 48 | | * |
| 49 | | * @since 1.5.0 |
| 50 | | * @since 4.1.0 The `$comment_id` and `$comment` parameters were added. |
| 51 | | * |
| 52 | | * @param string $comment_author The comment author's username. |
| 53 | | * @param string $comment_id The comment ID as a numeric string. |
| 54 | | * @param WP_Comment $comment The comment object. |
| 55 | | */ |
| 56 | | return apply_filters( 'get_comment_author', $comment_author, $comment_id, $comment ); |
| | 25 | $comment = get_comment( $comment_id ); |
| | 26 | if ( is_object( $comment ) && ! empty( $comment->comment_ID ) ) { |
| | 27 | $comment_id = $comment->comment_ID; |
| | 28 | } elseif ( is_scalar( $comment_id ) ) { |
| | 29 | $comment_id = (string) $comment_id; |
| | 30 | } else { |
| | 31 | $comment_id = ''; |
| | 32 | } |
| | 33 | if ( empty( $comment->comment_author ) ) { |
| | 34 | $comment_author = ! empty( $comment->user_id ) ? get_userdata( $comment->user_id )->display_name ?? _( 'Anonymous' ) : _( 'Anonymous' ); |
| | 35 | } else { |
| | 36 | $comment_author = $comment->comment_author; |
| | 37 | } |
| | 38 | /** |
| | 39 | * Filters the returned comment author name. |
| | 40 | * |
| | 41 | * @since 1.5.0 |
| | 42 | * @since 4.1.0 The `$comment_id` and `$comment` parameters were added. |
| | 43 | * |
| | 44 | * @param string $comment_author The comment author's username. |
| | 45 | * @param string $comment_id The comment ID as a numeric string. |
| | 46 | * @param WP_Comment $comment The comment object. |
| | 47 | */ |
| | 48 | return apply_filters( 'get_comment_author', $comment_author, $comment_id, $comment ); |