@@ -16,713 +16,713 @@ |
||
16 | 16 | class EE_Admin_Page_Loader |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var LoaderInterface $loader |
|
21 | - */ |
|
22 | - protected $loader; |
|
23 | - |
|
24 | - /** |
|
25 | - * _installed_pages |
|
26 | - * objects for page_init objects detected and loaded |
|
27 | - * |
|
28 | - * @access private |
|
29 | - * @var EE_Admin_Page_Init[] |
|
30 | - */ |
|
31 | - private $_installed_pages = array(); |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * this is used to hold the registry of menu slugs for all the installed admin pages |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - private $_menu_slugs = array(); |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * _caffeinated_extends |
|
44 | - * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and |
|
45 | - * pieces needed to do so). This property is defined in the _set_caffeinated method. |
|
46 | - * |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - private $_caffeinated_extends = array(); |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * _current_caf_extend_slug |
|
54 | - * This property is used for holding the page slug that is required for referencing the correct |
|
55 | - * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed. |
|
56 | - * |
|
57 | - * @var array |
|
58 | - */ |
|
59 | - private $_current_caf_extend_slug; |
|
60 | - |
|
61 | - /** |
|
62 | - * _prepped_menu_maps |
|
63 | - * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu. |
|
64 | - * |
|
65 | - * @since 4.4.0 |
|
66 | - * @var EE_Admin_Page_Menu_Map[] |
|
67 | - */ |
|
68 | - private $_prepped_menu_maps = array(); |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * _admin_menu_groups |
|
73 | - * array that holds the group headings and details for |
|
74 | - * |
|
75 | - * @access private |
|
76 | - * @var array |
|
77 | - */ |
|
78 | - private $_admin_menu_groups = array(); |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * This property will hold the hook file for setting up the filter that does all the connections between admin |
|
83 | - * pages. |
|
84 | - * |
|
85 | - * @var string |
|
86 | - */ |
|
87 | - public $hook_file; |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * constructor |
|
92 | - * |
|
93 | - * @access public |
|
94 | - * @throws EE_Error |
|
95 | - * @throws InvalidArgumentException |
|
96 | - * @throws InvalidDataTypeException |
|
97 | - * @throws ReflectionException |
|
98 | - * @throws InvalidInterfaceException |
|
99 | - */ |
|
100 | - public function __construct() |
|
101 | - { |
|
102 | - $this->loader = LoaderFactory::getLoader(); |
|
103 | - // load menu_map classes |
|
104 | - EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core'); |
|
105 | - // define the default "groups" for the admin_pages |
|
106 | - $this->_set_menu_groups(); |
|
107 | - // let's do a scan and see what installed pages we have |
|
108 | - $this->_get_installed_pages(); |
|
109 | - // set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to). |
|
110 | - add_action('admin_menu', array($this, 'set_menus')); |
|
111 | - add_action('network_admin_menu', array($this, 'set_network_menus')); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by |
|
117 | - * files in the caffeinated folder. |
|
118 | - * |
|
119 | - * @access private |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - private function _define_caffeinated_constants() |
|
123 | - { |
|
124 | - if (! defined('EE_CORE_CAF_ADMIN')) { |
|
125 | - define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
126 | - define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
127 | - define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
128 | - define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
129 | - define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
130 | - define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * _set_menu_groups |
|
137 | - * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
138 | - * |
|
139 | - * @access private |
|
140 | - * @return void |
|
141 | - * @throws EE_Error |
|
142 | - */ |
|
143 | - private function _set_menu_groups() |
|
144 | - { |
|
145 | - // set array of EE_Admin_Page_Menu_Group objects |
|
146 | - $groups = array( |
|
147 | - 'main' => new EE_Admin_Page_Menu_Group( |
|
148 | - array( |
|
149 | - 'menu_label' => __('Main', 'event_espresso'), |
|
150 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::NONE, |
|
151 | - 'menu_slug' => 'main', |
|
152 | - 'capability' => 'ee_read_ee', |
|
153 | - 'menu_order' => 0, |
|
154 | - 'parent_slug' => 'espresso_events', |
|
155 | - ) |
|
156 | - ), |
|
157 | - 'management' => new EE_Admin_Page_Menu_Group( |
|
158 | - array( |
|
159 | - 'menu_label' => __('Management', 'event_espresso'), |
|
160 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
161 | - 'menu_slug' => 'management', |
|
162 | - 'capability' => 'ee_read_ee', |
|
163 | - 'menu_order' => 10, |
|
164 | - 'parent_slug' => 'espresso_events', |
|
165 | - ) |
|
166 | - ), |
|
167 | - 'settings' => new EE_Admin_Page_Menu_Group( |
|
168 | - array( |
|
169 | - 'menu_label' => __('Settings', 'event_espresso'), |
|
170 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
171 | - 'menu_slug' => 'settings', |
|
172 | - 'capability' => 'ee_read_ee', |
|
173 | - 'menu_order' => 30, |
|
174 | - 'parent_slug' => 'espresso_events', |
|
175 | - ) |
|
176 | - ), |
|
177 | - 'templates' => new EE_Admin_Page_Menu_Group( |
|
178 | - array( |
|
179 | - 'menu_label' => __('Templates', 'event_espresso'), |
|
180 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
181 | - 'menu_slug' => 'templates', |
|
182 | - 'capability' => 'ee_read_ee', |
|
183 | - 'menu_order' => 40, |
|
184 | - 'parent_slug' => 'espresso_events', |
|
185 | - ) |
|
186 | - ), |
|
187 | - 'extras' => new EE_Admin_Page_Menu_Group( |
|
188 | - array( |
|
189 | - 'menu_label' => __('Extras', 'event_espresso'), |
|
190 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
191 | - 'menu_slug' => 'extras', |
|
192 | - 'capability' => 'ee_read_ee', |
|
193 | - 'menu_order' => 50, |
|
194 | - 'parent_slug' => 'espresso_events', |
|
195 | - 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
196 | - ) |
|
197 | - ), |
|
198 | - 'tools' => new EE_Admin_Page_Menu_Group( |
|
199 | - array( |
|
200 | - 'menu_label' => __('Tools', 'event_espresso'), |
|
201 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
202 | - 'menu_slug' => 'tools', |
|
203 | - 'capability' => 'ee_read_ee', |
|
204 | - 'menu_order' => 60, |
|
205 | - 'parent_slug' => 'espresso_events', |
|
206 | - ) |
|
207 | - ), |
|
208 | - 'addons' => new EE_Admin_Page_Menu_Group( |
|
209 | - array( |
|
210 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
211 | - 'menu_label' => __('Add-ons', 'event_espresso'), |
|
212 | - 'menu_slug' => 'addons', |
|
213 | - 'capability' => 'ee_read_ee', |
|
214 | - 'menu_order' => 20, |
|
215 | - 'parent_slug' => 'espresso_events', |
|
216 | - ) |
|
217 | - ), |
|
218 | - ); |
|
219 | - $this->_admin_menu_groups = apply_filters( |
|
220 | - 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
221 | - $groups |
|
222 | - ); |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group |
|
228 | - * slug. The other utility with this function is it validates that all the groups are instances of |
|
229 | - * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons). |
|
230 | - * |
|
231 | - * @return EE_Admin_Page_Menu_Group[] |
|
232 | - * @throws EE_Error |
|
233 | - * @since 4.4.0 |
|
234 | - */ |
|
235 | - private function _rearrange_menu_groups() |
|
236 | - { |
|
237 | - $groups = array(); |
|
238 | - // first let's order the menu groups by their internal menu order |
|
239 | - // (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
|
240 | - usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
|
241 | - foreach ($this->_admin_menu_groups as $group) { |
|
242 | - if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
243 | - throw new EE_Error( |
|
244 | - sprintf( |
|
245 | - __( |
|
246 | - 'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups. All values in this array are required to be a EE_Admin_Page_Menu_Group object. Instead there was: %s', |
|
247 | - 'event_espresso' |
|
248 | - ), |
|
249 | - print_r($group, true) |
|
250 | - ) |
|
251 | - ); |
|
252 | - } |
|
253 | - $groups[ $group->menu_slug ] = $group; |
|
254 | - } |
|
255 | - return $groups; |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * _get_installed_pages |
|
261 | - * This just gets the list of installed EE_Admin_pages. |
|
262 | - * |
|
263 | - * @access private |
|
264 | - * @return void |
|
265 | - * @throws EE_Error |
|
266 | - * @throws InvalidArgumentException |
|
267 | - * @throws InvalidDataTypeException |
|
268 | - * @throws InvalidInterfaceException |
|
269 | - * @throws ReflectionException |
|
270 | - */ |
|
271 | - private function _get_installed_pages() |
|
272 | - { |
|
273 | - $installed_refs = array(); |
|
274 | - $exclude = array('assets', 'templates'); |
|
275 | - // grab everything in the admin core directory |
|
276 | - $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
277 | - if ($admin_screens) { |
|
278 | - foreach ($admin_screens as $admin_screen) { |
|
279 | - $admin_screen_name = basename($admin_screen); |
|
280 | - // files and anything in the exclude array need not apply |
|
281 | - if (is_dir($admin_screen) && ! in_array($admin_screen_name, $exclude, true)) { |
|
282 | - // these folders represent the different EE admin pages |
|
283 | - $installed_refs[ $admin_screen_name ] = $admin_screen; |
|
284 | - } |
|
285 | - } |
|
286 | - } |
|
287 | - if (empty($installed_refs)) { |
|
288 | - $error_msg[] = __( |
|
289 | - 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
|
290 | - 'event_espresso' |
|
291 | - ); |
|
292 | - $error_msg[] = $error_msg[0] . "\r\n" |
|
293 | - . sprintf( |
|
294 | - __( |
|
295 | - 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
|
296 | - 'event_espresso' |
|
297 | - ), |
|
298 | - EE_ADMIN_PAGES |
|
299 | - ); |
|
300 | - throw new EE_Error(implode('||', $error_msg)); |
|
301 | - } |
|
302 | - // this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
|
303 | - $installed_refs = $this->_set_caffeinated($installed_refs); |
|
304 | - // allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
|
305 | - $installed_refs = apply_filters( |
|
306 | - 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
|
307 | - $installed_refs |
|
308 | - ); |
|
309 | - $this->_caffeinated_extends = apply_filters( |
|
310 | - 'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends', |
|
311 | - $this->_caffeinated_extends |
|
312 | - ); |
|
313 | - // loop through admin pages and setup the $_installed_pages array. |
|
314 | - $hooks_ref = []; |
|
315 | - foreach ($installed_refs as $page => $path) { |
|
316 | - // set autoloaders for our admin page classes based on included path information |
|
317 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
318 | - // build list of installed pages |
|
319 | - $this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path); |
|
320 | - // verify returned object |
|
321 | - if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
322 | - if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
323 | - continue; |
|
324 | - } |
|
325 | - // skip if in full maintenance mode and maintenance_mode_parent is set |
|
326 | - $maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent; |
|
327 | - if (empty($maintenance_mode_parent) |
|
328 | - && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
329 | - ) { |
|
330 | - unset($installed_refs[ $page ]); |
|
331 | - continue; |
|
332 | - } |
|
333 | - $menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug; |
|
334 | - $this->_menu_slugs[ $menu_slug ] = $page; |
|
335 | - // flag for register hooks on extended pages b/c extended pages use the default INIT. |
|
336 | - $extend = false; |
|
337 | - // now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals. If there are then let's hook into the init admin filter and load our extend instead. |
|
338 | - if (isset($this->_caffeinated_extends[ $page ])) { |
|
339 | - $this->_current_caf_extend_slug = $page; |
|
340 | - $admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name(); |
|
341 | - $caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path']; |
|
342 | - $caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page']; |
|
343 | - add_filter( |
|
344 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}", |
|
345 | - static function ($path_to_file) use ($caf_path) { |
|
346 | - return $caf_path; |
|
347 | - } |
|
348 | - ); |
|
349 | - add_filter( |
|
350 | - "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}", |
|
351 | - static function ($admin_page) use ($caf_admin_page) { |
|
352 | - return $caf_admin_page; |
|
353 | - } |
|
354 | - ); |
|
355 | - $extend = true; |
|
356 | - } |
|
357 | - // let's do the registered hooks |
|
358 | - $extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend); |
|
359 | - foreach ($extended_hooks as $key => $value) { |
|
360 | - $hooks_ref[] = $value; |
|
361 | - } |
|
362 | - } |
|
363 | - } |
|
364 | - // the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder. So we want to make sure we load the file for the parent. |
|
365 | - // first make sure we've got unique values |
|
366 | - $hooks_ref = array_unique($hooks_ref); |
|
367 | - // now let's loop and require! |
|
368 | - foreach ($hooks_ref as $path) { |
|
369 | - require_once($path); |
|
370 | - } |
|
371 | - // make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested. |
|
372 | - global $ee_menu_slugs; |
|
373 | - $ee_menu_slugs = $this->_menu_slugs; |
|
374 | - // we need to loop again to run any early code |
|
375 | - foreach ($installed_refs as $page => $path) { |
|
376 | - if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
377 | - $this->_installed_pages[ $page ]->do_initial_loads(); |
|
378 | - } |
|
379 | - } |
|
380 | - do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * get_admin_page_object |
|
386 | - * |
|
387 | - * @param string $page_slug |
|
388 | - * @return EE_Admin_Page |
|
389 | - */ |
|
390 | - public function get_admin_page_object($page_slug = '') |
|
391 | - { |
|
392 | - if (isset($this->_installed_pages[ $page_slug ])) { |
|
393 | - return $this->_installed_pages[ $page_slug ]->loaded_page_object(); |
|
394 | - } |
|
395 | - return null; |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - /** |
|
400 | - * _get_classname_for_admin_page |
|
401 | - * generates an "Admin Page" class based on the directory name |
|
402 | - * |
|
403 | - * @param $dir_name |
|
404 | - * @return string |
|
405 | - */ |
|
406 | - private function _get_classname_for_admin_page($dir_name = '') |
|
407 | - { |
|
408 | - $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
409 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * _get_classname_for_admin_init_page |
|
415 | - * generates an "Admin Page Init" class based on the directory name |
|
416 | - * |
|
417 | - * @param $dir_name |
|
418 | - * @return string |
|
419 | - */ |
|
420 | - private function _get_classname_for_admin_init_page($dir_name = '') |
|
421 | - { |
|
422 | - $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
423 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * _load_admin_page |
|
429 | - * Loads and instantiates page_init object for a single EE_admin page. |
|
430 | - * |
|
431 | - * @param string $page page_reference |
|
432 | - * @param string $path |
|
433 | - * @return object|bool return page object if valid, bool false if not. |
|
434 | - * @throws EE_Error |
|
435 | - * @throws InvalidArgumentException |
|
436 | - * @throws InvalidDataTypeException |
|
437 | - * @throws ReflectionException |
|
438 | - * @throws InvalidInterfaceException |
|
439 | - */ |
|
440 | - private function _load_admin_page($page = '', $path = '') |
|
441 | - { |
|
442 | - $class_name = $this->_get_classname_for_admin_init_page($page); |
|
443 | - EE_Registry::instance()->load_file($path, $class_name, 'core'); |
|
444 | - if (! class_exists($class_name)) { |
|
445 | - $inner_error_msg = '<br />' |
|
446 | - . sprintf( |
|
447 | - esc_html__( |
|
448 | - 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
449 | - 'event_espresso' |
|
450 | - ), |
|
451 | - '<strong>' . $class_name . '</strong>' |
|
452 | - ); |
|
453 | - $error_msg[] = sprintf( |
|
454 | - __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
|
455 | - $page |
|
456 | - ); |
|
457 | - $error_msg[] = $error_msg[0] |
|
458 | - . "\r\n" |
|
459 | - . sprintf( |
|
460 | - esc_html__( |
|
461 | - 'There is no Init class in place for the %s admin page.', |
|
462 | - 'event_espresso' |
|
463 | - ), |
|
464 | - $page |
|
465 | - ) |
|
466 | - . $inner_error_msg; |
|
467 | - throw new EE_Error(implode('||', $error_msg)); |
|
468 | - } |
|
469 | - return $this->loader->getShared($class_name); |
|
470 | - } |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * set_menus |
|
475 | - * This method sets up the menus for EE Admin Pages |
|
476 | - * |
|
477 | - * @access private |
|
478 | - * @return void |
|
479 | - * @throws EE_Error |
|
480 | - * @throws InvalidDataTypeException |
|
481 | - * @throws ReflectionException |
|
482 | - */ |
|
483 | - public function set_menus() |
|
484 | - { |
|
485 | - // prep the menu pages (sort, group.) |
|
486 | - $this->_prep_pages(); |
|
487 | - foreach ($this->_prepped_menu_maps as $menu_map) { |
|
488 | - if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
489 | - $menu_map->add_menu_page(); |
|
490 | - } |
|
491 | - } |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * set_network_menus |
|
497 | - * This method sets up the menus for network EE Admin Pages. |
|
498 | - * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
499 | - * are only added to the menu map if they are intended for the admin menu |
|
500 | - * |
|
501 | - * @return void |
|
502 | - * @throws EE_Error |
|
503 | - * @throws InvalidDataTypeException |
|
504 | - * @throws ReflectionException |
|
505 | - */ |
|
506 | - public function set_network_menus() |
|
507 | - { |
|
508 | - $this->_prep_pages(); |
|
509 | - foreach ($this->_prepped_menu_maps as $menu_map) { |
|
510 | - if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
511 | - $menu_map->add_menu_page(true); |
|
512 | - } |
|
513 | - } |
|
514 | - } |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * _prep_pages |
|
519 | - * sets the _prepped_menu_maps property |
|
520 | - * |
|
521 | - * @access private |
|
522 | - * @return void |
|
523 | - * @throws EE_Error |
|
524 | - * @throws InvalidDataTypeException |
|
525 | - */ |
|
526 | - private function _prep_pages() |
|
527 | - { |
|
528 | - $pages_array = array(); |
|
529 | - // rearrange _admin_menu_groups to be indexed by group slug. |
|
530 | - $menu_groups = $this->_rearrange_menu_groups(); |
|
531 | - foreach ($this->_installed_pages as $page) { |
|
532 | - if ($page instanceof EE_Admin_page_Init) { |
|
533 | - $page_map = $page->get_menu_map(); |
|
534 | - // if we've got an array then the menu map is in the old format |
|
535 | - // so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
|
536 | - if ($page_map === null || is_array($page_map)) { |
|
537 | - new PersistentAdminNotice( |
|
538 | - 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
539 | - sprintf( |
|
540 | - __( |
|
541 | - 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
|
542 | - 'event_espresso' |
|
543 | - ), |
|
544 | - $page->label |
|
545 | - ) |
|
546 | - ); |
|
547 | - continue; |
|
548 | - } |
|
549 | - // if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
|
550 | - if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
551 | - throw new EE_Error( |
|
552 | - sprintf( |
|
553 | - __( |
|
554 | - 'The menu map for %s must be an EE_Admin_Page_Menu_Map object. Instead it is %s. Please double check that the menu map has been configured correctly.', |
|
555 | - 'event_espresso' |
|
556 | - ), |
|
557 | - $page->label, |
|
558 | - $page_map |
|
559 | - ) |
|
560 | - ); |
|
561 | - } |
|
562 | - // use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array. |
|
563 | - if (empty($page_map->maintenance_mode_parent) |
|
564 | - && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
565 | - ) { |
|
566 | - continue; |
|
567 | - } |
|
568 | - // assign to group (remember $page_map has the admin page stored in it). |
|
569 | - $pages_array[ $page_map->menu_group ][] = $page_map; |
|
570 | - } |
|
571 | - } |
|
572 | - if (empty($pages_array)) { |
|
573 | - throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso')); |
|
574 | - } |
|
575 | - // let's sort the groups, make sure it's a valid group, add header (if to show). |
|
576 | - foreach ($pages_array as $group => $menu_maps) { |
|
577 | - // valid_group? |
|
578 | - if (! array_key_exists($group, $menu_groups)) { |
|
579 | - continue; |
|
580 | - } |
|
581 | - // sort pages. |
|
582 | - usort($menu_maps, array($this, '_sort_menu_maps')); |
|
583 | - // prepend header |
|
584 | - array_unshift($menu_maps, $menu_groups[ $group ]); |
|
585 | - // reset $pages_array with prepped data |
|
586 | - $pages_array[ $group ] = $menu_maps; |
|
587 | - } |
|
588 | - |
|
589 | - // now let's setup the _prepped_menu_maps property |
|
590 | - foreach ($menu_groups as $group => $group_objs) { |
|
591 | - if (isset($pages_array[ $group ])) { |
|
592 | - foreach ($pages_array[ $group ] as $key => $value) { |
|
593 | - $this->_prepped_menu_maps[] = $value; |
|
594 | - } |
|
595 | - } |
|
596 | - } |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * This method is the "workhorse" for detecting and setting up caffeinated functionality. |
|
602 | - * In this method there are three checks being done: |
|
603 | - * 1. Do we have any NEW admin page sets. If we do, lets add them into the menu setup (via the $installed_refs |
|
604 | - * array) etc. (new page sets are found in caffeinated/new/{page}) |
|
605 | - * 2. Do we have any EXTENDED page sets. Basically an extended EE_Admin Page extends the core {child}_Admin_Page |
|
606 | - * class. eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class: |
|
607 | - * Extend_Events_Admin_Page extends Events_Admin_Page. |
|
608 | - * 3. Do we have any files just for setting up hooks into other core pages. The files can be any name in |
|
609 | - * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the |
|
610 | - * classname inside. These classes are instantiated really early so that any hooks in them are run before the |
|
611 | - * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated |
|
612 | - * admin_pages) |
|
613 | - * |
|
614 | - * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be |
|
615 | - * loaded. |
|
616 | - * @return array |
|
617 | - * @throws EE_Error |
|
618 | - * @throws ReflectionException |
|
619 | - */ |
|
620 | - private function _set_caffeinated($installed_refs) |
|
621 | - { |
|
622 | - // first let's check if there IS a caffeinated folder. If there is not then lets get out. |
|
623 | - if ((defined('EE_DECAF') && EE_DECAF) || ! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated/admin')) { |
|
624 | - return $installed_refs; |
|
625 | - } |
|
626 | - $this->_define_caffeinated_constants(); |
|
627 | - $exclude = array('tickets'); |
|
628 | - // okay let's setup an "New" pages first (we'll return installed refs later) |
|
629 | - $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
630 | - if ($new_admin_screens) { |
|
631 | - foreach ($new_admin_screens as $admin_screen) { |
|
632 | - $admin_screen_name = basename($admin_screen); |
|
633 | - // files and anything in the exclude array need not apply |
|
634 | - if (is_dir($admin_screen) && ! in_array($admin_screen_name, $exclude, true)) { |
|
635 | - // these folders represent the different NEW EE admin pages |
|
636 | - $installed_refs[ $admin_screen_name ] = $admin_screen; |
|
637 | - // set autoloaders for our admin page classes based on included path information |
|
638 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($admin_screen); |
|
639 | - } |
|
640 | - } |
|
641 | - } |
|
642 | - // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
|
643 | - $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
644 | - if ($extends) { |
|
645 | - foreach ($extends as $extend) { |
|
646 | - if (is_dir($extend)) { |
|
647 | - $extend_ref = basename($extend); |
|
648 | - // now let's make sure there is a file that matches the expected format |
|
649 | - $filename = str_replace( |
|
650 | - ' ', |
|
651 | - '_', |
|
652 | - ucwords( |
|
653 | - str_replace( |
|
654 | - '_', |
|
655 | - ' ', |
|
656 | - $extend_ref |
|
657 | - ) |
|
658 | - ) |
|
659 | - ); |
|
660 | - $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
661 | - $this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace( |
|
662 | - array('\\', '/'), |
|
663 | - '/', |
|
664 | - EE_CORE_CAF_ADMIN |
|
665 | - . 'extend/' |
|
666 | - . $extend_ref |
|
667 | - . '/' |
|
668 | - . $filename |
|
669 | - . '.core.php' |
|
670 | - ); |
|
671 | - $this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename; |
|
672 | - // set autoloaders for our admin page classes based on included path information |
|
673 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($extend); |
|
674 | - } |
|
675 | - } |
|
676 | - } |
|
677 | - // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
|
678 | - $ee_admin_hooks = array(); |
|
679 | - $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
680 | - if ($hooks) { |
|
681 | - foreach ($hooks as $hook) { |
|
682 | - if (is_readable($hook)) { |
|
683 | - require_once $hook; |
|
684 | - $classname = str_replace( |
|
685 | - [EE_CORE_CAF_ADMIN . 'hooks/', '.class.php'], |
|
686 | - '', |
|
687 | - $hook |
|
688 | - ); |
|
689 | - if (class_exists($classname)) { |
|
690 | - $admin_page = $this->loader->getShared($classname); |
|
691 | - $ee_admin_hooks[] = $admin_page; |
|
692 | - } |
|
693 | - } |
|
694 | - } |
|
695 | - } |
|
696 | - $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks); |
|
697 | - return $installed_refs; |
|
698 | - } |
|
699 | - |
|
700 | - |
|
701 | - /** |
|
702 | - * Utility method for sorting the _menu_maps (callback for usort php function) |
|
703 | - * |
|
704 | - * @since 4.4.0 |
|
705 | - * @param EE_Admin_Page_Menu_Map $a menu_map object |
|
706 | - * @param EE_Admin_Page_Menu_Map $b being compared to |
|
707 | - * @return int sort order |
|
708 | - */ |
|
709 | - private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b) |
|
710 | - { |
|
711 | - if ($a->menu_order === $b->menu_order) { |
|
712 | - return 0; |
|
713 | - } |
|
714 | - return ($a->menu_order < $b->menu_order) ? -1 : 1; |
|
715 | - } |
|
716 | - |
|
717 | - |
|
718 | - /** |
|
719 | - * _default_header_link |
|
720 | - * This is just a dummy method to use with header submenu items |
|
721 | - * |
|
722 | - * @return bool false |
|
723 | - */ |
|
724 | - public function _default_header_link() |
|
725 | - { |
|
726 | - return false; |
|
727 | - } |
|
19 | + /** |
|
20 | + * @var LoaderInterface $loader |
|
21 | + */ |
|
22 | + protected $loader; |
|
23 | + |
|
24 | + /** |
|
25 | + * _installed_pages |
|
26 | + * objects for page_init objects detected and loaded |
|
27 | + * |
|
28 | + * @access private |
|
29 | + * @var EE_Admin_Page_Init[] |
|
30 | + */ |
|
31 | + private $_installed_pages = array(); |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * this is used to hold the registry of menu slugs for all the installed admin pages |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + private $_menu_slugs = array(); |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * _caffeinated_extends |
|
44 | + * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and |
|
45 | + * pieces needed to do so). This property is defined in the _set_caffeinated method. |
|
46 | + * |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + private $_caffeinated_extends = array(); |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * _current_caf_extend_slug |
|
54 | + * This property is used for holding the page slug that is required for referencing the correct |
|
55 | + * _caffeinated_extends index when the corresponding core child EE_Admin_Page_init hooks are executed. |
|
56 | + * |
|
57 | + * @var array |
|
58 | + */ |
|
59 | + private $_current_caf_extend_slug; |
|
60 | + |
|
61 | + /** |
|
62 | + * _prepped_menu_maps |
|
63 | + * This is the prepared array of EE_Admin_Page_Menu_Maps for adding to the admin_menu. |
|
64 | + * |
|
65 | + * @since 4.4.0 |
|
66 | + * @var EE_Admin_Page_Menu_Map[] |
|
67 | + */ |
|
68 | + private $_prepped_menu_maps = array(); |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * _admin_menu_groups |
|
73 | + * array that holds the group headings and details for |
|
74 | + * |
|
75 | + * @access private |
|
76 | + * @var array |
|
77 | + */ |
|
78 | + private $_admin_menu_groups = array(); |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * This property will hold the hook file for setting up the filter that does all the connections between admin |
|
83 | + * pages. |
|
84 | + * |
|
85 | + * @var string |
|
86 | + */ |
|
87 | + public $hook_file; |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * constructor |
|
92 | + * |
|
93 | + * @access public |
|
94 | + * @throws EE_Error |
|
95 | + * @throws InvalidArgumentException |
|
96 | + * @throws InvalidDataTypeException |
|
97 | + * @throws ReflectionException |
|
98 | + * @throws InvalidInterfaceException |
|
99 | + */ |
|
100 | + public function __construct() |
|
101 | + { |
|
102 | + $this->loader = LoaderFactory::getLoader(); |
|
103 | + // load menu_map classes |
|
104 | + EE_Registry::instance()->load_file(EE_ADMIN, 'EE_Admin_Page_Menu_Map', 'core'); |
|
105 | + // define the default "groups" for the admin_pages |
|
106 | + $this->_set_menu_groups(); |
|
107 | + // let's do a scan and see what installed pages we have |
|
108 | + $this->_get_installed_pages(); |
|
109 | + // set menus (has to be done on every load - we're not actually loading the page just setting the menus and where they point to). |
|
110 | + add_action('admin_menu', array($this, 'set_menus')); |
|
111 | + add_action('network_admin_menu', array($this, 'set_network_menus')); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by |
|
117 | + * files in the caffeinated folder. |
|
118 | + * |
|
119 | + * @access private |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + private function _define_caffeinated_constants() |
|
123 | + { |
|
124 | + if (! defined('EE_CORE_CAF_ADMIN')) { |
|
125 | + define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
126 | + define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
127 | + define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
128 | + define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
129 | + define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
130 | + define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * _set_menu_groups |
|
137 | + * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array) |
|
138 | + * |
|
139 | + * @access private |
|
140 | + * @return void |
|
141 | + * @throws EE_Error |
|
142 | + */ |
|
143 | + private function _set_menu_groups() |
|
144 | + { |
|
145 | + // set array of EE_Admin_Page_Menu_Group objects |
|
146 | + $groups = array( |
|
147 | + 'main' => new EE_Admin_Page_Menu_Group( |
|
148 | + array( |
|
149 | + 'menu_label' => __('Main', 'event_espresso'), |
|
150 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::NONE, |
|
151 | + 'menu_slug' => 'main', |
|
152 | + 'capability' => 'ee_read_ee', |
|
153 | + 'menu_order' => 0, |
|
154 | + 'parent_slug' => 'espresso_events', |
|
155 | + ) |
|
156 | + ), |
|
157 | + 'management' => new EE_Admin_Page_Menu_Group( |
|
158 | + array( |
|
159 | + 'menu_label' => __('Management', 'event_espresso'), |
|
160 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
161 | + 'menu_slug' => 'management', |
|
162 | + 'capability' => 'ee_read_ee', |
|
163 | + 'menu_order' => 10, |
|
164 | + 'parent_slug' => 'espresso_events', |
|
165 | + ) |
|
166 | + ), |
|
167 | + 'settings' => new EE_Admin_Page_Menu_Group( |
|
168 | + array( |
|
169 | + 'menu_label' => __('Settings', 'event_espresso'), |
|
170 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
171 | + 'menu_slug' => 'settings', |
|
172 | + 'capability' => 'ee_read_ee', |
|
173 | + 'menu_order' => 30, |
|
174 | + 'parent_slug' => 'espresso_events', |
|
175 | + ) |
|
176 | + ), |
|
177 | + 'templates' => new EE_Admin_Page_Menu_Group( |
|
178 | + array( |
|
179 | + 'menu_label' => __('Templates', 'event_espresso'), |
|
180 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
181 | + 'menu_slug' => 'templates', |
|
182 | + 'capability' => 'ee_read_ee', |
|
183 | + 'menu_order' => 40, |
|
184 | + 'parent_slug' => 'espresso_events', |
|
185 | + ) |
|
186 | + ), |
|
187 | + 'extras' => new EE_Admin_Page_Menu_Group( |
|
188 | + array( |
|
189 | + 'menu_label' => __('Extras', 'event_espresso'), |
|
190 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
191 | + 'menu_slug' => 'extras', |
|
192 | + 'capability' => 'ee_read_ee', |
|
193 | + 'menu_order' => 50, |
|
194 | + 'parent_slug' => 'espresso_events', |
|
195 | + 'maintenance_mode_parent' => 'espresso_maintenance_settings', |
|
196 | + ) |
|
197 | + ), |
|
198 | + 'tools' => new EE_Admin_Page_Menu_Group( |
|
199 | + array( |
|
200 | + 'menu_label' => __('Tools', 'event_espresso'), |
|
201 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
202 | + 'menu_slug' => 'tools', |
|
203 | + 'capability' => 'ee_read_ee', |
|
204 | + 'menu_order' => 60, |
|
205 | + 'parent_slug' => 'espresso_events', |
|
206 | + ) |
|
207 | + ), |
|
208 | + 'addons' => new EE_Admin_Page_Menu_Group( |
|
209 | + array( |
|
210 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_AND_NETWORK_ADMIN, |
|
211 | + 'menu_label' => __('Add-ons', 'event_espresso'), |
|
212 | + 'menu_slug' => 'addons', |
|
213 | + 'capability' => 'ee_read_ee', |
|
214 | + 'menu_order' => 20, |
|
215 | + 'parent_slug' => 'espresso_events', |
|
216 | + ) |
|
217 | + ), |
|
218 | + ); |
|
219 | + $this->_admin_menu_groups = apply_filters( |
|
220 | + 'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups', |
|
221 | + $groups |
|
222 | + ); |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * This takes all the groups in the _admin_menu_groups array and returns the array indexed by group |
|
228 | + * slug. The other utility with this function is it validates that all the groups are instances of |
|
229 | + * EE_Admin_Page_Menu_Group (cause some invalid things might have slipped in via addons). |
|
230 | + * |
|
231 | + * @return EE_Admin_Page_Menu_Group[] |
|
232 | + * @throws EE_Error |
|
233 | + * @since 4.4.0 |
|
234 | + */ |
|
235 | + private function _rearrange_menu_groups() |
|
236 | + { |
|
237 | + $groups = array(); |
|
238 | + // first let's order the menu groups by their internal menu order |
|
239 | + // (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
|
240 | + usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
|
241 | + foreach ($this->_admin_menu_groups as $group) { |
|
242 | + if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
243 | + throw new EE_Error( |
|
244 | + sprintf( |
|
245 | + __( |
|
246 | + 'Unable to continue sorting the menu groups array because there is an invalid value for the menu groups. All values in this array are required to be a EE_Admin_Page_Menu_Group object. Instead there was: %s', |
|
247 | + 'event_espresso' |
|
248 | + ), |
|
249 | + print_r($group, true) |
|
250 | + ) |
|
251 | + ); |
|
252 | + } |
|
253 | + $groups[ $group->menu_slug ] = $group; |
|
254 | + } |
|
255 | + return $groups; |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * _get_installed_pages |
|
261 | + * This just gets the list of installed EE_Admin_pages. |
|
262 | + * |
|
263 | + * @access private |
|
264 | + * @return void |
|
265 | + * @throws EE_Error |
|
266 | + * @throws InvalidArgumentException |
|
267 | + * @throws InvalidDataTypeException |
|
268 | + * @throws InvalidInterfaceException |
|
269 | + * @throws ReflectionException |
|
270 | + */ |
|
271 | + private function _get_installed_pages() |
|
272 | + { |
|
273 | + $installed_refs = array(); |
|
274 | + $exclude = array('assets', 'templates'); |
|
275 | + // grab everything in the admin core directory |
|
276 | + $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
277 | + if ($admin_screens) { |
|
278 | + foreach ($admin_screens as $admin_screen) { |
|
279 | + $admin_screen_name = basename($admin_screen); |
|
280 | + // files and anything in the exclude array need not apply |
|
281 | + if (is_dir($admin_screen) && ! in_array($admin_screen_name, $exclude, true)) { |
|
282 | + // these folders represent the different EE admin pages |
|
283 | + $installed_refs[ $admin_screen_name ] = $admin_screen; |
|
284 | + } |
|
285 | + } |
|
286 | + } |
|
287 | + if (empty($installed_refs)) { |
|
288 | + $error_msg[] = __( |
|
289 | + 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
|
290 | + 'event_espresso' |
|
291 | + ); |
|
292 | + $error_msg[] = $error_msg[0] . "\r\n" |
|
293 | + . sprintf( |
|
294 | + __( |
|
295 | + 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
|
296 | + 'event_espresso' |
|
297 | + ), |
|
298 | + EE_ADMIN_PAGES |
|
299 | + ); |
|
300 | + throw new EE_Error(implode('||', $error_msg)); |
|
301 | + } |
|
302 | + // this just checks the caffeinated folder and takes care of setting up any caffeinated stuff. |
|
303 | + $installed_refs = $this->_set_caffeinated($installed_refs); |
|
304 | + // allow plugins to add in their own pages (note at this point they will need to have an autoloader defined for their class) OR hook into EEH_Autoloader::load_admin_page() to add their path.; |
|
305 | + $installed_refs = apply_filters( |
|
306 | + 'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs', |
|
307 | + $installed_refs |
|
308 | + ); |
|
309 | + $this->_caffeinated_extends = apply_filters( |
|
310 | + 'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends', |
|
311 | + $this->_caffeinated_extends |
|
312 | + ); |
|
313 | + // loop through admin pages and setup the $_installed_pages array. |
|
314 | + $hooks_ref = []; |
|
315 | + foreach ($installed_refs as $page => $path) { |
|
316 | + // set autoloaders for our admin page classes based on included path information |
|
317 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
318 | + // build list of installed pages |
|
319 | + $this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path); |
|
320 | + // verify returned object |
|
321 | + if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
322 | + if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
323 | + continue; |
|
324 | + } |
|
325 | + // skip if in full maintenance mode and maintenance_mode_parent is set |
|
326 | + $maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent; |
|
327 | + if (empty($maintenance_mode_parent) |
|
328 | + && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
329 | + ) { |
|
330 | + unset($installed_refs[ $page ]); |
|
331 | + continue; |
|
332 | + } |
|
333 | + $menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug; |
|
334 | + $this->_menu_slugs[ $menu_slug ] = $page; |
|
335 | + // flag for register hooks on extended pages b/c extended pages use the default INIT. |
|
336 | + $extend = false; |
|
337 | + // now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals. If there are then let's hook into the init admin filter and load our extend instead. |
|
338 | + if (isset($this->_caffeinated_extends[ $page ])) { |
|
339 | + $this->_current_caf_extend_slug = $page; |
|
340 | + $admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name(); |
|
341 | + $caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path']; |
|
342 | + $caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page']; |
|
343 | + add_filter( |
|
344 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}", |
|
345 | + static function ($path_to_file) use ($caf_path) { |
|
346 | + return $caf_path; |
|
347 | + } |
|
348 | + ); |
|
349 | + add_filter( |
|
350 | + "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}", |
|
351 | + static function ($admin_page) use ($caf_admin_page) { |
|
352 | + return $caf_admin_page; |
|
353 | + } |
|
354 | + ); |
|
355 | + $extend = true; |
|
356 | + } |
|
357 | + // let's do the registered hooks |
|
358 | + $extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend); |
|
359 | + foreach ($extended_hooks as $key => $value) { |
|
360 | + $hooks_ref[] = $value; |
|
361 | + } |
|
362 | + } |
|
363 | + } |
|
364 | + // the hooks_ref is all the pages where we have $extended _Hooks files that will extend a class in a different folder. So we want to make sure we load the file for the parent. |
|
365 | + // first make sure we've got unique values |
|
366 | + $hooks_ref = array_unique($hooks_ref); |
|
367 | + // now let's loop and require! |
|
368 | + foreach ($hooks_ref as $path) { |
|
369 | + require_once($path); |
|
370 | + } |
|
371 | + // make sure we have menu slugs global setup. Used in EE_Admin_Page->page_setup() to ensure we don't do a full class load for an admin page that isn't requested. |
|
372 | + global $ee_menu_slugs; |
|
373 | + $ee_menu_slugs = $this->_menu_slugs; |
|
374 | + // we need to loop again to run any early code |
|
375 | + foreach ($installed_refs as $page => $path) { |
|
376 | + if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
377 | + $this->_installed_pages[ $page ]->do_initial_loads(); |
|
378 | + } |
|
379 | + } |
|
380 | + do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * get_admin_page_object |
|
386 | + * |
|
387 | + * @param string $page_slug |
|
388 | + * @return EE_Admin_Page |
|
389 | + */ |
|
390 | + public function get_admin_page_object($page_slug = '') |
|
391 | + { |
|
392 | + if (isset($this->_installed_pages[ $page_slug ])) { |
|
393 | + return $this->_installed_pages[ $page_slug ]->loaded_page_object(); |
|
394 | + } |
|
395 | + return null; |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + /** |
|
400 | + * _get_classname_for_admin_page |
|
401 | + * generates an "Admin Page" class based on the directory name |
|
402 | + * |
|
403 | + * @param $dir_name |
|
404 | + * @return string |
|
405 | + */ |
|
406 | + private function _get_classname_for_admin_page($dir_name = '') |
|
407 | + { |
|
408 | + $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
409 | + return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * _get_classname_for_admin_init_page |
|
415 | + * generates an "Admin Page Init" class based on the directory name |
|
416 | + * |
|
417 | + * @param $dir_name |
|
418 | + * @return string |
|
419 | + */ |
|
420 | + private function _get_classname_for_admin_init_page($dir_name = '') |
|
421 | + { |
|
422 | + $class_name = str_replace('_', ' ', strtolower($dir_name)); |
|
423 | + return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * _load_admin_page |
|
429 | + * Loads and instantiates page_init object for a single EE_admin page. |
|
430 | + * |
|
431 | + * @param string $page page_reference |
|
432 | + * @param string $path |
|
433 | + * @return object|bool return page object if valid, bool false if not. |
|
434 | + * @throws EE_Error |
|
435 | + * @throws InvalidArgumentException |
|
436 | + * @throws InvalidDataTypeException |
|
437 | + * @throws ReflectionException |
|
438 | + * @throws InvalidInterfaceException |
|
439 | + */ |
|
440 | + private function _load_admin_page($page = '', $path = '') |
|
441 | + { |
|
442 | + $class_name = $this->_get_classname_for_admin_init_page($page); |
|
443 | + EE_Registry::instance()->load_file($path, $class_name, 'core'); |
|
444 | + if (! class_exists($class_name)) { |
|
445 | + $inner_error_msg = '<br />' |
|
446 | + . sprintf( |
|
447 | + esc_html__( |
|
448 | + 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
449 | + 'event_espresso' |
|
450 | + ), |
|
451 | + '<strong>' . $class_name . '</strong>' |
|
452 | + ); |
|
453 | + $error_msg[] = sprintf( |
|
454 | + __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
|
455 | + $page |
|
456 | + ); |
|
457 | + $error_msg[] = $error_msg[0] |
|
458 | + . "\r\n" |
|
459 | + . sprintf( |
|
460 | + esc_html__( |
|
461 | + 'There is no Init class in place for the %s admin page.', |
|
462 | + 'event_espresso' |
|
463 | + ), |
|
464 | + $page |
|
465 | + ) |
|
466 | + . $inner_error_msg; |
|
467 | + throw new EE_Error(implode('||', $error_msg)); |
|
468 | + } |
|
469 | + return $this->loader->getShared($class_name); |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * set_menus |
|
475 | + * This method sets up the menus for EE Admin Pages |
|
476 | + * |
|
477 | + * @access private |
|
478 | + * @return void |
|
479 | + * @throws EE_Error |
|
480 | + * @throws InvalidDataTypeException |
|
481 | + * @throws ReflectionException |
|
482 | + */ |
|
483 | + public function set_menus() |
|
484 | + { |
|
485 | + // prep the menu pages (sort, group.) |
|
486 | + $this->_prep_pages(); |
|
487 | + foreach ($this->_prepped_menu_maps as $menu_map) { |
|
488 | + if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
489 | + $menu_map->add_menu_page(); |
|
490 | + } |
|
491 | + } |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * set_network_menus |
|
497 | + * This method sets up the menus for network EE Admin Pages. |
|
498 | + * Almost identical to EE_Admin_Page_Loader::set_menus() except pages |
|
499 | + * are only added to the menu map if they are intended for the admin menu |
|
500 | + * |
|
501 | + * @return void |
|
502 | + * @throws EE_Error |
|
503 | + * @throws InvalidDataTypeException |
|
504 | + * @throws ReflectionException |
|
505 | + */ |
|
506 | + public function set_network_menus() |
|
507 | + { |
|
508 | + $this->_prep_pages(); |
|
509 | + foreach ($this->_prepped_menu_maps as $menu_map) { |
|
510 | + if (EE_Registry::instance()->CAP->current_user_can($menu_map->capability, $menu_map->menu_slug)) { |
|
511 | + $menu_map->add_menu_page(true); |
|
512 | + } |
|
513 | + } |
|
514 | + } |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * _prep_pages |
|
519 | + * sets the _prepped_menu_maps property |
|
520 | + * |
|
521 | + * @access private |
|
522 | + * @return void |
|
523 | + * @throws EE_Error |
|
524 | + * @throws InvalidDataTypeException |
|
525 | + */ |
|
526 | + private function _prep_pages() |
|
527 | + { |
|
528 | + $pages_array = array(); |
|
529 | + // rearrange _admin_menu_groups to be indexed by group slug. |
|
530 | + $menu_groups = $this->_rearrange_menu_groups(); |
|
531 | + foreach ($this->_installed_pages as $page) { |
|
532 | + if ($page instanceof EE_Admin_page_Init) { |
|
533 | + $page_map = $page->get_menu_map(); |
|
534 | + // if we've got an array then the menu map is in the old format |
|
535 | + // so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
|
536 | + if ($page_map === null || is_array($page_map)) { |
|
537 | + new PersistentAdminNotice( |
|
538 | + 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
539 | + sprintf( |
|
540 | + __( |
|
541 | + 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
|
542 | + 'event_espresso' |
|
543 | + ), |
|
544 | + $page->label |
|
545 | + ) |
|
546 | + ); |
|
547 | + continue; |
|
548 | + } |
|
549 | + // if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
|
550 | + if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
551 | + throw new EE_Error( |
|
552 | + sprintf( |
|
553 | + __( |
|
554 | + 'The menu map for %s must be an EE_Admin_Page_Menu_Map object. Instead it is %s. Please double check that the menu map has been configured correctly.', |
|
555 | + 'event_espresso' |
|
556 | + ), |
|
557 | + $page->label, |
|
558 | + $page_map |
|
559 | + ) |
|
560 | + ); |
|
561 | + } |
|
562 | + // use the maintenance_mode_parent property and maintenance mode status to determine if this page even gets added to array. |
|
563 | + if (empty($page_map->maintenance_mode_parent) |
|
564 | + && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
565 | + ) { |
|
566 | + continue; |
|
567 | + } |
|
568 | + // assign to group (remember $page_map has the admin page stored in it). |
|
569 | + $pages_array[ $page_map->menu_group ][] = $page_map; |
|
570 | + } |
|
571 | + } |
|
572 | + if (empty($pages_array)) { |
|
573 | + throw new EE_Error(__('Something went wrong when prepping the admin pages', 'event_espresso')); |
|
574 | + } |
|
575 | + // let's sort the groups, make sure it's a valid group, add header (if to show). |
|
576 | + foreach ($pages_array as $group => $menu_maps) { |
|
577 | + // valid_group? |
|
578 | + if (! array_key_exists($group, $menu_groups)) { |
|
579 | + continue; |
|
580 | + } |
|
581 | + // sort pages. |
|
582 | + usort($menu_maps, array($this, '_sort_menu_maps')); |
|
583 | + // prepend header |
|
584 | + array_unshift($menu_maps, $menu_groups[ $group ]); |
|
585 | + // reset $pages_array with prepped data |
|
586 | + $pages_array[ $group ] = $menu_maps; |
|
587 | + } |
|
588 | + |
|
589 | + // now let's setup the _prepped_menu_maps property |
|
590 | + foreach ($menu_groups as $group => $group_objs) { |
|
591 | + if (isset($pages_array[ $group ])) { |
|
592 | + foreach ($pages_array[ $group ] as $key => $value) { |
|
593 | + $this->_prepped_menu_maps[] = $value; |
|
594 | + } |
|
595 | + } |
|
596 | + } |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * This method is the "workhorse" for detecting and setting up caffeinated functionality. |
|
602 | + * In this method there are three checks being done: |
|
603 | + * 1. Do we have any NEW admin page sets. If we do, lets add them into the menu setup (via the $installed_refs |
|
604 | + * array) etc. (new page sets are found in caffeinated/new/{page}) |
|
605 | + * 2. Do we have any EXTENDED page sets. Basically an extended EE_Admin Page extends the core {child}_Admin_Page |
|
606 | + * class. eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class: |
|
607 | + * Extend_Events_Admin_Page extends Events_Admin_Page. |
|
608 | + * 3. Do we have any files just for setting up hooks into other core pages. The files can be any name in |
|
609 | + * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the |
|
610 | + * classname inside. These classes are instantiated really early so that any hooks in them are run before the |
|
611 | + * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated |
|
612 | + * admin_pages) |
|
613 | + * |
|
614 | + * @param array $installed_refs the original installed_refs array that may contain our NEW EE_Admin_Pages to be |
|
615 | + * loaded. |
|
616 | + * @return array |
|
617 | + * @throws EE_Error |
|
618 | + * @throws ReflectionException |
|
619 | + */ |
|
620 | + private function _set_caffeinated($installed_refs) |
|
621 | + { |
|
622 | + // first let's check if there IS a caffeinated folder. If there is not then lets get out. |
|
623 | + if ((defined('EE_DECAF') && EE_DECAF) || ! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated/admin')) { |
|
624 | + return $installed_refs; |
|
625 | + } |
|
626 | + $this->_define_caffeinated_constants(); |
|
627 | + $exclude = array('tickets'); |
|
628 | + // okay let's setup an "New" pages first (we'll return installed refs later) |
|
629 | + $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
630 | + if ($new_admin_screens) { |
|
631 | + foreach ($new_admin_screens as $admin_screen) { |
|
632 | + $admin_screen_name = basename($admin_screen); |
|
633 | + // files and anything in the exclude array need not apply |
|
634 | + if (is_dir($admin_screen) && ! in_array($admin_screen_name, $exclude, true)) { |
|
635 | + // these folders represent the different NEW EE admin pages |
|
636 | + $installed_refs[ $admin_screen_name ] = $admin_screen; |
|
637 | + // set autoloaders for our admin page classes based on included path information |
|
638 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($admin_screen); |
|
639 | + } |
|
640 | + } |
|
641 | + } |
|
642 | + // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
|
643 | + $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
644 | + if ($extends) { |
|
645 | + foreach ($extends as $extend) { |
|
646 | + if (is_dir($extend)) { |
|
647 | + $extend_ref = basename($extend); |
|
648 | + // now let's make sure there is a file that matches the expected format |
|
649 | + $filename = str_replace( |
|
650 | + ' ', |
|
651 | + '_', |
|
652 | + ucwords( |
|
653 | + str_replace( |
|
654 | + '_', |
|
655 | + ' ', |
|
656 | + $extend_ref |
|
657 | + ) |
|
658 | + ) |
|
659 | + ); |
|
660 | + $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
661 | + $this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace( |
|
662 | + array('\\', '/'), |
|
663 | + '/', |
|
664 | + EE_CORE_CAF_ADMIN |
|
665 | + . 'extend/' |
|
666 | + . $extend_ref |
|
667 | + . '/' |
|
668 | + . $filename |
|
669 | + . '.core.php' |
|
670 | + ); |
|
671 | + $this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename; |
|
672 | + // set autoloaders for our admin page classes based on included path information |
|
673 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($extend); |
|
674 | + } |
|
675 | + } |
|
676 | + } |
|
677 | + // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
|
678 | + $ee_admin_hooks = array(); |
|
679 | + $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
680 | + if ($hooks) { |
|
681 | + foreach ($hooks as $hook) { |
|
682 | + if (is_readable($hook)) { |
|
683 | + require_once $hook; |
|
684 | + $classname = str_replace( |
|
685 | + [EE_CORE_CAF_ADMIN . 'hooks/', '.class.php'], |
|
686 | + '', |
|
687 | + $hook |
|
688 | + ); |
|
689 | + if (class_exists($classname)) { |
|
690 | + $admin_page = $this->loader->getShared($classname); |
|
691 | + $ee_admin_hooks[] = $admin_page; |
|
692 | + } |
|
693 | + } |
|
694 | + } |
|
695 | + } |
|
696 | + $ee_admin_hooks = apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks); |
|
697 | + return $installed_refs; |
|
698 | + } |
|
699 | + |
|
700 | + |
|
701 | + /** |
|
702 | + * Utility method for sorting the _menu_maps (callback for usort php function) |
|
703 | + * |
|
704 | + * @since 4.4.0 |
|
705 | + * @param EE_Admin_Page_Menu_Map $a menu_map object |
|
706 | + * @param EE_Admin_Page_Menu_Map $b being compared to |
|
707 | + * @return int sort order |
|
708 | + */ |
|
709 | + private function _sort_menu_maps(EE_Admin_Page_Menu_Map $a, EE_Admin_Page_Menu_Map $b) |
|
710 | + { |
|
711 | + if ($a->menu_order === $b->menu_order) { |
|
712 | + return 0; |
|
713 | + } |
|
714 | + return ($a->menu_order < $b->menu_order) ? -1 : 1; |
|
715 | + } |
|
716 | + |
|
717 | + |
|
718 | + /** |
|
719 | + * _default_header_link |
|
720 | + * This is just a dummy method to use with header submenu items |
|
721 | + * |
|
722 | + * @return bool false |
|
723 | + */ |
|
724 | + public function _default_header_link() |
|
725 | + { |
|
726 | + return false; |
|
727 | + } |
|
728 | 728 | } |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | */ |
122 | 122 | private function _define_caffeinated_constants() |
123 | 123 | { |
124 | - if (! defined('EE_CORE_CAF_ADMIN')) { |
|
125 | - define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/'); |
|
126 | - define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/'); |
|
127 | - define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/'); |
|
128 | - define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/'); |
|
129 | - define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/'); |
|
130 | - define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/'); |
|
124 | + if ( ! defined('EE_CORE_CAF_ADMIN')) { |
|
125 | + define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH.'caffeinated/admin/'); |
|
126 | + define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL.'caffeinated/admin/'); |
|
127 | + define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN.'new/'); |
|
128 | + define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN.'extend/'); |
|
129 | + define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL.'extend/'); |
|
130 | + define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN.'hooks/'); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | // (note usort type hinting to ensure the incoming array is EE_Admin_Page_Menu_Map objects ) |
240 | 240 | usort($this->_admin_menu_groups, array($this, '_sort_menu_maps')); |
241 | 241 | foreach ($this->_admin_menu_groups as $group) { |
242 | - if (! $group instanceof EE_Admin_Page_Menu_Group) { |
|
242 | + if ( ! $group instanceof EE_Admin_Page_Menu_Group) { |
|
243 | 243 | throw new EE_Error( |
244 | 244 | sprintf( |
245 | 245 | __( |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | ) |
251 | 251 | ); |
252 | 252 | } |
253 | - $groups[ $group->menu_slug ] = $group; |
|
253 | + $groups[$group->menu_slug] = $group; |
|
254 | 254 | } |
255 | 255 | return $groups; |
256 | 256 | } |
@@ -273,14 +273,14 @@ discard block |
||
273 | 273 | $installed_refs = array(); |
274 | 274 | $exclude = array('assets', 'templates'); |
275 | 275 | // grab everything in the admin core directory |
276 | - $admin_screens = glob(EE_ADMIN_PAGES . '*', GLOB_ONLYDIR); |
|
276 | + $admin_screens = glob(EE_ADMIN_PAGES.'*', GLOB_ONLYDIR); |
|
277 | 277 | if ($admin_screens) { |
278 | 278 | foreach ($admin_screens as $admin_screen) { |
279 | 279 | $admin_screen_name = basename($admin_screen); |
280 | 280 | // files and anything in the exclude array need not apply |
281 | 281 | if (is_dir($admin_screen) && ! in_array($admin_screen_name, $exclude, true)) { |
282 | 282 | // these folders represent the different EE admin pages |
283 | - $installed_refs[ $admin_screen_name ] = $admin_screen; |
|
283 | + $installed_refs[$admin_screen_name] = $admin_screen; |
|
284 | 284 | } |
285 | 285 | } |
286 | 286 | } |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | 'There are no EE_Admin pages detected, it looks like EE did not install properly', |
290 | 290 | 'event_espresso' |
291 | 291 | ); |
292 | - $error_msg[] = $error_msg[0] . "\r\n" |
|
292 | + $error_msg[] = $error_msg[0]."\r\n" |
|
293 | 293 | . sprintf( |
294 | 294 | __( |
295 | 295 | 'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.', |
@@ -316,46 +316,46 @@ discard block |
||
316 | 316 | // set autoloaders for our admin page classes based on included path information |
317 | 317 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
318 | 318 | // build list of installed pages |
319 | - $this->_installed_pages[ $page ] = $this->_load_admin_page($page, $path); |
|
319 | + $this->_installed_pages[$page] = $this->_load_admin_page($page, $path); |
|
320 | 320 | // verify returned object |
321 | - if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
322 | - if (! $this->_installed_pages[ $page ]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
321 | + if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
322 | + if ( ! $this->_installed_pages[$page]->get_menu_map() instanceof EE_Admin_Page_Menu_Map) { |
|
323 | 323 | continue; |
324 | 324 | } |
325 | 325 | // skip if in full maintenance mode and maintenance_mode_parent is set |
326 | - $maintenance_mode_parent = $this->_installed_pages[ $page ]->get_menu_map()->maintenance_mode_parent; |
|
326 | + $maintenance_mode_parent = $this->_installed_pages[$page]->get_menu_map()->maintenance_mode_parent; |
|
327 | 327 | if (empty($maintenance_mode_parent) |
328 | 328 | && EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance |
329 | 329 | ) { |
330 | - unset($installed_refs[ $page ]); |
|
330 | + unset($installed_refs[$page]); |
|
331 | 331 | continue; |
332 | 332 | } |
333 | - $menu_slug = $this->_installed_pages[ $page ]->get_menu_map()->menu_slug; |
|
334 | - $this->_menu_slugs[ $menu_slug ] = $page; |
|
333 | + $menu_slug = $this->_installed_pages[$page]->get_menu_map()->menu_slug; |
|
334 | + $this->_menu_slugs[$menu_slug] = $page; |
|
335 | 335 | // flag for register hooks on extended pages b/c extended pages use the default INIT. |
336 | 336 | $extend = false; |
337 | 337 | // now that we've got the admin_init objects... lets see if there are any caffeinated pages extending the originals. If there are then let's hook into the init admin filter and load our extend instead. |
338 | - if (isset($this->_caffeinated_extends[ $page ])) { |
|
338 | + if (isset($this->_caffeinated_extends[$page])) { |
|
339 | 339 | $this->_current_caf_extend_slug = $page; |
340 | - $admin_page_name = $this->_installed_pages[ $page ]->get_admin_page_name(); |
|
341 | - $caf_path = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['path']; |
|
342 | - $caf_admin_page = $this->_caffeinated_extends[ $this->_current_caf_extend_slug ]['admin_page']; |
|
340 | + $admin_page_name = $this->_installed_pages[$page]->get_admin_page_name(); |
|
341 | + $caf_path = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['path']; |
|
342 | + $caf_admin_page = $this->_caffeinated_extends[$this->_current_caf_extend_slug]['admin_page']; |
|
343 | 343 | add_filter( |
344 | 344 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_{$admin_page_name}", |
345 | - static function ($path_to_file) use ($caf_path) { |
|
345 | + static function($path_to_file) use ($caf_path) { |
|
346 | 346 | return $caf_path; |
347 | 347 | } |
348 | 348 | ); |
349 | 349 | add_filter( |
350 | 350 | "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_{$admin_page_name}", |
351 | - static function ($admin_page) use ($caf_admin_page) { |
|
351 | + static function($admin_page) use ($caf_admin_page) { |
|
352 | 352 | return $caf_admin_page; |
353 | 353 | } |
354 | 354 | ); |
355 | 355 | $extend = true; |
356 | 356 | } |
357 | 357 | // let's do the registered hooks |
358 | - $extended_hooks = $this->_installed_pages[ $page ]->register_hooks($extend); |
|
358 | + $extended_hooks = $this->_installed_pages[$page]->register_hooks($extend); |
|
359 | 359 | foreach ($extended_hooks as $key => $value) { |
360 | 360 | $hooks_ref[] = $value; |
361 | 361 | } |
@@ -373,8 +373,8 @@ discard block |
||
373 | 373 | $ee_menu_slugs = $this->_menu_slugs; |
374 | 374 | // we need to loop again to run any early code |
375 | 375 | foreach ($installed_refs as $page => $path) { |
376 | - if ($this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init) { |
|
377 | - $this->_installed_pages[ $page ]->do_initial_loads(); |
|
376 | + if ($this->_installed_pages[$page] instanceof EE_Admin_Page_Init) { |
|
377 | + $this->_installed_pages[$page]->do_initial_loads(); |
|
378 | 378 | } |
379 | 379 | } |
380 | 380 | do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages); |
@@ -389,8 +389,8 @@ discard block |
||
389 | 389 | */ |
390 | 390 | public function get_admin_page_object($page_slug = '') |
391 | 391 | { |
392 | - if (isset($this->_installed_pages[ $page_slug ])) { |
|
393 | - return $this->_installed_pages[ $page_slug ]->loaded_page_object(); |
|
392 | + if (isset($this->_installed_pages[$page_slug])) { |
|
393 | + return $this->_installed_pages[$page_slug]->loaded_page_object(); |
|
394 | 394 | } |
395 | 395 | return null; |
396 | 396 | } |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | private function _get_classname_for_admin_page($dir_name = '') |
407 | 407 | { |
408 | 408 | $class_name = str_replace('_', ' ', strtolower($dir_name)); |
409 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page'; |
|
409 | + return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page'; |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | private function _get_classname_for_admin_init_page($dir_name = '') |
421 | 421 | { |
422 | 422 | $class_name = str_replace('_', ' ', strtolower($dir_name)); |
423 | - return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init'; |
|
423 | + return str_replace(' ', '_', ucwords($class_name)).'_Admin_Page_Init'; |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | |
@@ -441,14 +441,14 @@ discard block |
||
441 | 441 | { |
442 | 442 | $class_name = $this->_get_classname_for_admin_init_page($page); |
443 | 443 | EE_Registry::instance()->load_file($path, $class_name, 'core'); |
444 | - if (! class_exists($class_name)) { |
|
444 | + if ( ! class_exists($class_name)) { |
|
445 | 445 | $inner_error_msg = '<br />' |
446 | 446 | . sprintf( |
447 | 447 | esc_html__( |
448 | 448 | 'Make sure you have %1$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
449 | 449 | 'event_espresso' |
450 | 450 | ), |
451 | - '<strong>' . $class_name . '</strong>' |
|
451 | + '<strong>'.$class_name.'</strong>' |
|
452 | 452 | ); |
453 | 453 | $error_msg[] = sprintf( |
454 | 454 | __('Something went wrong with loading the %s admin page.', 'event_espresso'), |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | // so let's throw a persistent notice that the admin system isn't setup correctly for this item. |
536 | 536 | if ($page_map === null || is_array($page_map)) { |
537 | 537 | new PersistentAdminNotice( |
538 | - 'menu_map_warning_' . str_replace(' ', '_', $page->label) . '_' . EVENT_ESPRESSO_VERSION, |
|
538 | + 'menu_map_warning_'.str_replace(' ', '_', $page->label).'_'.EVENT_ESPRESSO_VERSION, |
|
539 | 539 | sprintf( |
540 | 540 | __( |
541 | 541 | 'The admin page for %s was not correctly setup because it is using an older method for integrating with Event Espresso Core. This means that full functionality for this component is not available. This error message usually appears with an Add-on that is out of date. Make sure you update all your Event Espresso 4 add-ons to the latest version to ensure they have necessary compatibility updates in place.', |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | continue; |
548 | 548 | } |
549 | 549 | // if page map is NOT a EE_Admin_Page_Menu_Map object then throw error. |
550 | - if (! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
550 | + if ( ! $page_map instanceof EE_Admin_Page_Menu_Map) { |
|
551 | 551 | throw new EE_Error( |
552 | 552 | sprintf( |
553 | 553 | __( |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | continue; |
567 | 567 | } |
568 | 568 | // assign to group (remember $page_map has the admin page stored in it). |
569 | - $pages_array[ $page_map->menu_group ][] = $page_map; |
|
569 | + $pages_array[$page_map->menu_group][] = $page_map; |
|
570 | 570 | } |
571 | 571 | } |
572 | 572 | if (empty($pages_array)) { |
@@ -575,21 +575,21 @@ discard block |
||
575 | 575 | // let's sort the groups, make sure it's a valid group, add header (if to show). |
576 | 576 | foreach ($pages_array as $group => $menu_maps) { |
577 | 577 | // valid_group? |
578 | - if (! array_key_exists($group, $menu_groups)) { |
|
578 | + if ( ! array_key_exists($group, $menu_groups)) { |
|
579 | 579 | continue; |
580 | 580 | } |
581 | 581 | // sort pages. |
582 | 582 | usort($menu_maps, array($this, '_sort_menu_maps')); |
583 | 583 | // prepend header |
584 | - array_unshift($menu_maps, $menu_groups[ $group ]); |
|
584 | + array_unshift($menu_maps, $menu_groups[$group]); |
|
585 | 585 | // reset $pages_array with prepped data |
586 | - $pages_array[ $group ] = $menu_maps; |
|
586 | + $pages_array[$group] = $menu_maps; |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | // now let's setup the _prepped_menu_maps property |
590 | 590 | foreach ($menu_groups as $group => $group_objs) { |
591 | - if (isset($pages_array[ $group ])) { |
|
592 | - foreach ($pages_array[ $group ] as $key => $value) { |
|
591 | + if (isset($pages_array[$group])) { |
|
592 | + foreach ($pages_array[$group] as $key => $value) { |
|
593 | 593 | $this->_prepped_menu_maps[] = $value; |
594 | 594 | } |
595 | 595 | } |
@@ -620,27 +620,27 @@ discard block |
||
620 | 620 | private function _set_caffeinated($installed_refs) |
621 | 621 | { |
622 | 622 | // first let's check if there IS a caffeinated folder. If there is not then lets get out. |
623 | - if ((defined('EE_DECAF') && EE_DECAF) || ! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated/admin')) { |
|
623 | + if ((defined('EE_DECAF') && EE_DECAF) || ! is_dir(EE_PLUGIN_DIR_PATH.'caffeinated/admin')) { |
|
624 | 624 | return $installed_refs; |
625 | 625 | } |
626 | 626 | $this->_define_caffeinated_constants(); |
627 | 627 | $exclude = array('tickets'); |
628 | 628 | // okay let's setup an "New" pages first (we'll return installed refs later) |
629 | - $new_admin_screens = glob(EE_CORE_CAF_ADMIN . 'new/*', GLOB_ONLYDIR); |
|
629 | + $new_admin_screens = glob(EE_CORE_CAF_ADMIN.'new/*', GLOB_ONLYDIR); |
|
630 | 630 | if ($new_admin_screens) { |
631 | 631 | foreach ($new_admin_screens as $admin_screen) { |
632 | 632 | $admin_screen_name = basename($admin_screen); |
633 | 633 | // files and anything in the exclude array need not apply |
634 | 634 | if (is_dir($admin_screen) && ! in_array($admin_screen_name, $exclude, true)) { |
635 | 635 | // these folders represent the different NEW EE admin pages |
636 | - $installed_refs[ $admin_screen_name ] = $admin_screen; |
|
636 | + $installed_refs[$admin_screen_name] = $admin_screen; |
|
637 | 637 | // set autoloaders for our admin page classes based on included path information |
638 | 638 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($admin_screen); |
639 | 639 | } |
640 | 640 | } |
641 | 641 | } |
642 | 642 | // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page) |
643 | - $extends = glob(EE_CORE_CAF_ADMIN . 'extend/*', GLOB_ONLYDIR); |
|
643 | + $extends = glob(EE_CORE_CAF_ADMIN.'extend/*', GLOB_ONLYDIR); |
|
644 | 644 | if ($extends) { |
645 | 645 | foreach ($extends as $extend) { |
646 | 646 | if (is_dir($extend)) { |
@@ -657,8 +657,8 @@ discard block |
||
657 | 657 | ) |
658 | 658 | ) |
659 | 659 | ); |
660 | - $filename = 'Extend_' . $filename . '_Admin_Page'; |
|
661 | - $this->_caffeinated_extends[ $extend_ref ]['path'] = str_replace( |
|
660 | + $filename = 'Extend_'.$filename.'_Admin_Page'; |
|
661 | + $this->_caffeinated_extends[$extend_ref]['path'] = str_replace( |
|
662 | 662 | array('\\', '/'), |
663 | 663 | '/', |
664 | 664 | EE_CORE_CAF_ADMIN |
@@ -668,7 +668,7 @@ discard block |
||
668 | 668 | . $filename |
669 | 669 | . '.core.php' |
670 | 670 | ); |
671 | - $this->_caffeinated_extends[ $extend_ref ]['admin_page'] = $filename; |
|
671 | + $this->_caffeinated_extends[$extend_ref]['admin_page'] = $filename; |
|
672 | 672 | // set autoloaders for our admin page classes based on included path information |
673 | 673 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($extend); |
674 | 674 | } |
@@ -676,13 +676,13 @@ discard block |
||
676 | 676 | } |
677 | 677 | // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!). |
678 | 678 | $ee_admin_hooks = array(); |
679 | - $hooks = glob(EE_CORE_CAF_ADMIN . 'hooks/*.class.php'); |
|
679 | + $hooks = glob(EE_CORE_CAF_ADMIN.'hooks/*.class.php'); |
|
680 | 680 | if ($hooks) { |
681 | 681 | foreach ($hooks as $hook) { |
682 | 682 | if (is_readable($hook)) { |
683 | 683 | require_once $hook; |
684 | 684 | $classname = str_replace( |
685 | - [EE_CORE_CAF_ADMIN . 'hooks/', '.class.php'], |
|
685 | + [EE_CORE_CAF_ADMIN.'hooks/', '.class.php'], |
|
686 | 686 | '', |
687 | 687 | $hook |
688 | 688 | ); |
@@ -16,168 +16,168 @@ |
||
16 | 16 | class RequestTypeContext extends Context |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * indicates that the current request involves some form of activation |
|
21 | - */ |
|
22 | - const ACTIVATION = 'activation-request'; |
|
23 | - |
|
24 | - /** |
|
25 | - * indicates that the current request is for the admin but is not being made via AJAX |
|
26 | - */ |
|
27 | - const ADMIN = 'non-ajax-admin-request'; |
|
28 | - |
|
29 | - /** |
|
30 | - * indicates that the current request is for the admin AND is being made via AJAX |
|
31 | - */ |
|
32 | - const AJAX_ADMIN = 'admin-ajax-request'; |
|
33 | - |
|
34 | - /** |
|
35 | - * indicates that the current request is for the frontend AND is being made via AJAX |
|
36 | - */ |
|
37 | - const AJAX_FRONT = 'frontend-ajax-request'; |
|
38 | - |
|
39 | - /** |
|
40 | - * indicates that the current request is for the WP Heartbeat |
|
41 | - */ |
|
42 | - const AJAX_HEARTBEAT = 'admin-ajax-heartbeat'; |
|
43 | - |
|
44 | - /** |
|
45 | - * indicates that the current request is being made via AJAX, but is NOT for EE |
|
46 | - */ |
|
47 | - const AJAX_OTHER = 'other-ajax-request'; |
|
48 | - |
|
49 | - /** |
|
50 | - * indicates that the current request is for the EE REST API |
|
51 | - */ |
|
52 | - const API = 'rest-api'; |
|
53 | - |
|
54 | - /** |
|
55 | - * indicates that the current request is from the command line |
|
56 | - */ |
|
57 | - const CLI = 'command-line'; |
|
58 | - |
|
59 | - /** |
|
60 | - * indicates that the current request is for a WP_Cron |
|
61 | - */ |
|
62 | - const CRON = 'wp-cron'; |
|
63 | - |
|
64 | - /** |
|
65 | - * indicates that the current request is for a feed (ie: RSS) |
|
66 | - */ |
|
67 | - const FEED = 'feed-request'; |
|
68 | - |
|
69 | - /** |
|
70 | - * indicates that the current request is for the frontend but is not being made via AJAX |
|
71 | - */ |
|
72 | - const FRONTEND = 'non-ajax-frontend-request'; |
|
73 | - |
|
74 | - /** |
|
75 | - * indicates that the current request is for content that is to be displayed within an iframe |
|
76 | - */ |
|
77 | - const IFRAME = 'iframe-request'; |
|
78 | - |
|
79 | - /** |
|
80 | - * indicates that the current request is for the EE GraphQL manager |
|
81 | - */ |
|
82 | - const GQL = 'graphql'; |
|
83 | - |
|
84 | - /** |
|
85 | - * indicates that the current request is occurring while unit testing |
|
86 | - */ |
|
87 | - const UNIT_TEST = 'ee-unit-tests'; |
|
88 | - |
|
89 | - /** |
|
90 | - * indicates that the current request is for the WP REST API |
|
91 | - */ |
|
92 | - const WP_API = 'wp-rest-api'; |
|
93 | - |
|
94 | - /** |
|
95 | - * indicates that the current request is a loopback sent from WP core to test for errors |
|
96 | - */ |
|
97 | - const WP_SCRAPE = 'wordpress-scrape'; |
|
98 | - |
|
99 | - /** |
|
100 | - * @var boolean $is_activation |
|
101 | - */ |
|
102 | - private $is_activation = false; |
|
103 | - |
|
104 | - /** |
|
105 | - * @var array $valid_request_types |
|
106 | - */ |
|
107 | - private $valid_request_types = array(); |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * RequestTypeContext constructor. |
|
112 | - * |
|
113 | - * @param string $slug |
|
114 | - * @param string $description |
|
115 | - * @throws InvalidArgumentException |
|
116 | - */ |
|
117 | - public function __construct($slug, $description) |
|
118 | - { |
|
119 | - parent::__construct($slug, $description); |
|
120 | - if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
121 | - throw new InvalidArgumentException( |
|
122 | - sprintf( |
|
123 | - esc_html__( |
|
124 | - 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
125 | - 'event_espresso' |
|
126 | - ), |
|
127 | - '<br />', |
|
128 | - var_export($this->validRequestTypes(), true) |
|
129 | - ) |
|
130 | - ); |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @return array |
|
137 | - */ |
|
138 | - public function validRequestTypes() |
|
139 | - { |
|
140 | - if (empty($this->valid_request_types)) { |
|
141 | - $this->valid_request_types = apply_filters( |
|
142 | - 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
143 | - array( |
|
144 | - RequestTypeContext::ACTIVATION, |
|
145 | - RequestTypeContext::ADMIN, |
|
146 | - RequestTypeContext::AJAX_ADMIN, |
|
147 | - RequestTypeContext::AJAX_FRONT, |
|
148 | - RequestTypeContext::AJAX_HEARTBEAT, |
|
149 | - RequestTypeContext::AJAX_OTHER, |
|
150 | - RequestTypeContext::API, |
|
151 | - RequestTypeContext::CLI, |
|
152 | - RequestTypeContext::CRON, |
|
153 | - RequestTypeContext::FEED, |
|
154 | - RequestTypeContext::FRONTEND, |
|
155 | - RequestTypeContext::GQL, |
|
156 | - RequestTypeContext::IFRAME, |
|
157 | - RequestTypeContext::UNIT_TEST, |
|
158 | - RequestTypeContext::WP_API, |
|
159 | - RequestTypeContext::WP_SCRAPE, |
|
160 | - ) |
|
161 | - ); |
|
162 | - } |
|
163 | - return $this->valid_request_types; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @return bool |
|
169 | - */ |
|
170 | - public function isActivation() |
|
171 | - { |
|
172 | - return $this->is_activation; |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * @param bool $is_activation |
|
178 | - */ |
|
179 | - public function setIsActivation($is_activation) |
|
180 | - { |
|
181 | - $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
182 | - } |
|
19 | + /** |
|
20 | + * indicates that the current request involves some form of activation |
|
21 | + */ |
|
22 | + const ACTIVATION = 'activation-request'; |
|
23 | + |
|
24 | + /** |
|
25 | + * indicates that the current request is for the admin but is not being made via AJAX |
|
26 | + */ |
|
27 | + const ADMIN = 'non-ajax-admin-request'; |
|
28 | + |
|
29 | + /** |
|
30 | + * indicates that the current request is for the admin AND is being made via AJAX |
|
31 | + */ |
|
32 | + const AJAX_ADMIN = 'admin-ajax-request'; |
|
33 | + |
|
34 | + /** |
|
35 | + * indicates that the current request is for the frontend AND is being made via AJAX |
|
36 | + */ |
|
37 | + const AJAX_FRONT = 'frontend-ajax-request'; |
|
38 | + |
|
39 | + /** |
|
40 | + * indicates that the current request is for the WP Heartbeat |
|
41 | + */ |
|
42 | + const AJAX_HEARTBEAT = 'admin-ajax-heartbeat'; |
|
43 | + |
|
44 | + /** |
|
45 | + * indicates that the current request is being made via AJAX, but is NOT for EE |
|
46 | + */ |
|
47 | + const AJAX_OTHER = 'other-ajax-request'; |
|
48 | + |
|
49 | + /** |
|
50 | + * indicates that the current request is for the EE REST API |
|
51 | + */ |
|
52 | + const API = 'rest-api'; |
|
53 | + |
|
54 | + /** |
|
55 | + * indicates that the current request is from the command line |
|
56 | + */ |
|
57 | + const CLI = 'command-line'; |
|
58 | + |
|
59 | + /** |
|
60 | + * indicates that the current request is for a WP_Cron |
|
61 | + */ |
|
62 | + const CRON = 'wp-cron'; |
|
63 | + |
|
64 | + /** |
|
65 | + * indicates that the current request is for a feed (ie: RSS) |
|
66 | + */ |
|
67 | + const FEED = 'feed-request'; |
|
68 | + |
|
69 | + /** |
|
70 | + * indicates that the current request is for the frontend but is not being made via AJAX |
|
71 | + */ |
|
72 | + const FRONTEND = 'non-ajax-frontend-request'; |
|
73 | + |
|
74 | + /** |
|
75 | + * indicates that the current request is for content that is to be displayed within an iframe |
|
76 | + */ |
|
77 | + const IFRAME = 'iframe-request'; |
|
78 | + |
|
79 | + /** |
|
80 | + * indicates that the current request is for the EE GraphQL manager |
|
81 | + */ |
|
82 | + const GQL = 'graphql'; |
|
83 | + |
|
84 | + /** |
|
85 | + * indicates that the current request is occurring while unit testing |
|
86 | + */ |
|
87 | + const UNIT_TEST = 'ee-unit-tests'; |
|
88 | + |
|
89 | + /** |
|
90 | + * indicates that the current request is for the WP REST API |
|
91 | + */ |
|
92 | + const WP_API = 'wp-rest-api'; |
|
93 | + |
|
94 | + /** |
|
95 | + * indicates that the current request is a loopback sent from WP core to test for errors |
|
96 | + */ |
|
97 | + const WP_SCRAPE = 'wordpress-scrape'; |
|
98 | + |
|
99 | + /** |
|
100 | + * @var boolean $is_activation |
|
101 | + */ |
|
102 | + private $is_activation = false; |
|
103 | + |
|
104 | + /** |
|
105 | + * @var array $valid_request_types |
|
106 | + */ |
|
107 | + private $valid_request_types = array(); |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * RequestTypeContext constructor. |
|
112 | + * |
|
113 | + * @param string $slug |
|
114 | + * @param string $description |
|
115 | + * @throws InvalidArgumentException |
|
116 | + */ |
|
117 | + public function __construct($slug, $description) |
|
118 | + { |
|
119 | + parent::__construct($slug, $description); |
|
120 | + if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
121 | + throw new InvalidArgumentException( |
|
122 | + sprintf( |
|
123 | + esc_html__( |
|
124 | + 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
125 | + 'event_espresso' |
|
126 | + ), |
|
127 | + '<br />', |
|
128 | + var_export($this->validRequestTypes(), true) |
|
129 | + ) |
|
130 | + ); |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @return array |
|
137 | + */ |
|
138 | + public function validRequestTypes() |
|
139 | + { |
|
140 | + if (empty($this->valid_request_types)) { |
|
141 | + $this->valid_request_types = apply_filters( |
|
142 | + 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
143 | + array( |
|
144 | + RequestTypeContext::ACTIVATION, |
|
145 | + RequestTypeContext::ADMIN, |
|
146 | + RequestTypeContext::AJAX_ADMIN, |
|
147 | + RequestTypeContext::AJAX_FRONT, |
|
148 | + RequestTypeContext::AJAX_HEARTBEAT, |
|
149 | + RequestTypeContext::AJAX_OTHER, |
|
150 | + RequestTypeContext::API, |
|
151 | + RequestTypeContext::CLI, |
|
152 | + RequestTypeContext::CRON, |
|
153 | + RequestTypeContext::FEED, |
|
154 | + RequestTypeContext::FRONTEND, |
|
155 | + RequestTypeContext::GQL, |
|
156 | + RequestTypeContext::IFRAME, |
|
157 | + RequestTypeContext::UNIT_TEST, |
|
158 | + RequestTypeContext::WP_API, |
|
159 | + RequestTypeContext::WP_SCRAPE, |
|
160 | + ) |
|
161 | + ); |
|
162 | + } |
|
163 | + return $this->valid_request_types; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @return bool |
|
169 | + */ |
|
170 | + public function isActivation() |
|
171 | + { |
|
172 | + return $this->is_activation; |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * @param bool $is_activation |
|
178 | + */ |
|
179 | + public function setIsActivation($is_activation) |
|
180 | + { |
|
181 | + $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
182 | + } |
|
183 | 183 | } |
@@ -15,11 +15,11 @@ |
||
15 | 15 | class WordPressPluginsPage extends RouteMatchSpecification |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @inheritDoc |
|
20 | - */ |
|
21 | - public function isMatchingRoute() |
|
22 | - { |
|
23 | - return strpos($this->request->requestUri(), 'wp-admin/plugins.php') !== false; |
|
24 | - } |
|
18 | + /** |
|
19 | + * @inheritDoc |
|
20 | + */ |
|
21 | + public function isMatchingRoute() |
|
22 | + { |
|
23 | + return strpos($this->request->requestUri(), 'wp-admin/plugins.php') !== false; |
|
24 | + } |
|
25 | 25 | } |
@@ -16,239 +16,239 @@ |
||
16 | 16 | class RequestTypeContextChecker extends ContextChecker implements RequestTypeContextCheckerInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var RequestTypeContext $request_type |
|
21 | - */ |
|
22 | - private $request_type; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * RequestTypeContextChecker constructor. |
|
27 | - * |
|
28 | - * @param RequestTypeContext $request_type |
|
29 | - */ |
|
30 | - public function __construct(RequestTypeContext $request_type) |
|
31 | - { |
|
32 | - $this->request_type = $request_type; |
|
33 | - parent::__construct( |
|
34 | - 'RequestTypeContextChecker', |
|
35 | - $this->request_type->validRequestTypes() |
|
36 | - ); |
|
37 | - } |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * true if the current request involves some form of activation |
|
42 | - * |
|
43 | - * @return bool |
|
44 | - */ |
|
45 | - public function isActivation() |
|
46 | - { |
|
47 | - return $this->request_type->isActivation(); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * @param $is_activation |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - public function setIsActivation($is_activation) |
|
56 | - { |
|
57 | - return $this->request_type->setIsActivation($is_activation); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * true if the current request is for the admin and is not being made via AJAX |
|
63 | - * |
|
64 | - * @return bool |
|
65 | - */ |
|
66 | - public function isAdmin() |
|
67 | - { |
|
68 | - return $this->request_type->slug() === RequestTypeContext::ADMIN; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * true if the current request is for the admin AND is being made via AJAX |
|
74 | - * |
|
75 | - * @return bool |
|
76 | - */ |
|
77 | - public function isAdminAjax() |
|
78 | - { |
|
79 | - return $this->request_type->slug() === RequestTypeContext::AJAX_ADMIN; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * true if the current request is being made via AJAX... any AJAX |
|
85 | - * |
|
86 | - * @return bool |
|
87 | - */ |
|
88 | - public function isAjax() |
|
89 | - { |
|
90 | - return $this->isEeAjax() || $this->isOtherAjax(); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
96 | - * |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public function isEeAjax() |
|
100 | - { |
|
101 | - return $this->isAdminAjax() || $this->isFrontAjax(); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * true if the current request is being made via AJAX but is NOT for EE related logic |
|
107 | - * |
|
108 | - * @return bool |
|
109 | - */ |
|
110 | - public function isOtherAjax() |
|
111 | - { |
|
112 | - return $this->request_type->slug() === RequestTypeContext::AJAX_OTHER; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * true if the current request is for the EE REST API |
|
117 | - * |
|
118 | - * @return bool |
|
119 | - */ |
|
120 | - public function isApi() |
|
121 | - { |
|
122 | - return $this->request_type->slug() === RequestTypeContext::API; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * true if the current request is from the command line |
|
128 | - * |
|
129 | - * @return bool |
|
130 | - */ |
|
131 | - public function isCli() |
|
132 | - { |
|
133 | - return $this->request_type->slug() === RequestTypeContext::CLI; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * true if the current request is for a WP_Cron |
|
139 | - * |
|
140 | - * @return bool |
|
141 | - */ |
|
142 | - public function isCron() |
|
143 | - { |
|
144 | - return $this->request_type->slug() === RequestTypeContext::CRON; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * true if the current request is for a feed (ie: RSS) |
|
150 | - * |
|
151 | - * @return bool |
|
152 | - */ |
|
153 | - public function isFeed() |
|
154 | - { |
|
155 | - return $this->request_type->slug() === RequestTypeContext::FEED; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * true if the current request is for the frontend and is not being made via AJAX |
|
161 | - * |
|
162 | - * @return bool |
|
163 | - */ |
|
164 | - public function isFrontend() |
|
165 | - { |
|
166 | - return $this->request_type->slug() === RequestTypeContext::FRONTEND; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * true if the current request is for the frontend AND is being made via AJAX |
|
172 | - * |
|
173 | - * @return bool |
|
174 | - */ |
|
175 | - public function isFrontAjax() |
|
176 | - { |
|
177 | - return $this->request_type->slug() === RequestTypeContext::AJAX_FRONT; |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * true if the current request is for the EE GraphQL manager |
|
183 | - * |
|
184 | - * @return bool |
|
185 | - */ |
|
186 | - public function isGQL() |
|
187 | - { |
|
188 | - return $this->request_type->slug() === RequestTypeContext::GQL; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * true if the current request is for content that is to be displayed within an iframe |
|
194 | - * |
|
195 | - * @return bool |
|
196 | - */ |
|
197 | - public function isIframe() |
|
198 | - { |
|
199 | - return $this->request_type->slug() === RequestTypeContext::IFRAME; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * true if the current request is occurring while unit testing |
|
205 | - * |
|
206 | - * @return bool |
|
207 | - */ |
|
208 | - public function isUnitTest() |
|
209 | - { |
|
210 | - return $this->request_type->slug() === RequestTypeContext::UNIT_TEST; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * true if the current request is for the WP REST API |
|
216 | - * |
|
217 | - * @return bool |
|
218 | - */ |
|
219 | - public function isWordPressApi() |
|
220 | - { |
|
221 | - return $this->request_type->slug() === RequestTypeContext::WP_API; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * true if the current request is being made via AJAX for the WP Heartbeat |
|
227 | - * |
|
228 | - * @return bool |
|
229 | - */ |
|
230 | - public function isWordPressHeartbeat() |
|
231 | - { |
|
232 | - return $this->request_type->slug() === RequestTypeContext::AJAX_HEARTBEAT; |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * true if the current request is a loopback sent from WP core to test for errors |
|
238 | - * |
|
239 | - * @return bool |
|
240 | - */ |
|
241 | - public function isWordPressScrape() |
|
242 | - { |
|
243 | - return $this->request_type->slug() === RequestTypeContext::WP_SCRAPE; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * @return string |
|
249 | - */ |
|
250 | - public function slug() |
|
251 | - { |
|
252 | - return $this->request_type->slug(); |
|
253 | - } |
|
19 | + /** |
|
20 | + * @var RequestTypeContext $request_type |
|
21 | + */ |
|
22 | + private $request_type; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * RequestTypeContextChecker constructor. |
|
27 | + * |
|
28 | + * @param RequestTypeContext $request_type |
|
29 | + */ |
|
30 | + public function __construct(RequestTypeContext $request_type) |
|
31 | + { |
|
32 | + $this->request_type = $request_type; |
|
33 | + parent::__construct( |
|
34 | + 'RequestTypeContextChecker', |
|
35 | + $this->request_type->validRequestTypes() |
|
36 | + ); |
|
37 | + } |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * true if the current request involves some form of activation |
|
42 | + * |
|
43 | + * @return bool |
|
44 | + */ |
|
45 | + public function isActivation() |
|
46 | + { |
|
47 | + return $this->request_type->isActivation(); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * @param $is_activation |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + public function setIsActivation($is_activation) |
|
56 | + { |
|
57 | + return $this->request_type->setIsActivation($is_activation); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * true if the current request is for the admin and is not being made via AJAX |
|
63 | + * |
|
64 | + * @return bool |
|
65 | + */ |
|
66 | + public function isAdmin() |
|
67 | + { |
|
68 | + return $this->request_type->slug() === RequestTypeContext::ADMIN; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * true if the current request is for the admin AND is being made via AJAX |
|
74 | + * |
|
75 | + * @return bool |
|
76 | + */ |
|
77 | + public function isAdminAjax() |
|
78 | + { |
|
79 | + return $this->request_type->slug() === RequestTypeContext::AJAX_ADMIN; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * true if the current request is being made via AJAX... any AJAX |
|
85 | + * |
|
86 | + * @return bool |
|
87 | + */ |
|
88 | + public function isAjax() |
|
89 | + { |
|
90 | + return $this->isEeAjax() || $this->isOtherAjax(); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
96 | + * |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public function isEeAjax() |
|
100 | + { |
|
101 | + return $this->isAdminAjax() || $this->isFrontAjax(); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * true if the current request is being made via AJAX but is NOT for EE related logic |
|
107 | + * |
|
108 | + * @return bool |
|
109 | + */ |
|
110 | + public function isOtherAjax() |
|
111 | + { |
|
112 | + return $this->request_type->slug() === RequestTypeContext::AJAX_OTHER; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * true if the current request is for the EE REST API |
|
117 | + * |
|
118 | + * @return bool |
|
119 | + */ |
|
120 | + public function isApi() |
|
121 | + { |
|
122 | + return $this->request_type->slug() === RequestTypeContext::API; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * true if the current request is from the command line |
|
128 | + * |
|
129 | + * @return bool |
|
130 | + */ |
|
131 | + public function isCli() |
|
132 | + { |
|
133 | + return $this->request_type->slug() === RequestTypeContext::CLI; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * true if the current request is for a WP_Cron |
|
139 | + * |
|
140 | + * @return bool |
|
141 | + */ |
|
142 | + public function isCron() |
|
143 | + { |
|
144 | + return $this->request_type->slug() === RequestTypeContext::CRON; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * true if the current request is for a feed (ie: RSS) |
|
150 | + * |
|
151 | + * @return bool |
|
152 | + */ |
|
153 | + public function isFeed() |
|
154 | + { |
|
155 | + return $this->request_type->slug() === RequestTypeContext::FEED; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * true if the current request is for the frontend and is not being made via AJAX |
|
161 | + * |
|
162 | + * @return bool |
|
163 | + */ |
|
164 | + public function isFrontend() |
|
165 | + { |
|
166 | + return $this->request_type->slug() === RequestTypeContext::FRONTEND; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * true if the current request is for the frontend AND is being made via AJAX |
|
172 | + * |
|
173 | + * @return bool |
|
174 | + */ |
|
175 | + public function isFrontAjax() |
|
176 | + { |
|
177 | + return $this->request_type->slug() === RequestTypeContext::AJAX_FRONT; |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * true if the current request is for the EE GraphQL manager |
|
183 | + * |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | + public function isGQL() |
|
187 | + { |
|
188 | + return $this->request_type->slug() === RequestTypeContext::GQL; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * true if the current request is for content that is to be displayed within an iframe |
|
194 | + * |
|
195 | + * @return bool |
|
196 | + */ |
|
197 | + public function isIframe() |
|
198 | + { |
|
199 | + return $this->request_type->slug() === RequestTypeContext::IFRAME; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * true if the current request is occurring while unit testing |
|
205 | + * |
|
206 | + * @return bool |
|
207 | + */ |
|
208 | + public function isUnitTest() |
|
209 | + { |
|
210 | + return $this->request_type->slug() === RequestTypeContext::UNIT_TEST; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * true if the current request is for the WP REST API |
|
216 | + * |
|
217 | + * @return bool |
|
218 | + */ |
|
219 | + public function isWordPressApi() |
|
220 | + { |
|
221 | + return $this->request_type->slug() === RequestTypeContext::WP_API; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * true if the current request is being made via AJAX for the WP Heartbeat |
|
227 | + * |
|
228 | + * @return bool |
|
229 | + */ |
|
230 | + public function isWordPressHeartbeat() |
|
231 | + { |
|
232 | + return $this->request_type->slug() === RequestTypeContext::AJAX_HEARTBEAT; |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * true if the current request is a loopback sent from WP core to test for errors |
|
238 | + * |
|
239 | + * @return bool |
|
240 | + */ |
|
241 | + public function isWordPressScrape() |
|
242 | + { |
|
243 | + return $this->request_type->slug() === RequestTypeContext::WP_SCRAPE; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * @return string |
|
249 | + */ |
|
250 | + public function slug() |
|
251 | + { |
|
252 | + return $this->request_type->slug(); |
|
253 | + } |
|
254 | 254 | } |
@@ -13,152 +13,152 @@ |
||
13 | 13 | interface RequestTypeContextCheckerInterface |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * true if the current request involves some form of activation |
|
18 | - * |
|
19 | - * @return bool |
|
20 | - */ |
|
21 | - public function isActivation(); |
|
16 | + /** |
|
17 | + * true if the current request involves some form of activation |
|
18 | + * |
|
19 | + * @return bool |
|
20 | + */ |
|
21 | + public function isActivation(); |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * @param $is_activation |
|
26 | - * @return bool |
|
27 | - */ |
|
28 | - public function setIsActivation($is_activation); |
|
24 | + /** |
|
25 | + * @param $is_activation |
|
26 | + * @return bool |
|
27 | + */ |
|
28 | + public function setIsActivation($is_activation); |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * true if the current request is for the admin and is not being made via AJAX |
|
33 | - * |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function isAdmin(); |
|
31 | + /** |
|
32 | + * true if the current request is for the admin and is not being made via AJAX |
|
33 | + * |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function isAdmin(); |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * true if the current request is for the admin AND is being made via AJAX |
|
41 | - * and the ajax request contains the request parameter "ee_admin_ajax" |
|
42 | - * |
|
43 | - * @return bool |
|
44 | - */ |
|
45 | - public function isAdminAjax(); |
|
39 | + /** |
|
40 | + * true if the current request is for the admin AND is being made via AJAX |
|
41 | + * and the ajax request contains the request parameter "ee_admin_ajax" |
|
42 | + * |
|
43 | + * @return bool |
|
44 | + */ |
|
45 | + public function isAdminAjax(); |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * true if the current request is being made via AJAX... any AJAX |
|
50 | - * |
|
51 | - * @return bool |
|
52 | - */ |
|
53 | - public function isAjax(); |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * true if the current request is for the EE REST API |
|
58 | - * |
|
59 | - * @return bool |
|
60 | - */ |
|
61 | - public function isApi(); |
|
48 | + /** |
|
49 | + * true if the current request is being made via AJAX... any AJAX |
|
50 | + * |
|
51 | + * @return bool |
|
52 | + */ |
|
53 | + public function isAjax(); |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * true if the current request is for the EE REST API |
|
58 | + * |
|
59 | + * @return bool |
|
60 | + */ |
|
61 | + public function isApi(); |
|
62 | 62 | |
63 | - |
|
64 | - /** |
|
65 | - * true if the current request is from the command line |
|
66 | - * |
|
67 | - * @return bool |
|
68 | - */ |
|
69 | - public function isCli(); |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * true if the current request is for a WP_Cron |
|
74 | - * |
|
75 | - * @return bool |
|
76 | - */ |
|
77 | - public function isCron(); |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
82 | - * |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function isEeAjax(); |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * true if the current request is for a feed (ie: RSS) |
|
90 | - * |
|
91 | - * @return bool |
|
92 | - */ |
|
93 | - public function isFeed(); |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * true if the current request is for the frontend and is not being made via AJAX |
|
98 | - * |
|
99 | - * @return bool |
|
100 | - */ |
|
101 | - public function isFrontend(); |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @return bool |
|
106 | - */ |
|
107 | - public function isFrontAjax(); |
|
108 | - |
|
109 | - /** |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function isGQL(); |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @return bool |
|
117 | - */ |
|
118 | - public function isIframe(); |
|
63 | + |
|
64 | + /** |
|
65 | + * true if the current request is from the command line |
|
66 | + * |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + public function isCli(); |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * true if the current request is for a WP_Cron |
|
74 | + * |
|
75 | + * @return bool |
|
76 | + */ |
|
77 | + public function isCron(); |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * true if the current request is for either the EE admin or EE frontend AND is being made via AJAX |
|
82 | + * |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function isEeAjax(); |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * true if the current request is for a feed (ie: RSS) |
|
90 | + * |
|
91 | + * @return bool |
|
92 | + */ |
|
93 | + public function isFeed(); |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * true if the current request is for the frontend and is not being made via AJAX |
|
98 | + * |
|
99 | + * @return bool |
|
100 | + */ |
|
101 | + public function isFrontend(); |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @return bool |
|
106 | + */ |
|
107 | + public function isFrontAjax(); |
|
108 | + |
|
109 | + /** |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function isGQL(); |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @return bool |
|
117 | + */ |
|
118 | + public function isIframe(); |
|
119 | 119 | |
120 | 120 | |
121 | - /** |
|
122 | - * true if the current request is being made via AJAX but is NOT for EE related logic |
|
123 | - * |
|
124 | - * @return bool |
|
125 | - */ |
|
126 | - public function isOtherAjax(); |
|
121 | + /** |
|
122 | + * true if the current request is being made via AJAX but is NOT for EE related logic |
|
123 | + * |
|
124 | + * @return bool |
|
125 | + */ |
|
126 | + public function isOtherAjax(); |
|
127 | 127 | |
128 | 128 | |
129 | - /** |
|
130 | - * true if the current request is occurring while unit testing |
|
131 | - * |
|
132 | - * @return bool |
|
133 | - */ |
|
134 | - public function isUnitTest(); |
|
129 | + /** |
|
130 | + * true if the current request is occurring while unit testing |
|
131 | + * |
|
132 | + * @return bool |
|
133 | + */ |
|
134 | + public function isUnitTest(); |
|
135 | 135 | |
136 | - /** |
|
137 | - * true if the current request is for the WP REST API |
|
138 | - * |
|
139 | - * @return bool |
|
140 | - */ |
|
141 | - public function isWordPressApi(); |
|
136 | + /** |
|
137 | + * true if the current request is for the WP REST API |
|
138 | + * |
|
139 | + * @return bool |
|
140 | + */ |
|
141 | + public function isWordPressApi(); |
|
142 | 142 | |
143 | 143 | |
144 | - /** |
|
145 | - * true if the current request is being made via AJAX for the WP Heartbeat |
|
146 | - * |
|
147 | - * @return bool |
|
148 | - */ |
|
149 | - public function isWordPressHeartbeat(); |
|
144 | + /** |
|
145 | + * true if the current request is being made via AJAX for the WP Heartbeat |
|
146 | + * |
|
147 | + * @return bool |
|
148 | + */ |
|
149 | + public function isWordPressHeartbeat(); |
|
150 | 150 | |
151 | 151 | |
152 | - /** |
|
153 | - * true if the current request is a loopback sent from WP core to test for errors |
|
154 | - * |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public function isWordPressScrape(); |
|
152 | + /** |
|
153 | + * true if the current request is a loopback sent from WP core to test for errors |
|
154 | + * |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public function isWordPressScrape(); |
|
158 | 158 | |
159 | 159 | |
160 | - /** |
|
161 | - * @return string |
|
162 | - */ |
|
163 | - public function slug(); |
|
160 | + /** |
|
161 | + * @return string |
|
162 | + */ |
|
163 | + public function slug(); |
|
164 | 164 | } |
@@ -17,134 +17,134 @@ |
||
17 | 17 | class RequestTypeContextFactory implements RequestTypeContextFactoryInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var LoaderInterface $loader |
|
22 | - */ |
|
23 | - private $loader; |
|
20 | + /** |
|
21 | + * @var LoaderInterface $loader |
|
22 | + */ |
|
23 | + private $loader; |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * RequestTypeContextFactory constructor. |
|
28 | - * |
|
29 | - * @param LoaderInterface $loader |
|
30 | - */ |
|
31 | - public function __construct(LoaderInterface $loader) |
|
32 | - { |
|
33 | - $this->loader = $loader; |
|
34 | - } |
|
26 | + /** |
|
27 | + * RequestTypeContextFactory constructor. |
|
28 | + * |
|
29 | + * @param LoaderInterface $loader |
|
30 | + */ |
|
31 | + public function __construct(LoaderInterface $loader) |
|
32 | + { |
|
33 | + $this->loader = $loader; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * @param string $slug |
|
39 | - * @return RequestTypeContext |
|
40 | - */ |
|
41 | - public function create($slug) |
|
42 | - { |
|
43 | - switch ($slug) { |
|
44 | - case RequestTypeContext::ACTIVATION: |
|
45 | - $description = esc_html__( |
|
46 | - 'The current request is for some form of activation', |
|
47 | - 'event_espresso' |
|
48 | - ); |
|
49 | - break; |
|
50 | - case RequestTypeContext::API: |
|
51 | - $description = esc_html__( |
|
52 | - 'The current request is for the EE REST API', |
|
53 | - 'event_espresso' |
|
54 | - ); |
|
55 | - break; |
|
56 | - case RequestTypeContext::AJAX_FRONT: |
|
57 | - $description = esc_html__( |
|
58 | - 'The current request is for the frontend via AJAX', |
|
59 | - 'event_espresso' |
|
60 | - ); |
|
61 | - break; |
|
62 | - case RequestTypeContext::AJAX_ADMIN: |
|
63 | - $description = esc_html__( |
|
64 | - 'The current request is for the admin via AJAX', |
|
65 | - 'event_espresso' |
|
66 | - ); |
|
67 | - break; |
|
68 | - case RequestTypeContext::AJAX_HEARTBEAT: |
|
69 | - $description = esc_html__( |
|
70 | - 'The current request is for the WP Heartbeat', |
|
71 | - 'event_espresso' |
|
72 | - ); |
|
73 | - break; |
|
74 | - case RequestTypeContext::AJAX_OTHER: |
|
75 | - $description = esc_html__( |
|
76 | - 'The current request is for non-EE related code via AJAX', |
|
77 | - 'event_espresso' |
|
78 | - ); |
|
79 | - break; |
|
80 | - case RequestTypeContext::CRON: |
|
81 | - $description = esc_html__( |
|
82 | - 'The current request is for a WP_Cron', |
|
83 | - 'event_espresso' |
|
84 | - ); |
|
85 | - break; |
|
86 | - case RequestTypeContext::CLI: |
|
87 | - $description = esc_html__( |
|
88 | - 'The current request is from the command line', |
|
89 | - 'event_espresso' |
|
90 | - ); |
|
91 | - break; |
|
92 | - case RequestTypeContext::ADMIN: |
|
93 | - $description = esc_html__( |
|
94 | - 'The current request is for the admin', |
|
95 | - 'event_espresso' |
|
96 | - ); |
|
97 | - break; |
|
98 | - case RequestTypeContext::IFRAME: |
|
99 | - $description = esc_html__( |
|
100 | - 'The current request is for an iframe', |
|
101 | - 'event_espresso' |
|
102 | - ); |
|
103 | - break; |
|
104 | - case RequestTypeContext::FEED: |
|
105 | - $description = esc_html__( |
|
106 | - 'The current request is for a feed (ie: RSS)', |
|
107 | - 'event_espresso' |
|
108 | - ); |
|
109 | - break; |
|
110 | - case RequestTypeContext::GQL: |
|
111 | - $description = esc_html__( |
|
112 | - 'The current request is for the EE GraphQL Manager', |
|
113 | - 'event_espresso' |
|
114 | - ); |
|
115 | - break; |
|
116 | - case RequestTypeContext::UNIT_TEST: |
|
117 | - $description = esc_html__( |
|
118 | - 'The current request is occurring while unit testing', |
|
119 | - 'event_espresso' |
|
120 | - ); |
|
121 | - break; |
|
122 | - case RequestTypeContext::WP_API: |
|
123 | - $description = esc_html__( |
|
124 | - 'The current request is for the WordPress REST API', |
|
125 | - 'event_espresso' |
|
126 | - ); |
|
127 | - break; |
|
128 | - case RequestTypeContext::WP_SCRAPE: |
|
129 | - $description = esc_html__( |
|
130 | - 'The current request is for a WordPress loopback scrape', |
|
131 | - 'event_espresso' |
|
132 | - ); |
|
133 | - break; |
|
134 | - case RequestTypeContext::FRONTEND: |
|
135 | - default: |
|
136 | - $description = esc_html__( |
|
137 | - 'The current request is for the frontend', |
|
138 | - 'event_espresso' |
|
139 | - ); |
|
140 | - break; |
|
141 | - } |
|
142 | - // we're using the Loader with sharing turned on, |
|
143 | - // so that the generated RequestTypeContext object is accessible anywhere |
|
144 | - // by simply requesting it again from the loader |
|
145 | - return $this->loader->getShared( |
|
146 | - 'EventEspresso\core\domain\entities\contexts\RequestTypeContext', |
|
147 | - array($slug, $description) |
|
148 | - ); |
|
149 | - } |
|
37 | + /** |
|
38 | + * @param string $slug |
|
39 | + * @return RequestTypeContext |
|
40 | + */ |
|
41 | + public function create($slug) |
|
42 | + { |
|
43 | + switch ($slug) { |
|
44 | + case RequestTypeContext::ACTIVATION: |
|
45 | + $description = esc_html__( |
|
46 | + 'The current request is for some form of activation', |
|
47 | + 'event_espresso' |
|
48 | + ); |
|
49 | + break; |
|
50 | + case RequestTypeContext::API: |
|
51 | + $description = esc_html__( |
|
52 | + 'The current request is for the EE REST API', |
|
53 | + 'event_espresso' |
|
54 | + ); |
|
55 | + break; |
|
56 | + case RequestTypeContext::AJAX_FRONT: |
|
57 | + $description = esc_html__( |
|
58 | + 'The current request is for the frontend via AJAX', |
|
59 | + 'event_espresso' |
|
60 | + ); |
|
61 | + break; |
|
62 | + case RequestTypeContext::AJAX_ADMIN: |
|
63 | + $description = esc_html__( |
|
64 | + 'The current request is for the admin via AJAX', |
|
65 | + 'event_espresso' |
|
66 | + ); |
|
67 | + break; |
|
68 | + case RequestTypeContext::AJAX_HEARTBEAT: |
|
69 | + $description = esc_html__( |
|
70 | + 'The current request is for the WP Heartbeat', |
|
71 | + 'event_espresso' |
|
72 | + ); |
|
73 | + break; |
|
74 | + case RequestTypeContext::AJAX_OTHER: |
|
75 | + $description = esc_html__( |
|
76 | + 'The current request is for non-EE related code via AJAX', |
|
77 | + 'event_espresso' |
|
78 | + ); |
|
79 | + break; |
|
80 | + case RequestTypeContext::CRON: |
|
81 | + $description = esc_html__( |
|
82 | + 'The current request is for a WP_Cron', |
|
83 | + 'event_espresso' |
|
84 | + ); |
|
85 | + break; |
|
86 | + case RequestTypeContext::CLI: |
|
87 | + $description = esc_html__( |
|
88 | + 'The current request is from the command line', |
|
89 | + 'event_espresso' |
|
90 | + ); |
|
91 | + break; |
|
92 | + case RequestTypeContext::ADMIN: |
|
93 | + $description = esc_html__( |
|
94 | + 'The current request is for the admin', |
|
95 | + 'event_espresso' |
|
96 | + ); |
|
97 | + break; |
|
98 | + case RequestTypeContext::IFRAME: |
|
99 | + $description = esc_html__( |
|
100 | + 'The current request is for an iframe', |
|
101 | + 'event_espresso' |
|
102 | + ); |
|
103 | + break; |
|
104 | + case RequestTypeContext::FEED: |
|
105 | + $description = esc_html__( |
|
106 | + 'The current request is for a feed (ie: RSS)', |
|
107 | + 'event_espresso' |
|
108 | + ); |
|
109 | + break; |
|
110 | + case RequestTypeContext::GQL: |
|
111 | + $description = esc_html__( |
|
112 | + 'The current request is for the EE GraphQL Manager', |
|
113 | + 'event_espresso' |
|
114 | + ); |
|
115 | + break; |
|
116 | + case RequestTypeContext::UNIT_TEST: |
|
117 | + $description = esc_html__( |
|
118 | + 'The current request is occurring while unit testing', |
|
119 | + 'event_espresso' |
|
120 | + ); |
|
121 | + break; |
|
122 | + case RequestTypeContext::WP_API: |
|
123 | + $description = esc_html__( |
|
124 | + 'The current request is for the WordPress REST API', |
|
125 | + 'event_espresso' |
|
126 | + ); |
|
127 | + break; |
|
128 | + case RequestTypeContext::WP_SCRAPE: |
|
129 | + $description = esc_html__( |
|
130 | + 'The current request is for a WordPress loopback scrape', |
|
131 | + 'event_espresso' |
|
132 | + ); |
|
133 | + break; |
|
134 | + case RequestTypeContext::FRONTEND: |
|
135 | + default: |
|
136 | + $description = esc_html__( |
|
137 | + 'The current request is for the frontend', |
|
138 | + 'event_espresso' |
|
139 | + ); |
|
140 | + break; |
|
141 | + } |
|
142 | + // we're using the Loader with sharing turned on, |
|
143 | + // so that the generated RequestTypeContext object is accessible anywhere |
|
144 | + // by simply requesting it again from the loader |
|
145 | + return $this->loader->getShared( |
|
146 | + 'EventEspresso\core\domain\entities\contexts\RequestTypeContext', |
|
147 | + array($slug, $description) |
|
148 | + ); |
|
149 | + } |
|
150 | 150 | } |
@@ -18,55 +18,55 @@ |
||
18 | 18 | */ |
19 | 19 | class EspressoEditorAssetManager extends ReactAssetManager |
20 | 20 | { |
21 | - const JS_HANDLE_EDITOR = 'eventespresso-editor'; |
|
22 | - const CSS_HANDLE_EDITOR = 'eventespresso-editor'; |
|
21 | + const JS_HANDLE_EDITOR = 'eventespresso-editor'; |
|
22 | + const CSS_HANDLE_EDITOR = 'eventespresso-editor'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @throws InvalidDataTypeException |
|
26 | - * @throws InvalidEntityException |
|
27 | - * @throws DuplicateCollectionIdentifierException |
|
28 | - * @throws DomainException |
|
29 | - */ |
|
30 | - public function addAssets() |
|
31 | - { |
|
32 | - parent::addAssets(); |
|
33 | - $this->registerJavascript(); |
|
34 | - $this->registerStyleSheets(); |
|
35 | - } |
|
24 | + /** |
|
25 | + * @throws InvalidDataTypeException |
|
26 | + * @throws InvalidEntityException |
|
27 | + * @throws DuplicateCollectionIdentifierException |
|
28 | + * @throws DomainException |
|
29 | + */ |
|
30 | + public function addAssets() |
|
31 | + { |
|
32 | + parent::addAssets(); |
|
33 | + $this->registerJavascript(); |
|
34 | + $this->registerStyleSheets(); |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * Register javascript assets |
|
40 | - * |
|
41 | - * @throws InvalidDataTypeException |
|
42 | - * @throws InvalidEntityException |
|
43 | - * @throws DuplicateCollectionIdentifierException |
|
44 | - * @throws DomainException |
|
45 | - */ |
|
46 | - private function registerJavascript() |
|
47 | - { |
|
48 | - $this->addJs( |
|
49 | - EspressoEditorAssetManager::JS_HANDLE_EDITOR, |
|
50 | - [ |
|
51 | - ReactAssetManager::JS_HANDLE_REACT, |
|
52 | - ReactAssetManager::JS_HANDLE_REACT_DOM, |
|
53 | - CoreAssetManager::JS_HANDLE_JS_CORE, |
|
54 | - 'wp-i18n', |
|
55 | - ] |
|
56 | - )->setRequiresTranslation(); |
|
57 | - } |
|
38 | + /** |
|
39 | + * Register javascript assets |
|
40 | + * |
|
41 | + * @throws InvalidDataTypeException |
|
42 | + * @throws InvalidEntityException |
|
43 | + * @throws DuplicateCollectionIdentifierException |
|
44 | + * @throws DomainException |
|
45 | + */ |
|
46 | + private function registerJavascript() |
|
47 | + { |
|
48 | + $this->addJs( |
|
49 | + EspressoEditorAssetManager::JS_HANDLE_EDITOR, |
|
50 | + [ |
|
51 | + ReactAssetManager::JS_HANDLE_REACT, |
|
52 | + ReactAssetManager::JS_HANDLE_REACT_DOM, |
|
53 | + CoreAssetManager::JS_HANDLE_JS_CORE, |
|
54 | + 'wp-i18n', |
|
55 | + ] |
|
56 | + )->setRequiresTranslation(); |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * Register CSS assets. |
|
62 | - * |
|
63 | - * @throws DuplicateCollectionIdentifierException |
|
64 | - * @throws InvalidDataTypeException |
|
65 | - * @throws InvalidEntityException |
|
66 | - * @throws DomainException |
|
67 | - */ |
|
68 | - private function registerStyleSheets() |
|
69 | - { |
|
70 | - $this->addCss(EspressoEditorAssetManager::CSS_HANDLE_EDITOR); |
|
71 | - } |
|
60 | + /** |
|
61 | + * Register CSS assets. |
|
62 | + * |
|
63 | + * @throws DuplicateCollectionIdentifierException |
|
64 | + * @throws InvalidDataTypeException |
|
65 | + * @throws InvalidEntityException |
|
66 | + * @throws DomainException |
|
67 | + */ |
|
68 | + private function registerStyleSheets() |
|
69 | + { |
|
70 | + $this->addCss(EspressoEditorAssetManager::CSS_HANDLE_EDITOR); |
|
71 | + } |
|
72 | 72 | } |
@@ -22,91 +22,91 @@ |
||
22 | 22 | class WordpressPluginsPageAssetManager extends ReactAssetManager |
23 | 23 | { |
24 | 24 | |
25 | - const JS_HANDLE_WP_PLUGINS_PAGE = 'eventespresso-wp-plugins-page'; |
|
25 | + const JS_HANDLE_WP_PLUGINS_PAGE = 'eventespresso-wp-plugins-page'; |
|
26 | 26 | |
27 | - const CSS_HANDLE_WP_PLUGINS_PAGE = 'eventespresso-wp-plugins-page'; |
|
27 | + const CSS_HANDLE_WP_PLUGINS_PAGE = 'eventespresso-wp-plugins-page'; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var ExitModal $exit_modal |
|
31 | - */ |
|
32 | - private $exit_modal; |
|
29 | + /** |
|
30 | + * @var ExitModal $exit_modal |
|
31 | + */ |
|
32 | + private $exit_modal; |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * WordpressPluginsPageAssetManager constructor. |
|
37 | - * |
|
38 | - * @param AssetCollection $assets |
|
39 | - * @param DomainInterface $domain |
|
40 | - * @param Registry $registry |
|
41 | - * @param ExitModal $exit_modal |
|
42 | - */ |
|
43 | - public function __construct( |
|
44 | - AssetCollection $assets, |
|
45 | - DomainInterface $domain, |
|
46 | - Registry $registry, |
|
47 | - ExitModal $exit_modal |
|
48 | - ) { |
|
49 | - $this->exit_modal = $exit_modal; |
|
50 | - parent::__construct($domain, $assets, $registry); |
|
51 | - } |
|
35 | + /** |
|
36 | + * WordpressPluginsPageAssetManager constructor. |
|
37 | + * |
|
38 | + * @param AssetCollection $assets |
|
39 | + * @param DomainInterface $domain |
|
40 | + * @param Registry $registry |
|
41 | + * @param ExitModal $exit_modal |
|
42 | + */ |
|
43 | + public function __construct( |
|
44 | + AssetCollection $assets, |
|
45 | + DomainInterface $domain, |
|
46 | + Registry $registry, |
|
47 | + ExitModal $exit_modal |
|
48 | + ) { |
|
49 | + $this->exit_modal = $exit_modal; |
|
50 | + parent::__construct($domain, $assets, $registry); |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * @inheritDoc |
|
56 | - */ |
|
57 | - public function addAssets() |
|
58 | - { |
|
59 | - parent::addAssets(); |
|
60 | - $this->registerJavascript(); |
|
61 | - $this->registerStyleSheets(); |
|
62 | - } |
|
54 | + /** |
|
55 | + * @inheritDoc |
|
56 | + */ |
|
57 | + public function addAssets() |
|
58 | + { |
|
59 | + parent::addAssets(); |
|
60 | + $this->registerJavascript(); |
|
61 | + $this->registerStyleSheets(); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * Register javascript assets |
|
67 | - * |
|
68 | - * @throws InvalidDataTypeException |
|
69 | - * @throws InvalidEntityException |
|
70 | - * @throws DuplicateCollectionIdentifierException |
|
71 | - * @throws DomainException |
|
72 | - */ |
|
73 | - private function registerJavascript() |
|
74 | - { |
|
75 | - $this->addJs( |
|
76 | - WordpressPluginsPageAssetManager::JS_HANDLE_WP_PLUGINS_PAGE, |
|
77 | - [ |
|
78 | - ReactAssetManager::JS_HANDLE_REACT, |
|
79 | - ReactAssetManager::JS_HANDLE_REACT_DOM, |
|
80 | - CoreAssetManager::JS_HANDLE_JS_CORE, |
|
81 | - 'wp-components', |
|
82 | - 'wp-i18n', |
|
83 | - 'wp-url' |
|
84 | - ] |
|
85 | - ) |
|
86 | - ->setRequiresTranslation() |
|
87 | - ->enqueueAsset(); |
|
65 | + /** |
|
66 | + * Register javascript assets |
|
67 | + * |
|
68 | + * @throws InvalidDataTypeException |
|
69 | + * @throws InvalidEntityException |
|
70 | + * @throws DuplicateCollectionIdentifierException |
|
71 | + * @throws DomainException |
|
72 | + */ |
|
73 | + private function registerJavascript() |
|
74 | + { |
|
75 | + $this->addJs( |
|
76 | + WordpressPluginsPageAssetManager::JS_HANDLE_WP_PLUGINS_PAGE, |
|
77 | + [ |
|
78 | + ReactAssetManager::JS_HANDLE_REACT, |
|
79 | + ReactAssetManager::JS_HANDLE_REACT_DOM, |
|
80 | + CoreAssetManager::JS_HANDLE_JS_CORE, |
|
81 | + 'wp-components', |
|
82 | + 'wp-i18n', |
|
83 | + 'wp-url' |
|
84 | + ] |
|
85 | + ) |
|
86 | + ->setRequiresTranslation() |
|
87 | + ->enqueueAsset(); |
|
88 | 88 | |
89 | - $this->registry->addData( |
|
90 | - 'exitModalInfo', |
|
91 | - $this->exit_modal->getExitSurveyInfo() |
|
92 | - ); |
|
93 | - } |
|
89 | + $this->registry->addData( |
|
90 | + 'exitModalInfo', |
|
91 | + $this->exit_modal->getExitSurveyInfo() |
|
92 | + ); |
|
93 | + } |
|
94 | 94 | |
95 | 95 | |
96 | - /** |
|
97 | - * Register CSS assets. |
|
98 | - * |
|
99 | - * @throws DuplicateCollectionIdentifierException |
|
100 | - * @throws InvalidDataTypeException |
|
101 | - * @throws InvalidEntityException |
|
102 | - * @throws DomainException |
|
103 | - */ |
|
104 | - private function registerStyleSheets() |
|
105 | - { |
|
106 | - $this->addCss( |
|
107 | - WordpressPluginsPageAssetManager::CSS_HANDLE_WP_PLUGINS_PAGE, |
|
108 | - ['wp-components'] |
|
109 | - ) |
|
110 | - ->enqueueAsset(); |
|
111 | - } |
|
96 | + /** |
|
97 | + * Register CSS assets. |
|
98 | + * |
|
99 | + * @throws DuplicateCollectionIdentifierException |
|
100 | + * @throws InvalidDataTypeException |
|
101 | + * @throws InvalidEntityException |
|
102 | + * @throws DomainException |
|
103 | + */ |
|
104 | + private function registerStyleSheets() |
|
105 | + { |
|
106 | + $this->addCss( |
|
107 | + WordpressPluginsPageAssetManager::CSS_HANDLE_WP_PLUGINS_PAGE, |
|
108 | + ['wp-components'] |
|
109 | + ) |
|
110 | + ->enqueueAsset(); |
|
111 | + } |
|
112 | 112 | } |
@@ -15,104 +15,104 @@ |
||
15 | 15 | class EspressoAdminAssetManager extends AssetManager |
16 | 16 | { |
17 | 17 | |
18 | - const JS_HANDLE_INJECT_WP = 'ee-inject-wp'; |
|
18 | + const JS_HANDLE_INJECT_WP = 'ee-inject-wp'; |
|
19 | 19 | |
20 | - const JS_HANDLE_JQUERY_COOKIE = 'jquery-cookie'; |
|
20 | + const JS_HANDLE_JQUERY_COOKIE = 'jquery-cookie'; |
|
21 | 21 | |
22 | - const JS_HANDLE_JOYRIDE_MODERNIZR = 'joyride-modernizr'; |
|
22 | + const JS_HANDLE_JOYRIDE_MODERNIZR = 'joyride-modernizr'; |
|
23 | 23 | |
24 | - const JS_HANDLE_JQUERY_JOYRIDE = 'jquery-joyride'; |
|
24 | + const JS_HANDLE_JQUERY_JOYRIDE = 'jquery-joyride'; |
|
25 | 25 | |
26 | - const CSS_HANDLE_EE_JOYRIDE = 'ee-joyride-css'; |
|
26 | + const CSS_HANDLE_EE_JOYRIDE = 'ee-joyride-css'; |
|
27 | 27 | |
28 | - const CSS_HANDLE_JOYRIDE = 'joyride-css'; |
|
28 | + const CSS_HANDLE_JOYRIDE = 'joyride-css'; |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * @inheritDoc |
|
33 | - */ |
|
34 | - public function addAssets() |
|
35 | - { |
|
36 | - $joyride = filter_var(apply_filters('FHEE_load_joyride', false), FILTER_VALIDATE_BOOLEAN); |
|
37 | - $this->registerJavascript($joyride); |
|
38 | - $this->registerStyleSheets($joyride); |
|
39 | - } |
|
31 | + /** |
|
32 | + * @inheritDoc |
|
33 | + */ |
|
34 | + public function addAssets() |
|
35 | + { |
|
36 | + $joyride = filter_var(apply_filters('FHEE_load_joyride', false), FILTER_VALIDATE_BOOLEAN); |
|
37 | + $this->registerJavascript($joyride); |
|
38 | + $this->registerStyleSheets($joyride); |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * Register javascript assets |
|
44 | - * |
|
45 | - * @param bool $joyride |
|
46 | - */ |
|
47 | - private function registerJavascript($joyride = false) |
|
48 | - { |
|
49 | - // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
50 | - // Note: the intention of this script is to only do TARGETED injections. |
|
51 | - //ie: only injecting on certain script calls. |
|
52 | - $this->addJavascript( |
|
53 | - EspressoAdminAssetManager::JS_HANDLE_INJECT_WP, |
|
54 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
55 | - ['jquery'], |
|
56 | - true, |
|
57 | - EVENT_ESPRESSO_VERSION |
|
58 | - ); |
|
59 | - // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, |
|
60 | - // can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
61 | - if (! $joyride) { |
|
62 | - return; |
|
63 | - } |
|
64 | - // register cookie script for future dependencies |
|
65 | - $this->addJavascript( |
|
66 | - EspressoAdminAssetManager::JS_HANDLE_JQUERY_COOKIE, |
|
67 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
68 | - ['jquery'], |
|
69 | - true, |
|
70 | - '2.1' |
|
71 | - ); |
|
72 | - $this->addJavascript( |
|
73 | - EspressoAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
|
74 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
75 | - [], |
|
76 | - true, |
|
77 | - '2.1' |
|
78 | - ); |
|
79 | - // wanna go for a joyride? |
|
80 | - $this->addJavascript( |
|
81 | - EspressoAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
|
82 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
83 | - [ |
|
84 | - EspressoAdminAssetManager::JS_HANDLE_JQUERY_COOKIE, |
|
85 | - EspressoAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR |
|
86 | - ], |
|
87 | - '2.1', |
|
88 | - true |
|
89 | - )->enqueueAsset(); |
|
90 | - } |
|
42 | + /** |
|
43 | + * Register javascript assets |
|
44 | + * |
|
45 | + * @param bool $joyride |
|
46 | + */ |
|
47 | + private function registerJavascript($joyride = false) |
|
48 | + { |
|
49 | + // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
50 | + // Note: the intention of this script is to only do TARGETED injections. |
|
51 | + //ie: only injecting on certain script calls. |
|
52 | + $this->addJavascript( |
|
53 | + EspressoAdminAssetManager::JS_HANDLE_INJECT_WP, |
|
54 | + EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
55 | + ['jquery'], |
|
56 | + true, |
|
57 | + EVENT_ESPRESSO_VERSION |
|
58 | + ); |
|
59 | + // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, |
|
60 | + // can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
61 | + if (! $joyride) { |
|
62 | + return; |
|
63 | + } |
|
64 | + // register cookie script for future dependencies |
|
65 | + $this->addJavascript( |
|
66 | + EspressoAdminAssetManager::JS_HANDLE_JQUERY_COOKIE, |
|
67 | + EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
68 | + ['jquery'], |
|
69 | + true, |
|
70 | + '2.1' |
|
71 | + ); |
|
72 | + $this->addJavascript( |
|
73 | + EspressoAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
|
74 | + EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
75 | + [], |
|
76 | + true, |
|
77 | + '2.1' |
|
78 | + ); |
|
79 | + // wanna go for a joyride? |
|
80 | + $this->addJavascript( |
|
81 | + EspressoAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
|
82 | + EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
83 | + [ |
|
84 | + EspressoAdminAssetManager::JS_HANDLE_JQUERY_COOKIE, |
|
85 | + EspressoAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR |
|
86 | + ], |
|
87 | + '2.1', |
|
88 | + true |
|
89 | + )->enqueueAsset(); |
|
90 | + } |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * Register CSS assets. |
|
95 | - * |
|
96 | - * @param bool $joyride |
|
97 | - */ |
|
98 | - private function registerStyleSheets($joyride = false) |
|
99 | - { |
|
100 | - if (! $joyride) { |
|
101 | - return; |
|
102 | - } // joyride style |
|
103 | - $this->addStylesheet( |
|
104 | - EspressoAdminAssetManager::CSS_HANDLE_JOYRIDE, |
|
105 | - EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', |
|
106 | - [], |
|
107 | - 'all', |
|
108 | - '2.1' |
|
109 | - ); |
|
110 | - $this->addStylesheet( |
|
111 | - EspressoAdminAssetManager::CSS_HANDLE_EE_JOYRIDE, |
|
112 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
113 | - ['joyride-css'], |
|
114 | - 'all', |
|
115 | - EVENT_ESPRESSO_VERSION |
|
116 | - )->enqueueAsset(); |
|
117 | - } |
|
93 | + /** |
|
94 | + * Register CSS assets. |
|
95 | + * |
|
96 | + * @param bool $joyride |
|
97 | + */ |
|
98 | + private function registerStyleSheets($joyride = false) |
|
99 | + { |
|
100 | + if (! $joyride) { |
|
101 | + return; |
|
102 | + } // joyride style |
|
103 | + $this->addStylesheet( |
|
104 | + EspressoAdminAssetManager::CSS_HANDLE_JOYRIDE, |
|
105 | + EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', |
|
106 | + [], |
|
107 | + 'all', |
|
108 | + '2.1' |
|
109 | + ); |
|
110 | + $this->addStylesheet( |
|
111 | + EspressoAdminAssetManager::CSS_HANDLE_EE_JOYRIDE, |
|
112 | + EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
113 | + ['joyride-css'], |
|
114 | + 'all', |
|
115 | + EVENT_ESPRESSO_VERSION |
|
116 | + )->enqueueAsset(); |
|
117 | + } |
|
118 | 118 | } |
@@ -51,27 +51,27 @@ discard block |
||
51 | 51 | //ie: only injecting on certain script calls. |
52 | 52 | $this->addJavascript( |
53 | 53 | EspressoAdminAssetManager::JS_HANDLE_INJECT_WP, |
54 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
54 | + EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', |
|
55 | 55 | ['jquery'], |
56 | 56 | true, |
57 | 57 | EVENT_ESPRESSO_VERSION |
58 | 58 | ); |
59 | 59 | // joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, |
60 | 60 | // can be turned back on again via: add_filter('FHEE_load_joyride', '__return_true' ); |
61 | - if (! $joyride) { |
|
61 | + if ( ! $joyride) { |
|
62 | 62 | return; |
63 | 63 | } |
64 | 64 | // register cookie script for future dependencies |
65 | 65 | $this->addJavascript( |
66 | 66 | EspressoAdminAssetManager::JS_HANDLE_JQUERY_COOKIE, |
67 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
67 | + EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', |
|
68 | 68 | ['jquery'], |
69 | 69 | true, |
70 | 70 | '2.1' |
71 | 71 | ); |
72 | 72 | $this->addJavascript( |
73 | 73 | EspressoAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR, |
74 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
74 | + EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', |
|
75 | 75 | [], |
76 | 76 | true, |
77 | 77 | '2.1' |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | // wanna go for a joyride? |
80 | 80 | $this->addJavascript( |
81 | 81 | EspressoAdminAssetManager::JS_HANDLE_JQUERY_JOYRIDE, |
82 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
82 | + EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', |
|
83 | 83 | [ |
84 | 84 | EspressoAdminAssetManager::JS_HANDLE_JQUERY_COOKIE, |
85 | 85 | EspressoAdminAssetManager::JS_HANDLE_JOYRIDE_MODERNIZR |
@@ -97,19 +97,19 @@ discard block |
||
97 | 97 | */ |
98 | 98 | private function registerStyleSheets($joyride = false) |
99 | 99 | { |
100 | - if (! $joyride) { |
|
100 | + if ( ! $joyride) { |
|
101 | 101 | return; |
102 | 102 | } // joyride style |
103 | 103 | $this->addStylesheet( |
104 | 104 | EspressoAdminAssetManager::CSS_HANDLE_JOYRIDE, |
105 | - EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', |
|
105 | + EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', |
|
106 | 106 | [], |
107 | 107 | 'all', |
108 | 108 | '2.1' |
109 | 109 | ); |
110 | 110 | $this->addStylesheet( |
111 | 111 | EspressoAdminAssetManager::CSS_HANDLE_EE_JOYRIDE, |
112 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
112 | + EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', |
|
113 | 113 | ['joyride-css'], |
114 | 114 | 'all', |
115 | 115 | EVENT_ESPRESSO_VERSION |