From aaff0e5c41852426d075416bdc21485bf02768ad Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Thu, 4 Jun 2026 13:12:10 -0500 Subject: [PATCH] Add API connection settings --- inc/class-settings.php | 66 +++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/inc/class-settings.php b/inc/class-settings.php index ecfc40e..947283b 100644 --- a/inc/class-settings.php +++ b/inc/class-settings.php @@ -19,6 +19,7 @@ final class Settings { use Singleton; const CAPABILITY = 'manage_options'; + const DEFAULT_INSTANCE_URL = 'https://captcha.cleverogre.com'; protected function __construct() { add_action('admin_menu', [$this, 'menu']); @@ -31,8 +32,16 @@ final class Settings { return $data; } - private function is_checked(string $name, string $value):bool { - return in_array($value, (array) $this->get($name)); + public function get_instance_url():string { + return !empty($value = (string) $this->get('instance_url')) ? $value : self::DEFAULT_INSTANCE_URL; + } + + public function get_site_key():string { + return (string) $this->get('site_key'); + } + + public function get_secret_key():string { + return (string) $this->get('secret_key'); } public function menu() { @@ -45,23 +54,45 @@ final class Settings { add_settings_section( 'default', - Plugin::__('General'), + Plugin::__('Cap API Credentials'), [$this, 'section'], Plugin::get_id(), [ - 'description' => Plugin::__('General settings for this plugin.'), + 'description' => Plugin::__('The configuration settings for your Cap CAPTCHA API connection.'), ] ); add_settings_field( - Plugin::get_id() . '_text', - Plugin::__('Text'), + Plugin::get_id() . '_instance_url', + Plugin::__('Instance URL'), [$this, 'field'], Plugin::get_id(), args: [ - 'name' => 'text', - 'placeholder' => Plugin::__('Insert some text here...'), - 'description' => Plugin::__('An example field.'), + 'name' => 'instance_url', + 'placeholder' => Plugin::__('https://captcha.cleverogre.com/'), + 'description' => Plugin::__('Provide the base URL to an instance of Cap. Defaults to CleverOgre\'s CAPTCHA server.'), + ] + ); + + add_settings_field( + Plugin::get_id() . '_site_key', + Plugin::__('Site key'), + [$this, 'field'], + Plugin::get_id(), + args: [ + 'name' => 'site_key', + 'description' => Plugin::__('Provide your Cap site key.'), + ] + ); + + add_settings_field( + Plugin::get_id() . '_secret_key', + Plugin::__('Secret key'), + [$this, 'field'], + Plugin::get_id(), + args: [ + 'name' => 'secret_key', + 'description' => Plugin::__('Provide your Cap secret key.'), ] ); } @@ -143,23 +174,6 @@ final class Settings { } } - public function checkbox_field(array $args):void { - extract($args); - - echo implode('
', array_map( - fn (object $option):string => sprintf( - '', - esc_attr(Plugin::get_id()), - esc_attr($name), - esc_attr($option->name), - checked($this->is_checked($name, $option->name), display: false), - esc_html($option->label), - esc_html($option->name) - ), - $options - )); - } - public static function get_url():string { return admin_url('options-general.php?page=' . Plugin::get_id()); }