@@ -13,649 +13,649 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Payment_Method extends EE_Base_Class |
15 | 15 | { |
16 | - /** |
|
17 | - * Payment Method type object, which has all the info about this type of payment method, |
|
18 | - * including functions for processing payments, to get settings forms, etc. |
|
19 | - * |
|
20 | - * @var EE_PMT_Base|null |
|
21 | - */ |
|
22 | - protected ?EE_PMT_Base $_type_obj = null; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * @param array $props_n_values |
|
27 | - * @return EE_Payment_Method |
|
28 | - * @throws EE_Error |
|
29 | - * @throws ReflectionException |
|
30 | - */ |
|
31 | - public static function new_instance($props_n_values = []) |
|
32 | - { |
|
33 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
34 | - return $has_object ?: new self($props_n_values, false); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @param array $props_n_values |
|
40 | - * @return EE_Payment_Method |
|
41 | - * @throws EE_Error |
|
42 | - * @throws ReflectionException |
|
43 | - */ |
|
44 | - public static function new_instance_from_db($props_n_values = []) |
|
45 | - { |
|
46 | - return new self($props_n_values, true); |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
53 | - * Otherwise returns a normal EE_Payment_Method |
|
54 | - * |
|
55 | - * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
56 | - * the classname minus 'EEPM_') |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - // private static function _payment_method_type($props_n_values) |
|
60 | - // { |
|
61 | - // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
62 | - // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
63 | - // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
64 | - // return 'EEPM_' . $type_string; |
|
65 | - // } else { |
|
66 | - // return __CLASS__; |
|
67 | - // } |
|
68 | - // } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
73 | - * |
|
74 | - * @return int[]|string[] |
|
75 | - * @throws EE_Error |
|
76 | - * @throws ReflectionException |
|
77 | - */ |
|
78 | - public function active(): array |
|
79 | - { |
|
80 | - return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
86 | - * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
87 | - * |
|
88 | - * @throws EE_Error |
|
89 | - * @throws ReflectionException |
|
90 | - */ |
|
91 | - public function set_active() |
|
92 | - { |
|
93 | - $default_scopes = [EEM_Payment_Method::scope_cart]; |
|
94 | - if ( |
|
95 | - $this->type_obj() && |
|
96 | - $this->type_obj()->payment_occurs() === EE_PMT_Base::offline |
|
97 | - ) { |
|
98 | - $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
99 | - } |
|
100 | - $this->set_scope($default_scopes); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
106 | - */ |
|
107 | - public function deactivate() |
|
108 | - { |
|
109 | - $this->set_scope([]); |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * Gets button_url |
|
115 | - * |
|
116 | - * @return string |
|
117 | - * @throws EE_Error |
|
118 | - * @throws ReflectionException |
|
119 | - */ |
|
120 | - public function button_url() |
|
121 | - { |
|
122 | - return $this->get('PMD_button_url'); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Sets button_url |
|
128 | - * |
|
129 | - * @param string $button_url |
|
130 | - * @throws EE_Error |
|
131 | - * @throws ReflectionException |
|
132 | - */ |
|
133 | - public function set_button_url($button_url) |
|
134 | - { |
|
135 | - $this->set('PMD_button_url', $button_url); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * Gets debug_mode |
|
141 | - * |
|
142 | - * @return boolean |
|
143 | - * @throws EE_Error |
|
144 | - * @throws ReflectionException |
|
145 | - */ |
|
146 | - public function debug_mode(): bool |
|
147 | - { |
|
148 | - return (bool) $this->get('PMD_debug_mode'); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * Sets debug_mode |
|
154 | - * |
|
155 | - * @param boolean $debug_mode |
|
156 | - * @throws EE_Error |
|
157 | - * @throws ReflectionException |
|
158 | - */ |
|
159 | - public function set_debug_mode($debug_mode) |
|
160 | - { |
|
161 | - $this->set('PMD_debug_mode', $debug_mode); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Gets description |
|
167 | - * |
|
168 | - * @return string |
|
169 | - * @throws EE_Error |
|
170 | - * @throws ReflectionException |
|
171 | - */ |
|
172 | - public function description() |
|
173 | - { |
|
174 | - return $this->get('PMD_desc'); |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * Sets description |
|
180 | - * |
|
181 | - * @param string $description |
|
182 | - * @throws EE_Error |
|
183 | - * @throws ReflectionException |
|
184 | - */ |
|
185 | - public function set_description($description) |
|
186 | - { |
|
187 | - $this->set('PMD_desc', $description); |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * Gets name |
|
193 | - * |
|
194 | - * @return string |
|
195 | - * @throws EE_Error |
|
196 | - * @throws ReflectionException |
|
197 | - */ |
|
198 | - public function name() |
|
199 | - { |
|
200 | - return $this->get('PMD_name'); |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * Sets name |
|
206 | - * |
|
207 | - * @param string $name |
|
208 | - * @throws EE_Error |
|
209 | - * @throws ReflectionException |
|
210 | - */ |
|
211 | - public function set_name($name) |
|
212 | - { |
|
213 | - $this->set('PMD_name', $name); |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * Gets open_by_default |
|
219 | - * |
|
220 | - * @return boolean |
|
221 | - * @throws EE_Error |
|
222 | - * @throws ReflectionException |
|
223 | - */ |
|
224 | - public function open_by_default() |
|
225 | - { |
|
226 | - return $this->get('PMD_open_by_default'); |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * Sets open_by_default |
|
232 | - * |
|
233 | - * @param boolean $open_by_default |
|
234 | - * @throws EE_Error |
|
235 | - * @throws ReflectionException |
|
236 | - */ |
|
237 | - public function set_open_by_default($open_by_default) |
|
238 | - { |
|
239 | - $this->set('PMD_open_by_default', $open_by_default); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * Gets order |
|
245 | - * |
|
246 | - * @return int |
|
247 | - * @throws EE_Error |
|
248 | - * @throws ReflectionException |
|
249 | - */ |
|
250 | - public function order() |
|
251 | - { |
|
252 | - return $this->get('PMD_order'); |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * Sets order |
|
258 | - * |
|
259 | - * @param int $order |
|
260 | - * @throws EE_Error |
|
261 | - * @throws ReflectionException |
|
262 | - */ |
|
263 | - public function set_order($order) |
|
264 | - { |
|
265 | - $this->set('PMD_order', $order); |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * Gets slug |
|
271 | - * |
|
272 | - * @return string |
|
273 | - * @throws EE_Error |
|
274 | - * @throws ReflectionException |
|
275 | - */ |
|
276 | - public function slug() |
|
277 | - { |
|
278 | - return $this->get('PMD_slug'); |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * Sets slug |
|
284 | - * |
|
285 | - * @param string $slug |
|
286 | - * @throws EE_Error |
|
287 | - * @throws ReflectionException |
|
288 | - */ |
|
289 | - public function set_slug($slug) |
|
290 | - { |
|
291 | - $this->set('PMD_slug', $slug); |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * Gets type |
|
297 | - * |
|
298 | - * @return string |
|
299 | - * @throws EE_Error |
|
300 | - * @throws ReflectionException |
|
301 | - */ |
|
302 | - public function type() |
|
303 | - { |
|
304 | - return $this->get('PMD_type'); |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * Sets type |
|
310 | - * |
|
311 | - * @param string $type |
|
312 | - * @throws EE_Error |
|
313 | - * @throws ReflectionException |
|
314 | - */ |
|
315 | - public function set_type($type) |
|
316 | - { |
|
317 | - $this->set('PMD_type', $type); |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * Gets wp_user |
|
323 | - * |
|
324 | - * @return int |
|
325 | - * @throws EE_Error |
|
326 | - * @throws ReflectionException |
|
327 | - */ |
|
328 | - public function wp_user() |
|
329 | - { |
|
330 | - return $this->get('PMD_wp_user'); |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * Sets wp_user |
|
336 | - * |
|
337 | - * @param int $wp_user_id |
|
338 | - * @throws EE_Error |
|
339 | - * @throws ReflectionException |
|
340 | - */ |
|
341 | - public function set_wp_user($wp_user_id) |
|
342 | - { |
|
343 | - $this->set('PMD_wp_user', $wp_user_id); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
349 | - * |
|
350 | - * @param string $field_name |
|
351 | - * @param mixed $field_value |
|
352 | - * @param boolean $use_default |
|
353 | - * @throws EE_Error |
|
354 | - * @throws ReflectionException |
|
355 | - */ |
|
356 | - public function set($field_name, $field_value, $use_default = false) |
|
357 | - { |
|
358 | - if ($field_name === 'PMD_type') { |
|
359 | - // the type has probably changed, so forget about its old type object |
|
360 | - $this->_type_obj = null; |
|
361 | - } |
|
362 | - parent::set($field_name, $field_value, $use_default); |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - /** |
|
367 | - * Gets admin_name |
|
368 | - * |
|
369 | - * @return string |
|
370 | - * @throws EE_Error |
|
371 | - * @throws ReflectionException |
|
372 | - */ |
|
373 | - public function admin_name() |
|
374 | - { |
|
375 | - return $this->get('PMD_admin_name'); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * Sets admin_name |
|
381 | - * |
|
382 | - * @param string $admin_name |
|
383 | - * @throws EE_Error |
|
384 | - * @throws ReflectionException |
|
385 | - */ |
|
386 | - public function set_admin_name($admin_name) |
|
387 | - { |
|
388 | - $this->set('PMD_admin_name', $admin_name); |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * Gets admin_desc |
|
394 | - * |
|
395 | - * @return string |
|
396 | - * @throws EE_Error |
|
397 | - * @throws ReflectionException |
|
398 | - */ |
|
399 | - public function admin_desc() |
|
400 | - { |
|
401 | - return $this->get('PMD_admin_desc'); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * Sets admin_desc |
|
407 | - * |
|
408 | - * @param string $admin_desc |
|
409 | - * @throws EE_Error |
|
410 | - * @throws ReflectionException |
|
411 | - */ |
|
412 | - public function set_admin_desc($admin_desc) |
|
413 | - { |
|
414 | - $this->set('PMD_admin_desc', $admin_desc); |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - * Gets scope |
|
420 | - * |
|
421 | - * @return array |
|
422 | - * @throws EE_Error |
|
423 | - * @throws ReflectionException |
|
424 | - */ |
|
425 | - public function scope() |
|
426 | - { |
|
427 | - return (array) $this->get('PMD_scope'); |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * Sets scope |
|
433 | - * |
|
434 | - * @param array $scope |
|
435 | - * @throws EE_Error |
|
436 | - * @throws ReflectionException |
|
437 | - */ |
|
438 | - public function set_scope($scope) |
|
439 | - { |
|
440 | - $this->set('PMD_scope', (array) $scope); |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * Gets the payment method type for this payment method instance |
|
446 | - * |
|
447 | - * @return EE_PMT_Base |
|
448 | - * @throws EE_Error |
|
449 | - * @throws ReflectionException |
|
450 | - */ |
|
451 | - public function type_obj() |
|
452 | - { |
|
453 | - if (! $this->_type_obj) { |
|
454 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
455 | - if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
456 | - $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
457 | - if (! class_exists($class_name)) { |
|
458 | - throw new EE_Error( |
|
459 | - sprintf( |
|
460 | - esc_html__( |
|
461 | - 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
462 | - 'event_espresso' |
|
463 | - ), |
|
464 | - $class_name, |
|
465 | - '<br />', |
|
466 | - '<a href="' . admin_url('plugins.php') . '">', |
|
467 | - '</a>' |
|
468 | - ) |
|
469 | - ); |
|
470 | - } |
|
471 | - $r = new ReflectionClass($class_name); |
|
472 | - $this->_type_obj = $r->newInstanceArgs([$this]); |
|
473 | - } else { |
|
474 | - throw new EE_Error( |
|
475 | - sprintf( |
|
476 | - esc_html__( |
|
477 | - 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
478 | - 'event_espresso' |
|
479 | - ), |
|
480 | - $this->type(), |
|
481 | - implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
482 | - ) |
|
483 | - ); |
|
484 | - } |
|
485 | - } |
|
486 | - return $this->_type_obj; |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - /** |
|
491 | - * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
492 | - * and the extra meta. Mostly used for passing off ot gateways. * |
|
493 | - * |
|
494 | - * @return array |
|
495 | - * @throws EE_Error |
|
496 | - * @throws ReflectionException |
|
497 | - */ |
|
498 | - public function settings_array() |
|
499 | - { |
|
500 | - $fields = $this->model_field_array(); |
|
501 | - $extra_meta = $this->all_extra_meta_array(); |
|
502 | - // remove the model's prefix from the fields |
|
503 | - $combined_settings_array = []; |
|
504 | - foreach ($fields as $key => $value) { |
|
505 | - if (strpos($key, 'PMD_') === 0) { |
|
506 | - $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
507 | - $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
508 | - } |
|
509 | - } |
|
510 | - $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
511 | - return $combined_settings_array; |
|
512 | - } |
|
513 | - |
|
514 | - |
|
515 | - /** |
|
516 | - * Gets the HTML for displaying the payment method on a page. |
|
517 | - * |
|
518 | - * @param string $url |
|
519 | - * @param string $css_class |
|
520 | - * @return string of HTML for displaying the button |
|
521 | - * @throws EE_Error |
|
522 | - * @throws ReflectionException |
|
523 | - */ |
|
524 | - public function button_html($url = '', $css_class = '') |
|
525 | - { |
|
526 | - $payment_occurs = $this->type_obj()->payment_occurs(); |
|
527 | - return ' |
|
16 | + /** |
|
17 | + * Payment Method type object, which has all the info about this type of payment method, |
|
18 | + * including functions for processing payments, to get settings forms, etc. |
|
19 | + * |
|
20 | + * @var EE_PMT_Base|null |
|
21 | + */ |
|
22 | + protected ?EE_PMT_Base $_type_obj = null; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * @param array $props_n_values |
|
27 | + * @return EE_Payment_Method |
|
28 | + * @throws EE_Error |
|
29 | + * @throws ReflectionException |
|
30 | + */ |
|
31 | + public static function new_instance($props_n_values = []) |
|
32 | + { |
|
33 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
34 | + return $has_object ?: new self($props_n_values, false); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @param array $props_n_values |
|
40 | + * @return EE_Payment_Method |
|
41 | + * @throws EE_Error |
|
42 | + * @throws ReflectionException |
|
43 | + */ |
|
44 | + public static function new_instance_from_db($props_n_values = []) |
|
45 | + { |
|
46 | + return new self($props_n_values, true); |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
53 | + * Otherwise returns a normal EE_Payment_Method |
|
54 | + * |
|
55 | + * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
56 | + * the classname minus 'EEPM_') |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + // private static function _payment_method_type($props_n_values) |
|
60 | + // { |
|
61 | + // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
62 | + // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
63 | + // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
64 | + // return 'EEPM_' . $type_string; |
|
65 | + // } else { |
|
66 | + // return __CLASS__; |
|
67 | + // } |
|
68 | + // } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
73 | + * |
|
74 | + * @return int[]|string[] |
|
75 | + * @throws EE_Error |
|
76 | + * @throws ReflectionException |
|
77 | + */ |
|
78 | + public function active(): array |
|
79 | + { |
|
80 | + return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
86 | + * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
87 | + * |
|
88 | + * @throws EE_Error |
|
89 | + * @throws ReflectionException |
|
90 | + */ |
|
91 | + public function set_active() |
|
92 | + { |
|
93 | + $default_scopes = [EEM_Payment_Method::scope_cart]; |
|
94 | + if ( |
|
95 | + $this->type_obj() && |
|
96 | + $this->type_obj()->payment_occurs() === EE_PMT_Base::offline |
|
97 | + ) { |
|
98 | + $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
99 | + } |
|
100 | + $this->set_scope($default_scopes); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
106 | + */ |
|
107 | + public function deactivate() |
|
108 | + { |
|
109 | + $this->set_scope([]); |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * Gets button_url |
|
115 | + * |
|
116 | + * @return string |
|
117 | + * @throws EE_Error |
|
118 | + * @throws ReflectionException |
|
119 | + */ |
|
120 | + public function button_url() |
|
121 | + { |
|
122 | + return $this->get('PMD_button_url'); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Sets button_url |
|
128 | + * |
|
129 | + * @param string $button_url |
|
130 | + * @throws EE_Error |
|
131 | + * @throws ReflectionException |
|
132 | + */ |
|
133 | + public function set_button_url($button_url) |
|
134 | + { |
|
135 | + $this->set('PMD_button_url', $button_url); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * Gets debug_mode |
|
141 | + * |
|
142 | + * @return boolean |
|
143 | + * @throws EE_Error |
|
144 | + * @throws ReflectionException |
|
145 | + */ |
|
146 | + public function debug_mode(): bool |
|
147 | + { |
|
148 | + return (bool) $this->get('PMD_debug_mode'); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * Sets debug_mode |
|
154 | + * |
|
155 | + * @param boolean $debug_mode |
|
156 | + * @throws EE_Error |
|
157 | + * @throws ReflectionException |
|
158 | + */ |
|
159 | + public function set_debug_mode($debug_mode) |
|
160 | + { |
|
161 | + $this->set('PMD_debug_mode', $debug_mode); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Gets description |
|
167 | + * |
|
168 | + * @return string |
|
169 | + * @throws EE_Error |
|
170 | + * @throws ReflectionException |
|
171 | + */ |
|
172 | + public function description() |
|
173 | + { |
|
174 | + return $this->get('PMD_desc'); |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * Sets description |
|
180 | + * |
|
181 | + * @param string $description |
|
182 | + * @throws EE_Error |
|
183 | + * @throws ReflectionException |
|
184 | + */ |
|
185 | + public function set_description($description) |
|
186 | + { |
|
187 | + $this->set('PMD_desc', $description); |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * Gets name |
|
193 | + * |
|
194 | + * @return string |
|
195 | + * @throws EE_Error |
|
196 | + * @throws ReflectionException |
|
197 | + */ |
|
198 | + public function name() |
|
199 | + { |
|
200 | + return $this->get('PMD_name'); |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * Sets name |
|
206 | + * |
|
207 | + * @param string $name |
|
208 | + * @throws EE_Error |
|
209 | + * @throws ReflectionException |
|
210 | + */ |
|
211 | + public function set_name($name) |
|
212 | + { |
|
213 | + $this->set('PMD_name', $name); |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * Gets open_by_default |
|
219 | + * |
|
220 | + * @return boolean |
|
221 | + * @throws EE_Error |
|
222 | + * @throws ReflectionException |
|
223 | + */ |
|
224 | + public function open_by_default() |
|
225 | + { |
|
226 | + return $this->get('PMD_open_by_default'); |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * Sets open_by_default |
|
232 | + * |
|
233 | + * @param boolean $open_by_default |
|
234 | + * @throws EE_Error |
|
235 | + * @throws ReflectionException |
|
236 | + */ |
|
237 | + public function set_open_by_default($open_by_default) |
|
238 | + { |
|
239 | + $this->set('PMD_open_by_default', $open_by_default); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * Gets order |
|
245 | + * |
|
246 | + * @return int |
|
247 | + * @throws EE_Error |
|
248 | + * @throws ReflectionException |
|
249 | + */ |
|
250 | + public function order() |
|
251 | + { |
|
252 | + return $this->get('PMD_order'); |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * Sets order |
|
258 | + * |
|
259 | + * @param int $order |
|
260 | + * @throws EE_Error |
|
261 | + * @throws ReflectionException |
|
262 | + */ |
|
263 | + public function set_order($order) |
|
264 | + { |
|
265 | + $this->set('PMD_order', $order); |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * Gets slug |
|
271 | + * |
|
272 | + * @return string |
|
273 | + * @throws EE_Error |
|
274 | + * @throws ReflectionException |
|
275 | + */ |
|
276 | + public function slug() |
|
277 | + { |
|
278 | + return $this->get('PMD_slug'); |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * Sets slug |
|
284 | + * |
|
285 | + * @param string $slug |
|
286 | + * @throws EE_Error |
|
287 | + * @throws ReflectionException |
|
288 | + */ |
|
289 | + public function set_slug($slug) |
|
290 | + { |
|
291 | + $this->set('PMD_slug', $slug); |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * Gets type |
|
297 | + * |
|
298 | + * @return string |
|
299 | + * @throws EE_Error |
|
300 | + * @throws ReflectionException |
|
301 | + */ |
|
302 | + public function type() |
|
303 | + { |
|
304 | + return $this->get('PMD_type'); |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * Sets type |
|
310 | + * |
|
311 | + * @param string $type |
|
312 | + * @throws EE_Error |
|
313 | + * @throws ReflectionException |
|
314 | + */ |
|
315 | + public function set_type($type) |
|
316 | + { |
|
317 | + $this->set('PMD_type', $type); |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * Gets wp_user |
|
323 | + * |
|
324 | + * @return int |
|
325 | + * @throws EE_Error |
|
326 | + * @throws ReflectionException |
|
327 | + */ |
|
328 | + public function wp_user() |
|
329 | + { |
|
330 | + return $this->get('PMD_wp_user'); |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * Sets wp_user |
|
336 | + * |
|
337 | + * @param int $wp_user_id |
|
338 | + * @throws EE_Error |
|
339 | + * @throws ReflectionException |
|
340 | + */ |
|
341 | + public function set_wp_user($wp_user_id) |
|
342 | + { |
|
343 | + $this->set('PMD_wp_user', $wp_user_id); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
349 | + * |
|
350 | + * @param string $field_name |
|
351 | + * @param mixed $field_value |
|
352 | + * @param boolean $use_default |
|
353 | + * @throws EE_Error |
|
354 | + * @throws ReflectionException |
|
355 | + */ |
|
356 | + public function set($field_name, $field_value, $use_default = false) |
|
357 | + { |
|
358 | + if ($field_name === 'PMD_type') { |
|
359 | + // the type has probably changed, so forget about its old type object |
|
360 | + $this->_type_obj = null; |
|
361 | + } |
|
362 | + parent::set($field_name, $field_value, $use_default); |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + /** |
|
367 | + * Gets admin_name |
|
368 | + * |
|
369 | + * @return string |
|
370 | + * @throws EE_Error |
|
371 | + * @throws ReflectionException |
|
372 | + */ |
|
373 | + public function admin_name() |
|
374 | + { |
|
375 | + return $this->get('PMD_admin_name'); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * Sets admin_name |
|
381 | + * |
|
382 | + * @param string $admin_name |
|
383 | + * @throws EE_Error |
|
384 | + * @throws ReflectionException |
|
385 | + */ |
|
386 | + public function set_admin_name($admin_name) |
|
387 | + { |
|
388 | + $this->set('PMD_admin_name', $admin_name); |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * Gets admin_desc |
|
394 | + * |
|
395 | + * @return string |
|
396 | + * @throws EE_Error |
|
397 | + * @throws ReflectionException |
|
398 | + */ |
|
399 | + public function admin_desc() |
|
400 | + { |
|
401 | + return $this->get('PMD_admin_desc'); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * Sets admin_desc |
|
407 | + * |
|
408 | + * @param string $admin_desc |
|
409 | + * @throws EE_Error |
|
410 | + * @throws ReflectionException |
|
411 | + */ |
|
412 | + public function set_admin_desc($admin_desc) |
|
413 | + { |
|
414 | + $this->set('PMD_admin_desc', $admin_desc); |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + * Gets scope |
|
420 | + * |
|
421 | + * @return array |
|
422 | + * @throws EE_Error |
|
423 | + * @throws ReflectionException |
|
424 | + */ |
|
425 | + public function scope() |
|
426 | + { |
|
427 | + return (array) $this->get('PMD_scope'); |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * Sets scope |
|
433 | + * |
|
434 | + * @param array $scope |
|
435 | + * @throws EE_Error |
|
436 | + * @throws ReflectionException |
|
437 | + */ |
|
438 | + public function set_scope($scope) |
|
439 | + { |
|
440 | + $this->set('PMD_scope', (array) $scope); |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * Gets the payment method type for this payment method instance |
|
446 | + * |
|
447 | + * @return EE_PMT_Base |
|
448 | + * @throws EE_Error |
|
449 | + * @throws ReflectionException |
|
450 | + */ |
|
451 | + public function type_obj() |
|
452 | + { |
|
453 | + if (! $this->_type_obj) { |
|
454 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
455 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
456 | + $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
457 | + if (! class_exists($class_name)) { |
|
458 | + throw new EE_Error( |
|
459 | + sprintf( |
|
460 | + esc_html__( |
|
461 | + 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
462 | + 'event_espresso' |
|
463 | + ), |
|
464 | + $class_name, |
|
465 | + '<br />', |
|
466 | + '<a href="' . admin_url('plugins.php') . '">', |
|
467 | + '</a>' |
|
468 | + ) |
|
469 | + ); |
|
470 | + } |
|
471 | + $r = new ReflectionClass($class_name); |
|
472 | + $this->_type_obj = $r->newInstanceArgs([$this]); |
|
473 | + } else { |
|
474 | + throw new EE_Error( |
|
475 | + sprintf( |
|
476 | + esc_html__( |
|
477 | + 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
478 | + 'event_espresso' |
|
479 | + ), |
|
480 | + $this->type(), |
|
481 | + implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
482 | + ) |
|
483 | + ); |
|
484 | + } |
|
485 | + } |
|
486 | + return $this->_type_obj; |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + /** |
|
491 | + * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
492 | + * and the extra meta. Mostly used for passing off ot gateways. * |
|
493 | + * |
|
494 | + * @return array |
|
495 | + * @throws EE_Error |
|
496 | + * @throws ReflectionException |
|
497 | + */ |
|
498 | + public function settings_array() |
|
499 | + { |
|
500 | + $fields = $this->model_field_array(); |
|
501 | + $extra_meta = $this->all_extra_meta_array(); |
|
502 | + // remove the model's prefix from the fields |
|
503 | + $combined_settings_array = []; |
|
504 | + foreach ($fields as $key => $value) { |
|
505 | + if (strpos($key, 'PMD_') === 0) { |
|
506 | + $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
507 | + $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
508 | + } |
|
509 | + } |
|
510 | + $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
511 | + return $combined_settings_array; |
|
512 | + } |
|
513 | + |
|
514 | + |
|
515 | + /** |
|
516 | + * Gets the HTML for displaying the payment method on a page. |
|
517 | + * |
|
518 | + * @param string $url |
|
519 | + * @param string $css_class |
|
520 | + * @return string of HTML for displaying the button |
|
521 | + * @throws EE_Error |
|
522 | + * @throws ReflectionException |
|
523 | + */ |
|
524 | + public function button_html($url = '', $css_class = '') |
|
525 | + { |
|
526 | + $payment_occurs = $this->type_obj()->payment_occurs(); |
|
527 | + return ' |
|
528 | 528 | <div id="' |
529 | - . $this->slug() |
|
530 | - . '-payment-option-dv" class="' |
|
531 | - . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
529 | + . $this->slug() |
|
530 | + . '-payment-option-dv" class="' |
|
531 | + . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
532 | 532 | <a id="payment-gateway-button-' . $this->slug() |
533 | - . '" class="reg-page-payment-option-lnk" rel="' |
|
534 | - . $this->slug() . '" href="' . $url . '" > |
|
533 | + . '" class="reg-page-payment-option-lnk" rel="' |
|
534 | + . $this->slug() . '" href="' . $url . '" > |
|
535 | 535 | <img src="' . $this->button_url() . '" alt="' . sprintf( |
536 | - esc_attr__('Pay using %s', 'event_espresso'), |
|
537 | - $this->get_pretty('PMD_name', 'form_input') |
|
538 | - ) . '" /> |
|
536 | + esc_attr__('Pay using %s', 'event_espresso'), |
|
537 | + $this->get_pretty('PMD_name', 'form_input') |
|
538 | + ) . '" /> |
|
539 | 539 | </a> |
540 | 540 | </div> |
541 | 541 | '; |
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * Gets all the currencies which are an option for this payment method |
|
547 | - * (as defined by the gateway and the currently active currencies) |
|
548 | - * |
|
549 | - * @return EE_Currency[] |
|
550 | - * @throws EE_Error |
|
551 | - * @throws ReflectionException |
|
552 | - */ |
|
553 | - public function get_all_usable_currencies() |
|
554 | - { |
|
555 | - return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * Reports whether or not this payment method can be used for this payment method |
|
561 | - * |
|
562 | - * @param string $currency_code currency ID (code) |
|
563 | - * @return boolean |
|
564 | - * @throws EE_Error |
|
565 | - * @throws ReflectionException |
|
566 | - */ |
|
567 | - public function usable_for_currency($currency_code) |
|
568 | - { |
|
569 | - foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
570 | - if ($currency_obj->ID() === $currency_code) { |
|
571 | - return true; |
|
572 | - } |
|
573 | - } |
|
574 | - return false; |
|
575 | - } |
|
576 | - |
|
577 | - |
|
578 | - /** |
|
579 | - * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
580 | - * |
|
581 | - * @return bool |
|
582 | - * @throws EE_Error |
|
583 | - * @throws ReflectionException |
|
584 | - */ |
|
585 | - public function is_on_site() |
|
586 | - { |
|
587 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
588 | - } |
|
589 | - |
|
590 | - |
|
591 | - /** |
|
592 | - * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
593 | - * |
|
594 | - * @return bool |
|
595 | - * @throws EE_Error |
|
596 | - * @throws ReflectionException |
|
597 | - */ |
|
598 | - public function is_off_site() |
|
599 | - { |
|
600 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
601 | - } |
|
602 | - |
|
603 | - |
|
604 | - /** |
|
605 | - * Returns TRUE if this payment method does not utilize a gateway |
|
606 | - * |
|
607 | - * @return bool |
|
608 | - * @throws EE_Error |
|
609 | - * @throws ReflectionException |
|
610 | - */ |
|
611 | - public function is_off_line() |
|
612 | - { |
|
613 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
614 | - } |
|
615 | - |
|
616 | - |
|
617 | - /** |
|
618 | - * Overrides default __sleep so the object type is NOT cached. |
|
619 | - * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
620 | - * to load the required classes, and don't need them at the time of unserialization |
|
621 | - * |
|
622 | - * @return array |
|
623 | - */ |
|
624 | - public function __sleep() |
|
625 | - { |
|
626 | - $properties = get_object_vars($this); |
|
627 | - unset($properties['_type_obj']); |
|
628 | - return array_keys($properties); |
|
629 | - } |
|
630 | - |
|
631 | - |
|
632 | - /** |
|
633 | - * Overrides parent to add some logging for when payment methods get deactivated |
|
634 | - * |
|
635 | - * @param array $set_cols_n_values |
|
636 | - * @return bool|int|string @see EE_Base_Class::save() |
|
637 | - * @throws EE_Error |
|
638 | - * @throws ReflectionException |
|
639 | - */ |
|
640 | - public function save($set_cols_n_values = []) |
|
641 | - { |
|
642 | - $results = parent::save($set_cols_n_values); |
|
643 | - if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
644 | - /** @var CurrentPage $current_page */ |
|
645 | - $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
646 | - EE_Log::instance()->log( |
|
647 | - __FILE__, |
|
648 | - __FUNCTION__, |
|
649 | - sprintf( |
|
650 | - esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
651 | - $this->name(), |
|
652 | - serialize($this->get_original('PMD_scope')), |
|
653 | - serialize($this->get('PMD_scope')), |
|
654 | - $current_page->getPermalink() |
|
655 | - ), |
|
656 | - 'payment_method_change' |
|
657 | - ); |
|
658 | - } |
|
659 | - return $results; |
|
660 | - } |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * Gets all the currencies which are an option for this payment method |
|
547 | + * (as defined by the gateway and the currently active currencies) |
|
548 | + * |
|
549 | + * @return EE_Currency[] |
|
550 | + * @throws EE_Error |
|
551 | + * @throws ReflectionException |
|
552 | + */ |
|
553 | + public function get_all_usable_currencies() |
|
554 | + { |
|
555 | + return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * Reports whether or not this payment method can be used for this payment method |
|
561 | + * |
|
562 | + * @param string $currency_code currency ID (code) |
|
563 | + * @return boolean |
|
564 | + * @throws EE_Error |
|
565 | + * @throws ReflectionException |
|
566 | + */ |
|
567 | + public function usable_for_currency($currency_code) |
|
568 | + { |
|
569 | + foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
570 | + if ($currency_obj->ID() === $currency_code) { |
|
571 | + return true; |
|
572 | + } |
|
573 | + } |
|
574 | + return false; |
|
575 | + } |
|
576 | + |
|
577 | + |
|
578 | + /** |
|
579 | + * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
580 | + * |
|
581 | + * @return bool |
|
582 | + * @throws EE_Error |
|
583 | + * @throws ReflectionException |
|
584 | + */ |
|
585 | + public function is_on_site() |
|
586 | + { |
|
587 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
588 | + } |
|
589 | + |
|
590 | + |
|
591 | + /** |
|
592 | + * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
593 | + * |
|
594 | + * @return bool |
|
595 | + * @throws EE_Error |
|
596 | + * @throws ReflectionException |
|
597 | + */ |
|
598 | + public function is_off_site() |
|
599 | + { |
|
600 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
601 | + } |
|
602 | + |
|
603 | + |
|
604 | + /** |
|
605 | + * Returns TRUE if this payment method does not utilize a gateway |
|
606 | + * |
|
607 | + * @return bool |
|
608 | + * @throws EE_Error |
|
609 | + * @throws ReflectionException |
|
610 | + */ |
|
611 | + public function is_off_line() |
|
612 | + { |
|
613 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
614 | + } |
|
615 | + |
|
616 | + |
|
617 | + /** |
|
618 | + * Overrides default __sleep so the object type is NOT cached. |
|
619 | + * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
620 | + * to load the required classes, and don't need them at the time of unserialization |
|
621 | + * |
|
622 | + * @return array |
|
623 | + */ |
|
624 | + public function __sleep() |
|
625 | + { |
|
626 | + $properties = get_object_vars($this); |
|
627 | + unset($properties['_type_obj']); |
|
628 | + return array_keys($properties); |
|
629 | + } |
|
630 | + |
|
631 | + |
|
632 | + /** |
|
633 | + * Overrides parent to add some logging for when payment methods get deactivated |
|
634 | + * |
|
635 | + * @param array $set_cols_n_values |
|
636 | + * @return bool|int|string @see EE_Base_Class::save() |
|
637 | + * @throws EE_Error |
|
638 | + * @throws ReflectionException |
|
639 | + */ |
|
640 | + public function save($set_cols_n_values = []) |
|
641 | + { |
|
642 | + $results = parent::save($set_cols_n_values); |
|
643 | + if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
644 | + /** @var CurrentPage $current_page */ |
|
645 | + $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
646 | + EE_Log::instance()->log( |
|
647 | + __FILE__, |
|
648 | + __FUNCTION__, |
|
649 | + sprintf( |
|
650 | + esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
651 | + $this->name(), |
|
652 | + serialize($this->get_original('PMD_scope')), |
|
653 | + serialize($this->get('PMD_scope')), |
|
654 | + $current_page->getPermalink() |
|
655 | + ), |
|
656 | + 'payment_method_change' |
|
657 | + ); |
|
658 | + } |
|
659 | + return $results; |
|
660 | + } |
|
661 | 661 | } |
@@ -4,128 +4,128 @@ |
||
4 | 4 | |
5 | 5 | class AdminMenuTopLevel extends AdminMenuItem |
6 | 6 | { |
7 | - public const MENU_PARENT_ACTIVE = 'espresso_events'; |
|
8 | - |
|
9 | - public const MENU_PARENT_MAINTENANCE = 'espresso_maintenance_settings'; |
|
10 | - |
|
11 | - |
|
12 | - /** |
|
13 | - * The page to an icon used for this menu. |
|
14 | - * |
|
15 | - * @since 4.4.0 |
|
16 | - * @see http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters |
|
17 | - * for what can be set for this property. |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected string $icon_url = ''; |
|
21 | - |
|
22 | - /** |
|
23 | - * What position in the main menu order for the WP admin menu this menu item |
|
24 | - * should show. |
|
25 | - * |
|
26 | - * @since 4.4.0 |
|
27 | - * @see http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters |
|
28 | - * for what can be set for this property. |
|
29 | - * @var integer |
|
30 | - */ |
|
31 | - protected int $position = 0; |
|
32 | - |
|
33 | - /** |
|
34 | - * If included int incoming params, then this class will also register a Sub Menu Admin page with a different |
|
35 | - * subtitle than the main menu item. |
|
36 | - * |
|
37 | - * @since 4.4.0 |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - protected string $subtitle = ''; |
|
41 | - |
|
42 | - |
|
43 | - public function __construct(array $menu_args) |
|
44 | - { |
|
45 | - $this->setIconUrl($menu_args['icon_url'] ?? ''); |
|
46 | - $this->setPosition($menu_args['position'] ?? 0); |
|
47 | - $this->setSubtitle($menu_args['subtitle'] ?? ''); |
|
48 | - unset($menu_args['icon_url'], $menu_args['position'], $menu_args['subtitle']); |
|
49 | - parent::__construct( |
|
50 | - $menu_args, |
|
51 | - // required args |
|
52 | - [ |
|
53 | - 'menu_label', |
|
54 | - 'menu_slug', |
|
55 | - 'menu_group', |
|
56 | - 'menu_order', |
|
57 | - ] |
|
58 | - ); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * Uses the proper WP utility for registering a menu page for the main WP pages. |
|
64 | - */ |
|
65 | - protected function registerMenuItem(): string |
|
66 | - { |
|
67 | - return add_menu_page( |
|
68 | - $this->title(), |
|
69 | - $this->menuLabel(), |
|
70 | - $this->capability(), |
|
71 | - $this->parentSlug(), |
|
72 | - $this->menuCallback(), |
|
73 | - $this->iconUrl(), |
|
74 | - $this->position() |
|
75 | - ); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function iconUrl(): string |
|
83 | - { |
|
84 | - return $this->icon_url; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * @param string $icon_url |
|
90 | - */ |
|
91 | - public function setIconUrl(string $icon_url): void |
|
92 | - { |
|
93 | - $this->icon_url = $icon_url; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @return int |
|
99 | - */ |
|
100 | - public function position(): int |
|
101 | - { |
|
102 | - return $this->position; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @param int $position |
|
108 | - */ |
|
109 | - public function setPosition(int $position): void |
|
110 | - { |
|
111 | - $this->position = absint($position); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - public function subtitle(): string |
|
119 | - { |
|
120 | - return $this->subtitle; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @param string $subtitle |
|
126 | - */ |
|
127 | - public function setSubtitle(string $subtitle): void |
|
128 | - { |
|
129 | - $this->subtitle = $subtitle; |
|
130 | - } |
|
7 | + public const MENU_PARENT_ACTIVE = 'espresso_events'; |
|
8 | + |
|
9 | + public const MENU_PARENT_MAINTENANCE = 'espresso_maintenance_settings'; |
|
10 | + |
|
11 | + |
|
12 | + /** |
|
13 | + * The page to an icon used for this menu. |
|
14 | + * |
|
15 | + * @since 4.4.0 |
|
16 | + * @see http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters |
|
17 | + * for what can be set for this property. |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected string $icon_url = ''; |
|
21 | + |
|
22 | + /** |
|
23 | + * What position in the main menu order for the WP admin menu this menu item |
|
24 | + * should show. |
|
25 | + * |
|
26 | + * @since 4.4.0 |
|
27 | + * @see http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters |
|
28 | + * for what can be set for this property. |
|
29 | + * @var integer |
|
30 | + */ |
|
31 | + protected int $position = 0; |
|
32 | + |
|
33 | + /** |
|
34 | + * If included int incoming params, then this class will also register a Sub Menu Admin page with a different |
|
35 | + * subtitle than the main menu item. |
|
36 | + * |
|
37 | + * @since 4.4.0 |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + protected string $subtitle = ''; |
|
41 | + |
|
42 | + |
|
43 | + public function __construct(array $menu_args) |
|
44 | + { |
|
45 | + $this->setIconUrl($menu_args['icon_url'] ?? ''); |
|
46 | + $this->setPosition($menu_args['position'] ?? 0); |
|
47 | + $this->setSubtitle($menu_args['subtitle'] ?? ''); |
|
48 | + unset($menu_args['icon_url'], $menu_args['position'], $menu_args['subtitle']); |
|
49 | + parent::__construct( |
|
50 | + $menu_args, |
|
51 | + // required args |
|
52 | + [ |
|
53 | + 'menu_label', |
|
54 | + 'menu_slug', |
|
55 | + 'menu_group', |
|
56 | + 'menu_order', |
|
57 | + ] |
|
58 | + ); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * Uses the proper WP utility for registering a menu page for the main WP pages. |
|
64 | + */ |
|
65 | + protected function registerMenuItem(): string |
|
66 | + { |
|
67 | + return add_menu_page( |
|
68 | + $this->title(), |
|
69 | + $this->menuLabel(), |
|
70 | + $this->capability(), |
|
71 | + $this->parentSlug(), |
|
72 | + $this->menuCallback(), |
|
73 | + $this->iconUrl(), |
|
74 | + $this->position() |
|
75 | + ); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function iconUrl(): string |
|
83 | + { |
|
84 | + return $this->icon_url; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * @param string $icon_url |
|
90 | + */ |
|
91 | + public function setIconUrl(string $icon_url): void |
|
92 | + { |
|
93 | + $this->icon_url = $icon_url; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @return int |
|
99 | + */ |
|
100 | + public function position(): int |
|
101 | + { |
|
102 | + return $this->position; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @param int $position |
|
108 | + */ |
|
109 | + public function setPosition(int $position): void |
|
110 | + { |
|
111 | + $this->position = absint($position); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + public function subtitle(): string |
|
119 | + { |
|
120 | + return $this->subtitle; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @param string $subtitle |
|
126 | + */ |
|
127 | + public function setSubtitle(string $subtitle): void |
|
128 | + { |
|
129 | + $this->subtitle = $subtitle; |
|
130 | + } |
|
131 | 131 | } |
@@ -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 string $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 string $maintenance_mode_parent = ''; |
|
51 | - |
|
52 | - /** |
|
53 | - * The callback for displaying the page that the menu references. |
|
54 | - * |
|
55 | - * @since 4.4.0 |
|
56 | - * @var callable|string|null |
|
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 string $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 string $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 int $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 string $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 string $parent_slug; |
|
99 | - |
|
100 | - /** |
|
101 | - * set to TRUE once menu item has been added to generated menu |
|
102 | - * |
|
103 | - * @var bool |
|
104 | - */ |
|
105 | - protected bool $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 int $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 string $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' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
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|string|null $menu_callback |
|
346 | - */ |
|
347 | - public function setMenuCallback($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 bool |
|
475 | - */ |
|
476 | - public function showOnMaintenanceModeMenu(): bool |
|
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 string $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 string $maintenance_mode_parent = ''; |
|
51 | + |
|
52 | + /** |
|
53 | + * The callback for displaying the page that the menu references. |
|
54 | + * |
|
55 | + * @since 4.4.0 |
|
56 | + * @var callable|string|null |
|
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 string $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 string $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 int $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 string $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 string $parent_slug; |
|
99 | + |
|
100 | + /** |
|
101 | + * set to TRUE once menu item has been added to generated menu |
|
102 | + * |
|
103 | + * @var bool |
|
104 | + */ |
|
105 | + protected bool $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 int $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 string $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' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
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|string|null $menu_callback |
|
346 | + */ |
|
347 | + public function setMenuCallback($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 bool |
|
475 | + */ |
|
476 | + public function showOnMaintenanceModeMenu(): bool |
|
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 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | // verify that required keys are present in the incoming array. |
190 | 190 | $missing = array_diff($required, array_keys($menu_args)); |
191 | 191 | |
192 | - if (! empty($missing)) { |
|
192 | + if ( ! empty($missing)) { |
|
193 | 193 | throw new DomainException( |
194 | 194 | sprintf( |
195 | 195 | esc_html__( |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | $this->capability = $capability; |
272 | 272 | // filter capabilities (both static and dynamic) |
273 | 273 | $this->capability = apply_filters('FHEE_management_capability', $this->capability, null); |
274 | - $this->capability = apply_filters('FHEE_' . $this->menu_slug . '_capability', $this->capability, null); |
|
274 | + $this->capability = apply_filters('FHEE_'.$this->menu_slug.'_capability', $this->capability, null); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
492 | 492 | AdminMenuItem::DISPLAY_NETWORK_ONLY, |
493 | 493 | ]; |
494 | - if (! in_array($show_on_menu, $valid_menu_options, true)) { |
|
494 | + if ( ! in_array($show_on_menu, $valid_menu_options, true)) { |
|
495 | 495 | throw new DomainException( |
496 | 496 | sprintf( |
497 | 497 | esc_html__( |
@@ -16,81 +16,81 @@ |
||
16 | 16 | */ |
17 | 17 | class AdminMenuGroup extends AdminMenuItem |
18 | 18 | { |
19 | - public const MENU_SLUG_ADDONS = 'addons'; |
|
19 | + public const MENU_SLUG_ADDONS = 'addons'; |
|
20 | 20 | |
21 | - public const MENU_SLUG_EXTRAS = 'extras'; |
|
21 | + public const MENU_SLUG_EXTRAS = 'extras'; |
|
22 | 22 | |
23 | - public const MENU_SLUG_MAIN = 'main'; |
|
23 | + public const MENU_SLUG_MAIN = 'main'; |
|
24 | 24 | |
25 | - public const MENU_SLUG_MANAGEMENT = 'management'; |
|
25 | + public const MENU_SLUG_MANAGEMENT = 'management'; |
|
26 | 26 | |
27 | - public const MENU_SLUG_SETTINGS = 'settings'; |
|
27 | + public const MENU_SLUG_SETTINGS = 'settings'; |
|
28 | 28 | |
29 | - public const MENU_SLUG_TEMPLATES = 'templates'; |
|
29 | + public const MENU_SLUG_TEMPLATES = 'templates'; |
|
30 | 30 | |
31 | - public const MENU_SLUG_TOOLS = 'tools'; |
|
31 | + public const MENU_SLUG_TOOLS = 'tools'; |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * @var AdminMenuItem[] |
|
36 | - */ |
|
37 | - private array $menu_items = []; |
|
34 | + /** |
|
35 | + * @var AdminMenuItem[] |
|
36 | + */ |
|
37 | + private array $menu_items = []; |
|
38 | 38 | |
39 | 39 | |
40 | - public function __construct(array $menu_args) |
|
41 | - { |
|
42 | - parent::__construct( |
|
43 | - $menu_args, |
|
44 | - // required args |
|
45 | - [ |
|
46 | - 'menu_label', |
|
47 | - 'menu_slug', |
|
48 | - 'menu_order', |
|
49 | - 'parent_slug', |
|
50 | - ] |
|
51 | - ); |
|
52 | - } |
|
40 | + public function __construct(array $menu_args) |
|
41 | + { |
|
42 | + parent::__construct( |
|
43 | + $menu_args, |
|
44 | + // required args |
|
45 | + [ |
|
46 | + 'menu_label', |
|
47 | + 'menu_slug', |
|
48 | + 'menu_order', |
|
49 | + 'parent_slug', |
|
50 | + ] |
|
51 | + ); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - public function addMenuItem(AdminMenuItem $menu_item): void |
|
56 | - { |
|
57 | - $this->menu_items[ $menu_item->menuSlug() ] = $menu_item; |
|
58 | - } |
|
55 | + public function addMenuItem(AdminMenuItem $menu_item): void |
|
56 | + { |
|
57 | + $this->menu_items[ $menu_item->menuSlug() ] = $menu_item; |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - public function getMenuItems(): array |
|
62 | - { |
|
63 | - return $this->menu_items; |
|
64 | - } |
|
61 | + public function getMenuItems(): array |
|
62 | + { |
|
63 | + return $this->menu_items; |
|
64 | + } |
|
65 | 65 | |
66 | 66 | |
67 | - public function hasNoMenuItems(): bool |
|
68 | - { |
|
69 | - return empty($this->menu_items); |
|
70 | - } |
|
67 | + public function hasNoMenuItems(): bool |
|
68 | + { |
|
69 | + return empty($this->menu_items); |
|
70 | + } |
|
71 | 71 | |
72 | 72 | |
73 | - public function setMenuItems(array $menu_items): void |
|
74 | - { |
|
75 | - $this->menu_items = $menu_items; |
|
76 | - } |
|
73 | + public function setMenuItems(array $menu_items): void |
|
74 | + { |
|
75 | + $this->menu_items = $menu_items; |
|
76 | + } |
|
77 | 77 | |
78 | 78 | |
79 | - protected function registerMenuItem(): string |
|
80 | - { |
|
81 | - return add_submenu_page( |
|
82 | - $this->parentSlug(), |
|
83 | - $this->menuLabel(), |
|
84 | - $this->groupLink(), |
|
85 | - $this->capability(), |
|
86 | - $this->menuSlug(), |
|
87 | - '__return_false' |
|
88 | - ); |
|
89 | - } |
|
79 | + protected function registerMenuItem(): string |
|
80 | + { |
|
81 | + return add_submenu_page( |
|
82 | + $this->parentSlug(), |
|
83 | + $this->menuLabel(), |
|
84 | + $this->groupLink(), |
|
85 | + $this->capability(), |
|
86 | + $this->menuSlug(), |
|
87 | + '__return_false' |
|
88 | + ); |
|
89 | + } |
|
90 | 90 | |
91 | 91 | |
92 | - protected function groupLink(): string |
|
93 | - { |
|
94 | - return '<span class="ee_menu_group" onclick="return false;">' . $this->menuLabel() . '</span>'; |
|
95 | - } |
|
92 | + protected function groupLink(): string |
|
93 | + { |
|
94 | + return '<span class="ee_menu_group" onclick="return false;">' . $this->menuLabel() . '</span>'; |
|
95 | + } |
|
96 | 96 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | |
55 | 55 | public function addMenuItem(AdminMenuItem $menu_item): void |
56 | 56 | { |
57 | - $this->menu_items[ $menu_item->menuSlug() ] = $menu_item; |
|
57 | + $this->menu_items[$menu_item->menuSlug()] = $menu_item; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | |
@@ -91,6 +91,6 @@ discard block |
||
91 | 91 | |
92 | 92 | protected function groupLink(): string |
93 | 93 | { |
94 | - return '<span class="ee_menu_group" onclick="return false;">' . $this->menuLabel() . '</span>'; |
|
94 | + return '<span class="ee_menu_group" onclick="return false;">'.$this->menuLabel().'</span>'; |
|
95 | 95 | } |
96 | 96 | } |
@@ -4,15 +4,15 @@ |
||
4 | 4 | |
5 | 5 | class AdminMenuSubItem extends AdminMenuTopLevel |
6 | 6 | { |
7 | - protected function registerMenuItem(): string |
|
8 | - { |
|
9 | - return add_submenu_page( |
|
10 | - $this->parentSlug(), |
|
11 | - $this->title(), |
|
12 | - $this->menuLabel(), |
|
13 | - $this->capability(), |
|
14 | - $this->menuSlug(), |
|
15 | - $this->menuCallback() |
|
16 | - ) ?: ''; |
|
17 | - } |
|
7 | + protected function registerMenuItem(): string |
|
8 | + { |
|
9 | + return add_submenu_page( |
|
10 | + $this->parentSlug(), |
|
11 | + $this->title(), |
|
12 | + $this->menuLabel(), |
|
13 | + $this->capability(), |
|
14 | + $this->menuSlug(), |
|
15 | + $this->menuCallback() |
|
16 | + ) ?: ''; |
|
17 | + } |
|
18 | 18 | } |
@@ -8,360 +8,360 @@ |
||
8 | 8 | */ |
9 | 9 | class EE_Registration_Config extends EE_Config_Base |
10 | 10 | { |
11 | - /** |
|
12 | - * Default registration status |
|
13 | - * |
|
14 | - * @var string $default_STS_ID |
|
15 | - * eg 'RPP' |
|
16 | - */ |
|
17 | - public $default_STS_ID = RegStatus::PENDING_PAYMENT; |
|
18 | - |
|
19 | - /** |
|
20 | - * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
21 | - * registrations) |
|
22 | - * |
|
23 | - * @var int |
|
24 | - */ |
|
25 | - public $default_maximum_number_of_tickets = 10; |
|
26 | - |
|
27 | - /** |
|
28 | - * level of validation to apply to email addresses |
|
29 | - * |
|
30 | - * @var string $email_validation_level |
|
31 | - * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
32 | - */ |
|
33 | - public $email_validation_level = 'wp_default'; |
|
34 | - |
|
35 | - /** |
|
36 | - * whether to show alternate payment options during the reg process if payment status is pending |
|
37 | - * |
|
38 | - * @var bool $show_pending_payment_options |
|
39 | - */ |
|
40 | - public $show_pending_payment_options = true; |
|
41 | - |
|
42 | - /** |
|
43 | - * an array of SPCO reg steps where: |
|
44 | - * the keys denotes the reg step order |
|
45 | - * each element consists of an array with the following elements: |
|
46 | - * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
47 | - * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
48 | - * "slug" => the URL param used to trigger the reg step |
|
49 | - * |
|
50 | - * @var array $reg_steps |
|
51 | - */ |
|
52 | - public $reg_steps = []; |
|
53 | - |
|
54 | - /** |
|
55 | - * Whether registration confirmation should be the last page of SPCO |
|
56 | - * |
|
57 | - * @var bool $reg_confirmation_last |
|
58 | - */ |
|
59 | - public $reg_confirmation_last = false; |
|
60 | - |
|
61 | - /** |
|
62 | - * Whether to enable the EE Bot Trap |
|
63 | - * |
|
64 | - * @var bool $use_bot_trap |
|
65 | - */ |
|
66 | - public $use_bot_trap = true; |
|
67 | - |
|
68 | - /** |
|
69 | - * Whether to encrypt some data sent by the EE Bot Trap |
|
70 | - * |
|
71 | - * @var bool $use_encryption |
|
72 | - */ |
|
73 | - public $use_encryption = true; |
|
74 | - |
|
75 | - /** |
|
76 | - * Whether to use ReCaptcha |
|
77 | - * |
|
78 | - * @var bool $use_captcha |
|
79 | - */ |
|
80 | - public $use_captcha = false; |
|
81 | - |
|
82 | - /** |
|
83 | - * ReCaptcha Theme |
|
84 | - * |
|
85 | - * @var string $recaptcha_theme |
|
86 | - * options: 'dark', 'light', 'invisible' |
|
87 | - */ |
|
88 | - public $recaptcha_theme = 'light'; |
|
89 | - |
|
90 | - /** |
|
91 | - * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
92 | - * |
|
93 | - * @var string $recaptcha_badge |
|
94 | - * options: 'bottomright', 'bottomleft', 'inline' |
|
95 | - */ |
|
96 | - public $recaptcha_badge = 'bottomleft'; |
|
97 | - |
|
98 | - /** |
|
99 | - * ReCaptcha Type |
|
100 | - * |
|
101 | - * @var string $recaptcha_type |
|
102 | - * options: 'audio', 'image' |
|
103 | - */ |
|
104 | - public $recaptcha_type = 'image'; |
|
105 | - |
|
106 | - /** |
|
107 | - * ReCaptcha language |
|
108 | - * |
|
109 | - * @var string $recaptcha_language |
|
110 | - * eg 'en' |
|
111 | - */ |
|
112 | - public $recaptcha_language = 'en'; |
|
113 | - |
|
114 | - /** |
|
115 | - * ReCaptcha public key |
|
116 | - * |
|
117 | - * @var string|null $recaptcha_publickey |
|
118 | - */ |
|
119 | - public $recaptcha_publickey = null; |
|
120 | - |
|
121 | - /** |
|
122 | - * ReCaptcha private key |
|
123 | - * |
|
124 | - * @var string|null $recaptcha_privatekey |
|
125 | - */ |
|
126 | - public $recaptcha_privatekey = null; |
|
127 | - |
|
128 | - /** |
|
129 | - * array of form names protected by ReCaptcha |
|
130 | - * |
|
131 | - * @var array $recaptcha_protected_forms |
|
132 | - */ |
|
133 | - public $recaptcha_protected_forms = []; |
|
134 | - |
|
135 | - /** |
|
136 | - * ReCaptcha width |
|
137 | - * |
|
138 | - * @var int $recaptcha_width |
|
139 | - * @deprecated |
|
140 | - */ |
|
141 | - public $recaptcha_width = 500; |
|
142 | - |
|
143 | - /** |
|
144 | - * Whether invalid attempts to directly access the registration checkout page should be tracked. |
|
145 | - * |
|
146 | - * @var bool $track_invalid_checkout_access |
|
147 | - */ |
|
148 | - protected $track_invalid_checkout_access = true; |
|
149 | - |
|
150 | - /** |
|
151 | - * Whether to show the privacy policy consent checkbox |
|
152 | - * |
|
153 | - * @var bool |
|
154 | - */ |
|
155 | - public $consent_checkbox_enabled = false; |
|
156 | - |
|
157 | - /** |
|
158 | - * Label text to show on the checkbox |
|
159 | - * |
|
160 | - * @var string |
|
161 | - */ |
|
162 | - public $consent_checkbox_label_text = ''; |
|
163 | - |
|
164 | - /* |
|
11 | + /** |
|
12 | + * Default registration status |
|
13 | + * |
|
14 | + * @var string $default_STS_ID |
|
15 | + * eg 'RPP' |
|
16 | + */ |
|
17 | + public $default_STS_ID = RegStatus::PENDING_PAYMENT; |
|
18 | + |
|
19 | + /** |
|
20 | + * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
21 | + * registrations) |
|
22 | + * |
|
23 | + * @var int |
|
24 | + */ |
|
25 | + public $default_maximum_number_of_tickets = 10; |
|
26 | + |
|
27 | + /** |
|
28 | + * level of validation to apply to email addresses |
|
29 | + * |
|
30 | + * @var string $email_validation_level |
|
31 | + * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
32 | + */ |
|
33 | + public $email_validation_level = 'wp_default'; |
|
34 | + |
|
35 | + /** |
|
36 | + * whether to show alternate payment options during the reg process if payment status is pending |
|
37 | + * |
|
38 | + * @var bool $show_pending_payment_options |
|
39 | + */ |
|
40 | + public $show_pending_payment_options = true; |
|
41 | + |
|
42 | + /** |
|
43 | + * an array of SPCO reg steps where: |
|
44 | + * the keys denotes the reg step order |
|
45 | + * each element consists of an array with the following elements: |
|
46 | + * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
47 | + * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
48 | + * "slug" => the URL param used to trigger the reg step |
|
49 | + * |
|
50 | + * @var array $reg_steps |
|
51 | + */ |
|
52 | + public $reg_steps = []; |
|
53 | + |
|
54 | + /** |
|
55 | + * Whether registration confirmation should be the last page of SPCO |
|
56 | + * |
|
57 | + * @var bool $reg_confirmation_last |
|
58 | + */ |
|
59 | + public $reg_confirmation_last = false; |
|
60 | + |
|
61 | + /** |
|
62 | + * Whether to enable the EE Bot Trap |
|
63 | + * |
|
64 | + * @var bool $use_bot_trap |
|
65 | + */ |
|
66 | + public $use_bot_trap = true; |
|
67 | + |
|
68 | + /** |
|
69 | + * Whether to encrypt some data sent by the EE Bot Trap |
|
70 | + * |
|
71 | + * @var bool $use_encryption |
|
72 | + */ |
|
73 | + public $use_encryption = true; |
|
74 | + |
|
75 | + /** |
|
76 | + * Whether to use ReCaptcha |
|
77 | + * |
|
78 | + * @var bool $use_captcha |
|
79 | + */ |
|
80 | + public $use_captcha = false; |
|
81 | + |
|
82 | + /** |
|
83 | + * ReCaptcha Theme |
|
84 | + * |
|
85 | + * @var string $recaptcha_theme |
|
86 | + * options: 'dark', 'light', 'invisible' |
|
87 | + */ |
|
88 | + public $recaptcha_theme = 'light'; |
|
89 | + |
|
90 | + /** |
|
91 | + * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha. |
|
92 | + * |
|
93 | + * @var string $recaptcha_badge |
|
94 | + * options: 'bottomright', 'bottomleft', 'inline' |
|
95 | + */ |
|
96 | + public $recaptcha_badge = 'bottomleft'; |
|
97 | + |
|
98 | + /** |
|
99 | + * ReCaptcha Type |
|
100 | + * |
|
101 | + * @var string $recaptcha_type |
|
102 | + * options: 'audio', 'image' |
|
103 | + */ |
|
104 | + public $recaptcha_type = 'image'; |
|
105 | + |
|
106 | + /** |
|
107 | + * ReCaptcha language |
|
108 | + * |
|
109 | + * @var string $recaptcha_language |
|
110 | + * eg 'en' |
|
111 | + */ |
|
112 | + public $recaptcha_language = 'en'; |
|
113 | + |
|
114 | + /** |
|
115 | + * ReCaptcha public key |
|
116 | + * |
|
117 | + * @var string|null $recaptcha_publickey |
|
118 | + */ |
|
119 | + public $recaptcha_publickey = null; |
|
120 | + |
|
121 | + /** |
|
122 | + * ReCaptcha private key |
|
123 | + * |
|
124 | + * @var string|null $recaptcha_privatekey |
|
125 | + */ |
|
126 | + public $recaptcha_privatekey = null; |
|
127 | + |
|
128 | + /** |
|
129 | + * array of form names protected by ReCaptcha |
|
130 | + * |
|
131 | + * @var array $recaptcha_protected_forms |
|
132 | + */ |
|
133 | + public $recaptcha_protected_forms = []; |
|
134 | + |
|
135 | + /** |
|
136 | + * ReCaptcha width |
|
137 | + * |
|
138 | + * @var int $recaptcha_width |
|
139 | + * @deprecated |
|
140 | + */ |
|
141 | + public $recaptcha_width = 500; |
|
142 | + |
|
143 | + /** |
|
144 | + * Whether invalid attempts to directly access the registration checkout page should be tracked. |
|
145 | + * |
|
146 | + * @var bool $track_invalid_checkout_access |
|
147 | + */ |
|
148 | + protected $track_invalid_checkout_access = true; |
|
149 | + |
|
150 | + /** |
|
151 | + * Whether to show the privacy policy consent checkbox |
|
152 | + * |
|
153 | + * @var bool |
|
154 | + */ |
|
155 | + public $consent_checkbox_enabled = false; |
|
156 | + |
|
157 | + /** |
|
158 | + * Label text to show on the checkbox |
|
159 | + * |
|
160 | + * @var string |
|
161 | + */ |
|
162 | + public $consent_checkbox_label_text = ''; |
|
163 | + |
|
164 | + /* |
|
165 | 165 | * String describing how long to keep payment logs. Passed into DateTime constructor |
166 | 166 | * @var string |
167 | 167 | */ |
168 | - public $gateway_log_lifespan = '7 days'; |
|
169 | - |
|
170 | - /** |
|
171 | - * Enable copy attendee info at form |
|
172 | - * |
|
173 | - * @var bool $enable_copy_attendee |
|
174 | - */ |
|
175 | - protected $copy_attendee_info = true; |
|
176 | - |
|
177 | - /** |
|
178 | - * @var bool|int|string|null $skip_reg_confirmation |
|
179 | - * @deprecated |
|
180 | - */ |
|
181 | - public $skip_reg_confirmation; |
|
182 | - |
|
183 | - private bool $use_session_countdown = false; |
|
184 | - |
|
185 | - |
|
186 | - public function __construct() |
|
187 | - { |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
193 | - * |
|
194 | - * @since 4.8.8.rc.019 |
|
195 | - */ |
|
196 | - public function do_hooks() |
|
197 | - { |
|
198 | - add_action('AHEE__EE_Config___load_core_config__end', [$this, 'set_default_reg_status_on_EEM_Event']); |
|
199 | - add_action('AHEE__EE_Config___load_core_config__end', [$this, 'set_default_max_ticket_on_EEM_Event']); |
|
200 | - add_action('AHEE__EE_System__load_core_configuration__complete', [$this, 'setDefaultCheckboxLabelText']); |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
206 | - * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
207 | - * |
|
208 | - * @throws EE_Error |
|
209 | - */ |
|
210 | - public function set_default_reg_status_on_EEM_Event() |
|
211 | - { |
|
212 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
218 | - * for Events matches the config setting for default_maximum_number_of_tickets |
|
219 | - */ |
|
220 | - public function set_default_max_ticket_on_EEM_Event() |
|
221 | - { |
|
222 | - EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
228 | - * constructed because that happens before we can get the privacy policy page's permalink. |
|
229 | - */ |
|
230 | - public function setDefaultCheckboxLabelText() |
|
231 | - { |
|
232 | - if ( |
|
233 | - $this->getConsentCheckboxLabelText() === null |
|
234 | - || $this->getConsentCheckboxLabelText() === '' |
|
235 | - ) { |
|
236 | - $opening_a_tag = ''; |
|
237 | - $closing_a_tag = ''; |
|
238 | - if (function_exists('get_privacy_policy_url')) { |
|
239 | - $privacy_page_url = get_privacy_policy_url(); |
|
240 | - if (! empty($privacy_page_url)) { |
|
241 | - $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
242 | - $closing_a_tag = '</a>'; |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - $loader = LoaderFactory::getLoader(); |
|
247 | - /** @var EE_Organization_Config $org_config */ |
|
248 | - $org_config = $loader->getShared('EE_Organization_Config'); |
|
249 | - |
|
250 | - $this->setConsentCheckboxLabelText( |
|
251 | - sprintf( |
|
252 | - esc_html__( |
|
253 | - 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
254 | - 'event_espresso' |
|
255 | - ), |
|
256 | - $org_config->name, |
|
257 | - $opening_a_tag, |
|
258 | - $closing_a_tag |
|
259 | - ) |
|
260 | - ); |
|
261 | - } |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @return bool |
|
267 | - */ |
|
268 | - public function track_invalid_checkout_access(): bool |
|
269 | - { |
|
270 | - return (bool) $this->track_invalid_checkout_access; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * @param bool $track_invalid_checkout_access |
|
276 | - */ |
|
277 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
278 | - { |
|
279 | - $this->track_invalid_checkout_access = (bool) filter_var($track_invalid_checkout_access, FILTER_VALIDATE_BOOL); |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * @return bool |
|
285 | - */ |
|
286 | - public function copyAttendeeInfo(): bool |
|
287 | - { |
|
288 | - return (bool) $this->copy_attendee_info; |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * @param bool $copy_attendee_info |
|
294 | - */ |
|
295 | - public function setCopyAttendeeInfo($copy_attendee_info) |
|
296 | - { |
|
297 | - $this->copy_attendee_info = (bool) filter_var($copy_attendee_info, FILTER_VALIDATE_BOOL); |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * Gets the options to make available for the gateway log lifespan |
|
303 | - * |
|
304 | - * @return array |
|
305 | - */ |
|
306 | - public function gatewayLogLifespanOptions(): array |
|
307 | - { |
|
308 | - return (array) apply_filters( |
|
309 | - 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
310 | - [ |
|
311 | - '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
312 | - '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
313 | - '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
314 | - '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
315 | - '30 days' => esc_html__('30 Days', 'event_espresso'), |
|
316 | - ] |
|
317 | - ); |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * @return bool |
|
323 | - */ |
|
324 | - public function isConsentCheckboxEnabled(): bool |
|
325 | - { |
|
326 | - return (bool) $this->consent_checkbox_enabled; |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * @param bool $consent_checkbox_enabled |
|
332 | - */ |
|
333 | - public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
334 | - { |
|
335 | - $this->consent_checkbox_enabled = (bool) filter_var($consent_checkbox_enabled, FILTER_VALIDATE_BOOL); |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * @return string |
|
341 | - */ |
|
342 | - public function getConsentCheckboxLabelText(): string |
|
343 | - { |
|
344 | - return (string) $this->consent_checkbox_label_text; |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * @param string $consent_checkbox_label_text |
|
350 | - */ |
|
351 | - public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
352 | - { |
|
353 | - $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - public function useSessionCountdown(): bool |
|
358 | - { |
|
359 | - return $this->use_session_countdown; |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - public function setUseSessionCountdown(bool $use_session_countdown): void |
|
364 | - { |
|
365 | - $this->use_session_countdown = $use_session_countdown; |
|
366 | - } |
|
168 | + public $gateway_log_lifespan = '7 days'; |
|
169 | + |
|
170 | + /** |
|
171 | + * Enable copy attendee info at form |
|
172 | + * |
|
173 | + * @var bool $enable_copy_attendee |
|
174 | + */ |
|
175 | + protected $copy_attendee_info = true; |
|
176 | + |
|
177 | + /** |
|
178 | + * @var bool|int|string|null $skip_reg_confirmation |
|
179 | + * @deprecated |
|
180 | + */ |
|
181 | + public $skip_reg_confirmation; |
|
182 | + |
|
183 | + private bool $use_session_countdown = false; |
|
184 | + |
|
185 | + |
|
186 | + public function __construct() |
|
187 | + { |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
193 | + * |
|
194 | + * @since 4.8.8.rc.019 |
|
195 | + */ |
|
196 | + public function do_hooks() |
|
197 | + { |
|
198 | + add_action('AHEE__EE_Config___load_core_config__end', [$this, 'set_default_reg_status_on_EEM_Event']); |
|
199 | + add_action('AHEE__EE_Config___load_core_config__end', [$this, 'set_default_max_ticket_on_EEM_Event']); |
|
200 | + add_action('AHEE__EE_System__load_core_configuration__complete', [$this, 'setDefaultCheckboxLabelText']); |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the |
|
206 | + * EVT_default_registration_status field matches the config setting for default_STS_ID. |
|
207 | + * |
|
208 | + * @throws EE_Error |
|
209 | + */ |
|
210 | + public function set_default_reg_status_on_EEM_Event() |
|
211 | + { |
|
212 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
218 | + * for Events matches the config setting for default_maximum_number_of_tickets |
|
219 | + */ |
|
220 | + public function set_default_max_ticket_on_EEM_Event() |
|
221 | + { |
|
222 | + EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is |
|
228 | + * constructed because that happens before we can get the privacy policy page's permalink. |
|
229 | + */ |
|
230 | + public function setDefaultCheckboxLabelText() |
|
231 | + { |
|
232 | + if ( |
|
233 | + $this->getConsentCheckboxLabelText() === null |
|
234 | + || $this->getConsentCheckboxLabelText() === '' |
|
235 | + ) { |
|
236 | + $opening_a_tag = ''; |
|
237 | + $closing_a_tag = ''; |
|
238 | + if (function_exists('get_privacy_policy_url')) { |
|
239 | + $privacy_page_url = get_privacy_policy_url(); |
|
240 | + if (! empty($privacy_page_url)) { |
|
241 | + $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">'; |
|
242 | + $closing_a_tag = '</a>'; |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + $loader = LoaderFactory::getLoader(); |
|
247 | + /** @var EE_Organization_Config $org_config */ |
|
248 | + $org_config = $loader->getShared('EE_Organization_Config'); |
|
249 | + |
|
250 | + $this->setConsentCheckboxLabelText( |
|
251 | + sprintf( |
|
252 | + esc_html__( |
|
253 | + 'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.', |
|
254 | + 'event_espresso' |
|
255 | + ), |
|
256 | + $org_config->name, |
|
257 | + $opening_a_tag, |
|
258 | + $closing_a_tag |
|
259 | + ) |
|
260 | + ); |
|
261 | + } |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @return bool |
|
267 | + */ |
|
268 | + public function track_invalid_checkout_access(): bool |
|
269 | + { |
|
270 | + return (bool) $this->track_invalid_checkout_access; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * @param bool $track_invalid_checkout_access |
|
276 | + */ |
|
277 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
278 | + { |
|
279 | + $this->track_invalid_checkout_access = (bool) filter_var($track_invalid_checkout_access, FILTER_VALIDATE_BOOL); |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * @return bool |
|
285 | + */ |
|
286 | + public function copyAttendeeInfo(): bool |
|
287 | + { |
|
288 | + return (bool) $this->copy_attendee_info; |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * @param bool $copy_attendee_info |
|
294 | + */ |
|
295 | + public function setCopyAttendeeInfo($copy_attendee_info) |
|
296 | + { |
|
297 | + $this->copy_attendee_info = (bool) filter_var($copy_attendee_info, FILTER_VALIDATE_BOOL); |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * Gets the options to make available for the gateway log lifespan |
|
303 | + * |
|
304 | + * @return array |
|
305 | + */ |
|
306 | + public function gatewayLogLifespanOptions(): array |
|
307 | + { |
|
308 | + return (array) apply_filters( |
|
309 | + 'FHEE_EE_Admin_Config__gatewayLogLifespanOptions', |
|
310 | + [ |
|
311 | + '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'), |
|
312 | + '1 day' => esc_html__('1 Day', 'event_espresso'), |
|
313 | + '7 days' => esc_html__('7 Days', 'event_espresso'), |
|
314 | + '14 days' => esc_html__('14 Days', 'event_espresso'), |
|
315 | + '30 days' => esc_html__('30 Days', 'event_espresso'), |
|
316 | + ] |
|
317 | + ); |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * @return bool |
|
323 | + */ |
|
324 | + public function isConsentCheckboxEnabled(): bool |
|
325 | + { |
|
326 | + return (bool) $this->consent_checkbox_enabled; |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * @param bool $consent_checkbox_enabled |
|
332 | + */ |
|
333 | + public function setConsentCheckboxEnabled($consent_checkbox_enabled) |
|
334 | + { |
|
335 | + $this->consent_checkbox_enabled = (bool) filter_var($consent_checkbox_enabled, FILTER_VALIDATE_BOOL); |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * @return string |
|
341 | + */ |
|
342 | + public function getConsentCheckboxLabelText(): string |
|
343 | + { |
|
344 | + return (string) $this->consent_checkbox_label_text; |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * @param string $consent_checkbox_label_text |
|
350 | + */ |
|
351 | + public function setConsentCheckboxLabelText($consent_checkbox_label_text) |
|
352 | + { |
|
353 | + $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text; |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + public function useSessionCountdown(): bool |
|
358 | + { |
|
359 | + return $this->use_session_countdown; |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + public function setUseSessionCountdown(bool $use_session_countdown): void |
|
364 | + { |
|
365 | + $this->use_session_countdown = $use_session_countdown; |
|
366 | + } |
|
367 | 367 | } |
@@ -16,51 +16,51 @@ |
||
16 | 16 | */ |
17 | 17 | class ActivationRequests extends PrimaryRoute |
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->isActivation(); |
|
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->isActivation(); |
|
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\entities\routing\handlers\admin\AdminRoute', |
|
38 | - AdminRoute::getDefaultDependencies() |
|
39 | - ); |
|
40 | - $this->dependency_map->registerDependencies( |
|
41 | - 'EventEspresso\core\domain\entities\routing\handlers\admin\WordPressPluginsPage', |
|
42 | - AdminRoute::getDefaultDependencies() |
|
43 | - ); |
|
44 | - $this->dependency_map->registerDependencies( |
|
45 | - 'EventEspresso\core\domain\services\licensing\LicenseKeyActivationRoute', |
|
46 | - Route::getDefaultDependencies() |
|
47 | - ); |
|
48 | - } |
|
31 | + /** |
|
32 | + * @since 5.0.0.p |
|
33 | + */ |
|
34 | + protected function registerDependencies() |
|
35 | + { |
|
36 | + $this->dependency_map->registerDependencies( |
|
37 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\AdminRoute', |
|
38 | + AdminRoute::getDefaultDependencies() |
|
39 | + ); |
|
40 | + $this->dependency_map->registerDependencies( |
|
41 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\WordPressPluginsPage', |
|
42 | + AdminRoute::getDefaultDependencies() |
|
43 | + ); |
|
44 | + $this->dependency_map->registerDependencies( |
|
45 | + 'EventEspresso\core\domain\services\licensing\LicenseKeyActivationRoute', |
|
46 | + Route::getDefaultDependencies() |
|
47 | + ); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * implements logic required to run during request |
|
53 | - * |
|
54 | - * @return bool |
|
55 | - * @since 5.0.0.p |
|
56 | - */ |
|
57 | - protected function requestHandler(): bool |
|
58 | - { |
|
59 | - $this->setRouteRequestType(PrimaryRoute::ROUTE_REQUEST_TYPE_ACTIVATION); |
|
60 | - /** @var Textdomain $textdomain */ |
|
61 | - $textdomain = $this->loader->getShared(Textdomain::class); |
|
62 | - add_action('init', [$textdomain, 'loadTranslationsForLocaleOnActivation'], 0); |
|
63 | - add_action('admin_init', [$textdomain, 'deleteLegacyTextDomainOption'], 99); |
|
64 | - return true; |
|
65 | - } |
|
51 | + /** |
|
52 | + * implements logic required to run during request |
|
53 | + * |
|
54 | + * @return bool |
|
55 | + * @since 5.0.0.p |
|
56 | + */ |
|
57 | + protected function requestHandler(): bool |
|
58 | + { |
|
59 | + $this->setRouteRequestType(PrimaryRoute::ROUTE_REQUEST_TYPE_ACTIVATION); |
|
60 | + /** @var Textdomain $textdomain */ |
|
61 | + $textdomain = $this->loader->getShared(Textdomain::class); |
|
62 | + add_action('init', [$textdomain, 'loadTranslationsForLocaleOnActivation'], 0); |
|
63 | + add_action('admin_init', [$textdomain, 'deleteLegacyTextDomainOption'], 99); |
|
64 | + return true; |
|
65 | + } |
|
66 | 66 | } |
@@ -15,269 +15,269 @@ |
||
15 | 15 | */ |
16 | 16 | class Version |
17 | 17 | { |
18 | - const RELEASE_TYPE_RC = 'rc'; |
|
19 | - |
|
20 | - const RELEASE_TYPE_BETA = 'beta'; |
|
21 | - |
|
22 | - const RELEASE_TYPE_DECAF = 'decaf'; |
|
23 | - |
|
24 | - const RELEASE_TYPE_PROD = 'p'; |
|
25 | - |
|
26 | - |
|
27 | - private int $major; |
|
28 | - |
|
29 | - private int $minor; |
|
30 | - |
|
31 | - private int $patch; |
|
32 | - |
|
33 | - private int $build; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * Version constructor. |
|
38 | - * |
|
39 | - * @param int $major |
|
40 | - * @param int $minor |
|
41 | - * @param int $patch |
|
42 | - * @param int|string|null $build_or_release |
|
43 | - * @param int|null $build |
|
44 | - * @throws InvalidDataTypeException |
|
45 | - * @throws InvalidArgumentException |
|
46 | - */ |
|
47 | - public function __construct( |
|
48 | - int $major, |
|
49 | - int $minor, |
|
50 | - int $patch, |
|
51 | - $build_or_release = 0, |
|
52 | - ?int $build = null |
|
53 | - ) { |
|
54 | - $this->setMajor($major); |
|
55 | - $this->setMinor($minor); |
|
56 | - $this->setPatch($patch); |
|
57 | - $build = $build ?? $build_or_release; |
|
58 | - $this->setBuild($build); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @param string $version_string |
|
64 | - * @return Version |
|
65 | - * @throws InvalidArgumentException |
|
66 | - */ |
|
67 | - public static function fromString(string $version_string): Version |
|
68 | - { |
|
69 | - $version_string = trim($version_string); |
|
70 | - // compare incoming version string against the lowest possible valid version |
|
71 | - if (version_compare($version_string, '0.0.1.dev.001', '<')) { |
|
72 | - throw new InvalidArgumentException( |
|
73 | - sprintf( |
|
74 | - esc_html__('"%1$s" is not a valid version string', 'event_espresso'), |
|
75 | - $version_string |
|
76 | - ) |
|
77 | - ); |
|
78 | - } |
|
79 | - // break apart incoming version string |
|
80 | - $version_parts = explode('.', $version_string); |
|
81 | - // remove any non-numeric parts |
|
82 | - $version_parts = array_filter($version_parts, 'is_numeric'); |
|
83 | - // reindex the array so that the keys are sequential |
|
84 | - $version_parts = array_values($version_parts); |
|
85 | - // verify that version string at least contains {major}.{minor}.{patch} |
|
86 | - if (count($version_parts) < 3) { |
|
87 | - throw new InvalidArgumentException( |
|
88 | - sprintf( |
|
89 | - esc_html__( |
|
90 | - 'At minimum, a version string needs to be in a "{major}.{minor}.{patch}" format, therefore "%1$s" is not valid', |
|
91 | - 'event_espresso' |
|
92 | - ), |
|
93 | - $version_string |
|
94 | - ) |
|
95 | - ); |
|
96 | - } |
|
97 | - if (isset($version_parts[4])) { |
|
98 | - // if there are more than 4 parts, then the version string includes the old "release" part |
|
99 | - $build = $version_parts[4]; |
|
100 | - $version_parts[3] = $build; |
|
101 | - unset($version_parts[4]); |
|
102 | - } |
|
103 | - // add defaults for missing pieces |
|
104 | - $version_parts += ['0', '0', '0', '000']; |
|
105 | - ksort($version_parts, SORT_NUMERIC); |
|
106 | - $version_parts = array_map('trim', $version_parts); |
|
107 | - // reassign to individual variables |
|
108 | - [$major, $minor, $patch, $build] = $version_parts; |
|
109 | - return new Version( |
|
110 | - (int) $major, |
|
111 | - (int) $minor, |
|
112 | - (int) $patch, |
|
113 | - (int) $build |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @return int |
|
120 | - */ |
|
121 | - public function major(): int |
|
122 | - { |
|
123 | - return $this->major; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param int|string $major |
|
129 | - * @throws InvalidDataTypeException |
|
130 | - */ |
|
131 | - private function setMajor($major) |
|
132 | - { |
|
133 | - if (! is_int($major)) { |
|
134 | - throw new InvalidDataTypeException( |
|
135 | - '$major', |
|
136 | - $major, |
|
137 | - 'integer' |
|
138 | - ); |
|
139 | - } |
|
140 | - $this->major = absint($major); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @return int |
|
146 | - */ |
|
147 | - public function minor(): int |
|
148 | - { |
|
149 | - return $this->minor; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @param int|string $minor |
|
155 | - * @throws InvalidDataTypeException |
|
156 | - */ |
|
157 | - private function setMinor($minor) |
|
158 | - { |
|
159 | - if (! is_int($minor)) { |
|
160 | - throw new InvalidDataTypeException( |
|
161 | - '$minor', |
|
162 | - $minor, |
|
163 | - 'integer' |
|
164 | - ); |
|
165 | - } |
|
166 | - $this->minor = absint($minor); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * @return int |
|
172 | - */ |
|
173 | - public function patch(): int |
|
174 | - { |
|
175 | - return $this->patch; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * @param int|string $patch |
|
181 | - * @throws InvalidDataTypeException |
|
182 | - */ |
|
183 | - private function setPatch($patch) |
|
184 | - { |
|
185 | - if (! is_int($patch)) { |
|
186 | - throw new InvalidDataTypeException( |
|
187 | - '$patch', |
|
188 | - $patch, |
|
189 | - 'integer' |
|
190 | - ); |
|
191 | - } |
|
192 | - $this->patch = absint($patch); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function release(): string |
|
200 | - { |
|
201 | - return ''; |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * @return int |
|
207 | - */ |
|
208 | - public function build(): int |
|
209 | - { |
|
210 | - return $this->build; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * @param int|string $build |
|
216 | - * @throws InvalidDataTypeException |
|
217 | - */ |
|
218 | - private function setBuild($build) |
|
219 | - { |
|
220 | - if (! is_int($build)) { |
|
221 | - throw new InvalidDataTypeException( |
|
222 | - '$build', |
|
223 | - $build, |
|
224 | - 'integer' |
|
225 | - ); |
|
226 | - } |
|
227 | - $this->build = absint($build); |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * @param Version $other_version |
|
233 | - * @return int |
|
234 | - */ |
|
235 | - public function compare(Version $other_version): int |
|
236 | - { |
|
237 | - return version_compare((string) $this, (string) $other_version); |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * @param Version $other_version |
|
243 | - * @return bool |
|
244 | - */ |
|
245 | - public function equals(Version $other_version): bool |
|
246 | - { |
|
247 | - return version_compare((string) $this, (string) $other_version, '=='); |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * @param Version $other_version |
|
253 | - * @return bool |
|
254 | - */ |
|
255 | - public function newerThan(Version $other_version): bool |
|
256 | - { |
|
257 | - return version_compare((string) $this, (string) $other_version, '>'); |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * @param Version $other_version |
|
263 | - * @return bool |
|
264 | - */ |
|
265 | - public function olderThan(Version $other_version): bool |
|
266 | - { |
|
267 | - return version_compare((string) $this, (string) $other_version, '<'); |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * @return string |
|
273 | - */ |
|
274 | - public function __toString() |
|
275 | - { |
|
276 | - $version_string = "$this->major.$this->minor.$this->patch"; |
|
277 | - // if the build number is not 0, then append it to the version string |
|
278 | - $version_string .= $this->build |
|
279 | - ? '.' . str_pad($this->build, 3, '0', STR_PAD_LEFT) |
|
280 | - : ''; |
|
281 | - return $version_string; |
|
282 | - } |
|
18 | + const RELEASE_TYPE_RC = 'rc'; |
|
19 | + |
|
20 | + const RELEASE_TYPE_BETA = 'beta'; |
|
21 | + |
|
22 | + const RELEASE_TYPE_DECAF = 'decaf'; |
|
23 | + |
|
24 | + const RELEASE_TYPE_PROD = 'p'; |
|
25 | + |
|
26 | + |
|
27 | + private int $major; |
|
28 | + |
|
29 | + private int $minor; |
|
30 | + |
|
31 | + private int $patch; |
|
32 | + |
|
33 | + private int $build; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * Version constructor. |
|
38 | + * |
|
39 | + * @param int $major |
|
40 | + * @param int $minor |
|
41 | + * @param int $patch |
|
42 | + * @param int|string|null $build_or_release |
|
43 | + * @param int|null $build |
|
44 | + * @throws InvalidDataTypeException |
|
45 | + * @throws InvalidArgumentException |
|
46 | + */ |
|
47 | + public function __construct( |
|
48 | + int $major, |
|
49 | + int $minor, |
|
50 | + int $patch, |
|
51 | + $build_or_release = 0, |
|
52 | + ?int $build = null |
|
53 | + ) { |
|
54 | + $this->setMajor($major); |
|
55 | + $this->setMinor($minor); |
|
56 | + $this->setPatch($patch); |
|
57 | + $build = $build ?? $build_or_release; |
|
58 | + $this->setBuild($build); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @param string $version_string |
|
64 | + * @return Version |
|
65 | + * @throws InvalidArgumentException |
|
66 | + */ |
|
67 | + public static function fromString(string $version_string): Version |
|
68 | + { |
|
69 | + $version_string = trim($version_string); |
|
70 | + // compare incoming version string against the lowest possible valid version |
|
71 | + if (version_compare($version_string, '0.0.1.dev.001', '<')) { |
|
72 | + throw new InvalidArgumentException( |
|
73 | + sprintf( |
|
74 | + esc_html__('"%1$s" is not a valid version string', 'event_espresso'), |
|
75 | + $version_string |
|
76 | + ) |
|
77 | + ); |
|
78 | + } |
|
79 | + // break apart incoming version string |
|
80 | + $version_parts = explode('.', $version_string); |
|
81 | + // remove any non-numeric parts |
|
82 | + $version_parts = array_filter($version_parts, 'is_numeric'); |
|
83 | + // reindex the array so that the keys are sequential |
|
84 | + $version_parts = array_values($version_parts); |
|
85 | + // verify that version string at least contains {major}.{minor}.{patch} |
|
86 | + if (count($version_parts) < 3) { |
|
87 | + throw new InvalidArgumentException( |
|
88 | + sprintf( |
|
89 | + esc_html__( |
|
90 | + 'At minimum, a version string needs to be in a "{major}.{minor}.{patch}" format, therefore "%1$s" is not valid', |
|
91 | + 'event_espresso' |
|
92 | + ), |
|
93 | + $version_string |
|
94 | + ) |
|
95 | + ); |
|
96 | + } |
|
97 | + if (isset($version_parts[4])) { |
|
98 | + // if there are more than 4 parts, then the version string includes the old "release" part |
|
99 | + $build = $version_parts[4]; |
|
100 | + $version_parts[3] = $build; |
|
101 | + unset($version_parts[4]); |
|
102 | + } |
|
103 | + // add defaults for missing pieces |
|
104 | + $version_parts += ['0', '0', '0', '000']; |
|
105 | + ksort($version_parts, SORT_NUMERIC); |
|
106 | + $version_parts = array_map('trim', $version_parts); |
|
107 | + // reassign to individual variables |
|
108 | + [$major, $minor, $patch, $build] = $version_parts; |
|
109 | + return new Version( |
|
110 | + (int) $major, |
|
111 | + (int) $minor, |
|
112 | + (int) $patch, |
|
113 | + (int) $build |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @return int |
|
120 | + */ |
|
121 | + public function major(): int |
|
122 | + { |
|
123 | + return $this->major; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param int|string $major |
|
129 | + * @throws InvalidDataTypeException |
|
130 | + */ |
|
131 | + private function setMajor($major) |
|
132 | + { |
|
133 | + if (! is_int($major)) { |
|
134 | + throw new InvalidDataTypeException( |
|
135 | + '$major', |
|
136 | + $major, |
|
137 | + 'integer' |
|
138 | + ); |
|
139 | + } |
|
140 | + $this->major = absint($major); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @return int |
|
146 | + */ |
|
147 | + public function minor(): int |
|
148 | + { |
|
149 | + return $this->minor; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @param int|string $minor |
|
155 | + * @throws InvalidDataTypeException |
|
156 | + */ |
|
157 | + private function setMinor($minor) |
|
158 | + { |
|
159 | + if (! is_int($minor)) { |
|
160 | + throw new InvalidDataTypeException( |
|
161 | + '$minor', |
|
162 | + $minor, |
|
163 | + 'integer' |
|
164 | + ); |
|
165 | + } |
|
166 | + $this->minor = absint($minor); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * @return int |
|
172 | + */ |
|
173 | + public function patch(): int |
|
174 | + { |
|
175 | + return $this->patch; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * @param int|string $patch |
|
181 | + * @throws InvalidDataTypeException |
|
182 | + */ |
|
183 | + private function setPatch($patch) |
|
184 | + { |
|
185 | + if (! is_int($patch)) { |
|
186 | + throw new InvalidDataTypeException( |
|
187 | + '$patch', |
|
188 | + $patch, |
|
189 | + 'integer' |
|
190 | + ); |
|
191 | + } |
|
192 | + $this->patch = absint($patch); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function release(): string |
|
200 | + { |
|
201 | + return ''; |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * @return int |
|
207 | + */ |
|
208 | + public function build(): int |
|
209 | + { |
|
210 | + return $this->build; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * @param int|string $build |
|
216 | + * @throws InvalidDataTypeException |
|
217 | + */ |
|
218 | + private function setBuild($build) |
|
219 | + { |
|
220 | + if (! is_int($build)) { |
|
221 | + throw new InvalidDataTypeException( |
|
222 | + '$build', |
|
223 | + $build, |
|
224 | + 'integer' |
|
225 | + ); |
|
226 | + } |
|
227 | + $this->build = absint($build); |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * @param Version $other_version |
|
233 | + * @return int |
|
234 | + */ |
|
235 | + public function compare(Version $other_version): int |
|
236 | + { |
|
237 | + return version_compare((string) $this, (string) $other_version); |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * @param Version $other_version |
|
243 | + * @return bool |
|
244 | + */ |
|
245 | + public function equals(Version $other_version): bool |
|
246 | + { |
|
247 | + return version_compare((string) $this, (string) $other_version, '=='); |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * @param Version $other_version |
|
253 | + * @return bool |
|
254 | + */ |
|
255 | + public function newerThan(Version $other_version): bool |
|
256 | + { |
|
257 | + return version_compare((string) $this, (string) $other_version, '>'); |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * @param Version $other_version |
|
263 | + * @return bool |
|
264 | + */ |
|
265 | + public function olderThan(Version $other_version): bool |
|
266 | + { |
|
267 | + return version_compare((string) $this, (string) $other_version, '<'); |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * @return string |
|
273 | + */ |
|
274 | + public function __toString() |
|
275 | + { |
|
276 | + $version_string = "$this->major.$this->minor.$this->patch"; |
|
277 | + // if the build number is not 0, then append it to the version string |
|
278 | + $version_string .= $this->build |
|
279 | + ? '.' . str_pad($this->build, 3, '0', STR_PAD_LEFT) |
|
280 | + : ''; |
|
281 | + return $version_string; |
|
282 | + } |
|
283 | 283 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | private function setMajor($major) |
132 | 132 | { |
133 | - if (! is_int($major)) { |
|
133 | + if ( ! is_int($major)) { |
|
134 | 134 | throw new InvalidDataTypeException( |
135 | 135 | '$major', |
136 | 136 | $major, |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | */ |
157 | 157 | private function setMinor($minor) |
158 | 158 | { |
159 | - if (! is_int($minor)) { |
|
159 | + if ( ! is_int($minor)) { |
|
160 | 160 | throw new InvalidDataTypeException( |
161 | 161 | '$minor', |
162 | 162 | $minor, |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | */ |
183 | 183 | private function setPatch($patch) |
184 | 184 | { |
185 | - if (! is_int($patch)) { |
|
185 | + if ( ! is_int($patch)) { |
|
186 | 186 | throw new InvalidDataTypeException( |
187 | 187 | '$patch', |
188 | 188 | $patch, |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | */ |
218 | 218 | private function setBuild($build) |
219 | 219 | { |
220 | - if (! is_int($build)) { |
|
220 | + if ( ! is_int($build)) { |
|
221 | 221 | throw new InvalidDataTypeException( |
222 | 222 | '$build', |
223 | 223 | $build, |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | $version_string = "$this->major.$this->minor.$this->patch"; |
277 | 277 | // if the build number is not 0, then append it to the version string |
278 | 278 | $version_string .= $this->build |
279 | - ? '.' . str_pad($this->build, 3, '0', STR_PAD_LEFT) |
|
279 | + ? '.'.str_pad($this->build, 3, '0', STR_PAD_LEFT) |
|
280 | 280 | : ''; |
281 | 281 | return $version_string; |
282 | 282 | } |
@@ -15,441 +15,441 @@ |
||
15 | 15 | |
16 | 16 | class AdminMenuManager |
17 | 17 | { |
18 | - /** |
|
19 | - * Default: null - defaults to below Comments |
|
20 | - * |
|
21 | - * 5 - below Posts |
|
22 | - * 10 - below Media |
|
23 | - * 15 - below Links |
|
24 | - * 20 - below Pages |
|
25 | - * 25 - below comments |
|
26 | - * 60 - below first separator |
|
27 | - * 65 - below Plugins |
|
28 | - * 70 - below Users |
|
29 | - * 75 - below Tools |
|
30 | - * 80 - below Settings |
|
31 | - * 100 - below second separator |
|
32 | - */ |
|
33 | - const DEFAULT_MENU_POSITION = 100; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @var AdminMenuItem[] |
|
38 | - */ |
|
39 | - private array $menu_items = []; |
|
40 | - |
|
41 | - /** |
|
42 | - * objects for page_init objects detected and loaded |
|
43 | - * |
|
44 | - * @var EE_Admin_Page_Init[] |
|
45 | - */ |
|
46 | - private array $installed_pages = []; |
|
47 | - |
|
48 | - /** |
|
49 | - * set to TRUE if site is currently in maintenance mode level 2 |
|
50 | - * |
|
51 | - * @var bool |
|
52 | - */ |
|
53 | - protected bool $maintenance_mode = false; |
|
54 | - |
|
55 | - /** |
|
56 | - * same values used by AdminMenuManager::DEFAULT_MENU_POSITION |
|
57 | - * |
|
58 | - * @var int |
|
59 | - */ |
|
60 | - private int $menu_position; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var AdminMenuItem |
|
64 | - */ |
|
65 | - private AdminMenuItem $top_level_menu_item; |
|
66 | - |
|
67 | - |
|
68 | - public function __construct() |
|
69 | - { |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - public function initialize() |
|
74 | - { |
|
75 | - $this->maintenance_mode = MaintenanceStatus::isFullSite(); |
|
76 | - $this->menu_position = apply_filters( |
|
77 | - 'FHEE__EventEspresso_core_domain_services_admin_menu_AdminMenuManager__initialize__menu_position', |
|
78 | - AdminMenuManager::DEFAULT_MENU_POSITION, |
|
79 | - $this->maintenance_mode |
|
80 | - ); |
|
81 | - $this->addTopLevelMenuItem(); |
|
82 | - $this->initializeMenuGroups(); |
|
83 | - add_action('admin_menu', [$this, 'generateAdminMenu']); |
|
84 | - add_action('network_admin_menu', [$this, 'generateNetworkAdminMenu']); |
|
85 | - add_filter('custom_menu_order', '__return_true'); |
|
86 | - add_filter('menu_order', [$this, 'reorderAdminMenu']); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * adds the top level menu item that everything else descends from. |
|
92 | - * changes depending on whether site is in full maintenance mode or not |
|
93 | - * |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - private function addTopLevelMenuItem() |
|
97 | - { |
|
98 | - $this->top_level_menu_item = $this->maintenance_mode |
|
99 | - ? $this->instantiateAdminMenu( |
|
100 | - [ |
|
101 | - 'menu_slug' => AdminMenuTopLevel::MENU_PARENT_MAINTENANCE, |
|
102 | - 'menu_label' => esc_html__('Event Espresso', 'event_espresso'), |
|
103 | - 'capability' => 'manage_options', |
|
104 | - 'menu_group' => AdminMenuGroup::MENU_SLUG_MAIN, |
|
105 | - 'menu_order' => 10, |
|
106 | - 'menu_type' => AdminMenuItem::TYPE_MENU_TOP, |
|
107 | - 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_MAINTENANCE, |
|
108 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
109 | - ] |
|
110 | - ) |
|
111 | - : $this->instantiateAdminMenu( |
|
112 | - [ |
|
113 | - 'menu_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
114 | - 'menu_label' => esc_html__('Event Espresso', 'event_espresso'), |
|
115 | - 'capability' => 'ee_read_events', |
|
116 | - 'menu_group' => AdminMenuGroup::MENU_SLUG_MAIN, |
|
117 | - 'menu_order' => 10, |
|
118 | - 'menu_type' => AdminMenuItem::TYPE_MENU_TOP, |
|
119 | - 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
120 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
121 | - ] |
|
122 | - ); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
128 | - * |
|
129 | - * @return void |
|
130 | - */ |
|
131 | - private function initializeMenuGroups() |
|
132 | - { |
|
133 | - $this->menu_items = apply_filters( |
|
134 | - 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
135 | - [ |
|
136 | - AdminMenuGroup::MENU_SLUG_MAIN => $this->instantiateAdminMenu( |
|
137 | - [ |
|
138 | - 'menu_slug' => AdminMenuGroup::MENU_SLUG_MAIN, |
|
139 | - 'menu_label' => esc_html__('Main', 'event_espresso'), |
|
140 | - 'capability' => $this->maintenance_mode ? 'manage_options' : 'ee_read_ee', |
|
141 | - 'maintenance_mode_parent' => AdminMenuTopLevel::MENU_PARENT_MAINTENANCE, |
|
142 | - 'menu_order' => 0, |
|
143 | - 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
144 | - 'show_on_menu' => AdminMenuItem::DISPLAY_NONE, |
|
145 | - ] |
|
146 | - ), |
|
147 | - AdminMenuGroup::MENU_SLUG_MANAGEMENT => $this->instantiateAdminMenu( |
|
148 | - [ |
|
149 | - 'menu_slug' => AdminMenuGroup::MENU_SLUG_MANAGEMENT, |
|
150 | - 'menu_label' => esc_html__('Management', 'event_espresso'), |
|
151 | - 'capability' => 'ee_read_ee', |
|
152 | - 'menu_order' => 10, |
|
153 | - 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
154 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
155 | - ] |
|
156 | - ), |
|
157 | - AdminMenuGroup::MENU_SLUG_ADDONS => $this->instantiateAdminMenu( |
|
158 | - [ |
|
159 | - 'menu_slug' => AdminMenuGroup::MENU_SLUG_ADDONS, |
|
160 | - 'menu_label' => esc_html__('Add-ons', 'event_espresso'), |
|
161 | - 'capability' => 'ee_read_ee', |
|
162 | - 'menu_order' => 20, |
|
163 | - 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
164 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
|
165 | - ] |
|
166 | - ), |
|
167 | - AdminMenuGroup::MENU_SLUG_SETTINGS => $this->instantiateAdminMenu( |
|
168 | - [ |
|
169 | - 'menu_slug' => AdminMenuGroup::MENU_SLUG_SETTINGS, |
|
170 | - 'menu_label' => esc_html__('Settings', 'event_espresso'), |
|
171 | - 'capability' => 'ee_read_ee', |
|
172 | - 'menu_order' => 30, |
|
173 | - 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
174 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
175 | - ] |
|
176 | - ), |
|
177 | - AdminMenuGroup::MENU_SLUG_TEMPLATES => $this->instantiateAdminMenu( |
|
178 | - [ |
|
179 | - 'menu_slug' => AdminMenuGroup::MENU_SLUG_TEMPLATES, |
|
180 | - 'menu_label' => esc_html__('Templates', 'event_espresso'), |
|
181 | - 'capability' => 'ee_read_ee', |
|
182 | - 'menu_order' => 40, |
|
183 | - 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
184 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
185 | - ] |
|
186 | - ), |
|
187 | - AdminMenuGroup::MENU_SLUG_EXTRAS => $this->instantiateAdminMenu( |
|
188 | - [ |
|
189 | - 'menu_slug' => AdminMenuGroup::MENU_SLUG_EXTRAS, |
|
190 | - 'menu_label' => esc_html__('Extras', 'event_espresso'), |
|
191 | - 'capability' => 'ee_read_ee', |
|
192 | - 'maintenance_mode_parent' => AdminMenuTopLevel::MENU_PARENT_MAINTENANCE, |
|
193 | - 'menu_order' => 50, |
|
194 | - 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
195 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
|
196 | - ] |
|
197 | - ), |
|
198 | - AdminMenuGroup::MENU_SLUG_TOOLS => $this->instantiateAdminMenu( |
|
199 | - [ |
|
200 | - 'menu_slug' => AdminMenuGroup::MENU_SLUG_TOOLS, |
|
201 | - 'menu_label' => esc_html__('Tools', 'event_espresso'), |
|
202 | - 'capability' => 'ee_read_ee', |
|
203 | - 'menu_order' => 60, |
|
204 | - 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
205 | - 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
206 | - ] |
|
207 | - ), |
|
208 | - ] |
|
209 | - ); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * adds an AdminMenuItem |
|
215 | - * |
|
216 | - * @param AdminMenuItem $admin_menu_item |
|
217 | - * @return AdminMenuItem |
|
218 | - */ |
|
219 | - public function addAdminMenuItem(AdminMenuItem $admin_menu_item): AdminMenuItem |
|
220 | - { |
|
221 | - // get the menu group that this menu item belongs to and then add it |
|
222 | - $admin_group = $this->getMenuGroup($admin_menu_item); |
|
223 | - $admin_group->addMenuItem($admin_menu_item); |
|
224 | - return $admin_menu_item; |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * instantiates and returns the appropriate AdminMenuItem for the provided EE_Admin_Page_Init |
|
230 | - * |
|
231 | - * @param EE_Admin_Page_Init $admin_page_init |
|
232 | - * @return AdminMenuItem |
|
233 | - */ |
|
234 | - public function getAdminMenu(EE_Admin_Page_Init $admin_page_init): AdminMenuItem |
|
235 | - { |
|
236 | - // see if admin page init is using new classes |
|
237 | - $menu_properties = $admin_page_init->getMenuProperties(); |
|
238 | - if (empty($menu_properties)) { |
|
239 | - // no? ok then if admin menu doesn't already exist, set up the admin menu item the old way |
|
240 | - if (! $admin_page_init->adminMenu() instanceof AdminMenuItem) { |
|
241 | - $admin_page_init->setupLegacyAdminMenuItem(); |
|
242 | - } |
|
243 | - } else { |
|
244 | - // adding the admin page init callback here means the menu doesn't have to cart that object around |
|
245 | - $menu_properties['menu_callback'] = [$admin_page_init, 'initialize_admin_page']; |
|
246 | - if (! $admin_page_init->adminMenu() instanceof AdminMenuItem) { |
|
247 | - // if admin menu doesn't already exist, then instantiate a new one |
|
248 | - $admin_page_init->setAdminMenu($this->instantiateAdminMenu($menu_properties)); |
|
249 | - } |
|
250 | - } |
|
251 | - $admin_menu = $admin_page_init->adminMenu(); |
|
252 | - if (! $admin_menu instanceof AdminMenuItem) { |
|
253 | - throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso')); |
|
254 | - } |
|
255 | - if (! is_callable($admin_menu->menuCallback())) { |
|
256 | - $admin_menu->setMenuCallback([$admin_page_init, 'initialize_admin_page']); |
|
257 | - } |
|
258 | - // get the menu group that this menu item belongs to and then add it |
|
259 | - $admin_group = $this->getMenuGroup($admin_menu); |
|
260 | - $admin_group->addMenuItem($admin_menu); |
|
261 | - return $admin_menu; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @param array $menu_properties |
|
267 | - * @return AdminMenuItem|null |
|
268 | - */ |
|
269 | - private function instantiateAdminMenu(array $menu_properties): ?AdminMenuItem |
|
270 | - { |
|
271 | - $type = $menu_properties['menu_type'] ?? AdminMenuItem::TYPE_MENU_GROUP; |
|
272 | - unset($menu_properties['menu_type']); |
|
273 | - switch ($type) { |
|
274 | - case AdminMenuItem::TYPE_MENU_GROUP: |
|
275 | - unset($menu_properties['menu_callback']); |
|
276 | - return new AdminMenuGroup($menu_properties); |
|
277 | - case AdminMenuItem::TYPE_MENU_TOP: |
|
278 | - return new AdminMenuTopLevel($menu_properties); |
|
279 | - case AdminMenuItem::TYPE_MENU_SUB_ITEM: |
|
280 | - return new AdminMenuSubItem($menu_properties); |
|
281 | - } |
|
282 | - return null; |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * @param AdminMenuItem $admin_menu |
|
288 | - * @return AdminMenuGroup |
|
289 | - * @throws DomainException |
|
290 | - * @throws OutOfRangeException |
|
291 | - */ |
|
292 | - private function getMenuGroup(AdminMenuItem $admin_menu): AdminMenuGroup |
|
293 | - { |
|
294 | - if (! isset($this->menu_items[ $admin_menu->menuGroup() ])) { |
|
295 | - throw new OutOfRangeException(esc_html__('AdminMenuGroup does not exist', 'event_espresso')); |
|
296 | - } |
|
297 | - $admin_group = $this->menu_items[ $admin_menu->menuGroup() ]; |
|
298 | - if (! $admin_group instanceof AdminMenuGroup) { |
|
299 | - throw new DomainException(esc_html__('Invalid AdminMenuGroup found', 'event_espresso')); |
|
300 | - } |
|
301 | - return $admin_group; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * set_network_menus |
|
307 | - * This method sets up the menus for network EE Admin Pages. |
|
308 | - * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
309 | - * are only added to the menu map if they are intended for the admin menu |
|
310 | - * |
|
311 | - * @return void |
|
312 | - * @throws DomainException |
|
313 | - */ |
|
314 | - public function generateNetworkAdminMenu() |
|
315 | - { |
|
316 | - $this->generateAdminMenu(true); |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * This method sets up the menus for EE Admin Pages |
|
322 | - * |
|
323 | - * @return void |
|
324 | - * @throws DomainException |
|
325 | - */ |
|
326 | - public function generateAdminMenu(bool $network_admin = false) |
|
327 | - { |
|
328 | - $admin_menu = $this->sortMenu($this->menu_items); |
|
329 | - $this->top_level_menu_item->registerAdminMenuItem($network_admin); |
|
330 | - $this->registerAdminMenu($admin_menu, $network_admin); |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * @param AdminMenuItem[] $admin_menu |
|
336 | - * @param bool $network_admin |
|
337 | - */ |
|
338 | - private function registerAdminMenu(array $admin_menu, bool $network_admin) |
|
339 | - { |
|
340 | - foreach ($admin_menu as $menu_item) { |
|
341 | - if ($this->skipMenuItem($menu_item)) { |
|
342 | - continue; |
|
343 | - } |
|
344 | - try { |
|
345 | - $wp_page_slug = $menu_item->registerAdminMenuItem($network_admin); |
|
346 | - $admin_init_page = $this->installed_pages[ $menu_item->menuSlug() ] ?? null; |
|
347 | - if ($wp_page_slug && $admin_init_page instanceof EE_Admin_Page_Init) { |
|
348 | - $admin_init_page->setWpPageSlug($wp_page_slug); |
|
349 | - $admin_init_page->set_page_dependencies($wp_page_slug); |
|
350 | - } |
|
351 | - if ($menu_item instanceof AdminMenuGroup) { |
|
352 | - $this->registerAdminMenu($menu_item->getMenuItems(), $network_admin); |
|
353 | - } |
|
354 | - } catch (Exception $e) { |
|
355 | - EE_Error::add_error($e->getMessage(), $e->getFile(), __FUNCTION__, $e->getLine()); |
|
356 | - } |
|
357 | - } |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * returns TRUE if any of the following conditions is met: |
|
363 | - * - menu item is NOT an instanceof AdminMenuItem |
|
364 | - * - menu item has already been registered |
|
365 | - * - menu item should not be shown when site is in full maintenance mode |
|
366 | - * - current user does not have the required access permission |
|
367 | - * - menu item is a group but has no sub items |
|
368 | - * |
|
369 | - * @param AdminMenuItem|null $menu_item |
|
370 | - * @return bool |
|
371 | - */ |
|
372 | - private function skipMenuItem(?AdminMenuItem $menu_item): bool |
|
373 | - { |
|
374 | - return ! $menu_item instanceof AdminMenuItem |
|
375 | - || $menu_item->isRegistered() |
|
376 | - || ! $menu_item->showOnMaintenanceModeMenu() |
|
377 | - || ! $menu_item->currentUserHasAccess() |
|
378 | - || ( |
|
379 | - $menu_item instanceof AdminMenuGroup |
|
380 | - && $menu_item->hasNoMenuItems() |
|
381 | - ); |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * @param EE_Admin_Page_Init[] $installed_pages |
|
387 | - */ |
|
388 | - public function setInstalledPages(array $installed_pages): void |
|
389 | - { |
|
390 | - $this->installed_pages = $installed_pages; |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * Recursively sort menu groups and their sub items |
|
396 | - * |
|
397 | - * @return AdminMenuItem[] |
|
398 | - * @throws DomainException |
|
399 | - */ |
|
400 | - public function sortMenu(array $admin_menu): array |
|
401 | - { |
|
402 | - foreach ($admin_menu as $menu_group) { |
|
403 | - if (! $menu_group instanceof AdminMenuItem) { |
|
404 | - throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso')); |
|
405 | - } |
|
406 | - if ($menu_group instanceof AdminMenuGroup) { |
|
407 | - // sort sub items |
|
408 | - $menu_items = $this->sortMenu($menu_group->getMenuItems()); |
|
409 | - $menu_group->setMenuItems($menu_items); |
|
410 | - } |
|
411 | - } |
|
412 | - // sort incoming array AFTER it's been looped through and elements have been validated |
|
413 | - usort($admin_menu, [$this, 'sortMenuItems']); |
|
414 | - return $admin_menu; |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - * sort sub menu items |
|
420 | - * |
|
421 | - * @param AdminMenuItem $a menu_item |
|
422 | - * @param AdminMenuItem $b being compared to |
|
423 | - * @return int sort order |
|
424 | - */ |
|
425 | - private function sortMenuItems(AdminMenuItem $a, AdminMenuItem $b): int |
|
426 | - { |
|
427 | - if ($a->menuOrder() === $b->menuOrder()) { |
|
428 | - return 0; |
|
429 | - } |
|
430 | - return $a->menuOrder() < $b->menuOrder() ? -1 : 1; |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - /** |
|
435 | - * Moves the Event Espresso admin menu to the position set by $this->menu_position |
|
436 | - * |
|
437 | - * @param array $menu_order |
|
438 | - * @return array |
|
439 | - */ |
|
440 | - public function reorderAdminMenu(array $menu_order): array |
|
441 | - { |
|
442 | - $menu_slug = $this->maintenance_mode |
|
443 | - ? AdminMenuTopLevel::MENU_PARENT_MAINTENANCE |
|
444 | - : AdminMenuTopLevel::MENU_PARENT_ACTIVE; |
|
445 | - $current_index = array_search($menu_slug, $menu_order); |
|
446 | - if ($current_index === false) { |
|
447 | - return $menu_order; |
|
448 | - } |
|
449 | - // chop out the espresso admin menu if found |
|
450 | - $espresso_menu = array_splice($menu_order, $current_index, 1); |
|
451 | - // reinsert at position set by $this->menu_position |
|
452 | - array_splice($menu_order, $this->menu_position, 0, $espresso_menu); |
|
453 | - return $menu_order; |
|
454 | - } |
|
18 | + /** |
|
19 | + * Default: null - defaults to below Comments |
|
20 | + * |
|
21 | + * 5 - below Posts |
|
22 | + * 10 - below Media |
|
23 | + * 15 - below Links |
|
24 | + * 20 - below Pages |
|
25 | + * 25 - below comments |
|
26 | + * 60 - below first separator |
|
27 | + * 65 - below Plugins |
|
28 | + * 70 - below Users |
|
29 | + * 75 - below Tools |
|
30 | + * 80 - below Settings |
|
31 | + * 100 - below second separator |
|
32 | + */ |
|
33 | + const DEFAULT_MENU_POSITION = 100; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @var AdminMenuItem[] |
|
38 | + */ |
|
39 | + private array $menu_items = []; |
|
40 | + |
|
41 | + /** |
|
42 | + * objects for page_init objects detected and loaded |
|
43 | + * |
|
44 | + * @var EE_Admin_Page_Init[] |
|
45 | + */ |
|
46 | + private array $installed_pages = []; |
|
47 | + |
|
48 | + /** |
|
49 | + * set to TRUE if site is currently in maintenance mode level 2 |
|
50 | + * |
|
51 | + * @var bool |
|
52 | + */ |
|
53 | + protected bool $maintenance_mode = false; |
|
54 | + |
|
55 | + /** |
|
56 | + * same values used by AdminMenuManager::DEFAULT_MENU_POSITION |
|
57 | + * |
|
58 | + * @var int |
|
59 | + */ |
|
60 | + private int $menu_position; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var AdminMenuItem |
|
64 | + */ |
|
65 | + private AdminMenuItem $top_level_menu_item; |
|
66 | + |
|
67 | + |
|
68 | + public function __construct() |
|
69 | + { |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + public function initialize() |
|
74 | + { |
|
75 | + $this->maintenance_mode = MaintenanceStatus::isFullSite(); |
|
76 | + $this->menu_position = apply_filters( |
|
77 | + 'FHEE__EventEspresso_core_domain_services_admin_menu_AdminMenuManager__initialize__menu_position', |
|
78 | + AdminMenuManager::DEFAULT_MENU_POSITION, |
|
79 | + $this->maintenance_mode |
|
80 | + ); |
|
81 | + $this->addTopLevelMenuItem(); |
|
82 | + $this->initializeMenuGroups(); |
|
83 | + add_action('admin_menu', [$this, 'generateAdminMenu']); |
|
84 | + add_action('network_admin_menu', [$this, 'generateNetworkAdminMenu']); |
|
85 | + add_filter('custom_menu_order', '__return_true'); |
|
86 | + add_filter('menu_order', [$this, 'reorderAdminMenu']); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * adds the top level menu item that everything else descends from. |
|
92 | + * changes depending on whether site is in full maintenance mode or not |
|
93 | + * |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + private function addTopLevelMenuItem() |
|
97 | + { |
|
98 | + $this->top_level_menu_item = $this->maintenance_mode |
|
99 | + ? $this->instantiateAdminMenu( |
|
100 | + [ |
|
101 | + 'menu_slug' => AdminMenuTopLevel::MENU_PARENT_MAINTENANCE, |
|
102 | + 'menu_label' => esc_html__('Event Espresso', 'event_espresso'), |
|
103 | + 'capability' => 'manage_options', |
|
104 | + 'menu_group' => AdminMenuGroup::MENU_SLUG_MAIN, |
|
105 | + 'menu_order' => 10, |
|
106 | + 'menu_type' => AdminMenuItem::TYPE_MENU_TOP, |
|
107 | + 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_MAINTENANCE, |
|
108 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
109 | + ] |
|
110 | + ) |
|
111 | + : $this->instantiateAdminMenu( |
|
112 | + [ |
|
113 | + 'menu_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
114 | + 'menu_label' => esc_html__('Event Espresso', 'event_espresso'), |
|
115 | + 'capability' => 'ee_read_events', |
|
116 | + 'menu_group' => AdminMenuGroup::MENU_SLUG_MAIN, |
|
117 | + 'menu_order' => 10, |
|
118 | + 'menu_type' => AdminMenuItem::TYPE_MENU_TOP, |
|
119 | + 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
120 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
121 | + ] |
|
122 | + ); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
128 | + * |
|
129 | + * @return void |
|
130 | + */ |
|
131 | + private function initializeMenuGroups() |
|
132 | + { |
|
133 | + $this->menu_items = apply_filters( |
|
134 | + 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
135 | + [ |
|
136 | + AdminMenuGroup::MENU_SLUG_MAIN => $this->instantiateAdminMenu( |
|
137 | + [ |
|
138 | + 'menu_slug' => AdminMenuGroup::MENU_SLUG_MAIN, |
|
139 | + 'menu_label' => esc_html__('Main', 'event_espresso'), |
|
140 | + 'capability' => $this->maintenance_mode ? 'manage_options' : 'ee_read_ee', |
|
141 | + 'maintenance_mode_parent' => AdminMenuTopLevel::MENU_PARENT_MAINTENANCE, |
|
142 | + 'menu_order' => 0, |
|
143 | + 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
144 | + 'show_on_menu' => AdminMenuItem::DISPLAY_NONE, |
|
145 | + ] |
|
146 | + ), |
|
147 | + AdminMenuGroup::MENU_SLUG_MANAGEMENT => $this->instantiateAdminMenu( |
|
148 | + [ |
|
149 | + 'menu_slug' => AdminMenuGroup::MENU_SLUG_MANAGEMENT, |
|
150 | + 'menu_label' => esc_html__('Management', 'event_espresso'), |
|
151 | + 'capability' => 'ee_read_ee', |
|
152 | + 'menu_order' => 10, |
|
153 | + 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
154 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
155 | + ] |
|
156 | + ), |
|
157 | + AdminMenuGroup::MENU_SLUG_ADDONS => $this->instantiateAdminMenu( |
|
158 | + [ |
|
159 | + 'menu_slug' => AdminMenuGroup::MENU_SLUG_ADDONS, |
|
160 | + 'menu_label' => esc_html__('Add-ons', 'event_espresso'), |
|
161 | + 'capability' => 'ee_read_ee', |
|
162 | + 'menu_order' => 20, |
|
163 | + 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
164 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
|
165 | + ] |
|
166 | + ), |
|
167 | + AdminMenuGroup::MENU_SLUG_SETTINGS => $this->instantiateAdminMenu( |
|
168 | + [ |
|
169 | + 'menu_slug' => AdminMenuGroup::MENU_SLUG_SETTINGS, |
|
170 | + 'menu_label' => esc_html__('Settings', 'event_espresso'), |
|
171 | + 'capability' => 'ee_read_ee', |
|
172 | + 'menu_order' => 30, |
|
173 | + 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
174 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
175 | + ] |
|
176 | + ), |
|
177 | + AdminMenuGroup::MENU_SLUG_TEMPLATES => $this->instantiateAdminMenu( |
|
178 | + [ |
|
179 | + 'menu_slug' => AdminMenuGroup::MENU_SLUG_TEMPLATES, |
|
180 | + 'menu_label' => esc_html__('Templates', 'event_espresso'), |
|
181 | + 'capability' => 'ee_read_ee', |
|
182 | + 'menu_order' => 40, |
|
183 | + 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
184 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
185 | + ] |
|
186 | + ), |
|
187 | + AdminMenuGroup::MENU_SLUG_EXTRAS => $this->instantiateAdminMenu( |
|
188 | + [ |
|
189 | + 'menu_slug' => AdminMenuGroup::MENU_SLUG_EXTRAS, |
|
190 | + 'menu_label' => esc_html__('Extras', 'event_espresso'), |
|
191 | + 'capability' => 'ee_read_ee', |
|
192 | + 'maintenance_mode_parent' => AdminMenuTopLevel::MENU_PARENT_MAINTENANCE, |
|
193 | + 'menu_order' => 50, |
|
194 | + 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
195 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_AND_NETWORK, |
|
196 | + ] |
|
197 | + ), |
|
198 | + AdminMenuGroup::MENU_SLUG_TOOLS => $this->instantiateAdminMenu( |
|
199 | + [ |
|
200 | + 'menu_slug' => AdminMenuGroup::MENU_SLUG_TOOLS, |
|
201 | + 'menu_label' => esc_html__('Tools', 'event_espresso'), |
|
202 | + 'capability' => 'ee_read_ee', |
|
203 | + 'menu_order' => 60, |
|
204 | + 'parent_slug' => AdminMenuTopLevel::MENU_PARENT_ACTIVE, |
|
205 | + 'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY, |
|
206 | + ] |
|
207 | + ), |
|
208 | + ] |
|
209 | + ); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * adds an AdminMenuItem |
|
215 | + * |
|
216 | + * @param AdminMenuItem $admin_menu_item |
|
217 | + * @return AdminMenuItem |
|
218 | + */ |
|
219 | + public function addAdminMenuItem(AdminMenuItem $admin_menu_item): AdminMenuItem |
|
220 | + { |
|
221 | + // get the menu group that this menu item belongs to and then add it |
|
222 | + $admin_group = $this->getMenuGroup($admin_menu_item); |
|
223 | + $admin_group->addMenuItem($admin_menu_item); |
|
224 | + return $admin_menu_item; |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * instantiates and returns the appropriate AdminMenuItem for the provided EE_Admin_Page_Init |
|
230 | + * |
|
231 | + * @param EE_Admin_Page_Init $admin_page_init |
|
232 | + * @return AdminMenuItem |
|
233 | + */ |
|
234 | + public function getAdminMenu(EE_Admin_Page_Init $admin_page_init): AdminMenuItem |
|
235 | + { |
|
236 | + // see if admin page init is using new classes |
|
237 | + $menu_properties = $admin_page_init->getMenuProperties(); |
|
238 | + if (empty($menu_properties)) { |
|
239 | + // no? ok then if admin menu doesn't already exist, set up the admin menu item the old way |
|
240 | + if (! $admin_page_init->adminMenu() instanceof AdminMenuItem) { |
|
241 | + $admin_page_init->setupLegacyAdminMenuItem(); |
|
242 | + } |
|
243 | + } else { |
|
244 | + // adding the admin page init callback here means the menu doesn't have to cart that object around |
|
245 | + $menu_properties['menu_callback'] = [$admin_page_init, 'initialize_admin_page']; |
|
246 | + if (! $admin_page_init->adminMenu() instanceof AdminMenuItem) { |
|
247 | + // if admin menu doesn't already exist, then instantiate a new one |
|
248 | + $admin_page_init->setAdminMenu($this->instantiateAdminMenu($menu_properties)); |
|
249 | + } |
|
250 | + } |
|
251 | + $admin_menu = $admin_page_init->adminMenu(); |
|
252 | + if (! $admin_menu instanceof AdminMenuItem) { |
|
253 | + throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso')); |
|
254 | + } |
|
255 | + if (! is_callable($admin_menu->menuCallback())) { |
|
256 | + $admin_menu->setMenuCallback([$admin_page_init, 'initialize_admin_page']); |
|
257 | + } |
|
258 | + // get the menu group that this menu item belongs to and then add it |
|
259 | + $admin_group = $this->getMenuGroup($admin_menu); |
|
260 | + $admin_group->addMenuItem($admin_menu); |
|
261 | + return $admin_menu; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @param array $menu_properties |
|
267 | + * @return AdminMenuItem|null |
|
268 | + */ |
|
269 | + private function instantiateAdminMenu(array $menu_properties): ?AdminMenuItem |
|
270 | + { |
|
271 | + $type = $menu_properties['menu_type'] ?? AdminMenuItem::TYPE_MENU_GROUP; |
|
272 | + unset($menu_properties['menu_type']); |
|
273 | + switch ($type) { |
|
274 | + case AdminMenuItem::TYPE_MENU_GROUP: |
|
275 | + unset($menu_properties['menu_callback']); |
|
276 | + return new AdminMenuGroup($menu_properties); |
|
277 | + case AdminMenuItem::TYPE_MENU_TOP: |
|
278 | + return new AdminMenuTopLevel($menu_properties); |
|
279 | + case AdminMenuItem::TYPE_MENU_SUB_ITEM: |
|
280 | + return new AdminMenuSubItem($menu_properties); |
|
281 | + } |
|
282 | + return null; |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * @param AdminMenuItem $admin_menu |
|
288 | + * @return AdminMenuGroup |
|
289 | + * @throws DomainException |
|
290 | + * @throws OutOfRangeException |
|
291 | + */ |
|
292 | + private function getMenuGroup(AdminMenuItem $admin_menu): AdminMenuGroup |
|
293 | + { |
|
294 | + if (! isset($this->menu_items[ $admin_menu->menuGroup() ])) { |
|
295 | + throw new OutOfRangeException(esc_html__('AdminMenuGroup does not exist', 'event_espresso')); |
|
296 | + } |
|
297 | + $admin_group = $this->menu_items[ $admin_menu->menuGroup() ]; |
|
298 | + if (! $admin_group instanceof AdminMenuGroup) { |
|
299 | + throw new DomainException(esc_html__('Invalid AdminMenuGroup found', 'event_espresso')); |
|
300 | + } |
|
301 | + return $admin_group; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * set_network_menus |
|
307 | + * This method sets up the menus for network EE Admin Pages. |
|
308 | + * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
309 | + * are only added to the menu map if they are intended for the admin menu |
|
310 | + * |
|
311 | + * @return void |
|
312 | + * @throws DomainException |
|
313 | + */ |
|
314 | + public function generateNetworkAdminMenu() |
|
315 | + { |
|
316 | + $this->generateAdminMenu(true); |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * This method sets up the menus for EE Admin Pages |
|
322 | + * |
|
323 | + * @return void |
|
324 | + * @throws DomainException |
|
325 | + */ |
|
326 | + public function generateAdminMenu(bool $network_admin = false) |
|
327 | + { |
|
328 | + $admin_menu = $this->sortMenu($this->menu_items); |
|
329 | + $this->top_level_menu_item->registerAdminMenuItem($network_admin); |
|
330 | + $this->registerAdminMenu($admin_menu, $network_admin); |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * @param AdminMenuItem[] $admin_menu |
|
336 | + * @param bool $network_admin |
|
337 | + */ |
|
338 | + private function registerAdminMenu(array $admin_menu, bool $network_admin) |
|
339 | + { |
|
340 | + foreach ($admin_menu as $menu_item) { |
|
341 | + if ($this->skipMenuItem($menu_item)) { |
|
342 | + continue; |
|
343 | + } |
|
344 | + try { |
|
345 | + $wp_page_slug = $menu_item->registerAdminMenuItem($network_admin); |
|
346 | + $admin_init_page = $this->installed_pages[ $menu_item->menuSlug() ] ?? null; |
|
347 | + if ($wp_page_slug && $admin_init_page instanceof EE_Admin_Page_Init) { |
|
348 | + $admin_init_page->setWpPageSlug($wp_page_slug); |
|
349 | + $admin_init_page->set_page_dependencies($wp_page_slug); |
|
350 | + } |
|
351 | + if ($menu_item instanceof AdminMenuGroup) { |
|
352 | + $this->registerAdminMenu($menu_item->getMenuItems(), $network_admin); |
|
353 | + } |
|
354 | + } catch (Exception $e) { |
|
355 | + EE_Error::add_error($e->getMessage(), $e->getFile(), __FUNCTION__, $e->getLine()); |
|
356 | + } |
|
357 | + } |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * returns TRUE if any of the following conditions is met: |
|
363 | + * - menu item is NOT an instanceof AdminMenuItem |
|
364 | + * - menu item has already been registered |
|
365 | + * - menu item should not be shown when site is in full maintenance mode |
|
366 | + * - current user does not have the required access permission |
|
367 | + * - menu item is a group but has no sub items |
|
368 | + * |
|
369 | + * @param AdminMenuItem|null $menu_item |
|
370 | + * @return bool |
|
371 | + */ |
|
372 | + private function skipMenuItem(?AdminMenuItem $menu_item): bool |
|
373 | + { |
|
374 | + return ! $menu_item instanceof AdminMenuItem |
|
375 | + || $menu_item->isRegistered() |
|
376 | + || ! $menu_item->showOnMaintenanceModeMenu() |
|
377 | + || ! $menu_item->currentUserHasAccess() |
|
378 | + || ( |
|
379 | + $menu_item instanceof AdminMenuGroup |
|
380 | + && $menu_item->hasNoMenuItems() |
|
381 | + ); |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * @param EE_Admin_Page_Init[] $installed_pages |
|
387 | + */ |
|
388 | + public function setInstalledPages(array $installed_pages): void |
|
389 | + { |
|
390 | + $this->installed_pages = $installed_pages; |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * Recursively sort menu groups and their sub items |
|
396 | + * |
|
397 | + * @return AdminMenuItem[] |
|
398 | + * @throws DomainException |
|
399 | + */ |
|
400 | + public function sortMenu(array $admin_menu): array |
|
401 | + { |
|
402 | + foreach ($admin_menu as $menu_group) { |
|
403 | + if (! $menu_group instanceof AdminMenuItem) { |
|
404 | + throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso')); |
|
405 | + } |
|
406 | + if ($menu_group instanceof AdminMenuGroup) { |
|
407 | + // sort sub items |
|
408 | + $menu_items = $this->sortMenu($menu_group->getMenuItems()); |
|
409 | + $menu_group->setMenuItems($menu_items); |
|
410 | + } |
|
411 | + } |
|
412 | + // sort incoming array AFTER it's been looped through and elements have been validated |
|
413 | + usort($admin_menu, [$this, 'sortMenuItems']); |
|
414 | + return $admin_menu; |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + * sort sub menu items |
|
420 | + * |
|
421 | + * @param AdminMenuItem $a menu_item |
|
422 | + * @param AdminMenuItem $b being compared to |
|
423 | + * @return int sort order |
|
424 | + */ |
|
425 | + private function sortMenuItems(AdminMenuItem $a, AdminMenuItem $b): int |
|
426 | + { |
|
427 | + if ($a->menuOrder() === $b->menuOrder()) { |
|
428 | + return 0; |
|
429 | + } |
|
430 | + return $a->menuOrder() < $b->menuOrder() ? -1 : 1; |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + /** |
|
435 | + * Moves the Event Espresso admin menu to the position set by $this->menu_position |
|
436 | + * |
|
437 | + * @param array $menu_order |
|
438 | + * @return array |
|
439 | + */ |
|
440 | + public function reorderAdminMenu(array $menu_order): array |
|
441 | + { |
|
442 | + $menu_slug = $this->maintenance_mode |
|
443 | + ? AdminMenuTopLevel::MENU_PARENT_MAINTENANCE |
|
444 | + : AdminMenuTopLevel::MENU_PARENT_ACTIVE; |
|
445 | + $current_index = array_search($menu_slug, $menu_order); |
|
446 | + if ($current_index === false) { |
|
447 | + return $menu_order; |
|
448 | + } |
|
449 | + // chop out the espresso admin menu if found |
|
450 | + $espresso_menu = array_splice($menu_order, $current_index, 1); |
|
451 | + // reinsert at position set by $this->menu_position |
|
452 | + array_splice($menu_order, $this->menu_position, 0, $espresso_menu); |
|
453 | + return $menu_order; |
|
454 | + } |
|
455 | 455 | } |
@@ -237,22 +237,22 @@ discard block |
||
237 | 237 | $menu_properties = $admin_page_init->getMenuProperties(); |
238 | 238 | if (empty($menu_properties)) { |
239 | 239 | // no? ok then if admin menu doesn't already exist, set up the admin menu item the old way |
240 | - if (! $admin_page_init->adminMenu() instanceof AdminMenuItem) { |
|
240 | + if ( ! $admin_page_init->adminMenu() instanceof AdminMenuItem) { |
|
241 | 241 | $admin_page_init->setupLegacyAdminMenuItem(); |
242 | 242 | } |
243 | 243 | } else { |
244 | 244 | // adding the admin page init callback here means the menu doesn't have to cart that object around |
245 | 245 | $menu_properties['menu_callback'] = [$admin_page_init, 'initialize_admin_page']; |
246 | - if (! $admin_page_init->adminMenu() instanceof AdminMenuItem) { |
|
246 | + if ( ! $admin_page_init->adminMenu() instanceof AdminMenuItem) { |
|
247 | 247 | // if admin menu doesn't already exist, then instantiate a new one |
248 | 248 | $admin_page_init->setAdminMenu($this->instantiateAdminMenu($menu_properties)); |
249 | 249 | } |
250 | 250 | } |
251 | 251 | $admin_menu = $admin_page_init->adminMenu(); |
252 | - if (! $admin_menu instanceof AdminMenuItem) { |
|
252 | + if ( ! $admin_menu instanceof AdminMenuItem) { |
|
253 | 253 | throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso')); |
254 | 254 | } |
255 | - if (! is_callable($admin_menu->menuCallback())) { |
|
255 | + if ( ! is_callable($admin_menu->menuCallback())) { |
|
256 | 256 | $admin_menu->setMenuCallback([$admin_page_init, 'initialize_admin_page']); |
257 | 257 | } |
258 | 258 | // get the menu group that this menu item belongs to and then add it |
@@ -291,11 +291,11 @@ discard block |
||
291 | 291 | */ |
292 | 292 | private function getMenuGroup(AdminMenuItem $admin_menu): AdminMenuGroup |
293 | 293 | { |
294 | - if (! isset($this->menu_items[ $admin_menu->menuGroup() ])) { |
|
294 | + if ( ! isset($this->menu_items[$admin_menu->menuGroup()])) { |
|
295 | 295 | throw new OutOfRangeException(esc_html__('AdminMenuGroup does not exist', 'event_espresso')); |
296 | 296 | } |
297 | - $admin_group = $this->menu_items[ $admin_menu->menuGroup() ]; |
|
298 | - if (! $admin_group instanceof AdminMenuGroup) { |
|
297 | + $admin_group = $this->menu_items[$admin_menu->menuGroup()]; |
|
298 | + if ( ! $admin_group instanceof AdminMenuGroup) { |
|
299 | 299 | throw new DomainException(esc_html__('Invalid AdminMenuGroup found', 'event_espresso')); |
300 | 300 | } |
301 | 301 | return $admin_group; |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | } |
344 | 344 | try { |
345 | 345 | $wp_page_slug = $menu_item->registerAdminMenuItem($network_admin); |
346 | - $admin_init_page = $this->installed_pages[ $menu_item->menuSlug() ] ?? null; |
|
346 | + $admin_init_page = $this->installed_pages[$menu_item->menuSlug()] ?? null; |
|
347 | 347 | if ($wp_page_slug && $admin_init_page instanceof EE_Admin_Page_Init) { |
348 | 348 | $admin_init_page->setWpPageSlug($wp_page_slug); |
349 | 349 | $admin_init_page->set_page_dependencies($wp_page_slug); |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | public function sortMenu(array $admin_menu): array |
401 | 401 | { |
402 | 402 | foreach ($admin_menu as $menu_group) { |
403 | - if (! $menu_group instanceof AdminMenuItem) { |
|
403 | + if ( ! $menu_group instanceof AdminMenuItem) { |
|
404 | 404 | throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso')); |
405 | 405 | } |
406 | 406 | if ($menu_group instanceof AdminMenuGroup) { |