| 1 |
<?php |
| 2 |
/** |
| 3 |
* Spam check using WordPress spam comments |
| 4 |
* |
| 5 |
* @since 6.21 |
| 6 |
* |
| 7 |
* @package Formidable |
| 8 |
*/ |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
die( 'You are not allowed to call this page directly.' ); |
| 12 |
} |
| 13 |
|
| 14 |
class FrmSpamCheckUseWPComments extends FrmSpamCheck { |
| 15 |
|
| 16 |
protected function check() { |
| 17 |
$spam_comments = get_comments( |
| 18 |
array( |
| 19 |
'status' => 'spam', |
| 20 |
// Reasonable limit to prevent performance issues. |
| 21 |
'number' => 100, |
| 22 |
'orderby' => 'comment_date_gmt', |
| 23 |
'order' => 'DESC', |
| 24 |
) |
| 25 |
); |
| 26 |
|
| 27 |
if ( ! is_array( $spam_comments ) ) { |
| 28 |
return false; |
| 29 |
} |
| 30 |
|
| 31 |
$ip_address = FrmAppHelper::get_ip_address(); |
| 32 |
$whitelist_ip = FrmAntiSpamController::get_allowed_ips(); |
| 33 |
$is_whitelist_ip = in_array( $ip_address, $whitelist_ip, true ); |
| 34 |
$item_meta = FrmAppHelper::array_flatten( $this->values['item_meta'] ); |
| 35 |
|
| 36 |
foreach ( $spam_comments as $comment ) { |
| 37 |
if ( ! $is_whitelist_ip && $ip_address === $comment->comment_author_IP ) { |
| 38 |
return true; |
| 39 |
} |
| 40 |
|
| 41 |
foreach ( $item_meta as $value ) { |
| 42 |
if ( ! $value ) { |
| 43 |
continue; |
| 44 |
} |
| 45 |
|
| 46 |
if ( $value === $comment->comment_author_email || $value === $comment->comment_author_url ) { |
| 47 |
return true; |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
return false; |
| 53 |
} |
| 54 |
|
| 55 |
protected function is_enabled() { |
| 56 |
$frm_settings = FrmAppHelper::get_settings(); |
| 57 |
return ! empty( $frm_settings->wp_spam_check ); |
| 58 |
} |
| 59 |
} |
| 60 |
|