Contact Form 7 – reCaptcha v2 - Version 1.3.8

Version Description

(2022-03-07) = * New global reCaptcha Locale filter hook wpcf7_recaptcha_locale.

Download this release

Release Info

Developer IQComputing
Plugin Icon 128x128 Contact Form 7 – reCaptcha v2
Version 1.3.8
Comparing to
See all releases

Code changes from version 1.3.7 to 1.3.8

Files changed (4) hide show
  1. changelog.txt +18 -8
  2. readme.txt +5 -5
  3. recaptcha-v2.php +80 -80
  4. wpcf7-recaptcha.php +78 -78
changelog.txt CHANGED
@@ -2,6 +2,16 @@
2
 
3
  This is to keep track of all changes the plugin undertakes. The readme.txt should only contain the most recent 3.
4
 
 
 
 
 
 
 
 
 
 
 
5
  = 1.3.7 =
6
 
7
  Release Date: January 03, 2022
@@ -60,7 +70,7 @@ Release Date: February 25, 2021
60
 
61
  * Overview
62
  * Match Conatct Form 7 update changes.
63
-
64
  * Code Changes
65
  * Updated the remove action hook priority for wpcf7_recaptcha_enqueue_scripts from 10 to 20
66
 
@@ -77,7 +87,7 @@ Release Date: August 26, 2020
77
 
78
  * Overview
79
  * Some users reported issues with reCaptcha displaying, likely based on enqueue method
80
-
81
  * Code Changes
82
  * Removed `iqfix_wpcf7_recaptcha_callback_script()` function
83
  * Enqueued reCaptcha controls based on whether google reCaptcha is enqueued.
@@ -140,7 +150,7 @@ Release Date: November 13, 2019
140
  * Added reCaptcha alignment controls to the reCaptcha shortcode. Left, Center, Right.
141
  * Added support for the Contact Form 7 constants `WPCF7_RECAPTCHA_SITEKEY` and `WPCF7_RECAPTCHA_SECRET` in the WP Config.
142
  * For more information see the post by Takayuki Miyoshi ( https://contactform7.com/2019/08/04/contact-form-7-514/ )
143
-
144
  * Fixes
145
  * Updated the logging feature for whenever the reCaptcha returns an error. Uses Contact Form 7 log method.
146
 
@@ -166,7 +176,7 @@ Release Date: June 13, 2019
166
  * Removed jQuery dependecy entirely.
167
  * Converted inline jQuery to JavaScript in regards to reCaptcha validation upon submission.
168
  * Updated noscript reCaptcha to include a line break which A3 Lazy Load decides it won't lazy load for some reason.
169
-
170
  * Code Changes
171
  * recaptcha-v2.php -> iqfix_wpcf7_recaptcha_callback_script() Updated inline jQuery to vanilla JavaScript.
172
  * recaptcha-v2.php -> iqfix_wpcf7_recaptcha_noscript() Added a linebreak to noscript iframe and textarea in an attempt to prevent A3 Lazy Load plugin from lazying loading the iframe.
@@ -178,7 +188,7 @@ Release Date: May 14, 2019
178
  * Overview
179
  * Added option to allow user to choose which website to pull the reCaptcha resources from.
180
  The choices are google.com or recaptcha.net. These are for situations or countries that specifically block Google and prevent our reCaptcha from appearing.
181
-
182
  * Code Changes
183
  * Updated recaptcha-v2.php file to switch out the recaptcha source URLs.
184
  * Updated reCaptcha noscript to look nicer and function better.
@@ -196,7 +206,7 @@ Release Date: April 26, 2019
196
  We've hook into before Contact Form 7 does their Flamingo submission and removed the hook if 1) There's a reCaptcha on the form and 2) no reCaptcha verification was found in the submitted data.]
197
  This should prevent the multitude of spam posts being saved in Flamingo.
198
  Thanks to @scits to bringing this issue to our attention!
199
-
200
  * Files Added
201
  * wpcf7-recaptcha/flamingo.php
202
  * Only gets included and processed whenever Flamingo is detected to be installed and active.
@@ -225,12 +235,12 @@ Relase Date: February 22, 2019
225
  * General
226
  * Ensured WordPress 5.1 compatibility
227
  * We need your help translating this plugin! Please contribute at: https://translate.wordpress.org/projects/wp-plugins/wpcf7-recaptcha
228
-
229
  * Multisite
230
  * Multisite - Network Admins will notice a new menu item under plugins labelled "WPCF7 reCaptcha Settings"
231
  * Multisite - Network Admins now have the ability to add default keys and settings for sites. Individual sites can overwrite these defaults should they choose to.
232
  * Multisite - Default Network settings do not override keys or settings if they are already set/saved on the individual site. These only apply if none are found on the individual site.
233
-
234
  * Cleanup
235
  * Removed languages folder to avoid confusion with glotpress.
236
 
2
 
3
  This is to keep track of all changes the plugin undertakes. The readme.txt should only contain the most recent 3.
4
 
5
+ = 1.3.8 =
6
+
7
+ Release Date: March 07, 2022
8
+
9
+ * Overview
10
+ * Added new filter hook to allow developers to filter the global reCaptcha locale.
11
+
12
+ * Code Changes
13
+ * New filter `wpcf7_recaptcha_locale` with the passed Site Locale in recaptcha-v2.php
14
+
15
  = 1.3.7 =
16
 
17
  Release Date: January 03, 2022
70
 
71
  * Overview
72
  * Match Conatct Form 7 update changes.
73
+
74
  * Code Changes
75
  * Updated the remove action hook priority for wpcf7_recaptcha_enqueue_scripts from 10 to 20
76
 
87
 
88
  * Overview
89
  * Some users reported issues with reCaptcha displaying, likely based on enqueue method
90
+
91
  * Code Changes
92
  * Removed `iqfix_wpcf7_recaptcha_callback_script()` function
93
  * Enqueued reCaptcha controls based on whether google reCaptcha is enqueued.
150
  * Added reCaptcha alignment controls to the reCaptcha shortcode. Left, Center, Right.
151
  * Added support for the Contact Form 7 constants `WPCF7_RECAPTCHA_SITEKEY` and `WPCF7_RECAPTCHA_SECRET` in the WP Config.
152
  * For more information see the post by Takayuki Miyoshi ( https://contactform7.com/2019/08/04/contact-form-7-514/ )
153
+
154
  * Fixes
155
  * Updated the logging feature for whenever the reCaptcha returns an error. Uses Contact Form 7 log method.
156
 
176
  * Removed jQuery dependecy entirely.
177
  * Converted inline jQuery to JavaScript in regards to reCaptcha validation upon submission.
178
  * Updated noscript reCaptcha to include a line break which A3 Lazy Load decides it won't lazy load for some reason.
179
+
180
  * Code Changes
181
  * recaptcha-v2.php -> iqfix_wpcf7_recaptcha_callback_script() Updated inline jQuery to vanilla JavaScript.
182
  * recaptcha-v2.php -> iqfix_wpcf7_recaptcha_noscript() Added a linebreak to noscript iframe and textarea in an attempt to prevent A3 Lazy Load plugin from lazying loading the iframe.
188
  * Overview
189
  * Added option to allow user to choose which website to pull the reCaptcha resources from.
190
  The choices are google.com or recaptcha.net. These are for situations or countries that specifically block Google and prevent our reCaptcha from appearing.
191
+
192
  * Code Changes
193
  * Updated recaptcha-v2.php file to switch out the recaptcha source URLs.
194
  * Updated reCaptcha noscript to look nicer and function better.
206
  We've hook into before Contact Form 7 does their Flamingo submission and removed the hook if 1) There's a reCaptcha on the form and 2) no reCaptcha verification was found in the submitted data.]
207
  This should prevent the multitude of spam posts being saved in Flamingo.
208
  Thanks to @scits to bringing this issue to our attention!
209
+
210
  * Files Added
211
  * wpcf7-recaptcha/flamingo.php
212
  * Only gets included and processed whenever Flamingo is detected to be installed and active.
235
  * General
236
  * Ensured WordPress 5.1 compatibility
237
  * We need your help translating this plugin! Please contribute at: https://translate.wordpress.org/projects/wp-plugins/wpcf7-recaptcha
238
+
239
  * Multisite
240
  * Multisite - Network Admins will notice a new menu item under plugins labelled "WPCF7 reCaptcha Settings"
