Changeset 61105
- Timestamp:
- 10/31/2025 06:55:47 PM (6 weeks ago)
- Location:
- trunk
- Files:
-
- 7 edited
-
src/wp-admin/includes/class-wp-comments-list-table.php (modified) (1 diff)
-
src/wp-admin/includes/comment.php (modified) (1 diff)
-
src/wp-includes/class-wp-comment-query.php (modified) (2 diffs)
-
src/wp-includes/comment.php (modified) (1 diff)
-
src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php (modified) (2 diffs)
-
tests/phpunit/tests/comment/query.php (modified) (1 diff)
-
tests/phpunit/tests/rest-api/rest-comments-controller.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-comments-list-table.php
r60987 r61105 152 152 'post_type' => $post_type, 153 153 'update_comment_post_cache' => true, 154 'type__not_in' => array( 'note' ),155 154 ); 156 155 -
trunk/src/wp-admin/includes/comment.php
r60987 r61105 139 139 * 140 140 * @since 2.3.0 141 * @since 6.9.0 Exclude the 'note' comment type from the count. 141 142 * 142 143 * @global wpdb $wpdb WordPress database abstraction object. -
trunk/src/wp-includes/class-wp-comment-query.php
r60697 r61105 537 537 * 538 538 * @since 4.4.0 539 * @since 6.9.0 Excludes the 'note' comment type, unless 'all' or the 'note' types are requested. 539 540 * 540 541 * @global wpdb $wpdb WordPress database abstraction object. … … 770 771 'NOT IN' => (array) $this->query_vars['type__not_in'], 771 772 ); 773 774 // Exclude the 'note' comment type, unless 'all' types or the 'note' type explicitly are requested. 775 if ( 776 ! in_array( 'all', $raw_types['IN'], true ) && 777 ! in_array( 'note', $raw_types['IN'], true ) && 778 ! in_array( 'note', $raw_types['NOT IN'], true ) 779 ) { 780 $raw_types['NOT IN'][] = 'note'; 781 } 772 782 773 783 $comment_types = array(); -
trunk/src/wp-includes/comment.php
r61089 r61105 418 418 'update_comment_meta_cache' => false, 419 419 'orderby' => 'none', 420 'type__not_in' => array( 'note' ),421 420 ); 422 421 if ( $post_id > 0 ) { -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
r61002 r61105 1255 1255 'count' => true, 1256 1256 'orderby' => 'none', 1257 'type' => 'all', 1257 1258 ) 1258 1259 ); … … 1261 1262 $args = array( 1262 1263 'parent' => $comment->comment_ID, 1264 ); 1265 1266 $rest_url = add_query_arg( $args, rest_url( $this->namespace . '/' . $this->rest_base ) ); 1267 1268 $links['children'] = array( 1269 'href' => $rest_url, 1270 'embeddable' => true, 1271 ); 1272 } 1273 1274 // Embedding children for notes requires `type` and `status` inheritance. 1275 if ( isset( $links['children'] ) && 'note' === $comment->comment_type ) { 1276 $args = array( 1277 'parent' => $comment->comment_ID, 1278 'type' => $comment->comment_type, 1279 'status' => 'all', 1263 1280 ); 1264 1281 -
trunk/tests/phpunit/tests/comment/query.php
r60235 r61105 5373 5373 $this->assertSame( ltrim( $q->request ), $q->request, 'The query has leading whitespace' ); 5374 5374 } 5375 5376 /** 5377 * Helper method to create standard test comments for note type exclusion tests. 5378 * 5379 * @since 6.9.0 5380 * 5381 * @return array<'comment'|'pingback'|'note', int> Array of comments created. 5382 */ 5383 protected function create_note_type_test_comments(): array { 5384 return array( 5385 'comment' => self::factory()->comment->create( 5386 array( 5387 'comment_post_ID' => self::$post_id, 5388 'comment_approved' => '1', 5389 ) 5390 ), 5391 'pingback' => self::factory()->comment->create( 5392 array( 5393 'comment_post_ID' => self::$post_id, 5394 'comment_approved' => '1', 5395 'comment_type' => 'pingback', 5396 ) 5397 ), 5398 'note' => self::factory()->comment->create( 5399 array( 5400 'comment_post_ID' => self::$post_id, 5401 'comment_approved' => '1', 5402 'comment_type' => 'note', 5403 ) 5404 ), 5405 ); 5406 } 5407 5408 /** 5409 * @ticket 64145 5410 * @covers WP_Comment_Query::get_comment_ids 5411 * @dataProvider data_note_type_exclusion 5412 * 5413 * @param array<string, string|array> $query_args Query arguments for WP_Comment_Query. 5414 * @param string[] $expected_types Expected comment types. 5415 */ 5416 public function test_note_type_exclusion( array $query_args, array $expected_types ) { 5417 $this->create_note_type_test_comments(); 5418 5419 $query = new WP_Comment_Query(); 5420 $found = $query->query( array_merge( $query_args, array( 'fields' => 'ids' ) ) ); 5421 5422 $actual_types = array_map( 5423 static function ( int $comment_id ): string { 5424 return get_comment( $comment_id )->comment_type; 5425 }, 5426 $found 5427 ); 5428 5429 $this->assertSameSets( $expected_types, $actual_types, 'Expected comment query to return comments of the these types.' ); 5430 } 5431 5432 /** 5433 * Data provider for note type exclusion tests. 5434 * 5435 * @since 6.9.0 5436 * 5437 * @return array<string, array{ query_args: array<string, string|array>, expected_types: string[] }> 5438 */ 5439 public function data_note_type_exclusion(): array { 5440 return array( 5441 'default query excludes note' => array( 5442 'query_args' => array(), 5443 'expected_types' => array( 'comment', 'pingback' ), 5444 ), 5445 'empty type parameter excludes note' => array( 5446 'query_args' => array( 'type' => '' ), 5447 'expected_types' => array( 'comment', 'pingback' ), 5448 ), 5449 'type all includes note' => array( 5450 'query_args' => array( 'type' => 'all' ), 5451 'expected_types' => array( 'comment', 'pingback', 'note' ), 5452 ), 5453 'explicit note type' => array( 5454 'query_args' => array( 'type' => 'note' ), 5455 'expected_types' => array( 'note' ), 5456 ), 5457 'type__in with note' => array( 5458 'query_args' => array( 'type__in' => array( 'note' ) ), 5459 'expected_types' => array( 'note' ), 5460 ), 5461 'type__in with note and pingback' => array( 5462 'query_args' => array( 'type__in' => array( 'note', 'pingback' ) ), 5463 'expected_types' => array( 'note', 'pingback' ), 5464 ), 5465 'type pings excludes note' => array( 5466 'query_args' => array( 'type' => 'pings' ), 5467 'expected_types' => array( 'pingback' ), 5468 ), 5469 'type__not_in with note' => array( 5470 'query_args' => array( 'type__not_in' => array( 'note' ) ), 5471 'expected_types' => array( 'comment', 'pingback' ), 5472 ), 5473 ); 5474 } 5475 5476 /** 5477 * @ticket 64145 5478 * @covers WP_Comment_Query::get_comment_ids 5479 */ 5480 public function test_note_type_not_duplicated_in_type__not_in() { 5481 global $wpdb; 5482 5483 $comments = $this->create_note_type_test_comments(); 5484 5485 $query = new WP_Comment_Query(); 5486 $found = $query->query( 5487 array( 5488 'type__not_in' => array( 'note' ), 5489 'fields' => 'ids', 5490 ) 5491 ); 5492 5493 $this->assertSameSets( array( $comments['comment'], $comments['pingback'] ), $found ); 5494 $this->assertNotContains( $comments['note'], $found ); 5495 $note_count = substr_count( $wpdb->last_query, "'note'" ); 5496 $this->assertSame( 1, $note_count, 'The note type should only appear once in the query' ); 5497 } 5498 5499 /** 5500 * @ticket 64145 5501 * @covers ::get_comment_count 5502 */ 5503 public function test_get_comment_count_excludes_note_type() { 5504 $post_id = self::factory()->post->create(); 5505 5506 self::factory()->comment->create( 5507 array( 5508 'comment_post_ID' => $post_id, 5509 'comment_approved' => '1', 5510 ) 5511 ); 5512 self::factory()->comment->create( 5513 array( 5514 'comment_post_ID' => $post_id, 5515 'comment_approved' => '1', 5516 'comment_type' => 'note', 5517 ) 5518 ); 5519 self::factory()->comment->create( 5520 array( 5521 'comment_post_ID' => $post_id, 5522 'comment_approved' => '0', 5523 'comment_type' => 'note', 5524 ) 5525 ); 5526 5527 $counts = get_comment_count( $post_id ); 5528 5529 $this->assertSame( 1, $counts['approved'] ); 5530 $this->assertSame( 0, $counts['awaiting_moderation'] ); 5531 $this->assertSame( 0, $counts['spam'] ); 5532 $this->assertSame( 0, $counts['trash'] ); 5533 $this->assertSame( 0, $counts['post-trashed'] ); 5534 $this->assertSame( 1, $counts['all'] ); 5535 $this->assertSame( 1, $counts['total_comments'] ); 5536 } 5375 5537 } -
trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php
r61089 r61105 4077 4077 ); 4078 4078 } 4079 4080 /** 4081 * Test children link for note comment type. Based on test_get_comment_with_children_link. 4082 * 4083 * @ticket 64152 4084 */ 4085 public function test_get_note_with_children_link() { 4086 $parent_comment_id = self::factory()->comment->create( 4087 array( 4088 'comment_approved' => 1, 4089 'comment_post_ID' => self::$post_id, 4090 'user_id' => self::$admin_id, 4091 'comment_type' => 'note', 4092 'comment_content' => 'Parent note comment', 4093 ) 4094 ); 4095 4096 self::factory()->comment->create( 4097 array( 4098 'comment_approved' => 1, 4099 'comment_parent' => $parent_comment_id, 4100 'comment_post_ID' => self::$post_id, 4101 'user_id' => self::$admin_id, 4102 'comment_type' => 'note', 4103 'comment_content' => 'First child note comment', 4104 ) 4105 ); 4106 4107 wp_set_current_user( self::$admin_id ); 4108 $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/comments/%s', $parent_comment_id ) ); 4109 $request->set_param( 'type', 'note' ); 4110 $request->set_param( 'context', 'edit' ); 4111 $response = rest_get_server()->dispatch( $request ); 4112 $this->assertSame( 200, $response->get_status() ); 4113 4114 $this->assertArrayHasKey( 'children', $response->get_links() ); 4115 4116 $request = new WP_REST_Request( 'GET', '/wp/v2/comments' ); 4117 $request->set_param( 'post', self::$post_id ); 4118 $request->set_param( 'type', 'note' ); 4119 $request->set_param( 'context', 'edit' ); 4120 $request->set_param( 'parent', 0 ); 4121 4122 $response = rest_get_server()->dispatch( $request ); 4123 $this->assertSame( 200, $response->get_status() ); 4124 4125 $data = $response->get_data(); 4126 4127 $this->assertArrayHasKey( '_links', $data[0] ); 4128 $this->assertArrayHasKey( 'children', $data[0]['_links'] ); 4129 4130 $children = $data[0]['_links']['children']; 4131 4132 // Verify the href attribute contains the expected status and type parameters. 4133 $this->assertStringContainsString( 'status=all', $children[0]['href'] ); 4134 $this->assertStringContainsString( 'type=note', $children[0]['href'] ); 4135 } 4079 4136 }
Note: See TracChangeset
for help on using the changeset viewer.