Make WordPress Core


Ignore:
Timestamp:
12/11/2025 01:53:26 AM (3 months ago)
Author:
westonruter
Message:

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 https://github.com/WordPress/wordpress-develop/pull/8383

Props abcd95, WPExplorer, desrosj, mukesh27, westonruter, SirLouen, lbones, mdibrahimk48, audrasjb, jorbin, wildworks, hellofromTonya, saurabh.dhariwal, mabfahad.
Fixes #61244.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/export.php

    r60632 r61369  
    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                    ?>
Note: See TracChangeset for help on using the changeset viewer.