Skip to content

Commit fb8588f

Browse files
committed
Comments: Use proper HTTP response codes for validation errors.
props miqrogroove, solarissmoke, mackensen. fixes WordPress#11286. git-svn-id: https://develop.svn.wordpress.org/trunk@30579 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 17cefe0 commit fb8588f

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

src/wp-comments-post.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
* @param int $comment_post_ID Post ID.
4848
*/
4949
do_action( 'comment_closed', $comment_post_ID );
50-
wp_die( __('Sorry, comments are closed for this item.') );
50+
wp_die( __( 'Sorry, comments are closed for this item.' ), 403 );
5151
} elseif ( 'trash' == $status ) {
5252
/**
5353
* Fires when a comment is attempted on a trashed post.
@@ -111,21 +111,24 @@
111111
}
112112
}
113113
} else {
114-
if ( get_option('comment_registration') || 'private' == $status )
115-
wp_die( __('Sorry, you must be logged in to post a comment.') );
114+
if ( get_option( 'comment_registration' ) || 'private' == $status ) {
115+
wp_die( __( 'Sorry, you must be logged in to post a comment.' ), 403 );
116+
}
116117
}
117118

118119
$comment_type = '';
119120

120121
if ( get_option('require_name_email') && !$user->exists() ) {
121-
if ( 6 > strlen($comment_author_email) || '' == $comment_author )
122-
wp_die( __('<strong>ERROR</strong>: please fill the required fields (name, email).') );
123-
elseif ( !is_email($comment_author_email))
124-
wp_die( __('<strong>ERROR</strong>: please enter a valid email address.') );
122+
if ( 6 > strlen( $comment_author_email ) || '' == $comment_author ) {
123+
wp_die( __( '<strong>ERROR</strong>: please fill the required fields (name, email).' ), 200 );
124+
} else if ( ! is_email( $comment_author_email ) ) {
125+
wp_die( __( '<strong>ERROR</strong>: please enter a valid email address.' ), 200 );
126+
}
125127
}
126128

127-
if ( '' == $comment_content )
128-
wp_die( __('<strong>ERROR</strong>: please type a comment.') );
129+
if ( '' == $comment_content ) {
130+
wp_die( __( '<strong>ERROR</strong>: please type a comment.' ), 200 );
131+
}
129132

130133
$comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
131134

src/wp-includes/comment.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ function wp_allow_comment( $commentdata ) {
11311131
if ( defined( 'DOING_AJAX' ) ) {
11321132
die( __('Duplicate comment detected; it looks as though you&#8217;ve already said that!') );
11331133
}
1134-
wp_die( __('Duplicate comment detected; it looks as though you&#8217;ve already said that!') );
1134+
wp_die( __( 'Duplicate comment detected; it looks as though you&#8217;ve already said that!' ), 409 );
11351135
}
11361136

11371137
/**
@@ -1249,7 +1249,7 @@ function check_comment_flood_db( $ip, $email, $date ) {
12491249
if ( defined('DOING_AJAX') )
12501250
die( __('You are posting comments too quickly. Slow down.') );
12511251

1252-
wp_die( __('You are posting comments too quickly. Slow down.'), '', array('response' => 403) );
1252+
wp_die( __( 'You are posting comments too quickly. Slow down.' ), 429 );
12531253
}
12541254
}
12551255
}

0 commit comments

Comments
 (0)