Opened 8 years ago
Closed 7 years ago
#41228 closed enhancement (fixed)
No way to get the post ID after a comment is deleted
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Comments | Keywords: | has-patch |
Focuses: | Cc: |
Description
If we hook to deleted_comment
we get given $comment_ID
but at this point the comment has been removed from the database so we can't do things like this:
$comment = get_comment( $comment_ID ); echo $comment->comment_post_ID;
Can we pass a 2nd arg to do_action()
? For example:
do_action( 'deleted_comment', $comment->comment_ID, $post_id );
Attachments (3)
Change History (10)
@
8 years ago
41228.diff passes a 2nd argument to do_action(). This will allow full access to the deleted comment in hooked functions.
#3
in reply to:
↑ 1
@
8 years ago
- Component changed from General to Comments
Replying to henry.wright:
Alternatively, the 2nd arg could be
$comment
, where$comment
is the (deleted) comment object.
Makes sense to me, but I think the same should be done for all the related actions, for consistency:
delete_comment
deleted_comment
trash_comment
trashed_comment
untrash_comment
untrashed_comment
spam_comment
spammed_comment
unspam_comment
unspammed_comment
Or you could use one of the hooks in wp_transition_comment_status()
, e.g. transition_comment_status
, which gets called on comment deletion with delete
as the new status, and does pass the full comment object to the hook.
@
8 years ago
41288.2.diff addresses the related actions. Thanks @SergeyBiryukov for mentioning transition_comment_status
that will come in useful :)
#4
@
8 years ago
- Milestone changed from Awaiting Review to 4.9
I agree about adding the param to all of the hooks.
@henrywright: We're also going to need changelog entries for each of the hooks getting the new params.
@
8 years ago
Thanks for the link to the coding standards. I'll note what constitutes a significant change for next time. 41228.3.diff adds @since tags to each DocBlock.
Alternatively, the 2nd arg could be
$comment
, where$comment
is the (deleted) comment object.