Skip to content

Commit

Permalink
Add support for wp_login_form() function and LoginOut block.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Jan 28, 2025
1 parent 5079a67 commit 7aed0e9
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .tests/php/integration/AAAMainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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' ],
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/php/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ],
Expand Down
6 changes: 0 additions & 6 deletions src/php/WP/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions src/php/WP/LoginOut.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* LoginOut class file.
*
* @package hcaptcha-wp
*/

namespace HCaptcha\WP;

use HCaptcha\Abstracts\LoginBase;
use HCaptcha\Helpers\HCaptcha;

/**
* Class LoginOut.
* Supports wp_login_form() function and LoginOut block.
*/
class LoginOut extends LoginBase {

/**
* Init hooks.
*
* @return void
*/
protected function init_hooks(): void {
parent::init_hooks();

add_filter( 'login_form_middle', [ $this, 'add_wp_login_out_hcaptcha' ], 10, 2 );
}

/**
* Add hCaptcha.
*
* @param string|mixed $content Content to display. Default empty.
* @param array $args Array of login form arguments.
*
* @return string
* @noinspection PhpUnusedParameterInspection
*/
public function add_wp_login_out_hcaptcha( $content, array $args ): string {
$content = (string) $content;

if ( ! $this->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' );
}
}

0 comments on commit 7aed0e9

Please sign in to comment.