diff --git a/readme.txt b/readme.txt index b9e47d5d..b96ebae9 100644 --- a/readme.txt +++ b/readme.txt @@ -627,6 +627,7 @@ Instructions for popular native integrations are below: * Fixed scrolling to the message on the General page. * Fixed fatal error during integration installation in some cases. * Fixed the Integrations page when active plugin was deleted. +* Fixed error when hCaptcha is disabled for standard login but enabled for LearnPress login. * Fixed error when hCaptcha is disabled for standard login but enabled for Tutor login. = 4.9.0 = diff --git a/src/php/LearnPress/Login.php b/src/php/LearnPress/Login.php index 08a6f6d5..a1283b7f 100644 --- a/src/php/LearnPress/Login.php +++ b/src/php/LearnPress/Login.php @@ -8,6 +8,9 @@ namespace HCaptcha\LearnPress; use HCaptcha\Abstracts\LoginBase; +use HCaptcha\Helpers\HCaptcha; +use WP_Error; +use WP_User; /** * Class Login. @@ -23,7 +26,7 @@ protected function init_hooks(): void { parent::init_hooks(); add_action( 'login_form', [ $this, 'add_captcha' ] ); - add_filter( 'wp_authenticate_user', [ $this, 'login_base_verify' ], PHP_INT_MAX, 2 ); + add_filter( 'wp_authenticate_user', [ $this, 'verify' ], 10, 2 ); } /** @@ -38,4 +41,30 @@ public function add_captcha(): void { parent::add_captcha(); } + + /** + * Verify a login form. + * + * @param WP_User|WP_Error $user WP_User or WP_Error object + * if a previous callback failed authentication. + * @param string $password Password to check against the user. + * + * @return WP_User|WP_Error + */ + public function verify( $user, string $password ) { + if ( ! $this->is_learn_press_form() ) { + return $user; + } + + return $this->login_base_verify( $user, $password ); + } + + /** + * Whether we process the Learn Press login form. + * + * @return bool + */ + private function is_learn_press_form(): bool { + return HCaptcha::did_filter( 'learnpress_login_credentials' ); + } } diff --git a/src/php/LearnPress/Register.php b/src/php/LearnPress/Register.php index 3e54778b..26a9d6b7 100644 --- a/src/php/LearnPress/Register.php +++ b/src/php/LearnPress/Register.php @@ -67,6 +67,7 @@ public function add_hcaptcha(): void { * Verify hCaptcha. * * @return void + * @noinspection PhpUndefinedFunctionInspection */ public function verify(): void { $action = 'learn-press-register';