Simple Google reCAPTCHA - Version 3.4

Version Description

  • Bugfix: Translations works again correctly
  • New: Works in countries where Google domain is blocked
  • New: Possibility to replace v3 reCAPTCHA badge by text
Download this release

Release Info

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

Code changes from version 3.3 to 3.4

Files changed (6) hide show
  1. readme.txt +24 -13
  2. sgr.css +6 -0
  3. sgr3_hide.css +8 -0
  4. simple-google-recaptcha.php +82 -58
  5. style.css +0 -10
  6. uninstall.php +1 -1
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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.3
7
- Requires PHP: 7.0
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
  Donate link: https://www.paypal.me/NovaMi
@@ -38,31 +38,42 @@ If you write me (on support forum etc.), be patient, please. I work on this plug
38
 
39
  == Frequently Asked Questions ==
40
  = Why to install this plugin? =
41
- Just pure protection - no ads, no tracking and any other unnecessary changes.
 
 
 
 
 
42
 
43
  = How to disable this plugin? =
44
  Use standard WordPress Plugins page. In emergency case, rename plugin folder under /wp-content/plugins/ over FTP access.
45
 
46
  == Screenshots ==
47
- 1. Simple Google reCAPTCHA - Add new comment form
48
- 2. Simple Google reCAPTCHA - New password form
49
- 3. Simple Google reCAPTCHA - Registration form
50
- 4. Simple Google reCAPTCHA - Login form
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.
61
 
62
  = 3.1 =
63
- * New: Keys validation after save.
64
- * New: More detailed error messages.
65
- * New: Plugin is disabled until you set correct keys.
66
 
67
  = 3.0 =
68
  * Bugfix: User login (including password in plaintext) could get into server error log in specific case.
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.4
7
+ Requires PHP: 7.1
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
  Donate link: https://www.paypal.me/NovaMi
38
 
39
  == Frequently Asked Questions ==
40
  = Why to install this plugin? =
41
+ * No ads & user tracking
42
+ * Only 1 simple script file
43
+ * New (hidden) reCAPTCHA v3
44
+ * Possibility to replace v3 reCAPTCHA badge by text
45
+ * reCAPTCHA language based on WordPress settings
46
+ * Works in countries where Google domain is blocked
47
 
48
  = How to disable this plugin? =
49
  Use standard WordPress Plugins page. In emergency case, rename plugin folder under /wp-content/plugins/ over FTP access.
50
 
51
  == Screenshots ==
52
+ 1. New comment
53
+ 2. New password
54
+ 3. Registration
55
+ 4. Login
56
+ 5. Settings
57
+ 6. reCAPTCHA v3 text instead of badge
58
 
59
  == Changelog ==
60
+ = 3.4 =
61
+ * Bugfix: Translations works again correctly
62
+ * New: Works in countries where Google domain is blocked
63
+ * New: Possibility to replace v3 reCAPTCHA badge by text
64
+
65
  = 3.3 =
66
  * Bugfix: BuddyPress registration is now pass through
67
  * Bugfix: Other minor fixes
68
 
69
  = 3.2 =
70
+ * Warning: Keys validation after save was not reliable, validation removed
71
+ * New: Added support for Google reCAPTCHA v3
72
 
73
  = 3.1 =
74
+ * New: Keys validation after save
75
+ * New: More detailed error messages
76
+ * New: Plugin is disabled until you set correct keys
77
 
78
  = 3.0 =
79
  * Bugfix: User login (including password in plaintext) could get into server error log in specific case.
sgr.css ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ .sgr-recaptcha {
2
+ transform: scale(0.895);
3
+ transform-origin: 0 0;
4
+ clear: both;
5
+ padding: 10px 0 5px 0;
6
+ }
sgr3_hide.css ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ .sgr-infotext {
2
+ padding-bottom: 15px;
3
+ font-size: 85%;
4
+ }
5
+
6
+ .grecaptcha-badge {
7
+ visibility: hidden;
8
+ }
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.3
6
  * Author: Michal Novák
