WordPress.org

Make WordPress Core

Ticket #11286: fix-http-status-in-comments.2.patch

File fix-http-status-in-comments.2.patch, 3.6 KB (added by miqrogroove, 12 years ago)

Dropkick blank commenters back to the post page. Prefer 400 status.

  • wp-comments-post.php

     
    2323
    2424if ( empty($status->comment_status) ) {
    2525        do_action('comment_id_not_found', $comment_post_ID);
    26         exit;
     26        wp_die( __('Error: Request not understood. Please go back and try again.'), '', array('response' => 400) );
    2727} elseif ( !comments_open($comment_post_ID) ) {
    2828        do_action('comment_closed', $comment_post_ID);
    29         wp_die( __('Sorry, comments are closed for this item.') );
     29        wp_die( __('Sorry, comments are closed for this item.'), '', array('response' => 403) );
    3030} elseif ( in_array($status->post_status, array('draft', 'future', 'pending') ) ) {
    3131        do_action('comment_on_draft', $comment_post_ID);
    32         exit;
     32        wp_die( __('Sorry, comments are closed for this item.'), '', array('response' => 403) );
    3333} elseif ( 'trash' == $status->post_status ) {
    3434        do_action('comment_on_trash', $comment_post_ID);
    35         exit;
     35        wp_die( __('Sorry, comments are closed for this item.'), '', array('response' => 403) );
    3636} elseif ( post_password_required($comment_post_ID) ) {
    3737        do_action('comment_on_password_protected', $comment_post_ID);
    38         exit;
     38        wp_die( __('Sorry, you must enter the password for this item.'), '', array('response' => 403) );
    3939} else {
    4040        do_action('pre_comment_on_post', $comment_post_ID);
    4141}
     
    6161        }
    6262} else {
    6363        if ( get_option('comment_registration') || 'private' == $status->post_status )
    64                 wp_die( __('Sorry, you must be logged in to post a comment.') );
     64                wp_die( __('Sorry, you must be logged in to post a comment.'), '', array('response' => 403) );
    6565}
    6666
    6767$comment_type = '';
    6868
    6969if ( get_option('require_name_email') && !$user->ID ) {
    7070        if ( 6 > strlen($comment_author_email) || '' == $comment_author )
    71                 wp_die( __('Error: please fill the required fields (name, email).') );
     71                wp_die( __('Error: please fill the required fields (name, email).'), '', array('response' => 400) );
    7272        elseif ( !is_email($comment_author_email))
    73                 wp_die( __('Error: please enter a valid email address.') );
     73                wp_die( __('Error: please enter a valid email address.'), '', array('response' => 400) );
    7474}
    7575
    76 if ( '' == $comment_content )
    77         wp_die( __('Error: please type a comment.') );
     76if ( '' == $comment_content ) {
     77        // User did not submit anything, bounce back to post.
     78        $comment = NULL;
     79        $location = empty($_POST['redirect_to']) ? get_permalink($comment_post_ID) : $_POST['redirect_to'];
     80        $location = apply_filters('comment_post_redirect', $location, $comment);
     81        wp_redirect($location);
     82        exit;
     83}
    7884
    7985$comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
    8086
  • wp-includes/comment.php

     
    550550                if ( defined('DOING_AJAX') )
    551551                        die( __('Duplicate comment detected; it looks as though you’ve already said that!') );
    552552
    553                 wp_die( __('Duplicate comment detected; it looks as though you’ve already said that!') );
     553                wp_die( __('Duplicate comment detected; it looks as though you’ve already said that!'), '', array('response' => 400) );
    554554        }
    555555
    556556        do_action( 'check_comment_flood', $comment_author_IP, $comment_author_email, $comment_date_gmt );
     
    610610                        if ( defined('DOING_AJAX') )
    611611                                die( __('You are posting comments too quickly.  Slow down.') );
    612612
    613                         wp_die( __('You are posting comments too quickly.  Slow down.'), '', array('response' => 403) );
     613                        wp_die( __('You are posting comments too quickly.  Slow down.'), '', array('response' => 400) );
    614614                }
    615615        }
    616616}