Pluggable comment throttling from Mark Jaquith. fixes #3175

git-svn-id: https://develop.svn.wordpress.org/trunk@4265 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2006-10-02 18:19:44 +00:00
parent cdd3f05642
commit 09830f0bbd
2 changed files with 13 additions and 2 deletions

View File

@ -187,9 +187,10 @@ function wp_allow_comment($commentdata) {
if ( $lasttime = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_author_IP = '$comment_author_IP' OR comment_author_email = '$comment_author_email' ORDER BY comment_date DESC LIMIT 1") ) {
$time_lastcomment = mysql2date('U', $lasttime);
$time_newcomment = mysql2date('U', $comment_date_gmt);
if ( ($time_newcomment - $time_lastcomment) < 15 ) {
$flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment);
if ( $flood_die ) {
do_action('comment_flood_trigger', $time_lastcomment, $time_newcomment);
wp_die( __('Sorry, you can only post a new comment once every 15 seconds. Slow down cowboy.') );
wp_die( __('You are posting comments too quickly. Slow down.') );
}
}
@ -355,6 +356,14 @@ function wp_filter_comment($commentdata) {
return $commentdata;
}
function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment) {
if ( $block ) // a plugin has already blocked... we'll let that decision stand
return $block;
if ( ($time_newcomment - $time_lastcomment) < 15 )
return true;
return false;
}
function wp_new_comment( $commentdata ) {
$commentdata = apply_filters('preprocess_comment', $commentdata);

View File

@ -38,6 +38,8 @@ add_filter('comment_author', 'wp_specialchars');
add_filter('comment_email', 'antispambot');
add_filter('comment_flood_filter', 'wp_throttle_comment_flood', 10, 3);
add_filter('comment_url', 'clean_url');
add_filter('comment_text', 'convert_chars');