Contact Form 7 Captcha - Version 0.0.9

Version Description

Download this release

Release Info

Developer 247wd
Plugin Icon wp plugin Contact Form 7 Captcha
Version 0.0.9
Comparing to
See all releases

Code changes from version 0.0.8 to 0.0.9

Files changed (2) hide show
  1. contact-form-7-simple-recaptcha.php +17 -12
  2. readme.txt +5 -4
contact-form-7-simple-recaptcha.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Contact Form 7 Captcha
4
  Description: Add No CAPTCHA reCAPTCHA to Contact Form 7 using [cf7sr-simple-recaptcha] shortcode
5
- Version: 0.0.8
6
  Author: 247wd
7
  */
8
 
@@ -52,8 +52,8 @@ if (!empty($cf7sr_key) && !empty($cf7sr_secret) && !is_admin()) {
52
  global $cf7sr;
53
  $cf7sr = true;
54
  $cf7sr_key = get_option('cf7sr_key');
55
- return '<div id="cf7sr-' . uniqid() . '" class="cf7sr-g-recaptcha" data-sitekey="' . $cf7sr_key
56
- . '"></div><span class="wpcf7-form-control-wrap cf7sr-g-recaptcha-invalid"></span>';
57
  }
58
  add_shortcode('cf7sr-simple-recaptcha', 'cf7sr_shortcode');
59
 
@@ -82,7 +82,7 @@ if (!empty($cf7sr_key) && !empty($cf7sr_secret) && !is_admin()) {
82
  }
83
 
84
  if (empty($data['g-recaptcha-response'])) {
85
- $result->invalidate(array('type' => 'captcha', 'name' => 'cf7sr-g-recaptcha-invalid'), $message);
86
  return $result;
87
  }
88
 
@@ -92,7 +92,7 @@ if (!empty($cf7sr_key) && !empty($cf7sr_secret) && !is_admin()) {
92
  $body = wp_remote_retrieve_body($request);
93
  $response = json_decode($body);
94
  if (!(isset ($response->success) && 1 == $response->success)) {
95
- $result->invalidate(array('type' => 'captcha', 'name' => 'cf7sr-g-recaptcha-invalid'), $message);
96
  }
97
 
98
  return $result;
@@ -116,14 +116,18 @@ if (is_admin()) {
116
  echo '<p>To use <strong>Contact Form 7 Captcha</strong> please update <strong>Contact Form 7</strong> plugin as current version is not supported.</p>';
117
  return;
118
  }
119
- if (!empty ($_POST['update'])) {
120
- $cf7sr_key = !empty ($_POST['cf7sr_key']) ? sanitize_text_field($_POST['cf7sr_key']) : '';
 
 
 
 
121
  update_option('cf7sr_key', $cf7sr_key);
122
 
123
- $cf7sr_secret = !empty ($_POST['cf7sr_secret']) ? sanitize_text_field($_POST['cf7sr_secret']) : '';
124
  update_option('cf7sr_secret', $cf7sr_secret);
125
 
126
- $cf7sr_message = !empty ($_POST['cf7sr_message']) ? sanitize_text_field($_POST['cf7sr_message']) : '';
127
  update_option('cf7sr_message', $cf7sr_message);
128
 
129
  $updated = 1;
@@ -145,10 +149,11 @@ if (is_admin()) {
145
  To add Recaptcha to CF7 form, add <strong>[cf7sr-simple-recaptcha]</strong> in your form ( preferable above submit button )<br>
146
  <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
147
  <input type="hidden" value="1" name="update">
 
148
  <ul>
149
- <li><input type="text" style="width: 370px;" value="<?php echo $cf7sr_key; ?>" name="cf7sr_key"> Site key</li>
150
- <li><input type="text" style="width: 370px;" value="<?php echo $cf7sr_secret; ?>" name="cf7sr_secret"> Secret key</li>
151
- <li><input type="text" style="width: 370px;" value="<?php echo $cf7sr_message; ?>" name="cf7sr_message"> Invalid captcha error message</li>
152
  </ul>
153
  <input type="submit" class="button-primary" value="Save Settings">
154
  </form><br>
2
  /*
3
  Plugin Name: Contact Form 7 Captcha
4
  Description: Add No CAPTCHA reCAPTCHA to Contact Form 7 using [cf7sr-simple-recaptcha] shortcode
5
+ Version: 0.0.9
6
  Author: 247wd
7
  */
8
 
52
  global $cf7sr;
53
  $cf7sr = true;
54
  $cf7sr_key = get_option('cf7sr_key');
55
+ return '<div id="cf7sr-' . uniqid() . '" class="cf7sr-g-recaptcha" data-sitekey="' . esc_attr($cf7sr_key)
56
+ . '"></div><span class="wpcf7-form-control-wrap cf7sr-recaptcha"><input type="hidden" name="cf7sr-recaptcha" value="" class="wpcf7-form-control"></span>';
57
  }
58
  add_shortcode('cf7sr-simple-recaptcha', 'cf7sr_shortcode');
59
 
82
  }
83
 
84
  if (empty($data['g-recaptcha-response'])) {
85
+ $result->invalidate(array('type' => 'captcha', 'name' => 'cf7sr-recaptcha'), $message);
86
  return $result;
87
  }
88
 
92
  $body = wp_remote_retrieve_body($request);
93
  $response = json_decode($body);
94
  if (!(isset ($response->success) && 1 == $response->success)) {
95
+ $result->invalidate(array('type' => 'captcha', 'name' => 'cf7sr-recaptcha'), $message);
96
  }
97
 
98
  return $result;
116
  echo '<p>To use <strong>Contact Form 7 Captcha</strong> please update <strong>Contact Form 7</strong> plugin as current version is not supported.</p>';
117
  return;
118
  }
