Contact Form 7 Honeypot - Version 2.0.5

Version Description

Improved backwards compatibility. Solves issues when plugin installed on older versions of CF7.

Download this release

Release Info

Developer nocean
Plugin Icon 128x128 Contact Form 7 Honeypot
Version 2.0.5
Comparing to
See all releases

Code changes from version 2.0.4 to 2.0.5

Files changed (4) hide show
  1. honeypot.php +17 -2
  2. includes/admin.php +23 -0
  3. includes/honeypot4cf7.php +24 -10
  4. readme.txt +11 -2
honeypot.php CHANGED
@@ -5,12 +5,12 @@ Plugin URI: http://www.nocean.ca/plugins/honeypot-module-for-contact-form-7-word
5
  Description: Add honeypot anti-spam functionality to the popular Contact Form 7 plugin.
6
  Author: Nocean
7
  Author URI: http://www.nocean.ca
8
- Version: 2.0.4
9
  Text Domain: contact-form-7-honeypot
10
  Domain Path: /languages/
11
  */
12
 
13
- define( 'HONEYPOT4CF7_VERSION', '2.0.4' );
14
  define( 'HONEYPOT4CF7_PLUGIN', __FILE__ );
15
  define( 'HONEYPOT4CF7_PLUGIN_BASENAME', plugin_basename( HONEYPOT4CF7_PLUGIN ) );
16
  define( 'HONEYPOT4CF7_PLUGIN_NAME', trim( dirname( HONEYPOT4CF7_PLUGIN_BASENAME ), '/' ) );
