#64049 closed defect (bug) (fixed)
REST API: Updating comment via REST does not respect allow_empty_comment filter
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.9 | Priority: | normal |
| Severity: | normal | Version: | trunk |
| Component: | REST API | Keywords: | |
| Focuses: | rest-api | Cc: |
Description (last modified by )
When updating a comment via the REST API we currently fail comment updates in the WP_REST_Comments_Controller::update_item method if the updated content is empty(). On REST comment creation and within traditional comment updates via wp_handle_comment_submission we respect the return value of the allow_empty_comment filter and permit empty comment content when this filter is set.
My understanding of the history here is that allowing empty comments permits moderation by allowing inappropriate comment content to be deleted without removing the content entity itself; or alternatively (and as discussed in #43177) to permit comments to be saved which only contain metadata and do not have any "content" in the traditional sense.
This may also unblock certain actions for editorial comments within the block editor.
Change History (9)
#3
@
6 weeks ago
Added link in description to #62684 which (most-recently that I can find) documents that editing a comment to be empty is desired functionality.
This ticket was mentioned in PR #10083 on WordPress/wordpress-develop by @kadamwhite.
6 weeks ago
#4
- Keywords has-patch has-unit-tests added
Originally proposed by @adamsilverstein in https://github.com/WordPress/wordpress-develop/pull/9988, this PR adds tests to his fix while also resolving a potential logical error which could prevent updates to unrelated comment object properties.
- #9988 as written causes an error in some existing unit tests (including my newly-added one for this ticket),
Undefined array key "comment_content", because the controller expects to be able to process _partial objects_: For example, you can pass an object in a PUT which changes the author but alters no other fields. - We therefore only want to check the content for emptiness (and verify using the filter whether that is allowable) when the property has been passed back.
- Currently, the only path through which
check_is_comment_content_allowed()can be called is during the create_item method, which ensurescomment_contentis initialized to''if not present — this should not result in any change to existing behavior on comment creation or updates.
Trac ticket: [](https://core.trac.wordpress.org/ticket/64049)
#5
@
6 weeks ago
- Description modified (diff)
- Keywords has-patch has-unit-tests removed
@TimothyBlynJacobs @ryan I've refreshed @adamsilverstein's patch here and added a test to validate that content updates respect the filter value. Thoughts?
This was proposed as part of the block editor commenting initiative, but to me it feels like a good inconsistency to fix regardless of the ongoing work on that feature.
Note from @rmccue, one concept in this endpoint (and the API generally) is that we should support sending partial documents for updates -- if the content is empty that could indicate "no update". In other words, an empty string may signal different intent than an unset key