Make WordPress Core


Ignore:
Timestamp:
04/28/2022 01:16:18 AM (2 years ago)
Author:
peterwilsoncc
Message:

Editor: Show comment previews in the Comment Query Loop.

Update build_comment_query_vars_from_block() to show previews of unmoderated comments to the original author of the comment. This duplicates the existing logic in wp_list_comments().

Props darerodz, bernhard-reiter, czapla.
Fixes #55634.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/blocks/renderCommentTemplate.php

    r53258 r53298  
    251251        );
    252252    }
     253
     254    /**
     255     * Test that unapproved comments are included if it is a preview.
     256     *
     257     * @ticket 55634
     258     * @covers ::build_comment_query_vars_from_block
     259     */
     260    function test_build_comment_query_vars_from_block_with_comment_preview() {
     261        $parsed_blocks = parse_blocks(
     262            '<!-- wp:comment-template --><!-- wp:comment-author-name /--><!-- wp:comment-content /--><!-- /wp:comment-template -->'
     263        );
     264
     265        $block = new WP_Block(
     266            $parsed_blocks[0],
     267            array(
     268                'postId' => self::$custom_post->ID,
     269            )
     270        );
     271
     272        $commenter_filter = function () {
     273            return array(
     274                'comment_author_email' => 'unapproved@example.org',
     275            );
     276        };
     277
     278        add_filter( 'wp_get_current_commenter', $commenter_filter );
     279
     280        $this->assertEquals(
     281            build_comment_query_vars_from_block( $block ),
     282            array(
     283                'orderby'            => 'comment_date_gmt',
     284                'order'              => 'ASC',
     285                'status'             => 'approve',
     286                'no_found_rows'      => false,
     287                'include_unapproved' => array( 'unapproved@example.org' ),
     288                'post_id'            => self::$custom_post->ID,
     289                'hierarchical'       => 'threaded',
     290                'number'             => 5,
     291                'paged'              => 1,
     292            )
     293        );
     294    }
    253295}
Note: See TracChangeset for help on using the changeset viewer.