74 lines
1.6 KiB
PHP
74 lines
1.6 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;
|
|
|
|
use Ogre\Singleton;
|
|
use Ogre\Captcha as Plugin;
|
|
use Ogre\Captcha\Settings;
|
|
use WP_Error;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
abstract class Location {
|
|
use Singleton;
|
|
|
|
protected string $name;
|
|
|
|
protected function __construct(string $name) {
|
|
$this->name = $name;
|
|
add_action('init', [$this, 'init']);
|
|
}
|
|
|
|
public function enabled():bool {
|
|
return Settings::is_form_location_enabled($this->name);
|
|
}
|
|
|
|
public function init():void {
|
|
if (is_multisite()) {
|
|
$blog_id = get_current_blog_id();
|
|
switch_to_blog($blog_id);
|
|
}
|
|
$enabled = $this->enabled();
|
|
if (is_multisite()) {
|
|
restore_current_blog();
|
|
}
|
|
if (!$enabled) return;
|
|
|
|
$this->activate();
|
|
}
|
|
|
|
abstract public function activate():void;
|
|
|
|
public function render():void {
|
|
Widget::render();
|
|
}
|
|
|
|
public function process(WP_Error|null $errors = null):void {
|
|
API::process(Widget::get_token(), $errors);
|
|
}
|
|
|
|
protected function print_errors(WP_Error $errors):void {
|
|
if (!$errors->has_errors()) return;
|
|
|
|
$messages = [];
|
|
foreach ($errors->get_error_codes() as $code) {
|
|
foreach ($errors->get_error_messages($code) as $message) {
|
|
$messages[] = $message;
|
|
}
|
|
}
|
|
|
|
ob_start();
|
|
echo '<ul><li>' . implode('</li><li>', $messages) . '</li></ul>';
|
|
wp_die(ob_get_clean());
|
|
}
|
|
|
|
}
|