7
  * Author URI: https://www.novami.cz
8
  * License: GPL3
@@ -19,12 +19,14 @@ if (!defined('ABSPATH')) {
19
  */
20
  class SimpleGoogleRecaptcha
21
  {
 
22
  const V2 = 'v2 "I\'m not a robot" Checkbox';
23
  const V3 = 'v3';
24
 
25
  private $pluginName;
26
  private $version;
27
  private $loginDisable;
 
28
  private $siteKey;
29
  private $secretKey;
30
 
@@ -38,37 +40,37 @@ class SimpleGoogleRecaptcha
38
  $this->pluginName = get_file_data(__FILE__, ['Name' => 'Plugin Name'])['Name'];
39
  $this->version = (int)filter_var(get_option('sgr_version'), FILTER_SANITIZE_NUMBER_INT);
40
  $this->loginDisable = (int)filter_var(get_option('sgr_login_disable'), FILTER_SANITIZE_NUMBER_INT);
41
-
42
  $this->siteKey = filter_var(get_option('sgr_site_key'), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
43
  $this->secretKey = filter_var(get_option('sgr_secret_key'), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
44
 
45
- add_filter(sprintf('plugin_action_links_%s', plugin_basename(__FILE__)), [$this, 'sgr_add_plugin_action_links']);
46
 
47
- add_action('activated_plugin', [$this, 'sgr_activation']);
48
- add_action('admin_menu', [$this, 'sgr_menu']);
49
- add_action('admin_init', [$this, 'sgr_display_options']);
50
- add_action('wp_loaded', [$this, 'sgr_check']);
51
  }
52
 
53
  /**
54
  * @param $links
55
  * @return array
56
  */
57
- public function sgr_add_plugin_action_links($links)
58
  {
59
- return array_merge(['settings' => sprintf('<a href="options-general.php?page=sgr_options">%s</a>', __('Settings'))], $links);
60
  }
61
 
62
- public function sgr_activation($plugin)
63
  {
64
  if ($plugin == plugin_basename(__FILE__) && (!$this->siteKey || !$this->secretKey)) {
65
  exit(wp_redirect(admin_url('options-general.php?page=sgr_options')));
66
  }
67
  }
68
 
69
- public function sgr_options_page()
70
  {
71
- echo sprintf('<div class="wrap"><h1>%s option</h1><form method="post" action="options.php">', $this->pluginName);
72
 
73
  settings_fields('sgr_header_section');
74
  do_settings_sections('sgr_options');
@@ -78,48 +80,56 @@ class SimpleGoogleRecaptcha
78
  echo sprintf('</form>%s</div>', $this->messageProtectionStatus());
79
  }
80
 
81
- public function sgr_menu()
82
  {
83
- $this->sgr_enqueue_main();
84
- add_submenu_page('options-general.php', $this->pluginName, 'Google reCAPTCHA', 'manage_options', 'sgr_options', [$this, 'sgr_options_page']);
85
  }
86
 
87
- public function sgr_display_site_key_element()
88
  {
89
  echo sprintf('<input type="text" name="sgr_site_key" class="regular-text" id="sgr_site_key" value="%s" />', $this->siteKey);
90
  }
91
 
92
- public function sgr_display_secret_key_element()
93
  {
94
  echo sprintf('<input type="text" name="sgr_secret_key" class="regular-text" id="sgr_secret_key" value="%s" />', $this->secretKey);
95
  }
96
 
97
- public function sgr_display_version()
 
 
 
 
 
98
  {
99
  echo sprintf('<input type="checkbox" name="sgr_version" id="sgr_version" value="3" %s />', checked(3, $this->version, false));
100
  }
101
 
102
- public function sgr_display_login_disable()
103
  {
104
- echo sprintf('<input type="checkbox" name="sgr_login_disable" id="sgr_login_disable" value="1" %s />', checked(1, $this->loginDisable, false));
105
  }
106
 
107
- public function sgr_display_options()
108
  {
109
- add_settings_section('sgr_header_section', __('Google reCAPTCHA keys'), [], 'sgr_options');
 
 
 
 
 
 
110
 
111
- add_settings_field('sgr_site_key', __('Site Key'), [$this, 'sgr_display_site_key_element'], 'sgr_options', 'sgr_header_section');
112
- add_settings_field('sgr_secret_key', __('Secret Key'), [$this, 'sgr_display_secret_key_element'], 'sgr_options', 'sgr_header_section');
113
- add_settings_field('sgr_login_disable', __('Disable on login form'), [$this, 'sgr_display_login_disable'], 'sgr_options', 'sgr_header_section');
114
- add_settings_field('sgr_version', __('Enable reCAPTCHA v3'), [$this, 'sgr_display_version'], 'sgr_options', 'sgr_header_section');
115
 
116
- register_setting('sgr_header_section', 'sgr_site_key');
117
- register_setting('sgr_header_section', 'sgr_secret_key');
118
- register_setting('sgr_header_section', 'sgr_login_disable');
119
- register_setting('sgr_header_section', 'sgr_version');
120
  }
121
 
122
- public function sgr_enqueue_main()
123
  {
124
  $jsName = 'sgr.js';
125
  $jsPath = sprintf('%s%s', plugin_dir_path(__FILE__), $jsName);
@@ -129,19 +139,21 @@ class SimpleGoogleRecaptcha
129
  wp_localize_script('sgr_recaptcha_main', 'sgr_recaptcha', ['site_key' => $this->siteKey]);
130
  }
131
 
132
- public function sgr_enqueue_scripts()
133
  {
134
- $jsUrl = sprintf('https://www.google.com/recaptcha/api.js?hl=%s&onload=sgr_2&render=explicit', get_locale());
 
 
135
  if ($this->version === 3) {
136
- $jsUrl = sprintf('https://www.google.com/recaptcha/api.js?hl=%s&render=%s&onload=sgr_3', get_locale(), $this->siteKey);
137
  }
138
 
139
  wp_enqueue_script('sgr_recaptcha', $jsUrl);
140
  }
141
 
142
- public function sgr_frontend_script()
143
  {
144
- $this->sgr_enqueue_main();
145
 
146
  $sgr_display_list = [
147
  'comment_form_after_fields',
@@ -166,32 +178,44 @@ class SimpleGoogleRecaptcha
166
  array_push($sgr_verify_list, 'wp_authenticate_user');
167
  }
168
 
169
- $sgrDisplay = $this->version === 3 ? 'sgr3_display' : 'sgr_display';
170
 
171
  foreach ($sgr_display_list as $sgr_display) {
172
- add_action($sgr_display, [$this, 'sgr_enqueue_scripts']);
173
  add_action($sgr_display, [$this, $sgrDisplay]);
174
  }
175
 
176
  foreach ($sgr_verify_list as $sgr_verify) {
177
- add_action($sgr_verify, [$this, 'sgr_verify']);
178
  }
179
  }
180
 
181
- public function sgr_display()
182
  {
183
- $cssName = 'style.css';
184
  $cssPath = sprintf('%s%s', plugin_dir_path(__FILE__), $cssName);
185
  $cssVersion = filemtime($cssPath);
186
 
187
- wp_enqueue_style("style", sprintf('%s%s', plugin_dir_url(__FILE__), $cssName), [], $cssVersion);
188
 
189
  echo '<div class="sgr-recaptcha"></div>';
190
  }
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)
@@ -200,22 +224,22 @@ class SimpleGoogleRecaptcha
200
 
201
  switch ($error_code) {
202
  case 'missing-input-secret':
203
- $error_message = __('The secret parameter is missing.');
204
  break;
205
  case 'missing-input-response':
206
- $error_message = __('The response parameter is missing.');
207
  break;
208
  case 'invalid-input-secret':
209
- $error_message = __('The secret parameter is invalid or malformed.');
210
  break;
211
  case 'invalid-input-response':
212
- $error_message = __('The response parameter is invalid or malformed.');
213
  break;
214
  case 'bad-request':
215
- $error_message = __('The request is invalid or malformed.');
216
  break;
217
  case 'timeout-or-duplicate':
218
- $error_message = __('The response is no longer valid: either is too old or has been used previously.');
219
  break;
220
  }
221
 
@@ -225,7 +249,7 @@ class SimpleGoogleRecaptcha
225
  private function recaptchaResponse()
226
  {
227
  $recaptchaResponse = filter_input(INPUT_POST, 'g-recaptcha-response', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
228
- $response = (array)wp_remote_get(sprintf('https://www.google.com/recaptcha/api/siteverify?secret=%s&response=%s', $this->secretKey, $recaptchaResponse));
229
 
230
  $this->recaptchaResponse = isset($response['body']) ? json_decode($response['body'], 1) : ['success' => false, 'error-codes' => ['general-fail']];
231
  }
@@ -234,7 +258,7 @@ class SimpleGoogleRecaptcha
234
  * @param $input
235
  * @return mixed
236
  */
237
- public function sgr_verify($input)
238
  {
239
  $this->recaptchaResponse();
240
 
@@ -245,10 +269,10 @@ class SimpleGoogleRecaptcha
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]);
252
  }
253
  }
