From 5e093b54732483d5182d77c689dd33dcf0248bbc Mon Sep 17 00:00:00 2001 From: Avinash Date: Tue, 1 Dec 2026 21:44:17 +0530 Subject: [PATCH] Administration: Reserve avatar space for custom comment types in the Dashboard Activity widget. The Recent Comments row output the avatar before branching on the comment type, but only the regular comment branch added the `has-avatar` class that the dashboard stylesheet uses to reserve space. Avatars enabled for custom comment types through `get_avatar_comment_types` therefore overlapped the heading. Use one wrapper for both branches and add `has-avatar` only when an avatar is actually rendered. Props willmot. See #66889. --- src/wp-admin/includes/dashboard.php | 10 +- .../admin/wpDashboardRecentCommentsRow.php | 95 +++++++++++++++++++ 2 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 tests/phpunit/tests/admin/wpDashboardRecentCommentsRow.php diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php index 05e6e24f6b0c6..83cf6a505519d 100644 --- a/src/wp-admin/includes/dashboard.php +++ b/src/wp-admin/includes/dashboard.php @@ -855,17 +855,18 @@ function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
  • > +
    + comment_type || 'comment' === $comment->comment_type ) : ?> -

    -

    comment->create_and_get( + array( + 'comment_post_ID' => self::factory()->post->create(), + 'comment_type' => $comment_type, + ) + ); + + $output = get_echo( '_wp_dashboard_recent_comments_row', array( &$comment ) ); + + $this->assertStringContainsString( 'assertMatchesRegularExpression( '/class="dashboard-comment-wrap[^"]*\shas-avatar"/', $output ); + } + + /** + * @ticket 66889 + * + * @dataProvider data_comment_types + * + * @param string $comment_type Comment type. + */ + public function test_row_wrapper_has_no_avatar_class_when_avatars_are_disabled( $comment_type ) { + update_option( 'show_avatars', 0 ); + + $comment = self::factory()->comment->create_and_get( + array( + 'comment_post_ID' => self::factory()->post->create(), + 'comment_type' => $comment_type, + ) + ); + + $output = get_echo( '_wp_dashboard_recent_comments_row', array( &$comment ) ); + + $this->assertStringNotContainsString( 'has-avatar', $output ); + } + + /** + * @ticket 66889 + */ + public function test_row_wrapper_has_no_avatar_class_when_avatar_is_not_rendered() { + $comment = self::factory()->comment->create_and_get( + array( + 'comment_post_ID' => self::factory()->post->create(), + 'comment_type' => 'pingback', + ) + ); + + $output = get_echo( '_wp_dashboard_recent_comments_row', array( &$comment ) ); + + $this->assertStringNotContainsString( 'has-avatar', $output, 'Pingbacks do not get avatars by default.' ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_comment_types() { + return array( + 'regular comment' => array( 'comment' ), + 'custom type' => array( 'example_review' ), + ); + } +}