Skip to content

Commit ea504aa

Browse files
kagg-designhCaptcha GHA
andauthored
V4.21.1 (#445)
* Fix hCaptcha not loading on Contact Form 7. * Fix hCaptcha not loading on Contact Form 7. * Bump version to 4.21.1. * Update changelog from readme.txt * Respect dependency of cf7 scripts on main hcaptcha script. --------- Co-authored-by: hCaptcha GHA <[email protected]>
1 parent 02af3b9 commit ea504aa

File tree

8 files changed

+19
-8
lines changed

8 files changed

+19
-8
lines changed

assets/js/hcaptcha-cf7.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ document.addEventListener( 'DOMContentLoaded', function() {
1111
return form;
1212
} );
1313
} );
14+
15+
document.addEventListener( 'DOMContentLoaded', hCaptchaBindEvents );

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
= 4.21.1 =
2+
* Fixed hCaptcha not loading on Contact Form 7.
3+
14
= 4.21.0 =
25
* Added AI-ready security actions via the WordPress Abilities API, enabling automated threat inspection and response.
36
* Added compatibility with the latest version of the Ninja Forms plugin.

hcaptcha.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Plugin Name: hCaptcha for WP
1111
* Plugin URI: https://www.hcaptcha.com/
1212
* Description: hCaptcha keeps out bots and spam while putting privacy first. It is a drop-in replacement for reCAPTCHA.
13-
* Version: 4.21.0
13+
* Version: 4.21.1
1414
* Requires at least: 5.3
1515
* Requires PHP: 7.2
1616
* Author: hCaptcha
@@ -39,7 +39,7 @@
3939
/**
4040
* Plugin version.
4141
*/
42-
const HCAPTCHA_VERSION = '4.21.0';
42+
const HCAPTCHA_VERSION = '4.21.1';
4343

4444
/**
4545
* Path to the plugin dir.

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: captcha, hcaptcha, antispam, abuse, protect
44
Requires at least: 5.3
55
Tested up to: 6.9
66
Requires PHP: 7.2
7-
Stable tag: 4.21.0
7+
Stable tag: 4.21.1
88
License: GPLv2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -852,6 +852,9 @@ Instructions for popular native integrations are below:
852852

853853
== Changelog ==
854854

855+
= 4.21.1 =
856+
* Fixed hCaptcha not loading on Contact Form 7.
857+
855858
= 4.21.0 =
856859
* Added AI-ready security actions via the WordPress Abilities API, enabling automated threat inspection and response.
857860
* Added compatibility with the latest version of the Ninja Forms plugin.

src/js/hcaptcha/hcaptcha.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,12 +590,12 @@ class HCaptcha {
590590
this.getForms().map( ( formElement ) => {
591591
const hcaptchaElement = formElement.querySelector( '.h-captcha' );
592592

593-
if ( el && ( el !== hcaptchaElement ) ) {
593+
// Ignore forms not having hcaptcha.
594+
if ( null === hcaptchaElement ) {
594595
return formElement;
595596
}
596597

597-
// Ignore forms not having hcaptcha.
598-
if ( null === hcaptchaElement ) {
598+
if ( ( el instanceof HTMLElement ) && ( el !== hcaptchaElement ) ) {
599599
return formElement;
600600
}
601601

src/php/CF7/Admin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace HCaptcha\CF7;
1212

1313
use HCaptcha\Helpers\Pages;
14+
use HCaptcha\Main;
1415
use WPCF7_ContactForm;
1516
use WPCF7_TagGenerator;
1617
use WPCF7_TagGeneratorGenerator;
@@ -307,7 +308,7 @@ public function enqueue_admin_scripts_before_cf7(): void {
307308
wp_enqueue_script(
308309
self::HANDLE,
309310
HCAPTCHA_URL . "/assets/js/hcaptcha-cf7$min.js",
310-
[],
311+
[ Main::HANDLE ],
311312
HCAPTCHA_VERSION,
312313
true
313314
);

src/php/CF7/CF7.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use HCaptcha\Helpers\API;
1414
use HCaptcha\Helpers\HCaptcha;
15+
use HCaptcha\Main;
1516
use WPCF7_FormTag;
1617
use WPCF7_Submission;
1718
use WPCF7_Validation;
@@ -309,7 +310,7 @@ public function enqueue_scripts(): void {
309310
wp_enqueue_script(
310311
self::HANDLE,
311312
HCAPTCHA_URL . "/assets/js/hcaptcha-cf7$min.js",
312-
[],
313+
[ Main::HANDLE ],
313314
HCAPTCHA_VERSION,
314315
true
315316
);

tests/js/assets-js-files/hcaptcha-cf7.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe( 'hCaptcha Contact Form 7', () => {
1818

1919
require( '../../../assets/js/hcaptcha-cf7.js' );
2020
document.dispatchEvent( new Event( 'DOMContentLoaded' ) );
21+
hCaptchaBindEvents.mockClear();
2122
} );
2223

2324
afterEach( () => {

0 commit comments

Comments
 (0)