Block Links in Fluent Forms Messages
Shows an error when a Fluent Forms message field contains web links, which removes most link spam without a captcha.
Opens WPIDE on
Code
$wpide_ff_link_fields = array( 'message', 'description' ); // Field names to check.
$wpide_ff_max_links = 0;
add_filter( 'fluentform/validation_errors', function ( $errors, $data ) use ( $wpide_ff_link_fields, $wpide_ff_max_links ) {
foreach ( $wpide_ff_link_fields as $name ) {
if ( empty( $data[ $name ] ) || ! is_string( $data[ $name ] ) ) {
continue;
}
if ( preg_match_all( '#(https?://|www\.|\[url|<a\s)#i', $data[ $name ] ) > $wpide_ff_max_links ) {
$errors[ $name ] = array( 'Please remove the links from your message.' );
}
}
return $errors;
}, 10, 2 );
Notes
List the names of the fields to check at the top; the default is the "message" field.
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.