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;
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('<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 {
return admin_url('options-general.php?page=' . Plugin::get_id());
}