# Reject Comments Submitted Too Fast

> Rejects comments sent within a few seconds of the page loading, which only bots manage, using a signed timestamp in the form.

- Type: PHP
- Runs: Run everywhere
- Category: [Comments](https://wpide.com/library/category/comments/)
- Tags: comments, spam, bots
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/reject-too-fast-comments/

## Code

```php
// Minimum seconds between loading the page and submitting a comment.
$wpide_comment_min_seconds = 5;

add_action( 'comment_form', function () {
    if ( is_user_logged_in() ) {
        return;
    }

    $time = time();
    printf(
        '<input type="hidden" name="wpide_ct" value="%1$d"><input type="hidden" name="wpide_cs" value="%2$s">',
        (int) $time,
        esc_attr( hash_hmac( 'sha256', (string) $time, wp_salt( 'nonce' ) ) )
    );
} );

add_filter( 'preprocess_comment', function ( $commentdata ) use ( $wpide_comment_min_seconds ) {
    $type = isset( $commentdata['comment_type'] ) ? $commentdata['comment_type'] : '';

    if ( is_user_logged_in() || ( '' !== $type && 'comment' !== $type ) ) {
        return $commentdata;
    }

    $time = isset( $_POST['wpide_ct'] ) ? (int) $_POST['wpide_ct'] : 0;
    $sig  = isset( $_POST['wpide_cs'] ) ? sanitize_text_field( wp_unslash( $_POST['wpide_cs'] ) ) : '';

    if ( ! $time || ! hash_equals( hash_hmac( 'sha256', (string) $time, wp_salt( 'nonce' ) ), $sig ) || time() - $time < $wpide_comment_min_seconds ) {
        wp_die( 'Your comment could not be submitted. Please go back, wait a moment and try again.', 'Comment rejected', array( 'response' => 403, 'back_link' => true ) );
    }

    return $commentdata;
}, 1 );
```

## Notes

Works with page caching because the check only sets a minimum age.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Reject Comments Submitted Too Fast" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
