WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#44639 closed defect (bug) (wontfix)

Allow multiple comment types on class-wp-rest-comments-controller.php

Reported by: apermo 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 ) );
}
  1. Why does the comment endpoint except type if it only accepts a single value?
  2. 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)

#1 @swissspidy
2 years ago

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.

#2 @flixos90
2 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 @apermo
2 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.

https://github.com/Automattic/liveblog/issues/518

Last edited 2 years ago by apermo (previous) (diff)

#4 @netweb
2 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.