WordPress.org

Make WordPress Core

Opened 6 months ago

Last modified 6 months ago

#40293 new defect (bug)

Comment template - warning

Reported by: victorfreitas Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.8
Component: Comments Keywords: has-patch needs-unit-tests reporter-feedback
Focuses: Cc:

Description

Hi,

in the comments_template function, you are entering a divide-by-zero condition at line 1379 of the wp-includes/comment-template.php file.

The line described above is like this.

<?php
$comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
?>

I believe this will solve.

<?php
$offset = 0;

if ( $top_level_count && $per_page ) {
    $offset = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
}

$comment_args['offset'] = $offset;
?>

I'm using a default install with theme Twenty Seventeen.

Thank you!

Attachments (1)

comment-template.patch (592 bytes) - added by thamaraiselvam 6 months ago.

Download all attachments as: .zip

Change History (5)

#1 follow-up: @thamaraiselvam
6 months ago

  • Keywords has-patch added

Yes, It could lead to divide-by-zero condition in some scenario and @victorfreitas I have removed the variable

$offset

to reduce unnecessary memory usages because it's just one-time usage.

#2 follow-up: @johnbillion
6 months ago

  • Keywords needs-unit-tests reporter-feedback added

Thanks for the ticket @victorfreitas! Welcome to WordPress Trac.

Under what condition does this occur? Can you provide some steps to reproduce please?

Any change here will need unit tests.

#3 in reply to: ↑ 2 @victorfreitas
6 months ago

Hi @johnbillion,

Yes, on the Discussion Settings (options-discussion.php) page you need to put "Break comments into pages with" to 0 comments_per_page option.

Then just access a page or single.

Replying to johnbillion:

Thanks for the ticket @victorfreitas! Welcome to WordPress Trac.

Under what condition does this occur? Can you provide some steps to reproduce please?

Any change here will need unit tests.

#4 in reply to: ↑ 1 @victorfreitas
6 months ago

Thanks @thamaraiselvam you're right.
By default comment args offset is empty even.

Replying to thamaraiselvam:

Yes, It could lead to divide-by-zero condition in some scenario and @victorfreitas I have removed the variable

$offset

to reduce unnecessary memory usages because it's just one-time usage.

Note: See TracTickets for help on using tickets.