Simple Google reCAPTCHA - Version 1.7

Version Description

  • Bugfix: reCAPCTHA will be required only If the form has been submitted
  • You can choose where reCAPTCHA will be required
Download this release

Release Info

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

Code changes from version 1.6 to 1.7

Files changed (2) hide show
  1. readme.txt +12 -3
  2. simple-google-recaptcha.php +57 -21
readme.txt CHANGED
@@ -1,16 +1,16 @@
1
  === Simple Google reCAPTCHA ===
2
  Contributors: Minor
3
- Tags: recaptcha, spam, block, captcha, bots, brute-force, protect, comments, secure, admin
4
  Requires at least: 4.2.0
5
  Tested up to: 4.7
6
- Stable tag: 1.6
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
10
  Simply protect your WordPress against spam comments and brute-force attacks, thanks to Google reCAPTCHA!
11
 
12
  == Description ==
13
- Simple Google reCAPTCHA will protect your WordPress! No more spam comments and brute-force attacks against user accounts. Really lightweight plugin - just around 7 KB to download!
14
 
15
  = What is protected with Google reCAPTCHA? =
16
  * Comment form
@@ -18,9 +18,14 @@ Simple Google reCAPTCHA will protect your WordPress! No more spam comments and b
18
  * Registration form
19
  * Login form
20
 
 
 
 
21
  == Installation ==
22
  1. Upload the plugin files to the "/wp-content/plugins/simple-google-recaptcha" directory, or install the plugin through the WordPress plugins screen directly.
 
23
  2. Activate the plugin through the "Plugins" screen in WordPress.
 
24
  3. Use the Settings => reCAPTCHA screen to configure the plugin.
25
 
26
  == Frequently Asked Questions ==
@@ -35,6 +40,10 @@ Just pure protection - no ads and any other unnecessary changes in the WordPress
35
  5. Simple Google reCAPTCHA - Settings
36
 
37
  == Changelog ==
 
 
 
 
38
  = 1.6 =
