Simple Google reCAPTCHA - Version 3.3

Version Description

  • Bugfix: BuddyPress registration is now pass through
  • Bugfix: Other minor fixes
Download this release

Release Info

Developer Minor
Plugin Icon 128x128 Simple Google reCAPTCHA
Version 3.3
Comparing to
See all releases

Code changes from version 3.2 to 3.3

Files changed (3) hide show
  1. readme.txt +5 -1
  2. sgr.js +5 -5
  3. simple-google-recaptcha.php +8 -13
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: Minor
3
  Tags: recaptcha, spam, captcha, protect, secure, registration, login, form, google, invisible, checkbox
4
  Requires at least: 4.6
5
  Tested up to: 5.4
6
- Stable tag: 3.2
7
  Requires PHP: 7.0
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -51,6 +51,10 @@ Use standard WordPress Plugins page. In emergency case, rename plugin folder und
51
  5. Simple Google reCAPTCHA - Settings
52
 
53
  == Changelog ==
 
 
 
 
54
  = 3.2 =
55
  * Warning: Keys validation after save was not reliable, validation removed.
56
  * New: Added support for Google reCAPTCHA v3.
3
  Tags: recaptcha, spam, captcha, protect, secure, registration, login, form, google, invisible, checkbox
4
  Requires at least: 4.6
5
  Tested up to: 5.4
6
+ Stable tag: 3.3
7
  Requires PHP: 7.0
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
51
  5. Simple Google reCAPTCHA - Settings
52
 
53
  == Changelog ==
54
+ = 3.3 =
55
+ * Bugfix: BuddyPress registration is now pass through
56
+ * Bugfix: Other minor fixes
57
+
58
  = 3.2 =
59
  * Warning: Keys validation after save was not reliable, validation removed.
60
  * New: Added support for Google reCAPTCHA v3.
sgr.js CHANGED
@@ -1,17 +1,17 @@
1
  function sgr_2() {
2
  console.log('SGR_2 loaded!');
3
- let recaptcha = document.getElementsByClassName("sgr-recaptcha");
4
  for (var i = 0; i < recaptcha.length; i++) {
5
- grecaptcha.render(recaptcha.item(i), {"sitekey": sgr_recaptcha.site_key});
6
  }
7
  }
8
 
9
  function sgr_3() {
10
  console.log('SGR_3 loaded!');
11
  grecaptcha.execute(sgr_recaptcha.site_key, {action: 'sgr_global'}).then(function (token) {
12
- let recaptchaResponse = document.getElementById('sgr-response');
13
- if (recaptchaResponse) {
14
- recaptchaResponse.value = token;
15
  }
16
  });
17
  }
1
  function sgr_2() {
2
  console.log('SGR_2 loaded!');
3
+ let recaptcha = document.getElementsByClassName('sgr-recaptcha');
4
  for (var i = 0; i < recaptcha.length; i++) {
5
+ grecaptcha.render(recaptcha.item(i), {'sitekey': sgr_recaptcha.site_key});
6
  }
7
  }
8
 
9
  function sgr_3() {
10
  console.log('SGR_3 loaded!');
11
  grecaptcha.execute(sgr_recaptcha.site_key, {action: 'sgr_global'}).then(function (token) {
12
+ let recaptcha = document.getElementsByClassName('sgr-recaptcha');
13
+ for (var i = 0; i < recaptcha.length; i++) {
14
+ recaptcha.item(i).value = token;
15
  }
16
  });
17
  }
simple-google-recaptcha.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  * Plugin Name: Simple Google reCAPTCHA
4
  * Description: Simply protect your WordPress against spam comments and brute-force attacks, thanks to Google reCAPTCHA!
5
- * Version: 3.2
6
  * Author: Michal Novák
7
  * Author URI: https://www.novami.cz
8
  * License: GPL3
@@ -146,10 +146,7 @@ class SimpleGoogleRecaptcha
146
  $sgr_display_list = [
147
  'comment_form_after_fields',
148
  'register_form',
149
- 'lost_password',
150
  'lostpassword_form',
151
- 'retrieve_password',
152
- 'resetpass_form',
153
  'woocommerce_register_form',
154
  'woocommerce_lostpassword_form',
155
  'woocommerce_after_order_notes',
@@ -160,13 +157,13 @@ class SimpleGoogleRecaptcha
160
  'preprocess_comment',
161
  'registration_errors',
162
  'lostpassword_post',
163
- 'resetpass_post',
164
- 'woocommerce_register_post'
165
  ];