241
  * Multisite - Network Admins now have the ability to add default keys and settings for sites. Individual sites can overwrite these defaults should they choose to.
242
  * Multisite - Default Network settings do not override keys or settings if they are already set/saved on the individual site. These only apply if none are found on the individual site.
243
+
244
  * Cleanup
245
  * Removed languages folder to avoid confusion with glotpress.
246
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: iqcomputing
3
  Tags: contact-form-7, contact-form-7-recaptcha, recaptcha, spam
4
  Requires at least: 4.9
5
  Tested up to: 5.8
6
- Stable tag: 1.3.7
7
  License: GPLv2 or later
8
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -60,12 +60,12 @@ Should the above be correct, at this point it's time to open a support thread fo
60
 
61
  == Changelog ==
62
 
 
 
 
63
  = 1.3.7 (2022-01-03) =
64
  * Happy New Year!
65
  * Fixed issue with reCpatcha not appearing in the new WordPress Full Site Editing feature of TwentyTwentyTwo theme. Thanks @gerhardfasol !
66
 
67
  = 1.3.6 (2021-11-29) =
68
- * Resolved conflict with Conditional Fields for Contact Form 7.
69
-
70
- = 1.3.5 (2021-06-21) =
71
- * Updated support for WordPress 5.8
3
  Tags: contact-form-7, contact-form-7-recaptcha, recaptcha, spam
4
  Requires at least: 4.9
5
  Tested up to: 5.8
6
+ Stable tag: 1.3.8
7
  License: GPLv2 or later
8
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
9
 
60
 
61
  == Changelog ==
62
 
63
+ = 1.3.8 (2022-03-07) =
64
+ * New global reCaptcha Locale filter hook `wpcf7_recaptcha_locale`.
65
+
66
  = 1.3.7 (2022-01-03) =
67
  * Happy New Year!
68
  * Fixed issue with reCpatcha not appearing in the new WordPress Full Site Editing feature of TwentyTwentyTwo theme. Thanks @gerhardfasol !
69
 
70
  = 1.3.6 (2021-11-29) =
71
+ * Resolved conflict with Conditional Fields for Contact Form 7.
 
 
 
recaptcha-v2.php CHANGED
@@ -10,7 +10,7 @@ defined( 'ABSPATH' ) or die( 'You cannot be here.' );
10
 
11
  /**
12
  * Remove old hooks and add new hook callbacks
13
- *
14
  * @return void
15
  */
