Make WordPress Core

Opened 4 years ago

Last modified 4 years ago

#13091 new defect (bug)

edit_post action on wp_update_comment_count_now should not be fired if the comment count hasn't changed

Reported by: solarissmoke Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.0
Component: Comments Keywords: dev-feedback has-patch
Focuses: Cc:


wp_update_comment_count_now() is called whenever a comment status is transitioned (or a comment is deleted). However, if the comment transition is not from/to the 'approved' status (e.g., if the comment is transitioned from 'spam' to 'trash' or from 'unapproved' to 'trash'), then the associated post is not actually affected. Therefore in such cases the edit_post action shouldn't be fired, because the post has not been edited/modified in any way. I would argue that the 'wp_update_comment_count' action also should not be fired.

One solution is to check whether the comment count has changed before firing the action. Another possible option is to call wp_update_comment_count only when a comment has transitioned in/out of the "approved" status. I'm inclined to prefer the former because it involves less change.

Proposed patch to follow.

Attachments (2)

13091.patch (945 bytes) - added by solarissmoke 4 years ago.
13091-opt2.patch (575 bytes) - added by solarissmoke 4 years ago.
Check whether status is changing from/to approved before calling wp_update_comment_count()

Download all attachments as: .zip

Change History (7)

solarissmoke4 years ago

comment:1 solarissmoke4 years ago

  • Keywords dev-feedback has-patch added

comment:2 solarissmoke4 years ago

Actually most of the functions that call wp_update_comment count already check for this. The problem is in wp_set_comment_status, where it is called regardless of what the change is. So maybe to fix that would be better.

solarissmoke4 years ago

Check whether status is changing from/to approved before calling wp_update_comment_count()

comment:3 nacin4 years ago

  • Milestone changed from 3.0 to Future Release

Not convinced on this.

comment:4 solarissmoke4 years ago

Okay, let me try to explain my point of view:

Currently, all other calls for edit_post (in wp_insert_post() and wp_publish_post() ) are when post content has changed.

There are many instances where you might want to know when a post has visibly changed (e.g., post content or approved comments have changed) - for example for email notifications or cache invalidation. But you would not want to trigger such events if the change does not affect what is visible on the site (e.g., a spam comment was trashed).

If edit_post isn't mean to reflect visible changes to a post, perhaps we might introduce a new action that is? -- "post_changed", or something like that?

comment:5 hakre4 years ago

Close as wontfix? And if not, this might be a duplicate, I remember some other, older ticket that was reporting a similar sounding issue with the filter.

Note: See TracTickets for help on using tickets.