166
 
167
  if (!$this->loginDisable) {
168
  array_push($sgr_display_list, 'login_form', 'woocommerce_login_form');
169
- array_push($sgr_verify_list, 'wp_authenticate_user', 'bp_signup_validate');
170
  }
171
 
172
  $sgrDisplay = $this->version === 3 ? 'sgr3_display' : 'sgr_display';
@@ -194,7 +191,7 @@ class SimpleGoogleRecaptcha
194
 
195
  public function sgr3_display()
196
  {
197
- echo '<input type="hidden" name="g-recaptcha-response" id="sgr-response">';
198
  }
199
 
200
  public function errorMessage($error_code)
@@ -235,7 +232,7 @@ class SimpleGoogleRecaptcha
235
 
236
  /**
237
  * @param $input
238
- * @return WP_Error
239
  */
240
  public function sgr_verify($input)
241
  {
@@ -245,12 +242,10 @@ class SimpleGoogleRecaptcha
245
  $recaptcha_error_code = isset($this->recaptchaResponse['error-codes'][0]) ? $this->recaptchaResponse['error-codes'][0] : null;
246
  $error_message = $this->errorMessage($recaptcha_error_code);
247
 
248
- if ($this->recaptchaResponse['success']) {
249
  return $input;
250
- } elseif (is_array($input)) { // Array = Comment else Object
251
- wp_die(sprintf('<p><strong>%s</strong> Google reCAPTCHA %s. %s</p>', __('Error:'), __('verification failed'), $error_message), 'reCAPTCHA', ['response' => 403, 'back_link' => 1]);
252
  } else {
253
- return new WP_Error('reCAPTCHA', sprintf('<strong>%s</strong> Google reCAPTCHA %s. %s', __('Error:'), __('verification failed'), $error_message));
254
  }
255
  } else {
256
  wp_die(sprintf('<p><strong>%s</strong> Google reCAPTCHA %s. %s</p>', __('Error:'), __('verification failed'), __('Do you have JavaScript enabled?')), 'reCAPTCHA', ['response' => 403, 'back_link' => 1]);
2
  /*
3
  * Plugin Name: Simple Google reCAPTCHA
4
  * Description: Simply protect your WordPress against spam comments and brute-force attacks, thanks to Google reCAPTCHA!
5
+ * Version: 3.3
6
  * Author: Michal Novák
7
  * Author URI: https://www.novami.cz
8
  * License: GPL3
146
  $sgr_display_list = [
147
  'comment_form_after_fields',
148
  'register_form',
 
149
  'lostpassword_form',
 
 
150
  'woocommerce_register_form',
151
  'woocommerce_lostpassword_form',
152
  'woocommerce_after_order_notes',
157
  'preprocess_comment',
158
  'registration_errors',
159
  'lostpassword_post',
160
+ 'woocommerce_register_post',
161
+ 'bp_signup_validate'
162
  ];
163
 
164
  if (!$this->loginDisable) {
165
  array_push($sgr_display_list, 'login_form', 'woocommerce_login_form');
166
+ array_push($sgr_verify_list, 'wp_authenticate_user');
167
  }
168
 
169
  $sgrDisplay = $this->version === 3 ? 'sgr3_display' : 'sgr_display';
191
 
192
  public function sgr3_display()
193
  {
194
+ echo '<input type="hidden" name="g-recaptcha-response" class="sgr-recaptcha">';
195
  }
196
 
197
  public function errorMessage($error_code)
232
 
233
  /**
234
  * @param $input
235
+ * @return mixed
236
  */
237
  public function sgr_verify($input)
238
  {
242
  $recaptcha_error_code = isset($this->recaptchaResponse['error-codes'][0]) ? $this->recaptchaResponse['error-codes'][0] : null;
243
  $error_message = $this->errorMessage($recaptcha_error_code);
244
 
245
+ if ((int)$this->recaptchaResponse['success'] === 1) {
246
  return $input;
 
 
247
  } else {
248
+ wp_die(sprintf('<p><strong>%s</strong> Google reCAPTCHA %s. %s</p>', __('Error:'), __('verification failed'), $error_message), 'reCAPTCHA', ['response' => 403, 'back_link' => 1]);
249
  }
250
  } else {
251
  wp_die(sprintf('<p><strong>%s</strong> Google reCAPTCHA %s. %s</p>', __('Error:'), __('verification failed'), __('Do you have JavaScript enabled?')), 'reCAPTCHA', ['response' => 403, 'back_link' => 1]);