WordPress ReCaptcha Integration - Version 1.1.1

Version Description

  • Filter: wp_recaptcha_do_scripts allow disabling recaptcha scripts on certain pages.
  • Filter: wp_recaptcha_print_login_css, allow disabling login CSS.
  • Fix: Didn't render with Submit Button Disabling checked
  • Fix: Use add_query_arg() to generate recaptcha API URL
Download this release

Release Info

Developer podpirate
Plugin Icon 128x128 WordPress ReCaptcha Integration
Version 1.1.1
Comparing to
See all releases

Code changes from version 1.1.0 to 1.1.1

inc/class-wp_recaptcha_captcha.php CHANGED
@@ -10,6 +10,7 @@ abstract class WP_reCaptcha_Captcha {
10
  protected $_last_result = false;
11
 
12
  abstract function print_head();
 
13
  abstract function print_foot();
14
  abstract function get_html( $attr = array() );
15
  abstract function check();
10
  protected $_last_result = false;
11
 
12
  abstract function print_head();
13
+ abstract function print_login_head();
14
  abstract function print_foot();
15
  abstract function get_html( $attr = array() );
16
  abstract function check();
inc/class-wp_recaptcha_contactform7.php CHANGED
@@ -76,7 +76,9 @@ class WP_reCaptcha_ContactForm7 {
76
  }
77
 
78
  function recaptcha_enqueue_script() {
79
- wp_enqueue_script('wpcf7-recaptcha-integration',plugins_url('/js/wpcf7.js',dirname(__FILE__)),array('contact-form-7'));
 
 
80
  }
81
 
82
 
76
  }
77
 
78
  function recaptcha_enqueue_script() {
79
+ if ( apply_filters( 'wp_recaptcha_do_scripts' , true ) ) {
80
+ wp_enqueue_script('wpcf7-recaptcha-integration',plugins_url('/js/wpcf7.js',dirname(__FILE__)),array('contact-form-7'));
81
+ }
82
  }
83
 
84
 
inc/class-wp_recaptcha_ninjaforms.php CHANGED
@@ -105,36 +105,38 @@ class WP_reCaptcha_NinjaForms {
105
  }
106
 
