Warning: session_start(): Session cannot be started after headers have already been sent in /home/tvrreohg/public_html/manga.php on line 13
validation_rules([
'ag_settings_import' => [
'required_file',
'extension' => [
'json'
],
],
'ag_settings_import.type' => 'equals,application/json',
'data' => 'valid_json_string',
]);
$valid_data = $validator->run(array_merge($_POST, $_FILES, ['data' => $_FILES['ag_settings_import']['tmp_name'] ? file_get_contents($_FILES['ag_settings_import']['tmp_name']) : 's']));
if ($validator->errors()) {
$this->redirect($_POST['_wp_http_referer'], 0, 'tools');
}
$data = $validator->sanitize(json_decode($valid_data['data'], true));
$failed = [];
foreach ($data['options'] ?? [] as $option => $values) {
if ($option === 'access') {
global $wp_roles;
foreach ($values as $capability => $roles) {
foreach ($wp_roles->roles as $slug => $role) {
if (Immutable::AGE_GATE_ADMIN_PERMISSION[$capability] ?? false) {
$cap = Immutable::AGE_GATE_ADMIN_PERMISSION[$capability];
$role = get_role($slug);
if ($slug === 'administrator') {
continue;
}
if (array_key_exists($slug, $roles)) {
if (!$role->has_cap($cap)) {
$role->add_cap($cap);
}
} else {
if ($role->has_cap($cap)) {
$role->remove_cap($cap);
}
}
}
}
}
} elseif (Immutable::AGE_GATE_OPTIONS[$option] ?? false) {
update_option(Immutable::AGE_GATE_OPTIONS[$option], $values);
} else {
// TODO : Handle this
$failed[] = wp_generate_uuid4( );
}
}
$this->redirect($_POST['_wp_http_referer'], 1, 'tools');
}
}