From cf4d14f94fcc9965192fbdc9cde7efe8bd6aeae1 Mon Sep 17 00:00:00 2001
From: nimeshrathod <testing.testuser42@gmail.com>
Date: Thu, 25 Jul 2024 11:57:48 +0530
Subject: [PATCH] Fix for comment template issue in wp-includes #61715

---
 src/wp-includes/comment-template.php | 56 ++++++++++++----------------
 1 file changed, 24 insertions(+), 32 deletions(-)

diff --git a/src/wp-includes/comment-template.php b/src/wp-includes/comment-template.php
index fed6568..68f3cb4 100644
--- a/src/wp-includes/comment-template.php
+++ b/src/wp-includes/comment-template.php
@@ -22,38 +22,30 @@
  * @return string The comment author
  */
 function get_comment_author( $comment_id = 0 ) {
-	$comment = get_comment( $comment_id );
-
-	if ( ! empty( $comment->comment_ID ) ) {
-		$comment_id = $comment->comment_ID;
-	} elseif ( is_scalar( $comment_id ) ) {
-		$comment_id = (string) $comment_id;
-	} else {
-		$comment_id = '';
-	}
-
-	if ( empty( $comment->comment_author ) ) {
-		$user = ! empty( $comment->user_id ) ? get_userdata( $comment->user_id ) : false;
-		if ( $user ) {
-			$comment_author = $user->display_name;
-		} else {
-			$comment_author = __( 'Anonymous' );
-		}
-	} else {
-		$comment_author = $comment->comment_author;
-	}
-
-	/**
-	 * Filters the returned comment author name.
-	 *
-	 * @since 1.5.0
-	 * @since 4.1.0 The `$comment_id` and `$comment` parameters were added.
-	 *
-	 * @param string     $comment_author The comment author's username.
-	 * @param string     $comment_id     The comment ID as a numeric string.
-	 * @param WP_Comment $comment        The comment object.
-	 */
-	return apply_filters( 'get_comment_author', $comment_author, $comment_id, $comment );
+    $comment = get_comment( $comment_id );
+    if ( is_object( $comment ) && ! empty( $comment->comment_ID ) ) {
+        $comment_id = $comment->comment_ID;
+    } elseif ( is_scalar( $comment_id ) ) {
+        $comment_id = (string) $comment_id;
+    } else {
+        $comment_id = '';
+    }
+    if ( empty( $comment->comment_author ) ) {
+        $comment_author = ! empty( $comment->user_id ) ? get_userdata( $comment->user_id )->display_name ?? _( 'Anonymous' ) : _( 'Anonymous' );
+    } else {
+        $comment_author = $comment->comment_author;
+    }
+    /**
+     * Filters the returned comment author name.
+     *
+     * @since 1.5.0
+     * @since 4.1.0 The `$comment_id` and `$comment` parameters were added.
+     *
+     * @param string     $comment_author The comment author's username.
+     * @param string     $comment_id     The comment ID as a numeric string.
+     * @param WP_Comment $comment        The comment object.
+     */
+    return apply_filters( 'get_comment_author', $comment_author, $comment_id, $comment );
 }
 
 /**
-- 
2.25.1

