Make WordPress Core

Ticket #61715: 61715.patch

File 61715.patch, 2.7 KB (added by iflairwebtechnologies, 23 months ago)

Fix for comment template issue in wp-includes #61715. Please review new patch file.

  • src/wp-includes/comment-template.php

    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 b  
    2222 * @return string The comment author
    2323 */
    2424function get_comment_author( $comment_id = 0 ) {
    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 );
    5749}
    5850
    5951/**