redirect($postData['_wp_http_referer'], 0, 'tools'); } $data = [ 'version' => AGE_GATE_VERSION, 'options' => [], ]; foreach ($postData['ag_settings'] as $option => $value) { if ($option === 'all') { continue; } if ($option === 'access') { global $wp_roles; $access = []; foreach (Immutable::AGE_GATE_ADMIN_PERMISSION as $key => $cap) { $access[$key] = collect($wp_roles->roles)->map(fn($role) => array_key_exists($cap, $role['capabilities'] ?? []) ? $role['name'] : false)->filter()->toArray(); } // foreach ($) $data['options'][$option] = $access; } else { $data['options'][$option] = get_option(Immutable::AGE_GATE_OPTIONS[$option], []); } } $file = 'age-gate-export-' . date('Y-m-d') . '.json'; // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename={$file}"); header("Content-Type: application/json; charset=utf-8"); // return echo json_encode($data, JSON_PRETTY_PRINT); die; } }