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