Make WordPress Core

Opened 2 years ago

Last modified 15 months ago

#36564 new enhancement

Last Modified for Comments

Reported by: dshanske Owned by:
Milestone: Future Release Priority: normal
Severity: trivial Version: 4.4
Component: Comments Keywords: needs-patch dev-feedback needs-unit-tests
Focuses: Cc:


Related #28463, #19495.

Posts have a last modified and last modified gmt, but comments have no such thing. There are several proposals indicating a need for comment revision, or tracking when the comment is first created.

Wanted to explore the idea of having last modified and last modified gmt stored as comment meta triggered by update_comment as a simple, low impact way of adding this feature that could be used by a variety of plugins.

This could be implemented by plugin hooking to edit_comment, but if such a feature is to be useful, it needs a standard storage format.

Attachments (1)

36564.diff (662 bytes) - added by dshanske 2 years ago.

Download all attachments as: .zip

Change History (9)

#1 @dshanske
2 years ago

  • Severity changed from normal to trivial

2 years ago

This ticket was mentioned in Slack in #core-comments by dshanske. View the logs.

2 years ago

This ticket was mentioned in Slack in #core-comments by dshanske. View the logs.

2 years ago

#4 @rachelbaker
2 years ago

  • Keywords needs-patch dev-feedback needs-unit-tests added

Before we can say how to store a value, it would be ideal to have an understanding of how it would be used, and where it would be used

Would you expect to have the comment_modified value returned as part of WP_Comment?

#6 @chrisvanpatten
2 years ago

Offhand idea of how to use that: it'd serve as a good way to indicate when a comment was edited as a bit of transparency.

For instance, when you edit a message in Slack, it appends "(edited)", with a timestamp of the modification time displayed on hover. Storing the comment's post time/modified time might be an easy way to calculate and display that in a site that allows comments to be edited by the user.

Ugly code example:


add_filter( 'get_comment_date', function( $date, $d, $comment ) {
    if ( $comment->comment_modified_date != $date ) {
        return "{$date} <time class="modified" datetime="{$comment->comment_modified_date}">(Edited)</time>";
    } else {
        return $date;
}, 10, 3 )

(get_comment_date may very well be the wrong place to hook that, and I'm also fairly sure you'd need to re-format the datetime string to work in the <time> element, but you get the idea!)

Of course people can store that value as custom comment meta right now, but having it baked in would be pretty handy.

(Oh hey, noticed that this Trac comment also shows the time of last edit. There's another good example in the wild!)

Last edited 2 years ago by chrisvanpatten (previous) (diff)

#7 @dshanske
2 years ago

I had mentioned a bit vaguely in Slack what I wanted to use this for. I saw tickets where people wanted comment history, or comment revisions. Both are potentially useful, but they don't address the simplest element comments are missing in terms of history...a last modified date similar to the one that posts have.

And in order for this to be stable, it has to be in a set place. So, my suggestion was to set the keys in comment meta for this. And then create some functions around this such as get_comment_updated_date.

Maybe this idea is backward. Maybe the comment meta should be original date, and the modified date should be the existing one?

I hadn't considered WP_Comment as an issue, because I haven't really started using it...makes me want to try though. Being as it mirrors a post feature...a modified date, it probably should be retrieved as part of WP_Comment.

@chrisvanpatten has a perfect use case. But at the most basic level, I wanted to know the last time I updated a comment. I had been working on implementing Webmentions(something I hope to get into Core someday) and they allow for updates.

#8 @swissspidy
15 months ago

  • Milestone changed from Awaiting Review to Future Release

From #19495:

We should consider implementing comment history, taking a page from what Akismet has done. We could mark why a comment got marked as spam (or by whom), and cover who moderated what, who edited what, etc. It also opens the door into comment revisions and thus comment types.

A last_modified field would be a good first step I think.

Note: See TracTickets for help on using tickets.