[wp-trac] [WordPress Trac] #26240: Allow get_comments_number() to accept post object

WordPress Trac noreply at wordpress.org
Mon Nov 25 17:05:54 UTC 2013


#26240: Allow get_comments_number() to accept post object
--------------------------+-----------------------------
 Reporter:  coffee2code   |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Comments      |    Version:
 Severity:  normal        |   Keywords:  has-patch
--------------------------+-----------------------------
 `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).

--
Ticket URL: <http://core.trac.wordpress.org/ticket/26240>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list