WordPress.org

Make WordPress Core

Opened 13 months ago

Last modified 6 months ago

#51305 assigned defect (bug)

wp_list_comments returns nothing if "per_page" parameter is defined

Reported by: SGr33n Owned by: metalandcoffee
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.5.1
Component: Comments Keywords: needs-patch needs-unit-tests
Focuses: Cc:

Description

Hi,
The function wp_list_comments returns a notice if "per_page" parameter is defined.
The notice is in wp-includes/comments-template.php

wp_queue_comments_for_comment_meta_lazyload( $_comments )

message: "Undefined variable: _comments"

Thanks!

Change History (5)

#1 @SergeyBiryukov
13 months ago

  • Keywords needs-patch needs-unit-tests added

#2 @metalandcoffee
10 months ago

  • Owner set to metalandcoffee
  • Status changed from new to assigned

Hi @SGr33n - I tried to reproduce this error by calling wp_list_comments( array( 'per_page' => 1 ) ); but I'm not getting any PHP notices when this happens. Can you give steps to reproduce and provide all of the parameters you're using in wp_list_comments? How many comments are you expecting to see on the post in question? What is your PHP version?

#3 @SGr33n
10 months ago

Hi @metalandcoffee,
At first test looks working on the latest version.
Will keep you updated
Thanks!

#4 @SGr33n
10 months ago

First test, working:

<?php
        wp_list_comments(
                array(
                        'page'                  => 1,
                        'per_page'              => 10,
                        'style'                 => 'div',
                )
        );

Second test (non working):

<?php
        wp_list_comments(
                array(
                        'page'                  => 1,
                        'per_page'              => absint( get_option( 'comments_per_page' ) ),
                        'style'                 => 'div',
                )
        );

Is returning

[12-Dec-2020 17:07:55 UTC] PHP Notice:  Undefined variable: _comments in /web/wp-includes/comment-template.php on line 2236
[12-Dec-2020 17:07:55 UTC] PHP Notice:  Undefined variable: _comments in /web/wp-includes/comment-template.php on line 2244

PHP version 7.4
PHP-FPM
Webserver Nginx
WordPress version 5.6

#5 @donmhico
6 months ago

I'm unable to replicate the issue in current master branch (commit 02e9222e2ebaf97c75623112ad2370740a8db6a5).

Note: See TracTickets for help on using tickets.