WordPress.org

Make WordPress Core

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

File fix-http-status-in-comments.3.patch, 3.6 KB (added by solarissmoke, 8 years ago)
  • wp-comments-post.php

     
    2323
    2424if ( empty($post->comment_status) ) {
    2525        do_action('comment_id_not_found', $comment_post_ID);
     26        wp_die( __('Sorry, the item you are trying to comment on does not exist.'), '', array('response' => 400) );
    2627        exit;
    2728}
    2829
     
    3334
    3435if ( !comments_open($comment_post_ID) ) {
    3536        do_action('comment_closed', $comment_post_ID);
    36         wp_die( __('Sorry, comments are closed for this item.') );
     37        wp_die( __('Sorry, comments are closed for this item.'), '', array('response' => 403) );
    3738} elseif ( 'trash' == $status ) {
    3839        do_action('comment_on_trash', $comment_post_ID);
     40        wp_die( __('Sorry, comments are closed for this item.'), '', array('response' => 403) );
    3941        exit;
    4042} elseif ( !$status_obj->public ) {
    4143        do_action('comment_on_draft', $comment_post_ID);
     44        wp_die( __('Sorry, comments are closed for this item.'), '', array('response' => 403) );
    4245        exit;
    4346} elseif ( post_password_required($comment_post_ID) ) {
    4447        do_action('comment_on_password_protected', $comment_post_ID);
     48        wp_die( __('Sorry, the item you are trying to comment on is password-protected.'), '', array('response' => 403) );
    4549        exit;
    4650} else {
    4751        do_action('pre_comment_on_post', $comment_post_ID);
     
    6872        }
    6973} else {
    7074        if ( get_option('comment_registration') || 'private' == $status )
    71                 wp_die( __('Sorry, you must be logged in to post a comment.') );
     75                wp_die( __('Sorry, you must be logged in to post a comment.'), '', array('response' => 403) );
    7276}
    7377
    7478$comment_type = '';
    7579
    7680if ( get_option('require_name_email') && !$user->ID ) {
    7781        if ( 6 > strlen($comment_author_email) || '' == $comment_author )
    78                 wp_die( __('Error: please fill the required fields (name, email).') );
     82                wp_die( __('Error: please fill the required fields (name, email).'), '', array('response' => 400) );
    7983        elseif ( !is_email($comment_author_email))
    80                 wp_die( __('Error: please enter a valid email address.') );
     84                wp_die( __('Error: please enter a valid email address.'), '', array('response' => 400) );
    8185}
    8286
    83 if ( '' == $comment_content )
    84         wp_die( __('Error: please type a comment.') );
     87if ( '' == $comment_content ) {
     88        // User did not submit anything, bounce back to post.
     89        $comment = NULL;
     90        $location = empty($_POST['redirect_to']) ? get_permalink($comment_post_ID) : $_POST['redirect_to'];
     91        $location = apply_filters('comment_post_redirect', $location, $comment);
     92        wp_redirect($location);
     93        exit;
     94}
    8595
    8696$comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
    8797
  • wp-includes/comment.php

     
    557557                if ( defined('DOING_AJAX') )
    558558                        die( __('Duplicate comment detected; it looks as though you’ve already said that!') );
    559559
    560                 wp_die( __('Duplicate comment detected; it looks as though you’ve already said that!') );
     560                wp_die( __('Duplicate comment detected; it looks as though you’ve already said that!'), '', array('response' => 400) );
    561561        }
    562562
    563563        do_action( 'check_comment_flood', $comment_author_IP, $comment_author_email, $comment_date_gmt );
     
    617617                        if ( defined('DOING_AJAX') )
    618618                                die( __('You are posting comments too quickly.  Slow down.') );
    619619
    620                         wp_die( __('You are posting comments too quickly.  Slow down.'), '', array('response' => 403) );
     620                        wp_die( __('You are posting comments too quickly.  Slow down.'), '', array('response' => 400) );
    621621                }
    622622        }
    623623}