From 7aed0e991658dbda68c4a8d793e74b8e56b1929e Mon Sep 17 00:00:00 2001 From: kagg-design Date: Tue, 28 Jan 2025 23:48:57 +0300 Subject: [PATCH] Add support for wp_login_form() function and LoginOut block. --- .tests/php/integration/AAAMainTest.php | 3 +- readme.txt | 1 + src/php/Main.php | 2 +- src/php/WP/Login.php | 6 --- src/php/WP/LoginOut.php | 60 ++++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 src/php/WP/LoginOut.php diff --git a/.tests/php/integration/AAAMainTest.php b/.tests/php/integration/AAAMainTest.php index 9cd812fa..38f9d1b7 100644 --- a/.tests/php/integration/AAAMainTest.php +++ b/.tests/php/integration/AAAMainTest.php @@ -34,6 +34,7 @@ use HCaptcha\WCWishlists\CreateList; use HCaptcha\WP\Comment; use HCaptcha\WP\Login; +use HCaptcha\WP\LoginOut; use HCaptcha\WP\LostPassword; use HCaptcha\WP\PasswordProtected; use HCaptcha\WP\Register; @@ -1295,7 +1296,7 @@ public function dp_test_load_modules(): array { 'Login Form' => [ [ 'wp_status', 'login' ], '', - Login::class, + [ Login::class, LoginOut::class ], ], 'Lost Password Form' => [ [ 'wp_status', 'lost_pass' ], diff --git a/readme.txt b/readme.txt index 1cfb0686..a15d55d1 100644 --- a/readme.txt +++ b/readme.txt @@ -628,6 +628,7 @@ Instructions for popular native integrations are below: == Changelog == = 4.10.0 = +* Added support for wp_login_form() function and LoginOut block. * Added support for hCaptcha in HTML Gravity Forms fields. * Added support for custom nonce action and name in the [hcaptcha] shortcode. * Added compatibility with Cookies and Content Security Policy plugin. diff --git a/src/php/Main.php b/src/php/Main.php index 4a049a6f..63d41789 100644 --- a/src/php/Main.php +++ b/src/php/Main.php @@ -832,7 +832,7 @@ public function load_modules(): void { 'Login Form' => [ [ 'wp_status', 'login' ], '', - WP\Login::class, + [ WP\Login::class, WP\LoginOut::class ], ], 'Lost Password Form' => [ [ 'wp_status', 'lost_pass' ], diff --git a/src/php/WP/Login.php b/src/php/WP/Login.php index edd4b0dc..a4a78c42 100644 --- a/src/php/WP/Login.php +++ b/src/php/WP/Login.php @@ -5,15 +5,9 @@ * @package hcaptcha-wp */ -// phpcs:disable Generic.Commenting.DocComment.MissingShort -/** @noinspection PhpUndefinedNamespaceInspection */ -/** @noinspection PhpUndefinedClassInspection */ -// phpcs:enable Generic.Commenting.DocComment.MissingShort - namespace HCaptcha\WP; use HCaptcha\Abstracts\LoginBase; -use WordfenceLS\Controller_WordfenceLS; /** * Class Login diff --git a/src/php/WP/LoginOut.php b/src/php/WP/LoginOut.php new file mode 100644 index 00000000..d4fa5350 --- /dev/null +++ b/src/php/WP/LoginOut.php @@ -0,0 +1,60 @@ +is_wp_login_out_form() ) { + return $content; + } + + ob_start(); + $this->add_captcha(); + + return $content . ob_get_clean(); + } + + /** + * Whether we process the LoginOut form. + * + * @return bool + */ + private function is_wp_login_out_form(): bool { + return HCaptcha::did_filter( 'login_form_defaults' ); + } +}