check_comment_flood_db

The timeline below displays how wordpress function check_comment_flood_db has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 4.7

/**
 * Hooks WP's native database-based comment-flood check.
 *
 * This wrapper maintains backward compatibility with plugins that expect to
 * be able to unhook the legacy check_comment_flood_db() function from
 * 'check_comment_flood' using remove_action().
 *
 * @since 2.3.0
 * @since 4.7.0 Converted to be an add_filter() wrapper.
 */
function check_comment_flood_db()
{
    add_filter('wp_is_comment_flood', 'wp_check_comment_flood', 10, 5);
}

WordPress Version: 4.6

/**
 * Check whether comment flooding is occurring.
 *
 * Won't run, if current user can manage options, so to not block
 * administrators.
 *
 * @since 2.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $ip Comment IP.
 * @param string $email Comment author email address.
 * @param string $date MySQL time string.
 */
function check_comment_flood_db($ip, $email, $date)
{
    global $wpdb;
    // don't throttle admins or moderators
    if (current_user_can('manage_options') || current_user_can('moderate_comments')) {
        return;
    }
    $hour_ago = gmdate('Y-m-d H:i:s', time() - HOUR_IN_SECONDS);
    if (is_user_logged_in()) {
        $user = get_current_user_id();
        $check_column = '`user_id`';
    } else {
        $user = $ip;
        $check_column = '`comment_author_IP`';
    }
    $sql = $wpdb->prepare("SELECT `comment_date_gmt` FROM `{$wpdb->comments}` WHERE `comment_date_gmt` >= %s AND ( {$check_column} = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1", $hour_ago, $user, $email);
    $lasttime = $wpdb->get_var($sql);
    if ($lasttime) {
        $time_lastcomment = mysql2date('U', $lasttime, false);
        $time_newcomment = mysql2date('U', $date, false);
        /**
         * Filters the comment flood status.
         *
         * @since 2.1.0
         *
         * @param bool $bool             Whether a comment flood is occurring. Default false.
         * @param int  $time_lastcomment Timestamp of when the last comment was posted.
         * @param int  $time_newcomment  Timestamp of when the new comment was posted.
         */
        $flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment);
        if ($flood_die) {
            /**
             * Fires before the comment flood message is triggered.
             *
             * @since 1.5.0
             *
             * @param int $time_lastcomment Timestamp of when the last comment was posted.
             * @param int $time_newcomment  Timestamp of when the new comment was posted.
             */
            do_action('comment_flood_trigger', $time_lastcomment, $time_newcomment);
            if (defined('DOING_AJAX')) {
                die(__('You are posting comments too quickly. Slow down.'));
            }
            wp_die(__('You are posting comments too quickly. Slow down.'), 429);
        }
    }
}

WordPress Version: 4.4

/**
 * Check whether comment flooding is occurring.
 *
 * Won't run, if current user can manage options, so to not block
 * administrators.
 *
 * @since 2.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $ip Comment IP.
 * @param string $email Comment author email address.
 * @param string $date MySQL time string.
 */
function check_comment_flood_db($ip, $email, $date)
{
    global $wpdb;
    // don't throttle admins or moderators
    if (current_user_can('manage_options') || current_user_can('moderate_comments')) {
        return;
    }
    $hour_ago = gmdate('Y-m-d H:i:s', time() - HOUR_IN_SECONDS);
    if (is_user_logged_in()) {
        $user = get_current_user_id();
        $check_column = '`user_id`';
    } else {
        $user = $ip;
        $check_column = '`comment_author_IP`';
    }
    $sql = $wpdb->prepare("SELECT `comment_date_gmt` FROM `{$wpdb->comments}` WHERE `comment_date_gmt` >= %s AND ( {$check_column} = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1", $hour_ago, $user, $email);
    $lasttime = $wpdb->get_var($sql);
    if ($lasttime) {
        $time_lastcomment = mysql2date('U', $lasttime, false);
        $time_newcomment = mysql2date('U', $date, false);
        /**
         * Filter the comment flood status.
         *
         * @since 2.1.0
         *
         * @param bool $bool             Whether a comment flood is occurring. Default false.
         * @param int  $time_lastcomment Timestamp of when the last comment was posted.
         * @param int  $time_newcomment  Timestamp of when the new comment was posted.
         */
        $flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment);
        if ($flood_die) {
            /**
             * Fires before the comment flood message is triggered.
             *
             * @since 1.5.0
             *
             * @param int $time_lastcomment Timestamp of when the last comment was posted.
             * @param int $time_newcomment  Timestamp of when the new comment was posted.
             */
            do_action('comment_flood_trigger', $time_lastcomment, $time_newcomment);
            if (defined('DOING_AJAX')) {
                die(__('You are posting comments too quickly. Slow down.'));
            }
            wp_die(__('You are posting comments too quickly. Slow down.'), 429);
        }
    }
}

