[wp-trac] [WordPress Trac] #39578: Enhancement for rest api comment controller create_item method to check for WP error

WordPress Trac noreply at wordpress.org
Fri Jan 13 20:36:38 UTC 2017


#39578: Enhancement for rest api comment controller create_item method to check for
WP error
-------------------------+-----------------------------
 Reporter:  dspilka      |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  REST API     |    Version:  4.7.1
 Severity:  normal       |   Keywords:
  Focuses:  rest-api     |
-------------------------+-----------------------------
 In the WP_REST_Posts_Controller class, the create_item method calls the
 prepare_item_for_database method and checks its response for a WP error
 object.

 {{{#!php
 <?php
     $prepared_post = $this->prepare_item_for_database( $request );

      if ( is_wp_error( $prepared_post ) ) {
           return $prepared_post;
      }
 }}}

 This allows for further filtering and custom validation via the
 rest_pre_insert_{$this->post_type} filter and for returning a WP Error if
 needed to stop the request and return messaging.

 I'd like to propose similar in the WP_REST_Comments_Controller class.
 Right now when the create_item method applys the rest_pre_insert_comment
 filter, it doesn't check for a WP Error response.

 {{{#!php
 <?php
     $prepared_comment = apply_filters( 'rest_pre_insert_comment',
 $prepared_comment, $request );
     $comment_id = wp_insert_comment( $prepared_comment );
 }}}

 I'd like to propose checking for a WP Error.

 {{{#!php
 <?php
         $prepared_comment = apply_filters( 'rest_pre_insert_comment',
 $prepared_comment, $request );

         if ( is_wp_error( $prepared_comment ) ) {
                 return $prepared_comment;
         }

         $comment_id = wp_insert_comment( $prepared_comment );
 }}}

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


More information about the wp-trac mailing list