Skip to content

Commit

Permalink
Fix error when hCaptcha is disabled for standard login but enabled fo…
Browse files Browse the repository at this point in the history
…r LearnPress login.
  • Loading branch information
kagg-design committed Jan 15, 2025
1 parent 52a4cd6 commit f8a878d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
31 changes: 30 additions & 1 deletion src/php/LearnPress/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
namespace HCaptcha\LearnPress;

use HCaptcha\Abstracts\LoginBase;
use HCaptcha\Helpers\HCaptcha;
use WP_Error;
use WP_User;

/**
* Class Login.
Expand All @@ -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 );
}

/**
Expand All @@ -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' );
}
}
1 change: 1 addition & 0 deletions src/php/LearnPress/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function add_hcaptcha(): void {
* Verify hCaptcha.
*
* @return void
* @noinspection PhpUndefinedFunctionInspection
*/
public function verify(): void {
$action = 'learn-press-register';
Expand Down

0 comments on commit f8a878d

Please sign in to comment.