107
  function recaptcha_script($id) {
108
- /*
109
- refresh captcha after form submission.
110
- */
111
- $flavor = WP_reCaptcha::instance()->get_option( 'recaptcha_flavor' );
112
- switch ( $flavor ) {
113
- case 'recaptcha':
114
- $html = '<script type="text/javascript">
115
- // reload recaptcha after failed ajax form submit
116
- jQuery(document).on("submitResponse.default", function(e, response){
117
- Recaptcha.reload();
118
- });
119
- </script>';
120
- break;
121
- case 'grecaptcha':
122
- $html = '<script type="text/javascript">
123
- // reload recaptcha after failed ajax form submit
124
- (function($){
125
- $(document).on("submitResponse.default", function(e, response){
126
- if ( grecaptcha ) {
127
- var wid = $(\'#ninja_forms_form_\'+response.form_id).find(\'.g-recaptcha\').data(\'widget-id\');
128
- grecaptcha.reset(wid);
 
 
 
 
 
 
129
  }
130
- });
131
- })(jQuery);
132
- </script>';
133
- break;
134
  }
135
- WP_reCaptcha::instance()->begin_inject(false,', Ninja form integration');
136
- echo $html;
137
- WP_reCaptcha::instance()->end_inject();
138
  }
139
 
140
  function field_recaptcha_display($field_id, $data){
105
  }
106
 
107
  function recaptcha_script($id) {
108
+ if ( apply_filters( 'wp_recaptcha_do_scripts' , true ) ) {
109
+ /*
110
+ refresh captcha after form submission.
111
+ */
112
+ $flavor = WP_reCaptcha::instance()->get_option( 'recaptcha_flavor' );
113
+ switch ( $flavor ) {
114
+ case 'recaptcha':
115
+ $html = '<script type="text/javascript">
116
+ // reload recaptcha after failed ajax form submit
117
+ jQuery(document).on("submitResponse.default", function(e, response){
118
+ Recaptcha.reload();
119
+ });
120
+ </script>';
121
+ break;
122
+ case 'grecaptcha':
123
+ $html = '<script type="text/javascript">
124
+ // reload recaptcha after failed ajax form submit
125
+ (function($){
126
+ $(document).on("submitResponse.default", function(e, response){
127
+ if ( grecaptcha ) {
128
+ var wid = $(\'#ninja_forms_form_\'+response.form_id).find(\'.g-recaptcha\').data(\'widget-id\');
129
+ grecaptcha.reset(wid);
130
+ }
131
+ });
132
+ })(jQuery);
133
+ </script>';
134
+ break;
135
  }
136
+ WP_reCaptcha::instance()->begin_inject(false,', Ninja form integration');
137
+ echo $html;
138
+ WP_reCaptcha::instance()->end_inject();
 
139
  }
 
 
 
140
  }
141
 
142
  function field_recaptcha_display($field_id, $data){
inc/class-wp_recaptcha_nocaptcha.php CHANGED
@@ -79,7 +79,6 @@ class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
79
  * Prevent from creating more than one instance
80
  */
81
  private function __construct() {
82
-
83
  }
84
 
85
  public function get_supported_themes() {
@@ -114,8 +113,9 @@ class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
114
  $lang = $mapping[$lang];
115
  return parent::get_language( $lang );
116
  }
 
117
 
118
- public function print_head() {
119
  ?><style type="text/css">
120
  #login {
121
  width:350px !important;
@@ -127,8 +127,7 @@ class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
127
  public function print_foot() {
128
  $sitekey = WP_reCaptcha::instance()->get_option('recaptcha_publickey');
129
  $language_param = '';
130
- if ( $language_code = apply_filters( 'wp_recaptcha_language' , WP_reCaptcha::instance()->get_option( 'recaptcha_language' ) ) )
131
- $language_param = "&hl=$language_code";
132
 
133
  ?><script type="text/javascript">
134
  var recaptcha_widgets={};
@@ -148,13 +147,12 @@ class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
148
  var wid;
149
  <?php } ?>
150
  // check if captcha element is unrendered
151
- console.log(el);
152
  if ( ! el.childNodes.length) {
153
  wid = grecaptcha.render(el,{
154
  'sitekey':'<?php echo $sitekey ?>',
155
  'theme':el.getAttribute('data-theme') || '<?php echo WP_reCaptcha::instance()->get_option('recaptcha_theme'); ?>'
156
- <?php if ( WP_reCaptcha::instance()->get_option( 'recaptcha_disable_submit' ) ) { ?>
157
- ,
158
  'callback' : function(r){ get_form_submits(el).setEnabled(true); /* enable submit buttons */ }
159
  <?php } ?>
160
  });
@@ -175,7 +173,15 @@ class WP_reCaptcha_NoCaptcha extends WP_reCaptcha_Captcha {
175
  } );
176
 
177
  </script><?php
178
- ?><script src="https://www.google.com/recaptcha/api.js?onload=recaptchaLoadCallback&render=explicit<?php echo $language_param ?>" async defer></script><?php
 
 
 
 
 
 
 
 
179
  }
180
 
181
 
79
  * Prevent from creating more than one instance
80
  */
81
  private function __construct() {
 
82
  }
83
 
84
  public function get_supported_themes() {
113
  $lang = $mapping[$lang];
114
  return parent::get_language( $lang );
115
  }
116
+ public function print_head() {}
117
 
118
+ public function print_login_head() {
119
  ?><style type="text/css">
120
  #login {
121
  width:350px !important;
127
  public function print_foot() {
128
  $sitekey = WP_reCaptcha::instance()->get_option('recaptcha_publickey');
129
  $language_param = '';
130
+
 
131
 
132
  ?><script type="text/javascript">
133
  var recaptcha_widgets={};
147
  var wid;
148
  <?php } ?>
149
  // check if captcha element is unrendered
 
150
  if ( ! el.childNodes.length) {
151
  wid = grecaptcha.render(el,{
152
  'sitekey':'<?php echo $sitekey ?>',
153
  'theme':el.getAttribute('data-theme') || '<?php echo WP_reCaptcha::instance()->get_option('recaptcha_theme'); ?>'
154
+ <?php if ( WP_reCaptcha::instance()->get_option( 'recaptcha_disable_submit' ) ) {
155
+ ?> ,
156
  'callback' : function(r){ get_form_submits(el).setEnabled(true); /* enable submit buttons */ }
157
  <?php } ?>
158
  });
173
  } );
174
 
175
  </script><?php
176
+ $recaptcha_api_url = "https://www.google.com/recaptcha/api.js";
177
+ $recaptcha_api_url = add_query_arg(array(
178
+ 'onload' => 'recaptchaLoadCallback',
179
+ 'render' => 'explicit',
180
+ ),$recaptcha_api_url);
181
+ if ( $language_code = apply_filters( 'wp_recaptcha_language' , WP_reCaptcha::instance()->get_option( 'recaptcha_language' ) ) )
182
+ $recaptcha_api_url = add_query_arg('hl',$language_code,$recaptcha_api_url);
183
+
184
+ ?><script src="<?php echo esc_url( $recaptcha_api_url ) ?>" async defer></script><?php
185
  }
186
 
187
 
inc/class-wp_recaptcha_recaptcha.php CHANGED
@@ -64,7 +64,13 @@ class WP_reCaptcha_ReCaptcha extends WP_reCaptcha_Captcha {
64
  ),
65
  );
66
  }
