Simple Google reCAPTCHA - Version 3.1

Version Description

  • New: Keys validation after save.
  • New: More detailed error messages.
  • New: Plugin is disabled until you set correct keys.
Download this release

Release Info

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

Code changes from version 3.0 to 3.1

Files changed (3) hide show
  1. readme.txt +11 -5
  2. simple-google-recaptcha.php +238 -121
  3. uninstall.php +24 -8
readme.txt CHANGED
@@ -1,14 +1,15 @@
1
  === Simple Google reCAPTCHA ===
2
  Contributors: Minor
3
  Tags: recaptcha, spam, block, captcha, bots, brute, force, protect, comments, secure, attack, registration, reset, form, buddypress, woocommerce, google
4
- Requires at least: 4.2.0
5
- Tested up to: 5.2.2
6
- Stable tag: 3.0
 
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
  Donate link: https://www.paypal.me/NovaMi
10
 
11
- Simply protect your WordPress against spam comments and brute-force attacks thanks to Google reCAPTCHA for free and without ads!
12
 
13
  == Description ==
14
  Simple Google reCAPTCHA will protect your WordPress! No more spam comments and brute-force attacks against user accounts. Lightweight plugin - just few KBs to download and no ads! BuddyPress and WooCommerce support.
@@ -30,7 +31,7 @@ If you write to me (on support center etc.) and expect an answer, be patient, pl
30
  == Installation ==
31
  1. Upload Simple Google reCAPTCHA files to the "/wp-content/plugins/simple-google-recaptcha" directory, or install Simple Google reCAPTCHA through the WordPress Plugins page directly.
32
  2. Activate Simple Google reCAPTCHA through the WordPress Plugins page.
33
- 3. Use the menu Settings => reCAPTCHA to configure Simple Google reCAPTCHA.
34
 
35
  == Frequently Asked Questions ==
36
  = Why to install this plugin? =
@@ -47,6 +48,11 @@ Just use standard Plugin overview page in WordPress admin section and deactivate
47
  5. Simple Google reCAPTCHA - Settings
48
 
49
  == Changelog ==
 
 
 
 
 
50
  = 3.0 =
51
  * Bugfix: User login (including password in plaintext) could get into server error log in specific case.
52
 
1
  === Simple Google reCAPTCHA ===
2
  Contributors: Minor
3
  Tags: recaptcha, spam, block, captcha, bots, brute, force, protect, comments, secure, attack, registration, reset, form, buddypress, woocommerce, google
4
+ Requires at least: 4.2
5
+ Tested up to: 5.4
6
+ Stable tag: 3.1
7
+ Requires PHP: 5.6
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
  Donate link: https://www.paypal.me/NovaMi
11
 
12
+ Simply protect your WordPress against spam comments and brute-force attacks thanks to Google reCAPTCHA v2 Checkbox for free and without ads!
13
 
14
  == Description ==
15
  Simple Google reCAPTCHA will protect your WordPress! No more spam comments and brute-force attacks against user accounts. Lightweight plugin - just few KBs to download and no ads! BuddyPress and WooCommerce support.
31
  == Installation ==
32
  1. Upload Simple Google reCAPTCHA files to the "/wp-content/plugins/simple-google-recaptcha" directory, or install Simple Google reCAPTCHA through the WordPress Plugins page directly.
33
  2. Activate Simple Google reCAPTCHA through the WordPress Plugins page.
34
+ 3. Use the menu Settings => reCAPTCHA to configure Simple Google reCAPTCHA. You have to insert reCAPTCHA v2 Checkbox keys.
35
 
36
  == Frequently Asked Questions ==
37
  = Why to install this plugin? =
48
  5. Simple Google reCAPTCHA - Settings
49
 
50
  == Changelog ==
51
+ = 3.1 =
52
+ * New: Keys validation after save.
53
+ * New: More detailed error messages.
54
+ * New: Plugin is disabled until you set correct keys.
55
+
56
  = 3.0 =
