Completed
Branch master (d65695)
by
unknown
04:25
created
core/admin/EE_Admin_Page_Loader.core.php 1 patch
Indentation   +433 added lines, -433 removed lines patch added patch discarded remove patch
@@ -16,437 +16,437 @@
 block discarded – undo
16 16
  */
17 17
 class EE_Admin_Page_Loader
18 18
 {
19
-    /**
20
-     * @var AdminMenuManager $menu_manager
21
-     */
22
-    protected $menu_manager;
23
-
24
-    /**
25
-     * @var LoaderInterface $loader
26
-     */
27
-    protected $loader;
28
-
29
-    /**
30
-     * _installed_pages
31
-     * objects for page_init objects detected and loaded
32
-     *
33
-     * @access private
34
-     * @var EE_Admin_Page_Init[]
35
-     */
36
-    private $_installed_pages = [];
37
-
38
-
39
-    /**
40
-     * this is used to hold the registry of menu slugs for all the installed admin pages
41
-     *
42
-     * @var array
43
-     */
44
-    private $_menu_slugs = [];
45
-
46
-
47
-    /**
48
-     * _caffeinated_extends
49
-     * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and
50
-     * pieces needed to do so).  This property is defined in the _set_caffeinated method.
51
-     *
52
-     * @var array
53
-     */
54
-    private $_caffeinated_extends = [];
55
-
56
-
57
-    /**
58
-     * This property will hold the hook file for setting up the filter that does all the connections between admin
59
-     * pages.
60
-     *
61
-     * @var string
62
-     */
63
-    public $hook_file;
64
-
65
-    /**
66
-     * @var   int
67
-     * @since 5.0.0.p
68
-     */
69
-    private $maintenance_mode = 0;
70
-
71
-
72
-    /**
73
-     * @throws InvalidArgumentException
74
-     * @throws InvalidDataTypeException
75
-     * @throws InvalidInterfaceException
76
-     */
77
-    public function __construct(?LoaderInterface $loader)
78
-    {
79
-        $this->loader = $loader instanceof LoaderInterface ? $loader : LoaderFactory::getLoader();
80
-        $this->menu_manager = $this->loader->getShared(AdminMenuManager::class, [$this->loader]);
81
-    }
82
-
83
-
84
-    /**
85
-     * @throws EE_Error
86
-     * @throws ReflectionException
87
-     * @since 5.0.0.p
88
-     */
89
-    public function init()
90
-    {
91
-        $this->menu_manager->initialize();
92
-        $this->maintenance_mode = EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance;
93
-        // let's do a scan and see what installed pages we have
94
-        $this->findAndLoadAdminPages();
95
-    }
96
-
97
-
98
-    /**
99
-     * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by
100
-     * files in the caffeinated folder.
101
-     *
102
-     * @access private
103
-     * @return void
104
-     */
105
-    private function defineCaffeinatedConstants()
106
-    {
107
-        if (! defined('EE_CORE_CAF_ADMIN')) {
108
-            define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
109
-            define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
110
-            define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
111
-            define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
112
-            define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
113
-            define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
114
-        }
115
-    }
116
-
117
-
118
-    /**
119
-     * This just gets the list of installed EE_Admin_pages.
120
-     *
121
-     * @access private
122
-     * @return void
123
-     * @throws EE_Error
124
-     * @throws InvalidArgumentException
125
-     * @throws InvalidDataTypeException
126
-     * @throws InvalidInterfaceException
127
-     * @throws ReflectionException
128
-     */
129
-    private function findAndLoadAdminPages()
130
-    {
131
-        $admin_pages = $this->findAdminPages();
132
-        // this just checks the caffeinated folder and takes care of setting up any caffeinated stuff.
133
-        $admin_pages = $this->findCaffeinatedAdminPages($admin_pages);
134
-        // then extensions and hooks, although they don't get added to the admin pages array
135
-        $this->findAdminPageExtensions();
136
-        $this->findAdminPageHooks();
137
-        // 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.;
138
-        // loop through admin pages and setup the $_installed_pages array.
139
-        $hooks_ref = [];
140
-        $menu_pages = [];
141
-        foreach ($admin_pages as $page => $path) {
142
-            // don't load the page init class IF IT's ALREADY LOADED !!!
143
-            if (
144
-                isset($this->_installed_pages[ $page ])
145
-                && $this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init
146
-            ) {
147
-                continue;
148
-            }
149
-            // build list of installed pages
150
-            $admin_page_init = $this->loadAdminPageInit($page);
151
-            $this->_installed_pages[ $page ] = $admin_page_init;
152
-            $admin_menu = $this->menu_manager->getAdminMenu($admin_page_init);
153
-            $admin_page_init->setCapability($admin_menu->capability(), $admin_menu->menuSlug());
154
-            // skip if in full maintenance mode and maintenance_mode_parent is NOT set
155
-            if ($this->maintenance_mode && ! $admin_menu->maintenanceModeParent()) {
156
-                unset($admin_pages[ $page ]);
157
-                continue;
158
-            }
159
-            $menu_slug = $admin_menu->menuSlug();
160
-            $this->_menu_slugs[ $menu_slug ] = $page;
161
-            $menu_pages[ $menu_slug ] = $admin_page_init;
162
-            // now that we've got the admin_init objects...
163
-            // lets see if there are any caffeinated pages extending the originals.
164
-            // If there are then let's hook into the init admin filter and load our extend instead.
165
-            // Set flag for register hooks on extended pages b/c extended pages use the default INIT.
166
-            $extended_hooks = $admin_page_init->register_hooks(
167
-                $this->loadCaffeinatedExtensions($admin_page_init, $page, $menu_slug)
168
-            );
169
-            $hooks_ref      += $extended_hooks;
170
-        }
171
-        // the hooks_ref is all the pages where we have $extended _Hooks files
172
-        // that will extend a class in a different folder.
173
-        // So we want to make sure we load the file for the parent.
174
-        // first make sure we've got unique values
175
-        $hooks_ref = array_unique($hooks_ref);
176
-        // now let's loop and require!
177
-        foreach ($hooks_ref as $path) {
178
-            require_once($path);
179
-        }
180
-        // 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.
181
-        global $ee_menu_slugs;
182
-        $ee_menu_slugs = $this->_menu_slugs;
183
-        // we need to loop again to run any early code
184
-        foreach ($this->_installed_pages as $page) {
185
-            $page->do_initial_loads();
186
-        }
187
-        $this->menu_manager->setInstalledPages($menu_pages);
188
-        do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
189
-    }
190
-
191
-
192
-    /**
193
-     * @return array
194
-     * @throws EE_Error
195
-     * @since   5.0.0.p
196
-     */
197
-    private function findAdminPages(): array
198
-    {
199
-
200
-        // grab everything in the  admin core directory
201
-        $admin_page_folders = $this->findAdminPageFolders(EE_ADMIN_PAGES . '*');
202
-        $admin_page_folders = apply_filters(
203
-            'FHEE__EE_Admin_Page_Loader__findAdminPages__admin_page_folders',
204
-            $admin_page_folders
205
-        );
206
-        if (! empty($admin_page_folders)) {
207
-            return $admin_page_folders;
208
-        }
209
-        $error_msg = esc_html__(
210
-            'There are no EE_Admin pages detected, it looks like EE did not install properly',
211
-            'event_espresso'
212
-        );
213
-        $error_msg .= '||';
214
-        $error_msg .= sprintf(
215
-            esc_html__(
216
-                'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
217
-                'event_espresso'
218
-            ),
219
-            EE_ADMIN_PAGES
220
-        );
221
-        throw new RuntimeException($error_msg);
222
-    }
223
-
224
-
225
-    /**
226
-     * get_admin_page_object
227
-     *
228
-     * @param string $page_slug
229
-     * @return EE_Admin_Page
230
-     */
231
-    public function get_admin_page_object(string $page_slug = ''): ?EE_Admin_Page
232
-    {
233
-        return isset($this->_installed_pages[ $page_slug ])
234
-               && $this->_installed_pages[ $page_slug ] instanceof EE_Admin_Page_Init
235
-            ? $this->_installed_pages[ $page_slug ]->loaded_page_object()
236
-            : null;
237
-    }
238
-
239
-
240
-    /**
241
-     * generates an "Admin Page Init" class based on the directory  name
242
-     *
243
-     * @param string $dir_name
244
-     * @return string
245
-     */
246
-    private function getClassnameForAdminPageInit(string $dir_name = ''): string
247
-    {
248
-        $class_name = str_replace('_', ' ', strtolower($dir_name));
249
-        return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
250
-    }
251
-
252
-
253
-    /**
254
-     * _load_admin_page
255
-     * Loads and instantiates page_init object for a single EE_admin page.
256
-     *
257
-     * @param string $page page_reference
258
-     * @return EE_Admin_Page_Init
259
-     * @throws EE_Error
260
-     */
261
-    private function loadAdminPageInit(string $page = ''): EE_Admin_Page_Init
262
-    {
263
-        $class_name = $this->getClassnameForAdminPageInit($page);
264
-        if (class_exists($class_name)) {
265
-            $admin_page_init = $this->loader->getShared($class_name);
266
-            // verify returned object
267
-            if ($admin_page_init instanceof EE_Admin_Page_Init) {
268
-                return $admin_page_init;
269
-            }
270
-        }
271
-        $error_msg = sprintf(
272
-            esc_html__('Something went wrong with loading the %s admin page.', 'event_espresso'),
273
-            $page
274
-        );
275
-        $error_msg .= '||'; // separates public from developer messages
276
-        $error_msg .= "\r\n";
277
-        $error_msg .= sprintf(
278
-            esc_html__('There is no Init class in place for the %s admin page.', 'event_espresso'),
279
-            $page
280
-        );
281
-        $error_msg .= '<br />';
282
-        $error_msg .= sprintf(
283
-            esc_html__(
284
-                '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',
285
-                'event_espresso'
286
-            ),
287
-            '<strong>' . $class_name . '</strong>'
288
-        );
289
-        throw new EE_Error($error_msg);
290
-    }
291
-
292
-
293
-    /**
294
-     * This method is the "workhorse" for detecting and setting up caffeinated functionality.
295
-     * In this method there are three checks being done:
296
-     * 1. Do we have any NEW admin page sets.  If we do, lets add them into the menu setup (via the $admin_pages
297
-     * array) etc.  (new page sets are found in caffeinated/new/{page})
298
-     * 2. Do we have any EXTENDED page sets.  Basically an extended EE_Admin Page extends the core {child}_Admin_Page
299
-     * class.  eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class:
300
-     * Extend_Events_Admin_Page extends Events_Admin_Page.
301
-     * 3. Do we have any files just for setting up hooks into other core pages.  The files can be any name in
302
-     * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the
303
-     * classname inside.  These classes are instantiated really early so that any hooks in them are run before the
304
-     * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated
305
-     * admin_pages)
306
-     *
307
-     * @param array $admin_pages the original installed_refs array that may contain our NEW EE_Admin_Pages to be
308
-     *                              loaded.
309
-     * @return array
310
-     * @throws EE_Error
311
-     */
312
-    private function findCaffeinatedAdminPages(array $admin_pages): array
313
-    {
314
-        // first let's check if there IS a caffeinated folder. If there is not then lets get out.
315
-        if ((defined('EE_DECAF') && EE_DECAF) || ! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated/admin')) {
316
-            return $admin_pages;
317
-        }
318
-        $this->defineCaffeinatedConstants();
319
-        // okay let's setup an "New" pages first (we'll return installed refs later)
320
-        $admin_pages += $this->findAdminPageFolders(EE_CORE_CAF_ADMIN . 'new/*', ['tickets']);
321
-
322
-        return apply_filters(
323
-            'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs',
324
-            $admin_pages
325
-        );
326
-    }
327
-
328
-
329
-    /**
330
-     * @throws EE_Error
331
-     * @since   5.0.0.p
332
-     */
333
-    private function findAdminPageExtensions()
334
-    {
335
-        // let's see if there are any EXTENDS to setup in the $_caffeinated_extends array
336
-        // (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
337
-        $extensions = $this->findAdminPageFolders(EE_CORE_CAF_ADMIN . 'extend/*');
338
-        if ($extensions) {
339
-            foreach ($extensions as $folder => $extension) {
340
-                // convert lowercase_snake_case to Uppercase_Snake_Case
341
-                $filename = str_replace(' ', '_', ucwords(str_replace('_', ' ', $folder)));
342
-                $filename = "Extend_{$filename}_Admin_Page";
343
-                $filepath = EE_CORE_CAF_ADMIN . "extend/$folder/$filename.core.php";
344
-                // save filename and filepath for later
345
-                $this->_caffeinated_extends[ $folder ]['path']       = str_replace(['\\', '/'], '/', $filepath);
346
-                $this->_caffeinated_extends[ $folder ]['admin_page'] = $filename;
347
-            }
348
-        }
349
-        $this->_caffeinated_extends = apply_filters(
350
-            'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends',
351
-            $this->_caffeinated_extends
352
-        );
353
-    }
354
-
355
-
356
-    private function loadCaffeinatedExtensions(
357
-        EE_Admin_Page_Init $admin_page_init,
358
-        string $page,
359
-        string $menu_slug
360
-    ): bool {
361
-        if (! isset($this->_caffeinated_extends[ $page ])) {
362
-            return false;
363
-        }
364
-        $admin_page_name = $admin_page_init->get_admin_page_name();
365
-        $caf_path        = $this->_caffeinated_extends[ $page ]['path'];
366
-        $caf_admin_page  = $this->_caffeinated_extends[ $page ]['admin_page'];
367
-        add_filter(
368
-            "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_$admin_page_name",
369
-            static function ($path_to_file) use ($caf_path) {
370
-                return $caf_path;
371
-            }
372
-        );
373
-        add_filter(
374
-            "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_$admin_page_name",
375
-            static function ($admin_page) use ($caf_admin_page) {
376
-                return $caf_admin_page;
377
-            }
378
-        );
379
-        return true;
380
-    }
381
-
382
-
383
-    /**
384
-     * @throws EE_Error
385
-     * @since   5.0.0.p
386
-     */
387
-    private function findAdminPageHooks()
388
-    {
389
-        // let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
390
-        $ee_admin_hooks   = [];
391
-        $admin_page_hooks = $this->findAdminPageFolders(EE_CORE_CAF_ADMIN . 'hooks/*.class.php', [], 0, false);
392
-        if ($admin_page_hooks) {
393
-            foreach ($admin_page_hooks as $hook) {
394
-                if (is_readable($hook)) {
395
-                    require_once $hook;
396
-                    $classname = str_replace([EE_CORE_CAF_ADMIN . 'hooks/', '.class.php'], '', $hook);
397
-                    if (class_exists($classname)) {
398
-                        $ee_admin_hooks[] = $this->loader->getShared($classname);
399
-                    }
400
-                }
401
-            }
402
-        }
403
-        apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks);
404
-    }
405
-
406
-
407
-    /**
408
-     * _default_header_link
409
-     * This is just a dummy method to use with header submenu items
410
-     *
411
-     * @return bool false
412
-     */
413
-    public function _default_header_link(): bool
414
-    {
415
-        return false;
416
-    }
417
-
418
-
419
-    /**
420
-     * @param string $path
421
-     * @param int    $flags
422
-     * @param array  $exclude
423
-     * @param bool   $register_autoloaders
424
-     * @return array
425
-     * @throws EE_Error
426
-     * @since 5.0.0.p
427
-     */
428
-    private function findAdminPageFolders(
429
-        string $path,
430
-        array $exclude = [],
431
-        int $flags = GLOB_ONLYDIR,
432
-        bool $register_autoloaders = true
433
-    ): array {
434
-        $folders = [];
435
-        $subfolders = glob($path, $flags);
436
-        if ($subfolders) {
437
-            foreach ($subfolders as $admin_screen) {
438
-                $admin_screen_name = basename($admin_screen);
439
-                // files and anything in the exclude array need not apply
440
-                if (! in_array($admin_screen_name, $exclude, true)) {
441
-                    // these folders represent the different EE admin pages
442
-                    $folders[ $admin_screen_name ] = $admin_screen;
443
-                    if ($register_autoloaders) {
444
-                        // set autoloaders for our admin page classes based on included path information
445
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder($admin_screen);
446
-                    }
447
-                }
448
-            }
449
-        }
450
-        return $folders;
451
-    }
19
+	/**
20
+	 * @var AdminMenuManager $menu_manager
21
+	 */
22
+	protected $menu_manager;
23
+
24
+	/**
25
+	 * @var LoaderInterface $loader
26
+	 */
27
+	protected $loader;
28
+
29
+	/**
30
+	 * _installed_pages
31
+	 * objects for page_init objects detected and loaded
32
+	 *
33
+	 * @access private
34
+	 * @var EE_Admin_Page_Init[]
35
+	 */
36
+	private $_installed_pages = [];
37
+
38
+
39
+	/**
40
+	 * this is used to hold the registry of menu slugs for all the installed admin pages
41
+	 *
42
+	 * @var array
43
+	 */
44
+	private $_menu_slugs = [];
45
+
46
+
47
+	/**
48
+	 * _caffeinated_extends
49
+	 * This array is the generated configuration array for which core EE_Admin pages are extended (and the bits and
50
+	 * pieces needed to do so).  This property is defined in the _set_caffeinated method.
51
+	 *
52
+	 * @var array
53
+	 */
54
+	private $_caffeinated_extends = [];
55
+
56
+
57
+	/**
58
+	 * This property will hold the hook file for setting up the filter that does all the connections between admin
59
+	 * pages.
60
+	 *
61
+	 * @var string
62
+	 */
63
+	public $hook_file;
64
+
65
+	/**
66
+	 * @var   int
67
+	 * @since 5.0.0.p
68
+	 */
69
+	private $maintenance_mode = 0;
70
+
71
+
72
+	/**
73
+	 * @throws InvalidArgumentException
74
+	 * @throws InvalidDataTypeException
75
+	 * @throws InvalidInterfaceException
76
+	 */
77
+	public function __construct(?LoaderInterface $loader)
78
+	{
79
+		$this->loader = $loader instanceof LoaderInterface ? $loader : LoaderFactory::getLoader();
80
+		$this->menu_manager = $this->loader->getShared(AdminMenuManager::class, [$this->loader]);
81
+	}
82
+
83
+
84
+	/**
85
+	 * @throws EE_Error
86
+	 * @throws ReflectionException
87
+	 * @since 5.0.0.p
88
+	 */
89
+	public function init()
90
+	{
91
+		$this->menu_manager->initialize();
92
+		$this->maintenance_mode = EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance;
93
+		// let's do a scan and see what installed pages we have
94
+		$this->findAndLoadAdminPages();
95
+	}
96
+
97
+
98
+	/**
99
+	 * When caffeinated system is detected, this method is called to setup the caffeinated directory constants used by
100
+	 * files in the caffeinated folder.
101
+	 *
102
+	 * @access private
103
+	 * @return void
104
+	 */
105
+	private function defineCaffeinatedConstants()
106
+	{
107
+		if (! defined('EE_CORE_CAF_ADMIN')) {
108
+			define('EE_CORE_CAF_ADMIN', EE_PLUGIN_DIR_PATH . 'caffeinated/admin/');
109
+			define('EE_CORE_CAF_ADMIN_URL', EE_PLUGIN_DIR_URL . 'caffeinated/admin/');
110
+			define('EE_CORE_CAF_ADMIN_NEW', EE_CORE_CAF_ADMIN . 'new/');
111
+			define('EE_CORE_CAF_ADMIN_EXTEND', EE_CORE_CAF_ADMIN . 'extend/');
112
+			define('EE_CORE_CAF_ADMIN_EXTEND_URL', EE_CORE_CAF_ADMIN_URL . 'extend/');
113
+			define('EE_CORE_CAF_ADMIN_HOOKS', EE_CORE_CAF_ADMIN . 'hooks/');
114
+		}
115
+	}
116
+
117
+
118
+	/**
119
+	 * This just gets the list of installed EE_Admin_pages.
120
+	 *
121
+	 * @access private
122
+	 * @return void
123
+	 * @throws EE_Error
124
+	 * @throws InvalidArgumentException
125
+	 * @throws InvalidDataTypeException
126
+	 * @throws InvalidInterfaceException
127
+	 * @throws ReflectionException
128
+	 */
129
+	private function findAndLoadAdminPages()
130
+	{
131
+		$admin_pages = $this->findAdminPages();
132
+		// this just checks the caffeinated folder and takes care of setting up any caffeinated stuff.
133
+		$admin_pages = $this->findCaffeinatedAdminPages($admin_pages);
134
+		// then extensions and hooks, although they don't get added to the admin pages array
135
+		$this->findAdminPageExtensions();
136
+		$this->findAdminPageHooks();
137
+		// 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.;
138
+		// loop through admin pages and setup the $_installed_pages array.
139
+		$hooks_ref = [];
140
+		$menu_pages = [];
141
+		foreach ($admin_pages as $page => $path) {
142
+			// don't load the page init class IF IT's ALREADY LOADED !!!
143
+			if (
144
+				isset($this->_installed_pages[ $page ])
145
+				&& $this->_installed_pages[ $page ] instanceof EE_Admin_Page_Init
146
+			) {
147
+				continue;
148
+			}
149
+			// build list of installed pages
150
+			$admin_page_init = $this->loadAdminPageInit($page);
151
+			$this->_installed_pages[ $page ] = $admin_page_init;
152
+			$admin_menu = $this->menu_manager->getAdminMenu($admin_page_init);
153
+			$admin_page_init->setCapability($admin_menu->capability(), $admin_menu->menuSlug());
154
+			// skip if in full maintenance mode and maintenance_mode_parent is NOT set
155
+			if ($this->maintenance_mode && ! $admin_menu->maintenanceModeParent()) {
156
+				unset($admin_pages[ $page ]);
157
+				continue;
158
+			}
159
+			$menu_slug = $admin_menu->menuSlug();
160
+			$this->_menu_slugs[ $menu_slug ] = $page;
161
+			$menu_pages[ $menu_slug ] = $admin_page_init;
162
+			// now that we've got the admin_init objects...
163
+			// lets see if there are any caffeinated pages extending the originals.
164
+			// If there are then let's hook into the init admin filter and load our extend instead.
165
+			// Set flag for register hooks on extended pages b/c extended pages use the default INIT.
166
+			$extended_hooks = $admin_page_init->register_hooks(
167
+				$this->loadCaffeinatedExtensions($admin_page_init, $page, $menu_slug)
168
+			);
169
+			$hooks_ref      += $extended_hooks;
170
+		}
171
+		// the hooks_ref is all the pages where we have $extended _Hooks files
172
+		// that will extend a class in a different folder.
173
+		// So we want to make sure we load the file for the parent.
174
+		// first make sure we've got unique values
175
+		$hooks_ref = array_unique($hooks_ref);
176
+		// now let's loop and require!
177
+		foreach ($hooks_ref as $path) {
178
+			require_once($path);
179
+		}
180
+		// 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.
181
+		global $ee_menu_slugs;
182
+		$ee_menu_slugs = $this->_menu_slugs;
183
+		// we need to loop again to run any early code
184
+		foreach ($this->_installed_pages as $page) {
185
+			$page->do_initial_loads();
186
+		}
187
+		$this->menu_manager->setInstalledPages($menu_pages);
188
+		do_action('AHEE__EE_Admin_Page_Loader___get_installed_pages_loaded', $this->_installed_pages);
189
+	}
190
+
191
+
192
+	/**
193
+	 * @return array
194
+	 * @throws EE_Error
195
+	 * @since   5.0.0.p
196
+	 */
197
+	private function findAdminPages(): array
198
+	{
199
+
200
+		// grab everything in the  admin core directory
201
+		$admin_page_folders = $this->findAdminPageFolders(EE_ADMIN_PAGES . '*');
202
+		$admin_page_folders = apply_filters(
203
+			'FHEE__EE_Admin_Page_Loader__findAdminPages__admin_page_folders',
204
+			$admin_page_folders
205
+		);
206
+		if (! empty($admin_page_folders)) {
207
+			return $admin_page_folders;
208
+		}
209
+		$error_msg = esc_html__(
210
+			'There are no EE_Admin pages detected, it looks like EE did not install properly',
211
+			'event_espresso'
212
+		);
213
+		$error_msg .= '||';
214
+		$error_msg .= sprintf(
215
+			esc_html__(
216
+				'Check that the %s folder exists and is writable. Maybe try deactivating, then reactivating Event Espresso again.',
217
+				'event_espresso'
218
+			),
219
+			EE_ADMIN_PAGES
220
+		);
221
+		throw new RuntimeException($error_msg);
222
+	}
223
+
224
+
225
+	/**
226
+	 * get_admin_page_object
227
+	 *
228
+	 * @param string $page_slug
229
+	 * @return EE_Admin_Page
230
+	 */
231
+	public function get_admin_page_object(string $page_slug = ''): ?EE_Admin_Page
232
+	{
233
+		return isset($this->_installed_pages[ $page_slug ])
234
+			   && $this->_installed_pages[ $page_slug ] instanceof EE_Admin_Page_Init
235
+			? $this->_installed_pages[ $page_slug ]->loaded_page_object()
236
+			: null;
237
+	}
238
+
239
+
240
+	/**
241
+	 * generates an "Admin Page Init" class based on the directory  name
242
+	 *
243
+	 * @param string $dir_name
244
+	 * @return string
245
+	 */
246
+	private function getClassnameForAdminPageInit(string $dir_name = ''): string
247
+	{
248
+		$class_name = str_replace('_', ' ', strtolower($dir_name));
249
+		return str_replace(' ', '_', ucwords($class_name)) . '_Admin_Page_Init';
250
+	}
251
+
252
+
253
+	/**
254
+	 * _load_admin_page
255
+	 * Loads and instantiates page_init object for a single EE_admin page.
256
+	 *
257
+	 * @param string $page page_reference
258
+	 * @return EE_Admin_Page_Init
259
+	 * @throws EE_Error
260
+	 */
261
+	private function loadAdminPageInit(string $page = ''): EE_Admin_Page_Init
262
+	{
263
+		$class_name = $this->getClassnameForAdminPageInit($page);
264
+		if (class_exists($class_name)) {
265
+			$admin_page_init = $this->loader->getShared($class_name);
266
+			// verify returned object
267
+			if ($admin_page_init instanceof EE_Admin_Page_Init) {
268
+				return $admin_page_init;
269
+			}
270
+		}
271
+		$error_msg = sprintf(
272
+			esc_html__('Something went wrong with loading the %s admin page.', 'event_espresso'),
273
+			$page
274
+		);
275
+		$error_msg .= '||'; // separates public from developer messages
276
+		$error_msg .= "\r\n";
277
+		$error_msg .= sprintf(
278
+			esc_html__('There is no Init class in place for the %s admin page.', 'event_espresso'),
279
+			$page
280
+		);
281
+		$error_msg .= '<br />';
282
+		$error_msg .= sprintf(
283
+			esc_html__(
284
+				'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',
285
+				'event_espresso'
286
+			),
287
+			'<strong>' . $class_name . '</strong>'
288
+		);
289
+		throw new EE_Error($error_msg);
290
+	}
291
+
292
+
293
+	/**
294
+	 * This method is the "workhorse" for detecting and setting up caffeinated functionality.
295
+	 * In this method there are three checks being done:
296
+	 * 1. Do we have any NEW admin page sets.  If we do, lets add them into the menu setup (via the $admin_pages
297
+	 * array) etc.  (new page sets are found in caffeinated/new/{page})
298
+	 * 2. Do we have any EXTENDED page sets.  Basically an extended EE_Admin Page extends the core {child}_Admin_Page
299
+	 * class.  eg. would be caffeinated/extend/events/Extend_Events_Admin_Page.core.php and in there would be a class:
300
+	 * Extend_Events_Admin_Page extends Events_Admin_Page.
301
+	 * 3. Do we have any files just for setting up hooks into other core pages.  The files can be any name in
302
+	 * "caffeinated/hooks" EXCEPT they need a ".class.php" extension and the file name must correspond with the
303
+	 * classname inside.  These classes are instantiated really early so that any hooks in them are run before the
304
+	 * corresponding apply_filters/do_actions that are found in any future loaded EE_Admin pages (INCLUDING caffeinated
305
+	 * admin_pages)
306
+	 *
307
+	 * @param array $admin_pages the original installed_refs array that may contain our NEW EE_Admin_Pages to be
308
+	 *                              loaded.
309
+	 * @return array
310
+	 * @throws EE_Error
311
+	 */
312
+	private function findCaffeinatedAdminPages(array $admin_pages): array
313
+	{
314
+		// first let's check if there IS a caffeinated folder. If there is not then lets get out.
315
+		if ((defined('EE_DECAF') && EE_DECAF) || ! is_dir(EE_PLUGIN_DIR_PATH . 'caffeinated/admin')) {
316
+			return $admin_pages;
317
+		}
318
+		$this->defineCaffeinatedConstants();
319
+		// okay let's setup an "New" pages first (we'll return installed refs later)
320
+		$admin_pages += $this->findAdminPageFolders(EE_CORE_CAF_ADMIN . 'new/*', ['tickets']);
321
+
322
+		return apply_filters(
323
+			'FHEE__EE_Admin_Page_Loader___get_installed_pages__installed_refs',
324
+			$admin_pages
325
+		);
326
+	}
327
+
328
+
329
+	/**
330
+	 * @throws EE_Error
331
+	 * @since   5.0.0.p
332
+	 */
333
+	private function findAdminPageExtensions()
334
+	{
335
+		// let's see if there are any EXTENDS to setup in the $_caffeinated_extends array
336
+		// (that will be used later for hooking into the _initialize_admin_age in the related core_init admin page)
337
+		$extensions = $this->findAdminPageFolders(EE_CORE_CAF_ADMIN . 'extend/*');
338
+		if ($extensions) {
339
+			foreach ($extensions as $folder => $extension) {
340
+				// convert lowercase_snake_case to Uppercase_Snake_Case
341
+				$filename = str_replace(' ', '_', ucwords(str_replace('_', ' ', $folder)));
342
+				$filename = "Extend_{$filename}_Admin_Page";
343
+				$filepath = EE_CORE_CAF_ADMIN . "extend/$folder/$filename.core.php";
344
+				// save filename and filepath for later
345
+				$this->_caffeinated_extends[ $folder ]['path']       = str_replace(['\\', '/'], '/', $filepath);
346
+				$this->_caffeinated_extends[ $folder ]['admin_page'] = $filename;
347
+			}
348
+		}
349
+		$this->_caffeinated_extends = apply_filters(
350
+			'FHEE__EE_Admin_Page_Loader___get_installed_pages__caffeinated_extends',
351
+			$this->_caffeinated_extends
352
+		);
353
+	}
354
+
355
+
356
+	private function loadCaffeinatedExtensions(
357
+		EE_Admin_Page_Init $admin_page_init,
358
+		string $page,
359
+		string $menu_slug
360
+	): bool {
361
+		if (! isset($this->_caffeinated_extends[ $page ])) {
362
+			return false;
363
+		}
364
+		$admin_page_name = $admin_page_init->get_admin_page_name();
365
+		$caf_path        = $this->_caffeinated_extends[ $page ]['path'];
366
+		$caf_admin_page  = $this->_caffeinated_extends[ $page ]['admin_page'];
367
+		add_filter(
368
+			"FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$menu_slug}_$admin_page_name",
369
+			static function ($path_to_file) use ($caf_path) {
370
+				return $caf_path;
371
+			}
372
+		);
373
+		add_filter(
374
+			"FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$menu_slug}_$admin_page_name",
375
+			static function ($admin_page) use ($caf_admin_page) {
376
+				return $caf_admin_page;
377
+			}
378
+		);
379
+		return true;
380
+	}
381
+
382
+
383
+	/**
384
+	 * @throws EE_Error
385
+	 * @since   5.0.0.p
386
+	 */
387
+	private function findAdminPageHooks()
388
+	{
389
+		// let's see if there are any HOOK files and instantiate them if there are (so that hooks are loaded early!).
390
+		$ee_admin_hooks   = [];
391
+		$admin_page_hooks = $this->findAdminPageFolders(EE_CORE_CAF_ADMIN . 'hooks/*.class.php', [], 0, false);
392
+		if ($admin_page_hooks) {
393
+			foreach ($admin_page_hooks as $hook) {
394
+				if (is_readable($hook)) {
395
+					require_once $hook;
396
+					$classname = str_replace([EE_CORE_CAF_ADMIN . 'hooks/', '.class.php'], '', $hook);
397
+					if (class_exists($classname)) {
398
+						$ee_admin_hooks[] = $this->loader->getShared($classname);
399
+					}
400
+				}
401
+			}
402
+		}
403
+		apply_filters('FHEE__EE_Admin_Page_Loader__set_caffeinated__ee_admin_hooks', $ee_admin_hooks);
404
+	}
405
+
406
+
407
+	/**
408
+	 * _default_header_link
409
+	 * This is just a dummy method to use with header submenu items
410
+	 *
411
+	 * @return bool false
412
+	 */
413
+	public function _default_header_link(): bool
414
+	{
415
+		return false;
416
+	}
417
+
418
+
419
+	/**
420
+	 * @param string $path
421
+	 * @param int    $flags
422
+	 * @param array  $exclude
423
+	 * @param bool   $register_autoloaders
424
+	 * @return array
425
+	 * @throws EE_Error
426
+	 * @since 5.0.0.p
427
+	 */
428
+	private function findAdminPageFolders(
429
+		string $path,
430
+		array $exclude = [],
431
+		int $flags = GLOB_ONLYDIR,
432
+		bool $register_autoloaders = true
433
+	): array {
434
+		$folders = [];
435
+		$subfolders = glob($path, $flags);
436
+		if ($subfolders) {
437
+			foreach ($subfolders as $admin_screen) {
438
+				$admin_screen_name = basename($admin_screen);
439
+				// files and anything in the exclude array need not apply
440
+				if (! in_array($admin_screen_name, $exclude, true)) {
441
+					// these folders represent the different EE admin pages
442
+					$folders[ $admin_screen_name ] = $admin_screen;
443
+					if ($register_autoloaders) {
444
+						// set autoloaders for our admin page classes based on included path information
445
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder($admin_screen);
446
+					}
447
+				}
448
+			}
449
+		}
450
+		return $folders;
451
+	}
452 452
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 1 patch
Indentation   +4262 added lines, -4262 removed lines patch added patch discarded remove patch
@@ -24,4350 +24,4350 @@
 block discarded – undo
24 24
  */
25 25
 abstract class EE_Admin_Page extends EE_Base implements InterminableInterface
26 26
 {
27
-    /**
28
-     * @var EE_Admin_Config
29
-     */
30
-    protected $admin_config;
27
+	/**
28
+	 * @var EE_Admin_Config
29
+	 */
30
+	protected $admin_config;
31 31
 
32
-    /**
33
-     * @var LoaderInterface
34
-     */
35
-    protected $loader;
32
+	/**
33
+	 * @var LoaderInterface
34
+	 */
35
+	protected $loader;
36 36
 
37
-    /**
38
-     * @var RequestInterface
39
-     */
40
-    protected $request;
37
+	/**
38
+	 * @var RequestInterface
39
+	 */
40
+	protected $request;
41 41
 
42
-    // set in _init_page_props()
43
-    public $page_slug;
42
+	// set in _init_page_props()
43
+	public $page_slug;
44 44
 
45
-    public $page_label;
45
+	public $page_label;
46 46
 
47
-    public $page_folder;
47
+	public $page_folder;
48 48
 
49
-    // set in define_page_props()
50
-    protected $_admin_base_url;
49
+	// set in define_page_props()
50
+	protected $_admin_base_url;
51 51
 
52
-    protected $_admin_base_path;
52
+	protected $_admin_base_path;
53 53
 
54
-    protected $_admin_page_title;
54
+	protected $_admin_page_title;
55 55
 
56
-    protected $_labels;
56
+	protected $_labels;
57 57
 
58 58
 
59
-    // set early within EE_Admin_Init
60
-    protected $_wp_page_slug;
59
+	// set early within EE_Admin_Init
60
+	protected $_wp_page_slug;
61 61
 
62
-    // nav tabs
63
-    protected $_nav_tabs;
62
+	// nav tabs
63
+	protected $_nav_tabs;
64 64
 
65
-    protected $_default_nav_tab_name;
65
+	protected $_default_nav_tab_name;
66 66
 
67 67
 
68
-    // template variables (used by templates)
69
-    protected $_template_path;
68
+	// template variables (used by templates)
69
+	protected $_template_path;
70 70
 
71
-    protected $_column_template_path;
71
+	protected $_column_template_path;
72 72
 
73
-    /**
74
-     * @var array $_template_args
75
-     */
76
-    protected $_template_args = [];
73
+	/**
74
+	 * @var array $_template_args
75
+	 */
76
+	protected $_template_args = [];
77 77
 
78
-    /**
79
-     * this will hold the list table object for a given view.
80
-     *
81
-     * @var EE_Admin_List_Table $_list_table_object
82
-     */
83
-    protected $_list_table_object;
78
+	/**
79
+	 * this will hold the list table object for a given view.
80
+	 *
81
+	 * @var EE_Admin_List_Table $_list_table_object
82
+	 */
83
+	protected $_list_table_object;
84 84
 
85
-    // boolean
86
-    protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states.
85
+	// boolean
86
+	protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states.
87 87
 
88
-    protected $_routing;
88
+	protected $_routing;
89 89
 
90
-    // list table args
91
-    protected $_view;
90
+	// list table args
91
+	protected $_view;
92 92
 
93
-    protected $_views;
93
+	protected $_views;
94 94
 
95 95
 
96
-    // action => method pairs used for routing incoming requests
97
-    protected $_page_routes;
96
+	// action => method pairs used for routing incoming requests
97
+	protected $_page_routes;
98 98
 
99
-    /**
100
-     * @var array $_page_config
101
-     */
102
-    protected $_page_config;
99
+	/**
100
+	 * @var array $_page_config
101
+	 */
102
+	protected $_page_config;
103 103
 
104
-    /**
105
-     * the current page route and route config
106
-     *
107
-     * @var array|string|null $_route
108
-     */
109
-    protected $_route;
104
+	/**
105
+	 * the current page route and route config
106
+	 *
107
+	 * @var array|string|null $_route
108
+	 */
109
+	protected $_route;
110 110
 
111
-    /**
112
-     * @var string $_cpt_route
113
-     */
114
-    protected $_cpt_route;
111
+	/**
112
+	 * @var string $_cpt_route
113
+	 */
114
+	protected $_cpt_route;
115 115
 
116
-    /**
117
-     * @var array $_route_config
118
-     */
119
-    protected $_route_config;
116
+	/**
117
+	 * @var array $_route_config
118
+	 */
119
+	protected $_route_config;
120 120
 
121
-    /**
122
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
123
-     * actions.
124
-     *
125
-     * @since 4.6.x
126
-     * @var array.
127
-     */
128
-    protected $_default_route_query_args;
121
+	/**
122
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
123
+	 * actions.
124
+	 *
125
+	 * @since 4.6.x
126
+	 * @var array.
127
+	 */
128
+	protected $_default_route_query_args;
129 129
 
130
-    // set via request page and action args.
131
-    protected $_current_page;
130
+	// set via request page and action args.
131
+	protected $_current_page;
132 132
 
133
-    protected $_current_view;
133
+	protected $_current_view;
134 134
 
135
-    protected $_current_page_view_url;
135
+	protected $_current_page_view_url;
136 136
 
137
-    /**
138
-     * unprocessed value for the 'action' request param (default '')
139
-     *
140
-     * @var string
141
-     */
142
-    protected $raw_req_action = '';
137
+	/**
138
+	 * unprocessed value for the 'action' request param (default '')
139
+	 *
140
+	 * @var string
141
+	 */
142
+	protected $raw_req_action = '';
143 143
 
144
-    /**
145
-     * unprocessed value for the 'page' request param (default '')
146
-     *
147
-     * @var string
148
-     */
149
-    protected $raw_req_page = '';
150
-
151
-    /**
152
-     * sanitized request action (and nonce)
153
-     *
154
-     * @var string
155
-     */
156
-    protected $_req_action = '';
157
-
158
-    /**
159
-     * sanitized request action nonce
160
-     *
161
-     * @var string
162
-     */
163
-    protected $_req_nonce = '';
164
-
165
-    /**
166
-     * @var string
167
-     */
168
-    protected $_search_btn_label = '';
169
-
170
-    /**
171
-     * @var string
172
-     */
173
-    protected $_search_box_callback = '';
174
-
175
-    /**
176
-     * @var WP_Screen
177
-     */
178
-    protected $_current_screen;
179
-
180
-    // for holding EE_Admin_Hooks object when needed (set via set_hook_object())
181
-    protected $_hook_obj;
182
-
183
-    // for holding incoming request data
184
-    protected $_req_data = [];
185
-
186
-    // yes / no array for admin form fields
187
-    protected $_yes_no_values = [];
188
-
189
-    // some default things shared by all child classes
190
-    protected $_default_espresso_metaboxes = [
191
-        '_espresso_news_post_box',
192
-        '_espresso_links_post_box',
193
-        '_espresso_ratings_request',
194
-        '_espresso_sponsors_post_box',
195
-    ];
196
-
197
-    /**
198
-     * @var EE_Registry
199
-     */
200
-    protected $EE;
201
-
202
-
203
-    /**
204
-     * This is just a property that flags whether the given route is a caffeinated route or not.
205
-     *
206
-     * @var boolean
207
-     */
208
-    protected $_is_caf = false;
209
-
210
-    /**
211
-     * whether or not initializePage() has run
212
-     *
213
-     * @var boolean
214
-     */
215
-    protected $initialized = false;
216
-
217
-    /**
218
-     * @var FeatureFlags
219
-     */
220
-    protected $feature;
221
-
222
-
223
-    /**
224
-     * @var string
225
-     */
226
-    protected $class_name;
227
-
228
-    /**
229
-     * if the current class is an admin page extension, like: Extend_Events_Admin_Page,
230
-     * then this would be the parent classname: Events_Admin_Page
231
-     *
232
-     * @var string
233
-     */
234
-    protected $base_class_name;
235
-
236
-    /**
237
-     * @var array
238
-     * @since 5.0.0.p
239
-     */
240
-    private $publish_post_meta_box_hidden_fields = [];
241
-
242
-
243
-    /**
244
-     * @Constructor
245
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
246
-     * @throws InvalidArgumentException
247
-     * @throws InvalidDataTypeException
248
-     * @throws InvalidInterfaceException
249
-     * @throws ReflectionException
250
-     */
251
-    public function __construct($routing = true)
252
-    {
253
-        $this->loader       = LoaderFactory::getLoader();
254
-        $this->admin_config = $this->loader->getShared('EE_Admin_Config');
255
-        $this->feature      = $this->loader->getShared(FeatureFlags::class);
256
-        $this->request      = $this->loader->getShared(RequestInterface::class);
257
-        // routing enabled?
258
-        $this->_routing = $routing;
259
-
260
-        $this->class_name      = get_class($this);
261
-        $this->base_class_name = strpos($this->class_name, 'Extend_') === 0
262
-            ? str_replace('Extend_', '', $this->class_name)
263
-            : '';
264
-
265
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
266
-            $this->_is_caf = true;
267
-        }
268
-        $this->_yes_no_values = [
269
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
270
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
271
-        ];
272
-        // set the _req_data property.
273
-        $this->_req_data = $this->request->requestParams();
274
-    }
275
-
276
-
277
-    /**
278
-     * @return EE_Admin_Config
279
-     */
280
-    public function adminConfig(): EE_Admin_Config
281
-    {
282
-        return $this->admin_config;
283
-    }
284
-
285
-
286
-    /**
287
-     * @return FeatureFlags
288
-     */
289
-    public function feature(): FeatureFlags
290
-    {
291
-        return $this->feature;
292
-    }
293
-
294
-
295
-    /**
296
-     * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
297
-     * for child classes that needed to set properties prior to these methods getting called,
298
-     * but also needed the parent class to have its construction completed as well.
299
-     * Bottom line is that constructors should ONLY be used for setting initial properties
300
-     * and any complex initialization logic should only run after instantiation is complete.
301
-     *
302
-     * This method gets called immediately after construction from within
303
-     *      EE_Admin_Page_Init::_initialize_admin_page()
304
-     *
305
-     * @throws EE_Error
306
-     * @throws InvalidArgumentException
307
-     * @throws InvalidDataTypeException
308
-     * @throws InvalidInterfaceException
309
-     * @throws ReflectionException
310
-     * @since 5.0.0.p
311
-     */
312
-    public function initializePage()
313
-    {
314
-        if ($this->initialized) {
315
-            return;
316
-        }
317
-        // set initial page props (child method)
318
-        $this->_init_page_props();
319
-        // set global defaults
320
-        $this->_set_defaults();
321
-        // set early because incoming requests could be ajax related and we need to register those hooks.
322
-        $this->_global_ajax_hooks();
323
-        $this->_ajax_hooks();
324
-        // other_page_hooks have to be early too.
325
-        $this->_do_other_page_hooks();
326
-        // set up page dependencies
327
-        $this->_before_page_setup();
328
-        $this->_page_setup();
329
-        $this->initialized = true;
330
-    }
331
-
332
-
333
-    /**
334
-     * _init_page_props
335
-     * Child classes use to set at least the following properties:
336
-     * $page_slug.
337
-     * $page_label.
338
-     *
339
-     * @abstract
340
-     * @return void
341
-     */
342
-    abstract protected function _init_page_props();
343
-
344
-
345
-    /**
346
-     * _ajax_hooks
347
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
348
-     * Note: within the ajax callback methods.
349
-     *
350
-     * @abstract
351
-     * @return void
352
-     */
353
-    abstract protected function _ajax_hooks();
354
-
355
-
356
-    /**
357
-     * _define_page_props
358
-     * child classes define page properties in here.  Must include at least:
359
-     * $_admin_base_url = base_url for all admin pages
360
-     * $_admin_page_title = default admin_page_title for admin pages
361
-     * $_labels = array of default labels for various automatically generated elements:
362
-     *    array(
363
-     *        'buttons' => array(
364
-     *            'add' => esc_html__('label for add new button'),
365
-     *            'edit' => esc_html__('label for edit button'),
366
-     *            'delete' => esc_html__('label for delete button')
367
-     *            )
368
-     *        )
369
-     *
370
-     * @abstract
371
-     * @return void
372
-     */
373
-    abstract protected function _define_page_props();
374
-
375
-
376
-    /**
377
-     * _set_page_routes
378
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
379
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
380
-     * have a 'default' route. Here's the format
381
-     * $this->_page_routes = array(
382
-     *        'default' => array(
383
-     *            'func' => '_default_method_handling_route',
384
-     *            'args' => array('array','of','args'),
385
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
386
-     *            ajax request, backend processing)
387
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
388
-     *            headers route after.  The string you enter here should match the defined route reference for a
389
-     *            headers sent route.
390
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
391
-     *            this route.
392
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
393
-     *            checks).
394
-     *        ),
395
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
396
-     *        handling method.
397
-     *        )
398
-     * )
399
-     *
400
-     * @abstract
401
-     * @return void
402
-     */
403
-    abstract protected function _set_page_routes();
404
-
405
-
406
-    /**
407
-     * _set_page_config
408
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
409
-     * array corresponds to the page_route for the loaded page. Format:
410
-     * $this->_page_config = array(
411
-     *        'default' => array(
412
-     *            'labels' => array(
413
-     *                'buttons' => array(
414
-     *                    'add' => esc_html__('label for adding item'),
415
-     *                    'edit' => esc_html__('label for editing item'),
416
-     *                    'delete' => esc_html__('label for deleting item')
417
-     *                ),
418
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
419
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
420
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
421
-     *            _define_page_props() method
422
-     *            'nav' => array(
423
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
424
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
425
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
426
-     *                'order' => 10, //required to indicate tab position.
427
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
428
-     *                displayed then add this parameter.
429
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
430
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
431
-     *            metaboxes set for eventespresso admin pages.
432
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
433
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
434
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
435
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
436
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
437
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
438
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
439
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
440
-     *            want to display.
441
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
442
-     *                'tab_id' => array(
443
-     *                    'title' => 'tab_title',
444
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
445
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
446
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
447
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
448
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
449
-     *                    attempt to use the callback which should match the name of a method in the class
450
-     *                    ),
451
-     *                'tab2_id' => array(
452
-     *                    'title' => 'tab2 title',
453
-     *                    'filename' => 'file_name_2'
454
-     *                    'callback' => 'callback_method_for_content',
455
-     *                 ),
456
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
457
-     *            help tab area on an admin page. @return void
458
-     *
459
-     * @abstract
460
-     */
461
-    abstract protected function _set_page_config();
462
-
463
-
464
-    /**
465
-     * _add_screen_options
466
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
467
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
468
-     * to a particular view.
469
-     *
470
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
471
-     *         see also WP_Screen object documents...
472
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
473
-     * @abstract
474
-     * @return void
475
-     */
476
-    abstract protected function _add_screen_options();
477
-
478
-
479
-    /**
480
-     * _add_feature_pointers
481
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
482
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
483
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
484
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
485
-     * extended) also see:
486
-     *
487
-     * @link   http://eamann.com/tech/wordpress-portland/
488
-     * @abstract
489
-     * @return void
490
-     */
491
-    abstract protected function _add_feature_pointers();
492
-
493
-
494
-    /**
495
-     * load_scripts_styles
496
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
497
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
498
-     * scripts/styles per view by putting them in a dynamic function in this format
499
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
500
-     *
501
-     * @abstract
502
-     * @return void
503
-     */
504
-    abstract public function load_scripts_styles();
505
-
506
-
507
-    /**
508
-     * admin_init
509
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
510
-     * all pages/views loaded by child class.
511
-     *
512
-     * @abstract
513
-     * @return void
514
-     */
515
-    abstract public function admin_init();
516
-
517
-
518
-    /**
519
-     * admin_notices
520
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
521
-     * all pages/views loaded by child class.
522
-     *
523
-     * @abstract
524
-     * @return void
525
-     */
526
-    abstract public function admin_notices();
527
-
528
-
529
-    /**
530
-     * admin_footer_scripts
531
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
532
-     * will apply to all pages/views loaded by child class.
533
-     *
534
-     * @return void
535
-     */
536
-    abstract public function admin_footer_scripts();
537
-
538
-
539
-    /**
540
-     * admin_footer
541
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
542
-     * apply to all pages/views loaded by child class.
543
-     *
544
-     * @return void
545
-     */
546
-    public function admin_footer()
547
-    {
548
-    }
549
-
550
-
551
-    /**
552
-     * _global_ajax_hooks
553
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
554
-     * Note: within the ajax callback methods.
555
-     *
556
-     * @abstract
557
-     * @return void
558
-     */
559
-    protected function _global_ajax_hooks()
560
-    {
561
-        // for lazy loading of metabox content
562
-        add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
563
-
564
-        add_action(
565
-            'wp_ajax_espresso_hide_status_change_notice',
566
-            [$this, 'hideStatusChangeNotice']
567
-        );
568
-        add_action(
569
-            'wp_ajax_nopriv_espresso_hide_status_change_notice',
570
-            [$this, 'hideStatusChangeNotice']
571
-        );
572
-    }
573
-
574
-
575
-    public function ajax_metabox_content()
576
-    {
577
-        $content_id  = $this->request->getRequestParam('contentid', '');
578
-        $content_url = $this->request->getRequestParam('contenturl', '', 'url');
579
-        EE_Admin_Page::cached_rss_display($content_id, $content_url);
580
-        wp_die();
581
-    }
582
-
583
-
584
-    public function hideStatusChangeNotice()
585
-    {
586
-        $response = [];
587
-        try {
588
-            /** @var StatusChangeNotice $status_change_notice */
589
-            $status_change_notice = $this->loader->getShared(
590
-                'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
591
-            );
592
-            $response['success']  = $status_change_notice->dismiss() > -1;
593
-        } catch (Exception $exception) {
594
-            $response['errors'] = $exception->getMessage();
595
-        }
596
-        echo wp_json_encode($response);
597
-        exit();
598
-    }
599
-
600
-
601
-    /**
602
-     * allows extending classes do something specific before the parent constructor runs _page_setup().
603
-     *
604
-     * @return void
605
-     */
606
-    protected function _before_page_setup()
607
-    {
608
-        // default is to do nothing
609
-    }
610
-
611
-
612
-    /**
613
-     * Makes sure any things that need to be loaded early get handled.
614
-     * We also escape early here if the page requested doesn't match the object.
615
-     *
616
-     * @final
617
-     * @return void
618
-     * @throws EE_Error
619
-     * @throws InvalidArgumentException
620
-     * @throws ReflectionException
621
-     * @throws InvalidDataTypeException
622
-     * @throws InvalidInterfaceException
623
-     */
624
-    final protected function _page_setup()
625
-    {
626
-        // requires?
627
-        // admin_init stuff - global - we're setting this REALLY early
628
-        // so if EE_Admin pages have to hook into other WP pages they can.
629
-        // But keep in mind, not everything is available from the EE_Admin Page object at this point.
630
-        add_action('admin_init', [$this, 'admin_init_global'], 5);
631
-        // next verify if we need to load anything...
632
-        $this->_current_page = $this->request->getRequestParam('page', '', 'key');
633
-        $this->_current_page = $this->request->getRequestParam('current_page', $this->_current_page, 'key');
634
-        $this->page_folder   = strtolower(
635
-            str_replace(['_Admin_Page', 'Extend_'], '', $this->class_name)
636
-        );
637
-        global $ee_menu_slugs;
638
-        $ee_menu_slugs = (array) $ee_menu_slugs;
639
-        if (
640
-            ! $this->request->isAjax()
641
-            && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
642
-        ) {
643
-            return;
644
-        }
645
-        // because WP List tables have two duplicate select inputs for choosing bulk actions,
646
-        // we need to copy the action from the second to the first
647
-        $action     = $this->request->getRequestParam('action', '-1', 'key');
648
-        $action2    = $this->request->getRequestParam('action2', '-1', 'key');
649
-        $action     = $action !== '-1' ? $action : $action2;
650
-        $req_action = $action !== '-1' ? $action : 'default';
651
-
652
-        // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
653
-        // then let's use the route as the action.
654
-        // This covers cases where we're coming in from a list table that isn't on the default route.
655
-        $route             = $this->request->getRequestParam('route');
656
-        $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
657
-            ? $route
658
-            : $req_action;
659
-
660
-        $this->_current_view = $this->_req_action;
661
-        $this->_req_nonce    = $this->_req_action . '_nonce';
662
-        $this->_define_page_props();
663
-        $this->_current_page_view_url = add_query_arg(
664
-            ['page' => $this->_current_page, 'action' => $this->_current_view],
665
-            $this->_admin_base_url
666
-        );
667
-        // set page configs
668
-        $this->_set_page_routes();
669
-        $this->_set_page_config();
670
-        // let's include any referrer data in our default_query_args for this route for "stickiness".
671
-        if ($this->request->requestParamIsSet('wp_referer')) {
672
-            $wp_referer = $this->request->getRequestParam('wp_referer');
673
-            if ($wp_referer) {
674
-                $this->_default_route_query_args['wp_referer'] = $wp_referer;
675
-            }
676
-        }
677
-        // for CPT and other extended functionality.
678
-        // If there is an _extend_page_config_for_cpt
679
-        // then let's run that to modify all the various page configuration arrays.
680
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
681
-            $this->_extend_page_config_for_cpt();
682
-        }
683
-        // filter routes and page_config so addons can add their stuff. Filtering done per class
684
-        $this->_page_routes = apply_filters(
685
-            'FHEE__' . $this->class_name . '__page_setup__page_routes',
686
-            $this->_page_routes,
687
-            $this
688
-        );
689
-        $this->_page_config = apply_filters(
690
-            'FHEE__' . $this->class_name . '__page_setup__page_config',
691
-            $this->_page_config,
692
-            $this
693
-        );
694
-        if ($this->base_class_name !== '') {
695
-            $this->_page_routes = apply_filters(
696
-                'FHEE__' . $this->base_class_name . '__page_setup__page_routes',
697
-                $this->_page_routes,
698
-                $this
699
-            );
700
-            $this->_page_config = apply_filters(
701
-                'FHEE__' . $this->base_class_name . '__page_setup__page_config',
702
-                $this->_page_config,
703
-                $this
704
-            );
705
-        }
706
-        // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
707
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
708
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
709
-            add_action(
710
-                'AHEE__EE_Admin_Page__route_admin_request',
711
-                [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
712
-                10,
713
-                2
714
-            );
715
-        }
716
-        // next route only if routing enabled
717
-        if ($this->_routing && ! $this->request->isAjax()) {
718
-            $this->_verify_routes();
719
-            // next let's just check user_access and kill if no access
720
-            $this->check_user_access();
721
-            if ($this->_is_UI_request) {
722
-                // admin_init stuff - global, all views for this page class, specific view
723
-                add_action('admin_init', [$this, 'admin_init'], 10);
724
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
725
-                    add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
726
-                }
727
-            } else {
728
-                // hijack regular WP loading and route admin request immediately
729
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
730
-                $this->route_admin_request();
731
-            }
732
-        }
733
-    }
734
-
735
-
736
-    /**
737
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
738
-     *
739
-     * @return void
740
-     * @throws EE_Error
741
-     */
742
-    private function _do_other_page_hooks()
743
-    {
744
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
745
-        foreach ($registered_pages as $page) {
746
-            // now let's setup the file name and class that should be present
747
-            $classname = str_replace('.class.php', '', $page);
748
-            // autoloaders should take care of loading file
749
-            if (! class_exists($classname)) {
750
-                $error_msg[] = sprintf(
751
-                    esc_html__(
752
-                        'Something went wrong with loading the %s admin hooks page.',
753
-                        'event_espresso'
754
-                    ),
755
-                    $page
756
-                );
757
-                $error_msg[] = $error_msg[0]
758
-                               . "\r\n"
759
-                               . sprintf(
760
-                                   esc_html__(
761
-                                       'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
762
-                                       'event_espresso'
763
-                                   ),
764
-                                   $page,
765
-                                   '<br />',
766
-                                   '<strong>' . $classname . '</strong>'
767
-                               );
768
-                throw new EE_Error(implode('||', $error_msg));
769
-            }
770
-            // notice we are passing the instance of this class to the hook object.
771
-            $this->loader->getShared($classname, [$this]);
772
-        }
773
-    }
774
-
775
-
776
-    /**
777
-     * @throws ReflectionException
778
-     * @throws EE_Error
779
-     */
780
-    public function load_page_dependencies()
781
-    {
782
-        try {
783
-            $this->_load_page_dependencies();
784
-        } catch (EE_Error $e) {
785
-            $e->get_error();
786
-        }
787
-    }
788
-
789
-
790
-    /**
791
-     * load_page_dependencies
792
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
793
-     *
794
-     * @return void
795
-     * @throws DomainException
796
-     * @throws EE_Error
797
-     * @throws InvalidArgumentException
798
-     * @throws InvalidDataTypeException
799
-     * @throws InvalidInterfaceException
800
-     * @throws ReflectionException
801
-     */
802
-    protected function _load_page_dependencies()
803
-    {
804
-        // let's set the current_screen and screen options to override what WP set
805
-        $this->_current_screen = get_current_screen();
806
-        // load admin_notices - global, page class, and view specific
807
-        add_action('admin_notices', [$this, 'admin_notices_global'], 5);
808
-        add_action('admin_notices', [$this, 'admin_notices'], 10);
809
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
810
-            add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
811
-        }
812
-        // load network admin_notices - global, page class, and view specific
813
-        add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
814
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
815
-            add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
816
-        }
817
-        // this will save any per_page screen options if they are present
818
-        $this->_set_per_page_screen_options();
819
-        // setup list table properties
820
-        $this->_set_list_table();
821
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
822
-        // However in some cases the metaboxes will need to be added within a route handling callback.
823
-        add_action('add_meta_boxes', [$this, 'addRegisteredMetaBoxes'], 99);
824
-        // hack because promos admin was loading the edited promotion object in the metaboxes callback
825
-        // which should NOT be generated on non-UI requests like POST updates/inserts
826
-        if (
827
-            $this->class_name === 'Promotions_Admin_Page'
828
-            && ($this->_req_action === 'edit' || $this->_req_action === 'create_new')
829
-        ) {
830
-            $this->addRegisteredMetaBoxes();
831
-        }
832
-        $this->_add_screen_columns();
833
-        // add screen options - global, page child class, and view specific
834
-        $this->_add_global_screen_options();
835
-        $this->_add_screen_options();
836
-        $add_screen_options = "_add_screen_options_{$this->_current_view}";
837
-        if (method_exists($this, $add_screen_options)) {
838
-            $this->{$add_screen_options}();
839
-        }
840
-        // add help tab(s) - set via page_config and qtips.
841
-        $this->_add_help_tabs();
842
-        $this->_add_qtips();
843
-        // add feature_pointers - global, page child class, and view specific
844
-        $this->_add_feature_pointers();
845
-        $this->_add_global_feature_pointers();
846
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
847
-        if (method_exists($this, $add_feature_pointer)) {
848
-            $this->{$add_feature_pointer}();
849
-        }
850
-        // enqueue scripts/styles - global, page class, and view specific
851
-        add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
852
-        add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
853
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
854
-            add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
855
-        }
856
-        add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
857
-        // admin_print_footer_scripts - global, page child class, and view specific.
858
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
859
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
860
-        // is a good use case. Notice the late priority we're giving these
861
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
862
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
863
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
864
-            add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
865
-        }
866
-        // admin footer scripts
867
-        add_action('admin_footer', [$this, 'admin_footer_global'], 99);
868
-        add_action('admin_footer', [$this, 'admin_footer'], 100);
869
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
870
-            add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
871
-        }
872
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
873
-        // targeted hook
874
-        do_action(
875
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
876
-        );
877
-    }
878
-
879
-
880
-    /**
881
-     * _set_defaults
882
-     * This sets some global defaults for class properties.
883
-     */
884
-    private function _set_defaults()
885
-    {
886
-        $this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
887
-        $this->_event                = $this->_template_path = $this->_column_template_path = null;
888
-        $this->_nav_tabs             = $this->_views = $this->_page_routes = [];
889
-        $this->_page_config          = $this->_default_route_query_args = [];
890
-        $this->_default_nav_tab_name = 'overview';
891
-        // init template args
892
-        $this->set_template_args(
893
-            [
894
-                'admin_page_header'  => '',
895
-                'admin_page_content' => '',
896
-                'post_body_content'  => '',
897
-                'before_list_table'  => '',
898
-                'after_list_table'   => '',
899
-            ]
900
-        );
901
-    }
902
-
903
-
904
-    /**
905
-     * route_admin_request
906
-     *
907
-     * @return void
908
-     * @throws InvalidArgumentException
909
-     * @throws InvalidInterfaceException
910
-     * @throws InvalidDataTypeException
911
-     * @throws EE_Error
912
-     * @throws ReflectionException
913
-     * @see    _route_admin_request()
914
-     */
915
-    public function route_admin_request()
916
-    {
917
-        try {
918
-            $this->_route_admin_request();
919
-        } catch (EE_Error $e) {
920
-            $e->get_error();
921
-        }
922
-    }
923
-
924
-
925
-    public function set_wp_page_slug($wp_page_slug)
926
-    {
927
-        $this->_wp_page_slug = $wp_page_slug;
928
-        // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
929
-        if (is_network_admin()) {
930
-            $this->_wp_page_slug .= '-network';
931
-        }
932
-    }
933
-
934
-
935
-    /**
936
-     * _verify_routes
937
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
938
-     * we know if we need to drop out.
939
-     *
940
-     * @return bool
941
-     * @throws EE_Error
942
-     */
943
-    protected function _verify_routes()
944
-    {
945
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
946
-        if (! $this->_current_page && ! $this->request->isAjax()) {
947
-            return false;
948
-        }
949
-        $this->_route = false;
950
-        // check that the page_routes array is not empty
951
-        if (empty($this->_page_routes)) {
952
-            // user error msg
953
-            $error_msg = sprintf(
954
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
955
-                $this->_admin_page_title
956
-            );
957
-            // developer error msg
958
-            $error_msg .= '||' . $error_msg
959
-                          . esc_html__(
960
-                              ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
961
-                              'event_espresso'
962
-                          );
963
-            throw new EE_Error($error_msg);
964
-        }
965
-        // and that the requested page route exists
966
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
967
-            $this->_route        = $this->_page_routes[ $this->_req_action ];
968
-            $this->_route_config = $this->_page_config[ $this->_req_action ] ?? [];
969
-        } else {
970
-            // user error msg
971
-            $error_msg = sprintf(
972
-                esc_html__(
973
-                    'The requested page route does not exist for the %s admin page.',
974
-                    'event_espresso'
975
-                ),
976
-                $this->_admin_page_title
977
-            );
978
-            // developer error msg
979
-            $error_msg .= '||' . $error_msg
980
-                          . sprintf(
981
-                              esc_html__(
982
-                                  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
983
-                                  'event_espresso'
984
-                              ),
985
-                              $this->_req_action
986
-                          );
987
-            throw new EE_Error($error_msg);
988
-        }
989
-        // and that a default route exists
990
-        if (! array_key_exists('default', $this->_page_routes)) {
991
-            // user error msg
992
-            $error_msg = sprintf(
993
-                esc_html__(
994
-                    'A default page route has not been set for the % admin page.',
995
-                    'event_espresso'
996
-                ),
997
-                $this->_admin_page_title
998
-            );
999
-            // developer error msg
1000
-            $error_msg .= '||' . $error_msg
1001
-                          . esc_html__(
1002
-                              ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
1003
-                              'event_espresso'
1004
-                          );
1005
-            throw new EE_Error($error_msg);
1006
-        }
1007
-
1008
-        // first lets' catch if the UI request has EVER been set.
1009
-        if ($this->_is_UI_request === null) {
1010
-            // lets set if this is a UI request or not.
1011
-            $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
1012
-            // wait a minute... we might have a noheader in the route array
1013
-            $this->_is_UI_request = ! (
1014
-                is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
1015
-            )
1016
-                ? $this->_is_UI_request
1017
-                : false;
1018
-        }
1019
-        $this->_set_current_labels();
1020
-        return true;
1021
-    }
1022
-
1023
-
1024
-    /**
1025
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
1026
-     *
1027
-     * @param string $route the route name we're verifying
1028
-     * @return bool we'll throw an exception if this isn't a valid route.
1029
-     * @throws EE_Error
1030
-     */
1031
-    protected function _verify_route($route)
1032
-    {
1033
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
1034
-            return true;
1035
-        }
1036
-        // user error msg
1037
-        $error_msg = sprintf(
1038
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
1039
-            $this->_admin_page_title
1040
-        );
1041
-        // developer error msg
1042
-        $error_msg .= '||' . $error_msg
1043
-                      . sprintf(
1044
-                          esc_html__(
1045
-                              ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
1046
-                              'event_espresso'
1047
-                          ),
1048
-                          $route
1049
-                      );
1050
-        throw new EE_Error($error_msg);
1051
-    }
1052
-
1053
-
1054
-    /**
1055
-     * perform nonce verification
1056
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
1057
-     * using this method (and save retyping!)
1058
-     *
1059
-     * @param string $nonce     The nonce sent
1060
-     * @param string $nonce_ref The nonce reference string (name0)
1061
-     * @return void
1062
-     * @throws EE_Error
1063
-     * @throws InvalidArgumentException
1064
-     * @throws InvalidDataTypeException
1065
-     * @throws InvalidInterfaceException
1066
-     */
1067
-    protected function _verify_nonce($nonce, $nonce_ref)
1068
-    {
1069
-        // verify nonce against expected value
1070
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
1071
-            // these are not the droids you are looking for !!!
1072
-            $msg = sprintf(
1073
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
1074
-                '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
1075
-                '</a>'
1076
-            );
1077
-            if (WP_DEBUG) {
1078
-                $msg .= "\n  ";
1079
-                $msg .= sprintf(
1080
-                    esc_html__(
1081
-                        'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
1082
-                        'event_espresso'
1083
-                    ),
1084
-                    __CLASS__
1085
-                );
1086
-            }
1087
-            if (! $this->request->isAjax()) {
1088
-                wp_die($msg);
1089
-            }
1090
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1091
-            $this->_return_json();
1092
-        }
1093
-    }
1094
-
1095
-
1096
-    /**
1097
-     * _route_admin_request()
1098
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1099
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1100
-     * in the page routes and then will try to load the corresponding method.
1101
-     *
1102
-     * @return void
1103
-     * @throws EE_Error
1104
-     * @throws InvalidArgumentException
1105
-     * @throws InvalidDataTypeException
1106
-     * @throws InvalidInterfaceException
1107
-     * @throws ReflectionException
1108
-     */
1109
-    protected function _route_admin_request()
1110
-    {
1111
-        if (! $this->_is_UI_request) {
1112
-            $this->_verify_routes();
1113
-        }
1114
-        $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
1115
-        if ($this->_req_action !== 'default' && $nonce_check) {
1116
-            // set nonce from post data
1117
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
1118
-            $this->_verify_nonce($nonce, $this->_req_nonce);
1119
-        }
1120
-        // set the nav_tabs array but ONLY if this is  UI_request
1121
-        if ($this->_is_UI_request) {
1122
-            $this->_set_nav_tabs();
1123
-        }
1124
-        // grab callback function
1125
-        $func = is_array($this->_route) && isset($this->_route['func'])
1126
-            ? $this->_route['func']
1127
-            : $this->_route;
1128
-        // check if callback has args
1129
-        $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
1130
-        // action right before calling route
1131
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1132
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1133
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1134
-        }
1135
-        // strip _wp_http_referer from the server REQUEST_URI
1136
-        // else it grows in length on every submission due to recursion,
1137
-        // ultimately causing a "Request-URI Too Large" error
1138
-        $this->request->unSetRequestParam('_wp_http_referer');
1139
-        $this->request->unSetServerParam('_wp_http_referer');
1140
-        $cleaner_request_uri = remove_query_arg(
1141
-            '_wp_http_referer',
1142
-            wp_unslash($this->request->getServerParam('REQUEST_URI'))
1143
-        );
1144
-        $this->request->setRequestParam('_wp_http_referer', $cleaner_request_uri, true);
1145
-        $this->request->setServerParam('REQUEST_URI', $cleaner_request_uri, true);
1146
-        $route_callback = [];
1147
-        if (! empty($func)) {
1148
-            if (is_array($func)) {
1149
-                $route_callback = $func;
1150
-            } elseif (is_string($func)) {
1151
-                if (strpos($func, '::') !== false) {
1152
-                    $route_callback = explode('::', $func);
1153
-                } elseif (method_exists($this, $func)) {
1154
-                    $route_callback = [$this, $func];
1155
-                } else {
1156
-                    $route_callback = $func;
1157
-                }
1158
-            }
1159
-            [$class, $method] = $route_callback;
1160
-            // is it neither a class method NOR a standalone function?
1161
-            if (! is_callable($route_callback)) {
1162
-                // user error msg
1163
-                $error_msg = esc_html__(
1164
-                    'An error occurred. The  requested page route could not be found.',
1165
-                    'event_espresso'
1166
-                );
1167
-                // developer error msg
1168
-                $error_msg .= '||';
1169
-                $error_msg .= sprintf(
1170
-                    esc_html__(
1171
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1172
-                        'event_espresso'
1173
-                    ),
1174
-                    $method
1175
-                );
1176
-                throw new DomainException($error_msg);
1177
-            }
1178
-            if ($class !== $this && ! in_array($this, $args)) {
1179
-                // send along this admin page object for access by addons.
1180
-                $args['admin_page'] = $this;
1181
-            }
1182
-
1183
-            try {
1184
-                call_user_func_array($route_callback, $args);
1185
-            } catch (Throwable $throwable) {
1186
-                $arg_keys = array_keys($args);
1187
-                $nice_args = [];
1188
-                foreach ($args as $key => $arg) {
1189
-                    $nice_args[ $key ] = is_object($arg) ? get_class($arg) : $arg_keys[ $key ];
1190
-                }
1191
-                new ExceptionStackTraceDisplay(
1192
-                        new RuntimeException(
1193
-                            sprintf(
1194
-                                esc_html__(
1195
-                                    'Page route "%1$s" with the supplied arguments (%2$s) threw the following exception: %3$s',
1196
-                                    'event_espresso'
1197
-                                ),
1198
-                                $method,
1199
-                                implode(', ', $nice_args),
1200
-                                $throwable->getMessage()
1201
-                            ),
1202
-                            $throwable->getCode(),
1203
-                            $throwable
1204
-                        )
1205
-                );
1206
-            }
1207
-        }
1208
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1209
-        // then we need to reset the routing properties to the new route.
1210
-        // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1211
-        if (
1212
-            $this->_is_UI_request === false
1213
-            && is_array($this->_route)
1214
-            && ! empty($this->_route['headers_sent_route'])
1215
-        ) {
1216
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1217
-        }
1218
-    }
1219
-
1220
-
1221
-    /**
1222
-     * This method just allows the resetting of page properties in the case where a no headers
1223
-     * route redirects to a headers route in its route config.
1224
-     *
1225
-     * @param string $new_route New (non header) route to redirect to.
1226
-     * @return   void
1227
-     * @throws ReflectionException
1228
-     * @throws InvalidArgumentException
1229
-     * @throws InvalidInterfaceException
1230
-     * @throws InvalidDataTypeException
1231
-     * @throws EE_Error
1232
-     * @since   4.3.0
1233
-     */
1234
-    protected function _reset_routing_properties($new_route)
1235
-    {
1236
-        $this->_is_UI_request = true;
1237
-        // now we set the current route to whatever the headers_sent_route is set at
1238
-        $this->request->setRequestParam('action', $new_route);
1239
-        // rerun page setup
1240
-        $this->_page_setup();
1241
-    }
1242
-
1243
-
1244
-    /**
1245
-     * _add_query_arg
1246
-     * adds nonce to array of arguments then calls WP add_query_arg function
1247
-     *(internally just uses EEH_URL's function with the same name)
1248
-     *
1249
-     * @param array  $args
1250
-     * @param string $url
1251
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1252
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1253
-     *                                        Example usage: If the current page is:
1254
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1255
-     *                                        &action=default&event_id=20&month_range=March%202015
1256
-     *                                        &_wpnonce=5467821
1257
-     *                                        and you call:
1258
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1259
-     *                                        array(
1260
-     *                                        'action' => 'resend_something',
1261
-     *                                        'page=>espresso_registrations'
1262
-     *                                        ),
1263
-     *                                        $some_url,
1264
-     *                                        true
1265
-     *                                        );
1266
-     *                                        It will produce a url in this structure:
1267
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1268
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1269
-     *                                        month_range]=March%202015
1270
-     * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1271
-     * @param int    $context
1272
-     * @return string
1273
-     */
1274
-    public static function add_query_args_and_nonce(
1275
-        $args = [],
1276
-        $url = '',
1277
-        $sticky = false,
1278
-        $exclude_nonce = false,
1279
-        int $context = EEH_URL::CONTEXT_NONE
1280
-    ) {
1281
-        // if there is a _wp_http_referer include the values from the request but only if sticky = true
1282
-        if ($sticky) {
1283
-            /** @var RequestInterface $request */
1284
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1285
-            $request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true);
1286
-            $request->unSetServerParam('_wp_http_referer', true);
1287
-            foreach ($request->requestParams() as $key => $value) {
1288
-                // do not add nonces
1289
-                if (strpos($key, 'nonce') !== false) {
1290
-                    continue;
1291
-                }
1292
-                $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1293
-            }
1294
-        }
1295
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce, $context);
1296
-    }
1297
-
1298
-
1299
-    /**
1300
-     * This returns a generated link that will load the related help tab.
1301
-     *
1302
-     * @param string $help_tab_id the id for the connected help tab
1303
-     * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1304
-     * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1305
-     * @return string              generated link
1306
-     * @uses EEH_Template::get_help_tab_link()
1307
-     */
1308
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1309
-    {
1310
-        return EEH_Template::get_help_tab_link(
1311
-            $help_tab_id,
1312
-            $this->page_slug,
1313
-            $this->_req_action,
1314
-            $icon_style,
1315
-            $help_text
1316
-        );
1317
-    }
1318
-
1319
-
1320
-    /**
1321
-     * _add_help_tabs
1322
-     * Note child classes define their help tabs within the page_config array.
1323
-     *
1324
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1325
-     * @return void
1326
-     * @throws DomainException
1327
-     * @throws EE_Error
1328
-     * @throws ReflectionException
1329
-     */
1330
-    protected function _add_help_tabs()
1331
-    {
1332
-        if (isset($this->_page_config[ $this->_req_action ])) {
1333
-            $config = $this->_page_config[ $this->_req_action ];
1334
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1335
-            if (is_array($config) && isset($config['help_sidebar'])) {
1336
-                // check that the callback given is valid
1337
-                if (! method_exists($this, $config['help_sidebar'])) {
1338
-                    throw new EE_Error(
1339
-                        sprintf(
1340
-                            esc_html__(
1341
-                                'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1342
-                                'event_espresso'
1343
-                            ),
1344
-                            $config['help_sidebar'],
1345
-                            $this->class_name
1346
-                        )
1347
-                    );
1348
-                }
1349
-                $content = apply_filters(
1350
-                    'FHEE__' . $this->class_name . '__add_help_tabs__help_sidebar',
1351
-                    $this->{$config['help_sidebar']}()
1352
-                );
1353
-                $this->_current_screen->set_help_sidebar($content);
1354
-            }
1355
-            if (! isset($config['help_tabs'])) {
1356
-                return;
1357
-            } //no help tabs for this route
1358
-            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1359
-                // we're here so there ARE help tabs!
1360
-                // make sure we've got what we need
1361
-                if (! isset($cfg['title'])) {
1362
-                    throw new EE_Error(
1363
-                        esc_html__(
1364
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1365
-                            'event_espresso'
1366
-                        )
1367
-                    );
1368
-                }
1369
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1370
-                    throw new EE_Error(
1371
-                        esc_html__(
1372
-                            'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1373
-                            'event_espresso'
1374
-                        )
1375
-                    );
1376
-                }
1377
-                // first priority goes to content.
1378
-                if (! empty($cfg['content'])) {
1379
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1380
-                    // second priority goes to filename
1381
-                } elseif (! empty($cfg['filename'])) {
1382
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1383
-                    // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1384
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1385
-                                                             . basename($this->_get_dir())
1386
-                                                             . '/help_tabs/'
1387
-                                                             . $cfg['filename']
1388
-                                                             . '.help_tab.php' : $file_path;
1389
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1390
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1391
-                        EE_Error::add_error(
1392
-                            sprintf(
1393
-                                esc_html__(
1394
-                                    'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1395
-                                    'event_espresso'
1396
-                                ),
1397
-                                $tab_id,
1398
-                                key($config),
1399
-                                $file_path
1400
-                            ),
1401
-                            __FILE__,
1402
-                            __FUNCTION__,
1403
-                            __LINE__
1404
-                        );
1405
-                        return;
1406
-                    }
1407
-                    $template_args['admin_page_obj'] = $this;
1408
-                    $content                         = EEH_Template::display_template(
1409
-                        $file_path,
1410
-                        $template_args,
1411
-                        true
1412
-                    );
1413
-                } else {
1414
-                    $content = '';
1415
-                }
1416
-                // check if callback is valid
1417
-                if (
1418
-                    empty($content)
1419
-                    && (
1420
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1421
-                    )
1422
-                ) {
1423
-                    EE_Error::add_error(
1424
-                        sprintf(
1425
-                            esc_html__(
1426
-                                'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1427
-                                'event_espresso'
1428
-                            ),
1429
-                            $cfg['title']
1430
-                        ),
1431
-                        __FILE__,
1432
-                        __FUNCTION__,
1433
-                        __LINE__
1434
-                    );
1435
-                    return;
1436
-                }
1437
-                // setup config array for help tab method
1438
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1439
-                $_ht = [
1440
-                    'id'       => $id,
1441
-                    'title'    => $cfg['title'],
1442
-                    'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1443
-                    'content'  => $content,
1444
-                ];
1445
-                $this->_current_screen->add_help_tab($_ht);
1446
-            }
1447
-        }
1448
-    }
1449
-
1450
-
1451
-    /**
1452
-     * This simply sets up any qtips that have been defined in the page config
1453
-     *
1454
-     * @return void
1455
-     * @throws ReflectionException
1456
-     * @throws EE_Error
1457
-     */
1458
-    protected function _add_qtips()
1459
-    {
1460
-        if (isset($this->_route_config['qtips'])) {
1461
-            $qtips = (array) $this->_route_config['qtips'];
1462
-            // load qtip loader
1463
-            $path = [
1464
-                $this->_get_dir() . '/qtips/',
1465
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1466
-            ];
1467
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1468
-        }
1469
-    }
1470
-
1471
-
1472
-    /**
1473
-     * _set_nav_tabs
1474
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1475
-     * wish to add additional tabs or modify accordingly.
1476
-     *
1477
-     * @return void
1478
-     * @throws InvalidArgumentException
1479
-     * @throws InvalidInterfaceException
1480
-     * @throws InvalidDataTypeException
1481
-     */
1482
-    protected function _set_nav_tabs()
1483
-    {
1484
-        $i        = 0;
1485
-        $only_tab = count($this->_page_config) < 2;
1486
-        foreach ($this->_page_config as $slug => $config) {
1487
-            if (! is_array($config) || empty($config['nav'])) {
1488
-                continue;
1489
-            }
1490
-            // no nav tab for this config
1491
-            // check for persistent flag
1492
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1493
-                // nav tab is only to appear when route requested.
1494
-                continue;
1495
-            }
1496
-            if (! $this->check_user_access($slug, true)) {
1497
-                // no nav tab because current user does not have access.
1498
-                continue;
1499
-            }
1500
-            $css_class = $config['css_class'] ?? '';
1501
-            $css_class .= $only_tab ? ' ee-only-tab' : '';
1502
-            $css_class .= " ee-nav-tab__$slug";
1503
-
1504
-            $this->_nav_tabs[ $slug ] = [
1505
-                'url'       => $config['nav']['url'] ?? EE_Admin_Page::add_query_args_and_nonce(
1506
-                        ['action' => $slug],
1507
-                        $this->_admin_base_url
1508
-                    ),
1509
-                'link_text' => $this->navTabLabel($config['nav'], $slug),
1510
-                'css_class' => $this->_req_action === $slug ? $css_class . ' nav-tab-active' : $css_class,
1511
-                'order'     => $config['nav']['order'] ?? $i,
1512
-            ];
1513
-            $i++;
1514
-        }
1515
-        // if $this->_nav_tabs is empty then lets set the default
1516
-        if (empty($this->_nav_tabs)) {
1517
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1518
-                'url'       => $this->_admin_base_url,
1519
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1520
-                'css_class' => 'nav-tab-active',
1521
-                'order'     => 10,
1522
-            ];
1523
-        }
1524
-        // now let's sort the tabs according to order
1525
-        usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1526
-    }
1527
-
1528
-
1529
-    private function navTabLabel(array $nav_tab, string $slug): string
1530
-    {
1531
-        $label = $nav_tab['label'] ?? ucwords(str_replace('_', ' ', $slug));
1532
-        $icon  = $nav_tab['icon'] ?? null;
1533
-        $icon  = $icon ? '<span class="dashicons ' . $icon . '"></span>' : '';
1534
-        return '
144
+	/**
145
+	 * unprocessed value for the 'page' request param (default '')
146
+	 *
147
+	 * @var string
148
+	 */
149
+	protected $raw_req_page = '';
150
+
151
+	/**
152
+	 * sanitized request action (and nonce)
153
+	 *
154
+	 * @var string
155
+	 */
156
+	protected $_req_action = '';
157
+
158
+	/**
159
+	 * sanitized request action nonce
160
+	 *
161
+	 * @var string
162
+	 */
163
+	protected $_req_nonce = '';
164
+
165
+	/**
166
+	 * @var string
167
+	 */
168
+	protected $_search_btn_label = '';
169
+
170
+	/**
171
+	 * @var string
172
+	 */
173
+	protected $_search_box_callback = '';
174
+
175
+	/**
176
+	 * @var WP_Screen
177
+	 */
178
+	protected $_current_screen;
179
+
180
+	// for holding EE_Admin_Hooks object when needed (set via set_hook_object())
181
+	protected $_hook_obj;
182
+
183
+	// for holding incoming request data
184
+	protected $_req_data = [];
185
+
186
+	// yes / no array for admin form fields
187
+	protected $_yes_no_values = [];
188
+
189
+	// some default things shared by all child classes
190
+	protected $_default_espresso_metaboxes = [
191
+		'_espresso_news_post_box',
192
+		'_espresso_links_post_box',
193
+		'_espresso_ratings_request',
194
+		'_espresso_sponsors_post_box',
195
+	];
196
+
197
+	/**
198
+	 * @var EE_Registry
199
+	 */
200
+	protected $EE;
201
+
202
+
203
+	/**
204
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
205
+	 *
206
+	 * @var boolean
207
+	 */
208
+	protected $_is_caf = false;
209
+
210
+	/**
211
+	 * whether or not initializePage() has run
212
+	 *
213
+	 * @var boolean
214
+	 */
215
+	protected $initialized = false;
216
+
217
+	/**
218
+	 * @var FeatureFlags
219
+	 */
220
+	protected $feature;
221
+
222
+
223
+	/**
224
+	 * @var string
225
+	 */
226
+	protected $class_name;
227
+
228
+	/**
229
+	 * if the current class is an admin page extension, like: Extend_Events_Admin_Page,
230
+	 * then this would be the parent classname: Events_Admin_Page
231
+	 *
232
+	 * @var string
233
+	 */
234
+	protected $base_class_name;
235
+
236
+	/**
237
+	 * @var array
238
+	 * @since 5.0.0.p
239
+	 */
240
+	private $publish_post_meta_box_hidden_fields = [];
241
+
242
+
243
+	/**
244
+	 * @Constructor
245
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
246
+	 * @throws InvalidArgumentException
247
+	 * @throws InvalidDataTypeException
248
+	 * @throws InvalidInterfaceException
249
+	 * @throws ReflectionException
250
+	 */
251
+	public function __construct($routing = true)
252
+	{
253
+		$this->loader       = LoaderFactory::getLoader();
254
+		$this->admin_config = $this->loader->getShared('EE_Admin_Config');
255
+		$this->feature      = $this->loader->getShared(FeatureFlags::class);
256
+		$this->request      = $this->loader->getShared(RequestInterface::class);
257
+		// routing enabled?
258
+		$this->_routing = $routing;
259
+
260
+		$this->class_name      = get_class($this);
261
+		$this->base_class_name = strpos($this->class_name, 'Extend_') === 0
262
+			? str_replace('Extend_', '', $this->class_name)
263
+			: '';
264
+
265
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
266
+			$this->_is_caf = true;
267
+		}
268
+		$this->_yes_no_values = [
269
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
270
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
271
+		];
272
+		// set the _req_data property.
273
+		$this->_req_data = $this->request->requestParams();
274
+	}
275
+
276
+
277
+	/**
278
+	 * @return EE_Admin_Config
279
+	 */
280
+	public function adminConfig(): EE_Admin_Config
281
+	{
282
+		return $this->admin_config;
283
+	}
284
+
285
+
286
+	/**
287
+	 * @return FeatureFlags
288
+	 */
289
+	public function feature(): FeatureFlags
290
+	{
291
+		return $this->feature;
292
+	}
293
+
294
+
295
+	/**
296
+	 * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
297
+	 * for child classes that needed to set properties prior to these methods getting called,
298
+	 * but also needed the parent class to have its construction completed as well.
299
+	 * Bottom line is that constructors should ONLY be used for setting initial properties
300
+	 * and any complex initialization logic should only run after instantiation is complete.
301
+	 *
302
+	 * This method gets called immediately after construction from within
303
+	 *      EE_Admin_Page_Init::_initialize_admin_page()
304
+	 *
305
+	 * @throws EE_Error
306
+	 * @throws InvalidArgumentException
307
+	 * @throws InvalidDataTypeException
308
+	 * @throws InvalidInterfaceException
309
+	 * @throws ReflectionException
310
+	 * @since 5.0.0.p
311
+	 */
312
+	public function initializePage()
313
+	{
314
+		if ($this->initialized) {
315
+			return;
316
+		}
317
+		// set initial page props (child method)
318
+		$this->_init_page_props();
319
+		// set global defaults
320
+		$this->_set_defaults();
321
+		// set early because incoming requests could be ajax related and we need to register those hooks.
322
+		$this->_global_ajax_hooks();
323
+		$this->_ajax_hooks();
324
+		// other_page_hooks have to be early too.
325
+		$this->_do_other_page_hooks();
326
+		// set up page dependencies
327
+		$this->_before_page_setup();
328
+		$this->_page_setup();
329
+		$this->initialized = true;
330
+	}
331
+
332
+
333
+	/**
334
+	 * _init_page_props
335
+	 * Child classes use to set at least the following properties:
336
+	 * $page_slug.
337
+	 * $page_label.
338
+	 *
339
+	 * @abstract
340
+	 * @return void
341
+	 */
342
+	abstract protected function _init_page_props();
343
+
344
+
345
+	/**
346
+	 * _ajax_hooks
347
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
348
+	 * Note: within the ajax callback methods.
349
+	 *
350
+	 * @abstract
351
+	 * @return void
352
+	 */
353
+	abstract protected function _ajax_hooks();
354
+
355
+
356
+	/**
357
+	 * _define_page_props
358
+	 * child classes define page properties in here.  Must include at least:
359
+	 * $_admin_base_url = base_url for all admin pages
360
+	 * $_admin_page_title = default admin_page_title for admin pages
361
+	 * $_labels = array of default labels for various automatically generated elements:
362
+	 *    array(
363
+	 *        'buttons' => array(
364
+	 *            'add' => esc_html__('label for add new button'),
365
+	 *            'edit' => esc_html__('label for edit button'),
366
+	 *            'delete' => esc_html__('label for delete button')
367
+	 *            )
368
+	 *        )
369
+	 *
370
+	 * @abstract
371
+	 * @return void
372
+	 */
373
+	abstract protected function _define_page_props();
374
+
375
+
376
+	/**
377
+	 * _set_page_routes
378
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
379
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
380
+	 * have a 'default' route. Here's the format
381
+	 * $this->_page_routes = array(
382
+	 *        'default' => array(
383
+	 *            'func' => '_default_method_handling_route',
384
+	 *            'args' => array('array','of','args'),
385
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
386
+	 *            ajax request, backend processing)
387
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
388
+	 *            headers route after.  The string you enter here should match the defined route reference for a
389
+	 *            headers sent route.
390
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
391
+	 *            this route.
392
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
393
+	 *            checks).
394
+	 *        ),
395
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
396
+	 *        handling method.
397
+	 *        )
398
+	 * )
399
+	 *
400
+	 * @abstract
401
+	 * @return void
402
+	 */
403
+	abstract protected function _set_page_routes();
404
+
405
+
406
+	/**
407
+	 * _set_page_config
408
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
409
+	 * array corresponds to the page_route for the loaded page. Format:
410
+	 * $this->_page_config = array(
411
+	 *        'default' => array(
412
+	 *            'labels' => array(
413
+	 *                'buttons' => array(
414
+	 *                    'add' => esc_html__('label for adding item'),
415
+	 *                    'edit' => esc_html__('label for editing item'),
416
+	 *                    'delete' => esc_html__('label for deleting item')
417
+	 *                ),
418
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
419
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
420
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
421
+	 *            _define_page_props() method
422
+	 *            'nav' => array(
423
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
424
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
425
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
426
+	 *                'order' => 10, //required to indicate tab position.
427
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
428
+	 *                displayed then add this parameter.
429
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
430
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
431
+	 *            metaboxes set for eventespresso admin pages.
432
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
433
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
434
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
435
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
436
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
437
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
438
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
439
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
440
+	 *            want to display.
441
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
442
+	 *                'tab_id' => array(
443
+	 *                    'title' => 'tab_title',
444
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
445
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
446
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
447
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
448
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
449
+	 *                    attempt to use the callback which should match the name of a method in the class
450
+	 *                    ),
451
+	 *                'tab2_id' => array(
452
+	 *                    'title' => 'tab2 title',
453
+	 *                    'filename' => 'file_name_2'
454
+	 *                    'callback' => 'callback_method_for_content',
455
+	 *                 ),
456
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
457
+	 *            help tab area on an admin page. @return void
458
+	 *
459
+	 * @abstract
460
+	 */
461
+	abstract protected function _set_page_config();
462
+
463
+
464
+	/**
465
+	 * _add_screen_options
466
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
467
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
468
+	 * to a particular view.
469
+	 *
470
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
471
+	 *         see also WP_Screen object documents...
472
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
473
+	 * @abstract
474
+	 * @return void
475
+	 */
476
+	abstract protected function _add_screen_options();
477
+
478
+
479
+	/**
480
+	 * _add_feature_pointers
481
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
482
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
483
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
484
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
485
+	 * extended) also see:
486
+	 *
487
+	 * @link   http://eamann.com/tech/wordpress-portland/
488
+	 * @abstract
489
+	 * @return void
490
+	 */
491
+	abstract protected function _add_feature_pointers();
492
+
493
+
494
+	/**
495
+	 * load_scripts_styles
496
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
497
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
498
+	 * scripts/styles per view by putting them in a dynamic function in this format
499
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
500
+	 *
501
+	 * @abstract
502
+	 * @return void
503
+	 */
504
+	abstract public function load_scripts_styles();
505
+
506
+
507
+	/**
508
+	 * admin_init
509
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
510
+	 * all pages/views loaded by child class.
511
+	 *
512
+	 * @abstract
513
+	 * @return void
514
+	 */
515
+	abstract public function admin_init();
516
+
517
+
518
+	/**
519
+	 * admin_notices
520
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
521
+	 * all pages/views loaded by child class.
522
+	 *
523
+	 * @abstract
524
+	 * @return void
525
+	 */
526
+	abstract public function admin_notices();
527
+
528
+
529
+	/**
530
+	 * admin_footer_scripts
531
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
532
+	 * will apply to all pages/views loaded by child class.
533
+	 *
534
+	 * @return void
535
+	 */
536
+	abstract public function admin_footer_scripts();
537
+
538
+
539
+	/**
540
+	 * admin_footer
541
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
542
+	 * apply to all pages/views loaded by child class.
543
+	 *
544
+	 * @return void
545
+	 */
546
+	public function admin_footer()
547
+	{
548
+	}
549
+
550
+
551
+	/**
552
+	 * _global_ajax_hooks
553
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
554
+	 * Note: within the ajax callback methods.
555
+	 *
556
+	 * @abstract
557
+	 * @return void
558
+	 */
559
+	protected function _global_ajax_hooks()
560
+	{
561
+		// for lazy loading of metabox content
562
+		add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
563
+
564
+		add_action(
565
+			'wp_ajax_espresso_hide_status_change_notice',
566
+			[$this, 'hideStatusChangeNotice']
567
+		);
568
+		add_action(
569
+			'wp_ajax_nopriv_espresso_hide_status_change_notice',
570
+			[$this, 'hideStatusChangeNotice']
571
+		);
572
+	}
573
+
574
+
575
+	public function ajax_metabox_content()
576
+	{
577
+		$content_id  = $this->request->getRequestParam('contentid', '');
578
+		$content_url = $this->request->getRequestParam('contenturl', '', 'url');
579
+		EE_Admin_Page::cached_rss_display($content_id, $content_url);
580
+		wp_die();
581
+	}
582
+
583
+
584
+	public function hideStatusChangeNotice()
585
+	{
586
+		$response = [];
587
+		try {
588
+			/** @var StatusChangeNotice $status_change_notice */
589
+			$status_change_notice = $this->loader->getShared(
590
+				'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
591
+			);
592
+			$response['success']  = $status_change_notice->dismiss() > -1;
593
+		} catch (Exception $exception) {
594
+			$response['errors'] = $exception->getMessage();
595
+		}
596
+		echo wp_json_encode($response);
597
+		exit();
598
+	}
599
+
600
+
601
+	/**
602
+	 * allows extending classes do something specific before the parent constructor runs _page_setup().
603
+	 *
604
+	 * @return void
605
+	 */
606
+	protected function _before_page_setup()
607
+	{
608
+		// default is to do nothing
609
+	}
610
+
611
+
612
+	/**
613
+	 * Makes sure any things that need to be loaded early get handled.
614
+	 * We also escape early here if the page requested doesn't match the object.
615
+	 *
616
+	 * @final
617
+	 * @return void
618
+	 * @throws EE_Error
619
+	 * @throws InvalidArgumentException
620
+	 * @throws ReflectionException
621
+	 * @throws InvalidDataTypeException
622
+	 * @throws InvalidInterfaceException
623
+	 */
624
+	final protected function _page_setup()
625
+	{
626
+		// requires?
627
+		// admin_init stuff - global - we're setting this REALLY early
628
+		// so if EE_Admin pages have to hook into other WP pages they can.
629
+		// But keep in mind, not everything is available from the EE_Admin Page object at this point.
630
+		add_action('admin_init', [$this, 'admin_init_global'], 5);
631
+		// next verify if we need to load anything...
632
+		$this->_current_page = $this->request->getRequestParam('page', '', 'key');
633
+		$this->_current_page = $this->request->getRequestParam('current_page', $this->_current_page, 'key');
634
+		$this->page_folder   = strtolower(
635
+			str_replace(['_Admin_Page', 'Extend_'], '', $this->class_name)
636
+		);
637
+		global $ee_menu_slugs;
638
+		$ee_menu_slugs = (array) $ee_menu_slugs;
639
+		if (
640
+			! $this->request->isAjax()
641
+			&& (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
642
+		) {
643
+			return;
644
+		}
645
+		// because WP List tables have two duplicate select inputs for choosing bulk actions,
646
+		// we need to copy the action from the second to the first
647
+		$action     = $this->request->getRequestParam('action', '-1', 'key');
648
+		$action2    = $this->request->getRequestParam('action2', '-1', 'key');
649
+		$action     = $action !== '-1' ? $action : $action2;
650
+		$req_action = $action !== '-1' ? $action : 'default';
651
+
652
+		// if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
653
+		// then let's use the route as the action.
654
+		// This covers cases where we're coming in from a list table that isn't on the default route.
655
+		$route             = $this->request->getRequestParam('route');
656
+		$this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
657
+			? $route
658
+			: $req_action;
659
+
660
+		$this->_current_view = $this->_req_action;
661
+		$this->_req_nonce    = $this->_req_action . '_nonce';
662
+		$this->_define_page_props();
663
+		$this->_current_page_view_url = add_query_arg(
664
+			['page' => $this->_current_page, 'action' => $this->_current_view],
665
+			$this->_admin_base_url
666
+		);
667
+		// set page configs
668
+		$this->_set_page_routes();
669
+		$this->_set_page_config();
670
+		// let's include any referrer data in our default_query_args for this route for "stickiness".
671
+		if ($this->request->requestParamIsSet('wp_referer')) {
672
+			$wp_referer = $this->request->getRequestParam('wp_referer');
673
+			if ($wp_referer) {
674
+				$this->_default_route_query_args['wp_referer'] = $wp_referer;
675
+			}
676
+		}
677
+		// for CPT and other extended functionality.
678
+		// If there is an _extend_page_config_for_cpt
679
+		// then let's run that to modify all the various page configuration arrays.
680
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
681
+			$this->_extend_page_config_for_cpt();
682
+		}
683
+		// filter routes and page_config so addons can add their stuff. Filtering done per class
684
+		$this->_page_routes = apply_filters(
685
+			'FHEE__' . $this->class_name . '__page_setup__page_routes',
686
+			$this->_page_routes,
687
+			$this
688
+		);
689
+		$this->_page_config = apply_filters(
690
+			'FHEE__' . $this->class_name . '__page_setup__page_config',
691
+			$this->_page_config,
692
+			$this
693
+		);
694
+		if ($this->base_class_name !== '') {
695
+			$this->_page_routes = apply_filters(
696
+				'FHEE__' . $this->base_class_name . '__page_setup__page_routes',
697
+				$this->_page_routes,
698
+				$this
699
+			);
700
+			$this->_page_config = apply_filters(
701
+				'FHEE__' . $this->base_class_name . '__page_setup__page_config',
702
+				$this->_page_config,
703
+				$this
704
+			);
705
+		}
706
+		// if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
707
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
708
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
709
+			add_action(
710
+				'AHEE__EE_Admin_Page__route_admin_request',
711
+				[$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
712
+				10,
713
+				2
714
+			);
715
+		}
716
+		// next route only if routing enabled
717
+		if ($this->_routing && ! $this->request->isAjax()) {
718
+			$this->_verify_routes();
719
+			// next let's just check user_access and kill if no access
720
+			$this->check_user_access();
721
+			if ($this->_is_UI_request) {
722
+				// admin_init stuff - global, all views for this page class, specific view
723
+				add_action('admin_init', [$this, 'admin_init'], 10);
724
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
725
+					add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
726
+				}
727
+			} else {
728
+				// hijack regular WP loading and route admin request immediately
729
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
730
+				$this->route_admin_request();
731
+			}
732
+		}
733
+	}
734
+
735
+
736
+	/**
737
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
738
+	 *
739
+	 * @return void
740
+	 * @throws EE_Error
741
+	 */
742
+	private function _do_other_page_hooks()
743
+	{
744
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
745
+		foreach ($registered_pages as $page) {
746
+			// now let's setup the file name and class that should be present
747
+			$classname = str_replace('.class.php', '', $page);
748
+			// autoloaders should take care of loading file
749
+			if (! class_exists($classname)) {
750
+				$error_msg[] = sprintf(
751
+					esc_html__(
752
+						'Something went wrong with loading the %s admin hooks page.',
753
+						'event_espresso'
754
+					),
755
+					$page
756
+				);
757
+				$error_msg[] = $error_msg[0]
758
+							   . "\r\n"
759
+							   . sprintf(
760
+								   esc_html__(
761
+									   'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
762
+									   'event_espresso'
763
+								   ),
764
+								   $page,
765
+								   '<br />',
766
+								   '<strong>' . $classname . '</strong>'
767
+							   );
768
+				throw new EE_Error(implode('||', $error_msg));
769
+			}
770
+			// notice we are passing the instance of this class to the hook object.
771
+			$this->loader->getShared($classname, [$this]);
772
+		}
773
+	}
774
+
775
+
776
+	/**
777
+	 * @throws ReflectionException
778
+	 * @throws EE_Error
779
+	 */
780
+	public function load_page_dependencies()
781
+	{
782
+		try {
783
+			$this->_load_page_dependencies();
784
+		} catch (EE_Error $e) {
785
+			$e->get_error();
786
+		}
787
+	}
788
+
789
+
790
+	/**
791
+	 * load_page_dependencies
792
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
793
+	 *
794
+	 * @return void
795
+	 * @throws DomainException
796
+	 * @throws EE_Error
797
+	 * @throws InvalidArgumentException
798
+	 * @throws InvalidDataTypeException
799
+	 * @throws InvalidInterfaceException
800
+	 * @throws ReflectionException
801
+	 */
802
+	protected function _load_page_dependencies()
803
+	{
804
+		// let's set the current_screen and screen options to override what WP set
805
+		$this->_current_screen = get_current_screen();
806
+		// load admin_notices - global, page class, and view specific
807
+		add_action('admin_notices', [$this, 'admin_notices_global'], 5);
808
+		add_action('admin_notices', [$this, 'admin_notices'], 10);
809
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
810
+			add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
811
+		}
812
+		// load network admin_notices - global, page class, and view specific
813
+		add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
814
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
815
+			add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
816
+		}
817
+		// this will save any per_page screen options if they are present
818
+		$this->_set_per_page_screen_options();
819
+		// setup list table properties
820
+		$this->_set_list_table();
821
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
822
+		// However in some cases the metaboxes will need to be added within a route handling callback.
823
+		add_action('add_meta_boxes', [$this, 'addRegisteredMetaBoxes'], 99);
824
+		// hack because promos admin was loading the edited promotion object in the metaboxes callback
825
+		// which should NOT be generated on non-UI requests like POST updates/inserts
826
+		if (
827
+			$this->class_name === 'Promotions_Admin_Page'
828
+			&& ($this->_req_action === 'edit' || $this->_req_action === 'create_new')
829
+		) {
830
+			$this->addRegisteredMetaBoxes();
831
+		}
832
+		$this->_add_screen_columns();
833
+		// add screen options - global, page child class, and view specific
834
+		$this->_add_global_screen_options();
835
+		$this->_add_screen_options();
836
+		$add_screen_options = "_add_screen_options_{$this->_current_view}";
837
+		if (method_exists($this, $add_screen_options)) {
838
+			$this->{$add_screen_options}();
839
+		}
840
+		// add help tab(s) - set via page_config and qtips.
841
+		$this->_add_help_tabs();
842
+		$this->_add_qtips();
843
+		// add feature_pointers - global, page child class, and view specific
844
+		$this->_add_feature_pointers();
845
+		$this->_add_global_feature_pointers();
846
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
847
+		if (method_exists($this, $add_feature_pointer)) {
848
+			$this->{$add_feature_pointer}();
849
+		}
850
+		// enqueue scripts/styles - global, page class, and view specific
851
+		add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
852
+		add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
853
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
854
+			add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
855
+		}
856
+		add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
857
+		// admin_print_footer_scripts - global, page child class, and view specific.
858
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
859
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
860
+		// is a good use case. Notice the late priority we're giving these
861
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
862
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
863
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
864
+			add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
865
+		}
866
+		// admin footer scripts
867
+		add_action('admin_footer', [$this, 'admin_footer_global'], 99);
868
+		add_action('admin_footer', [$this, 'admin_footer'], 100);
869
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
870
+			add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
871
+		}
872
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
873
+		// targeted hook
874
+		do_action(
875
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
876
+		);
877
+	}
878
+
879
+
880
+	/**
881
+	 * _set_defaults
882
+	 * This sets some global defaults for class properties.
883
+	 */
884
+	private function _set_defaults()
885
+	{
886
+		$this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
887
+		$this->_event                = $this->_template_path = $this->_column_template_path = null;
888
+		$this->_nav_tabs             = $this->_views = $this->_page_routes = [];
889
+		$this->_page_config          = $this->_default_route_query_args = [];
890
+		$this->_default_nav_tab_name = 'overview';
891
+		// init template args
892
+		$this->set_template_args(
893
+			[
894
+				'admin_page_header'  => '',
895
+				'admin_page_content' => '',
896
+				'post_body_content'  => '',
897
+				'before_list_table'  => '',
898
+				'after_list_table'   => '',
899
+			]
900
+		);
901
+	}
902
+
903
+
904
+	/**
905
+	 * route_admin_request
906
+	 *
907
+	 * @return void
908
+	 * @throws InvalidArgumentException
909
+	 * @throws InvalidInterfaceException
910
+	 * @throws InvalidDataTypeException
911
+	 * @throws EE_Error
912
+	 * @throws ReflectionException
913
+	 * @see    _route_admin_request()
914
+	 */
915
+	public function route_admin_request()
916
+	{
917
+		try {
918
+			$this->_route_admin_request();
919
+		} catch (EE_Error $e) {
920
+			$e->get_error();
921
+		}
922
+	}
923
+
924
+
925
+	public function set_wp_page_slug($wp_page_slug)
926
+	{
927
+		$this->_wp_page_slug = $wp_page_slug;
928
+		// if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
929
+		if (is_network_admin()) {
930
+			$this->_wp_page_slug .= '-network';
931
+		}
932
+	}
933
+
934
+
935
+	/**
936
+	 * _verify_routes
937
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
938
+	 * we know if we need to drop out.
939
+	 *
940
+	 * @return bool
941
+	 * @throws EE_Error
942
+	 */
943
+	protected function _verify_routes()
944
+	{
945
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
946
+		if (! $this->_current_page && ! $this->request->isAjax()) {
947
+			return false;
948
+		}
949
+		$this->_route = false;
950
+		// check that the page_routes array is not empty
951
+		if (empty($this->_page_routes)) {
952
+			// user error msg
953
+			$error_msg = sprintf(
954
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
955
+				$this->_admin_page_title
956
+			);
957
+			// developer error msg
958
+			$error_msg .= '||' . $error_msg
959
+						  . esc_html__(
960
+							  ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
961
+							  'event_espresso'
962
+						  );
963
+			throw new EE_Error($error_msg);
964
+		}
965
+		// and that the requested page route exists
966
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
967
+			$this->_route        = $this->_page_routes[ $this->_req_action ];
968
+			$this->_route_config = $this->_page_config[ $this->_req_action ] ?? [];
969
+		} else {
970
+			// user error msg
971
+			$error_msg = sprintf(
972
+				esc_html__(
973
+					'The requested page route does not exist for the %s admin page.',
974
+					'event_espresso'
975
+				),
976
+				$this->_admin_page_title
977
+			);
978
+			// developer error msg
979
+			$error_msg .= '||' . $error_msg
980
+						  . sprintf(
981
+							  esc_html__(
982
+								  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
983
+								  'event_espresso'
984
+							  ),
985
+							  $this->_req_action
986
+						  );
987
+			throw new EE_Error($error_msg);
988
+		}
989
+		// and that a default route exists
990
+		if (! array_key_exists('default', $this->_page_routes)) {
991
+			// user error msg
992
+			$error_msg = sprintf(
993
+				esc_html__(
994
+					'A default page route has not been set for the % admin page.',
995
+					'event_espresso'
996
+				),
997
+				$this->_admin_page_title
998
+			);
999
+			// developer error msg
1000
+			$error_msg .= '||' . $error_msg
1001
+						  . esc_html__(
1002
+							  ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
1003
+							  'event_espresso'
1004
+						  );
1005
+			throw new EE_Error($error_msg);
1006
+		}
1007
+
1008
+		// first lets' catch if the UI request has EVER been set.
1009
+		if ($this->_is_UI_request === null) {
1010
+			// lets set if this is a UI request or not.
1011
+			$this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
1012
+			// wait a minute... we might have a noheader in the route array
1013
+			$this->_is_UI_request = ! (
1014
+				is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
1015
+			)
1016
+				? $this->_is_UI_request
1017
+				: false;
1018
+		}
1019
+		$this->_set_current_labels();
1020
+		return true;
1021
+	}
1022
+
1023
+
1024
+	/**
1025
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
1026
+	 *
1027
+	 * @param string $route the route name we're verifying
1028
+	 * @return bool we'll throw an exception if this isn't a valid route.
1029
+	 * @throws EE_Error
1030
+	 */
1031
+	protected function _verify_route($route)
1032
+	{
1033
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
1034
+			return true;
1035
+		}
1036
+		// user error msg
1037
+		$error_msg = sprintf(
1038
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
1039
+			$this->_admin_page_title
1040
+		);
1041
+		// developer error msg
1042
+		$error_msg .= '||' . $error_msg
1043
+					  . sprintf(
1044
+						  esc_html__(
1045
+							  ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
1046
+							  'event_espresso'
1047
+						  ),
1048
+						  $route
1049
+					  );
1050
+		throw new EE_Error($error_msg);
1051
+	}
1052
+
1053
+
1054
+	/**
1055
+	 * perform nonce verification
1056
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
1057
+	 * using this method (and save retyping!)
1058
+	 *
1059
+	 * @param string $nonce     The nonce sent
1060
+	 * @param string $nonce_ref The nonce reference string (name0)
1061
+	 * @return void
1062
+	 * @throws EE_Error
1063
+	 * @throws InvalidArgumentException
1064
+	 * @throws InvalidDataTypeException
1065
+	 * @throws InvalidInterfaceException
1066
+	 */
1067
+	protected function _verify_nonce($nonce, $nonce_ref)
1068
+	{
1069
+		// verify nonce against expected value
1070
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
1071
+			// these are not the droids you are looking for !!!
1072
+			$msg = sprintf(
1073
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
1074
+				'<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
1075
+				'</a>'
1076
+			);
1077
+			if (WP_DEBUG) {
1078
+				$msg .= "\n  ";
1079
+				$msg .= sprintf(
1080
+					esc_html__(
1081
+						'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
1082
+						'event_espresso'
1083
+					),
1084
+					__CLASS__
1085
+				);
1086
+			}
1087
+			if (! $this->request->isAjax()) {
1088
+				wp_die($msg);
1089
+			}
1090
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1091
+			$this->_return_json();
1092
+		}
1093
+	}
1094
+
1095
+
1096
+	/**
1097
+	 * _route_admin_request()
1098
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1099
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1100
+	 * in the page routes and then will try to load the corresponding method.
1101
+	 *
1102
+	 * @return void
1103
+	 * @throws EE_Error
1104
+	 * @throws InvalidArgumentException
1105
+	 * @throws InvalidDataTypeException
1106
+	 * @throws InvalidInterfaceException
1107
+	 * @throws ReflectionException
1108
+	 */
1109
+	protected function _route_admin_request()
1110
+	{
1111
+		if (! $this->_is_UI_request) {
1112
+			$this->_verify_routes();
1113
+		}
1114
+		$nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
1115
+		if ($this->_req_action !== 'default' && $nonce_check) {
1116
+			// set nonce from post data
1117
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
1118
+			$this->_verify_nonce($nonce, $this->_req_nonce);
1119
+		}
1120
+		// set the nav_tabs array but ONLY if this is  UI_request
1121
+		if ($this->_is_UI_request) {
1122
+			$this->_set_nav_tabs();
1123
+		}
1124
+		// grab callback function
1125
+		$func = is_array($this->_route) && isset($this->_route['func'])
1126
+			? $this->_route['func']
1127
+			: $this->_route;
1128
+		// check if callback has args
1129
+		$args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
1130
+		// action right before calling route
1131
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1132
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1133
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1134
+		}
1135
+		// strip _wp_http_referer from the server REQUEST_URI
1136
+		// else it grows in length on every submission due to recursion,
1137
+		// ultimately causing a "Request-URI Too Large" error
1138
+		$this->request->unSetRequestParam('_wp_http_referer');
1139
+		$this->request->unSetServerParam('_wp_http_referer');
1140
+		$cleaner_request_uri = remove_query_arg(
1141
+			'_wp_http_referer',
1142
+			wp_unslash($this->request->getServerParam('REQUEST_URI'))
1143
+		);
1144
+		$this->request->setRequestParam('_wp_http_referer', $cleaner_request_uri, true);
1145
+		$this->request->setServerParam('REQUEST_URI', $cleaner_request_uri, true);
1146
+		$route_callback = [];
1147
+		if (! empty($func)) {
1148
+			if (is_array($func)) {
1149
+				$route_callback = $func;
1150
+			} elseif (is_string($func)) {
1151
+				if (strpos($func, '::') !== false) {
1152
+					$route_callback = explode('::', $func);
1153
+				} elseif (method_exists($this, $func)) {
1154
+					$route_callback = [$this, $func];
1155
+				} else {
1156
+					$route_callback = $func;
1157
+				}
1158
+			}
1159
+			[$class, $method] = $route_callback;
1160
+			// is it neither a class method NOR a standalone function?
1161
+			if (! is_callable($route_callback)) {
1162
+				// user error msg
1163
+				$error_msg = esc_html__(
1164
+					'An error occurred. The  requested page route could not be found.',
1165
+					'event_espresso'
1166
+				);
1167
+				// developer error msg
1168
+				$error_msg .= '||';
1169
+				$error_msg .= sprintf(
1170
+					esc_html__(
1171
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1172
+						'event_espresso'
1173
+					),
1174
+					$method
1175
+				);
1176
+				throw new DomainException($error_msg);
1177
+			}
1178
+			if ($class !== $this && ! in_array($this, $args)) {
1179
+				// send along this admin page object for access by addons.
1180
+				$args['admin_page'] = $this;
1181
+			}
1182
+
1183
+			try {
1184
+				call_user_func_array($route_callback, $args);
1185
+			} catch (Throwable $throwable) {
1186
+				$arg_keys = array_keys($args);
1187
+				$nice_args = [];
1188
+				foreach ($args as $key => $arg) {
1189
+					$nice_args[ $key ] = is_object($arg) ? get_class($arg) : $arg_keys[ $key ];
1190
+				}
1191
+				new ExceptionStackTraceDisplay(
1192
+						new RuntimeException(
1193
+							sprintf(
1194
+								esc_html__(
1195
+									'Page route "%1$s" with the supplied arguments (%2$s) threw the following exception: %3$s',
1196
+									'event_espresso'
1197
+								),
1198
+								$method,
1199
+								implode(', ', $nice_args),
1200
+								$throwable->getMessage()
1201
+							),
1202
+							$throwable->getCode(),
1203
+							$throwable
1204
+						)
1205
+				);
1206
+			}
1207
+		}
1208
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1209
+		// then we need to reset the routing properties to the new route.
1210
+		// now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1211
+		if (
1212
+			$this->_is_UI_request === false
1213
+			&& is_array($this->_route)
1214
+			&& ! empty($this->_route['headers_sent_route'])
1215
+		) {
1216
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1217
+		}
1218
+	}
1219
+
1220
+
1221
+	/**
1222
+	 * This method just allows the resetting of page properties in the case where a no headers
1223
+	 * route redirects to a headers route in its route config.
1224
+	 *
1225
+	 * @param string $new_route New (non header) route to redirect to.
1226
+	 * @return   void
1227
+	 * @throws ReflectionException
1228
+	 * @throws InvalidArgumentException
1229
+	 * @throws InvalidInterfaceException
1230
+	 * @throws InvalidDataTypeException
1231
+	 * @throws EE_Error
1232
+	 * @since   4.3.0
1233
+	 */
1234
+	protected function _reset_routing_properties($new_route)
1235
+	{
1236
+		$this->_is_UI_request = true;
1237
+		// now we set the current route to whatever the headers_sent_route is set at
1238
+		$this->request->setRequestParam('action', $new_route);
1239
+		// rerun page setup
1240
+		$this->_page_setup();
1241
+	}
1242
+
1243
+
1244
+	/**
1245
+	 * _add_query_arg
1246
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1247
+	 *(internally just uses EEH_URL's function with the same name)
1248
+	 *
1249
+	 * @param array  $args
1250
+	 * @param string $url
1251
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1252
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1253
+	 *                                        Example usage: If the current page is:
1254
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1255
+	 *                                        &action=default&event_id=20&month_range=March%202015
1256
+	 *                                        &_wpnonce=5467821
1257
+	 *                                        and you call:
1258
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1259
+	 *                                        array(
1260
+	 *                                        'action' => 'resend_something',
1261
+	 *                                        'page=>espresso_registrations'
1262
+	 *                                        ),
1263
+	 *                                        $some_url,
1264
+	 *                                        true
1265
+	 *                                        );
1266
+	 *                                        It will produce a url in this structure:
1267
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1268
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1269
+	 *                                        month_range]=March%202015
1270
+	 * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1271
+	 * @param int    $context
1272
+	 * @return string
1273
+	 */
1274
+	public static function add_query_args_and_nonce(
1275
+		$args = [],
1276
+		$url = '',
1277
+		$sticky = false,
1278
+		$exclude_nonce = false,
1279
+		int $context = EEH_URL::CONTEXT_NONE
1280
+	) {
1281
+		// if there is a _wp_http_referer include the values from the request but only if sticky = true
1282
+		if ($sticky) {
1283
+			/** @var RequestInterface $request */
1284
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1285
+			$request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true);
1286
+			$request->unSetServerParam('_wp_http_referer', true);
1287
+			foreach ($request->requestParams() as $key => $value) {
1288
+				// do not add nonces
1289
+				if (strpos($key, 'nonce') !== false) {
1290
+					continue;
1291
+				}
1292
+				$args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1293
+			}
1294
+		}
1295
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce, $context);
1296
+	}
1297
+
1298
+
1299
+	/**
1300
+	 * This returns a generated link that will load the related help tab.
1301
+	 *
1302
+	 * @param string $help_tab_id the id for the connected help tab
1303
+	 * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1304
+	 * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1305
+	 * @return string              generated link
1306
+	 * @uses EEH_Template::get_help_tab_link()
1307
+	 */
1308
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1309
+	{
1310
+		return EEH_Template::get_help_tab_link(
1311
+			$help_tab_id,
1312
+			$this->page_slug,
1313
+			$this->_req_action,
1314
+			$icon_style,
1315
+			$help_text
1316
+		);
1317
+	}
1318
+
1319
+
1320
+	/**
1321
+	 * _add_help_tabs
1322
+	 * Note child classes define their help tabs within the page_config array.
1323
+	 *
1324
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1325
+	 * @return void
1326
+	 * @throws DomainException
1327
+	 * @throws EE_Error
1328
+	 * @throws ReflectionException
1329
+	 */
1330
+	protected function _add_help_tabs()
1331
+	{
1332
+		if (isset($this->_page_config[ $this->_req_action ])) {
1333
+			$config = $this->_page_config[ $this->_req_action ];
1334
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1335
+			if (is_array($config) && isset($config['help_sidebar'])) {
1336
+				// check that the callback given is valid
1337
+				if (! method_exists($this, $config['help_sidebar'])) {
1338
+					throw new EE_Error(
1339
+						sprintf(
1340
+							esc_html__(
1341
+								'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1342
+								'event_espresso'
1343
+							),
1344
+							$config['help_sidebar'],
1345
+							$this->class_name
1346
+						)
1347
+					);
1348
+				}
1349
+				$content = apply_filters(
1350
+					'FHEE__' . $this->class_name . '__add_help_tabs__help_sidebar',
1351
+					$this->{$config['help_sidebar']}()
1352
+				);
1353
+				$this->_current_screen->set_help_sidebar($content);
1354
+			}
1355
+			if (! isset($config['help_tabs'])) {
1356
+				return;
1357
+			} //no help tabs for this route
1358
+			foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1359
+				// we're here so there ARE help tabs!
1360
+				// make sure we've got what we need
1361
+				if (! isset($cfg['title'])) {
1362
+					throw new EE_Error(
1363
+						esc_html__(
1364
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1365
+							'event_espresso'
1366
+						)
1367
+					);
1368
+				}
1369
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1370
+					throw new EE_Error(
1371
+						esc_html__(
1372
+							'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1373
+							'event_espresso'
1374
+						)
1375
+					);
1376
+				}
1377
+				// first priority goes to content.
1378
+				if (! empty($cfg['content'])) {
1379
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1380
+					// second priority goes to filename
1381
+				} elseif (! empty($cfg['filename'])) {
1382
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1383
+					// it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1384
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1385
+															 . basename($this->_get_dir())
1386
+															 . '/help_tabs/'
1387
+															 . $cfg['filename']
1388
+															 . '.help_tab.php' : $file_path;
1389
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1390
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1391
+						EE_Error::add_error(
1392
+							sprintf(
1393
+								esc_html__(
1394
+									'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1395
+									'event_espresso'
1396
+								),
1397
+								$tab_id,
1398
+								key($config),
1399
+								$file_path
1400
+							),
1401
+							__FILE__,
1402
+							__FUNCTION__,
1403
+							__LINE__
1404
+						);
1405
+						return;
1406
+					}
1407
+					$template_args['admin_page_obj'] = $this;
1408
+					$content                         = EEH_Template::display_template(
1409
+						$file_path,
1410
+						$template_args,
1411
+						true
1412
+					);
1413
+				} else {
1414
+					$content = '';
1415
+				}
1416
+				// check if callback is valid
1417
+				if (
1418
+					empty($content)
1419
+					&& (
1420
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1421
+					)
1422
+				) {
1423
+					EE_Error::add_error(
1424
+						sprintf(
1425
+							esc_html__(
1426
+								'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1427
+								'event_espresso'
1428
+							),
1429
+							$cfg['title']
1430
+						),
1431
+						__FILE__,
1432
+						__FUNCTION__,
1433
+						__LINE__
1434
+					);
1435
+					return;
1436
+				}
1437
+				// setup config array for help tab method
1438
+				$id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1439
+				$_ht = [
1440
+					'id'       => $id,
1441
+					'title'    => $cfg['title'],
1442
+					'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1443
+					'content'  => $content,
1444
+				];
1445
+				$this->_current_screen->add_help_tab($_ht);
1446
+			}
1447
+		}
1448
+	}
1449
+
1450
+
1451
+	/**
1452
+	 * This simply sets up any qtips that have been defined in the page config
1453
+	 *
1454
+	 * @return void
1455
+	 * @throws ReflectionException
1456
+	 * @throws EE_Error
1457
+	 */
1458
+	protected function _add_qtips()
1459
+	{
1460
+		if (isset($this->_route_config['qtips'])) {
1461
+			$qtips = (array) $this->_route_config['qtips'];
1462
+			// load qtip loader
1463
+			$path = [
1464
+				$this->_get_dir() . '/qtips/',
1465
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1466
+			];
1467
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1468
+		}
1469
+	}
1470
+
1471
+
1472
+	/**
1473
+	 * _set_nav_tabs
1474
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1475
+	 * wish to add additional tabs or modify accordingly.
1476
+	 *
1477
+	 * @return void
1478
+	 * @throws InvalidArgumentException
1479
+	 * @throws InvalidInterfaceException
1480
+	 * @throws InvalidDataTypeException
1481
+	 */
1482
+	protected function _set_nav_tabs()
1483
+	{
1484
+		$i        = 0;
1485
+		$only_tab = count($this->_page_config) < 2;
1486
+		foreach ($this->_page_config as $slug => $config) {
1487
+			if (! is_array($config) || empty($config['nav'])) {
1488
+				continue;
1489
+			}
1490
+			// no nav tab for this config
1491
+			// check for persistent flag
1492
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1493
+				// nav tab is only to appear when route requested.
1494
+				continue;
1495
+			}
1496
+			if (! $this->check_user_access($slug, true)) {
1497
+				// no nav tab because current user does not have access.
1498
+				continue;
1499
+			}
1500
+			$css_class = $config['css_class'] ?? '';
1501
+			$css_class .= $only_tab ? ' ee-only-tab' : '';
1502
+			$css_class .= " ee-nav-tab__$slug";
1503
+
1504
+			$this->_nav_tabs[ $slug ] = [
1505
+				'url'       => $config['nav']['url'] ?? EE_Admin_Page::add_query_args_and_nonce(
1506
+						['action' => $slug],
1507
+						$this->_admin_base_url
1508
+					),
1509
+				'link_text' => $this->navTabLabel($config['nav'], $slug),
1510
+				'css_class' => $this->_req_action === $slug ? $css_class . ' nav-tab-active' : $css_class,
1511
+				'order'     => $config['nav']['order'] ?? $i,
1512
+			];
1513
+			$i++;
1514
+		}
1515
+		// if $this->_nav_tabs is empty then lets set the default
1516
+		if (empty($this->_nav_tabs)) {
1517
+			$this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1518
+				'url'       => $this->_admin_base_url,
1519
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1520
+				'css_class' => 'nav-tab-active',
1521
+				'order'     => 10,
1522
+			];
1523
+		}
1524
+		// now let's sort the tabs according to order
1525
+		usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1526
+	}
1527
+
1528
+
1529
+	private function navTabLabel(array $nav_tab, string $slug): string
1530
+	{
1531
+		$label = $nav_tab['label'] ?? ucwords(str_replace('_', ' ', $slug));
1532
+		$icon  = $nav_tab['icon'] ?? null;
1533
+		$icon  = $icon ? '<span class="dashicons ' . $icon . '"></span>' : '';
1534
+		return '
1535 1535
             <span class="ee-admin-screen-tab__label">
1536 1536
                 ' . $icon . '
1537 1537
                 <span class="ee-nav-label__text">' . $label . '</span>
1538 1538
             </span>';
1539
-    }
1540
-
1541
-
1542
-    /**
1543
-     * _set_current_labels
1544
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1545
-     * property array
1546
-     *
1547
-     * @return void
1548
-     */
1549
-    private function _set_current_labels()
1550
-    {
1551
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1552
-            foreach ($this->_route_config['labels'] as $label => $text) {
1553
-                if (is_array($text)) {
1554
-                    foreach ($text as $sublabel => $subtext) {
1555
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1556
-                    }
1557
-                } else {
1558
-                    $this->_labels[ $label ] = $text;
1559
-                }
1560
-            }
1561
-        }
1562
-    }
1563
-
1564
-
1565
-    /**
1566
-     *        verifies user access for this admin page
1567
-     *
1568
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1569
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1570
-     *                               return false if verify fail.
1571
-     * @return bool
1572
-     * @throws InvalidArgumentException
1573
-     * @throws InvalidDataTypeException
1574
-     * @throws InvalidInterfaceException
1575
-     */
1576
-    public function check_user_access($route_to_check = '', $verify_only = false)
1577
-    {
1578
-        $route_to_check = ! empty($route_to_check) ? $route_to_check : $this->_req_action;
1579
-        $capability     = ! empty($route_to_check)
1580
-                          && isset($this->_page_routes[ $route_to_check ])
1581
-                          && is_array($this->_page_routes[ $route_to_check ])
1582
-                          && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1583
-            ? $this->_page_routes[ $route_to_check ]['capability']
1584
-            : null;
1585
-
1586
-        if (empty($capability) && empty($route_to_check)) {
1587
-            $capability = ! empty($this->_route['capability']) ? $this->_route['capability'] : 'manage_options';
1588
-        } else {
1589
-            $capability = empty($capability) ? 'manage_options' : $capability;
1590
-        }
1591
-
1592
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1593
-
1594
-        if (
1595
-            ! $this->request->isAjax()
1596
-            && (
1597
-                ! function_exists('is_admin')
1598
-                || ! EE_Registry::instance()->CAP->current_user_can(
1599
-                    $capability,
1600
-                    "{$this->page_slug}_$route_to_check",
1601
-                    $id
1602
-                )
1603
-            )
1604
-        ) {
1605
-            if ($verify_only) {
1606
-                return false;
1607
-            }
1608
-            if (is_user_logged_in()) {
1609
-                wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1610
-            }
1611
-            return false;
1612
-        }
1613
-        return true;
1614
-    }
1615
-
1616
-
1617
-    /**
1618
-     * @param string                 $box_id
1619
-     * @param string                 $title
1620
-     * @param callable|string|null   $callback
1621
-     * @param string|array|WP_Screen $screen
1622
-     * @param string                 $context
1623
-     * @param string                 $priority
1624
-     * @param array|null             $callback_args
1625
-     */
1626
-    protected function addMetaBox(
1627
-        string $box_id,
1628
-        string $title,
1629
-        $callback,
1630
-        $screen,
1631
-        string $context = 'normal',
1632
-        string $priority = 'default',
1633
-        ?array $callback_args = null
1634
-    ) {
1635
-        if (! (is_callable($callback) || ! function_exists($callback))) {
1636
-            return;
1637
-        }
1638
-
1639
-        add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args);
1640
-        add_filter(
1641
-            "postbox_classes_{$this->_wp_page_slug}_{$box_id}",
1642
-            function ($classes) {
1643
-                $classes[] = 'ee-admin-container';
1644
-                return $classes;
1645
-            }
1646
-        );
1647
-    }
1648
-
1649
-
1650
-    /**
1651
-     * admin_init_global
1652
-     * This runs all the code that we want executed within the WP admin_init hook.
1653
-     * This method executes for ALL EE Admin pages.
1654
-     *
1655
-     * @return void
1656
-     */
1657
-    public function admin_init_global()
1658
-    {
1659
-    }
1660
-
1661
-
1662
-    /**
1663
-     * wp_loaded_global
1664
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1665
-     * EE_Admin page and will execute on every EE Admin Page load
1666
-     *
1667
-     * @return void
1668
-     */
1669
-    public function wp_loaded()
1670
-    {
1671
-    }
1672
-
1673
-
1674
-    /**
1675
-     * admin_notices
1676
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1677
-     * ALL EE_Admin pages.
1678
-     *
1679
-     * @return void
1680
-     */
1681
-    public function admin_notices_global()
1682
-    {
1683
-        $this->_display_no_javascript_warning();
1684
-        $this->_display_espresso_notices();
1685
-    }
1686
-
1687
-
1688
-    public function network_admin_notices_global()
1689
-    {
1690
-        $this->_display_no_javascript_warning();
1691
-        $this->_display_espresso_notices();
1692
-    }
1693
-
1694
-
1695
-    /**
1696
-     * admin_footer_scripts_global
1697
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1698
-     * will apply on ALL EE_Admin pages.
1699
-     *
1700
-     * @return void
1701
-     */
1702
-    public function admin_footer_scripts_global()
1703
-    {
1704
-        $this->_add_admin_page_ajax_loading_img();
1705
-        $this->_add_admin_page_overlay();
1706
-        // if metaboxes are present we need to add the nonce field
1707
-        if (
1708
-            isset($this->_route_config['metaboxes'])
1709
-            || isset($this->_route_config['list_table'])
1710
-            || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1711
-        ) {
1712
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1713
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1714
-        }
1715
-    }
1716
-
1717
-
1718
-    /**
1719
-     * admin_footer_global
1720
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1721
-     * This particular method will apply on ALL EE_Admin Pages.
1722
-     *
1723
-     * @return void
1724
-     */
1725
-    public function admin_footer_global()
1726
-    {
1727
-        // dialog container for dialog helper
1728
-        echo '
1539
+	}
1540
+
1541
+
1542
+	/**
1543
+	 * _set_current_labels
1544
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1545
+	 * property array
1546
+	 *
1547
+	 * @return void
1548
+	 */
1549
+	private function _set_current_labels()
1550
+	{
1551
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1552
+			foreach ($this->_route_config['labels'] as $label => $text) {
1553
+				if (is_array($text)) {
1554
+					foreach ($text as $sublabel => $subtext) {
1555
+						$this->_labels[ $label ][ $sublabel ] = $subtext;
1556
+					}
1557
+				} else {
1558
+					$this->_labels[ $label ] = $text;
1559
+				}
1560
+			}
1561
+		}
1562
+	}
1563
+
1564
+
1565
+	/**
1566
+	 *        verifies user access for this admin page
1567
+	 *
1568
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1569
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1570
+	 *                               return false if verify fail.
1571
+	 * @return bool
1572
+	 * @throws InvalidArgumentException
1573
+	 * @throws InvalidDataTypeException
1574
+	 * @throws InvalidInterfaceException
1575
+	 */
1576
+	public function check_user_access($route_to_check = '', $verify_only = false)
1577
+	{
1578
+		$route_to_check = ! empty($route_to_check) ? $route_to_check : $this->_req_action;
1579
+		$capability     = ! empty($route_to_check)
1580
+						  && isset($this->_page_routes[ $route_to_check ])
1581
+						  && is_array($this->_page_routes[ $route_to_check ])
1582
+						  && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1583
+			? $this->_page_routes[ $route_to_check ]['capability']
1584
+			: null;
1585
+
1586
+		if (empty($capability) && empty($route_to_check)) {
1587
+			$capability = ! empty($this->_route['capability']) ? $this->_route['capability'] : 'manage_options';
1588
+		} else {
1589
+			$capability = empty($capability) ? 'manage_options' : $capability;
1590
+		}
1591
+
1592
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1593
+
1594
+		if (
1595
+			! $this->request->isAjax()
1596
+			&& (
1597
+				! function_exists('is_admin')
1598
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1599
+					$capability,
1600
+					"{$this->page_slug}_$route_to_check",
1601
+					$id
1602
+				)
1603
+			)
1604
+		) {
1605
+			if ($verify_only) {
1606
+				return false;
1607
+			}
1608
+			if (is_user_logged_in()) {
1609
+				wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1610
+			}
1611
+			return false;
1612
+		}
1613
+		return true;
1614
+	}
1615
+
1616
+
1617
+	/**
1618
+	 * @param string                 $box_id
1619
+	 * @param string                 $title
1620
+	 * @param callable|string|null   $callback
1621
+	 * @param string|array|WP_Screen $screen
1622
+	 * @param string                 $context
1623
+	 * @param string                 $priority
1624
+	 * @param array|null             $callback_args
1625
+	 */
1626
+	protected function addMetaBox(
1627
+		string $box_id,
1628
+		string $title,
1629
+		$callback,
1630
+		$screen,
1631
+		string $context = 'normal',
1632
+		string $priority = 'default',
1633
+		?array $callback_args = null
1634
+	) {
1635
+		if (! (is_callable($callback) || ! function_exists($callback))) {
1636
+			return;
1637
+		}
1638
+
1639
+		add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args);
1640
+		add_filter(
1641
+			"postbox_classes_{$this->_wp_page_slug}_{$box_id}",
1642
+			function ($classes) {
1643
+				$classes[] = 'ee-admin-container';
1644
+				return $classes;
1645
+			}
1646
+		);
1647
+	}
1648
+
1649
+
1650
+	/**
1651
+	 * admin_init_global
1652
+	 * This runs all the code that we want executed within the WP admin_init hook.
1653
+	 * This method executes for ALL EE Admin pages.
1654
+	 *
1655
+	 * @return void
1656
+	 */
1657
+	public function admin_init_global()
1658
+	{
1659
+	}
1660
+
1661
+
1662
+	/**
1663
+	 * wp_loaded_global
1664
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1665
+	 * EE_Admin page and will execute on every EE Admin Page load
1666
+	 *
1667
+	 * @return void
1668
+	 */
1669
+	public function wp_loaded()
1670
+	{
1671
+	}
1672
+
1673
+
1674
+	/**
1675
+	 * admin_notices
1676
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1677
+	 * ALL EE_Admin pages.
1678
+	 *
1679
+	 * @return void
1680
+	 */
1681
+	public function admin_notices_global()
1682
+	{
1683
+		$this->_display_no_javascript_warning();
1684
+		$this->_display_espresso_notices();
1685
+	}
1686
+
1687
+
1688
+	public function network_admin_notices_global()
1689
+	{
1690
+		$this->_display_no_javascript_warning();
1691
+		$this->_display_espresso_notices();
1692
+	}
1693
+
1694
+
1695
+	/**
1696
+	 * admin_footer_scripts_global
1697
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1698
+	 * will apply on ALL EE_Admin pages.
1699
+	 *
1700
+	 * @return void
1701
+	 */
1702
+	public function admin_footer_scripts_global()
1703
+	{
1704
+		$this->_add_admin_page_ajax_loading_img();
1705
+		$this->_add_admin_page_overlay();
1706
+		// if metaboxes are present we need to add the nonce field
1707
+		if (
1708
+			isset($this->_route_config['metaboxes'])
1709
+			|| isset($this->_route_config['list_table'])
1710
+			|| (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1711
+		) {
1712
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1713
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1714
+		}
1715
+	}
1716
+
1717
+
1718
+	/**
1719
+	 * admin_footer_global
1720
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1721
+	 * This particular method will apply on ALL EE_Admin Pages.
1722
+	 *
1723
+	 * @return void
1724
+	 */
1725
+	public function admin_footer_global()
1726
+	{
1727
+		// dialog container for dialog helper
1728
+		echo '
1729 1729
         <div class="ee-admin-dialog-container auto-hide hidden">
1730 1730
             <div class="ee-notices"></div>
1731 1731
             <div class="ee-admin-dialog-container-inner-content"></div>
1732 1732
         </div>
1733 1733
         ';
1734 1734
 
1735
-        // current set timezone for timezone js
1736
-        echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1737
-    }
1738
-
1739
-
1740
-    /**
1741
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1742
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1743
-     * help popups then in your templates or your content you set "triggers" for the content using the
1744
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1745
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1746
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1747
-     * for the
1748
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1749
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1750
-     *    'help_trigger_id' => array(
1751
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1752
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1753
-     *    )
1754
-     * );
1755
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1756
-     *
1757
-     * @param array $help_array
1758
-     * @param bool  $display
1759
-     * @return string content
1760
-     * @throws DomainException
1761
-     * @throws EE_Error
1762
-     */
1763
-    protected function _set_help_popup_content($help_array = [], $display = false)
1764
-    {
1765
-        $content    = '';
1766
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1767
-        // loop through the array and setup content
1768
-        foreach ($help_array as $trigger => $help) {
1769
-            // make sure the array is setup properly
1770
-            if (! isset($help['title'], $help['content'])) {
1771
-                throw new EE_Error(
1772
-                    esc_html__(
1773
-                        'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1774
-                        'event_espresso'
1775
-                    )
1776
-                );
1777
-            }
1778
-            // we're good so let's setup the template vars and then assign parsed template content to our content.
1779
-            $template_args = [
1780
-                'help_popup_id'      => $trigger,
1781
-                'help_popup_title'   => $help['title'],
1782
-                'help_popup_content' => $help['content'],
1783
-            ];
1784
-            $content       .= EEH_Template::display_template(
1785
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1786
-                $template_args,
1787
-                true
1788
-            );
1789
-        }
1790
-        if ($display) {
1791
-            echo wp_kses($content, AllowedTags::getWithFormTags());
1792
-            return '';
1793
-        }
1794
-        return $content;
1795
-    }
1796
-
1797
-
1798
-    /**
1799
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1800
-     *
1801
-     * @return array properly formatted array for help popup content
1802
-     * @throws EE_Error
1803
-     */
1804
-    private function _get_help_content()
1805
-    {
1806
-        // what is the method we're looking for?
1807
-        $method_name = '_help_popup_content_' . $this->_req_action;
1808
-        // if method doesn't exist let's get out.
1809
-        if (! method_exists($this, $method_name)) {
1810
-            return [];
1811
-        }
1812
-        // k we're good to go let's retrieve the help array
1813
-        $help_array = $this->{$method_name}();
1814
-        // make sure we've got an array!
1815
-        if (! is_array($help_array)) {
1816
-            throw new EE_Error(
1817
-                esc_html__(
1818
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1819
-                    'event_espresso'
1820
-                )
1821
-            );
1822
-        }
1823
-        return $help_array;
1824
-    }
1825
-
1826
-
1827
-    /**
1828
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1829
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1830
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1831
-     *
1832
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1833
-     * @param boolean $display    if false then we return the trigger string
1834
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1835
-     * @return string
1836
-     * @throws DomainException
1837
-     * @throws EE_Error
1838
-     */
1839
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1840
-    {
1841
-        if ($this->request->isAjax()) {
1842
-            return '';
1843
-        }
1844
-        // let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1845
-        $help_array   = $this->_get_help_content();
1846
-        $help_content = '';
1847
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1848
-            $help_array[ $trigger_id ] = [
1849
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1850
-                'content' => esc_html__(
1851
-                    'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1852
-                    'event_espresso'
1853
-                ),
1854
-            ];
1855
-            $help_content              = $this->_set_help_popup_content($help_array);
1856
-        }
1857
-        // let's setup the trigger
1858
-        $content = '<a class="ee-dialog" href="?height='
1859
-                   . esc_attr($dimensions[0])
1860
-                   . '&width='
1861
-                   . esc_attr($dimensions[1])
1862
-                   . '&inlineId='
1863
-                   . esc_attr($trigger_id)
1864
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1865
-        $content .= $help_content;
1866
-        if ($display) {
1867
-            echo wp_kses($content, AllowedTags::getWithFormTags());
1868
-            return '';
1869
-        }
1870
-        return $content;
1871
-    }
1872
-
1873
-
1874
-    /**
1875
-     * _add_global_screen_options
1876
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1877
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1878
-     *
1879
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1880
-     *         see also WP_Screen object documents...
1881
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1882
-     * @abstract
1883
-     * @return void
1884
-     */
1885
-    private function _add_global_screen_options()
1886
-    {
1887
-    }
1888
-
1889
-
1890
-    /**
1891
-     * _add_global_feature_pointers
1892
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1893
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1894
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1895
-     *
1896
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1897
-     *         extended) also see:
1898
-     * @link   http://eamann.com/tech/wordpress-portland/
1899
-     * @abstract
1900
-     * @return void
1901
-     */
1902
-    private function _add_global_feature_pointers()
1903
-    {
1904
-    }
1905
-
1906
-
1907
-    /**
1908
-     * load_global_scripts_styles
1909
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1910
-     *
1911
-     * @return void
1912
-     */
1913
-    public function load_global_scripts_styles()
1914
-    {
1915
-        // add debugging styles
1916
-        if (WP_DEBUG) {
1917
-            add_action('admin_head', [$this, 'add_xdebug_style']);
1918
-        }
1919
-        // taking care of metaboxes
1920
-        if (
1921
-            empty($this->_cpt_route)
1922
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1923
-        ) {
1924
-            wp_enqueue_script('dashboard');
1925
-        }
1926
-
1927
-        wp_enqueue_script(JqueryAssetManager::JS_HANDLE_JQUERY_UI_TOUCH_PUNCH);
1928
-        wp_enqueue_script(EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN);
1929
-        // LOCALIZED DATA
1930
-        // localize script for ajax lazy loading
1931
-        wp_localize_script(
1932
-            EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1933
-            'eeLazyLoadingContainers',
1934
-            apply_filters(
1935
-                'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1936
-                ['espresso_news_post_box_content']
1937
-            )
1938
-        );
1939
-        StatusChangeNotice::loadAssets();
1940
-
1941
-        add_filter(
1942
-            'admin_body_class',
1943
-            function ($classes) {
1944
-                if (strpos($classes, 'espresso-admin') === false) {
1945
-                    $classes .= ' espresso-admin';
1946
-                }
1947
-                return $classes;
1948
-            }
1949
-        );
1950
-    }
1951
-
1952
-
1953
-    /**
1954
-     *        admin_footer_scripts_eei18n_js_strings
1955
-     *
1956
-     * @return        void
1957
-     */
1958
-    public function admin_footer_scripts_eei18n_js_strings()
1959
-    {
1960
-        EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1961
-        EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1962
-            __(
1963
-                'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
1964
-                'event_espresso'
1965
-            )
1966
-        );
1967
-        EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1968
-        EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1969
-        EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1970
-        EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1971
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1972
-        EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1973
-        EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1974
-        EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1975
-        EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1976
-        EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1977
-        EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1978
-        EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1979
-        EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1980
-        EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1981
-        EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1982
-        EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1983
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1984
-        EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1985
-        EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1986
-        EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1987
-        EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1988
-        EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1989
-        EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1990
-        EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1991
-        EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1992
-        EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1993
-        EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1994
-        EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1995
-        EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1996
-        EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1997
-        EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1998
-        EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1999
-        EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
2000
-        EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
2001
-        EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
2002
-        EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
2003
-        EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
2004
-        EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
2005
-    }
2006
-
2007
-
2008
-    /**
2009
-     *        load enhanced xdebug styles for ppl with failing eyesight
2010
-     *
2011
-     * @return        void
2012
-     */
2013
-    public function add_xdebug_style()
2014
-    {
2015
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2016
-    }
2017
-
2018
-
2019
-    /************************/
2020
-    /** LIST TABLE METHODS **/
2021
-    /************************/
2022
-    /**
2023
-     * this sets up the list table if the current view requires it.
2024
-     *
2025
-     * @return void
2026
-     * @throws EE_Error
2027
-     * @throws InvalidArgumentException
2028
-     * @throws InvalidDataTypeException
2029
-     * @throws InvalidInterfaceException
2030
-     */
2031
-    protected function _set_list_table()
2032
-    {
2033
-        // first is this a list_table view?
2034
-        if (! isset($this->_route_config['list_table'])) {
2035
-            return;
2036
-        } //not a list_table view so get out.
2037
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
2038
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
2039
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2040
-            // user error msg
2041
-            $error_msg = esc_html__(
2042
-                'An error occurred. The requested list table views could not be found.',
2043
-                'event_espresso'
2044
-            );
2045
-            // developer error msg
2046
-            $error_msg .= '||'
2047
-                          . sprintf(
2048
-                              esc_html__(
2049
-                                  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2050
-                                  'event_espresso'
2051
-                              ),
2052
-                              $this->_req_action,
2053
-                              $list_table_view
2054
-                          );
2055
-            throw new EE_Error($error_msg);
2056
-        }
2057
-        // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2058
-        $this->_views = apply_filters(
2059
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2060
-            $this->_views
2061
-        );
2062
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2063
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2064
-        $this->_set_list_table_view();
2065
-        $this->_set_list_table_object();
2066
-    }
2067
-
2068
-
2069
-    /**
2070
-     * set current view for List Table
2071
-     *
2072
-     * @return void
2073
-     */
2074
-    protected function _set_list_table_view()
2075
-    {
2076
-        $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2077
-        $status      = $this->request->getRequestParam('status', null, 'key');
2078
-        $this->_view = $status && array_key_exists($status, $this->_views)
2079
-            ? $status
2080
-            : $this->_view;
2081
-    }
2082
-
2083
-
2084
-    /**
2085
-     * _set_list_table_object
2086
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2087
-     *
2088
-     * @throws InvalidInterfaceException
2089
-     * @throws InvalidArgumentException
2090
-     * @throws InvalidDataTypeException
2091
-     * @throws EE_Error
2092
-     * @throws InvalidInterfaceException
2093
-     */
2094
-    protected function _set_list_table_object()
2095
-    {
2096
-        if (isset($this->_route_config['list_table'])) {
2097
-            if (! class_exists($this->_route_config['list_table'])) {
2098
-                throw new EE_Error(
2099
-                    sprintf(
2100
-                        esc_html__(
2101
-                            'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2102
-                            'event_espresso'
2103
-                        ),
2104
-                        $this->_route_config['list_table'],
2105
-                        $this->class_name
2106
-                    )
2107
-                );
2108
-            }
2109
-            $this->_list_table_object = $this->loader->getShared(
2110
-                $this->_route_config['list_table'],
2111
-                [
2112
-                    $this,
2113
-                    LoaderFactory::getShared(AdminListTableFilters::class)
2114
-                ]
2115
-            );
2116
-        }
2117
-    }
2118
-
2119
-
2120
-    /**
2121
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2122
-     *
2123
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2124
-     *                                                    urls.  The array should be indexed by the view it is being
2125
-     *                                                    added to.
2126
-     * @return array
2127
-     */
2128
-    public function get_list_table_view_RLs($extra_query_args = [])
2129
-    {
2130
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2131
-        if (empty($this->_views)) {
2132
-            $this->_views = [];
2133
-        }
2134
-        // cycle thru views
2135
-        foreach ($this->_views as $key => $view) {
2136
-            $query_args = [];
2137
-            // check for current view
2138
-            $this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2139
-            $query_args['action']                        = $this->_req_action;
2140
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2141
-            $query_args['status']                        = $view['slug'];
2142
-            // merge any other arguments sent in.
2143
-            if (isset($extra_query_args[ $view['slug'] ])) {
2144
-                foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2145
-                    $query_args[] = $extra_query_arg;
2146
-                }
2147
-            }
2148
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2149
-        }
2150
-        return $this->_views;
2151
-    }
2152
-
2153
-
2154
-    /**
2155
-     * _entries_per_page_dropdown
2156
-     * generates a dropdown box for selecting the number of visible rows in an admin page list table
2157
-     *
2158
-     * @param int $max_entries total number of rows in the table
2159
-     * @return string
2160
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2161
-     *                         WP does it.
2162
-     */
2163
-    protected function _entries_per_page_dropdown($max_entries = 0)
2164
-    {
2165
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2166
-        $values   = [10, 25, 50, 100];
2167
-        $per_page = $this->request->getRequestParam('per_page', 10, 'int');
2168
-        if ($max_entries) {
2169
-            $values[] = $max_entries;
2170
-            sort($values);
2171
-        }
2172
-        $entries_per_page_dropdown = '
1735
+		// current set timezone for timezone js
1736
+		echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1737
+	}
1738
+
1739
+
1740
+	/**
1741
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1742
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1743
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1744
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1745
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1746
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1747
+	 * for the
1748
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1749
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1750
+	 *    'help_trigger_id' => array(
1751
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1752
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1753
+	 *    )
1754
+	 * );
1755
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1756
+	 *
1757
+	 * @param array $help_array
1758
+	 * @param bool  $display
1759
+	 * @return string content
1760
+	 * @throws DomainException
1761
+	 * @throws EE_Error
1762
+	 */
1763
+	protected function _set_help_popup_content($help_array = [], $display = false)
1764
+	{
1765
+		$content    = '';
1766
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1767
+		// loop through the array and setup content
1768
+		foreach ($help_array as $trigger => $help) {
1769
+			// make sure the array is setup properly
1770
+			if (! isset($help['title'], $help['content'])) {
1771
+				throw new EE_Error(
1772
+					esc_html__(
1773
+						'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1774
+						'event_espresso'
1775
+					)
1776
+				);
1777
+			}
1778
+			// we're good so let's setup the template vars and then assign parsed template content to our content.
1779
+			$template_args = [
1780
+				'help_popup_id'      => $trigger,
1781
+				'help_popup_title'   => $help['title'],
1782
+				'help_popup_content' => $help['content'],
1783
+			];
1784
+			$content       .= EEH_Template::display_template(
1785
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1786
+				$template_args,
1787
+				true
1788
+			);
1789
+		}
1790
+		if ($display) {
1791
+			echo wp_kses($content, AllowedTags::getWithFormTags());
1792
+			return '';
1793
+		}
1794
+		return $content;
1795
+	}
1796
+
1797
+
1798
+	/**
1799
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1800
+	 *
1801
+	 * @return array properly formatted array for help popup content
1802
+	 * @throws EE_Error
1803
+	 */
1804
+	private function _get_help_content()
1805
+	{
1806
+		// what is the method we're looking for?
1807
+		$method_name = '_help_popup_content_' . $this->_req_action;
1808
+		// if method doesn't exist let's get out.
1809
+		if (! method_exists($this, $method_name)) {
1810
+			return [];
1811
+		}
1812
+		// k we're good to go let's retrieve the help array
1813
+		$help_array = $this->{$method_name}();
1814
+		// make sure we've got an array!
1815
+		if (! is_array($help_array)) {
1816
+			throw new EE_Error(
1817
+				esc_html__(
1818
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1819
+					'event_espresso'
1820
+				)
1821
+			);
1822
+		}
1823
+		return $help_array;
1824
+	}
1825
+
1826
+
1827
+	/**
1828
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1829
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1830
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1831
+	 *
1832
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1833
+	 * @param boolean $display    if false then we return the trigger string
1834
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1835
+	 * @return string
1836
+	 * @throws DomainException
1837
+	 * @throws EE_Error
1838
+	 */
1839
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1840
+	{
1841
+		if ($this->request->isAjax()) {
1842
+			return '';
1843
+		}
1844
+		// let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1845
+		$help_array   = $this->_get_help_content();
1846
+		$help_content = '';
1847
+		if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1848
+			$help_array[ $trigger_id ] = [
1849
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1850
+				'content' => esc_html__(
1851
+					'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1852
+					'event_espresso'
1853
+				),
1854
+			];
1855
+			$help_content              = $this->_set_help_popup_content($help_array);
1856
+		}
1857
+		// let's setup the trigger
1858
+		$content = '<a class="ee-dialog" href="?height='
1859
+				   . esc_attr($dimensions[0])
1860
+				   . '&width='
1861
+				   . esc_attr($dimensions[1])
1862
+				   . '&inlineId='
1863
+				   . esc_attr($trigger_id)
1864
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1865
+		$content .= $help_content;
1866
+		if ($display) {
1867
+			echo wp_kses($content, AllowedTags::getWithFormTags());
1868
+			return '';
1869
+		}
1870
+		return $content;
1871
+	}
1872
+
1873
+
1874
+	/**
1875
+	 * _add_global_screen_options
1876
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1877
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1878
+	 *
1879
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1880
+	 *         see also WP_Screen object documents...
1881
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1882
+	 * @abstract
1883
+	 * @return void
1884
+	 */
1885
+	private function _add_global_screen_options()
1886
+	{
1887
+	}
1888
+
1889
+
1890
+	/**
1891
+	 * _add_global_feature_pointers
1892
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1893
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1894
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1895
+	 *
1896
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1897
+	 *         extended) also see:
1898
+	 * @link   http://eamann.com/tech/wordpress-portland/
1899
+	 * @abstract
1900
+	 * @return void
1901
+	 */
1902
+	private function _add_global_feature_pointers()
1903
+	{
1904
+	}
1905
+
1906
+
1907
+	/**
1908
+	 * load_global_scripts_styles
1909
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1910
+	 *
1911
+	 * @return void
1912
+	 */
1913
+	public function load_global_scripts_styles()
1914
+	{
1915
+		// add debugging styles
1916
+		if (WP_DEBUG) {
1917
+			add_action('admin_head', [$this, 'add_xdebug_style']);
1918
+		}
1919
+		// taking care of metaboxes
1920
+		if (
1921
+			empty($this->_cpt_route)
1922
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1923
+		) {
1924
+			wp_enqueue_script('dashboard');
1925
+		}
1926
+
1927
+		wp_enqueue_script(JqueryAssetManager::JS_HANDLE_JQUERY_UI_TOUCH_PUNCH);
1928
+		wp_enqueue_script(EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN);
1929
+		// LOCALIZED DATA
1930
+		// localize script for ajax lazy loading
1931
+		wp_localize_script(
1932
+			EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1933
+			'eeLazyLoadingContainers',
1934
+			apply_filters(
1935
+				'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1936
+				['espresso_news_post_box_content']
1937
+			)
1938
+		);
1939
+		StatusChangeNotice::loadAssets();
1940
+
1941
+		add_filter(
1942
+			'admin_body_class',
1943
+			function ($classes) {
1944
+				if (strpos($classes, 'espresso-admin') === false) {
1945
+					$classes .= ' espresso-admin';
1946
+				}
1947
+				return $classes;
1948
+			}
1949
+		);
1950
+	}
1951
+
1952
+
1953
+	/**
1954
+	 *        admin_footer_scripts_eei18n_js_strings
1955
+	 *
1956
+	 * @return        void
1957
+	 */
1958
+	public function admin_footer_scripts_eei18n_js_strings()
1959
+	{
1960
+		EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1961
+		EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1962
+			__(
1963
+				'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
1964
+				'event_espresso'
1965
+			)
1966
+		);
1967
+		EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1968
+		EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1969
+		EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1970
+		EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1971
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1972
+		EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1973
+		EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1974
+		EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1975
+		EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1976
+		EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1977
+		EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1978
+		EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1979
+		EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1980
+		EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1981
+		EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1982
+		EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1983
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1984
+		EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1985
+		EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1986
+		EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1987
+		EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1988
+		EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1989
+		EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1990
+		EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1991
+		EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1992
+		EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1993
+		EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1994
+		EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1995
+		EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1996
+		EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1997
+		EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1998
+		EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1999
+		EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
2000
+		EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
2001
+		EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
2002
+		EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
2003
+		EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
2004
+		EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
2005
+	}
2006
+
2007
+
2008
+	/**
2009
+	 *        load enhanced xdebug styles for ppl with failing eyesight
2010
+	 *
2011
+	 * @return        void
2012
+	 */
2013
+	public function add_xdebug_style()
2014
+	{
2015
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2016
+	}
2017
+
2018
+
2019
+	/************************/
2020
+	/** LIST TABLE METHODS **/
2021
+	/************************/
2022
+	/**
2023
+	 * this sets up the list table if the current view requires it.
2024
+	 *
2025
+	 * @return void
2026
+	 * @throws EE_Error
2027
+	 * @throws InvalidArgumentException
2028
+	 * @throws InvalidDataTypeException
2029
+	 * @throws InvalidInterfaceException
2030
+	 */
2031
+	protected function _set_list_table()
2032
+	{
2033
+		// first is this a list_table view?
2034
+		if (! isset($this->_route_config['list_table'])) {
2035
+			return;
2036
+		} //not a list_table view so get out.
2037
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
2038
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
2039
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2040
+			// user error msg
2041
+			$error_msg = esc_html__(
2042
+				'An error occurred. The requested list table views could not be found.',
2043
+				'event_espresso'
2044
+			);
2045
+			// developer error msg
2046
+			$error_msg .= '||'
2047
+						  . sprintf(
2048
+							  esc_html__(
2049
+								  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2050
+								  'event_espresso'
2051
+							  ),
2052
+							  $this->_req_action,
2053
+							  $list_table_view
2054
+						  );
2055
+			throw new EE_Error($error_msg);
2056
+		}
2057
+		// let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2058
+		$this->_views = apply_filters(
2059
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2060
+			$this->_views
2061
+		);
2062
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2063
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2064
+		$this->_set_list_table_view();
2065
+		$this->_set_list_table_object();
2066
+	}
2067
+
2068
+
2069
+	/**
2070
+	 * set current view for List Table
2071
+	 *
2072
+	 * @return void
2073
+	 */
2074
+	protected function _set_list_table_view()
2075
+	{
2076
+		$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2077
+		$status      = $this->request->getRequestParam('status', null, 'key');
2078
+		$this->_view = $status && array_key_exists($status, $this->_views)
2079
+			? $status
2080
+			: $this->_view;
2081
+	}
2082
+
2083
+
2084
+	/**
2085
+	 * _set_list_table_object
2086
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2087
+	 *
2088
+	 * @throws InvalidInterfaceException
2089
+	 * @throws InvalidArgumentException
2090
+	 * @throws InvalidDataTypeException
2091
+	 * @throws EE_Error
2092
+	 * @throws InvalidInterfaceException
2093
+	 */
2094
+	protected function _set_list_table_object()
2095
+	{
2096
+		if (isset($this->_route_config['list_table'])) {
2097
+			if (! class_exists($this->_route_config['list_table'])) {
2098
+				throw new EE_Error(
2099
+					sprintf(
2100
+						esc_html__(
2101
+							'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2102
+							'event_espresso'
2103
+						),
2104
+						$this->_route_config['list_table'],
2105
+						$this->class_name
2106
+					)
2107
+				);
2108
+			}
2109
+			$this->_list_table_object = $this->loader->getShared(
2110
+				$this->_route_config['list_table'],
2111
+				[
2112
+					$this,
2113
+					LoaderFactory::getShared(AdminListTableFilters::class)
2114
+				]
2115
+			);
2116
+		}
2117
+	}
2118
+
2119
+
2120
+	/**
2121
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2122
+	 *
2123
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2124
+	 *                                                    urls.  The array should be indexed by the view it is being
2125
+	 *                                                    added to.
2126
+	 * @return array
2127
+	 */
2128
+	public function get_list_table_view_RLs($extra_query_args = [])
2129
+	{
2130
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2131
+		if (empty($this->_views)) {
2132
+			$this->_views = [];
2133
+		}
2134
+		// cycle thru views
2135
+		foreach ($this->_views as $key => $view) {
2136
+			$query_args = [];
2137
+			// check for current view
2138
+			$this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2139
+			$query_args['action']                        = $this->_req_action;
2140
+			$query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2141
+			$query_args['status']                        = $view['slug'];
2142
+			// merge any other arguments sent in.
2143
+			if (isset($extra_query_args[ $view['slug'] ])) {
2144
+				foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2145
+					$query_args[] = $extra_query_arg;
2146
+				}
2147
+			}
2148
+			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2149
+		}
2150
+		return $this->_views;
2151
+	}
2152
+
2153
+
2154
+	/**
2155
+	 * _entries_per_page_dropdown
2156
+	 * generates a dropdown box for selecting the number of visible rows in an admin page list table
2157
+	 *
2158
+	 * @param int $max_entries total number of rows in the table
2159
+	 * @return string
2160
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2161
+	 *                         WP does it.
2162
+	 */
2163
+	protected function _entries_per_page_dropdown($max_entries = 0)
2164
+	{
2165
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2166
+		$values   = [10, 25, 50, 100];
2167
+		$per_page = $this->request->getRequestParam('per_page', 10, 'int');
2168
+		if ($max_entries) {
2169
+			$values[] = $max_entries;
2170
+			sort($values);
2171
+		}
2172
+		$entries_per_page_dropdown = '
2173 2173
 			<div id="entries-per-page-dv" class="alignleft actions">
2174 2174
 				<label class="hide-if-no-js">
2175 2175
 					Show
2176 2176
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2177
-        foreach ($values as $value) {
2178
-            if ($value < $max_entries) {
2179
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2180
-                $entries_per_page_dropdown .= '
2177
+		foreach ($values as $value) {
2178
+			if ($value < $max_entries) {
2179
+				$selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2180
+				$entries_per_page_dropdown .= '
2181 2181
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2182
-            }
2183
-        }
2184
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2185
-        $entries_per_page_dropdown .= '
2182
+			}
2183
+		}
2184
+		$selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2185
+		$entries_per_page_dropdown .= '
2186 2186
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2187
-        $entries_per_page_dropdown .= '
2187
+		$entries_per_page_dropdown .= '
2188 2188
 					</select>
2189 2189
 					entries
2190 2190
 				</label>
2191 2191
 				<input id="entries-per-page-btn" class="button button--secondary" type="submit" value="Go" >
2192 2192
 			</div>
2193 2193
 		';
2194
-        return $entries_per_page_dropdown;
2195
-    }
2196
-
2197
-
2198
-    /**
2199
-     *        _set_search_attributes
2200
-     *
2201
-     * @return        void
2202
-     */
2203
-    public function _set_search_attributes()
2204
-    {
2205
-        $this->_template_args['search']['btn_label'] = sprintf(
2206
-            esc_html__('Search %s', 'event_espresso'),
2207
-            empty($this->_search_btn_label) ? $this->page_label
2208
-                : $this->_search_btn_label
2209
-        );
2210
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2211
-    }
2212
-
2213
-
2214
-
2215
-    /*** END LIST TABLE METHODS **/
2216
-
2217
-    /**
2218
-     * @return void
2219
-     * @throws EE_Error
2220
-     */
2221
-    public function addRegisteredMetaBoxes()
2222
-    {
2223
-        remove_action('add_meta_boxes', [$this, 'addRegisteredMetaBoxes'], 99);
2224
-        $this->_add_registered_meta_boxes();
2225
-    }
2226
-
2227
-
2228
-    /**
2229
-     * _add_registered_metaboxes
2230
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2231
-     *
2232
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2233
-     * @return void
2234
-     * @throws EE_Error
2235
-     */
2236
-    private function _add_registered_meta_boxes()
2237
-    {
2238
-        // we only add meta boxes if the page_route calls for it
2239
-        if (
2240
-            is_array($this->_route_config)
2241
-            && isset($this->_route_config['metaboxes'])
2242
-            && is_array($this->_route_config['metaboxes'])
2243
-        ) {
2244
-            // this simply loops through the callbacks provided
2245
-            // and checks if there is a corresponding callback registered by the child
2246
-            // if there is then we go ahead and process the metabox loader.
2247
-            foreach ($this->_route_config['metaboxes'] as $key => $metabox_callback) {
2248
-                // first check for Closures
2249
-                if ($metabox_callback instanceof Closure) {
2250
-                    $result = $metabox_callback();
2251
-                } elseif (is_callable($metabox_callback)) {
2252
-                    $result = call_user_func($metabox_callback);
2253
-                } elseif (method_exists($this, $metabox_callback)) {
2254
-                    $result = $this->{$metabox_callback}();
2255
-                } else {
2256
-                    $result = false;
2257
-                }
2258
-                if ($result === false) {
2259
-                    // user error msg
2260
-                    $error_msg = esc_html__(
2261
-                        'An error occurred. The  requested metabox could not be found.',
2262
-                        'event_espresso'
2263
-                    );
2264
-                    // developer error msg
2265
-                    $error_msg .= '||'
2266
-                                  . sprintf(
2267
-                                      esc_html__(
2268
-                                          'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2269
-                                          'event_espresso'
2270
-                                      ),
2271
-                                      $metabox_callback
2272
-                                  );
2273
-                    throw new EE_Error($error_msg);
2274
-                }
2275
-                unset($this->_route_config['metaboxes'][ $key ]);
2276
-            }
2277
-        }
2278
-    }
2279
-
2280
-
2281
-    /**
2282
-     * _add_screen_columns
2283
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2284
-     * the dynamic column template and we'll setup the column options for the page.
2285
-     *
2286
-     * @return void
2287
-     */
2288
-    private function _add_screen_columns()
2289
-    {
2290
-        if (
2291
-            is_array($this->_route_config)
2292
-            && isset($this->_route_config['columns'])
2293
-            && is_array($this->_route_config['columns'])
2294
-            && count($this->_route_config['columns']) === 2
2295
-        ) {
2296
-            add_screen_option(
2297
-                'layout_columns',
2298
-                [
2299
-                    'max'     => (int) $this->_route_config['columns'][0],
2300
-                    'default' => (int) $this->_route_config['columns'][1],
2301
-                ]
2302
-            );
2303
-            $this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2304
-            $screen_id                                           = $this->_current_screen->id;
2305
-            $screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2306
-            $total_columns                                       = ! empty($screen_columns)
2307
-                ? $screen_columns
2308
-                : $this->_route_config['columns'][1];
2309
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2310
-            $this->_template_args['current_page']                = $this->_wp_page_slug;
2311
-            $this->_template_args['screen']                      = $this->_current_screen;
2312
-            $this->_column_template_path                         = EE_ADMIN_TEMPLATE
2313
-                                                                   . 'admin_details_metabox_column_wrapper.template.php';
2314
-            // finally if we don't have has_metaboxes set in the route config
2315
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2316
-            $this->_route_config['has_metaboxes'] = true;
2317
-        }
2318
-    }
2319
-
2320
-
2321
-
2322
-    /** GLOBALLY AVAILABLE METABOXES **/
2323
-
2324
-
2325
-    /**
2326
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2327
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2328
-     * these get loaded on.
2329
-     */
2330
-    private function _espresso_news_post_box()
2331
-    {
2332
-        $news_box_title = apply_filters(
2333
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2334
-            esc_html__('New @ Event Espresso', 'event_espresso')
2335
-        );
2336
-        $this->addMetaBox(
2337
-            'espresso_news_post_box',
2338
-            $news_box_title,
2339
-            [
2340
-                $this,
2341
-                'espresso_news_post_box',
2342
-            ],
2343
-            $this->_wp_page_slug,
2344
-            'side',
2345
-            'low'
2346
-        );
2347
-    }
2348
-
2349
-
2350
-    /**
2351
-     * Code for setting up espresso ratings request metabox.
2352
-     */
2353
-    protected function _espresso_ratings_request()
2354
-    {
2355
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2356
-            return;
2357
-        }
2358
-        $ratings_box_title = apply_filters(
2359
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2360
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2361
-        );
2362
-        $this->addMetaBox(
2363
-            'espresso_ratings_request',
2364
-            $ratings_box_title,
2365
-            [
2366
-                $this,
2367
-                'espresso_ratings_request',
2368
-            ],
2369
-            $this->_wp_page_slug,
2370
-            'side'
2371
-        );
2372
-    }
2373
-
2374
-
2375
-    /**
2376
-     * Code for setting up espresso ratings request metabox content.
2377
-     *
2378
-     * @throws DomainException
2379
-     */
2380
-    public function espresso_ratings_request()
2381
-    {
2382
-        EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2383
-    }
2384
-
2385
-
2386
-    public static function cached_rss_display($rss_id, $url)
2387
-    {
2388
-        $loading   = '<p class="widget-loading hide-if-no-js">'
2389
-                     . esc_html__('Loading&#8230;', 'event_espresso')
2390
-                     . '</p><p class="hide-if-js">'
2391
-                     . esc_html__('This widget requires JavaScript.', 'event_espresso')
2392
-                     . '</p>';
2393
-        $pre       = '<div class="espresso-rss-display">' . "\n\t";
2394
-        $pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2395
-        $post      = '</div>' . "\n";
2396
-        $cache_key = 'ee_rss_' . md5($rss_id);
2397
-        $output    = get_transient($cache_key);
2398
-        if ($output !== false) {
2399
-            echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags());
2400
-            return true;
2401
-        }
2402
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2403
-            echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags());
2404
-            return false;
2405
-        }
2406
-        ob_start();
2407
-        wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2408
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2409
-        return true;
2410
-    }
2411
-
2412
-
2413
-    public function espresso_news_post_box()
2414
-    {
2415
-        ?>
2194
+		return $entries_per_page_dropdown;
2195
+	}
2196
+
2197
+
2198
+	/**
2199
+	 *        _set_search_attributes
2200
+	 *
2201
+	 * @return        void
2202
+	 */
2203
+	public function _set_search_attributes()
2204
+	{
2205
+		$this->_template_args['search']['btn_label'] = sprintf(
2206
+			esc_html__('Search %s', 'event_espresso'),
2207
+			empty($this->_search_btn_label) ? $this->page_label
2208
+				: $this->_search_btn_label
2209
+		);
2210
+		$this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2211
+	}
2212
+
2213
+
2214
+
2215
+	/*** END LIST TABLE METHODS **/
2216
+
2217
+	/**
2218
+	 * @return void
2219
+	 * @throws EE_Error
2220
+	 */
2221
+	public function addRegisteredMetaBoxes()
2222
+	{
2223
+		remove_action('add_meta_boxes', [$this, 'addRegisteredMetaBoxes'], 99);
2224
+		$this->_add_registered_meta_boxes();
2225
+	}
2226
+
2227
+
2228
+	/**
2229
+	 * _add_registered_metaboxes
2230
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2231
+	 *
2232
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2233
+	 * @return void
2234
+	 * @throws EE_Error
2235
+	 */
2236
+	private function _add_registered_meta_boxes()
2237
+	{
2238
+		// we only add meta boxes if the page_route calls for it
2239
+		if (
2240
+			is_array($this->_route_config)
2241
+			&& isset($this->_route_config['metaboxes'])
2242
+			&& is_array($this->_route_config['metaboxes'])
2243
+		) {
2244
+			// this simply loops through the callbacks provided
2245
+			// and checks if there is a corresponding callback registered by the child
2246
+			// if there is then we go ahead and process the metabox loader.
2247
+			foreach ($this->_route_config['metaboxes'] as $key => $metabox_callback) {
2248
+				// first check for Closures
2249
+				if ($metabox_callback instanceof Closure) {
2250
+					$result = $metabox_callback();
2251
+				} elseif (is_callable($metabox_callback)) {
2252
+					$result = call_user_func($metabox_callback);
2253
+				} elseif (method_exists($this, $metabox_callback)) {
2254
+					$result = $this->{$metabox_callback}();
2255
+				} else {
2256
+					$result = false;
2257
+				}
2258
+				if ($result === false) {
2259
+					// user error msg
2260
+					$error_msg = esc_html__(
2261
+						'An error occurred. The  requested metabox could not be found.',
2262
+						'event_espresso'
2263
+					);
2264
+					// developer error msg
2265
+					$error_msg .= '||'
2266
+								  . sprintf(
2267
+									  esc_html__(
2268
+										  'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2269
+										  'event_espresso'
2270
+									  ),
2271
+									  $metabox_callback
2272
+								  );
2273
+					throw new EE_Error($error_msg);
2274
+				}
2275
+				unset($this->_route_config['metaboxes'][ $key ]);
2276
+			}
2277
+		}
2278
+	}
2279
+
2280
+
2281
+	/**
2282
+	 * _add_screen_columns
2283
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2284
+	 * the dynamic column template and we'll setup the column options for the page.
2285
+	 *
2286
+	 * @return void
2287
+	 */
2288
+	private function _add_screen_columns()
2289
+	{
2290
+		if (
2291
+			is_array($this->_route_config)
2292
+			&& isset($this->_route_config['columns'])
2293
+			&& is_array($this->_route_config['columns'])
2294
+			&& count($this->_route_config['columns']) === 2
2295
+		) {
2296
+			add_screen_option(
2297
+				'layout_columns',
2298
+				[
2299
+					'max'     => (int) $this->_route_config['columns'][0],
2300
+					'default' => (int) $this->_route_config['columns'][1],
2301
+				]
2302
+			);
2303
+			$this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2304
+			$screen_id                                           = $this->_current_screen->id;
2305
+			$screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2306
+			$total_columns                                       = ! empty($screen_columns)
2307
+				? $screen_columns
2308
+				: $this->_route_config['columns'][1];
2309
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2310
+			$this->_template_args['current_page']                = $this->_wp_page_slug;
2311
+			$this->_template_args['screen']                      = $this->_current_screen;
2312
+			$this->_column_template_path                         = EE_ADMIN_TEMPLATE
2313
+																   . 'admin_details_metabox_column_wrapper.template.php';
2314
+			// finally if we don't have has_metaboxes set in the route config
2315
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2316
+			$this->_route_config['has_metaboxes'] = true;
2317
+		}
2318
+	}
2319
+
2320
+
2321
+
2322
+	/** GLOBALLY AVAILABLE METABOXES **/
2323
+
2324
+
2325
+	/**
2326
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2327
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2328
+	 * these get loaded on.
2329
+	 */
2330
+	private function _espresso_news_post_box()
2331
+	{
2332
+		$news_box_title = apply_filters(
2333
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2334
+			esc_html__('New @ Event Espresso', 'event_espresso')
2335
+		);
2336
+		$this->addMetaBox(
2337
+			'espresso_news_post_box',
2338
+			$news_box_title,
2339
+			[
2340
+				$this,
2341
+				'espresso_news_post_box',
2342
+			],
2343
+			$this->_wp_page_slug,
2344
+			'side',
2345
+			'low'
2346
+		);
2347
+	}
2348
+
2349
+
2350
+	/**
2351
+	 * Code for setting up espresso ratings request metabox.
2352
+	 */
2353
+	protected function _espresso_ratings_request()
2354
+	{
2355
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2356
+			return;
2357
+		}
2358
+		$ratings_box_title = apply_filters(
2359
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2360
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2361
+		);
2362
+		$this->addMetaBox(
2363
+			'espresso_ratings_request',
2364
+			$ratings_box_title,
2365
+			[
2366
+				$this,
2367
+				'espresso_ratings_request',
2368
+			],
2369
+			$this->_wp_page_slug,
2370
+			'side'
2371
+		);
2372
+	}
2373
+
2374
+
2375
+	/**
2376
+	 * Code for setting up espresso ratings request metabox content.
2377
+	 *
2378
+	 * @throws DomainException
2379
+	 */
2380
+	public function espresso_ratings_request()
2381
+	{
2382
+		EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2383
+	}
2384
+
2385
+
2386
+	public static function cached_rss_display($rss_id, $url)
2387
+	{
2388
+		$loading   = '<p class="widget-loading hide-if-no-js">'
2389
+					 . esc_html__('Loading&#8230;', 'event_espresso')
2390
+					 . '</p><p class="hide-if-js">'
2391
+					 . esc_html__('This widget requires JavaScript.', 'event_espresso')
2392
+					 . '</p>';
2393
+		$pre       = '<div class="espresso-rss-display">' . "\n\t";
2394
+		$pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2395
+		$post      = '</div>' . "\n";
2396
+		$cache_key = 'ee_rss_' . md5($rss_id);
2397
+		$output    = get_transient($cache_key);
2398
+		if ($output !== false) {
2399
+			echo wp_kses($pre . $output . $post, AllowedTags::getWithFormTags());
2400
+			return true;
2401
+		}
2402
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2403
+			echo wp_kses($pre . $loading . $post, AllowedTags::getWithFormTags());
2404
+			return false;
2405
+		}
2406
+		ob_start();
2407
+		wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2408
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2409
+		return true;
2410
+	}
2411
+
2412
+
2413
+	public function espresso_news_post_box()
2414
+	{
2415
+		?>
2416 2416
         <div class="padding">
2417 2417
             <div id="espresso_news_post_box_content" class="infolinks">
2418 2418
                 <?php
2419
-                // Get RSS Feed(s)
2420
-                EE_Admin_Page::cached_rss_display(
2421
-                    'espresso_news_post_box_content',
2422
-                    esc_url_raw(
2423
-                        apply_filters(
2424
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2425
-                            'https://eventespresso.com/feed/'
2426
-                        )
2427
-                    )
2428
-                );
2429
-                ?>
2419
+				// Get RSS Feed(s)
2420
+				EE_Admin_Page::cached_rss_display(
2421
+					'espresso_news_post_box_content',
2422
+					esc_url_raw(
2423
+						apply_filters(
2424
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2425
+							'https://eventespresso.com/feed/'
2426
+						)
2427
+					)
2428
+				);
2429
+				?>
2430 2430
             </div>
2431 2431
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2432 2432
         </div>
2433 2433
         <?php
2434
-    }
2435
-
2436
-
2437
-    private function _espresso_links_post_box()
2438
-    {
2439
-        // Hiding until we actually have content to put in here...
2440
-        // $this->addMetaBox('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2441
-    }
2442
-
2443
-
2444
-    public function espresso_links_post_box()
2445
-    {
2446
-        // Hiding until we actually have content to put in here...
2447
-        // EEH_Template::display_template(
2448
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2449
-        // );
2450
-    }
2451
-
2452
-
2453
-    protected function _espresso_sponsors_post_box()
2454
-    {
2455
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2456
-            $this->addMetaBox(
2457
-                'espresso_sponsors_post_box',
2458
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2459
-                [$this, 'espresso_sponsors_post_box'],
2460
-                $this->_wp_page_slug,
2461
-                'side'
2462
-            );
2463
-        }
2464
-    }
2465
-
2466
-
2467
-    public function espresso_sponsors_post_box()
2468
-    {
2469
-        EEH_Template::display_template(
2470
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2471
-        );
2472
-    }
2473
-
2474
-
2475
-    /**
2476
-     * if there is [ 'label' => [ 'publishbox' => 'some title' ]]
2477
-     * present in the _page_config array, then we'll use that for the metabox label.
2478
-     * Otherwise we'll just use publish
2479
-     * (publishbox itself could be an array of labels indexed by routes)
2480
-     *
2481
-     * @return string
2482
-     * @since   5.0.0.p
2483
-     */
2484
-    protected function getPublishBoxTitle(): string
2485
-    {
2486
-        $publish_box_title = esc_html__('Publish', 'event_espresso');
2487
-        if (! empty($this->_labels['publishbox'])) {
2488
-            if (is_array($this->_labels['publishbox'])) {
2489
-                $publish_box_title = $this->_labels['publishbox'][ $this->_req_action ] ?? $publish_box_title;
2490
-            } else {
2491
-                $publish_box_title = $this->_labels['publishbox'];
2492
-            }
2493
-        }
2494
-        return apply_filters(
2495
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2496
-            $publish_box_title,
2497
-            $this->_req_action,
2498
-            $this
2499
-        );
2500
-    }
2501
-
2502
-
2503
-    /**
2504
-     * @throws EE_Error
2505
-     */
2506
-    private function _publish_post_box()
2507
-    {
2508
-        $title = $this->getPublishBoxTitle();
2509
-        if (empty($this->_template_args['save_buttons'])) {
2510
-            $this->_set_publish_post_box_vars(
2511
-                sanitize_key($title),
2512
-                "espresso_{$this->page_slug}_editor_overview",
2513
-                '',
2514
-                '',
2515
-                true
2516
-            );
2517
-        } else {
2518
-            $this->addPublishPostMetaBoxHiddenFields(
2519
-                sanitize_key($title),
2520
-                ['type' => 'hidden', 'value' => "espresso_{$this->page_slug}_editor_overview"]
2521
-            );
2522
-        }
2523
-        $this->addMetaBox(
2524
-            "espresso_{$this->page_slug}_editor_overview",
2525
-            $title,
2526
-            [$this, 'editor_overview'],
2527
-            $this->_current_screen->id,
2528
-            'side',
2529
-            'high'
2530
-        );
2531
-    }
2532
-
2533
-
2534
-    public function editor_overview()
2535
-    {
2536
-        /**
2537
-         * @var string $publish_box_extra_content
2538
-         * @var string $publish_hidden_fields
2539
-         * @var string $publish_delete_link
2540
-         * @var string $save_buttons
2541
-         */
2542
-        // if we have extra content set let's add it in if not make sure its empty
2543
-        $this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? '';
2544
-        echo EEH_Template::display_template(
2545
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2546
-            $this->_template_args,
2547
-            true
2548
-        );
2549
-    }
2550
-
2551
-
2552
-    /** end of globally available metaboxes section **/
2553
-
2554
-
2555
-    /**
2556
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2557
-     * Note: currently there is no validation for this.  However, if you want the delete button, the
2558
-     * save, and save and close buttons to work properly, then you will want to include a
2559
-     * values for the name and id arguments.
2560
-     *
2561
-     * @param string|null $name                     key used for the action ID (i.e. event_id)
2562
-     * @param int|string  $id                       id attached to the item published
2563
-     * @param string|null $delete                   page route callback for the delete action
2564
-     * @param string|null $save_close_redirect_URL  custom URL to redirect to after Save & Close has been completed
2565
-     * @param boolean     $both_btns                whether to display BOTH the "Save & Close" and "Save" buttons
2566
-     *                                              or just the "Save" button
2567
-     * @throws EE_Error
2568
-     * @throws InvalidArgumentException
2569
-     * @throws InvalidDataTypeException
2570
-     * @throws InvalidInterfaceException
2571
-     * @todo  Add in validation for name/id arguments.
2572
-     */
2573
-    protected function _set_publish_post_box_vars(
2574
-        ?string $name = '',
2575
-        $id = 0,
2576
-        ?string $delete = '',
2577
-        ?string $save_close_redirect_URL = '',
2578
-        bool $both_btns = true
2579
-    ) {
2580
-        // if Save & Close, use a custom redirect URL or default to the main page?
2581
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2582
-            ? $save_close_redirect_URL
2583
-            : $this->_admin_base_url;
2584
-        // create the Save & Close and Save buttons
2585
-        $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2586
-        // if we have extra content set let's add it in if not make sure its empty
2587
-        $this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? '';
2588
-        if ($delete && ! empty($id) && empty($this->_template_args['publish_delete_link'])) {
2589
-            // make sure we have a default if just true is sent.
2590
-            $delete      = ! empty($delete) ? $delete : 'delete';
2591
-            $this->_template_args['publish_delete_link'] = $this->get_action_link_or_button(
2592
-                $delete,
2593
-                $delete,
2594
-                [$name => $id],
2595
-                'submitdelete deletion button button--outline button--caution'
2596
-            );
2597
-        }
2598
-        if (! isset($this->_template_args['publish_delete_link'])) {
2599
-            $this->_template_args['publish_delete_link'] = '';
2600
-        }
2601
-        if (! empty($name) && ! empty($id)) {
2602
-            $this->addPublishPostMetaBoxHiddenFields($name, ['type' => 'hidden', 'value' => $id]);
2603
-        }
2604
-        $hidden_fields = $this->_generate_admin_form_fields($this->publish_post_meta_box_hidden_fields, 'array');
2605
-        // add hidden fields
2606
-        $this->_template_args['publish_hidden_fields'] = $this->_template_args['publish_hidden_fields'] ?? '';
2607
-        foreach ($hidden_fields as $hidden_field) {
2608
-            $this->_template_args['publish_hidden_fields'] .= $hidden_field['field'] ?? '';
2609
-        }
2610
-    }
2611
-
2612
-
2613
-    /**
2614
-     * @param string|null $name
2615
-     * @param int|string  $id
2616
-     * @param string|null $delete
2617
-     * @param string|null $save_close_redirect_URL
2618
-     * @param bool        $both_btns
2619
-     * @throws EE_Error
2620
-     */
2621
-    public function set_publish_post_box_vars(
2622
-        ?string $name = '',
2623
-        $id = 0,
2624
-        ?string $delete = '',
2625
-        ?string $save_close_redirect_URL = '',
2626
-        bool $both_btns = false
2627
-    ) {
2628
-        $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2629
-    }
2630
-
2631
-
2632
-    protected function addPublishPostMetaBoxHiddenFields(string $field_name, array $field_attributes)
2633
-    {
2634
-        $this->publish_post_meta_box_hidden_fields[ $field_name ] = $field_attributes;
2635
-    }
2636
-
2637
-
2638
-    /**
2639
-     * displays an error message to ppl who have javascript disabled
2640
-     *
2641
-     * @return void
2642
-     */
2643
-    private function _display_no_javascript_warning()
2644
-    {
2645
-        ?>
2434
+	}
2435
+
2436
+
2437
+	private function _espresso_links_post_box()
2438
+	{
2439
+		// Hiding until we actually have content to put in here...
2440
+		// $this->addMetaBox('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2441
+	}
2442
+
2443
+
2444
+	public function espresso_links_post_box()
2445
+	{
2446
+		// Hiding until we actually have content to put in here...
2447
+		// EEH_Template::display_template(
2448
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2449
+		// );
2450
+	}
2451
+
2452
+
2453
+	protected function _espresso_sponsors_post_box()
2454
+	{
2455
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2456
+			$this->addMetaBox(
2457
+				'espresso_sponsors_post_box',
2458
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2459
+				[$this, 'espresso_sponsors_post_box'],
2460
+				$this->_wp_page_slug,
2461
+				'side'
2462
+			);
2463
+		}
2464
+	}
2465
+
2466
+
2467
+	public function espresso_sponsors_post_box()
2468
+	{
2469
+		EEH_Template::display_template(
2470
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2471
+		);
2472
+	}
2473
+
2474
+
2475
+	/**
2476
+	 * if there is [ 'label' => [ 'publishbox' => 'some title' ]]
2477
+	 * present in the _page_config array, then we'll use that for the metabox label.
2478
+	 * Otherwise we'll just use publish
2479
+	 * (publishbox itself could be an array of labels indexed by routes)
2480
+	 *
2481
+	 * @return string
2482
+	 * @since   5.0.0.p
2483
+	 */
2484
+	protected function getPublishBoxTitle(): string
2485
+	{
2486
+		$publish_box_title = esc_html__('Publish', 'event_espresso');
2487
+		if (! empty($this->_labels['publishbox'])) {
2488
+			if (is_array($this->_labels['publishbox'])) {
2489
+				$publish_box_title = $this->_labels['publishbox'][ $this->_req_action ] ?? $publish_box_title;
2490
+			} else {
2491
+				$publish_box_title = $this->_labels['publishbox'];
2492
+			}
2493
+		}
2494
+		return apply_filters(
2495
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2496
+			$publish_box_title,
2497
+			$this->_req_action,
2498
+			$this
2499
+		);
2500
+	}
2501
+
2502
+
2503
+	/**
2504
+	 * @throws EE_Error
2505
+	 */
2506
+	private function _publish_post_box()
2507
+	{
2508
+		$title = $this->getPublishBoxTitle();
2509
+		if (empty($this->_template_args['save_buttons'])) {
2510
+			$this->_set_publish_post_box_vars(
2511
+				sanitize_key($title),
2512
+				"espresso_{$this->page_slug}_editor_overview",
2513
+				'',
2514
+				'',
2515
+				true
2516
+			);
2517
+		} else {
2518
+			$this->addPublishPostMetaBoxHiddenFields(
2519
+				sanitize_key($title),
2520
+				['type' => 'hidden', 'value' => "espresso_{$this->page_slug}_editor_overview"]
2521
+			);
2522
+		}
2523
+		$this->addMetaBox(
2524
+			"espresso_{$this->page_slug}_editor_overview",
2525
+			$title,
2526
+			[$this, 'editor_overview'],
2527
+			$this->_current_screen->id,
2528
+			'side',
2529
+			'high'
2530
+		);
2531
+	}
2532
+
2533
+
2534
+	public function editor_overview()
2535
+	{
2536
+		/**
2537
+		 * @var string $publish_box_extra_content
2538
+		 * @var string $publish_hidden_fields
2539
+		 * @var string $publish_delete_link
2540
+		 * @var string $save_buttons
2541
+		 */
2542
+		// if we have extra content set let's add it in if not make sure its empty
2543
+		$this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? '';
2544
+		echo EEH_Template::display_template(
2545
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2546
+			$this->_template_args,
2547
+			true
2548
+		);
2549
+	}
2550
+
2551
+
2552
+	/** end of globally available metaboxes section **/
2553
+
2554
+
2555
+	/**
2556
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2557
+	 * Note: currently there is no validation for this.  However, if you want the delete button, the
2558
+	 * save, and save and close buttons to work properly, then you will want to include a
2559
+	 * values for the name and id arguments.
2560
+	 *
2561
+	 * @param string|null $name                     key used for the action ID (i.e. event_id)
2562
+	 * @param int|string  $id                       id attached to the item published
2563
+	 * @param string|null $delete                   page route callback for the delete action
2564
+	 * @param string|null $save_close_redirect_URL  custom URL to redirect to after Save & Close has been completed
2565
+	 * @param boolean     $both_btns                whether to display BOTH the "Save & Close" and "Save" buttons
2566
+	 *                                              or just the "Save" button
2567
+	 * @throws EE_Error
2568
+	 * @throws InvalidArgumentException
2569
+	 * @throws InvalidDataTypeException
2570
+	 * @throws InvalidInterfaceException
2571
+	 * @todo  Add in validation for name/id arguments.
2572
+	 */
2573
+	protected function _set_publish_post_box_vars(
2574
+		?string $name = '',
2575
+		$id = 0,
2576
+		?string $delete = '',
2577
+		?string $save_close_redirect_URL = '',
2578
+		bool $both_btns = true
2579
+	) {
2580
+		// if Save & Close, use a custom redirect URL or default to the main page?
2581
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2582
+			? $save_close_redirect_URL
2583
+			: $this->_admin_base_url;
2584
+		// create the Save & Close and Save buttons
2585
+		$this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2586
+		// if we have extra content set let's add it in if not make sure its empty
2587
+		$this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? '';
2588
+		if ($delete && ! empty($id) && empty($this->_template_args['publish_delete_link'])) {
2589
+			// make sure we have a default if just true is sent.
2590
+			$delete      = ! empty($delete) ? $delete : 'delete';
2591
+			$this->_template_args['publish_delete_link'] = $this->get_action_link_or_button(
2592
+				$delete,
2593
+				$delete,
2594
+				[$name => $id],
2595
+				'submitdelete deletion button button--outline button--caution'
2596
+			);
2597
+		}
2598
+		if (! isset($this->_template_args['publish_delete_link'])) {
2599
+			$this->_template_args['publish_delete_link'] = '';
2600
+		}
2601
+		if (! empty($name) && ! empty($id)) {
2602
+			$this->addPublishPostMetaBoxHiddenFields($name, ['type' => 'hidden', 'value' => $id]);
2603
+		}
2604
+		$hidden_fields = $this->_generate_admin_form_fields($this->publish_post_meta_box_hidden_fields, 'array');
2605
+		// add hidden fields
2606
+		$this->_template_args['publish_hidden_fields'] = $this->_template_args['publish_hidden_fields'] ?? '';
2607
+		foreach ($hidden_fields as $hidden_field) {
2608
+			$this->_template_args['publish_hidden_fields'] .= $hidden_field['field'] ?? '';
2609
+		}
2610
+	}
2611
+
2612
+
2613
+	/**
2614
+	 * @param string|null $name
2615
+	 * @param int|string  $id
2616
+	 * @param string|null $delete
2617
+	 * @param string|null $save_close_redirect_URL
2618
+	 * @param bool        $both_btns
2619
+	 * @throws EE_Error
2620
+	 */
2621
+	public function set_publish_post_box_vars(
2622
+		?string $name = '',
2623
+		$id = 0,
2624
+		?string $delete = '',
2625
+		?string $save_close_redirect_URL = '',
2626
+		bool $both_btns = false
2627
+	) {
2628
+		$this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2629
+	}
2630
+
2631
+
2632
+	protected function addPublishPostMetaBoxHiddenFields(string $field_name, array $field_attributes)
2633
+	{
2634
+		$this->publish_post_meta_box_hidden_fields[ $field_name ] = $field_attributes;
2635
+	}
2636
+
2637
+
2638
+	/**
2639
+	 * displays an error message to ppl who have javascript disabled
2640
+	 *
2641
+	 * @return void
2642
+	 */
2643
+	private function _display_no_javascript_warning()
2644
+	{
2645
+		?>
2646 2646
         <noscript>
2647 2647
             <div id="no-js-message" class="error">
2648 2648
                 <p style="font-size:1.3em;">
2649 2649
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2650 2650
                     <?php esc_html_e(
2651
-                        'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2652
-                        'event_espresso'
2653
-                    ); ?>
2651
+						'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2652
+						'event_espresso'
2653
+					); ?>
2654 2654
                 </p>
2655 2655
             </div>
2656 2656
         </noscript>
2657 2657
         <?php
2658
-    }
2659
-
2660
-
2661
-    /**
2662
-     * displays espresso success and/or error notices
2663
-     *
2664
-     * @return void
2665
-     */
2666
-    protected function _display_espresso_notices()
2667
-    {
2668
-        $notices = $this->_get_transient(true);
2669
-        echo stripslashes($notices);
2670
-    }
2671
-
2672
-
2673
-    /**
2674
-     * spinny things pacify the masses
2675
-     *
2676
-     * @return void
2677
-     */
2678
-    protected function _add_admin_page_ajax_loading_img()
2679
-    {
2680
-        ?>
2658
+	}
2659
+
2660
+
2661
+	/**
2662
+	 * displays espresso success and/or error notices
2663
+	 *
2664
+	 * @return void
2665
+	 */
2666
+	protected function _display_espresso_notices()
2667
+	{
2668
+		$notices = $this->_get_transient(true);
2669
+		echo stripslashes($notices);
2670
+	}
2671
+
2672
+
2673
+	/**
2674
+	 * spinny things pacify the masses
2675
+	 *
2676
+	 * @return void
2677
+	 */
2678
+	protected function _add_admin_page_ajax_loading_img()
2679
+	{
2680
+		?>
2681 2681
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2682 2682
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php
2683
-                esc_html_e('loading...', 'event_espresso'); ?></span>
2683
+				esc_html_e('loading...', 'event_espresso'); ?></span>
2684 2684
         </div>
2685 2685
         <?php
2686
-    }
2686
+	}
2687 2687
 
2688 2688
 
2689
-    /**
2690
-     * add admin page overlay for modal boxes
2691
-     *
2692
-     * @return void
2693
-     */
2694
-    protected function _add_admin_page_overlay()
2695
-    {
2696
-        ?>
2689
+	/**
2690
+	 * add admin page overlay for modal boxes
2691
+	 *
2692
+	 * @return void
2693
+	 */
2694
+	protected function _add_admin_page_overlay()
2695
+	{
2696
+		?>
2697 2697
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2698 2698
         <?php
2699
-    }
2700
-
2701
-
2702
-    /**
2703
-     * facade for $this->addMetaBox()
2704
-     *
2705
-     * @param string  $action        where the metabox gets displayed
2706
-     * @param string  $title         Title of Metabox (output in metabox header)
2707
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2708
-     *                               instead of the one created in here.
2709
-     * @param array   $callback_args an array of args supplied for the metabox
2710
-     * @param string  $column        what metabox column
2711
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2712
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2713
-     *                               created but just set our own callback for wp's add_meta_box.
2714
-     * @throws DomainException
2715
-     */
2716
-    public function _add_admin_page_meta_box(
2717
-        $action,
2718
-        $title,
2719
-        $callback,
2720
-        $callback_args,
2721
-        $column = 'normal',
2722
-        $priority = 'high',
2723
-        $create_func = true
2724
-    ) {
2725
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2726
-        // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2727
-        if (empty($callback_args) && $create_func) {
2728
-            $callback_args = [
2729
-                'template_path' => $this->_template_path,
2730
-                'template_args' => $this->_template_args,
2731
-            ];
2732
-        }
2733
-        // if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2734
-        $call_back_func = $create_func
2735
-            ? static function ($post, $metabox) {
2736
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2737
-                echo EEH_Template::display_template(
2738
-                    $metabox['args']['template_path'],
2739
-                    $metabox['args']['template_args'],
2740
-                    true
2741
-                );
2742
-            }
2743
-            : $callback;
2744
-        $this->addMetaBox(
2745
-            str_replace('_', '-', $action) . '-mbox',
2746
-            $title,
2747
-            $call_back_func,
2748
-            $this->_wp_page_slug,
2749
-            $column,
2750
-            $priority,
2751
-            $callback_args
2752
-        );
2753
-    }
2754
-
2755
-
2756
-    /**
2757
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2758
-     *
2759
-     * @throws DomainException
2760
-     * @throws EE_Error
2761
-     * @throws InvalidArgumentException
2762
-     * @throws InvalidDataTypeException
2763
-     * @throws InvalidInterfaceException
2764
-     */
2765
-    public function display_admin_page_with_metabox_columns()
2766
-    {
2767
-        $this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2768
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2769
-            $this->_column_template_path,
2770
-            $this->_template_args,
2771
-            true
2772
-        );
2773
-        // the final wrapper
2774
-        $this->admin_page_wrapper();
2775
-    }
2776
-
2777
-
2778
-    /**
2779
-     * generates  HTML wrapper for an admin details page
2780
-     *
2781
-     * @return void
2782
-     * @throws DomainException
2783
-     * @throws EE_Error
2784
-     * @throws InvalidArgumentException
2785
-     * @throws InvalidDataTypeException
2786
-     * @throws InvalidInterfaceException
2787
-     */
2788
-    public function display_admin_page_with_sidebar()
2789
-    {
2790
-        $this->_display_admin_page(true);
2791
-    }
2792
-
2793
-
2794
-    /**
2795
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2796
-     *
2797
-     * @return void
2798
-     * @throws DomainException
2799
-     * @throws EE_Error
2800
-     * @throws InvalidArgumentException
2801
-     * @throws InvalidDataTypeException
2802
-     * @throws InvalidInterfaceException
2803
-     */
2804
-    public function display_admin_page_with_no_sidebar()
2805
-    {
2806
-        $this->_display_admin_page();
2807
-    }
2808
-
2809
-
2810
-    /**
2811
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2812
-     *
2813
-     * @return void
2814
-     * @throws DomainException
2815
-     * @throws EE_Error
2816
-     * @throws InvalidArgumentException
2817
-     * @throws InvalidDataTypeException
2818
-     * @throws InvalidInterfaceException
2819
-     */
2820
-    public function display_about_admin_page()
2821
-    {
2822
-        $this->_display_admin_page(false, true);
2823
-    }
2824
-
2825
-
2826
-    /**
2827
-     * display_admin_page
2828
-     * contains the code for actually displaying an admin page
2829
-     *
2830
-     * @param boolean $sidebar true with sidebar, false without
2831
-     * @param boolean $about   use the about admin wrapper instead of the default.
2832
-     * @return void
2833
-     * @throws DomainException
2834
-     * @throws EE_Error
2835
-     * @throws InvalidArgumentException
2836
-     * @throws InvalidDataTypeException
2837
-     * @throws InvalidInterfaceException
2838
-     */
2839
-    private function _display_admin_page($sidebar = false, $about = false)
2840
-    {
2841
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2842
-        // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2843
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2844
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2845
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2846
-
2847
-        $post_body_content = $this->_template_args['before_admin_page_content'] ?? '';
2848
-
2849
-        $this->_template_args['add_page_frame'] = $this->_req_action !== 'system_status'
2850
-                                                  && $this->_req_action !== 'data_reset'
2851
-                                                  && $this->_wp_page_slug !== 'event-espresso_page_espresso_packages'
2852
-                                                  && strpos($post_body_content, 'wp-list-table') === false;
2853
-
2854
-        $this->_template_args['current_page']                 = $this->_wp_page_slug;
2855
-        $this->_template_args['admin_page_wrapper_div_id']    = $this->_cpt_route
2856
-            ? 'poststuff'
2857
-            : 'espresso-default-admin';
2858
-        $this->_template_args['admin_page_wrapper_div_class'] = str_replace(
2859
-                                                                    'event-espresso_page_espresso_',
2860
-                                                                    '',
2861
-                                                                    $this->_wp_page_slug
2862
-                                                                ) . ' ' . $this->_req_action . '-route';
2863
-
2864
-        $template_path = $sidebar
2865
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2866
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2867
-        if ($this->request->isAjax()) {
2868
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2869
-        }
2870
-        $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2871
-
2872
-        $this->_template_args['post_body_content']         = $this->_template_args['admin_page_content'] ?? '';
2873
-        $this->_template_args['before_admin_page_content'] = $post_body_content;
2874
-        $this->_template_args['after_admin_page_content']  = $this->_template_args['after_admin_page_content'] ?? '';
2875
-        $this->_template_args['admin_page_content']        = EEH_Template::display_template(
2876
-            $template_path,
2877
-            $this->_template_args,
2878
-            true
2879
-        );
2880
-        // the final template wrapper
2881
-        $this->admin_page_wrapper($about);
2882
-    }
2883
-
2884
-
2885
-    /**
2886
-     * This is used to display caf preview pages.
2887
-     *
2888
-     * @param string $utm_campaign_source what is the key used for google analytics link
2889
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2890
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2891
-     * @return void
2892
-     * @throws DomainException
2893
-     * @throws EE_Error
2894
-     * @throws InvalidArgumentException
2895
-     * @throws InvalidDataTypeException
2896
-     * @throws InvalidInterfaceException
2897
-     * @since 4.3.2
2898
-     */
2899
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2900
-    {
2901
-        // let's generate a default preview action button if there isn't one already present.
2902
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2903
-            'Upgrade to Event Espresso 4 Right Now',
2904
-            'event_espresso'
2905
-        );
2906
-        $buy_now_url                                   = add_query_arg(
2907
-            [
2908
-                'ee_ver'       => 'ee4',
2909
-                'utm_source'   => 'ee4_plugin_admin',
2910
-                'utm_medium'   => 'link',
2911
-                'utm_campaign' => $utm_campaign_source,
2912
-                'utm_content'  => 'buy_now_button',
2913
-            ],
2914
-            'https://eventespresso.com/pricing/'
2915
-        );
2916
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2917
-            ? $this->get_action_link_or_button(
2918
-                '',
2919
-                'buy_now',
2920
-                [],
2921
-                'button button--primary button--big',
2922
-                esc_url_raw($buy_now_url),
2923
-                true
2924
-            )
2925
-            : $this->_template_args['preview_action_button'];
2926
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2927
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2928
-            $this->_template_args,
2929
-            true
2930
-        );
2931
-        $this->_display_admin_page($display_sidebar);
2932
-    }
2933
-
2934
-
2935
-    /**
2936
-     * display_admin_list_table_page_with_sidebar
2937
-     * generates HTML wrapper for an admin_page with list_table
2938
-     *
2939
-     * @return void
2940
-     * @throws DomainException
2941
-     * @throws EE_Error
2942
-     * @throws InvalidArgumentException
2943
-     * @throws InvalidDataTypeException
2944
-     * @throws InvalidInterfaceException
2945
-     */
2946
-    public function display_admin_list_table_page_with_sidebar()
2947
-    {
2948
-        $this->_display_admin_list_table_page(true);
2949
-    }
2950
-
2951
-
2952
-    /**
2953
-     * display_admin_list_table_page_with_no_sidebar
2954
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2955
-     *
2956
-     * @return void
2957
-     * @throws DomainException
2958
-     * @throws EE_Error
2959
-     * @throws InvalidArgumentException
2960
-     * @throws InvalidDataTypeException
2961
-     * @throws InvalidInterfaceException
2962
-     */
2963
-    public function display_admin_list_table_page_with_no_sidebar()
2964
-    {
2965
-        $this->_display_admin_list_table_page();
2966
-    }
2967
-
2968
-
2969
-    /**
2970
-     * generates html wrapper for an admin_list_table page
2971
-     *
2972
-     * @param boolean $sidebar whether to display with sidebar or not.
2973
-     * @return void
2974
-     * @throws DomainException
2975
-     * @throws EE_Error
2976
-     * @throws InvalidArgumentException
2977
-     * @throws InvalidDataTypeException
2978
-     * @throws InvalidInterfaceException
2979
-     */
2980
-    private function _display_admin_list_table_page($sidebar = false)
2981
-    {
2982
-        // setup search attributes
2983
-        $this->_set_search_attributes();
2984
-        $this->_template_args['current_page']     = $this->_wp_page_slug;
2985
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2986
-        $this->_template_args['table_url']        = $this->request->isAjax()
2987
-            ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2988
-            : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2989
-        $this->_template_args['list_table']       = $this->_list_table_object;
2990
-        $this->_template_args['current_route']    = $this->_req_action;
2991
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2992
-        $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2993
-        if (! empty($ajax_sorting_callback)) {
2994
-            $sortable_list_table_form_fields = wp_nonce_field(
2995
-                $ajax_sorting_callback . '_nonce',
2996
-                $ajax_sorting_callback . '_nonce',
2997
-                false,
2998
-                false
2999
-            );
3000
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
3001
-                                                . $this->page_slug
3002
-                                                . '" />';
3003
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
3004
-                                                . $ajax_sorting_callback
3005
-                                                . '" />';
3006
-        } else {
3007
-            $sortable_list_table_form_fields = '';
3008
-        }
3009
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3010
-
3011
-        $hidden_form_fields = $this->_template_args['list_table_hidden_fields'] ?? '';
3012
-
3013
-        $nonce_ref          = $this->_req_action . '_nonce';
3014
-        $hidden_form_fields .= '
2699
+	}
2700
+
2701
+
2702
+	/**
2703
+	 * facade for $this->addMetaBox()
2704
+	 *
2705
+	 * @param string  $action        where the metabox gets displayed
2706
+	 * @param string  $title         Title of Metabox (output in metabox header)
2707
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2708
+	 *                               instead of the one created in here.
2709
+	 * @param array   $callback_args an array of args supplied for the metabox
2710
+	 * @param string  $column        what metabox column
2711
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2712
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2713
+	 *                               created but just set our own callback for wp's add_meta_box.
2714
+	 * @throws DomainException
2715
+	 */
2716
+	public function _add_admin_page_meta_box(
2717
+		$action,
2718
+		$title,
2719
+		$callback,
2720
+		$callback_args,
2721
+		$column = 'normal',
2722
+		$priority = 'high',
2723
+		$create_func = true
2724
+	) {
2725
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2726
+		// if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2727
+		if (empty($callback_args) && $create_func) {
2728
+			$callback_args = [
2729
+				'template_path' => $this->_template_path,
2730
+				'template_args' => $this->_template_args,
2731
+			];
2732
+		}
2733
+		// if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2734
+		$call_back_func = $create_func
2735
+			? static function ($post, $metabox) {
2736
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2737
+				echo EEH_Template::display_template(
2738
+					$metabox['args']['template_path'],
2739
+					$metabox['args']['template_args'],
2740
+					true
2741
+				);
2742
+			}
2743
+			: $callback;
2744
+		$this->addMetaBox(
2745
+			str_replace('_', '-', $action) . '-mbox',
2746
+			$title,
2747
+			$call_back_func,
2748
+			$this->_wp_page_slug,
2749
+			$column,
2750
+			$priority,
2751
+			$callback_args
2752
+		);
2753
+	}
2754
+
2755
+
2756
+	/**
2757
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2758
+	 *
2759
+	 * @throws DomainException
2760
+	 * @throws EE_Error
2761
+	 * @throws InvalidArgumentException
2762
+	 * @throws InvalidDataTypeException
2763
+	 * @throws InvalidInterfaceException
2764
+	 */
2765
+	public function display_admin_page_with_metabox_columns()
2766
+	{
2767
+		$this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2768
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2769
+			$this->_column_template_path,
2770
+			$this->_template_args,
2771
+			true
2772
+		);
2773
+		// the final wrapper
2774
+		$this->admin_page_wrapper();
2775
+	}
2776
+
2777
+
2778
+	/**
2779
+	 * generates  HTML wrapper for an admin details page
2780
+	 *
2781
+	 * @return void
2782
+	 * @throws DomainException
2783
+	 * @throws EE_Error
2784
+	 * @throws InvalidArgumentException
2785
+	 * @throws InvalidDataTypeException
2786
+	 * @throws InvalidInterfaceException
2787
+	 */
2788
+	public function display_admin_page_with_sidebar()
2789
+	{
2790
+		$this->_display_admin_page(true);
2791
+	}
2792
+
2793
+
2794
+	/**
2795
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2796
+	 *
2797
+	 * @return void
2798
+	 * @throws DomainException
2799
+	 * @throws EE_Error
2800
+	 * @throws InvalidArgumentException
2801
+	 * @throws InvalidDataTypeException
2802
+	 * @throws InvalidInterfaceException
2803
+	 */
2804
+	public function display_admin_page_with_no_sidebar()
2805
+	{
2806
+		$this->_display_admin_page();
2807
+	}
2808
+
2809
+
2810
+	/**
2811
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2812
+	 *
2813
+	 * @return void
2814
+	 * @throws DomainException
2815
+	 * @throws EE_Error
2816
+	 * @throws InvalidArgumentException
2817
+	 * @throws InvalidDataTypeException
2818
+	 * @throws InvalidInterfaceException
2819
+	 */
2820
+	public function display_about_admin_page()
2821
+	{
2822
+		$this->_display_admin_page(false, true);
2823
+	}
2824
+
2825
+
2826
+	/**
2827
+	 * display_admin_page
2828
+	 * contains the code for actually displaying an admin page
2829
+	 *
2830
+	 * @param boolean $sidebar true with sidebar, false without
2831
+	 * @param boolean $about   use the about admin wrapper instead of the default.
2832
+	 * @return void
2833
+	 * @throws DomainException
2834
+	 * @throws EE_Error
2835
+	 * @throws InvalidArgumentException
2836
+	 * @throws InvalidDataTypeException
2837
+	 * @throws InvalidInterfaceException
2838
+	 */
2839
+	private function _display_admin_page($sidebar = false, $about = false)
2840
+	{
2841
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2842
+		// custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2843
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2844
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2845
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2846
+
2847
+		$post_body_content = $this->_template_args['before_admin_page_content'] ?? '';
2848
+
2849
+		$this->_template_args['add_page_frame'] = $this->_req_action !== 'system_status'
2850
+												  && $this->_req_action !== 'data_reset'
2851
+												  && $this->_wp_page_slug !== 'event-espresso_page_espresso_packages'
2852
+												  && strpos($post_body_content, 'wp-list-table') === false;
2853
+
2854
+		$this->_template_args['current_page']                 = $this->_wp_page_slug;
2855
+		$this->_template_args['admin_page_wrapper_div_id']    = $this->_cpt_route
2856
+			? 'poststuff'
2857
+			: 'espresso-default-admin';
2858
+		$this->_template_args['admin_page_wrapper_div_class'] = str_replace(
2859
+																	'event-espresso_page_espresso_',
2860
+																	'',
2861
+																	$this->_wp_page_slug
2862
+																) . ' ' . $this->_req_action . '-route';
2863
+
2864
+		$template_path = $sidebar
2865
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2866
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2867
+		if ($this->request->isAjax()) {
2868
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2869
+		}
2870
+		$template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2871
+
2872
+		$this->_template_args['post_body_content']         = $this->_template_args['admin_page_content'] ?? '';
2873
+		$this->_template_args['before_admin_page_content'] = $post_body_content;
2874
+		$this->_template_args['after_admin_page_content']  = $this->_template_args['after_admin_page_content'] ?? '';
2875
+		$this->_template_args['admin_page_content']        = EEH_Template::display_template(
2876
+			$template_path,
2877
+			$this->_template_args,
2878
+			true
2879
+		);
2880
+		// the final template wrapper
2881
+		$this->admin_page_wrapper($about);
2882
+	}
2883
+
2884
+
2885
+	/**
2886
+	 * This is used to display caf preview pages.
2887
+	 *
2888
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2889
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2890
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2891
+	 * @return void
2892
+	 * @throws DomainException
2893
+	 * @throws EE_Error
2894
+	 * @throws InvalidArgumentException
2895
+	 * @throws InvalidDataTypeException
2896
+	 * @throws InvalidInterfaceException
2897
+	 * @since 4.3.2
2898
+	 */
2899
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2900
+	{
2901
+		// let's generate a default preview action button if there isn't one already present.
2902
+		$this->_labels['buttons']['buy_now']           = esc_html__(
2903
+			'Upgrade to Event Espresso 4 Right Now',
2904
+			'event_espresso'
2905
+		);
2906
+		$buy_now_url                                   = add_query_arg(
2907
+			[
2908
+				'ee_ver'       => 'ee4',
2909
+				'utm_source'   => 'ee4_plugin_admin',
2910
+				'utm_medium'   => 'link',
2911
+				'utm_campaign' => $utm_campaign_source,
2912
+				'utm_content'  => 'buy_now_button',
2913
+			],
2914
+			'https://eventespresso.com/pricing/'
2915
+		);
2916
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2917
+			? $this->get_action_link_or_button(
2918
+				'',
2919
+				'buy_now',
2920
+				[],
2921
+				'button button--primary button--big',
2922
+				esc_url_raw($buy_now_url),
2923
+				true
2924
+			)
2925
+			: $this->_template_args['preview_action_button'];
2926
+		$this->_template_args['admin_page_content']    = EEH_Template::display_template(
2927
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2928
+			$this->_template_args,
2929
+			true
2930
+		);
2931
+		$this->_display_admin_page($display_sidebar);
2932
+	}
2933
+
2934
+
2935
+	/**
2936
+	 * display_admin_list_table_page_with_sidebar
2937
+	 * generates HTML wrapper for an admin_page with list_table
2938
+	 *
2939
+	 * @return void
2940
+	 * @throws DomainException
2941
+	 * @throws EE_Error
2942
+	 * @throws InvalidArgumentException
2943
+	 * @throws InvalidDataTypeException
2944
+	 * @throws InvalidInterfaceException
2945
+	 */
2946
+	public function display_admin_list_table_page_with_sidebar()
2947
+	{
2948
+		$this->_display_admin_list_table_page(true);
2949
+	}
2950
+
2951
+
2952
+	/**
2953
+	 * display_admin_list_table_page_with_no_sidebar
2954
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2955
+	 *
2956
+	 * @return void
2957
+	 * @throws DomainException
2958
+	 * @throws EE_Error
2959
+	 * @throws InvalidArgumentException
2960
+	 * @throws InvalidDataTypeException
2961
+	 * @throws InvalidInterfaceException
2962
+	 */
2963
+	public function display_admin_list_table_page_with_no_sidebar()
2964
+	{
2965
+		$this->_display_admin_list_table_page();
2966
+	}
2967
+
2968
+
2969
+	/**
2970
+	 * generates html wrapper for an admin_list_table page
2971
+	 *
2972
+	 * @param boolean $sidebar whether to display with sidebar or not.
2973
+	 * @return void
2974
+	 * @throws DomainException
2975
+	 * @throws EE_Error
2976
+	 * @throws InvalidArgumentException
2977
+	 * @throws InvalidDataTypeException
2978
+	 * @throws InvalidInterfaceException
2979
+	 */
2980
+	private function _display_admin_list_table_page($sidebar = false)
2981
+	{
2982
+		// setup search attributes
2983
+		$this->_set_search_attributes();
2984
+		$this->_template_args['current_page']     = $this->_wp_page_slug;
2985
+		$template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2986
+		$this->_template_args['table_url']        = $this->request->isAjax()
2987
+			? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2988
+			: add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2989
+		$this->_template_args['list_table']       = $this->_list_table_object;
2990
+		$this->_template_args['current_route']    = $this->_req_action;
2991
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2992
+		$ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2993
+		if (! empty($ajax_sorting_callback)) {
2994
+			$sortable_list_table_form_fields = wp_nonce_field(
2995
+				$ajax_sorting_callback . '_nonce',
2996
+				$ajax_sorting_callback . '_nonce',
2997
+				false,
2998
+				false
2999
+			);
3000
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
3001
+												. $this->page_slug
3002
+												. '" />';
3003
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
3004
+												. $ajax_sorting_callback
3005
+												. '" />';
3006
+		} else {
3007
+			$sortable_list_table_form_fields = '';
3008
+		}
3009
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3010
+
3011
+		$hidden_form_fields = $this->_template_args['list_table_hidden_fields'] ?? '';
3012
+
3013
+		$nonce_ref          = $this->_req_action . '_nonce';
3014
+		$hidden_form_fields .= '
3015 3015
             <input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
3016 3016
 
3017
-        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
3018
-        // display message about search results?
3019
-        $search                                    = $this->request->getRequestParam('s');
3020
-        $this->_template_args['before_list_table'] .= ! empty($search)
3021
-            ? '<p class="ee-search-results">' . sprintf(
3022
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3023
-                trim($search, '%')
3024
-            ) . '</p>'
3025
-            : '';
3026
-        // filter before_list_table template arg
3027
-        $this->_template_args['before_list_table'] = apply_filters(
3028
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3029
-            $this->_template_args['before_list_table'],
3030
-            $this->page_slug,
3031
-            $this->request->requestParams(),
3032
-            $this->_req_action
3033
-        );
3034
-        // convert to array and filter again
3035
-        // arrays are easier to inject new items in a specific location,
3036
-        // but would not be backwards compatible, so we have to add a new filter
3037
-        $this->_template_args['before_list_table'] = implode(
3038
-            " \n",
3039
-            (array) apply_filters(
3040
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3041
-                (array) $this->_template_args['before_list_table'],
3042
-                $this->page_slug,
3043
-                $this->request->requestParams(),
3044
-                $this->_req_action
3045
-            )
3046
-        );
3047
-        // filter after_list_table template arg
3048
-        $this->_template_args['after_list_table'] = apply_filters(
3049
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3050
-            $this->_template_args['after_list_table'],
3051
-            $this->page_slug,
3052
-            $this->request->requestParams(),
3053
-            $this->_req_action
3054
-        );
3055
-        // convert to array and filter again
3056
-        // arrays are easier to inject new items in a specific location,
3057
-        // but would not be backwards compatible, so we have to add a new filter
3058
-        $this->_template_args['after_list_table']   = implode(
3059
-            " \n",
3060
-            (array) apply_filters(
3061
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3062
-                (array) $this->_template_args['after_list_table'],
3063
-                $this->page_slug,
3064
-                $this->request->requestParams(),
3065
-                $this->_req_action
3066
-            )
3067
-        );
3068
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3069
-            $template_path,
3070
-            $this->_template_args,
3071
-            true
3072
-        );
3073
-        // the final template wrapper
3074
-        if ($sidebar) {
3075
-            $this->display_admin_page_with_sidebar();
3076
-        } else {
3077
-            $this->display_admin_page_with_no_sidebar();
3078
-        }
3079
-    }
3080
-
3081
-
3082
-    /**
3083
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3084
-     * html string for the legend.
3085
-     * $items are expected in an array in the following format:
3086
-     * $legend_items = array(
3087
-     *        'item_id' => array(
3088
-     *            'icon' => 'http://url_to_icon_being_described.png',
3089
-     *            'desc' => esc_html__('localized description of item');
3090
-     *        )
3091
-     * );
3092
-     *
3093
-     * @param array $items see above for format of array
3094
-     * @return string html string of legend
3095
-     * @throws DomainException
3096
-     */
3097
-    protected function _display_legend($items)
3098
-    {
3099
-        $this->_template_args['items'] = apply_filters(
3100
-            'FHEE__EE_Admin_Page___display_legend__items',
3101
-            (array) $items,
3102
-            $this
3103
-        );
3104
-        /** @var StatusChangeNotice $status_change_notice */
3105
-        $status_change_notice                         = $this->loader->getShared(
3106
-            'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
3107
-        );
3108
-        $this->_template_args['status_change_notice'] = $status_change_notice->display(
3109
-            '__admin-legend',
3110
-            $this->page_slug
3111
-        );
3112
-        return EEH_Template::display_template(
3113
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3114
-            $this->_template_args,
3115
-            true
3116
-        );
3117
-    }
3118
-
3119
-
3120
-    /**
3121
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3122
-     * The returned json object is created from an array in the following format:
3123
-     * array(
3124
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3125
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
3126
-     *  'notices' => '', // - contains any EE_Error formatted notices
3127
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3128
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3129
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
3130
-     *  that might be included in here)
3131
-     * )
3132
-     * The json object is populated by whatever is set in the $_template_args property.
3133
-     *
3134
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3135
-     *                                 instead of displayed.
3136
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3137
-     * @return void
3138
-     * @throws EE_Error
3139
-     * @throws InvalidArgumentException
3140
-     * @throws InvalidDataTypeException
3141
-     * @throws InvalidInterfaceException
3142
-     */
3143
-    protected function _return_json($sticky_notices = false, $notices_arguments = [])
3144
-    {
3145
-        // make sure any EE_Error notices have been handled.
3146
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
3147
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
3148
-        unset($this->_template_args['data']);
3149
-        $json = [
3150
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3151
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3152
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3153
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3154
-            'notices'   => EE_Error::get_notices(),
3155
-            'content'   => isset($this->_template_args['admin_page_content'])
3156
-                ? $this->_template_args['admin_page_content'] : '',
3157
-            'data'      => array_merge($data, ['template_args' => $this->_template_args]),
3158
-            'isEEajax'  => true
3159
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3160
-        ];
3161
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
3162
-        if (null === error_get_last() || ! headers_sent()) {
3163
-            header('Content-Type: application/json; charset=UTF-8');
3164
-        }
3165
-        echo wp_json_encode($json);
3166
-        exit();
3167
-    }
3168
-
3169
-
3170
-    /**
3171
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3172
-     *
3173
-     * @return void
3174
-     * @throws EE_Error
3175
-     * @throws InvalidArgumentException
3176
-     * @throws InvalidDataTypeException
3177
-     * @throws InvalidInterfaceException
3178
-     */
3179
-    public function return_json()
3180
-    {
3181
-        if ($this->request->isAjax()) {
3182
-            $this->_return_json();
3183
-        } else {
3184
-            throw new EE_Error(
3185
-                sprintf(
3186
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3187
-                    __FUNCTION__
3188
-                )
3189
-            );
3190
-        }
3191
-    }
3192
-
3193
-
3194
-    /**
3195
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3196
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3197
-     *
3198
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3199
-     */
3200
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3201
-    {
3202
-        $this->_hook_obj = $hook_obj;
3203
-    }
3204
-
3205
-
3206
-    /**
3207
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3208
-     *
3209
-     * @param boolean $about whether to use the special about page wrapper or default.
3210
-     * @return void
3211
-     * @throws DomainException
3212
-     * @throws EE_Error
3213
-     * @throws InvalidArgumentException
3214
-     * @throws InvalidDataTypeException
3215
-     * @throws InvalidInterfaceException
3216
-     */
3217
-    public function admin_page_wrapper($about = false)
3218
-    {
3219
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3220
-        $this->_nav_tabs                          = $this->_get_main_nav_tabs();
3221
-        $this->_template_args['nav_tabs']         = $this->_nav_tabs;
3222
-        $this->_template_args['admin_page_title'] = $this->_admin_page_title;
3223
-
3224
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3225
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3226
-            $this->_template_args['before_admin_page_content'] ?? ''
3227
-        );
3228
-
3229
-        $this->_template_args['after_admin_page_content'] = apply_filters(
3230
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3231
-            $this->_template_args['after_admin_page_content'] ?? ''
3232
-        );
3233
-        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3234
-
3235
-        if ($this->request->isAjax()) {
3236
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3237
-            // $template_path,
3238
-                EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3239
-                $this->_template_args,
3240
-                true
3241
-            );
3242
-            $this->_return_json();
3243
-        }
3244
-        // load settings page wrapper template
3245
-        $template_path = $about
3246
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3247
-            : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3248
-
3249
-        EEH_Template::display_template($template_path, $this->_template_args);
3250
-    }
3251
-
3252
-
3253
-    /**
3254
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3255
-     *
3256
-     * @return string html
3257
-     * @throws EE_Error
3258
-     */
3259
-    protected function _get_main_nav_tabs()
3260
-    {
3261
-        // let's generate the html using the EEH_Tabbed_Content helper.
3262
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3263
-        // (rather than setting in the page_routes array)
3264
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs, $this->page_slug);
3265
-    }
3266
-
3267
-
3268
-    /**
3269
-     *        sort nav tabs
3270
-     *
3271
-     * @param $a
3272
-     * @param $b
3273
-     * @return int
3274
-     */
3275
-    private function _sort_nav_tabs($a, $b)
3276
-    {
3277
-        if ($a['order'] === $b['order']) {
3278
-            return 0;
3279
-        }
3280
-        return ($a['order'] < $b['order']) ? -1 : 1;
3281
-    }
3282
-
3283
-
3284
-    /**
3285
-     * generates HTML for the forms used on admin pages
3286
-     *
3287
-     * @param array  $input_vars - array of input field details
3288
-     * @param string $generator  indicates which generator to use: options are 'string' or 'array'
3289
-     * @param bool   $id
3290
-     * @return array|string
3291
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3292
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3293
-     */
3294
-    protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3295
-    {
3296
-        return $generator === 'string'
3297
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3298
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3299
-    }
3300
-
3301
-
3302
-    /**
3303
-     * generates the "Save" and "Save & Close" buttons for edit forms
3304
-     *
3305
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3306
-     *                                   Close" button.
3307
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3308
-     *                                   'Save', [1] => 'save & close')
3309
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3310
-     *                                   via the "name" value in the button).  We can also use this to just dump
3311
-     *                                   default actions by submitting some other value.
3312
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3313
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3314
-     *                                   close (normal form handling).
3315
-     */
3316
-    protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3317
-    {
3318
-        // make sure $text and $actions are in an array
3319
-        $text          = (array) $text;
3320
-        $actions       = (array) $actions;
3321
-        $referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3322
-        $button_text   = ! empty($text)
3323
-            ? $text
3324
-            : [
3325
-                esc_html__('Save', 'event_espresso'),
3326
-                esc_html__('Save and Close', 'event_espresso'),
3327
-            ];
3328
-        $default_names = ['save', 'save_and_close'];
3329
-        $buttons       = '';
3330
-        foreach ($button_text as $key => $button) {
3331
-            $ref     = $default_names[ $key ];
3332
-            $name    = ! empty($actions) ? $actions[ $key ] : $ref;
3333
-            $buttons .= '<input type="submit" class="button button--primary ' . $ref . '" '
3334
-                        . 'value="' . $button . '" name="' . $name . '" '
3335
-                        . 'id="' . $this->_current_view . '_' . $ref . '" />';
3336
-            if (! $both) {
3337
-                break;
3338
-            }
3339
-        }
3340
-        // add in a hidden index for the current page (so save and close redirects properly)
3341
-        $buttons                              .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3342
-                                                 . $referrer_url
3343
-                                                 . '" />';
3344
-        $this->_template_args['save_buttons'] = $buttons;
3345
-    }
3346
-
3347
-
3348
-    /**
3349
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3350
-     *
3351
-     * @param string $route
3352
-     * @param array  $additional_hidden_fields
3353
-     * @see   $this->_set_add_edit_form_tags() for details on params
3354
-     * @since 4.6.0
3355
-     */
3356
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3357
-    {
3358
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3359
-    }
3360
-
3361
-
3362
-    /**
3363
-     * set form open and close tags on add/edit pages.
3364
-     *
3365
-     * @param string $route                    the route you want the form to direct to
3366
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3367
-     * @return void
3368
-     */
3369
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3370
-    {
3371
-        if (empty($route)) {
3372
-            $user_msg = esc_html__(
3373
-                'An error occurred. No action was set for this page\'s form.',
3374
-                'event_espresso'
3375
-            );
3376
-            $dev_msg  = $user_msg . "\n"
3377
-                        . sprintf(
3378
-                            esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3379
-                            __FUNCTION__,
3380
-                            __CLASS__
3381
-                        );
3382
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3383
-        }
3384
-        // open form
3385
-        $action                                            = $this->_admin_base_url;
3386
-        $this->_template_args['before_admin_page_content'] = "
3017
+		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
3018
+		// display message about search results?
3019
+		$search                                    = $this->request->getRequestParam('s');
3020
+		$this->_template_args['before_list_table'] .= ! empty($search)
3021
+			? '<p class="ee-search-results">' . sprintf(
3022
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3023
+				trim($search, '%')
3024
+			) . '</p>'
3025
+			: '';
3026
+		// filter before_list_table template arg
3027
+		$this->_template_args['before_list_table'] = apply_filters(
3028
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3029
+			$this->_template_args['before_list_table'],
3030
+			$this->page_slug,
3031
+			$this->request->requestParams(),
3032
+			$this->_req_action
3033
+		);
3034
+		// convert to array and filter again
3035
+		// arrays are easier to inject new items in a specific location,
3036
+		// but would not be backwards compatible, so we have to add a new filter
3037
+		$this->_template_args['before_list_table'] = implode(
3038
+			" \n",
3039
+			(array) apply_filters(
3040
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3041
+				(array) $this->_template_args['before_list_table'],
3042
+				$this->page_slug,
3043
+				$this->request->requestParams(),
3044
+				$this->_req_action
3045
+			)
3046
+		);
3047
+		// filter after_list_table template arg
3048
+		$this->_template_args['after_list_table'] = apply_filters(
3049
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3050
+			$this->_template_args['after_list_table'],
3051
+			$this->page_slug,
3052
+			$this->request->requestParams(),
3053
+			$this->_req_action
3054
+		);
3055
+		// convert to array and filter again
3056
+		// arrays are easier to inject new items in a specific location,
3057
+		// but would not be backwards compatible, so we have to add a new filter
3058
+		$this->_template_args['after_list_table']   = implode(
3059
+			" \n",
3060
+			(array) apply_filters(
3061
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3062
+				(array) $this->_template_args['after_list_table'],
3063
+				$this->page_slug,
3064
+				$this->request->requestParams(),
3065
+				$this->_req_action
3066
+			)
3067
+		);
3068
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3069
+			$template_path,
3070
+			$this->_template_args,
3071
+			true
3072
+		);
3073
+		// the final template wrapper
3074
+		if ($sidebar) {
3075
+			$this->display_admin_page_with_sidebar();
3076
+		} else {
3077
+			$this->display_admin_page_with_no_sidebar();
3078
+		}
3079
+	}
3080
+
3081
+
3082
+	/**
3083
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3084
+	 * html string for the legend.
3085
+	 * $items are expected in an array in the following format:
3086
+	 * $legend_items = array(
3087
+	 *        'item_id' => array(
3088
+	 *            'icon' => 'http://url_to_icon_being_described.png',
3089
+	 *            'desc' => esc_html__('localized description of item');
3090
+	 *        )
3091
+	 * );
3092
+	 *
3093
+	 * @param array $items see above for format of array
3094
+	 * @return string html string of legend
3095
+	 * @throws DomainException
3096
+	 */
3097
+	protected function _display_legend($items)
3098
+	{
3099
+		$this->_template_args['items'] = apply_filters(
3100
+			'FHEE__EE_Admin_Page___display_legend__items',
3101
+			(array) $items,
3102
+			$this
3103
+		);
3104
+		/** @var StatusChangeNotice $status_change_notice */
3105
+		$status_change_notice                         = $this->loader->getShared(
3106
+			'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
3107
+		);
3108
+		$this->_template_args['status_change_notice'] = $status_change_notice->display(
3109
+			'__admin-legend',
3110
+			$this->page_slug
3111
+		);
3112
+		return EEH_Template::display_template(
3113
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3114
+			$this->_template_args,
3115
+			true
3116
+		);
3117
+	}
3118
+
3119
+
3120
+	/**
3121
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3122
+	 * The returned json object is created from an array in the following format:
3123
+	 * array(
3124
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3125
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
3126
+	 *  'notices' => '', // - contains any EE_Error formatted notices
3127
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3128
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3129
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
3130
+	 *  that might be included in here)
3131
+	 * )
3132
+	 * The json object is populated by whatever is set in the $_template_args property.
3133
+	 *
3134
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3135
+	 *                                 instead of displayed.
3136
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3137
+	 * @return void
3138
+	 * @throws EE_Error
3139
+	 * @throws InvalidArgumentException
3140
+	 * @throws InvalidDataTypeException
3141
+	 * @throws InvalidInterfaceException
3142
+	 */
3143
+	protected function _return_json($sticky_notices = false, $notices_arguments = [])
3144
+	{
3145
+		// make sure any EE_Error notices have been handled.
3146
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
3147
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
3148
+		unset($this->_template_args['data']);
3149
+		$json = [
3150
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3151
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3152
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3153
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3154
+			'notices'   => EE_Error::get_notices(),
3155
+			'content'   => isset($this->_template_args['admin_page_content'])
3156
+				? $this->_template_args['admin_page_content'] : '',
3157
+			'data'      => array_merge($data, ['template_args' => $this->_template_args]),
3158
+			'isEEajax'  => true
3159
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3160
+		];
3161
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
3162
+		if (null === error_get_last() || ! headers_sent()) {
3163
+			header('Content-Type: application/json; charset=UTF-8');
3164
+		}
3165
+		echo wp_json_encode($json);
3166
+		exit();
3167
+	}
3168
+
3169
+
3170
+	/**
3171
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3172
+	 *
3173
+	 * @return void
3174
+	 * @throws EE_Error
3175
+	 * @throws InvalidArgumentException
3176
+	 * @throws InvalidDataTypeException
3177
+	 * @throws InvalidInterfaceException
3178
+	 */
3179
+	public function return_json()
3180
+	{
3181
+		if ($this->request->isAjax()) {
3182
+			$this->_return_json();
3183
+		} else {
3184
+			throw new EE_Error(
3185
+				sprintf(
3186
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3187
+					__FUNCTION__
3188
+				)
3189
+			);
3190
+		}
3191
+	}
3192
+
3193
+
3194
+	/**
3195
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3196
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3197
+	 *
3198
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3199
+	 */
3200
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3201
+	{
3202
+		$this->_hook_obj = $hook_obj;
3203
+	}
3204
+
3205
+
3206
+	/**
3207
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3208
+	 *
3209
+	 * @param boolean $about whether to use the special about page wrapper or default.
3210
+	 * @return void
3211
+	 * @throws DomainException
3212
+	 * @throws EE_Error
3213
+	 * @throws InvalidArgumentException
3214
+	 * @throws InvalidDataTypeException
3215
+	 * @throws InvalidInterfaceException
3216
+	 */
3217
+	public function admin_page_wrapper($about = false)
3218
+	{
3219
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3220
+		$this->_nav_tabs                          = $this->_get_main_nav_tabs();
3221
+		$this->_template_args['nav_tabs']         = $this->_nav_tabs;
3222
+		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
3223
+
3224
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3225
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3226
+			$this->_template_args['before_admin_page_content'] ?? ''
3227
+		);
3228
+
3229
+		$this->_template_args['after_admin_page_content'] = apply_filters(
3230
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3231
+			$this->_template_args['after_admin_page_content'] ?? ''
3232
+		);
3233
+		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3234
+
3235
+		if ($this->request->isAjax()) {
3236
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3237
+			// $template_path,
3238
+				EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3239
+				$this->_template_args,
3240
+				true
3241
+			);
3242
+			$this->_return_json();
3243
+		}
3244
+		// load settings page wrapper template
3245
+		$template_path = $about
3246
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3247
+			: EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3248
+
3249
+		EEH_Template::display_template($template_path, $this->_template_args);
3250
+	}
3251
+
3252
+
3253
+	/**
3254
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3255
+	 *
3256
+	 * @return string html
3257
+	 * @throws EE_Error
3258
+	 */
3259
+	protected function _get_main_nav_tabs()
3260
+	{
3261
+		// let's generate the html using the EEH_Tabbed_Content helper.
3262
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3263
+		// (rather than setting in the page_routes array)
3264
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs, $this->page_slug);
3265
+	}
3266
+
3267
+
3268
+	/**
3269
+	 *        sort nav tabs
3270
+	 *
3271
+	 * @param $a
3272
+	 * @param $b
3273
+	 * @return int
3274
+	 */
3275
+	private function _sort_nav_tabs($a, $b)
3276
+	{
3277
+		if ($a['order'] === $b['order']) {
3278
+			return 0;
3279
+		}
3280
+		return ($a['order'] < $b['order']) ? -1 : 1;
3281
+	}
3282
+
3283
+
3284
+	/**
3285
+	 * generates HTML for the forms used on admin pages
3286
+	 *
3287
+	 * @param array  $input_vars - array of input field details
3288
+	 * @param string $generator  indicates which generator to use: options are 'string' or 'array'
3289
+	 * @param bool   $id
3290
+	 * @return array|string
3291
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3292
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3293
+	 */
3294
+	protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3295
+	{
3296
+		return $generator === 'string'
3297
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3298
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3299
+	}
3300
+
3301
+
3302
+	/**
3303
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3304
+	 *
3305
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3306
+	 *                                   Close" button.
3307
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3308
+	 *                                   'Save', [1] => 'save & close')
3309
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3310
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3311
+	 *                                   default actions by submitting some other value.
3312
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3313
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3314
+	 *                                   close (normal form handling).
3315
+	 */
3316
+	protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3317
+	{
3318
+		// make sure $text and $actions are in an array
3319
+		$text          = (array) $text;
3320
+		$actions       = (array) $actions;
3321
+		$referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3322
+		$button_text   = ! empty($text)
3323
+			? $text
3324
+			: [
3325
+				esc_html__('Save', 'event_espresso'),
3326
+				esc_html__('Save and Close', 'event_espresso'),
3327
+			];
3328
+		$default_names = ['save', 'save_and_close'];
3329
+		$buttons       = '';
3330
+		foreach ($button_text as $key => $button) {
3331
+			$ref     = $default_names[ $key ];
3332
+			$name    = ! empty($actions) ? $actions[ $key ] : $ref;
3333
+			$buttons .= '<input type="submit" class="button button--primary ' . $ref . '" '
3334
+						. 'value="' . $button . '" name="' . $name . '" '
3335
+						. 'id="' . $this->_current_view . '_' . $ref . '" />';
3336
+			if (! $both) {
3337
+				break;
3338
+			}
3339
+		}
3340
+		// add in a hidden index for the current page (so save and close redirects properly)
3341
+		$buttons                              .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3342
+												 . $referrer_url
3343
+												 . '" />';
3344
+		$this->_template_args['save_buttons'] = $buttons;
3345
+	}
3346
+
3347
+
3348
+	/**
3349
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3350
+	 *
3351
+	 * @param string $route
3352
+	 * @param array  $additional_hidden_fields
3353
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3354
+	 * @since 4.6.0
3355
+	 */
3356
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3357
+	{
3358
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3359
+	}
3360
+
3361
+
3362
+	/**
3363
+	 * set form open and close tags on add/edit pages.
3364
+	 *
3365
+	 * @param string $route                    the route you want the form to direct to
3366
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3367
+	 * @return void
3368
+	 */
3369
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3370
+	{
3371
+		if (empty($route)) {
3372
+			$user_msg = esc_html__(
3373
+				'An error occurred. No action was set for this page\'s form.',
3374
+				'event_espresso'
3375
+			);
3376
+			$dev_msg  = $user_msg . "\n"
3377
+						. sprintf(
3378
+							esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3379
+							__FUNCTION__,
3380
+							__CLASS__
3381
+						);
3382
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3383
+		}
3384
+		// open form
3385
+		$action                                            = $this->_admin_base_url;
3386
+		$this->_template_args['before_admin_page_content'] = "
3387 3387
             <form name='form' method='post' action='{$action}' id='{$route}_event_form' class='ee-admin-page-form' >
3388 3388
             ";
3389
-        // add nonce
3390
-        $nonce                                             =
3391
-            wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3392
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3393
-        // add REQUIRED form action
3394
-        $hidden_fields = [
3395
-            'action' => ['type' => 'hidden', 'value' => $route],
3396
-        ];
3397
-        // merge arrays
3398
-        $hidden_fields = is_array($additional_hidden_fields)
3399
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3400
-            : $hidden_fields;
3401
-        // generate form fields
3402
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3403
-        // add fields to form
3404
-        foreach ((array) $form_fields as $form_field) {
3405
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3406
-        }
3407
-        // close form
3408
-        $this->_template_args['after_admin_page_content'] = '</form>';
3409
-    }
3410
-
3411
-
3412
-    /**
3413
-     * Public Wrapper for _redirect_after_action() method since its
3414
-     * discovered it would be useful for external code to have access.
3415
-     *
3416
-     * @param bool   $success
3417
-     * @param string $what
3418
-     * @param string $action_desc
3419
-     * @param array  $query_args
3420
-     * @param bool   $override_overwrite
3421
-     * @throws EE_Error
3422
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3423
-     * @since 4.5.0
3424
-     */
3425
-    public function redirect_after_action(
3426
-        $success = false,
3427
-        $what = 'item',
3428
-        $action_desc = 'processed',
3429
-        $query_args = [],
3430
-        $override_overwrite = false
3431
-    ) {
3432
-        $this->_redirect_after_action(
3433
-            $success,
3434
-            $what,
3435
-            $action_desc,
3436
-            $query_args,
3437
-            $override_overwrite
3438
-        );
3439
-    }
3440
-
3441
-
3442
-    /**
3443
-     * Helper method for merging existing request data with the returned redirect url.
3444
-     *
3445
-     * This is typically used for redirects after an action so that if the original view was a filtered view those
3446
-     * filters are still applied.
3447
-     *
3448
-     * @param array $new_route_data
3449
-     * @return array
3450
-     */
3451
-    protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3452
-    {
3453
-        foreach ($this->request->requestParams() as $ref => $value) {
3454
-            // unset nonces
3455
-            if (strpos($ref, 'nonce') !== false) {
3456
-                $this->request->unSetRequestParam($ref);
3457
-                continue;
3458
-            }
3459
-            // urlencode values.
3460
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3461
-            $this->request->setRequestParam($ref, $value);
3462
-        }
3463
-        return array_merge($this->request->requestParams(), $new_route_data);
3464
-    }
3465
-
3466
-
3467
-    /**
3468
-     * @param int|float|string $success            - whether success was for two or more records, or just one, or none
3469
-     * @param string           $what               - what the action was performed on
3470
-     * @param string           $action_desc        - what was done ie: updated, deleted, etc
3471
-     * @param array            $query_args         - an array of query_args to be added to the URL to redirect to
3472
-     * @param BOOL             $override_overwrite - by default all EE_Error::success messages are overwritten,
3473
-     *                                             this allows you to override this so that they show.
3474
-     * @return void
3475
-     * @throws EE_Error
3476
-     * @throws InvalidArgumentException
3477
-     * @throws InvalidDataTypeException
3478
-     * @throws InvalidInterfaceException
3479
-     */
3480
-    protected function _redirect_after_action(
3481
-        $success = 0,
3482
-        string $what = 'item',
3483
-        string $action_desc = 'processed',
3484
-        array $query_args = [],
3485
-        bool $override_overwrite = false
3486
-    ) {
3487
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3488
-        $notices = EE_Error::get_notices(false);
3489
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3490
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3491
-            EE_Error::overwrite_success();
3492
-        }
3493
-        if (! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3494
-            // how many records affected ? more than one record ? or just one ?
3495
-            EE_Error::add_success(
3496
-                sprintf(
3497
-                    esc_html(
3498
-                        _n(
3499
-                            'The "%1$s" has been successfully %2$s.',
3500
-                            'The "%1$s" have been successfully %2$s.',
3501
-                            $success,
3502
-                            'event_espresso'
3503
-                        )
3504
-                    ),
3505
-                    $what,
3506
-                    $action_desc
3507
-                ),
3508
-                __FILE__,
3509
-                __FUNCTION__,
3510
-                __LINE__
3511
-            );
3512
-        }
3513
-        // check that $query_args isn't something crazy
3514
-        if (! is_array($query_args)) {
3515
-            $query_args = [];
3516
-        }
3517
-        /**
3518
-         * Allow injecting actions before the query_args are modified for possible different
3519
-         * redirections on save and close actions
3520
-         *
3521
-         * @param array $query_args       The original query_args array coming into the
3522
-         *                                method.
3523
-         * @since 4.2.0
3524
-         */
3525
-        do_action(
3526
-            "AHEE__{$this->class_name}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3527
-            $query_args
3528
-        );
3529
-        // set redirect url.
3530
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3531
-        // otherwise we go with whatever is set as the _admin_base_url
3532
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3533
-        // calculate where we're going (if we have a "save and close" button pushed)
3534
-        if (
3535
-            $this->request->requestParamIsSet('save_and_close')
3536
-            && $this->request->requestParamIsSet('save_and_close_referrer')
3537
-        ) {
3538
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3539
-            $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3540
-            // regenerate query args array from referrer URL
3541
-            parse_str($parsed_url['query'], $query_args);
3542
-            // correct page and action will be in the query args now
3543
-            $redirect_url = admin_url('admin.php');
3544
-        }
3545
-        // merge any default query_args set in _default_route_query_args property
3546
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3547
-            $args_to_merge = [];
3548
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3549
-                // is there a wp_referer array in our _default_route_query_args property?
3550
-                if ($query_param === 'wp_referer') {
3551
-                    $query_value = (array) $query_value;
3552
-                    foreach ($query_value as $reference => $value) {
3553
-                        if (strpos($reference, 'nonce') !== false) {
3554
-                            continue;
3555
-                        }
3556
-                        // finally we will override any arguments in the referer with
3557
-                        // what might be set on the _default_route_query_args array.
3558
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3559
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3560
-                        } else {
3561
-                            $args_to_merge[ $reference ] = urlencode($value);
3562
-                        }
3563
-                    }
3564
-                    continue;
3565
-                }
3566
-                $args_to_merge[ $query_param ] = $query_value;
3567
-            }
3568
-            // now let's merge these arguments but override with what was specifically sent in to the
3569
-            // redirect.
3570
-            $query_args = array_merge($args_to_merge, $query_args);
3571
-        }
3572
-        $this->_process_notices($query_args);
3573
-        // generate redirect url
3574
-        // if redirecting to anything other than the main page, add a nonce
3575
-        if (isset($query_args['action'])) {
3576
-            // manually generate wp_nonce and merge that with the query vars
3577
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3578
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3579
-        }
3580
-        // we're adding some hooks and filters in here for processing any things just before redirects
3581
-        // (example: an admin page has done an insert or update and we want to run something after that).
3582
-        do_action('AHEE_redirect_' . $this->class_name . $this->_req_action, $query_args);
3583
-        $redirect_url = apply_filters(
3584
-            'FHEE_redirect_' . $this->class_name . $this->_req_action,
3585
-            EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3586
-            $query_args
3587
-        );
3588
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3589
-        if ($this->request->isAjax()) {
3590
-            $default_data                    = [
3591
-                'close'        => true,
3592
-                'redirect_url' => $redirect_url,
3593
-                'where'        => 'main',
3594
-                'what'         => 'append',
3595
-            ];
3596
-            $this->_template_args['success'] = $success;
3597
-            $this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3598
-                $default_data,
3599
-                $this->_template_args['data']
3600
-            ) : $default_data;
3601
-            $this->_return_json();
3602
-        }
3603
-        wp_safe_redirect($redirect_url);
3604
-        exit();
3605
-    }
3606
-
3607
-
3608
-    /**
3609
-     * process any notices before redirecting (or returning ajax request)
3610
-     * This method sets the $this->_template_args['notices'] attribute;
3611
-     *
3612
-     * @param array $query_args         any query args that need to be used for notice transient ('action')
3613
-     * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3614
-     *                                  page_routes haven't been defined yet.
3615
-     * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3616
-     *                                  still save a transient for the notice.
3617
-     * @return void
3618
-     * @throws EE_Error
3619
-     * @throws InvalidArgumentException
3620
-     * @throws InvalidDataTypeException
3621
-     * @throws InvalidInterfaceException
3622
-     */
3623
-    protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3624
-    {
3625
-        // first let's set individual error properties if doing_ajax and the properties aren't already set.
3626
-        if ($this->request->isAjax()) {
3627
-            $notices = EE_Error::get_notices(false);
3628
-            if (empty($this->_template_args['success'])) {
3629
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3630
-            }
3631
-            if (empty($this->_template_args['errors'])) {
3632
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3633
-            }
3634
-            if (empty($this->_template_args['attention'])) {
3635
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3636
-            }
3637
-        }
3638
-        $this->_template_args['notices'] = EE_Error::get_notices();
3639
-        // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3640
-        if (! $this->request->isAjax() || $sticky_notices) {
3641
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3642
-            $this->_add_transient(
3643
-                $route,
3644
-                $this->_template_args['notices'],
3645
-                true,
3646
-                $skip_route_verify
3647
-            );
3648
-        }
3649
-    }
3650
-
3651
-
3652
-    /**
3653
-     * get_action_link_or_button
3654
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3655
-     *
3656
-     * @param string $action        use this to indicate which action the url is generated with.
3657
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3658
-     *                              property.
3659
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3660
-     * @param string $class         Use this to give the class for the button. Defaults to 'button--primary'
3661
-     * @param string $base_url      If this is not provided
3662
-     *                              the _admin_base_url will be used as the default for the button base_url.
3663
-     *                              Otherwise this value will be used.
3664
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3665
-     * @return string
3666
-     * @throws InvalidArgumentException
3667
-     * @throws InvalidInterfaceException
3668
-     * @throws InvalidDataTypeException
3669
-     * @throws EE_Error
3670
-     */
3671
-    public function get_action_link_or_button(
3672
-        $action,
3673
-        $type = 'add',
3674
-        $extra_request = [],
3675
-        $class = 'button button--primary',
3676
-        $base_url = '',
3677
-        $exclude_nonce = false
3678
-    ) {
3679
-        // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3680
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3681
-            throw new EE_Error(
3682
-                sprintf(
3683
-                    esc_html__(
3684
-                        'There is no page route for given action for the button.  This action was given: %s',
3685
-                        'event_espresso'
3686
-                    ),
3687
-                    $action
3688
-                )
3689
-            );
3690
-        }
3691
-        if (! isset($this->_labels['buttons'][ $type ])) {
3692
-            throw new EE_Error(
3693
-                sprintf(
3694
-                    esc_html__(
3695
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3696
-                        'event_espresso'
3697
-                    ),
3698
-                    $type
3699
-                )
3700
-            );
3701
-        }
3702
-        // finally check user access for this button.
3703
-        $has_access = $this->check_user_access($action, true);
3704
-        if (! $has_access) {
3705
-            return '';
3706
-        }
3707
-        $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3708
-        $query_args = [
3709
-            'action' => $action,
3710
-        ];
3711
-        // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3712
-        if (! empty($extra_request)) {
3713
-            $query_args = array_merge($extra_request, $query_args);
3714
-        }
3715
-        $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3716
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3717
-    }
3718
-
3719
-
3720
-    /**
3721
-     * _per_page_screen_option
3722
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3723
-     *
3724
-     * @return void
3725
-     * @throws InvalidArgumentException
3726
-     * @throws InvalidInterfaceException
3727
-     * @throws InvalidDataTypeException
3728
-     */
3729
-    protected function _per_page_screen_option()
3730
-    {
3731
-        $option = 'per_page';
3732
-        $args   = [
3733
-            'label'   => apply_filters(
3734
-                'FHEE__EE_Admin_Page___per_page_screen_options___label',
3735
-                $this->_admin_page_title,
3736
-                $this
3737
-            ),
3738
-            'default' => (int) apply_filters(
3739
-                'FHEE__EE_Admin_Page___per_page_screen_options__default',
3740
-                20
3741
-            ),
3742
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3743
-        ];
3744
-        // ONLY add the screen option if the user has access to it.
3745
-        if ($this->check_user_access($this->_current_view, true)) {
3746
-            add_screen_option($option, $args);
3747
-        }
3748
-    }
3749
-
3750
-
3751
-    /**
3752
-     * set_per_page_screen_option
3753
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3754
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3755
-     * admin_menu.
3756
-     *
3757
-     * @return void
3758
-     */
3759
-    private function _set_per_page_screen_options()
3760
-    {
3761
-        if ($this->request->requestParamIsSet('wp_screen_options')) {
3762
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3763
-            if (! $user = wp_get_current_user()) {
3764
-                return;
3765
-            }
3766
-            $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3767
-            if (! $option) {
3768
-                return;
3769
-            }
3770
-            $value      = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3771
-            $map_option = $option;
3772
-            $option     = str_replace('-', '_', $option);
3773
-            switch ($map_option) {
3774
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3775
-                    $max_value = apply_filters(
3776
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3777
-                        999,
3778
-                        $this->_current_page,
3779
-                        $this->_current_view
3780
-                    );
3781
-                    if ($value < 1) {
3782
-                        return;
3783
-                    }
3784
-                    $value = min($value, $max_value);
3785
-                    break;
3786
-                default:
3787
-                    $value = apply_filters(
3788
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3789
-                        false,
3790
-                        $option,
3791
-                        $value
3792
-                    );
3793
-                    if (false === $value) {
3794
-                        return;
3795
-                    }
3796
-                    break;
3797
-            }
3798
-            update_user_meta($user->ID, $option, $value);
3799
-            wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3800
-            exit;
3801
-        }
3802
-    }
3803
-
3804
-
3805
-    /**
3806
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3807
-     *
3808
-     * @param array $data array that will be assigned to template args.
3809
-     */
3810
-    public function set_template_args($data)
3811
-    {
3812
-        $this->_template_args = array_merge($this->_template_args, (array) $data);
3813
-    }
3814
-
3815
-
3816
-    /**
3817
-     * This makes available the WP transient system for temporarily moving data between routes
3818
-     *
3819
-     * @param string $route             the route that should receive the transient
3820
-     * @param array  $data              the data that gets sent
3821
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3822
-     *                                  normal route transient.
3823
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3824
-     *                                  when we are adding a transient before page_routes have been defined.
3825
-     * @return void
3826
-     * @throws EE_Error
3827
-     */
3828
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3829
-    {
3830
-        $user_id = get_current_user_id();
3831
-        if (! $skip_route_verify) {
3832
-            $this->_verify_route($route);
3833
-        }
3834
-        // now let's set the string for what kind of transient we're setting
3835
-        $transient = $notices
3836
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3837
-            : 'rte_tx_' . $route . '_' . $user_id;
3838
-        $data      = $notices ? ['notices' => $data] : $data;
3839
-        // is there already a transient for this route?  If there is then let's ADD to that transient
3840
-        $existing = is_multisite() && is_network_admin()
3841
-            ? get_site_transient($transient)
3842
-            : get_transient($transient);
3843
-        if ($existing) {
3844
-            $data = array_merge((array) $data, (array) $existing);
3845
-        }
3846
-        if (is_multisite() && is_network_admin()) {
3847
-            set_site_transient($transient, $data, 8);
3848
-        } else {
3849
-            set_transient($transient, $data, 8);
3850
-        }
3851
-    }
3852
-
3853
-
3854
-    /**
3855
-     * this retrieves the temporary transient that has been set for moving data between routes.
3856
-     *
3857
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3858
-     * @param string $route
3859
-     * @return mixed data
3860
-     */
3861
-    protected function _get_transient($notices = false, $route = '')
3862
-    {
3863
-        $user_id   = get_current_user_id();
3864
-        $route     = ! $route ? $this->_req_action : $route;
3865
-        $transient = $notices
3866
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3867
-            : 'rte_tx_' . $route . '_' . $user_id;
3868
-        $data      = is_multisite() && is_network_admin()
3869
-            ? get_site_transient($transient)
3870
-            : get_transient($transient);
3871
-        // delete transient after retrieval (just in case it hasn't expired);
3872
-        if (is_multisite() && is_network_admin()) {
3873
-            delete_site_transient($transient);
3874
-        } else {
3875
-            delete_transient($transient);
3876
-        }
3877
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3878
-    }
3879
-
3880
-
3881
-    /**
3882
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3883
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3884
-     * default route callback on the EE_Admin page you want it run.)
3885
-     *
3886
-     * @return void
3887
-     */
3888
-    protected function _transient_garbage_collection()
3889
-    {
3890
-        global $wpdb;
3891
-        // retrieve all existing transients
3892
-        $query =
3893
-            "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3894
-        if ($results = $wpdb->get_results($query)) {
3895
-            foreach ($results as $result) {
3896
-                $transient = str_replace('_transient_', '', $result->option_name);
3897
-                get_transient($transient);
3898
-                if (is_multisite() && is_network_admin()) {
3899
-                    get_site_transient($transient);
3900
-                }
3901
-            }
3902
-        }
3903
-    }
3904
-
3905
-
3906
-    /**
3907
-     * get_view
3908
-     *
3909
-     * @return string content of _view property
3910
-     */
3911
-    public function get_view()
3912
-    {
3913
-        return $this->_view;
3914
-    }
3915
-
3916
-
3917
-    /**
3918
-     * getter for the protected $_views property
3919
-     *
3920
-     * @return array
3921
-     */
3922
-    public function get_views()
3923
-    {
3924
-        return $this->_views;
3925
-    }
3926
-
3927
-
3928
-    /**
3929
-     * get_current_page
3930
-     *
3931
-     * @return string _current_page property value
3932
-     */
3933
-    public function get_current_page()
3934
-    {
3935
-        return $this->_current_page;
3936
-    }
3937
-
3938
-
3939
-    /**
3940
-     * get_current_view
3941
-     *
3942
-     * @return string _current_view property value
3943
-     */
3944
-    public function get_current_view()
3945
-    {
3946
-        return $this->_current_view;
3947
-    }
3948
-
3949
-
3950
-    /**
3951
-     * get_current_screen
3952
-     *
3953
-     * @return object The current WP_Screen object
3954
-     */
3955
-    public function get_current_screen()
3956
-    {
3957
-        return $this->_current_screen;
3958
-    }
3959
-
3960
-
3961
-    /**
3962
-     * get_current_page_view_url
3963
-     *
3964
-     * @return string This returns the url for the current_page_view.
3965
-     */
3966
-    public function get_current_page_view_url()
3967
-    {
3968
-        return $this->_current_page_view_url;
3969
-    }
3970
-
3971
-
3972
-    /**
3973
-     * just returns the Request
3974
-     *
3975
-     * @return RequestInterface
3976
-     */
3977
-    public function get_request()
3978
-    {
3979
-        return $this->request;
3980
-    }
3981
-
3982
-
3983
-    /**
3984
-     * just returns the _req_data property
3985
-     *
3986
-     * @return array
3987
-     */
3988
-    public function get_request_data()
3989
-    {
3990
-        return $this->request->requestParams();
3991
-    }
3992
-
3993
-
3994
-    /**
3995
-     * returns the _req_data protected property
3996
-     *
3997
-     * @return string
3998
-     */
3999
-    public function get_req_action()
4000
-    {
4001
-        return $this->_req_action;
4002
-    }
4003
-
4004
-
4005
-    /**
4006
-     * @return bool  value of $_is_caf property
4007
-     */
4008
-    public function is_caf()
4009
-    {
4010
-        return $this->_is_caf;
4011
-    }
4012
-
4013
-
4014
-    /**
4015
-     * @return mixed
4016
-     */
4017
-    public function default_espresso_metaboxes()
4018
-    {
4019
-        return $this->_default_espresso_metaboxes;
4020
-    }
4021
-
4022
-
4023
-    /**
4024
-     * @return mixed
4025
-     */
4026
-    public function admin_base_url()
4027
-    {
4028
-        return $this->_admin_base_url;
4029
-    }
4030
-
4031
-
4032
-    /**
4033
-     * @return mixed
4034
-     */
4035
-    public function wp_page_slug()
4036
-    {
4037
-        return $this->_wp_page_slug;
4038
-    }
4039
-
4040
-
4041
-    /**
4042
-     * updates  espresso configuration settings
4043
-     *
4044
-     * @param string                   $tab
4045
-     * @param EE_Config_Base|EE_Config $config
4046
-     * @param string                   $file file where error occurred
4047
-     * @param string                   $func function  where error occurred
4048
-     * @param string                   $line line no where error occurred
4049
-     * @return boolean
4050
-     */
4051
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4052
-    {
4053
-        // remove any options that are NOT going to be saved with the config settings.
4054
-        if (isset($config->core->ee_ueip_optin)) {
4055
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
4056
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4057
-            update_option('ee_ueip_has_notified', true);
4058
-        }
4059
-        // and save it (note we're also doing the network save here)
4060
-        $net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
4061
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
4062
-        if ($config_saved && $net_saved) {
4063
-            EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4064
-            return true;
4065
-        }
4066
-        EE_Error::add_error(
4067
-            sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab),
4068
-            $file,
4069
-            $func,
4070
-            $line
4071
-        );
4072
-        return false;
4073
-    }
4074
-
4075
-
4076
-    /**
4077
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4078
-     *
4079
-     * @return array
4080
-     */
4081
-    public function get_yes_no_values()
4082
-    {
4083
-        return $this->_yes_no_values;
4084
-    }
4085
-
4086
-
4087
-    /**
4088
-     * @return string
4089
-     * @throws ReflectionException
4090
-     * @since 5.0.0.p
4091
-     */
4092
-    protected function _get_dir()
4093
-    {
4094
-        $reflector = new ReflectionClass($this->class_name);
4095
-        return dirname($reflector->getFileName());
4096
-    }
4097
-
4098
-
4099
-    /**
4100
-     * A helper for getting a "next link".
4101
-     *
4102
-     * @param string $url   The url to link to
4103
-     * @param string $class The class to use.
4104
-     * @return string
4105
-     */
4106
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4107
-    {
4108
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4109
-    }
4110
-
4111
-
4112
-    /**
4113
-     * A helper for getting a "previous link".
4114
-     *
4115
-     * @param string $url   The url to link to
4116
-     * @param string $class The class to use.
4117
-     * @return string
4118
-     */
4119
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4120
-    {
4121
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4122
-    }
4123
-
4124
-
4125
-
4126
-
4127
-
4128
-
4129
-
4130
-    // below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4131
-
4132
-
4133
-    /**
4134
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4135
-     * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4136
-     * _req_data array.
4137
-     *
4138
-     * @return bool success/fail
4139
-     * @throws EE_Error
4140
-     * @throws InvalidArgumentException
4141
-     * @throws ReflectionException
4142
-     * @throws InvalidDataTypeException
4143
-     * @throws InvalidInterfaceException
4144
-     */
4145
-    protected function _process_resend_registration()
4146
-    {
4147
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4148
-        do_action(
4149
-            'AHEE__EE_Admin_Page___process_resend_registration',
4150
-            $this->_template_args['success'],
4151
-            $this->request->requestParams()
4152
-        );
4153
-        return $this->_template_args['success'];
4154
-    }
4155
-
4156
-
4157
-    /**
4158
-     * This automatically processes any payment message notifications when manual payment has been applied.
4159
-     *
4160
-     * @param EE_Payment $payment
4161
-     * @return bool success/fail
4162
-     */
4163
-    protected function _process_payment_notification(EE_Payment $payment)
4164
-    {
4165
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4166
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4167
-        $this->_template_args['success'] = apply_filters(
4168
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4169
-            false,
4170
-            $payment
4171
-        );
4172
-        return $this->_template_args['success'];
4173
-    }
4174
-
4175
-
4176
-    /**
4177
-     * @param EEM_Base      $entity_model
4178
-     * @param string        $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc
4179
-     * @param string        $action         one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4180
-     * @param string        $delete_column  name of the field that denotes whether entity is trashed
4181
-     * @param callable|null $callback       called after entity is trashed, restored, or deleted
4182
-     * @return int|float
4183
-     * @throws EE_Error
4184
-     */
4185
-    protected function trashRestoreDeleteEntities(
4186
-        EEM_Base $entity_model,
4187
-        $entity_PK_name,
4188
-        $action = EE_Admin_List_Table::ACTION_DELETE,
4189
-        $delete_column = '',
4190
-        callable $callback = null
4191
-    ) {
4192
-        $entity_PK      = $entity_model->get_primary_key_field();
4193
-        $entity_PK_name = $entity_PK_name ?: $entity_PK->get_name();
4194
-        $entity_PK_type = $this->resolveEntityFieldDataType($entity_PK);
4195
-        // grab ID if deleting a single entity
4196
-        if ($this->request->requestParamIsSet($entity_PK_name)) {
4197
-            $ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type);
4198
-            return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0;
4199
-        }
4200
-        // or grab checkbox array if bulk deleting
4201
-        $checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true);
4202
-        if (empty($checkboxes)) {
4203
-            return 0;
4204
-        }
4205
-        $success = 0;
4206
-        $IDs     = array_keys($checkboxes);
4207
-        // cycle thru bulk action checkboxes
4208
-        foreach ($IDs as $ID) {
4209
-            // increment $success
4210
-            if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) {
4211
-                $success++;
4212
-            }
4213
-        }
4214
-        $count = (int) count($checkboxes);
4215
-        // if multiple entities were deleted successfully, then $deleted will be full count of deletions,
4216
-        // otherwise it will be a fraction of ( actual deletions / total entities to be deleted )
4217
-        return $success === $count ? $count : $success / $count;
4218
-    }
4219
-
4220
-
4221
-    /**
4222
-     * @param EE_Primary_Key_Field_Base $entity_PK
4223
-     * @return string
4224
-     * @throws EE_Error
4225
-     * @since   4.10.30.p
4226
-     */
4227
-    private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK)
4228
-    {
4229
-        $entity_PK_type = $entity_PK->getSchemaType();
4230
-        switch ($entity_PK_type) {
4231
-            case 'boolean':
4232
-                return 'bool';
4233
-            case 'integer':
4234
-                return 'int';
4235
-            case 'number':
4236
-                return 'float';
4237
-            case 'string':
4238
-                return 'string';
4239
-        }
4240
-        throw new RuntimeException(
4241
-            sprintf(
4242
-                esc_html__(
4243
-                    '"%1$s" is an invalid schema type for the %2$s primary key.',
4244
-                    'event_espresso'
4245
-                ),
4246
-                $entity_PK_type,
4247
-                $entity_PK->get_name()
4248
-            )
4249
-        );
4250
-    }
4251
-
4252
-
4253
-    /**
4254
-     * @param EEM_Base      $entity_model
4255
-     * @param int|string    $entity_ID
4256
-     * @param string        $action        one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4257
-     * @param string        $delete_column name of the field that denotes whether entity is trashed
4258
-     * @param callable|null $callback      called after entity is trashed, restored, or deleted
4259
-     * @return bool
4260
-     */
4261
-    protected function trashRestoreDeleteEntity(
4262
-        EEM_Base $entity_model,
4263
-        $entity_ID,
4264
-        string $action,
4265
-        string $delete_column,
4266
-        ?callable $callback = null
4267
-    ): bool {
4268
-        $entity_ID = absint($entity_ID);
4269
-        if (! $entity_ID) {
4270
-            $this->trashRestoreDeleteError($action, $entity_model);
4271
-        }
4272
-        $result = 0;
4273
-        try {
4274
-            $entity = $entity_model->get_one_by_ID($entity_ID);
4275
-            if (! $entity instanceof EE_Base_Class) {
4276
-                throw new DomainException(
4277
-                    sprintf(
4278
-                        esc_html__(
4279
-                            'Missing or invalid %1$s entity with ID of "%2$s" returned from db.',
4280
-                            'event_espresso'
4281
-                        ),
4282
-                        str_replace('EEM_', '', $entity_model->get_this_model_name()),
4283
-                        $entity_ID
4284
-                    )
4285
-                );
4286
-            }
4287
-            switch ($action) {
4288
-                case EE_Admin_List_Table::ACTION_DELETE:
4289
-                    $result = (bool) $entity->delete_permanently();
4290
-                    break;
4291
-                case EE_Admin_List_Table::ACTION_RESTORE:
4292
-                    $result = $entity->delete_or_restore(false);
4293
-                    break;
4294
-                case EE_Admin_List_Table::ACTION_TRASH:
4295
-                    $result = $entity->delete_or_restore();
4296
-                    break;
4297
-            }
4298
-        } catch (Exception $exception) {
4299
-            $this->trashRestoreDeleteError($action, $entity_model, $exception);
4300
-        }
4301
-        if (is_callable($callback)) {
4302
-            call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]);
4303
-        }
4304
-        return $result;
4305
-    }
4306
-
4307
-
4308
-    /**
4309
-     * @param EEM_Base $entity_model
4310
-     * @param string   $delete_column
4311
-     * @since 4.10.30.p
4312
-     */
4313
-    private function validateDeleteColumn(EEM_Base $entity_model, $delete_column)
4314
-    {
4315
-        if (empty($delete_column)) {
4316
-            throw new DomainException(
4317
-                sprintf(
4318
-                    esc_html__(
4319
-                        'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.',
4320
-                        'event_espresso'
4321
-                    ),
4322
-                    $entity_model->get_this_model_name()
4323
-                )
4324
-            );
4325
-        }
4326
-        if (! $entity_model->has_field($delete_column)) {
4327
-            throw new DomainException(
4328
-                sprintf(
4329
-                    esc_html__(
4330
-                        'The %1$s field does not exist on the %2$s model.',
4331
-                        'event_espresso'
4332
-                    ),
4333
-                    $delete_column,
4334
-                    $entity_model->get_this_model_name()
4335
-                )
4336
-            );
4337
-        }
4338
-    }
4339
-
4340
-
4341
-    /**
4342
-     * @param EEM_Base       $entity_model
4343
-     * @param Exception|null $exception
4344
-     * @param string         $action
4345
-     * @since 4.10.30.p
4346
-     */
4347
-    private function trashRestoreDeleteError($action, EEM_Base $entity_model, Exception $exception = null)
4348
-    {
4349
-        if ($exception instanceof Exception) {
4350
-            throw new RuntimeException(
4351
-                sprintf(
4352
-                    esc_html__(
4353
-                        'Could not %1$s the %2$s because the following error occurred: %3$s',
4354
-                        'event_espresso'
4355
-                    ),
4356
-                    $action,
4357
-                    $entity_model->get_this_model_name(),
4358
-                    $exception->getMessage()
4359
-                )
4360
-            );
4361
-        }
4362
-        throw new RuntimeException(
4363
-            sprintf(
4364
-                esc_html__(
4365
-                    'Could not %1$s the %2$s because an invalid ID was received.',
4366
-                    'event_espresso'
4367
-                ),
4368
-                $action,
4369
-                $entity_model->get_this_model_name()
4370
-            )
4371
-        );
4372
-    }
3389
+		// add nonce
3390
+		$nonce                                             =
3391
+			wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3392
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3393
+		// add REQUIRED form action
3394
+		$hidden_fields = [
3395
+			'action' => ['type' => 'hidden', 'value' => $route],
3396
+		];
3397
+		// merge arrays
3398
+		$hidden_fields = is_array($additional_hidden_fields)
3399
+			? array_merge($hidden_fields, $additional_hidden_fields)
3400
+			: $hidden_fields;
3401
+		// generate form fields
3402
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3403
+		// add fields to form
3404
+		foreach ((array) $form_fields as $form_field) {
3405
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3406
+		}
3407
+		// close form
3408
+		$this->_template_args['after_admin_page_content'] = '</form>';
3409
+	}
3410
+
3411
+
3412
+	/**
3413
+	 * Public Wrapper for _redirect_after_action() method since its
3414
+	 * discovered it would be useful for external code to have access.
3415
+	 *
3416
+	 * @param bool   $success
3417
+	 * @param string $what
3418
+	 * @param string $action_desc
3419
+	 * @param array  $query_args
3420
+	 * @param bool   $override_overwrite
3421
+	 * @throws EE_Error
3422
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3423
+	 * @since 4.5.0
3424
+	 */
3425
+	public function redirect_after_action(
3426
+		$success = false,
3427
+		$what = 'item',
3428
+		$action_desc = 'processed',
3429
+		$query_args = [],
3430
+		$override_overwrite = false
3431
+	) {
3432
+		$this->_redirect_after_action(
3433
+			$success,
3434
+			$what,
3435
+			$action_desc,
3436
+			$query_args,
3437
+			$override_overwrite
3438
+		);
3439
+	}
3440
+
3441
+
3442
+	/**
3443
+	 * Helper method for merging existing request data with the returned redirect url.
3444
+	 *
3445
+	 * This is typically used for redirects after an action so that if the original view was a filtered view those
3446
+	 * filters are still applied.
3447
+	 *
3448
+	 * @param array $new_route_data
3449
+	 * @return array
3450
+	 */
3451
+	protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3452
+	{
3453
+		foreach ($this->request->requestParams() as $ref => $value) {
3454
+			// unset nonces
3455
+			if (strpos($ref, 'nonce') !== false) {
3456
+				$this->request->unSetRequestParam($ref);
3457
+				continue;
3458
+			}
3459
+			// urlencode values.
3460
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3461
+			$this->request->setRequestParam($ref, $value);
3462
+		}
3463
+		return array_merge($this->request->requestParams(), $new_route_data);
3464
+	}
3465
+
3466
+
3467
+	/**
3468
+	 * @param int|float|string $success            - whether success was for two or more records, or just one, or none
3469
+	 * @param string           $what               - what the action was performed on
3470
+	 * @param string           $action_desc        - what was done ie: updated, deleted, etc
3471
+	 * @param array            $query_args         - an array of query_args to be added to the URL to redirect to
3472
+	 * @param BOOL             $override_overwrite - by default all EE_Error::success messages are overwritten,
3473
+	 *                                             this allows you to override this so that they show.
3474
+	 * @return void
3475
+	 * @throws EE_Error
3476
+	 * @throws InvalidArgumentException
3477
+	 * @throws InvalidDataTypeException
3478
+	 * @throws InvalidInterfaceException
3479
+	 */
3480
+	protected function _redirect_after_action(
3481
+		$success = 0,
3482
+		string $what = 'item',
3483
+		string $action_desc = 'processed',
3484
+		array $query_args = [],
3485
+		bool $override_overwrite = false
3486
+	) {
3487
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3488
+		$notices = EE_Error::get_notices(false);
3489
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3490
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3491
+			EE_Error::overwrite_success();
3492
+		}
3493
+		if (! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3494
+			// how many records affected ? more than one record ? or just one ?
3495
+			EE_Error::add_success(
3496
+				sprintf(
3497
+					esc_html(
3498
+						_n(
3499
+							'The "%1$s" has been successfully %2$s.',
3500
+							'The "%1$s" have been successfully %2$s.',
3501
+							$success,
3502
+							'event_espresso'
3503
+						)
3504
+					),
3505
+					$what,
3506
+					$action_desc
3507
+				),
3508
+				__FILE__,
3509
+				__FUNCTION__,
3510
+				__LINE__
3511
+			);
3512
+		}
3513
+		// check that $query_args isn't something crazy
3514
+		if (! is_array($query_args)) {
3515
+			$query_args = [];
3516
+		}
3517
+		/**
3518
+		 * Allow injecting actions before the query_args are modified for possible different
3519
+		 * redirections on save and close actions
3520
+		 *
3521
+		 * @param array $query_args       The original query_args array coming into the
3522
+		 *                                method.
3523
+		 * @since 4.2.0
3524
+		 */
3525
+		do_action(
3526
+			"AHEE__{$this->class_name}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3527
+			$query_args
3528
+		);
3529
+		// set redirect url.
3530
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3531
+		// otherwise we go with whatever is set as the _admin_base_url
3532
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3533
+		// calculate where we're going (if we have a "save and close" button pushed)
3534
+		if (
3535
+			$this->request->requestParamIsSet('save_and_close')
3536
+			&& $this->request->requestParamIsSet('save_and_close_referrer')
3537
+		) {
3538
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3539
+			$parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3540
+			// regenerate query args array from referrer URL
3541
+			parse_str($parsed_url['query'], $query_args);
3542
+			// correct page and action will be in the query args now
3543
+			$redirect_url = admin_url('admin.php');
3544
+		}
3545
+		// merge any default query_args set in _default_route_query_args property
3546
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3547
+			$args_to_merge = [];
3548
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3549
+				// is there a wp_referer array in our _default_route_query_args property?
3550
+				if ($query_param === 'wp_referer') {
3551
+					$query_value = (array) $query_value;
3552
+					foreach ($query_value as $reference => $value) {
3553
+						if (strpos($reference, 'nonce') !== false) {
3554
+							continue;
3555
+						}
3556
+						// finally we will override any arguments in the referer with
3557
+						// what might be set on the _default_route_query_args array.
3558
+						if (isset($this->_default_route_query_args[ $reference ])) {
3559
+							$args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3560
+						} else {
3561
+							$args_to_merge[ $reference ] = urlencode($value);
3562
+						}
3563
+					}
3564
+					continue;
3565
+				}
3566
+				$args_to_merge[ $query_param ] = $query_value;
3567
+			}
3568
+			// now let's merge these arguments but override with what was specifically sent in to the
3569
+			// redirect.
3570
+			$query_args = array_merge($args_to_merge, $query_args);
3571
+		}
3572
+		$this->_process_notices($query_args);
3573
+		// generate redirect url
3574
+		// if redirecting to anything other than the main page, add a nonce
3575
+		if (isset($query_args['action'])) {
3576
+			// manually generate wp_nonce and merge that with the query vars
3577
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3578
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3579
+		}
3580
+		// we're adding some hooks and filters in here for processing any things just before redirects
3581
+		// (example: an admin page has done an insert or update and we want to run something after that).
3582
+		do_action('AHEE_redirect_' . $this->class_name . $this->_req_action, $query_args);
3583
+		$redirect_url = apply_filters(
3584
+			'FHEE_redirect_' . $this->class_name . $this->_req_action,
3585
+			EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3586
+			$query_args
3587
+		);
3588
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3589
+		if ($this->request->isAjax()) {
3590
+			$default_data                    = [
3591
+				'close'        => true,
3592
+				'redirect_url' => $redirect_url,
3593
+				'where'        => 'main',
3594
+				'what'         => 'append',
3595
+			];
3596
+			$this->_template_args['success'] = $success;
3597
+			$this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3598
+				$default_data,
3599
+				$this->_template_args['data']
3600
+			) : $default_data;
3601
+			$this->_return_json();
3602
+		}
3603
+		wp_safe_redirect($redirect_url);
3604
+		exit();
3605
+	}
3606
+
3607
+
3608
+	/**
3609
+	 * process any notices before redirecting (or returning ajax request)
3610
+	 * This method sets the $this->_template_args['notices'] attribute;
3611
+	 *
3612
+	 * @param array $query_args         any query args that need to be used for notice transient ('action')
3613
+	 * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3614
+	 *                                  page_routes haven't been defined yet.
3615
+	 * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3616
+	 *                                  still save a transient for the notice.
3617
+	 * @return void
3618
+	 * @throws EE_Error
3619
+	 * @throws InvalidArgumentException
3620
+	 * @throws InvalidDataTypeException
3621
+	 * @throws InvalidInterfaceException
3622
+	 */
3623
+	protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3624
+	{
3625
+		// first let's set individual error properties if doing_ajax and the properties aren't already set.
3626
+		if ($this->request->isAjax()) {
3627
+			$notices = EE_Error::get_notices(false);
3628
+			if (empty($this->_template_args['success'])) {
3629
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3630
+			}
3631
+			if (empty($this->_template_args['errors'])) {
3632
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3633
+			}
3634
+			if (empty($this->_template_args['attention'])) {
3635
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3636
+			}
3637
+		}
3638
+		$this->_template_args['notices'] = EE_Error::get_notices();
3639
+		// IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3640
+		if (! $this->request->isAjax() || $sticky_notices) {
3641
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3642
+			$this->_add_transient(
3643
+				$route,
3644
+				$this->_template_args['notices'],
3645
+				true,
3646
+				$skip_route_verify
3647
+			);
3648
+		}
3649
+	}
3650
+
3651
+
3652
+	/**
3653
+	 * get_action_link_or_button
3654
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3655
+	 *
3656
+	 * @param string $action        use this to indicate which action the url is generated with.
3657
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3658
+	 *                              property.
3659
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3660
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button--primary'
3661
+	 * @param string $base_url      If this is not provided
3662
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3663
+	 *                              Otherwise this value will be used.
3664
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3665
+	 * @return string
3666
+	 * @throws InvalidArgumentException
3667
+	 * @throws InvalidInterfaceException
3668
+	 * @throws InvalidDataTypeException
3669
+	 * @throws EE_Error
3670
+	 */
3671
+	public function get_action_link_or_button(
3672
+		$action,
3673
+		$type = 'add',
3674
+		$extra_request = [],
3675
+		$class = 'button button--primary',
3676
+		$base_url = '',
3677
+		$exclude_nonce = false
3678
+	) {
3679
+		// first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3680
+		if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3681
+			throw new EE_Error(
3682
+				sprintf(
3683
+					esc_html__(
3684
+						'There is no page route for given action for the button.  This action was given: %s',
3685
+						'event_espresso'
3686
+					),
3687
+					$action
3688
+				)
3689
+			);
3690
+		}
3691
+		if (! isset($this->_labels['buttons'][ $type ])) {
3692
+			throw new EE_Error(
3693
+				sprintf(
3694
+					esc_html__(
3695
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3696
+						'event_espresso'
3697
+					),
3698
+					$type
3699
+				)
3700
+			);
3701
+		}
3702
+		// finally check user access for this button.
3703
+		$has_access = $this->check_user_access($action, true);
3704
+		if (! $has_access) {
3705
+			return '';
3706
+		}
3707
+		$_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3708
+		$query_args = [
3709
+			'action' => $action,
3710
+		];
3711
+		// merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3712
+		if (! empty($extra_request)) {
3713
+			$query_args = array_merge($extra_request, $query_args);
3714
+		}
3715
+		$url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3716
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3717
+	}
3718
+
3719
+
3720
+	/**
3721
+	 * _per_page_screen_option
3722
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3723
+	 *
3724
+	 * @return void
3725
+	 * @throws InvalidArgumentException
3726
+	 * @throws InvalidInterfaceException
3727
+	 * @throws InvalidDataTypeException
3728
+	 */
3729
+	protected function _per_page_screen_option()
3730
+	{
3731
+		$option = 'per_page';
3732
+		$args   = [
3733
+			'label'   => apply_filters(
3734
+				'FHEE__EE_Admin_Page___per_page_screen_options___label',
3735
+				$this->_admin_page_title,
3736
+				$this
3737
+			),
3738
+			'default' => (int) apply_filters(
3739
+				'FHEE__EE_Admin_Page___per_page_screen_options__default',
3740
+				20
3741
+			),
3742
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3743
+		];
3744
+		// ONLY add the screen option if the user has access to it.
3745
+		if ($this->check_user_access($this->_current_view, true)) {
3746
+			add_screen_option($option, $args);
3747
+		}
3748
+	}
3749
+
3750
+
3751
+	/**
3752
+	 * set_per_page_screen_option
3753
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3754
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3755
+	 * admin_menu.
3756
+	 *
3757
+	 * @return void
3758
+	 */
3759
+	private function _set_per_page_screen_options()
3760
+	{
3761
+		if ($this->request->requestParamIsSet('wp_screen_options')) {
3762
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3763
+			if (! $user = wp_get_current_user()) {
3764
+				return;
3765
+			}
3766
+			$option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3767
+			if (! $option) {
3768
+				return;
3769
+			}
3770
+			$value      = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3771
+			$map_option = $option;
3772
+			$option     = str_replace('-', '_', $option);
3773
+			switch ($map_option) {
3774
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3775
+					$max_value = apply_filters(
3776
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3777
+						999,
3778
+						$this->_current_page,
3779
+						$this->_current_view
3780
+					);
3781
+					if ($value < 1) {
3782
+						return;
3783
+					}
3784
+					$value = min($value, $max_value);
3785
+					break;
3786
+				default:
3787
+					$value = apply_filters(
3788
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3789
+						false,
3790
+						$option,
3791
+						$value
3792
+					);
3793
+					if (false === $value) {
3794
+						return;
3795
+					}
3796
+					break;
3797
+			}
3798
+			update_user_meta($user->ID, $option, $value);
3799
+			wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3800
+			exit;
3801
+		}
3802
+	}
3803
+
3804
+
3805
+	/**
3806
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3807
+	 *
3808
+	 * @param array $data array that will be assigned to template args.
3809
+	 */
3810
+	public function set_template_args($data)
3811
+	{
3812
+		$this->_template_args = array_merge($this->_template_args, (array) $data);
3813
+	}
3814
+
3815
+
3816
+	/**
3817
+	 * This makes available the WP transient system for temporarily moving data between routes
3818
+	 *
3819
+	 * @param string $route             the route that should receive the transient
3820
+	 * @param array  $data              the data that gets sent
3821
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3822
+	 *                                  normal route transient.
3823
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3824
+	 *                                  when we are adding a transient before page_routes have been defined.
3825
+	 * @return void
3826
+	 * @throws EE_Error
3827
+	 */
3828
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3829
+	{
3830
+		$user_id = get_current_user_id();
3831
+		if (! $skip_route_verify) {
3832
+			$this->_verify_route($route);
3833
+		}
3834
+		// now let's set the string for what kind of transient we're setting
3835
+		$transient = $notices
3836
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3837
+			: 'rte_tx_' . $route . '_' . $user_id;
3838
+		$data      = $notices ? ['notices' => $data] : $data;
3839
+		// is there already a transient for this route?  If there is then let's ADD to that transient
3840
+		$existing = is_multisite() && is_network_admin()
3841
+			? get_site_transient($transient)
3842
+			: get_transient($transient);
3843
+		if ($existing) {
3844
+			$data = array_merge((array) $data, (array) $existing);
3845
+		}
3846
+		if (is_multisite() && is_network_admin()) {
3847
+			set_site_transient($transient, $data, 8);
3848
+		} else {
3849
+			set_transient($transient, $data, 8);
3850
+		}
3851
+	}
3852
+
3853
+
3854
+	/**
3855
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3856
+	 *
3857
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3858
+	 * @param string $route
3859
+	 * @return mixed data
3860
+	 */
3861
+	protected function _get_transient($notices = false, $route = '')
3862
+	{
3863
+		$user_id   = get_current_user_id();
3864
+		$route     = ! $route ? $this->_req_action : $route;
3865
+		$transient = $notices
3866
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3867
+			: 'rte_tx_' . $route . '_' . $user_id;
3868
+		$data      = is_multisite() && is_network_admin()
3869
+			? get_site_transient($transient)
3870
+			: get_transient($transient);
3871
+		// delete transient after retrieval (just in case it hasn't expired);
3872
+		if (is_multisite() && is_network_admin()) {
3873
+			delete_site_transient($transient);
3874
+		} else {
3875
+			delete_transient($transient);
3876
+		}
3877
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3878
+	}
3879
+
3880
+
3881
+	/**
3882
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3883
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3884
+	 * default route callback on the EE_Admin page you want it run.)
3885
+	 *
3886
+	 * @return void
3887
+	 */
3888
+	protected function _transient_garbage_collection()
3889
+	{
3890
+		global $wpdb;
3891
+		// retrieve all existing transients
3892
+		$query =
3893
+			"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3894
+		if ($results = $wpdb->get_results($query)) {
3895
+			foreach ($results as $result) {
3896
+				$transient = str_replace('_transient_', '', $result->option_name);
3897
+				get_transient($transient);
3898
+				if (is_multisite() && is_network_admin()) {
3899
+					get_site_transient($transient);
3900
+				}
3901
+			}
3902
+		}
3903
+	}
3904
+
3905
+
3906
+	/**
3907
+	 * get_view
3908
+	 *
3909
+	 * @return string content of _view property
3910
+	 */
3911
+	public function get_view()
3912
+	{
3913
+		return $this->_view;
3914
+	}
3915
+
3916
+
3917
+	/**
3918
+	 * getter for the protected $_views property
3919
+	 *
3920
+	 * @return array
3921
+	 */
3922
+	public function get_views()
3923
+	{
3924
+		return $this->_views;
3925
+	}
3926
+
3927
+
3928
+	/**
3929
+	 * get_current_page
3930
+	 *
3931
+	 * @return string _current_page property value
3932
+	 */
3933
+	public function get_current_page()
3934
+	{
3935
+		return $this->_current_page;
3936
+	}
3937
+
3938
+
3939
+	/**
3940
+	 * get_current_view
3941
+	 *
3942
+	 * @return string _current_view property value
3943
+	 */
3944
+	public function get_current_view()
3945
+	{
3946
+		return $this->_current_view;
3947
+	}
3948
+
3949
+
3950
+	/**
3951
+	 * get_current_screen
3952
+	 *
3953
+	 * @return object The current WP_Screen object
3954
+	 */
3955
+	public function get_current_screen()
3956
+	{
3957
+		return $this->_current_screen;
3958
+	}
3959
+
3960
+
3961
+	/**
3962
+	 * get_current_page_view_url
3963
+	 *
3964
+	 * @return string This returns the url for the current_page_view.
3965
+	 */
3966
+	public function get_current_page_view_url()
3967
+	{
3968
+		return $this->_current_page_view_url;
3969
+	}
3970
+
3971
+
3972
+	/**
3973
+	 * just returns the Request
3974
+	 *
3975
+	 * @return RequestInterface
3976
+	 */
3977
+	public function get_request()
3978
+	{
3979
+		return $this->request;
3980
+	}
3981
+
3982
+
3983
+	/**
3984
+	 * just returns the _req_data property
3985
+	 *
3986
+	 * @return array
3987
+	 */
3988
+	public function get_request_data()
3989
+	{
3990
+		return $this->request->requestParams();
3991
+	}
3992
+
3993
+
3994
+	/**
3995
+	 * returns the _req_data protected property
3996
+	 *
3997
+	 * @return string
3998
+	 */
3999
+	public function get_req_action()
4000
+	{
4001
+		return $this->_req_action;
4002
+	}
4003
+
4004
+
4005
+	/**
4006
+	 * @return bool  value of $_is_caf property
4007
+	 */
4008
+	public function is_caf()
4009
+	{
4010
+		return $this->_is_caf;
4011
+	}
4012
+
4013
+
4014
+	/**
4015
+	 * @return mixed
4016
+	 */
4017
+	public function default_espresso_metaboxes()
4018
+	{
4019
+		return $this->_default_espresso_metaboxes;
4020
+	}
4021
+
4022
+
4023
+	/**
4024
+	 * @return mixed
4025
+	 */
4026
+	public function admin_base_url()
4027
+	{
4028
+		return $this->_admin_base_url;
4029
+	}
4030
+
4031
+
4032
+	/**
4033
+	 * @return mixed
4034
+	 */
4035
+	public function wp_page_slug()
4036
+	{
4037
+		return $this->_wp_page_slug;
4038
+	}
4039
+
4040
+
4041
+	/**
4042
+	 * updates  espresso configuration settings
4043
+	 *
4044
+	 * @param string                   $tab
4045
+	 * @param EE_Config_Base|EE_Config $config
4046
+	 * @param string                   $file file where error occurred
4047
+	 * @param string                   $func function  where error occurred
4048
+	 * @param string                   $line line no where error occurred
4049
+	 * @return boolean
4050
+	 */
4051
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4052
+	{
4053
+		// remove any options that are NOT going to be saved with the config settings.
4054
+		if (isset($config->core->ee_ueip_optin)) {
4055
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
4056
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4057
+			update_option('ee_ueip_has_notified', true);
4058
+		}
4059
+		// and save it (note we're also doing the network save here)
4060
+		$net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
4061
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
4062
+		if ($config_saved && $net_saved) {
4063
+			EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4064
+			return true;
4065
+		}
4066
+		EE_Error::add_error(
4067
+			sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab),
4068
+			$file,
4069
+			$func,
4070
+			$line
4071
+		);
4072
+		return false;
4073
+	}
4074
+
4075
+
4076
+	/**
4077
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4078
+	 *
4079
+	 * @return array
4080
+	 */
4081
+	public function get_yes_no_values()
4082
+	{
4083
+		return $this->_yes_no_values;
4084
+	}
4085
+
4086
+
4087
+	/**
4088
+	 * @return string
4089
+	 * @throws ReflectionException
4090
+	 * @since 5.0.0.p
4091
+	 */
4092
+	protected function _get_dir()
4093
+	{
4094
+		$reflector = new ReflectionClass($this->class_name);
4095
+		return dirname($reflector->getFileName());
4096
+	}
4097
+
4098
+
4099
+	/**
4100
+	 * A helper for getting a "next link".
4101
+	 *
4102
+	 * @param string $url   The url to link to
4103
+	 * @param string $class The class to use.
4104
+	 * @return string
4105
+	 */
4106
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4107
+	{
4108
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4109
+	}
4110
+
4111
+
4112
+	/**
4113
+	 * A helper for getting a "previous link".
4114
+	 *
4115
+	 * @param string $url   The url to link to
4116
+	 * @param string $class The class to use.
4117
+	 * @return string
4118
+	 */
4119
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4120
+	{
4121
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4122
+	}
4123
+
4124
+
4125
+
4126
+
4127
+
4128
+
4129
+
4130
+	// below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4131
+
4132
+
4133
+	/**
4134
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4135
+	 * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4136
+	 * _req_data array.
4137
+	 *
4138
+	 * @return bool success/fail
4139
+	 * @throws EE_Error
4140
+	 * @throws InvalidArgumentException
4141
+	 * @throws ReflectionException
4142
+	 * @throws InvalidDataTypeException
4143
+	 * @throws InvalidInterfaceException
4144
+	 */
4145
+	protected function _process_resend_registration()
4146
+	{
4147
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4148
+		do_action(
4149
+			'AHEE__EE_Admin_Page___process_resend_registration',
4150
+			$this->_template_args['success'],
4151
+			$this->request->requestParams()
4152
+		);
4153
+		return $this->_template_args['success'];
4154
+	}
4155
+
4156
+
4157
+	/**
4158
+	 * This automatically processes any payment message notifications when manual payment has been applied.
4159
+	 *
4160
+	 * @param EE_Payment $payment
4161
+	 * @return bool success/fail
4162
+	 */
4163
+	protected function _process_payment_notification(EE_Payment $payment)
4164
+	{
4165
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4166
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4167
+		$this->_template_args['success'] = apply_filters(
4168
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4169
+			false,
4170
+			$payment
4171
+		);
4172
+		return $this->_template_args['success'];
4173
+	}
4174
+
4175
+
4176
+	/**
4177
+	 * @param EEM_Base      $entity_model
4178
+	 * @param string        $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc
4179
+	 * @param string        $action         one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4180
+	 * @param string        $delete_column  name of the field that denotes whether entity is trashed
4181
+	 * @param callable|null $callback       called after entity is trashed, restored, or deleted
4182
+	 * @return int|float
4183
+	 * @throws EE_Error
4184
+	 */
4185
+	protected function trashRestoreDeleteEntities(
4186
+		EEM_Base $entity_model,
4187
+		$entity_PK_name,
4188
+		$action = EE_Admin_List_Table::ACTION_DELETE,
4189
+		$delete_column = '',
4190
+		callable $callback = null
4191
+	) {
4192
+		$entity_PK      = $entity_model->get_primary_key_field();
4193
+		$entity_PK_name = $entity_PK_name ?: $entity_PK->get_name();
4194
+		$entity_PK_type = $this->resolveEntityFieldDataType($entity_PK);
4195
+		// grab ID if deleting a single entity
4196
+		if ($this->request->requestParamIsSet($entity_PK_name)) {
4197
+			$ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type);
4198
+			return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0;
4199
+		}
4200
+		// or grab checkbox array if bulk deleting
4201
+		$checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true);
4202
+		if (empty($checkboxes)) {
4203
+			return 0;
4204
+		}
4205
+		$success = 0;
4206
+		$IDs     = array_keys($checkboxes);
4207
+		// cycle thru bulk action checkboxes
4208
+		foreach ($IDs as $ID) {
4209
+			// increment $success
4210
+			if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) {
4211
+				$success++;
4212
+			}
4213
+		}
4214
+		$count = (int) count($checkboxes);
4215
+		// if multiple entities were deleted successfully, then $deleted will be full count of deletions,
4216
+		// otherwise it will be a fraction of ( actual deletions / total entities to be deleted )
4217
+		return $success === $count ? $count : $success / $count;
4218
+	}
4219
+
4220
+
4221
+	/**
4222
+	 * @param EE_Primary_Key_Field_Base $entity_PK
4223
+	 * @return string
4224
+	 * @throws EE_Error
4225
+	 * @since   4.10.30.p
4226
+	 */
4227
+	private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK)
4228
+	{
4229
+		$entity_PK_type = $entity_PK->getSchemaType();
4230
+		switch ($entity_PK_type) {
4231
+			case 'boolean':
4232
+				return 'bool';
4233
+			case 'integer':
4234
+				return 'int';
4235
+			case 'number':
4236
+				return 'float';
4237
+			case 'string':
4238
+				return 'string';
4239
+		}
4240
+		throw new RuntimeException(
4241
+			sprintf(
4242
+				esc_html__(
4243
+					'"%1$s" is an invalid schema type for the %2$s primary key.',
4244
+					'event_espresso'
4245
+				),
4246
+				$entity_PK_type,
4247
+				$entity_PK->get_name()
4248
+			)
4249
+		);
4250
+	}
4251
+
4252
+
4253
+	/**
4254
+	 * @param EEM_Base      $entity_model
4255
+	 * @param int|string    $entity_ID
4256
+	 * @param string        $action        one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4257
+	 * @param string        $delete_column name of the field that denotes whether entity is trashed
4258
+	 * @param callable|null $callback      called after entity is trashed, restored, or deleted
4259
+	 * @return bool
4260
+	 */
4261
+	protected function trashRestoreDeleteEntity(
4262
+		EEM_Base $entity_model,
4263
+		$entity_ID,
4264
+		string $action,
4265
+		string $delete_column,
4266
+		?callable $callback = null
4267
+	): bool {
4268
+		$entity_ID = absint($entity_ID);
4269
+		if (! $entity_ID) {
4270
+			$this->trashRestoreDeleteError($action, $entity_model);
4271
+		}
4272
+		$result = 0;
4273
+		try {
4274
+			$entity = $entity_model->get_one_by_ID($entity_ID);
4275
+			if (! $entity instanceof EE_Base_Class) {
4276
+				throw new DomainException(
4277
+					sprintf(
4278
+						esc_html__(
4279
+							'Missing or invalid %1$s entity with ID of "%2$s" returned from db.',
4280
+							'event_espresso'
4281
+						),
4282
+						str_replace('EEM_', '', $entity_model->get_this_model_name()),
4283
+						$entity_ID
4284
+					)
4285
+				);
4286
+			}
4287
+			switch ($action) {
4288
+				case EE_Admin_List_Table::ACTION_DELETE:
4289
+					$result = (bool) $entity->delete_permanently();
4290
+					break;
4291
+				case EE_Admin_List_Table::ACTION_RESTORE:
4292
+					$result = $entity->delete_or_restore(false);
4293
+					break;
4294
+				case EE_Admin_List_Table::ACTION_TRASH:
4295
+					$result = $entity->delete_or_restore();
4296
+					break;
4297
+			}
4298
+		} catch (Exception $exception) {
4299
+			$this->trashRestoreDeleteError($action, $entity_model, $exception);
4300
+		}
4301
+		if (is_callable($callback)) {
4302
+			call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]);
4303
+		}
4304
+		return $result;
4305
+	}
4306
+
4307
+
4308
+	/**
4309
+	 * @param EEM_Base $entity_model
4310
+	 * @param string   $delete_column
4311
+	 * @since 4.10.30.p
4312
+	 */
4313
+	private function validateDeleteColumn(EEM_Base $entity_model, $delete_column)
4314
+	{
4315
+		if (empty($delete_column)) {
4316
+			throw new DomainException(
4317
+				sprintf(
4318
+					esc_html__(
4319
+						'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.',
4320
+						'event_espresso'
4321
+					),
4322
+					$entity_model->get_this_model_name()
4323
+				)
4324
+			);
4325
+		}
4326
+		if (! $entity_model->has_field($delete_column)) {
4327
+			throw new DomainException(
4328
+				sprintf(
4329
+					esc_html__(
4330
+						'The %1$s field does not exist on the %2$s model.',
4331
+						'event_espresso'
4332
+					),
4333
+					$delete_column,
4334
+					$entity_model->get_this_model_name()
4335
+				)
4336
+			);
4337
+		}
4338
+	}
4339
+
4340
+
4341
+	/**
4342
+	 * @param EEM_Base       $entity_model
4343
+	 * @param Exception|null $exception
4344
+	 * @param string         $action
4345
+	 * @since 4.10.30.p
4346
+	 */
4347
+	private function trashRestoreDeleteError($action, EEM_Base $entity_model, Exception $exception = null)
4348
+	{
4349
+		if ($exception instanceof Exception) {
4350
+			throw new RuntimeException(
4351
+				sprintf(
4352
+					esc_html__(
4353
+						'Could not %1$s the %2$s because the following error occurred: %3$s',
4354
+						'event_espresso'
4355
+					),
4356
+					$action,
4357
+					$entity_model->get_this_model_name(),
4358
+					$exception->getMessage()
4359
+				)
4360
+			);
4361
+		}
4362
+		throw new RuntimeException(
4363
+			sprintf(
4364
+				esc_html__(
4365
+					'Could not %1$s the %2$s because an invalid ID was received.',
4366
+					'event_espresso'
4367
+				),
4368
+				$action,
4369
+				$entity_model->get_this_model_name()
4370
+			)
4371
+		);
4372
+	}
4373 4373
 }
Please login to merge, or discard this patch.
core/libraries/batch/BatchRequestProcessor.php 1 patch
Indentation   +303 added lines, -303 removed lines patch added patch discarded remove patch
@@ -31,307 +31,307 @@
 block discarded – undo
31 31
  */
32 32
 class BatchRequestProcessor
33 33
 {
34
-    /**
35
-     * Current job's ID (if assigned)
36
-     *
37
-     * @var string|null
38
-     */
39
-    protected $_job_id = '';
40
-
41
-    /**
42
-     * Current job's parameters
43
-     *
44
-     * @var JobParameters|null
45
-     */
46
-    protected $_job_parameters = null;
47
-
48
-    /**
49
-     * @var LoaderInterface|null
50
-     */
51
-    private $loader;
52
-
53
-
54
-    /**
55
-     * @var RequestInterface|null
56
-     */
57
-    private $request;
58
-
59
-
60
-    /**
61
-     * BatchRequestProcessor constructor.
62
-     *
63
-     * @param LoaderInterface  $loader
64
-     * @param RequestInterface $request
65
-     */
66
-    public function __construct(LoaderInterface $loader, RequestInterface $request)
67
-    {
68
-        $this->loader  = $loader;
69
-        $this->request = $request;
70
-    }
71
-
72
-
73
-    /**
74
-     * @param string $job_id
75
-     * @param string $job_handler_class
76
-     * @param array  $request_data
77
-     * @return JobHandlerInterface
78
-     * @throws BatchRequestException
79
-     * @since   5.0.0.p
80
-     */
81
-    private function initializeJobHandler(
82
-        string $job_id,
83
-        string $job_handler_class = '',
84
-        array $request_data = []
85
-    ): JobHandlerInterface {
86
-        $this->_job_id         = $job_id;
87
-        $this->_job_parameters = ! empty($job_handler_class)
88
-            ? new JobParameters($this->_job_id, $job_handler_class, $request_data)
89
-            : JobParameters::load($this->_job_id);
90
-        $this->_job_parameters->save();
91
-        return $this->instantiateBatchJobHandlerFromJobParameters($this->_job_parameters);
92
-    }
93
-
94
-
95
-    /**
96
-     * Creates a job for the specified batch handler class (which should be autoloaded)
97
-     * and the specified request data
98
-     *
99
-     * @return JobStepResponse
100
-     */
101
-    public function createJob(): JobStepResponse
102
-    {
103
-        try {
104
-            $request_data = $this->request->requestParams();
105
-            $job_id       = $this->request->getRequestParam(
106
-                'job_code',
107
-                wp_generate_password(15, false)
108
-            );
109
-            $service      = $this->request->getRequestParam('job_handler', '', 'fqcn');
110
-            $assessment   = $this->request->getRequestParam('job_assessment', '', 'fqcn');
111
-            $job_class    = $assessment !== '' ? $assessment : $service;
112
-            // replace escaped escaped backslashes with escaped unescaped backslashes :lol:
113
-            $job_class    = str_replace('\\\\', '\\', urldecode($job_class));
114
-            $job_handler  = $this->initializeJobHandler($job_id, $job_class, $request_data);
115
-            $job_response = $job_handler->createJob($this->_job_parameters);
116
-            $this->validateResponse('createJob', $this->_job_id, $job_response);
117
-            $success = $this->_job_parameters->save();
118
-            if (! $success) {
119
-                throw new BatchRequestException(
120
-                    sprintf(
121
-                        esc_html__(
122
-                            'Could not save job %1$s to the Wordpress Options table. These were the arguments used: %2$s',
123
-                            'event_espresso'
124
-                        ),
125
-                        $this->_job_id,
126
-                        wp_json_encode($request_data)
127
-                    )
128
-                );
129
-            }
130
-        } catch (Exception $e) {
131
-            $job_response = $this->_get_error_response($e, 'createJob');
132
-        }
133
-        return $job_response;
134
-    }
135
-
136
-
137
-    /**
138
-     * Retrieves the job's arguments
139
-     *
140
-     * @param string $job_id
141
-     * @param int    $batch_size
142
-     * @return JobStepResponse
143
-     */
144
-    public function continueJob(string $job_id, int $batch_size = 50): JobStepResponse
145
-    {
146
-        try {
147
-            $batch_size   = defined('EE_BATCHRUNNER_BATCH_SIZE')
148
-                ? EE_BATCHRUNNER_BATCH_SIZE
149
-                : $batch_size;
150
-            $job_handler  = $this->initializeJobHandler($job_id);
151
-            $job_response = $job_handler->continueJob($this->_job_parameters, $batch_size);
152
-            $this->validateResponse('continueJob', $this->_job_id, $job_response);
153
-            $this->_job_parameters->save();
154
-        } catch (Exception $e) {
155
-            $job_response = $this->_get_error_response($e, 'continueJob');
156
-        }
157
-        return $job_response;
158
-    }
159
-
160
-
161
-    /**
162
-     * Retrieves the job's arguments
163
-     *
164
-     * @param string $job_id
165
-     * @return JobStepResponse
166
-     */
167
-    public function advanceJob(string $job_id): JobStepResponse
168
-    {
169
-        try {
170
-            $job_handler  = $this->initializeJobHandler($job_id);
171
-            $job_response = $job_handler->advanceJob($this->_job_parameters);
172
-            $this->validateResponse('advanceJob', $this->_job_id, $job_response);
173
-            $this->_job_parameters->save();
174
-        } catch (Exception $e) {
175
-            $job_response = $this->_get_error_response($e, 'advanceJob');
176
-        }
177
-        return $job_response;
178
-    }
179
-
180
-
181
-    /**
182
-     * Forces a job to be cleaned up
183
-     *
184
-     * @param string $job_id
185
-     * @return JobStepResponse
186
-     */
187
-    public function cleanupJob(string $job_id): JobStepResponse
188
-    {
189
-        try {
190
-            $job_handler  = $this->initializeJobHandler($job_id);
191
-            $job_response = $job_handler->cleanupJob($this->_job_parameters);
192
-            $this->validateResponse('cleanupJob', $this->_job_id, $job_response);
193
-            $this->_job_parameters->set_status(JobParameters::status_cleaned_up);
194
-            $this->_job_parameters->delete();
195
-        } catch (Exception $e) {
196
-            $job_response = $this->_get_error_response($e, 'cleanupJob');
197
-        }
198
-        return $job_response;
199
-    }
200
-
201
-
202
-    /**
203
-     * Instantiates an object of type $classname, which implements
204
-     * JobHandlerInterface
205
-     *
206
-     * @param JobParameters $job_parameters
207
-     * @return JobHandlerInterface
208
-     * @throws BatchRequestException
209
-     */
210
-    public function instantiateBatchJobHandlerFromJobParameters(JobParameters $job_parameters): JobHandlerInterface
211
-    {
212
-        $this->verifyJobHandlerClassExists($job_parameters);
213
-        $job_handler = $this->loader->getNew($job_parameters->classname());
214
-        $this->validateJobHandler($job_handler, $job_parameters);
215
-        $job_handler->setRequestData($job_parameters->request_data());
216
-        if ($job_handler instanceof DbServiceJobHandler) {
217
-            $job_handler->initialize($job_parameters);
218
-        }
219
-        return $job_handler;
220
-    }
221
-
222
-
223
-    /**
224
-     * Instantiates an object of type $classname, which implements
225
-     * JobHandlerInterface
226
-     *
227
-     * @param string $classname
228
-     * @param array  $request_data
229
-     * @return JobHandlerInterface
230
-     * @throws BatchRequestException
231
-     * @deprecatd 5.0.0.p
232
-     */
233
-    public function instantiate_batch_job_handler_from_classname(
234
-        string $classname,
235
-        array $request_data = []
236
-    ): JobHandlerInterface {
237
-        return $this->instantiateBatchJobHandlerFromJobParameters($this->_job_parameters);
238
-    }
239
-
240
-
241
-    /**
242
-     * Creates a valid JobStepResponse object from an exception and method name.
243
-     *
244
-     * @param Exception $exception
245
-     * @param string    $method_name
246
-     * @return JobStepResponse
247
-     */
248
-    protected function _get_error_response(Exception $exception, string $method_name): JobStepResponse
249
-    {
250
-        if (! $this->_job_parameters instanceof JobParameters) {
251
-            $this->_job_parameters = new JobParameters($this->_job_id, esc_html__('__Unknown__', 'event_espresso'), []);
252
-        }
253
-        $this->_job_parameters->set_status(JobParameters::status_error);
254
-
255
-        $error_message = sprintf(
256
-            esc_html__(
257
-                '%1$sWhile running %3$s the following %2$s occurred: %4$s %5$s',
258
-                'event_espresso'
259
-            ),
260
-            '<h4>',
261
-            get_class($exception),
262
-            '<code>' . 'BatchRunner::' . $method_name . '()</code>',
263
-            '</h4><p>' . $exception->getMessage() . '</p>',
264
-            '<pre>' . $exception->getTraceAsString() . '</pre>'
265
-        );
266
-        return new JobStepResponse(
267
-            $this->_job_parameters,
268
-            "<div class='ee-batch-runner__error ee-status-outline ee-status-outline--error'>$error_message</div>"
269
-        );
270
-    }
271
-
272
-
273
-    /**
274
-     * @param string $function
275
-     * @param string $job_id
276
-     * @param        $job_response
277
-     * @throws BatchRequestException
278
-     * @since   5.0.0.p
279
-     */
280
-    private function validateResponse(string $function, string $job_id, $job_response)
281
-    {
282
-        if (! $job_response instanceof JobStepResponse) {
283
-            throw new BatchRequestException(
284
-                sprintf(
285
-                    esc_html__(
286
-                        'The class implementing JobHandlerInterface did not return a JobStepResponse when %1$s was called for job %2$s. It needs to return one or throw an Exception',
287
-                        'event_espresso'
288
-                    ),
289
-                    $function,
290
-                    $job_id
291
-                )
292
-            );
293
-        }
294
-    }
295
-
296
-
297
-    /**
298
-     * @param JobParameters $job_parameters
299
-     * @throws BatchRequestException
300
-     * @since   5.0.0.p
301
-     */
302
-    private function verifyJobHandlerClassExists(JobParameters $job_parameters)
303
-    {
304
-        if (! class_exists($job_parameters->classname())) {
305
-            throw new BatchRequestException(
306
-                sprintf(
307
-                    esc_html__(
308
-                        'The class %1$s does not exist, and so could not be used for running a job. It should implement JobHandlerInterface.',
309
-                        'event_espresso'
310
-                    ),
311
-                    $job_parameters->classname()
312
-                )
313
-            );
314
-        }
315
-    }
316
-
317
-    /**
318
-     * @param JobHandlerInterface|NULL $job_handler
319
-     * @param JobParameters $job_parameters
320
-     * @throws BatchRequestException
321
-     * @since   5.0.0.p
322
-     */
323
-    private function validateJobHandler(?JobHandlerInterface $job_handler, JobParameters $job_parameters)
324
-    {
325
-        if (! $job_handler instanceof JobHandlerInterface) {
326
-            throw new BatchRequestException(
327
-                sprintf(
328
-                    esc_html__(
329
-                        'The class %1$s does not implement JobHandlerInterface and so could not be used for running a job',
330
-                        'event_espresso'
331
-                    ),
332
-                    $job_parameters->classname()
333
-                )
334
-            );
335
-        }
336
-    }
34
+	/**
35
+	 * Current job's ID (if assigned)
36
+	 *
37
+	 * @var string|null
38
+	 */
39
+	protected $_job_id = '';
40
+
41
+	/**
42
+	 * Current job's parameters
43
+	 *
44
+	 * @var JobParameters|null
45
+	 */
46
+	protected $_job_parameters = null;
47
+
48
+	/**
49
+	 * @var LoaderInterface|null
50
+	 */
51
+	private $loader;
52
+
53
+
54
+	/**
55
+	 * @var RequestInterface|null
56
+	 */
57
+	private $request;
58
+
59
+
60
+	/**
61
+	 * BatchRequestProcessor constructor.
62
+	 *
63
+	 * @param LoaderInterface  $loader
64
+	 * @param RequestInterface $request
65
+	 */
66
+	public function __construct(LoaderInterface $loader, RequestInterface $request)
67
+	{
68
+		$this->loader  = $loader;
69
+		$this->request = $request;
70
+	}
71
+
72
+
73
+	/**
74
+	 * @param string $job_id
75
+	 * @param string $job_handler_class
76
+	 * @param array  $request_data
77
+	 * @return JobHandlerInterface
78
+	 * @throws BatchRequestException
79
+	 * @since   5.0.0.p
80
+	 */
81
+	private function initializeJobHandler(
82
+		string $job_id,
83
+		string $job_handler_class = '',
84
+		array $request_data = []
85
+	): JobHandlerInterface {
86
+		$this->_job_id         = $job_id;
87
+		$this->_job_parameters = ! empty($job_handler_class)
88
+			? new JobParameters($this->_job_id, $job_handler_class, $request_data)
89
+			: JobParameters::load($this->_job_id);
90
+		$this->_job_parameters->save();
91
+		return $this->instantiateBatchJobHandlerFromJobParameters($this->_job_parameters);
92
+	}
93
+
94
+
95
+	/**
96
+	 * Creates a job for the specified batch handler class (which should be autoloaded)
97
+	 * and the specified request data
98
+	 *
99
+	 * @return JobStepResponse
100
+	 */
101
+	public function createJob(): JobStepResponse
102
+	{
103
+		try {
104
+			$request_data = $this->request->requestParams();
105
+			$job_id       = $this->request->getRequestParam(
106
+				'job_code',
107
+				wp_generate_password(15, false)
108
+			);
109
+			$service      = $this->request->getRequestParam('job_handler', '', 'fqcn');
110
+			$assessment   = $this->request->getRequestParam('job_assessment', '', 'fqcn');
111
+			$job_class    = $assessment !== '' ? $assessment : $service;
112
+			// replace escaped escaped backslashes with escaped unescaped backslashes :lol:
113
+			$job_class    = str_replace('\\\\', '\\', urldecode($job_class));
114
+			$job_handler  = $this->initializeJobHandler($job_id, $job_class, $request_data);
115
+			$job_response = $job_handler->createJob($this->_job_parameters);
116
+			$this->validateResponse('createJob', $this->_job_id, $job_response);
117
+			$success = $this->_job_parameters->save();
118
+			if (! $success) {
119
+				throw new BatchRequestException(
120
+					sprintf(
121
+						esc_html__(
122
+							'Could not save job %1$s to the Wordpress Options table. These were the arguments used: %2$s',
123
+							'event_espresso'
124
+						),
125
+						$this->_job_id,
126
+						wp_json_encode($request_data)
127
+					)
128
+				);
129
+			}
130
+		} catch (Exception $e) {
131
+			$job_response = $this->_get_error_response($e, 'createJob');
132
+		}
133
+		return $job_response;
134
+	}
135
+
136
+
137
+	/**
138
+	 * Retrieves the job's arguments
139
+	 *
140
+	 * @param string $job_id
141
+	 * @param int    $batch_size
142
+	 * @return JobStepResponse
143
+	 */
144
+	public function continueJob(string $job_id, int $batch_size = 50): JobStepResponse
145
+	{
146
+		try {
147
+			$batch_size   = defined('EE_BATCHRUNNER_BATCH_SIZE')
148
+				? EE_BATCHRUNNER_BATCH_SIZE
149
+				: $batch_size;
150
+			$job_handler  = $this->initializeJobHandler($job_id);
151
+			$job_response = $job_handler->continueJob($this->_job_parameters, $batch_size);
152
+			$this->validateResponse('continueJob', $this->_job_id, $job_response);
153
+			$this->_job_parameters->save();
154
+		} catch (Exception $e) {
155
+			$job_response = $this->_get_error_response($e, 'continueJob');
156
+		}
157
+		return $job_response;
158
+	}
159
+
160
+
161
+	/**
162
+	 * Retrieves the job's arguments
163
+	 *
164
+	 * @param string $job_id
165
+	 * @return JobStepResponse
166
+	 */
167
+	public function advanceJob(string $job_id): JobStepResponse
168
+	{
169
+		try {
170
+			$job_handler  = $this->initializeJobHandler($job_id);
171
+			$job_response = $job_handler->advanceJob($this->_job_parameters);
172
+			$this->validateResponse('advanceJob', $this->_job_id, $job_response);
173
+			$this->_job_parameters->save();
174
+		} catch (Exception $e) {
175
+			$job_response = $this->_get_error_response($e, 'advanceJob');
176
+		}
177
+		return $job_response;
178
+	}
179
+
180
+
181
+	/**
182
+	 * Forces a job to be cleaned up
183
+	 *
184
+	 * @param string $job_id
185
+	 * @return JobStepResponse
186
+	 */
187
+	public function cleanupJob(string $job_id): JobStepResponse
188
+	{
189
+		try {
190
+			$job_handler  = $this->initializeJobHandler($job_id);
191
+			$job_response = $job_handler->cleanupJob($this->_job_parameters);
192
+			$this->validateResponse('cleanupJob', $this->_job_id, $job_response);
193
+			$this->_job_parameters->set_status(JobParameters::status_cleaned_up);
194
+			$this->_job_parameters->delete();
195
+		} catch (Exception $e) {
196
+			$job_response = $this->_get_error_response($e, 'cleanupJob');
197
+		}
198
+		return $job_response;
199
+	}
200
+
201
+
202
+	/**
203
+	 * Instantiates an object of type $classname, which implements
204
+	 * JobHandlerInterface
205
+	 *
206
+	 * @param JobParameters $job_parameters
207
+	 * @return JobHandlerInterface
208
+	 * @throws BatchRequestException
209
+	 */
210
+	public function instantiateBatchJobHandlerFromJobParameters(JobParameters $job_parameters): JobHandlerInterface
211
+	{
212
+		$this->verifyJobHandlerClassExists($job_parameters);
213
+		$job_handler = $this->loader->getNew($job_parameters->classname());
214
+		$this->validateJobHandler($job_handler, $job_parameters);
215
+		$job_handler->setRequestData($job_parameters->request_data());
216
+		if ($job_handler instanceof DbServiceJobHandler) {
217
+			$job_handler->initialize($job_parameters);
218
+		}
219
+		return $job_handler;
220
+	}
221
+
222
+
223
+	/**
224
+	 * Instantiates an object of type $classname, which implements
225
+	 * JobHandlerInterface
226
+	 *
227
+	 * @param string $classname
228
+	 * @param array  $request_data
229
+	 * @return JobHandlerInterface
230
+	 * @throws BatchRequestException
231
+	 * @deprecatd 5.0.0.p
232
+	 */
233
+	public function instantiate_batch_job_handler_from_classname(
234
+		string $classname,
235
+		array $request_data = []
236
+	): JobHandlerInterface {
237
+		return $this->instantiateBatchJobHandlerFromJobParameters($this->_job_parameters);
238
+	}
239
+
240
+
241
+	/**
242
+	 * Creates a valid JobStepResponse object from an exception and method name.
243
+	 *
244
+	 * @param Exception $exception
245
+	 * @param string    $method_name
246
+	 * @return JobStepResponse
247
+	 */
248
+	protected function _get_error_response(Exception $exception, string $method_name): JobStepResponse
249
+	{
250
+		if (! $this->_job_parameters instanceof JobParameters) {
251
+			$this->_job_parameters = new JobParameters($this->_job_id, esc_html__('__Unknown__', 'event_espresso'), []);
252
+		}
253
+		$this->_job_parameters->set_status(JobParameters::status_error);
254
+
255
+		$error_message = sprintf(
256
+			esc_html__(
257
+				'%1$sWhile running %3$s the following %2$s occurred: %4$s %5$s',
258
+				'event_espresso'
259
+			),
260
+			'<h4>',
261
+			get_class($exception),
262
+			'<code>' . 'BatchRunner::' . $method_name . '()</code>',
263
+			'</h4><p>' . $exception->getMessage() . '</p>',
264
+			'<pre>' . $exception->getTraceAsString() . '</pre>'
265
+		);
266
+		return new JobStepResponse(
267
+			$this->_job_parameters,
268
+			"<div class='ee-batch-runner__error ee-status-outline ee-status-outline--error'>$error_message</div>"
269
+		);
270
+	}
271
+
272
+
273
+	/**
274
+	 * @param string $function
275
+	 * @param string $job_id
276
+	 * @param        $job_response
277
+	 * @throws BatchRequestException
278
+	 * @since   5.0.0.p
279
+	 */
280
+	private function validateResponse(string $function, string $job_id, $job_response)
281
+	{
282
+		if (! $job_response instanceof JobStepResponse) {
283
+			throw new BatchRequestException(
284
+				sprintf(
285
+					esc_html__(
286
+						'The class implementing JobHandlerInterface did not return a JobStepResponse when %1$s was called for job %2$s. It needs to return one or throw an Exception',
287
+						'event_espresso'
288
+					),
289
+					$function,
290
+					$job_id
291
+				)
292
+			);
293
+		}
294
+	}
295
+
296
+
297
+	/**
298
+	 * @param JobParameters $job_parameters
299
+	 * @throws BatchRequestException
300
+	 * @since   5.0.0.p
301
+	 */
302
+	private function verifyJobHandlerClassExists(JobParameters $job_parameters)
303
+	{
304
+		if (! class_exists($job_parameters->classname())) {
305
+			throw new BatchRequestException(
306
+				sprintf(
307
+					esc_html__(
308
+						'The class %1$s does not exist, and so could not be used for running a job. It should implement JobHandlerInterface.',
309
+						'event_espresso'
310
+					),
311
+					$job_parameters->classname()
312
+				)
313
+			);
314
+		}
315
+	}
316
+
317
+	/**
318
+	 * @param JobHandlerInterface|NULL $job_handler
319
+	 * @param JobParameters $job_parameters
320
+	 * @throws BatchRequestException
321
+	 * @since   5.0.0.p
322
+	 */
323
+	private function validateJobHandler(?JobHandlerInterface $job_handler, JobParameters $job_parameters)
324
+	{
325
+		if (! $job_handler instanceof JobHandlerInterface) {
326
+			throw new BatchRequestException(
327
+				sprintf(
328
+					esc_html__(
329
+						'The class %1$s does not implement JobHandlerInterface and so could not be used for running a job',
330
+						'event_espresso'
331
+					),
332
+					$job_parameters->classname()
333
+				)
334
+			);
335
+		}
336
+	}
337 337
 }
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlerBaseClasses/JobHandler.php 1 patch
Indentation   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -17,271 +17,271 @@
 block discarded – undo
17 17
  */
18 18
 abstract class JobHandler implements JobHandlerInterface
19 19
 {
20
-    /**
21
-     * @var array
22
-     */
23
-    protected $feedback = [];
24
-
25
-    /**
26
-     * incoming Request data
27
-     *
28
-     * @var array
29
-     */
30
-    protected $request_data = [];
31
-
32
-    /**
33
-     * Extra data to include as part of the response, literally gets set as JobStepResponse::$_extra_data
34
-     *
35
-     * @var array
36
-     */
37
-    protected $response_data = [];
38
-
39
-
40
-    /**
41
-     * utilized in newer batch job implementations, but forwarding to existing methods for now.
42
-     * Performs any necessary setup for starting the job. This is also a good
43
-     * place to setup the $job_arguments which will be used for subsequent HTTP requests
44
-     * when continue_job will be called
45
-     *
46
-     * @param JobParameters $job_parameters
47
-     * @return JobStepResponse
48
-     * @throws BatchRequestException
49
-     * @since 5.0.0.p
50
-     */
51
-    public function createJob(JobParameters $job_parameters): JobStepResponse
52
-    {
53
-        return $this->create_job($job_parameters);
54
-    }
55
-
56
-
57
-    /**
58
-     * utilized in newer batch job implementations, but forwarding to existing methods for now.
59
-     * Performs another step of the job
60
-     *
61
-     * @param JobParameters $job_parameters
62
-     * @param int           $batch_size
63
-     * @return JobStepResponse
64
-     * @throws BatchRequestException
65
-     * @since 5.0.0.p
66
-     */
67
-    public function continueJob(JobParameters $job_parameters, int $batch_size = 50): JobStepResponse
68
-    {
69
-        return $this->continue_job($job_parameters, $batch_size);
70
-    }
71
-
72
-
73
-    /**
74
-     * utilized in newer batch job implementations, but forwarding to existing methods for now.
75
-     * used to advance from one batch job to another
76
-     * primarily used for executing a job assessment phase where an accurate count of items to update can be made,
77
-     * followed by the actual update job.
78
-     *
79
-     * @param JobParameters $job_parameters
80
-     * @return JobStepResponse
81
-     * @since 5.0.0.p
82
-     */
83
-    public function advanceJob(JobParameters $job_parameters): JobStepResponse
84
-    {
85
-        return $this->advance_job($job_parameters);
86
-    }
87
-
88
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
89
-    /**
90
-     * used to advance from one batch job to another
91
-     * primarily used for executing a job assessment phase where an accurate count of items to update can be made,
92
-     * followed by the actual update job.
93
-     * By default, this function won't do anything until overridden in a chile class.
94
-     *
95
-     * @param JobParameters $job_parameters
96
-     * @return JobStepResponse
97
-     * @since 5.0.0.p
98
-     */
99
-    public function advance_job(JobParameters $job_parameters): JobStepResponse
100
-    {
101
-        $job_parameters->set_status(JobParameters::status_continue);
102
-        return new JobStepResponse($job_parameters, $this->feedback);
103
-    }
104
-
105
-
106
-    /**
107
-     * utilized in newer batch job implementations, but forwarding to existing methods for now.
108
-     * Performs any clean-up logic when we know the job is completed
109
-     *
110
-     * @param JobParameters $job_parameters
111
-     * @return JobStepResponse
112
-     * @throws BatchRequestException
113
-     * @since 5.0.0.p
114
-     */
115
-    public function cleanupJob(JobParameters $job_parameters): JobStepResponse
116
-    {
117
-        return $this->cleanup_job($job_parameters);
118
-    }
119
-
120
-
121
-    /**
122
-     * @return array
123
-     */
124
-    public function requestData(): array
125
-    {
126
-        return $this->request_data;
127
-    }
128
-
129
-
130
-    /**
131
-     * @return mixed
132
-     */
133
-    public function getRequestData($key)
134
-    {
135
-        return $this->request_data[ $key ] ?? null;
136
-    }
137
-
138
-
139
-    /**
140
-     * @param array $request_data
141
-     */
142
-    public function setRequestData(array $request_data): void
143
-    {
144
-        $this->request_data = $request_data;
145
-    }
146
-
147
-
148
-    /**
149
-     * @return array
150
-     */
151
-    public function responseData(): array
152
-    {
153
-        return $this->response_data;
154
-    }
155
-
156
-
157
-    /**
158
-     * @param array $response_data
159
-     */
160
-    public function addResponseData(array $response_data): void
161
-    {
162
-        $this->response_data += $response_data;
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * @param array $response_data
169
-     */
170
-    public function setResponseData(array $response_data): void
171
-    {
172
-        $this->response_data = $response_data;
173
-    }
174
-
175
-
176
-
177
-
178
-    protected function displayJobStepResults(int $processed, string $custom_message = '')
179
-    {
180
-        $this->feedback[] = '
20
+	/**
21
+	 * @var array
22
+	 */
23
+	protected $feedback = [];
24
+
25
+	/**
26
+	 * incoming Request data
27
+	 *
28
+	 * @var array
29
+	 */
30
+	protected $request_data = [];
31
+
32
+	/**
33
+	 * Extra data to include as part of the response, literally gets set as JobStepResponse::$_extra_data
34
+	 *
35
+	 * @var array
36
+	 */
37
+	protected $response_data = [];
38
+
39
+
40
+	/**
41
+	 * utilized in newer batch job implementations, but forwarding to existing methods for now.
42
+	 * Performs any necessary setup for starting the job. This is also a good
43
+	 * place to setup the $job_arguments which will be used for subsequent HTTP requests
44
+	 * when continue_job will be called
45
+	 *
46
+	 * @param JobParameters $job_parameters
47
+	 * @return JobStepResponse
48
+	 * @throws BatchRequestException
49
+	 * @since 5.0.0.p
50
+	 */
51
+	public function createJob(JobParameters $job_parameters): JobStepResponse
52
+	{
53
+		return $this->create_job($job_parameters);
54
+	}
55
+
56
+
57
+	/**
58
+	 * utilized in newer batch job implementations, but forwarding to existing methods for now.
59
+	 * Performs another step of the job
60
+	 *
61
+	 * @param JobParameters $job_parameters
62
+	 * @param int           $batch_size
63
+	 * @return JobStepResponse
64
+	 * @throws BatchRequestException
65
+	 * @since 5.0.0.p
66
+	 */
67
+	public function continueJob(JobParameters $job_parameters, int $batch_size = 50): JobStepResponse
68
+	{
69
+		return $this->continue_job($job_parameters, $batch_size);
70
+	}
71
+
72
+
73
+	/**
74
+	 * utilized in newer batch job implementations, but forwarding to existing methods for now.
75
+	 * used to advance from one batch job to another
76
+	 * primarily used for executing a job assessment phase where an accurate count of items to update can be made,
77
+	 * followed by the actual update job.
78
+	 *
79
+	 * @param JobParameters $job_parameters
80
+	 * @return JobStepResponse
81
+	 * @since 5.0.0.p
82
+	 */
83
+	public function advanceJob(JobParameters $job_parameters): JobStepResponse
84
+	{
85
+		return $this->advance_job($job_parameters);
86
+	}
87
+
88
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
89
+	/**
90
+	 * used to advance from one batch job to another
91
+	 * primarily used for executing a job assessment phase where an accurate count of items to update can be made,
92
+	 * followed by the actual update job.
93
+	 * By default, this function won't do anything until overridden in a chile class.
94
+	 *
95
+	 * @param JobParameters $job_parameters
96
+	 * @return JobStepResponse
97
+	 * @since 5.0.0.p
98
+	 */
99
+	public function advance_job(JobParameters $job_parameters): JobStepResponse
100
+	{
101
+		$job_parameters->set_status(JobParameters::status_continue);
102
+		return new JobStepResponse($job_parameters, $this->feedback);
103
+	}
104
+
105
+
106
+	/**
107
+	 * utilized in newer batch job implementations, but forwarding to existing methods for now.
108
+	 * Performs any clean-up logic when we know the job is completed
109
+	 *
110
+	 * @param JobParameters $job_parameters
111
+	 * @return JobStepResponse
112
+	 * @throws BatchRequestException
113
+	 * @since 5.0.0.p
114
+	 */
115
+	public function cleanupJob(JobParameters $job_parameters): JobStepResponse
116
+	{
117
+		return $this->cleanup_job($job_parameters);
118
+	}
119
+
120
+
121
+	/**
122
+	 * @return array
123
+	 */
124
+	public function requestData(): array
125
+	{
126
+		return $this->request_data;
127
+	}
128
+
129
+
130
+	/**
131
+	 * @return mixed
132
+	 */
133
+	public function getRequestData($key)
134
+	{
135
+		return $this->request_data[ $key ] ?? null;
136
+	}
137
+
138
+
139
+	/**
140
+	 * @param array $request_data
141
+	 */
142
+	public function setRequestData(array $request_data): void
143
+	{
144
+		$this->request_data = $request_data;
145
+	}
146
+
147
+
148
+	/**
149
+	 * @return array
150
+	 */
151
+	public function responseData(): array
152
+	{
153
+		return $this->response_data;
154
+	}
155
+
156
+
157
+	/**
158
+	 * @param array $response_data
159
+	 */
160
+	public function addResponseData(array $response_data): void
161
+	{
162
+		$this->response_data += $response_data;
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * @param array $response_data
169
+	 */
170
+	public function setResponseData(array $response_data): void
171
+	{
172
+		$this->response_data = $response_data;
173
+	}
174
+
175
+
176
+
177
+
178
+	protected function displayJobStepResults(int $processed, string $custom_message = '')
179
+	{
180
+		$this->feedback[] = '
181 181
 			<div class="ee-batch-job-step-results">
182 182
 			' . $this->infoWrapper(
183
-            sprintf(
184
-                $custom_message !== ''
185
-                        ? $custom_message
186
-                        : esc_html__('processed this batch: %d', 'event_espresso'),
187
-                $processed
188
-            )
189
-        ) . '
183
+			sprintf(
184
+				$custom_message !== ''
185
+						? $custom_message
186
+						: esc_html__('processed this batch: %d', 'event_espresso'),
187
+				$processed
188
+			)
189
+		) . '
190 190
 			</div>';
191
-    }
191
+	}
192 192
 
193 193
 
194
-    protected function displayJobFinalResults(JobParameters $job_parameters, string $custom_message = '')
195
-    {
196
-        if ($job_parameters->status() === JobParameters::status_complete) {
197
-            $this->feedback[] = '
194
+	protected function displayJobFinalResults(JobParameters $job_parameters, string $custom_message = '')
195
+	{
196
+		if ($job_parameters->status() === JobParameters::status_complete) {
197
+			$this->feedback[] = '
198 198
 			<div class="ee-batch-job-final-results">
199 199
 				' . $this->okWrapper(
200
-                sprintf(
201
-                    $custom_message !== ''
202
-                            ? $custom_message
203
-                            : esc_html__('total units processed: %d', 'event_espresso'),
204
-                    $job_parameters->units_processed()
205
-                )
206
-            ) . '
200
+				sprintf(
201
+					$custom_message !== ''
202
+							? $custom_message
203
+							: esc_html__('total units processed: %d', 'event_espresso'),
204
+					$job_parameters->units_processed()
205
+				)
206
+			) . '
207 207
 				' . $this->jobStatusNotice($job_parameters) . '
208 208
 			</div>';
209
-        }
210
-    }
209
+		}
210
+	}
211 211
 
212 212
 
213
-    protected function jobStatusNotice(JobParameters $job_parameters): string
214
-    {
215
-        switch ($job_parameters->status()) {
216
-            case JobParameters::status_cleaned_up:
217
-            case JobParameters::status_continue:
218
-            case JobParameters::status_pause:
219
-                break;
220
-            case JobParameters::status_complete:
221
-                return $this->successWrapper('job status: COMPLETE');
222
-            case JobParameters::status_error:
223
-                return $this->errorWrapper('job status: ERROR');
224
-        }
225
-        return '';
226
-    }
213
+	protected function jobStatusNotice(JobParameters $job_parameters): string
214
+	{
215
+		switch ($job_parameters->status()) {
216
+			case JobParameters::status_cleaned_up:
217
+			case JobParameters::status_continue:
218
+			case JobParameters::status_pause:
219
+				break;
220
+			case JobParameters::status_complete:
221
+				return $this->successWrapper('job status: COMPLETE');
222
+			case JobParameters::status_error:
223
+				return $this->errorWrapper('job status: ERROR');
224
+		}
225
+		return '';
226
+	}
227 227
 
228 228
 
229
-    /**
230
-     * @param string $update_text
231
-     */
232
-    protected function updateText(string $update_text)
233
-    {
234
-        $this->feedback[] = "<p class='ee-batch-job-update'>$update_text</p>";
235
-    }
229
+	/**
230
+	 * @param string $update_text
231
+	 */
232
+	protected function updateText(string $update_text)
233
+	{
234
+		$this->feedback[] = "<p class='ee-batch-job-update'>$update_text</p>";
235
+	}
236 236
 
237 237
 
238
-    protected function updateTextHeader(string $update_text)
239
-    {
240
-        $this->feedback[] = "<h4 class='ee-batch-job-update-heading'>$update_text</h4>";
241
-    }
238
+	protected function updateTextHeader(string $update_text)
239
+	{
240
+		$this->feedback[] = "<h4 class='ee-batch-job-update-heading'>$update_text</h4>";
241
+	}
242 242
 
243 243
 
244
-    protected function attentionWrapper(string $update_text): string
245
-    {
246
-        return "<span class='ee-status-outline ee-status-bg--attention'>$update_text</span>";
247
-    }
244
+	protected function attentionWrapper(string $update_text): string
245
+	{
246
+		return "<span class='ee-status-outline ee-status-bg--attention'>$update_text</span>";
247
+	}
248 248
 
249 249
 
250
-    protected function errorWrapper(string $update_text): string
251
-    {
252
-        return "<span class='ee-status-outline ee-status-bg--error'>$update_text</span>";
253
-    }
250
+	protected function errorWrapper(string $update_text): string
251
+	{
252
+		return "<span class='ee-status-outline ee-status-bg--error'>$update_text</span>";
253
+	}
254 254
 
255 255
 
256
-    protected function infoWrapper(string $update_text): string
257
-    {
258
-        return "<span class='ee-status-outline ee-status-bg--info'>$update_text</span>";
259
-    }
256
+	protected function infoWrapper(string $update_text): string
257
+	{
258
+		return "<span class='ee-status-outline ee-status-bg--info'>$update_text</span>";
259
+	}
260 260
 
261 261
 
262
-    protected function okWrapper(string $update_text): string
263
-    {
264
-        return "<span class='ee-status-outline ee-status-bg--ok'>$update_text</span>";
265
-    }
262
+	protected function okWrapper(string $update_text): string
263
+	{
264
+		return "<span class='ee-status-outline ee-status-bg--ok'>$update_text</span>";
265
+	}
266 266
 
267 267
 
268
-    protected function successWrapper(string $update_text): string
269
-    {
270
-        return "<span class='ee-status-outline ee-status-bg--success'>$update_text</span>";
271
-    }
268
+	protected function successWrapper(string $update_text): string
269
+	{
270
+		return "<span class='ee-status-outline ee-status-bg--success'>$update_text</span>";
271
+	}
272 272
 
273 273
 
274
-    protected function warningWrapper(string $update_text): string
275
-    {
276
-        return "<span class='ee-status-outline ee-status-bg--warning'>$update_text</span>";
277
-    }
274
+	protected function warningWrapper(string $update_text): string
275
+	{
276
+		return "<span class='ee-status-outline ee-status-bg--warning'>$update_text</span>";
277
+	}
278 278
 
279 279
 
280
-    /**
281
-     * @return string
282
-     */
283
-    protected function spinner(): string
284
-    {
285
-        return '<span class="spinner"></span>';
286
-    }
280
+	/**
281
+	 * @return string
282
+	 */
283
+	protected function spinner(): string
284
+	{
285
+		return '<span class="spinner"></span>';
286
+	}
287 287
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Addon.lib.php 1 patch
Indentation   +1201 added lines, -1201 removed lines patch added patch discarded remove patch
@@ -24,1205 +24,1205 @@
 block discarded – undo
24 24
  */
25 25
 class EE_Register_Addon implements EEI_Plugin_API
26 26
 {
27
-    /**
28
-     * possibly truncated version of the EE core version string
29
-     *
30
-     * @var string
31
-     */
32
-    protected static $_core_version = '';
33
-
34
-    /**
35
-     * Holds values for registered addons
36
-     *
37
-     * @var array
38
-     */
39
-    protected static $_settings = [];
40
-
41
-    /**
42
-     * @var  array $_incompatible_addons keys are addon SLUGS
43
-     * (first argument passed to EE_Register_Addon::register()), keys are
44
-     * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
45
-     * Generally this should be used sparingly, as we don't want to muddle up
46
-     * EE core with knowledge of ALL the addons out there.
47
-     * If you want NO versions of an addon to run with a certain version of core,
48
-     * it's usually best to define the addon's "min_core_version" as part of its call
49
-     * to EE_Register_Addon::register(), rather than using this array with a super high value for its
50
-     * minimum plugin version.
51
-     * @access    protected
52
-     */
53
-    protected static $_incompatible_addons = [
54
-        'Multi_Event_Registration' => '2.0.11.rc.002',
55
-        'Promotions'               => '1.0.0.rc.084',
56
-    ];
57
-
58
-    /**
59
-     * @var LoaderInterface
60
-     */
61
-    protected static $loader;
62
-
63
-
64
-    /**
65
-     * We should always be comparing core to a version like '4.3.0.rc.000',
66
-     * not just '4.3.0'.
67
-     * So if the addon developer doesn't provide that full version string,
68
-     * fill in the blanks for them
69
-     *
70
-     * @param string $min_core_version
71
-     * @return string always like '4.3.0.rc.000'
72
-     */
73
-    protected static function _effective_version(string $min_core_version): string
74
-    {
75
-        // versions: 4 . 3 . 1 . p . 123
76
-        // offsets:    0 . 1 . 2 . 3 . 4
77
-        $version_parts = explode('.', $min_core_version);
78
-        // check they specified the micro version (after 2nd period)
79
-        if (! isset($version_parts[2])) {
80
-            $version_parts[2] = '0';
81
-        }
82
-        // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
83
-        // soon we can assume that's 'rc', but this current version is 'alpha'
84
-        if (! isset($version_parts[3])) {
85
-            $version_parts[3] = 'dev';
86
-        }
87
-        if (! isset($version_parts[4])) {
88
-            $version_parts[4] = '000';
89
-        }
90
-        return implode('.', $version_parts);
91
-    }
92
-
93
-
94
-    /**
95
-     * Returns whether or not the min core version requirement of the addon is met
96
-     *
97
-     * @param string $min_core_version    the minimum core version required by the addon
98
-     * @param string $actual_core_version the actual core version, optional
99
-     * @return bool
100
-     */
101
-    public static function _meets_min_core_version_requirement(
102
-        string $min_core_version,
103
-        string $actual_core_version = EVENT_ESPRESSO_VERSION
104
-    ): bool {
105
-        return version_compare(
106
-            self::_effective_version($actual_core_version),
107
-            self::_effective_version($min_core_version),
108
-            '>='
109
-        );
110
-    }
111
-
112
-
113
-    /**
114
-     * Method for registering new EE_Addons.
115
-     * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
116
-     * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
117
-     * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
118
-     * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
119
-     * 'activate_plugin', it registers the addon still, but its components are not registered
120
-     * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
121
-     * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
122
-     * (so that we can detect that the addon has activated on the subsequent request)
123
-     *
124
-     * @param string                  $addon_name                       [Required] the EE_Addon's name.
125
-     * @param array                   $setup_args                       {
126
-     *                                                                  An array of arguments provided for registering
127
-     *                                                                  the message type.
128
-     * @type  string                  $class_name                       the addon's main file name.
129
-     *                                                                  If left blank, generated from the addon name,
130
-     *                                                                  changes something like "calendar" to
131
-     *                                                                  "EE_Calendar"
132
-     * @type string                   $min_core_version                 the minimum version of EE Core that the
133
-     *                                                                  addon will work with. eg "4.8.1.rc.084"
134
-     * @type string                   $version                          the "software" version for the addon. eg
135
-     *                                                                  "1.0.0.p" for a first stable release, or
136
-     *                                                                  "1.0.0.rc.043" for a version in progress
137
-     * @type string                   $main_file_path                   the full server path to the main file
138
-     *                                                                  loaded directly by WP
139
-     * @type DomainInterface          $domain                           child class of
140
-     *                                                                  EventEspresso\core\domain\DomainBase
141
-     * @type string                   $domain_fqcn                      Fully Qualified Class Name
142
-     *                                                                  for the addon's Domain class
143
-     *                                                                  (see EventEspresso\core\domain\Domain)
144
-     * @type string                   $admin_path                       full server path to the folder where the
145
-     *                                                                  addon\'s admin files reside
146
-     * @type string                   $admin_callback                   a method to be called when the EE Admin is
147
-     *                                                                  first invoked, can be used for hooking into
148
-     *                                                                  any admin page
149
-     * @type string                   $config_section                   the section name for this addon's
150
-     *                                                                  configuration settings section
151
-     *                                                                  (defaults to "addons")
152
-     * @type string                   $config_class                     the class name for this addon's
153
-     *                                                                  configuration settings object
154
-     * @type string                   $config_name                      the class name for this addon's
155
-     *                                                                  configuration settings object
156
-     * @type string                   $autoloader_paths                 [Required] an array of class names and the full
157
-     *                                                                  server paths to those files.
158
-     * @type string                   $autoloader_folders               an array of  "full server paths" for any
159
-     *                                                                  folders containing classes that might be
160
-     *                                                                  invoked by the addon
161
-     * @type string                   $dms_paths                        [Required] an array of full server paths to
162
-     *                                                                  folders that contain data migration scripts.
163
-     *                                                                  The key should be the EE_Addon class name that
164
-     *                                                                  this set of data migration scripts belongs to.
165
-     *                                                                  If the EE_Addon class is namespaced, then this
166
-     *                                                                  needs to be the Fully Qualified Class Name
167
-     * @type string                   $module_paths                     an array of full server paths to any
168
-     *                                                                  EED_Modules used by the addon
169
-     * @type string                   $shortcode_paths                  an array of full server paths to folders
170
-     *                                                                  that contain EES_Shortcodes
171
-     * @type string                   $widget_paths                     an array of full server paths to folders
172
-     *                                                                  that contain WP_Widgets
173
-     * @type array                    $capabilities                     an array indexed by role name
174
-     *                                                                  (i.e administrator,author ) and the values
175
-     *                                                                  are an array of caps to add to the role.
176
-     *                                                                  'administrator' => array(
177
-     *                                                                  'read_addon',
178
-     *                                                                  'edit_addon',
179
-     *                                                                  etc.
180
-     *                                                                  ).
181
-     * @type EE_Meta_Capability_Map[] $capability_maps                  an array of EE_Meta_Capability_Map object
182
-     *                                                                  for any addons that need to register any
183
-     *                                                                  special meta mapped capabilities.  Should
184
-     *                                                                  be indexed where the key is the
185
-     *                                                                  EE_Meta_Capability_Map class name and the
186
-     *                                                                  values are the arguments sent to the class.
187
-     * @type array                    $model_paths                      array of folders containing DB models
188
-     * @return bool
189
-     * @throws DomainException
190
-     * @throws EE_Error
191
-     * @throws InvalidArgumentException
192
-     * @throws InvalidDataTypeException
193
-     * @throws InvalidInterfaceException
194
-     * @since                                                           4.3.0
195
-     * @see                                                             EE_Register_Model
196
-     * @type array                    $class_paths                      array of folders containing DB classes
197
-     * @see                                                             EE_Register_Model
198
-     * @type array                    $model_extension_paths            array of folders containing DB model
199
-     *                                                                  extensions
200
-     * @see                                                             EE_Register_Model_Extension
201
-     * @type array                    $class_extension_paths            array of folders containing DB class
202
-     *                                                                  extensions
203
-     * @see                                                             EE_Register_Model_Extension
204
-     * @type array message_types {
205
-     *                                                                  An array of message types with the key as
206
-     *                                                                  the message type name and the values as
207
-     *                                                                  below:
208
-     * @type string                   $mtfilename                       [Required] The filename of the message type
209
-     *                                                                  being registered. This will be the main
210
-     *                                                                  EE_{Message Type Name}_message_type class.
211
-     *                                                                  for example:
212
-     *                                                                  EE_Declined_Registration_message_type.class.php
213
-     * @type array                    $autoloadpaths                    [Required] An array of paths to add to the
214
-     *                                                                  messages autoloader for the new message type.
215
-     * @type array                    $messengers_to_activate_with      An array of messengers that this message
216
-     *                                                                  type should activate with. Each value in
217
-     *                                                                  the
218
-     *                                                                  array
219
-     *                                                                  should match the name property of a
220
-     *                                                                  EE_messenger. Optional.
221
-     * @type array                    $messengers_to_validate_with      An array of messengers that this message
222
-     *                                                                  type should validate with. Each value in
223
-     *                                                                  the
224
-     *                                                                  array
225
-     *                                                                  should match the name property of an
226
-     *                                                                  EE_messenger.
227
-     *                                                                  Optional.
228
-     *                                                                  }
229
-     * @type array                    $custom_post_types
230
-     * @type array                    $custom_taxonomies
231
-     * @type array                    $payment_method_paths             each element is the folder containing the
232
-     *                                                                  EE_PMT_Base child class
233
-     *                                                                  (eg,
234
-     *                                                                  '/wp-content/plugins/my_plugin/Payomatic/'
235
-     *                                                                  which contains the files
236
-     *                                                                  EE_PMT_Payomatic.pm.php)
237
-     * @type array                    $default_terms
238
-     * @type array                    $namespace                        {
239
-     *                                                                  An array with two items for registering the
240
-     *                                                                  addon's namespace. (If, for some reason, you
241
-     *                                                                  require additional namespaces,
242
-     *                                                                  use
243
-     *                                                                  EventEspresso\core\Psr4Autoloader::addNamespace()
244
-     *                                                                  directly)
245
-     * @see                                                             EventEspresso\core\Psr4Autoloader::addNamespace()
246
-     * @type string                   $FQNS                             the namespace prefix
247
-     * @type string                   $DIR                              a base directory for class files in the
248
-     *                                                                  namespace.
249
-     *                                                                  }
250
-     *                                                                  }
251
-     * @type string                   $privacy_policies                 FQNSs (namespaces, each of which contains only
252
-     *                                                                  privacy policy classes) or FQCNs (specific
253
-     *                                                                  classnames of privacy policy classes)
254
-     * @type string                   $personal_data_exporters          FQNSs (namespaces, each of which contains only
255
-     *                                                                  privacy policy classes) or FQCNs (specific
256
-     *                                                                  classnames of privacy policy classes)
257
-     * @type string                   $personal_data_erasers            FQNSs (namespaces, each of which contains only
258
-     *                                                                  privacy policy classes) or FQCNs (specific
259
-     *                                                                  classnames of privacy policy classes)
260
-     */
261
-    public static function register(string $addon_name = '', array $setup_args = []): bool
262
-    {
263
-        if (! self::$loader instanceof LoaderInterface) {
264
-            self::$loader = LoaderFactory::getLoader();
265
-        }
266
-        // make sure this was called in the right place!
267
-        if (
268
-            ! did_action('activate_plugin')
269
-            && (
270
-                ! did_action('AHEE__EE_System__load_espresso_addons')
271
-                || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
272
-            )
273
-        ) {
274
-            EE_Error::doing_it_wrong(
275
-                __METHOD__,
276
-                sprintf(
277
-                    esc_html__(
278
-                        'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
279
-                        'event_espresso'
280
-                    ),
281
-                    $addon_name
282
-                ),
283
-                '4.3.0'
284
-            );
285
-            return false;
286
-        }
287
-        // required fields MUST be present, so let's make sure they are.
288
-        EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
289
-        // get class name for addon
290
-        $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
291
-        // setup $_settings array from incoming values.
292
-        $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
293
-        // allow early addon setup or modification of addon api settings
294
-        self::$_settings = (array) apply_filters(
295
-            'FHEE__EE_Register_Addon__register',
296
-            self::$_settings,
297
-            $addon_name,
298
-            $class_name,
299
-            $setup_args
300
-        );
301
-        // does this addon work with this version of core or WordPress ?
302
-        // does this addon work with this version of core or WordPress ?
303
-        if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
304
-            return false;
305
-        }
306
-        // register namespaces
307
-        EE_Register_Addon::_setup_namespaces($addon_settings);
308
-        // check if this is an activation request
309
-        if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
310
-            // dont bother setting up the rest of the addon atm
311
-            return false;
312
-        }
313
-        // we need cars
314
-        EE_Register_Addon::_setup_autoloaders($addon_name);
315
-        // register new models and extensions
316
-        EE_Register_Addon::_register_models_and_extensions($addon_name);
317
-        // setup DMS
318
-        EE_Register_Addon::_register_data_migration_scripts($addon_name);
319
-        // if config_class is present let's register config.
320
-        EE_Register_Addon::_register_config($addon_name);
321
-        // register admin pages
322
-        EE_Register_Addon::_register_admin_pages($addon_name);
323
-        // add to list of modules to be registered
324
-        EE_Register_Addon::_register_modules($addon_name);
325
-        // add to list of shortcodes to be registered
326
-        EE_Register_Addon::_register_shortcodes($addon_name);
327
-        // add to list of widgets to be registered
328
-        EE_Register_Addon::_register_widgets($addon_name);
329
-        // register capability related stuff.
330
-        EE_Register_Addon::_register_capabilities($addon_name);
331
-        // any message type to register?
332
-        EE_Register_Addon::_register_message_types($addon_name);
333
-        // any custom post type/ custom capabilities or default terms to register
334
-        EE_Register_Addon::_register_custom_post_types($addon_name);
335
-        // and any payment methods
336
-        EE_Register_Addon::_register_payment_methods($addon_name);
337
-        // and privacy policy generators
338
-        EE_Register_Addon::registerPrivacyPolicies($addon_name);
339
-        // and privacy policy generators
340
-        EE_Register_Addon::registerPersonalDataExporters($addon_name);
341
-        // and privacy policy generators
342
-        EE_Register_Addon::registerPersonalDataErasers($addon_name);
343
-        // load and instantiate main addon class
344
-        $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name);
345
-        // delay calling after_registration hook on each addon until after all add-ons have been registered.
346
-        add_action('AHEE__EE_System__load_espresso_addons__complete', [$addon, 'after_registration'], 999);
347
-        return $addon instanceof EE_Addon;
348
-    }
349
-
350
-
351
-    /**
352
-     * @param string $addon_name
353
-     * @param array  $setup_args
354
-     * @return void
355
-     * @throws EE_Error
356
-     */
357
-    private static function _verify_parameters(string $addon_name, array $setup_args)
358
-    {
359
-        // required fields MUST be present, so let's make sure they are.
360
-        if (empty($addon_name) || empty($setup_args)) {
361
-            throw new EE_Error(
362
-                esc_html__(
363
-                    'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
364
-                    'event_espresso'
365
-                )
366
-            );
367
-        }
368
-        if (empty($setup_args['main_file_path'])) {
369
-            throw new EE_Error(
370
-                sprintf(
371
-                    esc_html__(
372
-                        'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
373
-                        'event_espresso'
374
-                    ),
375
-                    implode(',', array_keys($setup_args))
376
-                )
377
-            );
378
-        }
379
-        // check that addon has not already been registered with that name
380
-        if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
381
-            throw new EE_Error(
382
-                sprintf(
383
-                    esc_html__(
384
-                        'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
385
-                        'event_espresso'
386
-                    ),
387
-                    $addon_name
388
-                )
389
-            );
390
-        }
391
-    }
392
-
393
-
394
-    /**
395
-     * @param string $addon_name
396
-     * @param array  $setup_args
397
-     * @return string
398
-     */
399
-    private static function _parse_class_name(string $addon_name, array $setup_args): string
400
-    {
401
-        if (empty($setup_args['class_name'])) {
402
-            // generate one by first separating name with spaces
403
-            $class_name = str_replace(['-', '_'], ' ', trim($addon_name));
404
-            // capitalize, then replace spaces with underscores
405
-            $class_name = str_replace(' ', '_', ucwords($class_name));
406
-        } else {
407
-            $class_name = $setup_args['class_name'];
408
-        }
409
-        // check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
410
-        return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
411
-            ? $class_name
412
-            : 'EE_' . $class_name;
413
-    }
414
-
415
-
416
-    /**
417
-     * @param string $class_name
418
-     * @param array  $setup_args
419
-     * @return array
420
-     */
421
-    private static function _get_addon_settings(string $class_name, array $setup_args): array
422
-    {
423
-        // setup $_settings array from incoming values.
424
-        $addon_settings = [
425
-            // generated from the addon name, changes something like "calendar" to "EE_Calendar"
426
-            'class_name'            => $class_name,
427
-            // the addon slug for use in URLs, etc
428
-            'plugin_slug'           => isset($setup_args['plugin_slug'])
429
-                ? (string) $setup_args['plugin_slug']
430
-                : '',
431
-            // page slug to be used when generating the "Settings" link on the WP plugin page
432
-            'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
433
-                ? (string) $setup_args['plugin_action_slug']
434
-                : '',
435
-            // the "software" version for the addon
436
-            'version'               => isset($setup_args['version'])
437
-                ? (string) $setup_args['version']
438
-                : '',
439
-            // the minimum version of EE Core that the addon will work with
440
-            'min_core_version'      => isset($setup_args['min_core_version'])
441
-                ? (string) $setup_args['min_core_version']
442
-                : '',
443
-            // the minimum version of WordPress that the addon will work with
444
-            'min_wp_version'        => isset($setup_args['min_wp_version'])
445
-                ? (string) $setup_args['min_wp_version']
446
-                : EE_MIN_WP_VER_REQUIRED,
447
-            // full server path to main file (file loaded directly by WP)
448
-            'main_file_path'        => isset($setup_args['main_file_path'])
449
-                ? (string) $setup_args['main_file_path']
450
-                : '',
451
-            // instance of \EventEspresso\core\domain\DomainInterface
452
-            'domain'                => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface
453
-                ? $setup_args['domain']
454
-                : null,
455
-            // Fully Qualified Class Name for the addon's Domain class
456
-            'domain_fqcn'           => isset($setup_args['domain_fqcn'])
457
-                ? (string) $setup_args['domain_fqcn']
458
-                : '',
459
-            // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
460
-            'admin_path'            => isset($setup_args['admin_path'])
461
-                ? (string) $setup_args['admin_path'] : '',
462
-            // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
463
-            'admin_callback'        => isset($setup_args['admin_callback'])
464
-                ? (string) $setup_args['admin_callback']
465
-                : '',
466
-            // the section name for this addon's configuration settings section (defaults to "addons")
467
-            'config_section'        => isset($setup_args['config_section'])
468
-                ? (string) $setup_args['config_section']
469
-                : 'addons',
470
-            // the class name for this addon's configuration settings object
471
-            'config_class'          => isset($setup_args['config_class'])
472
-                ? (string) $setup_args['config_class'] : '',
473
-            // the name given to the config for this addons' configuration settings object (optional)
474
-            'config_name'           => isset($setup_args['config_name'])
475
-                ? (string) $setup_args['config_name'] : '',
476
-            // an array of "class names" => "full server paths" for any classes that might be invoked by the addon
477
-            'autoloader_paths'      => isset($setup_args['autoloader_paths'])
478
-                ? (array) $setup_args['autoloader_paths']
479
-                : [],
480
-            // an array of  "full server paths" for any folders containing classes that might be invoked by the addon
481
-            'autoloader_folders'    => isset($setup_args['autoloader_folders'])
482
-                ? (array) $setup_args['autoloader_folders']
483
-                : [],
484
-            // array of full server paths to any EE_DMS data migration scripts used by the addon.
485
-            // The key should be the EE_Addon class name that this set of data migration scripts belongs to.
486
-            // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name
487
-            'dms_paths'             => isset($setup_args['dms_paths'])
488
-                ? (array) $setup_args['dms_paths']
489
-                : [],
490
-            // array of full server paths to any EED_Modules used by the addon
491
-            'module_paths'          => isset($setup_args['module_paths'])
492
-                ? (array) $setup_args['module_paths']
493
-                : [],
494
-            // array of full server paths to any EES_Shortcodes used by the addon
495
-            'shortcode_paths'       => isset($setup_args['shortcode_paths'])
496
-                ? (array) $setup_args['shortcode_paths']
497
-                : [],
498
-            'shortcode_fqcns'       => isset($setup_args['shortcode_fqcns'])
499
-                ? (array) $setup_args['shortcode_fqcns']
500
-                : [],
501
-            // array of full server paths to any WP_Widgets used by the addon
502
-            'widget_paths'          => isset($setup_args['widget_paths'])
503
-                ? (array) $setup_args['widget_paths']
504
-                : [],
505
-            'message_types'         => isset($setup_args['message_types'])
506
-                ? (array) $setup_args['message_types']
507
-                : [],
508
-            'capabilities'          => isset($setup_args['capabilities'])
509
-                ? (array) $setup_args['capabilities']
510
-                : [],
511
-            'capability_maps'       => isset($setup_args['capability_maps'])
512
-                ? (array) $setup_args['capability_maps']
513
-                : [],
514
-            'model_paths'           => isset($setup_args['model_paths'])
515
-                ? (array) $setup_args['model_paths']
516
-                : [],
517
-            'class_paths'           => isset($setup_args['class_paths'])
518
-                ? (array) $setup_args['class_paths']
519
-                : [],
520
-            'model_extension_paths' => isset($setup_args['model_extension_paths'])
521
-                ? (array) $setup_args['model_extension_paths']
522
-                : [],
523
-            'class_extension_paths' => isset($setup_args['class_extension_paths'])
524
-                ? (array) $setup_args['class_extension_paths']
525
-                : [],
526
-            'custom_post_types'     => isset($setup_args['custom_post_types'])
527
-                ? (array) $setup_args['custom_post_types']
528
-                : [],
529
-            'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
530
-                ? (array) $setup_args['custom_taxonomies']
531
-                : [],
532
-            'payment_method_paths'  => isset($setup_args['payment_method_paths'])
533
-                ? (array) $setup_args['payment_method_paths']
534
-                : [],
535
-            'default_terms'         => isset($setup_args['default_terms'])
536
-                ? (array) $setup_args['default_terms']
537
-                : [],
538
-            // if not empty, inserts a new table row after this plugin's row on the WP Plugins page
539
-            // that can be used for adding upgrading/marketing info
540
-            'plugins_page_row'      => isset($setup_args['plugins_page_row'])
541
-                ? (array) $setup_args['plugins_page_row']
542
-                : [],
543
-            'namespace'             => isset(
544
-                $setup_args['namespace']['FQNS'],
545
-                $setup_args['namespace']['DIR']
546
-            )
547
-                ? (array) $setup_args['namespace']
548
-                : [],
549
-            'privacy_policies'      => isset($setup_args['privacy_policies'])
550
-                ? (array) $setup_args['privacy_policies']
551
-                : '',
552
-        ];
553
-        // if plugin_action_slug is NOT set, but an admin page path IS set,
554
-        // then let's just use the plugin_slug since that will be used for linking to the admin page
555
-        $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
556
-                                                && ! empty($addon_settings['admin_path'])
557
-            ? $addon_settings['plugin_slug']
558
-            : $addon_settings['plugin_action_slug'];
559
-        // full server path to main file (file loaded directly by WP)
560
-        $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
561
-        return $addon_settings;
562
-    }
563
-
564
-
565
-    /**
566
-     * @param string $addon_name
567
-     * @param array  $addon_settings
568
-     * @return bool
569
-     */
570
-    private static function _addon_is_compatible(string $addon_name, array $addon_settings): bool
571
-    {
572
-        global $wp_version;
573
-        $incompatibility_message = '';
574
-        // check whether this addon version is compatible with EE core
575
-        if (
576
-            isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
577
-            && ! self::_meets_min_core_version_requirement(
578
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
579
-                $addon_settings['version']
580
-            )
581
-        ) {
582
-            $incompatibility_message = sprintf(
583
-                esc_html__(
584
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.',
585
-                    'event_espresso'
586
-                ),
587
-                $addon_name,
588
-                '<br />',
589
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
590
-                '<span style="font-weight: bold; color: #D54E21;">',
591
-                '</span><br />'
592
-            );
593
-        } elseif (
594
-            ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
595
-        ) {
596
-            $incompatibility_message = sprintf(
597
-                esc_html__(
598
-                    '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
599
-                    'event_espresso'
600
-                ),
601
-                $addon_name,
602
-                self::_effective_version($addon_settings['min_core_version']),
603
-                self::_effective_version(espresso_version()),
604
-                '<br />',
605
-                '<span style="font-weight: bold; color: #D54E21;">',
606
-                '</span><br />'
607
-            );
608
-        } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
609
-            $incompatibility_message = sprintf(
610
-                esc_html__(
611
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
612
-                    'event_espresso'
613
-                ),
614
-                $addon_name,
615
-                $addon_settings['min_wp_version'],
616
-                '<br />',
617
-                '<span style="font-weight: bold; color: #D54E21;">',
618
-                '</span><br />'
619
-            );
620
-        }
621
-        if (! empty($incompatibility_message)) {
622
-            // remove 'activate' from the REQUEST
623
-            // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
624
-            /** @var RequestInterface $request */
625
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
626
-            $request->unSetRequestParam('activate', true);
627
-            if (current_user_can('activate_plugins')) {
628
-                // show an error message indicating the plugin didn't activate properly
629
-                EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
630
-            }
631
-            unset($_GET['activate'], $_REQUEST['activate']);
632
-            if (! function_exists('deactivate_plugins')) {
633
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
634
-            }
635
-            deactivate_plugins(plugin_basename($addon_settings['main_file_path']));
636
-            // BAIL FROM THE ADDON REGISTRATION PROCESS
637
-            return false;
638
-        }
639
-        // addon IS compatible
640
-        return true;
641
-    }
642
-
643
-
644
-    /**
645
-     * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
646
-     *
647
-     * @param array $addon_settings
648
-     * @return void
649
-     */
650
-    private static function _setup_namespaces(array $addon_settings)
651
-    {
652
-        //
653
-        if (
654
-            isset(
655
-                $addon_settings['namespace']['FQNS'],
656
-                $addon_settings['namespace']['DIR']
657
-            )
658
-        ) {
659
-            EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
660
-                $addon_settings['namespace']['FQNS'],
661
-                $addon_settings['namespace']['DIR']
662
-            );
663
-        }
664
-    }
665
-
666
-
667
-    /**
668
-     * @param string $addon_name
669
-     * @param array  $addon_settings
670
-     * @return bool
671
-     * @throws InvalidArgumentException
672
-     * @throws InvalidDataTypeException
673
-     * @throws InvalidInterfaceException
674
-     */
675
-    private static function _addon_activation(string $addon_name, array $addon_settings): bool
676
-    {
677
-        // this is an activation request
678
-        if (did_action('activate_plugin')) {
679
-            // to find if THIS is the addon that was activated, just check if we have already registered it or not
680
-            // (as the newly-activated addon wasn't around the first time addons were registered).
681
-            // Note: the presence of pue_options in the addon registration options will initialize the $_settings
682
-            // property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
683
-            if (
684
-                ! isset(self::$_settings[ $addon_name ])
685
-                || (isset(self::$_settings[ $addon_name ])
686
-                    && ! isset(self::$_settings[ $addon_name ]['class_name'])
687
-                )
688
-            ) {
689
-                self::$_settings[ $addon_name ] = $addon_settings;
690
-                $addon                          = self::_load_and_init_addon_class($addon_name);
691
-                $addon->set_activation_indicator_option();
692
-                // dont bother setting up the rest of the addon.
693
-                // we know it was just activated and the request will end soon
694
-            }
695
-            return true;
696
-        }
697
-        // make sure addon settings are set correctly without overwriting anything existing
698
-        if (isset(self::$_settings[ $addon_name ])) {
699
-            self::$_settings[ $addon_name ] += $addon_settings;
700
-        } else {
701
-            self::$_settings[ $addon_name ] = $addon_settings;
702
-        }
703
-        return false;
704
-    }
705
-
706
-
707
-    /**
708
-     * @param string $addon_name
709
-     * @return void
710
-     * @throws EE_Error
711
-     */
712
-    private static function _setup_autoloaders(string $addon_name)
713
-    {
714
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
715
-            // setup autoloader for single file
716
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
717
-        }
718
-        // setup autoloaders for folders
719
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
720
-            foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
721
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
722
-            }
723
-        }
724
-    }
725
-
726
-
727
-    /**
728
-     * register new models and extensions
729
-     *
730
-     * @param string $addon_name
731
-     * @return void
732
-     * @throws EE_Error
733
-     */
734
-    private static function _register_models_and_extensions(string $addon_name)
735
-    {
736
-        // register new models
737
-        if (
738
-            ! empty(self::$_settings[ $addon_name ]['model_paths'])
739
-            || ! empty(self::$_settings[ $addon_name ]['class_paths'])
740
-        ) {
741
-            EE_Register_Model::register(
742
-                $addon_name,
743
-                [
744
-                    'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
745
-                    'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
746
-                ]
747
-            );
748
-        }
749
-        // register model extensions
750
-        if (
751
-            ! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
752
-            || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
753
-        ) {
754
-            EE_Register_Model_Extensions::register(
755
-                $addon_name,
756
-                [
757
-                    'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
758
-                    'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
759
-                ]
760
-            );
761
-        }
762
-    }
763
-
764
-
765
-    /**
766
-     * @param string $addon_name
767
-     * @return void
768
-     * @throws EE_Error
769
-     */
770
-    private static function _register_data_migration_scripts(string $addon_name)
771
-    {
772
-        // setup DMS
773
-        if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
774
-            EE_Register_Data_Migration_Scripts::register(
775
-                $addon_name,
776
-                ['dms_paths' => self::$_settings[ $addon_name ]['dms_paths']]
777
-            );
778
-        }
779
-    }
780
-
781
-
782
-    /**
783
-     * @param string $addon_name
784
-     * @return void
785
-     * @throws EE_Error
786
-     */
787
-    private static function _register_config(string $addon_name)
788
-    {
789
-        // if config_class is present let's register config.
790
-        if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
791
-            EE_Register_Config::register(
792
-                self::$_settings[ $addon_name ]['config_class'],
793
-                [
794
-                    'config_section' => self::$_settings[ $addon_name ]['config_section'],
795
-                    'config_name'    => self::$_settings[ $addon_name ]['config_name'],
796
-                ]
797
-            );
798
-        }
799
-    }
800
-
801
-
802
-    /**
803
-     * @param string $addon_name
804
-     * @return void
805
-     * @throws EE_Error
806
-     */
807
-    private static function _register_admin_pages(string $addon_name)
808
-    {
809
-        if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
810
-            EE_Register_Admin_Page::register(
811
-                $addon_name,
812
-                ['page_path' => self::$_settings[ $addon_name ]['admin_path']]
813
-            );
814
-        }
815
-    }
816
-
817
-
818
-    /**
819
-     * @param string $addon_name
820
-     * @return void
821
-     * @throws EE_Error
822
-     */
823
-    private static function _register_modules(string $addon_name)
824
-    {
825
-        if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
826
-            EE_Register_Module::register(
827
-                $addon_name,
828
-                ['module_paths' => self::$_settings[ $addon_name ]['module_paths']]
829
-            );
830
-        }
831
-    }
832
-
833
-
834
-    /**
835
-     * @param string $addon_name
836
-     * @return void
837
-     * @throws EE_Error
838
-     */
839
-    private static function _register_shortcodes(string $addon_name)
840
-    {
841
-        if (
842
-            ! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
843
-            || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
844
-        ) {
845
-            EE_Register_Shortcode::register(
846
-                $addon_name,
847
-                [
848
-                    'shortcode_paths' => self::$_settings[ $addon_name ]['shortcode_paths'] ?? [],
849
-                    'shortcode_fqcns' => self::$_settings[ $addon_name ]['shortcode_fqcns'] ?? [],
850
-                ]
851
-            );
852
-        }
853
-    }
854
-
855
-
856
-    /**
857
-     * @param string $addon_name
858
-     * @return void
859
-     * @throws EE_Error
860
-     */
861
-    private static function _register_widgets(string $addon_name)
862
-    {
863
-        if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
864
-            EE_Register_Widget::register(
865
-                $addon_name,
866
-                ['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']]
867
-            );
868
-        }
869
-    }
870
-
871
-
872
-    /**
873
-     * @param string $addon_name
874
-     * @return void
875
-     * @throws EE_Error
876
-     */
877
-    private static function _register_capabilities(string $addon_name)
878
-    {
879
-        if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
880
-            EE_Register_Capabilities::register(
881
-                $addon_name,
882
-                [
883
-                    'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
884
-                    'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
885
-                ]
886
-            );
887
-        }
888
-    }
889
-
890
-
891
-    /**
892
-     * @param string $addon_name
893
-     * @return void
894
-     */
895
-    private static function _register_message_types(string $addon_name)
896
-    {
897
-        if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
898
-            add_action(
899
-                'EE_Brewing_Regular___messages_caf',
900
-                ['EE_Register_Addon', 'register_message_types']
901
-            );
902
-        }
903
-    }
904
-
905
-
906
-    /**
907
-     * @param string $addon_name
908
-     * @return void
909
-     * @throws EE_Error
910
-     */
911
-    private static function _register_custom_post_types(string $addon_name)
912
-    {
913
-        if (
914
-            ! empty(self::$_settings[ $addon_name ]['custom_post_types'])
915
-            || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
916
-        ) {
917
-            EE_Register_CPT::register(
918
-                $addon_name,
919
-                [
920
-                    'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
921
-                    'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
922
-                    'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
923
-                ]
924
-            );
925
-        }
926
-    }
927
-
928
-
929
-    /**
930
-     * @param string $addon_name
931
-     * @return void
932
-     * @throws InvalidArgumentException
933
-     * @throws InvalidInterfaceException
934
-     * @throws InvalidDataTypeException
935
-     * @throws DomainException
936
-     * @throws EE_Error
937
-     */
938
-    private static function _register_payment_methods(string $addon_name)
939
-    {
940
-        if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
941
-            EE_Register_Payment_Method::register(
942
-                $addon_name,
943
-                ['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']]
944
-            );
945
-        }
946
-    }
947
-
948
-
949
-    /**
950
-     * @param string $addon_name
951
-     * @return void
952
-     * @throws InvalidArgumentException
953
-     * @throws InvalidInterfaceException
954
-     * @throws InvalidDataTypeException
955
-     * @throws DomainException
956
-     */
957
-    private static function registerPrivacyPolicies(string $addon_name)
958
-    {
959
-        if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
960
-            EE_Register_Privacy_Policy::register(
961
-                $addon_name,
962
-                self::$_settings[ $addon_name ]['privacy_policies']
963
-            );
964
-        }
965
-    }
966
-
967
-
968
-    /**
969
-     * @param string $addon_name
970
-     * @return void
971
-     */
972
-    private static function registerPersonalDataExporters(string $addon_name)
973
-    {
974
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
975
-            EE_Register_Personal_Data_Eraser::register(
976
-                $addon_name,
977
-                self::$_settings[ $addon_name ]['personal_data_exporters']
978
-            );
979
-        }
980
-    }
981
-
982
-
983
-    /**
984
-     * @param string $addon_name
985
-     * @return void
986
-     */
987
-    private static function registerPersonalDataErasers(string $addon_name)
988
-    {
989
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
990
-            EE_Register_Personal_Data_Eraser::register(
991
-                $addon_name,
992
-                self::$_settings[ $addon_name ]['personal_data_erasers']
993
-            );
994
-        }
995
-    }
996
-
997
-
998
-    /**
999
-     * Loads and instantiates the EE_Addon class and adds it onto the registry
1000
-     *
1001
-     * @param string $addon_name
1002
-     * @return EE_Addon
1003
-     * @throws InvalidArgumentException
1004
-     * @throws InvalidInterfaceException
1005
-     * @throws InvalidDataTypeException
1006
-     */
1007
-    private static function _load_and_init_addon_class(string $addon_name): EE_Addon
1008
-    {
1009
-        $addon = self::$loader->getShared(
1010
-            self::$_settings[ $addon_name ]['class_name'],
1011
-            ['EE_Registry::create(addon)' => true]
1012
-        );
1013
-        if (! $addon instanceof EE_Addon) {
1014
-            throw new DomainException(
1015
-                sprintf(
1016
-                    esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'),
1017
-                    self::$_settings[ $addon_name ]['class_name']
1018
-                )
1019
-            );
1020
-        }
1021
-        // setter inject dep map if required
1022
-        if ($addon->dependencyMap() === null) {
1023
-            $addon->setDependencyMap(self::$loader->getShared('EE_Dependency_Map'));
1024
-        }
1025
-        // setter inject domain if required
1026
-        EE_Register_Addon::injectAddonDomain($addon_name, $addon);
1027
-
1028
-        $addon->set_name($addon_name);
1029
-        $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1030
-        $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1031
-        $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1032
-        $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1033
-        $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1034
-        $addon->set_version(self::$_settings[ $addon_name ]['version']);
1035
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1036
-        $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1037
-        $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1038
-        $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1039
-        do_action(
1040
-            'AHEE__EE_Register_Addon___load_and_init_addon_class',
1041
-            $addon,
1042
-            $addon_name,
1043
-            self::$_settings
1044
-        );
1045
-        // unfortunately this can't be hooked in upon construction,
1046
-        // because we don't have the plugin's mainfile path upon construction.
1047
-        register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']);
1048
-        // call any additional admin_callback functions during load_admin_controller hook
1049
-        if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1050
-            add_action(
1051
-                'AHEE__EE_System__load_controllers__load_admin_controllers',
1052
-                [$addon, self::$_settings[ $addon_name ]['admin_callback']]
1053
-            );
1054
-        }
1055
-        return $addon;
1056
-    }
1057
-
1058
-
1059
-    /**
1060
-     * @param string   $addon_name
1061
-     * @param EE_Addon $addon
1062
-     * @since   4.10.13.p
1063
-     */
1064
-    private static function injectAddonDomain(string $addon_name, EE_Addon $addon)
1065
-    {
1066
-        if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) {
1067
-            // using supplied Domain object
1068
-            $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1069
-                ? self::$_settings[ $addon_name ]['domain']
1070
-                : null;
1071
-            // or construct one using Domain FQCN
1072
-            if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1073
-                $domain = self::$loader->getShared(
1074
-                    self::$_settings[ $addon_name ]['domain_fqcn'],
1075
-                    [
1076
-                        new EventEspresso\core\domain\values\FilePath(
1077
-                            self::$_settings[ $addon_name ]['main_file_path']
1078
-                        ),
1079
-                        EventEspresso\core\domain\values\Version::fromString(
1080
-                            self::$_settings[ $addon_name ]['version']
1081
-                        ),
1082
-                    ]
1083
-                );
1084
-            }
1085
-            if ($domain instanceof DomainInterface) {
1086
-                $addon->setDomain($domain);
1087
-            }
1088
-        }
1089
-    }
1090
-
1091
-
1092
-    /**
1093
-     * @return void
1094
-     * @deprecated 5.0.0.p
1095
-     */
1096
-    public static function load_pue_update()
1097
-    {
1098
-        RegisterAddonPUE::loadPueUpdate();
1099
-    }
1100
-
1101
-
1102
-    /**
1103
-     * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
1104
-     *
1105
-     * @return void
1106
-     * @throws EE_Error
1107
-     * @since 4.4.0
1108
-     */
1109
-    public static function register_message_types()
1110
-    {
1111
-        foreach (self::$_settings as $settings) {
1112
-            if (! empty($settings['message_types'])) {
1113
-                foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1114
-                    EE_Register_Message_Type::register($message_type, $message_type_settings);
1115
-                }
1116
-            }
1117
-        }
1118
-    }
1119
-
1120
-
1121
-    /**
1122
-     * This deregisters an addon that was previously registered with a specific addon_name.
1123
-     *
1124
-     * @param string $addon_name the name for the addon that was previously registered
1125
-     * @throws DomainException
1126
-     * @throws InvalidArgumentException
1127
-     * @throws InvalidDataTypeException
1128
-     * @throws InvalidInterfaceException
1129
-     * @since    4.3.0
1130
-     */
1131
-    public static function deregister(string $addon_name = '')
1132
-    {
1133
-        if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1134
-            try {
1135
-                do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1136
-                $class_name = self::$_settings[ $addon_name ]['class_name'];
1137
-                if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1138
-                    // setup DMS
1139
-                    EE_Register_Data_Migration_Scripts::deregister($addon_name);
1140
-                }
1141
-                if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1142
-                    // register admin page
1143
-                    EE_Register_Admin_Page::deregister($addon_name);
1144
-                }
1145
-                if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1146
-                    // add to list of modules to be registered
1147
-                    EE_Register_Module::deregister($addon_name);
1148
-                }
1149
-                if (
1150
-                    ! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1151
-                    || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1152
-                ) {
1153
-                    // add to list of shortcodes to be registered
1154
-                    EE_Register_Shortcode::deregister($addon_name);
1155
-                }
1156
-                if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1157
-                    // if config_class present let's register config.
1158
-                    EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1159
-                }
1160
-                if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1161
-                    // add to list of widgets to be registered
1162
-                    EE_Register_Widget::deregister($addon_name);
1163
-                }
1164
-                if (
1165
-                    ! empty(self::$_settings[ $addon_name ]['model_paths'])
1166
-                    || ! empty(self::$_settings[ $addon_name ]['class_paths'])
1167
-                ) {
1168
-                    // add to list of shortcodes to be registered
1169
-                    EE_Register_Model::deregister($addon_name);
1170
-                }
1171
-                if (
1172
-                    ! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1173
-                    || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1174
-                ) {
1175
-                    // add to list of shortcodes to be registered
1176
-                    EE_Register_Model_Extensions::deregister($addon_name);
1177
-                }
1178
-                if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1179
-                    foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1180
-                        EE_Register_Message_Type::deregister($message_type);
1181
-                    }
1182
-                }
1183
-                // deregister capabilities for addon
1184
-                if (
1185
-                    ! empty(self::$_settings[ $addon_name ]['capabilities'])
1186
-                    || ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1187
-                ) {
1188
-                    EE_Register_Capabilities::deregister($addon_name);
1189
-                }
1190
-                // deregister custom_post_types for addon
1191
-                if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1192
-                    EE_Register_CPT::deregister($addon_name);
1193
-                }
1194
-                if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1195
-                    EE_Register_Payment_Method::deregister($addon_name);
1196
-                }
1197
-                $addon = EE_Registry::instance()->getAddon($class_name);
1198
-                if ($addon instanceof EE_Addon) {
1199
-                    remove_action(
1200
-                        'deactivate_' . $addon->get_main_plugin_file_basename(),
1201
-                        [$addon, 'deactivation']
1202
-                    );
1203
-                    remove_action(
1204
-                        'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1205
-                        [$addon, 'initialize_db_if_no_migrations_required']
1206
-                    );
1207
-                    // remove `after_registration` call
1208
-                    remove_action(
1209
-                        'AHEE__EE_System__load_espresso_addons__complete',
1210
-                        [$addon, 'after_registration'],
1211
-                        999
1212
-                    );
1213
-                }
1214
-                EE_Registry::instance()->removeAddon($class_name);
1215
-                LoaderFactory::getLoader()->remove($class_name);
1216
-            } catch (OutOfBoundsException $addon_not_yet_registered_exception) {
1217
-                // the add-on was not yet registered in the registry,
1218
-                // so RegistryContainer::__get() throws this exception.
1219
-                // also no need to worry about this or log it,
1220
-                // it's ok to deregister an add-on before its registered in the registry
1221
-            } catch (Exception $e) {
1222
-                new ExceptionLogger($e);
1223
-            }
1224
-            unset(self::$_settings[ $addon_name ]);
1225
-            do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1226
-        }
1227
-    }
27
+	/**
28
+	 * possibly truncated version of the EE core version string
29
+	 *
30
+	 * @var string
31
+	 */
32
+	protected static $_core_version = '';
33
+
34
+	/**
35
+	 * Holds values for registered addons
36
+	 *
37
+	 * @var array
38
+	 */
39
+	protected static $_settings = [];
40
+
41
+	/**
42
+	 * @var  array $_incompatible_addons keys are addon SLUGS
43
+	 * (first argument passed to EE_Register_Addon::register()), keys are
44
+	 * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
45
+	 * Generally this should be used sparingly, as we don't want to muddle up
46
+	 * EE core with knowledge of ALL the addons out there.
47
+	 * If you want NO versions of an addon to run with a certain version of core,
48
+	 * it's usually best to define the addon's "min_core_version" as part of its call
49
+	 * to EE_Register_Addon::register(), rather than using this array with a super high value for its
50
+	 * minimum plugin version.
51
+	 * @access    protected
52
+	 */
53
+	protected static $_incompatible_addons = [
54
+		'Multi_Event_Registration' => '2.0.11.rc.002',
55
+		'Promotions'               => '1.0.0.rc.084',
56
+	];
57
+
58
+	/**
59
+	 * @var LoaderInterface
60
+	 */
61
+	protected static $loader;
62
+
63
+
64
+	/**
65
+	 * We should always be comparing core to a version like '4.3.0.rc.000',
66
+	 * not just '4.3.0'.
67
+	 * So if the addon developer doesn't provide that full version string,
68
+	 * fill in the blanks for them
69
+	 *
70
+	 * @param string $min_core_version
71
+	 * @return string always like '4.3.0.rc.000'
72
+	 */
73
+	protected static function _effective_version(string $min_core_version): string
74
+	{
75
+		// versions: 4 . 3 . 1 . p . 123
76
+		// offsets:    0 . 1 . 2 . 3 . 4
77
+		$version_parts = explode('.', $min_core_version);
78
+		// check they specified the micro version (after 2nd period)
79
+		if (! isset($version_parts[2])) {
80
+			$version_parts[2] = '0';
81
+		}
82
+		// if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
83
+		// soon we can assume that's 'rc', but this current version is 'alpha'
84
+		if (! isset($version_parts[3])) {
85
+			$version_parts[3] = 'dev';
86
+		}
87
+		if (! isset($version_parts[4])) {
88
+			$version_parts[4] = '000';
89
+		}
90
+		return implode('.', $version_parts);
91
+	}
92
+
93
+
94
+	/**
95
+	 * Returns whether or not the min core version requirement of the addon is met
96
+	 *
97
+	 * @param string $min_core_version    the minimum core version required by the addon
98
+	 * @param string $actual_core_version the actual core version, optional
99
+	 * @return bool
100
+	 */
101
+	public static function _meets_min_core_version_requirement(
102
+		string $min_core_version,
103
+		string $actual_core_version = EVENT_ESPRESSO_VERSION
104
+	): bool {
105
+		return version_compare(
106
+			self::_effective_version($actual_core_version),
107
+			self::_effective_version($min_core_version),
108
+			'>='
109
+		);
110
+	}
111
+
112
+
113
+	/**
114
+	 * Method for registering new EE_Addons.
115
+	 * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
116
+	 * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
117
+	 * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
118
+	 * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
119
+	 * 'activate_plugin', it registers the addon still, but its components are not registered
120
+	 * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
121
+	 * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
122
+	 * (so that we can detect that the addon has activated on the subsequent request)
123
+	 *
124
+	 * @param string                  $addon_name                       [Required] the EE_Addon's name.
125
+	 * @param array                   $setup_args                       {
126
+	 *                                                                  An array of arguments provided for registering
127
+	 *                                                                  the message type.
128
+	 * @type  string                  $class_name                       the addon's main file name.
129
+	 *                                                                  If left blank, generated from the addon name,
130
+	 *                                                                  changes something like "calendar" to
131
+	 *                                                                  "EE_Calendar"
132
+	 * @type string                   $min_core_version                 the minimum version of EE Core that the
133
+	 *                                                                  addon will work with. eg "4.8.1.rc.084"
134
+	 * @type string                   $version                          the "software" version for the addon. eg
135
+	 *                                                                  "1.0.0.p" for a first stable release, or
136
+	 *                                                                  "1.0.0.rc.043" for a version in progress
137
+	 * @type string                   $main_file_path                   the full server path to the main file
138
+	 *                                                                  loaded directly by WP
139
+	 * @type DomainInterface          $domain                           child class of
140
+	 *                                                                  EventEspresso\core\domain\DomainBase
141
+	 * @type string                   $domain_fqcn                      Fully Qualified Class Name
142
+	 *                                                                  for the addon's Domain class
143
+	 *                                                                  (see EventEspresso\core\domain\Domain)
144
+	 * @type string                   $admin_path                       full server path to the folder where the
145
+	 *                                                                  addon\'s admin files reside
146
+	 * @type string                   $admin_callback                   a method to be called when the EE Admin is
147
+	 *                                                                  first invoked, can be used for hooking into
148
+	 *                                                                  any admin page
149
+	 * @type string                   $config_section                   the section name for this addon's
150
+	 *                                                                  configuration settings section
151
+	 *                                                                  (defaults to "addons")
152
+	 * @type string                   $config_class                     the class name for this addon's
153
+	 *                                                                  configuration settings object
154
+	 * @type string                   $config_name                      the class name for this addon's
155
+	 *                                                                  configuration settings object
156
+	 * @type string                   $autoloader_paths                 [Required] an array of class names and the full
157
+	 *                                                                  server paths to those files.
158
+	 * @type string                   $autoloader_folders               an array of  "full server paths" for any
159
+	 *                                                                  folders containing classes that might be
160
+	 *                                                                  invoked by the addon
161
+	 * @type string                   $dms_paths                        [Required] an array of full server paths to
162
+	 *                                                                  folders that contain data migration scripts.
163
+	 *                                                                  The key should be the EE_Addon class name that
164
+	 *                                                                  this set of data migration scripts belongs to.
165
+	 *                                                                  If the EE_Addon class is namespaced, then this
166
+	 *                                                                  needs to be the Fully Qualified Class Name
167
+	 * @type string                   $module_paths                     an array of full server paths to any
168
+	 *                                                                  EED_Modules used by the addon
169
+	 * @type string                   $shortcode_paths                  an array of full server paths to folders
170
+	 *                                                                  that contain EES_Shortcodes
171
+	 * @type string                   $widget_paths                     an array of full server paths to folders
172
+	 *                                                                  that contain WP_Widgets
173
+	 * @type array                    $capabilities                     an array indexed by role name
174
+	 *                                                                  (i.e administrator,author ) and the values
175
+	 *                                                                  are an array of caps to add to the role.
176
+	 *                                                                  'administrator' => array(
177
+	 *                                                                  'read_addon',
178
+	 *                                                                  'edit_addon',
179
+	 *                                                                  etc.
180
+	 *                                                                  ).
181
+	 * @type EE_Meta_Capability_Map[] $capability_maps                  an array of EE_Meta_Capability_Map object
182
+	 *                                                                  for any addons that need to register any
183
+	 *                                                                  special meta mapped capabilities.  Should
184
+	 *                                                                  be indexed where the key is the
185
+	 *                                                                  EE_Meta_Capability_Map class name and the
186
+	 *                                                                  values are the arguments sent to the class.
187
+	 * @type array                    $model_paths                      array of folders containing DB models
188
+	 * @return bool
189
+	 * @throws DomainException
190
+	 * @throws EE_Error
191
+	 * @throws InvalidArgumentException
192
+	 * @throws InvalidDataTypeException
193
+	 * @throws InvalidInterfaceException
194
+	 * @since                                                           4.3.0
195
+	 * @see                                                             EE_Register_Model
196
+	 * @type array                    $class_paths                      array of folders containing DB classes
197
+	 * @see                                                             EE_Register_Model
198
+	 * @type array                    $model_extension_paths            array of folders containing DB model
199
+	 *                                                                  extensions
200
+	 * @see                                                             EE_Register_Model_Extension
201
+	 * @type array                    $class_extension_paths            array of folders containing DB class
202
+	 *                                                                  extensions
203
+	 * @see                                                             EE_Register_Model_Extension
204
+	 * @type array message_types {
205
+	 *                                                                  An array of message types with the key as
206
+	 *                                                                  the message type name and the values as
207
+	 *                                                                  below:
208
+	 * @type string                   $mtfilename                       [Required] The filename of the message type
209
+	 *                                                                  being registered. This will be the main
210
+	 *                                                                  EE_{Message Type Name}_message_type class.
211
+	 *                                                                  for example:
212
+	 *                                                                  EE_Declined_Registration_message_type.class.php
213
+	 * @type array                    $autoloadpaths                    [Required] An array of paths to add to the
214
+	 *                                                                  messages autoloader for the new message type.
215
+	 * @type array                    $messengers_to_activate_with      An array of messengers that this message
216
+	 *                                                                  type should activate with. Each value in
217
+	 *                                                                  the
218
+	 *                                                                  array
219
+	 *                                                                  should match the name property of a
220
+	 *                                                                  EE_messenger. Optional.
221
+	 * @type array                    $messengers_to_validate_with      An array of messengers that this message
222
+	 *                                                                  type should validate with. Each value in
223
+	 *                                                                  the
224
+	 *                                                                  array
225
+	 *                                                                  should match the name property of an
226
+	 *                                                                  EE_messenger.
227
+	 *                                                                  Optional.
228
+	 *                                                                  }
229
+	 * @type array                    $custom_post_types
230
+	 * @type array                    $custom_taxonomies
231
+	 * @type array                    $payment_method_paths             each element is the folder containing the
232
+	 *                                                                  EE_PMT_Base child class
233
+	 *                                                                  (eg,
234
+	 *                                                                  '/wp-content/plugins/my_plugin/Payomatic/'
235
+	 *                                                                  which contains the files
236
+	 *                                                                  EE_PMT_Payomatic.pm.php)
237
+	 * @type array                    $default_terms
238
+	 * @type array                    $namespace                        {
239
+	 *                                                                  An array with two items for registering the
240
+	 *                                                                  addon's namespace. (If, for some reason, you
241
+	 *                                                                  require additional namespaces,
242
+	 *                                                                  use
243
+	 *                                                                  EventEspresso\core\Psr4Autoloader::addNamespace()
244
+	 *                                                                  directly)
245
+	 * @see                                                             EventEspresso\core\Psr4Autoloader::addNamespace()
246
+	 * @type string                   $FQNS                             the namespace prefix
247
+	 * @type string                   $DIR                              a base directory for class files in the
248
+	 *                                                                  namespace.
249
+	 *                                                                  }
250
+	 *                                                                  }
251
+	 * @type string                   $privacy_policies                 FQNSs (namespaces, each of which contains only
252
+	 *                                                                  privacy policy classes) or FQCNs (specific
253
+	 *                                                                  classnames of privacy policy classes)
254
+	 * @type string                   $personal_data_exporters          FQNSs (namespaces, each of which contains only
255
+	 *                                                                  privacy policy classes) or FQCNs (specific
256
+	 *                                                                  classnames of privacy policy classes)
257
+	 * @type string                   $personal_data_erasers            FQNSs (namespaces, each of which contains only
258
+	 *                                                                  privacy policy classes) or FQCNs (specific
259
+	 *                                                                  classnames of privacy policy classes)
260
+	 */
261
+	public static function register(string $addon_name = '', array $setup_args = []): bool
262
+	{
263
+		if (! self::$loader instanceof LoaderInterface) {
264
+			self::$loader = LoaderFactory::getLoader();
265
+		}
266
+		// make sure this was called in the right place!
267
+		if (
268
+			! did_action('activate_plugin')
269
+			&& (
270
+				! did_action('AHEE__EE_System__load_espresso_addons')
271
+				|| did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
272
+			)
273
+		) {
274
+			EE_Error::doing_it_wrong(
275
+				__METHOD__,
276
+				sprintf(
277
+					esc_html__(
278
+						'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
279
+						'event_espresso'
280
+					),
281
+					$addon_name
282
+				),
283
+				'4.3.0'
284
+			);
285
+			return false;
286
+		}
287
+		// required fields MUST be present, so let's make sure they are.
288
+		EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
289
+		// get class name for addon
290
+		$class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
291
+		// setup $_settings array from incoming values.
292
+		$addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
293
+		// allow early addon setup or modification of addon api settings
294
+		self::$_settings = (array) apply_filters(
295
+			'FHEE__EE_Register_Addon__register',
296
+			self::$_settings,
297
+			$addon_name,
298
+			$class_name,
299
+			$setup_args
300
+		);
301
+		// does this addon work with this version of core or WordPress ?
302
+		// does this addon work with this version of core or WordPress ?
303
+		if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
304
+			return false;
305
+		}
306
+		// register namespaces
307
+		EE_Register_Addon::_setup_namespaces($addon_settings);
308
+		// check if this is an activation request
309
+		if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
310
+			// dont bother setting up the rest of the addon atm
311
+			return false;
312
+		}
313
+		// we need cars
314
+		EE_Register_Addon::_setup_autoloaders($addon_name);
315
+		// register new models and extensions
316
+		EE_Register_Addon::_register_models_and_extensions($addon_name);
317
+		// setup DMS
318
+		EE_Register_Addon::_register_data_migration_scripts($addon_name);
319
+		// if config_class is present let's register config.
320
+		EE_Register_Addon::_register_config($addon_name);
321
+		// register admin pages
322
+		EE_Register_Addon::_register_admin_pages($addon_name);
323
+		// add to list of modules to be registered
324
+		EE_Register_Addon::_register_modules($addon_name);
325
+		// add to list of shortcodes to be registered
326
+		EE_Register_Addon::_register_shortcodes($addon_name);
327
+		// add to list of widgets to be registered
328
+		EE_Register_Addon::_register_widgets($addon_name);
329
+		// register capability related stuff.
330
+		EE_Register_Addon::_register_capabilities($addon_name);
331
+		// any message type to register?
332
+		EE_Register_Addon::_register_message_types($addon_name);
333
+		// any custom post type/ custom capabilities or default terms to register
334
+		EE_Register_Addon::_register_custom_post_types($addon_name);
335
+		// and any payment methods
336
+		EE_Register_Addon::_register_payment_methods($addon_name);
337
+		// and privacy policy generators
338
+		EE_Register_Addon::registerPrivacyPolicies($addon_name);
339
+		// and privacy policy generators
340
+		EE_Register_Addon::registerPersonalDataExporters($addon_name);
341
+		// and privacy policy generators
342
+		EE_Register_Addon::registerPersonalDataErasers($addon_name);
343
+		// load and instantiate main addon class
344
+		$addon = EE_Register_Addon::_load_and_init_addon_class($addon_name);
345
+		// delay calling after_registration hook on each addon until after all add-ons have been registered.
346
+		add_action('AHEE__EE_System__load_espresso_addons__complete', [$addon, 'after_registration'], 999);
347
+		return $addon instanceof EE_Addon;
348
+	}
349
+
350
+
351
+	/**
352
+	 * @param string $addon_name
353
+	 * @param array  $setup_args
354
+	 * @return void
355
+	 * @throws EE_Error
356
+	 */
357
+	private static function _verify_parameters(string $addon_name, array $setup_args)
358
+	{
359
+		// required fields MUST be present, so let's make sure they are.
360
+		if (empty($addon_name) || empty($setup_args)) {
361
+			throw new EE_Error(
362
+				esc_html__(
363
+					'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
364
+					'event_espresso'
365
+				)
366
+			);
367
+		}
368
+		if (empty($setup_args['main_file_path'])) {
369
+			throw new EE_Error(
370
+				sprintf(
371
+					esc_html__(
372
+						'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
373
+						'event_espresso'
374
+					),
375
+					implode(',', array_keys($setup_args))
376
+				)
377
+			);
378
+		}
379
+		// check that addon has not already been registered with that name
380
+		if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
381
+			throw new EE_Error(
382
+				sprintf(
383
+					esc_html__(
384
+						'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
385
+						'event_espresso'
386
+					),
387
+					$addon_name
388
+				)
389
+			);
390
+		}
391
+	}
392
+
393
+
394
+	/**
395
+	 * @param string $addon_name
396
+	 * @param array  $setup_args
397
+	 * @return string
398
+	 */
399
+	private static function _parse_class_name(string $addon_name, array $setup_args): string
400
+	{
401
+		if (empty($setup_args['class_name'])) {
402
+			// generate one by first separating name with spaces
403
+			$class_name = str_replace(['-', '_'], ' ', trim($addon_name));
404
+			// capitalize, then replace spaces with underscores
405
+			$class_name = str_replace(' ', '_', ucwords($class_name));
406
+		} else {
407
+			$class_name = $setup_args['class_name'];
408
+		}
409
+		// check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
410
+		return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
411
+			? $class_name
412
+			: 'EE_' . $class_name;
413
+	}
414
+
415
+
416
+	/**
417
+	 * @param string $class_name
418
+	 * @param array  $setup_args
419
+	 * @return array
420
+	 */
421
+	private static function _get_addon_settings(string $class_name, array $setup_args): array
422
+	{
423
+		// setup $_settings array from incoming values.
424
+		$addon_settings = [
425
+			// generated from the addon name, changes something like "calendar" to "EE_Calendar"
426
+			'class_name'            => $class_name,
427
+			// the addon slug for use in URLs, etc
428
+			'plugin_slug'           => isset($setup_args['plugin_slug'])
429
+				? (string) $setup_args['plugin_slug']
430
+				: '',
431
+			// page slug to be used when generating the "Settings" link on the WP plugin page
432
+			'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
433
+				? (string) $setup_args['plugin_action_slug']
434
+				: '',
435
+			// the "software" version for the addon
436
+			'version'               => isset($setup_args['version'])
437
+				? (string) $setup_args['version']
438
+				: '',
439
+			// the minimum version of EE Core that the addon will work with
440
+			'min_core_version'      => isset($setup_args['min_core_version'])
441
+				? (string) $setup_args['min_core_version']
442
+				: '',
443
+			// the minimum version of WordPress that the addon will work with
444
+			'min_wp_version'        => isset($setup_args['min_wp_version'])
445
+				? (string) $setup_args['min_wp_version']
446
+				: EE_MIN_WP_VER_REQUIRED,
447
+			// full server path to main file (file loaded directly by WP)
448
+			'main_file_path'        => isset($setup_args['main_file_path'])
449
+				? (string) $setup_args['main_file_path']
450
+				: '',
451
+			// instance of \EventEspresso\core\domain\DomainInterface
452
+			'domain'                => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface
453
+				? $setup_args['domain']
454
+				: null,
455
+			// Fully Qualified Class Name for the addon's Domain class
456
+			'domain_fqcn'           => isset($setup_args['domain_fqcn'])
457
+				? (string) $setup_args['domain_fqcn']
458
+				: '',
459
+			// path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
460
+			'admin_path'            => isset($setup_args['admin_path'])
461
+				? (string) $setup_args['admin_path'] : '',
462
+			// a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
463
+			'admin_callback'        => isset($setup_args['admin_callback'])
464
+				? (string) $setup_args['admin_callback']
465
+				: '',
466
+			// the section name for this addon's configuration settings section (defaults to "addons")
467
+			'config_section'        => isset($setup_args['config_section'])
468
+				? (string) $setup_args['config_section']
469
+				: 'addons',
470
+			// the class name for this addon's configuration settings object
471
+			'config_class'          => isset($setup_args['config_class'])
472
+				? (string) $setup_args['config_class'] : '',
473
+			// the name given to the config for this addons' configuration settings object (optional)
474
+			'config_name'           => isset($setup_args['config_name'])
475
+				? (string) $setup_args['config_name'] : '',
476
+			// an array of "class names" => "full server paths" for any classes that might be invoked by the addon
477
+			'autoloader_paths'      => isset($setup_args['autoloader_paths'])
478
+				? (array) $setup_args['autoloader_paths']
479
+				: [],
480
+			// an array of  "full server paths" for any folders containing classes that might be invoked by the addon
481
+			'autoloader_folders'    => isset($setup_args['autoloader_folders'])
482
+				? (array) $setup_args['autoloader_folders']
483
+				: [],
484
+			// array of full server paths to any EE_DMS data migration scripts used by the addon.
485
+			// The key should be the EE_Addon class name that this set of data migration scripts belongs to.
486
+			// If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name
487
+			'dms_paths'             => isset($setup_args['dms_paths'])
488
+				? (array) $setup_args['dms_paths']
489
+				: [],
490
+			// array of full server paths to any EED_Modules used by the addon
491
+			'module_paths'          => isset($setup_args['module_paths'])
492
+				? (array) $setup_args['module_paths']
493
+				: [],
494
+			// array of full server paths to any EES_Shortcodes used by the addon
495
+			'shortcode_paths'       => isset($setup_args['shortcode_paths'])
496
+				? (array) $setup_args['shortcode_paths']
497
+				: [],
498
+			'shortcode_fqcns'       => isset($setup_args['shortcode_fqcns'])
499
+				? (array) $setup_args['shortcode_fqcns']
500
+				: [],
501
+			// array of full server paths to any WP_Widgets used by the addon
502
+			'widget_paths'          => isset($setup_args['widget_paths'])
503
+				? (array) $setup_args['widget_paths']
504
+				: [],
505
+			'message_types'         => isset($setup_args['message_types'])
506
+				? (array) $setup_args['message_types']
507
+				: [],
508
+			'capabilities'          => isset($setup_args['capabilities'])
509
+				? (array) $setup_args['capabilities']
510
+				: [],
511
+			'capability_maps'       => isset($setup_args['capability_maps'])
512
+				? (array) $setup_args['capability_maps']
513
+				: [],
514
+			'model_paths'           => isset($setup_args['model_paths'])
515
+				? (array) $setup_args['model_paths']
516
+				: [],
517
+			'class_paths'           => isset($setup_args['class_paths'])
518
+				? (array) $setup_args['class_paths']
519
+				: [],
520
+			'model_extension_paths' => isset($setup_args['model_extension_paths'])
521
+				? (array) $setup_args['model_extension_paths']
522
+				: [],
523
+			'class_extension_paths' => isset($setup_args['class_extension_paths'])
524
+				? (array) $setup_args['class_extension_paths']
525
+				: [],
526
+			'custom_post_types'     => isset($setup_args['custom_post_types'])
527
+				? (array) $setup_args['custom_post_types']
528
+				: [],
529
+			'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
530
+				? (array) $setup_args['custom_taxonomies']
531
+				: [],
532
+			'payment_method_paths'  => isset($setup_args['payment_method_paths'])
533
+				? (array) $setup_args['payment_method_paths']
534
+				: [],
535
+			'default_terms'         => isset($setup_args['default_terms'])
536
+				? (array) $setup_args['default_terms']
537
+				: [],
538
+			// if not empty, inserts a new table row after this plugin's row on the WP Plugins page
539
+			// that can be used for adding upgrading/marketing info
540
+			'plugins_page_row'      => isset($setup_args['plugins_page_row'])
541
+				? (array) $setup_args['plugins_page_row']
542
+				: [],
543
+			'namespace'             => isset(
544
+				$setup_args['namespace']['FQNS'],
545
+				$setup_args['namespace']['DIR']
546
+			)
547
+				? (array) $setup_args['namespace']
548
+				: [],
549
+			'privacy_policies'      => isset($setup_args['privacy_policies'])
550
+				? (array) $setup_args['privacy_policies']
551
+				: '',
552
+		];
553
+		// if plugin_action_slug is NOT set, but an admin page path IS set,
554
+		// then let's just use the plugin_slug since that will be used for linking to the admin page
555
+		$addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
556
+												&& ! empty($addon_settings['admin_path'])
557
+			? $addon_settings['plugin_slug']
558
+			: $addon_settings['plugin_action_slug'];
559
+		// full server path to main file (file loaded directly by WP)
560
+		$addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
561
+		return $addon_settings;
562
+	}
563
+
564
+
565
+	/**
566
+	 * @param string $addon_name
567
+	 * @param array  $addon_settings
568
+	 * @return bool
569
+	 */
570
+	private static function _addon_is_compatible(string $addon_name, array $addon_settings): bool
571
+	{
572
+		global $wp_version;
573
+		$incompatibility_message = '';
574
+		// check whether this addon version is compatible with EE core
575
+		if (
576
+			isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
577
+			&& ! self::_meets_min_core_version_requirement(
578
+				EE_Register_Addon::$_incompatible_addons[ $addon_name ],
579
+				$addon_settings['version']
580
+			)
581
+		) {
582
+			$incompatibility_message = sprintf(
583
+				esc_html__(
584
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.',
585
+					'event_espresso'
586
+				),
587
+				$addon_name,
588
+				'<br />',
589
+				EE_Register_Addon::$_incompatible_addons[ $addon_name ],
590
+				'<span style="font-weight: bold; color: #D54E21;">',
591
+				'</span><br />'
592
+			);
593
+		} elseif (
594
+			! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
595
+		) {
596
+			$incompatibility_message = sprintf(
597
+				esc_html__(
598
+					'%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
599
+					'event_espresso'
600
+				),
601
+				$addon_name,
602
+				self::_effective_version($addon_settings['min_core_version']),
603
+				self::_effective_version(espresso_version()),
604
+				'<br />',
605
+				'<span style="font-weight: bold; color: #D54E21;">',
606
+				'</span><br />'
607
+			);
608
+		} elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
609
+			$incompatibility_message = sprintf(
610
+				esc_html__(
611
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
612
+					'event_espresso'
613
+				),
614
+				$addon_name,
615
+				$addon_settings['min_wp_version'],
616
+				'<br />',
617
+				'<span style="font-weight: bold; color: #D54E21;">',
618
+				'</span><br />'
619
+			);
620
+		}
621
+		if (! empty($incompatibility_message)) {
622
+			// remove 'activate' from the REQUEST
623
+			// so WP doesn't erroneously tell the user the plugin activated fine when it didn't
624
+			/** @var RequestInterface $request */
625
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
626
+			$request->unSetRequestParam('activate', true);
627
+			if (current_user_can('activate_plugins')) {
628
+				// show an error message indicating the plugin didn't activate properly
629
+				EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
630
+			}
631
+			unset($_GET['activate'], $_REQUEST['activate']);
632
+			if (! function_exists('deactivate_plugins')) {
633
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
634
+			}
635
+			deactivate_plugins(plugin_basename($addon_settings['main_file_path']));
636
+			// BAIL FROM THE ADDON REGISTRATION PROCESS
637
+			return false;
638
+		}
639
+		// addon IS compatible
640
+		return true;
641
+	}
642
+
643
+
644
+	/**
645
+	 * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
646
+	 *
647
+	 * @param array $addon_settings
648
+	 * @return void
649
+	 */
650
+	private static function _setup_namespaces(array $addon_settings)
651
+	{
652
+		//
653
+		if (
654
+			isset(
655
+				$addon_settings['namespace']['FQNS'],
656
+				$addon_settings['namespace']['DIR']
657
+			)
658
+		) {
659
+			EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
660
+				$addon_settings['namespace']['FQNS'],
661
+				$addon_settings['namespace']['DIR']
662
+			);
663
+		}
664
+	}
665
+
666
+
667
+	/**
668
+	 * @param string $addon_name
669
+	 * @param array  $addon_settings
670
+	 * @return bool
671
+	 * @throws InvalidArgumentException
672
+	 * @throws InvalidDataTypeException
673
+	 * @throws InvalidInterfaceException
674
+	 */
675
+	private static function _addon_activation(string $addon_name, array $addon_settings): bool
676
+	{
677
+		// this is an activation request
678
+		if (did_action('activate_plugin')) {
679
+			// to find if THIS is the addon that was activated, just check if we have already registered it or not
680
+			// (as the newly-activated addon wasn't around the first time addons were registered).
681
+			// Note: the presence of pue_options in the addon registration options will initialize the $_settings
682
+			// property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
683
+			if (
684
+				! isset(self::$_settings[ $addon_name ])
685
+				|| (isset(self::$_settings[ $addon_name ])
686
+					&& ! isset(self::$_settings[ $addon_name ]['class_name'])
687
+				)
688
+			) {
689
+				self::$_settings[ $addon_name ] = $addon_settings;
690
+				$addon                          = self::_load_and_init_addon_class($addon_name);
691
+				$addon->set_activation_indicator_option();
692
+				// dont bother setting up the rest of the addon.
693
+				// we know it was just activated and the request will end soon
694
+			}
695
+			return true;
696
+		}
697
+		// make sure addon settings are set correctly without overwriting anything existing
698
+		if (isset(self::$_settings[ $addon_name ])) {
699
+			self::$_settings[ $addon_name ] += $addon_settings;
700
+		} else {
701
+			self::$_settings[ $addon_name ] = $addon_settings;
702
+		}
703
+		return false;
704
+	}
705
+
706
+
707
+	/**
708
+	 * @param string $addon_name
709
+	 * @return void
710
+	 * @throws EE_Error
711
+	 */
712
+	private static function _setup_autoloaders(string $addon_name)
713
+	{
714
+		if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
715
+			// setup autoloader for single file
716
+			EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
717
+		}
718
+		// setup autoloaders for folders
719
+		if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
720
+			foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
721
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
722
+			}
723
+		}
724
+	}
725
+
726
+
727
+	/**
728
+	 * register new models and extensions
729
+	 *
730
+	 * @param string $addon_name
731
+	 * @return void
732
+	 * @throws EE_Error
733
+	 */
734
+	private static function _register_models_and_extensions(string $addon_name)
735
+	{
736
+		// register new models
737
+		if (
738
+			! empty(self::$_settings[ $addon_name ]['model_paths'])
739
+			|| ! empty(self::$_settings[ $addon_name ]['class_paths'])
740
+		) {
741
+			EE_Register_Model::register(
742
+				$addon_name,
743
+				[
744
+					'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
745
+					'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
746
+				]
747
+			);
748
+		}
749
+		// register model extensions
750
+		if (
751
+			! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
752
+			|| ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
753
+		) {
754
+			EE_Register_Model_Extensions::register(
755
+				$addon_name,
756
+				[
757
+					'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
758
+					'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
759
+				]
760
+			);
761
+		}
762
+	}
763
+
764
+
765
+	/**
766
+	 * @param string $addon_name
767
+	 * @return void
768
+	 * @throws EE_Error
769
+	 */
770
+	private static function _register_data_migration_scripts(string $addon_name)
771
+	{
772
+		// setup DMS
773
+		if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
774
+			EE_Register_Data_Migration_Scripts::register(
775
+				$addon_name,
776
+				['dms_paths' => self::$_settings[ $addon_name ]['dms_paths']]
777
+			);
778
+		}
779
+	}
780
+
781
+
782
+	/**
783
+	 * @param string $addon_name
784
+	 * @return void
785
+	 * @throws EE_Error
786
+	 */
787
+	private static function _register_config(string $addon_name)
788
+	{
789
+		// if config_class is present let's register config.
790
+		if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
791
+			EE_Register_Config::register(
792
+				self::$_settings[ $addon_name ]['config_class'],
793
+				[
794
+					'config_section' => self::$_settings[ $addon_name ]['config_section'],
795
+					'config_name'    => self::$_settings[ $addon_name ]['config_name'],
796
+				]
797
+			);
798
+		}
799
+	}
800
+
801
+
802
+	/**
803
+	 * @param string $addon_name
804
+	 * @return void
805
+	 * @throws EE_Error
806
+	 */
807
+	private static function _register_admin_pages(string $addon_name)
808
+	{
809
+		if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
810
+			EE_Register_Admin_Page::register(
811
+				$addon_name,
812
+				['page_path' => self::$_settings[ $addon_name ]['admin_path']]
813
+			);
814
+		}
815
+	}
816
+
817
+
818
+	/**
819
+	 * @param string $addon_name
820
+	 * @return void
821
+	 * @throws EE_Error
822
+	 */
823
+	private static function _register_modules(string $addon_name)
824
+	{
825
+		if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
826
+			EE_Register_Module::register(
827
+				$addon_name,
828
+				['module_paths' => self::$_settings[ $addon_name ]['module_paths']]
829
+			);
830
+		}
831
+	}
832
+
833
+
834
+	/**
835
+	 * @param string $addon_name
836
+	 * @return void
837
+	 * @throws EE_Error
838
+	 */
839
+	private static function _register_shortcodes(string $addon_name)
840
+	{
841
+		if (
842
+			! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
843
+			|| ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
844
+		) {
845
+			EE_Register_Shortcode::register(
846
+				$addon_name,
847
+				[
848
+					'shortcode_paths' => self::$_settings[ $addon_name ]['shortcode_paths'] ?? [],
849
+					'shortcode_fqcns' => self::$_settings[ $addon_name ]['shortcode_fqcns'] ?? [],
850
+				]
851
+			);
852
+		}
853
+	}
854
+
855
+
856
+	/**
857
+	 * @param string $addon_name
858
+	 * @return void
859
+	 * @throws EE_Error
860
+	 */
861
+	private static function _register_widgets(string $addon_name)
862
+	{
863
+		if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
864
+			EE_Register_Widget::register(
865
+				$addon_name,
866
+				['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']]
867
+			);
868
+		}
869
+	}
870
+
871
+
872
+	/**
873
+	 * @param string $addon_name
874
+	 * @return void
875
+	 * @throws EE_Error
876
+	 */
877
+	private static function _register_capabilities(string $addon_name)
878
+	{
879
+		if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
880
+			EE_Register_Capabilities::register(
881
+				$addon_name,
882
+				[
883
+					'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
884
+					'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
885
+				]
886
+			);
887
+		}
888
+	}
889
+
890
+
891
+	/**
892
+	 * @param string $addon_name
893
+	 * @return void
894
+	 */
895
+	private static function _register_message_types(string $addon_name)
896
+	{
897
+		if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
898
+			add_action(
899
+				'EE_Brewing_Regular___messages_caf',
900
+				['EE_Register_Addon', 'register_message_types']
901
+			);
902
+		}
903
+	}
904
+
905
+
906
+	/**
907
+	 * @param string $addon_name
908
+	 * @return void
909
+	 * @throws EE_Error
910
+	 */
911
+	private static function _register_custom_post_types(string $addon_name)
912
+	{
913
+		if (
914
+			! empty(self::$_settings[ $addon_name ]['custom_post_types'])
915
+			|| ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
916
+		) {
917
+			EE_Register_CPT::register(
918
+				$addon_name,
919
+				[
920
+					'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
921
+					'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
922
+					'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
923
+				]
924
+			);
925
+		}
926
+	}
927
+
928
+
929
+	/**
930
+	 * @param string $addon_name
931
+	 * @return void
932
+	 * @throws InvalidArgumentException
933
+	 * @throws InvalidInterfaceException
934
+	 * @throws InvalidDataTypeException
935
+	 * @throws DomainException
936
+	 * @throws EE_Error
937
+	 */
938
+	private static function _register_payment_methods(string $addon_name)
939
+	{
940
+		if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
941
+			EE_Register_Payment_Method::register(
942
+				$addon_name,
943
+				['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']]
944
+			);
945
+		}
946
+	}
947
+
948
+
949
+	/**
950
+	 * @param string $addon_name
951
+	 * @return void
952
+	 * @throws InvalidArgumentException
953
+	 * @throws InvalidInterfaceException
954
+	 * @throws InvalidDataTypeException
955
+	 * @throws DomainException
956
+	 */
957
+	private static function registerPrivacyPolicies(string $addon_name)
958
+	{
959
+		if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
960
+			EE_Register_Privacy_Policy::register(
961
+				$addon_name,
962
+				self::$_settings[ $addon_name ]['privacy_policies']
963
+			);
964
+		}
965
+	}
966
+
967
+
968
+	/**
969
+	 * @param string $addon_name
970
+	 * @return void
971
+	 */
972
+	private static function registerPersonalDataExporters(string $addon_name)
973
+	{
974
+		if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
975
+			EE_Register_Personal_Data_Eraser::register(
976
+				$addon_name,
977
+				self::$_settings[ $addon_name ]['personal_data_exporters']
978
+			);
979
+		}
980
+	}
981
+
982
+
983
+	/**
984
+	 * @param string $addon_name
985
+	 * @return void
986
+	 */
987
+	private static function registerPersonalDataErasers(string $addon_name)
988
+	{
989
+		if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
990
+			EE_Register_Personal_Data_Eraser::register(
991
+				$addon_name,
992
+				self::$_settings[ $addon_name ]['personal_data_erasers']
993
+			);
994
+		}
995
+	}
996
+
997
+
998
+	/**
999
+	 * Loads and instantiates the EE_Addon class and adds it onto the registry
1000
+	 *
1001
+	 * @param string $addon_name
1002
+	 * @return EE_Addon
1003
+	 * @throws InvalidArgumentException
1004
+	 * @throws InvalidInterfaceException
1005
+	 * @throws InvalidDataTypeException
1006
+	 */
1007
+	private static function _load_and_init_addon_class(string $addon_name): EE_Addon
1008
+	{
1009
+		$addon = self::$loader->getShared(
1010
+			self::$_settings[ $addon_name ]['class_name'],
1011
+			['EE_Registry::create(addon)' => true]
1012
+		);
1013
+		if (! $addon instanceof EE_Addon) {
1014
+			throw new DomainException(
1015
+				sprintf(
1016
+					esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'),
1017
+					self::$_settings[ $addon_name ]['class_name']
1018
+				)
1019
+			);
1020
+		}
1021
+		// setter inject dep map if required
1022
+		if ($addon->dependencyMap() === null) {
1023
+			$addon->setDependencyMap(self::$loader->getShared('EE_Dependency_Map'));
1024
+		}
1025
+		// setter inject domain if required
1026
+		EE_Register_Addon::injectAddonDomain($addon_name, $addon);
1027
+
1028
+		$addon->set_name($addon_name);
1029
+		$addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1030
+		$addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1031
+		$addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1032
+		$addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1033
+		$addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1034
+		$addon->set_version(self::$_settings[ $addon_name ]['version']);
1035
+		$addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1036
+		$addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1037
+		$addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1038
+		$addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1039
+		do_action(
1040
+			'AHEE__EE_Register_Addon___load_and_init_addon_class',
1041
+			$addon,
1042
+			$addon_name,
1043
+			self::$_settings
1044
+		);
1045
+		// unfortunately this can't be hooked in upon construction,
1046
+		// because we don't have the plugin's mainfile path upon construction.
1047
+		register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']);
1048
+		// call any additional admin_callback functions during load_admin_controller hook
1049
+		if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1050
+			add_action(
1051
+				'AHEE__EE_System__load_controllers__load_admin_controllers',
1052
+				[$addon, self::$_settings[ $addon_name ]['admin_callback']]
1053
+			);
1054
+		}
1055
+		return $addon;
1056
+	}
1057
+
1058
+
1059
+	/**
1060
+	 * @param string   $addon_name
1061
+	 * @param EE_Addon $addon
1062
+	 * @since   4.10.13.p
1063
+	 */
1064
+	private static function injectAddonDomain(string $addon_name, EE_Addon $addon)
1065
+	{
1066
+		if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) {
1067
+			// using supplied Domain object
1068
+			$domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1069
+				? self::$_settings[ $addon_name ]['domain']
1070
+				: null;
1071
+			// or construct one using Domain FQCN
1072
+			if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1073
+				$domain = self::$loader->getShared(
1074
+					self::$_settings[ $addon_name ]['domain_fqcn'],
1075
+					[
1076
+						new EventEspresso\core\domain\values\FilePath(
1077
+							self::$_settings[ $addon_name ]['main_file_path']
1078
+						),
1079
+						EventEspresso\core\domain\values\Version::fromString(
1080
+							self::$_settings[ $addon_name ]['version']
1081
+						),
1082
+					]
1083
+				);
1084
+			}
1085
+			if ($domain instanceof DomainInterface) {
1086
+				$addon->setDomain($domain);
1087
+			}
1088
+		}
1089
+	}
1090
+
1091
+
1092
+	/**
1093
+	 * @return void
1094
+	 * @deprecated 5.0.0.p
1095
+	 */
1096
+	public static function load_pue_update()
1097
+	{
1098
+		RegisterAddonPUE::loadPueUpdate();
1099
+	}
1100
+
1101
+
1102
+	/**
1103
+	 * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
1104
+	 *
1105
+	 * @return void
1106
+	 * @throws EE_Error
1107
+	 * @since 4.4.0
1108
+	 */
1109
+	public static function register_message_types()
1110
+	{
1111
+		foreach (self::$_settings as $settings) {
1112
+			if (! empty($settings['message_types'])) {
1113
+				foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1114
+					EE_Register_Message_Type::register($message_type, $message_type_settings);
1115
+				}
1116
+			}
1117
+		}
1118
+	}
1119
+
1120
+
1121
+	/**
1122
+	 * This deregisters an addon that was previously registered with a specific addon_name.
1123
+	 *
1124
+	 * @param string $addon_name the name for the addon that was previously registered
1125
+	 * @throws DomainException
1126
+	 * @throws InvalidArgumentException
1127
+	 * @throws InvalidDataTypeException
1128
+	 * @throws InvalidInterfaceException
1129
+	 * @since    4.3.0
1130
+	 */
1131
+	public static function deregister(string $addon_name = '')
1132
+	{
1133
+		if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1134
+			try {
1135
+				do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1136
+				$class_name = self::$_settings[ $addon_name ]['class_name'];
1137
+				if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1138
+					// setup DMS
1139
+					EE_Register_Data_Migration_Scripts::deregister($addon_name);
1140
+				}
1141
+				if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1142
+					// register admin page
1143
+					EE_Register_Admin_Page::deregister($addon_name);
1144
+				}
1145
+				if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1146
+					// add to list of modules to be registered
1147
+					EE_Register_Module::deregister($addon_name);
1148
+				}
1149
+				if (
1150
+					! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1151
+					|| ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1152
+				) {
1153
+					// add to list of shortcodes to be registered
1154
+					EE_Register_Shortcode::deregister($addon_name);
1155
+				}
1156
+				if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1157
+					// if config_class present let's register config.
1158
+					EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1159
+				}
1160
+				if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1161
+					// add to list of widgets to be registered
1162
+					EE_Register_Widget::deregister($addon_name);
1163
+				}
1164
+				if (
1165
+					! empty(self::$_settings[ $addon_name ]['model_paths'])
1166
+					|| ! empty(self::$_settings[ $addon_name ]['class_paths'])
1167
+				) {
1168
+					// add to list of shortcodes to be registered
1169
+					EE_Register_Model::deregister($addon_name);
1170
+				}
1171
+				if (
1172
+					! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1173
+					|| ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1174
+				) {
1175
+					// add to list of shortcodes to be registered
1176
+					EE_Register_Model_Extensions::deregister($addon_name);
1177
+				}
1178
+				if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1179
+					foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1180
+						EE_Register_Message_Type::deregister($message_type);
1181
+					}
1182
+				}
1183
+				// deregister capabilities for addon
1184
+				if (
1185
+					! empty(self::$_settings[ $addon_name ]['capabilities'])
1186
+					|| ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1187
+				) {
1188
+					EE_Register_Capabilities::deregister($addon_name);
1189
+				}
1190
+				// deregister custom_post_types for addon
1191
+				if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1192
+					EE_Register_CPT::deregister($addon_name);
1193
+				}
1194
+				if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1195
+					EE_Register_Payment_Method::deregister($addon_name);
1196
+				}
1197
+				$addon = EE_Registry::instance()->getAddon($class_name);
1198
+				if ($addon instanceof EE_Addon) {
1199
+					remove_action(
1200
+						'deactivate_' . $addon->get_main_plugin_file_basename(),
1201
+						[$addon, 'deactivation']
1202
+					);
1203
+					remove_action(
1204
+						'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1205
+						[$addon, 'initialize_db_if_no_migrations_required']
1206
+					);
1207
+					// remove `after_registration` call
1208
+					remove_action(
1209
+						'AHEE__EE_System__load_espresso_addons__complete',
1210
+						[$addon, 'after_registration'],
1211
+						999
1212
+					);
1213
+				}
1214
+				EE_Registry::instance()->removeAddon($class_name);
1215
+				LoaderFactory::getLoader()->remove($class_name);
1216
+			} catch (OutOfBoundsException $addon_not_yet_registered_exception) {
1217
+				// the add-on was not yet registered in the registry,
1218
+				// so RegistryContainer::__get() throws this exception.
1219
+				// also no need to worry about this or log it,
1220
+				// it's ok to deregister an add-on before its registered in the registry
1221
+			} catch (Exception $e) {
1222
+				new ExceptionLogger($e);
1223
+			}
1224
+			unset(self::$_settings[ $addon_name ]);
1225
+			do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1226
+		}
1227
+	}
1228 1228
 }
Please login to merge, or discard this patch.
core/EE_System.core.php 1 patch
Indentation   +1230 added lines, -1230 removed lines patch added patch discarded remove patch
@@ -24,1234 +24,1234 @@
 block discarded – undo
24 24
  */
25 25
 final class EE_System implements ResettableInterface
26 26
 {
27
-    /**
28
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
29
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
30
-     */
31
-    const req_type_normal = 0;
32
-
33
-    /**
34
-     * Indicates this is a brand new installation of EE so we should install
35
-     * tables and default data etc
36
-     */
37
-    const req_type_new_activation = 1;
38
-
39
-    /**
40
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
41
-     * and we just exited maintenance mode). We MUST check the database is setup properly
42
-     * and that default data is setup too
43
-     */
44
-    const req_type_reactivation = 2;
45
-
46
-    /**
47
-     * indicates that EE has been upgraded since its previous request.
48
-     * We may have data migration scripts to call and will want to trigger maintenance mode
49
-     */
50
-    const req_type_upgrade = 3;
51
-
52
-    /**
53
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
54
-     */
55
-    const req_type_downgrade = 4;
56
-
57
-    /**
58
-     * @deprecated since version 4.6.0.dev.006
59
-     * Now whenever a new_activation is detected the request type is still just
60
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we're in maintenance mode
61
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
62
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
63
-     * (Specifically, when the migration manager indicates migrations are finished
64
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
65
-     */
66
-    const req_type_activation_but_not_installed = 5;
67
-
68
-    /**
69
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
70
-     */
71
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
72
-
73
-    /**
74
-     * @var AddonManager $addon_manager
75
-     */
76
-    private $addon_manager;
77
-
78
-    /**
79
-     * @var EE_System $_instance
80
-     */
81
-    private static $_instance;
82
-
83
-    /**
84
-     * @var EE_Registry $registry
85
-     */
86
-    private $registry;
87
-
88
-    /**
89
-     * @var LoaderInterface $loader
90
-     */
91
-    private $loader;
92
-
93
-    /**
94
-     * @var EE_Capabilities $capabilities
95
-     */
96
-    private $capabilities;
97
-
98
-    /**
99
-     * @var EE_Maintenance_Mode $maintenance_mode
100
-     */
101
-    private $maintenance_mode;
102
-
103
-    /**
104
-     * @var RequestInterface $request
105
-     */
106
-    private $request;
107
-
108
-    /**
109
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
110
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
111
-     *
112
-     * @var int $_req_type
113
-     */
114
-    private $_req_type;
115
-
116
-    /**
117
-     * Whether or not there was a non-micro version change in EE core version during this request
118
-     *
119
-     * @var boolean $_major_version_change
120
-     */
121
-    private $_major_version_change = false;
122
-
123
-    /**
124
-     * @var Router $router
125
-     */
126
-    private $router;
127
-
128
-    /**
129
-     * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes
130
-     */
131
-    private $register_custom_post_types;
132
-
133
-    /**
134
-     * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies
135
-     */
136
-    private $register_custom_taxonomies;
137
-
138
-    /**
139
-     * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms
140
-     */
141
-    private $register_custom_taxonomy_terms;
142
-
143
-    /**
144
-     * @singleton method used to instantiate class object
145
-     * @param LoaderInterface|null     $loader
146
-     * @param EE_Maintenance_Mode|null $maintenance_mode
147
-     * @param EE_Registry|null         $registry
148
-     * @param RequestInterface|null    $request
149
-     * @param Router|null              $router
150
-     * @return EE_System
151
-     */
152
-    public static function instance(
153
-        LoaderInterface $loader = null,
154
-        EE_Maintenance_Mode $maintenance_mode = null,
155
-        EE_Registry $registry = null,
156
-        RequestInterface $request = null,
157
-        Router $router = null
158
-    ): EE_System {
159
-        // check if class object is instantiated
160
-        if (! self::$_instance instanceof EE_System) {
161
-            self::$_instance = new self($loader, $maintenance_mode, $registry, $request, $router);
162
-        }
163
-        return self::$_instance;
164
-    }
165
-
166
-
167
-    /**
168
-     * resets the instance and returns it
169
-     *
170
-     * @return EE_System
171
-     */
172
-    public static function reset(): EE_System
173
-    {
174
-        self::$_instance->_req_type = null;
175
-        // make sure none of the old hooks are left hanging around
176
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
177
-        // we need to reset the migration manager in order for it to detect DMSs properly
178
-        EE_Data_Migration_Manager::reset();
179
-        self::instance()->detect_activations_or_upgrades();
180
-        self::instance()->perform_activations_upgrades_and_migrations();
181
-        return self::instance();
182
-    }
183
-
184
-
185
-    /**
186
-     * sets hooks for running rest of system
187
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
188
-     * starting EE Addons from any other point may lead to problems
189
-     *
190
-     * @param LoaderInterface     $loader
191
-     * @param EE_Maintenance_Mode $maintenance_mode
192
-     * @param EE_Registry         $registry
193
-     * @param RequestInterface    $request
194
-     * @param Router              $router
195
-     */
196
-    private function __construct(
197
-        LoaderInterface $loader,
198
-        EE_Maintenance_Mode $maintenance_mode,
199
-        EE_Registry $registry,
200
-        RequestInterface $request,
201
-        Router $router
202
-    ) {
203
-        $this->registry         = $registry;
204
-        $this->loader           = $loader;
205
-        $this->request          = $request;
206
-        $this->router           = $router;
207
-        $this->maintenance_mode = $maintenance_mode;
208
-        do_action('AHEE__EE_System__construct__begin', $this);
209
-        add_action(
210
-            'AHEE__EE_Bootstrap__load_espresso_addons',
211
-            [$this, 'loadCapabilities'],
212
-            5
213
-        );
214
-        add_action(
215
-            'AHEE__EE_Bootstrap__load_espresso_addons',
216
-            [$this, 'loadCommandBus'],
217
-            7
218
-        );
219
-        add_action(
220
-            'AHEE__EE_Bootstrap__load_espresso_addons',
221
-            [$this, 'loadPluginApi'],
222
-            9
223
-        );
224
-        // give caff stuff a chance to play during the activation process too.
225
-        add_action(
226
-            'AHEE__EE_Bootstrap__load_espresso_addons',
227
-            [$this, 'brewCaffeinated'],
228
-            9
229
-        );
230
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
231
-        add_action(
232
-            'AHEE__EE_Bootstrap__load_espresso_addons',
233
-            [$this, 'load_espresso_addons']
234
-        );
235
-        // when an ee addon is activated, we want to call the core hook(s) again
236
-        // because the newly-activated addon didn't get a chance to run at all
237
-        add_action('activate_plugin', [$this, 'load_espresso_addons'], 1);
238
-        // detect whether install or upgrade
239
-        add_action(
240
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
241
-            [$this, 'detect_activations_or_upgrades'],
242
-            3
243
-        );
244
-        // load EE_Config, EE_Textdomain, etc
245
-        add_action(
246
-            'AHEE__EE_Bootstrap__load_core_configuration',
247
-            [$this, 'load_core_configuration'],
248
-            5
249
-        );
250
-        // load specifications for matching routes to current request
251
-        add_action(
252
-            'AHEE__EE_Bootstrap__load_core_configuration',
253
-            [$this, 'loadRouteMatchSpecifications']
254
-        );
255
-        // load specifications for custom post types
256
-        add_action(
257
-            'AHEE__EE_Bootstrap__load_core_configuration',
258
-            array($this, 'loadCustomPostTypes')
259
-        );
260
-        // load specifications for custom post types
261
-        add_action(
262
-            'AHEE__EE_Bootstrap__load_core_configuration',
263
-            array($this, 'loadCustomPostTypes')
264
-        );
265
-        // load EE_Config, EE_Textdomain, etc
266
-        add_action(
267
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
268
-            [$this, 'register_shortcodes_modules_and_widgets'],
269
-            7
270
-        );
271
-        // you wanna get going? I wanna get going... let's get going!
272
-        add_action(
273
-            'AHEE__EE_Bootstrap__brew_espresso',
274
-            [$this, 'brew_espresso'],
275
-            9
276
-        );
277
-        // other housekeeping
278
-        // exclude EE critical pages from wp_list_pages
279
-        add_filter(
280
-            'wp_list_pages_excludes',
281
-            [$this, 'remove_pages_from_wp_list_pages'],
282
-            10
283
-        );
284
-        // ALL EE Addons should use the following hook point to attach their initial setup too
285
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
286
-        do_action('AHEE__EE_System__construct__complete', $this);
287
-    }
288
-
289
-
290
-    /**
291
-     * load and setup EE_Capabilities
292
-     *
293
-     * @return void
294
-     */
295
-    public function loadCapabilities()
296
-    {
297
-        $this->capabilities = $this->loader->getShared('EE_Capabilities');
298
-        add_action(
299
-            'AHEE__EE_Capabilities__init_caps__before_initialization',
300
-            function () {
301
-                LoaderFactory::getLoader()->getShared('EventEspresso\PaymentMethods\Manager');
302
-                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
303
-            }
304
-        );
305
-    }
306
-
307
-
308
-    /**
309
-     * create and cache the CommandBus, and also add middleware
310
-     * The CapChecker middleware requires the use of EE_Capabilities
311
-     * which is why we need to load the CommandBus after Caps are set up
312
-     * CommandBus middleware operate FIFO - First In First Out
313
-     * so LocateMovedCommands will run first in order to return any new commands
314
-     *
315
-     * @return void
316
-     */
317
-    public function loadCommandBus()
318
-    {
319
-        $this->loader->getShared(
320
-            'CommandBusInterface',
321
-            [
322
-                null,
323
-                apply_filters(
324
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
325
-                    [
326
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\LocateMovedCommands'),
327
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
328
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
329
-                    ]
330
-                ),
331
-            ]
332
-        );
333
-    }
334
-
335
-
336
-    /**
337
-     * @return void
338
-     * @throws Exception
339
-     */
340
-    public function loadPluginApi()
341
-    {
342
-        $this->addon_manager = $this->loader->getShared(AddonManager::class);
343
-        $this->addon_manager->initialize();
344
-        $this->loader->getShared('EE_Request_Handler');
345
-    }
346
-
347
-
348
-    /**
349
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
350
-     * that need to be setup before our EE_System launches.
351
-     *
352
-     * @return void
353
-     * @throws DomainException
354
-     * @throws InvalidArgumentException
355
-     * @throws InvalidDataTypeException
356
-     * @throws InvalidInterfaceException
357
-     * @throws InvalidClassException
358
-     * @throws InvalidFilePathException
359
-     * @throws EE_Error
360
-     */
361
-    public function brewCaffeinated()
362
-    {
363
-        static $brew;
364
-        /** @var Domain $domain */
365
-        $domain = DomainFactory::getEventEspressoCoreDomain();
366
-        if ($domain->isCaffeinated() && ! $brew instanceof EE_Brewing_Regular) {
367
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
368
-            /** @var EE_Brewing_Regular $brew */
369
-            $brew = LoaderFactory::getLoader()->getShared(EE_Brewing_Regular::class);
370
-            $brew->initializePUE();
371
-            add_action(
372
-                'AHEE__EE_System__load_core_configuration__begin',
373
-                [$brew, 'caffeinated']
374
-            );
375
-        }
376
-    }
377
-
378
-
379
-    /**
380
-     * load_espresso_addons
381
-     * allow addons to load first so that they can set hooks for running DMS's, etc
382
-     * this is hooked into both:
383
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
384
-     *        which runs during the WP 'plugins_loaded' action at priority 5
385
-     *    and the WP 'activate_plugin' hook point
386
-     *
387
-     * @return void
388
-     * @throws Exception
389
-     */
390
-    public function load_espresso_addons()
391
-    {
392
-        // looking for hooks? they've been moved into the AddonManager to maintain compatibility
393
-        $this->addon_manager->loadAddons();
394
-    }
395
-
396
-
397
-    /**
398
-     * detect_activations_or_upgrades
399
-     * Checks for activation or upgrade of core first;
400
-     * then also checks if any registered addons have been activated or upgraded
401
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
402
-     * which runs during the WP 'plugins_loaded' action at priority 3
403
-     *
404
-     * @access public
405
-     * @return void
406
-     */
407
-    public function detect_activations_or_upgrades()
408
-    {
409
-        // first off: let's make sure to handle core
410
-        $this->detect_if_activation_or_upgrade();
411
-        foreach ($this->registry->addons as $addon) {
412
-            if ($addon instanceof EE_Addon) {
413
-                // detect teh request type for that addon
414
-                $addon->detect_req_type();
415
-            }
416
-        }
417
-    }
418
-
419
-
420
-    /**
421
-     * detect_if_activation_or_upgrade
422
-     * Takes care of detecting whether this is a brand new install or code upgrade,
423
-     * and either setting up the DB or setting up maintenance mode etc.
424
-     *
425
-     * @access public
426
-     * @return void
427
-     */
428
-    public function detect_if_activation_or_upgrade()
429
-    {
430
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
431
-        // check if db has been updated, or if its a brand-new installation
432
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
433
-        $request_type       = $this->detect_req_type($espresso_db_update);
434
-        // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
435
-        switch ($request_type) {
436
-            case EE_System::req_type_new_activation:
437
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
438
-                $this->_handle_core_version_change($espresso_db_update);
439
-                break;
440
-            case EE_System::req_type_reactivation:
441
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
442
-                $this->_handle_core_version_change($espresso_db_update);
443
-                break;
444
-            case EE_System::req_type_upgrade:
445
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
446
-                // migrations may be required now that we've upgraded
447
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
448
-                $this->_handle_core_version_change($espresso_db_update);
449
-                break;
450
-            case EE_System::req_type_downgrade:
451
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
452
-                // its possible migrations are no longer required
453
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
454
-                $this->_handle_core_version_change($espresso_db_update);
455
-                break;
456
-            case EE_System::req_type_normal:
457
-            default:
458
-                break;
459
-        }
460
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
461
-    }
462
-
463
-
464
-    /**
465
-     * Updates the list of installed versions and sets hooks for
466
-     * initializing the database later during the request
467
-     *
468
-     * @param array $espresso_db_update
469
-     */
470
-    private function _handle_core_version_change(array $espresso_db_update)
471
-    {
472
-        $this->update_list_of_installed_versions($espresso_db_update);
473
-        // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
474
-        add_action(
475
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
476
-            [$this, 'initialize_db_if_no_migrations_required']
477
-        );
478
-    }
479
-
480
-
481
-    /**
482
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
483
-     * information about what versions of EE have been installed and activated,
484
-     * NOT necessarily the state of the database
485
-     *
486
-     * @param mixed $espresso_db_update           the value of the WordPress option.
487
-     *                                            If not supplied, fetches it from the options table
488
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
489
-     */
490
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null): array
491
-    {
492
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
493
-        if (! $espresso_db_update) {
494
-            $espresso_db_update = get_option('espresso_db_update');
495
-        }
496
-        // check that option is an array
497
-        if (! is_array($espresso_db_update)) {
498
-            // if option is FALSE, then it never existed
499
-            if ($espresso_db_update === false) {
500
-                // make $espresso_db_update an array and save option with autoload OFF
501
-                $espresso_db_update = [];
502
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
503
-            } else {
504
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
505
-                $espresso_db_update = [$espresso_db_update => []];
506
-                update_option('espresso_db_update', $espresso_db_update);
507
-            }
508
-        } else {
509
-            $corrected_db_update = [];
510
-            // if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
511
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
512
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
513
-                    // the key is an int, and the value IS NOT an array
514
-                    // so it must be numerically-indexed, where values are versions installed...
515
-                    // fix it!
516
-                    $version_string                         = $should_be_array;
517
-                    $corrected_db_update[ $version_string ] = ['unknown-date'];
518
-                } else {
519
-                    // ok it checks out
520
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
521
-                }
522
-            }
523
-            $espresso_db_update = $corrected_db_update;
524
-            update_option('espresso_db_update', $espresso_db_update);
525
-        }
526
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
527
-        return ! empty($espresso_db_update) ? $espresso_db_update : [];
528
-    }
529
-
530
-
531
-    /**
532
-     * Does the traditional work of setting up the plugin's database and adding default data.
533
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
534
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
535
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
536
-     * so that it will be done when migrations are finished
537
-     *
538
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
539
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
540
-     *                                       This is a resource-intensive job
541
-     *                                       so we prefer to only do it when necessary
542
-     * @return void
543
-     * @throws EE_Error
544
-     * @throws ReflectionException
545
-     */
546
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
547
-    {
548
-        $request_type = $this->detect_req_type();
549
-        // only initialize system if we're not in maintenance mode.
550
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
551
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
552
-            $rewrite_rules = $this->loader->getShared(
553
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
554
-            );
555
-            $rewrite_rules->flush();
556
-            if ($verify_schema) {
557
-                EEH_Activation::initialize_db_and_folders();
558
-            }
559
-            EEH_Activation::initialize_db_content();
560
-            EEH_Activation::system_initialization();
561
-            if ($initialize_addons_too) {
562
-                $this->initialize_addons();
563
-            }
564
-        } else {
565
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
566
-        }
567
-        if (
568
-            $request_type === EE_System::req_type_new_activation
569
-            || $request_type === EE_System::req_type_reactivation
570
-            || (
571
-                $request_type === EE_System::req_type_upgrade
572
-                && $this->is_major_version_change()
573
-            )
574
-        ) {
575
-            add_action('AHEE__EE_System__initialize_last', [$this, 'redirect_to_about_ee'], 9);
576
-        }
577
-    }
578
-
579
-
580
-    /**
581
-     * Initializes the db for all registered addons
582
-     *
583
-     * @throws EE_Error
584
-     * @throws ReflectionException
585
-     */
586
-    public function initialize_addons()
587
-    {
588
-        // foreach registered addon, make sure its db is up-to-date too
589
-        foreach ($this->registry->addons as $addon) {
590
-            if ($addon instanceof EE_Addon) {
591
-                $addon->initialize_db_if_no_migrations_required();
592
-            }
593
-        }
594
-    }
595
-
596
-
597
-    /**
598
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
599
-     *
600
-     * @param array  $version_history
601
-     * @param string $current_version_to_add version to be added to the version history
602
-     * @return    boolean success as to whether or not this option was changed
603
-     */
604
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null): bool
605
-    {
606
-        if (! $version_history) {
607
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
608
-        }
609
-        if ($current_version_to_add === null) {
610
-            $current_version_to_add = espresso_version();
611
-        }
612
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
613
-        // re-save
614
-        return update_option('espresso_db_update', $version_history);
615
-    }
616
-
617
-
618
-    /**
619
-     * Detects if the current version indicated in the has existed in the list of
620
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
621
-     *
622
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
623
-     *                                  If not supplied, fetches it from the options table.
624
-     *                                  Also, caches its result so later parts of the code can also know whether
625
-     *                                  there's been an update or not. This way we can add the current version to
626
-     *                                  espresso_db_update, but still know if this is a new install or not
627
-     * @return int one of the constants on EE_System::req_type_
628
-     */
629
-    public function detect_req_type($espresso_db_update = null): int
630
-    {
631
-        if ($this->_req_type === null) {
632
-            $espresso_db_update          = ! empty($espresso_db_update)
633
-                ? $espresso_db_update
634
-                : $this->fix_espresso_db_upgrade_option();
635
-            $this->_req_type             = EE_System::detect_req_type_given_activation_history(
636
-                $espresso_db_update,
637
-                'ee_espresso_activation',
638
-                espresso_version()
639
-            );
640
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
641
-            $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
642
-        }
643
-        return $this->_req_type;
644
-    }
645
-
646
-
647
-    /**
648
-     * Returns whether or not there was a non-micro version change (ie, change in either
649
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
650
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
651
-     *
652
-     * @param $activation_history
653
-     * @return bool
654
-     */
655
-    private function _detect_major_version_change($activation_history): bool
656
-    {
657
-        $previous_version       = EE_System::getMostRecentlyActiveVersion($activation_history);
658
-        $previous_version_parts = explode('.', $previous_version);
659
-        $current_version_parts  = explode('.', espresso_version());
660
-        return isset(
661
-            $previous_version_parts[0],
662
-            $previous_version_parts[1],
663
-            $current_version_parts[0],
664
-            $current_version_parts[1]
665
-        ) && (
666
-            $previous_version_parts[0] !== $current_version_parts[0]
667
-            || $previous_version_parts[1] !== $current_version_parts[1]
668
-        );
669
-    }
670
-
671
-
672
-    /**
673
-     * Returns true if either the major or minor version of EE changed during this request.
674
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
675
-     *
676
-     * @return bool
677
-     */
678
-    public function is_major_version_change(): bool
679
-    {
680
-        return $this->_major_version_change;
681
-    }
682
-
683
-
684
-    /**
685
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
686
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
687
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
688
-     * just activated to (for core that will always be espresso_version())
689
-     *
690
-     * @param array|null $activation_history             the option's value which stores the activation history for
691
-     *                                                 this
692
-     *                                                 ee plugin. for core that's 'espresso_db_update'
693
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
694
-     *                                                 indicate that this plugin was just activated
695
-     * @param string $current_version                  the version that was just upgraded to (for core that will be
696
-     *                                                 espresso_version())
697
-     * @return int one of the constants on EE_System::req_type_
698
-     */
699
-    public static function detect_req_type_given_activation_history(
700
-        array $activation_history,
701
-        string $activation_indicator_option_name,
702
-        string $current_version
703
-    ): int {
704
-        $version_change = self::compareVersionWithPrevious($activation_history, $current_version);
705
-        $is_activation  = get_option($activation_indicator_option_name, false);
706
-        $req_type       = self::getRequestType($activation_history, $version_change, $is_activation);
707
-        if ($is_activation) {
708
-            // cleanup in aisle 6
709
-            delete_option($activation_indicator_option_name);
710
-        }
711
-        return $req_type;
712
-    }
713
-
714
-
715
-    /**
716
-     * @param array  $activation_history
717
-     * @param int    $version_change
718
-     * @param bool   $is_activation
719
-     * @return int
720
-     * @since 5.0.0.p
721
-     */
722
-    private static function getRequestType(array $activation_history, int $version_change, bool $is_activation): int
723
-    {
724
-        // if no previous activation history exists, then this is a brand new install
725
-        if (empty($activation_history)) {
726
-            return EE_System::req_type_new_activation;
727
-        }
728
-        // current version is higher than previous version, so it's an upgrade
729
-        if ($version_change === 1) {
730
-            return EE_System::req_type_upgrade;
731
-        }
732
-        // current version is lower than previous version, so it's a downgrade
733
-        if ($version_change === -1) {
734
-            return EE_System::req_type_downgrade;
735
-        }
736
-        // version hasn't changed since last version so check if the activation indicator is set
737
-        // to determine if it's a reactivation, or just a normal request
738
-        return $is_activation
739
-            ? EE_System::req_type_reactivation
740
-            : EE_System::req_type_normal;
741
-    }
742
-
743
-
744
-    /**
745
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
746
-     * the $activation_history_for_addon
747
-     *
748
-     * @param array  $activation_history    array where keys are versions,
749
-     *                                      values are arrays of times activated (sometimes 'unknown-date')
750
-     * @param string $current_version
751
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
752
-     *                                      -1 if $version_to_upgrade_to is LOWER (downgrade);
753
-     *                                      0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
754
-     *                                      1 if $version_to_upgrade_to is HIGHER (upgrade) ;
755
-     */
756
-    private static function compareVersionWithPrevious(array $activation_history, string $current_version): int
757
-    {
758
-        // find the most recently-activated version
759
-        $most_recently_active_version = EE_System::getMostRecentlyActiveVersion($activation_history);
760
-        return version_compare($current_version, $most_recently_active_version);
761
-    }
762
-
763
-
764
-    /**
765
-     * Gets the most recently active version listed in the activation history,
766
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
767
-     *
768
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
769
-     *                                   sometimes containing 'unknown-date'
770
-     * @return string
771
-     */
772
-    private static function getMostRecentlyActiveVersion(array $activation_history): string
773
-    {
774
-        $most_recent_activation_date  = '1970-01-01 00:00:00';
775
-        $most_recently_active_version = '0.0.0.dev.000';
776
-        if (is_array($activation_history)) {
777
-            foreach ($activation_history as $version => $activation_dates) {
778
-                // check there is a record of when this version was activated.
779
-                // Otherwise, mark it as unknown
780
-                if (! $activation_dates) {
781
-                    $activation_dates = ['unknown-date'];
782
-                }
783
-                $activation_dates = is_string($activation_dates) ? [$activation_dates] : $activation_dates;
784
-                foreach ($activation_dates as $activation_date) {
785
-                    if ($activation_date !== 'unknown-date' && $activation_date > $most_recent_activation_date) {
786
-                        $most_recently_active_version = $version;
787
-                        $most_recent_activation_date  = $activation_date;
788
-                    }
789
-                }
790
-            }
791
-        }
792
-        return $most_recently_active_version;
793
-    }
794
-
795
-
796
-    /**
797
-     * This redirects to the about EE page after activation
798
-     *
799
-     * @return void
800
-     */
801
-    public function redirect_to_about_ee()
802
-    {
803
-        $notices = EE_Error::get_notices(false);
804
-        // if current user is an admin and it's not an ajax or rest request
805
-        if (
806
-            ! isset($notices['errors'])
807
-            && $this->request->isAdmin()
808
-            && apply_filters(
809
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
810
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
811
-            )
812
-        ) {
813
-            $query_params = ['page' => 'espresso_about'];
814
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
815
-                $query_params['new_activation'] = true;
816
-            }
817
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
818
-                $query_params['reactivation'] = true;
819
-            }
820
-            $url = add_query_arg($query_params, admin_url('admin.php'));
821
-            EEH_URL::safeRedirectAndExit($url);
822
-        }
823
-    }
824
-
825
-
826
-    /**
827
-     * load_core_configuration
828
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
829
-     * which runs during the WP 'plugins_loaded' action at priority 5
830
-     *
831
-     * @return void
832
-     * @throws ReflectionException
833
-     * @throws Exception
834
-     */
835
-    public function load_core_configuration()
836
-    {
837
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
838
-        $this->loader->getShared('EE_Load_Textdomain');
839
-        // load textdomain
840
-        EE_Load_Textdomain::load_textdomain();
841
-        // load and setup EE_Config and EE_Network_Config
842
-        $config = $this->loader->getShared('EE_Config');
843
-        $this->loader->getShared('EE_Network_Config');
844
-        // setup autoloaders
845
-        // enable logging?
846
-        $this->loader->getShared('EventEspresso\core\services\orm\TrashLogger');
847
-        if ($config->admin->use_remote_logging) {
848
-            $this->loader->getShared('EE_Log');
849
-        }
850
-        // check for activation errors
851
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
852
-        if ($activation_errors) {
853
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
854
-            update_option('ee_plugin_activation_errors', false);
855
-        }
856
-        // get model names
857
-        $this->_parse_model_names();
858
-        // configure custom post type definitions
859
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
860
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
861
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
862
-    }
863
-
864
-
865
-    /**
866
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
867
-     *
868
-     * @return void
869
-     * @throws ReflectionException
870
-     */
871
-    private function _parse_model_names()
872
-    {
873
-        // get all the files in the EE_MODELS folder that end in .model.php
874
-        $models                 = glob(EE_MODELS . '*.model.php');
875
-        $model_names            = [];
876
-        $non_abstract_db_models = [];
877
-        foreach ($models as $model) {
878
-            // get model classname
879
-            $classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
880
-            $short_name      = str_replace('EEM_', '', $classname);
881
-            $reflectionClass = new ReflectionClass($classname);
882
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
883
-                $non_abstract_db_models[ $short_name ] = $classname;
884
-            }
885
-            $model_names[ $short_name ] = $classname;
886
-        }
887
-        $this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
888
-        $this->registry->non_abstract_db_models = apply_filters(
889
-            'FHEE__EE_System__parse_implemented_model_names',
890
-            $non_abstract_db_models
891
-        );
892
-    }
893
-
894
-
895
-    /**
896
-     * @throws Exception
897
-     * @since 4.9.71.p
898
-     */
899
-    public function loadRouteMatchSpecifications()
900
-    {
901
-        try {
902
-            $this->loader->getShared('EventEspresso\core\services\routing\RouteMatchSpecificationManager');
903
-            $this->loader->getShared('EventEspresso\core\services\routing\RouteCollection');
904
-            $this->router->loadPrimaryRoutes();
905
-        } catch (Exception $exception) {
906
-            new ExceptionStackTraceDisplay($exception);
907
-        }
908
-        do_action('AHEE__EE_System__loadRouteMatchSpecifications');
909
-    }
910
-
911
-
912
-    /**
913
-     * loading CPT related classes earlier so that their definitions are available
914
-     * but not performing any actual registration with WP core until load_CPTs_and_session() is called
915
-     *
916
-     * @since   4.10.21.p
917
-     */
918
-    public function loadCustomPostTypes()
919
-    {
920
-        $this->register_custom_taxonomies = $this->loader->getShared(
921
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
922
-        );
923
-        $this->register_custom_post_types = $this->loader->getShared(
924
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
925
-        );
926
-        $this->register_custom_taxonomy_terms = $this->loader->getShared(
927
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
928
-        );
929
-        // integrate WP_Query with the EE models
930
-        $this->loader->getShared('EE_CPT_Strategy');
931
-        // load legacy EE_Request_Handler in case add-ons still need it
932
-        $this->loader->getShared('EE_Request_Handler');
933
-    }
934
-
935
-
936
-    /**
937
-     * register_shortcodes_modules_and_widgets
938
-     * generate lists of shortcodes and modules, then verify paths and classes
939
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
940
-     * which runs during the WP 'plugins_loaded' action at priority 7
941
-     *
942
-     * @access public
943
-     * @return void
944
-     * @throws Exception
945
-     */
946
-    public function register_shortcodes_modules_and_widgets()
947
-    {
948
-        $this->router->registerShortcodesModulesAndWidgets();
949
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
950
-        // check for addons using old hook point
951
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
952
-            $this->_incompatible_addon_error();
953
-        }
954
-    }
955
-
956
-
957
-    /**
958
-     * _incompatible_addon_error
959
-     *
960
-     * @access public
961
-     * @return void
962
-     */
963
-    private function _incompatible_addon_error()
964
-    {
965
-        // get array of classes hooking into here
966
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
967
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
968
-        );
969
-        if (! empty($class_names)) {
970
-            $msg = esc_html__(
971
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
972
-                'event_espresso'
973
-            );
974
-            $msg .= '<ul>';
975
-            foreach ($class_names as $class_name) {
976
-                $msg .= '<li><b>Event Espresso - '
977
-                        . str_replace(
978
-                            ['EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'],
979
-                            '',
980
-                            $class_name
981
-                        ) . '</b></li>';
982
-            }
983
-            $msg .= '</ul>';
984
-            $msg .= esc_html__(
985
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
986
-                'event_espresso'
987
-            );
988
-            // save list of incompatible addons to wp-options for later use
989
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
990
-            if (is_admin()) {
991
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
992
-            }
993
-        }
994
-    }
995
-
996
-
997
-    /**
998
-     * brew_espresso
999
-     * begins the process of setting hooks for initializing EE in the correct order
1000
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1001
-     * which runs during the WP 'plugins_loaded' action at priority 9
1002
-     *
1003
-     * @return void
1004
-     * @throws Exception
1005
-     */
1006
-    public function brew_espresso()
1007
-    {
1008
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1009
-        // load some final core systems
1010
-        add_action('init', [$this, 'set_hooks_for_core'], 1);
1011
-        add_action('init', [$this, 'perform_activations_upgrades_and_migrations'], 3);
1012
-        add_action('init', [$this, 'load_CPTs_and_session'], 5);
1013
-        add_action('init', [$this, 'load_controllers'], 7);
1014
-        add_action('init', [$this, 'core_loaded_and_ready'], 9);
1015
-        add_action('init', [$this, 'initialize'], 10);
1016
-        add_action('init', [$this, 'initialize_last'], 100);
1017
-        $this->router->brewEspresso();
1018
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1019
-    }
1020
-
1021
-
1022
-    /**
1023
-     *    set_hooks_for_core
1024
-     *
1025
-     * @access public
1026
-     * @return    void
1027
-     * @throws EE_Error
1028
-     */
1029
-    public function set_hooks_for_core()
1030
-    {
1031
-        $this->_deactivate_incompatible_addons();
1032
-        do_action('AHEE__EE_System__set_hooks_for_core');
1033
-        $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1034
-        // caps need to be initialized on every request so that capability maps are set.
1035
-        // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1036
-        $this->registry->CAP->init_caps();
1037
-    }
1038
-
1039
-
1040
-    /**
1041
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1042
-     * deactivates any addons considered incompatible with the current version of EE
1043
-     */
1044
-    private function _deactivate_incompatible_addons()
1045
-    {
1046
-        $incompatible_addons = get_option('ee_incompatible_addons', []);
1047
-        if (! empty($incompatible_addons)) {
1048
-            $active_plugins = get_option('active_plugins', []);
1049
-            foreach ($active_plugins as $active_plugin) {
1050
-                foreach ($incompatible_addons as $incompatible_addon) {
1051
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1052
-                        $this->request->unSetRequestParams(['activate'], true);
1053
-                        espresso_deactivate_plugin($active_plugin);
1054
-                    }
1055
-                }
1056
-            }
1057
-        }
1058
-    }
1059
-
1060
-
1061
-    /**
1062
-     *    perform_activations_upgrades_and_migrations
1063
-     *
1064
-     * @access public
1065
-     * @return    void
1066
-     */
1067
-    public function perform_activations_upgrades_and_migrations()
1068
-    {
1069
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1070
-    }
1071
-
1072
-
1073
-    /**
1074
-     * @return void
1075
-     * @throws DomainException
1076
-     */
1077
-    public function load_CPTs_and_session()
1078
-    {
1079
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1080
-        $this->register_custom_taxonomies->registerCustomTaxonomies();
1081
-        $this->register_custom_post_types->registerCustomPostTypes();
1082
-        $this->register_custom_taxonomy_terms->registerCustomTaxonomyTerms();
1083
-        // load legacy Custom Post Types and Taxonomies
1084
-        $this->loader->getShared('EE_Register_CPTs');
1085
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1086
-    }
1087
-
1088
-
1089
-    /**
1090
-     * load_controllers
1091
-     * this is the best place to load any additional controllers that needs access to EE core.
1092
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1093
-     * time
1094
-     *
1095
-     * @access public
1096
-     * @return void
1097
-     * @throws Exception
1098
-     */
1099
-    public function load_controllers()
1100
-    {
1101
-        do_action('AHEE__EE_System__load_controllers__start');
1102
-        $this->router->loadControllers();
1103
-        do_action('AHEE__EE_System__load_controllers__complete');
1104
-    }
1105
-
1106
-
1107
-    /**
1108
-     * core_loaded_and_ready
1109
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1110
-     *
1111
-     * @access public
1112
-     * @return void
1113
-     * @throws Exception
1114
-     */
1115
-    public function core_loaded_and_ready()
1116
-    {
1117
-        $this->router->coreLoadedAndReady();
1118
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1119
-        // always load template tags, because it's faster than checking if it's a front-end request, and many page
1120
-        // builders require these even on the front-end
1121
-        require_once EE_PUBLIC . 'template_tags.php';
1122
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1123
-    }
1124
-
1125
-
1126
-    /**
1127
-     * initialize
1128
-     * this is the best place to begin initializing client code
1129
-     *
1130
-     * @access public
1131
-     * @return void
1132
-     */
1133
-    public function initialize()
1134
-    {
1135
-        do_action('AHEE__EE_System__initialize');
1136
-        add_filter(
1137
-            'safe_style_css',
1138
-            function ($styles) {
1139
-                $styles[] = 'display';
1140
-                $styles[] = 'visibility';
1141
-                $styles[] = 'position';
1142
-                $styles[] = 'top';
1143
-                $styles[] = 'right';
1144
-                $styles[] = 'bottom';
1145
-                $styles[] = 'left';
1146
-                $styles[] = 'resize';
1147
-                $styles[] = 'max-width';
1148
-                $styles[] = 'max-height';
1149
-                return $styles;
1150
-            }
1151
-        );
1152
-    }
1153
-
1154
-
1155
-    /**
1156
-     * initialize_last
1157
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1158
-     * initialize has done so
1159
-     *
1160
-     * @access public
1161
-     * @return void
1162
-     * @throws Exception
1163
-     */
1164
-    public function initialize_last()
1165
-    {
1166
-        $this->router->initializeLast();
1167
-        do_action('AHEE__EE_System__initialize_last');
1168
-        /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1169
-        $rewrite_rules = $this->loader->getShared(
1170
-            'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1171
-        );
1172
-        $rewrite_rules->flushRewriteRules();
1173
-        add_action('admin_bar_init', [$this, 'addEspressoToolbar']);
1174
-    }
1175
-
1176
-
1177
-    /**
1178
-     * @return void
1179
-     */
1180
-    public function addEspressoToolbar()
1181
-    {
1182
-        $this->loader->getShared(
1183
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1184
-            [$this->registry->CAP]
1185
-        );
1186
-    }
1187
-
1188
-
1189
-    /**
1190
-     * do_not_cache
1191
-     * sets no cache headers and defines no cache constants for WP plugins
1192
-     *
1193
-     * @access public
1194
-     * @return void
1195
-     */
1196
-    public static function do_not_cache()
1197
-    {
1198
-        // set no cache constants
1199
-        if (! defined('DONOTCACHEPAGE')) {
1200
-            define('DONOTCACHEPAGE', true);
1201
-        }
1202
-        if (! defined('DONOTCACHCEOBJECT')) {
1203
-            define('DONOTCACHCEOBJECT', true);
1204
-        }
1205
-        if (! defined('DONOTCACHEDB')) {
1206
-            define('DONOTCACHEDB', true);
1207
-        }
1208
-        // add no cache headers
1209
-        add_action('send_headers', ['EE_System', 'nocache_headers'], 10);
1210
-        // plus a little extra for nginx and Google Chrome
1211
-        add_filter('nocache_headers', ['EE_System', 'extra_nocache_headers'], 10, 1);
1212
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1213
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1214
-    }
1215
-
1216
-
1217
-    /**
1218
-     *    extra_nocache_headers
1219
-     *
1220
-     * @access    public
1221
-     * @param $headers
1222
-     * @return    array
1223
-     */
1224
-    public static function extra_nocache_headers($headers): array
1225
-    {
1226
-        // for NGINX
1227
-        $headers['X-Accel-Expires'] = 0;
1228
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1229
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1230
-        return $headers;
1231
-    }
1232
-
1233
-
1234
-    /**
1235
-     *    nocache_headers
1236
-     *
1237
-     * @access    public
1238
-     * @return    void
1239
-     */
1240
-    public static function nocache_headers()
1241
-    {
1242
-        nocache_headers();
1243
-    }
1244
-
1245
-
1246
-    /**
1247
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1248
-     * never returned with the function.
1249
-     *
1250
-     * @param array $exclude_array any existing pages being excluded are in this array.
1251
-     * @return array
1252
-     */
1253
-    public function remove_pages_from_wp_list_pages(array $exclude_array): array
1254
-    {
1255
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1256
-    }
27
+	/**
28
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
29
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
30
+	 */
31
+	const req_type_normal = 0;
32
+
33
+	/**
34
+	 * Indicates this is a brand new installation of EE so we should install
35
+	 * tables and default data etc
36
+	 */
37
+	const req_type_new_activation = 1;
38
+
39
+	/**
40
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
41
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
42
+	 * and that default data is setup too
43
+	 */
44
+	const req_type_reactivation = 2;
45
+
46
+	/**
47
+	 * indicates that EE has been upgraded since its previous request.
48
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
49
+	 */
50
+	const req_type_upgrade = 3;
51
+
52
+	/**
53
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
54
+	 */
55
+	const req_type_downgrade = 4;
56
+
57
+	/**
58
+	 * @deprecated since version 4.6.0.dev.006
59
+	 * Now whenever a new_activation is detected the request type is still just
60
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we're in maintenance mode
61
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
62
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
63
+	 * (Specifically, when the migration manager indicates migrations are finished
64
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
65
+	 */
66
+	const req_type_activation_but_not_installed = 5;
67
+
68
+	/**
69
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
70
+	 */
71
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
72
+
73
+	/**
74
+	 * @var AddonManager $addon_manager
75
+	 */
76
+	private $addon_manager;
77
+
78
+	/**
79
+	 * @var EE_System $_instance
80
+	 */
81
+	private static $_instance;
82
+
83
+	/**
84
+	 * @var EE_Registry $registry
85
+	 */
86
+	private $registry;
87
+
88
+	/**
89
+	 * @var LoaderInterface $loader
90
+	 */
91
+	private $loader;
92
+
93
+	/**
94
+	 * @var EE_Capabilities $capabilities
95
+	 */
96
+	private $capabilities;
97
+
98
+	/**
99
+	 * @var EE_Maintenance_Mode $maintenance_mode
100
+	 */
101
+	private $maintenance_mode;
102
+
103
+	/**
104
+	 * @var RequestInterface $request
105
+	 */
106
+	private $request;
107
+
108
+	/**
109
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
110
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
111
+	 *
112
+	 * @var int $_req_type
113
+	 */
114
+	private $_req_type;
115
+
116
+	/**
117
+	 * Whether or not there was a non-micro version change in EE core version during this request
118
+	 *
119
+	 * @var boolean $_major_version_change
120
+	 */
121
+	private $_major_version_change = false;
122
+
123
+	/**
124
+	 * @var Router $router
125
+	 */
126
+	private $router;
127
+
128
+	/**
129
+	 * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes
130
+	 */
131
+	private $register_custom_post_types;
132
+
133
+	/**
134
+	 * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies
135
+	 */
136
+	private $register_custom_taxonomies;
137
+
138
+	/**
139
+	 * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms
140
+	 */
141
+	private $register_custom_taxonomy_terms;
142
+
143
+	/**
144
+	 * @singleton method used to instantiate class object
145
+	 * @param LoaderInterface|null     $loader
146
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
147
+	 * @param EE_Registry|null         $registry
148
+	 * @param RequestInterface|null    $request
149
+	 * @param Router|null              $router
150
+	 * @return EE_System
151
+	 */
152
+	public static function instance(
153
+		LoaderInterface $loader = null,
154
+		EE_Maintenance_Mode $maintenance_mode = null,
155
+		EE_Registry $registry = null,
156
+		RequestInterface $request = null,
157
+		Router $router = null
158
+	): EE_System {
159
+		// check if class object is instantiated
160
+		if (! self::$_instance instanceof EE_System) {
161
+			self::$_instance = new self($loader, $maintenance_mode, $registry, $request, $router);
162
+		}
163
+		return self::$_instance;
164
+	}
165
+
166
+
167
+	/**
168
+	 * resets the instance and returns it
169
+	 *
170
+	 * @return EE_System
171
+	 */
172
+	public static function reset(): EE_System
173
+	{
174
+		self::$_instance->_req_type = null;
175
+		// make sure none of the old hooks are left hanging around
176
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
177
+		// we need to reset the migration manager in order for it to detect DMSs properly
178
+		EE_Data_Migration_Manager::reset();
179
+		self::instance()->detect_activations_or_upgrades();
180
+		self::instance()->perform_activations_upgrades_and_migrations();
181
+		return self::instance();
182
+	}
183
+
184
+
185
+	/**
186
+	 * sets hooks for running rest of system
187
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
188
+	 * starting EE Addons from any other point may lead to problems
189
+	 *
190
+	 * @param LoaderInterface     $loader
191
+	 * @param EE_Maintenance_Mode $maintenance_mode
192
+	 * @param EE_Registry         $registry
193
+	 * @param RequestInterface    $request
194
+	 * @param Router              $router
195
+	 */
196
+	private function __construct(
197
+		LoaderInterface $loader,
198
+		EE_Maintenance_Mode $maintenance_mode,
199
+		EE_Registry $registry,
200
+		RequestInterface $request,
201
+		Router $router
202
+	) {
203
+		$this->registry         = $registry;
204
+		$this->loader           = $loader;
205
+		$this->request          = $request;
206
+		$this->router           = $router;
207
+		$this->maintenance_mode = $maintenance_mode;
208
+		do_action('AHEE__EE_System__construct__begin', $this);
209
+		add_action(
210
+			'AHEE__EE_Bootstrap__load_espresso_addons',
211
+			[$this, 'loadCapabilities'],
212
+			5
213
+		);
214
+		add_action(
215
+			'AHEE__EE_Bootstrap__load_espresso_addons',
216
+			[$this, 'loadCommandBus'],
217
+			7
218
+		);
219
+		add_action(
220
+			'AHEE__EE_Bootstrap__load_espresso_addons',
221
+			[$this, 'loadPluginApi'],
222
+			9
223
+		);
224
+		// give caff stuff a chance to play during the activation process too.
225
+		add_action(
226
+			'AHEE__EE_Bootstrap__load_espresso_addons',
227
+			[$this, 'brewCaffeinated'],
228
+			9
229
+		);
230
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
231
+		add_action(
232
+			'AHEE__EE_Bootstrap__load_espresso_addons',
233
+			[$this, 'load_espresso_addons']
234
+		);
235
+		// when an ee addon is activated, we want to call the core hook(s) again
236
+		// because the newly-activated addon didn't get a chance to run at all
237
+		add_action('activate_plugin', [$this, 'load_espresso_addons'], 1);
238
+		// detect whether install or upgrade
239
+		add_action(
240
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
241
+			[$this, 'detect_activations_or_upgrades'],
242
+			3
243
+		);
244
+		// load EE_Config, EE_Textdomain, etc
245
+		add_action(
246
+			'AHEE__EE_Bootstrap__load_core_configuration',
247
+			[$this, 'load_core_configuration'],
248
+			5
249
+		);
250
+		// load specifications for matching routes to current request
251
+		add_action(
252
+			'AHEE__EE_Bootstrap__load_core_configuration',
253
+			[$this, 'loadRouteMatchSpecifications']
254
+		);
255
+		// load specifications for custom post types
256
+		add_action(
257
+			'AHEE__EE_Bootstrap__load_core_configuration',
258
+			array($this, 'loadCustomPostTypes')
259
+		);
260
+		// load specifications for custom post types
261
+		add_action(
262
+			'AHEE__EE_Bootstrap__load_core_configuration',
263
+			array($this, 'loadCustomPostTypes')
264
+		);
265
+		// load EE_Config, EE_Textdomain, etc
266
+		add_action(
267
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
268
+			[$this, 'register_shortcodes_modules_and_widgets'],
269
+			7
270
+		);
271
+		// you wanna get going? I wanna get going... let's get going!
272
+		add_action(
273
+			'AHEE__EE_Bootstrap__brew_espresso',
274
+			[$this, 'brew_espresso'],
275
+			9
276
+		);
277
+		// other housekeeping
278
+		// exclude EE critical pages from wp_list_pages
279
+		add_filter(
280
+			'wp_list_pages_excludes',
281
+			[$this, 'remove_pages_from_wp_list_pages'],
282
+			10
283
+		);
284
+		// ALL EE Addons should use the following hook point to attach their initial setup too
285
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
286
+		do_action('AHEE__EE_System__construct__complete', $this);
287
+	}
288
+
289
+
290
+	/**
291
+	 * load and setup EE_Capabilities
292
+	 *
293
+	 * @return void
294
+	 */
295
+	public function loadCapabilities()
296
+	{
297
+		$this->capabilities = $this->loader->getShared('EE_Capabilities');
298
+		add_action(
299
+			'AHEE__EE_Capabilities__init_caps__before_initialization',
300
+			function () {
301
+				LoaderFactory::getLoader()->getShared('EventEspresso\PaymentMethods\Manager');
302
+				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
303
+			}
304
+		);
305
+	}
306
+
307
+
308
+	/**
309
+	 * create and cache the CommandBus, and also add middleware
310
+	 * The CapChecker middleware requires the use of EE_Capabilities
311
+	 * which is why we need to load the CommandBus after Caps are set up
312
+	 * CommandBus middleware operate FIFO - First In First Out
313
+	 * so LocateMovedCommands will run first in order to return any new commands
314
+	 *
315
+	 * @return void
316
+	 */
317
+	public function loadCommandBus()
318
+	{
319
+		$this->loader->getShared(
320
+			'CommandBusInterface',
321
+			[
322
+				null,
323
+				apply_filters(
324
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
325
+					[
326
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\LocateMovedCommands'),
327
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
328
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
329
+					]
330
+				),
331
+			]
332
+		);
333
+	}
334
+
335
+
336
+	/**
337
+	 * @return void
338
+	 * @throws Exception
339
+	 */
340
+	public function loadPluginApi()
341
+	{
342
+		$this->addon_manager = $this->loader->getShared(AddonManager::class);
343
+		$this->addon_manager->initialize();
344
+		$this->loader->getShared('EE_Request_Handler');
345
+	}
346
+
347
+
348
+	/**
349
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
350
+	 * that need to be setup before our EE_System launches.
351
+	 *
352
+	 * @return void
353
+	 * @throws DomainException
354
+	 * @throws InvalidArgumentException
355
+	 * @throws InvalidDataTypeException
356
+	 * @throws InvalidInterfaceException
357
+	 * @throws InvalidClassException
358
+	 * @throws InvalidFilePathException
359
+	 * @throws EE_Error
360
+	 */
361
+	public function brewCaffeinated()
362
+	{
363
+		static $brew;
364
+		/** @var Domain $domain */
365
+		$domain = DomainFactory::getEventEspressoCoreDomain();
366
+		if ($domain->isCaffeinated() && ! $brew instanceof EE_Brewing_Regular) {
367
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
368
+			/** @var EE_Brewing_Regular $brew */
369
+			$brew = LoaderFactory::getLoader()->getShared(EE_Brewing_Regular::class);
370
+			$brew->initializePUE();
371
+			add_action(
372
+				'AHEE__EE_System__load_core_configuration__begin',
373
+				[$brew, 'caffeinated']
374
+			);
375
+		}
376
+	}
377
+
378
+
379
+	/**
380
+	 * load_espresso_addons
381
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
382
+	 * this is hooked into both:
383
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
384
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
385
+	 *    and the WP 'activate_plugin' hook point
386
+	 *
387
+	 * @return void
388
+	 * @throws Exception
389
+	 */
390
+	public function load_espresso_addons()
391
+	{
392
+		// looking for hooks? they've been moved into the AddonManager to maintain compatibility
393
+		$this->addon_manager->loadAddons();
394
+	}
395
+
396
+
397
+	/**
398
+	 * detect_activations_or_upgrades
399
+	 * Checks for activation or upgrade of core first;
400
+	 * then also checks if any registered addons have been activated or upgraded
401
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
402
+	 * which runs during the WP 'plugins_loaded' action at priority 3
403
+	 *
404
+	 * @access public
405
+	 * @return void
406
+	 */
407
+	public function detect_activations_or_upgrades()
408
+	{
409
+		// first off: let's make sure to handle core
410
+		$this->detect_if_activation_or_upgrade();
411
+		foreach ($this->registry->addons as $addon) {
412
+			if ($addon instanceof EE_Addon) {
413
+				// detect teh request type for that addon
414
+				$addon->detect_req_type();
415
+			}
416
+		}
417
+	}
418
+
419
+
420
+	/**
421
+	 * detect_if_activation_or_upgrade
422
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
423
+	 * and either setting up the DB or setting up maintenance mode etc.
424
+	 *
425
+	 * @access public
426
+	 * @return void
427
+	 */
428
+	public function detect_if_activation_or_upgrade()
429
+	{
430
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
431
+		// check if db has been updated, or if its a brand-new installation
432
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
433
+		$request_type       = $this->detect_req_type($espresso_db_update);
434
+		// EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
435
+		switch ($request_type) {
436
+			case EE_System::req_type_new_activation:
437
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
438
+				$this->_handle_core_version_change($espresso_db_update);
439
+				break;
440
+			case EE_System::req_type_reactivation:
441
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
442
+				$this->_handle_core_version_change($espresso_db_update);
443
+				break;
444
+			case EE_System::req_type_upgrade:
445
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
446
+				// migrations may be required now that we've upgraded
447
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
448
+				$this->_handle_core_version_change($espresso_db_update);
449
+				break;
450
+			case EE_System::req_type_downgrade:
451
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
452
+				// its possible migrations are no longer required
453
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
454
+				$this->_handle_core_version_change($espresso_db_update);
455
+				break;
456
+			case EE_System::req_type_normal:
457
+			default:
458
+				break;
459
+		}
460
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
461
+	}
462
+
463
+
464
+	/**
465
+	 * Updates the list of installed versions and sets hooks for
466
+	 * initializing the database later during the request
467
+	 *
468
+	 * @param array $espresso_db_update
469
+	 */
470
+	private function _handle_core_version_change(array $espresso_db_update)
471
+	{
472
+		$this->update_list_of_installed_versions($espresso_db_update);
473
+		// get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
474
+		add_action(
475
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
476
+			[$this, 'initialize_db_if_no_migrations_required']
477
+		);
478
+	}
479
+
480
+
481
+	/**
482
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
483
+	 * information about what versions of EE have been installed and activated,
484
+	 * NOT necessarily the state of the database
485
+	 *
486
+	 * @param mixed $espresso_db_update           the value of the WordPress option.
487
+	 *                                            If not supplied, fetches it from the options table
488
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
489
+	 */
490
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null): array
491
+	{
492
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
493
+		if (! $espresso_db_update) {
494
+			$espresso_db_update = get_option('espresso_db_update');
495
+		}
496
+		// check that option is an array
497
+		if (! is_array($espresso_db_update)) {
498
+			// if option is FALSE, then it never existed
499
+			if ($espresso_db_update === false) {
500
+				// make $espresso_db_update an array and save option with autoload OFF
501
+				$espresso_db_update = [];
502
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
503
+			} else {
504
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
505
+				$espresso_db_update = [$espresso_db_update => []];
506
+				update_option('espresso_db_update', $espresso_db_update);
507
+			}
508
+		} else {
509
+			$corrected_db_update = [];
510
+			// if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
511
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
512
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
513
+					// the key is an int, and the value IS NOT an array
514
+					// so it must be numerically-indexed, where values are versions installed...
515
+					// fix it!
516
+					$version_string                         = $should_be_array;
517
+					$corrected_db_update[ $version_string ] = ['unknown-date'];
518
+				} else {
519
+					// ok it checks out
520
+					$corrected_db_update[ $should_be_version_string ] = $should_be_array;
521
+				}
522
+			}
523
+			$espresso_db_update = $corrected_db_update;
524
+			update_option('espresso_db_update', $espresso_db_update);
525
+		}
526
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
527
+		return ! empty($espresso_db_update) ? $espresso_db_update : [];
528
+	}
529
+
530
+
531
+	/**
532
+	 * Does the traditional work of setting up the plugin's database and adding default data.
533
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
534
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
535
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
536
+	 * so that it will be done when migrations are finished
537
+	 *
538
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
539
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
540
+	 *                                       This is a resource-intensive job
541
+	 *                                       so we prefer to only do it when necessary
542
+	 * @return void
543
+	 * @throws EE_Error
544
+	 * @throws ReflectionException
545
+	 */
546
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
547
+	{
548
+		$request_type = $this->detect_req_type();
549
+		// only initialize system if we're not in maintenance mode.
550
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
551
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
552
+			$rewrite_rules = $this->loader->getShared(
553
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
554
+			);
555
+			$rewrite_rules->flush();
556
+			if ($verify_schema) {
557
+				EEH_Activation::initialize_db_and_folders();
558
+			}
559
+			EEH_Activation::initialize_db_content();
560
+			EEH_Activation::system_initialization();
561
+			if ($initialize_addons_too) {
562
+				$this->initialize_addons();
563
+			}
564
+		} else {
565
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
566
+		}
567
+		if (
568
+			$request_type === EE_System::req_type_new_activation
569
+			|| $request_type === EE_System::req_type_reactivation
570
+			|| (
571
+				$request_type === EE_System::req_type_upgrade
572
+				&& $this->is_major_version_change()
573
+			)
574
+		) {
575
+			add_action('AHEE__EE_System__initialize_last', [$this, 'redirect_to_about_ee'], 9);
576
+		}
577
+	}
578
+
579
+
580
+	/**
581
+	 * Initializes the db for all registered addons
582
+	 *
583
+	 * @throws EE_Error
584
+	 * @throws ReflectionException
585
+	 */
586
+	public function initialize_addons()
587
+	{
588
+		// foreach registered addon, make sure its db is up-to-date too
589
+		foreach ($this->registry->addons as $addon) {
590
+			if ($addon instanceof EE_Addon) {
591
+				$addon->initialize_db_if_no_migrations_required();
592
+			}
593
+		}
594
+	}
595
+
596
+
597
+	/**
598
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
599
+	 *
600
+	 * @param array  $version_history
601
+	 * @param string $current_version_to_add version to be added to the version history
602
+	 * @return    boolean success as to whether or not this option was changed
603
+	 */
604
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null): bool
605
+	{
606
+		if (! $version_history) {
607
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
608
+		}
609
+		if ($current_version_to_add === null) {
610
+			$current_version_to_add = espresso_version();
611
+		}
612
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
613
+		// re-save
614
+		return update_option('espresso_db_update', $version_history);
615
+	}
616
+
617
+
618
+	/**
619
+	 * Detects if the current version indicated in the has existed in the list of
620
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
621
+	 *
622
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
623
+	 *                                  If not supplied, fetches it from the options table.
624
+	 *                                  Also, caches its result so later parts of the code can also know whether
625
+	 *                                  there's been an update or not. This way we can add the current version to
626
+	 *                                  espresso_db_update, but still know if this is a new install or not
627
+	 * @return int one of the constants on EE_System::req_type_
628
+	 */
629
+	public function detect_req_type($espresso_db_update = null): int
630
+	{
631
+		if ($this->_req_type === null) {
632
+			$espresso_db_update          = ! empty($espresso_db_update)
633
+				? $espresso_db_update
634
+				: $this->fix_espresso_db_upgrade_option();
635
+			$this->_req_type             = EE_System::detect_req_type_given_activation_history(
636
+				$espresso_db_update,
637
+				'ee_espresso_activation',
638
+				espresso_version()
639
+			);
640
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
641
+			$this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
642
+		}
643
+		return $this->_req_type;
644
+	}
645
+
646
+
647
+	/**
648
+	 * Returns whether or not there was a non-micro version change (ie, change in either
649
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
650
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
651
+	 *
652
+	 * @param $activation_history
653
+	 * @return bool
654
+	 */
655
+	private function _detect_major_version_change($activation_history): bool
656
+	{
657
+		$previous_version       = EE_System::getMostRecentlyActiveVersion($activation_history);
658
+		$previous_version_parts = explode('.', $previous_version);
659
+		$current_version_parts  = explode('.', espresso_version());
660
+		return isset(
661
+			$previous_version_parts[0],
662
+			$previous_version_parts[1],
663
+			$current_version_parts[0],
664
+			$current_version_parts[1]
665
+		) && (
666
+			$previous_version_parts[0] !== $current_version_parts[0]
667
+			|| $previous_version_parts[1] !== $current_version_parts[1]
668
+		);
669
+	}
670
+
671
+
672
+	/**
673
+	 * Returns true if either the major or minor version of EE changed during this request.
674
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
675
+	 *
676
+	 * @return bool
677
+	 */
678
+	public function is_major_version_change(): bool
679
+	{
680
+		return $this->_major_version_change;
681
+	}
682
+
683
+
684
+	/**
685
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
686
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
687
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
688
+	 * just activated to (for core that will always be espresso_version())
689
+	 *
690
+	 * @param array|null $activation_history             the option's value which stores the activation history for
691
+	 *                                                 this
692
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
693
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
694
+	 *                                                 indicate that this plugin was just activated
695
+	 * @param string $current_version                  the version that was just upgraded to (for core that will be
696
+	 *                                                 espresso_version())
697
+	 * @return int one of the constants on EE_System::req_type_
698
+	 */
699
+	public static function detect_req_type_given_activation_history(
700
+		array $activation_history,
701
+		string $activation_indicator_option_name,
702
+		string $current_version
703
+	): int {
704
+		$version_change = self::compareVersionWithPrevious($activation_history, $current_version);
705
+		$is_activation  = get_option($activation_indicator_option_name, false);
706
+		$req_type       = self::getRequestType($activation_history, $version_change, $is_activation);
707
+		if ($is_activation) {
708
+			// cleanup in aisle 6
709
+			delete_option($activation_indicator_option_name);
710
+		}
711
+		return $req_type;
712
+	}
713
+
714
+
715
+	/**
716
+	 * @param array  $activation_history
717
+	 * @param int    $version_change
718
+	 * @param bool   $is_activation
719
+	 * @return int
720
+	 * @since 5.0.0.p
721
+	 */
722
+	private static function getRequestType(array $activation_history, int $version_change, bool $is_activation): int
723
+	{
724
+		// if no previous activation history exists, then this is a brand new install
725
+		if (empty($activation_history)) {
726
+			return EE_System::req_type_new_activation;
727
+		}
728
+		// current version is higher than previous version, so it's an upgrade
729
+		if ($version_change === 1) {
730
+			return EE_System::req_type_upgrade;
731
+		}
732
+		// current version is lower than previous version, so it's a downgrade
733
+		if ($version_change === -1) {
734
+			return EE_System::req_type_downgrade;
735
+		}
736
+		// version hasn't changed since last version so check if the activation indicator is set
737
+		// to determine if it's a reactivation, or just a normal request
738
+		return $is_activation
739
+			? EE_System::req_type_reactivation
740
+			: EE_System::req_type_normal;
741
+	}
742
+
743
+
744
+	/**
745
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
746
+	 * the $activation_history_for_addon
747
+	 *
748
+	 * @param array  $activation_history    array where keys are versions,
749
+	 *                                      values are arrays of times activated (sometimes 'unknown-date')
750
+	 * @param string $current_version
751
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
752
+	 *                                      -1 if $version_to_upgrade_to is LOWER (downgrade);
753
+	 *                                      0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
754
+	 *                                      1 if $version_to_upgrade_to is HIGHER (upgrade) ;
755
+	 */
756
+	private static function compareVersionWithPrevious(array $activation_history, string $current_version): int
757
+	{
758
+		// find the most recently-activated version
759
+		$most_recently_active_version = EE_System::getMostRecentlyActiveVersion($activation_history);
760
+		return version_compare($current_version, $most_recently_active_version);
761
+	}
762
+
763
+
764
+	/**
765
+	 * Gets the most recently active version listed in the activation history,
766
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
767
+	 *
768
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
769
+	 *                                   sometimes containing 'unknown-date'
770
+	 * @return string
771
+	 */
772
+	private static function getMostRecentlyActiveVersion(array $activation_history): string
773
+	{
774
+		$most_recent_activation_date  = '1970-01-01 00:00:00';
775
+		$most_recently_active_version = '0.0.0.dev.000';
776
+		if (is_array($activation_history)) {
777
+			foreach ($activation_history as $version => $activation_dates) {
778
+				// check there is a record of when this version was activated.
779
+				// Otherwise, mark it as unknown
780
+				if (! $activation_dates) {
781
+					$activation_dates = ['unknown-date'];
782
+				}
783
+				$activation_dates = is_string($activation_dates) ? [$activation_dates] : $activation_dates;
784
+				foreach ($activation_dates as $activation_date) {
785
+					if ($activation_date !== 'unknown-date' && $activation_date > $most_recent_activation_date) {
786
+						$most_recently_active_version = $version;
787
+						$most_recent_activation_date  = $activation_date;
788
+					}
789
+				}
790
+			}
791
+		}
792
+		return $most_recently_active_version;
793
+	}
794
+
795
+
796
+	/**
797
+	 * This redirects to the about EE page after activation
798
+	 *
799
+	 * @return void
800
+	 */
801
+	public function redirect_to_about_ee()
802
+	{
803
+		$notices = EE_Error::get_notices(false);
804
+		// if current user is an admin and it's not an ajax or rest request
805
+		if (
806
+			! isset($notices['errors'])
807
+			&& $this->request->isAdmin()
808
+			&& apply_filters(
809
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
810
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
811
+			)
812
+		) {
813
+			$query_params = ['page' => 'espresso_about'];
814
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
815
+				$query_params['new_activation'] = true;
816
+			}
817
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
818
+				$query_params['reactivation'] = true;
819
+			}
820
+			$url = add_query_arg($query_params, admin_url('admin.php'));
821
+			EEH_URL::safeRedirectAndExit($url);
822
+		}
823
+	}
824
+
825
+
826
+	/**
827
+	 * load_core_configuration
828
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
829
+	 * which runs during the WP 'plugins_loaded' action at priority 5
830
+	 *
831
+	 * @return void
832
+	 * @throws ReflectionException
833
+	 * @throws Exception
834
+	 */
835
+	public function load_core_configuration()
836
+	{
837
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
838
+		$this->loader->getShared('EE_Load_Textdomain');
839
+		// load textdomain
840
+		EE_Load_Textdomain::load_textdomain();
841
+		// load and setup EE_Config and EE_Network_Config
842
+		$config = $this->loader->getShared('EE_Config');
843
+		$this->loader->getShared('EE_Network_Config');
844
+		// setup autoloaders
845
+		// enable logging?
846
+		$this->loader->getShared('EventEspresso\core\services\orm\TrashLogger');
847
+		if ($config->admin->use_remote_logging) {
848
+			$this->loader->getShared('EE_Log');
849
+		}
850
+		// check for activation errors
851
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
852
+		if ($activation_errors) {
853
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
854
+			update_option('ee_plugin_activation_errors', false);
855
+		}
856
+		// get model names
857
+		$this->_parse_model_names();
858
+		// configure custom post type definitions
859
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
860
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
861
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
862
+	}
863
+
864
+
865
+	/**
866
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
867
+	 *
868
+	 * @return void
869
+	 * @throws ReflectionException
870
+	 */
871
+	private function _parse_model_names()
872
+	{
873
+		// get all the files in the EE_MODELS folder that end in .model.php
874
+		$models                 = glob(EE_MODELS . '*.model.php');
875
+		$model_names            = [];
876
+		$non_abstract_db_models = [];
877
+		foreach ($models as $model) {
878
+			// get model classname
879
+			$classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
880
+			$short_name      = str_replace('EEM_', '', $classname);
881
+			$reflectionClass = new ReflectionClass($classname);
882
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
883
+				$non_abstract_db_models[ $short_name ] = $classname;
884
+			}
885
+			$model_names[ $short_name ] = $classname;
886
+		}
887
+		$this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
888
+		$this->registry->non_abstract_db_models = apply_filters(
889
+			'FHEE__EE_System__parse_implemented_model_names',
890
+			$non_abstract_db_models
891
+		);
892
+	}
893
+
894
+
895
+	/**
896
+	 * @throws Exception
897
+	 * @since 4.9.71.p
898
+	 */
899
+	public function loadRouteMatchSpecifications()
900
+	{
901
+		try {
902
+			$this->loader->getShared('EventEspresso\core\services\routing\RouteMatchSpecificationManager');
903
+			$this->loader->getShared('EventEspresso\core\services\routing\RouteCollection');
904
+			$this->router->loadPrimaryRoutes();
905
+		} catch (Exception $exception) {
906
+			new ExceptionStackTraceDisplay($exception);
907
+		}
908
+		do_action('AHEE__EE_System__loadRouteMatchSpecifications');
909
+	}
910
+
911
+
912
+	/**
913
+	 * loading CPT related classes earlier so that their definitions are available
914
+	 * but not performing any actual registration with WP core until load_CPTs_and_session() is called
915
+	 *
916
+	 * @since   4.10.21.p
917
+	 */
918
+	public function loadCustomPostTypes()
919
+	{
920
+		$this->register_custom_taxonomies = $this->loader->getShared(
921
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
922
+		);
923
+		$this->register_custom_post_types = $this->loader->getShared(
924
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
925
+		);
926
+		$this->register_custom_taxonomy_terms = $this->loader->getShared(
927
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
928
+		);
929
+		// integrate WP_Query with the EE models
930
+		$this->loader->getShared('EE_CPT_Strategy');
931
+		// load legacy EE_Request_Handler in case add-ons still need it
932
+		$this->loader->getShared('EE_Request_Handler');
933
+	}
934
+
935
+
936
+	/**
937
+	 * register_shortcodes_modules_and_widgets
938
+	 * generate lists of shortcodes and modules, then verify paths and classes
939
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
940
+	 * which runs during the WP 'plugins_loaded' action at priority 7
941
+	 *
942
+	 * @access public
943
+	 * @return void
944
+	 * @throws Exception
945
+	 */
946
+	public function register_shortcodes_modules_and_widgets()
947
+	{
948
+		$this->router->registerShortcodesModulesAndWidgets();
949
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
950
+		// check for addons using old hook point
951
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
952
+			$this->_incompatible_addon_error();
953
+		}
954
+	}
955
+
956
+
957
+	/**
958
+	 * _incompatible_addon_error
959
+	 *
960
+	 * @access public
961
+	 * @return void
962
+	 */
963
+	private function _incompatible_addon_error()
964
+	{
965
+		// get array of classes hooking into here
966
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
967
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
968
+		);
969
+		if (! empty($class_names)) {
970
+			$msg = esc_html__(
971
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
972
+				'event_espresso'
973
+			);
974
+			$msg .= '<ul>';
975
+			foreach ($class_names as $class_name) {
976
+				$msg .= '<li><b>Event Espresso - '
977
+						. str_replace(
978
+							['EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'],
979
+							'',
980
+							$class_name
981
+						) . '</b></li>';
982
+			}
983
+			$msg .= '</ul>';
984
+			$msg .= esc_html__(
985
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
986
+				'event_espresso'
987
+			);
988
+			// save list of incompatible addons to wp-options for later use
989
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
990
+			if (is_admin()) {
991
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
992
+			}
993
+		}
994
+	}
995
+
996
+
997
+	/**
998
+	 * brew_espresso
999
+	 * begins the process of setting hooks for initializing EE in the correct order
1000
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1001
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1002
+	 *
1003
+	 * @return void
1004
+	 * @throws Exception
1005
+	 */
1006
+	public function brew_espresso()
1007
+	{
1008
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1009
+		// load some final core systems
1010
+		add_action('init', [$this, 'set_hooks_for_core'], 1);
1011
+		add_action('init', [$this, 'perform_activations_upgrades_and_migrations'], 3);
1012
+		add_action('init', [$this, 'load_CPTs_and_session'], 5);
1013
+		add_action('init', [$this, 'load_controllers'], 7);
1014
+		add_action('init', [$this, 'core_loaded_and_ready'], 9);
1015
+		add_action('init', [$this, 'initialize'], 10);
1016
+		add_action('init', [$this, 'initialize_last'], 100);
1017
+		$this->router->brewEspresso();
1018
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1019
+	}
1020
+
1021
+
1022
+	/**
1023
+	 *    set_hooks_for_core
1024
+	 *
1025
+	 * @access public
1026
+	 * @return    void
1027
+	 * @throws EE_Error
1028
+	 */
1029
+	public function set_hooks_for_core()
1030
+	{
1031
+		$this->_deactivate_incompatible_addons();
1032
+		do_action('AHEE__EE_System__set_hooks_for_core');
1033
+		$this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1034
+		// caps need to be initialized on every request so that capability maps are set.
1035
+		// @see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1036
+		$this->registry->CAP->init_caps();
1037
+	}
1038
+
1039
+
1040
+	/**
1041
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1042
+	 * deactivates any addons considered incompatible with the current version of EE
1043
+	 */
1044
+	private function _deactivate_incompatible_addons()
1045
+	{
1046
+		$incompatible_addons = get_option('ee_incompatible_addons', []);
1047
+		if (! empty($incompatible_addons)) {
1048
+			$active_plugins = get_option('active_plugins', []);
1049
+			foreach ($active_plugins as $active_plugin) {
1050
+				foreach ($incompatible_addons as $incompatible_addon) {
1051
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1052
+						$this->request->unSetRequestParams(['activate'], true);
1053
+						espresso_deactivate_plugin($active_plugin);
1054
+					}
1055
+				}
1056
+			}
1057
+		}
1058
+	}
1059
+
1060
+
1061
+	/**
1062
+	 *    perform_activations_upgrades_and_migrations
1063
+	 *
1064
+	 * @access public
1065
+	 * @return    void
1066
+	 */
1067
+	public function perform_activations_upgrades_and_migrations()
1068
+	{
1069
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1070
+	}
1071
+
1072
+
1073
+	/**
1074
+	 * @return void
1075
+	 * @throws DomainException
1076
+	 */
1077
+	public function load_CPTs_and_session()
1078
+	{
1079
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1080
+		$this->register_custom_taxonomies->registerCustomTaxonomies();
1081
+		$this->register_custom_post_types->registerCustomPostTypes();
1082
+		$this->register_custom_taxonomy_terms->registerCustomTaxonomyTerms();
1083
+		// load legacy Custom Post Types and Taxonomies
1084
+		$this->loader->getShared('EE_Register_CPTs');
1085
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1086
+	}
1087
+
1088
+
1089
+	/**
1090
+	 * load_controllers
1091
+	 * this is the best place to load any additional controllers that needs access to EE core.
1092
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1093
+	 * time
1094
+	 *
1095
+	 * @access public
1096
+	 * @return void
1097
+	 * @throws Exception
1098
+	 */
1099
+	public function load_controllers()
1100
+	{
1101
+		do_action('AHEE__EE_System__load_controllers__start');
1102
+		$this->router->loadControllers();
1103
+		do_action('AHEE__EE_System__load_controllers__complete');
1104
+	}
1105
+
1106
+
1107
+	/**
1108
+	 * core_loaded_and_ready
1109
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1110
+	 *
1111
+	 * @access public
1112
+	 * @return void
1113
+	 * @throws Exception
1114
+	 */
1115
+	public function core_loaded_and_ready()
1116
+	{
1117
+		$this->router->coreLoadedAndReady();
1118
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1119
+		// always load template tags, because it's faster than checking if it's a front-end request, and many page
1120
+		// builders require these even on the front-end
1121
+		require_once EE_PUBLIC . 'template_tags.php';
1122
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1123
+	}
1124
+
1125
+
1126
+	/**
1127
+	 * initialize
1128
+	 * this is the best place to begin initializing client code
1129
+	 *
1130
+	 * @access public
1131
+	 * @return void
1132
+	 */
1133
+	public function initialize()
1134
+	{
1135
+		do_action('AHEE__EE_System__initialize');
1136
+		add_filter(
1137
+			'safe_style_css',
1138
+			function ($styles) {
1139
+				$styles[] = 'display';
1140
+				$styles[] = 'visibility';
1141
+				$styles[] = 'position';
1142
+				$styles[] = 'top';
1143
+				$styles[] = 'right';
1144
+				$styles[] = 'bottom';
1145
+				$styles[] = 'left';
1146
+				$styles[] = 'resize';
1147
+				$styles[] = 'max-width';
1148
+				$styles[] = 'max-height';
1149
+				return $styles;
1150
+			}
1151
+		);
1152
+	}
1153
+
1154
+
1155
+	/**
1156
+	 * initialize_last
1157
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1158
+	 * initialize has done so
1159
+	 *
1160
+	 * @access public
1161
+	 * @return void
1162
+	 * @throws Exception
1163
+	 */
1164
+	public function initialize_last()
1165
+	{
1166
+		$this->router->initializeLast();
1167
+		do_action('AHEE__EE_System__initialize_last');
1168
+		/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1169
+		$rewrite_rules = $this->loader->getShared(
1170
+			'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1171
+		);
1172
+		$rewrite_rules->flushRewriteRules();
1173
+		add_action('admin_bar_init', [$this, 'addEspressoToolbar']);
1174
+	}
1175
+
1176
+
1177
+	/**
1178
+	 * @return void
1179
+	 */
1180
+	public function addEspressoToolbar()
1181
+	{
1182
+		$this->loader->getShared(
1183
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1184
+			[$this->registry->CAP]
1185
+		);
1186
+	}
1187
+
1188
+
1189
+	/**
1190
+	 * do_not_cache
1191
+	 * sets no cache headers and defines no cache constants for WP plugins
1192
+	 *
1193
+	 * @access public
1194
+	 * @return void
1195
+	 */
1196
+	public static function do_not_cache()
1197
+	{
1198
+		// set no cache constants
1199
+		if (! defined('DONOTCACHEPAGE')) {
1200
+			define('DONOTCACHEPAGE', true);
1201
+		}
1202
+		if (! defined('DONOTCACHCEOBJECT')) {
1203
+			define('DONOTCACHCEOBJECT', true);
1204
+		}
1205
+		if (! defined('DONOTCACHEDB')) {
1206
+			define('DONOTCACHEDB', true);
1207
+		}
1208
+		// add no cache headers
1209
+		add_action('send_headers', ['EE_System', 'nocache_headers'], 10);
1210
+		// plus a little extra for nginx and Google Chrome
1211
+		add_filter('nocache_headers', ['EE_System', 'extra_nocache_headers'], 10, 1);
1212
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1213
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1214
+	}
1215
+
1216
+
1217
+	/**
1218
+	 *    extra_nocache_headers
1219
+	 *
1220
+	 * @access    public
1221
+	 * @param $headers
1222
+	 * @return    array
1223
+	 */
1224
+	public static function extra_nocache_headers($headers): array
1225
+	{
1226
+		// for NGINX
1227
+		$headers['X-Accel-Expires'] = 0;
1228
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1229
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1230
+		return $headers;
1231
+	}
1232
+
1233
+
1234
+	/**
1235
+	 *    nocache_headers
1236
+	 *
1237
+	 * @access    public
1238
+	 * @return    void
1239
+	 */
1240
+	public static function nocache_headers()
1241
+	{
1242
+		nocache_headers();
1243
+	}
1244
+
1245
+
1246
+	/**
1247
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1248
+	 * never returned with the function.
1249
+	 *
1250
+	 * @param array $exclude_array any existing pages being excluded are in this array.
1251
+	 * @return array
1252
+	 */
1253
+	public function remove_pages_from_wp_list_pages(array $exclude_array): array
1254
+	{
1255
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1256
+	}
1257 1257
 }
Please login to merge, or discard this patch.
core/domain/DomainBase.php 1 patch
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -16,231 +16,231 @@
 block discarded – undo
16 16
  */
17 17
 abstract class DomainBase implements DomainInterface
18 18
 {
19
-    const ASSETS_FOLDER = 'assets/';
20
-
21
-    /**
22
-     * Equivalent to `__FILE__` for main plugin file.
23
-     *
24
-     * @var FilePath
25
-     */
26
-    private $plugin_file;
27
-
28
-    /**
29
-     * String indicating version for plugin
30
-     *
31
-     * @var string
32
-     */
33
-    private $version;
34
-
35
-    /**
36
-     * @var string $plugin_basename
37
-     */
38
-    private $plugin_basename;
39
-
40
-    /**
41
-     * @var string $plugin_path
42
-     */
43
-    private $plugin_path;
44
-
45
-    /**
46
-     * @var string $plugin_url
47
-     */
48
-    private $plugin_url;
49
-
50
-    /**
51
-     * @var string $asset_namespace
52
-     */
53
-    private $asset_namespace;
54
-
55
-    /**
56
-     * @var string $assets_path
57
-     */
58
-    private $assets_path;
59
-
60
-    /**
61
-     * @var bool
62
-     */
63
-    protected $initialized = false;
64
-
65
-
66
-    /**
67
-     * Initializes internal properties.
68
-     *
69
-     * @param FilePath $plugin_file
70
-     * @param Version  $version
71
-     * @param string $asset_namespace
72
-     */
73
-    public function __construct(
74
-        FilePath $plugin_file,
75
-        Version $version,
76
-        string $asset_namespace = Domain::ASSET_NAMESPACE
77
-    ) {
78
-        $this->plugin_file = $plugin_file;
79
-        $this->version     = $version;
80
-        $this->initialize($asset_namespace);
81
-    }
82
-
83
-
84
-    /**
85
-     * @param string $asset_namespace
86
-     * @return void
87
-     * @since 5.0.0.p
88
-     */
89
-    public function initialize($asset_namespace = Domain::ASSET_NAMESPACE)
90
-    {
91
-        if (! $this->initialized) {
92
-            $this->plugin_basename = plugin_basename($this->pluginFile());
93
-            $this->plugin_path     = plugin_dir_path($this->pluginFile());
94
-            $this->plugin_url      = plugin_dir_url($this->pluginFile());
95
-            $this->setAssetNamespace($asset_namespace);
96
-            $this->setDistributionAssetsPath();
97
-            $this->initialized = true;
98
-        }
99
-    }
100
-
101
-
102
-    /**
103
-     * @param string $asset_namespace
104
-     * @return void
105
-     */
106
-    public function setAssetNamespace($asset_namespace = Domain::ASSET_NAMESPACE)
107
-    {
108
-        if (! $this->asset_namespace) {
109
-            $this->asset_namespace = sanitize_key(
110
-                // convert directory separators to dashes and remove file extension
111
-                str_replace(['/', '.php'], ['-', ''], $asset_namespace)
112
-            );
113
-        }
114
-    }
115
-
116
-
117
-    /**
118
-     * @throws DomainException
119
-     * @since 5.0.0.p
120
-     */
121
-    private function setDistributionAssetsPath()
122
-    {
123
-        $assets_folder_paths = [
124
-            $this->plugin_path . DomainBase::ASSETS_FOLDER,
125
-            $this->plugin_path . 'src/' . DomainBase::ASSETS_FOLDER,
126
-        ];
127
-        foreach ($assets_folder_paths as $assets_folder_path) {
128
-            if (is_readable($assets_folder_path)) {
129
-                $this->assets_path = trailingslashit($assets_folder_path);
130
-                // once we find a valid path, just break out of loop
131
-                break;
132
-            }
133
-        }
134
-    }
135
-
136
-
137
-    /**
138
-     * @return string
139
-     */
140
-    public function pluginFile(): string
141
-    {
142
-        return (string) $this->plugin_file;
143
-    }
144
-
145
-
146
-    /**
147
-     * @return FilePath
148
-     */
149
-    public function pluginFileObject(): FilePath
150
-    {
151
-        return $this->plugin_file;
152
-    }
153
-
154
-
155
-    /**
156
-     * @return string
157
-     */
158
-    public function pluginBasename(): string
159
-    {
160
-        return $this->plugin_basename;
161
-    }
162
-
163
-
164
-    /**
165
-     * @param string $additional_path
166
-     * @return string
167
-     */
168
-    public function pluginPath($additional_path = ''): string
169
-    {
170
-        return is_string($additional_path) && $additional_path !== ''
171
-            ? $this->plugin_path . $additional_path
172
-            : $this->plugin_path;
173
-    }
174
-
175
-
176
-    /**
177
-     * @param string $additional_path
178
-     * @return string
179
-     */
180
-    public function pluginUrl($additional_path = ''): string
181
-    {
182
-        return is_string($additional_path) && $additional_path !== ''
183
-            ? $this->plugin_url . $additional_path
184
-            : $this->plugin_url;
185
-    }
186
-
187
-
188
-    /**
189
-     * @return string
190
-     */
191
-    public function version(): string
192
-    {
193
-        return (string) $this->version;
194
-    }
195
-
196
-
197
-    /**
198
-     * @return Version
199
-     */
200
-    public function versionValueObject()
201
-    {
202
-        return $this->version;
203
-    }
204
-
205
-
206
-    /**
207
-     * @return string
208
-     */
209
-    public function distributionAssetsFolder(): string
210
-    {
211
-        return DomainBase::ASSETS_FOLDER;
212
-    }
213
-
214
-
215
-    /**
216
-     * @param string $additional_path
217
-     * @return string
218
-     */
219
-    public function distributionAssetsPath($additional_path = ''): string
220
-    {
221
-        return is_string($additional_path) && $additional_path !== ''
222
-            ? $this->assets_path . $additional_path
223
-            : $this->assets_path;
224
-    }
225
-
226
-
227
-    /**
228
-     * @param string $additional_path
229
-     * @return string
230
-     */
231
-    public function distributionAssetsUrl($additional_path = ''): string
232
-    {
233
-        return is_string($additional_path) && $additional_path !== ''
234
-            ? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path
235
-            : $this->plugin_url . DomainBase::ASSETS_FOLDER;
236
-    }
237
-
238
-
239
-    /**
240
-     * @return string
241
-     */
242
-    public function assetNamespace(): string
243
-    {
244
-        return $this->asset_namespace;
245
-    }
19
+	const ASSETS_FOLDER = 'assets/';
20
+
21
+	/**
22
+	 * Equivalent to `__FILE__` for main plugin file.
23
+	 *
24
+	 * @var FilePath
25
+	 */
26
+	private $plugin_file;
27
+
28
+	/**
29
+	 * String indicating version for plugin
30
+	 *
31
+	 * @var string
32
+	 */
33
+	private $version;
34
+
35
+	/**
36
+	 * @var string $plugin_basename
37
+	 */
38
+	private $plugin_basename;
39
+
40
+	/**
41
+	 * @var string $plugin_path
42
+	 */
43
+	private $plugin_path;
44
+
45
+	/**
46
+	 * @var string $plugin_url
47
+	 */
48
+	private $plugin_url;
49
+
50
+	/**
51
+	 * @var string $asset_namespace
52
+	 */
53
+	private $asset_namespace;
54
+
55
+	/**
56
+	 * @var string $assets_path
57
+	 */
58
+	private $assets_path;
59
+
60
+	/**
61
+	 * @var bool
62
+	 */
63
+	protected $initialized = false;
64
+
65
+
66
+	/**
67
+	 * Initializes internal properties.
68
+	 *
69
+	 * @param FilePath $plugin_file
70
+	 * @param Version  $version
71
+	 * @param string $asset_namespace
72
+	 */
73
+	public function __construct(
74
+		FilePath $plugin_file,
75
+		Version $version,
76
+		string $asset_namespace = Domain::ASSET_NAMESPACE
77
+	) {
78
+		$this->plugin_file = $plugin_file;
79
+		$this->version     = $version;
80
+		$this->initialize($asset_namespace);
81
+	}
82
+
83
+
84
+	/**
85
+	 * @param string $asset_namespace
86
+	 * @return void
87
+	 * @since 5.0.0.p
88
+	 */
89
+	public function initialize($asset_namespace = Domain::ASSET_NAMESPACE)
90
+	{
91
+		if (! $this->initialized) {
92
+			$this->plugin_basename = plugin_basename($this->pluginFile());
93
+			$this->plugin_path     = plugin_dir_path($this->pluginFile());
94
+			$this->plugin_url      = plugin_dir_url($this->pluginFile());
95
+			$this->setAssetNamespace($asset_namespace);
96
+			$this->setDistributionAssetsPath();
97
+			$this->initialized = true;
98
+		}
99
+	}
100
+
101
+
102
+	/**
103
+	 * @param string $asset_namespace
104
+	 * @return void
105
+	 */
106
+	public function setAssetNamespace($asset_namespace = Domain::ASSET_NAMESPACE)
107
+	{
108
+		if (! $this->asset_namespace) {
109
+			$this->asset_namespace = sanitize_key(
110
+				// convert directory separators to dashes and remove file extension
111
+				str_replace(['/', '.php'], ['-', ''], $asset_namespace)
112
+			);
113
+		}
114
+	}
115
+
116
+
117
+	/**
118
+	 * @throws DomainException
119
+	 * @since 5.0.0.p
120
+	 */
121
+	private function setDistributionAssetsPath()
122
+	{
123
+		$assets_folder_paths = [
124
+			$this->plugin_path . DomainBase::ASSETS_FOLDER,
125
+			$this->plugin_path . 'src/' . DomainBase::ASSETS_FOLDER,
126
+		];
127
+		foreach ($assets_folder_paths as $assets_folder_path) {
128
+			if (is_readable($assets_folder_path)) {
129
+				$this->assets_path = trailingslashit($assets_folder_path);
130
+				// once we find a valid path, just break out of loop
131
+				break;
132
+			}
133
+		}
134
+	}
135
+
136
+
137
+	/**
138
+	 * @return string
139
+	 */
140
+	public function pluginFile(): string
141
+	{
142
+		return (string) $this->plugin_file;
143
+	}
144
+
145
+
146
+	/**
147
+	 * @return FilePath
148
+	 */
149
+	public function pluginFileObject(): FilePath
150
+	{
151
+		return $this->plugin_file;
152
+	}
153
+
154
+
155
+	/**
156
+	 * @return string
157
+	 */
158
+	public function pluginBasename(): string
159
+	{
160
+		return $this->plugin_basename;
161
+	}
162
+
163
+
164
+	/**
165
+	 * @param string $additional_path
166
+	 * @return string
167
+	 */
168
+	public function pluginPath($additional_path = ''): string
169
+	{
170
+		return is_string($additional_path) && $additional_path !== ''
171
+			? $this->plugin_path . $additional_path
172
+			: $this->plugin_path;
173
+	}
174
+
175
+
176
+	/**
177
+	 * @param string $additional_path
178
+	 * @return string
179
+	 */
180
+	public function pluginUrl($additional_path = ''): string
181
+	{
182
+		return is_string($additional_path) && $additional_path !== ''
183
+			? $this->plugin_url . $additional_path
184
+			: $this->plugin_url;
185
+	}
186
+
187
+
188
+	/**
189
+	 * @return string
190
+	 */
191
+	public function version(): string
192
+	{
193
+		return (string) $this->version;
194
+	}
195
+
196
+
197
+	/**
198
+	 * @return Version
199
+	 */
200
+	public function versionValueObject()
201
+	{
202
+		return $this->version;
203
+	}
204
+
205
+
206
+	/**
207
+	 * @return string
208
+	 */
209
+	public function distributionAssetsFolder(): string
210
+	{
211
+		return DomainBase::ASSETS_FOLDER;
212
+	}
213
+
214
+
215
+	/**
216
+	 * @param string $additional_path
217
+	 * @return string
218
+	 */
219
+	public function distributionAssetsPath($additional_path = ''): string
220
+	{
221
+		return is_string($additional_path) && $additional_path !== ''
222
+			? $this->assets_path . $additional_path
223
+			: $this->assets_path;
224
+	}
225
+
226
+
227
+	/**
228
+	 * @param string $additional_path
229
+	 * @return string
230
+	 */
231
+	public function distributionAssetsUrl($additional_path = ''): string
232
+	{
233
+		return is_string($additional_path) && $additional_path !== ''
234
+			? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path
235
+			: $this->plugin_url . DomainBase::ASSETS_FOLDER;
236
+	}
237
+
238
+
239
+	/**
240
+	 * @return string
241
+	 */
242
+	public function assetNamespace(): string
243
+	{
244
+		return $this->asset_namespace;
245
+	}
246 246
 }
Please login to merge, or discard this patch.
core/domain/values/assets/JavascriptAsset.php 1 patch
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -18,172 +18,172 @@
 block discarded – undo
18 18
 class JavascriptAsset extends BrowserAsset
19 19
 {
20 20
 
21
-    /**
22
-     * @var boolean $load_in_footer
23
-     */
24
-    private $load_in_footer = false;
25
-
26
-    /**
27
-     * @var boolean $requires_translation
28
-     */
29
-    private $requires_translation = false;
30
-
31
-    /**
32
-     * @var boolean $has_inline_data
33
-     */
34
-    private $has_inline_data = false;
35
-
36
-    /**
37
-     * @var Closure $inline_data_callback
38
-     */
39
-    private $inline_data_callback;
40
-
41
-
42
-    /**
43
-     * Asset constructor.
44
-     *
45
-     * @param string          $handle
46
-     * @param string          $source
47
-     * @param array           $dependencies
48
-     * @param bool            $load_in_footer
49
-     * @param DomainInterface $domain
50
-     * @param string          $version
51
-     * @throws InvalidDataTypeException
52
-     * @throws DomainException
53
-     */
54
-    public function __construct(
55
-        $handle,
56
-        $source,
57
-        array $dependencies,
58
-        $load_in_footer,
59
-        DomainInterface $domain,
60
-        $version = ''
61
-    ) {
62
-        parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain, $version);
63
-        $this->setLoadInFooter($load_in_footer);
64
-    }
65
-
66
-
67
-    /**
68
-     * @return bool
69
-     */
70
-    public function loadInFooter()
71
-    {
72
-        return $this->load_in_footer;
73
-    }
74
-
75
-
76
-    /**
77
-     * @param bool $load_in_footer
78
-     */
79
-    private function setLoadInFooter($load_in_footer = true)
80
-    {
81
-        $this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN);
82
-    }
83
-
84
-
85
-    /**
86
-     * @return bool
87
-     */
88
-    public function requiresTranslation()
89
-    {
90
-        return $this->requires_translation;
91
-    }
92
-
93
-
94
-    /**
95
-     * @return bool
96
-     */
97
-    public function hasInlineData()
98
-    {
99
-        return $this->has_inline_data;
100
-    }
101
-
102
-
103
-    /**
104
-     * @param bool $has_inline_data
105
-     * @return JavascriptAsset
106
-     */
107
-    public function setHasInlineData($has_inline_data = true)
108
-    {
109
-        $this->has_inline_data = filter_var($has_inline_data, FILTER_VALIDATE_BOOLEAN);
110
-        return $this;
111
-    }
112
-
113
-
114
-    /**
115
-     * @return Closure
116
-     */
117
-    public function inlineDataCallback()
118
-    {
119
-        return $this->inline_data_callback;
120
-    }
121
-
122
-
123
-    /**
124
-     * @return bool
125
-     */
126
-    public function hasInlineDataCallback()
127
-    {
128
-        return $this->inline_data_callback instanceof Closure;
129
-    }
130
-
131
-
132
-    /**
133
-     * @param Closure $inline_data_callback
134
-     * @return JavascriptAsset
135
-     */
136
-    public function setInlineDataCallback(Closure $inline_data_callback)
137
-    {
138
-        $this->inline_data_callback = $inline_data_callback;
139
-        $this->setHasInlineData();
140
-        return $this;
141
-    }
142
-
143
-
144
-    /**
145
-     * @since 4.9.62.p
146
-     */
147
-    public function enqueueAsset()
148
-    {
149
-        if ($this->source() === '') {
150
-            return;
151
-        }
152
-        $attributes = $this->getAttributes();
153
-        if (!empty($attributes)) {
154
-            add_filter('script_loader_tag', [$this, 'addAttributeTagsToScript'], 10, 2);
155
-        }
156
-        wp_enqueue_script($this->handle());
157
-    }
158
-
159
-
160
-    public function addAttributeTagsToScript($tag, $handle)
161
-    {
162
-        if ($handle === $this->handle()) {
163
-            $attributes = $this->getAttributes();
164
-            $attributes_string = '';
165
-            foreach ($attributes as $key => $value) {
166
-                if (is_int($key)) {
167
-                    $attributes_string .= " {$value}";
168
-                } else {
169
-                    $attributes_string .= " {$key}='{$value}'";
170
-                }
171
-            }
172
-            $tag = str_replace('></script>', $attributes_string . '></script>', $tag);
173
-        }
174
-
175
-        return $tag;
176
-    }
177
-
178
-
179
-    /**
180
-     * @deprecated 5.0.0.p
181
-     * @param bool $requires_translation
182
-     * @return JavascriptAsset
183
-     */
184
-    public function setRequiresTranslation($requires_translation = true)
185
-    {
186
-        $this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN);
187
-        return $this;
188
-    }
21
+	/**
22
+	 * @var boolean $load_in_footer
23
+	 */
24
+	private $load_in_footer = false;
25
+
26
+	/**
27
+	 * @var boolean $requires_translation
28
+	 */
29
+	private $requires_translation = false;
30
+
31
+	/**
32
+	 * @var boolean $has_inline_data
33
+	 */
34
+	private $has_inline_data = false;
35
+
36
+	/**
37
+	 * @var Closure $inline_data_callback
38
+	 */
39
+	private $inline_data_callback;
40
+
41
+
42
+	/**
43
+	 * Asset constructor.
44
+	 *
45
+	 * @param string          $handle
46
+	 * @param string          $source
47
+	 * @param array           $dependencies
48
+	 * @param bool            $load_in_footer
49
+	 * @param DomainInterface $domain
50
+	 * @param string          $version
51
+	 * @throws InvalidDataTypeException
52
+	 * @throws DomainException
53
+	 */
54
+	public function __construct(
55
+		$handle,
56
+		$source,
57
+		array $dependencies,
58
+		$load_in_footer,
59
+		DomainInterface $domain,
60
+		$version = ''
61
+	) {
62
+		parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain, $version);
63
+		$this->setLoadInFooter($load_in_footer);
64
+	}
65
+
66
+
67
+	/**
68
+	 * @return bool
69
+	 */
70
+	public function loadInFooter()
71
+	{
72
+		return $this->load_in_footer;
73
+	}
74
+
75
+
76
+	/**
77
+	 * @param bool $load_in_footer
78
+	 */
79
+	private function setLoadInFooter($load_in_footer = true)
80
+	{
81
+		$this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN);
82
+	}
83
+
84
+
85
+	/**
86
+	 * @return bool
87
+	 */
88
+	public function requiresTranslation()
89
+	{
90
+		return $this->requires_translation;
91
+	}
92
+
93
+
94
+	/**
95
+	 * @return bool
96
+	 */
97
+	public function hasInlineData()
98
+	{
99
+		return $this->has_inline_data;
100
+	}
101
+
102
+
103
+	/**
104
+	 * @param bool $has_inline_data
105
+	 * @return JavascriptAsset
106
+	 */
107
+	public function setHasInlineData($has_inline_data = true)
108
+	{
109
+		$this->has_inline_data = filter_var($has_inline_data, FILTER_VALIDATE_BOOLEAN);
110
+		return $this;
111
+	}
112
+
113
+
114
+	/**
115
+	 * @return Closure
116
+	 */
117
+	public function inlineDataCallback()
118
+	{
119
+		return $this->inline_data_callback;
120
+	}
121
+
122
+
123
+	/**
124
+	 * @return bool
125
+	 */
126
+	public function hasInlineDataCallback()
127
+	{
128
+		return $this->inline_data_callback instanceof Closure;
129
+	}
130
+
131
+
132
+	/**
133
+	 * @param Closure $inline_data_callback
134
+	 * @return JavascriptAsset
135
+	 */
136
+	public function setInlineDataCallback(Closure $inline_data_callback)
137
+	{
138
+		$this->inline_data_callback = $inline_data_callback;
139
+		$this->setHasInlineData();
140
+		return $this;
141
+	}
142
+
143
+
144
+	/**
145
+	 * @since 4.9.62.p
146
+	 */
147
+	public function enqueueAsset()
148
+	{
149
+		if ($this->source() === '') {
150
+			return;
151
+		}
152
+		$attributes = $this->getAttributes();
153
+		if (!empty($attributes)) {
154
+			add_filter('script_loader_tag', [$this, 'addAttributeTagsToScript'], 10, 2);
155
+		}
156
+		wp_enqueue_script($this->handle());
157
+	}
158
+
159
+
160
+	public function addAttributeTagsToScript($tag, $handle)
161
+	{
162
+		if ($handle === $this->handle()) {
163
+			$attributes = $this->getAttributes();
164
+			$attributes_string = '';
165
+			foreach ($attributes as $key => $value) {
166
+				if (is_int($key)) {
167
+					$attributes_string .= " {$value}";
168
+				} else {
169
+					$attributes_string .= " {$key}='{$value}'";
170
+				}
171
+			}
172
+			$tag = str_replace('></script>', $attributes_string . '></script>', $tag);
173
+		}
174
+
175
+		return $tag;
176
+	}
177
+
178
+
179
+	/**
180
+	 * @deprecated 5.0.0.p
181
+	 * @param bool $requires_translation
182
+	 * @return JavascriptAsset
183
+	 */
184
+	public function setRequiresTranslation($requires_translation = true)
185
+	{
186
+		$this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN);
187
+		return $this;
188
+	}
189 189
 }
Please login to merge, or discard this patch.
core/domain/values/assets/BrowserAsset.php 1 patch
Indentation   +230 added lines, -230 removed lines patch added patch discarded remove patch
@@ -17,234 +17,234 @@
 block discarded – undo
17 17
 abstract class BrowserAsset extends Asset
18 18
 {
19 19
 
20
-    /**
21
-     * @var array $attributes
22
-     */
23
-    private $attributes = [];
24
-
25
-    /**
26
-     * @var array $allowed_attributes
27
-     */
28
-    private static $allowed_attributes = [
29
-        Asset::TYPE_CSS => [
30
-            'crossorigin',
31
-            'media',
32
-            'referrerpolicy',
33
-            'sizes',
34
-            'type',
35
-        ],
36
-        Asset::TYPE_JS => [
37
-            'async',
38
-            'charset',
39
-            'crossorigin',
40
-            'defer',
41
-            'type',
42
-        ]
43
-    ];
44
-
45
-    /**
46
-     * @var array $dependencies
47
-     */
48
-    private $dependencies;
49
-
50
-    /**
51
-     * @var string $source
52
-     */
53
-    private $source;
54
-
55
-    /**
56
-     * @var string $version
57
-     */
58
-    private $version;
59
-
60
-
61
-    /**
62
-     * Asset constructor.
63
-     *
64
-     * @param string          $type
65
-     * @param string          $handle
66
-     * @param string          $source
67
-     * @param array           $dependencies
68
-     * @param DomainInterface $domain
69
-     * @param string          $version
70
-     * @throws DomainException
71
-     * @throws InvalidDataTypeException
72
-     */
73
-    public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain, $version = '')
74
-    {
75
-        parent::__construct($type, $handle, $domain);
76
-        $this->setSource($source);
77
-        $this->setDependencies($dependencies);
78
-        $this->setVersion($version, false);
79
-    }
80
-
81
-
82
-    /**
83
-     * @since 4.9.62.p
84
-     */
85
-    abstract public function enqueueAsset();
86
-
87
-
88
-    /**
89
-     * @return array
90
-     */
91
-    public function getAttributes()
92
-    {
93
-        return $this->attributes;
94
-    }
95
-
96
-
97
-    /**
98
-     * @param array $attributes
99
-     * @throws DomainException
100
-     * @since 5.0.0.p
101
-     */
102
-    public function addAttributes(array $attributes)
103
-    {
104
-        if (empty($attributes)) {
105
-            throw new DomainException(
106
-                esc_html__('The attributes array needs at least one value.', 'event_espresso')
107
-            );
108
-        }
109
-        foreach ($attributes as $key => $value) {
110
-            if (is_int($key) && $this->validateAttribute($value)) {
111
-                $this->attributes[] = $value;
112
-            } else if ($this->validateAttribute($key)) {
113
-                $this->attributes[ $key ] = $value;
114
-            }
115
-        }
116
-    }
117
-
118
-
119
-    /**
120
-     * @param string $attribute
121
-     * @return bool
122
-     * @throws DomainException
123
-     * @since 5.0.0.p
124
-     */
125
-    private function validateAttribute($attribute)
126
-    {
127
-        $allowed = BrowserAsset::$allowed_attributes[ $this->type() ];
128
-        if (! in_array($attribute, $allowed, true)) {
129
-            throw new DomainException(
130
-                sprintf(
131
-                    esc_html__('Invalid attribute! The only allowed attributes are: "%1$s"', 'event_espresso'),
132
-                    implode('", "', $allowed)
133
-                )
134
-            );
135
-        }
136
-        return true;
137
-    }
138
-
139
-
140
-    /**
141
-     * @return array
142
-     */
143
-    public function dependencies()
144
-    {
145
-        return $this->dependencies;
146
-    }
147
-
148
-
149
-    /**
150
-     * @param array $dependencies
151
-     */
152
-    public function addDependencies(array $dependencies)
153
-    {
154
-        $this->dependencies = array_merge($this->dependencies, $dependencies);
155
-    }
156
-
157
-
158
-    /**
159
-     * @param array $dependencies
160
-     */
161
-    protected function setDependencies(array $dependencies)
162
-    {
163
-        $this->dependencies = $dependencies;
164
-    }
165
-
166
-
167
-    /**
168
-     * @since 4.9.62.p
169
-     * @return bool
170
-     */
171
-    public function hasDependencies()
172
-    {
173
-        return count($this->dependencies) > 0;
174
-    }
175
-
176
-
177
-    /**
178
-     * @return string
179
-     */
180
-    public function source()
181
-    {
182
-        return $this->source;
183
-    }
184
-
185
-
186
-    /**
187
-     * @param string $source
188
-     * @throws InvalidDataTypeException
189
-     */
190
-    private function setSource($source)
191
-    {
192
-        if (! is_string($source)) {
193
-            throw new InvalidDataTypeException(
194
-                '$source',
195
-                $source,
196
-                'string'
197
-            );
198
-        }
199
-        $this->source = $source;
200
-    }
201
-
202
-
203
-    /**
204
-     * @return string
205
-     * @throws InvalidDataTypeException
206
-     * @throws DomainException
207
-     */
208
-    public function version()
209
-    {
210
-        return $this->version;
211
-    }
212
-
213
-
214
-    /**
215
-     * @param string $version
216
-     * @param bool   $fluent
217
-     * @return BrowserAsset|null
218
-     * @throws DomainException
219
-     * @throws InvalidDataTypeException
220
-     */
221
-    public function setVersion($version, $fluent = true)
222
-    {
223
-        // if version is NOT set and this asset was NOT built for distribution,
224
-        // then set the version equal to the EE core plugin version
225
-        if (empty($version) && ! $this->isBuiltDistributionSource()) {
226
-            $version = $this->domain->version();
227
-        }
228
-        if (! is_string($version)) {
229
-            throw new InvalidDataTypeException(
230
-                '$version',
231
-                $version,
232
-                'string'
233
-            );
234
-        }
235
-        $this->version = $version;
236
-        if ($fluent) {
237
-            return $this;
238
-        }
239
-        return null;
240
-    }
241
-
242
-
243
-    /**
244
-     * @return bool
245
-     */
246
-    public function isBuiltDistributionSource() {
247
-        return substr($this->source, -8) === Asset::FILE_EXTENSION_DISTRIBUTION_JS
248
-               || substr($this->source, -9) === Asset::FILE_EXTENSION_DISTRIBUTION_CSS;
249
-    }
20
+	/**
21
+	 * @var array $attributes
22
+	 */
23
+	private $attributes = [];
24
+
25
+	/**
26
+	 * @var array $allowed_attributes
27
+	 */
28
+	private static $allowed_attributes = [
29
+		Asset::TYPE_CSS => [
30
+			'crossorigin',
31
+			'media',
32
+			'referrerpolicy',
33
+			'sizes',
34
+			'type',
35
+		],
36
+		Asset::TYPE_JS => [
37
+			'async',
38
+			'charset',
39
+			'crossorigin',
40
+			'defer',
41
+			'type',
42
+		]
43
+	];
44
+
45
+	/**
46
+	 * @var array $dependencies
47
+	 */
48
+	private $dependencies;
49
+
50
+	/**
51
+	 * @var string $source
52
+	 */
53
+	private $source;
54
+
55
+	/**
56
+	 * @var string $version
57
+	 */
58
+	private $version;
59
+
60
+
61
+	/**
62
+	 * Asset constructor.
63
+	 *
64
+	 * @param string          $type
65
+	 * @param string          $handle
66
+	 * @param string          $source
67
+	 * @param array           $dependencies
68
+	 * @param DomainInterface $domain
69
+	 * @param string          $version
70
+	 * @throws DomainException
71
+	 * @throws InvalidDataTypeException
72
+	 */
73
+	public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain, $version = '')
74
+	{
75
+		parent::__construct($type, $handle, $domain);
76
+		$this->setSource($source);
77
+		$this->setDependencies($dependencies);
78
+		$this->setVersion($version, false);
79
+	}
80
+
81
+
82
+	/**
83
+	 * @since 4.9.62.p
84
+	 */
85
+	abstract public function enqueueAsset();
86
+
87
+
88
+	/**
89
+	 * @return array
90
+	 */
91
+	public function getAttributes()
92
+	{
93
+		return $this->attributes;
94
+	}
95
+
96
+
97
+	/**
98
+	 * @param array $attributes
99
+	 * @throws DomainException
100
+	 * @since 5.0.0.p
101
+	 */
102
+	public function addAttributes(array $attributes)
103
+	{
104
+		if (empty($attributes)) {
105
+			throw new DomainException(
106
+				esc_html__('The attributes array needs at least one value.', 'event_espresso')
107
+			);
108
+		}
109
+		foreach ($attributes as $key => $value) {
110
+			if (is_int($key) && $this->validateAttribute($value)) {
111
+				$this->attributes[] = $value;
112
+			} else if ($this->validateAttribute($key)) {
113
+				$this->attributes[ $key ] = $value;
114
+			}
115
+		}
116
+	}
117
+
118
+
119
+	/**
120
+	 * @param string $attribute
121
+	 * @return bool
122
+	 * @throws DomainException
123
+	 * @since 5.0.0.p
124
+	 */
125
+	private function validateAttribute($attribute)
126
+	{
127
+		$allowed = BrowserAsset::$allowed_attributes[ $this->type() ];
128
+		if (! in_array($attribute, $allowed, true)) {
129
+			throw new DomainException(
130
+				sprintf(
131
+					esc_html__('Invalid attribute! The only allowed attributes are: "%1$s"', 'event_espresso'),
132
+					implode('", "', $allowed)
133
+				)
134
+			);
135
+		}
136
+		return true;
137
+	}
138
+
139
+
140
+	/**
141
+	 * @return array
142
+	 */
143
+	public function dependencies()
144
+	{
145
+		return $this->dependencies;
146
+	}
147
+
148
+
149
+	/**
150
+	 * @param array $dependencies
151
+	 */
152
+	public function addDependencies(array $dependencies)
153
+	{
154
+		$this->dependencies = array_merge($this->dependencies, $dependencies);
155
+	}
156
+
157
+
158
+	/**
159
+	 * @param array $dependencies
160
+	 */
161
+	protected function setDependencies(array $dependencies)
162
+	{
163
+		$this->dependencies = $dependencies;
164
+	}
165
+
166
+
167
+	/**
168
+	 * @since 4.9.62.p
169
+	 * @return bool
170
+	 */
171
+	public function hasDependencies()
172
+	{
173
+		return count($this->dependencies) > 0;
174
+	}
175
+
176
+
177
+	/**
178
+	 * @return string
179
+	 */
180
+	public function source()
181
+	{
182
+		return $this->source;
183
+	}
184
+
185
+
186
+	/**
187
+	 * @param string $source
188
+	 * @throws InvalidDataTypeException
189
+	 */
190
+	private function setSource($source)
191
+	{
192
+		if (! is_string($source)) {
193
+			throw new InvalidDataTypeException(
194
+				'$source',
195
+				$source,
196
+				'string'
197
+			);
198
+		}
199
+		$this->source = $source;
200
+	}
201
+
202
+
203
+	/**
204
+	 * @return string
205
+	 * @throws InvalidDataTypeException
206
+	 * @throws DomainException
207
+	 */
208
+	public function version()
209
+	{
210
+		return $this->version;
211
+	}
212
+
213
+
214
+	/**
215
+	 * @param string $version
216
+	 * @param bool   $fluent
217
+	 * @return BrowserAsset|null
218
+	 * @throws DomainException
219
+	 * @throws InvalidDataTypeException
220
+	 */
221
+	public function setVersion($version, $fluent = true)
222
+	{
223
+		// if version is NOT set and this asset was NOT built for distribution,
224
+		// then set the version equal to the EE core plugin version
225
+		if (empty($version) && ! $this->isBuiltDistributionSource()) {
226
+			$version = $this->domain->version();
227
+		}
228
+		if (! is_string($version)) {
229
+			throw new InvalidDataTypeException(
230
+				'$version',
231
+				$version,
232
+				'string'
233
+			);
234
+		}
235
+		$this->version = $version;
236
+		if ($fluent) {
237
+			return $this;
238
+		}
239
+		return null;
240
+	}
241
+
242
+
243
+	/**
244
+	 * @return bool
245
+	 */
246
+	public function isBuiltDistributionSource() {
247
+		return substr($this->source, -8) === Asset::FILE_EXTENSION_DISTRIBUTION_JS
248
+			   || substr($this->source, -9) === Asset::FILE_EXTENSION_DISTRIBUTION_CSS;
249
+	}
250 250
 }
Please login to merge, or discard this patch.