@@ -18,5 +18,20 @@ define( 'HONEYPOT4CF7_PLUGIN_DIR', untrailingslashit( dirname( HONEYPOT4CF7_PLUG
18
  define( 'HONEYPOT4CF7_PLUGIN_DIR_URL', untrailingslashit( plugin_dir_url( HONEYPOT4CF7_PLUGIN ) ) );
19
  define( 'HONEYPOT4CF7_DEP_PLUGIN', 'contact-form-7/wp-contact-form-7.php' );
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  require_once HONEYPOT4CF7_PLUGIN_DIR . '/includes/admin.php';
22
  require_once HONEYPOT4CF7_PLUGIN_DIR . '/includes/honeypot4cf7.php';
5
  Description: Add honeypot anti-spam functionality to the popular Contact Form 7 plugin.
6
  Author: Nocean
7
  Author URI: http://www.nocean.ca
8
+ Version: 2.0.5
9
  Text Domain: contact-form-7-honeypot
10
  Domain Path: /languages/
11
  */
12
 
13
+ define( 'HONEYPOT4CF7_VERSION', '2.0.5' );
14
  define( 'HONEYPOT4CF7_PLUGIN', __FILE__ );
15
  define( 'HONEYPOT4CF7_PLUGIN_BASENAME', plugin_basename( HONEYPOT4CF7_PLUGIN ) );
16
  define( 'HONEYPOT4CF7_PLUGIN_NAME', trim( dirname( HONEYPOT4CF7_PLUGIN_BASENAME ), '/' ) );
18
  define( 'HONEYPOT4CF7_PLUGIN_DIR_URL', untrailingslashit( plugin_dir_url( HONEYPOT4CF7_PLUGIN ) ) );
19
  define( 'HONEYPOT4CF7_DEP_PLUGIN', 'contact-form-7/wp-contact-form-7.php' );
20
 
21
+ if ( defined( 'WPCF7_VERSION' ) ) {
22
+ define( 'HONEYPOT4CF7_WPCF7_VERSION', WPCF7_VERSION );
23
+ } else {
24
+ $path_to_cf7 = WP_PLUGIN_DIR . '/' . HONEYPOT4CF7_DEP_PLUGIN;
25
+ if ( file_exists( $path_to_cf7 ) ) {
26
+ $cf7_plugin_data = get_file_data($path_to_cf7, array('Version' => 'Version'), 'plugin');
27
+ }
28
+
29
+ if ( ! empty( $cf7_plugin_data['Version'] ) ) {
30
+ define( 'HONEYPOT4CF7_WPCF7_VERSION', $cf7_plugin_data['Version'] );
31
+ } else {
32
+ define( 'HONEYPOT4CF7_WPCF7_VERSION', '0.0.0' );
33
+ }
34
+ }
35
+
36
  require_once HONEYPOT4CF7_PLUGIN_DIR . '/includes/admin.php';
37
  require_once HONEYPOT4CF7_PLUGIN_DIR . '/includes/honeypot4cf7.php';
includes/admin.php CHANGED
@@ -11,10 +11,17 @@ function honeypot4cf7_init() {
11
  // Get Options
12
  $honeypot4cf7_config = honeypot4cf7_get_config();
13
 
 
14
  if ( is_admin() && current_user_can( 'activate_plugins' ) && !is_plugin_active( HONEYPOT4CF7_DEP_PLUGIN ) && empty( $honeypot4cf7_config['honeypot_cf7_req_msg_dismissed'] ) ) {
15
  add_action( 'admin_notices', 'honeypot4cf7_nocf7_notice' );
16
  }
17
 
 
 
 
 
 
 
18
  // This resets dismissed notice
19
  if ( is_plugin_active( HONEYPOT4CF7_DEP_PLUGIN ) && $honeypot4cf7_config['honeypot_cf7_req_msg_dismissed'] === 1 ) {
20
  $honeypot4cf7_config['honeypot_cf7_req_msg_dismissed'] = 0;
@@ -38,6 +45,22 @@ function honeypot4cf7_nocf7_notice() {
38
  <?php
39
  }
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  add_action( 'wp_ajax_honeypot4cf7_dismiss_notice', 'honeypot4cf7_dismiss_notice' );
43
  function honeypot4cf7_dismiss_notice() {
11
  // Get Options
12
  $honeypot4cf7_config = honeypot4cf7_get_config();
13
 
14
+ // CF7 is not enabled
15
  if ( is_admin() && current_user_can( 'activate_plugins' ) && !is_plugin_active( HONEYPOT4CF7_DEP_PLUGIN ) && empty( $honeypot4cf7_config['honeypot_cf7_req_msg_dismissed'] ) ) {
16
  add_action( 'admin_notices', 'honeypot4cf7_nocf7_notice' );
17
  }
18
 
19
+ // CF7 is enabled, but it is OOOOOLD. Display message and deactivate Honeypot.
20
+ if ( is_admin() && current_user_can( 'activate_plugins' ) && is_plugin_active( HONEYPOT4CF7_DEP_PLUGIN ) && defined('WPCF7_VERSION') && version_compare(WPCF7_VERSION, '3.0', '<' ) ) {
21
+ add_action( 'admin_notices', 'honeypot4cf7_oldcf7_notice' );
22
+ deactivate_plugins( HONEYPOT4CF7_PLUGIN_BASENAME );
23
+ }
24
+
25
  // This resets dismissed notice
26
  if ( is_plugin_active( HONEYPOT4CF7_DEP_PLUGIN ) && $honeypot4cf7_config['honeypot_cf7_req_msg_dismissed'] === 1 ) {
27
  $honeypot4cf7_config['honeypot_cf7_req_msg_dismissed'] = 0;
45
  <?php
46
  }
47
 
48
+ function honeypot4cf7_oldcf7_notice() {
49
+ ?>
50
+ <div class="notice error">
51
+ <p>
52
+ <?php
53
+ printf(
54
+ /* translators: %s: Link to Contact Form 7 plugin page. */
55
+ __('The version of %s that is installed will not work with this version of Honeypot for CF7.', 'contact-form-7-honeypot'),
56
+ '<a href="'.admin_url('plugin-install.php?tab=search&s=contact+form+7').'">'.__('Contact Form 7','contact-form-7-honeypot').'</a>'
57
+ );
58
+ ?>
59
+ </p>
60
+ </div>
61
+ <?php
62
+ }
63
+
64
 
65
  add_action( 'wp_ajax_honeypot4cf7_dismiss_notice', 'honeypot4cf7_dismiss_notice' );
66
  function honeypot4cf7_dismiss_notice() {
includes/honeypot4cf7.php CHANGED
@@ -106,9 +106,20 @@ function honeypot4cf7_form_tag_handler( $tag ) {
106
  * Bots beware!
107
  *
108
  */
109
- add_filter( 'wpcf7_spam', 'honeypot4cf7_spam_check', 10, 2 );
110
 
111
- function honeypot4cf7_spam_check( $spam, $submission ) {
 
 
 
 
 
 
 
 
 
 
 
 
112
  if ( $spam ) {
113
  return $spam;
114
  }
@@ -133,14 +144,17 @@ function honeypot4cf7_spam_check( $spam, $submission ) {
133
  if ( $value != '' ) {
134
  // Bots!
135
  $spam = true;
136
- $submission->add_spam_log( array(
137
- 'agent' => 'honeypot',
138
- 'reason' => sprintf(
139
- /* translators: %s: honeypot field ID */
140
- __( 'Something is stuck in the honey. Field ID = %s', 'contact-form-7-honeypot' ),
141
- $hpid
142
- ),
143
- ) );
 
 
 
144
 
145
  $honeypot4cf7_config = honeypot4cf7_get_config();
146
  $honeypot4cf7_config['honeypot_count'] = ( isset( $honeypot4cf7_config['honeypot_count'] ) ) ? $honeypot4cf7_config['honeypot_count'] + 1 : 1;
106
  * Bots beware!
107
  *
108
  */
 
109
 
110
+ if ( version_compare(HONEYPOT4CF7_WPCF7_VERSION, '5.3.0', '>=' ) ) {
111
+ // Newer Spam filter - with log
112
+ add_filter( 'wpcf7_spam', 'honeypot4cf7_spam_check', 10, 2 );
113
+ } elseif ( version_compare(HONEYPOT4CF7_WPCF7_VERSION, '3.0', '>=' ) ) {
114
+ // Older Spam filter - no log
115
+ add_filter( 'wpcf7_spam', 'honeypot4cf7_spam_check', 10, 1 );
116
+ } else {
117
+ // Real old - unsupported
118
+ return false;
119
+ }
120
+
121
+ function honeypot4cf7_spam_check( $spam, $submission = null ) {
122
+
123
  if ( $spam ) {
124
  return $spam;
125
  }
144
  if ( $value != '' ) {
145
  // Bots!
146
  $spam = true;
147
+
148
+ if ( $submission ) {
149
+ $submission->add_spam_log( array(
150
+ 'agent' => 'honeypot',
151
+ 'reason' => sprintf(
152
+ /* translators: %s: honeypot field ID */
153
+ __( 'Something is stuck in the honey. Field ID = %s', 'contact-form-7-honeypot' ),
154
+ $hpid
155
+ ),
156
+ ) );
157
+ }
158
 
159
  $honeypot4cf7_config = honeypot4cf7_get_config();
160
  $honeypot4cf7_config['honeypot_count'] = ( isset( $honeypot4cf7_config['honeypot_count'] ) ) ? $honeypot4cf7_config['honeypot_count'] + 1 : 1;
readme.txt CHANGED
@@ -17,7 +17,9 @@ This simple addon module to the wonderful [Contact Form 7](https://wordpress.org
17
 
18
  The principle of a honeypot is simple -- *bots are stupid*. While some spam is hand-delivered, the vast majority is submitted by bots scripted in a specific (wide-scope) way to submit spam to the largest number of form types. In this way they somewhat blindly fill in fields, regardless of whether the field should be filled in or not. This is how a honeypot catches the bot -- it introduces an additional field in the form that if filled out will trigger the honeypot and flag the submission as spam.
19
 
20
- = RECOMMENDED PLUGIN =
 
 
21
  We highly recommend [Flamingo](https://wordpress.org/plugins/flamingo/) with CF7 and this plugin. Using Flamingo allows you to track spam submissions (via `inbound messages / spam` tab in Flamingo), showing you what got caught in the honeypot and why. Be sure to check your Honeypot settings to turn storing the honeypot on for this.
22
 
23
  = SUPPORT / SOCIALS =
@@ -31,7 +33,7 @@ This plugin does not track users, store any user data, send user data to externa
31
  = LOCALIZATION / TRANSLATION =
32
  If you'd like to translate this plugin, please visit the plugin's [translate.wordpress.org](https://translate.wordpress.org/projects/wp-plugins/contact-form-7-honeypot) page. As of v1.10, all translation is handled there. Version 2.0 brings a bunch of new strings in need of translation, so a huge thank you to the polyglots that contribute!
33
 
34
- = IMPORTANT NOTES =
35
  The latest version of this plugin is designed to work with the latest version of Contact Form 7 and Wordpress. If you are using older versions of either, you're best to find the version of this plugin released around the same time as the version you're using. You can access older versions of this plugin by clicking *Advanced View* on the right of the plugin's page and scrolling to the bottom of the plugin's page. **Use at your own risk**. We strongly recommend upgrading to the latest versions whenever possible.
36
 
37
  == Installation ==
@@ -74,6 +76,7 @@ As of version 2.0, this shouldn't be the case any longer. However, if it is for
74
  You bet! If the honeypot trap is triggered, an email isn't sent, but the form submission is added to the **spam** section of Flamingo so you can review what tripped things up.
75
 
76
  = Why do you have affiliate ads on your settings page? =
 
77
  I realize not everyone loves ads, but daddy's gotta pay the bills. I'm extremely grateful to the numerous users that have donated to the plugin's development over the years, and while that's awesome, I don't think donations will ever come remotely close to covering the time and effort it takes to maintain and support a plugin that now has **nearly 1.5 million downloads** and **more than 300,000 active installs**.
78
 
79
  == Screenshots ==
@@ -82,6 +85,9 @@ I realize not everyone loves ads, but daddy's gotta pay the bills. I'm extremely
82
  2. Honeypot CF7 Form Tag Settings
83
 
84
  == Changelog ==
 
 
 
85
  = 2.0.4 =
86
  Better error checking for missing config problems.
87
 
@@ -158,6 +164,9 @@ Small update for W3C compliance. Thanks [Jeff](http://wordpress.org/support/topi
158
  * Initial release.
159
 
160
  == Upgrade Notice ==
 
 
 
161
  = 2.0.4 =
162
  This fixes some php notices about missing settings. Recommended update.
163
 
17
 
18
  The principle of a honeypot is simple -- *bots are stupid*. While some spam is hand-delivered, the vast majority is submitted by bots scripted in a specific (wide-scope) way to submit spam to the largest number of form types. In this way they somewhat blindly fill in fields, regardless of whether the field should be filled in or not. This is how a honeypot catches the bot -- it introduces an additional field in the form that if filled out will trigger the honeypot and flag the submission as spam.
19
 
20
+ = REQUIRED/RECOMMENDED PLUGINS =
21
+ You will need [Contact Form 7](https://wordpress.org/plugins/contact-form-7/) version 3.0+ at a minimum. It is recommended to use version 5.3+ of CF7, for better spam logging. For the best results, we suggest always using the latest versions of WordPress and CF7.
22
+
23
  We highly recommend [Flamingo](https://wordpress.org/plugins/flamingo/) with CF7 and this plugin. Using Flamingo allows you to track spam submissions (via `inbound messages / spam` tab in Flamingo), showing you what got caught in the honeypot and why. Be sure to check your Honeypot settings to turn storing the honeypot on for this.
24
 
25
  = SUPPORT / SOCIALS =
33
  = LOCALIZATION / TRANSLATION =
34
  If you'd like to translate this plugin, please visit the plugin's [translate.wordpress.org](https://translate.wordpress.org/projects/wp-plugins/contact-form-7-honeypot) page. As of v1.10, all translation is handled there. Version 2.0 brings a bunch of new strings in need of translation, so a huge thank you to the polyglots that contribute!
35
 
36
+ = LEGACY/OLD VERSIONS =
37
  The latest version of this plugin is designed to work with the latest version of Contact Form 7 and Wordpress. If you are using older versions of either, you're best to find the version of this plugin released around the same time as the version you're using. You can access older versions of this plugin by clicking *Advanced View* on the right of the plugin's page and scrolling to the bottom of the plugin's page. **Use at your own risk**. We strongly recommend upgrading to the latest versions whenever possible.
38
 
39
  == Installation ==
76
  You bet! If the honeypot trap is triggered, an email isn't sent, but the form submission is added to the **spam** section of Flamingo so you can review what tripped things up.
77
 
78
  = Why do you have affiliate ads on your settings page? =
79
+
80
  I realize not everyone loves ads, but daddy's gotta pay the bills. I'm extremely grateful to the numerous users that have donated to the plugin's development over the years, and while that's awesome, I don't think donations will ever come remotely close to covering the time and effort it takes to maintain and support a plugin that now has **nearly 1.5 million downloads** and **more than 300,000 active installs**.
81
 
82
  == Screenshots ==
85
  2. Honeypot CF7 Form Tag Settings
86
 
87
  == Changelog ==
88
+ = 2.0.5 =
89
+ Improved backwards compatibility. Solves issues when plugin installed on older versions of CF7.
90
+
91
  = 2.0.4 =
92
  Better error checking for missing config problems.
93
 
164
  * Initial release.
165
 
166
  == Upgrade Notice ==
167
+ = 2.0.5 =
168
+ Fixes some backwards compatibility issues. Recommended update.
169
+
170
  = 2.0.4 =
171
  This fixes some php notices about missing settings. Recommended update.
172