Add API connection settings
Validate Build / validate-build (push) Failing after 1m3s

This commit is contained in:
Cooper Dalrymple
2026-06-04 13:12:10 -05:00
parent bcfe35fa91
commit aaff0e5c41
+40 -26
View File
@@ -19,6 +19,7 @@ final class Settings {
use Singleton; use Singleton;
const CAPABILITY = 'manage_options'; const CAPABILITY = 'manage_options';
const DEFAULT_INSTANCE_URL = 'https://captcha.cleverogre.com';
protected function __construct() { protected function __construct() {
add_action('admin_menu', [$this, 'menu']); add_action('admin_menu', [$this, 'menu']);
@@ -31,8 +32,16 @@ final class Settings {
return $data; return $data;
} }
private function is_checked(string $name, string $value):bool { public function get_instance_url():string {
return in_array($value, (array) $this->get($name)); 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() { public function menu() {
@@ -45,23 +54,45 @@ final class Settings {
add_settings_section( add_settings_section(
'default', 'default',
Plugin::__('General'), Plugin::__('Cap API Credentials'),
[$this, 'section'], [$this, 'section'],
Plugin::get_id(), Plugin::get_id(),
[ [
'description' => Plugin::__('General settings for this plugin.'), 'description' => Plugin::__('The configuration settings for your Cap CAPTCHA API connection.'),
] ]
); );
add_settings_field( add_settings_field(
Plugin::get_id() . '_text', Plugin::get_id() . '_instance_url',
Plugin::__('Text'), Plugin::__('Instance URL'),
[$this, 'field'], [$this, 'field'],
Plugin::get_id(), Plugin::get_id(),
args: [ args: [
'name' => 'text', 'name' => 'instance_url',
'placeholder' => Plugin::__('Insert some text here...'), 'placeholder' => Plugin::__('https://captcha.cleverogre.com/'),
'description' => Plugin::__('An example field.'), '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('<br>', array_map(
fn (object $option):string => sprintf(
'<label><input type="checkbox" name="%s[%s][]" value="%s" %s>&nbsp;%s (%s)</label>',
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 { public static function get_url():string {
return admin_url('options-general.php?page=' . Plugin::get_id()); return admin_url('options-general.php?page=' . Plugin::get_id());
} }