WordPress Version: 4.1

/**
 * Check whether comment flooding is occurring.
 *
 * Won't run, if current user can manage options, so to not block
 * administrators.
 *
 * @since 2.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $ip Comment IP.
 * @param string $email Comment author email address.
 * @param string $date MySQL time string.
 */
function check_comment_flood_db($ip, $email, $date)
{
    global $wpdb;
    if (current_user_can('manage_options')) {
        return;
    }
    // don't throttle admins
    $hour_ago = gmdate('Y-m-d H:i:s', time() - HOUR_IN_SECONDS);
    if ($lasttime = $wpdb->get_var($wpdb->prepare("SELECT `comment_date_gmt` FROM `{$wpdb->comments}` WHERE `comment_date_gmt` >= %s AND ( `comment_author_IP` = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1", $hour_ago, $ip, $email))) {
        $time_lastcomment = mysql2date('U', $lasttime, false);
        $time_newcomment = mysql2date('U', $date, false);
        /**
         * Filter the comment flood status.
         *
         * @since 2.1.0
         *
         * @param bool $bool             Whether a comment flood is occurring. Default false.
         * @param int  $time_lastcomment Timestamp of when the last comment was posted.
         * @param int  $time_newcomment  Timestamp of when the new comment was posted.
         */
        $flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment);
        if ($flood_die) {
            /**
             * Fires before the comment flood message is triggered.
             *
             * @since 1.5.0
             *
             * @param int $time_lastcomment Timestamp of when the last comment was posted.
             * @param int $time_newcomment  Timestamp of when the new comment was posted.
             */
            do_action('comment_flood_trigger', $time_lastcomment, $time_newcomment);
            if (defined('DOING_AJAX')) {
                die(__('You are posting comments too quickly. Slow down.'));
            }
            wp_die(__('You are posting comments too quickly. Slow down.'), 429);
        }
    }
}

WordPress Version: 3.9

/**
 * Check whether comment flooding is occurring.
 *
 * Won't run, if current user can manage options, so to not block
 * administrators.
 *
 * @since 2.3.0
 * @uses $wpdb
 *
 * @param string $ip Comment IP.
 * @param string $email Comment author email address.
 * @param string $date MySQL time string.
 */
function check_comment_flood_db($ip, $email, $date)
{
    global $wpdb;
    if (current_user_can('manage_options')) {
        return;
    }
    // don't throttle admins
    $hour_ago = gmdate('Y-m-d H:i:s', time() - HOUR_IN_SECONDS);
    if ($lasttime = $wpdb->get_var($wpdb->prepare("SELECT `comment_date_gmt` FROM `{$wpdb->comments}` WHERE `comment_date_gmt` >= %s AND ( `comment_author_IP` = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1", $hour_ago, $ip, $email))) {
        $time_lastcomment = mysql2date('U', $lasttime, false);
        $time_newcomment = mysql2date('U', $date, false);
        /**
         * Filter the comment flood status.
         *
         * @since 2.1.0
         *
         * @param bool $bool             Whether a comment flood is occurring. Default false.
         * @param int  $time_lastcomment Timestamp of when the last comment was posted.
         * @param int  $time_newcomment  Timestamp of when the new comment was posted.
         */
        $flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment);
        if ($flood_die) {
            /**
             * Fires before the comment flood message is triggered.
             *
             * @since 1.5.0
             *
             * @param int $time_lastcomment Timestamp of when the last comment was posted.
             * @param int $time_newcomment  Timestamp of when the new comment was posted.
             */
            do_action('comment_flood_trigger', $time_lastcomment, $time_newcomment);
            if (defined('DOING_AJAX')) {
                die(__('You are posting comments too quickly. Slow down.'));
            }
            wp_die(__('You are posting comments too quickly. Slow down.'), '', array('response' => 403));
        }
    }
}

