[wp-trac] [WordPress Trac] #41775: REST API: Add filter to allow creation of custom comment type

WordPress Trac noreply at wordpress.org
Fri Sep 1 11:31:10 UTC 2017


#41775: REST API: Add filter to allow creation of custom comment type
-------------------------+-----------------------------
 Reporter:  langan       |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  REST API     |    Version:
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 When trying to create a comment using the REST API that has a different
 comment type I get the following error.

 ''Cannot create a comment with that type.''

 Looks like it is coming from this code.

 {{{#!php
 // 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 ) );
 }
 }}}

 Looks like this was added to fix defect #38820

 Would it be possible to change this check to use a filter that will allow
 some comment types?  Something like this

 {{{#!php
 if ( ! empty( $request['type'] ) && false === in_array($request['type'],
 apply_filters( 'rest_allow_comment_types', array('comment'), $request ) )
 {
         return new WP_Error( 'rest_invalid_comment_type', __( 'Cannot
 create a comment with that type.' ), array( 'status' => 400 ) );
 }
 }}}

 We could then use the same filter in the update_item call as well I've
 attached a diff with a first draft idea

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41775>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list