67
-
 
 
 
 
 
 
68
  public function print_head() {
69
  $recaptcha_theme = WP_reCaptcha::instance()->get_option('recaptcha_theme');
70
  if ( $recaptcha_theme == 'custom' ) {
64
  ),
65
  );
66
  }
67
+ public function print_login_head() {
68
+ ?><style type="text/css">
69
+ #login {
70
+ width:360px !important;
71
+ }
72
+ </style><?php
73
+ }
74
  public function print_head() {
75
  $recaptcha_theme = WP_reCaptcha::instance()->get_option('recaptcha_theme');
76
  if ( $recaptcha_theme == 'custom' ) {
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: security, captcha, recaptcha, no captcha, login, signup, contact form 7, ninja forms, woocommerce
5
  Requires at least: 3.8
6
  Tested up to: 4.2
7
- Stable tag: 1.1.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -243,6 +243,12 @@ I will migrate all the translation stuff there.
243
 
244
  == Changelog ==
245
 
 
 
 
 
 
 
246
  = 1.1.0 =
247
  - Feature: Prevent Lockout - Admins can still log in when the API keys are invalid
248
  - Feature: Customize error message on contact form 7 and ninja forms
4
  Tags: security, captcha, recaptcha, no captcha, login, signup, contact form 7, ninja forms, woocommerce
5
  Requires at least: 3.8
6
  Tested up to: 4.2
7
+ Stable tag: 1.1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
243
 
244
  == Changelog ==
245
 
246
+ = 1.1.1 =
247
+ - Filter: `wp_recaptcha_do_scripts` allow disabling recaptcha scripts on certain pages.
248
+ - Filter: `wp_recaptcha_print_login_css`, allow disabling login CSS.
249
+ - Fix: Didn't render with Submit Button Disabling checked
250
+ - Fix: Use `add_query_arg()` to generate recaptcha API URL
251
+
252
  = 1.1.0 =
253
  - Feature: Prevent Lockout - Admins can still log in when the API keys are invalid
254
  - Feature: Customize error message on contact form 7 and ninja forms
wp-recaptcha-integration.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP reCaptcha Integration
4
  Plugin URI: https://wordpress.org/plugins/wp-recaptcha-integration/
5
  Description: Integrate reCaptcha in your blog. Supports no Captcha (new style recaptcha) as well as the old style reCaptcha. Provides of the box integration for signup, login, comment forms, lost password, Ninja Forms and contact form 7.
6
- Version: 1.1.0
7
  Author: Jörn Lund
8
  Author URI: https://github.com/mcguffin/
9
  */
@@ -142,6 +142,7 @@ class WP_reCaptcha {
142
 
143
  if ( $this->get_option('recaptcha_enable_signup') || $this->get_option('recaptcha_enable_login') || $this->get_option('recaptcha_enable_lostpw') ) {
144
  add_action( 'login_head' , array(&$this,'recaptcha_head') );
 
145
  add_action( 'login_footer' , array(&$this,'recaptcha_foot') );
146
  }
147
  if ( $this->get_option('recaptcha_enable_comments') ) {
@@ -238,9 +239,23 @@ class WP_reCaptcha {
238
  * hooks into `wp_head`
239
  */
240
  function recaptcha_head( ) {
241
- $this->begin_inject( );
242
- $this->captcha_instance()->print_head();
243
- $this->end_inject( );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  }
245
 
246
  /**
@@ -249,38 +264,40 @@ class WP_reCaptcha {
249
  *
250
  */
251
  function recaptcha_foot( ) {
252
- $this->begin_inject( );
 
253
 
254
- // getting submit buttons of an elements form
255
- if ( $this->get_option( 'recaptcha_disable_submit' ) ) {
256
- ?><script type="text/javascript">
257
- function get_form_submits(el){
258
- var form,current=el,ui,type,slice = Array.prototype.slice,self=this;
259
- this.submits=[];
260
- this.form=false;
261
 
262
- this.setEnabled=function(e){
263
- for ( var s in self.submits ) {
264
- if (e) self.submits[s].removeAttribute('disabled');
265
- else self.submits[s].setAttribute('disabled','disabled');
 
 
 
 
 
266
  }
 
 
 
 
 
267
  return this;
268
- };
269
- while ( current && current.nodeName != 'BODY' && current.nodeName != 'FORM' ) {
270
- current = current.parentNode;
271
  }
272
- if ( !current || current.nodeName != 'FORM' )
273
- return false;
274
- this.form=current;
275
- ui=slice.call(this.form.getElementsByTagName('input')).concat(slice.call(this.form.getElementsByTagName('button')));
276
- for (var i in ui ) if ( (type=ui[i].getAttribute('TYPE')) && type=='submit' ) this.submits.push(ui[i]);
277
- return this;
278
  }
279
- </script><?php
280
- }
281
- $this->captcha_instance()->print_foot();
282
 
283
- $this->end_inject( );
 
284
  }
285
 
286
  /**
3
  Plugin Name: WP reCaptcha Integration
4
  Plugin URI: https://wordpress.org/plugins/wp-recaptcha-integration/
5
  Description: Integrate reCaptcha in your blog. Supports no Captcha (new style recaptcha) as well as the old style reCaptcha. Provides of the box integration for signup, login, comment forms, lost password, Ninja Forms and contact form 7.
6
+ Version: 1.1.1
7
  Author: Jörn Lund
8
  Author URI: https://github.com/mcguffin/
9
  */
142
 
143
  if ( $this->get_option('recaptcha_enable_signup') || $this->get_option('recaptcha_enable_login') || $this->get_option('recaptcha_enable_lostpw') ) {
144
  add_action( 'login_head' , array(&$this,'recaptcha_head') );
145
+ add_action( 'login_head' , array(&$this,'recaptcha_login_head') );
146
  add_action( 'login_footer' , array(&$this,'recaptcha_foot') );
147
  }
148
  if ( $this->get_option('recaptcha_enable_comments') ) {
239
  * hooks into `wp_head`
240
  */
241
  function recaptcha_head( ) {
242
+ if ( apply_filters( 'wp_recaptcha_do_scripts' , true ) ) {
243
+ $this->begin_inject( );
244
+ $this->captcha_instance()->print_head();
245
+ $this->end_inject( );
246
+ }
247
+ }
248
+
249
+ /**
250
+ * print recaptcha login form stylesheets
251
+ * hooks into `wp_head`
252
+ */
253
+ function recaptcha_login_head( ) {
254
+ if ( apply_filters( 'wp_recaptcha_print_login_css' , true ) ) {
255
+ $this->begin_inject( );
256
+ $this->captcha_instance()->print_login_head();
257
+ $this->end_inject( );
258
+ }
259
  }
260
 
261
  /**
264
  *
265
  */
266
  function recaptcha_foot( ) {
267
+ if ( apply_filters( 'wp_recaptcha_do_scripts' , true ) ) {
268
+ $this->begin_inject( );
269
 
270
+ // getting submit buttons of an elements form
271
+ if ( $this->get_option( 'recaptcha_disable_submit' ) ) {
272
+ ?><script type="text/javascript">
273
+ function get_form_submits(el){
274
+ var form,current=el,ui,type,slice = Array.prototype.slice,self=this;
275
+ this.submits=[];
276
+ this.form=false;
277
 
278
+ this.setEnabled=function(e){
279
+ for ( var s in self.submits ) {
280
+ if (e) self.submits[s].removeAttribute('disabled');
281
+ else self.submits[s].setAttribute('disabled','disabled');
282
+ }
283
+ return this;
284
+ };
285
+ while ( current && current.nodeName != 'BODY' && current.nodeName != 'FORM' ) {
286
+ current = current.parentNode;
287
  }
288
+ if ( !current || current.nodeName != 'FORM' )
289
+ return false;
290
+ this.form=current;
291
+ ui=slice.call(this.form.getElementsByTagName('input')).concat(slice.call(this.form.getElementsByTagName('button')));
292
+ for (var i = 0; i < ui.length; i++) if ( (type=ui[i].getAttribute('TYPE')) && type=='submit' ) this.submits.push(ui[i]);
293
  return this;
 
 
 
294
  }
295
+ </script><?php
 
 
 
 
 
296
  }
297
+ $this->captcha_instance()->print_foot();
 
 
298
 
299
+ $this->end_inject( );
300
+ }
301
  }
302
 
303
  /**