| 1 |
<?php |
| 2 |
/** |
| 3 |
* Spam check using WordPress disallowed words |
| 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 FrmSpamCheckWPDisallowedWords extends FrmSpamCheck { |
| 14 |
|
| 15 |
public function check() { |
| 16 |
$mod_keys = trim( $this->get_disallowed_words() ); |
| 17 |
if ( empty( $mod_keys ) ) { |
| 18 |
return false; |
| 19 |
} |
| 20 |
|
| 21 |
$values = $this->values; |
| 22 |
$content = FrmEntriesHelper::entry_array_to_string( $values ); |
| 23 |
|
| 24 |
FrmEntryValidate::prepare_values_for_spam_check( $values ); |
| 25 |
$ip = FrmAppHelper::get_ip_address(); |
| 26 |
$user_agent = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ); |
| 27 |
$user_info = FrmEntryValidate::get_spam_check_user_info( $values ); |
| 28 |
|
| 29 |
return $this->do_check_wp_disallowed_words( |
| 30 |
$user_info['comment_author'], |
| 31 |
$user_info['comment_author_email'], |
| 32 |
$user_info['comment_author_url'], |
| 33 |
$content, |
| 34 |
$ip, |
| 35 |
$user_agent |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* For WP 5.5 compatibility. |
| 41 |
* |
| 42 |
* @return string |
| 43 |
*/ |
| 44 |
private function get_disallowed_words() { |
| 45 |
$keys = get_option( 'disallowed_keys' ); |
| 46 |
if ( false === $keys ) { |
| 47 |
// Fallback for WP < 5.5. |
| 48 |
// phpcs:ignore WordPress.WP.DeprecatedParameterValues.Found |
| 49 |
$keys = get_option( 'blacklist_keys' ); |
| 50 |
} |
| 51 |
return $keys; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* For WP 5.5 compatibility. |
| 56 |
* |
| 57 |
* @return bool Return `true` if contains disallowed words. |
| 58 |
*/ |
| 59 |
private function do_check_wp_disallowed_words( $author, $email, $url, $content, $ip, $user_agent ) { |
| 60 |
if ( function_exists( 'wp_check_comment_disallowed_list' ) ) { |
| 61 |
return wp_check_comment_disallowed_list( $author, $email, $url, $content, $ip, $user_agent ); |
| 62 |
} |
| 63 |
// phpcs:ignore WordPress.WP.DeprecatedFunctions.wp_blacklist_checkFound |
| 64 |
return wp_blacklist_check( $author, $email, $url, $content, $ip, $user_agent ); |
| 65 |
} |
| 66 |
|
| 67 |
protected function is_enabled() { |
| 68 |
return apply_filters( 'frm_check_blacklist', true, $this->values ); |
| 69 |
} |
| 70 |
|
| 71 |
protected function get_spam_message() { |
| 72 |
return __( 'Your entry appears to be blocked spam!', 'formidable' ); |
| 73 |
} |
| 74 |
} |
| 75 |
|