Locations and verification
Validate Build / validate-build (push) Failing after 35s
Validate Build / validate-build (push) Failing after 35s
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* @package ogre-captcha
|
||||
* @author cleverogre
|
||||
* @copyright 2026 CleverOgre
|
||||
* @license GLP-3.0-or-later
|
||||
* @version 0.0.0
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
namespace Ogre\Captcha\Location;
|
||||
|
||||
use Override;
|
||||
use Ogre\Captcha\Location;
|
||||
use Ogre\Captcha\Settings;
|
||||
use WP_Error;
|
||||
use WP_User;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
final class LoginPage extends Location {
|
||||
|
||||
protected function __construct() {
|
||||
parent::__construct(Settings::LOCATION_LOGIN_PAGE);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function enabled(): bool
|
||||
{
|
||||
return is_user_logged_in() ? false : parent::enabled();
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function activate(): void
|
||||
{
|
||||
add_action('login_form', [$this, 'render']);
|
||||
add_filter('shake_error_codes', [$this, 'shake_error_codes']);
|
||||
add_filter('authenticate', [$this, 'process_form'], 20, 1);
|
||||
}
|
||||
|
||||
public function shake_error_codes(array $shake_error_codes):array {
|
||||
return array_merge(
|
||||
$shake_error_codes,
|
||||
[
|
||||
self::ERROR_EMPTY_TOKEN,
|
||||
self::ERROR_INVALID_CAPTCHA,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function process_form(WP_User|WP_Error $user):WP_User|WP_Error {
|
||||
if (is_wp_error($user)) return $user;
|
||||
if (!isset($_POST['log']) || !isset($_POST['pwd'])) return $user;
|
||||
$errors = new WP_Error();
|
||||
$this->process($errors);
|
||||
return $errors->has_errors() ? $errors : $user;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LoginPage::instance();
|
||||
Reference in New Issue
Block a user