39
  * Changed name of settings to avoid unwanted cancellation of settings (wasn't unique name of settings for this plugin in database)
40
 
1
  === Simple Google reCAPTCHA ===
2
  Contributors: Minor
3
+ Tags: recaptcha, spam, block, captcha, bots, brute-force, protect, comments, secure, admin, attack
4
  Requires at least: 4.2.0
5
  Tested up to: 4.7
6
+ Stable tag: 1.7
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
10
  Simply protect your WordPress against spam comments and brute-force attacks, thanks to Google reCAPTCHA!
11
 
12
  == Description ==
13
+ Simple Google reCAPTCHA will protect your WordPress! No more spam comments and brute-force attacks against user accounts. Really lightweight plugin - just around 10 kB to download!
14
 
15
  = What is protected with Google reCAPTCHA? =
16
  * Comment form
18
  * Registration form
19
  * Login form
20
 
21
+ You can choose where reCAPTCHA will be required.
22
+
23
+
24
  == Installation ==
25
  1. Upload the plugin files to the "/wp-content/plugins/simple-google-recaptcha" directory, or install the plugin through the WordPress plugins screen directly.
26
+
27
  2. Activate the plugin through the "Plugins" screen in WordPress.
28
+
29
  3. Use the Settings => reCAPTCHA screen to configure the plugin.
30
 
31
  == Frequently Asked Questions ==
40
  5. Simple Google reCAPTCHA - Settings
41
 
42
  == Changelog ==
43
+ = 1.7 =
44
+ * Bugfix: reCAPCTHA will be required only If the form has been submitted
45
+ * You can choose where reCAPTCHA will be required
46
+
47
  = 1.6 =
48
  * Changed name of settings to avoid unwanted cancellation of settings (wasn't unique name of settings for this plugin in database)
49
 
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: 1.6
6
  * Author: Michal Novák
7
  * Author URI: https://www.novami.cz
8
  * License: GPL3
@@ -35,10 +35,18 @@ function sgr_display_options() {
35
  add_settings_field("sgr_site_key", __("Site Key", "sgr"), "sgr_display_site_key_element", "sgr-options", "sgr_header_section");
36
  add_settings_field("sgr_secret_key", __("Secret Key", "sgr"), "sgr_display_secret_key_element", "sgr-options", "sgr_header_section");
37
  add_settings_field("sgr_logged_users_comments_disable", __("Disable reCAPTCHA in comment form for logged in users", "sgr"), "sgr_display_logged_users_comments_disable", "sgr-options", "sgr_header_section");
38
-
 
 
 
 
39
  register_setting("sgr_header_section", "sgr_site_key");
40
  register_setting("sgr_header_section", "sgr_secret_key");
41
  register_setting("sgr_header_section", "sgr_logged_users_comments_disable");
 
 
 
 
42
  }
43
 
44
  function sgr_display_content() {
@@ -57,6 +65,22 @@ function sgr_display_logged_users_comments_disable() {
57
  echo "<input type=\"checkbox\" name=\"sgr_logged_users_comments_disable\" id=\"sgr_logged_users_comments_disable\" value=\"1\" ".checked(1, get_option("sgr_logged_users_comments_disable"), false)." />";
58
  }
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  add_action("admin_init", "sgr_display_options");
61
 
62
  function frontend_sgr_script() {
@@ -83,7 +107,7 @@ function sgr_verify($input) {
83
  $recaptcha_secret = get_option("sgr_secret_key");
84
  $response = wp_remote_get("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$recaptcha_response);
85
  $response = json_decode($response["body"], true);
86
- if (true == $response["success"]) {
87
  return $input;
88
  } else {
89
  wp_die(__("<p><strong>ERROR</strong>: Google reCAPTCHA verification failed.</p>", "sgr")."</p>\n\n<p><a href=".wp_get_referer().">&laquo; Zpět</a>");
@@ -97,28 +121,40 @@ function sgr_verify($input) {
97
 
98
  function sgr_check() {
99
  if (get_option("sgr_site_key") != "" && get_option("sgr_secret_key") != "") {
100
- if (get_option("sgr_logged_users_comments_disable") != "1") {
101
- add_action("comment_form_logged_in_after", "sgr_display");
 
 
 
 
 
 
102
  }
103
 
104
- add_action("comment_form_after_fields", "sgr_display");
105
- add_action("login_form", "sgr_display" );
106
- add_action("register_form", "sgr_display");
107
- add_action("lostpassword_form", "sgr_display");
108
-
109
- if ((is_user_logged_in() && get_option("sgr_logged_users_comments_disable") != "1") || !is_user_logged_in()) {
110
- do_action("preprocess_comment", $commentdata);
111
- add_action("preprocess_comment", "sgr_verify");
112
  }
113
 
114
- do_action("wp_authenticate_user", $user);
115
- add_action("wp_authenticate_user", "sgr_verify");
116
-
117
- do_action("registration_errors", $errors);
118
- add_action("registration_errors", "sgr_verify");
119
-
120
- do_action("lostpassword_post", $errors);
121
- add_action("lostpassword_post", "sgr_verify");
 
 
 
 
 
 
 
122
  }
123
  }
124
  add_action("init", "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: 1.7
6
  * Author: Michal Nov&aacute;k
7
  * Author URI: https://www.novami.cz
8
  * License: GPL3
35
  add_settings_field("sgr_site_key", __("Site Key", "sgr"), "sgr_display_site_key_element", "sgr-options", "sgr_header_section");
36
  add_settings_field("sgr_secret_key", __("Secret Key", "sgr"), "sgr_display_secret_key_element", "sgr-options", "sgr_header_section");
37
  add_settings_field("sgr_logged_users_comments_disable", __("Disable reCAPTCHA in comment form for logged in users", "sgr"), "sgr_display_logged_users_comments_disable", "sgr-options", "sgr_header_section");
38
+ add_settings_field("sgr_comment_form_disable", __("Disable reCAPTCHA for comments", "sgr"), "sgr_display_comment_form_disable", "sgr-options", "sgr_header_section");
39
+ add_settings_field("sgr_login_form_disable", __("Disable reCAPTCHA for login page", "sgr"), "sgr_display_login_form_disable", "sgr-options", "sgr_header_section");
40
+ add_settings_field("sgr_register_form_disable", __("Disable reCAPTCHA for register page", "sgr"), "sgr_display_register_form_disable", "sgr-options", "sgr_header_section");
41
+ add_settings_field("sgr_forgot_form_disable", __("Disable reCAPTCHA for forgot password page", "sgr"), "sgr_display_forgot_form_disable", "sgr-options", "sgr_header_section");
42
+
43
  register_setting("sgr_header_section", "sgr_site_key");
44
  register_setting("sgr_header_section", "sgr_secret_key");
45
  register_setting("sgr_header_section", "sgr_logged_users_comments_disable");
46
+ register_setting("sgr_header_section", "sgr_comment_form_disable");
47
+ register_setting("sgr_header_section", "sgr_login_form_disable");
48
+ register_setting("sgr_header_section", "sgr_register_form_disable");
49
+ register_setting("sgr_header_section", "sgr_forgot_form_disable");
50
  }
51
 
52
  function sgr_display_content() {
65
  echo "<input type=\"checkbox\" name=\"sgr_logged_users_comments_disable\" id=\"sgr_logged_users_comments_disable\" value=\"1\" ".checked(1, get_option("sgr_logged_users_comments_disable"), false)." />";
66
  }
67
 
68
+ function sgr_display_comment_form_disable() {
69
+ echo "<input type=\"checkbox\" name=\"sgr_comment_form_disable\" id=\"sgr_comment_form_disable\" value=\"1\" ".checked(1, get_option("sgr_comment_form_disable"), false)." />";
70
+ }
71
+
72
+ function sgr_display_login_form_disable() {
73
+ echo "<input type=\"checkbox\" name=\"sgr_login_form_disable\" id=\"sgr_login_form_disable\" value=\"1\" ".checked(1, get_option("sgr_login_form_disable"), false)." />";
74
+ }
75
+
76
+ function sgr_display_register_form_disable() {
77
+ echo "<input type=\"checkbox\" name=\"sgr_register_form_disable\" id=\"sgr_register_form_disable\" value=\"1\" ".checked(1, get_option("sgr_register_form_disable"), false)." />";
78
+ }
79
+
80
+ function sgr_display_forgot_form_disable() {
81
+ echo "<input type=\"checkbox\" name=\"sgr_forgot_form_disable\" id=\"sgr_forgot_form_disable\" value=\"1\" ".checked(1, get_option("sgr_forgot_form_disable"), false)." />";
82
+ }
83
+
84
  add_action("admin_init", "sgr_display_options");
85
 
86
  function frontend_sgr_script() {
107
  $recaptcha_secret = get_option("sgr_secret_key");
108
  $response = wp_remote_get("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$recaptcha_response);
109
  $response = json_decode($response["body"], true);
110
+ if ($response["success"] == true) {
111
  return $input;
112
  } else {
113
  wp_die(__("<p><strong>ERROR</strong>: Google reCAPTCHA verification failed.</p>", "sgr")."</p>\n\n<p><a href=".wp_get_referer().">&laquo; Zpět</a>");
121
 
122
  function sgr_check() {
123
  if (get_option("sgr_site_key") != "" && get_option("sgr_secret_key") != "") {
124
+
125
+ if (get_option("sgr_comment_form_disable") != "1" && ((is_user_logged_in() && get_option("sgr_logged_users_comments_disable") != "1") || !is_user_logged_in())) {
126
+ add_action("comment_form_after_fields", "sgr_display");
127
+ add_action("comment_form_logged_in_after", "sgr_display");
128
+ if ($_SERVER["REQUEST_METHOD"] == "POST") {
129
+ do_action("preprocess_comment", $commentdata);
130
+ add_action("preprocess_comment", "sgr_verify");
131
+ }
132
  }
133
 
134
+ if (get_option("sgr_login_form_disable") != "1") {
135
+ add_action("login_form", "sgr_display" );
136
+ if ($_SERVER["REQUEST_METHOD"] == "POST") {
137
+ do_action("wp_authenticate_user", $user);
138
+ add_action("wp_authenticate_user", "sgr_verify");
139
+ }
140
+
 
141
  }
142
 
143
+ if (get_option("sgr_register_form_disable") != "1") {
144
+ add_action("register_form", "sgr_display");
145
+ if ($_SERVER["REQUEST_METHOD"] == "POST") {
146
+ do_action("registration_errors", $errors);
147
+ add_action("registration_errors", "sgr_verify");
148
+ }
149
+ }
150
+
151
+ if (get_option("sgr_forgot_form_disable") != "1") {
152
+ add_action("lostpassword_form", "sgr_display");
153
+ if ($_SERVER["REQUEST_METHOD"] == "POST") {
154
+ do_action("lostpassword_post", $errors);
155
+ add_action("lostpassword_post", "sgr_verify");
156
+ }
157
+ }
158
  }
159
  }
160
  add_action("init", "sgr_check");