akismet
1 year ago
constant-contact
1 year ago
recaptcha
1 year ago
sendinblue
1 year ago
stripe
1 year ago
acceptance.php
1 year ago
checkbox.php
1 year ago
count.php
1 year ago
date.php
1 year ago
disallowed-list.php
1 year ago
doi-helper.php
4 years ago
file.php
1 year ago
flamingo.php
1 year ago
hidden.php
7 years ago
listo.php
2 years ago
number.php
1 year ago
quiz.php
1 year ago
really-simple-captcha.php
1 year ago
reflection.php
3 years ago
response.php
6 years ago
select.php
1 year ago
submit.php
1 year ago
text.php
1 year ago
textarea.php
1 year ago
disallowed-list.php
92 lines
| 1 | <?php |
| 2 | |
| 3 | add_filter( 'wpcf7_spam', 'wpcf7_disallowed_list', 10, 2 ); |
| 4 | |
| 5 | function wpcf7_disallowed_list( $spam, $submission ) { |
| 6 | if ( $spam ) { |
| 7 | return $spam; |
| 8 | } |
| 9 | |
| 10 | $target = wpcf7_array_flatten( $submission->get_posted_data() ); |
| 11 | $target[] = $submission->get_meta( 'remote_ip' ); |
| 12 | $target[] = $submission->get_meta( 'user_agent' ); |
| 13 | $target = implode( "\n", $target ); |
| 14 | |
| 15 | $word = wpcf7_check_disallowed_list( $target ); |
| 16 | |
| 17 | $word = wpcf7_apply_filters_deprecated( |
| 18 | 'wpcf7_submission_is_blacklisted', |
| 19 | array( $word, $submission ), |
| 20 | '5.3', |
| 21 | 'wpcf7_submission_has_disallowed_words' |
| 22 | ); |
| 23 | |
| 24 | $word = apply_filters( |
| 25 | 'wpcf7_submission_has_disallowed_words', |
| 26 | $word, |
| 27 | $submission |
| 28 | ); |
| 29 | |
| 30 | if ( $word ) { |
| 31 | if ( is_bool( $word ) ) { |
| 32 | $reason = __( "Disallowed words are used.", 'contact-form-7' ); |
| 33 | } else { |
| 34 | $reason = sprintf( |
| 35 | /* translators: %s: comma separated list of disallowed words */ |
| 36 | __( "Disallowed words (%s) are used.", 'contact-form-7' ), |
| 37 | implode( ', ', (array) $word ) |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | $submission->add_spam_log( array( |
| 42 | 'agent' => 'disallowed_list', |
| 43 | 'reason' => $reason, |
| 44 | ) ); |
| 45 | } |
| 46 | |
| 47 | $spam = (bool) $word; |
| 48 | |
| 49 | return $spam; |
| 50 | } |
| 51 | |
| 52 | function wpcf7_check_disallowed_list( $target ) { |
| 53 | $mod_keys = get_option( 'disallowed_keys' ); |
| 54 | |
| 55 | if ( is_scalar( $mod_keys ) ) { |
| 56 | $mod_keys = trim( $mod_keys ); |
| 57 | } else { |
| 58 | $mod_keys = ''; |
| 59 | } |
| 60 | |
| 61 | if ( '' === $mod_keys ) { |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | foreach ( explode( "\n", $mod_keys ) as $word ) { |
| 66 | $word = trim( $word ); |
| 67 | $length = strlen( $word ); |
| 68 | |
| 69 | if ( $length < 2 or 256 < $length ) { |
| 70 | continue; |
| 71 | } |
| 72 | |
| 73 | $pattern = sprintf( '#%s#i', preg_quote( $word, '#' ) ); |
| 74 | |
| 75 | if ( preg_match( $pattern, $target ) ) { |
| 76 | return $word; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | function wpcf7_blacklist_check( $target ) { |
| 84 | wpcf7_deprecated_function( |
| 85 | __FUNCTION__, |
| 86 | '5.3', |
| 87 | 'wpcf7_check_disallowed_list' |
| 88 | ); |
| 89 | |
| 90 | return wpcf7_check_disallowed_list( $target ); |
| 91 | } |
| 92 |