Contact Form 7 – reCaptcha v2 - Version 1.1.9

Version Description

(2019-05-14) = * Added selectable option to choose which website to pull reCaptcha resources from (google.com | recaptcha.net) Thanks @scits! * Added and modified some class methods. See extended changelog for further details. * Modified noscript reCaptcha to look and function better "default". Styling left to theme authors and developers.

Download this release

Release Info

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

Code changes from version 1.1.8 to 1.1.9

Files changed (5) hide show
  1. changelog.txt +109 -93
  2. flamingo.php +78 -78
  3. readme.txt +72 -72
  4. recaptcha-v2.php +637 -633
  5. wpcf7-recaptcha.php +406 -344
changelog.txt CHANGED
@@ -1,94 +1,110 @@
1
- == Changelog Archive ==
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.1.8 =
6
-
7
- Release Date: April 26, 2019
8
-
9
- * Overview
10
- * Contact Forms could still be submitted to Flamingo even when the reCaptcha was not being clicked or interacted with.
11
- 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.]
12
- This should prevent the multitude of spam posts being saved in Flamingo.
13
- Thanks to @scits to bringing this issue to our attention!
14
-
15
- * Files Added
16
- * wpcf7-recaptcha/flamingo.php
17
- * Only gets included and processed whenever Flamingo is detected to be installed and active.
18
-
19
- = 1.1.6 =
20
-
21
- Release Date: April 02, 2019
22
-
23
- * Overview
24
- * Forum user @aldebaran57 points out how to add localization to the reCaptcha API which was tested and integrated.
25
- * https://wordpress.org/support/topic/force-language-of-widget-so-it-reacts-to-language-switcher-on-multi-lang-sites/
26
-
27
- = 1.1.5 =
28
-
29
- Release Date: February 25, 2019
30
-
31
- * Overview
32
- * Added plugin to github and link to github on description page.
33
- * Ran into issue committing v1.1.4 which caused json checksums to not reflect some changes made. Thank @willpresleyev for pointing this out!
34
- * https://wordpress.org/support/topic/plugin-checksum-json-needs-updated/
35
-
36
- = 1.1.4 =
37
-
38
- Relase Date: February 22, 2019
39
-
40
- * General
41
- * Ensured WordPress 5.1 compatibility
42
- * We need your help translating this plugin! Please contribute at: https://translate.wordpress.org/projects/wp-plugins/wpcf7-recaptcha
43
-
44
- * Multisite
45
- * Multisite - Network Admins will notice a new menu item under plugins labelled "WPCF7 reCaptcha Settings"
46
- * 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.
47
- * 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.
48
-
49
- * Cleanup
50
- * Removed languages folder to avoid confusion with glotpress.
51
-
52
- = 1.1.3 =
53
-
54
- Relase Date: February 06, 2019
55
-
56
- * Overview
57
- * An attempt to make translations easier and better overall.
58
- * Combined a few redundant translation functions into a single translation function.
59
- * Changed instances of reCaptcha that were all caps and not consistent.
60
- * Added a margin-bottom: 0 style to the reCaptcha iframe in an attempt to prevent CSS overlapping using the `add_action( 'wp_enqueue_scripts', 'iqfix_recaptcha_inline_css' )` hook.
61
-
62
-
63
- = 1.1.2 =
64
-
65
- Relase Date: January 14, 2019
66
-
67
- * Overview
68
- * Replaces old Text Domain 'iqc' with new Text Domain 'wpcf7-recaptcha' to match the plugin slug. This fix should help translations.
69
- * Added Portable Object Template (.pot) file to the /languages/ folder to help translators.
70
- * Added call to action on the settings page which encourages users to like IQComputing on Facebook to receive the latest news and updates regarding this plugin and future plugins we develop.
71
-
72
- = 1.1.1 =
73
-
74
- Release Date: January 07, 2019
75
-
76
- * Overview
77
- * Adds message whenever user forgets to click reCaptcha checkbox.
78
-
79
- = 1.1.0 =
80
-
81
- Release Date: December 28, 2018
82
-
83
- * Overview
84
- * Prevents Contact Form 7 from removing reCaptcha keys upon update.
85
- * Removes Contact Form 7 reCaptcha upgrade notice.
86
-
87
- = 1.0 =
88
-
89
- Release Date: December 28, 2018
90
-
91
- * Overview
92
- * Initial release of plugin.
93
- * Contact Form 7 5.0.5 reCaptcha functionality copied over.
94
* Created subpage under "Contact" named "reCaptcha Version" to be used as a settings page.
1
+ == Changelog Archive ==
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.1.9 =
6
+
7
+ Release Date: May 14, 2019
8
+
9
+ * Overview
10
+ * Added option to allow user to choose which website to pull the reCaptcha resources from.
11
+ The choices are google.com or recaptcha.net. These are for situations or countries that specifically block Google and prevent our reCaptcha from appearing.
12
+
13
+ * Code Changes
14
+ * Updated recaptcha-v2.php file to switch out the recaptcha source URLs.
15
+ * Updated reCaptcha noscript to look nicer and function better.
16
+ * We've left styling the noscript reCaptcha up to themes and developers.
17
+ * Added private method to handle saving settings: IQFix_WPCF7_Deity::save_recaptcha_settings()
18
+ * Added public static method to ensure my own sanity: IQFix_WPCF7_Deity::verify_recaptcha_source()
19
+ * Makes sure that at every point our source is either google.com or recaptcha.net
20
+
21
+ = 1.1.8 =
22
+
23
+ Release Date: April 26, 2019
24
+
25
+ * Overview
26
+ * Contact Forms could still be submitted to Flamingo even when the reCaptcha was not being clicked or interacted with.
27
+ 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.]
28
+ This should prevent the multitude of spam posts being saved in Flamingo.
29
+ Thanks to @scits to bringing this issue to our attention!
30
+
31
+ * Files Added
32
+ * wpcf7-recaptcha/flamingo.php
33
+ * Only gets included and processed whenever Flamingo is detected to be installed and active.
34
+
35
+ = 1.1.6 =
36
+
37
+ Release Date: April 02, 2019
38
+
39
+ * Overview
40
+ * Forum user @aldebaran57 points out how to add localization to the reCaptcha API which was tested and integrated.
41
+ * https://wordpress.org/support/topic/force-language-of-widget-so-it-reacts-to-language-switcher-on-multi-lang-sites/
42
+
43
+ = 1.1.5 =
44
+
45
+ Release Date: February 25, 2019
46
+
47
+ * Overview
48
+ * Added plugin to github and link to github on description page.
49
+ * Ran into issue committing v1.1.4 which caused json checksums to not reflect some changes made. Thank @willpresleyev for pointing this out!
50
+ * https://wordpress.org/support/topic/plugin-checksum-json-needs-updated/
51
+
52
+ = 1.1.4 =
53
+
54
+ Relase Date: February 22, 2019
55
+
56
+ * General
57
+ * Ensured WordPress 5.1 compatibility
58
+ * We need your help translating this plugin! Please contribute at: https://translate.wordpress.org/projects/wp-plugins/wpcf7-recaptcha
59
+
60
+ * Multisite
61
+ * Multisite - Network Admins will notice a new menu item under plugins labelled "WPCF7 reCaptcha Settings"
62
+ * 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.
63
+ * 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.
64
+
65
+ * Cleanup
66
+ * Removed languages folder to avoid confusion with glotpress.
67
+
68
+ = 1.1.3 =
69
+
70
+ Relase Date: February 06, 2019
71
+
72
+ * Overview
73
+ * An attempt to make translations easier and better overall.
74
+ * Combined a few redundant translation functions into a single translation function.
75
+ * Changed instances of reCaptcha that were all caps and not consistent.
76
+ * Added a margin-bottom: 0 style to the reCaptcha iframe in an attempt to prevent CSS overlapping using the `add_action( 'wp_enqueue_scripts', 'iqfix_recaptcha_inline_css' )` hook.
77
+
78
+
79
+ = 1.1.2 =
80
+
81
+ Relase Date: January 14, 2019
82
+
83
+ * Overview
84
+ * Replaces old Text Domain 'iqc' with new Text Domain 'wpcf7-recaptcha' to match the plugin slug. This fix should help translations.
85
+ * Added Portable Object Template (.pot) file to the /languages/ folder to help translators.
86
+ * Added call to action on the settings page which encourages users to like IQComputing on Facebook to receive the latest news and updates regarding this plugin and future plugins we develop.
87
+
88
+ = 1.1.1 =
89
+
90
+ Release Date: January 07, 2019
91
+
92
+ * Overview
93
+ * Adds message whenever user forgets to click reCaptcha checkbox.
94
+
95
+ = 1.1.0 =
96
+
97
+ Release Date: December 28, 2018
98
+
99
+ * Overview
100
+ * Prevents Contact Form 7 from removing reCaptcha keys upon update.
101
+ * Removes Contact Form 7 reCaptcha upgrade notice.
102
+
103
+ = 1.0 =
104
+
105
+ Release Date: December 28, 2018
106
+
107
+ * Overview
108
+ * Initial release of plugin.
109
+ * Contact Form 7 5.0.5 reCaptcha functionality copied over.
110
* Created subpage under "Contact" named "reCaptcha Version" to be used as a settings page.
flamingo.php CHANGED
@@ -1,79 +1,79 @@
1
- <?php
2
- /**
3
- * This file works with reCaptcha v2 to prevent Spam submissions from being stored.
4
- *
5
- * Originally, submitting a form without interacting with the reCaptcha box would submit to Contact Form 7
6
- * And end up being labelled as "Spam" by Flamingo.
7
- * This update will only check a submission _after_ reCaptcha has been compelted.
8
- */
9
-
10
-
11
- defined( 'ABSPATH' ) or die( "Hey, you're not a flamingo! Goodbye." );
12
-
13
-
14
- Class IQFix_Flamingo {
15
-
16
-
17
- /**
18
- * Class Registration, set up necessities
19
- *
20
- * @return void
21
- */
22
- public static function register() {
23
-
24
- $selection = WPCF7::get_option( 'iqfix_recaptcha' );
25
-
26
- if( empty( $selection ) ) {
27
- return;
28
- }
29
-
30
- $class = new self();
31
- $class->action_hooks();
32
-
33
- }
34
-
35
-
36
- /**
37
- * Add any necessary action hooks
38
- *
39
- * @return void
40
- */
41
- private function action_hooks() {
42
-
43
- // See: contact-form-7/modules/flamingo.php
44
- // Run before priority 10 to shortcircut Flamingo hook
45
- add_action( 'wpcf7_submit', array( $this, 'flamingo_acceptable_mail' ), 9, 2 );
46
-
47
- }
48
-
49
-
50
- /**
51
- * Remove the flamingo submission hook if our form has a ReCaptcha and an empty ReCaptcha response
52
- * @see contact-form-7/modules/flamingo.php LN7
53
- *
54
- * @param Array $types
55
- *
56
- * @return Array $types
57
- */
58
- public function flamingo_acceptable_mail( $wpcform, $result ) {
59
-
60
- $recaptcha = $wpcform->scan_form_tags( array( 'type' => 'recaptcha' ) );
61
-
62
- if( ! empty( $recaptcha ) ) {
63
-
64
- if( empty( $_POST['g-recaptcha-response'] ) ) {
65
-
66
- // Remove the Flamingo hook, don't run it until we have a successful recaptcha
67
- remove_action( 'wpcf7_submit', 'wpcf7_flamingo_submit', 10 );
68
-
69
- }
70
-
71
- }
72
-
73
- }
74
-
75
-
76
- } // END IQFix_Flamingo Class
77
-
78
-
79
IQFix_Flamingo::register();
1
+ <?php
2
+ /**
3
+ * This file works with reCaptcha v2 to prevent Spam submissions from being stored.
4
+ *
5
+ * Originally, submitting a form without interacting with the reCaptcha box would submit to Contact Form 7
6
+ * And end up being labelled as "Spam" by Flamingo.
7
+ * This update will only check a submission _after_ reCaptcha has been compelted.
8
+ */
9
+
10
+
11
+ defined( 'ABSPATH' ) or die( "Hey, you're not a flamingo! Goodbye." );
12
+
13
+
14
+ Class IQFix_Flamingo {
15
+
16
+
17
+ /**
18
+ * Class Registration, set up necessities
19
+ *
20
+ * @return void
21
+ */
22
+ public static function register() {
23
+
24
+ $selection = WPCF7::get_option( 'iqfix_recaptcha' );
25
+
26
+ if( empty( $selection ) ) {
27
+ return;
28
+ }
29
+
30
+ $class = new self();
31
+ $class->action_hooks();
32
+
33
+ }
34
+
35
+
36
+ /**
37
+ * Add any necessary action hooks
38
+ *
39
+ * @return void
40
+ */
41
+ private function action_hooks() {
42
+
43
+ // See: contact-form-7/modules/flamingo.php
44
+ // Run before priority 10 to shortcircut Flamingo hook
45
+ add_action( 'wpcf7_submit', array( $this, 'flamingo_acceptable_mail' ), 9, 2 );
46
+
47
+ }
48
+
49
+
50
+ /**
51
+ * Remove the flamingo submission hook if our form has a ReCaptcha and an empty ReCaptcha response
52
+ * @see contact-form-7/modules/flamingo.php LN7
53
+ *
54
+ * @param Array $types
55
+ *
56
+ * @return Array $types
57
+ */
58
+ public function flamingo_acceptable_mail( $wpcform, $result ) {
59
+
60
+ $recaptcha = $wpcform->scan_form_tags( array( 'type' => 'recaptcha' ) );
61
+
62
+ if( ! empty( $recaptcha ) ) {
63
+
64
+ if( empty( $_POST['g-recaptcha-response'] ) ) {
65
+
66
+ // Remove the Flamingo hook, don't run it until we have a successful recaptcha
67
+ remove_action( 'wpcf7_submit', 'wpcf7_flamingo_submit', 10 );
68
+
69
+ }
70
+
71
+ }
72
+
73
+ }
74
+
75
+
76
+ } // END IQFix_Flamingo Class
77
+
78
+
79
IQFix_Flamingo::register();
readme.txt CHANGED
@@ -1,72 +1,72 @@
1
- === Contact Form 7 - reCaptcha v2 ===
2
- Contributors: iqcomputing
3
- Tags: contact-form-7, contact-form-7-recaptcha, recaptcha, spam
4
- Requires at least: 4.9
5
- Tested up to: 5.1
6
- Stable tag: 1.1.8
7
- License: GPLv2 or later
8
- License URI: https://www.gnu.org/licenses/gpl-2.0.html
9
-
10
- Adds reCaptcha v2 from Contact Form 7 5.0.5 that was dropped on Contact Form 7 5.1
11
-
12
- == Description ==
13
-
14
- Contact Form 7 v5.1 dropped support for reCaptcha v2 along with the `[recaptcha]` tag December 2018. This plugin brings that functionality back from Contact Form 7 5.0.5 and re-adds the `[recaptcha]` tag.
15
-
16
- If this plugin is installed before updating Contact Form 7 from v5.0.5 to v5.1.1 then it will carry over your old API keys. At that point you will just need to head to this plugins settings page to tell the website to use reCaptcha v2.
17
-
18
- Once installed and configured it should be the same reCaptcha functionality you are used to in previous versions of Contact Form 7.
19
-
20
- == IQComputing ==
21
-
22
- * Like us on [Facebook](https://www.facebook.com/iqcomputing/ "IQComputing on Facebook")
23
- * Follow us on [Twitter](https://twitter.com/iqcomputing/ "IQComputing on Twitter")
24
- * Fork on [Github](https://github.com/IQComputing/wpcf7-recaptcha "IQComputing on Github")
25
-
26
- == Installation ==
27
-
28
- [Contact Form 7](https://wordpress.org/plugins/contact-form-7/ "Contact Form 7 plugin page") is required to work with this plugin.
29
-
30
- 1. Install this (Contact Form 7 - reCaptcha v2) plugin
31
- 1. Update Contact Form 7 to the latest version
32
- 1. Re-add the reCaptcha version 2 API keys (if no keys are currently set). For more information you may read the [Contact Form 7 documentation](https://contactform7.com/recaptcha-v2/ "Contact Form 7 reCaptcha(v2)")
33
- 1. Using the left-hand admin navigation in the Contact Form 7 subpages click "reCaptcha Version" (Contact -> reCaptcha Version)
34
- 1. Once on the "Contact Form 7 - reCaptcha v2" settings page, select from the select list "reCaptcha Version 2" and click "save"
35
-
36
- Once the version 2 API keys are set, the version 2 has been selected in the plugin settings, all [recaptcha] tags will be replaced with the expected Google reCaptcha on all forms.
37
-
38
- == Frequently Asked Questions ==
39
-
40
- = Will this plugin work with Version 3 keys? =
41
-
42
- No and yes. Google reCaptcha has specific keys for each API. If you are doing an upgrade from a previous version of Contact Form 7 to the current version you will need to re-add the Version 2 API keys using the traditional method. That being said you can set the plugin usage to default and it will use the inherit Contact Form 7 reCaptcha Version 3 API.
43
-
44
- = Where do I add my Version 2 keys? =
45
-
46
- Under Contact -> Integration you can see a "reCAPTCHA" service box where you may either "Setup Integration" following instructions from the [Contact Form 7 documentation](https://contactform7.com/recaptcha-v2/ "Contact Form 7 reCaptcha(v2)"). If you already have keys set you will need to click the "Remove Keys" button and re-add them following the [Contact Form 7 documentation](https://contactform7.com/recaptcha-v2/ "Contact Form 7 reCaptcha(v2)").
47
-
48
- = I've added the Version 2 keys but nothing has changed =
49
-
50
- If you have added the Version 2 keys and you still do not see the reCaptcha show up on your forms please check the following:
51
-
52
- 1. In WordPress admin, under Contact -> reCaptcha Version please ensure that you have "reCaptcha Version 2" selected and saved.
53
- 1. On your contact forms please ensure that you have the [recaptcha] tag somewhere in the form.
54
-
55
- Should the above be correct, at this point it's time to open a support thread for us to look into the issue further.
56
-
57
- == Screenshots ==
58
-
59
- 1. Settings page
60
-
61
- == Changelog ==
62
-
63
- = 1.1.8 (2019-04-26) =
64
- * Fixed WPCF7+Flamingo bug which saved un-verified submissions to spam in Flamingo. Thanks @scits!
65
-
66
- = 1.1.6 (2019-04-02) =
67
- * Added localization to reCaptcha API box which translates related text. Thanks @aldebaran57!
68
-
69
- = 1.1.5 (2019-02-25) =
70
-
71
- * Added link to github in description
72
- * Updated version number to fix json checksum (Thanks @willpresleyev)!
1
+ === Contact Form 7 - reCaptcha v2 ===
2
+ Contributors: iqcomputing
3
+ Tags: contact-form-7, contact-form-7-recaptcha, recaptcha, spam
4
+ Requires at least: 4.9
5
+ Tested up to: 5.2
6
+ Stable tag: 1.1.9
7
+ License: GPLv2 or later
8
+ License URI: https://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ Adds reCaptcha v2 from Contact Form 7 5.0.5 that was dropped on Contact Form 7 5.1
11
+
12
+ == Description ==
13
+
14
+ Contact Form 7 v5.1 dropped support for reCaptcha v2 along with the `[recaptcha]` tag December 2018. This plugin brings that functionality back from Contact Form 7 5.0.5 and re-adds the `[recaptcha]` tag.
15
+
16
+ If this plugin is installed before updating Contact Form 7 from v5.0.5 to v5.1.1 then it will carry over your old API keys. At that point you will just need to head to this plugins settings page to tell the website to use reCaptcha v2.
17
+
18
+ Once installed and configured it should be the same reCaptcha functionality you are used to in previous versions of Contact Form 7.
19
+
20
+ == IQComputing ==
21
+
22
+ * Like us on [Facebook](https://www.facebook.com/iqcomputing/ "IQComputing on Facebook")
23
+ * Follow us on [Twitter](https://twitter.com/iqcomputing/ "IQComputing on Twitter")
24
+ * Fork on [Github](https://github.com/IQComputing/wpcf7-recaptcha "IQComputing on Github")
25
+
26
+ == Installation ==
27
+
28
+ [Contact Form 7](https://wordpress.org/plugins/contact-form-7/ "Contact Form 7 plugin page") is required to work with this plugin.
29
+
30
+ 1. Install this (Contact Form 7 - reCaptcha v2) plugin
31
+ 1. Update Contact Form 7 to the latest version
32
+ 1. Re-add the reCaptcha version 2 API keys (if no keys are currently set). For more information you may read [How to Generate Google reCAPTCHA v2 Keys](https://www.iqcomputing.com/support/articles/generate-google-recaptcha-v2-keys/) by IQComputing and [Contact Form 7 documentation](https://contactform7.com/recaptcha-v2/ "Contact Form 7 reCaptcha(v2)")
33
+ 1. Using the left-hand admin navigation in the Contact Form 7 subpages click "reCaptcha Version" (Contact -> reCaptcha Version)
34
+ 1. Once on the "Contact Form 7 - reCaptcha v2" settings page, select from the select list "reCaptcha Version 2" and click "save"
35
+
36
+ Once the version 2 API keys are set, the version 2 has been selected in the plugin settings, all [recaptcha] tags will be replaced with the expected Google reCaptcha on all forms.
37
+
38
+ == Frequently Asked Questions ==
39
+
40
+ = Will this plugin work with Version 3 keys? =
41
+
42
+ No and yes. Google reCaptcha has specific keys for each API. If you are doing an upgrade from a previous version of Contact Form 7 to the current version you will need to re-add the Version 2 API keys using the traditional method. That being said you can set the plugin usage to default and it will use the inherit Contact Form 7 reCaptcha Version 3 API.
43
+
44
+ = Where do I add my Version 2 keys? =
45
+
46
+ Under Contact -> Integration you can see a "reCAPTCHA" service box where you may either "Setup Integration" following instructions from the [Contact Form 7 documentation](https://contactform7.com/recaptcha-v2/ "Contact Form 7 reCaptcha(v2)"). If you already have keys set you will need to click the "Remove Keys" button and re-add them following the [Contact Form 7 documentation](https://contactform7.com/recaptcha-v2/ "Contact Form 7 reCaptcha(v2)").
47
+
48
+ = I've added the Version 2 keys but nothing has changed =
49
+
50
+ If you have added the Version 2 keys and you still do not see the reCaptcha show up on your forms please check the following:
51
+
52
+ 1. In WordPress admin, under Contact -> reCaptcha Version please ensure that you have "reCaptcha Version 2" selected and saved.
53
+ 1. On your contact forms please ensure that you have the [recaptcha] tag somewhere in the form.
54
+
55
+ Should the above be correct, at this point it's time to open a support thread for us to look into the issue further.
56
+
57
+ == Screenshots ==
58
+
59
+ 1. Settings page
60
+
61
+ == Changelog ==
62
+
63
+ = 1.1.9 (2019-05-14) =
64
+ * Added selectable option to choose which website to pull reCaptcha resources from (google.com | recaptcha.net) Thanks @scits!
65
+ * Added and modified some class methods. See extended changelog for further details.
66
+ * Modified noscript reCaptcha to look and function better "default". Styling left to theme authors and developers.
67
+
68
+ = 1.1.8 (2019-04-26) =
69
+ * Fixed WPCF7+Flamingo bug which saved un-verified submissions to spam in Flamingo. Thanks @scits!
70
+
71
+ = 1.1.6 (2019-04-02) =
72
+ * Added localization to reCaptcha API box which translates related text. Thanks @aldebaran57!
recaptcha-v2.php CHANGED
@@ -1,634 +1,638 @@
1
- <?php
2
- /**
3
- * Replace reCaptcha v3 with ReCaptcha v2
4
- * Use [recaptcha] shortcode when possible
5
- */
6
-
7
-
8
- defined( 'ABSPATH' ) or die( 'You cannot be here.' );
9
-
10
-
11
- /**
12
- * Remove old hooks and add new hook callbacks
13
- *
14
- * @return void
15
- */
16
- function iqfix_wpcf7_manage_hooks() {
17
-
18
- // reCaptcha Verification
19
- remove_filter( 'wpcf7_spam', 'wpcf7_recaptcha_verify_response', 9 );
20
- add_filter( 'wpcf7_spam', 'iqfix_wpcf7_recaptcha_check_with_google', 9 );
21
-
22
- // reCaptcha Enqueues
23
- remove_action( 'wp_enqueue_scripts', 'wpcf7_recaptcha_enqueue_scripts', 10 );
24
- add_action( 'wp_enqueue_scripts', 'iqfix_wpcf7_recaptcha_enqueue_scripts', 10 );
25
-
26
- // reCaptcha Footer Javascript
27
- remove_action( 'wp_footer', 'wpcf7_recaptcha_onload_script', 40 );
28
- add_action( 'wp_footer', 'iqfix_wpcf7_recaptcha_callback_script', 40 );
29
-
30
- }
31
- add_action( 'setup_theme', 'iqfix_wpcf7_manage_hooks' );
32
-
33
-
34
- /**
35
- * Remove current [recaptcha] tag and replace it with old reCaptcha tag
36
- *
37
- * @return void
38
- */
39
- function iqfix_wpcf7_add_recaptcha_tag() {
40
-
41
- wpcf7_remove_form_tag( 'recaptcha' );
42
- wpcf7_add_form_tag(
43
- 'recaptcha',
44
- 'iqfix_wpcf7_recaptcha_form_tag_handler',
45
- array( 'display-block' => true )
46
- );
47
-
48
- }
49
- add_action( 'wpcf7_init', 'iqfix_wpcf7_add_recaptcha_tag', 20 );
50
-
51
-
52
- /**
53
- * Register the Google reCaptcha API script
54
- *
55
- * The following function was not written by IQComputing and is included in
56
- * Contact Form 7 v5.0.5 by Takayuki Miyoshi
57
- * contact-form-7\modules\recaptcha.php LN241
58
- *
59
- * @return void
60
- */
61
- function iqfix_wpcf7_recaptcha_enqueue_scripts() {
62
-
63
- $url = 'https://www.google.com/recaptcha/api.js';
64
- $url = add_query_arg( array(
65
- 'hl' => esc_attr( get_locale() ), // Lowercase L
66
- 'onload' => 'recaptchaCallback',
67
- 'render' => 'explicit',
68
- ), $url );
69
-
70
- wp_register_script( 'google-recaptcha', $url, array(), '2.0', true );
71
- wp_localize_script( 'google-recaptcha', 'wpcf7iqfix', array(
72
- 'recaptcha_empty' => esc_html__( 'Please verify that you are not a robot.', 'wpcf7-recaptcha' ),
73
- ) );
74
-
75
- }
76
- // See `iqfix_wpcf7_manage_hooks` callback above
77
-
78
-
79
- /**
80
- * reCaptcha Javascript
81
- *
82
- * The following function was not written by IQComputing and is included in
83
- * Contact Form 7 v5.0.5 by Takayuki Miyoshi
84
- * contact-form-7\modules\recaptcha.php LN253
85
- *
86
- * @return void
87
- */
88
- function iqfix_wpcf7_recaptcha_callback_script() {
89
-
90
- if ( ! wp_script_is( 'google-recaptcha', 'enqueued' ) ) {
91
- return;
92
- }
93
-
94
- ?>
95
- <script type="text/javascript">
96
- var recaptchaWidgets = [];
97
- var recaptchaCallback = function() {
98
- var forms = document.getElementsByTagName( 'form' );
99
- var pattern = /(^|\s)g-recaptcha(\s|$)/;
100
-
101
- for ( var i = 0; i < forms.length; i++ ) {
102
- var divs = forms[ i ].getElementsByTagName( 'div' );
103
-
104
- for ( var j = 0; j < divs.length; j++ ) {
105
- var sitekey = divs[ j ].getAttribute( 'data-sitekey' );
106
-
107
- if ( divs[ j ].className && divs[ j ].className.match( pattern ) && sitekey ) {
108
- var params = {
109
- 'sitekey': sitekey,
110
- 'type': divs[ j ].getAttribute( 'data-type' ),
111
- 'size': divs[ j ].getAttribute( 'data-size' ),
112
- 'theme': divs[ j ].getAttribute( 'data-theme' ),
113
- 'badge': divs[ j ].getAttribute( 'data-badge' ),
114
- 'tabindex': divs[ j ].getAttribute( 'data-tabindex' )
115
- };
116
-
117
- var callback = divs[ j ].getAttribute( 'data-callback' );
118
-
119
- if ( callback && 'function' == typeof window[ callback ] ) {
120
- params[ 'callback' ] = window[ callback ];
121
- }
122
-
123
- var expired_callback = divs[ j ].getAttribute( 'data-expired-callback' );
124
-
125
- if ( expired_callback && 'function' == typeof window[ expired_callback ] ) {
126
- params[ 'expired-callback' ] = window[ expired_callback ];
127
- }
128
-
129
- var widget_id = grecaptcha.render( divs[ j ], params );
130
- recaptchaWidgets.push( widget_id );
131
- break;
132
- }
133
- }
134
- }
135
- };
136
-
137
- document.addEventListener( 'wpcf7submit', function( event ) {
138
- switch ( event.detail.status ) {
139
- case 'spam':
140
- case 'mail_sent':
141
- case 'mail_failed':
142
- for ( var i = 0; i < recaptchaWidgets.length; i++ ) {
143
- grecaptcha.reset( recaptchaWidgets[ i ] );
144
- }
145
- }
146
- }, false );
147
-
148
- ( function( $ ) {
149
- $( '.wpcf7' ).on( 'wpcf7:spam', function( e ) {
150
- $( '[name="g-recaptcha-response"]', $( this ) ).each( function() {
151
- if ( '' === $( this ).val() ) {
152
- var $recaptcha = $( this ).closest( '.wpcf7-form-control-wrap' );
153
- wpcf7.notValidTip( $recaptcha, wpcf7iqfix.recaptcha_empty );
154
- }
155
- } );
156
- } );
157
- } )( jQuery );
158
- </script>
159
- <?php
160
-
161
- }
162
- // See `iqfix_wpcf7_manage_hooks` callback above
163
-
164
-
165
- /**
166
- * reCaptcha Callback
167
- *
168
- * The following function was not written by IQComputing and is included in
169
- * Contact Form 7 v5.0.5
170
- * contact-form-7\modules\recaptcha.php LN326
171
- *
172
- * @param WPCF7_FormTag $tag
173
- *
174
- * @return String $html
175
- */
176
- function iqfix_wpcf7_recaptcha_form_tag_handler( $tag ) {
177
-
178
- if ( ! wp_script_is( 'google-recaptcha', 'registered' ) ) {
179
- wpcf7_recaptcha_enqueue_scripts();
180
- }
181
-
182
- wp_enqueue_script( 'google-recaptcha' );
183
-
184
- $atts = array();
185
-
186
- $recaptcha = WPCF7_RECAPTCHA::get_instance();
187
- $atts['data-sitekey'] = $recaptcha->get_sitekey();
188
- $atts['data-type'] = $tag->get_option( 'type', '(audio|image)', true );
189
- $atts['data-size'] = $tag->get_option(
190
- 'size', '(compact|normal|invisible)', true );
191
- $atts['data-theme'] = $tag->get_option( 'theme', '(dark|light)', true );
192
- $atts['data-badge'] = $tag->get_option(
193
- 'badge', '(bottomright|bottomleft|inline)', true );
194
- $atts['data-tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
195
- $atts['data-callback'] = $tag->get_option( 'callback', '', true );
196
- $atts['data-expired-callback'] =
197
- $tag->get_option( 'expired_callback', '', true );
198
-
199
- $atts['class'] = $tag->get_class_option(
200
- wpcf7_form_controls_class( $tag->type, 'g-recaptcha' ) );
201
- $atts['id'] = $tag->get_id_option();
202
-
203
- $html = sprintf( '<div %1$s></div>', wpcf7_format_atts( $atts ) );
204
- $html .= iqfix_wpcf7_recaptcha_noscript(
205
- array( 'sitekey' => $atts['data-sitekey'] ) );
206
- $html = sprintf( '<div class="wpcf7-form-control-wrap">%s</div>', $html );
207
-
208
- return $html;
209
-
210
- }
211
- // See `iqfix_wpcf7_add_recaptcha_tag` callback above.
212
-
213
-
214
- /**
215
- * Display reCaptcha noscript tag should javacript be disabled.
216
- *
217
- * The following function was not written by IQComputing and is included in
218
- * Contact Form 7 v5.0.5 by Takayuki Miyoshi
219
- * contact-form-7\modules\recaptcha.php LN360
220
- *
221
- * @param Array $args
222
- *
223
- * @return String
224
- */
225
- function iqfix_wpcf7_recaptcha_noscript( $args = '' ) {
226
-
227
- $args = wp_parse_args( $args, array(
228
- 'sitekey' => '',
229
- ) );
230
-
231
- if ( empty( $args['sitekey'] ) ) {
232
- return;
233
- }
234
-
235
- $url = add_query_arg( 'k', $args['sitekey'],
236
- 'https://www.google.com/recaptcha/api/fallback' );
237
-
238
- ob_start();
239
- ?>
240
-
241
- <noscript>
242
- <div style="width: 302px; height: 422px;">
243
- <div style="width: 302px; height: 422px; position: relative;">
244
- <div style="width: 302px; height: 422px; position: absolute;">
245
- <iframe src="<?php echo esc_url( $url ); ?>" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;">
246
- </iframe>
247
- </div>
248
- <div style="width: 300px; height: 60px; border-style: none; bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px;">
249
- <textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px; height: 40px; border: 1px solid #c1c1c1; margin: 10px 25px; padding: 0px; resize: none;">
250
- </textarea>
251
- </div>
252
- </div>
253
- </div>
254
- </noscript>
255
- <?php
256
- return ob_get_clean();
257
- }
258
-
259
-
260
- /**
261
- * Verify submission is legitimate, verify reCaptcha response
262
- *
263
- * The following function was not written by IQComputing and is included in
264
- * Contact Form 7 v5.0.5 by Takayuki Miyoshi
265
- * contact-form-7\modules\recaptcha.php LN395
266
- *
267
- * @param Boolean $spam
268
- *
269
- * @return Boolean $spam
270
- */
271
- function iqfix_wpcf7_recaptcha_check_with_google( $spam ) {
272
-
273
- if ( $spam ) {
274
- return $spam;
275
- }
276
-
277
- $contact_form = wpcf7_get_current_contact_form();
278
-
279
- if ( ! $contact_form ) {
280
- return $spam;
281
- }
282
-
283
- $tags = $contact_form->scan_form_tags( array( 'type' => 'recaptcha' ) );
284
-
285
- if ( empty( $tags ) ) {
286
- return $spam;
287
- }
288
-
289
- $recaptcha = IQFix_ReCaptcha::get_instance();
290
-
291
- if( ! $recaptcha->is_active() ) {
292
- return $spam;
293
- }
294
-
295
- $response_token = wpcf7_recaptcha_response();
296
-
297
- $spam = ! $recaptcha->verify( $response_token );
298
-
299
- return $spam;
300
-
301
- }
302
- // See `iqfix_wpcf7_manage_hooks` callback above
303
-
304
-
305
- /**
306
- * Grab and return the posted reCaptcha response
307
- *
308
- * The following function was not written by IQComputing and is included in
309
- * Contact Form 7 v5.0.5 by Takayuki Miyoshi
310
- * contact-form-7\modules\recaptcha.php LN509
311
- *
312
- * @return String|FALSE
313
- */
314
- function wpcf7_recaptcha_response() {
315
-
316
- if ( isset( $_POST['g-recaptcha-response'] ) ) {
317
- return $_POST['g-recaptcha-response'];
318
- }
319
-
320
- return false;
321
-
322
- }
323
-
324
-
325
- /**
326
- * Add [recaptcha] to Contact Form 7 field list
327
- *
328
- * The following function was not written by IQComputing and is included in
329
- * Contact Form 7 v5.0.5 by Takayuki Miyoshi
330
- * contact-form-7\modules\recaptcha.php LN426
331
- *
332
- * @return void
333
- */
334
- function iqfix_wpcf7_add_tag_generator_recaptcha() {
335
-
336
- $tag_generator = WPCF7_TagGenerator::get_instance();
337
- $tag_generator->add(
338
- 'recaptcha',
339
- esc_html__( 'reCaptcha', 'wpcf7-recaptcha' ),
340
- 'iqfix_wpcf7_tag_generator_recaptcha',
341
- array( 'nameless' => 1 )
342
- );
343
-
344
- }
345
- add_action( 'wpcf7_admin_init', 'iqfix_wpcf7_add_tag_generator_recaptcha', 45 );
346
-
347
-
348
- /**
349
- * Show [recaptcha] field settings
350
- *
351
- * The following function was not written by IQComputing and is included in
352
- * Contact Form 7 v5.0.5 by Takayuki Miyoshi
353
- * contact-form-7\modules\recaptcha.php LN432
354
- *
355
- * @param WPCF7_ContactForm $contact_form
356
- * @param Array $args
357
- *
358
- * @return void
359
- */
360
- function iqfix_wpcf7_tag_generator_recaptcha( $contact_form, $args = '' ) {
361
-
362
- $args = wp_parse_args( $args, array() );
363
- $recaptcha = IQFix_ReCaptcha::get_instance();
364
-
365
- if ( ! $recaptcha->is_active() ) {
366
-
367
- ?>
368
- <div class="control-box">
369
- <fieldset>
370
- <legend><?php
371
- /* translators: %s is a link to the Contact Form 7 blog post regarding reCaptcha v3 */
372
- echo sprintf( esc_html__( "To use reCaptcha, first you need to install an API key pair. For more details, see %s.", 'wpcf7-recaptcha' ), wpcf7_link( 'https://contactform7.com/recaptcha/', esc_html__( 'reCaptcha', 'wpcf7-recaptcha' ) ) );
373
- ?></legend>
374
- </fieldset>
375
- </div>
376
- <?php
377
-
378
- return;
379
- }
380
-
381
- /* translators: %s is a link to the Contact Form 7 blog post regarding reCaptcha v3 */
382
- $description = esc_html__( "Generate a form-tag for a reCaptcha widget. For more details, see %s.", 'wpcf7-recaptcha' );
383
- $desc_link = wpcf7_link( 'https://contactform7.com/recaptcha/', esc_html__( 'reCaptcha', 'wpcf7-recaptcha' ) );
384
-
385
- ?>
386
- <div class="control-box">
387
- <fieldset>
388
- <legend><?php echo sprintf( $description, $desc_link ); ?></legend>
389
-
390
- <table class="form-table">
391
- <tbody>
392
- <tr>
393
- <th scope="row"><?php
394
- /* translators: ReCaptcha size (normal or compact) */
395
- esc_html_e( 'Size', 'wpcf7-recaptcha' );
396
- ?></th>
397
- <td>
398
- <fieldset>
399
- <legend class="screen-reader-text"><?php
400
- /* translators: Screen reader text, reCaptcha size (normal or compact) */
401
- esc_html_e( 'Size', 'wpcf7-recaptcha' );
402
- ?></legend>
403
- <label for="<?php echo esc_attr( $args['content'] . '-size-normal' ); ?>"><input type="radio" name="size" class="option default" id="<?php echo esc_attr( $args['content'] . '-size-normal' ); ?>" value="normal" checked="checked" /> <?php /* translators: ReCaptcha size: normal */ esc_html_e( 'Normal', 'wpcf7-recaptcha' ); ?></label>
404
- <br />
405
- <label for="<?php echo esc_attr( $args['content'] . '-size-compact' ); ?>"><input type="radio" name="size" class="option" id="<?php echo esc_attr( $args['content'] . '-size-compact' ); ?>" value="compact" /> <?php /* translators: ReCaptcha size: compact */ esc_html_e( 'Compact', 'wpcf7-recaptcha' ); ?></label>
406
- </fieldset>
407
- </td>
408
- </tr>
409
-
410
- <tr>
411
- <th scope="row"><?php
412
- /* translators: ReCaptcha theme (light or dark) */
413
- esc_html_e( 'Theme', 'wpcf7-recaptcha' );
414
- ?></th>
415
- <td>
416
- <fieldset>
417
- <legend class="screen-reader-text"><?php
418
- /* translators: Screen reader text, reCaptcha theme (light or dark) */
419
- esc_html_e( 'Theme', 'wpcf7-recaptcha' );
420
- ?></legend>
421
- <label for="<?php echo esc_attr( $args['content'] . '-theme-light' ); ?>"><input type="radio" name="theme" class="option default" id="<?php echo esc_attr( $args['content'] . '-theme-light' ); ?>" value="light" checked="checked" /> <?php /* translators: ReCaptcha theme: light */ esc_html_e( 'Light', 'wpcf7-recaptcha' ); ?></label>
422
- <br />
423
- <label for="<?php echo esc_attr( $args['content'] . '-theme-dark' ); ?>"><input type="radio" name="theme" class="option" id="<?php echo esc_attr( $args['content'] . '-theme-dark' ); ?>" value="dark" /> <?php /* translators: ReCaptcha theme: dark */ esc_html_e( 'Dark', 'wpcf7-recaptcha' ); ?></label>
424
- </fieldset>
425
- </td>
426
- </tr>
427
-
428
- <tr>
429
- <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php
430
- /* translators: HTML Attribute ID for reCaptcha box */
431
- esc_html_e( 'Id attribute', 'wpcf7-recaptcha' );
432
- ?></label></th>
433
- <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
434
- </tr>
435
-
436
- <tr>
437
- <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php
438
- /* translators: HTML Attribute class for reCaptcha box */
439
- esc_html_e( 'Class attribute', 'wpcf7-recaptcha' );
440
- ?></label></th>
441
- <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
442
- </tr>
443
-
444
- </tbody>
445
- </table>
446
- </fieldset>
447
- </div>
448
-
449
- <div class="insert-box">
450
- <input type="text" name="recaptcha" class="tag code" readonly="readonly" onfocus="this.select()" />
451
-
452
- <div class="submitbox">
453
- <input type="button" class="button button-primary insert-tag" value="<?php
454
- /* translators: Insert shortcode tag into the page content */
455
- esc_attr_e( 'Insert Tag', 'wpcf7-recaptcha' );
456
- ?>" />
457
- </div>
458
- </div>
459
- <?php
460
-
461
- }
462
- // See `iqfix_wpcf7_add_tag_generator_recaptcha` callback above
463
-
464
-
465
- /**
466
- * The following class is supposed to use and replicate some functionality
467
- * From Contact Form 7 v5.0.5
468
- *
469
- * @return void
470
- */
471
- function iqfix_recaptcha_class_init() {
472
-
473
- if( ! class_exists( 'WPCF7_RECAPTCHA' ) ) {
474
- return false;
475
- }
476
-
477
- Class IQFix_ReCaptcha extends WPCF7_RECAPTCHA {
478
-
479
- const VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify';
480
-
481
- private static $instance;
482
- private $sitekeys;
483
-
484
-
485
- /**
486
- * Class initialization
487
- *
488
- * The following method was not written by IQComputing and is included in
489
- * Contact Form 7 v5.0.5 by Takayuki Miyoshi
490
- * contact-form-7\modules\recaptcha.php LN202
491
- *
492
- * return void
493
- */
494
- private function __construct() {
495
- $this->sitekeys = WPCF7::get_option( 'recaptcha' );
496
- }
497
-
498
-
499
- /**
500
- * Singleton
501
- *
502
- * The following method was not written by IQComputing and is included in
503
- * Contact Form 7 v5.0.5 by Takayuki Miyoshi
504
- * contact-form-7\modules\recaptcha.php LN10
505
- *
506
- * @return IQFix_ReCaptcha
507
- */
508
- public static function get_instance() {
509
- if ( empty( self::$instance ) ) {
510
- self::$instance = new self;
511
- }
512
-
513
- return self::$instance;
514
- }
515
-
516
-
517
- /**
518
- * Check if reCaptcha is active
519
- *
520
- * The following method was not written by IQComputing and is included in
521
- * Contact Form 7 v5.0.5 by Takayuki Miyoshi
522
- * contact-form-7\modules\recaptcha.php LN26
523
- *
524
- * @return Boolean
525
- */
526
- public function is_active() {
527
- $sitekey = $this->get_sitekey();
528
- $secret = $this->get_secret( $sitekey );
529
- return $sitekey && $secret;
530
- }
531
-
532
-
533
- /**
534
- * Get set reCaptcha sitekey
535
- *
536
- * The following method was not written by IQComputing and is included in
537
- * Contact Form 7 v5.0.5 by Takayuki Miyoshi
538
- * contact-form-7\modules\recaptcha.php LN45
539
- *
540
- * @return String|FALSE
541
- */
542
- public function get_sitekey() {
543
- if ( empty( $this->sitekeys )
544
- or ! is_array( $this->sitekeys ) ) {
545
- return false;
546
- }
547
-
548
- $sitekeys = array_keys( $this->sitekeys );
549
-
550
- return $sitekeys[0];
551
- }
552
-
553
-
554
- /**
555
- * Get set reCaptcha secret key
556
- *
557
- * The following method was not written by IQComputing and is included in
558
- * Contact Form 7 v5.0.5 by Takayuki Miyoshi
559
- * contact-form-7\modules\recaptcha.php LN55
560
- *
561
- * @return String|FALSE
562
- */
563
- public function get_secret( $sitekey ) {
564
- $sitekeys = (array) $this->sitekeys;
565
-
566
- if ( isset( $sitekeys[$sitekey] ) ) {
567
- return $sitekeys[$sitekey];
568
- } else {
569
- return false;
570
- }
571
- }
572
-
573
-
574
- /**
575
- * Verify reCaptcha Response
576
- *
577
- * The following method was not written by IQComputing and is included in
578
- * Contact Form 7 v5.0.5 by Takayuki Miyoshi
579
- * contact-form-7\modules\recaptcha.php LN65
580
- *
581
- * @param String $response_token
582
- *
583
- * @return Boolean $is_human
584
- */
585
- public function verify( $response_token ) {
586
-
587
- $is_human = false;
588
-
589
- if ( empty( $response_token ) ) {
590
- return $is_human;
591
- }
592
-
593
- $url = self::VERIFY_URL;
594
- $sitekey = $this->get_sitekey();
595
- $secret = $this->get_secret( $sitekey );
596
-
597
- $response = wp_safe_remote_post( $url, array(
598
- 'body' => array(
599
- 'secret' => $secret,
600
- 'response' => $response_token,
601
- 'remoteip' => $_SERVER['REMOTE_ADDR'],
602
- ),
603
- ) );
604
-
605
- if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
606
- return $is_human;
607
- }
608
-
609
- $response = wp_remote_retrieve_body( $response );
610
- $response = json_decode( $response, true );
611
-
612
- $is_human = isset( $response['success'] ) && true == $response['success'];
613
- return $is_human;
614
-
615
- }
616
-
617
- }
618
-
619
- }
620
- add_action( 'init', 'iqfix_recaptcha_class_init', 11 );
621
-
622
-
623
- /**
624
- * Add some inline CSS for the reCaptcha iframe
625
- *
626
- * @return void
627
- */
628
- function iqfix_recaptcha_inline_css() {
629
-
630
- $iqfix_css ='.wpcf7 .wpcf7-recaptcha iframe {margin-bottom: 0;}';
631
- wp_add_inline_style( 'contact-form-7', $iqfix_css );
632
-
633
- }
634
add_action( 'wp_enqueue_scripts', 'iqfix_recaptcha_inline_css' );
1
+ <?php
2
+ /**
3
+ * Replace reCaptcha v3 with ReCaptcha v2
4
+ * Use [recaptcha] shortcode when possible
5
+ */
6
+
7
+
8
+ defined( 'ABSPATH' ) or die( 'You cannot be here.' );
9
+
10
+
11
+ /**
12
+ * Remove old hooks and add new hook callbacks
13
+ *
14
+ * @return void
15
+ */
16
+ function iqfix_wpcf7_manage_hooks() {
17
+
18
+ // reCaptcha Verification
19
+ remove_filter( 'wpcf7_spam', 'wpcf7_recaptcha_verify_response', 9 );
20
+ add_filter( 'wpcf7_spam', 'iqfix_wpcf7_recaptcha_check_with_google', 9 );
21
+
22
+ // reCaptcha Enqueues
23
+ remove_action( 'wp_enqueue_scripts', 'wpcf7_recaptcha_enqueue_scripts', 10 );
24
+ add_action( 'wp_enqueue_scripts', 'iqfix_wpcf7_recaptcha_enqueue_scripts', 10 );
25
+
26
+ // reCaptcha Footer Javascript
27
+ remove_action( 'wp_footer', 'wpcf7_recaptcha_onload_script', 40 );
28
+ add_action( 'wp_footer', 'iqfix_wpcf7_recaptcha_callback_script', 40 );
29
+
30
+ }
31
+ add_action( 'setup_theme', 'iqfix_wpcf7_manage_hooks' );
32
+
33
+
34
+ /**
35
+ * Remove current [recaptcha] tag and replace it with old reCaptcha tag
36
+ *
37
+ * @return void
38
+ */
39
+ function iqfix_wpcf7_add_recaptcha_tag() {
40
+
41
+ wpcf7_remove_form_tag( 'recaptcha' );
42
+ wpcf7_add_form_tag(
43
+ 'recaptcha',
44
+ 'iqfix_wpcf7_recaptcha_form_tag_handler',
45
+ array( 'display-block' => true )
46
+ );
47
+
48
+ }
49
+ add_action( 'wpcf7_init', 'iqfix_wpcf7_add_recaptcha_tag', 20 );
50
+
51
+
52
+ /**
53
+ * Register the Google reCaptcha API script
54
+ *
55
+ * The following function was not written by IQComputing and is included in
56
+ * Contact Form 7 v5.0.5 by Takayuki Miyoshi
57
+ * contact-form-7\modules\recaptcha.php LN241
58
+ *
59
+ * @return void
60
+ */
61
+ function iqfix_wpcf7_recaptcha_enqueue_scripts() {
62
+
63
+ $source = WPCF7::get_option( 'iqfix_recaptcha_source' );
64
+ $source = IQFix_WPCF7_Deity::verify_recaptcha_source( $source );
65
+
66
+ $url = sprintf( 'https://www.%s/recaptcha/api.js', $source );
67
+ $url = add_query_arg( array(
68
+ 'hl' => esc_attr( get_locale() ), // Lowercase L
69
+ 'onload' => 'recaptchaCallback',
70
+ 'render' => 'explicit',
71
+ ), $url );
72
+
73
+ wp_register_script( 'google-recaptcha', $url, array( 'jquery' ), '2.0', true );
74
+ wp_localize_script( 'google-recaptcha', 'wpcf7iqfix', array(
75
+ 'recaptcha_empty' => esc_html__( 'Please verify that you are not a robot.', 'wpcf7-recaptcha' ),
76
+ ) );
77
+
78
+ }
79
+ // See `iqfix_wpcf7_manage_hooks` callback above
80
+
81
+
82
+ /**
83
+ * reCaptcha Javascript
84
+ *
85
+ * The following function was not written by IQComputing and is included in
86
+ * Contact Form 7 v5.0.5 by Takayuki Miyoshi
87
+ * contact-form-7\modules\recaptcha.php LN253
88
+ *
89
+ * @return void
90
+ */
91
+ function iqfix_wpcf7_recaptcha_callback_script() {
92
+
93
+ if ( ! wp_script_is( 'google-recaptcha', 'enqueued' ) ) {
94
+ return;
95
+ }
96
+
97
+ ?>
98
+ <script type="text/javascript">
99
+ var recaptchaWidgets = [];
100
+ var recaptchaCallback = function() {
101
+ var forms = document.getElementsByTagName( 'form' );
102
+ var pattern = /(^|\s)g-recaptcha(\s|$)/;
103
+
104
+ for ( var i = 0; i < forms.length; i++ ) {
105
+ var divs = forms[ i ].getElementsByTagName( 'div' );
106
+
107
+ for ( var j = 0; j < divs.length; j++ ) {
108
+ var sitekey = divs[ j ].getAttribute( 'data-sitekey' );
109
+
110
+ if ( divs[ j ].className && divs[ j ].className.match( pattern ) && sitekey ) {
111
+ var params = {
112
+ 'sitekey': sitekey,
113
+ 'type': divs[ j ].getAttribute( 'data-type' ),
114
+ 'size': divs[ j ].getAttribute( 'data-size' ),
115
+ 'theme': divs[ j ].getAttribute( 'data-theme' ),
116
+ 'badge': divs[ j ].getAttribute( 'data-badge' ),
117
+ 'tabindex': divs[ j ].getAttribute( 'data-tabindex' )
118
+ };
119
+
120
+ var callback = divs[ j ].getAttribute( 'data-callback' );
121
+
122
+ if ( callback && 'function' == typeof window[ callback ] ) {
123
+ params[ 'callback' ] = window[ callback ];
124
+ }
125
+
126
+ var expired_callback = divs[ j ].getAttribute( 'data-expired-callback' );
127
+
128
+ if ( expired_callback && 'function' == typeof window[ expired_callback ] ) {
129
+ params[ 'expired-callback' ] = window[ expired_callback ];
130
+ }
131
+
132
+ var widget_id = grecaptcha.render( divs[ j ], params );
133
+ recaptchaWidgets.push( widget_id );
134
+ break;
135
+ }
136
+ }
137
+ }
138
+ };
139
+
140
+ document.addEventListener( 'wpcf7submit', function( event ) {
141
+ switch ( event.detail.status ) {
142
+ case 'spam':
143
+ case 'mail_sent':
144
+ case 'mail_failed':
145
+ for ( var i = 0; i < recaptchaWidgets.length; i++ ) {
146
+ grecaptcha.reset( recaptchaWidgets[ i ] );
147
+ }
148
+ }
149
+ }, false );
150
+
151
+ ( function( $ ) {
152
+ $( '.wpcf7' ).on( 'wpcf7:spam', function( e ) {
153
+ $( '[name="g-recaptcha-response"]', $( this ) ).each( function() {
154
+ if ( '' === $( this ).val() ) {
155
+ var $recaptcha = $( this ).closest( '.wpcf7-form-control-wrap' );
156
+ wpcf7.notValidTip( $recaptcha, wpcf7iqfix.recaptcha_empty );
157
+ }
158
+ } );
159
+ } );
160
+ } )( jQuery );
161
+ </script>
162
+ <?php
163
+
164
+ }
165
+ // See `iqfix_wpcf7_manage_hooks` callback above
166
+
167
+
168
+ /**
169
+ * reCaptcha Callback
170
+ *
171
+ * The following function was not written by IQComputing and is included in
172
+ * Contact Form 7 v5.0.5
173
+ * contact-form-7\modules\recaptcha.php LN326
174
+ *
175
+ * @param WPCF7_FormTag $tag
176
+ *
177
+ * @return String $html
178
+ */
179
+ function iqfix_wpcf7_recaptcha_form_tag_handler( $tag ) {
180
+
181
+ if ( ! wp_script_is( 'google-recaptcha', 'registered' ) ) {
182
+ wpcf7_recaptcha_enqueue_scripts();
183
+ }
184
+
185
+ wp_enqueue_script( 'google-recaptcha' );
186
+
187
+ $atts = array();
188
+
189
+ $recaptcha = WPCF7_RECAPTCHA::get_instance();
190
+ $atts['data-sitekey'] = $recaptcha->get_sitekey();
191
+ $atts['data-type'] = $tag->get_option( 'type', '(audio|image)', true );
192
+ $atts['data-size'] = $tag->get_option(
193
+ 'size', '(compact|normal|invisible)', true );
194
+ $atts['data-theme'] = $tag->get_option( 'theme', '(dark|light)', true );
195
+ $atts['data-badge'] = $tag->get_option(
196
+ 'badge', '(bottomright|bottomleft|inline)', true );
197
+ $atts['data-tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
198
+ $atts['data-callback'] = $tag->get_option( 'callback', '', true );
199
+ $atts['data-expired-callback'] =
200
+ $tag->get_option( 'expired_callback', '', true );
201
+
202
+ $atts['class'] = $tag->get_class_option(
203
+ wpcf7_form_controls_class( $tag->type, 'g-recaptcha' ) );
204
+ $atts['id'] = $tag->get_id_option();
205
+
206
+ $html = sprintf( '<div %1$s></div>', wpcf7_format_atts( $atts ) );
207
+ $html .= iqfix_wpcf7_recaptcha_noscript(
208
+ array( 'sitekey' => $atts['data-sitekey'] ) );
209
+ $html = sprintf( '<div class="wpcf7-form-control-wrap">%s</div>', $html );
210
+
211
+ return $html;
212
+
213
+ }
214
+ // See `iqfix_wpcf7_add_recaptcha_tag` callback above.
215
+
216
+
217
+ /**
218
+ * Display reCaptcha noscript tag should javacript be disabled.
219
+ *
220
+ * The following function was not written by IQComputing and is included in
221
+ * Contact Form 7 v5.0.5 by Takayuki Miyoshi
222
+ * contact-form-7\modules\recaptcha.php LN360
223
+ *
224
+ * @param Array $args
225
+ *
226
+ * @return String
227
+ */
228
+ function iqfix_wpcf7_recaptcha_noscript( $args = '' ) {
229
+
230
+ $args = wp_parse_args( $args, array(
231
+ 'sitekey' => '',
232
+ ) );
233
+
234
+ if ( empty( $args['sitekey'] ) ) {
235
+ return;
236
+ }
237
+
238
+ $source = WPCF7::get_option( 'iqfix_recaptcha_source' );
239
+ $source = IQFix_WPCF7_Deity::verify_recaptcha_source( $source );
240
+ $url = add_query_arg( 'k', $args['sitekey'],
241
+ sprintf( 'https://www.%s/recaptcha/api/fallback', $source )
242
+ );
243
+
244
+ ob_start();
245
+ ?>
246
+
247
+ <noscript>
248
+ <div class="grecaptcha-noscript">
249
+ <iframe src="<?php echo esc_url( $url ); ?>" frameborder="0" scrolling="no" width="310" height="430"></iframe>
250
+ <textarea name="g-recaptcha-response" rows="3" cols="40" placeholder="<?php esc_attr_e( 'reCaptcha Response Here' ); ?>"></textarea>
251
+ </div>
252
+ </noscript>
253
+ <?php
254
+ return ob_get_clean();
255
+ }
256
+
257
+
258
+ /**
259
+ * Verify submission is legitimate, verify reCaptcha response
260
+ *
261
+ * The following function was not written by IQComputing and is included in
262
+ * Contact Form 7 v5.0.5 by Takayuki Miyoshi
263
+ * contact-form-7\modules\recaptcha.php LN395
264
+ *
265
+ * @param Boolean $spam
266
+ *
267
+ * @return Boolean $spam
268
+ */
269
+ function iqfix_wpcf7_recaptcha_check_with_google( $spam ) {
270
+
271
+ if ( $spam ) {
272
+ return $spam;
273
+ }
274
+
275
+ $contact_form = wpcf7_get_current_contact_form();
276
+
277
+ if ( ! $contact_form ) {
278
+ return $spam;
279
+ }
280
+
281
+ $tags = $contact_form->scan_form_tags( array( 'type' => 'recaptcha' ) );
282
+
283
+ if ( empty( $tags ) ) {
284
+ return $spam;
285
+ }
286
+
287
+ $recaptcha = IQFix_ReCaptcha::get_instance();
288
+
289
+ if( ! $recaptcha->is_active() ) {
290
+ return $spam;
291
+ }
292
+
293
+ $response_token = wpcf7_recaptcha_response();
294
+
295
+ $spam = ! $recaptcha->verify( $response_token );
296
+
297
+ return $spam;
298
+
299
+ }
300
+ // See `iqfix_wpcf7_manage_hooks` callback above
301
+
302
+
303
+ /**
304
+ * Grab and return the posted reCaptcha response
305
+ *
306
+ * The following function was not written by IQComputing and is included in
307
+ * Contact Form 7 v5.0.5 by Takayuki Miyoshi
308
+ * contact-form-7\modules\recaptcha.php LN509
309
+ *
310
+ * @return String|FALSE
311
+ */
312
+ function wpcf7_recaptcha_response() {
313
+
314
+ if ( isset( $_POST['g-recaptcha-response'] ) ) {
315
+ return $_POST['g-recaptcha-response'];
316
+ }
317
+
318
+ return false;
319
+
320
+ }
321
+
322
+
323
+ /**
324
+ * Add [recaptcha] to Contact Form 7 field list
325
+ *
326
+ * The following function was not written by IQComputing and is included in
327
+ * Contact Form 7 v5.0.5 by Takayuki Miyoshi
328
+ * contact-form-7\modules\recaptcha.php LN426
329
+ *
330
+ * @return void
331
+ */
332
+ function iqfix_wpcf7_add_tag_generator_recaptcha() {
333
+
334
+ $tag_generator = WPCF7_TagGenerator::get_instance();
335
+ $tag_generator->add(
336
+ 'recaptcha',
337
+ esc_html__( 'reCaptcha', 'wpcf7-recaptcha' ),
338
+ 'iqfix_wpcf7_tag_generator_recaptcha',
339
+ array( 'nameless' => 1 )
340
+ );
341
+
342
+ }
343
+ add_action( 'wpcf7_admin_init', 'iqfix_wpcf7_add_tag_generator_recaptcha', 45 );
344
+
345
+
346
+ /**
347
+ * Show [recaptcha] field settings
348
+ *
349
+ * The following function was not written by IQComputing and is included in
350
+ * Contact Form 7 v5.0.5 by Takayuki Miyoshi
351
+ * contact-form-7\modules\recaptcha.php LN432
352
+ *
353
+ * @param WPCF7_ContactForm $contact_form
354
+ * @param Array $args
355
+ *
356
+ * @return void
357
+ */
358
+ function iqfix_wpcf7_tag_generator_recaptcha( $contact_form, $args = '' ) {
359
+
360
+ $args = wp_parse_args( $args, array() );
361
+ $recaptcha = IQFix_ReCaptcha::get_instance();
362
+
363
+ if ( ! $recaptcha->is_active() ) {
364
+
365
+ ?>
366
+ <div class="control-box">
367
+ <fieldset>
368
+ <legend><?php
369
+ /* translators: %s is a link to the Contact Form 7 blog post regarding reCaptcha v3 */
370
+ echo sprintf( esc_html__( "To use reCaptcha, first you need to install an API key pair. For more details, see %s.", 'wpcf7-recaptcha' ), wpcf7_link( 'https://contactform7.com/recaptcha/', esc_html__( 'reCaptcha', 'wpcf7-recaptcha' ) ) );
371
+ ?></legend>
372
+ </fieldset>
373
+ </div>
374
+ <?php
375
+
376
+ return;
377
+ }
378
+
379
+ /* translators: %s is a link to the Contact Form 7 blog post regarding reCaptcha v3 */
380
+ $description = esc_html__( "Generate a form-tag for a reCaptcha widget. For more details, see %s.", 'wpcf7-recaptcha' );
381
+ $desc_link = wpcf7_link( 'https://contactform7.com/recaptcha/', esc_html__( 'reCaptcha', 'wpcf7-recaptcha' ) );
382
+
383
+ ?>
384
+ <div class="control-box">
385
+ <fieldset>
386
+ <legend><?php echo sprintf( $description, $desc_link ); ?></legend>
387
+
388
+ <table class="form-table">
389
+ <tbody>
390
+ <tr>
391
+ <th scope="row"><?php
392
+ /* translators: ReCaptcha size (normal or compact) */
393
+ esc_html_e( 'Size', 'wpcf7-recaptcha' );
394
+ ?></th>
395
+ <td>
396
+ <fieldset>
397
+ <legend class="screen-reader-text"><?php
398
+ /* translators: Screen reader text, reCaptcha size (normal or compact) */
399
+ esc_html_e( 'Size', 'wpcf7-recaptcha' );
400
+ ?></legend>
401
+ <label for="<?php echo esc_attr( $args['content'] . '-size-normal' ); ?>"><input type="radio" name="size" class="option default" id="<?php echo esc_attr( $args['content'] . '-size-normal' ); ?>" value="normal" checked="checked" /> <?php /* translators: ReCaptcha size: normal */ esc_html_e( 'Normal', 'wpcf7-recaptcha' ); ?></label>
402
+ <br />
403
+ <label for="<?php echo esc_attr( $args['content'] . '-size-compact' ); ?>"><input type="radio" name="size" class="option" id="<?php echo esc_attr( $args['content'] . '-size-compact' ); ?>" value="compact" /> <?php /* translators: ReCaptcha size: compact */ esc_html_e( 'Compact', 'wpcf7-recaptcha' ); ?></label>
404
+ </fieldset>
405
+ </td>
406
+ </tr>
407
+
408
+ <tr>
409
+ <th scope="row"><?php
410
+ /* translators: ReCaptcha theme (light or dark) */
411
+ esc_html_e( 'Theme', 'wpcf7-recaptcha' );
412
+ ?></th>
413
+ <td>
414
+ <fieldset>
415
+ <legend class="screen-reader-text"><?php
416
+ /* translators: Screen reader text, reCaptcha theme (light or dark) */
417
+ esc_html_e( 'Theme', 'wpcf7-recaptcha' );
418
+ ?></legend>
419
+ <label for="<?php echo esc_attr( $args['content'] . '-theme-light' ); ?>"><input type="radio" name="theme" class="option default" id="<?php echo esc_attr( $args['content'] . '-theme-light' ); ?>" value="light" checked="checked" /> <?php /* translators: ReCaptcha theme: light */ esc_html_e( 'Light', 'wpcf7-recaptcha' ); ?></label>
420
+ <br />
421
+ <label for="<?php echo esc_attr( $args['content'] . '-theme-dark' ); ?>"><input type="radio" name="theme" class="option" id="<?php echo esc_attr( $args['content'] . '-theme-dark' ); ?>" value="dark" /> <?php /* translators: ReCaptcha theme: dark */ esc_html_e( 'Dark', 'wpcf7-recaptcha' ); ?></label>
422
+ </fieldset>
423
+ </td>
424
+ </tr>
425
+
426
+ <tr>
427
+ <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php
428
+ /* translators: HTML Attribute ID for reCaptcha box */
429
+ esc_html_e( 'Id attribute', 'wpcf7-recaptcha' );
430
+ ?></label></th>
431
+ <td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
432
+ </tr>
433
+
434
+ <tr>
435
+ <th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php
436
+ /* translators: HTML Attribute class for reCaptcha box */
437
+ esc_html_e( 'Class attribute', 'wpcf7-recaptcha' );
438
+ ?></label></th>
439
+ <td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
440
+ </tr>
441
+
442
+ </tbody>
443
+ </table>
444
+ </fieldset>
445
+ </div>
446
+
447
+ <div class="insert-box">
448
+ <input type="text" name="recaptcha" class="tag code" readonly="readonly" onfocus="this.select()" />
449
+
450
+ <div class="submitbox">
451
+ <input type="button" class="button button-primary insert-tag" value="<?php
452
+ /* translators: Insert shortcode tag into the page content */
453
+ esc_attr_e( 'Insert Tag', 'wpcf7-recaptcha' );
454
+ ?>" />
455
+ </div>
456
+ </div>
457
+ <?php
458
+
459
+ }
460
+ // See `iqfix_wpcf7_add_tag_generator_recaptcha` callback above
461
+
462
+
463
+ /**
464
+ * The following class is supposed to use and replicate some functionality
465
+ * From Contact Form 7 v5.0.5
466
+ *
467
+ * @return void
468
+ */
469
+ function iqfix_recaptcha_class_init() {
470
+
471
+ if( ! class_exists( 'WPCF7_RECAPTCHA' ) ) {
472
+ return false;
473
+ }
474
+
475
+ Class IQFix_ReCaptcha extends WPCF7_RECAPTCHA {
476
+
477
+ private static $instance;
478
+ private $sitekeys;
479
+
480
+
481
+ /**
482
+ * Class initialization
483
+ *
484
+ * The following method was not written by IQComputing and is included in
485
+ * Contact Form 7 v5.0.5 by Takayuki Miyoshi
486
+ * contact-form-7\modules\recaptcha.php LN202
487
+ *
488
+ * return void
489
+ */
490
+ private function __construct() {
491
+ $this->sitekeys = WPCF7::get_option( 'recaptcha' );
492
+ }
493
+
494
+
495
+ /**
496
+ * Singleton
497
+ *
498
+ * The following method was not written by IQComputing and is included in
499
+ * Contact Form 7 v5.0.5 by Takayuki Miyoshi
500
+ * contact-form-7\modules\recaptcha.php LN10
501
+ *
502
+ * @return IQFix_ReCaptcha
503
+ */
504
+ public static function get_instance() {
505
+ if ( empty( self::$instance ) ) {
506
+ self::$instance = new self;
507
+ }
508
+
509
+ return self::$instance;
510
+ }
511
+
512
+
513
+ /**
514
+ * Check if reCaptcha is active
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 LN26
519
+ *
520
+ * @return Boolean
521
+ */
522
+ public function is_active() {
523
+ $sitekey = $this->get_sitekey();
524
+ $secret = $this->get_secret( $sitekey );
525
+ return $sitekey && $secret;
526
+ }
527
+
528
+
529
+ /**
530
+ * Get set reCaptcha sitekey
531
+ *
532
+ * The following method was not written by IQComputing and is included in
533
+ * Contact Form 7 v5.0.5 by Takayuki Miyoshi
534
+ * contact-form-7\modules\recaptcha.php LN45
535
+ *
536
+ * @return String|FALSE
537
+ */
538
+ public function get_sitekey() {
539
+ if ( empty( $this->sitekeys )
540
+ or ! is_array( $this->sitekeys ) ) {
541
+ return false;
542
+ }
543
+
544
+ $sitekeys = array_keys( $this->sitekeys );
545
+
546
+ return $sitekeys[0];
547
+ }
548
+
549
+
550
+ /**
551
+ * Get set reCaptcha secret key
552
+ *
553
+ * The following method was not written by IQComputing and is included in
554
+ * Contact Form 7 v5.0.5 by Takayuki Miyoshi
555
+ * contact-form-7\modules\recaptcha.php LN55
556
+ *
557
+ * @return String|FALSE
558
+ */
559
+ public function get_secret( $sitekey ) {
560
+ $sitekeys = (array) $this->sitekeys;
561
+
562
+ if ( isset( $sitekeys[$sitekey] ) ) {
563
+ return $sitekeys[$sitekey];
564
+ } else {
565
+ return false;
566
+ }
567
+ }
568
+
569
+
570
+ /**
571
+ * Verify reCaptcha Response
572
+ *
573
+ * The following method was not written by IQComputing and is included in
574
+ * Contact Form 7 v5.0.5 by Takayuki Miyoshi
575
+ * contact-form-7\modules\recaptcha.php LN65
576
+ *
577
+ * @param String $response_token
578
+ *
579
+ * @return Boolean $is_human
580
+ */
581
+ public function verify( $response_token ) {
582
+
583
+ $is_human = false;
584
+
585
+ if ( empty( $response_token ) ) {
586
+ return $is_human;
587
+ }
588
+
589
+ $source = WPCF7::get_option( 'iqfix_recaptcha_source' );
590
+ $source = IQFix_WPCF7_Deity::verify_recaptcha_source( $source );
591
+ $url = sprintf( 'https://www.%s/recaptcha/api/siteverify', $source );
592
+ $sitekey = $this->get_sitekey();
593
+ $secret = $this->get_secret( $sitekey );
594
+
595
+ $response = wp_safe_remote_post( $url, array(
596
+ 'body' => array(
597
+ 'secret' => $secret,
598
+ 'response' => $response_token,
599
+ 'remoteip' => $_SERVER['REMOTE_ADDR'],
600
+ ),
601
+ ) );
602
+
603
+ if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
604
+
605
+ if ( WP_DEBUG ) {
606
+ $this->log( $endpoint, $request, $response );
607
+ }
608
+
609
+ return $is_human;
610
+
611
+ }
612
+
613
+ $response = wp_remote_retrieve_body( $response );
614
+ $response = json_decode( $response, true );
615
+ $is_human = isset( $response['success'] ) && true == $response['success'];
616
+
617
+ return apply_filters( 'wpcf7_recaptcha_verify_response', $is_human, $response );
618
+
619
+ }
620
+
621
+ }
622
+
623
+ }
624
+ add_action( 'init', 'iqfix_recaptcha_class_init', 11 );
625
+
626
+
627
+ /**
628
+ * Add some inline CSS for the reCaptcha iframe
629
+ *
630
+ * @return void
631
+ */
632
+ function iqfix_recaptcha_inline_css() {
633
+
634
+ $iqfix_css ='.wpcf7 .wpcf7-recaptcha iframe {margin-bottom: 0;}';
635
+ wp_add_inline_style( 'contact-form-7', $iqfix_css );
636
+
637
+ }
638
add_action( 'wp_enqueue_scripts', 'iqfix_recaptcha_inline_css' );
wpcf7-recaptcha.php CHANGED
@@ -1,345 +1,407 @@
1
- <?php
2
- /**
3
- * Plugin Name: Contact Form 7 - reCaptcha v2
4
- * Description: ReCaptcha v2 Fix for Contact Form 7 5.1 and later.
5
- * Version: 1.1.8
6
- * Author: IQComputing
7
- * Author URI: http://www.iqcomputing.com/
8
- * License: GPL2
9
- * Text Domain: wpcf7-recaptcha
10
- */
11
-
12
-
13
- defined( 'ABSPATH' ) or die( 'You cannot be here.' );
14
-
15
-
16
- /**
17
- * IQComputing Contact Form 7 reCaptcha Fix, Deity Class
18
- */
19
- Class IQFix_WPCF7_Deity {
20
-
21
- public static $version = '1.1.8';
22
-
23
-
24
- /**
25
- * Class Registration, set up necessities
26
- *
27
- * @return void
28
- */
29
- public static function register() {
30
-
31
- $class = new self();
32
- $class->include_files();
33
- $class->action_hooks();
34
- $class->filter_hooks();
35
-
36
- }
37
-
38
-
39
- /**
40
- * Include any necessary files
41
- *
42
- * @return void
43
- */
44
- private function include_files() {
45
-
46
- $selection = WPCF7::get_option( 'iqfix_recaptcha' );
47
-
48
- // Prevent update from v2 to v3 notice.
49
- WPCF7::update_option( 'recaptcha_v2_v3_warning', false );
50
-
51
- if( empty( $selection ) || version_compare( WPCF7_VERSION, '5.1', '<' ) ) {
52
- return;
53
- }
54
-
55
- include_once( plugin_dir_path( __FILE__ ) . 'recaptcha-v2.php' );
56
-
57
- if( class_exists( 'Flamingo_Contact' ) ) {
58
- include_once( plugin_dir_path( __FILE__ ) . 'flamingo.php' ); // Flamingo updates
59
- }
60
-
61
- }
62
-
63
-
64
- /**
65
- * Add any necessary action hooks
66
- *
67
- * @return void
68
- */
69
- private function action_hooks() {
70
-
71
- add_action( 'admin_menu', array( $this, 'register_submenus' ) );
72
- add_action( 'network_admin_menu', array( $this, 'register_network_submenus' ) );
73
-
74
- }
75
-
76
-
77
- /**
78
- * Add any necessary filter hooks
79
- *
80
- * @return void
81
- */
82
- private function filter_hooks() {
83
-
84
- add_filter( 'option_wpcf7', array( $this, 'network_wpcf7_options' ), 9 );
85
-
86
- }
87
-
88
-
89
- /**
90
- * Register submenus for picking ReCaptcha versions
91
- *
92
- * @return void
93
- */
94
- public function register_submenus() {
95
-
96
- add_submenu_page(
97
- 'wpcf7',
98
- esc_html__( 'reCaptcha Version', 'wpcf7-recaptcha' ),
99
- esc_html__( 'reCaptcha Version', 'wpcf7-recaptcha' ),
100
- WPCF7_ADMIN_READ_WRITE_CAPABILITY,
101
- 'recaptcha-version',
102
- array( $this, 'display_recaptcha_version_subpage' )
103
- );
104
-
105
- }
106
-
107
-
108
- /**
109
- * Register submenus for the Network Admin Panel
110
- *
111
- * @return void
112
- */
113
- public function register_network_submenus() {
114
-
115
- add_submenu_page(
116
- 'plugins.php',
117
- esc_html__( 'WPCF7 reCaptcha Settings', 'wpcf7-recaptcha' ),
118
- esc_html__( 'WPCF7 reCaptcha Settings', 'wpcf7-recaptcha' ),
119
- 'manage_network_plugins',
120
- 'recaptcha-version',
121
- array( $this, 'display_recaptcha_version_subpage' )
122
- );
123
-
124
- }
125
-
126
-
127
- /**
128
- * Display reCaptcha version subpage
129
- *
130
- * @return void
131
- */
132
- public function display_recaptcha_version_subpage() {
133
-
134
- $updated = false;
135
-
136
- if( is_network_admin() ) {
137
- $network_options = get_site_option( 'network_iqfix_recaptcha' );
138
- $selection = ( ! empty( $network_options['iqfix_recaptcha'] ) ) ? $network_options['iqfix_recaptcha'] : '';
139
- $sitekey = ( ! empty( $network_options['sitekey'] ) ) ? $network_options['sitekey'] : '';
140
- $secretkey = ( ! empty( $network_options['secret'] ) ) ? $network_options['secret'] : '';
141
- } else {
142
- $selection = WPCF7::get_option( 'iqfix_recaptcha' );
143
- }
144
-
145
- // Update Option
146
- if( isset( $_POST, $_POST['iqfix_recaptcha_version'], $_POST['iqfix_wpcf7_submit'] ) ) {
147
-
148
- if( ! empty( $_POST['iqfix_wpcf7_nonce'] ) && wp_verify_nonce( $_POST['iqfix_wpcf7_nonce'], 'iqfix_wpcf7_vers_select' ) ) {
149
- $selection = intval( $_POST['iqfix_recaptcha_version'] );
150
-
151
- if( is_network_admin() && isset( $_POST['wpcf7_recaptcha_network'] ) ) {
152
-
153
- $sitekey = trim( $_POST['wpcf7_recaptcha_network']['sitekey'] );
154
- $secretkey = trim( $_POST['wpcf7_recaptcha_network']['secretkey'] );
155
-
156
- update_site_option( 'network_iqfix_recaptcha', array(
157
- 'sitekey' => $sitekey,
158
- 'secret' => $secretkey,
159
- 'iqfix_recaptcha' => $selection,
160
- ) );
161
-
162
- } else {
163
-
164
- WPCF7::update_option( 'iqfix_recaptcha', $selection );
165
-
166
- }
167
-
168
- $updated = true;
169
- }
170
-
171
- }
172
-
173
- // Show simple message
174
- if( version_compare( WPCF7_VERSION, '5.1', '<' ) ) {
175
- printf(
176
- '<div class="wrap"><h1>%1$s</h1><p>%2$s</p></div>',
177
- esc_html__( 'Contact Form 7 - reCaptcha v2', 'wpcf7-recaptcha' ),
178
- esc_html__( 'This version of Contact Form 7 already uses reCaptcha version 2, you do not need \'Contact Form 7 - reCaptcha v2\' installed at this time.', 'wpcf7-recaptcha' )
179
- );
180
- return;
181
- }
182
-
183
- ?>
184
-
185
- <div class="wrap">
186
- <style>
187
- #iqFacebook {margin-top: 40px;}
188
- #iqFacebook a {display: inline-block; margin-bottom: 12px;}
189
- #iqFacebook img {display: block; max-width: 100%; height: auto;}
190
- </style>
191
-
192
- <?php
193
-
194
- printf( '<h1>%1$s</h1>', esc_html__( 'Contact Form 7 - reCaptcha v2', 'wpcf7-recaptcha' ) );
195
-
196
- if( $updated ) {
197
- printf(
198
- '<div class="notice updated"><p>%1$s</p></div>',
199
- esc_html__( 'Your reCaptcha settings have been updated.', 'wpcf7-recaptcha' )
200
- );
201
- }
202
-
203
- /* translators: %s is a shortcode example wrapped in <code> tags. */
204
- printf( '<p>%1$s</p>',
205
- 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' ),
206
- '<code>[recaptcha]</code>'
207
- )
208
- );
209
- ?>
210
-
211
- <form method="post">
212
- <?php wp_nonce_field( 'iqfix_wpcf7_vers_select', 'iqfix_wpcf7_nonce' ); ?>
213
- <select name="iqfix_recaptcha_version">
214
- <option value="0"><?php esc_html_e( 'Default Usage', 'wpcf7-recaptcha' ); ?></option>
215
- <option value="2" <?php selected( $selection, 2, true ); ?>><?php esc_html_e( 'reCaptcha Version 2', 'wpcf7-recaptcha' ); ?></option>
216
- </select>
217
-
218
- <?php if( is_network_admin() ) : ?>
219
-
220
- <hr />
221
- <h2>Network Wide Settings</h2>
222
-
223
- <p><strong><?php _e( 'Please read all of the below before committing to these changes.', 'wpcf7-recaptcha' ); ?></strong></p>
224
- <p><?php _e( 'You may set Network wide API keys below. Please ensure that every network site is whitelisted in the Google API Console. ReCaptcha keys can still be set ( or unset ) on a per site basis if necessary.', 'wpcf7-recaptcha' ); ?></p>
225
- <p><?php
226
- /* translators: Care for HTML in string used for emphasis. */
227
- _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' );
228
- ?></p>
229
-
230
- <table class="form-table">
231
- <tbody>
232
- <tr>
233
- <th><?php _e( 'Site Key', 'wpcf7-recaptcha' ); ?></th>
234
- <td><input type="text" name="wpcf7_recaptcha_network[sitekey]" class="regular-text" value="<?php echo esc_attr( $sitekey ); ?>" /></td>
235
- </tr>
236
- <tr>
237
- <th><?php _e( 'Secret Key', 'wpcf7-recaptcha' ); ?></th>
238
- <td><input type="password" name="wpcf7_recaptcha_network[secretkey]" class="regular-text" value="<?php echo esc_attr( $secretkey ); ?>" /></td>
239
- </tr>
240
- </tbody>
241
- </table>
242
-
243
- <?php endif; ?>
244
-
245
- <?php submit_button( esc_html__( 'Submit', 'wpcf7-recaptcha' ), 'submit', 'iqfix_wpcf7_submit' ); ?>
246
- </form>
247
-
248
- <div id="iqFacebook">
249
- <?php
250
- printf( '<a href="%1$s" target="_blank"><img src="%2$s" width="540" height="410" alt="%3$s" /></a>',
251
- esc_url( 'https://www.facebook.com/iqcomputing' ),
252
- plugins_url( 'assets/images/facebook-like.png', __FILE__ ),
253
- /* translators: Image alternative tag. */
254
- esc_attr__( 'Like IQComputing on Facebook mascot', 'wpcf7-recaptcha' )
255
- );
256
- printf( '<p>%1$s</p>',
257
- esc_html__( 'Click the image above and like us on Facebook! Facebook is where you will receive the latest news on both this plugin and all future IQComputing plugins.', 'wpcf7-recaptcha' )
258
- );
259
- ?>
260
- </div> <!-- id="iqFacebook" -->
261
-
262
- </div>
263
-
264
- <?php
265
-
266
- }
267
-
268
-
269
- /**
270
- * Filter Hook into WPCF7 get option
271
- * Maybe replace it work a network option
272
- *
273
- * @param Mixed $value
274
- * @param Stirng $option_name
275
- *
276
- * @return Mixed $value
277
- */
278
- public function network_wpcf7_options( $value ) {
279
-
280
- // If we're not on a multisite setup we can skip this filter hook
281
- if( ! is_multisite() || empty( $value ) ) {
282
- return $value;
283
- }
284
-
285
- // Allow sites to be setup regardless of network specifciations
286
- if( is_admin()
287
- && isset( $_GET, $_GET['page'], $_GET['service'], $_GET['action'] )
288
- && 'wpcf7-integration' == $_GET['page']
289
- && 'recaptcha' == $_GET['service']
290
- && 'setup' == $_GET['action']
291
- ) {
292
- return $value;
293
- }
294
-
295
- // Grab Network Option
296
- $network_wpcf7 = get_site_option( 'network_iqfix_recaptcha' );
297
- $network_wpcf7 = array_filter( (array)$network_wpcf7 );
298
-
299
- // Set site keys IF there are no API keys set.
300
- if( empty( $value['recaptcha'] ) && ! empty( $network_wpcf7['sitekey'] ) && ! empty( $network_wpcf7['secret'] ) ) {
301
- $value['recaptcha'] = array(
302
- $network_wpcf7['sitekey'] => $network_wpcf7['secret'],
303
- );
304
- }
305
-
306
- // Set IQFix reCaptcha
307
- if( ! isset( $value['iqfix_recaptcha'] ) && ! empty( $network_wpcf7['iqfix_recaptcha'] ) ) {
308
- $value['iqfix_recaptcha'] = $network_wpcf7['iqfix_recaptcha'];
309
- }
310
-
311
- return $value;
312
-
313
- }
314
-
315
-
316
- } // END Class IQFix_WPCF7_Deity
317
-
318
-
319
- /**
320
- * Initialize Class
321
- *
322
- * @return void
323
- */
324
- function iqfix_wpcf7_deity_init() {
325
-
326
- if( class_exists( 'WPCF7' ) ) {
327
- IQFix_WPCF7_Deity::register();
328
- }
329
-
330
- }
331
- add_action( 'plugins_loaded', 'iqfix_wpcf7_deity_init' );
332
-
333
-
334
- /**
335
- * Remove upgrade notice from v2 to v3
336
- * Prevent api keys from being reset.
337
- *
338
- * @return void
339
- */
340
- function iqfix_wpcf7_upgrade_recaptcha_v2_v3_removal() {
341
-
342
- remove_action( 'wpcf7_upgrade', 'wpcf7_upgrade_recaptcha_v2_v3', 10 );
343
-
344
- }
345
add_action( 'admin_init', 'iqfix_wpcf7_upgrade_recaptcha_v2_v3_removal', 9 );
1
+ <?php
2
+ /**
3
+ * Plugin Name: Contact Form 7 - reCaptcha v2
4
+ * Description: ReCaptcha v2 Fix for Contact Form 7 5.1 and later.
5
+ * Version: 1.1.9
6
+ * Author: IQComputing
7
+ * Author URI: http://www.iqcomputing.com/
8
+ * License: GPL2
9
+ * Text Domain: wpcf7-recaptcha
10
+ */
11
+
12
+
13
+ defined( 'ABSPATH' ) or die( 'You cannot be here.' );
14
+
15
+
16
+ /**
17
+ * IQComputing Contact Form 7 reCaptcha Fix, Deity Class
18
+ */
19
+ Class IQFix_WPCF7_Deity {
20
+
21
+ public static $version = '1.1.9';
22
+
23
+
24
+ /**
25
+ * Class Registration, set up necessities
26
+ *
27
+ * @return void
28
+ */
29
+ public static function register() {
30
+
31
+ $class = new self();
32
+ $class->include_files();
33
+ $class->action_hooks();
34
+ $class->filter_hooks();
35
+
36
+ }
37
+
38
+
39
+ /**
40
+ * Really don't like dynamically assigning URLs by user saved options.
41
+ * This method will verify at every stage that the given value is either
42
+ * `google.com` or `recaptcha.net`
43
+ * Nowhere in between can this value be changed to anything but those two.
44
+ *
45
+ * @param $expectation
46
+ *
47
+ * @return $reality
48
+ */
49
+ public static function verify_recaptcha_source( $expectation = 'google.com' ) {
50
+
51
+ $reality = ( in_array( $expectation, array( 'google.com', 'recaptcha.net' ) ) ) ? $expectation : 'google.com';
52
+
53
+ return $reality;
54
+
55
+ }
56
+
57
+
58
+ /**
59
+ * Include any necessary files
60
+ *
61
+ * @return void
62
+ */
63
+ private function include_files() {
64
+
65
+ $selection = WPCF7::get_option( 'iqfix_recaptcha' );
66
+
67
+ // Prevent update from v2 to v3 notice.
68
+ WPCF7::update_option( 'recaptcha_v2_v3_warning', false );
69
+
70
+ if( empty( $selection ) || version_compare( WPCF7_VERSION, '5.1', '<' ) ) {
71
+ return;
72
+ }
73
+
74
+ include_once( plugin_dir_path( __FILE__ ) . 'recaptcha-v2.php' );
75
+
76
+ if( class_exists( 'Flamingo_Contact' ) ) {
77
+ include_once( plugin_dir_path( __FILE__ ) . 'flamingo.php' ); // Flamingo updates
78
+ }
79
+
80
+ }
81
+
82
+
83
+ /**
84
+ * Save the reCaptcha settings from our options page
85
+ * @see IQFix_WPCF7_Deity::display_recaptcha_version_subpage()
86
+ *
87
+ * @return Boolean
88
+ */
89
+ private function save_recaptcha_settings() {
90
+
91
+ // Form hasn't POSTed, return early
92
+ if( ! isset( $_POST, $_POST['iqfix_recaptcha_version'], $_POST['iqfix_wpcf7_submit'] ) ) {
93
+ return false;
94
+ }
95
+
96
+ // Ensure we have and can verify our nonce. IF not, return early
97
+ if( ! ( ! empty( $_POST['iqfix_wpcf7_nonce'] ) && wp_verify_nonce( $_POST['iqfix_wpcf7_nonce'], 'iqfix_wpcf7_vers_select' ) ) ) {
98
+ return false;
99
+ }
100
+
101
+ $selection = intval( $_POST['iqfix_recaptcha_version'] );
102
+ $source = ( isset( $_POST, $_POST['iqfix_recaptcha_source'] ) ) ? sanitize_text_field( $_POST['iqfix_recaptcha_source'] ) : 'google.com';
103
+ $source = self::verify_recaptcha_source( $source );
104
+
105
+ // Save Network Settings
106
+ if( is_network_admin() && isset( $_POST['wpcf7_recaptcha_network'] ) ) {
107
+
108
+ $sitekey = trim( $_POST['wpcf7_recaptcha_network']['sitekey'] );
109
+ $secretkey = trim( $_POST['wpcf7_recaptcha_network']['secretkey'] );
110
+
111
+ update_site_option( 'network_iqfix_recaptcha', array(
112
+ 'sitekey' => $sitekey,
113
+ 'secret' => $secretkey,
114
+ 'iqfix_recaptcha' => $selection,
115
+ 'recaptcha_source' => $source,
116
+ ) );
117
+
118
+ // Save Regular WPCF7 Settings
119
+ } else {
120
+
121
+ WPCF7::update_option( 'iqfix_recaptcha', $selection );
122
+ WPCF7::update_option( 'iqfix_recaptcha_source', $source );
123
+
124
+ }
125
+
126
+ return true;
127
+
128
+ }
129
+
130
+
131
+ /**
132
+ * Add any necessary action hooks
133
+ *
134
+ * @return void
135
+ */
136
+ private function action_hooks() {
137
+
138
+ add_action( 'admin_menu', array( $this, 'register_submenus' ) );
139
+ add_action( 'network_admin_menu', array( $this, 'register_network_submenus' ) );
140
+
141
+ }
142
+
143
+
144
+ /**
145
+ * Add any necessary filter hooks
146
+ *
147
+ * @return void
148
+ */
149
+ private function filter_hooks() {
150
+
151
+ add_filter( 'option_wpcf7', array( $this, 'network_wpcf7_options' ), 9 );
152
+
153
+ }
154
+
155
+
156
+ /**
157
+ * Register submenus for picking ReCaptcha versions
158
+ *
159
+ * @return void
160
+ */
161
+ public function register_submenus() {
162
+
163
+ add_submenu_page(
164
+ 'wpcf7',
165
+ esc_html__( 'reCaptcha Version', 'wpcf7-recaptcha' ),
166
+ esc_html__( 'reCaptcha Version', 'wpcf7-recaptcha' ),
167
+ WPCF7_ADMIN_READ_WRITE_CAPABILITY,
168
+ 'recaptcha-version',
169
+ array( $this, 'display_recaptcha_version_subpage' )
170
+ );
171
+
172
+ }
173
+
174
+
175
+ /**
176
+ * Register submenus for the Network Admin Panel
177
+ *
178
+ * @return void
179
+ */
180
+ public function register_network_submenus() {
181
+
182
+ add_submenu_page(
183
+ 'plugins.php',
184
+ esc_html__( 'WPCF7 reCaptcha Settings', 'wpcf7-recaptcha' ),
185
+ esc_html__( 'WPCF7 reCaptcha Settings', 'wpcf7-recaptcha' ),
186
+ 'manage_network_plugins',
187
+ 'recaptcha-version',
188
+ array( $this, 'display_recaptcha_version_subpage' )
189
+ );
190
+
191
+ }
192
+
193
+
194
+ /**
195
+ * Display reCaptcha version subpage
196
+ *
197
+ * @return void
198
+ */
199
+ public function display_recaptcha_version_subpage() {
200
+
201
+ $updated = $this->save_recaptcha_settings();
202
+
203
+ // Grab Network Settings
204
+ if( is_network_admin() ) {
205
+
206
+ $network_options = get_site_option( 'network_iqfix_recaptcha' );
207
+ $selection = ( ! empty( $network_options['iqfix_recaptcha'] ) ) ? $network_options['iqfix_recaptcha'] : '';
208
+ $source = ( ! empty( $network_options['recaptcha_source'] ) ) ? $network_options['recaptcha_source'] : '';
209
+ $sitekey = ( ! empty( $network_options['sitekey'] ) ) ? $network_options['sitekey'] : '';
210
+ $secretkey = ( ! empty( $network_options['secret'] ) ) ? $network_options['secret'] : '';
211
+
212
+ // Grab Site Settings
213
+ } else {
214
+
215
+ $selection = WPCF7::get_option( 'iqfix_recaptcha' );
216
+ $source = WPCF7::get_option( 'iqfix_recaptcha_source' );
217
+
218
+ }
219
+
220
+ // Show simple message
221
+ if( version_compare( WPCF7_VERSION, '5.1', '<' ) ) {
222
+ printf(
223
+ '<div class="wrap"><h1>%1$s</h1><p>%2$s</p></div>',
224
+ esc_html__( 'Contact Form 7 - reCaptcha v2', 'wpcf7-recaptcha' ),
225
+ esc_html__( 'This version of Contact Form 7 already uses reCaptcha version 2, you do not need \'Contact Form 7 - reCaptcha v2\' installed at this time.', 'wpcf7-recaptcha' )
226
+ );
227
+ return;
228
+ }
229
+
230
+ ?>
231
+
232
+ <div class="wrap">
233
+ <style>
234
+ #iqFacebook {margin-top: 40px;}
235
+ #iqFacebook a {display: inline-block; margin-bottom: 12px;}
236
+ #iqFacebook img {display: block; max-width: 100%; height: auto;}
237
+ </style>
238
+
239
+ <?php
240
+
241
+ printf( '<h1>%1$s</h1>', esc_html__( 'Contact Form 7 - reCaptcha v2', 'wpcf7-recaptcha' ) );
242
+
243
+ if( $updated ) {
244
+ printf(
245
+ '<div class="notice updated"><p>%1$s</p></div>',
246
+ esc_html__( 'Your reCaptcha settings have been updated.', 'wpcf7-recaptcha' )
247
+ );
248
+ }
249
+
250
+ /* translators: %s is a shortcode example wrapped in <code> tags. */
251
+ printf( '<p>%1$s</p>',
252
+ 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' ),
253
+ '<code>[recaptcha]</code>'
254
+ )
255
+ );
256
+ ?>
257
+
258
+ <form method="post">
259
+ <?php wp_nonce_field( 'iqfix_wpcf7_vers_select', 'iqfix_wpcf7_nonce' ); ?>
260
+
261
+ <label for="iqfix_recaptcha_version"><strong><?php esc_html_e( 'Select reCaptcha Usage' ); ?>:</strong></label><br />
262
+ <select id="iqfix_recaptcha_version" name="iqfix_recaptcha_version">
263
+ <option value="0"><?php esc_html_e( 'Default Usage', 'wpcf7-recaptcha' ); ?></option>
264
+ <option value="2" <?php selected( $selection, 2, true ); ?>><?php esc_html_e( 'reCaptcha Version 2', 'wpcf7-recaptcha' ); ?></option>
265
+ </select>
266
+
267
+ <?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.' ) ); ?>
268
+
269
+ <label for="iqfix_recaptcha_source"><strong><?php esc_html_e( 'Select reCaptcha Source' ); ?>:</strong></label><br />
270
+ <select id="iqfix_recaptcha_source" name="iqfix_recaptcha_source">
271
+ <option value="google.com">google.com</option>
272
+ <option value="recaptcha.net" <?php selected( $source, 'recaptcha.net', true ); ?>>recaptcha.net</option>
273
+ </select>
274
+
275
+ <?php if( is_network_admin() ) : ?>
276
+
277
+ <hr />
278
+ <h2><?php esc_html__( 'Network Wide Settings' ); ?></h2>
279
+
280
+ <p><strong><?php _e( 'Please read all of the below before committing to these changes.', 'wpcf7-recaptcha' ); ?></strong></p>
281
+ <p><?php _e( 'You may set Network wide API keys below. Please ensure that every network site is whitelisted in the Google API Console. ReCaptcha keys can still be set ( or unset ) on a per site basis if necessary.', 'wpcf7-recaptcha' ); ?></p>
282
+ <p><?php
283
+ /* translators: Care for HTML in string used for emphasis. */
284
+ _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' );
285
+ ?></p>
286
+
287
+ <table class="form-table">
288
+ <tbody>
289
+ <tr>
290
+ <th><?php _e( 'Site Key', 'wpcf7-recaptcha' ); ?></th>
291
+ <td><input type="text" name="wpcf7_recaptcha_network[sitekey]" class="regular-text" value="<?php echo esc_attr( $sitekey ); ?>" /></td>
292
+ </tr>
293
+ <tr>
294
+ <th><?php _e( 'Secret Key', 'wpcf7-recaptcha' ); ?></th>
295
+ <td><input type="password" name="wpcf7_recaptcha_network[secretkey]" class="regular-text" value="<?php echo esc_attr( $secretkey ); ?>" /></td>
296
+ </tr>
297
+ </tbody>
298
+ </table>
299
+
300
+ <?php endif; ?>
301
+
302
+ <?php submit_button( esc_html__( 'Submit', 'wpcf7-recaptcha' ), 'submit', 'iqfix_wpcf7_submit' ); ?>
303
+ </form>
304
+
305
+ <div id="iqFacebook">
306
+ <?php
307
+ printf( '<a href="%1$s" target="_blank"><img src="%2$s" width="540" height="410" alt="%3$s" /></a>',
308
+ esc_url( 'https://www.facebook.com/iqcomputing' ),
309
+ plugins_url( 'assets/images/facebook-like.png', __FILE__ ),
310
+ /* translators: Image alternative tag. */
311
+ esc_attr__( 'Like IQComputing on Facebook mascot', 'wpcf7-recaptcha' )
312
+ );
313
+ printf( '<p>%1$s</p>',
314
+ esc_html__( 'Click the image above and like us on Facebook! Facebook is where you will receive the latest news on both this plugin and all future IQComputing plugins.', 'wpcf7-recaptcha' )
315
+ );
316
+ ?>
317
+ </div> <!-- id="iqFacebook" -->
318
+
319
+ </div>
320
+
321
+ <?php
322
+
323
+ }
324
+
325
+
326
+ /**
327
+ * Filter Hook into WPCF7 get option
328
+ * Maybe replace it work a network option
329
+ *
330
+ * @param Mixed $value
331
+ * @param Stirng $option_name
332
+ *
333
+ * @return Mixed $value
334
+ */
335
+ public function network_wpcf7_options( $value ) {
336
+
337
+ // If we're not on a multisite setup we can skip this filter hook
338
+ if( ! is_multisite() || empty( $value ) ) {
339
+ return $value;
340
+ }
341
+
342
+ // Allow sites to be setup regardless of network specifciations
343
+ if( is_admin()
344
+ && isset( $_GET, $_GET['page'], $_GET['service'], $_GET['action'] )
345
+ && 'wpcf7-integration' == $_GET['page']
346
+ && 'recaptcha' == $_GET['service']
347
+ && 'setup' == $_GET['action']
348
+ ) {
349
+ return $value;
350
+ }
351
+
352
+ // Grab Network Option
353
+ $network_wpcf7 = get_site_option( 'network_iqfix_recaptcha' );
354
+ $network_wpcf7 = array_filter( (array)$network_wpcf7 );
355
+
356
+ // Set site keys IF there are no API keys set.
357
+ if( empty( $value['recaptcha'] ) && ! empty( $network_wpcf7['sitekey'] ) && ! empty( $network_wpcf7['secret'] ) ) {
358
+ $value['recaptcha'] = array(
359
+ $network_wpcf7['sitekey'] => $network_wpcf7['secret'],
360
+ );
361
+ }
362
+
363
+ // Set IQFix reCaptcha
364
+ if( ! isset( $value['iqfix_recaptcha'] ) && ! empty( $network_wpcf7['iqfix_recaptcha'] ) ) {
365
+ $value['iqfix_recaptcha'] = $network_wpcf7['iqfix_recaptcha'];
366
+ }
367
+
368
+ // Set IQFix reCaptcha Source
369
+ if( ! isset( $value['iqfix_recaptcha_source'] ) && ! empty( $network_wpcf7['recaptcha_source'] ) ) {
370
+ $value['iqfix_recaptcha_source'] = $network_wpcf7['recaptcha_source'];
371
+ }
372
+
373
+ return $value;
374
+
375
+ }
376
+
377
+
378
+ } // END Class IQFix_WPCF7_Deity
379
+
380
+
381
+ /**
382
+ * Initialize Class
383
+ *
384
+ * @return void
385
+ */
386
+ function iqfix_wpcf7_deity_init() {
387
+
388
+ if( class_exists( 'WPCF7' ) ) {
389
+ IQFix_WPCF7_Deity::register();
390
+ }
391
+
392
+ }
393
+ add_action( 'plugins_loaded', 'iqfix_wpcf7_deity_init' );
394
+
395
+
396
+ /**
397
+ * Remove upgrade notice from v2 to v3
398
+ * Prevent api keys from being reset.
399
+ *
400
+ * @return void
401
+ */
402
+ function iqfix_wpcf7_upgrade_recaptcha_v2_v3_removal() {
403
+
404
+ remove_action( 'wpcf7_upgrade', 'wpcf7_upgrade_recaptcha_v2_v3', 10 );
405
+
406
+ }
407
add_action( 'admin_init', 'iqfix_wpcf7_upgrade_recaptcha_v2_v3_removal', 9 );