- Timestamp:
- 11/18/2016 09:12:03 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
r39298 r39302 372 372 } 373 373 374 // Limit who can set comment `author` or `status` to anything other than the default.374 // Limit who can set comment `author`, `author_ip` or `status` to anything other than the default. 375 375 if ( isset( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( 'moderate_comments' ) ) { 376 376 /* translators: %s: request parameter */ 377 377 return new WP_Error( 'rest_comment_invalid_author', sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author' ), array( 'status' => rest_authorization_required_code() ) ); 378 } 379 380 if ( isset( $request['author_ip'] ) && ! current_user_can( 'moderate_comments' ) ) { 381 if ( empty( $_SERVER['REMOTE_ADDR'] ) || $request['author_ip'] !== $_SERVER['REMOTE_ADDR'] ) { 382 return new WP_Error( 'rest_comment_invalid_author_ip', __( 'Sorry, you are not allowed to set author_ip for comments.' ), array( 'status' => rest_authorization_required_code() ) ); 383 } 378 384 } 379 385 … … 1042 1048 } 1043 1049 1044 if ( isset( $request['author_ip'] ) ) {1050 if ( isset( $request['author_ip'] ) && current_user_can( 'moderate_comments' ) ) { 1045 1051 $prepared_comment['comment_author_IP'] = $request['author_ip']; 1052 } elseif ( ! empty( $_SERVER['REMOTE_ADDR'] ) && rest_is_ip_address( $_SERVER['REMOTE_ADDR'] ) ) { 1053 $prepared_comment['comment_author_IP'] = $_SERVER['REMOTE_ADDR']; 1054 } else { 1055 $prepared_comment['comment_author_IP'] = '127.0.0.1'; 1046 1056 } 1047 1057 … … 1120 1130 'format' => 'ip', 1121 1131 'context' => array( 'edit' ), 1122 'default' => '127.0.0.1',1123 1132 ), 1124 1133 'author_name' => array(
Note: See TracChangeset
for help on using the changeset viewer.