akismet
2 years ago
constant-contact
3 years ago
recaptcha
2 years ago
sendinblue
2 years ago
stripe
2 years ago
acceptance.php
3 years ago
checkbox.php
3 years ago
count.php
3 years ago
date.php
3 years ago
disallowed-list.php
4 years ago
doi-helper.php
4 years ago
file.php
3 years ago
flamingo.php
3 years ago
hidden.php
7 years ago
listo.php
3 years ago
number.php
3 years ago
quiz.php
4 years ago
really-simple-captcha.php
3 years ago
reflection.php
3 years ago
response.php
6 years ago
select.php
3 years ago
submit.php
4 years ago
text.php
3 years ago
textarea.php
3 years ago
disallowed-list.php
91 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 | __( "Disallowed words (%s) are used.", 'contact-form-7' ), |
| 36 | implode( ', ', (array) $word ) |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | $submission->add_spam_log( array( |
| 41 | 'agent' => 'disallowed_list', |
| 42 | 'reason' => $reason, |
| 43 | ) ); |
| 44 | } |
| 45 | |
| 46 | $spam = (bool) $word; |
| 47 | |
| 48 | return $spam; |
| 49 | } |
| 50 | |
| 51 | function wpcf7_check_disallowed_list( $target ) { |
| 52 | $mod_keys = get_option( 'disallowed_keys' ); |
| 53 | |
| 54 | if ( is_scalar( $mod_keys ) ) { |
| 55 | $mod_keys = trim( $mod_keys ); |
| 56 | } else { |
| 57 | $mod_keys = ''; |
| 58 | } |
| 59 | |
| 60 | if ( '' === $mod_keys ) { |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | foreach ( explode( "\n", $mod_keys ) as $word ) { |
| 65 | $word = trim( $word ); |
| 66 | $length = strlen( $word ); |
| 67 | |
| 68 | if ( $length < 2 or 256 < $length ) { |
| 69 | continue; |
| 70 | } |
| 71 | |
| 72 | $pattern = sprintf( '#%s#i', preg_quote( $word, '#' ) ); |
| 73 | |
| 74 | if ( preg_match( $pattern, $target ) ) { |
| 75 | return $word; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | function wpcf7_blacklist_check( $target ) { |
| 83 | wpcf7_deprecated_function( |
| 84 | __FUNCTION__, |
| 85 | '5.3', |
| 86 | 'wpcf7_check_disallowed_list' |
| 87 | ); |
| 88 | |
| 89 | return wpcf7_check_disallowed_list( $target ); |
| 90 | } |
| 91 |