Skip to content

Commit 0e73699

Browse files
committed
Comments: Explicitly exclude note comment type on the comments table.
Fix an issue where adding `comment_type=all` as a query parameter to the `wp-admin/edit-comments.php` page would unexpectedly cause notes to show. Follow-up to [61183]. Props adamsilverstein, jorbin, mukesh27, ozgursar, Presskopp, r1k0, rollybueno, soyebsalar01, westonruter, wildworks. Fixes #64474. git-svn-id: https://develop.svn.wordpress.org/trunk@61525 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 4e5c0e2 commit 0e73699

2 files changed

Lines changed: 40 additions & 8 deletions

File tree

src/wp-admin/includes/class-wp-comments-list-table.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public function prepare_items() {
155155
'number' => $number,
156156
'post_id' => $post_id,
157157
'type' => $comment_type,
158+
'type__not_in' => array( 'note' ),
158159
'orderby' => $orderby,
159160
'order' => $order,
160161
'post_type' => $post_type,

tests/phpunit/tests/admin/wpCommentsListTable.php

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -218,30 +218,61 @@ public function test_get_views_should_return_views_by_default() {
218218
* Verify that the comments table never shows the note comment_type.
219219
*
220220
* @ticket 64198
221+
* @ticket 64474
222+
*
223+
* @dataProvider data_comment_type
224+
*
225+
* @param string $comment_type The comment_type parameter value to test.
221226
*/
222-
public function test_comments_list_table_does_not_show_note_comment_type() {
223-
$post_id = self::factory()->post->create();
224-
$note_id = self::factory()->comment->create(
227+
public function test_comments_list_table_does_not_show_note_comment_type( string $comment_type ) {
228+
$post_id = self::factory()->post->create();
229+
self::factory()->comment->create(
225230
array(
226231
'comment_post_ID' => $post_id,
227232
'comment_content' => 'This is a note.',
228233
'comment_type' => 'note',
229234
'comment_approved' => '1',
235+
'comment_date' => '2024-01-01 10:00:00',
236+
'comment_date_gmt' => '2024-01-01 10:00:00',
230237
)
231238
);
232-
$comment_id = self::factory()->comment->create(
239+
$regular_comment_id = self::factory()->comment->create(
233240
array(
234241
'comment_post_ID' => $post_id,
235242
'comment_content' => 'This is a regular comment.',
236243
'comment_type' => '',
237244
'comment_approved' => '1',
245+
'comment_date' => '2024-01-01 11:00:00',
246+
'comment_date_gmt' => '2024-01-01 11:00:00',
247+
)
248+
);
249+
$pingback_comment_id = self::factory()->comment->create(
250+
array(
251+
'comment_post_ID' => $post_id,
252+
'comment_content' => 'This is a pingback comment.',
253+
'comment_type' => '',
254+
'comment_approved' => '1',
255+
'comment_date' => '2024-01-01 12:00:00',
256+
'comment_date_gmt' => '2024-01-01 12:00:00',
238257
)
239258
);
240-
// Request the note comment type.
241-
$_REQUEST['comment_type'] = 'note';
259+
$_REQUEST['comment_type'] = $comment_type;
242260
$this->table->prepare_items();
243261
$items = $this->table->items;
244-
$this->assertCount( 1, $items );
245-
$this->assertEquals( $comment_id, $items[0]->comment_ID );
262+
$this->assertCount( 2, $items );
263+
$this->assertEquals( $pingback_comment_id, $items[0]->comment_ID );
264+
$this->assertEquals( $regular_comment_id, $items[1]->comment_ID );
265+
}
266+
267+
/**
268+
* Data provider for test_comments_list_table_does_not_show_note_comment_type().
269+
*
270+
* @return array<string, string[]>
271+
*/
272+
public function data_comment_type(): array {
273+
return array(
274+
'note type explicitly requested' => array( 'note' ),
275+
'all type requested' => array( 'all' ),
276+
);
246277
}
247278
}

0 commit comments

Comments
 (0)