#13091 closed defect (bug) (invalid)
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: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Comments | Version: | 3.0 |
| Severity: | normal | Keywords: | dev-feedback has-patch |
| Cc: | Focuses: |
Description
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)
Change History (9)
@
16 years ago
Check whether status is changing from/to approved before calling wp_update_comment_count()
#4
@
16 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?
#5
@
16 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.
#6
@
12 years ago
- Resolution → invalid
- Status new → closed
A valid usecase against proposed is if a comment comes in and is awaiting approval, you can edit the comment then set it as spam, pending or approved. As such, edit_post should be fired as its possible for the comment to be edited without the status of the comment changing.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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.