Simple Google reCAPTCHA - Version 2.9

Version Description

  • New: Option for disable reCAPTCHA on login page
  • New: Error message instead of redirecting to the error page, besides the case of posting comments
  • Bugfix: Loading Js file on unique HTML element to avoid collision
Download this release

Release Info

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

Code changes from version 2.8 to 2.9

Files changed (5) hide show
  1. main.js +1 -1
  2. readme.txt +7 -2
  3. simple-google-recaptcha.php +35 -15
  4. style.css +2 -6
  5. uninstall.php +7 -8
main.js CHANGED
@@ -1,5 +1,5 @@
1
  function sgr() {
2
- var recaptcha = document.getElementsByClassName("g-recaptcha");
3
  for (var i = 0; i < recaptcha.length; i++) {
4
  grecaptcha.render(recaptcha.item(i), {"sitekey" : sgr_recaptcha.site_key});
5
  }
1
  function sgr() {
2
+ var recaptcha = document.getElementsByClassName("sgr-recaptcha");
3
  for (var i = 0; i < recaptcha.length; i++) {
4
  grecaptcha.render(recaptcha.item(i), {"sitekey" : sgr_recaptcha.site_key});
5
  }
readme.txt CHANGED
@@ -2,8 +2,8 @@
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: 4.9.4
6
- Stable tag: 2.8
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
  Donate link: https://www.paypal.me/NovaMi
@@ -47,6 +47,11 @@ Just use standard Plugin overview page in WordPress admin section and deactivate
47
  5. Simple Google reCAPTCHA - Settings
48
 
49
  == Changelog ==
 
 
 
 
 
50
  = 2.8 =
51
  * Warning: New logic - Google reCAPTCHA js file will be loaded in the background on every page for non logged in users
52
  * Warning: If Google reCAPTCHA verification fail, response code is 403 instead of 500 now. Thank you for contribution, Sara Kozińska!
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
6
+ Stable tag: 2.9
7
  License: GPLv3
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
  Donate link: https://www.paypal.me/NovaMi
47
  5. Simple Google reCAPTCHA - Settings
48
 
49
  == Changelog ==
50
+ = 2.9 =
51
+ * New: Option for disable reCAPTCHA on login page
52
+ * New: Error message instead of redirecting to the error page, besides the case of posting comments
53
+ * Bugfix: Loading Js file on unique HTML element to avoid collision
54
+
55
  = 2.8 =
56
  * Warning: New logic - Google reCAPTCHA js file will be loaded in the background on every page for non logged in users
57
  * Warning: If Google reCAPTCHA verification fail, response code is 403 instead of 500 now. Thank you for contribution, Sara Kozińska!
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: 2.8
6
  * Author: Michal Nov&aacute;k
7
  * Author URI: https://www.novami.cz
8
  * License: GPL3
@@ -10,6 +10,10 @@
10
  * Domain Path: /languages
11
  */
12
 
 
 
 
 
13
  function sgr_add_plugin_action_links($links) {
14
  return array_merge(array("settings" => "<a href=\"options-general.php?page=sgr-options\">".__("Settings", "simple-google-recaptcha")."</a>"), $links);
15
  }
@@ -52,14 +56,20 @@ function sgr_display_secret_key_element() {
52
  echo "<input type=\"text\" name=\"sgr_secret_key\" class=\"regular-text\" id=\"sgr_secret_key\" value=\"{$sgr_secret_key}\" />";
53
  }
54
 
 
 
 
 
55
  function sgr_display_options() {
56
  add_settings_section("sgr_header_section", __("What first?", "simple-google-recaptcha"), "sgr_display_content", "sgr-options");
57
 
58
  add_settings_field("sgr_site_key", __("Site Key", "simple-google-recaptcha"), "sgr_display_site_key_element", "sgr-options", "sgr_header_section");
59
  add_settings_field("sgr_secret_key", __("Secret Key", "simple-google-recaptcha"), "sgr_display_secret_key_element", "sgr-options", "sgr_header_section");
 
60
 
61
  register_setting("sgr_header_section", "sgr_site_key");
62
  register_setting("sgr_header_section", "sgr_secret_key");
 
63
  }
64
  add_action("admin_init", "sgr_display_options");
65
 
@@ -70,22 +80,28 @@ add_action("plugins_loaded", "load_language_sgr");
70
 
71
  function frontend_sgr_script() {
72
  $sgr_site_key = filter_var(get_option("sgr_site_key"), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
73
- $sgr_display_list = array("comment_form_after_fields", "login_form", "register_form", "lost_password", "lostpassword_form", "retrieve_password", "resetpass_form", "woocommerce_login_form", "woocommerce_register_form", "woocommerce_lostpassword_form", "woocommerce_after_order_notes", "bp_after_signup_profile_fields");
74
 
75
- wp_register_script("sgr_recaptcha_main", plugin_dir_url(__FILE__)."main.js");
76
- wp_enqueue_script("sgr_recaptcha_main");
77
- wp_localize_script("sgr_recaptcha_main", "sgr_recaptcha", array("site_key" => $sgr_site_key));
78
- wp_register_script("sgr_recaptcha", "https://www.google.com/recaptcha/api.js?hl=".get_locale()."&onload=sgr&render=explicit");
79
- wp_enqueue_script("sgr_recaptcha");
80
- wp_enqueue_style("style", plugin_dir_url(__FILE__)."style.css");
81
 
82
  foreach($sgr_display_list as $sgr_display) {
83
  add_action($sgr_display, "sgr_display");
84
  }
 
 
 
 
 
 
 
 
 
85
  }
86
 
87
  function sgr_display() {
88
- echo "<div class=\"g-recaptcha\"></div>";
89
  }
90
 
91
  function sgr_verify($input) {
@@ -97,22 +113,26 @@ function sgr_verify($input) {
97
 
98
  if ($response["success"]) {
99
  return $input;
 
 
100
  } else {
101
- wp_die("<p><strong>".__("ERROR:", "simple-google-recaptcha")."</strong> ".__("Google reCAPTCHA verification failed.", "simple-google-recaptcha")."</p>\n\n<p><a href=".wp_get_referer().">&laquo; ".__("Back", "simple-google-recaptcha")."</a>", "", 403);
102
- return null;
103
  }
104
  } else {
105
- 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>\n\n<p><a href=".wp_get_referer().">&laquo; ".__("Back", "simple-google-recaptcha")."</a>", "", 403);
106
- return null;
107
  }
108
  }
109
 
110
  function sgr_check() {
111
- if (get_option("sgr_site_key") && get_option("sgr_secret_key") && !is_user_logged_in()) {
112
  add_action("login_enqueue_scripts", "frontend_sgr_script");
113
  add_action("wp_enqueue_scripts", "frontend_sgr_script");
114
 
115
- $sgr_verify_list = array("preprocess_comment", "wp_authenticate_user", "registration_errors", "lostpassword_post", "resetpass_post", "bp_signup_validate", "woocommerce_register_post");
 
 
 
 
116
 
117
  foreach($sgr_verify_list as $sgr_verify) {
118
  add_action($sgr_verify, "sgr_verify");
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: 2.9
6
  * Author: Michal Nov&aacute;k
7
  * Author URI: https://www.novami.cz
8
  * License: GPL3
10
  * Domain Path: /languages
11
  */
12
 
13
+ if (!defined('ABSPATH')) {
14
+ die( 'Direct access not allowed!' );
15
+ }
16
+
17
  function sgr_add_plugin_action_links($links) {
18
  return array_merge(array("settings" => "<a href=\"options-general.php?page=sgr-options\">".__("Settings", "simple-google-recaptcha")."</a>"), $links);
19
  }
56
  echo "<input type=\"text\" name=\"sgr_secret_key\" class=\"regular-text\" id=\"sgr_secret_key\" value=\"{$sgr_secret_key}\" />";
57
  }
58
 
59
+ function sgr_display_login_check_disable() {
60
+ 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)." />";
61
+ }
62
+
63
  function sgr_display_options() {
64
  add_settings_section("sgr_header_section", __("What first?", "simple-google-recaptcha"), "sgr_display_content", "sgr-options");
65
 
66
  add_settings_field("sgr_site_key", __("Site Key", "simple-google-recaptcha"), "sgr_display_site_key_element", "sgr-options", "sgr_header_section");
67
  add_settings_field("sgr_secret_key", __("Secret Key", "simple-google-recaptcha"), "sgr_display_secret_key_element", "sgr-options", "sgr_header_section");
68
+ add_settings_field("sgr_login_check_disable", __("Disable reCAPTCHA for login", "simple-google-recaptcha"), "sgr_display_login_check_disable", "sgr-options", "sgr_header_section");
69
 
70
  register_setting("sgr_header_section", "sgr_site_key");
71
  register_setting("sgr_header_section", "sgr_secret_key");
72
+ register_setting("sgr_header_section", "sgr_login_check_disable");
73
  }
74
  add_action("admin_init", "sgr_display_options");
75
 
80
 
81
  function frontend_sgr_script() {
82
  $sgr_site_key = filter_var(get_option("sgr_site_key"), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
83
+ $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");
84
 
85
+ if (!get_option("sgr_login_check_disable")) {
86
+ array_push($sgr_display_list, "login_form", "woocommerce_login_form");
87
+ }
 
 
 
88
 
89
  foreach($sgr_display_list as $sgr_display) {
90
  add_action($sgr_display, "sgr_display");
91
  }
92
+
93
+ wp_register_script("sgr_recaptcha_main", plugin_dir_url(__FILE__)."main.js?v=2.9");
94
+ wp_enqueue_script("sgr_recaptcha_main");
95
+ wp_localize_script("sgr_recaptcha_main", "sgr_recaptcha", array("site_key" => $sgr_site_key));
96
+
97
+ wp_register_script("sgr_recaptcha", "https://www.google.com/recaptcha/api.js?hl=".get_locale()."&onload=sgr&render=explicit");
98
+ wp_enqueue_script("sgr_recaptcha");
99
+
100
+ wp_enqueue_style("style", plugin_dir_url(__FILE__)."style.css?v=2.9");
101
  }
102
 
103
  function sgr_display() {
104
+ echo "<div class=\"sgr-recaptcha\"></div>";
105
  }
106
 
107
  function sgr_verify($input) {
113
 
114
  if ($response["success"]) {
115
  return $input;
116
+ } elseif (is_array($input)) { // Array = Comment else Object
117
+ wp_die("<p><strong>".__("ERROR:", "simple-google-recaptcha")."</strong> ".__("Google reCAPTCHA verification failed.", "simple-google-recaptcha")."</p>", "reCAPTCHA", array("response" => 403, "back_link" => 1));
118
  } else {
119
+ return new WP_Error("reCAPTCHA", "<strong>".__("ERROR:", "simple-google-recaptcha")."</strong> ".__("Google reCAPTCHA verification failed.", "simple-google-recaptcha"));
 
120
  }
121
  } else {
122
+ 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));
 
123
  }
124
  }
125
 
126
  function sgr_check() {
127
+ if (get_option("sgr_site_key") && get_option("sgr_secret_key") && !is_user_logged_in() && !function_exists("wpcf7_contact_form_shortcode")) {
128
  add_action("login_enqueue_scripts", "frontend_sgr_script");
129
  add_action("wp_enqueue_scripts", "frontend_sgr_script");
130
 
131
+ $sgr_verify_list = array("preprocess_comment", "registration_errors", "lostpassword_post", "resetpass_post", "woocommerce_register_post");
132
+
133
+ if (!get_option("sgr_login_check_disable")) {
134
+ array_push($sgr_verify_list, "wp_authenticate_user", "bp_signup_validate");
135
+ }
136
 
137
  foreach($sgr_verify_list as $sgr_verify) {
138
  add_action($sgr_verify, "sgr_verify");
style.css CHANGED
@@ -1,14 +1,10 @@
1
- .g-recaptcha {
2
  transform: scale(0.90);
3
  transform-origin: 0 0;
4
  clear: both;
5
- padding: 10px 0;
6
  }
7
 
8
  .login form {
9
  padding-bottom: 26px;
10
- }
11
-
12
- .clef-login-container {
13
- z-index: 1;
14
  }
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
@@ -1,13 +1,12 @@
1
  <?php
2
- if (!defined("WP_UNINSTALL_PLUGIN")) {
3
- exit();
4
  }
5
 
6
- function sgr_delete() {
7
- global $wpdb;
8
- delete_option("sgr_site_key");
9
- delete_option("sgr_secret_key");
10
  }
11
 
12
- sgr_delete();
13
- ?>
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"));