57
  * Bugfix: User login (including password in plaintext) could get into server error log in specific case.
58
 
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.0
6
  * Author: Michal Novák
7
  * Author URI: https://www.novami.cz
8
  * License: GPL3
@@ -10,140 +10,257 @@
10
  * Domain Path: /languages
11
  */
12
 
13
- if (!defined('ABSPATH')) {
14
- die( 'Direct access not allowed!' );
15
- }
 
 
 
 
16
 
17
- const VERSION = '3.0';
18
 
19
- function sgr_add_plugin_action_links($links) {
20
- return array_merge(array("settings" => "<a href=\"options-general.php?page=sgr-options\">".__("Settings", "simple-google-recaptcha")."</a>"), $links);
21
- }
22
- add_filter("plugin_action_links_".plugin_basename(__FILE__), "sgr_add_plugin_action_links");
 
 
 
 
23
 
24
- function sgr_activation($plugin) {
25
- if ($plugin == plugin_basename(__FILE__) && (!get_option("sgr_site_key") || !get_option("sgr_secret_key"))) {
26
- exit(wp_redirect(admin_url("options-general.php?page=sgr-options")));
27
- }
28
- }
29
- add_action("activated_plugin", "sgr_activation");
30
-
31
- function sgr_options_page() {
32
- echo "<div class=\"wrap\">
33
- <h1>".__("Simple Google reCAPTCHA Options", "simple-google-recaptcha")."</h1>
34
- <form method=\"post\" action=\"options.php\">";
35
- settings_fields("sgr_header_section");
36
- do_settings_sections("sgr-options");
37
- submit_button();
38
- echo "</form>
39
- </div>";
40
- }
41
 
42
- function sgr_menu() {
43
- add_submenu_page("options-general.php", "reCAPTCHA", "reCAPTCHA", "manage_options", "sgr-options", "sgr_options_page");
44
- }
45
- add_action("admin_menu", "sgr_menu");
 
 
 
 
46
 
47
- function sgr_display_content() {
48
- echo "<p>".__("You have to <a href=\"https://www.google.com/recaptcha/admin\" rel=\"external\">register your domain</a> first, get required keys (reCAPTCHA V2) from Google and save them bellow.", "simple-google-recaptcha")."</p>";
49
- }
 
 
 
50
 
