Contact Form 7 Honeypot - Version 1.0

Version Description

Download this release

Release Info

Developer DaoByDesign
Plugin Icon 128x128 Contact Form 7 Honeypot
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (2) hide show
  1. honeypot.php +137 -0
  2. readme.txt +46 -0
honeypot.php ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Contact Form 7 Honeypot
4
+ Plugin URI: http://www.daobydesign.com/free-plugins/honeypot-module-for-contact-form-7-wordpress-plugin
5
+ Description: Add honeypot functionality to the popular Contact Form 7 plugin.
6
+ Author: Dao By Design
7
+ Author URI: http://www.daobydesign.com
8
+ Version: 1.0.0
9
+ */
10
+
11
+ /* Copyright 2011 Dao By Design (email : info@daobydesign.com)
12
+
13
+ This program is free software; you can redistribute it and/or modify
14
+ it under the terms of the GNU General Public License as published by
15
+ the Free Software Foundation; either version 2 of the License, or
16
+ (at your option) any later version.
17
+
18
+ This program is distributed in the hope that it will be useful,
19
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ GNU General Public License for more details.
22
+
23
+ You should have received a copy of the GNU General Public License
24
+ along with this program; if not, write to the Free Software
25
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
+
27
+ ---
28
+
29
+ Thanks to Katz Web Services, Inc. (http://www.katzwebservices.com) for basic plugin structure.
30
+ */
31
+
32
+ add_action('plugins_loaded', 'wpcf7_honeypot_loader', 10);
33
+
34
+ function wpcf7_honeypot_loader() {
35
+ global $pagenow;
36
+ if (function_exists('wpcf7_add_shortcode')) {
37
+ wpcf7_add_shortcode( 'honeypot', 'wpcf7_honeypot_shortcode_handler', true );
38
+ } else {
39
+ if ($pagenow != 'plugins.php') { return; }
40
+ add_action('admin_notices', 'cfhiddenfieldserror');
41
+ wp_enqueue_script('thickbox');
42
+ function cfhiddenfieldserror() {
43
+ $out = '<div class="error" id="messages"><p>';
44
+ if(file_exists(WP_PLUGIN_DIR.'/contact-form-7/wp-contact-form-7.php')) {
45
+ $out .= 'The Contact Form 7 is installed, but <strong>you must activate Contact Form 7</strong> below for the Honeypot Module to work.';
46
+ } else {
47
+ $out .= 'The Contact Form 7 plugin must be installed for the Honeypot Module to work. <a href="'.admin_url('plugin-install.php?tab=plugin-information&plugin=contact-form-7&from=plugins&TB_iframe=true&width=600&height=550').'" class="thickbox" title="Contact Form 7">Install Now.</a>';
48
+ }
49
+ $out .= '</p></div>';
50
+ echo $out;
51
+ }
52
+ }
53
+ }
54
+
55
+
56
+ /**
57
+ ** A base module for [honeypot]
58
+ **/
59
+
60
+ /* Shortcode handler */
61
+ function wpcf7_honeypot_shortcode_handler( $tag ) {
62
+ global $wpcf7_contact_form;
63
+
64
+ if ( ! is_array( $tag ) )
65
+ return '';
66
+
67
+ $type = $tag['type'];
68
+ $name = $tag['name'];
69
+
70
+ if ( empty( $name ) )
71
+ return '';
72
+
73
+ $validation_error = '';
74
+ if ( is_a( $wpcf7_contact_form, 'WPCF7_ContactForm' ) )
75
+ $validation_error = $wpcf7_contact_form->validation_error( $name );
76
+
77
+ $html = '<div style="display:none;" class="hidden">
78
+ <label for="email-wpcf7-hp"><small>Leave this field empty.</small></label>
79
+ <input class="wpcf7-text" type="text" name="email-wpcf7-hp" id="email-wpcf7-hp" value="" size="40" tabindex="3" />
80
+ </div>';
81
+
82
+
83
+ $html = '<span class="wpcf7-form-control-wrap ' . $name . '">' . $html . $validation_error . '</span>';
84
+
85
+ return $html;
86
+ }
87
+
88
+
89
+ /* honeypot filter */
90
+ add_filter( 'wpcf7_validate_honeypot', 'wpcf7_honeypot_filter' ,10,2);
91
+
92
+ function wpcf7_honeypot_filter ($result, $tag) {
93
+ global $wpcf7_contact_form;
94
+ global $user_ID;
95
+
96
+ $type = $tag['type'];
97
+ $name = $tag['name'];
98
+
99
+
100
+ $honeypot = $_POST['email-wpcf7-hp'];
101
+ if ( $honeypot != '' ) {
102
+ $result['valid'] = false;
103
+ //$result['reason'][$name] = wpcf7_get_message( 'Apologies, there was a problem with your submission.' );
104
+ }
105
+
106
+ return $result;
107
+ }
108
+
109
+
110
+ /* Tag generator */
111
+
112
+ add_action( 'admin_init', 'wpcf7_add_tag_generator_honeypot', 35 );
113
+
114
+ function wpcf7_add_tag_generator_honeypot() {
115
+ if (function_exists('wpcf7_add_tag_generator')) {
116
+ wpcf7_add_tag_generator( 'honeypot', __( 'Honeypot', 'wpcf7' ), 'wpcf7-tg-pane-honeypot', 'wpcf7_tg_pane_honeypot' );
117
+ }
118
+ }
119
+
120
+ function wpcf7_tg_pane_honeypot( &$contact_form ) { ?>
121
+ <div id="wpcf7-tg-pane-honeypot" class="hidden">
122
+ <form action="">
123
+ <table>
124
+ <tr><td>
125
+ <?php echo esc_html( __( 'Name', 'wpcf7' ) ); ?>
126
+ <br /><input type="text" name="name" class="tg-name oneline" />
127
+ <br /><em><small><?php echo esc_html( __( 'For better security, change "honeypot" to something less bot-recognizable.', 'wpcf7' ) ); ?></small></em>
128
+ </td><td></td></tr>
129
+ </table>
130
+
131
+ <div class="tg-tag"><?php echo esc_html( __( "Copy this code and paste it into the form left.", 'wpcf7' ) ); ?><br /><input type="text" name="honeypot" class="tag" readonly="readonly" onfocus="this.select()" /></div>
132
+ </form>
133
+ </div>
134
+
135
+ <?php }
136
+
137
+ ?>
readme.txt ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Contact Form 7 Honeypot ===
2
+ Tags: honeypot, antispam, captcha, spam, form, forms, contact form 7, contactform7, contact form, cf7, cforms, Contact Forms 7, Contact Forms, contacts
3
+ Requires at least: 2.8
4
+ Tested up to: 3.5
5
+ Stable tag: trunk
6
+ Contributors: DaoByDesign
7
+ Donate link: http://www.daobydesign.com/buy-us-a-coffee/
8
+
9
+ Contact Form 7 - Adds honeypot functionality to Contact Form 7 forms.
10
+
11
+ == Description ==
12
+
13
+ This simple addition to the wonderful <a href="http://wordpress.org/extend/plugins/contact-form-7/">Contact Form 7</a> plugin adds basic honeypot functionality to thwart spambots without the need for an ugly captcha.
14
+
15
+ The principle of a honeypot is simple -- <em>bots are stupid</em>. 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, irregardless 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 cause the form not to validate.
16
+
17
+ Follow us on [Twitter](http://www.twitter.com/daobydesign) and on [Facebook](http://www.facebook.com/daobydesign) for updates and news.
18
+
19
+ Visit the <a href="http://www.daobydesign.com/free-plugins/honeypot-module-for-contact-form-7-wordpress-plugin">Contact Form 7 Honeypot plugin page</a> for support & additional information.
20
+
21
+ == Installation ==
22
+
23
+ 1. Upload plugin files to your plugins folder <strong>or</strong> install using Wordpress' "Add Plugin" feature -- just search for "Contact Form 7 Honeypot"
24
+ 1. Activate the plugin
25
+ 1. Edit a form in Contact Form 7
26
+ 1. Choose "Honeypot" from the Generate Tag dropdown. <em>Recommended: change the honeypot element's ID.</em>
27
+ 1. Insert the generated tag anywhere in your form. The added field uses inline CSS styles to hide the field from your visitors.
28
+
29
+ == Frequently Asked Questions ==
30
+
31
+ = Will this module stop all my contact form spam? =
32
+
33
+ * Probably not. But it should reduce it to a level whereby you don't require any additonal spam challenges (CAPTCHA, math questions, etc.).
34
+
35
+ = Are honeypots better than CAPTCHAs? =
36
+
37
+ * This largely depends on the quality of the CAPTCHA. Unfortunately the more difficult a CAPTCHA is to break, the more user-unfriendly it is. This honeypot module was created because we don't like CAPTCHA's cluttering up our forms. Our recommendation is to try this module first, and if you find that it doesn't stop enough spam, then employ more challenging anti-spam techniques.
38
+
39
+ = What is the plugin license? =
40
+
41
+ * This plugin is released under a GPL license.
42
+
43
+ == Changelog ==
44
+
45
+ = 1.0.0 =
46
+ * Initial release.