[wp-trac] [WordPress Trac] #35090: Query for comments where post isn't set
WordPress Trac
noreply at wordpress.org
Tue Dec 15 22:10:08 UTC 2015
#35090: Query for comments where post isn't set
------------------------------------------+------------------
Reporter: danielbachhuber | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: 4.5
Component: Comments | Version:
Severity: normal | Resolution:
Keywords: needs-patch needs-unit-tests | Focuses:
------------------------------------------+------------------
Changes (by boonebgorges):
* keywords: has-patch has-unit-tests dev-feedback => needs-patch needs-
unit-tests
Comment:
The test in [30402] was meant to describe the legacy behavior of
`get_comments()`. Since it was introduced in [8543], it's had an `empty(
$post_id )` check, so that `post_id = 0` has always resulted in the
`post_id` param being ignored. In other words, I wasn't endorsing it as
"correct" behavior so much as I was describing it.
I agree that there ought to be a way to query for comments that have 0 as
a post_id. This change will necessarily involve breaking backward
compatibility in at least some cases. [attachment:35090.1.2.diff] breaks
too much: it makes it impossible to query for all comments regardless of
`comment_post_ID`. Here's what I think would be an acceptable break, and
what should be described in unit tests:
* Default value of `post_id` (ie not provided in the params array) should
skip the `comment_post_ID` clause (return all comments)
* Passing an empty string, bool `false`, or `null` to `post_id` should
skip the `comment_post_ID` clause
* int `0` or string `'0'` (`is_numeric( $post_id )`) should return
comments with `comment_post_ID IN ( '0', '' )`
This will probably require changing the default value of `post_id` in
`get_comments()` and/or `WP_Comment_Query::query()`.
The only behavior that will change will thus be cases where `'post_id' =>
'0'` or `'post_id' => 0`; currently, they return comments of all posts,
but after the change they'll return only comments with a null post. This
is a break that makes sense to me.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/35090#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list