119
+ if (
120
+ ! empty ($_POST['update'])
121
+ && ! empty($_POST['cf7sr_nonce'])
122
+ && wp_verify_nonce($_POST['cf7sr_nonce'],'cf7sr_update_settings' )
123
+ ) {
124
+ $cf7sr_key = ! empty ($_POST['cf7sr_key']) ? sanitize_text_field($_POST['cf7sr_key']) : '';
125
  update_option('cf7sr_key', $cf7sr_key);
126
 
127
+ $cf7sr_secret = ! empty ($_POST['cf7sr_secret']) ? sanitize_text_field($_POST['cf7sr_secret']) : '';
128
  update_option('cf7sr_secret', $cf7sr_secret);
129
 
130
+ $cf7sr_message = ! empty ($_POST['cf7sr_message']) ? sanitize_text_field($_POST['cf7sr_message']) : '';
131
  update_option('cf7sr_message', $cf7sr_message);
132
 
133
  $updated = 1;
149
  To add Recaptcha to CF7 form, add <strong>[cf7sr-simple-recaptcha]</strong> in your form ( preferable above submit button )<br>
150
  <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
151
  <input type="hidden" value="1" name="update">
152
+ <?php wp_nonce_field( 'cf7sr_update_settings', 'cf7sr_nonce' ); ?>
153
  <ul>
154
+ <li><input type="text" style="width: 370px;" value="<?php echo esc_attr($cf7sr_key); ?>" name="cf7sr_key"> Site key</li>
155
+ <li><input type="text" style="width: 370px;" value="<?php echo esc_attr($cf7sr_secret); ?>" name="cf7sr_secret"> Secret key</li>
156
+ <li><input type="text" style="width: 370px;" value="<?php echo esc_attr($cf7sr_message); ?>" name="cf7sr_message"> Invalid captcha error message</li>
157
  </ul>
158
  <input type="submit" class="button-primary" value="Save Settings">
159
  </form><br>
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: 247wd
3
  Donate link: https://www.paypal.me/cf7captcha
4
  Tags: captcha, recaptcha, new recaptcha, contact form 7, no captcha
5
  Requires at least: 4.1.2
6
- Tested up to: 5.5.1
7
- Stable tag: 0.0.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -17,9 +17,10 @@ This plugin implements "I'm not a robot" checkbox. When generating keys, choose
17
  Add Google CAPTCHA to Contact Form 7.<br>
18
  Protect your Contact Form 7 forms from spam and abuse.<br>
19
  Can be used to protect multiple forms on same page.<br>
20
- Tested with Contact Form 7 version 5.2.2 and WordPress version 5.5.1<br>
21
  Configure plugin from Settings => CF7 Simple Recaptcha.<br>
22
- After configuration, add [cf7sr-simple-recaptcha] to any Contact Form 7 form.<br>
 
23
 
24
  == Installation ==
25
 
3
  Donate link: https://www.paypal.me/cf7captcha
4
  Tags: captcha, recaptcha, new recaptcha, contact form 7, no captcha
5
  Requires at least: 4.1.2
6
+ Tested up to: 5.8
7
+ Stable tag: 0.0.9
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
17
  Add Google CAPTCHA to Contact Form 7.<br>
18
  Protect your Contact Form 7 forms from spam and abuse.<br>
19
  Can be used to protect multiple forms on same page.<br>
20
+ Tested with Contact Form 7 version 5.4.2 and WordPress version 5.8<br>
21
  Configure plugin from Settings => CF7 Simple Recaptcha.<br>
22
+ After configuration, add [cf7sr-simple-recaptcha] to any Contact Form 7 form.<br>
23
+ Added CSRF check and escaped attributes in Settings page.
24
 
25
  == Installation ==
26