Add woocommerce form locations
Validate Build / validate-build (push) Failing after 27s
Validate Build / validate-build (push) Failing after 27s
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?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\WooCommerce;
|
||||
|
||||
use Override;
|
||||
use Ogre\Captcha\Location;
|
||||
use Ogre\Captcha\Settings;
|
||||
use WP_Error;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
final class Checkout extends Location {
|
||||
|
||||
protected function __construct() {
|
||||
parent::__construct(Settings::LOCATION_WC_CHECKOUT);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function enabled(): bool
|
||||
{
|
||||
return is_user_logged_in() ? false : parent::enabled();
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function activate(): void
|
||||
{
|
||||
add_action('woocommerce_after_checkout_billing_form', [$this, 'render']);
|
||||
add_action('woocommerce_after_checkout_validation', [$this, 'process_form'], 10, 2);
|
||||
}
|
||||
|
||||
public function process_form(array $data, WP_Error $errors) {
|
||||
$this->process($errors);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Checkout::instance();
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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\WooCommerce;
|
||||
|
||||
use Override;
|
||||
use Ogre\Captcha\Location;
|
||||
use Ogre\Captcha\Settings;
|
||||
use WP_Error;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
final class Login extends Location {
|
||||
|
||||
protected function __construct() {
|
||||
parent::__construct(Settings::LOCATION_WC_LOGIN);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function enabled(): bool
|
||||
{
|
||||
return is_user_logged_in() ? false : parent::enabled();
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function activate(): void
|
||||
{
|
||||
add_action('woocommerce_login_form', [$this, 'render']);
|
||||
if (isset($_POST['woocommerce-login-nonce'])) {
|
||||
add_filter('woocommerce_process_login_errors', [$this, 'process_form'], 10, 3);
|
||||
}
|
||||
}
|
||||
|
||||
public function process_form(WP_Error $validation_error, string $user_login, string $user_password):WP_Error {
|
||||
$this->process($validation_error);
|
||||
return $validation_error;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Login::instance();
|
||||
@@ -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\WooCommerce;
|
||||
|
||||
use Override;
|
||||
use Ogre\Captcha\Location;
|
||||
use Ogre\Captcha\Settings;
|
||||
use WP_Error;
|
||||
use WP_User;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
final class LostPassword extends Location {
|
||||
|
||||
protected function __construct() {
|
||||
parent::__construct(Settings::LOCATION_WC_LOST_PASSWORD);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function enabled(): bool
|
||||
{
|
||||
return is_user_logged_in() ? false : parent::enabled();
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function activate(): void
|
||||
{
|
||||
add_action('woocommerce_lostpassword_form', [$this, 'render']);
|
||||
if (isset($_POST['woocommerce-lost-password-nonce'])) {
|
||||
add_action('lostpassword_post', [$this, 'process_form']);
|
||||
}
|
||||
}
|
||||
|
||||
public function process_form(WP_Error $errors, WP_User|bool $user_data) {
|
||||
$this->process($errors);
|
||||
// NOTE: Potentially use `allow_password_reset` to display error message?
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
LostPassword::instance();
|
||||
@@ -0,0 +1,48 @@
|
||||
<?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\WooCommerce;
|
||||
|
||||
use Override;
|
||||
use Ogre\Captcha\Location;
|
||||
use Ogre\Captcha\Settings;
|
||||
use WP_Error;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
final class Register extends Location {
|
||||
|
||||
protected function __construct() {
|
||||
parent::__construct(Settings::LOCATION_WC_REGISTER);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function enabled(): bool
|
||||
{
|
||||
return is_user_logged_in() ? false : parent::enabled();
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function activate(): void
|
||||
{
|
||||
add_action('woocommerce_register_form', [$this, 'render']);
|
||||
if (isset($_POST['woocommerce-register-nonce'])) {
|
||||
add_filter('woocommerce_process_registration_errors', [$this, 'process_form'], 10, 4);
|
||||
}
|
||||
}
|
||||
|
||||
public function process_form(WP_Error $validation_error, string $username, string $password, string $email):WP_Error {
|
||||
$this->process($validation_error);
|
||||
return $validation_error;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Register::instance();
|
||||
Reference in New Issue
Block a user