Limit Fluent Forms Submissions per Visitor
Allows only a few Fluent Forms submissions per IP address each hour and shows a polite message after that, which stops flooding and repeated spam.
Opens WPIDE on
Code
$wpide_ff_max_per_hour = 3;
$wpide_ff_rate_key = function () {
$ip = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
return 'wpide_ff_rate_' . md5( wp_salt() . $ip );
};
add_filter( 'fluentform/validation_errors', function ( $errors ) use ( $wpide_ff_max_per_hour, $wpide_ff_rate_key ) {
if ( (int) get_transient( $wpide_ff_rate_key() ) >= $wpide_ff_max_per_hour ) {
$errors['_wpide_rate_limit'] = array( 'You have sent several messages recently. Please try again later.' );
}
return $errors;
}, 20 );
add_action( 'fluentform/submission_inserted', function () use ( $wpide_ff_rate_key ) {
$key = $wpide_ff_rate_key();
set_transient( $key, (int) get_transient( $key ) + 1, HOUR_IN_SECONDS );
} );
Notes
IPs are stored only as hashes in short-lived transients; raise the limit for forms used from shared offices.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.