Version Description
(2020-06-14) = * Updated the controls JS file to be encapsulated. * Added the reCaptcha error messages to the Contact Form 7 "Messages" screen so they may be changed.
Download this release
Release Info
Developer | IQComputing |
Plugin | Contact Form 7 – reCaptcha v2 |
Version | 1.3.4 |
Comparing to | |
See all releases |
Code changes from version 1.3.3 to 1.3.4
- assets/js/wpcf7-recaptcha-controls.js +59 -55
- changelog.txt +12 -0
- readme.txt +6 -6
- recaptcha-v2.php +30 -4
- wpcf7-recaptcha.php +2 -2
assets/js/wpcf7-recaptcha-controls.js
CHANGED
@@ -1,61 +1,65 @@
|
|
1 |
-
|
2 |
-
recaptchaCallback = function() {
|
3 |
|
4 |
-
let
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
let
|
9 |
-
|
10 |
-
for ( let j = 0; j < recaptchas.length; j++ ) {
|
11 |
-
let sitekey = recaptchas[ j ].getAttribute( 'data-sitekey' );
|
12 |
-
|
13 |
-
if ( recaptchas[ j ].className && recaptchas[ j ].className.match( pattern ) && sitekey ) {
|
14 |
-
let params = {
|
15 |
-
'sitekey': sitekey,
|
16 |
-
'type': recaptchas[ j ].getAttribute( 'data-type' ),
|
17 |
-
'size': recaptchas[ j ].getAttribute( 'data-size' ),
|
18 |
-
'theme': recaptchas[ j ].getAttribute( 'data-theme' ),
|
19 |
-
'align': recaptchas[ j ].getAttribute( 'data-align' ),
|
20 |
-
'badge': recaptchas[ j ].getAttribute( 'data-badge' ),
|
21 |
-
'tabindex': recaptchas[ j ].getAttribute( 'data-tabindex' )
|
22 |
-
};
|
23 |
-
|
24 |
-
let callback = recaptchas[ j ].getAttribute( 'data-callback' );
|
25 |
-
|
26 |
-
if ( callback && 'function' == typeof window[ callback ] ) {
|
27 |
-
params[ 'callback' ] = window[ callback ];
|
28 |
-
}
|
29 |
|
30 |
-
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
if (
|
33 |
-
params
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
39 |
}
|
40 |
}
|
41 |
-
}
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
}
|
61 |
-
|
|
1 |
+
( function() {
|
|
|
2 |
|
3 |
+
let recaptchaWidgets = [];
|
4 |
+
recaptchaCallback = function() {
|
5 |
+
|
6 |
+
let forms = document.getElementsByTagName( 'form' );
|
7 |
+
let pattern = /(^|\s)g-recaptcha(\s|$)/;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
for ( let i = 0; i < forms.length; i++ ) {
|
10 |
+
let recaptchas = forms[ i ].getElementsByClassName( 'wpcf7-recaptcha' );
|
11 |
+
|
12 |
+
for ( let j = 0; j < recaptchas.length; j++ ) {
|
13 |
+
let sitekey = recaptchas[ j ].getAttribute( 'data-sitekey' );
|
14 |
|
15 |
+
if ( recaptchas[ j ].className && recaptchas[ j ].className.match( pattern ) && sitekey ) {
|
16 |
+
let params = {
|
17 |
+
'sitekey': sitekey,
|
18 |
+
'type': recaptchas[ j ].getAttribute( 'data-type' ),
|
19 |
+
'size': recaptchas[ j ].getAttribute( 'data-size' ),
|
20 |
+
'theme': recaptchas[ j ].getAttribute( 'data-theme' ),
|
21 |
+
'align': recaptchas[ j ].getAttribute( 'data-align' ),
|
22 |
+
'badge': recaptchas[ j ].getAttribute( 'data-badge' ),
|
23 |
+
'tabindex': recaptchas[ j ].getAttribute( 'data-tabindex' )
|
24 |
+
};
|
25 |
+
|
26 |
+
let callback = recaptchas[ j ].getAttribute( 'data-callback' );
|
27 |
+
|
28 |
+
if ( callback && 'function' == typeof window[ callback ] ) {
|
29 |
+
params[ 'callback' ] = window[ callback ];
|
30 |
+
}
|
31 |
+
|
32 |
+
let expired_callback = recaptchas[ j ].getAttribute( 'data-expired-callback' );
|
33 |
+
|
34 |
+
if ( expired_callback && 'function' == typeof window[ expired_callback ] ) {
|
35 |
+
params[ 'expired-callback' ] = window[ expired_callback ];
|
36 |
+
}
|
37 |
|
38 |
+
let widget_id = grecaptcha.render( recaptchas[ j ], params );
|
39 |
+
recaptchaWidgets.push( widget_id );
|
40 |
+
break;
|
41 |
+
}
|
42 |
}
|
43 |
}
|
44 |
+
};
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Reset the reCaptcha when Contact Form 7 gives us:
|
48 |
+
* - Spam
|
49 |
+
* - Success
|
50 |
+
* - Fail
|
51 |
+
*
|
52 |
+
* @return void
|
53 |
+
*/
|
54 |
+
document.addEventListener( 'wpcf7submit', function( event ) {
|
55 |
+
switch ( event.detail.status ) {
|
56 |
+
case 'spam':
|
57 |
+
case 'mail_sent':
|
58 |
+
case 'mail_failed':
|
59 |
+
for ( let i = 0; i < recaptchaWidgets.length; i++ ) {
|
60 |
+
grecaptcha.reset( recaptchaWidgets[ i ] );
|
61 |
+
}
|
62 |
+
}
|
63 |
+
}, false );
|
64 |
+
|
65 |
+
} )();
|
changelog.txt
CHANGED
@@ -2,6 +2,18 @@
|
|
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.3 =
|
6 |
|
7 |
Release Date: March 01, 2021
|
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.4 =
|
6 |
+
|
7 |
+
Release Date: June 14, 2021
|
8 |
+
|
9 |
+
* Overview
|
10 |
+
* Allow users to edit the reCaptcha messages via the "Messages" tab when editing a form. A fallback translation is still provided for older forms.
|
11 |
+
* Encapsulated the controls JS file to make it easier for optimize plugins to include our script in their script soup file.
|
12 |
+
|
13 |
+
* Code Changes
|
14 |
+
* Encapsulated the JS in the assets/wpcf7-recaptcha-controls.js file.
|
15 |
+
* Added CF7 filter "wpcf7_messages" to allow users to change validation messages.
|
16 |
+
|
17 |
= 1.3.3 =
|
18 |
|
19 |
Release Date: March 01, 2021
|
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.6
|
6 |
-
Stable tag: 1.3.
|
7 |
License: GPLv2 or later
|
8 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -60,13 +60,13 @@ Should the above be correct, at this point it's time to open a support thread fo
|
|
60 |
|
61 |
== Changelog ==
|
62 |
|
|
|
|
|
|
|
|
|
63 |
= 1.3.3 (2020-03-01) =
|
64 |
* Updated reCaptcha HTML to be wrapped in span tag as Contact Form 7 expects.
|
65 |
* Updated javascript to reflect HTML change above.
|
66 |
|
67 |
= 1.3.2 (2020-02-25) =
|
68 |
-
* Updated the remove action hook priority for wpcf7_recaptcha_enqueue_scripts from 10 to 20
|
69 |
-
|
70 |
-
= 1.3.0 (2020-12-21) =
|
71 |
-
* Removed `iqfix_wpcf7_recaptcha_callback_script()` function
|
72 |
-
* Enqueued reCaptcha controls based on whether google reCaptcha is enqueued.
|
3 |
Tags: contact-form-7, contact-form-7-recaptcha, recaptcha, spam
|
4 |
Requires at least: 4.9
|
5 |
Tested up to: 5.6
|
6 |
+
Stable tag: 1.3.4
|
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.4 (2020-06-14) =
|
64 |
+
* Updated the controls JS file to be encapsulated.
|
65 |
+
* Added the reCaptcha error messages to the Contact Form 7 "Messages" screen so they may be changed.
|
66 |
+
|
67 |
= 1.3.3 (2020-03-01) =
|
68 |
* Updated reCaptcha HTML to be wrapped in span tag as Contact Form 7 expects.
|
69 |
* Updated javascript to reflect HTML change above.
|
70 |
|
71 |
= 1.3.2 (2020-02-25) =
|
72 |
+
* Updated the remove action hook priority for wpcf7_recaptcha_enqueue_scripts from 10 to 20
|
|
|
|
|
|
|
|
recaptcha-v2.php
CHANGED
@@ -69,7 +69,7 @@ function iqfix_wpcf7_recaptcha_enqueue_scripts() {
|
|
69 |
'render' => 'explicit',
|
70 |
), $url );
|
71 |
|
72 |
-
wp_register_script( 'wpcf7-recaptcha-controls', plugins_url( 'assets/js/wpcf7-recaptcha-controls.js', __FILE__ ), array(), '1.
|
73 |
wp_register_script( 'google-recaptcha', $url, array( 'wpcf7-recaptcha-controls' ), '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' ),
|
@@ -598,16 +598,18 @@ function iqfix_recaptcha_validation( $result, $tag ) {
|
|
598 |
$tag->name = 'recaptcha';
|
599 |
if( ! isset( $_POST['g-recaptcha-response'] ) ) {
|
600 |
|
|
|
601 |
$result->invalidate(
|
602 |
$tag,
|
603 |
-
|
604 |
);
|
605 |
|
606 |
} else if( empty( $_POST['g-recaptcha-response'] ) ) {
|
607 |
|
|
|
608 |
$result->invalidate(
|
609 |
$tag,
|
610 |
-
|
611 |
);
|
612 |
|
613 |
}
|
@@ -616,4 +618,28 @@ function iqfix_recaptcha_validation( $result, $tag ) {
|
|
616 |
|
617 |
}
|
618 |
add_filter( 'wpcf7_validate_recaptcha', 'iqfix_recaptcha_validation', 10, 2 );
|
619 |
-
add_filter( 'wpcf7_validate_recaptcha*', 'iqfix_recaptcha_validation', 10, 2 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
'render' => 'explicit',
|
70 |
), $url );
|
71 |
|
72 |
+
wp_register_script( 'wpcf7-recaptcha-controls', plugins_url( 'assets/js/wpcf7-recaptcha-controls.js', __FILE__ ), array(), '1.2', true );
|
73 |
wp_register_script( 'google-recaptcha', $url, array( 'wpcf7-recaptcha-controls' ), '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' ),
|
598 |
$tag->name = 'recaptcha';
|
599 |
if( ! isset( $_POST['g-recaptcha-response'] ) ) {
|
600 |
|
601 |
+
$invalidate = wpcf7_get_message( 'iqfix_recaptcha_no_set' );
|
602 |
$result->invalidate(
|
603 |
$tag,
|
604 |
+
( ( ! empty( $invalidate ) ) ? $invalidate : __( 'Could not verify the reCaptcha response.', 'wpcf7-recaptcha' ) )
|
605 |
);
|
606 |
|
607 |
} else if( empty( $_POST['g-recaptcha-response'] ) ) {
|
608 |
|
609 |
+
$invalidate = wpcf7_get_message( 'iqfix_recaptcha_response_empty' );
|
610 |
$result->invalidate(
|
611 |
$tag,
|
612 |
+
( ( ! empty( $invalidate ) ) ? $invalidate : __( 'Please verify that you are not a robot.', 'wpcf7-recaptcha' ) )
|
613 |
);
|
614 |
|
615 |
}
|
618 |
|
619 |
}
|
620 |
add_filter( 'wpcf7_validate_recaptcha', 'iqfix_recaptcha_validation', 10, 2 );
|
621 |
+
add_filter( 'wpcf7_validate_recaptcha*', 'iqfix_recaptcha_validation', 10, 2 );
|
622 |
+
|
623 |
+
|
624 |
+
/**
|
625 |
+
* Add reCaptcha message settings to Contact Form 7
|
626 |
+
*
|
627 |
+
* @param String $message
|
628 |
+
*
|
629 |
+
* @return String $message
|
630 |
+
*/
|
631 |
+
function iqfix_recaptcha_messages( $messages ) {
|
632 |
+
|
633 |
+
return array_merge( $messages, array(
|
634 |
+
'iqfix_recaptcha_no_set' => array(
|
635 |
+
'description' => __( 'This message shows whenever the reCaptcha is completely blocked. Added by plugin: ReCaptcha for Contact Form 7.', 'wpcf7-recaptcha' ),
|
636 |
+
'default' => __( 'Could not verify the reCaptcha response.', 'wpcf7-recaptcha' ),
|
637 |
+
),
|
638 |
+
'iqfix_recaptcha_response_empty' => array(
|
639 |
+
'description' => __( 'This message shows whenever the reCaptcha is unchecked upon submission. Added by plugin: ReCaptcha for Contact Form 7.', 'wpcf7-recaptcha' ),
|
640 |
+
'default' => __( 'Please verify that you are not a robot.', 'wpcf7-recaptcha' ),
|
641 |
+
),
|
642 |
+
) );
|
643 |
+
|
644 |
+
}
|
645 |
+
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.
|
6 |
* Author: IQComputing
|
7 |
* Author URI: http://www.iqcomputing.com/
|
8 |
* License: GPL2
|
@@ -24,7 +24,7 @@ Class IQFix_WPCF7_Deity {
|
|
24 |
*
|
25 |
* @var String
|
26 |
*/
|
27 |
-
public static $version = '1.3.
|
28 |
|
29 |
|
30 |
/**
|
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.4
|
6 |
* Author: IQComputing
|
7 |
* Author URI: http://www.iqcomputing.com/
|
8 |
* License: GPL2
|
24 |
*
|
25 |
* @var String
|
26 |
*/
|
27 |
+
public static $version = '1.3.4';
|
28 |
|
29 |
|
30 |
/**
|