-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Fix: Disable block commenting when postId is not number #71643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Disable block commenting when postId is not number #71643
Conversation
| if ( ! hasValidPostId ) { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: We could just inline the check here. I usually avoid creating the variables if they're only used once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I update it like this, @Mamaduka? And would it be fine to add a comment?
// If postId is not a valid number, do not render the comment sidebar.
if ( ! ( !! postId && typeof postId === 'number' ) ) {
return null;
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that looks about right.
|
@R1shabh-Gupta, is this ready for the review? |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
@Mamaduka, do we ship this PR first and then add a block comment post type support? #71642 (comment) |
|
@t-hamano, yes. We should resolve current errors and since post type supports is still in discussion, this seems like a fastest way. |
t-hamano
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
What?
Closes #71642
This PR fixes block commenting functionality to prevent crashes and disable comments when editing templates or other contexts without valid integer post ID.
Why?
Comments were allowed in template editing (where post ID is a string like
'twentytwentyfive//home'), but the WordPress REST API requires post IDs to be integers, causing requests to failHow?
Added a check to only show comment functionality when
postIdis a valid number (integer), completely hiding comment UI for templates and other invalid contextsTesting Instructions
Test normal post commenting (should still work):
Test template editing (comments should be disabled):
Screenshots or screencast