WordPress Version: 3.8

/**
 * Check whether comment flooding is occurring.
 *
 * Won't run, if current user can manage options, so to not block
 * administrators.
 *
 * @since 2.3.0
 * @uses $wpdb
 * @uses apply_filters() Calls 'comment_flood_filter' filter with first
 *		parameter false, last comment timestamp, new comment timestamp.
 * @uses do_action() Calls 'comment_flood_trigger' action with parameters with
 *		last comment timestamp and new comment timestamp.
 *
 * @param string $ip Comment IP.
 * @param string $email Comment author email address.
 * @param string $date MySQL time string.
 */
function check_comment_flood_db($ip, $email, $date)
{
    global $wpdb;
    if (current_user_can('manage_options')) {
        return;
    }
    // don't throttle admins
    $hour_ago = gmdate('Y-m-d H:i:s', time() - HOUR_IN_SECONDS);
    if ($lasttime = $wpdb->get_var($wpdb->prepare("SELECT `comment_date_gmt` FROM `{$wpdb->comments}` WHERE `comment_date_gmt` >= %s AND ( `comment_author_IP` = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1", $hour_ago, $ip, $email))) {
        $time_lastcomment = mysql2date('U', $lasttime, false);
        $time_newcomment = mysql2date('U', $date, false);
        /**
         * Filter the comment flood status.
         *
         * @since 2.1.0
         *
         * @param bool $bool             Whether a comment flood is occurring. Default false.
         * @param int  $time_lastcomment Timestamp of when the last comment was posted.
         * @param int  $time_newcomment  Timestamp of when the new comment was posted.
         */
        $flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment);
        if ($flood_die) {
            /**
             * Fires before the comment flood message is triggered.
             *
             * @since 1.5.0
             *
             * @param int $time_lastcomment Timestamp of when the last comment was posted.
             * @param int $time_newcomment  Timestamp of when the new comment was posted.
             */
            do_action('comment_flood_trigger', $time_lastcomment, $time_newcomment);
            if (defined('DOING_AJAX')) {
                die(__('You are posting comments too quickly. Slow down.'));
            }
            wp_die(__('You are posting comments too quickly. Slow down.'), '', array('response' => 403));
        }
    }
}

WordPress Version: 3.7

/**
 * Check whether comment flooding is occurring.
 *
 * Won't run, if current user can manage options, so to not block
 * administrators.
 *
 * @since 2.3.0
 * @uses $wpdb
 * @uses apply_filters() Calls 'comment_flood_filter' filter with first
 *		parameter false, last comment timestamp, new comment timestamp.
 * @uses do_action() Calls 'comment_flood_trigger' action with parameters with
 *		last comment timestamp and new comment timestamp.
 *
 * @param string $ip Comment IP.
 * @param string $email Comment author email address.
 * @param string $date MySQL time string.
 */
function check_comment_flood_db($ip, $email, $date)
{
    global $wpdb;
    if (current_user_can('manage_options')) {
        return;
    }
    // don't throttle admins
    $hour_ago = gmdate('Y-m-d H:i:s', time() - HOUR_IN_SECONDS);
    if ($lasttime = $wpdb->get_var($wpdb->prepare("SELECT `comment_date_gmt` FROM `{$wpdb->comments}` WHERE `comment_date_gmt` >= %s AND ( `comment_author_IP` = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1", $hour_ago, $ip, $email))) {
        $time_lastcomment = mysql2date('U', $lasttime, false);
        $time_newcomment = mysql2date('U', $date, false);
        $flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment);
        if ($flood_die) {
            do_action('comment_flood_trigger', $time_lastcomment, $time_newcomment);
            if (defined('DOING_AJAX')) {
                die(__('You are posting comments too quickly. Slow down.'));
            }
            wp_die(__('You are posting comments too quickly. Slow down.'), '', array('response' => 403));
        }
    }
}