PluginProbe
Age Gate / 3.7.3
Age Gate v3.7.3
3.7.3 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 All 113 releases
age-gate / src / Admin / Tools / Export.php

Export.php in Age Gate 3.7.3, at src/Admin/Tools/Export.php

70 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AgeGate\Admin\Tools;
4
5 use AgeGate\Common\Admin\Helper;
6 use AgeGate\Common\Immutable\Constants as Immutable;
7
8 class Export
9 {
10 use Helper;
11
12 public const PERMISSION = Immutable::EXPORT;
13
14 public function __construct()
15 {
16 add_action('admin_post_age_gate_export', [$this, 'action']);
17 }
18
19 public function action()
20 {
21 $postData = wp_unslash($_POST ?? []);
22
23 if (!current_user_can(self::PERMISSION) || !wp_verify_nonce($postData['ag_export'] ?? '', 'ag_export')) {
24 wp_die('Disallowed action');
25 }
26
27 if (empty($postData['ag_settings'])) {
28 $this->redirect($postData['_wp_http_referer'], 0, 'tools');
29
30 }
31
32 $data = [
33 'version' => AGE_GATE_VERSION,
34 'options' => [],
35 ];
36
37 foreach ($postData['ag_settings'] as $option => $value) {
38 if ($option === 'all') {
39 continue;
40 }
41
42 if ($option === 'access') {
43 global $wp_roles;
44
45 $access = [];
46
47 foreach (Immutable::AGE_GATE_ADMIN_PERMISSION as $key => $cap) {
48 $access[$key] = collect($wp_roles->roles)->map(fn($role) => array_key_exists($cap, $role['capabilities'] ?? []) ? $role['name'] : false)->filter()->toArray();
49 }
50 // foreach ($)
51 $data['options'][$option] = $access;
52
53 } else {
54 $data['options'][$option] = get_option(Immutable::AGE_GATE_OPTIONS[$option], []);
55 }
56 }
57
58 $file = 'age-gate-export-' . date('Y-m-d') . '.json'; // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
59
60 header("Content-Description: File Transfer");
61 header("Content-Disposition: attachment; filename={$file}");
62 header("Content-Type: application/json; charset=utf-8");
63
64 // return
65 echo json_encode($data, JSON_PRETTY_PRINT);
66 die;
67
68 }
69 }
70