97 lines
2.7 KiB
PHP
97 lines
2.7 KiB
PHP
<?php
|
|
/**
|
|
* @package ogre-consent
|
|
* @author cleverogre
|
|
* @copyright 2026 CleverOgre
|
|
* @license GLP-3.0-or-later
|
|
* @version 0.0.0
|
|
* @since 0.0.0
|
|
*/
|
|
|
|
namespace Ogre\Consent;
|
|
|
|
use Override;
|
|
use Ogre\Consent as Plugin;
|
|
use Ogre\Settings as AbstractSettings;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
final class Settings extends AbstractSettings {
|
|
|
|
protected function __construct() {
|
|
parent::__construct(Plugin::instance());
|
|
}
|
|
|
|
#[Override]
|
|
public function register_settings(): void {
|
|
|
|
$this->add_section(
|
|
Plugin::__('General'),
|
|
sprintf(
|
|
Plugin::__('General settings for %s.'),
|
|
Plugin::get_title()
|
|
)
|
|
);
|
|
|
|
$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())
|
|
),
|
|
[
|
|
'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)
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
Settings::instance();
|