Make WordPress Core


Ignore:
Timestamp:
12/11/2025 01:53:26 AM (6 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/tests/phpunit/tests/comment.php

    r61248 r61369  
    18971897        $this->assertSame( '1', get_comment( $sibling_note )->comment_approved );
    18981898    }
     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    }
    18991915}
Note: See TracChangeset for help on using the changeset viewer.