Changeset 39446 for branches/4.7/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
- Timestamp:
- 12/02/2016 10:45:06 PM (8 years ago)
- Location:
- branches/4.7
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.7
-
branches/4.7/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
r39349 r39446 509 509 // Honor the discussion setting that requires a name and email address of the comment author. 510 510 if ( get_option( 'require_name_email' ) ) { 511 if ( ! isset( $prepared_comment['comment_author'] ) && ! isset( $prepared_comment['comment_author_email'] ) ) {511 if ( empty( $prepared_comment['comment_author'] ) || empty( $prepared_comment['comment_author_email'] ) ) { 512 512 return new WP_Error( 'rest_comment_author_data_required', __( 'Creating a comment requires valid author name and email values.' ), array( 'status' => 400 ) ); 513 }514 515 if ( ! isset( $prepared_comment['comment_author'] ) ) {516 return new WP_Error( 'rest_comment_author_required', __( 'Creating a comment requires a valid author name.' ), array( 'status' => 400 ) );517 }518 519 if ( ! isset( $prepared_comment['comment_author_email'] ) ) {520 return new WP_Error( 'rest_comment_author_email_required', __( 'Creating a comment requires a valid author email.' ), array( 'status' => 400 ) );521 513 } 522 514 } … … 1156 1148 'format' => 'email', 1157 1149 'context' => array( 'edit' ), 1150 'arg_options' => array( 1151 'sanitize_callback' => array( $this, 'check_comment_author_email' ), 1152 'validate_callback' => null, // skip built-in validation of 'email'. 1153 ), 1158 1154 ), 1159 1155 'author_ip' => array( … … 1582 1578 return current_user_can( 'edit_comment', $comment->comment_ID ); 1583 1579 } 1580 1581 /** 1582 * Checks a comment author email for validity. 1583 * 1584 * Accepts either a valid email address or empty string as a valid comment 1585 * author email address. Setting the comment author email to an empty 1586 * string is allowed when a comment is being updated. 1587 * 1588 * @since 4.7.0 1589 * 1590 * @param string $value Author email value submitted. 1591 * @param WP_REST_Request $request Full details about the request. 1592 * @param string $param The parameter name. 1593 * @return WP_Error|string The sanitized email address, if valid, 1594 * otherwise an error. 1595 */ 1596 public function check_comment_author_email( $value, $request, $param ) { 1597 $email = (string) $value; 1598 if ( empty( $email ) ) { 1599 return $email; 1600 } 1601 1602 $check_email = rest_validate_request_arg( $email, $request, $param ); 1603 if ( is_wp_error( $check_email ) ) { 1604 return $check_email; 1605 } 1606 1607 return $email; 1608 } 1584 1609 }
Note: See TracChangeset
for help on using the changeset viewer.