Make WordPress Core

Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#48093 closed defect (bug) (fixed)

get_comment_count() should return an integer for all counts of all statuses

Reported by: johnbillion Owned by: johnbillion
Priority: normal Milestone: 5.5
Component: Comments Version: 2.0
Severity: normal Keywords: good-first-bug has-patch needs-testing has-unit-tests has-dev-note
Cc: Focuses:

Description

get_comment_count() returns a mixture of integers and numeric strings depending on the comment status and count.

Any status with zero comments is represented by integer 0.
Any status with more than zero comments is represented by a numeric string.
The total_comments and all elements are always integers.

Example:

array(7) {
  ["approved"]            => string(1) "221"
  ["awaiting_moderation"] => int(0)
  ["spam"]                => string(1) "10"
  ["trash"]               => int(0)
  ["post-trashed"]        => int(0)
  ["total_comments"]      => int(221)
  ["all"]                 => int(211)
}

It should return integers for all statuses for consistency.

The tests in Tests_Get_Comment_Count() should be switched to using assertSame().

Attachments (2)

48093.patch (443 bytes ) - added by progremzion 7 years ago.
48093.diff (8.3 KB ) - added by m.usama.masood 7 years ago.

Download all attachments as: .zip

Change History (20)

#1 @johnbillion
7 years ago

In 46223:

Docs: Improve the docs for comment counting related functions.

See #47110, #48093

#2 @johnbillion
7 years ago

  • Keywords good-first-bug added

#3 @progremzion
7 years ago

  • Keywords has-patch added; needs-patch removed

Hi @johnbillion

I have fixed the issue. Can you please review? I am new to core contribution, so please do let me know if something is missing.

We don't need to update the Tests_Get_Comment_Count() class as by updating the get_comment_count function's return value will resolve that.

Thanks!

@progremzion
7 years ago

#4 @progremzion
7 years ago

  • Keywords needs-testing added

@m.usama.masood
7 years ago

#5 @m.usama.masood
7 years ago

  • Keywords has-unit-tests added; needs-unit-tests removed
  • Resolutionworksforme
  • Status newclosed

Hi @davidakennedy,

I have applied patch and update docs of functions. I also updated the Tests_Get_Comment_Count() class & Tests_Import_Import() class for phpunit test.

Thanks!

#6 @knutsp
7 years ago

  • Resolution worksforme
  • Status closedreopened

A valid bug ticket is first closed after committed, then as "fixed".

This ticket was mentioned in Slack in #core by sergey. View the logs.


7 years ago

#8 @SergeyBiryukov
7 years ago

  • Milestone Awaiting Review5.4

This ticket was mentioned in Slack in #core by sergey. View the logs.


7 years ago

#10 @sncoker
7 years ago

At #WCUS Contributor Day. Patch still applies cleanly. Unit tests are passing.

#11 @yingling017
7 years ago

At #WCUSContributorDay patch applies cleanly and unit tests are passing.

#12 @desrosj
7 years ago

  • Keywords needs-dev-note added

This could be a good thing to call out in the Miscellaneos Developer Changes dev note just in case someone is performing strict comparisons.

#13 @johnbillion
7 years ago

  • Milestone 5.45.5

#14 @johnbillion
6 years ago

  • Owner set to johnbillion
  • Resolutionfixed
  • Status reopenedclosed

In 47526:

Comments: Ensure all elements in the array returned by get_comment_count() are integers.

Previously elements would be a mixture of strings and integers depending on their numeric value.

Props progremzion, m.usama.masood

Fixes #48093

#15 @desrosj
6 years ago

  • Keywords has-dev-note added; needs-dev-note removed

This received a call out in the Miscellaneous Developer Changes in 5.5 dev note: https://make.wordpress.org/core/2020/07/29/miscellaneous-developer-focused-changes-in-wordpress-5-5/.

#16 @desrosj
6 years ago

  • Keywords needs-dev-note added; has-dev-note removed

Actually, I am mistaken. Confused this with another ticket.

This ticket was mentioned in Slack in #core by desrosj. View the logs.


6 years ago

#18 @justinahinon
6 years ago

  • Keywords has-dev-note added; needs-dev-note removed
Note: See TracTickets for help on using tickets.