Make WordPress Core

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: henrywright's profile henry.wright Owned by: sergeybiryukov's profile SergeyBiryukov
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)

41228.diff (591 bytes) - added by henry.wright 8 years ago.
41228.diff passes a 2nd argument to do_action(). This will allow full access to the deleted comment in hooked functions.
41228.2.diff (4.2 KB) - added by henry.wright 8 years ago.
41288.2.diff addresses the related actions. Thanks @SergeyBiryukov for mentioning transition_comment_status that will come in useful :)
41228.3.diff (5.3 KB) - added by henry.wright 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.

Download all attachments as: .zip

Change History (10)

#1 follow-up: @henry.wright
8 years ago

Alternatively, the 2nd arg could be $comment, where $comment is the (deleted) comment object.

@henry.wright
8 years ago

41228.diff passes a 2nd argument to do_action(). This will allow full access to the deleted comment in hooked functions.

#2 @henry.wright
8 years ago

  • Keywords has-patch added

#3 in reply to: ↑ 1 @SergeyBiryukov
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.

@henry.wright
8 years ago

41288.2.diff addresses the related actions. Thanks @SergeyBiryukov for mentioning transition_comment_status that will come in useful :)

#4 @DrewAPicture
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.

@henry.wright
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.

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


7 years ago

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


7 years ago

#7 @SergeyBiryukov
7 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 41689:

Comments: Pass $comment object to comment actions:

  • delete_comment
  • deleted_comment
  • trash_comment
  • trashed_comment
  • untrash_comment
  • untrashed_comment
  • spam_comment
  • spammed_comment
  • unspam_comment
  • unspammed_comment

Props henry.wright.
Fixes #41228.

Note: See TracTickets for help on using tickets.