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,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;
|
||||
|
||||
use Ogre\Captcha\Settings;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
final class Widget {
|
||||
|
||||
private const SCRIPT_HANDLE = 'cap';
|
||||
private const TOKEN_NAME = 'cap-token';
|
||||
|
||||
private static function get_script_url():string {
|
||||
if (!Settings::is_connected()) return '';
|
||||
return Settings::get_instance_url('assets/widget.js');
|
||||
}
|
||||
|
||||
public static function enqueue_script():void {
|
||||
if (!Settings::is_connected() || wp_script_is(self::SCRIPT_HANDLE)) return;
|
||||
wp_enqueue_script(self::SCRIPT_HANDLE, self::get_script_url());
|
||||
}
|
||||
|
||||
public static function render(string $id = 'cap'):void {
|
||||
if (!Settings::is_connected()) return;
|
||||
self::enqueue_script();
|
||||
printf(
|
||||
'<cap-widget id="%s" required data-cap-api-endpoint="%s"></cap-widget>',
|
||||
esc_attr($id),
|
||||
esc_url(Settings::get_instance_url(Settings::get_site_key() . '/'))
|
||||
);
|
||||
}
|
||||
|
||||
public static function get_token():string {
|
||||
return isset($_POST[self::TOKEN_NAME]) ? (string) $_POST[self::TOKEN_NAME] : '';
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user