#44639 closed defect (bug) (wontfix)
Allow multiple comment types on class-wp-rest-comments-controller.php
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | REST API | Keywords: | close |
Focuses: | Cc: |
Description
I want to create an entry/comment for the Liveblogging Plugin https://de.wordpress.org/plugins/liveblog/ with the rest api.
The Liveblog Plugin uses comments with a special comment_type liveblog
and a special comment_approved liveblog
The rest API WP_REST_Comments_Controller::create_item()
has a hardcoded check for a comment type
// Do not allow comments to be created with a non-default type. if ( ! empty( $request['type'] ) && 'comment' !== $request['type'] ) { return new WP_Error( 'rest_invalid_comment_type', __( 'Cannot create a comment with that type.' ), array( 'status' => 400 ) ); }
- Why does the comment endpoint except
type
if it only accepts a single value? - Can you at least add a filter here, maybe like:
$allowed_comment_types = apply_filter( 'fancy_allowed_comment_types_filter_name', [ 'comment' ] ); // Do not allow comments to be created with a non-default type. if ( ! empty( $request['type'] ) && ! in_array( $request['type'], allowed_comment_types ) ) { return new WP_Error( 'rest_invalid_comment_type', __( 'Cannot create a comment with that type.' ), array( 'status' => 400 ) ); }
Extending the whole class, while copying a single function of nearly 150 lines to change a single if statement seems a bit over the top.
Change History (4)
#2
@
5 years ago
- Keywords close added
I agree with @swissspidy here, as the comments controller in the REST API only deals with actual comments. Comment types are generally not well-scoped at the moment, and until a bigger initiative starts going that direction, implementing a separate controller in that specific plugin appears to be the most solid solution.
#3
@
5 years ago
- Resolution set to wontfix
- Status changed from new to closed
In that case I will try to make a ticket on the Live Blog plugin with a link here.
Related: #41775.
See also https://github.com/WP-API/WP-API/issues/2012
If it doesn't already do so, the liveblog plugin should most likely register a new endpoint dedicated to its specific comment format. Just like pingbacks hold different data than regular comments, I imagine liveblog comments to be quite different as well.