Version Description
General code cleanup, better adherence to WP coding standards and fixes for i18n functions.
Download this release
Release Info
Developer | nocean |
Plugin | Contact Form 7 Honeypot |
Version | 2.0.3 |
Comparing to | |
See all releases |
Code changes from version 2.0.2 to 2.0.3
- honeypot.php +2 -2
- includes/admin.php +131 -81
- includes/honeypot4cf7.php +81 -64
- readme.txt +4 -1
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.
|
9 |
Text Domain: contact-form-7-honeypot
|
10 |
Domain Path: /languages/
|
11 |
*/
|
12 |
|
13 |
-
define( 'HONEYPOT4CF7_VERSION', '2.0.
|
14 |
define( 'HONEYPOT4CF7_PLUGIN', __FILE__ );
|
15 |
define( 'HONEYPOT4CF7_PLUGIN_BASENAME', plugin_basename( HONEYPOT4CF7_PLUGIN ) );
|
16 |
define( 'HONEYPOT4CF7_PLUGIN_NAME', trim( dirname( HONEYPOT4CF7_PLUGIN_BASENAME ), '/' ) );
|
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.3
|
9 |
Text Domain: contact-form-7-honeypot
|
10 |
Domain Path: /languages/
|
11 |
*/
|
12 |
|
13 |
+
define( 'HONEYPOT4CF7_VERSION', '2.0.3' );
|
14 |
define( 'HONEYPOT4CF7_PLUGIN', __FILE__ );
|
15 |
define( 'HONEYPOT4CF7_PLUGIN_BASENAME', plugin_basename( HONEYPOT4CF7_PLUGIN ) );
|
16 |
define( 'HONEYPOT4CF7_PLUGIN_NAME', trim( dirname( HONEYPOT4CF7_PLUGIN_BASENAME ), '/' ) );
|
includes/admin.php
CHANGED
@@ -9,30 +9,34 @@
|
|
9 |
add_action( 'admin_init', 'honeypot4cf7_has_parent_plugin' );
|
10 |
function honeypot4cf7_has_parent_plugin() {
|
11 |
// Get Options
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
$honeypot4cf7_config = honeypot4cf7_restore_config();
|
16 |
}
|
17 |
|
18 |
-
if ( is_admin() && current_user_can( 'activate_plugins' ) && !is_plugin_active( HONEYPOT4CF7_DEP_PLUGIN ) && empty( $honeypot4cf7_config['honeypot_cf7_req_msg_dismissed'])) {
|
19 |
add_action( 'admin_notices', 'honeypot4cf7_nocf7_notice' );
|
20 |
}
|
21 |
|
22 |
// This resets dismissed notice
|
23 |
-
if (is_plugin_active( HONEYPOT4CF7_DEP_PLUGIN ) && $honeypot4cf7_config['honeypot_cf7_req_msg_dismissed']
|
24 |
$honeypot4cf7_config['honeypot_cf7_req_msg_dismissed'] = 0;
|
25 |
update_option( 'honeypot4cf7_config', $honeypot4cf7_config );
|
26 |
}
|
27 |
}
|
28 |
|
29 |
-
function honeypot4cf7_nocf7_notice() {
|
|
|
30 |
<div class="notice error honeypot4cf7-notice is-dismissible">
|
31 |
<p>
|
32 |
-
<?php
|
|
|
|
|
33 |
__('%s must be installed and activated for the CF7 Honeypot plugin to work', 'contact-form-7-honeypot'),
|
34 |
-
'<a href="'.admin_url('plugin-install.php?tab=search&s=contact+form+7').'">Contact Form 7</a>'
|
35 |
-
);
|
|
|
36 |
</p>
|
37 |
</div>
|
38 |
<?php
|
@@ -42,7 +46,7 @@ function honeypot4cf7_nocf7_notice() { ?>
|
|
42 |
add_action( 'wp_ajax_honeypot4cf7_dismiss_notice', 'honeypot4cf7_dismiss_notice' );
|
43 |
|
44 |
function honeypot4cf7_dismiss_notice() {
|
45 |
-
$honeypot4cf7_config = get_option('honeypot4cf7_config');
|
46 |
$honeypot4cf7_config['honeypot_cf7_req_msg_dismissed'] = 1;
|
47 |
update_option( 'honeypot4cf7_config', $honeypot4cf7_config );
|
48 |
}
|
@@ -53,9 +57,9 @@ function honeypot4cf7_dismiss_notice() {
|
|
53 |
* This cleans up on uninstall.
|
54 |
*
|
55 |
*/
|
56 |
-
register_uninstall_hook(HONEYPOT4CF7_PLUGIN, 'honeypot4cf7_uninstall');
|
57 |
function honeypot4cf7_uninstall() {
|
58 |
-
delete_option('honeypot4cf7_config');
|
59 |
}
|
60 |
|
61 |
|
@@ -65,17 +69,18 @@ function honeypot4cf7_uninstall() {
|
|
65 |
*
|
66 |
*********** */
|
67 |
function honeypot4cf7_on_activation() {
|
68 |
-
if ( ! current_user_can( 'activate_plugins' ) )
|
69 |
return;
|
|
|
70 |
|
71 |
$plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : '';
|
72 |
check_admin_referer( "activate-plugin_{$plugin}" );
|
73 |
|
74 |
// Initialize option values
|
75 |
-
return honeypot4cf7_restore_config('init');
|
76 |
}
|
77 |
|
78 |
-
register_activation_hook(HONEYPOT4CF7_PLUGIN, 'honeypot4cf7_on_activation');
|
79 |
|
80 |
|
81 |
add_filter( 'plugin_action_links_'.HONEYPOT4CF7_PLUGIN_BASENAME, 'honeypot4cf7_settings_link' );
|
@@ -86,9 +91,9 @@ function honeypot4cf7_settings_link( $links ) {
|
|
86 |
get_admin_url() . 'admin.php'
|
87 |
) );
|
88 |
|
89 |
-
$settings_link = "<a href='$url'>" . __( 'Settings' ) . '</a>';
|
90 |
|
91 |
-
array_push($links
|
92 |
|
93 |
return $links;
|
94 |
}
|
@@ -99,13 +104,13 @@ function honeypot4cf7_settings_link( $links ) {
|
|
99 |
* Restore built-in defaults, optionally overwriting existing values
|
100 |
*
|
101 |
*********** */
|
102 |
-
function honeypot4cf7_restore_config($type=false) {
|
103 |
// Make sure the current user can manage options
|
104 |
-
if (!current_user_can('manage_options')) {
|
105 |
return;
|
106 |
}
|
107 |
|
108 |
-
$honeypot4cf7_config = get_option('honeypot4cf7_config');
|
109 |
|
110 |
if (empty($honeypot4cf7_config) || 'reset' == $type) {
|
111 |
|
@@ -113,13 +118,13 @@ function honeypot4cf7_restore_config($type=false) {
|
|
113 |
'store_honeypot' => 0,
|
114 |
'placeholder' => '',
|
115 |
'accessibility_message' => '',
|
116 |
-
'w3c_valid_autocomplete' => array('false'),
|
117 |
-
'move_inline_css' => array('false'),
|
118 |
-
'nomessage' => array('false'),
|
119 |
-
'honeypot_count' => (!empty($honeypot4cf7_config['honeypot_count'])) ? $honeypot4cf7_config['honeypot_count'] : 0,
|
120 |
-
'honeypot_install_date' => (!empty($honeypot4cf7_config['honeypot_install_date'])) ? $honeypot4cf7_config['honeypot_install_date'] : time(),
|
121 |
'honeypot_cf7_req_msg_dismissed' => 0,
|
122 |
-
'honeypot4cf7_version' => HONEYPOT4CF7_VERSION
|
123 |
);
|
124 |
|
125 |
$honeypot4cf7_config = $honeypot4cf7_config_defaults;
|
@@ -137,123 +142,147 @@ function honeypot4cf7_restore_config($type=false) {
|
|
137 |
*
|
138 |
*********** */
|
139 |
|
140 |
-
add_action('admin_menu', 'honeypot4cf7_admin_menu');
|
141 |
function honeypot4cf7_admin_menu() {
|
142 |
-
add_submenu_page(
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
}
|
144 |
|
145 |
function honeypot4cf7_admin_page() {
|
146 |
// Reset Values
|
147 |
-
if (!empty($_POST['clear'])) {
|
148 |
-
honeypot4cf7_restore_config('reset');
|
149 |
-
echo '<div id="message" class="updated"><p>'.esc_html(__('The settings have been reset to their defaults.','contact-form-7-honeypot')).'</p></div>';
|
150 |
}
|
151 |
|
152 |
// Get Options
|
153 |
-
$honeypot4cf7_config = $honeypot4cf7_config = get_option('honeypot4cf7_config');
|
154 |
|
155 |
// Save Values
|
156 |
-
if (!empty($_POST['save'])) {
|
157 |
|
158 |
// Check nonce and user ability
|
159 |
-
if (
|
160 |
|
161 |
// Validate & Sanitize
|
162 |
$honeypot4cf7_config_update = array(
|
163 |
-
'store_honeypot' => (isset($_POST['honeypot4cf7_store'])) ? $_POST['honeypot4cf7_store'] : 0,
|
164 |
-
'placeholder' => (isset($_POST['honeypot4cf7_placeholder'])) ? $_POST['honeypot4cf7_placeholder'] : '',
|
165 |
-
'accessibility_message' => (isset($_POST['honeypot4cf7_accessibility_message'])) ? $_POST['honeypot4cf7_accessibility_message'] : '',
|
166 |
-
'w3c_valid_autocomplete' => (isset($_POST['honeypot4cf7_w3c_valid_autocomplete'])) ? $_POST['honeypot4cf7_w3c_valid_autocomplete'] : array('false'),
|
167 |
-
'move_inline_css' => (isset($_POST['honeypot4cf7_move_inline_css'])) ? $_POST['honeypot4cf7_move_inline_css'] : array('false'),
|
168 |
-
'nomessage' => (isset($_POST['honeypot4cf7_nomessage'])) ? $_POST['honeypot4cf7_nomessage'] : array('false'),
|
169 |
);
|
170 |
|
171 |
-
$honeypot4cf7_config = array_replace($honeypot4cf7_config, $honeypot4cf7_config_update);
|
172 |
|
173 |
update_option( 'honeypot4cf7_config', $honeypot4cf7_config );
|
174 |
|
175 |
-
echo '<div id="message" class="updated"><p>'.esc_html(__('The changes have been saved.','contact-form-7-honeypot')).'</p></div>';
|
176 |
}
|
177 |
}
|
178 |
?>
|
179 |
|
180 |
<div class="wrap" class="honeypot4cf7-admin" id="honeypot4cf7-admin-page">
|
181 |
-
<h1 class="honeypot4cf7-admin__title"
|
|
|
|
|
182 |
<div class="honeypot4cf7-admin__primary">
|
183 |
<div class="honeypot4cf7-admin__box">
|
184 |
<form action="" method="post" id="honeypot4cf7_options_form" name="honeypot4cf7_options_form">
|
185 |
-
<?php wp_nonce_field('honeypot4cf7-submit', 'honeypot4cf7_nonce'); ?>
|
186 |
<a href="https://wordpress.org/support/plugin/contact-form-7-honeypot/" target="_blank" class="honeypot4cf7_admin__support-link">
|
187 |
<span class="dashicons dashicons-editor-help"></span>
|
188 |
-
<?php esc_html_e(
|
189 |
</a>
|
190 |
-
<h3><span class="dashicons dashicons-admin-generic"></span> <?php esc_html_e('Honeypot Settings'); ?></h3>
|
191 |
<table class="form-table">
|
192 |
<tbody>
|
193 |
<tr valign="top">
|
194 |
-
<th><label for="honeypot4cf7__store-honeypot"><?php esc_html_e(
|
195 |
<td>
|
196 |
-
<input type="checkbox" name="honeypot4cf7_store" id="honeypot4cf7__store-honeypot" value="1" <?php checked($honeypot4cf7_config['store_honeypot'],1); ?>>
|
197 |
</td>
|
198 |
</tr>
|
199 |
<tr valign="top">
|
200 |
-
<td class="description" colspan="2"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
</tr>
|
202 |
|
203 |
<tr valign="top">
|
204 |
-
<th><label for="honeypot4cf7__placeholder"><?php esc_html_e(
|
205 |
<td>
|
206 |
-
<input type="text" class="regular-text" name="honeypot4cf7_placeholder" id="honeypot4cf7__placeholder" value="<?php echo sanitize_text_field($honeypot4cf7_config['placeholder']); ?>">
|
207 |
</td>
|
208 |
</tr>
|
209 |
<tr valign="top">
|
210 |
-
<td class="description" colspan="2"><?php esc_html_e(
|
211 |
</tr>
|
212 |
|
213 |
<tr valign="top">
|
214 |
-
<th><label for="honeypot4cf7__accessibility_message"><?php esc_html_e(
|
215 |
<td>
|
216 |
-
<input type="text" class="regular-text" name="honeypot4cf7_accessibility_message" id="honeypot4cf7__accessibility_message" value="<?php echo sanitize_text_field($honeypot4cf7_config['accessibility_message']); ?>">
|
217 |
</td>
|
218 |
</tr>
|
219 |
<tr valign="top">
|
220 |
-
<td class="description" colspan="2"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
</tr>
|
222 |
|
223 |
<tr valign="top">
|
224 |
-
<th><label for="honeypot4cf7__w3c-valid-autocomplete"><?php esc_html_e(
|
225 |
<td>
|
226 |
-
<input type="checkbox" name="honeypot4cf7_w3c_valid_autocomplete[]" id="honeypot4cf7__w3c-valid-autocomplete" value="true" <?php checked($honeypot4cf7_config['w3c_valid_autocomplete'][0],'true'); ?>>
|
227 |
</td>
|
228 |
</tr>
|
229 |
<tr valign="top">
|
230 |
-
<td class="description" colspan="2"><?php esc_html_e(
|
231 |
</tr>
|
232 |
|
233 |
<tr valign="top">
|
234 |
-
<th><label for="honeypot4cf7__move_inline_css"><?php esc_html_e(
|
235 |
<td>
|
236 |
-
<input type="checkbox" name="honeypot4cf7_move_inline_css[]" id="honeypot4cf7__move_inline_css" value="true" <?php checked($honeypot4cf7_config['move_inline_css'][0],'true'); ?>>
|
237 |
</td>
|
238 |
</tr>
|
239 |
<tr valign="top">
|
240 |
-
<td class="description" colspan="2"><?php esc_html_e(
|
241 |
</tr>
|
242 |
|
243 |
<tr valign="top">
|
244 |
-
<th><label for="honeypot4cf7__nomessage"><?php esc_html_e(
|
245 |
<td>
|
246 |
-
<input type="checkbox" name="honeypot4cf7_nomessage[]" id="honeypot4cf7__nomessage" value="true" <?php checked($honeypot4cf7_config['nomessage'][0],'true'); ?>>
|
247 |
</td>
|
248 |
</tr>
|
249 |
<tr valign="top">
|
250 |
-
<td class="description" colspan="2"><?php esc_html_e(
|
251 |
</tr>
|
252 |
</tbody>
|
253 |
</table>
|
254 |
<p class="submit">
|
255 |
-
<input name="save" id="save" class="button button-primary" value="<?php
|
256 |
-
<input name="clear" id="reset" class="button" value="<?php
|
257 |
|
258 |
</p>
|
259 |
</form>
|
@@ -266,11 +295,15 @@ function honeypot4cf7_admin_page() {
|
|
266 |
</div>
|
267 |
<div class="honeypot4cf7-admin__box honeypot4cf7-admin__box--count-message">
|
268 |
<p>
|
269 |
-
<span class="dashicons dashicons-chart-area"></span>
|
270 |
-
|
271 |
-
|
272 |
-
date
|
273 |
-
|
|
|
|
|
|
|
|
|
274 |
</p>
|
275 |
</div>
|
276 |
</div>
|
@@ -278,18 +311,21 @@ function honeypot4cf7_admin_page() {
|
|
278 |
<div class="honeypot4cf7-admin__secondary">
|
279 |
<div class="honeypot4cf7-admin__box honeypot4cf7-admin__box--coffee">
|
280 |
<p class="honeypot4cf7-admin__coffee-message">
|
281 |
-
<?php esc_html_e(
|
282 |
<a href="http://www.nocean.ca/buy-us-a-coffee/" target="_blank" class="button button-primary"><strong>
|
283 |
-
<span class="dashicons dashicons-coffee"></span> <?php esc_html_e(
|
284 |
</strong></a>
|
285 |
</p>
|
286 |
</div>
|
287 |
<div class="honeypot4cf7-admin__box">
|
288 |
<p class="honeypot4cf7__banner-ad-message">
|
289 |
-
<?php
|
|
|
|
|
290 |
__( 'We use %s and find it incredibly valuable. If you choose to use them too (even for free), you are helping continued development and support of this plugin. Thank you!', 'contact-form-7-honeypot' ),
|
291 |
'<a href="https://shareasale.com/r.cfm?b=1537039&u=2748065&m=97231&urllink=&afftrack=0" target="_blank">Semrush</a>'
|
292 |
-
);
|
|
|
293 |
</p>
|
294 |
<div class="honeypot4cf7__banner-ad honeypot4cf7__banner-ad--2">
|
295 |
<a target="_blank" href="https://shareasale.com/r.cfm?b=1550765&u=2748065&m=97231&urllink=&afftrack="><img src="<?php echo HONEYPOT4CF7_PLUGIN_DIR_URL; ?>/includes/images/banners/semrush-2_300x250.png" border="0" alt="position tracking" /></a>
|
@@ -297,8 +333,22 @@ function honeypot4cf7_admin_page() {
|
|
297 |
</div>
|
298 |
|
299 |
<div class="honeypot4cf7-admin__box honeypot4cf7-admin__rate-us">
|
300 |
-
<div class="honeypot4cf7-admin__stars"
|
301 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
302 |
</div>
|
303 |
</div>
|
304 |
</div>
|
@@ -311,10 +361,10 @@ function honeypot4cf7_admin_page() {
|
|
311 |
* Add admin page CSS
|
312 |
*
|
313 |
*********** */
|
314 |
-
function honeypot4cf7_admin_enqueues($hook) {
|
315 |
-
wp_enqueue_script( 'honeypot4cf7-admin-js', plugins_url( 'includes/js/notice-update.js', HONEYPOT4CF7_PLUGIN ), array( 'jquery' ), HONEYPOT4CF7_VERSION, true
|
316 |
-
if( strpos($hook, 'honeypot4cf7') !== false ) {
|
317 |
-
wp_enqueue_style( 'honeypot4cf7-admin-css', plugins_url( 'includes/css/styles.css', HONEYPOT4CF7_PLUGIN), array(), HONEYPOT4CF7_VERSION, 'all');
|
318 |
}
|
319 |
}
|
320 |
add_action( 'admin_enqueue_scripts', 'honeypot4cf7_admin_enqueues' );
|
9 |
add_action( 'admin_init', 'honeypot4cf7_has_parent_plugin' );
|
10 |
function honeypot4cf7_has_parent_plugin() {
|
11 |
// Get Options
|
12 |
+
$honeypot4cf7_config = get_option( 'honeypot4cf7_config' );
|
13 |
+
|
14 |
+
if ( ! $honeypot4cf7_config ) {
|
15 |
$honeypot4cf7_config = honeypot4cf7_restore_config();
|
16 |
}
|
17 |
|
18 |
+
if ( is_admin() && current_user_can( 'activate_plugins' ) && !is_plugin_active( HONEYPOT4CF7_DEP_PLUGIN ) && empty( $honeypot4cf7_config['honeypot_cf7_req_msg_dismissed'] ) ) {
|
19 |
add_action( 'admin_notices', 'honeypot4cf7_nocf7_notice' );
|
20 |
}
|
21 |
|
22 |
// This resets dismissed notice
|
23 |
+
if ( is_plugin_active( HONEYPOT4CF7_DEP_PLUGIN ) && $honeypot4cf7_config['honeypot_cf7_req_msg_dismissed'] === 1 ) {
|
24 |
$honeypot4cf7_config['honeypot_cf7_req_msg_dismissed'] = 0;
|
25 |
update_option( 'honeypot4cf7_config', $honeypot4cf7_config );
|
26 |
}
|
27 |
}
|
28 |
|
29 |
+
function honeypot4cf7_nocf7_notice() {
|
30 |
+
?>
|
31 |
<div class="notice error honeypot4cf7-notice is-dismissible">
|
32 |
<p>
|
33 |
+
<?php
|
34 |
+
printf(
|
35 |
+
/* translators: %s: Link to Contact Form 7 plugin page. */
|
36 |
__('%s must be installed and activated for the CF7 Honeypot plugin to work', 'contact-form-7-honeypot'),
|
37 |
+
'<a href="'.admin_url('plugin-install.php?tab=search&s=contact+form+7').'">'.__('Contact Form 7','contact-form-7-honeypot').'</a>'
|
38 |
+
);
|
39 |
+
?>
|
40 |
</p>
|
41 |
</div>
|
42 |
<?php
|
46 |
add_action( 'wp_ajax_honeypot4cf7_dismiss_notice', 'honeypot4cf7_dismiss_notice' );
|
47 |
|
48 |
function honeypot4cf7_dismiss_notice() {
|
49 |
+
$honeypot4cf7_config = get_option( 'honeypot4cf7_config' );
|
50 |
$honeypot4cf7_config['honeypot_cf7_req_msg_dismissed'] = 1;
|
51 |
update_option( 'honeypot4cf7_config', $honeypot4cf7_config );
|
52 |
}
|
57 |
* This cleans up on uninstall.
|
58 |
*
|
59 |
*/
|
60 |
+
register_uninstall_hook( HONEYPOT4CF7_PLUGIN, 'honeypot4cf7_uninstall' );
|
61 |
function honeypot4cf7_uninstall() {
|
62 |
+
delete_option( 'honeypot4cf7_config' );
|
63 |
}
|
64 |
|
65 |
|
69 |
*
|
70 |
*********** */
|
71 |
function honeypot4cf7_on_activation() {
|
72 |
+
if ( ! current_user_can( 'activate_plugins' ) ) {
|
73 |
return;
|
74 |
+
}
|
75 |
|
76 |
$plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : '';
|
77 |
check_admin_referer( "activate-plugin_{$plugin}" );
|
78 |
|
79 |
// Initialize option values
|
80 |
+
return honeypot4cf7_restore_config( 'init' );
|
81 |
}
|
82 |
|
83 |
+
register_activation_hook( HONEYPOT4CF7_PLUGIN, 'honeypot4cf7_on_activation' );
|
84 |
|
85 |
|
86 |
add_filter( 'plugin_action_links_'.HONEYPOT4CF7_PLUGIN_BASENAME, 'honeypot4cf7_settings_link' );
|
91 |
get_admin_url() . 'admin.php'
|
92 |
) );
|
93 |
|
94 |
+
$settings_link = "<a href='$url'>" . __( 'Settings', 'contact-form-7-honeypot' ) . '</a>';
|
95 |
|
96 |
+
array_push( $links, $settings_link );
|
97 |
|
98 |
return $links;
|
99 |
}
|
104 |
* Restore built-in defaults, optionally overwriting existing values
|
105 |
*
|
106 |
*********** */
|
107 |
+
function honeypot4cf7_restore_config( $type = false ) {
|
108 |
// Make sure the current user can manage options
|
109 |
+
if ( ! current_user_can( 'manage_options' ) ) {
|
110 |
return;
|
111 |
}
|
112 |
|
113 |
+
$honeypot4cf7_config = get_option( 'honeypot4cf7_config' );
|
114 |
|
115 |
if (empty($honeypot4cf7_config) || 'reset' == $type) {
|
116 |
|
118 |
'store_honeypot' => 0,
|
119 |
'placeholder' => '',
|
120 |
'accessibility_message' => '',
|
121 |
+
'w3c_valid_autocomplete' => array( 'false' ),
|
122 |
+
'move_inline_css' => array( 'false' ),
|
123 |
+
'nomessage' => array( 'false' ),
|
124 |
+
'honeypot_count' => ( ! empty( $honeypot4cf7_config['honeypot_count'] ) ) ? $honeypot4cf7_config['honeypot_count'] : 0,
|
125 |
+
'honeypot_install_date' => ( ! empty( $honeypot4cf7_config['honeypot_install_date'] ) ) ? $honeypot4cf7_config['honeypot_install_date'] : time(),
|
126 |
'honeypot_cf7_req_msg_dismissed' => 0,
|
127 |
+
'honeypot4cf7_version' => HONEYPOT4CF7_VERSION,
|
128 |
);
|
129 |
|
130 |
$honeypot4cf7_config = $honeypot4cf7_config_defaults;
|
142 |
*
|
143 |
*********** */
|
144 |
|
145 |
+
add_action( 'admin_menu', 'honeypot4cf7_admin_menu' );
|
146 |
function honeypot4cf7_admin_menu() {
|
147 |
+
add_submenu_page(
|
148 |
+
'wpcf7',
|
149 |
+
__('Honeypot for Conctact Form 7', 'contact-form-7-honeypot'),
|
150 |
+
__('Honeypot', 'contact-form-7-honeypot'),
|
151 |
+
'manage_options','honeypot4cf7',
|
152 |
+
'honeypot4cf7_admin_page'
|
153 |
+
);
|
154 |
}
|
155 |
|
156 |
function honeypot4cf7_admin_page() {
|
157 |
// Reset Values
|
158 |
+
if ( ! empty( $_POST['clear'] ) ) {
|
159 |
+
honeypot4cf7_restore_config( 'reset' );
|
160 |
+
echo '<div id="message" class="updated"><p>'.esc_html( __('The settings have been reset to their defaults.', 'contact-form-7-honeypot' ) ).'</p></div>';
|
161 |
}
|
162 |
|
163 |
// Get Options
|
164 |
+
$honeypot4cf7_config = $honeypot4cf7_config = get_option( 'honeypot4cf7_config' );
|
165 |
|
166 |
// Save Values
|
167 |
+
if ( ! empty( $_POST['save'] ) ) {
|
168 |
|
169 |
// Check nonce and user ability
|
170 |
+
if (check_admin_referer( 'honeypot4cf7-submit', 'honeypot4cf7_nonce' ) && current_user_can( 'manage_options' ) ) {
|
171 |
|
172 |
// Validate & Sanitize
|
173 |
$honeypot4cf7_config_update = array(
|
174 |
+
'store_honeypot' => ( isset( $_POST['honeypot4cf7_store'] ) ) ? $_POST['honeypot4cf7_store'] : 0,
|
175 |
+
'placeholder' => ( isset( $_POST['honeypot4cf7_placeholder'] ) ) ? $_POST['honeypot4cf7_placeholder'] : '',
|
176 |
+
'accessibility_message' => ( isset( $_POST['honeypot4cf7_accessibility_message'] ) ) ? $_POST['honeypot4cf7_accessibility_message'] : '',
|
177 |
+
'w3c_valid_autocomplete' => ( isset( $_POST['honeypot4cf7_w3c_valid_autocomplete'] ) ) ? $_POST['honeypot4cf7_w3c_valid_autocomplete'] : array( 'false' ),
|
178 |
+
'move_inline_css' => ( isset( $_POST['honeypot4cf7_move_inline_css'] ) ) ? $_POST['honeypot4cf7_move_inline_css'] : array( 'false' ),
|
179 |
+
'nomessage' => ( isset( $_POST['honeypot4cf7_nomessage'] ) ) ? $_POST['honeypot4cf7_nomessage'] : array( 'false' ),
|
180 |
);
|
181 |
|
182 |
+
$honeypot4cf7_config = array_replace( $honeypot4cf7_config, $honeypot4cf7_config_update );
|
183 |
|
184 |
update_option( 'honeypot4cf7_config', $honeypot4cf7_config );
|
185 |
|
186 |
+
echo '<div id="message" class="updated"><p>' . esc_html( __( 'The changes have been saved.', 'contact-form-7-honeypot' ) ).'</p></div>';
|
187 |
}
|
188 |
}
|
189 |
?>
|
190 |
|
191 |
<div class="wrap" class="honeypot4cf7-admin" id="honeypot4cf7-admin-page">
|
192 |
+
<h1 class="honeypot4cf7-admin__title">
|
193 |
+
<?php esc_html_e( 'Honeypot for Contact Form 7', 'contact-form-7-honeypot' ); ?> <span><?php echo esc_html( 'v' . HONEYPOT4CF7_VERSION ); ?>
|
194 |
+
</h1>
|
195 |
<div class="honeypot4cf7-admin__primary">
|
196 |
<div class="honeypot4cf7-admin__box">
|
197 |
<form action="" method="post" id="honeypot4cf7_options_form" name="honeypot4cf7_options_form">
|
198 |
+
<?php wp_nonce_field( 'honeypot4cf7-submit', 'honeypot4cf7_nonce' ); ?>
|
199 |
<a href="https://wordpress.org/support/plugin/contact-form-7-honeypot/" target="_blank" class="honeypot4cf7_admin__support-link">
|
200 |
<span class="dashicons dashicons-editor-help"></span>
|
201 |
+
<?php esc_html_e( 'Get Support', 'contact-form-7-honeypot' ); ?>
|
202 |
</a>
|
203 |
+
<h3><span class="dashicons dashicons-admin-generic"></span> <?php esc_html_e( 'Honeypot Settings', 'contact-form-7-honeypot' ); ?></h3>
|
204 |
<table class="form-table">
|
205 |
<tbody>
|
206 |
<tr valign="top">
|
207 |
+
<th><label for="honeypot4cf7__store-honeypot"><?php esc_html_e( 'Store Honeypot Value', 'contact-form-7-honeypot' ); ?></label></th>
|
208 |
<td>
|
209 |
+
<input type="checkbox" name="honeypot4cf7_store" id="honeypot4cf7__store-honeypot" value="1" <?php checked( $honeypot4cf7_config['store_honeypot'], 1 ); ?>>
|
210 |
</td>
|
211 |
</tr>
|
212 |
<tr valign="top">
|
213 |
+
<td class="description" colspan="2">
|
214 |
+
<?php
|
215 |
+
printf(
|
216 |
+
/* translators: 1: Link to Flamingo plugin page */
|
217 |
+
__( '(Recommended) By default the Honeypot field is not stored with other fields in form-saving plugins like %1$s. However, saving the field can be useful to see what spam bots are leaving behind to help you improve your spam stopping superpowers. If you\'d like to store the value of the field, simply check this box (and install %1$s).', 'contact-form-7-honeypot' ),
|
218 |
+
'<a href="https://wordpress.org/plugins/flamingo/" target="_blank">' . __( 'Flamingo', 'contact-form-7-honeypot' ) . '</a>'
|
219 |
+
);
|
220 |
+
?>
|
221 |
+
</td>
|
222 |
</tr>
|
223 |
|
224 |
<tr valign="top">
|
225 |
+
<th><label for="honeypot4cf7__placeholder"><?php esc_html_e( 'Global Placeholder', 'contact-form-7-honeypot' ); ?></label></th>
|
226 |
<td>
|
227 |
+
<input type="text" class="regular-text" name="honeypot4cf7_placeholder" id="honeypot4cf7__placeholder" value="<?php echo sanitize_text_field( $honeypot4cf7_config['placeholder'] ); ?>">
|
228 |
</td>
|
229 |
</tr>
|
230 |
<tr valign="top">
|
231 |
+
<td class="description" colspan="2"><?php esc_html_e( 'If using placeholders on other fields, this can help honeypot mimic a "real" field. This can be overridden in the contact form. If you\'re unsure, leave blank.', 'contact-form-7-honeypot' ); ?></td>
|
232 |
</tr>
|
233 |
|
234 |
<tr valign="top">
|
235 |
+
<th><label for="honeypot4cf7__accessibility_message"><?php esc_html_e( 'Accessibility Message', 'contact-form-7-honeypot' ); ?></label></th>
|
236 |
<td>
|
237 |
+
<input type="text" class="regular-text" name="honeypot4cf7_accessibility_message" id="honeypot4cf7__accessibility_message" value="<?php echo sanitize_text_field( $honeypot4cf7_config['accessibility_message'] ); ?>">
|
238 |
</td>
|
239 |
</tr>
|
240 |
<tr valign="top">
|
241 |
+
<td class="description" colspan="2">
|
242 |
+
<?php
|
243 |
+
printf(
|
244 |
+
/* translators: %s: default value */
|
245 |
+
__( 'You can customize the (hidden) accessibility message, or just leave it the default value: %s', 'contact-form-7-honeypot' ),
|
246 |
+
'<em>' . __( 'Please leave this field empty.', 'contact-form-7-honeypot' ) . '</em>'
|
247 |
+
);
|
248 |
+
?>
|
249 |
+
</td>
|
250 |
</tr>
|
251 |
|
252 |
<tr valign="top">
|
253 |
+
<th><label for="honeypot4cf7__w3c-valid-autocomplete"><?php esc_html_e( 'Use Standard Autocomplete Value', 'contact-form-7-honeypot' ); ?></label></th>
|
254 |
<td>
|
255 |
+
<input type="checkbox" name="honeypot4cf7_w3c_valid_autocomplete[]" id="honeypot4cf7__w3c-valid-autocomplete" value="true" <?php checked( $honeypot4cf7_config['w3c_valid_autocomplete'][0], 'true' ); ?>>
|
256 |
</td>
|
257 |
</tr>
|
258 |
<tr valign="top">
|
259 |
+
<td class="description" colspan="2"><?php esc_html_e( 'To assure the honeypot isn\'t auto-completed by a browser, we add an atypical "autocomplete" attribute value. If you have any problems with this, you can switch it to the more standard (but less effective) "off" value. If you\'re unsure, leave this unchecked.', 'contact-form-7-honeypot' ); ?></td>
|
260 |
</tr>
|
261 |
|
262 |
<tr valign="top">
|
263 |
+
<th><label for="honeypot4cf7__move_inline_css"><?php esc_html_e( 'Move Inline CSS', 'contact-form-7-honeypot' ); ?></label></th>
|
264 |
<td>
|
265 |
+
<input type="checkbox" name="honeypot4cf7_move_inline_css[]" id="honeypot4cf7__move_inline_css" value="true" <?php checked( $honeypot4cf7_config['move_inline_css'][0], 'true' ); ?>>
|
266 |
</td>
|
267 |
</tr>
|
268 |
<tr valign="top">
|
269 |
+
<td class="description" colspan="2"><?php esc_html_e( 'By default Honeypot uses inline CSS on the honeypot field to hide it. Checking this box moves that CSS to the footer of the page. It may help confuse bots.', 'contact-form-7-honeypot' ); ?></td>
|
270 |
</tr>
|
271 |
|
272 |
<tr valign="top">
|
273 |
+
<th><label for="honeypot4cf7__nomessage"><?php esc_html_e( 'Disable Accessibility Label', 'contact-form-7-honeypot' ); ?></label></th>
|
274 |
<td>
|
275 |
+
<input type="checkbox" name="honeypot4cf7_nomessage[]" id="honeypot4cf7__nomessage" value="true" <?php checked( $honeypot4cf7_config['nomessage'][0], 'true' ); ?>>
|
276 |
</td>
|
277 |
</tr>
|
278 |
<tr valign="top">
|
279 |
+
<td class="description" colspan="2"><?php esc_html_e( 'If checked, the accessibility label will not be generated. This is not recommended, but may improve spam blocking. If you\'re unsure, leave this unchecked.', 'contact-form-7-honeypot' ); ?></td>
|
280 |
</tr>
|
281 |
</tbody>
|
282 |
</table>
|
283 |
<p class="submit">
|
284 |
+
<input name="save" id="save" class="button button-primary" value="<?php esc_attr_e( 'Save', 'contact-form-7-honeypot' ); ?>" type="submit" />
|
285 |
+
<input name="clear" id="reset" class="button" value="<?php esc_attr_e( 'Reset to Defaults', 'contact-form-7-honeypot' ); ?>" type="submit" />
|
286 |
|
287 |
</p>
|
288 |
</form>
|
295 |
</div>
|
296 |
<div class="honeypot4cf7-admin__box honeypot4cf7-admin__box--count-message">
|
297 |
<p>
|
298 |
+
<span class="dashicons dashicons-chart-area"></span>
|
299 |
+
<?php
|
300 |
+
printf(
|
301 |
+
/* translators: 1: spam count 2: install date */
|
302 |
+
__( 'Honeypot has stopped %1$s spam submissions since %2$s', 'contact-form-7-honeypot' ),
|
303 |
+
'<strong>' . $honeypot4cf7_config['honeypot_count'] . '</strong>',
|
304 |
+
date( get_option( 'date_format' ), $honeypot4cf7_config['honeypot_install_date'] )
|
305 |
+
);
|
306 |
+
?>
|
307 |
</p>
|
308 |
</div>
|
309 |
</div>
|
311 |
<div class="honeypot4cf7-admin__secondary">
|
312 |
<div class="honeypot4cf7-admin__box honeypot4cf7-admin__box--coffee">
|
313 |
<p class="honeypot4cf7-admin__coffee-message">
|
314 |
+
<?php esc_html_e( 'Do you like Honeypot for CF7? Consider showing your support:', 'contact-form-7-honeypot' ); ?><br>
|
315 |
<a href="http://www.nocean.ca/buy-us-a-coffee/" target="_blank" class="button button-primary"><strong>
|
316 |
+
<span class="dashicons dashicons-coffee"></span> <?php esc_html_e( 'Buy Us a Coffee', 'contact-form-7-honeypot' ); ?>
|
317 |
</strong></a>
|
318 |
</p>
|
319 |
</div>
|
320 |
<div class="honeypot4cf7-admin__box">
|
321 |
<p class="honeypot4cf7__banner-ad-message">
|
322 |
+
<?php
|
323 |
+
printf(
|
324 |
+
/* translators: %s: Affiliate Link */
|
325 |
__( 'We use %s and find it incredibly valuable. If you choose to use them too (even for free), you are helping continued development and support of this plugin. Thank you!', 'contact-form-7-honeypot' ),
|
326 |
'<a href="https://shareasale.com/r.cfm?b=1537039&u=2748065&m=97231&urllink=&afftrack=0" target="_blank">Semrush</a>'
|
327 |
+
);
|
328 |
+
?>
|
329 |
</p>
|
330 |
<div class="honeypot4cf7__banner-ad honeypot4cf7__banner-ad--2">
|
331 |
<a target="_blank" href="https://shareasale.com/r.cfm?b=1550765&u=2748065&m=97231&urllink=&afftrack="><img src="<?php echo HONEYPOT4CF7_PLUGIN_DIR_URL; ?>/includes/images/banners/semrush-2_300x250.png" border="0" alt="position tracking" /></a>
|
333 |
</div>
|
334 |
|
335 |
<div class="honeypot4cf7-admin__box honeypot4cf7-admin__rate-us">
|
336 |
+
<div class="honeypot4cf7-admin__stars">
|
337 |
+
<a target="_blank" href="https://wordpress.org/support/plugin/contact-form-7-honeypot/reviews/?filter=5#new-post">
|
338 |
+
<span class="dashicons dashicons-star-filled"></span>
|
339 |
+
<span class="dashicons dashicons-star-filled"></span>
|
340 |
+
<span class="dashicons dashicons-star-filled"></span>
|
341 |
+
<span class="dashicons dashicons-star-filled"></span>
|
342 |
+
<span class="dashicons dashicons-star-filled"></span>
|
343 |
+
</a>
|
344 |
+
</div>
|
345 |
+
<?php
|
346 |
+
printf(
|
347 |
+
/* translators: %s: Plugin's reviews page link */
|
348 |
+
__( 'Please rate us on %s. Thanks!!', 'contact-form-7-honeypot' ),
|
349 |
+
'<a target="_blank" href="https://wordpress.org/support/plugin/contact-form-7-honeypot/reviews/?filter=5#new-post">wordpress.org</a>'
|
350 |
+
);
|
351 |
+
?>
|
352 |
</div>
|
353 |
</div>
|
354 |
</div>
|
361 |
* Add admin page CSS
|
362 |
*
|
363 |
*********** */
|
364 |
+
function honeypot4cf7_admin_enqueues( $hook ) {
|
365 |
+
wp_enqueue_script( 'honeypot4cf7-admin-js', plugins_url( 'includes/js/notice-update.js', HONEYPOT4CF7_PLUGIN ), array( 'jquery' ), HONEYPOT4CF7_VERSION, true );
|
366 |
+
if ( strpos( $hook, 'honeypot4cf7' ) !== false ) {
|
367 |
+
wp_enqueue_style( 'honeypot4cf7-admin-css', plugins_url( 'includes/css/styles.css', HONEYPOT4CF7_PLUGIN ), array(), HONEYPOT4CF7_VERSION, 'all' );
|
368 |
}
|
369 |
}
|
370 |
add_action( 'admin_enqueue_scripts', 'honeypot4cf7_admin_enqueues' );
|
includes/honeypot4cf7.php
CHANGED
@@ -6,21 +6,21 @@
|
|
6 |
* This lets CF7 know about Mr. Honeypot.
|
7 |
*
|
8 |
*/
|
9 |
-
add_action('wpcf7_init', 'honeypot4cf7_add_form_tag', 10);
|
10 |
function honeypot4cf7_add_form_tag() {
|
11 |
|
12 |
-
$honeypot4cf7_config = get_option('honeypot4cf7_config');
|
13 |
-
$do_not_store = (empty($honeypot4cf7_config['store_honeypot'])) ? true : false;
|
14 |
|
15 |
// Test if new 4.6+ functions exists
|
16 |
-
if (function_exists('wpcf7_add_form_tag')) {
|
17 |
wpcf7_add_form_tag(
|
18 |
'honeypot',
|
19 |
'honeypot4cf7_form_tag_handler',
|
20 |
array(
|
21 |
'name-attr' => true,
|
22 |
'do-not-store' => $do_not_store,
|
23 |
-
'not-for-mail' => true
|
24 |
)
|
25 |
);
|
26 |
} else {
|
@@ -38,64 +38,65 @@ function honeypot4cf7_add_form_tag() {
|
|
38 |
function honeypot4cf7_form_tag_handler( $tag ) {
|
39 |
|
40 |
// Test if new 4.6+ functions exists
|
41 |
-
$tag = (class_exists('WPCF7_FormTag')) ? new WPCF7_FormTag( $tag ) : new WPCF7_Shortcode( $tag );
|
42 |
|
43 |
-
if ( empty( $tag->name ) )
|
44 |
return '';
|
|
|
45 |
|
46 |
$validation_error = wpcf7_get_validation_error( $tag->name );
|
47 |
|
48 |
-
$honeypot4cf7_config = get_option('honeypot4cf7_config');
|
49 |
|
50 |
$class = wpcf7_form_controls_class( 'text' );
|
51 |
|
52 |
$placeholder = (string) reset( $tag->values );
|
53 |
|
54 |
-
$accessibility_message = ($honeypot4cf7_config['accessibility_message']) ? $honeypot4cf7_config['accessibility_message'] : __('Please leave this field empty.','contact-form-7-honeypot');
|
55 |
|
56 |
$atts = array(
|
57 |
'class' => $tag->get_class_option( $class ),
|
58 |
'id' => $tag->get_option( 'id', 'id', true ),
|
59 |
-
'wrapper_id' => $tag->get_option('wrapper-id'),
|
60 |
-
'placeholder' => ($placeholder) ? $placeholder : $honeypot4cf7_config['placeholder'],
|
61 |
-
'message' => apply_filters('wpcf7_honeypot_accessibility_message', $accessibility_message),
|
62 |
'name' => $tag->name,
|
63 |
'type' => $tag->type,
|
64 |
-
'validautocomplete' => ($tag->get_option('validautocomplete')) ? $tag->get_option('validautocomplete') : $honeypot4cf7_config['w3c_valid_autocomplete'],
|
65 |
-
'move_inline_css' => ($tag->get_option('move-inline-css')) ? $tag->get_option('move-inline-css') : $honeypot4cf7_config['move_inline_css'],
|
66 |
-
'nomessage' => ($tag->get_option('nomessage')) ? $tag->get_option('nomessage') : $honeypot4cf7_config['nomessage'],
|
67 |
'validation_error' => $validation_error,
|
68 |
-
'css' => apply_filters('wpcf7_honeypot_container_css', 'display:none !important; visibility:hidden !important;')
|
69 |
);
|
70 |
|
71 |
-
$unique_id = uniqid('wpcf7-');
|
72 |
-
$wrapper_id = (!empty($atts['wrapper_id'])) ? reset($atts['wrapper_id']) : $unique_id.'-wrapper';
|
73 |
-
$input_placeholder = (!empty($atts['placeholder'])) ? ' placeholder="'
|
74 |
-
$input_id = (!empty($atts['id'])) ? $atts['id'] : $unique_id.'-field';
|
75 |
-
$autocomplete_value = ($atts['validautocomplete'][0] === 'true') ? 'off' : 'new-password';
|
76 |
|
77 |
// Check if we should move the CSS off the element and into the footer
|
78 |
-
if (!empty($atts['move_inline_css']) && $atts['move_inline_css'][0] === 'true') {
|
79 |
-
$hp_css = '#'
|
80 |
-
wp_register_style( $unique_id.'-inline', false);
|
81 |
-
wp_enqueue_style( $unique_id.'-inline' );
|
82 |
-
wp_add_inline_style( $unique_id.'-inline', $hp_css );
|
83 |
$el_css = '';
|
84 |
} else {
|
85 |
-
$el_css = 'style="'
|
86 |
}
|
87 |
|
88 |
-
$html = '<span id="'
|
89 |
|
90 |
-
if (empty($atts['nomessage']) || $atts['nomessage'][0] === 'false') {
|
91 |
-
$html .= '<label for="' . $input_id . '" class="hp-message">'
|
92 |
}
|
93 |
|
94 |
-
$html .= '<input id="' . $input_id .'"' . $input_placeholder . 'class="' . $atts['class'] . '" type="text" name="' . $atts['name'] . '" value="" size="40" tabindex="-1" autocomplete="'
|
95 |
$html .= $validation_error . '</span>';
|
96 |
|
97 |
// Hook for filtering finished Honeypot form element.
|
98 |
-
return apply_filters('wpcf7_honeypot_html_output'
|
99 |
}
|
100 |
|
101 |
|
@@ -107,40 +108,48 @@ function honeypot4cf7_form_tag_handler( $tag ) {
|
|
107 |
*/
|
108 |
add_filter( 'wpcf7_spam', 'honeypot4cf7_spam_check', 10, 2 );
|
109 |
|
110 |
-
function honeypot4cf7_spam_check($spam, $submission) {
|
111 |
-
if ( $spam )
|
|
|
|
|
112 |
|
113 |
$cf7form = WPCF7_ContactForm::get_current();
|
114 |
$form_tags = $cf7form->scan_form_tags();
|
115 |
|
116 |
-
foreach ($form_tags as $tag)
|
117 |
-
if ($tag->type == 'honeypot')
|
118 |
$hp_ids[] = $tag->name;
|
119 |
-
|
120 |
-
|
121 |
|
122 |
// Check if form has Honeypot fields, if not, exit
|
123 |
-
if (empty($hp_ids))
|
|
|
|
|
124 |
|
125 |
-
foreach ($hp_ids as $hpid)
|
126 |
$value = isset( $_POST[$hpid] ) ? $_POST[$hpid] : '';
|
127 |
|
128 |
-
if ( $value != '' )
|
129 |
// Bots!
|
130 |
$spam = true;
|
131 |
$submission->add_spam_log( array(
|
132 |
'agent' => 'honeypot',
|
133 |
-
'reason' =>
|
|
|
|
|
|
|
|
|
134 |
) );
|
135 |
|
136 |
-
$honeypot4cf7_config = get_option('honeypot4cf7_config');
|
137 |
-
$honeypot4cf7_config['honeypot_count'] = (isset($honeypot4cf7_config['honeypot_count'])) ? $honeypot4cf7_config['honeypot_count'] + 1 : 1;
|
138 |
update_option( 'honeypot4cf7_config', $honeypot4cf7_config );
|
139 |
|
140 |
return $spam; // There's no need to go on, we've got flies in the honey.
|
141 |
-
|
142 |
|
143 |
-
|
144 |
|
145 |
return $spam;
|
146 |
}
|
@@ -159,29 +168,37 @@ function honeypot4cf7_generate_form_tag() {
|
|
159 |
$tag_generator->add( 'honeypot', __( 'Honeypot', 'contact-form-7-honeypot' ), 'honeypot4cf7_form_tag_generator' );
|
160 |
}
|
161 |
|
162 |
-
function honeypot4cf7_form_tag_generator($contact_form, $args = '') {
|
163 |
$args = wp_parse_args( $args, array() );
|
164 |
-
$description = __(
|
165 |
-
$desc_link = '<a href="https://wordpress.org/plugins/contact-form-7-honeypot/" target="_blank">'.__( 'Honeypot for CF7', 'contact-form-7-honeypot' ).'</a>';
|
166 |
?>
|
167 |
<div class="control-box">
|
168 |
<fieldset>
|
169 |
-
<legend
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
<table class="form-table"><tbody>
|
172 |
<tr>
|
173 |
<th scope="row">
|
174 |
-
<label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php
|
175 |
</th>
|
176 |
<td>
|
177 |
<input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /><br>
|
178 |
-
<em><?php
|
179 |
</td>
|
180 |
</tr>
|
181 |
|
182 |
<tr>
|
183 |
<th scope="row">
|
184 |
-
<label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php
|
185 |
</th>
|
186 |
<td>
|
187 |
<input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" />
|
@@ -190,7 +207,7 @@ function honeypot4cf7_form_tag_generator($contact_form, $args = '') {
|
|
190 |
|
191 |
<tr>
|
192 |
<th scope="row">
|
193 |
-
<label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php
|
194 |
</th>
|
195 |
<td>
|
196 |
<input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" />
|
@@ -199,11 +216,11 @@ function honeypot4cf7_form_tag_generator($contact_form, $args = '') {
|
|
199 |
|
200 |
<tr>
|
201 |
<th scope="row">
|
202 |
-
<label for="<?php echo esc_attr( $args['content'] . '-wrapper-id' ); ?>"><?php
|
203 |
</th>
|
204 |
<td>
|
205 |
<input type="text" name="wrapper-id" class="wrapper-id-value oneline option" id="<?php echo esc_attr( $args['content'] . '-wrapper-id' ); ?>" /><br>
|
206 |
-
<em><?php
|
207 |
</td>
|
208 |
</tr>
|
209 |
|
@@ -213,37 +230,37 @@ function honeypot4cf7_form_tag_generator($contact_form, $args = '') {
|
|
213 |
</th>
|
214 |
<td>
|
215 |
<input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /><br>
|
216 |
-
<em><?php
|
217 |
</td>
|
218 |
</tr>
|
219 |
|
220 |
<tr>
|
221 |
<th scope="row">
|
222 |
-
<label for="<?php echo esc_attr( $args['content'] . '-validautocomplete' ); ?>"><?php
|
223 |
</th>
|
224 |
<td>
|
225 |
<input type="checkbox" name="validautocomplete:true" id="<?php echo esc_attr( $args['content'] . '-validautocomplete' ); ?>" class="validautocompletevalue option" /><br />
|
226 |
-
<em><?php
|
227 |
</td>
|
228 |
</tr>
|
229 |
|
230 |
<tr>
|
231 |
<th scope="row">
|
232 |
-
<label for="<?php echo esc_attr( $args['content'] . '-move-inline-css' ); ?>"><?php
|
233 |
</th>
|
234 |
<td>
|
235 |
<input type="checkbox" name="move-inline-css:true" id="<?php echo esc_attr( $args['content'] . '-move-inline-css' ); ?>" class="move-inline-css-value option" /><br />
|
236 |
-
<em><?php
|
237 |
</td>
|
238 |
</tr>
|
239 |
|
240 |
<tr>
|
241 |
<th scope="row">
|
242 |
-
<label for="<?php echo esc_attr( $args['content'] . '-nomessage' ); ?>"><?php
|
243 |
</th>
|
244 |
<td>
|
245 |
<input type="checkbox" name="nomessage:true" id="<?php echo esc_attr( $args['content'] . '-nomessage' ); ?>" class="messagekillvalue option" /><br />
|
246 |
-
<em><?php
|
247 |
</td>
|
248 |
</tr>
|
249 |
|
@@ -255,7 +272,7 @@ function honeypot4cf7_form_tag_generator($contact_form, $args = '') {
|
|
255 |
<input type="text" name="honeypot" class="tag code" readonly="readonly" onfocus="this.select()" />
|
256 |
|
257 |
<div class="submitbox">
|
258 |
-
<input type="button" class="button button-primary insert-tag" value="<?php
|
259 |
</div>
|
260 |
|
261 |
<br class="clear" />
|
6 |
* This lets CF7 know about Mr. Honeypot.
|
7 |
*
|
8 |
*/
|
9 |
+
add_action( 'wpcf7_init', 'honeypot4cf7_add_form_tag', 10 );
|
10 |
function honeypot4cf7_add_form_tag() {
|
11 |
|
12 |
+
$honeypot4cf7_config = get_option( 'honeypot4cf7_config' );
|
13 |
+
$do_not_store = ( empty( $honeypot4cf7_config['store_honeypot'] ) ) ? true : false;
|
14 |
|
15 |
// Test if new 4.6+ functions exists
|
16 |
+
if ( function_exists( 'wpcf7_add_form_tag' ) ) {
|
17 |
wpcf7_add_form_tag(
|
18 |
'honeypot',
|
19 |
'honeypot4cf7_form_tag_handler',
|
20 |
array(
|
21 |
'name-attr' => true,
|
22 |
'do-not-store' => $do_not_store,
|
23 |
+
'not-for-mail' => true,
|
24 |
)
|
25 |
);
|
26 |
} else {
|
38 |
function honeypot4cf7_form_tag_handler( $tag ) {
|
39 |
|
40 |
// Test if new 4.6+ functions exists
|
41 |
+
$tag = ( class_exists( 'WPCF7_FormTag' ) ) ? new WPCF7_FormTag( $tag ) : new WPCF7_Shortcode( $tag );
|
42 |
|
43 |
+
if ( empty( $tag->name ) ) {
|
44 |
return '';
|
45 |
+
}
|
46 |
|
47 |
$validation_error = wpcf7_get_validation_error( $tag->name );
|
48 |
|
49 |
+
$honeypot4cf7_config = get_option( 'honeypot4cf7_config' );
|
50 |
|
51 |
$class = wpcf7_form_controls_class( 'text' );
|
52 |
|
53 |
$placeholder = (string) reset( $tag->values );
|
54 |
|
55 |
+
$accessibility_message = ( ! empty( $honeypot4cf7_config['accessibility_message'] ) ) ? $honeypot4cf7_config['accessibility_message'] : __( 'Please leave this field empty.', 'contact-form-7-honeypot' );
|
56 |
|
57 |
$atts = array(
|
58 |
'class' => $tag->get_class_option( $class ),
|
59 |
'id' => $tag->get_option( 'id', 'id', true ),
|
60 |
+
'wrapper_id' => $tag->get_option( 'wrapper-id' ),
|
61 |
+
'placeholder' => ( $placeholder ) ? $placeholder : $honeypot4cf7_config['placeholder'],
|
62 |
+
'message' => apply_filters( 'wpcf7_honeypot_accessibility_message', $accessibility_message ),
|
63 |
'name' => $tag->name,
|
64 |
'type' => $tag->type,
|
65 |
+
'validautocomplete' => ( $tag->get_option( 'validautocomplete' ) ) ? $tag->get_option( 'validautocomplete' ) : $honeypot4cf7_config['w3c_valid_autocomplete'],
|
66 |
+
'move_inline_css' => ( $tag->get_option( 'move-inline-css' ) ) ? $tag->get_option( 'move-inline-css' ) : $honeypot4cf7_config['move_inline_css'],
|
67 |
+
'nomessage' => ( $tag->get_option( 'nomessage' ) ) ? $tag->get_option( 'nomessage' ) : $honeypot4cf7_config['nomessage'],
|
68 |
'validation_error' => $validation_error,
|
69 |
+
'css' => apply_filters( 'wpcf7_honeypot_container_css', 'display:none !important; visibility:hidden !important;' ),
|
70 |
);
|
71 |
|
72 |
+
$unique_id = uniqid( 'wpcf7-' );
|
73 |
+
$wrapper_id = ( ! empty($atts['wrapper_id'] ) ) ? reset( $atts['wrapper_id'] ) : $unique_id . '-wrapper';
|
74 |
+
$input_placeholder = ( ! empty( $atts['placeholder'] ) ) ? ' placeholder="' . $atts['placeholder'] . '" ' : '';
|
75 |
+
$input_id = ( ! empty( $atts['id'] ) ) ? $atts['id'] : $unique_id . '-field';
|
76 |
+
$autocomplete_value = ( $atts['validautocomplete'][0] === 'true' ) ? 'off' : 'new-password';
|
77 |
|
78 |
// Check if we should move the CSS off the element and into the footer
|
79 |
+
if ( ! empty( $atts['move_inline_css'] ) && $atts['move_inline_css'][0] === 'true' ) {
|
80 |
+
$hp_css = '#' . $wrapper_id . ' {' . $atts['css'] . '}';
|
81 |
+
wp_register_style( $unique_id . '-inline', false );
|
82 |
+
wp_enqueue_style( $unique_id . '-inline' );
|
83 |
+
wp_add_inline_style( $unique_id . '-inline', $hp_css );
|
84 |
$el_css = '';
|
85 |
} else {
|
86 |
+
$el_css = 'style="' . $atts['css'] . '"';
|
87 |
}
|
88 |
|
89 |
+
$html = '<span id="' . $wrapper_id . '" class="wpcf7-form-control-wrap ' . $atts['name'] . '-wrap" ' . $el_css . '>';
|
90 |
|
91 |
+
if ( empty( $atts['nomessage'] ) || $atts['nomessage'][0] === 'false' ) {
|
92 |
+
$html .= '<label for="' . $input_id . '" class="hp-message">' . $atts['message'] . '</label>';
|
93 |
}
|
94 |
|
95 |
+
$html .= '<input id="' . $input_id . '"' . $input_placeholder . 'class="' . $atts['class'] . '" type="text" name="' . $atts['name'] . '" value="" size="40" tabindex="-1" autocomplete="'. $autocomplete_value . '" />';
|
96 |
$html .= $validation_error . '</span>';
|
97 |
|
98 |
// Hook for filtering finished Honeypot form element.
|
99 |
+
return apply_filters( 'wpcf7_honeypot_html_output' , $html, $atts );
|
100 |
}
|
101 |
|
102 |
|
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 |
+
}
|
115 |
|
116 |
$cf7form = WPCF7_ContactForm::get_current();
|
117 |
$form_tags = $cf7form->scan_form_tags();
|
118 |
|
119 |
+
foreach ( $form_tags as $tag ) {
|
120 |
+
if ( $tag->type == 'honeypot' ) {
|
121 |
$hp_ids[] = $tag->name;
|
122 |
+
}
|
123 |
+
}
|
124 |
|
125 |
// Check if form has Honeypot fields, if not, exit
|
126 |
+
if ( empty( $hp_ids ) ) {
|
127 |
+
return $spam;
|
128 |
+
}
|
129 |
|
130 |
+
foreach ( $hp_ids as $hpid ) {
|
131 |
$value = isset( $_POST[$hpid] ) ? $_POST[$hpid] : '';
|
132 |
|
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 = get_option( 'honeypot4cf7_config' );
|
146 |
+
$honeypot4cf7_config['honeypot_count'] = ( isset( $honeypot4cf7_config['honeypot_count'] ) ) ? $honeypot4cf7_config['honeypot_count'] + 1 : 1;
|
147 |
update_option( 'honeypot4cf7_config', $honeypot4cf7_config );
|
148 |
|
149 |
return $spam; // There's no need to go on, we've got flies in the honey.
|
150 |
+
}
|
151 |
|
152 |
+
}
|
153 |
|
154 |
return $spam;
|
155 |
}
|
168 |
$tag_generator->add( 'honeypot', __( 'Honeypot', 'contact-form-7-honeypot' ), 'honeypot4cf7_form_tag_generator' );
|
169 |
}
|
170 |
|
171 |
+
function honeypot4cf7_form_tag_generator( $contact_form, $args = '' ) {
|
172 |
$args = wp_parse_args( $args, array() );
|
173 |
+
$description = __( 'Generate a form-tag for a spam-stopping honeypot field. For more details, see %s.', 'contact-form-7-honeypot' );
|
174 |
+
$desc_link = '<a href="https://wordpress.org/plugins/contact-form-7-honeypot/" target="_blank">' . __( 'Honeypot for CF7', 'contact-form-7-honeypot' ) . '</a>';
|
175 |
?>
|
176 |
<div class="control-box">
|
177 |
<fieldset>
|
178 |
+
<legend>
|
179 |
+
<?php
|
180 |
+
printf(
|
181 |
+
/* translators: %s: Link to Honeypot plugin page */
|
182 |
+
esc_html( __( 'Generate a form-tag for a spam-stopping honeypot field. For more details, see %s.', 'contact-form-7-honeypot' ) ),
|
183 |
+
'<a href="https://wordpress.org/plugins/contact-form-7-honeypot/" target="_blank">'.__( 'Honeypot for CF7', 'contact-form-7-honeypot' ).'</a>'
|
184 |
+
);
|
185 |
+
?>
|
186 |
+
</legend>
|
187 |
|
188 |
<table class="form-table"><tbody>
|
189 |
<tr>
|
190 |
<th scope="row">
|
191 |
+
<label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php esc_html_e( 'Name', 'contact-form-7-honeypot' ); ?></label>
|
192 |
</th>
|
193 |
<td>
|
194 |
<input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /><br>
|
195 |
+
<em><?php esc_html_e( 'This can be anything, but should be changed from the default generated "honeypot". For better security, change "honeypot" to something more appealing to a bot, such as text including "email" or "website".', 'contact-form-7-honeypot' ); ?></em>
|
196 |
</td>
|
197 |
</tr>
|
198 |
|
199 |
<tr>
|
200 |
<th scope="row">
|
201 |
+
<label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php esc_html_e( 'ID (optional)', 'contact-form-7-honeypot' ); ?></label>
|
202 |
</th>
|
203 |
<td>
|
204 |
<input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" />
|
207 |
|
208 |
<tr>
|
209 |
<th scope="row">
|
210 |
+
<label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php esc_html_e( 'Class (optional)', 'contact-form-7-honeypot' ); ?></label>
|
211 |
</th>
|
212 |
<td>
|
213 |
<input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" />
|
216 |
|
217 |
<tr>
|
218 |
<th scope="row">
|
219 |
+
<label for="<?php echo esc_attr( $args['content'] . '-wrapper-id' ); ?>"><?php esc_html_e( 'Wrapper ID (optional)', 'contact-form-7-honeypot' ); ?></label>
|
220 |
</th>
|
221 |
<td>
|
222 |
<input type="text" name="wrapper-id" class="wrapper-id-value oneline option" id="<?php echo esc_attr( $args['content'] . '-wrapper-id' ); ?>" /><br>
|
223 |
+
<em><?php esc_html_e( 'By default the markup that wraps this form item has a random ID. You can customize it here. If you\'re unsure, leave blank.', 'contact-form-7-honeypot' ); ?></em>
|
224 |
</td>
|
225 |
</tr>
|
226 |
|
230 |
</th>
|
231 |
<td>
|
232 |
<input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /><br>
|
233 |
+
<em><?php esc_html_e( 'If using placeholders on other fields, this can help honeypot mimic a "real" field. If you\'re unsure, leave blank.', 'contact-form-7-honeypot' ); ?></em>
|
234 |
</td>
|
235 |
</tr>
|
236 |
|
237 |
<tr>
|
238 |
<th scope="row">
|
239 |
+
<label for="<?php echo esc_attr( $args['content'] . '-validautocomplete' ); ?>"><?php esc_html_e( 'Use Standard Autocomplete Value (optional)', 'contact-form-7-honeypot' ); ?></label>
|
240 |
</th>
|
241 |
<td>
|
242 |
<input type="checkbox" name="validautocomplete:true" id="<?php echo esc_attr( $args['content'] . '-validautocomplete' ); ?>" class="validautocompletevalue option" /><br />
|
243 |
+
<em><?php esc_html_e( 'To assure the honeypot isn\'t auto-completed by a browser, we add an atypical "autocomplete" attribute value. If you have any problems with this, you can switch it to the more standard (but less effective) "off" value. If you\'re unsure, leave this unchecked.', 'contact-form-7-honeypot' ); ?></em>
|
244 |
</td>
|
245 |
</tr>
|
246 |
|
247 |
<tr>
|
248 |
<th scope="row">
|
249 |
+
<label for="<?php echo esc_attr( $args['content'] . '-move-inline-css' ); ?>"><?php esc_html_e( 'Move inline CSS (optional)', 'contact-form-7-honeypot' ); ?></label>
|
250 |
</th>
|
251 |
<td>
|
252 |
<input type="checkbox" name="move-inline-css:true" id="<?php echo esc_attr( $args['content'] . '-move-inline-css' ); ?>" class="move-inline-css-value option" /><br />
|
253 |
+
<em><?php esc_html_e( 'Moves the CSS to hide the honeypot from the element to the footer of the page. May help confuse bots.', 'contact-form-7-honeypot' ); ?></em>
|
254 |
</td>
|
255 |
</tr>
|
256 |
|
257 |
<tr>
|
258 |
<th scope="row">
|
259 |
+
<label for="<?php echo esc_attr( $args['content'] . '-nomessage' ); ?>"><?php esc_html_e( 'Disable Accessibility Label (optional)', 'contact-form-7-honeypot' ); ?></label>
|
260 |
</th>
|
261 |
<td>
|
262 |
<input type="checkbox" name="nomessage:true" id="<?php echo esc_attr( $args['content'] . '-nomessage' ); ?>" class="messagekillvalue option" /><br />
|
263 |
+
<em><?php esc_html_e( 'If checked, the accessibility label will not be generated. This is not recommended, but may improve spam blocking. If you\'re unsure, leave this unchecked.', 'contact-form-7-honeypot' ); ?></em>
|
264 |
</td>
|
265 |
</tr>
|
266 |
|
272 |
<input type="text" name="honeypot" class="tag code" readonly="readonly" onfocus="this.select()" />
|
273 |
|
274 |
<div class="submitbox">
|
275 |
+
<input type="button" class="button button-primary insert-tag" value="<?php esc_attr_e( 'Insert Tag', 'contact-form-7-honeypot' ); ?>" />
|
276 |
</div>
|
277 |
|
278 |
<br class="clear" />
|
readme.txt
CHANGED
@@ -82,8 +82,11 @@ 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.2 =
|
86 |
-
Replaced text domain constant with plain string for better i18n compatability
|
87 |
|
88 |
= 2.0.1 =
|
89 |
Hotfix for issue with options not being set on upgrade.
|
82 |
2. Honeypot CF7 Form Tag Settings
|
83 |
|
84 |
== Changelog ==
|
85 |
+
= 2.0.3 =
|
86 |
+
General code cleanup, better adherence to WP coding standards and fixes for i18n functions.
|
87 |
+
|
88 |
= 2.0.2 =
|
89 |
+
Replaced text domain constant with plain string for better i18n compatability.
|
90 |
|
91 |
= 2.0.1 =
|
92 |
Hotfix for issue with options not being set on upgrade.
|