Opened 8 years ago
Closed 8 years ago
#40286 closed defect (bug) (fixed)
It appears to me that comments_open() is passing the wrong args to apply_filters
Reported by: | sringwood | Owned by: | rachelbaker |
---|---|---|---|
Milestone: | 4.8 | Priority: | normal |
Severity: | normal | Version: | 1.5 |
Component: | Comments | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
The function comments_open() is passed one argument which may be null ($post_id) which is used to call get_post(). The function get_post() will use the current post if $post_id is null.
The last line of the function comments_open() is
return apply_filters( 'comments_open', $open, $post_id );
Logically in the call it seems to me that $post_id (which may be null) should be $_post->ID to reflect the post returned by the call get_post().
Attachments (4)
Change History (16)
#1
@
8 years ago
- Keywords needs-patch good-first-bug added
- Milestone changed from Awaiting Review to Future Release
- Version changed from 4.7.3 to 1.5
#4
@
8 years ago
- Keywords has-patch needs-testing added; needs-patch removed
- Milestone changed from Future Release to 4.8
Thank you, @shulard!
#5
follow-up:
↓ 6
@
8 years ago
- Keywords needs-docs added
Looks like this also needs a change to the inline docs for the comments_open
and pings_open
filters since $_post->ID
would always be an integer, and never a WP_Post object.
#6
in reply to:
↑ 5
@
8 years ago
@rachelbaker, you are right, I've submitted a new patch with fixed doc too.
#7
@
8 years ago
- Keywords 2nd-opinion added; good-first-bug needs-testing needs-docs removed
This might be overkill, but because there is no way to be sure $_post->ID
is defined, I added a conditional that will pass 0
to the comments_open()
or pings_open()
filter for the Post ID. Would love a second opinion on if this conditional is worthy of the edge-case handling. 40286.3.diff
#8
@
8 years ago
I though that get_post
function will always return an WP_Post
instance so $_post->ID
will always be defined. It can be null
but it's defined ($ID
is a public property of WP_Post
class).
#9
@
8 years ago
@shulard get_post()
can return null
. These two functions can be used anywhere, and cannot assume the post global is populated.
Hi @sringwood, welcome to WordPress Trac!
Well spotted, this does appear to be a valid bug. It affects the
pings_open()
function too.