The check_comment_flood_db() WordPress PHP function hooks into WordPress’s native database-based comment-flood check.
Usage
Let’s say you want to disable the comment flood check for a specific situation. You can use the check_comment_flood_db() function in combination with remove_action():
remove_action('check_comment_flood', 'check_comment_flood_db');
This will remove the comment flood check, allowing comments to be submitted without any rate limit.
Parameters
- This function does not accept any parameters.
More information
See WordPress Developer Resources: check_comment_flood_db()
This function is included since WordPress version 2.3.0. It is not deprecated and you can find the source code in wp-includes/comment.php
.
Examples
Disable comment flood check
If you want to disable the comment flood check completely, you can remove the action in your theme’s functions.php
:
// Disabling the comment flood check. remove_action('check_comment_flood', 'check_comment_flood_db');
Disable comment flood check for a specific post
You can also disable the comment flood check only for a specific post:
add_action( 'check_comment_flood', 'disable_comment_flood_check_for_post', 10, 3 ); function disable_comment_flood_check_for_post( $time_lastcomment, $time_newcomment, $flood_die ) { if ( get_the_ID() === 42 ) { remove_action('check_comment_flood', 'check_comment_flood_db'); } }
Re-enable comment flood check
If you’ve disabled the comment flood check and want to enable it again:
// Enabling the comment flood check. add_action('check_comment_flood', 'check_comment_flood_db');
Disable comment flood check for logged in users
If you want to disable the comment flood check only for logged in users:
if ( is_user_logged_in() ) { remove_action('check_comment_flood', 'check_comment_flood_db'); }
Enable comment flood check only during business hours
If you only want to allow rapid commenting during business hours (9AM to 5PM):
$current_hour = date('G'); if ( $current_hour >= 9 && $current_hour <= 17 ) { remove_action('check_comment_flood', 'check_comment_flood_db'); } else { add_action('check_comment_flood', 'check_comment_flood_db'); }