65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* @package ogre-captcha
|
|
* @author cleverogre
|
|
* @copyright 2026 CleverOgre
|
|
* @license GLP-3.0-or-later
|
|
* @version 1.0.0
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
namespace Ogre\Captcha\Location;
|
|
|
|
use Ogre\Captcha\API;
|
|
use Override;
|
|
use Ogre\Captcha\LoginLocation;
|
|
use Ogre\Captcha\Settings;
|
|
use Ogre\Captcha\Widget;
|
|
use WP_Error;
|
|
use WP_User;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
final class LoginPage extends LoginLocation {
|
|
|
|
protected function __construct() {
|
|
parent::__construct(Settings::LOCATION_LOGIN_PAGE, 'login');
|
|
}
|
|
|
|
#[Override]
|
|
public function enabled(): bool
|
|
{
|
|
return is_user_logged_in() ? false : parent::enabled();
|
|
}
|
|
|
|
#[Override]
|
|
public function activate(): void
|
|
{
|
|
parent::activate();
|
|
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,
|
|
[
|
|
API::ERROR_EMPTY_TOKEN,
|
|
API::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();
|