WordPress.org

Make WordPress Core

Ticket #10377: 10377.3.patch

File 10377.3.patch, 3.0 KB (added by rachelbaker, 6 years ago)
  • src/wp-comments-post.php

     
    130130        wp_die( __( '<strong>ERROR</strong>: please type a comment.' ), 200 );
    131131}
    132132
     133$comment_content_length = wp_get_comment_content_max_length();
     134if ( $comment_content_length < strlen( $comment_content ) ) {
     135        wp_die( __( '<strong>ERROR</strong>: your comment is too large.' ), 200 );
     136}
     137
    133138$comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
    134139
    135140$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
  • src/wp-includes/comment-functions.php

     
    853853}
    854854
    855855/**
     856 * Calculate the maximum length of the comment_content column of the comments table.
     857 *
     858 * @since 4.4.0
     859 *
     860 * @global wpdb $wpdb WordPress database abstraction object.
     861 *
     862 * @return int Maximum comment_content character length.
     863 */
     864function wp_get_comment_content_max_length() {
     865        global $wpdb;
     866
     867        $col_length = $wpdb->get_col_length( $wpdb->comments, 'comment_content' );
     868
     869        if ( ! is_array( $col_length ) && (int) $col_length > 0 ) {
     870                $content_length = (int) $col_length;
     871        } elseif ( is_array( $col_length ) && isset( $col_length['length'] ) && (int) $col_length > 0 ) {
     872                $content_length = (int) $col_length['length'];
     873        } else {
     874                $content_length = 65535;
     875        }
     876
     877        return intval( $content_length ) - 10;
     878}
     879
     880/**
    856881 * Does comment contain blacklisted characters or words.
    857882 *
    858883 * @since 1.5.0
  • src/wp-includes/comment-template.php

     
    19211921        $fields = apply_filters( 'comment_form_default_fields', $fields );
    19221922        $defaults = array(
    19231923                'fields'               => $fields,
    1924                 'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required="required"></textarea></p>',
     1924                'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="' . wp_get_comment_content_max_length() . '" aria-required="true" required="required"></textarea></p>',
    19251925                /** This filter is documented in wp-includes/link-template.php */
    19261926                'must_log_in'          => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
    19271927                /** This filter is documented in wp-includes/link-template.php */