Make WordPress Core

Opened 10 years ago

Closed 6 years ago

#20262 closed defect (bug) (fixed)

When "Automatically close comments on articles older than X days" is enabled, comments appear closed on draft posts

Reported by: evarlese Owned by: rachelbaker
Milestone: 4.4 Priority: normal
Severity: normal Version: 3.3
Component: Comments Keywords: has-patch commit has-unit-tests
Focuses: Cc:


If the setting to "Automatically close comments on articles older than X days" is enabled via Settings -> Discussion, comments automatically appear as closed on draft posts until the post is published. This is regardless of the Discussion settings configured on the Post Edit page for the draft post.

To replicate:

  1. Via Settings -> Discussion, click on "Automatically close comments on articles older than X days."
  1. Create a new post and save it as a draft. Make sure comments are enabled in your Discussion module.
  1. When previewing the draft post, it will say "Comments closed" regardless of the Discussion settings.

The post will show comments as being allowed once it's published, they only show up as closed when in the draft format.

Attachments (6)

20262.diff (908 bytes) - added by solarissmoke 10 years ago.
Only close comments on published posts
20262.2.diff (1.6 KB) - added by MikeHansenMe 7 years ago.
20262.3.diff (1.6 KB) - added by rachelbaker 6 years ago.
20262.4.diff (538 bytes) - added by nacin 6 years ago.
20262.5.diff (1.8 KB) - added by rachelbaker 6 years ago.
20262.6.diff (1.8 KB) - added by rachelbaker 6 years ago.
Correcting unit test factory methods from 20262.5.diff to get the id

Download all attachments as: .zip

Change History (23)

10 years ago

Only close comments on published posts

#1 @solarissmoke
10 years ago

  • Component changed from General to Comments
  • Keywords has-patch added

This is being caused by _close_comments_for_old_posts(), which uses post_date_gmt to work out when the post was published. But for drafts this is always set to 0, so the post always appears to be older than the max age threshold.

I'm thinking that the filter should only apply to published posts... see patch.

#2 @solarissmoke
10 years ago

  • Keywords dev-feedback added

... although you can't comment on drafts anyway, so maybe we should never be displaying a comment form on draft previews?

#3 @MikeHansenMe
9 years ago

This does not seem like it would be a problem to me since no one can comment on a draft anyway. I guess if you leave a draft for months before you publish it, it could cause problems but I would hope you would update the post date in this case.

7 years ago

#4 @rachelbaker
7 years ago

  • Owner set to rachelbaker
  • Status changed from new to reviewing

This looks to work as intended to me.

6 years ago

#5 @rachelbaker
6 years ago

  • Keywords commit added; dev-feedback removed
  • Milestone changed from Awaiting Review to 4.3
  • Status changed from reviewing to accepted

Tested the patch from @MikeHansenMe and it works as intended. With the "close comments after X days" option enabled comments are no longer closed on unpublished posts. I added 20262.3.diff which just uses a stricter check on the publish conditional.

#6 @nacin
6 years ago

I think this needs to be a bit more encompassing. Right now, core closes comments on drafts, published posts, etc., but also privately published posts. Changing this to just 'publish' would harm some of that.

I think we should just hardcode this to skip 0 values.

I would have it skip 'draft', 'pending', and 'auto-draft' — like what currently happens for 0000-00-00 values in wp_insert_post() — but I think hardcoding it actually makes sense here. If it's a "draft" backdated 31 days, then it probably *should* show up as comments closed.

6 years ago

#7 @nacin
6 years ago

  • Keywords close added; commit removed

Hmm. Given that the form won't work, I'm not actually sure it should be shown in this case.

This should e A) wontfix, B) 20262.4.diff, or C) a major change to how this is themed. I don't think 'C' interests me.


#8 follow-up: @nacin
6 years ago

I do tend to think that there's a UX issue saying comments are closed when they are not, but I'm not sure I like any of the alternatives.

What's the best UX here? Show the form and disable the fields?

#9 in reply to: ↑ 8 @rachelbaker
6 years ago

  • Keywords ux-feedback added
  • Milestone changed from 4.3 to Future Release

Based on @Nacin's comments above, moving this out of the 4.3 milestone and added the UX feedback keyword.

#10 @MikeHansenMe
6 years ago

I think we should go with option B. It seems to be pretty common that people draft content for long periods of time. @nacin's patch still applies.

#11 @wonderboymusic
6 years ago

  • Keywords close removed
  • Milestone changed from Future Release to 4.4

more opinions on B, please

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

6 years ago

#13 @SergeyBiryukov
6 years ago

  • Keywords needs-unit-tests added

20262.4.diff makes sense to me.

6 years ago

#14 @rachelbaker
6 years ago

  • Keywords commit added; ux-feedback needs-unit-tests removed

In 20262.5.diff I refreshed @nacin's patch against trunk and added a few unit tests for _close_comments_for_old_post().

#15 @rachelbaker
6 years ago

  • Keywords has-unit-tests added

6 years ago

Correcting unit test factory methods from 20262.5.diff to get the id

#16 @rachelbaker
6 years ago

In 20262.6.diff I corrected uses of self::factory()->post->create_and_get() where I was expecting to return the post_id to the correct factory method self::factory()->post->create() thanks to feedback from @wonderboymusic.

#17 @wonderboymusic
6 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 35475:

Comments: don't auto-close comments on draft posts.

Adds unit tests.

Props solarissmoke, MikeHansenMe, nacin, rachelbaker.
Fixes #20262.

Note: See TracTickets for help on using tickets.