16
  function iqfix_wpcf7_manage_hooks() {
@@ -31,7 +31,7 @@ add_action( 'setup_theme', 'iqfix_wpcf7_manage_hooks' );
31
 
32
  /**
33
  * Remove current [recaptcha] tag and replace it with old reCaptcha tag
34
- *
35
  * @return void
36
  */
37
  function iqfix_wpcf7_add_recaptcha_tag() {
@@ -49,25 +49,25 @@ add_action( 'wpcf7_init', 'iqfix_wpcf7_add_recaptcha_tag', 20 );
49
 
50
  /**
51
  * Register the Google reCaptcha API script
52
- *
53
  * The following function was not written by IQComputing and is included in
54
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
55
  * contact-form-7\modules\recaptcha.php LN241
56
- *
57
  * @return void
58
  */
59
  function iqfix_wpcf7_recaptcha_enqueue_scripts() {
60
-
61
  if( wp_script_is( 'google-recaptcha', 'registered' ) ) {
62
  return;
63
  }
64
-
65
  $source = WPCF7::get_option( 'iqfix_recaptcha_source' );
66
  $source = IQFix_WPCF7_Deity::verify_recaptcha_source( $source );
67
-
68
  $url = sprintf( 'https://www.%s/recaptcha/api.js', $source );
69
  $url = add_query_arg( array(
70
- 'hl' => esc_attr( get_locale() ), // Lowercase L
71
  'onload' => 'recaptchaCallback',
72
  'render' => 'explicit',
73
  ), $url );
@@ -78,7 +78,7 @@ function iqfix_wpcf7_recaptcha_enqueue_scripts() {
78
  'recaptcha_empty' => esc_html__( 'Please verify that you are not a robot.', 'wpcf7-recaptcha' ),
79
  'response_err' => esc_html__( 'wpcf7-recaptcha: Could not verify reCaptcha response.', 'wpcf7-recaptcha' ),
80
  ) );
81
-
82
  wp_enqueue_script( 'google-recaptcha' );
83
 
84
  }
@@ -87,13 +87,13 @@ add_action( 'wp_enqueue_scripts', 'iqfix_wpcf7_recaptcha_enqueue_scripts', 50 );
87
 
88
  /**
89
  * reCaptcha Callback
90
- *
91
  * The following function was not written by IQComputing and is included in
92
  * Contact Form 7 v5.0.5
93
  * contact-form-7\modules\recaptcha.php LN326
94
- *
95
  * @param WPCF7_FormTag $tag
96
- *
97
  * @return String $html
98
  */
99
  function iqfix_wpcf7_recaptcha_form_tag_handler( $tag ) {
@@ -131,13 +131,13 @@ function iqfix_wpcf7_recaptcha_form_tag_handler( $tag ) {
131
 
132
  /**
133
  * Display reCaptcha noscript tag should javacript be disabled.
134
- *
135
  * The following function was not written by IQComputing and is included in
136
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
137
  * contact-form-7\modules\recaptcha.php LN360
138
- *
139
  * @param Array $args
140
- *
141
  * @return String
142
  */
143
  function iqfix_wpcf7_recaptcha_noscript( $args = '' ) {
@@ -149,7 +149,7 @@ function iqfix_wpcf7_recaptcha_noscript( $args = '' ) {
149
  if ( empty( $args['sitekey'] ) ) {
150
  return;
151
  }
152
-
153
  $source = WPCF7::get_option( 'iqfix_recaptcha_source' );
154
  $source = IQFix_WPCF7_Deity::verify_recaptcha_source( $source );
155
  $url = add_query_arg( 'k', $args['sitekey'],
@@ -174,13 +174,13 @@ function iqfix_wpcf7_recaptcha_noscript( $args = '' ) {
174
 
175
  /**
176
  * Verify submission is legitimate, verify reCaptcha response
177
- *
178
  * The following function was not written by IQComputing and is included in
179
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
180
  * contact-form-7\modules\recaptcha.php LN395
181
- *
182
  * @param Boolean $spam
183
- *
184
  * @return Boolean $spam
185
  */
186
  function iqfix_wpcf7_recaptcha_check_with_google( $spam ) {
@@ -219,11 +219,11 @@ function iqfix_wpcf7_recaptcha_check_with_google( $spam ) {
219
 
220
  /**
221
  * Grab and return the posted reCaptcha response
222
- *
223
  * The following function was not written by IQComputing and is included in
224
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
225
  * contact-form-7\modules\recaptcha.php LN509
226
- *
227
  * @return String|FALSE
228
  */
229
  function wpcf7_recaptcha_response() {
@@ -239,11 +239,11 @@ function wpcf7_recaptcha_response() {
239
 
240
  /**
241
  * Add [recaptcha] to Contact Form 7 field list
242
- *
243
  * The following function was not written by IQComputing and is included in
244
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
245
  * contact-form-7\modules\recaptcha.php LN426
246
- *
247
  * @return void
248
  */
249
  function iqfix_wpcf7_add_tag_generator_recaptcha() {
@@ -262,14 +262,14 @@ add_action( 'wpcf7_admin_init', 'iqfix_wpcf7_add_tag_generator_recaptcha', 45 );
262
 
263
  /**
264
  * Show [recaptcha] field settings
265
- *
266
  * The following function was not written by IQComputing and is included in
267
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
268
  * contact-form-7\modules\recaptcha.php LN432
269
- *
270
  * @param WPCF7_ContactForm $contact_form
271
  * @param Array $args
272
- *
273
  * @return void
274
  */
275
  function iqfix_wpcf7_tag_generator_recaptcha( $contact_form, $args = '' ) {
@@ -292,7 +292,7 @@ function iqfix_wpcf7_tag_generator_recaptcha( $contact_form, $args = '' ) {
292
 
293
  return;
294
  }
295
-
296
  /* translators: %s is a link to the Contact Form 7 blog post regarding reCaptcha v3 */
297
  $description = esc_html__( "Generate a form-tag for a reCaptcha widget. For more details, see %s.", 'wpcf7-recaptcha' );
298
  $desc_link = wpcf7_link( 'https://contactform7.com/recaptcha/', esc_html__( 'reCaptcha', 'wpcf7-recaptcha' ) );
@@ -400,7 +400,7 @@ function iqfix_wpcf7_tag_generator_recaptcha( $contact_form, $args = '' ) {
400
  /**
401
  * The following class is supposed to use and replicate some functionality
402
  * From Contact Form 7 v5.0.5
403
- *
404
  * @return void
405
  */
406
  function iqfix_recaptcha_class_init() {
@@ -408,7 +408,7 @@ function iqfix_recaptcha_class_init() {
408
  if( ! class_exists( 'WPCF7_RECAPTCHA' ) ) {
409
  return false;
410
  }
411
-
412
  Class IQFix_ReCaptcha extends WPCF7_RECAPTCHA {
413
 
414
  private static $instance;
@@ -417,49 +417,49 @@ function iqfix_recaptcha_class_init() {
417
 
418
  /**
419
  * Class initialization
420
- *
421
  * The following method was not written by IQComputing and is included in
422
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
423
  * contact-form-7\modules\recaptcha.php LN202
424
- *
425
  * return void
426
  */
427
  private function __construct() {
428
-
429
  if( defined( 'WPCF7_RECAPTCHA_SITEKEY' ) && defined( 'WPCF7_RECAPTCHA_SECRET' ) ) {
430
  $this->sitekeys = array( WPCF7_RECAPTCHA_SITEKEY => WPCF7_RECAPTCHA_SECRET );
431
  } else {
432
  $this->sitekeys = WPCF7::get_option( 'recaptcha' );
433
  }
434
-
435
  }
436
 
437
 
438
  /**
439
  * Singleton
440
- *
441
  * The following method was not written by IQComputing and is included in
442
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
443
- * contact-form-7\modules\recaptcha.php LN10
444
- *
445
  * @return IQFix_ReCaptcha
446
  */
447
  public static function get_instance() {
448
  if ( empty( self::$instance ) ) {
449
  self::$instance = new self;
450
  }
451
-
452
  return self::$instance;
453
  }
454
 
455
 
456
  /**
457
  * Check if reCaptcha is active
458
- *
459
  * The following method was not written by IQComputing and is included in
460
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
461
  * contact-form-7\modules\recaptcha.php LN26
462
- *
463
  * @return Boolean
464
  */
465
  public function is_active() {
@@ -471,11 +471,11 @@ function iqfix_recaptcha_class_init() {
471
 
472
  /**
473
  * Get set reCaptcha sitekey
474
- *
475
  * The following method was not written by IQComputing and is included in
476
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
477
  * contact-form-7\modules\recaptcha.php LN45
478
- *
479
  * @return String|FALSE
480
  */
481
  public function get_sitekey() {
@@ -483,25 +483,25 @@ function iqfix_recaptcha_class_init() {
483
  or ! is_array( $this->sitekeys ) ) {
484
  return false;
485
  }
486
-
487
  $sitekeys = array_keys( $this->sitekeys );
488
-
489
  return $sitekeys[0];
490
  }
491
-
492
 
493
  /**
494
  * Get set reCaptcha secret key
495
- *
496
  * The following method was not written by IQComputing and is included in
497
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
498
  * contact-form-7\modules\recaptcha.php LN55
499
- *
500
  * @return String|FALSE
501
  */
502
  public function get_secret( $sitekey ) {
503
  $sitekeys = (array) $this->sitekeys;
504
-
505
  if ( isset( $sitekeys[$sitekey] ) ) {
506
  return $sitekeys[$sitekey];
507
  } else {
@@ -512,13 +512,13 @@ function iqfix_recaptcha_class_init() {
512
 
513
  /**
514
  * Verify reCaptcha Response
515
- *
516
  * The following method was not written by IQComputing and is included in
517
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
518
  * contact-form-7\modules\recaptcha.php LN65
519
- *
520
  * @param String $response_token
521
- *
522
  * @return Boolean $is_human
523
  */
524
  public function verify( $response_token ) {
@@ -528,7 +528,7 @@ function iqfix_recaptcha_class_init() {
528
  if ( empty( $response_token ) ) {
529
  return $is_human;
530
  }
531
-
532
  $source = WPCF7::get_option( 'iqfix_recaptcha_source' );
533
  $source = IQFix_WPCF7_Deity::verify_recaptcha_source( $source );
534
  $endpoint = sprintf( 'https://www.%s/recaptcha/api/siteverify', $source );
@@ -541,23 +541,23 @@ function iqfix_recaptcha_class_init() {
541
  'remoteip' => $_SERVER['REMOTE_ADDR'],
542
  ),
543
  );
544
-
545
  $response = wp_safe_remote_post( esc_url_raw( $endpoint ), $request );
546
-
547
  if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
548
-
549
  if ( WP_DEBUG ) {
550
  $this->log( $endpoint, $request, $response );
551
  }
552
-
553
  return $is_human;
554
-
555
  }
556
-
557
  $response = wp_remote_retrieve_body( $response );
558
  $response = json_decode( $response, true );
559
  $is_human = isset( $response['success'] ) && true == $response['success'];
560
-
561
  return apply_filters( 'wpcf7_recaptcha_verify_response', $is_human, $response );
562
 
563
  }
@@ -570,54 +570,54 @@ add_action( 'init', 'iqfix_recaptcha_class_init', 11 );
570
 
571
  /**
572
  * Add some inline CSS for the reCaptcha iframe
573
- *
574
  * @return void
575
  */
576
  function iqfix_recaptcha_inline_css() {
577
-
578
  $iqfix_css = '.wpcf7 .wpcf7-recaptcha iframe {margin-bottom: 0;}';
579
  $iqfix_css .= '.wpcf7 .wpcf7-recaptcha[data-align="center"] > div {margin: 0 auto;}';
580
  $iqfix_css .= '.wpcf7 .wpcf7-recaptcha[data-align="right"] > div {margin: 0 0 0 auto;}';
581
  wp_add_inline_style( 'contact-form-7', $iqfix_css );
582
-
583
  }
584
  add_action( 'wp_enqueue_scripts', 'iqfix_recaptcha_inline_css' );
585
 
586
 
587
  /**
588
  * Validate empty reCaptcha
589
- *
590
  * @param Object $result
591
  * @param Object $tag
592
- *
593
  * @return Object $result
594
  */
595
  function iqfix_recaptcha_validation( $result, $tag ) {
596
-
597
  if( empty( $tag->name ) ) {
598
  $tag->name = 'recaptcha';
599
  }
600
-
601
  if( ! isset( $_POST['g-recaptcha-response'] ) ) {
602
-
603
  $invalidate = wpcf7_get_message( 'iqfix_recaptcha_no_set' );
604
  $result->invalidate(
605
  $tag,
606
  ( ( ! empty( $invalidate ) ) ? $invalidate : __( 'Could not verify the reCaptcha response.', 'wpcf7-recaptcha' ) )
607
  );
608
-
609
  } else if( empty( $_POST['g-recaptcha-response'] ) ) {
610
-
611
  $invalidate = wpcf7_get_message( 'iqfix_recaptcha_response_empty' );
612
  $result->invalidate(
613
  $tag,
614
  ( ( ! empty( $invalidate ) ) ? $invalidate : __( 'Please verify that you are not a robot.', 'wpcf7-recaptcha' ) )
615
  );
616
-
617
  }
618
-
619
  return $result;
620
-
621
  }
622
  add_filter( 'wpcf7_validate_recaptcha', 'iqfix_recaptcha_validation', 10, 2 );
623
  add_filter( 'wpcf7_validate_recaptcha*', 'iqfix_recaptcha_validation', 10, 2 );
@@ -625,32 +625,32 @@ add_filter( 'wpcf7_validate_recaptcha*', 'iqfix_recaptcha_validation', 10, 2 );
625
 
626
  /**
627
  * Ensure that the reCaptcha has a name
628
- *
629
  * @param Array $tag
630
- *
631
  * @return Array $tag
632
  */
633
  function iqfix_recaptcha_tag_name( $tag ) {
634
-
635
  if( empty( $tag['name'] ) && 'recaptcha' === $tag['type'] ) {
636
  $tag['name'] = 'recaptcha';
637
  }
638
-
639
  return $tag;
640
-
641
  }
642
  add_filter( 'wpcf7_form_tag', 'iqfix_recaptcha_tag_name' );
643
 
644
 
645
  /**
646
  * Add reCaptcha message settings to Contact Form 7
647
- *
648
  * @param String $message
649
- *
650
  * @return String $message
651
  */
652
  function iqfix_recaptcha_messages( $messages ) {
653
-
654
  return array_merge( $messages, array(
655
  'iqfix_recaptcha_no_set' => array(
656
  'description' => __( 'This message shows whenever the reCaptcha is completely blocked. Added by plugin: ReCaptcha for Contact Form 7.', 'wpcf7-recaptcha' ),
@@ -661,6 +661,6 @@ function iqfix_recaptcha_messages( $messages ) {
661
  'default' => __( 'Please verify that you are not a robot.', 'wpcf7-recaptcha' ),
662
  ),
663
  ) );
664
-
665
  }
666
  add_filter( 'wpcf7_messages', 'iqfix_recaptcha_messages' );
10
 
11
  /**
12
  * Remove old hooks and add new hook callbacks
13
+ *
14
  * @return void
15
  */
16
  function iqfix_wpcf7_manage_hooks() {
31
 
32
  /**
33
  * Remove current [recaptcha] tag and replace it with old reCaptcha tag
34
+ *
35
  * @return void
36
  */
37
  function iqfix_wpcf7_add_recaptcha_tag() {
49
 
50
  /**
51
  * Register the Google reCaptcha API script
52
+ *
53
  * The following function was not written by IQComputing and is included in
54
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
55
  * contact-form-7\modules\recaptcha.php LN241
56
+ *
57
  * @return void
58
  */
59
  function iqfix_wpcf7_recaptcha_enqueue_scripts() {
60
+
61
  if( wp_script_is( 'google-recaptcha', 'registered' ) ) {
62
  return;
63
  }
64
+
65
  $source = WPCF7::get_option( 'iqfix_recaptcha_source' );
66
  $source = IQFix_WPCF7_Deity::verify_recaptcha_source( $source );
67
+
68
  $url = sprintf( 'https://www.%s/recaptcha/api.js', $source );
69
  $url = add_query_arg( array(
70
+ 'hl' => esc_attr( apply_filters( 'wpcf7_recaptcha_locale', get_locale() ) ), // Lowercase L
71
  'onload' => 'recaptchaCallback',
72
  'render' => 'explicit',
73
  ), $url );
78
  'recaptcha_empty' => esc_html__( 'Please verify that you are not a robot.', 'wpcf7-recaptcha' ),
79
  'response_err' => esc_html__( 'wpcf7-recaptcha: Could not verify reCaptcha response.', 'wpcf7-recaptcha' ),
80
  ) );
81
+
82
  wp_enqueue_script( 'google-recaptcha' );
83
 
84
  }
87
 
88
  /**
89
  * reCaptcha Callback
90
+ *
91
  * The following function was not written by IQComputing and is included in
92
  * Contact Form 7 v5.0.5
93
  * contact-form-7\modules\recaptcha.php LN326
94
+ *
95
  * @param WPCF7_FormTag $tag
96
+ *
97
  * @return String $html
98
  */
99
  function iqfix_wpcf7_recaptcha_form_tag_handler( $tag ) {
131
 
132
  /**
133
  * Display reCaptcha noscript tag should javacript be disabled.
134
+ *
135
  * The following function was not written by IQComputing and is included in
136
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
137
  * contact-form-7\modules\recaptcha.php LN360
138
+ *
139
  * @param Array $args
140
+ *
141
  * @return String
142
  */
143
  function iqfix_wpcf7_recaptcha_noscript( $args = '' ) {
149
  if ( empty( $args['sitekey'] ) ) {
150
  return;
151
  }
152
+
153
  $source = WPCF7::get_option( 'iqfix_recaptcha_source' );
154
  $source = IQFix_WPCF7_Deity::verify_recaptcha_source( $source );
155
  $url = add_query_arg( 'k', $args['sitekey'],
174
 
175
  /**
176
  * Verify submission is legitimate, verify reCaptcha response
177
+ *
178
  * The following function was not written by IQComputing and is included in
179
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
180
  * contact-form-7\modules\recaptcha.php LN395
181
+ *
182
  * @param Boolean $spam
183
+ *
184
  * @return Boolean $spam
185
  */
186
  function iqfix_wpcf7_recaptcha_check_with_google( $spam ) {
219
 
220
  /**
221
  * Grab and return the posted reCaptcha response
222
+ *
223
  * The following function was not written by IQComputing and is included in
224
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
225
  * contact-form-7\modules\recaptcha.php LN509
226
+ *
227
  * @return String|FALSE
228
  */
229
  function wpcf7_recaptcha_response() {
239
 
240
  /**
241
  * Add [recaptcha] to Contact Form 7 field list
242
+ *
243
  * The following function was not written by IQComputing and is included in
244
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
245
  * contact-form-7\modules\recaptcha.php LN426
246
+ *
247
  * @return void
248
  */
249
  function iqfix_wpcf7_add_tag_generator_recaptcha() {
262
 
263
  /**
264
  * Show [recaptcha] field settings
265
+ *
266
  * The following function was not written by IQComputing and is included in
267
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
268
  * contact-form-7\modules\recaptcha.php LN432
269
+ *
270
  * @param WPCF7_ContactForm $contact_form
271
  * @param Array $args
272
+ *
273
  * @return void
274
  */
275
  function iqfix_wpcf7_tag_generator_recaptcha( $contact_form, $args = '' ) {
292
 
293
  return;
294
  }
295
+
296
  /* translators: %s is a link to the Contact Form 7 blog post regarding reCaptcha v3 */
297
  $description = esc_html__( "Generate a form-tag for a reCaptcha widget. For more details, see %s.", 'wpcf7-recaptcha' );
298
  $desc_link = wpcf7_link( 'https://contactform7.com/recaptcha/', esc_html__( 'reCaptcha', 'wpcf7-recaptcha' ) );
400
  /**
401
  * The following class is supposed to use and replicate some functionality
402
  * From Contact Form 7 v5.0.5
403
+ *
404
  * @return void
405
  */
406
  function iqfix_recaptcha_class_init() {
408
  if( ! class_exists( 'WPCF7_RECAPTCHA' ) ) {
409
  return false;
410
  }
411
+
412
  Class IQFix_ReCaptcha extends WPCF7_RECAPTCHA {
413
 
414
  private static $instance;
417
 
418
  /**
419
  * Class initialization
420
+ *
421
  * The following method was not written by IQComputing and is included in
422
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
423
  * contact-form-7\modules\recaptcha.php LN202
424
+ *
425
  * return void
426
  */
427
  private function __construct() {
428
+
429
  if( defined( 'WPCF7_RECAPTCHA_SITEKEY' ) && defined( 'WPCF7_RECAPTCHA_SECRET' ) ) {
430
  $this->sitekeys = array( WPCF7_RECAPTCHA_SITEKEY => WPCF7_RECAPTCHA_SECRET );
431
  } else {
432
  $this->sitekeys = WPCF7::get_option( 'recaptcha' );
433
  }
434
+
435
  }
436
 
437
 
438
  /**
439
  * Singleton
440
+ *
441
  * The following method was not written by IQComputing and is included in
442
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
443
+ * contact-form-7\modules\recaptcha.php LN10
444
+ *
445
  * @return IQFix_ReCaptcha
446
  */
447
  public static function get_instance() {
448
  if ( empty( self::$instance ) ) {
449
  self::$instance = new self;
450
  }
451
+
452
  return self::$instance;
453
  }
454
 
455
 
456
  /**
457
  * Check if reCaptcha is active
458
+ *
459
  * The following method was not written by IQComputing and is included in
460
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
461
  * contact-form-7\modules\recaptcha.php LN26
462
+ *
463
  * @return Boolean
464
  */
465
  public function is_active() {
471
 
472
  /**
473
  * Get set reCaptcha sitekey
474
+ *
475
  * The following method was not written by IQComputing and is included in
476
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
477
  * contact-form-7\modules\recaptcha.php LN45
478
+ *
479
  * @return String|FALSE
480
  */
481
  public function get_sitekey() {
483
  or ! is_array( $this->sitekeys ) ) {
484
  return false;
485
  }
486
+
487
  $sitekeys = array_keys( $this->sitekeys );
488
+
489
  return $sitekeys[0];
490
  }
491
+
492
 
493
  /**
494
  * Get set reCaptcha secret key
495
+ *
496
  * The following method was not written by IQComputing and is included in
497
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
498
  * contact-form-7\modules\recaptcha.php LN55
499
+ *
500
  * @return String|FALSE
501
  */
502
  public function get_secret( $sitekey ) {
503
  $sitekeys = (array) $this->sitekeys;
504
+
505
  if ( isset( $sitekeys[$sitekey] ) ) {
506
  return $sitekeys[$sitekey];
507
  } else {
512
 
513
  /**
514
  * Verify reCaptcha Response
515
+ *
516
  * The following method was not written by IQComputing and is included in
517
  * Contact Form 7 v5.0.5 by Takayuki Miyoshi
518
  * contact-form-7\modules\recaptcha.php LN65
519
+ *
520
  * @param String $response_token
521
+ *
522
  * @return Boolean $is_human
523
  */
524
  public function verify( $response_token ) {
528
  if ( empty( $response_token ) ) {
529
  return $is_human;
530
  }
531
+
532
  $source = WPCF7::get_option( 'iqfix_recaptcha_source' );
533
  $source = IQFix_WPCF7_Deity::verify_recaptcha_source( $source );
534
  $endpoint = sprintf( 'https://www.%s/recaptcha/api/siteverify', $source );
541
  'remoteip' => $_SERVER['REMOTE_ADDR'],
542
  ),
543
  );
544
+
545
  $response = wp_safe_remote_post( esc_url_raw( $endpoint ), $request );
546
+
547
  if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
548
+
549
  if ( WP_DEBUG ) {
550
  $this->log( $endpoint, $request, $response );
551
  }
552
+
553
  return $is_human;
554
+
555
  }
556
+
557
  $response = wp_remote_retrieve_body( $response );
558
  $response = json_decode( $response, true );
559
  $is_human = isset( $response['success'] ) && true == $response['success'];
560
+
561
  return apply_filters( 'wpcf7_recaptcha_verify_response', $is_human, $response );
562
 
563
  }
570
 
571
  /**
572
  * Add some inline CSS for the reCaptcha iframe
573
+ *
574
  * @return void
575
  */
576
  function iqfix_recaptcha_inline_css() {
577
+
578
  $iqfix_css = '.wpcf7 .wpcf7-recaptcha iframe {margin-bottom: 0;}';
579
  $iqfix_css .= '.wpcf7 .wpcf7-recaptcha[data-align="center"] > div {margin: 0 auto;}';
580
  $iqfix_css .= '.wpcf7 .wpcf7-recaptcha[data-align="right"] > div {margin: 0 0 0 auto;}';
581
  wp_add_inline_style( 'contact-form-7', $iqfix_css );
582
+
583
  }
584
  add_action( 'wp_enqueue_scripts', 'iqfix_recaptcha_inline_css' );
585
 
586
 
587
  /**
588
  * Validate empty reCaptcha
589
+ *
590
  * @param Object $result
591
  * @param Object $tag
592
+ *
593
  * @return Object $result
594
  */
595
  function iqfix_recaptcha_validation( $result, $tag ) {
596
+
597
  if( empty( $tag->name ) ) {
598
  $tag->name = 'recaptcha';
599
  }
600
+
601
  if( ! isset( $_POST['g-recaptcha-response'] ) ) {
602
+
603
  $invalidate = wpcf7_get_message( 'iqfix_recaptcha_no_set' );
604
  $result->invalidate(
605
  $tag,
606
  ( ( ! empty( $invalidate ) ) ? $invalidate : __( 'Could not verify the reCaptcha response.', 'wpcf7-recaptcha' ) )
607
  );
608
+
609
  } else if( empty( $_POST['g-recaptcha-response'] ) ) {
610
+
611
  $invalidate = wpcf7_get_message( 'iqfix_recaptcha_response_empty' );
612
  $result->invalidate(
613
  $tag,
614
  ( ( ! empty( $invalidate ) ) ? $invalidate : __( 'Please verify that you are not a robot.', 'wpcf7-recaptcha' ) )
615
  );
616
+
617
  }
618
+
619
  return $result;
620
+
621
  }
622
  add_filter( 'wpcf7_validate_recaptcha', 'iqfix_recaptcha_validation', 10, 2 );
623
  add_filter( 'wpcf7_validate_recaptcha*', 'iqfix_recaptcha_validation', 10, 2 );
625
 
626
  /**
627
  * Ensure that the reCaptcha has a name
628
+ *
629
  * @param Array $tag
630
+ *
631
  * @return Array $tag
632
  */
633
  function iqfix_recaptcha_tag_name( $tag ) {
634
+
635
  if( empty( $tag['name'] ) && 'recaptcha' === $tag['type'] ) {
636
  $tag['name'] = 'recaptcha';
637
  }
638
+
639
  return $tag;
640
+
641
  }
642
  add_filter( 'wpcf7_form_tag', 'iqfix_recaptcha_tag_name' );
643
 
644
 
645
  /**
646
  * Add reCaptcha message settings to Contact Form 7
647
+ *
648
  * @param String $message
649
+ *
650
  * @return String $message
651
  */
652
  function iqfix_recaptcha_messages( $messages ) {
653
+
654
  return array_merge( $messages, array(
655
  'iqfix_recaptcha_no_set' => array(
656
  'description' => __( 'This message shows whenever the reCaptcha is completely blocked. Added by plugin: ReCaptcha for Contact Form 7.', 'wpcf7-recaptcha' ),
661
  'default' => __( 'Please verify that you are not a robot.', 'wpcf7-recaptcha' ),
662
  ),
663
  ) );
664
+
665
  }
666
  add_filter( 'wpcf7_messages', 'iqfix_recaptcha_messages' );
wpcf7-recaptcha.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * Plugin Name: ReCaptcha v2 for Contact Form 7
4
  * Description: ReCaptcha v2 Fix for Contact Form 7 5.1 and later.
5
- * Version: 1.3.7
6
  * Author: IQComputing
7
  * Author URI: http://www.iqcomputing.com/
8
  * License: GPL2
@@ -18,18 +18,18 @@ defined( 'ABSPATH' ) or die( 'You cannot be here.' );
18
  */
19
  Class IQFix_WPCF7_Deity {
20
 
21
-
22
  /**
23
  * WPCF7 ReCaptcha Plugin Version
24
- *
25
  * @var String
26
  */
27
- public static $version = '1.3.7';
28
 
29
 
30
  /**
31
  * Class Registration, set up necessities
32
- *
33
  * @return void
34
  */
35
  public static function register() {
@@ -40,34 +40,34 @@ Class IQFix_WPCF7_Deity {
40
  $class->include_files();
41
 
42
  }
43
-
44
-
45
  /**
46
  * Really don't like dynamically assigning URLs by user saved options.
47
  * This method will verify at every stage that the given value is either
48
  * `google.com` or `recaptcha.net`
49
  * Nowhere in between can this value be changed to anything but those two.
50
- *
51
  * @param $expectation
52
- *
53
  * @return $reality
54
  */
55
  public static function verify_recaptcha_source( $expectation = 'google.com' ) {
56
-
57
  $reality = ( in_array( $expectation, array( 'google.com', 'recaptcha.net' ) ) ) ? $expectation : 'google.com';
58
-
59
  return $reality;
60
-
61
  }
62
 
63
-
64
  /**
65
  * Include any necessary files
66
- *
67
  * @return void
68
  */
69
  private function include_files() {
70
-
71
  $selection = WPCF7::get_option( 'iqfix_recaptcha' );
72
  $cf7_version = ( defined( 'WPCF7_VERSION' ) ) ? WPCF7_VERSION : WPCF7::get_option( 'version', '0' );
73
 
@@ -79,65 +79,65 @@ Class IQFix_WPCF7_Deity {
79
  }
80
 
81
  include_once( plugin_dir_path( __FILE__ ) . 'recaptcha-v2.php' );
82
-
83
  if( class_exists( 'Flamingo_Contact' ) ) {
84
  include_once( plugin_dir_path( __FILE__ ) . 'flamingo.php' ); // Flamingo updates
85
  }
86
 
87
  }
88
-
89
-
90
  /**
91
  * Save the reCaptcha settings from our options page
92
  * @see IQFix_WPCF7_Deity::display_recaptcha_version_subpage()
93
- *
94
  * @return Boolean
95
  */
96
  private function save_recaptcha_settings() {
97
-
98
  // Form hasn't POSTed, return early
99
  if( ! isset( $_POST, $_POST['iqfix_recaptcha_version'], $_POST['iqfix_wpcf7_submit'] ) ) {
100
  return false;
101
  }
102
-
103
  // Ensure we have and can verify our nonce. IF not, return early
104
  if( ! ( ! empty( $_POST['iqfix_wpcf7_nonce'] ) && wp_verify_nonce( $_POST['iqfix_wpcf7_nonce'], 'iqfix_wpcf7_vers_select' ) ) ) {
105
  return false;
106
  }
107
-
108
  $selection = intval( $_POST['iqfix_recaptcha_version'] );
109
  $source = ( isset( $_POST, $_POST['iqfix_recaptcha_source'] ) ) ? sanitize_text_field( $_POST['iqfix_recaptcha_source'] ) : 'google.com';
110
  $source = self::verify_recaptcha_source( $source );
111
-
112
  // Save Network Settings
113
  if( is_network_admin() && isset( $_POST['wpcf7_recaptcha_network'] ) ) {
114
-
115
  $sitekey = trim( $_POST['wpcf7_recaptcha_network']['sitekey'] );
116
  $secretkey = trim( $_POST['wpcf7_recaptcha_network']['secretkey'] );
117
-
118
  update_site_option( 'network_iqfix_recaptcha', array(
119
  'sitekey' => $sitekey,
120
  'secret' => $secretkey,
121
  'iqfix_recaptcha' => $selection,
122
  'recaptcha_source' => $source,
123
  ) );
124
-
125
  // Save Regular WPCF7 Settings
126
  } else {
127
-
128
  WPCF7::update_option( 'iqfix_recaptcha', $selection );
129
  WPCF7::update_option( 'iqfix_recaptcha_source', $source );
130
-
131
  }
132
-
133
  return true;
134
-
135
  }
136
 
137
 
138
  /**
139
  * Add any necessary action hooks
140
- *
141
  * @return void
142
  */
143
  private function action_hooks() {
@@ -146,30 +146,30 @@ Class IQFix_WPCF7_Deity {
146
  add_action( 'network_admin_menu', array( $this, 'register_network_submenus' ) );
147
 
148
  }
149
-
150
-
151
  /**
152
  * Add any necessary filter hooks
153
- *
154
  * @return void
155
  */
156
  private function filter_hooks() {
157
-
158
  add_filter( 'option_wpcf7', array( $this, 'network_wpcf7_options' ), 9 );
159
-
160
  }
161
 
162
 
163
  /**
164
  * Register submenus for picking ReCaptcha versions
165
- *
166
  * @return void
167
  */
168
  public function register_submenus() {
169
-
170
  $cf7_admin_cap = ( defined( 'WPCF7_ADMIN_READ_WRITE_CAPABILITY' ) ) ? WPCF7_ADMIN_READ_WRITE_CAPABILITY : 'publish_pages';
171
-
172
- add_submenu_page(
173
  'wpcf7',
174
  esc_html__( 'reCaptcha Version', 'wpcf7-recaptcha' ),
175
  esc_html__( 'reCaptcha Version', 'wpcf7-recaptcha' ),
@@ -179,16 +179,16 @@ Class IQFix_WPCF7_Deity {
179
  );
180
 
181
  }
182
-
183
-
184
  /**
185
  * Register submenus for the Network Admin Panel
186
- *
187
  * @return void
188
  */
189
  public function register_network_submenus() {
190
-
191
- add_submenu_page(
192
  'plugins.php',
193
  esc_html__( 'WPCF7 reCaptcha Settings', 'wpcf7-recaptcha' ),
194
  esc_html__( 'WPCF7 reCaptcha Settings', 'wpcf7-recaptcha' ),
@@ -196,35 +196,35 @@ Class IQFix_WPCF7_Deity {
196
  'recaptcha-version',
197
  array( $this, 'display_recaptcha_version_subpage' )
198
  );
199
-
200
  }
201
 
202
 
203
  /**
204
  * Display reCaptcha version subpage
205
- *
206
  * @return void
207
  */
208
  public function display_recaptcha_version_subpage() {
209
-
210
  $updated = $this->save_recaptcha_settings();
211
  $cf7_version = ( defined( 'WPCF7_VERSION' ) ) ? WPCF7_VERSION : WPCF7::get_option( 'version', '0' );
212
-
213
  // Grab Network Settings
214
  if( is_network_admin() ) {
215
-
216
  $network_options = get_site_option( 'network_iqfix_recaptcha' );
217
  $selection = ( ! empty( $network_options['iqfix_recaptcha'] ) ) ? $network_options['iqfix_recaptcha'] : '';
218
  $source = ( ! empty( $network_options['recaptcha_source'] ) ) ? $network_options['recaptcha_source'] : '';
219
  $sitekey = ( ! empty( $network_options['sitekey'] ) ) ? $network_options['sitekey'] : '';
220
  $secretkey = ( ! empty( $network_options['secret'] ) ) ? $network_options['secret'] : '';
221
-
222
  // Grab Site Settings
223
  } else {
224
-
225
  $selection = WPCF7::get_option( 'iqfix_recaptcha' );
226
  $source = WPCF7::get_option( 'iqfix_recaptcha_source' );
227
-
228
  }
229
 
230
  // Show simple message
@@ -256,7 +256,7 @@ Class IQFix_WPCF7_Deity {
256
  esc_html__( 'Your reCaptcha settings have been updated.', 'wpcf7-recaptcha' )
257
  );
258
  }
259
-
260
  /* translators: %s is a shortcode example wrapped in <code> tags. */
261
  printf( '<p>%1$s</p>',
262
  sprintf( esc_html__( 'Select the version of reCaptcha you would like to use. You will still need to use the %s shortcode tag in your Contact Form 7 forms.', 'wpcf7-recaptcha' ),
@@ -267,33 +267,33 @@ Class IQFix_WPCF7_Deity {
267
 
268
  <form method="post">
269
  <?php wp_nonce_field( 'iqfix_wpcf7_vers_select', 'iqfix_wpcf7_nonce' ); ?>
270
-
271
  <label for="iqfix_recaptcha_version"><strong><?php esc_html_e( 'Select reCaptcha Usage', 'wpcf7-recaptcha' ); ?>:</strong></label><br />
272
  <select id="iqfix_recaptcha_version" name="iqfix_recaptcha_version">
273
  <option value="0"><?php esc_html_e( 'Default Usage', 'wpcf7-recaptcha' ); ?></option>
274
  <option value="2" <?php selected( $selection, 2, true ); ?>><?php esc_html_e( 'reCaptcha Version 2', 'wpcf7-recaptcha' ); ?></option>
275
  </select>
276
-
277
  <?php printf( '<p>%s</p>', esc_html__( 'If you\'re not sure if your country blocks Google then you may leave this as default. Otherwise, if your country blocks google.com requests then please select the suggested recaptcha.net alternative below.', 'wpcf7-recaptcha' ) ); ?>
278
-
279
  <label for="iqfix_recaptcha_source"><strong><?php esc_html_e( 'Select reCaptcha Source', 'wpcf7-recaptcha' ); ?>:</strong></label><br />
280
  <select id="iqfix_recaptcha_source" name="iqfix_recaptcha_source">
281
  <option value="google.com">google.com</option>
282
  <option value="recaptcha.net" <?php selected( $source, 'recaptcha.net', true ); ?>>recaptcha.net</option>
283
  </select>
284
-
285
  <?php if( is_network_admin() ) : ?>
286
-
287
  <hr />
288
  <h2><?php esc_html__( 'Network Wide Settings', 'wpcf7-recaptcha' ); ?></h2>
289
-
290
  <p><strong><?php _e( 'Please read all of the below before committing to these changes.', 'wpcf7-recaptcha' ); ?></strong></p>
291
  <p><?php _e( 'You may set Network wide API keys below. Please ensure that every network site is on the domain list in the Google API Consolefor this API key. ReCaptcha keys can still be set ( or unset ) on a per site basis if necessary.', 'wpcf7-recaptcha' ); ?></p>
292
  <p><?php
293
  /* translators: Care for HTML in string used for emphasis. */
294
  _e( 'Do note that these keys will automatically apply to all network websites upon save <strong>if keys are not detected</strong>. If some network websites use reCaptcha v3 please <u>do not use this option</u> and set it on a per site level.', 'wpcf7-recaptcha' );
295
  ?></p>
296
-
297
  <table class="form-table">
298
  <tbody>
299
  <tr>
@@ -306,15 +306,15 @@ Class IQFix_WPCF7_Deity {
306
  </tr>
307
  </tbody>
308
  </table>
309
-
310
  <?php endif; ?>
311
-
312
  <?php submit_button( esc_html__( 'Submit', 'wpcf7-recaptcha' ), 'submit', 'iqfix_wpcf7_submit' ); ?>
313
  </form>
314
-
315
  <div id="iqFacebook">
316
  <?php
317
- printf( '<a href="%1$s" target="_blank"><img src="%2$s" width="540" height="410" alt="%3$s" /></a>',
318
  esc_url( 'https://www.facebook.com/iqcomputing' ),
319
  plugins_url( 'assets/images/facebook-like.png', __FILE__ ),
320
  /* translators: Image alternative tag. */
@@ -331,24 +331,24 @@ Class IQFix_WPCF7_Deity {
331
  <?php
332
 
333
  }
334
-
335
-
336
  /**
337
  * Filter Hook into WPCF7 get option
338
  * Maybe replace it work a network option
339
- *
340
  * @param Mixed $value
341
  * @param Stirng $option_name
342
- *
343
  * @return Mixed $value
344
  */
345
  public function network_wpcf7_options( $value ) {
346
-
347
  // If we're not on a multisite setup we can skip this filter hook
348
  if( ! is_multisite() || empty( $value ) ) {
349
  return $value;
350
  }
351
-
352
  // Allow sites to be setup regardless of network specifciations
353
  if( is_admin()
354
  && isset( $_GET, $_GET['page'], $_GET['service'], $_GET['action'] )
@@ -358,7 +358,7 @@ Class IQFix_WPCF7_Deity {
358
  ) {
359
  return $value;
360
  }
361
-
362
  // Grab Network Option
363
  $network_wpcf7 = get_site_option( 'network_iqfix_recaptcha' );
364
  $network_wpcf7 = array_filter( (array)$network_wpcf7 );
@@ -369,19 +369,19 @@ Class IQFix_WPCF7_Deity {
369
  $network_wpcf7['sitekey'] => $network_wpcf7['secret'],
370
  );
371
  }
372
-
373
  // Set IQFix reCaptcha
374
  if( ! isset( $value['iqfix_recaptcha'] ) && ! empty( $network_wpcf7['iqfix_recaptcha'] ) ) {
375
  $value['iqfix_recaptcha'] = $network_wpcf7['iqfix_recaptcha'];
376
  }
377
-
378
  // Set IQFix reCaptcha Source
379
  if( ! isset( $value['iqfix_recaptcha_source'] ) && ! empty( $network_wpcf7['recaptcha_source'] ) ) {
380
  $value['iqfix_recaptcha_source'] = $network_wpcf7['recaptcha_source'];
381
  }
382
-
383
  return $value;
384
-
385
  }
386
 
387
 
@@ -390,7 +390,7 @@ Class IQFix_WPCF7_Deity {
390
 
391
  /**
392
  * Initialize Class
393
- *
394
  * @return void
395
  */
396
  function iqfix_wpcf7_deity_init() {
@@ -406,7 +406,7 @@ add_action( 'plugins_loaded', 'iqfix_wpcf7_deity_init' );
406
  /**
407
  * Remove upgrade notice from v2 to v3
408
  * Prevent api keys from being reset.
409
- *
410
  * @return void
411
  */
412
  function iqfix_wpcf7_upgrade_recaptcha_v2_v3_removal() {
2
  /**
3
  * Plugin Name: ReCaptcha v2 for Contact Form 7
4
  * Description: ReCaptcha v2 Fix for Contact Form 7 5.1 and later.
5
+ * Version: 1.3.8
6
  * Author: IQComputing
7
  * Author URI: http://www.iqcomputing.com/
8
  * License: GPL2
18
  */
19
  Class IQFix_WPCF7_Deity {
20
 
21
+
22
  /**
23
  * WPCF7 ReCaptcha Plugin Version
24
+ *
25
  * @var String
26
  */
27
+ public static $version = '1.3.8';
28
 
29
 
30
  /**
31
  * Class Registration, set up necessities
32
+ *
33
  * @return void
34
  */
35
  public static function register() {
40
  $class->include_files();
41
 
42
  }
43
+
44
+
45
  /**
46
  * Really don't like dynamically assigning URLs by user saved options.
47
  * This method will verify at every stage that the given value is either
48
  * `google.com` or `recaptcha.net`
49
  * Nowhere in between can this value be changed to anything but those two.
50
+ *
51
  * @param $expectation
52
+ *
53
  * @return $reality
54
  */
55
  public static function verify_recaptcha_source( $expectation = 'google.com' ) {
56
+
57
  $reality = ( in_array( $expectation, array( 'google.com', 'recaptcha.net' ) ) ) ? $expectation : 'google.com';
58
+
59
  return $reality;
60
+
61
  }
62
 
63
+
64
  /**
65
  * Include any necessary files
66
+ *
67
  * @return void
68
  */
69
  private function include_files() {
70
+
71
  $selection = WPCF7::get_option( 'iqfix_recaptcha' );
72
  $cf7_version = ( defined( 'WPCF7_VERSION' ) ) ? WPCF7_VERSION : WPCF7::get_option( 'version', '0' );
73
 
79
  }
80
 
81
  include_once( plugin_dir_path( __FILE__ ) . 'recaptcha-v2.php' );
82
+
83
  if( class_exists( 'Flamingo_Contact' ) ) {
84
  include_once( plugin_dir_path( __FILE__ ) . 'flamingo.php' ); // Flamingo updates
85
  }
86
 
87
  }
88
+
89
+
90
  /**
91
  * Save the reCaptcha settings from our options page
92
  * @see IQFix_WPCF7_Deity::display_recaptcha_version_subpage()
93
+ *
94
  * @return Boolean
95
  */
96
  private function save_recaptcha_settings() {
97
+
98
  // Form hasn't POSTed, return early
99
  if( ! isset( $_POST, $_POST['iqfix_recaptcha_version'], $_POST['iqfix_wpcf7_submit'] ) ) {
100
  return false;
101
  }
102
+
103
  // Ensure we have and can verify our nonce. IF not, return early
104
  if( ! ( ! empty( $_POST['iqfix_wpcf7_nonce'] ) && wp_verify_nonce( $_POST['iqfix_wpcf7_nonce'], 'iqfix_wpcf7_vers_select' ) ) ) {
105
  return false;
106
  }
107
+
108
  $selection = intval( $_POST['iqfix_recaptcha_version'] );
109
  $source = ( isset( $_POST, $_POST['iqfix_recaptcha_source'] ) ) ? sanitize_text_field( $_POST['iqfix_recaptcha_source'] ) : 'google.com';
110
  $source = self::verify_recaptcha_source( $source );
111
+
112
  // Save Network Settings
113
  if( is_network_admin() && isset( $_POST['wpcf7_recaptcha_network'] ) ) {
114
+
115
  $sitekey = trim( $_POST['wpcf7_recaptcha_network']['sitekey'] );
116
  $secretkey = trim( $_POST['wpcf7_recaptcha_network']['secretkey'] );
117
+
118
  update_site_option( 'network_iqfix_recaptcha', array(
119
  'sitekey' => $sitekey,
120
  'secret' => $secretkey,
121
  'iqfix_recaptcha' => $selection,
122
  'recaptcha_source' => $source,
123
  ) );
124
+
125
  // Save Regular WPCF7 Settings
126
  } else {
127
+
128
  WPCF7::update_option( 'iqfix_recaptcha', $selection );
129
  WPCF7::update_option( 'iqfix_recaptcha_source', $source );
130
+
131
  }
132
+
133
  return true;
134
+
135
  }
136
 
137
 
138
  /**
139
  * Add any necessary action hooks
140
+ *
141
  * @return void
142
  */
143
  private function action_hooks() {
146
  add_action( 'network_admin_menu', array( $this, 'register_network_submenus' ) );
147
 
148
  }
149
+
150
+
151
  /**
152
  * Add any necessary filter hooks
153
+ *
154
  * @return void
155
  */
156
  private function filter_hooks() {
157
+
158
  add_filter( 'option_wpcf7', array( $this, 'network_wpcf7_options' ), 9 );
159
+
160
  }
161
 
162
 
163
  /**
164
  * Register submenus for picking ReCaptcha versions
165
+ *
166
  * @return void
167
  */
168
  public function register_submenus() {
169
+
170
  $cf7_admin_cap = ( defined( 'WPCF7_ADMIN_READ_WRITE_CAPABILITY' ) ) ? WPCF7_ADMIN_READ_WRITE_CAPABILITY : 'publish_pages';
171
+
172
+ add_submenu_page(
173
  'wpcf7',
174
  esc_html__( 'reCaptcha Version', 'wpcf7-recaptcha' ),
175
  esc_html__( 'reCaptcha Version', 'wpcf7-recaptcha' ),
179
  );
180
 
181
  }
182
+
183
+
184
  /**
185
  * Register submenus for the Network Admin Panel
186
+ *
187
  * @return void
188
  */
189
  public function register_network_submenus() {
190
+
191
+ add_submenu_page(
192
  'plugins.php',
193
  esc_html__( 'WPCF7 reCaptcha Settings', 'wpcf7-recaptcha' ),
194
  esc_html__( 'WPCF7 reCaptcha Settings', 'wpcf7-recaptcha' ),
196
  'recaptcha-version',
197
  array( $this, 'display_recaptcha_version_subpage' )
198
  );
199
+
200
  }
201
 
202
 
203
  /**
204
  * Display reCaptcha version subpage
205
+ *
206
  * @return void
207
  */
208
  public function display_recaptcha_version_subpage() {
209
+
210
  $updated = $this->save_recaptcha_settings();
211
  $cf7_version = ( defined( 'WPCF7_VERSION' ) ) ? WPCF7_VERSION : WPCF7::get_option( 'version', '0' );
212
+
213
  // Grab Network Settings
214
  if( is_network_admin() ) {
215
+
216
  $network_options = get_site_option( 'network_iqfix_recaptcha' );
217
  $selection = ( ! empty( $network_options['iqfix_recaptcha'] ) ) ? $network_options['iqfix_recaptcha'] : '';
218
  $source = ( ! empty( $network_options['recaptcha_source'] ) ) ? $network_options['recaptcha_source'] : '';
219
  $sitekey = ( ! empty( $network_options['sitekey'] ) ) ? $network_options['sitekey'] : '';
220
  $secretkey = ( ! empty( $network_options['secret'] ) ) ? $network_options['secret'] : '';
221
+
222
  // Grab Site Settings
223
  } else {
224
+
225
  $selection = WPCF7::get_option( 'iqfix_recaptcha' );
226
  $source = WPCF7::get_option( 'iqfix_recaptcha_source' );
227
+
228
  }
229
 
230
  // Show simple message
256
  esc_html__( 'Your reCaptcha settings have been updated.', 'wpcf7-recaptcha' )
257
  );
258
  }
259
+
260
  /* translators: %s is a shortcode example wrapped in <code> tags. */
261
  printf( '<p>%1$s</p>',
262
  sprintf( esc_html__( 'Select the version of reCaptcha you would like to use. You will still need to use the %s shortcode tag in your Contact Form 7 forms.', 'wpcf7-recaptcha' ),
267
 
268
  <form method="post">
269
  <?php wp_nonce_field( 'iqfix_wpcf7_vers_select', 'iqfix_wpcf7_nonce' ); ?>
270
+
271
  <label for="iqfix_recaptcha_version"><strong><?php esc_html_e( 'Select reCaptcha Usage', 'wpcf7-recaptcha' ); ?>:</strong></label><br />
272
  <select id="iqfix_recaptcha_version" name="iqfix_recaptcha_version">
273
  <option value="0"><?php esc_html_e( 'Default Usage', 'wpcf7-recaptcha' ); ?></option>
274
  <option value="2" <?php selected( $selection, 2, true ); ?>><?php esc_html_e( 'reCaptcha Version 2', 'wpcf7-recaptcha' ); ?></option>
275
  </select>
276
+
277
  <?php printf( '<p>%s</p>', esc_html__( 'If you\'re not sure if your country blocks Google then you may leave this as default. Otherwise, if your country blocks google.com requests then please select the suggested recaptcha.net alternative below.', 'wpcf7-recaptcha' ) ); ?>
278
+
279
  <label for="iqfix_recaptcha_source"><strong><?php esc_html_e( 'Select reCaptcha Source', 'wpcf7-recaptcha' ); ?>:</strong></label><br />
280
  <select id="iqfix_recaptcha_source" name="iqfix_recaptcha_source">
281
  <option value="google.com">google.com</option>
282
  <option value="recaptcha.net" <?php selected( $source, 'recaptcha.net', true ); ?>>recaptcha.net</option>
283
  </select>
284
+
285
  <?php if( is_network_admin() ) : ?>
286
+
287
  <hr />
288
  <h2><?php esc_html__( 'Network Wide Settings', 'wpcf7-recaptcha' ); ?></h2>
289
+
290
  <p><strong><?php _e( 'Please read all of the below before committing to these changes.', 'wpcf7-recaptcha' ); ?></strong></p>
291
  <p><?php _e( 'You may set Network wide API keys below. Please ensure that every network site is on the domain list in the Google API Consolefor this API key. ReCaptcha keys can still be set ( or unset ) on a per site basis if necessary.', 'wpcf7-recaptcha' ); ?></p>
292
  <p><?php
293
  /* translators: Care for HTML in string used for emphasis. */
294
  _e( 'Do note that these keys will automatically apply to all network websites upon save <strong>if keys are not detected</strong>. If some network websites use reCaptcha v3 please <u>do not use this option</u> and set it on a per site level.', 'wpcf7-recaptcha' );
295
  ?></p>
296
+
297
  <table class="form-table">
298
  <tbody>
299
  <tr>
306
  </tr>
307
  </tbody>
308
  </table>
309
+
310
  <?php endif; ?>
311
+
312
  <?php submit_button( esc_html__( 'Submit', 'wpcf7-recaptcha' ), 'submit', 'iqfix_wpcf7_submit' ); ?>
313
  </form>
314
+
315
  <div id="iqFacebook">
316
  <?php
317
+ printf( '<a href="%1$s" target="_blank"><img src="%2$s" width="540" height="410" alt="%3$s" /></a>',
318
  esc_url( 'https://www.facebook.com/iqcomputing' ),
319
  plugins_url( 'assets/images/facebook-like.png', __FILE__ ),
320
  /* translators: Image alternative tag. */
331
  <?php
332
 
333
  }
334
+
335
+
336
  /**
337
  * Filter Hook into WPCF7 get option
338
  * Maybe replace it work a network option
339
+ *
340
  * @param Mixed $value
341
  * @param Stirng $option_name
342
+ *
343
  * @return Mixed $value
344
  */
345
  public function network_wpcf7_options( $value ) {
346
+
347
  // If we're not on a multisite setup we can skip this filter hook
348
  if( ! is_multisite() || empty( $value ) ) {
349
  return $value;
350
  }
351
+
352
  // Allow sites to be setup regardless of network specifciations
353
  if( is_admin()
354
  && isset( $_GET, $_GET['page'], $_GET['service'], $_GET['action'] )
358
  ) {
359
  return $value;
360
  }
361
+
362
  // Grab Network Option
363
  $network_wpcf7 = get_site_option( 'network_iqfix_recaptcha' );
364
  $network_wpcf7 = array_filter( (array)$network_wpcf7 );
369
  $network_wpcf7['sitekey'] => $network_wpcf7['secret'],
370
  );
371
  }
372
+
373
  // Set IQFix reCaptcha
374
  if( ! isset( $value['iqfix_recaptcha'] ) && ! empty( $network_wpcf7['iqfix_recaptcha'] ) ) {
375
  $value['iqfix_recaptcha'] = $network_wpcf7['iqfix_recaptcha'];
376
  }
377
+
378
  // Set IQFix reCaptcha Source
379
  if( ! isset( $value['iqfix_recaptcha_source'] ) && ! empty( $network_wpcf7['recaptcha_source'] ) ) {
380
  $value['iqfix_recaptcha_source'] = $network_wpcf7['recaptcha_source'];
381
  }
382
+
383
  return $value;
384
+
385
  }
386
 
387
 
390
 
391
  /**
392
  * Initialize Class
393
+ *
394
  * @return void
395
  */
396
  function iqfix_wpcf7_deity_init() {
406
  /**
407
  * Remove upgrade notice from v2 to v3
408
  * Prevent api keys from being reset.
409
+ *
410
  * @return void
411
  */
412
  function iqfix_wpcf7_upgrade_recaptcha_v2_v3_removal() {