51
- function sgr_display_site_key_element() {
52
- $sgr_site_key = filter_var(get_option("sgr_site_key"), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
53
- echo "<input type=\"text\" name=\"sgr_site_key\" class=\"regular-text\" id=\"sgr_site_key\" value=\"{$sgr_site_key}\" />";
54
- }
55
 
56
- function sgr_display_secret_key_element() {
57
- $sgr_secret_key = filter_var(get_option("sgr_secret_key"), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
58
- echo "<input type=\"text\" name=\"sgr_secret_key\" class=\"regular-text\" id=\"sgr_secret_key\" value=\"{$sgr_secret_key}\" />";
59
- }
60
 
61
- function sgr_display_login_check_disable() {
62
- echo "<input type=\"checkbox\" name=\"sgr_login_check_disable\" id=\"sgr_login_check_disable\" value=\"1\" ".checked(1, get_option("sgr_login_check_disable"), false)." />";
63
- }
64
 
65
- function sgr_display_options() {
66
- add_settings_section("sgr_header_section", __("What first?", "simple-google-recaptcha"), "sgr_display_content", "sgr-options");
 
67
 
68
- add_settings_field("sgr_site_key", __("Site Key", "simple-google-recaptcha"), "sgr_display_site_key_element", "sgr-options", "sgr_header_section");
69
- add_settings_field("sgr_secret_key", __("Secret Key", "simple-google-recaptcha"), "sgr_display_secret_key_element", "sgr-options", "sgr_header_section");
70
- add_settings_field("sgr_login_check_disable", __("Disable reCAPTCHA for login", "simple-google-recaptcha"), "sgr_display_login_check_disable", "sgr-options", "sgr_header_section");
71
 
72
- register_setting("sgr_header_section", "sgr_site_key");
73
- register_setting("sgr_header_section", "sgr_secret_key");
74
- register_setting("sgr_header_section", "sgr_login_check_disable");
75
- }
76
- add_action("admin_init", "sgr_display_options");
77
 
78
- function load_language_sgr() {
79
- load_plugin_textdomain("simple-google-recaptcha", false, dirname(plugin_basename(__FILE__))."/languages/");
80
- }
81
- add_action("plugins_loaded", "load_language_sgr");
82
-
83
- function frontend_sgr_script() {
84
- $sgr_site_key = filter_var(get_option("sgr_site_key"), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
85
- $sgr_display_list = array("comment_form_after_fields", "register_form", "lost_password", "lostpassword_form", "retrieve_password", "resetpass_form", "woocommerce_register_form", "woocommerce_lostpassword_form", "woocommerce_after_order_notes", "bp_after_signup_profile_fields");
86
-
87
- if (!get_option("sgr_login_check_disable")) {
88
- array_push($sgr_display_list, "login_form", "woocommerce_login_form");
89
- }
90
-
91
- foreach($sgr_display_list as $sgr_display) {
92
- add_action($sgr_display, "sgr_display");
93
- }
94
-
95
- wp_register_script("sgr_recaptcha_main", plugin_dir_url(__FILE__)."main.js?v=".VERSION);
96
- wp_enqueue_script("sgr_recaptcha_main");
97
- wp_localize_script("sgr_recaptcha_main", "sgr_recaptcha", array("site_key" => $sgr_site_key));
98
-
99
- wp_register_script("sgr_recaptcha", "https://www.google.com/recaptcha/api.js?hl=".get_locale()."&onload=sgr&render=explicit");
100
- wp_enqueue_script("sgr_recaptcha");
101
-
102
- wp_enqueue_style("style", plugin_dir_url(__FILE__)."style.css?v=".VERSION);
103
- }
104
 
105
- function sgr_display() {
106
- echo "<div class=\"sgr-recaptcha\"></div>";
107
- }
 
108
 
109
- function sgr_verify($input) {
110
- if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["g-recaptcha-response"])) {
111
- $sgr_secret_key = filter_var(get_option("sgr_secret_key"), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
112
- $recaptcha_response = filter_input(INPUT_POST, "g-recaptcha-response", FILTER_SANITIZE_FULL_SPECIAL_CHARS);
113
- $response = wp_remote_get("https://www.google.com/recaptcha/api/siteverify?secret={$sgr_secret_key}&response={$recaptcha_response}");
114
-
115
- if (is_array($response)) {
116
- $response = json_decode($response["body"], 1);
117
- if ($response["success"]) {
118
- return $input;
119
- } elseif (is_array($input)) { // Array = Comment else Object
120
- wp_die("<p><strong>".__("ERROR:", "simple-google-recaptcha")."</strong> ".__("Google reCAPTCHA verification failed.", "simple-google-recaptcha")."</p>", "reCAPTCHA", array("response" => 403, "back_link" => 1));
121
- } else {
122
- return new WP_Error("reCAPTCHA", "<strong>".__("ERROR:", "simple-google-recaptcha")."</strong> ".__("Google reCAPTCHA verification failed.", "simple-google-recaptcha"));
123
- }
124
- } else {
125
- return new WP_Error("reCAPTCHA", "<strong>".__("ERROR:", "simple-google-recaptcha")."</strong> ".__("Wrong response from Google.", "simple-google-recaptcha"));
126
- }
127
- } else {
128
- wp_die("<p><strong>".__("ERROR:", "simple-google-recaptcha")."</strong> ".__("Google reCAPTCHA verification failed.", "simple-google-recaptcha")." ".__("Do you have JavaScript enabled?", "simple-google-recaptcha")."</p>", "reCAPTCHA", array("response" => 403, "back_link" => 1));
129
- }
130
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
 
132
- function sgr_check() {
133
- if (get_option("sgr_site_key") && get_option("sgr_secret_key") && !is_user_logged_in() && !function_exists("wpcf7_contact_form_shortcode")) {
134
- add_action("login_enqueue_scripts", "frontend_sgr_script");
135
- add_action("wp_enqueue_scripts", "frontend_sgr_script");
136
-
137
- $sgr_verify_list = array("preprocess_comment", "registration_errors", "lostpassword_post", "resetpass_post", "woocommerce_register_post");
138
-
139
- if (!get_option("sgr_login_check_disable")) {
140
- array_push($sgr_verify_list, "wp_authenticate_user", "bp_signup_validate");
141
- }
142
-
143
- foreach($sgr_verify_list as $sgr_verify) {
144
- add_action($sgr_verify, "sgr_verify");
145
- }
146
- }
147
  }
148
 
149
- add_action("wp_loaded", "sgr_check");
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.1
6
  * Author: Michal Nov&aacute;k
7
  * Author URI: https://www.novami.cz
8
  * License: GPL3
10
  * Domain Path: /languages
11
  */
12
 
13
+ /**
14
+ * Class SimpleGoogleRecaptcha
15
+ */
16
+ class SimpleGoogleRecaptcha
17
+ {
18
+ const VERSION = '3.1';
19
+ const TEXT_DOMAIN = 'simple-google-recaptcha';
20
 
21
+ private $recaptcha_response;
22
 
23
+ /**
24
+ * SimpleGoogleRecaptcha constructor.
25
+ */
26
+ public function __construct()
27
+ {
28
+ if (!defined('ABSPATH')) {
29
+ die('Direct access not allowed!');
30
+ }
31
 
32
+ add_action("wp_loaded", [$this, "sgr_check"]);
33
+ add_filter(sprintf("plugin_action_links_%s", plugin_basename(__FILE__)), [$this, "sgr_add_plugin_action_links"]);
34
+ add_action("activated_plugin", [$this, "sgr_activation"]);
35
+ add_action("admin_menu", [$this, "sgr_menu"]);
36
+ add_action("admin_init", [$this, "sgr_display_options"]);
37
+ add_action("plugins_loaded", [$this, "load_language_sgr"]);
38
+ }
 
 
 
 
 
 
 
 
 
 
39
 
40
+ /**
41
+ * @param $links
42
+ * @return array
43
+ */
44
+ public function sgr_add_plugin_action_links($links)
45
+ {
46
+ return array_merge(array("settings" => sprintf("<a href=\"options-general.php?page=sgr-options\">%s</a>", __("Settings", self::TEXT_DOMAIN))), $links);
47
+ }
48
 
49
+ public function sgr_activation($plugin)
50
+ {
51
+ if ($plugin == plugin_basename(__FILE__) && (!get_option("sgr_site_key") || !get_option("sgr_secret_key"))) {
52
+ exit(wp_redirect(admin_url("options-general.php?page=sgr-options")));
53
+ }
54
+ }
55
 
56
+ public function sgr_options_page()
57
+ {
58
+ echo sprintf("<div class=\"wrap\"><h1>%s</h1><form method=\"post\" action=\"options.php\">", __("Simple Google reCAPTCHA Options", self::TEXT_DOMAIN));
 
59
 
60
+ settings_fields("sgr_header_section");
61
+ do_settings_sections("sgr-options");
 
 
62
 
63
+ $isKeysValid = $this->areKeysCorrect();
 
 
64
 
65
+ if ($isKeysValid['valid'] === false) {
66
+ echo sprintf("<div class=\"notice notice-error\"><p><strong>%s</strong> %s</p></div>", __("Warning:", self::TEXT_DOMAIN), $isKeysValid['message']);
67
+ }
68
 
69
+ submit_button();
 
 
70
 
71
+ echo sprintf("</form>%s</div>", $this->messageDisablePluginViaFtp());
72
+ }
 
 
 
73
 
74
+ public function sgr_menu()
75
+ {
76
+ add_submenu_page("options-general.php", "reCAPTCHA", "reCAPTCHA", "manage_options", "sgr-options", [$this, "sgr_options_page"]);
77
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
+ public function sgr_display_content()
80
+ {
81
+ echo sprintf("<p>%s</p>", __("You have to <a href=\"https://www.google.com/recaptcha/admin\" rel=\"external\">register your domain</a> first, get required keys (reCAPTCHA V2 Checkbox) from Google and save them bellow.", self::TEXT_DOMAIN));
82
+ }
83
 
84
+ public function sgr_display_site_key_element()
85
+ {
86
+ $sgr_site_key = filter_var(get_option("sgr_site_key"), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
87
+ echo sprintf("<input type=\"text\" name=\"sgr_site_key\" class=\"regular-text\" id=\"sgr_site_key\" value=\"%s\" />", $sgr_site_key);
88
+ }
89
+
90
+ public function sgr_display_secret_key_element()
91
+ {
92
+ $sgr_secret_key = filter_var(get_option("sgr_secret_key"), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
93
+ echo sprintf("<input type=\"text\" name=\"sgr_secret_key\" class=\"regular-text\" id=\"sgr_secret_key\" value=\"%s\" />", $sgr_secret_key);
94
+ }
95
+
96
+ public function sgr_display_login_check_disable()
97
+ {
98
+ echo sprintf("<input type=\"checkbox\" name=\"sgr_login_check_disable\" id=\"sgr_login_check_disable\" value=\"1\" %s />", checked(1, get_option("sgr_login_check_disable"), false));
99
+ }
100
+
101
+ public function sgr_display_options()
102
+ {
103
+ add_settings_section("sgr_header_section", __("What first?", self::TEXT_DOMAIN), [$this, "sgr_display_content"], "sgr-options");
104
+
105
+ add_settings_field("sgr_site_key", __("Site Key", self::TEXT_DOMAIN), [$this, "sgr_display_site_key_element"], "sgr-options", "sgr_header_section");
106
+ add_settings_field("sgr_secret_key", __("Secret Key", self::TEXT_DOMAIN), [$this, "sgr_display_secret_key_element"], "sgr-options", "sgr_header_section");
107
+ add_settings_field("sgr_login_check_disable", __("Disable reCAPTCHA for login", self::TEXT_DOMAIN), [$this, "sgr_display_login_check_disable"], "sgr-options", "sgr_header_section");
108
+
109
+ register_setting("sgr_header_section", "sgr_site_key");
110
+ register_setting("sgr_header_section", "sgr_secret_key");
111
+ register_setting("sgr_header_section", "sgr_login_check_disable");
112
+ }
113
+
114
+ public function load_language_sgr()
115
+ {
116
+ load_plugin_textdomain(self::TEXT_DOMAIN, false, sprintf("%s/languages/", dirname(plugin_basename(__FILE__))));
117
+ }
118
+
119
+ public function frontend_sgr_script()
120
+ {
121
+ $sgr_site_key = filter_var(get_option("sgr_site_key"), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
122
+ $sgr_display_list = array("comment_form_after_fields", "register_form", "lost_password", "lostpassword_form", "retrieve_password", "resetpass_form", "woocommerce_register_form", "woocommerce_lostpassword_form", "woocommerce_after_order_notes", "bp_after_signup_profile_fields");
123
+
124
+ if (!get_option("sgr_login_check_disable")) {
125
+ array_push($sgr_display_list, "login_form", "woocommerce_login_form");
126
+ }
127
+
128
+ foreach ($sgr_display_list as $sgr_display) {
129
+ add_action($sgr_display, [$this, "sgr_display"]);
130
+ }
131
+
132
+ wp_register_script("sgr_recaptcha_main", plugin_dir_url(__FILE__) . "main.js?v=" . self::VERSION);
133
+ wp_enqueue_script("sgr_recaptcha_main");
134
+ wp_localize_script("sgr_recaptcha_main", "sgr_recaptcha", array("site_key" => $sgr_site_key));
135
+
136
+ wp_register_script("sgr_recaptcha", sprintf("https://www.google.com/recaptcha/api.js?hl=%s&onload=sgr&render=explicit", get_locale()));
137
+ wp_enqueue_script("sgr_recaptcha");
138
+
139
+ wp_enqueue_style("style", plugin_dir_url(__FILE__) . "style.css?v=" . self::VERSION);
140
+ }
141
+
142
+ public function sgr_display()
143
+ {
144
+ echo "<div class=\"sgr-recaptcha\"></div>";
145
+ }
146
+
147
+ public function errorMessage($error_code)
148
+ {
149
+ $error_message = null;
150
+
151
+ switch ($error_code) {
152
+ case 'missing-input-secret':
153
+ $error_message = __("The secret parameter is missing.", self::TEXT_DOMAIN);
154
+ break;
155
+ case 'missing-input-response':
156
+ $error_message = __("The response parameter is missing.", self::TEXT_DOMAIN);
157
+ break;
158
+ case 'invalid-input-secret':
159
+ $error_message = __("The secret parameter is invalid or malformed.", self::TEXT_DOMAIN);
160
+ break;
161
+ case 'invalid-input-response':
162
+ $error_message = __("The response parameter is invalid or malformed.", self::TEXT_DOMAIN);
163
+ break;
164
+ case 'bad-request':
165
+ $error_message = __("The request is invalid or malformed.", self::TEXT_DOMAIN);
166
+ break;
167
+ case 'timeout-or-duplicate':
168
+ $error_message = __("The response is no longer valid: either is too old or has been used previously.", self::TEXT_DOMAIN);
169
+ break;
170
+ }
171
+
172
+ return $error_message;
173
+ }
174
+
175
+ /**
176
+ * @return array|mixed
177
+ */
178
+ private function recaptchaResponse()
179
+ {
180
+ $sgr_secret_key = filter_var(get_option("sgr_secret_key"), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
181
+ $recaptcha_response = filter_input(INPUT_POST, "g-recaptcha-response", FILTER_SANITIZE_FULL_SPECIAL_CHARS);
182
+ $response = (array)wp_remote_get("https://www.google.com/recaptcha/api/siteverify?secret={$sgr_secret_key}&response={$recaptcha_response}");
183
+
184
+ return isset($response["body"]) ? json_decode($response["body"], 1) : ['success' => false, 'error-codes' => ['general-fail']];
185
+ }
186
+
187
+ /**
188
+ * @param $input
189
+ * @return WP_Error
190
+ */
191
+ public function sgr_verify($input)
192
+ {
193
+ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["g-recaptcha-response"])) {
194
+ $recaptcha_error_code = isset($this->recaptcha_response['error-codes'][0]) ? $this->recaptcha_response['error-codes'][0] : null;
195
+ $error_message = $this->errorMessage($recaptcha_error_code);
196
+
197
+ if ($this->recaptcha_response["success"]) {
198
+ return $input;
199
+ } elseif (is_array($input)) { // Array = Comment else Object
200
+ wp_die(sprintf("<p><strong>%s</strong> %s %s</p>", __("ERROR:", self::TEXT_DOMAIN), __("Google reCAPTCHA verification failed.", self::TEXT_DOMAIN), $error_message), "reCAPTCHA", array("response" => 403, "back_link" => 1));
201
+ } else {
202
+ return new WP_Error("reCAPTCHA", sprintf("<strong>%s</strong> %s %s", __("ERROR:", self::TEXT_DOMAIN), __("Google reCAPTCHA verification failed.", self::TEXT_DOMAIN), $error_message));
203
+ }
204
+ } else {
205
+ wp_die(sprintf("<p><strong>%s</strong> %s %s</p>", __("ERROR:", self::TEXT_DOMAIN), __("Google reCAPTCHA verification failed.", self::TEXT_DOMAIN), __("Do you have JavaScript enabled?", self::TEXT_DOMAIN)), "reCAPTCHA", array("response" => 403, "back_link" => 1));
206
+ }
207
+ }
208
+
209
+ /**
210
+ * @return array
211
+ */
212
+ private function areKeysCorrect()
213
+ {
214
+ $this->recaptcha_response = $this->recaptchaResponse();
215
+
216
+ if (!get_option("sgr_site_key") || !get_option("sgr_secret_key")) {
217
+ $status = [
218
+ 'valid' => false,
219
+ 'message' => __('You have to save reCAPTCHA keys v2 "I\'m not a robot" Checkbox first!', self::TEXT_DOMAIN)
220
+ ];
221
+ } elseif (isset($this->recaptcha_response['error-codes']) && in_array('invalid-input-secret', $this->recaptcha_response['error-codes'])) {
222
+ $status = [
223
+ 'valid' => false,
224
+ 'message' => __('Saved keys are not valid! Did you really insert keys for reCAPTCHA v2 "I\'m not a robot" Checkbox?', self::TEXT_DOMAIN)
225
+ ];
226
+ } else {
227
+ $status = [
228
+ 'valid' => true,
229
+ 'message' => __('Saved keys are correct, thank you!', self::TEXT_DOMAIN)
230
+ ];
231
+ }
232
+
233
+ return $status;
234
+ }
235
+
236
+ public function messageDisablePluginViaFtp()
237
+ {
238
+ return sprintf("<div class=\"notice notice-info\"><p><strong>%s</strong> %s</p></div>", __("Notice:", 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));
239
+ }
240
+
241
+ public function sgr_check()
242
+ {
243
+ if ($this->areKeysCorrect()['valid'] && !is_user_logged_in() && !function_exists("wpcf7_contact_form_shortcode")) {
244
+ add_action("login_enqueue_scripts", [$this, "frontend_sgr_script"]);
245
+ add_action("wp_enqueue_scripts", [$this, "frontend_sgr_script"]);
246
+
247
+ $sgr_verify_list = array(
248
+ "preprocess_comment",
249
+ "registration_errors",
250
+ "lostpassword_post",
251
+ "resetpass_post",
252
+ "woocommerce_register_post"
253
+ );
254
+
255
+ if (!get_option("sgr_login_check_disable")) {
256
+ array_push($sgr_verify_list, "wp_authenticate_user", "bp_signup_validate");
257
+ }
258
 
259
+ foreach ($sgr_verify_list as $sgr_verify) {
260
+ add_action($sgr_verify, [$this, "sgr_verify"]);
261
+ }
262
+ }
263
+ }
 
 
 
 
 
 
 
 
 
 
264
  }
265
 
266
+ new SimpleGoogleRecaptcha();
uninstall.php CHANGED
@@ -1,12 +1,28 @@
1
  <?php
2
- if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) {
3
- die( 'Direct access not allowed!' );
4
- }
5
 
6
- function sgr_delete($array) {
7
- foreach ($array as $one) {
8
- delete_option("sgr_{$one}");
9
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  }
11
 
12
- sgr_delete(array("site_key", "secret_key", "login_check_disable"));
1
  <?php
 
 
 
2
 
3
+ /**
4
+ * Class SimpleGoogleRecaptchaUninstall
5
+ */
6
+ class SimpleGoogleRecaptchaUninstall
7
+ {
8
+ /**
9
+ * SimpleGoogleRecaptchaUninstall constructor.
10
+ */
11
+ public function __construct()
12
+ {
13
+ if (!defined('WP_UNINSTALL_PLUGIN')) {
14
+ die('Direct access not allowed');
15
+ }
16
+
17
+ $this->sgr_delete(array("site_key", "secret_key", "login_check_disable"));
18
+ }
19
+
20
+ private function sgr_delete($array)
21
+ {
22
+ foreach ($array as $item) {
23
+ delete_option(sprintf("sgr_%s", $item));
24
+ }
25
+ }
26
  }
27
 
28
+ new SimpleGoogleRecaptchaUninstall();