Changeset 39337
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
r39327 r39337 459 459 } 460 460 461 $prepared_comment = $this->prepare_item_for_database( $request );462 463 if ( is_wp_error( $prepared_comment ) ) {464 return $prepared_comment;465 }466 467 461 // Do not allow comments to be created with a non-default type. 468 462 if ( ! empty( $request['type'] ) && 'comment' !== $request['type'] ) { 469 463 return new WP_Error( 'rest_invalid_comment_type', __( 'Cannot create a comment with that type.' ), array( 'status' => 400 ) ); 470 464 } 465 466 $prepared_comment = $this->prepare_item_for_database( $request ); 467 if ( is_wp_error( $prepared_comment ) ) { 468 return $prepared_comment; 469 } 470 471 $prepared_comment['comment_type'] = ''; 471 472 472 473 /* … … 1088 1089 } elseif ( $request->get_header( 'user_agent' ) ) { 1089 1090 $prepared_comment['comment_agent'] = $request->get_header( 'user_agent' ); 1090 }1091 1092 if ( isset( $request['type'] ) ) {1093 // Comment type "comment" needs to be created as an empty string.1094 $prepared_comment['comment_type'] = 'comment' === $request['type'] ? '' : $request['type'];1095 1091 } 1096 1092 … … 1245 1241 'type' => 'string', 1246 1242 'context' => array( 'view', 'edit', 'embed' ), 1247 'default' => 'comment', 1248 'arg_options' => array( 1249 'sanitize_callback' => 'sanitize_key', 1250 ), 1243 'readonly' => true, 1251 1244 ), 1252 1245 ), -
trunk/tests/phpunit/tests/rest-api/rest-comments-controller.php
r39327 r39337 2331 2331 $this->assertArrayHasKey( 'status', $properties ); 2332 2332 $this->assertArrayHasKey( 'type', $properties ); 2333 $this->assertEquals( 'comment', $properties['type']['default'] );2334 2333 2335 2334 $this->assertEquals( 0, $properties['parent']['default'] ); 2336 2335 $this->assertEquals( 0, $properties['post']['default'] ); 2336 2337 $this->assertEquals( true, $properties['link']['readonly'] ); 2338 $this->assertEquals( true, $properties['type']['readonly'] ); 2337 2339 } 2338 2340
Note: See TracChangeset
for help on using the changeset viewer.