Skip to content

Commit 9eeebf5

Browse files
committed
Export: Update export_wp() to handle get_comment() returning null due to filter.
The `get_comment` filter now explicitly documents returning `null` in addition to a `WP_Comment` object. This allows the filter to be used to exclude comments from an export. The `get_comment()` function already supported returning `null`. Developed in WordPress/wordpress-develop#8383 Props abcd95, WPExplorer, desrosj, mukesh27, westonruter, SirLouen, lbones, mdibrahimk48, audrasjb, jorbin, wildworks, hellofromTonya, saurabh.dhariwal, mabfahad. Fixes #61244. Built from https://develop.svn.wordpress.org/trunk@61369 git-svn-id: https://core.svn.wordpress.org/trunk@60681 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent 2abe734 commit 9eeebf5

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

wp-admin/includes/export.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,12 @@ function wxr_filter_postmeta( $return_me, $meta_key ) {
685685
endforeach;
686686

687687
$_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+
);
689694
foreach ( $comments as $c ) :
690695
?>
691696
<wp:comment>

wp-includes/comment.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,12 @@ function get_comment( $comment = null, $output = OBJECT ) {
240240
*
241241
* @since 2.3.0
242242
*
243-
* @param WP_Comment $_comment Comment data.
243+
* @param WP_Comment|null $_comment Comment data.
244244
*/
245245
$_comment = apply_filters( 'get_comment', $_comment );
246+
if ( ! ( $_comment instanceof WP_Comment ) ) {
247+
return null;
248+
}
246249

247250
if ( OBJECT === $output ) {
248251
return $_comment;

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '7.0-alpha-61368';
19+
$wp_version = '7.0-alpha-61369';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)