Changeset 61369
- Timestamp:
- 12/11/2025 01:53:26 AM (3 days ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
src/wp-admin/includes/export.php (modified) (1 diff)
-
src/wp-includes/comment.php (modified) (1 diff)
-
tests/phpunit/tests/admin/exportWp.php (modified) (1 diff)
-
tests/phpunit/tests/comment.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/export.php
r60632 r61369 686 686 687 687 $_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) ); 688 $comments = array_map( 'get_comment', $_comments ); 688 $comments = array_filter( 689 array_map( 'get_comment', $_comments ), 690 static function ( $comment ) { 691 return $comment instanceof WP_Comment; 692 } 693 ); 689 694 foreach ( $comments as $c ) : 690 695 ?> -
trunk/src/wp-includes/comment.php
r61336 r61369 241 241 * @since 2.3.0 242 242 * 243 * @param WP_Comment $_comment Comment data.243 * @param WP_Comment|null $_comment Comment data. 244 244 */ 245 245 $_comment = apply_filters( 'get_comment', $_comment ); 246 if ( ! ( $_comment instanceof WP_Comment ) ) { 247 return null; 248 } 246 249 247 250 if ( OBJECT === $output ) { -
trunk/tests/phpunit/tests/admin/exportWp.php
r57681 r61369 291 291 $args['author'] = self::$post_ids[ $post_ids_key ]['post_author']; 292 292 } 293 294 /** 295 * @ticket 61244 296 */ 297 public function test_export_wp_should_not_include_empty_comments_when_filtered() { 298 $post_id = self::factory()->post->create( array( 'post_title' => 'Test Post' ) ); 299 self::factory()->comment->create_post_comments( $post_id, 3 ); 300 301 // Add filter to make get_comment return null. 302 add_action( 303 'export_wp', 304 static function () { 305 add_filter( 'get_comment', '__return_null' ); 306 } 307 ); 308 309 $xml_obj = $this->get_the_export( array() ); 310 $comment_tags = $xml_obj->xpath( '//wp:comment' ); 311 $this->assertCount( 0, $comment_tags, 'No <wp:comment> tags should be present when comments are filtered out.' ); 312 } 313 314 /** 315 * @ticket 61244 316 */ 317 public function test_export_wp_includes_comments_when_not_filtered() { 318 $post_id = self::factory()->post->create( array( 'post_title' => 'Test Post' ) ); 319 $comment_count = 3; 320 self::factory()->comment->create_post_comments( $post_id, $comment_count ); 321 322 $xml_obj = $this->get_the_export( array() ); 323 $comment_tags = $xml_obj->xpath( '//wp:comment' ); 324 $this->assertCount( $comment_count, $comment_tags, 'Export should include all comments when not filtered.' ); 325 } 293 326 } -
trunk/tests/phpunit/tests/comment.php
r61248 r61369 1897 1897 $this->assertSame( '1', get_comment( $sibling_note )->comment_approved ); 1898 1898 } 1899 1900 /** 1901 * @ticket 61244 1902 * 1903 * @covers ::get_comment 1904 */ 1905 public function test_get_comment_filter() { 1906 $comment_id = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id ) ); 1907 1908 $comment = get_comment( $comment_id ); 1909 $this->assertInstanceOf( WP_Comment::class, $comment ); 1910 $this->assertSame( $comment_id, (int) $comment->comment_ID, 'Expected the same comment.' ); 1911 1912 add_filter( 'get_comment', '__return_null' ); 1913 $this->assertNull( get_comment( $comment_id ), 'Expected get_comment() to return null when get_comment filter returns null.' ); 1914 } 1899 1915 }
Note: See TracChangeset
for help on using the changeset viewer.