WordPress.org

Make WordPress Core

Ticket #47393: 47393.0.diff

File 47393.0.diff, 3.2 KB (added by westonruter, 2 years ago)

Use 400 status instead of 200 status for invalid comment form submission responses to align with REST API: https://github.com/westonruter/wordpress-develop/pull/2

  • src/wp-includes/comment.php

    diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php
    index 6c2f332893..70c64e19b0 100644
    a b function wp_check_comment_data_max_lengths( $comment_data ) { 
    12111211        $max_lengths = wp_get_comment_fields_max_lengths();
    12121212
    12131213        if ( isset( $comment_data['comment_author'] ) && mb_strlen( $comment_data['comment_author'], '8bit' ) > $max_lengths['comment_author'] ) {
    1214                 return new WP_Error( 'comment_author_column_length', __( '<strong>ERROR</strong>: your name is too long.' ), 200 );
     1214                return new WP_Error( 'comment_author_column_length', __( '<strong>ERROR</strong>: your name is too long.' ), 400 );
    12151215        }
    12161216
    12171217        if ( isset( $comment_data['comment_author_email'] ) && strlen( $comment_data['comment_author_email'] ) > $max_lengths['comment_author_email'] ) {
    1218                 return new WP_Error( 'comment_author_email_column_length', __( '<strong>ERROR</strong>: your email address is too long.' ), 200 );
     1218                return new WP_Error( 'comment_author_email_column_length', __( '<strong>ERROR</strong>: your email address is too long.' ), 400 );
    12191219        }
    12201220
    12211221        if ( isset( $comment_data['comment_author_url'] ) && strlen( $comment_data['comment_author_url'] ) > $max_lengths['comment_author_url'] ) {
    1222                 return new WP_Error( 'comment_author_url_column_length', __( '<strong>ERROR</strong>: your url is too long.' ), 200 );
     1222                return new WP_Error( 'comment_author_url_column_length', __( '<strong>ERROR</strong>: your url is too long.' ), 400 );
    12231223        }
    12241224
    12251225        if ( isset( $comment_data['comment_content'] ) && mb_strlen( $comment_data['comment_content'], '8bit' ) > $max_lengths['comment_content'] ) {
    1226                 return new WP_Error( 'comment_content_column_length', __( '<strong>ERROR</strong>: your comment is too long.' ), 200 );
     1226                return new WP_Error( 'comment_content_column_length', __( '<strong>ERROR</strong>: your comment is too long.' ), 400 );
    12271227        }
    12281228
    12291229        return true;
    function wp_handle_comment_submission( $comment_data ) { 
    32803280
    32813281        if ( get_option( 'require_name_email' ) && ! $user->exists() ) {
    32823282                if ( '' == $comment_author_email || '' == $comment_author ) {
    3283                         return new WP_Error( 'require_name_email', __( '<strong>ERROR</strong>: please fill the required fields (name, email).' ), 200 );
     3283                        return new WP_Error( 'require_name_email', __( '<strong>ERROR</strong>: please fill the required fields (name, email).' ), 400 );
    32843284                } elseif ( ! is_email( $comment_author_email ) ) {
    3285                         return new WP_Error( 'require_valid_email', __( '<strong>ERROR</strong>: please enter a valid email address.' ), 200 );
     3285                        return new WP_Error( 'require_valid_email', __( '<strong>ERROR</strong>: please enter a valid email address.' ), 400 );
    32863286                }
    32873287        }
    32883288
    function wp_handle_comment_submission( $comment_data ) { 
    33073307         */
    33083308        $allow_empty_comment = apply_filters( 'allow_empty_comment', false, $commentdata );
    33093309        if ( '' === $comment_content && ! $allow_empty_comment ) {
    3310                 return new WP_Error( 'require_valid_comment', __( '<strong>ERROR</strong>: please type a comment.' ), 200 );
     3310                return new WP_Error( 'require_valid_comment', __( '<strong>ERROR</strong>: please type a comment.' ), 400 );
    33113311        }
    33123312
    33133313        $check_max_lengths = wp_check_comment_data_max_lengths( $commentdata );