Ticket #38855: 38855.diff
File 38855.diff, 1.8 KB (added by , 9 years ago) |
---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
366 366 * @return WP_Error|bool True if the request has access to create items, error object otherwise. 367 367 */ 368 368 public function create_item_permissions_check( $request ) { 369 370 369 if ( ! is_user_logged_in() && get_option( 'comment_registration' ) ) { 371 370 return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) ); 372 371 } 373 372 373 /** 374 * Filters whether comments can be created without authentication. 375 * 376 * Enables creating comments for anonymous users. 377 * 378 * @since 4.7.0 379 * 380 * @param bool $allow_anonymous Whether to allow anonymous 381 * comments to be created. 382 * Default `false`. 383 * @param WP_REST_Request $request Request used to generate the 384 * response. 385 */ 386 $allow_anonymous = apply_filters( 'rest_allow_anonymous_comments', false, $request ); 387 if ( ! is_user_logged_in() && false === $allow_anonymous ) { 388 return new WP_Error( 'rest_comment_login_required', __( 'Sorry, you must be logged in to comment.' ), array( 'status' => 401 ) ); 389 } 390 374 391 // Limit who can set comment `author`, `author_ip` or `status` to anything other than the default. 375 392 if ( isset( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( 'moderate_comments' ) ) { 376 393 /* translators: %s: request parameter */