Allow get_comments_number() to accept post object
|Reported by:||coffee2code||Owned by:||DrewAPicture|
get_comments_number() unnecessarily enforces an int value for its $post_id argument. This is contrary to expectations whereby most template functions accept either a post object or ID, and it doesn't match up with the function's phpDocs which indicate either value is acceptable.
Ultimately, the $post_id argument gets sent to get_post() to obtain the post, so the argument can be directly passed along and left to be handled by get_post().
Attached is a patch which removes the unnecessary typecasting. The patch also adds braces to the if conditional to match the new guideline change.
Also included are some unit tests for it. Since there doesn't appear to be any unit tests for comment-template.php functions, I created tests/comment/output.php to mirror how posts template functions are tested in tests/post/output.php (though post template tests are pretty meager).
Change History (19)
comment:4 @DrewAPicture — 9 months ago
- Keywords commit added
- Milestone changed from Awaiting Review to 4.0
comment:10 @DrewAPicture — 9 months ago
- Owner set to DrewAPicture
- Resolution set to fixed
- Status changed from reopened to closed
- Keywords has-patch added; needs-patch removed
- Resolution fixed deleted
- Status changed from closed to reopened