#39650 closed defect (bug) (fixed)
Commenting on a draft post results in blank page
Reported by: | sumitbagthariya16 | Owned by: | johnbillion |
---|---|---|---|
Milestone: | 4.8 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Comments | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
Hi,
When I submit the comment on draft post it will redirect to the blank page. I have attached video for the more information.
Thanks
Attachments (11)
Change History (32)
#2
@
8 years ago
- Keywords has-patch added
Hi @bhaveshkhadodara , @sumitbagthariya16
I have added patch with above issue solution.
Thanks
@
8 years ago
Patch will not show comment form if post status is not publish. The patch will also take care of pending status.
This ticket was mentioned in Slack in #core by sagarprajapati. View the logs.
8 years ago
This ticket was mentioned in Slack in #core by sumitbagthariya16. View the logs.
8 years ago
#7
@
8 years ago
@sagarprajapati It's better to have this condition after the first `if` condition. Because there might be some chances the $post_id
will be null
.
if ( null === $post_id ) $post_id = get_the_ID();
#8
@
8 years ago
@sagarprajapati same thing happens when we have pending status my patch will show comment form only if status is publish.
@dhanendran thanks for suggestions!
#9
@
8 years ago
- Keywords needs-patch added; has-patch removed
- Summary changed from Display blank page when post status is draft to Commenting on a draft post results in blank page
- Version 4.7.1 deleted
What @dhanendran said. Also, the code would need somebrackets to follow the WordPress PHP coding standards.
However, I don't think hiding the comment form for draft posts is the ideal solution here. Allowing comments on drafts might be desirable under some circumstances (live previews in the customizer, REST API, etc. See also #19739).
Instead of a blank page there should be an actual error message. This means changing wp_handle_comment_submission()
accordingly, where there's currently this line: return new WP_Error( 'comment_on_draft' );
(note the lack of error message).
#10
@
8 years ago
@milindmore22 Please note that your patch would break commenting on private posts.
#12
@
8 years ago
- Keywords has-patch added; needs-patch removed
Hi @swissspidy
I agree with you. I have prepared a patch with your suggestions. Please check it.
Thanks
#13
@
8 years ago
Hi @swissspidy and @mayurk
@mayurk: I also working on this issue. I agreed your patch but we will need to add the proper error message as per swissspidy's suggestions.
I have added the patch with the error message. Please check it.
Thanks
#14
@
8 years ago
- Keywords needs-unit-tests dev-feedback added
Seems like you guys should work together / coordinate on who's updating a patch :-)
39650.4.patch is not needed. That would be to big of a change. Adding the message argument to the WP_Error
object automatically displays that message when posting the comment. That's why the exit;
there is just fine as-is.
39650.5.patch does not need to touch wp-comments-post.php
either. Also, why adding the error message to every WP_Error
object and not just on comment_on_draft
(the original scenario described in the ticket)?
The error message should probably only be shown if the user has the capability to read the post, so a current_user_can()
check seems to be needed.
#15
@
8 years ago
- Keywords has-unit-tests added; needs-unit-tests removed
Sorry @swissspidy
I thought that it is not working for all others. I have updated patch with the changes. Please check it.
I have also done unit test for the above patch and here is the result.
C:\wamp\www\wordpress-core>phpunit --group comment Installing... Running as single site... To run multisite, use -c tests/phpunit/multisite.xml Not running ajax tests. To execute these, use --group ajax. Not running ms-files tests. To execute these, use --group ms-files. Not running external-http tests. To execute these, use --group external-http. PHPUnit 5.7.5 by Sebastian Bergmann and contributors. .............................................................. 62 / 339 ( 18%) .............................................................. 124 / 339 ( 36%) .............................................................. 186 / 339 ( 54%) .............................................................. 248 / 339 ( 73%) .............................................................. 310 / 339 ( 91%) ............................. 339 / 339 (100%) Time: 50.03 seconds, Memory: 90.00MB OK (339 tests, 657 assertions)
Thank you.
#16
@
8 years ago
- Keywords needs-unit-tests added; has-unit-tests removed
needs-unit-tests
means some unit tests need to be written for this, not only running the existing tests. See the handbook for a list of all trac keywords. Let me know if I can help with that. I might have time to write tests myself next week.
39650.6.patch goes into the right direction. The correct capability might be edit_post
instead of read_post
, but we'll see that with the unit test.
#17
follow-up:
↓ 18
@
8 years ago
Great work with patch @sagarprajapati, Thanks @swissspidy totally forgot that will keep in mind about flow
Guys #19739 does this ticket related?
#18
in reply to:
↑ 17
@
8 years ago
Replying to milindmore22:
Great work with patch @sagarprajapati, Thanks @swissspidy totally forgot that will keep in mind about flow
Guys #19739 does this ticket related?
Yep, it's related and I mentioned it before. Let's see if we can fix both at once.
#19
@
8 years ago
- Keywords has-unit-tests added; dev-feedback needs-unit-tests removed
The correct capability might be
edit_post
instead ofread_post
, but we'll see that with the unit test.
read_post
is fine. map_meta_cap()
handles this perfectly.
Hi @sumitbagthariya16,
Here we should remove the comment box when the post is draft.
Thanks