More work on this, incomplete!
Validate Build / validate-build (push) Canceled after 0s

This commit is contained in:
Cooper Dalrymple
2026-10-06 17:00:20 -05:00
parent 5f702470cc
commit b8902b4afa
23 changed files with 2138 additions and 175 deletions
+58 -8
View File
@@ -11,8 +11,8 @@
namespace Ogre\Consent;
use Override;
use Ogre\Settings as AbstractSettings;
use Ogre\Consent as Plugin;
use Ogre\Settings as AbstractSettings;
defined('ABSPATH') || exit;
@@ -27,18 +27,68 @@ final class Settings extends AbstractSettings {
$this->add_section(
Plugin::__('General'),
Plugin::__('General settings for this plugin.')
sprintf(
Plugin::__('General settings for %s.'),
Plugin::get_title()
)
);
$this->add_field(
'text',
Plugin::__('Text'),
$this->add_checkbox_field(
'user_roles',
Plugin::__('User Roles'),
array_map(
fn (array $details): string => translate_user_role($details['name']),
array_reverse(get_editable_roles())
),
[
'placeholder' => Plugin::__('Insert some text here...'),
'description' => Plugin::__('An example field.'),
'description' => Plugin::__('The consent modal is disabled by default for all users. You can enable it for each user role using the settings below.'),
]
);
$this->add_section(
Plugin::__('Services'),
Plugin::__('You can control which services are included in user consent (opt-in) using the options below.'),
'services'
);
$purposes = Config::get_purposes();
foreach ($purposes as $name => $label) {
$services = [];
foreach (Services::instance()->get_services_by_purpose($name) as $service) {
$services[$service->get_name()] = $service->get_title();
}
if (empty($services)) continue;
$this->add_checkbox_field(
sprintf('services-%s', $name),
$label,
$services,
[
'name' => 'services',
'hide_value' => true,
],
'services'
);
}
}
public function is_service_enabled(Service|string $service): bool
{
if (is_a($service, Service::class)) {
$service = $service->get_name();
} else if (!is_string($service) || empty($service)) {
return false;
}
return $this->is_checked('services', $service);
}
public function get_enabled_user_roles(): array
{
if (!function_exists('get_editable_roles')) include_once(ABSPATH . 'wp-admin/includes/user.php');
return array_filter(
array_keys(get_editable_roles()),
fn (string $role): bool => $this->is_checked('user_roles', $role)
);
}
}