Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions classes/models/FrmEntryValidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ private static function create_regular_expression_from_format( $pattern ) {
* @param array $errors By reference.
*/
public static function spam_check( $exclude, $values, &$errors ) {
if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
// Do not check spam on importing.
return;
}

if ( ! empty( $exclude ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) {
// only check spam if there are no other errors
return;
Expand Down
3 changes: 3 additions & 0 deletions classes/models/FrmSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class FrmSettings {

public $wp_spam_check;

public $denylist_check;

public $disallowed_words;

public $allowed_words;
Expand Down Expand Up @@ -173,6 +175,7 @@ public function default_options() {
'custom_css' => false,
'honeypot' => 1,
'wp_spam_check' => 0,
'denylist_check' => 0,
'disallowed_words' => '',
'allowed_words' => '',
);
Expand Down
23 changes: 20 additions & 3 deletions classes/models/FrmSpamCheckDenylist.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ protected function maybe_add_form_id_to_values( &$values ) {
}

protected function is_enabled() {
$frm_settings = FrmAppHelper::get_settings();
$is_enabled = $frm_settings->denylist_check;

/**
* Allows to disable the denylist check.
* Allows disabling the denylist check.
*
* @since 6.21
*
* @param bool $is_enabled Whether the denylist check is enabled.
* @param array $values The entry values.
*/
return apply_filters( 'frm_check_denylist', true, $this->values );
return apply_filters( 'frm_check_denylist', $is_enabled, $this->values );
}

/**
Expand Down Expand Up @@ -194,6 +197,7 @@ protected function fill_default_denylist_data( &$denylist ) {
'words' => array(),
'is_regex' => false,
'field_types' => array(),
// Add `other` if you want to skip checking Other values of some field types.
'skip_field_types' => array(),
// Is ignore if `is_regex` is `true`.
'compare' => self::COMPARE_CONTAINS,
Expand All @@ -202,6 +206,12 @@ protected function fill_default_denylist_data( &$denylist ) {
'skip' => false,
)
);

// Some field types should never be checked.
$denylist['skip_field_types'] = array_merge(
$denylist['skip_field_types'],
array( 'password', 'captcha', 'signature', 'checkbox', 'radio', 'select' )
);
}

/**
Expand Down Expand Up @@ -338,10 +348,17 @@ protected function get_values_to_check( $denylist ) {
$this->add_to_values_to_check( $values_to_check, $sub_value );
}
}
} elseif ( 'other' === $key ) {
if ( ! in_array( 'other', $denylist['skip_field_types'], true ) ) {
// This is Other values, loop through this and add sub values.
foreach ( $value as $sub_value ) {
$this->add_to_values_to_check( $values_to_check, $sub_value );
}
}
} elseif ( $this->should_check_this_field( $key, $field_ids_to_check ) ) {
$this->add_to_values_to_check( $values_to_check, $value );
}
}
}//end foreach

if ( isset( $denylist['extract_value'] ) && is_callable( $denylist['extract_value'] ) ) {
$values_to_check = call_user_func( $denylist['extract_value'], $values_to_check, $denylist );
Expand Down
1 change: 1 addition & 0 deletions classes/models/FrmUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ private function settings() {
'active_captcha',
'honeypot',
'wp_spam_check',
'denylist_check',
);

foreach ( $pass_settings as $setting ) {
Expand Down
7 changes: 7 additions & 0 deletions classes/views/frm-settings/captcha/captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@
</label>
</p>

<p>
<label>
<input type="checkbox" name="frm_denylist_check" value="1" <?php checked( $frm_settings->denylist_check, 1 ); ?> />
<?php esc_html_e( 'Check denylist data to validate for spam', 'formidable' ); ?>
</label>
</p>

<p>
<label for="frm-disallowed-words">
<?php esc_html_e( 'Custom disallowed words', 'formidable' ); ?>
Expand Down