- Timestamp:
- 10/24/2020 10:44:38 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
r49299 r49303 588 588 $prepared_comment['comment_type'] = 'comment'; 589 589 590 /*591 * Do not allow a comment to be created with missing or empty592 * comment_content. See wp_handle_comment_submission().593 */ 594 if ( empty( $prepared_comment['comment_content']) ) {590 if ( ! isset( $prepared_comment['comment_content'] ) ) { 591 $prepared_comment['comment_content'] = ''; 592 } 593 594 if ( ! $this->check_is_comment_content_allowed( $prepared_comment ) ) { 595 595 return new WP_Error( 596 596 'rest_comment_content_invalid', … … 1281 1281 */ 1282 1282 if ( isset( $request['content'] ) && is_string( $request['content'] ) ) { 1283 $prepared_comment['comment_content'] = $request['content'];1283 $prepared_comment['comment_content'] = trim( $request['content'] ); 1284 1284 } elseif ( isset( $request['content']['raw'] ) && is_string( $request['content']['raw'] ) ) { 1285 $prepared_comment['comment_content'] = $request['content']['raw'];1285 $prepared_comment['comment_content'] = trim( $request['content']['raw'] ); 1286 1286 } 1287 1287 … … 1867 1867 return $email; 1868 1868 } 1869 1870 /** 1871 * If empty comments are not allowed, checks if the provided comment content is not empty. 1872 * 1873 * @since 5.6.0 1874 * 1875 * @param array $prepared_comment The prepared comment data. 1876 * @return bool True if the content is allowed, false otherwise. 1877 */ 1878 protected function check_is_comment_content_allowed( $prepared_comment ) { 1879 $check = wp_parse_args( 1880 $prepared_comment, 1881 array( 1882 'comment_post_ID' => 0, 1883 'comment_parent' => 0, 1884 'user_ID' => 0, 1885 'comment_author' => null, 1886 'comment_author_email' => null, 1887 'comment_author_url' => null, 1888 ) 1889 ); 1890 1891 /** This filter is documented in wp-includes/comment.php */ 1892 $allow_empty = apply_filters( 'allow_empty_comment', false, $check ); 1893 1894 if ( $allow_empty ) { 1895 return true; 1896 } 1897 1898 /* 1899 * Do not allow a comment to be created with missing or empty 1900 * comment_content. See wp_handle_comment_submission(). 1901 */ 1902 return '' !== $check['comment_content']; 1903 } 1869 1904 }
Note: See TracChangeset
for help on using the changeset viewer.