@@ -12,15 +12,15 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class CurrentUser extends GraphQLData |
14 | 14 | { |
15 | - /** |
|
16 | - * @param array $where_params |
|
17 | - * @return array|null |
|
18 | - * @since 5.0.0.p |
|
19 | - */ |
|
20 | - public function getData(array $where_params = []): ?array |
|
21 | - { |
|
22 | - $field_key = 'viewer'; |
|
23 | - $query = <<<QUERY |
|
15 | + /** |
|
16 | + * @param array $where_params |
|
17 | + * @return array|null |
|
18 | + * @since 5.0.0.p |
|
19 | + */ |
|
20 | + public function getData(array $where_params = []): ?array |
|
21 | + { |
|
22 | + $field_key = 'viewer'; |
|
23 | + $query = <<<QUERY |
|
24 | 24 | query GET_CURRENT_USER { |
25 | 25 | $field_key { |
26 | 26 | id |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | } |
39 | 39 | } |
40 | 40 | QUERY; |
41 | - $this->setParams([ |
|
42 | - 'operation_name' => 'GET_CURRENT_USER', |
|
43 | - 'query' => $query, |
|
44 | - ]); |
|
41 | + $this->setParams([ |
|
42 | + 'operation_name' => 'GET_CURRENT_USER', |
|
43 | + 'query' => $query, |
|
44 | + ]); |
|
45 | 45 | |
46 | - return $this->getQueryResponse($field_key, $where_params); |
|
47 | - } |
|
46 | + return $this->getQueryResponse($field_key, $where_params); |
|
47 | + } |
|
48 | 48 | } |
@@ -12,15 +12,15 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class Prices extends GraphQLData |
14 | 14 | { |
15 | - /** |
|
16 | - * @param array $where_params |
|
17 | - * @return array|null |
|
18 | - * @since 5.0.0.p |
|
19 | - */ |
|
20 | - public function getData(array $where_params = []): ?array |
|
21 | - { |
|
22 | - $field_key = lcfirst($this->namespace) . 'Prices'; |
|
23 | - $query = <<<QUERY |
|
15 | + /** |
|
16 | + * @param array $where_params |
|
17 | + * @return array|null |
|
18 | + * @since 5.0.0.p |
|
19 | + */ |
|
20 | + public function getData(array $where_params = []): ?array |
|
21 | + { |
|
22 | + $field_key = lcfirst($this->namespace) . 'Prices'; |
|
23 | + $query = <<<QUERY |
|
24 | 24 | query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
25 | 25 | $field_key(where: \$where, first: \$first, last: \$last) { |
26 | 26 | nodes { |
@@ -44,14 +44,14 @@ discard block |
||
44 | 44 | } |
45 | 45 | } |
46 | 46 | QUERY; |
47 | - $this->setParams([ |
|
48 | - 'operation_name' => 'GET_PRICES', |
|
49 | - 'variables' => [ |
|
50 | - 'first' => GraphQLData::QUERY_LIMIT, |
|
51 | - ], |
|
52 | - 'query' => $query, |
|
53 | - ]); |
|
47 | + $this->setParams([ |
|
48 | + 'operation_name' => 'GET_PRICES', |
|
49 | + 'variables' => [ |
|
50 | + 'first' => GraphQLData::QUERY_LIMIT, |
|
51 | + ], |
|
52 | + 'query' => $query, |
|
53 | + ]); |
|
54 | 54 | |
55 | - return $this->getQueryResponse($field_key, $where_params); |
|
56 | - } |
|
55 | + return $this->getQueryResponse($field_key, $where_params); |
|
56 | + } |
|
57 | 57 | } |
@@ -19,7 +19,7 @@ |
||
19 | 19 | */ |
20 | 20 | public function getData(array $where_params = []): ?array |
21 | 21 | { |
22 | - $field_key = lcfirst($this->namespace) . 'Prices'; |
|
22 | + $field_key = lcfirst($this->namespace).'Prices'; |
|
23 | 23 | $query = <<<QUERY |
24 | 24 | query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
25 | 25 | $field_key(where: \$where, first: \$first, last: \$last) { |
@@ -12,15 +12,15 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class Datetimes extends GraphQLData |
14 | 14 | { |
15 | - /** |
|
16 | - * @param array $where_params |
|
17 | - * @return array|null |
|
18 | - * @since 5.0.0.p |
|
19 | - */ |
|
20 | - public function getData(array $where_params = []): ?array |
|
21 | - { |
|
22 | - $field_key = lcfirst($this->namespace) . 'Datetimes'; |
|
23 | - $query = <<<QUERY |
|
15 | + /** |
|
16 | + * @param array $where_params |
|
17 | + * @return array|null |
|
18 | + * @since 5.0.0.p |
|
19 | + */ |
|
20 | + public function getData(array $where_params = []): ?array |
|
21 | + { |
|
22 | + $field_key = lcfirst($this->namespace) . 'Datetimes'; |
|
23 | + $query = <<<QUERY |
|
24 | 24 | query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
25 | 25 | $field_key(where: \$where, first: \$first, last: \$last) { |
26 | 26 | nodes { |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | } |
51 | 51 | } |
52 | 52 | QUERY; |
53 | - $this->setParams([ |
|
54 | - 'operation_name' => 'GET_DATETIMES', |
|
55 | - 'variables' => [ |
|
56 | - 'first' => GraphQLData::QUERY_LIMIT, |
|
57 | - ], |
|
58 | - 'query' => $query, |
|
59 | - ]); |
|
53 | + $this->setParams([ |
|
54 | + 'operation_name' => 'GET_DATETIMES', |
|
55 | + 'variables' => [ |
|
56 | + 'first' => GraphQLData::QUERY_LIMIT, |
|
57 | + ], |
|
58 | + 'query' => $query, |
|
59 | + ]); |
|
60 | 60 | |
61 | - return $this->getQueryResponse($field_key, $where_params); |
|
62 | - } |
|
61 | + return $this->getQueryResponse($field_key, $where_params); |
|
62 | + } |
|
63 | 63 | } |
@@ -19,7 +19,7 @@ |
||
19 | 19 | */ |
20 | 20 | public function getData(array $where_params = []): ?array |
21 | 21 | { |
22 | - $field_key = lcfirst($this->namespace) . 'Datetimes'; |
|
22 | + $field_key = lcfirst($this->namespace).'Datetimes'; |
|
23 | 23 | $query = <<<QUERY |
24 | 24 | query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
25 | 25 | $field_key(where: \$where, first: \$first, last: \$last) { |
@@ -12,10 +12,10 @@ |
||
12 | 12 | */ |
13 | 13 | interface GraphQLDataInterface |
14 | 14 | { |
15 | - /** |
|
16 | - * @param array $where_params |
|
17 | - * @return array|null |
|
18 | - * @since 5.0.0.p |
|
19 | - */ |
|
20 | - public function getData(array $where_params = []): ?array; |
|
15 | + /** |
|
16 | + * @param array $where_params |
|
17 | + * @return array|null |
|
18 | + * @since 5.0.0.p |
|
19 | + */ |
|
20 | + public function getData(array $where_params = []): ?array; |
|
21 | 21 | } |
@@ -12,15 +12,15 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class Tickets extends GraphQLData |
14 | 14 | { |
15 | - /** |
|
16 | - * @param array $where_params |
|
17 | - * @return array|null |
|
18 | - * @since 5.0.0.p |
|
19 | - */ |
|
20 | - public function getData(array $where_params = []): ?array |
|
21 | - { |
|
22 | - $field_key = lcfirst($this->namespace) . 'Tickets'; |
|
23 | - $query = <<<QUERY |
|
15 | + /** |
|
16 | + * @param array $where_params |
|
17 | + * @return array|null |
|
18 | + * @since 5.0.0.p |
|
19 | + */ |
|
20 | + public function getData(array $where_params = []): ?array |
|
21 | + { |
|
22 | + $field_key = lcfirst($this->namespace) . 'Tickets'; |
|
23 | + $query = <<<QUERY |
|
24 | 24 | query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs, \$first: Int, \$last: Int ) { |
25 | 25 | $field_key(where: \$where, first: \$first, last: \$last) { |
26 | 26 | nodes { |
@@ -57,14 +57,14 @@ discard block |
||
57 | 57 | } |
58 | 58 | } |
59 | 59 | QUERY; |
60 | - $this->setParams([ |
|
61 | - 'operation_name' => 'GET_TICKETS', |
|
62 | - 'variables' => [ |
|
63 | - 'first' => GraphQLData::QUERY_LIMIT, |
|
64 | - ], |
|
65 | - 'query' => $query, |
|
66 | - ]); |
|
60 | + $this->setParams([ |
|
61 | + 'operation_name' => 'GET_TICKETS', |
|
62 | + 'variables' => [ |
|
63 | + 'first' => GraphQLData::QUERY_LIMIT, |
|
64 | + ], |
|
65 | + 'query' => $query, |
|
66 | + ]); |
|
67 | 67 | |
68 | - return $this->getQueryResponse($field_key, $where_params); |
|
69 | - } |
|
68 | + return $this->getQueryResponse($field_key, $where_params); |
|
69 | + } |
|
70 | 70 | } |
@@ -19,7 +19,7 @@ |
||
19 | 19 | */ |
20 | 20 | public function getData(array $where_params = []): ?array |
21 | 21 | { |
22 | - $field_key = lcfirst($this->namespace) . 'Tickets'; |
|
22 | + $field_key = lcfirst($this->namespace).'Tickets'; |
|
23 | 23 | $query = <<<QUERY |
24 | 24 | query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs, \$first: Int, \$last: Int ) { |
25 | 25 | $field_key(where: \$where, first: \$first, last: \$last) { |
@@ -12,15 +12,15 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class Venues extends GraphQLData |
14 | 14 | { |
15 | - /** |
|
16 | - * @param array $where_params |
|
17 | - * @return array|null |
|
18 | - * @since 5.0.0.p |
|
19 | - */ |
|
20 | - public function getData(array $where_params = []): ?array |
|
21 | - { |
|
22 | - $field_key = lcfirst($this->namespace) . 'Venues'; |
|
23 | - $query = <<<QUERY |
|
15 | + /** |
|
16 | + * @param array $where_params |
|
17 | + * @return array|null |
|
18 | + * @since 5.0.0.p |
|
19 | + */ |
|
20 | + public function getData(array $where_params = []): ?array |
|
21 | + { |
|
22 | + $field_key = lcfirst($this->namespace) . 'Venues'; |
|
23 | + $query = <<<QUERY |
|
24 | 24 | query GET_VENUES(\$where: RootQueryTo{$this->namespace}VenueConnectionWhereArgs, \$first: Int, \$last: Int ) { |
25 | 25 | $field_key(where: \$where, first: \$first, last: \$last) { |
26 | 26 | nodes { |
@@ -49,14 +49,14 @@ discard block |
||
49 | 49 | } |
50 | 50 | } |
51 | 51 | QUERY; |
52 | - $this->setParams([ |
|
53 | - 'operation_name' => 'GET_VENUES', |
|
54 | - 'variables' => [ |
|
55 | - 'first' => GraphQLData::QUERY_LIMIT, |
|
56 | - ], |
|
57 | - 'query' => $query, |
|
58 | - ]); |
|
52 | + $this->setParams([ |
|
53 | + 'operation_name' => 'GET_VENUES', |
|
54 | + 'variables' => [ |
|
55 | + 'first' => GraphQLData::QUERY_LIMIT, |
|
56 | + ], |
|
57 | + 'query' => $query, |
|
58 | + ]); |
|
59 | 59 | |
60 | - return $this->getQueryResponse($field_key, $where_params); |
|
61 | - } |
|
60 | + return $this->getQueryResponse($field_key, $where_params); |
|
61 | + } |
|
62 | 62 | } |
@@ -19,7 +19,7 @@ |
||
19 | 19 | */ |
20 | 20 | public function getData(array $where_params = []): ?array |
21 | 21 | { |
22 | - $field_key = lcfirst($this->namespace) . 'Venues'; |
|
22 | + $field_key = lcfirst($this->namespace).'Venues'; |
|
23 | 23 | $query = <<<QUERY |
24 | 24 | query GET_VENUES(\$where: RootQueryTo{$this->namespace}VenueConnectionWhereArgs, \$first: Int, \$last: Int ) { |
25 | 25 | $field_key(where: \$where, first: \$first, last: \$last) { |
@@ -11,517 +11,517 @@ |
||
11 | 11 | |
12 | 12 | abstract class AdminMenuItem |
13 | 13 | { |
14 | - public const DISPLAY_NONE = 0; |
|
15 | - |
|
16 | - public const DISPLAY_BLOG_ONLY = 1; |
|
17 | - |
|
18 | - public const DISPLAY_BLOG_AND_NETWORK = 2; |
|
19 | - |
|
20 | - public const DISPLAY_NETWORK_ONLY = 3; |
|
21 | - |
|
22 | - public const TYPE_MENU_TOP = 'top'; |
|
23 | - |
|
24 | - public const TYPE_MENU_GROUP = 'group'; |
|
25 | - |
|
26 | - public const TYPE_MENU_SUB_ITEM = 'sub-item'; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * What capability is required to access this page. |
|
31 | - * |
|
32 | - * @since 4.4.0 |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - protected $capability = 'administrator'; |
|
36 | - |
|
37 | - /** |
|
38 | - * set to TRUE if site is currently in maintenance mode level 2 |
|
39 | - * |
|
40 | - * @var bool |
|
41 | - */ |
|
42 | - protected bool $maintenance_mode = false; |
|
43 | - |
|
44 | - /** |
|
45 | - * Menu maps can define a parent slug that gets used instead of the main parent slug for the menu when |
|
46 | - * EE_Maintenance_Mode::STATUS_FULL_SITE is active. |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - public $maintenance_mode_parent = ''; |
|
51 | - |
|
52 | - /** |
|
53 | - * The callback for displaying the page that the menu references. |
|
54 | - * |
|
55 | - * @since 4.4.0 |
|
56 | - * @var string |
|
57 | - */ |
|
58 | - protected $menu_callback; |
|
59 | - |
|
60 | - /** |
|
61 | - * The EE specific group this menu item belongs in (group slug). |
|
62 | - * |
|
63 | - * @since 4.4.0 |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - protected $menu_group; |
|
67 | - |
|
68 | - /** |
|
69 | - * The label for the menu item. (What shows up in the actual menu). |
|
70 | - * |
|
71 | - * @since 4.4.0 |
|
72 | - * @var string |
|
73 | - */ |
|
74 | - protected $menu_label; |
|
75 | - |
|
76 | - /** |
|
77 | - * What order this item should be in the menu. |
|
78 | - * |
|
79 | - * @since 4.4.0 |
|
80 | - * @var int |
|
81 | - */ |
|
82 | - protected $menu_order; |
|
83 | - |
|
84 | - /** |
|
85 | - * What slug should be used to reference this menu item. |
|
86 | - * |
|
87 | - * @since 4.4.0 |
|
88 | - * @var string |
|
89 | - */ |
|
90 | - protected $menu_slug; |
|
91 | - |
|
92 | - /** |
|
93 | - * What menu item is the parent of this menu item. |
|
94 | - * |
|
95 | - * @since 4.4.0 |
|
96 | - * @var string |
|
97 | - */ |
|
98 | - protected $parent_slug; |
|
99 | - |
|
100 | - /** |
|
101 | - * set to TRUE once menu item has been added to generated menu |
|
102 | - * |
|
103 | - * @var bool |
|
104 | - */ |
|
105 | - protected $registered = false; |
|
106 | - |
|
107 | - /** |
|
108 | - * Whether this item is displayed in the menu or not. |
|
109 | - * Sometimes an EE Admin Page needs to register itself but is not accessible via the WordPress |
|
110 | - * admin menu. |
|
111 | - * |
|
112 | - * @since 4.4.0 |
|
113 | - * @var int |
|
114 | - */ |
|
115 | - protected $show_on_menu = self::DISPLAY_BLOG_ONLY; |
|
116 | - |
|
117 | - /** |
|
118 | - * The title for the menu page. (the page the menu links to) |
|
119 | - * |
|
120 | - * @since 4.4.0 |
|
121 | - * @var string |
|
122 | - */ |
|
123 | - protected $title; |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @param array $menu_args An array of arguments used to setup the menu properties on construct. |
|
128 | - * @param array $required An array of keys that should be in the $menu_args, |
|
129 | - * this is used to validate that the items that should be defined are present. |
|
130 | - * @return void |
|
131 | - * @throws DomainException |
|
132 | - * @throws InvalidArgumentException |
|
133 | - * @throws OutOfBoundsException |
|
134 | - */ |
|
135 | - public function __construct(array $menu_args, array $required) |
|
136 | - { |
|
137 | - // we don't want this coupling anymore >:( |
|
138 | - unset($menu_args['admin_init_page'], $required['admin_init_page']); |
|
139 | - $this->maintenance_mode = MaintenanceStatus::isFullSite(); |
|
140 | - |
|
141 | - // filter all args before processing so plugins can manipulate various settings for menus. |
|
142 | - $menu_args = apply_filters( |
|
143 | - 'FHEE__EE_Admin_Page_Menu_Map__construct__menu_args', |
|
144 | - $menu_args, |
|
145 | - $required, |
|
146 | - get_class($this) |
|
147 | - ); |
|
148 | - |
|
149 | - $this->verifyRequired($menu_args, $required); |
|
150 | - $this->setProperties($menu_args); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * This method should define how the menu page gets added for this particular item |
|
156 | - * and go ahead and define it. Note that child classes MUST also return the result of |
|
157 | - * the function used to register the WordPress admin page (the wp_page_slug string) |
|
158 | - * |
|
159 | - * @return string wp_page_slug. |
|
160 | - * @since 4.4.0 |
|
161 | - */ |
|
162 | - abstract protected function registerMenuItem(): string; |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Called by client code to use this menu map for registering a WordPress admin page |
|
167 | - * |
|
168 | - * @param boolean $network_admin whether this is being added to the network admin page or not |
|
169 | - * @since 4.4.0 |
|
170 | - */ |
|
171 | - public function registerAdminMenuItem(bool $network_admin = false): string |
|
172 | - { |
|
173 | - $this->registered = true; |
|
174 | - return $this->displayOnBlogAndNetworkAdmin() |
|
175 | - || $this->displayOnBlogAdmin($network_admin) |
|
176 | - || $this->displayOnNetworkAdmin($network_admin) |
|
177 | - ? $this->registerMenuItem() |
|
178 | - : ''; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @param array $menu_args |
|
184 | - * @param array $required |
|
185 | - * @throws DomainException |
|
186 | - */ |
|
187 | - private function verifyRequired(array $menu_args, array $required) |
|
188 | - { |
|
189 | - // verify that required keys are present in the incoming array. |
|
190 | - $missing = array_diff($required, array_keys($menu_args)); |
|
191 | - |
|
192 | - if (! empty($missing)) { |
|
193 | - throw new DomainException( |
|
194 | - sprintf( |
|
195 | - esc_html__( |
|
196 | - '%1$s is missing some expected keys in the argument array. The following keys are missing: %2$s', |
|
197 | - 'event_espresso' |
|
198 | - ), |
|
199 | - get_class($this), |
|
200 | - implode(', ', $missing) |
|
201 | - ) |
|
202 | - ); |
|
203 | - } |
|
204 | - |
|
205 | - if ( |
|
206 | - in_array('admin_init_page', $required, true) |
|
207 | - && ! (isset($menu_args['admin_init_page']) && $menu_args['admin_init_page'] instanceof EE_Admin_Page_Init) |
|
208 | - ) { |
|
209 | - throw new InvalidArgumentException( |
|
210 | - sprintf( |
|
211 | - esc_html__( |
|
212 | - 'The value for the "admin_init_page" argument must be an instance of an EE_Admin_Page_Init object. Instead %s was given as the value.', |
|
213 | - 'event_espresso' |
|
214 | - ), |
|
215 | - print_r($menu_args['admin_init_page'] ?? null, true) |
|
216 | - ) |
|
217 | - ); |
|
218 | - } |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * @param array $menu_args |
|
224 | - * @throws InvalidArgumentException |
|
225 | - * @throws OutOfBoundsException |
|
226 | - */ |
|
227 | - private function setProperties(array $menu_args) |
|
228 | - { |
|
229 | - $menu_args += [ |
|
230 | - 'capability' => 'ee_read_ee', |
|
231 | - 'maintenance_mode_parent' => '', |
|
232 | - 'menu_callback' => null, |
|
233 | - 'menu_group' => '', |
|
234 | - 'menu_label' => '', |
|
235 | - 'menu_order' => 100, |
|
236 | - 'menu_slug' => '', |
|
237 | - 'parent_slug' => 'espresso_events', |
|
238 | - 'show_on_menu' => AdminMenuItem::DISPLAY_NONE, |
|
239 | - 'title' => '', |
|
240 | - ]; |
|
241 | - |
|
242 | - $this->setMenuSlug($menu_args['menu_slug']); |
|
243 | - $this->setCapability($menu_args['capability']); |
|
244 | - $this->setMaintenanceModeParent($menu_args['maintenance_mode_parent']); |
|
245 | - $this->setMenuCallback($menu_args['menu_callback']); |
|
246 | - $this->setMenuGroup($menu_args['menu_group']); |
|
247 | - $this->setMenuLabel($menu_args['menu_label']); |
|
248 | - $this->setMenuOrder($menu_args['menu_order']); |
|
249 | - $this->setParentSlug($menu_args['parent_slug']); |
|
250 | - $this->setShowOnMenu($menu_args['show_on_menu']); |
|
251 | - $this->setTitle($menu_args['title']); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * The capability required for this menu to be displayed to the user. |
|
257 | - * |
|
258 | - * @return string |
|
259 | - */ |
|
260 | - public function capability(): string |
|
261 | - { |
|
262 | - return $this->capability; |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * @param string $capability |
|
268 | - */ |
|
269 | - public function setCapability(string $capability): void |
|
270 | - { |
|
271 | - $this->capability = $capability; |
|
272 | - // filter capabilities (both static and dynamic) |
|
273 | - $this->capability = apply_filters('FHEE_management_capability', $this->capability, null); |
|
274 | - $this->capability = apply_filters('FHEE_' . $this->menu_slug . '_capability', $this->capability, null); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - public function currentUserHasAccess(): bool |
|
279 | - { |
|
280 | - return EE_Capabilities::instance()->current_user_can($this->capability(), $this->menuSlug()); |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * @param bool $network_admin |
|
286 | - * @return bool |
|
287 | - */ |
|
288 | - public function displayOnBlogAdmin(bool $network_admin): bool |
|
289 | - { |
|
290 | - return ! $network_admin && $this->show_on_menu === AdminMenuItem::DISPLAY_BLOG_ONLY; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @return bool |
|
296 | - */ |
|
297 | - public function displayOnBlogAndNetworkAdmin(): bool |
|
298 | - { |
|
299 | - return $this->show_on_menu === AdminMenuItem::DISPLAY_BLOG_AND_NETWORK; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * @param bool $network_admin |
|
305 | - * @return bool |
|
306 | - */ |
|
307 | - public function displayOnNetworkAdmin(bool $network_admin): bool |
|
308 | - { |
|
309 | - return $network_admin && $this->show_on_menu === AdminMenuItem::DISPLAY_NETWORK_ONLY; |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * parent slug to use when site is in full maintenance mode |
|
315 | - * |
|
316 | - * @return string |
|
317 | - */ |
|
318 | - public function maintenanceModeParent(): string |
|
319 | - { |
|
320 | - return $this->maintenance_mode_parent; |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * @param string $maintenance_mode_parent |
|
326 | - */ |
|
327 | - public function setMaintenanceModeParent(string $maintenance_mode_parent): void |
|
328 | - { |
|
329 | - $this->maintenance_mode_parent = $maintenance_mode_parent; |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * Optional. The function to be called to output the content for this page. |
|
335 | - * |
|
336 | - * @return callable|null |
|
337 | - */ |
|
338 | - public function menuCallback(): ?callable |
|
339 | - { |
|
340 | - return $this->menu_callback; |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * @param callable|null $menu_callback |
|
346 | - */ |
|
347 | - public function setMenuCallback(?callable $menu_callback): void |
|
348 | - { |
|
349 | - $this->menu_callback = $menu_callback; |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * Slug for menu group that this menu item will appear under |
|
355 | - * |
|
356 | - * @return string |
|
357 | - */ |
|
358 | - public function menuGroup(): string |
|
359 | - { |
|
360 | - return $this->menu_group; |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * @param string $menu_group |
|
366 | - */ |
|
367 | - public function setMenuGroup(string $menu_group): void |
|
368 | - { |
|
369 | - $this->menu_group = $menu_group; |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * The text to be used for the menu. |
|
375 | - * |
|
376 | - * @return string |
|
377 | - */ |
|
378 | - public function menuLabel(): string |
|
379 | - { |
|
380 | - return $this->menu_label; |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * @param string $menu_label |
|
386 | - */ |
|
387 | - public function setMenuLabel(string $menu_label): void |
|
388 | - { |
|
389 | - $this->menu_label = $menu_label; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * Optional. The position in the menu order this item should appear. |
|
395 | - * |
|
396 | - * @return int |
|
397 | - */ |
|
398 | - public function menuOrder(): int |
|
399 | - { |
|
400 | - return $this->menu_order; |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * @param int $menu_order |
|
406 | - */ |
|
407 | - public function setMenuOrder(int $menu_order): void |
|
408 | - { |
|
409 | - $this->menu_order = absint($menu_order); |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * The slug name to refer to this menu by. Should be unique for this menu |
|
415 | - * |
|
416 | - * @return string |
|
417 | - */ |
|
418 | - public function menuSlug(): string |
|
419 | - { |
|
420 | - return $this->menu_slug; |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * @param string $menu_slug |
|
426 | - */ |
|
427 | - public function setMenuSlug(string $menu_slug): void |
|
428 | - { |
|
429 | - $this->menu_slug = sanitize_key($menu_slug); |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * The slug name for the parent menu (or the file name of a standard WordPress admin page). |
|
435 | - * |
|
436 | - * @return string |
|
437 | - */ |
|
438 | - public function parentSlug(): string |
|
439 | - { |
|
440 | - return $this->parent_slug; |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * if site is in full maintenance mode, |
|
446 | - * then parent slug will be swapped with the maintenance_mode_parent if that property has been set |
|
447 | - * |
|
448 | - * @param string $parent_slug |
|
449 | - */ |
|
450 | - public function setParentSlug(string $parent_slug): void |
|
451 | - { |
|
452 | - $this->parent_slug = $this->maintenance_mode && $this->maintenance_mode_parent |
|
453 | - ? $this->maintenance_mode_parent |
|
454 | - : $parent_slug; |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * returns true if menu item has already been registered with WP core |
|
460 | - * |
|
461 | - * @return bool |
|
462 | - */ |
|
463 | - public function isRegistered(): bool |
|
464 | - { |
|
465 | - return $this->registered; |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - /** |
|
470 | - * returns TRUE if: |
|
471 | - * - site is currently NOT in full site maintenance mode |
|
472 | - * - site IS in full site maintenance mode and menu item has a valid maintenance mode parent |
|
473 | - * |
|
474 | - * @return int |
|
475 | - */ |
|
476 | - public function showOnMaintenanceModeMenu(): int |
|
477 | - { |
|
478 | - return ! $this->maintenance_mode || $this->maintenanceModeParent() !== ''; |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * @param int $show_on_menu |
|
484 | - * @throws DomainException |
|
485 | - */ |
|
486 | - public function setShowOnMenu(int $show_on_menu): void |
|
487 | - { |
|
488 | - $valid_menu_options = [ |
|
489 | - AdminMenuItem::DISPLAY_NONE, |
|
490 | - AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
491 | - AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
|
492 | - AdminMenuItem::DISPLAY_NETWORK_ONLY, |
|
493 | - ]; |
|
494 | - if (! in_array($show_on_menu, $valid_menu_options, true)) { |
|
495 | - throw new DomainException( |
|
496 | - sprintf( |
|
497 | - esc_html__( |
|
498 | - 'Invalid "ShowOnMenu" option of "%1$s" supplied. You must use one of the AdminMenuItem::DISPLAY_* constants.', |
|
499 | - 'event_espresso' |
|
500 | - ), |
|
501 | - $show_on_menu |
|
502 | - ) |
|
503 | - ); |
|
504 | - } |
|
505 | - $this->show_on_menu = $show_on_menu; |
|
506 | - } |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * The text to be displayed in the title tags of the page when the menu is selected |
|
511 | - * |
|
512 | - * @return string |
|
513 | - */ |
|
514 | - public function title(): string |
|
515 | - { |
|
516 | - return $this->title; |
|
517 | - } |
|
518 | - |
|
519 | - |
|
520 | - /** |
|
521 | - * @param string $title |
|
522 | - */ |
|
523 | - public function setTitle(string $title): void |
|
524 | - { |
|
525 | - $this->title = $title; |
|
526 | - } |
|
14 | + public const DISPLAY_NONE = 0; |
|
15 | + |
|
16 | + public const DISPLAY_BLOG_ONLY = 1; |
|
17 | + |
|
18 | + public const DISPLAY_BLOG_AND_NETWORK = 2; |
|
19 | + |
|
20 | + public const DISPLAY_NETWORK_ONLY = 3; |
|
21 | + |
|
22 | + public const TYPE_MENU_TOP = 'top'; |
|
23 | + |
|
24 | + public const TYPE_MENU_GROUP = 'group'; |
|
25 | + |
|
26 | + public const TYPE_MENU_SUB_ITEM = 'sub-item'; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * What capability is required to access this page. |
|
31 | + * |
|
32 | + * @since 4.4.0 |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + protected $capability = 'administrator'; |
|
36 | + |
|
37 | + /** |
|
38 | + * set to TRUE if site is currently in maintenance mode level 2 |
|
39 | + * |
|
40 | + * @var bool |
|
41 | + */ |
|
42 | + protected bool $maintenance_mode = false; |
|
43 | + |
|
44 | + /** |
|
45 | + * Menu maps can define a parent slug that gets used instead of the main parent slug for the menu when |
|
46 | + * EE_Maintenance_Mode::STATUS_FULL_SITE is active. |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + public $maintenance_mode_parent = ''; |
|
51 | + |
|
52 | + /** |
|
53 | + * The callback for displaying the page that the menu references. |
|
54 | + * |
|
55 | + * @since 4.4.0 |
|
56 | + * @var string |
|
57 | + */ |
|
58 | + protected $menu_callback; |
|
59 | + |
|
60 | + /** |
|
61 | + * The EE specific group this menu item belongs in (group slug). |
|
62 | + * |
|
63 | + * @since 4.4.0 |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + protected $menu_group; |
|
67 | + |
|
68 | + /** |
|
69 | + * The label for the menu item. (What shows up in the actual menu). |
|
70 | + * |
|
71 | + * @since 4.4.0 |
|
72 | + * @var string |
|
73 | + */ |
|
74 | + protected $menu_label; |
|
75 | + |
|
76 | + /** |
|
77 | + * What order this item should be in the menu. |
|
78 | + * |
|
79 | + * @since 4.4.0 |
|
80 | + * @var int |
|
81 | + */ |
|
82 | + protected $menu_order; |
|
83 | + |
|
84 | + /** |
|
85 | + * What slug should be used to reference this menu item. |
|
86 | + * |
|
87 | + * @since 4.4.0 |
|
88 | + * @var string |
|
89 | + */ |
|
90 | + protected $menu_slug; |
|
91 | + |
|
92 | + /** |
|
93 | + * What menu item is the parent of this menu item. |
|
94 | + * |
|
95 | + * @since 4.4.0 |
|
96 | + * @var string |
|
97 | + */ |
|
98 | + protected $parent_slug; |
|
99 | + |
|
100 | + /** |
|
101 | + * set to TRUE once menu item has been added to generated menu |
|
102 | + * |
|
103 | + * @var bool |
|
104 | + */ |
|
105 | + protected $registered = false; |
|
106 | + |
|
107 | + /** |
|
108 | + * Whether this item is displayed in the menu or not. |
|
109 | + * Sometimes an EE Admin Page needs to register itself but is not accessible via the WordPress |
|
110 | + * admin menu. |
|
111 | + * |
|
112 | + * @since 4.4.0 |
|
113 | + * @var int |
|
114 | + */ |
|
115 | + protected $show_on_menu = self::DISPLAY_BLOG_ONLY; |
|
116 | + |
|
117 | + /** |
|
118 | + * The title for the menu page. (the page the menu links to) |
|
119 | + * |
|
120 | + * @since 4.4.0 |
|
121 | + * @var string |
|
122 | + */ |
|
123 | + protected $title; |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @param array $menu_args An array of arguments used to setup the menu properties on construct. |
|
128 | + * @param array $required An array of keys that should be in the $menu_args, |
|
129 | + * this is used to validate that the items that should be defined are present. |
|
130 | + * @return void |
|
131 | + * @throws DomainException |
|
132 | + * @throws InvalidArgumentException |
|
133 | + * @throws OutOfBoundsException |
|
134 | + */ |
|
135 | + public function __construct(array $menu_args, array $required) |
|
136 | + { |
|
137 | + // we don't want this coupling anymore >:( |
|
138 | + unset($menu_args['admin_init_page'], $required['admin_init_page']); |
|
139 | + $this->maintenance_mode = MaintenanceStatus::isFullSite(); |
|
140 | + |
|
141 | + // filter all args before processing so plugins can manipulate various settings for menus. |
|
142 | + $menu_args = apply_filters( |
|
143 | + 'FHEE__EE_Admin_Page_Menu_Map__construct__menu_args', |
|
144 | + $menu_args, |
|
145 | + $required, |
|
146 | + get_class($this) |
|
147 | + ); |
|
148 | + |
|
149 | + $this->verifyRequired($menu_args, $required); |
|
150 | + $this->setProperties($menu_args); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * This method should define how the menu page gets added for this particular item |
|
156 | + * and go ahead and define it. Note that child classes MUST also return the result of |
|
157 | + * the function used to register the WordPress admin page (the wp_page_slug string) |
|
158 | + * |
|
159 | + * @return string wp_page_slug. |
|
160 | + * @since 4.4.0 |
|
161 | + */ |
|
162 | + abstract protected function registerMenuItem(): string; |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Called by client code to use this menu map for registering a WordPress admin page |
|
167 | + * |
|
168 | + * @param boolean $network_admin whether this is being added to the network admin page or not |
|
169 | + * @since 4.4.0 |
|
170 | + */ |
|
171 | + public function registerAdminMenuItem(bool $network_admin = false): string |
|
172 | + { |
|
173 | + $this->registered = true; |
|
174 | + return $this->displayOnBlogAndNetworkAdmin() |
|
175 | + || $this->displayOnBlogAdmin($network_admin) |
|
176 | + || $this->displayOnNetworkAdmin($network_admin) |
|
177 | + ? $this->registerMenuItem() |
|
178 | + : ''; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @param array $menu_args |
|
184 | + * @param array $required |
|
185 | + * @throws DomainException |
|
186 | + */ |
|
187 | + private function verifyRequired(array $menu_args, array $required) |
|
188 | + { |
|
189 | + // verify that required keys are present in the incoming array. |
|
190 | + $missing = array_diff($required, array_keys($menu_args)); |
|
191 | + |
|
192 | + if (! empty($missing)) { |
|
193 | + throw new DomainException( |
|
194 | + sprintf( |
|
195 | + esc_html__( |
|
196 | + '%1$s is missing some expected keys in the argument array. The following keys are missing: %2$s', |
|
197 | + 'event_espresso' |
|
198 | + ), |
|
199 | + get_class($this), |
|
200 | + implode(', ', $missing) |
|
201 | + ) |
|
202 | + ); |
|
203 | + } |
|
204 | + |
|
205 | + if ( |
|
206 | + in_array('admin_init_page', $required, true) |
|
207 | + && ! (isset($menu_args['admin_init_page']) && $menu_args['admin_init_page'] instanceof EE_Admin_Page_Init) |
|
208 | + ) { |
|
209 | + throw new InvalidArgumentException( |
|
210 | + sprintf( |
|
211 | + esc_html__( |
|
212 | + 'The value for the "admin_init_page" argument must be an instance of an EE_Admin_Page_Init object. Instead %s was given as the value.', |
|
213 | + 'event_espresso' |
|
214 | + ), |
|
215 | + print_r($menu_args['admin_init_page'] ?? null, true) |
|
216 | + ) |
|
217 | + ); |
|
218 | + } |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * @param array $menu_args |
|
224 | + * @throws InvalidArgumentException |
|
225 | + * @throws OutOfBoundsException |
|
226 | + */ |
|
227 | + private function setProperties(array $menu_args) |
|
228 | + { |
|
229 | + $menu_args += [ |
|
230 | + 'capability' => 'ee_read_ee', |
|
231 | + 'maintenance_mode_parent' => '', |
|
232 | + 'menu_callback' => null, |
|
233 | + 'menu_group' => '', |
|
234 | + 'menu_label' => '', |
|
235 | + 'menu_order' => 100, |
|
236 | + 'menu_slug' => '', |
|
237 | + 'parent_slug' => 'espresso_events', |
|
238 | + 'show_on_menu' => AdminMenuItem::DISPLAY_NONE, |
|
239 | + 'title' => '', |
|
240 | + ]; |
|
241 | + |
|
242 | + $this->setMenuSlug($menu_args['menu_slug']); |
|
243 | + $this->setCapability($menu_args['capability']); |
|
244 | + $this->setMaintenanceModeParent($menu_args['maintenance_mode_parent']); |
|
245 | + $this->setMenuCallback($menu_args['menu_callback']); |
|
246 | + $this->setMenuGroup($menu_args['menu_group']); |
|
247 | + $this->setMenuLabel($menu_args['menu_label']); |
|
248 | + $this->setMenuOrder($menu_args['menu_order']); |
|
249 | + $this->setParentSlug($menu_args['parent_slug']); |
|
250 | + $this->setShowOnMenu($menu_args['show_on_menu']); |
|
251 | + $this->setTitle($menu_args['title']); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * The capability required for this menu to be displayed to the user. |
|
257 | + * |
|
258 | + * @return string |
|
259 | + */ |
|
260 | + public function capability(): string |
|
261 | + { |
|
262 | + return $this->capability; |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * @param string $capability |
|
268 | + */ |
|
269 | + public function setCapability(string $capability): void |
|
270 | + { |
|
271 | + $this->capability = $capability; |
|
272 | + // filter capabilities (both static and dynamic) |
|
273 | + $this->capability = apply_filters('FHEE_management_capability', $this->capability, null); |
|
274 | + $this->capability = apply_filters('FHEE_' . $this->menu_slug . '_capability', $this->capability, null); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + public function currentUserHasAccess(): bool |
|
279 | + { |
|
280 | + return EE_Capabilities::instance()->current_user_can($this->capability(), $this->menuSlug()); |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * @param bool $network_admin |
|
286 | + * @return bool |
|
287 | + */ |
|
288 | + public function displayOnBlogAdmin(bool $network_admin): bool |
|
289 | + { |
|
290 | + return ! $network_admin && $this->show_on_menu === AdminMenuItem::DISPLAY_BLOG_ONLY; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * @return bool |
|
296 | + */ |
|
297 | + public function displayOnBlogAndNetworkAdmin(): bool |
|
298 | + { |
|
299 | + return $this->show_on_menu === AdminMenuItem::DISPLAY_BLOG_AND_NETWORK; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * @param bool $network_admin |
|
305 | + * @return bool |
|
306 | + */ |
|
307 | + public function displayOnNetworkAdmin(bool $network_admin): bool |
|
308 | + { |
|
309 | + return $network_admin && $this->show_on_menu === AdminMenuItem::DISPLAY_NETWORK_ONLY; |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * parent slug to use when site is in full maintenance mode |
|
315 | + * |
|
316 | + * @return string |
|
317 | + */ |
|
318 | + public function maintenanceModeParent(): string |
|
319 | + { |
|
320 | + return $this->maintenance_mode_parent; |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * @param string $maintenance_mode_parent |
|
326 | + */ |
|
327 | + public function setMaintenanceModeParent(string $maintenance_mode_parent): void |
|
328 | + { |
|
329 | + $this->maintenance_mode_parent = $maintenance_mode_parent; |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * Optional. The function to be called to output the content for this page. |
|
335 | + * |
|
336 | + * @return callable|null |
|
337 | + */ |
|
338 | + public function menuCallback(): ?callable |
|
339 | + { |
|
340 | + return $this->menu_callback; |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * @param callable|null $menu_callback |
|
346 | + */ |
|
347 | + public function setMenuCallback(?callable $menu_callback): void |
|
348 | + { |
|
349 | + $this->menu_callback = $menu_callback; |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * Slug for menu group that this menu item will appear under |
|
355 | + * |
|
356 | + * @return string |
|
357 | + */ |
|
358 | + public function menuGroup(): string |
|
359 | + { |
|
360 | + return $this->menu_group; |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * @param string $menu_group |
|
366 | + */ |
|
367 | + public function setMenuGroup(string $menu_group): void |
|
368 | + { |
|
369 | + $this->menu_group = $menu_group; |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * The text to be used for the menu. |
|
375 | + * |
|
376 | + * @return string |
|
377 | + */ |
|
378 | + public function menuLabel(): string |
|
379 | + { |
|
380 | + return $this->menu_label; |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * @param string $menu_label |
|
386 | + */ |
|
387 | + public function setMenuLabel(string $menu_label): void |
|
388 | + { |
|
389 | + $this->menu_label = $menu_label; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * Optional. The position in the menu order this item should appear. |
|
395 | + * |
|
396 | + * @return int |
|
397 | + */ |
|
398 | + public function menuOrder(): int |
|
399 | + { |
|
400 | + return $this->menu_order; |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * @param int $menu_order |
|
406 | + */ |
|
407 | + public function setMenuOrder(int $menu_order): void |
|
408 | + { |
|
409 | + $this->menu_order = absint($menu_order); |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * The slug name to refer to this menu by. Should be unique for this menu |
|
415 | + * |
|
416 | + * @return string |
|
417 | + */ |
|
418 | + public function menuSlug(): string |
|
419 | + { |
|
420 | + return $this->menu_slug; |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * @param string $menu_slug |
|
426 | + */ |
|
427 | + public function setMenuSlug(string $menu_slug): void |
|
428 | + { |
|
429 | + $this->menu_slug = sanitize_key($menu_slug); |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * The slug name for the parent menu (or the file name of a standard WordPress admin page). |
|
435 | + * |
|
436 | + * @return string |
|
437 | + */ |
|
438 | + public function parentSlug(): string |
|
439 | + { |
|
440 | + return $this->parent_slug; |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * if site is in full maintenance mode, |
|
446 | + * then parent slug will be swapped with the maintenance_mode_parent if that property has been set |
|
447 | + * |
|
448 | + * @param string $parent_slug |
|
449 | + */ |
|
450 | + public function setParentSlug(string $parent_slug): void |
|
451 | + { |
|
452 | + $this->parent_slug = $this->maintenance_mode && $this->maintenance_mode_parent |
|
453 | + ? $this->maintenance_mode_parent |
|
454 | + : $parent_slug; |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * returns true if menu item has already been registered with WP core |
|
460 | + * |
|
461 | + * @return bool |
|
462 | + */ |
|
463 | + public function isRegistered(): bool |
|
464 | + { |
|
465 | + return $this->registered; |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + /** |
|
470 | + * returns TRUE if: |
|
471 | + * - site is currently NOT in full site maintenance mode |
|
472 | + * - site IS in full site maintenance mode and menu item has a valid maintenance mode parent |
|
473 | + * |
|
474 | + * @return int |
|
475 | + */ |
|
476 | + public function showOnMaintenanceModeMenu(): int |
|
477 | + { |
|
478 | + return ! $this->maintenance_mode || $this->maintenanceModeParent() !== ''; |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * @param int $show_on_menu |
|
484 | + * @throws DomainException |
|
485 | + */ |
|
486 | + public function setShowOnMenu(int $show_on_menu): void |
|
487 | + { |
|
488 | + $valid_menu_options = [ |
|
489 | + AdminMenuItem::DISPLAY_NONE, |
|
490 | + AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
491 | + AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
|
492 | + AdminMenuItem::DISPLAY_NETWORK_ONLY, |
|
493 | + ]; |
|
494 | + if (! in_array($show_on_menu, $valid_menu_options, true)) { |
|
495 | + throw new DomainException( |
|
496 | + sprintf( |
|
497 | + esc_html__( |
|
498 | + 'Invalid "ShowOnMenu" option of "%1$s" supplied. You must use one of the AdminMenuItem::DISPLAY_* constants.', |
|
499 | + 'event_espresso' |
|
500 | + ), |
|
501 | + $show_on_menu |
|
502 | + ) |
|
503 | + ); |
|
504 | + } |
|
505 | + $this->show_on_menu = $show_on_menu; |
|
506 | + } |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * The text to be displayed in the title tags of the page when the menu is selected |
|
511 | + * |
|
512 | + * @return string |
|
513 | + */ |
|
514 | + public function title(): string |
|
515 | + { |
|
516 | + return $this->title; |
|
517 | + } |
|
518 | + |
|
519 | + |
|
520 | + /** |
|
521 | + * @param string $title |
|
522 | + */ |
|
523 | + public function setTitle(string $title): void |
|
524 | + { |
|
525 | + $this->title = $title; |
|
526 | + } |
|
527 | 527 | } |
@@ -27,103 +27,103 @@ |
||
27 | 27 | */ |
28 | 28 | class AdminRoute extends Route |
29 | 29 | { |
30 | - protected EE_Admin_Config $admin_config; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var array $default_dependencies |
|
34 | - */ |
|
35 | - protected static $default_dependencies = [ |
|
36 | - 'EE_Admin_Config' => EE_Dependency_Map::load_from_cache, |
|
37 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
38 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
39 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
40 | - ]; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * Route constructor. |
|
45 | - * |
|
46 | - * @param EE_Admin_Config $admin_config |
|
47 | - * @param EE_Dependency_Map $dependency_map |
|
48 | - * @param LoaderInterface $loader |
|
49 | - * @param RequestInterface $request |
|
50 | - * @param JsonDataNode|null $data_node |
|
51 | - * @param RouteMatchSpecificationInterface|null $specification |
|
52 | - */ |
|
53 | - public function __construct( |
|
54 | - EE_Admin_Config $admin_config, |
|
55 | - EE_Dependency_Map $dependency_map, |
|
56 | - LoaderInterface $loader, |
|
57 | - RequestInterface $request, |
|
58 | - JsonDataNode $data_node = null, |
|
59 | - RouteMatchSpecificationInterface $specification = null |
|
60 | - ) { |
|
61 | - $this->admin_config = $admin_config; |
|
62 | - parent::__construct($dependency_map, $loader, $request, $data_node, $specification); |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * @return CapCheckInterface |
|
68 | - */ |
|
69 | - public function getCapCheck() |
|
70 | - { |
|
71 | - return new CapCheck('ee_read_events', 'access Event Espresso admin route'); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @return array |
|
77 | - */ |
|
78 | - public static function getDefaultDependencies(): array |
|
79 | - { |
|
80 | - return self::$default_dependencies; |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * returns true if the current request matches this route |
|
86 | - * |
|
87 | - * @return bool |
|
88 | - */ |
|
89 | - public function matchesCurrentRequest(): bool |
|
90 | - { |
|
91 | - return $this->request->isAdmin() || $this->request->isAdminAjax() || $this->request->isActivation(); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @return void |
|
97 | - */ |
|
98 | - protected function registerDependencies() |
|
99 | - { |
|
100 | - $this->dependency_map->registerDependencies( |
|
101 | - 'EventEspresso\core\services\admin\AdminListTableFilters', |
|
102 | - [ |
|
103 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
104 | - ] |
|
105 | - ); |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * implements logic required to run during request |
|
111 | - * |
|
112 | - * @return bool |
|
113 | - */ |
|
114 | - protected function requestHandler(): bool |
|
115 | - { |
|
116 | - // don't handle request more than once!!! |
|
117 | - if (did_action('AHEE__EE_System__load_controllers__load_admin_controllers')) { |
|
118 | - return true; |
|
119 | - } |
|
120 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
121 | - $this->loader->getShared('EE_Admin'); |
|
122 | - do_action( |
|
123 | - 'AHEE__EventEspresso_core_domain_entities_routing_handlers_admin_AdminRoute__requestHandler__admin_loaded' |
|
124 | - ); |
|
125 | - |
|
126 | - AdminFontSize::setAdminFontSizeBodyClass(); |
|
127 | - return true; |
|
128 | - } |
|
30 | + protected EE_Admin_Config $admin_config; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var array $default_dependencies |
|
34 | + */ |
|
35 | + protected static $default_dependencies = [ |
|
36 | + 'EE_Admin_Config' => EE_Dependency_Map::load_from_cache, |
|
37 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
38 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
39 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
40 | + ]; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * Route constructor. |
|
45 | + * |
|
46 | + * @param EE_Admin_Config $admin_config |
|
47 | + * @param EE_Dependency_Map $dependency_map |
|
48 | + * @param LoaderInterface $loader |
|
49 | + * @param RequestInterface $request |
|
50 | + * @param JsonDataNode|null $data_node |
|
51 | + * @param RouteMatchSpecificationInterface|null $specification |
|
52 | + */ |
|
53 | + public function __construct( |
|
54 | + EE_Admin_Config $admin_config, |
|
55 | + EE_Dependency_Map $dependency_map, |
|
56 | + LoaderInterface $loader, |
|
57 | + RequestInterface $request, |
|
58 | + JsonDataNode $data_node = null, |
|
59 | + RouteMatchSpecificationInterface $specification = null |
|
60 | + ) { |
|
61 | + $this->admin_config = $admin_config; |
|
62 | + parent::__construct($dependency_map, $loader, $request, $data_node, $specification); |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * @return CapCheckInterface |
|
68 | + */ |
|
69 | + public function getCapCheck() |
|
70 | + { |
|
71 | + return new CapCheck('ee_read_events', 'access Event Espresso admin route'); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @return array |
|
77 | + */ |
|
78 | + public static function getDefaultDependencies(): array |
|
79 | + { |
|
80 | + return self::$default_dependencies; |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * returns true if the current request matches this route |
|
86 | + * |
|
87 | + * @return bool |
|
88 | + */ |
|
89 | + public function matchesCurrentRequest(): bool |
|
90 | + { |
|
91 | + return $this->request->isAdmin() || $this->request->isAdminAjax() || $this->request->isActivation(); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @return void |
|
97 | + */ |
|
98 | + protected function registerDependencies() |
|
99 | + { |
|
100 | + $this->dependency_map->registerDependencies( |
|
101 | + 'EventEspresso\core\services\admin\AdminListTableFilters', |
|
102 | + [ |
|
103 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
104 | + ] |
|
105 | + ); |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * implements logic required to run during request |
|
111 | + * |
|
112 | + * @return bool |
|
113 | + */ |
|
114 | + protected function requestHandler(): bool |
|
115 | + { |
|
116 | + // don't handle request more than once!!! |
|
117 | + if (did_action('AHEE__EE_System__load_controllers__load_admin_controllers')) { |
|
118 | + return true; |
|
119 | + } |
|
120 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
121 | + $this->loader->getShared('EE_Admin'); |
|
122 | + do_action( |
|
123 | + 'AHEE__EventEspresso_core_domain_entities_routing_handlers_admin_AdminRoute__requestHandler__admin_loaded' |
|
124 | + ); |
|
125 | + |
|
126 | + AdminFontSize::setAdminFontSizeBodyClass(); |
|
127 | + return true; |
|
128 | + } |
|
129 | 129 | } |
@@ -16,84 +16,84 @@ |
||
16 | 16 | */ |
17 | 17 | class PersonalDataRequests extends PublicRoute |
18 | 18 | { |
19 | - /** |
|
20 | - * returns true if the current request matches this route |
|
21 | - * |
|
22 | - * @return bool |
|
23 | - * @since 5.0.0.p |
|
24 | - */ |
|
25 | - public function matchesCurrentRequest(): bool |
|
26 | - { |
|
27 | - return ($this->request->isAdmin() || $this->request->isAjax()) && DbStatus::isOnline(); |
|
28 | - } |
|
19 | + /** |
|
20 | + * returns true if the current request matches this route |
|
21 | + * |
|
22 | + * @return bool |
|
23 | + * @since 5.0.0.p |
|
24 | + */ |
|
25 | + public function matchesCurrentRequest(): bool |
|
26 | + { |
|
27 | + return ($this->request->isAdmin() || $this->request->isAjax()) && DbStatus::isOnline(); |
|
28 | + } |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * @since 5.0.0.p |
|
33 | - */ |
|
34 | - protected function registerDependencies() |
|
35 | - { |
|
36 | - $this->dependency_map->registerDependencies( |
|
37 | - 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy', |
|
38 | - [ |
|
39 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
40 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
41 | - ] |
|
42 | - ); |
|
43 | - $this->dependency_map->registerDependencies( |
|
44 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee', |
|
45 | - ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
46 | - ); |
|
47 | - $this->dependency_map->registerDependencies( |
|
48 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData', |
|
49 | - [ |
|
50 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
51 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
52 | - ] |
|
53 | - ); |
|
54 | - $this->dependency_map->registerDependencies( |
|
55 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins', |
|
56 | - ['EEM_Checkin' => EE_Dependency_Map::load_from_cache] |
|
57 | - ); |
|
58 | - $this->dependency_map->registerDependencies( |
|
59 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration', |
|
60 | - ['EEM_Registration' => EE_Dependency_Map::load_from_cache] |
|
61 | - ); |
|
62 | - $this->dependency_map->registerDependencies( |
|
63 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction', |
|
64 | - ['EEM_Transaction' => EE_Dependency_Map::load_from_cache] |
|
65 | - ); |
|
66 | - $this->dependency_map->registerDependencies( |
|
67 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData', |
|
68 | - ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
69 | - ); |
|
70 | - $this->dependency_map->registerDependencies( |
|
71 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers', |
|
72 | - [ |
|
73 | - 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
74 | - 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
75 | - ] |
|
76 | - ); |
|
77 | - $this->dependency_map->registerDependencies( |
|
78 | - 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler', |
|
79 | - [ |
|
80 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
81 | - 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
82 | - ] |
|
83 | - ); |
|
84 | - } |
|
31 | + /** |
|
32 | + * @since 5.0.0.p |
|
33 | + */ |
|
34 | + protected function registerDependencies() |
|
35 | + { |
|
36 | + $this->dependency_map->registerDependencies( |
|
37 | + 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy', |
|
38 | + [ |
|
39 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
40 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
41 | + ] |
|
42 | + ); |
|
43 | + $this->dependency_map->registerDependencies( |
|
44 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee', |
|
45 | + ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
46 | + ); |
|
47 | + $this->dependency_map->registerDependencies( |
|
48 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData', |
|
49 | + [ |
|
50 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
51 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
52 | + ] |
|
53 | + ); |
|
54 | + $this->dependency_map->registerDependencies( |
|
55 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins', |
|
56 | + ['EEM_Checkin' => EE_Dependency_Map::load_from_cache] |
|
57 | + ); |
|
58 | + $this->dependency_map->registerDependencies( |
|
59 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration', |
|
60 | + ['EEM_Registration' => EE_Dependency_Map::load_from_cache] |
|
61 | + ); |
|
62 | + $this->dependency_map->registerDependencies( |
|
63 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction', |
|
64 | + ['EEM_Transaction' => EE_Dependency_Map::load_from_cache] |
|
65 | + ); |
|
66 | + $this->dependency_map->registerDependencies( |
|
67 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData', |
|
68 | + ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
69 | + ); |
|
70 | + $this->dependency_map->registerDependencies( |
|
71 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers', |
|
72 | + [ |
|
73 | + 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
74 | + 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
75 | + ] |
|
76 | + ); |
|
77 | + $this->dependency_map->registerDependencies( |
|
78 | + 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler', |
|
79 | + [ |
|
80 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
81 | + 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
82 | + ] |
|
83 | + ); |
|
84 | + } |
|
85 | 85 | |
86 | 86 | |
87 | - /** |
|
88 | - * implements logic required to run during request |
|
89 | - * |
|
90 | - * @return bool |
|
91 | - * @since 5.0.0.p |
|
92 | - */ |
|
93 | - protected function requestHandler(): bool |
|
94 | - { |
|
95 | - $this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager'); |
|
96 | - $this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager'); |
|
97 | - return true; |
|
98 | - } |
|
87 | + /** |
|
88 | + * implements logic required to run during request |
|
89 | + * |
|
90 | + * @return bool |
|
91 | + * @since 5.0.0.p |
|
92 | + */ |
|
93 | + protected function requestHandler(): bool |
|
94 | + { |
|
95 | + $this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager'); |
|
96 | + $this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager'); |
|
97 | + return true; |
|
98 | + } |
|
99 | 99 | } |