From d9793c3e8d324c996acc730d776419030c37d5f3 Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 27 Aug 2007 06:34:18 +0000 Subject: [PATCH] Make the entire comment flood check pluggable as it can cause load problems on large sites. git-svn-id: http://svn.automattic.com/wordpress/trunk@5947 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment.php | 23 +++++++++++++---------- wp-includes/default-filters.php | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 7f36a45abe..37dc38a1b4 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -191,16 +191,7 @@ function wp_allow_comment($commentdata) { if ( $wpdb->get_var($dupe) ) wp_die( __('Duplicate comment detected; it looks as though you\'ve already said that!') ); - // Simple flood-protection - 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); - $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( __('You are posting comments too quickly. Slow down.') ); - } - } + do_action( 'check_comment_flood', $comment_author_IP, $comment_author_email, $comment_date_gmt ); if ( $user_id ) { $userdata = get_userdata($user_id); @@ -225,6 +216,18 @@ function wp_allow_comment($commentdata) { return $approved; } +function check_comment_flood_db( $ip, $email, $date ) { + global $wpdb; + if ( $lasttime = $wpdb->get_var("SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_author_IP = '$ip' OR comment_author_email = '$email' ORDER BY comment_date DESC LIMIT 1") ) { + $time_lastcomment = mysql2date('U', $lasttime); + $time_newcomment = mysql2date('U', $date); + $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( __('You are posting comments too quickly. Slow down.') ); + } + } +} function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) { global $wpdb; diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index ddc653f5ed..39911e96f3 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -106,6 +106,7 @@ add_filter('mce_plugins', '_mce_load_rtl_plugin'); add_filter('mce_buttons', '_mce_add_direction_buttons'); add_filter('pre_kses', 'wp_pre_kses_less_than'); add_filter('sanitize_title', 'sanitize_title_with_dashes'); +add_action('check_comment_flood', 'check_comment_flood_db', 10, 3); add_filter('comment_flood_filter', 'wp_throttle_comment_flood', 10, 3); add_filter('pre_comment_content', 'wp_rel_nofollow', 15); add_filter('comment_email', 'antispambot');