[wp-trac] [WordPress Trac] #35337: Global $post is null in "comment_post" and "pre_comment_on_post" hooks
WordPress Trac
noreply at wordpress.org
Sat Jan 9 04:08:30 UTC 2016
#35337: Global $post is null in "comment_post" and "pre_comment_on_post" hooks
--------------------------+------------------------------
Reporter: dennis_f | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Comments | Version: 4.4
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by boonebgorges):
Gotcha. It appears that this is due to [34799], which moved the handling
of comment submission from wp-comments-post.php into a new function,
`wp_handle_comment_submission()`. This move had the side-effect that a
bunch of the variables that were previously being declared in the global
scope - such as `$post` - are now local to the function.
Technically, each of these deglobalized variables is a potential backward
compatibility break. It's possible, for example, that someone is filtering
'comment_post' and expecting `$GLOBALS['status_obj']` to be populated. (To
quote @wonderboymusic: Globals will kill WordPress. Globals are killing
WordPress.) In most of these cases, I think it's perfectly reasonable for
us to drop backward compatibility. But `$post` may be a special case,
since we have a convention throughout WordPress for `global $post` to
contain the "current" post object. So maybe we can make an exception here
and hoist the post into global scope.
Ping @johnbillion @SergeyBiryukov
--
Ticket URL: <https://core.trac.wordpress.org/ticket/35337#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list