254
 
@@ -257,16 +281,16 @@ class SimpleGoogleRecaptcha
257
  $type = $this->version === 3 ? self::V3 : self::V2;
258
 
259
  if (!$this->siteKey || !$this->secretKey) {
260
- return sprintf('<div class="notice notice-error"><p><strong>%s</strong> Google reCAPTCHA %s!</p><p>%s</p></div>', __('Warning:'), __('is disabled'), __(sprintf('You have to <a href="https://www.google.com/recaptcha/admin" rel="external">register your domain</a>, get required Google reCAPTCHA keys %s and save them bellow.', $type)));
261
  } else {
262
- return sprintf('<div class="notice notice-warning"><p><strong>%s</strong> Google reCAPTCHA %s!</p><p>%s</p></div>', __('Notice:'), __('is enabled'), __('Keep on mind, that in case of emergency, you can disable this plugin via FTP access, just rename the plugin folder.'));
263
  }
264
  }
265
 
266
- public function sgr_check()
267
  {
268
  if (!is_user_logged_in() && !wp_doing_ajax() && !function_exists('wpcf7_contact_form_shortcode') && $this->siteKey && $this->secretKey) {
269
- $this->sgr_frontend_script();
270
  }
271
  }
272
  }
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.4
6
  * Author: Michal Novák
