Ticket #18630: 18630.diff
File 18630.diff, 4.9 KB (added by , 10 years ago) |
---|
-
wp-includes/comment.php
1095 1095 * 1096 1096 * @global wpdb $wpdb WordPress database abstraction object. 1097 1097 * 1098 * @param array $commentdata Contains information on the comment 1099 * @return mixed Signifies the approval status (0|1|'spam') 1098 * @param array $commentdata Contains information on the comment. 1099 * @param bool $wp_error Whether to return a WP_Error object instead of dying if there is a failure. Default is false. 1100 * @return mixed Signifies the approval status (0|1|'spam') on success, optionally WP_Error on failure. 1100 1101 */ 1101 function wp_allow_comment( $commentdata ) {1102 global $wpdb ;1102 function wp_allow_comment( $commentdata, $wp_error = false ) { 1103 global $wpdb, $_comment_flood_wp_error_flag, $_comment_flood_wp_error_obj; 1103 1104 1104 1105 // Simple duplicate check 1105 1106 // expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content) … … 1128 1129 * @param array $commentdata Comment data. 1129 1130 */ 1130 1131 do_action( 'comment_duplicate_trigger', $commentdata ); 1131 if ( defined( 'DOING_AJAX' ) ) { 1132 die( __('Duplicate comment detected; it looks as though you’ve already said that!') ); 1132 $msg = __( 'Duplicate comment detected; it looks as though you’ve already said that!' ); 1133 if ( $wp_error ) { 1134 return new WP_Error( 'duplicate_comment', $msg ); 1135 } elseif ( defined( 'DOING_AJAX' ) ) { 1136 die( $msg ); 1137 } else { 1138 wp_die( $msg ); 1133 1139 } 1134 wp_die( __('Duplicate comment detected; it looks as though you’ve already said that!') );1135 1140 } 1136 1141 1142 $old_cf_error_flag = $_comment_flood_wp_error_flag; 1143 $_comment_flood_wp_error_flag = $wp_error; 1144 1137 1145 /** 1138 1146 * Fires immediately before a comment is marked approved. 1139 1147 * … … 1152 1160 $commentdata['comment_date_gmt'] 1153 1161 ); 1154 1162 1163 $_comment_flood_wp_error_flag = $old_cf_error_flag; 1164 1165 if ( $wp_error && is_wp_error( $_comment_flood_wp_error_obj ) ) { 1166 return $_comment_flood_wp_error_obj; 1167 } 1168 1155 1169 if ( ! empty( $commentdata['user_id'] ) ) { 1156 1170 $user = get_userdata( $commentdata['user_id'] ); 1157 1171 $post_author = $wpdb->get_var( $wpdb->prepare( … … 1203 1217 return $approved; 1204 1218 } 1205 1219 1220 // Comment flood detection error handling 1221 1206 1222 /** 1223 * Whether check_comment_flood_db() should die or return a WP_Error object if a comment flood is detected. 1224 * @global bool $_comment_flood_wp_error_flag 1225 * 1226 * The WP_Error object returned by check_comment_flood_db(). 1227 * @global WP_Error $_comment_flood_wp_error_obj 1228 */ 1229 global $_comment_flood_wp_error_flag, $_comment_flood_wp_error_obj; 1230 $_comment_flood_wp_error_flag = false; 1231 1232 /** 1207 1233 * Check whether comment flooding is occurring. 1208 1234 * 1209 1235 * Won't run, if current user can manage options, so to not block … … 1218 1244 * @param string $date MySQL time string. 1219 1245 */ 1220 1246 function check_comment_flood_db( $ip, $email, $date ) { 1221 global $wpdb; 1247 global $wpdb, $_comment_flood_wp_error_flag, $_comment_flood_wp_error_obj; 1248 if ( $_comment_flood_wp_error_flag ) { 1249 $_comment_flood_wp_error_obj = null; 1250 } 1222 1251 if ( current_user_can( 'manage_options' ) ) 1223 1252 return; // don't throttle admins 1224 1253 $hour_ago = gmdate( 'Y-m-d H:i:s', time() - HOUR_IN_SECONDS ); … … 1246 1275 */ 1247 1276 do_action( 'comment_flood_trigger', $time_lastcomment, $time_newcomment ); 1248 1277 1249 if ( defined('DOING_AJAX') ) 1250 die( __('You are posting comments too quickly. Slow down.') ); 1251 1252 wp_die( __('You are posting comments too quickly. Slow down.'), '', array('response' => 403) ); 1278 $msg = __('You are posting comments too quickly. Slow down.'); 1279 if ( $_comment_flood_wp_error_flag ) { 1280 $_comment_flood_wp_error_obj = new WP_Error( 'comment_flood', $msg ); 1281 return; 1282 } elseif ( defined( 'DOING_AJAX' ) ) { 1283 die( $msg ); 1284 } else { 1285 wp_die( $msg, '', array('response' => 403) ); 1286 } 1253 1287 } 1254 1288 } 1255 1289 } … … 2041 2075 * 2042 2076 * @since 1.5.0 2043 2077 * @param array $commentdata Contains information on the comment. 2044 * @return int|bool The ID of the comment on success, false on failure. 2078 * @param bool $wp_error Whether to return a WP_Error object if there is a failure. Default is false. 2079 * @return int|bool|WP_Error The ID of the comment on success, false or WP_Error on failure. 2045 2080 */ 2046 function wp_new_comment( $commentdata ) {2081 function wp_new_comment( $commentdata, $wp_error = false ) { 2047 2082 if ( isset( $commentdata['user_ID'] ) ) { 2048 2083 $commentdata['user_id'] = $commentdata['user_ID'] = (int) $commentdata['user_ID']; 2049 2084 } … … 2078 2113 2079 2114 $commentdata = wp_filter_comment($commentdata); 2080 2115 2081 $commentdata['comment_approved'] = wp_allow_comment($commentdata); 2116 $approved = wp_allow_comment( $commentdata, $wp_error ); 2117 if ( $wp_error && is_wp_error( $approved ) ) { 2118 return $approved; 2119 } else { 2120 $commentdata['comment_approved'] = $approved; 2121 } 2082 2122 2083 2123 $comment_ID = wp_insert_comment($commentdata); 2084 2124 if ( ! $comment_ID ) {