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 / Controller / ToolsController.php

ToolsController.php in Age Gate 3.7.3, at src/Admin/Controller/ToolsController.php

85 lines 2.2 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\Controller;
4
5 use AgeGate\Admin\Tools\Reset;
6 use AgeGate\Admin\Tools\Export;
7 use AgeGate\Admin\Tools\Import;
8 use AgeGate\Admin\Settings\Tools;
9 use AgeGate\Common\Admin\AbstractController;
10 use AgeGate\Common\Immutable\Constants as Immutable;
11
12 class ToolsController extends AbstractController
13 {
14 use Tools;
15
16 // const PERMISSION = Constants::RESTRICTIONS;
17 public const PERMISSION = Immutable::TOOLS;
18 protected const OPTION = Immutable::OPTION_TOOLS;
19
20 protected $template = 'tools';
21
22 public function register(): void
23 {
24 $user = wp_get_current_user();
25
26 $possibleCaps = array_values(
27 array_intersect(
28 array_keys($user->allcaps),
29 [
30 self::PERMISSION,
31 Immutable::HARD_RESET,
32 Immutable::EXPORT,
33 Immutable::IMPORT,
34 ]
35 )
36 );
37
38 $cap = $possibleCaps[0] ?? self::PERMISSION;
39
40 $this->menu(__('Tools', 'age-gate'), $cap);
41
42 if (in_array(Immutable::EXPORT, $possibleCaps)) {
43 new Export();
44 }
45
46 if (in_array(Immutable::IMPORT, $possibleCaps)) {
47 new Import();
48 }
49
50 if (in_array(Immutable::HARD_RESET, $possibleCaps)) {
51 new Reset();
52 }
53 }
54
55 protected function required(): bool
56 {
57 return current_user_can(self::PERMISSION) || current_user_can(Immutable::HARD_RESET) || current_user_can(Immutable::EXPORT) || current_user_can(Immutable::IMPORT);
58 }
59
60 protected function data(): array
61 {
62 $this->view->addData([
63 'export_options' => Immutable::AGE_GATE_OPTIONS,
64 'export_capability' => Immutable::EXPORT,
65 'import_capability' => Immutable::IMPORT,
66 'reset_capability' => Immutable::HARD_RESET,
67 ]);
68 return get_option(self::OPTION, []) ?: [];
69 }
70
71 protected function fields(): array
72 {
73 return $this->getToolsFields();
74 }
75
76 protected function rules() : array
77 {
78 return [
79 'dev_warning' => 'boolean',
80 'dev_endpoint' => 'boolean',
81 'feedback' => 'boolean',
82 ];
83 }
84 }
85