Locations and verification
Validate Build / validate-build (push) Failing after 35s

This commit is contained in:
Cooper Dalrymple
2026-06-04 17:05:42 -05:00
parent 471e5dd053
commit e8b8fc1871
11 changed files with 538 additions and 13 deletions
+53
View File
@@ -0,0 +1,53 @@
<?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;
defined('ABSPATH') || exit;
final class CommentForm extends Location {
protected function __construct() {
parent::__construct(Settings::LOCATION_COMMENT_FORM);
}
#[Override]
public function activate(): void
{
add_action('comment_form_after_fields', [$this, 'render'], 1);
add_filter('preprocess_comment', [$this, 'process_form']);
}
public function process_form(array $commentdata):array {
// Don't process CAPTCHA for comment replies inside admin menu
if (isset($_REQUEST['action']) && 'replyto-comment' == $_REQUEST['action'] && (check_ajax_referer('replyto-comment', '_ajax_nonce', false) || check_ajax_referer('replyto-comment', '_ajax_nonce-replyto-comment', false))) {
return $comment;
}
// Don't do CAPTCHA for pingback/trackback
if ('' != $comment['comment_type'] && 'comment' != $comment['comment_type'] && 'review' != $comment['comment_type']) {
return $comment;
}
$errors = new WP_Error();
$this->process($errors);
$this->print_errors($errors);
return $commentdata;
}
}
CommentForm::instance();
+47
View File
@@ -0,0 +1,47 @@
<?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;
defined('ABSPATH') || exit;
final class LoginForm extends Location {
protected function __construct() {
parent::__construct(Settings::LOCATION_LOGIN_FORM);
}
#[Override]
public function enabled(): bool
{
return is_user_logged_in() ? false : parent::enabled();
}
#[Override]
public function activate(): void
{
add_filter('login_form_middle', [$this, 'render_form'], 10, 2);
// NOTE: Requires login page processing
}
public function render_form(string $content, array $args):string {
ob_start();
$this->render();
$content .= ob_get_clean();
return $content;
}
}
LoginForm::instance();
+61
View File
@@ -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();
+46
View File
@@ -0,0 +1,46 @@
<?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 LostPasswordForm extends Location {
protected function __construct() {
parent::__construct(Settings::LOCATION_LOST_PASSWORD_FORM);
}
#[Override]
public function enabled(): bool
{
return is_user_logged_in() ? false : parent::enabled();
}
#[Override]
public function activate(): void
{
add_action('lostpassword_form', [$this, 'render']);
add_action('lostpassword_post', [$this, 'process_form']);
}
public function process_form(WP_Error $errors, WP_User|bool $user_data):void {
$this->process($errors);
}
}
LostPasswordForm::instance();
+49
View File
@@ -0,0 +1,49 @@
<?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_Post;
defined('ABSPATH') || exit;
final class PostPasswordForm extends Location {
protected function __construct() {
parent::__construct(Settings::LOCATION_POST_PASSWORD_FORM);
}
#[Override]
public function activate(): void
{
add_filter('the_password_form', [$this, 'render_form']);
add_action('login_form_postpass', [$this, 'process_form']);
}
public function render_form(string $output, WP_Post $post, string $invalid_password):string {
ob_start();
$this->render();
$output .= ob_get_clean();
return $output;
}
public function process_form():void {
$errors = new WP_Error();
$this->process($errors);
$this->print_errors($errors);
}
}
PostPasswordForm::instance();
+56
View File
@@ -0,0 +1,56 @@
<?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;
defined('ABSPATH') || exit;
final class RegistrationPage extends Location {
protected function __construct() {
parent::__construct(Settings::LOCATION_REGISTRATION_PAGE);
}
#[Override]
public function enabled(): bool
{
return is_user_logged_in() ? false : parent::enabled();
}
#[Override]
public function activate(): void
{
if (is_multisite()) {
add_action('signup_extra_fields', [$this, 'render']);
add_filter('wpmu_validate_user_signup', [$this, 'process_multisite_form']);
} else {
add_action('register_form', [$this, 'render']);
}
add_filter('registration_errors', [$this, 'process_form'], 10, 3);
}
public function process_multisite_form(array $result):array {
$this->process($result['errors']);
return $result;
}
public function process_form(WP_Error $errors, string $sanitized_user_login, string $user_email):WP_Error {
$this->process($errors);
return $errors;
}
}
RegistrationPage::instance();