Version Description
- New: Emergency reCAPTCHA deactivate link
Download this release
Release Info
Developer | Minor |
Plugin | Simple Google reCAPTCHA |
Version | 3.6 |
Comparing to | |
See all releases |
Code changes from version 3.5 to 3.6
- readme.txt +9 -2
- sgr.js +4 -4
- simple-google-recaptcha.php +111 -34
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.
|
7 |
Requires PHP: 7.1
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
@@ -18,6 +18,8 @@ No more spam comments and brute-force attacks against user accounts. Small plugi
|
|
18 |
|
19 |
Google reCAPTCHA verification will be required only for not logged in users.
|
20 |
|
|
|
|
|
21 |
= What is protected with reCAPTCHA? =
|
22 |
* Login form
|
23 |
* Registration form
|
@@ -44,9 +46,10 @@ If you write me (on support forum etc.), be patient, please. I work on this plug
|
|
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
|
@@ -55,8 +58,12 @@ Use standard WordPress Plugins page. In emergency case, rename plugin folder und
|
|
55 |
4. Login
|
56 |
5. Settings
|
57 |
6. reCAPTCHA v3 text instead of badge
|
|
|
58 |
|
59 |
== Changelog ==
|
|
|
|
|
|
|
60 |
= 3.5 =
|
61 |
* Bugfix: More reliable reCAPTCHA injection (init action)
|
62 |
* New: Dynamic action name to see stats in Google reCAPTCHA admin console for each page
|
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.6
|
7 |
Requires PHP: 7.1
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
18 |
|
19 |
Google reCAPTCHA verification will be required only for not logged in users.
|
20 |
|
21 |
+
User, who newly setup the keys, will see (max for 30 days) emergency reCAPTCHA deactivate link - don't need FTP access to disable Simple Google reCAPTCHA in case of emergency now.
|
22 |
+
|
23 |
= What is protected with reCAPTCHA? =
|
24 |
* Login form
|
25 |
* Registration form
|
46 |
* Possibility to replace v3 reCAPTCHA badge by text
|
47 |
* reCAPTCHA language based on WordPress settings
|
48 |
* Works in countries where Google domain is blocked
|
49 |
+
* Emergency reCAPTCHA deactivate link
|
50 |
|
51 |
= How to disable this plugin? =
|
52 |
+
Use standard WordPress Plugins page. In emergency case, rename plugin folder under /wp-content/plugins/ over FTP access or use emergency reCAPTCHA deactivate link.
|
53 |
|
54 |
== Screenshots ==
|
55 |
1. New comment
|
58 |
4. Login
|
59 |
5. Settings
|
60 |
6. reCAPTCHA v3 text instead of badge
|
61 |
+
7. Emergency reCAPTCHA deactivate link
|
62 |
|
63 |
== Changelog ==
|
64 |
+
= 3.6 =
|
65 |
+
* New: Emergency reCAPTCHA deactivate link
|
66 |
+
|
67 |
= 3.5 =
|
68 |
* Bugfix: More reliable reCAPTCHA injection (init action)
|
69 |
* New: Dynamic action name to see stats in Google reCAPTCHA admin console for each page
|
sgr.js
CHANGED
@@ -2,7 +2,7 @@ function sgr_2() {
|
|
2 |
console.log('SGR_2 loaded!');
|
3 |
let recaptcha = document.getElementsByClassName('sgr-recaptcha');
|
4 |
for (let i = 0; i < recaptcha.length; i++) {
|
5 |
-
grecaptcha.render(recaptcha.item(i), {'sitekey': sgr_recaptcha.
|
6 |
}
|
7 |
}
|
8 |
|
@@ -10,7 +10,7 @@ function sgr_3() {
|
|
10 |
console.log('SGR_3 loaded!');
|
11 |
let actionName = window.location.pathname + window.location.search;
|
12 |
actionName = actionName.replace(/[^a-zA-Z0-9 ]/g, '_');
|
13 |
-
grecaptcha.execute(sgr_recaptcha.
|
14 |
let recaptcha = document.getElementsByClassName('sgr-recaptcha');
|
15 |
for (let i = 0; i < recaptcha.length; i++) {
|
16 |
recaptcha.item(i).value = token;
|
@@ -23,13 +23,13 @@ document.addEventListener('DOMContentLoaded', function (event) {
|
|
23 |
|
24 |
if (sgr_version) {
|
25 |
console.log('SGR admin loaded!');
|
26 |
-
sgr_version.addEventListener('
|
27 |
|
28 |
function removeKeys() {
|
29 |
let sgr_site_key = document.getElementById('sgr_site_key');
|
30 |
let sgr_secret_key = document.getElementById('sgr_secret_key');
|
31 |
|
32 |
-
if (sgr_site_key.value === sgr_recaptcha.
|
33 |
sgr_site_key.value = '';
|
34 |
sgr_secret_key.value = '';
|
35 |
}
|
2 |
console.log('SGR_2 loaded!');
|
3 |
let recaptcha = document.getElementsByClassName('sgr-recaptcha');
|
4 |
for (let i = 0; i < recaptcha.length; i++) {
|
5 |
+
grecaptcha.render(recaptcha.item(i), {'sitekey': sgr_recaptcha.sgr_site_key});
|
6 |
}
|
7 |
}
|
8 |
|
10 |
console.log('SGR_3 loaded!');
|
11 |
let actionName = window.location.pathname + window.location.search;
|
12 |
actionName = actionName.replace(/[^a-zA-Z0-9 ]/g, '_');
|
13 |
+
grecaptcha.execute(sgr_recaptcha.sgr_site_key, {action: 'sgr_' + actionName}).then(function (token) {
|
14 |
let recaptcha = document.getElementsByClassName('sgr-recaptcha');
|
15 |
for (let i = 0; i < recaptcha.length; i++) {
|
16 |
recaptcha.item(i).value = token;
|
23 |
|
24 |
if (sgr_version) {
|
25 |
console.log('SGR admin loaded!');
|
26 |
+
sgr_version.addEventListener('click', removeKeys);
|
27 |
|
28 |
function removeKeys() {
|
29 |
let sgr_site_key = document.getElementById('sgr_site_key');
|
30 |
let sgr_secret_key = document.getElementById('sgr_secret_key');
|
31 |
|
32 |
+
if (sgr_site_key.value === sgr_recaptcha.sgr_site_key) {
|
33 |
sgr_site_key.value = '';
|
34 |
sgr_secret_key.value = '';
|
35 |
}
|
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.
|
6 |
* Author: Michal Novák
|
7 |
* Author URI: https://www.novami.cz
|
8 |
* License: GPL3
|
@@ -19,9 +19,17 @@ if (!defined('ABSPATH')) {
|
|
19 |
*/
|
20 |
class SimpleGoogleRecaptcha
|
21 |
{
|
22 |
-
const
|
23 |
-
const
|
24 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
private $pluginName;
|
27 |
private $version;
|
@@ -29,6 +37,7 @@ class SimpleGoogleRecaptcha
|
|
29 |
private $badgeHide;
|
30 |
private $siteKey;
|
31 |
private $secretKey;
|
|
|
32 |
|
33 |
private $recaptchaResponse;
|
34 |
|
@@ -38,11 +47,23 @@ class SimpleGoogleRecaptcha
|
|
38 |
public function __construct()
|
39 |
{
|
40 |
$this->pluginName = get_file_data(__FILE__, ['Name' => 'Plugin Name'])['Name'];
|
41 |
-
|
42 |
-
$
|
43 |
-
$
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
add_filter(sprintf('plugin_action_links_%s', plugin_basename(__FILE__)), [$this, 'action_links']);
|
48 |
|
@@ -52,25 +73,42 @@ class SimpleGoogleRecaptcha
|
|
52 |
add_action('init', [$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
|
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
|
68 |
}
|
69 |
}
|
70 |
|
71 |
public function options_page()
|
72 |
{
|
73 |
-
echo sprintf('<div class="wrap"><h1>%s - %s</h1><form method="post" action="
|
74 |
|
75 |
settings_fields('sgr_header_section');
|
76 |
do_settings_sections('sgr_options');
|
@@ -115,14 +153,14 @@ class SimpleGoogleRecaptcha
|
|
115 |
public function display_options()
|
116 |
{
|
117 |
$fields = [
|
118 |
-
['id' =>
|
119 |
-
['id' =>
|
120 |
-
['id' =>
|
121 |
-
['id' =>
|
122 |
-
['id' =>
|
123 |
];
|
124 |
|
125 |
-
add_settings_section('sgr_header_section', __('Google reCAPTCHA keys', self::
|
126 |
|
127 |
foreach ($fields as $field) {
|
128 |
add_settings_field($field['id'], $field['label'], [$this, sprintf('display_%s', $field['id'])], 'sgr_options', 'sgr_header_section');
|
@@ -137,7 +175,7 @@ class SimpleGoogleRecaptcha
|
|
137 |
$jsVersion = filemtime($jsPath);
|
138 |
|
139 |
wp_enqueue_script('sgr_recaptcha_main', sprintf('%s%s', plugin_dir_url(__FILE__), $jsName), [], $jsVersion);
|
140 |
-
wp_localize_script('sgr_recaptcha_main', 'sgr_recaptcha', [
|
141 |
}
|
142 |
|
143 |
public function enqueue_scripts()
|
@@ -162,7 +200,6 @@ class SimpleGoogleRecaptcha
|
|
162 |
'lostpassword_form',
|
163 |
'woocommerce_register_form',
|
164 |
'woocommerce_lostpassword_form',
|
165 |
-
'woocommerce_after_order_notes',
|
166 |
'bp_after_signup_profile_fields',
|
167 |
];
|
168 |
|
@@ -199,6 +236,8 @@ class SimpleGoogleRecaptcha
|
|
199 |
|
200 |
wp_enqueue_style('style', sprintf('%s%s', plugin_dir_url(__FILE__), $cssName), [], $cssVersion);
|
201 |
|
|
|
|
|
202 |
echo '<div class="sgr-recaptcha"></div>';
|
203 |
}
|
204 |
|
@@ -213,34 +252,57 @@ class SimpleGoogleRecaptcha
|
|
213 |
|
214 |
wp_enqueue_style('style', sprintf('%s%s', plugin_dir_url(__FILE__), $cssName), [], $cssVersion);
|
215 |
|
216 |
-
$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::
|
217 |
}
|
218 |
|
|
|
|
|
219 |
echo sprintf('<input type="hidden" name="g-recaptcha-response" class="sgr-recaptcha">%s', $badgeText);
|
220 |
}
|
221 |
|
222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
{
|
224 |
$error_message = null;
|
225 |
|
226 |
switch ($error_code) {
|
227 |
case 'missing-input-secret':
|
228 |
-
$error_message = __('The secret parameter is missing.', self::
|
229 |
break;
|
230 |
case 'missing-input-response':
|
231 |
-
$error_message = __('The response parameter is missing.', self::
|
232 |
break;
|
233 |
case 'invalid-input-secret':
|
234 |
-
$error_message = __('The secret parameter is invalid or malformed.', self::
|
235 |
break;
|
236 |
case 'invalid-input-response':
|
237 |
-
$error_message = __('The response parameter is invalid or malformed.', self::
|
238 |
break;
|
239 |
case 'bad-request':
|
240 |
-
$error_message = __('The request is invalid or malformed.', self::
|
241 |
break;
|
242 |
case 'timeout-or-duplicate':
|
243 |
-
$error_message = __('The response is no longer valid: either is too old or has been used previously.', self::
|
244 |
break;
|
245 |
}
|
246 |
|
@@ -263,28 +325,43 @@ class SimpleGoogleRecaptcha
|
|
263 |
{
|
264 |
$this->recaptchaResponse();
|
265 |
|
266 |
-
if ($_SERVER['REQUEST_METHOD']
|
267 |
$recaptcha_error_code = isset($this->recaptchaResponse['error-codes'][0]) ? $this->recaptchaResponse['error-codes'][0] : null;
|
268 |
$error_message = $this->errorMessage($recaptcha_error_code);
|
269 |
|
270 |
if ((int)$this->recaptchaResponse['success'] === 1) {
|
271 |
return $input;
|
272 |
} else {
|
273 |
-
wp_die(sprintf('<p><strong>%s</strong> Google reCAPTCHA %s. %s</p>', __('Error:', self::
|
274 |
}
|
275 |
} else {
|
276 |
-
wp_die(sprintf('<p><strong>%s</strong> Google reCAPTCHA %s. %s</p>', __('Error:', self::
|
277 |
}
|
278 |
}
|
279 |
|
|
|
|
|
|
|
280 |
public function messageProtectionStatus()
|
281 |
{
|
282 |
-
$type = $this->version === 3 ? self::
|
283 |
|
284 |
if (!$this->siteKey || !$this->secretKey) {
|
285 |
-
return sprintf('<div class="notice notice-error"><p><strong>%s</strong> Google reCAPTCHA %s!</p><p>%s</p></div>', __('Warning:', self::
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
286 |
} else {
|
287 |
-
return
|
288 |
}
|
289 |
}
|
290 |
|
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.6
|
6 |
* Author: Michal Novák
|
7 |
* Author URI: https://www.novami.cz
|
8 |
* License: GPL3
|
19 |
*/
|
20 |
class SimpleGoogleRecaptcha
|
21 |
{
|
22 |
+
const SGR_TEXT_DOMAIN = 'simple-google-recaptcha';
|
23 |
+
const SGR_PAGE_OPTIONS_QUERY = '?page=sgr_options';
|
24 |
+
const SGR_GET_DISABLE = 'sgr_disable';
|
25 |
+
const SGR_OPTION_VERSION = 'sgr_version';
|
26 |
+
const SGR_OPTION_LOGIN_DISABLE = 'sgr_login_disable';
|
27 |
+
const SGR_OPTION_BADGE_HIDE = 'sgr_badge_hide';
|
28 |
+
const SGR_OPTION_SITE_KEY = 'sgr_site_key';
|
29 |
+
const SGR_OPTION_SECRET_KEY = 'sgr_secret_key';
|
30 |
+
const SGR_OPTION_HASH = 'sgr_hash';
|
31 |
+
const SGR_V2 = 'v2 "I\'m not a robot" Checkbox';
|
32 |
+
const SGR_V3 = 'v3';
|
33 |
|
34 |
private $pluginName;
|
35 |
private $version;
|
37 |
private $badgeHide;
|
38 |
private $siteKey;
|
39 |
private $secretKey;
|
40 |
+
private $cookieHash;
|
41 |
|
42 |
private $recaptchaResponse;
|
43 |
|
47 |
public function __construct()
|
48 |
{
|
49 |
$this->pluginName = get_file_data(__FILE__, ['Name' => 'Plugin Name'])['Name'];
|
50 |
+
|
51 |
+
$postAction = filter_input(INPUT_POST, 'action', FILTER_SANITIZE_SPECIAL_CHARS);
|
52 |
+
if ($postAction === 'update') {
|
53 |
+
$this->updateSettings();
|
54 |
+
}
|
55 |
+
|
56 |
+
$this->version = (int)filter_var(get_option(self::SGR_OPTION_VERSION), FILTER_SANITIZE_NUMBER_INT);
|
57 |
+
$this->loginDisable = (int)filter_var(get_option(self::SGR_OPTION_LOGIN_DISABLE), FILTER_SANITIZE_NUMBER_INT);
|
58 |
+
$this->badgeHide = (int)filter_var(get_option(self::SGR_OPTION_BADGE_HIDE), FILTER_SANITIZE_NUMBER_INT);
|
59 |
+
$this->siteKey = filter_var(get_option(self::SGR_OPTION_SITE_KEY), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
60 |
+
$this->secretKey = filter_var(get_option(self::SGR_OPTION_SECRET_KEY), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
61 |
+
|
62 |
+
$this->cookieHash = filter_input(INPUT_COOKIE, self::SGR_OPTION_HASH, FILTER_SANITIZE_SPECIAL_CHARS);
|
63 |
+
|
64 |
+
if (filter_input(INPUT_GET, 'action', FILTER_SANITIZE_SPECIAL_CHARS) === self::SGR_GET_DISABLE) {
|
65 |
+
$this->disableProtection();
|
66 |
+
}
|
67 |
|
68 |
add_filter(sprintf('plugin_action_links_%s', plugin_basename(__FILE__)), [$this, 'action_links']);
|
69 |
|
73 |
add_action('init', [$this, 'check']);
|
74 |
}
|
75 |
|
76 |
+
public function updateSettings()
|
77 |
+
{
|
78 |
+
$hash = null;
|
79 |
+
$options = [self::SGR_OPTION_VERSION, self::SGR_OPTION_LOGIN_DISABLE, self::SGR_OPTION_BADGE_HIDE, self::SGR_OPTION_SITE_KEY, self::SGR_OPTION_SECRET_KEY];
|
80 |
+
|
81 |
+
foreach ($options as $option) {
|
82 |
+
$postValue = filter_input(INPUT_POST, $option, FILTER_SANITIZE_SPECIAL_CHARS);
|
83 |
+
update_option($option, $postValue);
|
84 |
+
|
85 |
+
if (substr_count($option, 'key')) {
|
86 |
+
$hash .= $postValue;
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
setcookie(self::SGR_OPTION_HASH, md5($hash), time() + 60 * 60 * 24 * 30, '/');
|
91 |
+
}
|
92 |
+
|
93 |
/**
|
94 |
* @param $links
|
95 |
* @return array
|
96 |
*/
|
97 |
public function action_links($links)
|
98 |
{
|
99 |
+
return array_merge(['settings' => sprintf('<a href="options-general.php%s">%s</a>', self::SGR_PAGE_OPTIONS_QUERY, __('Settings', self::SGR_TEXT_DOMAIN))], $links);
|
100 |
}
|
101 |
|
102 |
public function activation($plugin)
|
103 |
{
|
104 |
if ($plugin == plugin_basename(__FILE__) && (!$this->siteKey || !$this->secretKey)) {
|
105 |
+
exit(wp_redirect(admin_url(sprintf('options-general.php%s', self::SGR_PAGE_OPTIONS_QUERY))));
|
106 |
}
|
107 |
}
|
108 |
|
109 |
public function options_page()
|
110 |
{
|
111 |
+
echo sprintf('<div class="wrap"><h1>%s - %s</h1><form method="post" action="%s">', $this->pluginName, __('Settings', self::SGR_TEXT_DOMAIN), self::SGR_PAGE_OPTIONS_QUERY);
|
112 |
|
113 |
settings_fields('sgr_header_section');
|
114 |
do_settings_sections('sgr_options');
|
153 |
public function display_options()
|
154 |
{
|
155 |
$fields = [
|
156 |
+
['id' => self::SGR_OPTION_SITE_KEY, 'label' => __('Site Key', self::SGR_TEXT_DOMAIN)],
|
157 |
+
['id' => self::SGR_OPTION_SECRET_KEY, 'label' => __('Secret Key', self::SGR_TEXT_DOMAIN)],
|
158 |
+
['id' => self::SGR_OPTION_LOGIN_DISABLE, 'label' => __('Disable on login form', self::SGR_TEXT_DOMAIN)],
|
159 |
+
['id' => self::SGR_OPTION_VERSION, 'label' => __('Enable reCAPTCHA v3', self::SGR_TEXT_DOMAIN)],
|
160 |
+
['id' => self::SGR_OPTION_BADGE_HIDE, 'label' => __('Hide reCAPTCHA v3 badge', self::SGR_TEXT_DOMAIN)],
|
161 |
];
|
162 |
|
163 |
+
add_settings_section('sgr_header_section', __('Google reCAPTCHA keys', self::SGR_TEXT_DOMAIN), [], 'sgr_options');
|
164 |
|
165 |
foreach ($fields as $field) {
|
166 |
add_settings_field($field['id'], $field['label'], [$this, sprintf('display_%s', $field['id'])], 'sgr_options', 'sgr_header_section');
|
175 |
$jsVersion = filemtime($jsPath);
|
176 |
|
177 |
wp_enqueue_script('sgr_recaptcha_main', sprintf('%s%s', plugin_dir_url(__FILE__), $jsName), [], $jsVersion);
|
178 |
+
wp_localize_script('sgr_recaptcha_main', 'sgr_recaptcha', [self::SGR_OPTION_SITE_KEY => $this->siteKey]);
|
179 |
}
|
180 |
|
181 |
public function enqueue_scripts()
|
200 |
'lostpassword_form',
|
201 |
'woocommerce_register_form',
|
202 |
'woocommerce_lostpassword_form',
|
|
|
203 |
'bp_after_signup_profile_fields',
|
204 |
];
|
205 |
|
236 |
|
237 |
wp_enqueue_style('style', sprintf('%s%s', plugin_dir_url(__FILE__), $cssName), [], $cssVersion);
|
238 |
|
239 |
+
$this->displayDisableProtection();
|
240 |
+
|
241 |
echo '<div class="sgr-recaptcha"></div>';
|
242 |
}
|
243 |
|
252 |
|
253 |
wp_enqueue_style('style', sprintf('%s%s', plugin_dir_url(__FILE__), $cssName), [], $cssVersion);
|
254 |
|
255 |
+
$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::SGR_TEXT_DOMAIN));
|
256 |
}
|
257 |
|
258 |
+
$this->displayDisableProtection();
|
259 |
+
|
260 |
echo sprintf('<input type="hidden" name="g-recaptcha-response" class="sgr-recaptcha">%s', $badgeText);
|
261 |
}
|
262 |
|
263 |
+
private function displayDisableProtection()
|
264 |
+
{
|
265 |
+
if ($this->adminCookieHash()) {
|
266 |
+
echo sprintf(sprintf('<p class="sgr-infotext"><a href="?action=%%s">%s</a></p>', __('Emergency reCAPTCHA deactivate', self::SGR_TEXT_DOMAIN)), self::SGR_GET_DISABLE);
|
267 |
+
}
|
268 |
+
}
|
269 |
+
|
270 |
+
private function disableProtection()
|
271 |
+
{
|
272 |
+
if ($this->adminCookieHash()) {
|
273 |
+
delete_option(self::SGR_OPTION_SITE_KEY);
|
274 |
+
delete_option(self::SGR_OPTION_SECRET_KEY);
|
275 |
+
|
276 |
+
$this->siteKey = $this->secretKey = null;
|
277 |
+
}
|
278 |
+
}
|
279 |
+
|
280 |
+
/**
|
281 |
+
* @param $error_code
|
282 |
+
* @return string|void|null
|
283 |
+
*/
|
284 |
+
private function errorMessage($error_code)
|
285 |
{
|
286 |
$error_message = null;
|
287 |
|
288 |
switch ($error_code) {
|
289 |
case 'missing-input-secret':
|
290 |
+
$error_message = __('The secret parameter is missing.', self::SGR_TEXT_DOMAIN);
|
291 |
break;
|
292 |
case 'missing-input-response':
|
293 |
+
$error_message = __('The response parameter is missing.', self::SGR_TEXT_DOMAIN);
|
294 |
break;
|
295 |
case 'invalid-input-secret':
|
296 |
+
$error_message = __('The secret parameter is invalid or malformed.', self::SGR_TEXT_DOMAIN);
|
297 |
break;
|
298 |
case 'invalid-input-response':
|
299 |
+
$error_message = __('The response parameter is invalid or malformed.', self::SGR_TEXT_DOMAIN);
|
300 |
break;
|
301 |
case 'bad-request':
|
302 |
+
$error_message = __('The request is invalid or malformed.', self::SGR_TEXT_DOMAIN);
|
303 |
break;
|
304 |
case 'timeout-or-duplicate':
|
305 |
+
$error_message = __('The response is no longer valid: either is too old or has been used previously.', self::SGR_TEXT_DOMAIN);
|
306 |
break;
|
307 |
}
|
308 |
|
325 |
{
|
326 |
$this->recaptchaResponse();
|
327 |
|
328 |
+
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['g-recaptcha-response'])) {
|
329 |
$recaptcha_error_code = isset($this->recaptchaResponse['error-codes'][0]) ? $this->recaptchaResponse['error-codes'][0] : null;
|
330 |
$error_message = $this->errorMessage($recaptcha_error_code);
|
331 |
|
332 |
if ((int)$this->recaptchaResponse['success'] === 1) {
|
333 |
return $input;
|
334 |
} else {
|
335 |
+
wp_die(sprintf('<p><strong>%s</strong> Google reCAPTCHA %s. %s</p>', __('Error:', self::SGR_TEXT_DOMAIN), __('verification failed', self::SGR_TEXT_DOMAIN), $error_message), 'reCAPTCHA', ['response' => 403, 'back_link' => 1]);
|
336 |
}
|
337 |
} else {
|
338 |
+
wp_die(sprintf('<p><strong>%s</strong> Google reCAPTCHA %s. %s</p>', __('Error:', self::SGR_TEXT_DOMAIN), __('verification failed', self::SGR_TEXT_DOMAIN), __('Do you have JavaScript enabled?', self::SGR_TEXT_DOMAIN)), 'reCAPTCHA', ['response' => 403, 'back_link' => 1]);
|
339 |
}
|
340 |
}
|
341 |
|
342 |
+
/**
|
343 |
+
* @return string
|
344 |
+
*/
|
345 |
public function messageProtectionStatus()
|
346 |
{
|
347 |
+
$type = $this->version === 3 ? self::SGR_V3 : self::SGR_V2;
|
348 |
|
349 |
if (!$this->siteKey || !$this->secretKey) {
|
350 |
+
return sprintf('<div class="notice notice-error"><p><strong>%s</strong> Google reCAPTCHA %s!</p><p>%s</p></div>', __('Warning:', self::SGR_TEXT_DOMAIN), __('is disabled', self::SGR_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::SGR_TEXT_DOMAIN));
|
351 |
+
} else {
|
352 |
+
return sprintf('<div class="notice notice-warning"><p><strong>%s</strong> Google reCAPTCHA %s!</p><p>%s</p></div>', __('Notice:', self::SGR_TEXT_DOMAIN), __('is enabled', self::SGR_TEXT_DOMAIN), __('Keep on mind, that in case of emergency, you can disable this plugin via FTP access, just rename the plugin folder.', self::SGR_TEXT_DOMAIN));
|
353 |
+
}
|
354 |
+
}
|
355 |
+
|
356 |
+
/**
|
357 |
+
* @return bool
|
358 |
+
*/
|
359 |
+
public function adminCookieHash()
|
360 |
+
{
|
361 |
+
if ($this->cookieHash === md5($this->siteKey . $this->secretKey)) {
|
362 |
+
return true;
|
363 |
} else {
|
364 |
+
return false;
|
365 |
}
|
366 |
}
|
367 |
|