7
  * Author URI: https://www.novami.cz
8
  * License: GPL3
19
  */
20
  class SimpleGoogleRecaptcha
21
  {
22
+ const TEXT_DOMAIN = 'simple-google-recaptcha';
23
  const V2 = 'v2 "I\'m not a robot" Checkbox';
24
  const V3 = 'v3';
25
 
26
  private $pluginName;
27
  private $version;
28
  private $loginDisable;
29
+ private $badgeHide;
30
  private $siteKey;
31
  private $secretKey;
32
 
40
  $this->pluginName = get_file_data(__FILE__, ['Name' => 'Plugin Name'])['Name'];
41
  $this->version = (int)filter_var(get_option('sgr_version'), FILTER_SANITIZE_NUMBER_INT);
42
  $this->loginDisable = (int)filter_var(get_option('sgr_login_disable'), FILTER_SANITIZE_NUMBER_INT);
43
+ $this->badgeHide = (int)filter_var(get_option('sgr_badge_hide'), FILTER_SANITIZE_NUMBER_INT);
44
  $this->siteKey = filter_var(get_option('sgr_site_key'), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
45
  $this->secretKey = filter_var(get_option('sgr_secret_key'), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
46
 
47
+ add_filter(sprintf('plugin_action_links_%s', plugin_basename(__FILE__)), [$this, 'action_links']);
48
 
49
+ add_action('activated_plugin', [$this, 'activation']);
50
+ add_action('admin_menu', [$this, 'menu']);
51
+ add_action('admin_init', [$this, 'display_options']);
52
+ add_action('wp_loaded', [$this, 'check']);
53
  }
54
 
55
  /**
56
  * @param $links
57
  * @return array
58
  */
59
+ public function action_links($links)
60
  {
61
+ return array_merge(['settings' => sprintf('<a href="options-general.php?page=sgr_options">%s</a>', __('Settings', self::TEXT_DOMAIN))], $links);
62
  }
63
 
64
+ public function activation($plugin)
65
  {
66
  if ($plugin == plugin_basename(__FILE__) && (!$this->siteKey || !$this->secretKey)) {
67
  exit(wp_redirect(admin_url('options-general.php?page=sgr_options')));
68
  }
69
  }
70
 
71
+ public function options_page()
72
  {
73
+ echo sprintf('<div class="wrap"><h1>%s - %s</h1><form method="post" action="options.php">', $this->pluginName, __('Settings', self::TEXT_DOMAIN));
74
 
75
  settings_fields('sgr_header_section');
76
  do_settings_sections('sgr_options');
80
  echo sprintf('</form>%s</div>', $this->messageProtectionStatus());
81
  }
82
 
83
+ public function menu()
84
  {
85
+ $this->enqueue_main();
86
+ add_submenu_page('options-general.php', $this->pluginName, 'Google reCAPTCHA', 'manage_options', 'sgr_options', [$this, 'options_page']);
87
  }
88
 
89
+ public function display_sgr_site_key()
90
  {
91
  echo sprintf('<input type="text" name="sgr_site_key" class="regular-text" id="sgr_site_key" value="%s" />', $this->siteKey);
92
  }
93
 
94
+ public function display_sgr_secret_key()
95
  {
96
  echo sprintf('<input type="text" name="sgr_secret_key" class="regular-text" id="sgr_secret_key" value="%s" />', $this->secretKey);
97
  }
98
 
99
+ public function display_sgr_login_disable()
100
+ {
101
+ echo sprintf('<input type="checkbox" name="sgr_login_disable" id="sgr_login_disable" value="1" %s />', checked(1, $this->loginDisable, false));
102
+ }
103
+
104
+ public function display_sgr_version()
105
  {
106
  echo sprintf('<input type="checkbox" name="sgr_version" id="sgr_version" value="3" %s />', checked(3, $this->version, false));
107
  }
108
 
109
+ public function display_sgr_badge_hide()
110
  {
111
+ echo sprintf('<input type="checkbox" name="sgr_badge_hide" id="sgr_badge_hide" value="1" %s />', checked(1, $this->badgeHide, false));
112
  }
113
 
114
+ public function display_options()
115
  {
116
+ $fields = [
117
+ ['id' => 'sgr_site_key', 'label' => __('Site Key', self::TEXT_DOMAIN)],
118
+ ['id' => 'sgr_secret_key', 'label' => __('Secret Key', self::TEXT_DOMAIN)],
119
+ ['id' => 'sgr_login_disable', 'label' => __('Disable on login form', self::TEXT_DOMAIN)],
120
+ ['id' => 'sgr_version', 'label' => __('Enable reCAPTCHA v3', self::TEXT_DOMAIN)],
121
+ ['id' => 'sgr_badge_hide', 'label' => __('Hide reCAPTCHA v3 badge', self::TEXT_DOMAIN)],
122
+ ];
123
 
124
+ add_settings_section('sgr_header_section', __('Google reCAPTCHA keys', self::TEXT_DOMAIN), [], 'sgr_options');
 
 
 
125
 
126
+ foreach ($fields as $field) {
127
+ add_settings_field($field['id'], $field['label'], [$this, sprintf('display_%s', $field['id'])], 'sgr_options', 'sgr_header_section');
128
+ register_setting('sgr_header_section', $field['id']);
129
+ }
130
  }
131
 
132
+ public function enqueue_main()
133
  {
134
  $jsName = 'sgr.js';
135
  $jsPath = sprintf('%s%s', plugin_dir_path(__FILE__), $jsName);
139
  wp_localize_script('sgr_recaptcha_main', 'sgr_recaptcha', ['site_key' => $this->siteKey]);
140
  }
141
 
142
+ public function enqueue_scripts()
143
  {
144
+ $apiUrlBase = sprintf('https://www.recaptcha.net/recaptcha/api.js?hl=%s', get_locale());
145
+ $jsUrl = sprintf('%s&onload=sgr_2&render=explicit', $apiUrlBase);
146
+
147
  if ($this->version === 3) {
148
+ $jsUrl = sprintf('%s&render=%s&onload=sgr_3', $apiUrlBase, $this->siteKey);
149
  }
150
 
151
  wp_enqueue_script('sgr_recaptcha', $jsUrl);
152
  }
153
 
154
+ public function frontend()
155
  {
156
+ $this->enqueue_main();
157
 
158
  $sgr_display_list = [
159
  'comment_form_after_fields',
178
  array_push($sgr_verify_list, 'wp_authenticate_user');
179
  }
180
 
181
+ $sgrDisplay = $this->version === 3 ? 'v3_display' : 'v2_display';
182
 
183
  foreach ($sgr_display_list as $sgr_display) {
184
+ add_action($sgr_display, [$this, 'enqueue_scripts']);
185
  add_action($sgr_display, [$this, $sgrDisplay]);
186
  }
187
 
188
  foreach ($sgr_verify_list as $sgr_verify) {
189
+ add_action($sgr_verify, [$this, 'verify']);
190
  }
191
  }
192
 
193
+ public function v2_display()
194
  {
195
+ $cssName = 'sgr.css';
196
  $cssPath = sprintf('%s%s', plugin_dir_path(__FILE__), $cssName);
197
  $cssVersion = filemtime($cssPath);
198
 
199
+ wp_enqueue_style('style', sprintf('%s%s', plugin_dir_url(__FILE__), $cssName), [], $cssVersion);
200
 
201
  echo '<div class="sgr-recaptcha"></div>';
202
  }
203
 
204
+ public function v3_display()
205
  {
206
+ $badgeText = null;
207
+
208
+ if ($this->badgeHide) {
209
+ $cssName = 'sgr3_hide.css';
210
+ $cssPath = sprintf('%s%s', plugin_dir_path(__FILE__), $cssName);
211
+ $cssVersion = filemtime($cssPath);
212
+
213
+ wp_enqueue_style('style', sprintf('%s%s', plugin_dir_url(__FILE__), $cssName), [], $cssVersion);
214
+
215
+ $badgeText = sprintf('%s<p class="sgr-infotext">%s</p>', PHP_EOL, __('This site is protected by reCAPTCHA and the Google <a href="https://policies.google.com/privacy">Privacy Policy</a> and <a href="https://policies.google.com/terms">Terms of Service</a> apply.', self::TEXT_DOMAIN));
216
+ }
217
+
218
+ echo sprintf('<input type="hidden" name="g-recaptcha-response" class="sgr-recaptcha">%s', $badgeText);
219
  }
220
 
221
  public function errorMessage($error_code)
224
 
225
  switch ($error_code) {
226
  case 'missing-input-secret':
227
+ $error_message = __('The secret parameter is missing.', self::TEXT_DOMAIN);
228
  break;
229
  case 'missing-input-response':
230
+ $error_message = __('The response parameter is missing.', self::TEXT_DOMAIN);
231
  break;
232
  case 'invalid-input-secret':
233
+ $error_message = __('The secret parameter is invalid or malformed.', self::TEXT_DOMAIN);
234
  break;
235
  case 'invalid-input-response':
236
+ $error_message = __('The response parameter is invalid or malformed.', self::TEXT_DOMAIN);
237
  break;
238
  case 'bad-request':
239
+ $error_message = __('The request is invalid or malformed.', self::TEXT_DOMAIN);
240
  break;
241
  case 'timeout-or-duplicate':
242
+ $error_message = __('The response is no longer valid: either is too old or has been used previously.', self::TEXT_DOMAIN);
243
  break;
244
  }
245
 
249
  private function recaptchaResponse()
250
  {
251
  $recaptchaResponse = filter_input(INPUT_POST, 'g-recaptcha-response', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
252
+ $response = (array)wp_remote_get(sprintf('https://www.recaptcha.net/recaptcha/api/siteverify?secret=%s&response=%s', $this->secretKey, $recaptchaResponse));
253
 
254
  $this->recaptchaResponse = isset($response['body']) ? json_decode($response['body'], 1) : ['success' => false, 'error-codes' => ['general-fail']];
255
  }
258
  * @param $input
259
  * @return mixed
260
  */
261
+ public function verify($input)
262
  {
263
  $this->recaptchaResponse();
264
 
269
  if ((int)$this->recaptchaResponse['success'] === 1) {
270
  return $input;
271
  } else {
272
+ wp_die(sprintf('<p><strong>%s</strong> Google reCAPTCHA %s. %s</p>', __('Error:', self::TEXT_DOMAIN), __('verification failed', self::TEXT_DOMAIN), $error_message), 'reCAPTCHA', ['response' => 403, 'back_link' => 1]);
273
  }
274
  } else {
275
+ wp_die(sprintf('<p><strong>%s</strong> Google reCAPTCHA %s. %s</p>', __('Error:', self::TEXT_DOMAIN), __('verification failed', self::TEXT_DOMAIN), __('Do you have JavaScript enabled?', self::TEXT_DOMAIN)), 'reCAPTCHA', ['response' => 403, 'back_link' => 1]);
276
  }
277
  }
278
 
281
  $type = $this->version === 3 ? self::V3 : self::V2;
282
 
283
  if (!$this->siteKey || !$this->secretKey) {
284
+ return sprintf('<div class="notice notice-error"><p><strong>%s</strong> Google reCAPTCHA %s!</p><p>%s</p></div>', __('Warning:', self::TEXT_DOMAIN), __('is disabled', self::TEXT_DOMAIN), __(sprintf('You have to <a href="https://www.google.com/recaptcha/admin" rel="external">register your domain</a>, get required Google reCAPTCHA keys %s and save them bellow.', $type), self::TEXT_DOMAIN));
285
  } else {
286
+ return sprintf('<div class="notice notice-warning"><p><strong>%s</strong> Google reCAPTCHA %s!</p><p>%s</p></div>', __('Notice:', self::TEXT_DOMAIN), __('is enabled', self::TEXT_DOMAIN), __('Keep on mind, that in case of emergency, you can disable this plugin via FTP access, just rename the plugin folder.', self::TEXT_DOMAIN));
287
  }
288
  }
289
 
290
+ public function check()
291
  {
292
  if (!is_user_logged_in() && !wp_doing_ajax() && !function_exists('wpcf7_contact_form_shortcode') && $this->siteKey && $this->secretKey) {
293
+ $this->frontend();
294
  }
295
  }
296
  }
style.css DELETED
@@ -1,10 +0,0 @@
1
- .sgr-recaptcha {
2
- transform: scale(0.90);
3
- transform-origin: 0 0;
4
- clear: both;
5
- padding: 10px 0 5px 0;
6
- }
7
-
8
- .login form {
9
- padding-bottom: 26px;
10
- }
 
 
 
 
 
 
 
 
 
 
uninstall.php CHANGED
@@ -15,7 +15,7 @@ class SimpleGoogleRecaptchaUninstall
15
  */
16
  public function __construct()
17
  {
18
- $this->sgr_delete(['site_key', 'secret_key', 'login_disable', 'version']);
19
  }
20
 
21
  private function sgr_delete($array)
15
  */
16
  public function __construct()
17
  {
18
+ $this->sgr_delete(['site_key', 'secret_key', 'login_disable', 'version', 'badge_hide']);
19
  }
20
 
21
  private function sgr_delete($array)