Completed
Branch Gutenberg/master (9bdde5)
by
unknown
54:35 queued 41:01
created
modules/venue_single/EED_Venue_Single.module.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -35,26 +35,26 @@
 block discarded – undo
35 35
 	}
36 36
 
37 37
 
38
-    /**
39
-     * set_hooks - for hooking into EE Core, other modules, etc
40
-     *
41
-     * @return void
42
-     * @throws InvalidArgumentException
43
-     * @throws InvalidDataTypeException
44
-     * @throws InvalidInterfaceException
45
-     */
38
+	/**
39
+	 * set_hooks - for hooking into EE Core, other modules, etc
40
+	 *
41
+	 * @return void
42
+	 * @throws InvalidArgumentException
43
+	 * @throws InvalidDataTypeException
44
+	 * @throws InvalidInterfaceException
45
+	 */
46 46
 	public static function set_hooks() {
47
-        /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */
48
-        $custom_post_type_definitions = LoaderFactory::getLoader()->getShared(
49
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
50
-        );
51
-        $custom_post_types = $custom_post_type_definitions->getDefinitions();
52
-        EE_Config::register_route(
53
-            $custom_post_types['espresso_venues']['singular_slug'],
54
-            'Venue_Single',
55
-            'run'
56
-        );
57
-    }
47
+		/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */
48
+		$custom_post_type_definitions = LoaderFactory::getLoader()->getShared(
49
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
50
+		);
51
+		$custom_post_types = $custom_post_type_definitions->getDefinitions();
52
+		EE_Config::register_route(
53
+			$custom_post_types['espresso_venues']['singular_slug'],
54
+			'Venue_Single',
55
+			'run'
56
+		);
57
+	}
58 58
 
59 59
 	/**
60 60
 	 * 	set_hooks_admin - for hooking into EE Admin Core, other modules, etc
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,9 @@
 block discarded – undo
2 2
 use EventEspresso\core\exceptions\InvalidInterfaceException;
3 3
 use EventEspresso\core\services\loaders\LoaderFactory;
4 4
 
5
-if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
5
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
6
+	exit('No direct script access allowed');
7
+}
6 8
 /**
7 9
  * Event Espresso
8 10
  *
Please login to merge, or discard this patch.
modules/event_single/EED_Event_Single.module.php 1 patch
Indentation   +469 added lines, -469 removed lines patch added patch discarded remove patch
@@ -17,474 +17,474 @@  discard block
 block discarded – undo
17 17
 class EED_Event_Single extends EED_Module
18 18
 {
19 19
 
20
-    const EVENT_DETAILS_PRIORITY = 100;
21
-    const EVENT_DATETIMES_PRIORITY = 110;
22
-    const EVENT_TICKETS_PRIORITY = 120;
23
-    const EVENT_VENUES_PRIORITY = 130;
24
-
25
-    /**
26
-     * @type bool $using_get_the_excerpt
27
-     */
28
-    protected static $using_get_the_excerpt = false;
29
-
30
-
31
-    /**
32
-     * @type EE_Template_Part_Manager $template_parts
33
-     */
34
-    protected $template_parts;
35
-
36
-
37
-    /**
38
-     * @return EED_Module|EED_Event_Single
39
-     */
40
-    public static function instance()
41
-    {
42
-        return parent::get_instance(__CLASS__);
43
-    }
44
-
45
-
46
-    /**
47
-     * set_hooks - for hooking into EE Core, other modules, etc
48
-     *
49
-     * @return void
50
-     * @throws InvalidArgumentException
51
-     * @throws InvalidDataTypeException
52
-     * @throws InvalidInterfaceException
53
-     */
54
-    public static function set_hooks()
55
-    {
56
-        add_filter('FHEE_run_EE_wp', '__return_true');
57
-        add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
58
-        /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */
59
-        $custom_post_type_definitions = LoaderFactory::getLoader()->getShared(
60
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
61
-        );
62
-        $custom_post_types = $custom_post_type_definitions->getDefinitions();
63
-        EE_Config::register_route(
64
-            $custom_post_types['espresso_events']['singular_slug'],
65
-            'Event_Single',
66
-            'run'
67
-        );
68
-    }
69
-
70
-    /**
71
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
72
-     *
73
-     * @return    void
74
-     */
75
-    public static function set_hooks_admin()
76
-    {
77
-        add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
78
-    }
79
-
80
-
81
-    /**
82
-     * set_definitions
83
-     *
84
-     * @static
85
-     * @return void
86
-     */
87
-    public static function set_definitions()
88
-    {
89
-        define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
90
-        define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates' . DS);
91
-    }
92
-
93
-
94
-    /**
95
-     * set_config
96
-     *
97
-     * @void
98
-     */
99
-    protected function set_config()
100
-    {
101
-        $this->set_config_section('template_settings');
102
-        $this->set_config_class('EE_Event_Single_Config');
103
-        $this->set_config_name('EED_Event_Single');
104
-    }
105
-
106
-
107
-    /**
108
-     * initialize_template_parts
109
-     *
110
-     * @param EE_Config_Base|EE_Event_Single_Config $config
111
-     * @return EE_Template_Part_Manager
112
-     */
113
-    public function initialize_template_parts(EE_Event_Single_Config $config = null)
114
-    {
115
-        /** @type EE_Event_Single_Config $config */
116
-        $config = $config instanceof EE_Event_Single_Config ? $config : $this->config();
117
-        EEH_Autoloader::instance()->register_template_part_autoloaders();
118
-        $template_parts = new EE_Template_Part_Manager();
119
-        $template_parts->add_template_part(
120
-            'tickets',
121
-            __('Ticket Selector', 'event_espresso'),
122
-            'content-espresso_events-tickets.php',
123
-            $config->display_order_tickets
124
-        );
125
-        $template_parts->add_template_part(
126
-            'datetimes',
127
-            __('Dates and Times', 'event_espresso'),
128
-            'content-espresso_events-datetimes.php',
129
-            $config->display_order_datetimes
130
-        );
131
-        $template_parts->add_template_part(
132
-            'event',
133
-            __('Event Description', 'event_espresso'),
134
-            'content-espresso_events-details.php',
135
-            $config->display_order_event
136
-        );
137
-        $template_parts->add_template_part(
138
-            'venue',
139
-            __('Venue Information', 'event_espresso'),
140
-            'content-espresso_events-venues.php',
141
-            $config->display_order_venue
142
-        );
143
-        do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts);
144
-        return $template_parts;
145
-    }
146
-
147
-
148
-    /**
149
-     * run - initial module setup
150
-     *
151
-     * @param WP $WP
152
-     * @return    void
153
-     */
154
-    public function run($WP)
155
-    {
156
-        // ensure valid EE_Events_Single_Config() object exists
157
-        $this->set_config();
158
-        // check what template is loaded
159
-        add_filter('template_include', array($this, 'template_include'), 999, 1);
160
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
161
-        // load css
162
-        add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
163
-    }
164
-
165
-
166
-    /**
167
-     * template_include
168
-     *
169
-     * @param    string $template
170
-     * @return    string
171
-     */
172
-    public function template_include($template)
173
-    {
174
-        global $post;
175
-        /** @type EE_Event_Single_Config $config */
176
-        $config = $this->config();
177
-        if ($config->display_status_banner_single) {
178
-            add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2);
179
-        }
180
-        // not a custom template?
181
-        if (
182
-            !post_password_required($post)
183
-            && (
184
-                apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false)
185
-                || EE_Registry::instance()
186
-                    ->load_core('Front_Controller')
187
-                    ->get_selected_template() !== 'single-espresso_events.php'
188
-            )
189
-
190
-        ) {
191
-            EEH_Template::load_espresso_theme_functions();
192
-            // then add extra event data via hooks
193
-            add_action('loop_start', array('EED_Event_Single', 'loop_start'));
194
-            add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1);
195
-            add_filter(
196
-                'the_content',
197
-                array('EED_Event_Single', 'event_details'),
198
-                EED_Event_Single::EVENT_DETAILS_PRIORITY
199
-            );
200
-            add_action('loop_end', array('EED_Event_Single', 'loop_end'));
201
-            // don't display entry meta because the existing theme will take car of that
202
-            add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
203
-        }
204
-        return $template;
205
-    }
206
-
207
-
208
-    /**
209
-     * loop_start
210
-     *
211
-     * @param    array $wp_query_array an array containing the WP_Query object
212
-     * @return    void
213
-     */
214
-    public static function loop_start($wp_query_array)
215
-    {
216
-        global $post;
217
-        do_action('AHEE_event_details_before_post', $post, $wp_query_array);
218
-    }
219
-
220
-
221
-    /**
222
-     * the_title
223
-     *
224
-     * @param    string $title
225
-     * @param    int $id
226
-     * @return    string
227
-     */
228
-    public static function the_title($title = '', $id = 0)
229
-    {
230
-        global $post;
231
-        return in_the_loop() && $post->ID === (int)$id
232
-            ? espresso_event_status_banner($post->ID) . $title
233
-            : $title;
234
-    }
235
-
236
-
237
-    /**
238
-     * get_the_excerpt
239
-     * kinda hacky, but if a theme is using get_the_excerpt(),
240
-     * then we need to remove our filters on the_content()
241
-     *
242
-     * @param        string $excerpt
243
-     * @return        string
244
-     */
245
-    public static function get_the_excerpt($excerpt = '')
246
-    {
247
-        EED_Event_Single::$using_get_the_excerpt = true;
248
-        add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1);
249
-        return $excerpt;
250
-    }
251
-
252
-
253
-    /**
254
-     * end_get_the_excerpt
255
-     *
256
-     * @param  string $text
257
-     * @return string
258
-     */
259
-    public static function end_get_the_excerpt($text = '')
260
-    {
261
-        EED_Event_Single::$using_get_the_excerpt = false;
262
-        return $text;
263
-    }
264
-
265
-
266
-    /**
267
-     * event_details
268
-     *
269
-     * @param    string $content
270
-     * @return    string
271
-     */
272
-    public static function event_details($content)
273
-    {
274
-        global $post;
275
-        static $current_post_ID = 0;
276
-        if (
277
-            $current_post_ID !== $post->ID
278
-            && $post->post_type === 'espresso_events'
279
-            && !EED_Event_Single::$using_get_the_excerpt
280
-            && !post_password_required()
281
-        ) {
282
-            // Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
283
-            // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
284
-            // BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
285
-            // We want to allow those plugins to still do their thing and have access to our content, but depending on
286
-            // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
287
-            // so the following allows this filter to be applied multiple times, but only once for real
288
-            $current_post_ID = did_action('loop_start') ? $post->ID : 0;
289
-            if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) {
290
-                // we need to first remove this callback from being applied to the_content()
291
-                // (otherwise it will recurse and blow up the interweb)
292
-                remove_filter(
293
-                    'the_content',
294
-                    array('EED_Event_Single', 'event_details'),
295
-                    EED_Event_Single::EVENT_DETAILS_PRIORITY
296
-                );
297
-                EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts();
298
-                $content = EEH_Template::locate_template('content-espresso_events-details.php');
299
-                $content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content);
300
-                add_filter(
301
-                    'the_content',
302
-                    array('EED_Event_Single', 'event_details'),
303
-                    EED_Event_Single::EVENT_DETAILS_PRIORITY
304
-                );
305
-            } else {
306
-                $content = EED_Event_Single::use_filterable_display_order();
307
-            }
308
-        }
309
-        return $content;
310
-    }
311
-
312
-
313
-    /**
314
-     * use_filterable_display_order
315
-     *
316
-     * @return string
317
-     */
318
-    protected static function use_filterable_display_order()
319
-    {
320
-        // since the 'content-espresso_events-details.php' template might be used directly from within a theme,
321
-        // it uses the_content() for displaying the $post->post_content
322
-        // so in order to load a template that uses the_content()
323
-        // from within a callback being used to filter the_content(),
324
-        // we need to first remove this callback from being applied to the_content()
325
-        // (otherwise it will recurse and blow up the interweb)
326
-        remove_filter(
327
-            'the_content',
328
-            array('EED_Event_Single', 'event_details'),
329
-            EED_Event_Single::EVENT_DETAILS_PRIORITY
330
-        );
331
-        //now add additional content
332
-        add_filter(
333
-            'the_content',
334
-            array('EED_Event_Single', 'event_datetimes'),
335
-            EED_Event_Single::EVENT_DATETIMES_PRIORITY,
336
-            1
337
-        );
338
-        add_filter(
339
-            'the_content',
340
-            array('EED_Event_Single', 'event_tickets'),
341
-            EED_Event_Single::EVENT_TICKETS_PRIORITY,
342
-            1
343
-        );
344
-        add_filter(
345
-            'the_content',
346
-            array('EED_Event_Single', 'event_venues'),
347
-            EED_Event_Single::EVENT_VENUES_PRIORITY,
348
-            1
349
-        );
350
-        do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters');
351
-        // now load our template
352
-        $content = EEH_Template::locate_template('content-espresso_events-details.php');
353
-        //now add our filter back in, plus some others
354
-        add_filter(
355
-            'the_content',
356
-            array('EED_Event_Single', 'event_details'),
357
-            EED_Event_Single::EVENT_DETAILS_PRIORITY
358
-        );
359
-        remove_filter(
360
-            'the_content',
361
-            array('EED_Event_Single', 'event_datetimes'),
362
-            EED_Event_Single::EVENT_DATETIMES_PRIORITY
363
-        );
364
-        remove_filter(
365
-            'the_content',
366
-            array('EED_Event_Single', 'event_tickets'),
367
-            EED_Event_Single::EVENT_TICKETS_PRIORITY
368
-        );
369
-        remove_filter(
370
-            'the_content',
371
-            array('EED_Event_Single', 'event_venues'),
372
-            EED_Event_Single::EVENT_VENUES_PRIORITY
373
-        );
374
-        do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters');
375
-        // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
376
-        return $content;
377
-    }
378
-
379
-
380
-    /**
381
-     * event_datetimes - adds datetimes ABOVE content
382
-     *
383
-     * @param        string $content
384
-     * @return        string
385
-     */
386
-    public static function event_datetimes($content)
387
-    {
388
-        return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
389
-    }
390
-
391
-
392
-    /**
393
-     * event_tickets - adds tickets ABOVE content (which includes datetimes)
394
-     *
395
-     * @param        string $content
396
-     * @return        string
397
-     */
398
-    public static function event_tickets($content)
399
-    {
400
-        return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
401
-    }
402
-
403
-
404
-    /**
405
-     * event_venues
406
-     *
407
-     * @param    string $content
408
-     * @return    string
409
-     */
410
-    public static function event_venue($content)
411
-    {
412
-        return EED_Event_Single::event_venues($content);
413
-    }
414
-
415
-
416
-    /**
417
-     * event_venues - adds venues BELOW content
418
-     *
419
-     * @param        string $content
420
-     * @return        string
421
-     */
422
-    public static function event_venues($content)
423
-    {
424
-        return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
425
-    }
426
-
427
-
428
-    /**
429
-     * loop_end
430
-     *
431
-     * @param        array $wp_query_array an array containing the WP_Query object
432
-     * @return        void
433
-     */
434
-    public static function loop_end($wp_query_array)
435
-    {
436
-        global $post;
437
-        do_action('AHEE_event_details_after_post', $post, $wp_query_array);
438
-    }
439
-
440
-
441
-    /**
442
-     * wp_enqueue_scripts
443
-     *
444
-     * @return    void
445
-     */
446
-    public function wp_enqueue_scripts()
447
-    {
448
-        // get some style
449
-        if (
450
-            apply_filters('FHEE_enable_default_espresso_css', TRUE)
451
-            && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', TRUE)
452
-        ) {
453
-            // first check uploads folder
454
-            if (is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) {
455
-                wp_register_style(
456
-                    $this->theme,
457
-                    get_stylesheet_directory_uri() . $this->theme . DS . 'style.css',
458
-                    array('dashicons', 'espresso_default')
459
-                );
460
-            } else {
461
-                wp_register_style(
462
-                    $this->theme,
463
-                    EE_TEMPLATES_URL . $this->theme . DS . 'style.css',
464
-                    array('dashicons', 'espresso_default')
465
-                );
466
-            }
467
-            wp_enqueue_script($this->theme);
468
-            if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
469
-                add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
470
-            }
471
-        }
472
-    }
473
-
474
-
475
-    /**
476
-     * display_venue
477
-     *
478
-     * @return    bool
479
-     */
480
-    public static function display_venue()
481
-    {
482
-        /** @type EE_Event_Single_Config $config */
483
-        $config = EED_Event_Single::instance()->config();
484
-        $display_venue = $config->display_venue === null ? true : $config->display_venue;
485
-        $venue_name = EEH_Venue_View::venue_name();
486
-        return $display_venue && !empty($venue_name);
487
-    }
20
+	const EVENT_DETAILS_PRIORITY = 100;
21
+	const EVENT_DATETIMES_PRIORITY = 110;
22
+	const EVENT_TICKETS_PRIORITY = 120;
23
+	const EVENT_VENUES_PRIORITY = 130;
24
+
25
+	/**
26
+	 * @type bool $using_get_the_excerpt
27
+	 */
28
+	protected static $using_get_the_excerpt = false;
29
+
30
+
31
+	/**
32
+	 * @type EE_Template_Part_Manager $template_parts
33
+	 */
34
+	protected $template_parts;
35
+
36
+
37
+	/**
38
+	 * @return EED_Module|EED_Event_Single
39
+	 */
40
+	public static function instance()
41
+	{
42
+		return parent::get_instance(__CLASS__);
43
+	}
44
+
45
+
46
+	/**
47
+	 * set_hooks - for hooking into EE Core, other modules, etc
48
+	 *
49
+	 * @return void
50
+	 * @throws InvalidArgumentException
51
+	 * @throws InvalidDataTypeException
52
+	 * @throws InvalidInterfaceException
53
+	 */
54
+	public static function set_hooks()
55
+	{
56
+		add_filter('FHEE_run_EE_wp', '__return_true');
57
+		add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
58
+		/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */
59
+		$custom_post_type_definitions = LoaderFactory::getLoader()->getShared(
60
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
61
+		);
62
+		$custom_post_types = $custom_post_type_definitions->getDefinitions();
63
+		EE_Config::register_route(
64
+			$custom_post_types['espresso_events']['singular_slug'],
65
+			'Event_Single',
66
+			'run'
67
+		);
68
+	}
69
+
70
+	/**
71
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
72
+	 *
73
+	 * @return    void
74
+	 */
75
+	public static function set_hooks_admin()
76
+	{
77
+		add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
78
+	}
79
+
80
+
81
+	/**
82
+	 * set_definitions
83
+	 *
84
+	 * @static
85
+	 * @return void
86
+	 */
87
+	public static function set_definitions()
88
+	{
89
+		define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
90
+		define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates' . DS);
91
+	}
92
+
93
+
94
+	/**
95
+	 * set_config
96
+	 *
97
+	 * @void
98
+	 */
99
+	protected function set_config()
100
+	{
101
+		$this->set_config_section('template_settings');
102
+		$this->set_config_class('EE_Event_Single_Config');
103
+		$this->set_config_name('EED_Event_Single');
104
+	}
105
+
106
+
107
+	/**
108
+	 * initialize_template_parts
109
+	 *
110
+	 * @param EE_Config_Base|EE_Event_Single_Config $config
111
+	 * @return EE_Template_Part_Manager
112
+	 */
113
+	public function initialize_template_parts(EE_Event_Single_Config $config = null)
114
+	{
115
+		/** @type EE_Event_Single_Config $config */
116
+		$config = $config instanceof EE_Event_Single_Config ? $config : $this->config();
117
+		EEH_Autoloader::instance()->register_template_part_autoloaders();
118
+		$template_parts = new EE_Template_Part_Manager();
119
+		$template_parts->add_template_part(
120
+			'tickets',
121
+			__('Ticket Selector', 'event_espresso'),
122
+			'content-espresso_events-tickets.php',
123
+			$config->display_order_tickets
124
+		);
125
+		$template_parts->add_template_part(
126
+			'datetimes',
127
+			__('Dates and Times', 'event_espresso'),
128
+			'content-espresso_events-datetimes.php',
129
+			$config->display_order_datetimes
130
+		);
131
+		$template_parts->add_template_part(
132
+			'event',
133
+			__('Event Description', 'event_espresso'),
134
+			'content-espresso_events-details.php',
135
+			$config->display_order_event
136
+		);
137
+		$template_parts->add_template_part(
138
+			'venue',
139
+			__('Venue Information', 'event_espresso'),
140
+			'content-espresso_events-venues.php',
141
+			$config->display_order_venue
142
+		);
143
+		do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts);
144
+		return $template_parts;
145
+	}
146
+
147
+
148
+	/**
149
+	 * run - initial module setup
150
+	 *
151
+	 * @param WP $WP
152
+	 * @return    void
153
+	 */
154
+	public function run($WP)
155
+	{
156
+		// ensure valid EE_Events_Single_Config() object exists
157
+		$this->set_config();
158
+		// check what template is loaded
159
+		add_filter('template_include', array($this, 'template_include'), 999, 1);
160
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
161
+		// load css
162
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
163
+	}
164
+
165
+
166
+	/**
167
+	 * template_include
168
+	 *
169
+	 * @param    string $template
170
+	 * @return    string
171
+	 */
172
+	public function template_include($template)
173
+	{
174
+		global $post;
175
+		/** @type EE_Event_Single_Config $config */
176
+		$config = $this->config();
177
+		if ($config->display_status_banner_single) {
178
+			add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2);
179
+		}
180
+		// not a custom template?
181
+		if (
182
+			!post_password_required($post)
183
+			&& (
184
+				apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false)
185
+				|| EE_Registry::instance()
186
+					->load_core('Front_Controller')
187
+					->get_selected_template() !== 'single-espresso_events.php'
188
+			)
189
+
190
+		) {
191
+			EEH_Template::load_espresso_theme_functions();
192
+			// then add extra event data via hooks
193
+			add_action('loop_start', array('EED_Event_Single', 'loop_start'));
194
+			add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1);
195
+			add_filter(
196
+				'the_content',
197
+				array('EED_Event_Single', 'event_details'),
198
+				EED_Event_Single::EVENT_DETAILS_PRIORITY
199
+			);
200
+			add_action('loop_end', array('EED_Event_Single', 'loop_end'));
201
+			// don't display entry meta because the existing theme will take car of that
202
+			add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
203
+		}
204
+		return $template;
205
+	}
206
+
207
+
208
+	/**
209
+	 * loop_start
210
+	 *
211
+	 * @param    array $wp_query_array an array containing the WP_Query object
212
+	 * @return    void
213
+	 */
214
+	public static function loop_start($wp_query_array)
215
+	{
216
+		global $post;
217
+		do_action('AHEE_event_details_before_post', $post, $wp_query_array);
218
+	}
219
+
220
+
221
+	/**
222
+	 * the_title
223
+	 *
224
+	 * @param    string $title
225
+	 * @param    int $id
226
+	 * @return    string
227
+	 */
228
+	public static function the_title($title = '', $id = 0)
229
+	{
230
+		global $post;
231
+		return in_the_loop() && $post->ID === (int)$id
232
+			? espresso_event_status_banner($post->ID) . $title
233
+			: $title;
234
+	}
235
+
236
+
237
+	/**
238
+	 * get_the_excerpt
239
+	 * kinda hacky, but if a theme is using get_the_excerpt(),
240
+	 * then we need to remove our filters on the_content()
241
+	 *
242
+	 * @param        string $excerpt
243
+	 * @return        string
244
+	 */
245
+	public static function get_the_excerpt($excerpt = '')
246
+	{
247
+		EED_Event_Single::$using_get_the_excerpt = true;
248
+		add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1);
249
+		return $excerpt;
250
+	}
251
+
252
+
253
+	/**
254
+	 * end_get_the_excerpt
255
+	 *
256
+	 * @param  string $text
257
+	 * @return string
258
+	 */
259
+	public static function end_get_the_excerpt($text = '')
260
+	{
261
+		EED_Event_Single::$using_get_the_excerpt = false;
262
+		return $text;
263
+	}
264
+
265
+
266
+	/**
267
+	 * event_details
268
+	 *
269
+	 * @param    string $content
270
+	 * @return    string
271
+	 */
272
+	public static function event_details($content)
273
+	{
274
+		global $post;
275
+		static $current_post_ID = 0;
276
+		if (
277
+			$current_post_ID !== $post->ID
278
+			&& $post->post_type === 'espresso_events'
279
+			&& !EED_Event_Single::$using_get_the_excerpt
280
+			&& !post_password_required()
281
+		) {
282
+			// Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
283
+			// Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
284
+			// BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
285
+			// We want to allow those plugins to still do their thing and have access to our content, but depending on
286
+			// how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
287
+			// so the following allows this filter to be applied multiple times, but only once for real
288
+			$current_post_ID = did_action('loop_start') ? $post->ID : 0;
289
+			if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) {
290
+				// we need to first remove this callback from being applied to the_content()
291
+				// (otherwise it will recurse and blow up the interweb)
292
+				remove_filter(
293
+					'the_content',
294
+					array('EED_Event_Single', 'event_details'),
295
+					EED_Event_Single::EVENT_DETAILS_PRIORITY
296
+				);
297
+				EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts();
298
+				$content = EEH_Template::locate_template('content-espresso_events-details.php');
299
+				$content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content);
300
+				add_filter(
301
+					'the_content',
302
+					array('EED_Event_Single', 'event_details'),
303
+					EED_Event_Single::EVENT_DETAILS_PRIORITY
304
+				);
305
+			} else {
306
+				$content = EED_Event_Single::use_filterable_display_order();
307
+			}
308
+		}
309
+		return $content;
310
+	}
311
+
312
+
313
+	/**
314
+	 * use_filterable_display_order
315
+	 *
316
+	 * @return string
317
+	 */
318
+	protected static function use_filterable_display_order()
319
+	{
320
+		// since the 'content-espresso_events-details.php' template might be used directly from within a theme,
321
+		// it uses the_content() for displaying the $post->post_content
322
+		// so in order to load a template that uses the_content()
323
+		// from within a callback being used to filter the_content(),
324
+		// we need to first remove this callback from being applied to the_content()
325
+		// (otherwise it will recurse and blow up the interweb)
326
+		remove_filter(
327
+			'the_content',
328
+			array('EED_Event_Single', 'event_details'),
329
+			EED_Event_Single::EVENT_DETAILS_PRIORITY
330
+		);
331
+		//now add additional content
332
+		add_filter(
333
+			'the_content',
334
+			array('EED_Event_Single', 'event_datetimes'),
335
+			EED_Event_Single::EVENT_DATETIMES_PRIORITY,
336
+			1
337
+		);
338
+		add_filter(
339
+			'the_content',
340
+			array('EED_Event_Single', 'event_tickets'),
341
+			EED_Event_Single::EVENT_TICKETS_PRIORITY,
342
+			1
343
+		);
344
+		add_filter(
345
+			'the_content',
346
+			array('EED_Event_Single', 'event_venues'),
347
+			EED_Event_Single::EVENT_VENUES_PRIORITY,
348
+			1
349
+		);
350
+		do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters');
351
+		// now load our template
352
+		$content = EEH_Template::locate_template('content-espresso_events-details.php');
353
+		//now add our filter back in, plus some others
354
+		add_filter(
355
+			'the_content',
356
+			array('EED_Event_Single', 'event_details'),
357
+			EED_Event_Single::EVENT_DETAILS_PRIORITY
358
+		);
359
+		remove_filter(
360
+			'the_content',
361
+			array('EED_Event_Single', 'event_datetimes'),
362
+			EED_Event_Single::EVENT_DATETIMES_PRIORITY
363
+		);
364
+		remove_filter(
365
+			'the_content',
366
+			array('EED_Event_Single', 'event_tickets'),
367
+			EED_Event_Single::EVENT_TICKETS_PRIORITY
368
+		);
369
+		remove_filter(
370
+			'the_content',
371
+			array('EED_Event_Single', 'event_venues'),
372
+			EED_Event_Single::EVENT_VENUES_PRIORITY
373
+		);
374
+		do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters');
375
+		// we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
376
+		return $content;
377
+	}
378
+
379
+
380
+	/**
381
+	 * event_datetimes - adds datetimes ABOVE content
382
+	 *
383
+	 * @param        string $content
384
+	 * @return        string
385
+	 */
386
+	public static function event_datetimes($content)
387
+	{
388
+		return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
389
+	}
390
+
391
+
392
+	/**
393
+	 * event_tickets - adds tickets ABOVE content (which includes datetimes)
394
+	 *
395
+	 * @param        string $content
396
+	 * @return        string
397
+	 */
398
+	public static function event_tickets($content)
399
+	{
400
+		return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
401
+	}
402
+
403
+
404
+	/**
405
+	 * event_venues
406
+	 *
407
+	 * @param    string $content
408
+	 * @return    string
409
+	 */
410
+	public static function event_venue($content)
411
+	{
412
+		return EED_Event_Single::event_venues($content);
413
+	}
414
+
415
+
416
+	/**
417
+	 * event_venues - adds venues BELOW content
418
+	 *
419
+	 * @param        string $content
420
+	 * @return        string
421
+	 */
422
+	public static function event_venues($content)
423
+	{
424
+		return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
425
+	}
426
+
427
+
428
+	/**
429
+	 * loop_end
430
+	 *
431
+	 * @param        array $wp_query_array an array containing the WP_Query object
432
+	 * @return        void
433
+	 */
434
+	public static function loop_end($wp_query_array)
435
+	{
436
+		global $post;
437
+		do_action('AHEE_event_details_after_post', $post, $wp_query_array);
438
+	}
439
+
440
+
441
+	/**
442
+	 * wp_enqueue_scripts
443
+	 *
444
+	 * @return    void
445
+	 */
446
+	public function wp_enqueue_scripts()
447
+	{
448
+		// get some style
449
+		if (
450
+			apply_filters('FHEE_enable_default_espresso_css', TRUE)
451
+			&& apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', TRUE)
452
+		) {
453
+			// first check uploads folder
454
+			if (is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) {
455
+				wp_register_style(
456
+					$this->theme,
457
+					get_stylesheet_directory_uri() . $this->theme . DS . 'style.css',
458
+					array('dashicons', 'espresso_default')
459
+				);
460
+			} else {
461
+				wp_register_style(
462
+					$this->theme,
463
+					EE_TEMPLATES_URL . $this->theme . DS . 'style.css',
464
+					array('dashicons', 'espresso_default')
465
+				);
466
+			}
467
+			wp_enqueue_script($this->theme);
468
+			if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
469
+				add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
470
+			}
471
+		}
472
+	}
473
+
474
+
475
+	/**
476
+	 * display_venue
477
+	 *
478
+	 * @return    bool
479
+	 */
480
+	public static function display_venue()
481
+	{
482
+		/** @type EE_Event_Single_Config $config */
483
+		$config = EED_Event_Single::instance()->config();
484
+		$display_venue = $config->display_venue === null ? true : $config->display_venue;
485
+		$venue_name = EEH_Venue_View::venue_name();
486
+		return $display_venue && !empty($venue_name);
487
+	}
488 488
 
489 489
 
490 490
 }
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
  */
499 499
 function espresso_display_venue_in_event_details()
500 500
 {
501
-    return EED_Event_Single::display_venue();
501
+	return EED_Event_Single::display_venue();
502 502
 }
503 503
 
504 504
 
Please login to merge, or discard this patch.
caffeinated/brewing_regular.php 1 patch
Indentation   +281 added lines, -281 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use EventEspresso\core\services\database\TableAnalysis;
7 7
 
8 8
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
9
-    exit('No direct script access allowed');
9
+	exit('No direct script access allowed');
10 10
 }
11 11
 /**
12 12
  * the purpose of this file is to simply contain any action/filter hook callbacks etc for specific aspects of EE
@@ -31,289 +31,289 @@  discard block
 block discarded – undo
31 31
 class EE_Brewing_Regular extends EE_BASE implements InterminableInterface
32 32
 {
33 33
 
34
-    /**
35
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
36
-     */
37
-    protected $_table_analysis;
38
-
39
-
40
-    /**
41
-     * EE_Brewing_Regular constructor.
42
-     * @throws \DomainException
43
-     * @throws \EE_Error
44
-     * @throws InvalidDataTypeException
45
-     * @throws InvalidInterfaceException
46
-     * @throws \InvalidArgumentException
47
-     */
48
-    public function __construct(TableAnalysis $table_analysis)
49
-    {
50
-        $this->_table_analysis = $table_analysis;
51
-        if (defined('EE_CAFF_PATH')) {
52
-            // activation
53
-            add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content'));
54
-            // load caff init
55
-            add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init'));
56
-            // remove the "powered by" credit link from receipts and invoices
57
-            add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
58
-            // add caffeinated modules
59
-            add_filter(
60
-                'FHEE__EE_Config__register_modules__modules_to_register',
61
-                array($this, 'caffeinated_modules_to_register')
62
-            );
63
-            // load caff scripts
64
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10);
65
-            add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
66
-            //add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
67
-            EE_Register_Payment_Method::register(
68
-                'caffeinated_payment_methods',
69
-                array(
70
-                    'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR)
71
-                )
72
-            );
73
-            // caffeinated constructed
74
-            do_action('AHEE__EE_Brewing_Regular__construct__complete');
75
-            //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
76
-            add_filter('FHEE__ee_show_affiliate_links', '__return_false');
77
-        }
78
-    }
79
-
80
-
81
-
82
-    /**
83
-     * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
84
-     *
85
-     * @param array $paths original helper paths array
86
-     * @return array             new array of paths
87
-     */
88
-    public function caf_helper_paths($paths)
89
-    {
90
-        $paths[] = EE_CAF_CORE . 'helpers' . DS;
91
-        return $paths;
92
-    }
93
-
94
-
95
-
96
-    /**
97
-     * Upon brand-new activation, if this is a new activation of CAF, we want to add
98
-     * some global prices that will show off EE4's capabilities. However, if they're upgrading
99
-     * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
100
-     * This action should only be called when EE 4.x.0.P is initially activated.
101
-     * Right now the only CAF content are these global prices. If there's more in the future, then
102
-     * we should probably create a caf file to contain it all instead just a function like this.
103
-     * Right now, we ASSUME the only price types in the system are default ones
104
-     *
105
-     * @global wpdb $wpdb
106
-     */
107
-    public function initialize_caf_db_content()
108
-    {
109
-        global $wpdb;
110
-        //use same method of getting creator id as the version introducing the change
111
-        $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
112
-        $price_type_table = $wpdb->prefix . "esp_price_type";
113
-        $price_table = $wpdb->prefix . "esp_price";
114
-        if ($this->_get_table_analysis()->tableExists($price_type_table)) {
115
-            $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types
116
-            $tax_price_type_count = $wpdb->get_var($SQL);
117
-            if ($tax_price_type_count <= 1) {
118
-                $wpdb->insert(
119
-                    $price_type_table,
120
-                    array(
121
-                        'PRT_name'       => __("Regional Tax", "event_espresso"),
122
-                        'PBT_ID'         => 4,
123
-                        'PRT_is_percent' => true,
124
-                        'PRT_order'      => 60,
125
-                        'PRT_deleted'    => false,
126
-                        'PRT_wp_user'    => $default_creator_id,
127
-                    ),
128
-                    array(
129
-                        '%s',//PRT_name
130
-                        '%d',//PBT_id
131
-                        '%d',//PRT_is_percent
132
-                        '%d',//PRT_order
133
-                        '%d',//PRT_deleted
134
-                        '%d', //PRT_wp_user
135
-                    )
136
-                );
137
-                //federal tax
138
-                $result = $wpdb->insert(
139
-                    $price_type_table,
140
-                    array(
141
-                        'PRT_name'       => __("Federal Tax", "event_espresso"),
142
-                        'PBT_ID'         => 4,
143
-                        'PRT_is_percent' => true,
144
-                        'PRT_order'      => 70,
145
-                        'PRT_deleted'    => false,
146
-                        'PRT_wp_user'    => $default_creator_id,
147
-                    ),
148
-                    array(
149
-                        '%s',//PRT_name
150
-                        '%d',//PBT_id
151
-                        '%d',//PRT_is_percent
152
-                        '%d',//PRT_order
153
-                        '%d',//PRT_deleted
154
-                        '%d' //PRT_wp_user
155
-                    )
156
-                );
157
-                if ($result) {
158
-                    $wpdb->insert(
159
-                        $price_table,
160
-                        array(
161
-                            'PRT_ID'         => $wpdb->insert_id,
162
-                            'PRC_amount'     => 15.00,
163
-                            'PRC_name'       => __("Sales Tax", "event_espresso"),
164
-                            'PRC_desc'       => '',
165
-                            'PRC_is_default' => true,
166
-                            'PRC_overrides'  => null,
167
-                            'PRC_deleted'    => false,
168
-                            'PRC_order'      => 50,
169
-                            'PRC_parent'     => null,
170
-                            'PRC_wp_user'    => $default_creator_id,
171
-                        ),
172
-                        array(
173
-                            '%d',//PRT_id
174
-                            '%f',//PRC_amount
175
-                            '%s',//PRC_name
176
-                            '%s',//PRC_desc
177
-                            '%d',//PRC_is_default
178
-                            '%d',//PRC_overrides
179
-                            '%d',//PRC_deleted
180
-                            '%d',//PRC_order
181
-                            '%d',//PRC_parent
182
-                            '%d' //PRC_wp_user
183
-                        )
184
-                    );
185
-                }
186
-            }
187
-        }
188
-    }
189
-
190
-
191
-
192
-    /**
193
-     *    caffeinated_modules_to_register
194
-     *
195
-     * @access public
196
-     * @param array $modules_to_register
197
-     * @return array
198
-     */
199
-    public function caffeinated_modules_to_register($modules_to_register = array())
200
-    {
201
-        if (is_readable(EE_CAFF_PATH . 'modules')) {
202
-            $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
203
-            if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
204
-                $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
205
-            }
206
-        }
207
-        return $modules_to_register;
208
-    }
209
-
210
-
211
-    /**
212
-     * @throws EE_Error
213
-     * @throws InvalidArgumentException
214
-     * @throws ReflectionException
215
-     * @throws InvalidDataTypeException
216
-     * @throws InvalidInterfaceException
217
-     */
218
-    public function caffeinated_init()
219
-    {
220
-        // Custom Post Type hooks
221
-        add_filter(
222
-            'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies',
223
-            array($this, 'filter_taxonomies')
224
-        );
225
-        add_filter(
226
-            'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes',
227
-            array($this, 'filter_cpts')
228
-        );
229
-        add_filter(
230
-            'FHEE__EE_Admin__get_extra_nav_menu_pages_items',
231
-            array($this, 'nav_metabox_items')
232
-        );
233
-        EE_Registry::instance()->load_file(
234
-            EE_CAFF_PATH,
235
-            'EE_Caf_Messages',
236
-            'class',
237
-            array(),
238
-            false
239
-        );
240
-        // caffeinated_init__complete hook
241
-        do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
242
-    }
243
-
244
-
245
-
246
-    public function enqueue_caffeinated_scripts()
247
-    {
248
-        // sound of crickets...
249
-    }
250
-
251
-
252
-
253
-    /**
254
-     * callbacks below here
255
-     *
256
-     * @param array $taxonomy_array
257
-     * @return array
258
-     */
259
-    public function filter_taxonomies(array $taxonomy_array)
260
-    {
261
-        $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
262
-        return $taxonomy_array;
263
-    }
264
-
265
-
266
-
267
-    /**
268
-     * @param array $cpt_array
269
-     * @return mixed
270
-     */
271
-    public function filter_cpts(array $cpt_array)
272
-    {
273
-        $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
274
-        return $cpt_array;
275
-    }
276
-
277
-
278
-
279
-    /**
280
-     * @param array $menuitems
281
-     * @return array
282
-     */
283
-    public function nav_metabox_items(array $menuitems)
284
-    {
285
-        $menuitems[] = array(
286
-            'title'       => __('Venue List', 'event_espresso'),
287
-            'url'         => get_post_type_archive_link('espresso_venues'),
288
-            'description' => __('Archive page for all venues.', 'event_espresso'),
289
-        );
290
-        return $menuitems;
291
-    }
292
-
293
-
294
-    /**
295
-     * Gets the injected table analyzer, or throws an exception
296
-     *
297
-     * @return TableAnalysis
298
-     * @throws \EE_Error
299
-     */
300
-    protected function _get_table_analysis()
301
-    {
302
-        if ($this->_table_analysis instanceof TableAnalysis) {
303
-            return $this->_table_analysis;
304
-        } else {
305
-            throw new \EE_Error(
306
-                sprintf(
307
-                    __('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
308
-                    get_class($this)
309
-                )
310
-            );
311
-        }
312
-    }
34
+	/**
35
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
36
+	 */
37
+	protected $_table_analysis;
38
+
39
+
40
+	/**
41
+	 * EE_Brewing_Regular constructor.
42
+	 * @throws \DomainException
43
+	 * @throws \EE_Error
44
+	 * @throws InvalidDataTypeException
45
+	 * @throws InvalidInterfaceException
46
+	 * @throws \InvalidArgumentException
47
+	 */
48
+	public function __construct(TableAnalysis $table_analysis)
49
+	{
50
+		$this->_table_analysis = $table_analysis;
51
+		if (defined('EE_CAFF_PATH')) {
52
+			// activation
53
+			add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content'));
54
+			// load caff init
55
+			add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init'));
56
+			// remove the "powered by" credit link from receipts and invoices
57
+			add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false');
58
+			// add caffeinated modules
59
+			add_filter(
60
+				'FHEE__EE_Config__register_modules__modules_to_register',
61
+				array($this, 'caffeinated_modules_to_register')
62
+			);
63
+			// load caff scripts
64
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10);
65
+			add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
66
+			//add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10);
67
+			EE_Register_Payment_Method::register(
68
+				'caffeinated_payment_methods',
69
+				array(
70
+					'payment_method_paths' => glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR)
71
+				)
72
+			);
73
+			// caffeinated constructed
74
+			do_action('AHEE__EE_Brewing_Regular__construct__complete');
75
+			//seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer
76
+			add_filter('FHEE__ee_show_affiliate_links', '__return_false');
77
+		}
78
+	}
79
+
80
+
81
+
82
+	/**
83
+	 * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths
84
+	 *
85
+	 * @param array $paths original helper paths array
86
+	 * @return array             new array of paths
87
+	 */
88
+	public function caf_helper_paths($paths)
89
+	{
90
+		$paths[] = EE_CAF_CORE . 'helpers' . DS;
91
+		return $paths;
92
+	}
93
+
94
+
95
+
96
+	/**
97
+	 * Upon brand-new activation, if this is a new activation of CAF, we want to add
98
+	 * some global prices that will show off EE4's capabilities. However, if they're upgrading
99
+	 * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices.
100
+	 * This action should only be called when EE 4.x.0.P is initially activated.
101
+	 * Right now the only CAF content are these global prices. If there's more in the future, then
102
+	 * we should probably create a caf file to contain it all instead just a function like this.
103
+	 * Right now, we ASSUME the only price types in the system are default ones
104
+	 *
105
+	 * @global wpdb $wpdb
106
+	 */
107
+	public function initialize_caf_db_content()
108
+	{
109
+		global $wpdb;
110
+		//use same method of getting creator id as the version introducing the change
111
+		$default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id());
112
+		$price_type_table = $wpdb->prefix . "esp_price_type";
113
+		$price_table = $wpdb->prefix . "esp_price";
114
+		if ($this->_get_table_analysis()->tableExists($price_type_table)) {
115
+			$SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types
116
+			$tax_price_type_count = $wpdb->get_var($SQL);
117
+			if ($tax_price_type_count <= 1) {
118
+				$wpdb->insert(
119
+					$price_type_table,
120
+					array(
121
+						'PRT_name'       => __("Regional Tax", "event_espresso"),
122
+						'PBT_ID'         => 4,
123
+						'PRT_is_percent' => true,
124
+						'PRT_order'      => 60,
125
+						'PRT_deleted'    => false,
126
+						'PRT_wp_user'    => $default_creator_id,
127
+					),
128
+					array(
129
+						'%s',//PRT_name
130
+						'%d',//PBT_id
131
+						'%d',//PRT_is_percent
132
+						'%d',//PRT_order
133
+						'%d',//PRT_deleted
134
+						'%d', //PRT_wp_user
135
+					)
136
+				);
137
+				//federal tax
138
+				$result = $wpdb->insert(
139
+					$price_type_table,
140
+					array(
141
+						'PRT_name'       => __("Federal Tax", "event_espresso"),
142
+						'PBT_ID'         => 4,
143
+						'PRT_is_percent' => true,
144
+						'PRT_order'      => 70,
145
+						'PRT_deleted'    => false,
146
+						'PRT_wp_user'    => $default_creator_id,
147
+					),
148
+					array(
149
+						'%s',//PRT_name
150
+						'%d',//PBT_id
151
+						'%d',//PRT_is_percent
152
+						'%d',//PRT_order
153
+						'%d',//PRT_deleted
154
+						'%d' //PRT_wp_user
155
+					)
156
+				);
157
+				if ($result) {
158
+					$wpdb->insert(
159
+						$price_table,
160
+						array(
161
+							'PRT_ID'         => $wpdb->insert_id,
162
+							'PRC_amount'     => 15.00,
163
+							'PRC_name'       => __("Sales Tax", "event_espresso"),
164
+							'PRC_desc'       => '',
165
+							'PRC_is_default' => true,
166
+							'PRC_overrides'  => null,
167
+							'PRC_deleted'    => false,
168
+							'PRC_order'      => 50,
169
+							'PRC_parent'     => null,
170
+							'PRC_wp_user'    => $default_creator_id,
171
+						),
172
+						array(
173
+							'%d',//PRT_id
174
+							'%f',//PRC_amount
175
+							'%s',//PRC_name
176
+							'%s',//PRC_desc
177
+							'%d',//PRC_is_default
178
+							'%d',//PRC_overrides
179
+							'%d',//PRC_deleted
180
+							'%d',//PRC_order
181
+							'%d',//PRC_parent
182
+							'%d' //PRC_wp_user
183
+						)
184
+					);
185
+				}
186
+			}
187
+		}
188
+	}
189
+
190
+
191
+
192
+	/**
193
+	 *    caffeinated_modules_to_register
194
+	 *
195
+	 * @access public
196
+	 * @param array $modules_to_register
197
+	 * @return array
198
+	 */
199
+	public function caffeinated_modules_to_register($modules_to_register = array())
200
+	{
201
+		if (is_readable(EE_CAFF_PATH . 'modules')) {
202
+			$caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR);
203
+			if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) {
204
+				$modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register);
205
+			}
206
+		}
207
+		return $modules_to_register;
208
+	}
209
+
210
+
211
+	/**
212
+	 * @throws EE_Error
213
+	 * @throws InvalidArgumentException
214
+	 * @throws ReflectionException
215
+	 * @throws InvalidDataTypeException
216
+	 * @throws InvalidInterfaceException
217
+	 */
218
+	public function caffeinated_init()
219
+	{
220
+		// Custom Post Type hooks
221
+		add_filter(
222
+			'FHEE__EventEspresso_core_domain_entities_custom_post_types_TaxonomyDefinitions__getTaxonomies',
223
+			array($this, 'filter_taxonomies')
224
+		);
225
+		add_filter(
226
+			'FHEE__EventEspresso_core_domain_entities_custom_post_types_CustomPostTypeDefinitions__getCustomPostTypes',
227
+			array($this, 'filter_cpts')
228
+		);
229
+		add_filter(
230
+			'FHEE__EE_Admin__get_extra_nav_menu_pages_items',
231
+			array($this, 'nav_metabox_items')
232
+		);
233
+		EE_Registry::instance()->load_file(
234
+			EE_CAFF_PATH,
235
+			'EE_Caf_Messages',
236
+			'class',
237
+			array(),
238
+			false
239
+		);
240
+		// caffeinated_init__complete hook
241
+		do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete');
242
+	}
243
+
244
+
245
+
246
+	public function enqueue_caffeinated_scripts()
247
+	{
248
+		// sound of crickets...
249
+	}
250
+
251
+
252
+
253
+	/**
254
+	 * callbacks below here
255
+	 *
256
+	 * @param array $taxonomy_array
257
+	 * @return array
258
+	 */
259
+	public function filter_taxonomies(array $taxonomy_array)
260
+	{
261
+		$taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true;
262
+		return $taxonomy_array;
263
+	}
264
+
265
+
266
+
267
+	/**
268
+	 * @param array $cpt_array
269
+	 * @return mixed
270
+	 */
271
+	public function filter_cpts(array $cpt_array)
272
+	{
273
+		$cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true;
274
+		return $cpt_array;
275
+	}
276
+
277
+
278
+
279
+	/**
280
+	 * @param array $menuitems
281
+	 * @return array
282
+	 */
283
+	public function nav_metabox_items(array $menuitems)
284
+	{
285
+		$menuitems[] = array(
286
+			'title'       => __('Venue List', 'event_espresso'),
287
+			'url'         => get_post_type_archive_link('espresso_venues'),
288
+			'description' => __('Archive page for all venues.', 'event_espresso'),
289
+		);
290
+		return $menuitems;
291
+	}
292
+
293
+
294
+	/**
295
+	 * Gets the injected table analyzer, or throws an exception
296
+	 *
297
+	 * @return TableAnalysis
298
+	 * @throws \EE_Error
299
+	 */
300
+	protected function _get_table_analysis()
301
+	{
302
+		if ($this->_table_analysis instanceof TableAnalysis) {
303
+			return $this->_table_analysis;
304
+		} else {
305
+			throw new \EE_Error(
306
+				sprintf(
307
+					__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
308
+					get_class($this)
309
+				)
310
+			);
311
+		}
312
+	}
313 313
 }
314 314
 
315 315
 
316 316
 
317 317
 $brewing = new EE_Brewing_Regular(
318
-    EE_Registry::instance()->create('TableAnalysis', array(), true)
318
+	EE_Registry::instance()->create('TableAnalysis', array(), true)
319 319
 );
320 320
\ No newline at end of file
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_CPT.core.php 2 patches
Indentation   +1444 added lines, -1444 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use EventEspresso\core\services\request\middleware\RecommendedVersions;
7 7
 
8 8
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
9
-    exit('No direct script access allowed');
9
+	exit('No direct script access allowed');
10 10
 }
11 11
 
12 12
 /**
@@ -31,475 +31,475 @@  discard block
 block discarded – undo
31 31
 {
32 32
 
33 33
 
34
-    /**
35
-     * This gets set in _setup_cpt
36
-     * It will contain the object for the custom post type.
37
-     *
38
-     * @var EE_CPT_Base
39
-     */
40
-    protected $_cpt_object;
41
-
42
-
43
-
44
-    /**
45
-     * a boolean flag to set whether the current route is a cpt route or not.
46
-     *
47
-     * @var bool
48
-     */
49
-    protected $_cpt_route = false;
50
-
51
-
52
-
53
-    /**
54
-     * This property allows cpt classes to define multiple routes as cpt routes.
55
-     * //in this array we define what the custom post type for this route is.
56
-     * array(
57
-     * 'route_name' => 'custom_post_type_slug'
58
-     * )
59
-     *
60
-     * @var array
61
-     */
62
-    protected $_cpt_routes = array();
63
-
34
+	/**
35
+	 * This gets set in _setup_cpt
36
+	 * It will contain the object for the custom post type.
37
+	 *
38
+	 * @var EE_CPT_Base
39
+	 */
40
+	protected $_cpt_object;
41
+
42
+
43
+
44
+	/**
45
+	 * a boolean flag to set whether the current route is a cpt route or not.
46
+	 *
47
+	 * @var bool
48
+	 */
49
+	protected $_cpt_route = false;
50
+
51
+
52
+
53
+	/**
54
+	 * This property allows cpt classes to define multiple routes as cpt routes.
55
+	 * //in this array we define what the custom post type for this route is.
56
+	 * array(
57
+	 * 'route_name' => 'custom_post_type_slug'
58
+	 * )
59
+	 *
60
+	 * @var array
61
+	 */
62
+	protected $_cpt_routes = array();
63
+
64 64
 
65 65
 
66
-    /**
67
-     * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
68
-     * in this format:
69
-     * array(
70
-     * 'post_type_slug' => 'edit_route'
71
-     * )
72
-     *
73
-     * @var array
74
-     */
75
-    protected $_cpt_edit_routes = array();
76
-
77
-
78
-
79
-    /**
80
-     * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
81
-     * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
82
-     * _cpt_model_names property should be in the following format: array(
83
-     * 'route_defined_by_action_param' => 'Model_Name')
84
-     *
85
-     * @var array $_cpt_model_names
86
-     */
87
-    protected $_cpt_model_names = array();
88
-
89
-
90
-    /**
91
-     * @var EE_CPT_Base
92
-     */
93
-    protected $_cpt_model_obj = false;
94
-
95
-
96
-
97
-    /**
98
-     * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
99
-     * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
100
-     * the _register_autosave_containers() method so that we don't override any other containers already registered.
101
-     * Registration of containers should be done before load_page_dependencies() is run.
102
-     *
103
-     * @var array()
104
-     */
105
-    protected $_autosave_containers = array();
106
-    protected $_autosave_fields = array();
107
-
108
-    /**
109
-     * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
110
-     * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
111
-     *
112
-     * @var array
113
-     */
114
-    protected $_pagenow_map;
115
-
116
-
117
-
118
-    /**
119
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
120
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
121
-     * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
122
-     * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
123
-     * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
124
-     *
125
-     * @access protected
126
-     * @abstract
127
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
128
-     * @param  EE_CPT_Base $post    The post object of the cpt that was saved.
129
-     * @return void
130
-     */
131
-    abstract protected function _insert_update_cpt_item($post_id, $post);
132
-
133
-
134
-
135
-    /**
136
-     * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
137
-     *
138
-     * @abstract
139
-     * @access public
140
-     * @param  string $post_id The ID of the cpt that was trashed
141
-     * @return void
142
-     */
143
-    abstract public function trash_cpt_item($post_id);
144
-
145
-
146
-
147
-    /**
148
-     * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
149
-     *
150
-     * @param  string $post_id theID of the cpt that was untrashed
151
-     * @return void
152
-     */
153
-    abstract public function restore_cpt_item($post_id);
154
-
155
-
156
-
157
-    /**
158
-     * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
159
-     * from the db
160
-     *
161
-     * @param  string $post_id the ID of the cpt that was deleted
162
-     * @return void
163
-     */
164
-    abstract public function delete_cpt_item($post_id);
165
-
166
-
167
-
168
-    /**
169
-     * Just utilizing the method EE_Admin exposes for doing things before page setup.
170
-     *
171
-     * @access protected
172
-     * @return void
173
-     */
174
-    protected function _before_page_setup()
175
-    {
176
-        $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
177
-        $this->_cpt_routes = array_merge(array(
178
-            'create_new' => $this->page_slug,
179
-            'edit'       => $this->page_slug,
180
-            'trash'      => $this->page_slug,
181
-        ), $this->_cpt_routes);
182
-        //let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
183
-        $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']])
184
-            ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
185
-            : get_post_type_object($page);
186
-        //tweak pagenow for page loading.
187
-        if ( ! $this->_pagenow_map) {
188
-            $this->_pagenow_map = array(
189
-                'create_new' => 'post-new.php',
190
-                'edit'       => 'post.php',
191
-                'trash'      => 'post.php',
192
-            );
193
-        }
194
-        add_action('current_screen', array($this, 'modify_pagenow'));
195
-        //TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
196
-        //get current page from autosave
197
-        $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
198
-            ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
199
-            : null;
200
-        $this->_current_page = isset($this->_req_data['current_page'])
201
-            ? $this->_req_data['current_page']
202
-            : $current_page;
203
-        //autosave... make sure its only for the correct page
204
-        //if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
205
-            //setup autosave ajax hook
206
-            //add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
207
-        //}
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     * Simply ensure that we simulate the correct post route for cpt screens
214
-     *
215
-     * @param WP_Screen $current_screen
216
-     * @return void
217
-     */
218
-    public function modify_pagenow($current_screen)
219
-    {
220
-        global $pagenow, $hook_suffix;
221
-        //possibly reset pagenow.
222
-        if ( ! empty($this->_req_data['page'])
223
-             && $this->_req_data['page'] == $this->page_slug
224
-             && ! empty($this->_req_data['action'])
225
-             && isset($this->_pagenow_map[$this->_req_data['action']])
226
-        ) {
227
-            $pagenow = $this->_pagenow_map[$this->_req_data['action']];
228
-            $hook_suffix = $pagenow;
229
-        }
230
-    }
231
-
232
-
233
-
234
-    /**
235
-     * This method is used to register additional autosave containers to the _autosave_containers property.
236
-     *
237
-     * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
238
-     *       automatically register the id for the post metabox as a container.
239
-     * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
240
-     *                    you would send along the id of a metabox container.
241
-     * @return void
242
-     */
243
-    protected function _register_autosave_containers($ids)
244
-    {
245
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
246
-    }
247
-
248
-
249
-
250
-    /**
251
-     * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
252
-     * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
253
-     */
254
-    protected function _set_autosave_containers()
255
-    {
256
-        global $wp_meta_boxes;
257
-        $containers = array();
258
-        if (empty($wp_meta_boxes)) {
259
-            return;
260
-        }
261
-        $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
262
-        foreach ($current_metaboxes as $box_context) {
263
-            foreach ($box_context as $box_details) {
264
-                foreach ($box_details as $box) {
265
-                    if (
266
-                        is_array($box['callback'])
267
-                        && (
268
-                            $box['callback'][0] instanceof EE_Admin_Page
269
-                            || $box['callback'][0] instanceof EE_Admin_Hooks
270
-                        )
271
-                    ) {
272
-                        $containers[] = $box['id'];
273
-                    }
274
-                }
275
-            }
276
-        }
277
-        $this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
278
-        //add hidden inputs container
279
-        $this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
280
-    }
281
-
282
-
283
-
284
-    protected function _load_autosave_scripts_styles()
285
-    {
286
-        /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
66
+	/**
67
+	 * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
68
+	 * in this format:
69
+	 * array(
70
+	 * 'post_type_slug' => 'edit_route'
71
+	 * )
72
+	 *
73
+	 * @var array
74
+	 */
75
+	protected $_cpt_edit_routes = array();
76
+
77
+
78
+
79
+	/**
80
+	 * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
81
+	 * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
82
+	 * _cpt_model_names property should be in the following format: array(
83
+	 * 'route_defined_by_action_param' => 'Model_Name')
84
+	 *
85
+	 * @var array $_cpt_model_names
86
+	 */
87
+	protected $_cpt_model_names = array();
88
+
89
+
90
+	/**
91
+	 * @var EE_CPT_Base
92
+	 */
93
+	protected $_cpt_model_obj = false;
94
+
95
+
96
+
97
+	/**
98
+	 * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
99
+	 * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
100
+	 * the _register_autosave_containers() method so that we don't override any other containers already registered.
101
+	 * Registration of containers should be done before load_page_dependencies() is run.
102
+	 *
103
+	 * @var array()
104
+	 */
105
+	protected $_autosave_containers = array();
106
+	protected $_autosave_fields = array();
107
+
108
+	/**
109
+	 * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
110
+	 * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
111
+	 *
112
+	 * @var array
113
+	 */
114
+	protected $_pagenow_map;
115
+
116
+
117
+
118
+	/**
119
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
120
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
121
+	 * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
122
+	 * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
123
+	 * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
124
+	 *
125
+	 * @access protected
126
+	 * @abstract
127
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
128
+	 * @param  EE_CPT_Base $post    The post object of the cpt that was saved.
129
+	 * @return void
130
+	 */
131
+	abstract protected function _insert_update_cpt_item($post_id, $post);
132
+
133
+
134
+
135
+	/**
136
+	 * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
137
+	 *
138
+	 * @abstract
139
+	 * @access public
140
+	 * @param  string $post_id The ID of the cpt that was trashed
141
+	 * @return void
142
+	 */
143
+	abstract public function trash_cpt_item($post_id);
144
+
145
+
146
+
147
+	/**
148
+	 * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
149
+	 *
150
+	 * @param  string $post_id theID of the cpt that was untrashed
151
+	 * @return void
152
+	 */
153
+	abstract public function restore_cpt_item($post_id);
154
+
155
+
156
+
157
+	/**
158
+	 * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
159
+	 * from the db
160
+	 *
161
+	 * @param  string $post_id the ID of the cpt that was deleted
162
+	 * @return void
163
+	 */
164
+	abstract public function delete_cpt_item($post_id);
165
+
166
+
167
+
168
+	/**
169
+	 * Just utilizing the method EE_Admin exposes for doing things before page setup.
170
+	 *
171
+	 * @access protected
172
+	 * @return void
173
+	 */
174
+	protected function _before_page_setup()
175
+	{
176
+		$page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
177
+		$this->_cpt_routes = array_merge(array(
178
+			'create_new' => $this->page_slug,
179
+			'edit'       => $this->page_slug,
180
+			'trash'      => $this->page_slug,
181
+		), $this->_cpt_routes);
182
+		//let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
183
+		$this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']])
184
+			? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
185
+			: get_post_type_object($page);
186
+		//tweak pagenow for page loading.
187
+		if ( ! $this->_pagenow_map) {
188
+			$this->_pagenow_map = array(
189
+				'create_new' => 'post-new.php',
190
+				'edit'       => 'post.php',
191
+				'trash'      => 'post.php',
192
+			);
193
+		}
194
+		add_action('current_screen', array($this, 'modify_pagenow'));
195
+		//TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
196
+		//get current page from autosave
197
+		$current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
198
+			? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
199
+			: null;
200
+		$this->_current_page = isset($this->_req_data['current_page'])
201
+			? $this->_req_data['current_page']
202
+			: $current_page;
203
+		//autosave... make sure its only for the correct page
204
+		//if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
205
+			//setup autosave ajax hook
206
+			//add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
207
+		//}
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 * Simply ensure that we simulate the correct post route for cpt screens
214
+	 *
215
+	 * @param WP_Screen $current_screen
216
+	 * @return void
217
+	 */
218
+	public function modify_pagenow($current_screen)
219
+	{
220
+		global $pagenow, $hook_suffix;
221
+		//possibly reset pagenow.
222
+		if ( ! empty($this->_req_data['page'])
223
+			 && $this->_req_data['page'] == $this->page_slug
224
+			 && ! empty($this->_req_data['action'])
225
+			 && isset($this->_pagenow_map[$this->_req_data['action']])
226
+		) {
227
+			$pagenow = $this->_pagenow_map[$this->_req_data['action']];
228
+			$hook_suffix = $pagenow;
229
+		}
230
+	}
231
+
232
+
233
+
234
+	/**
235
+	 * This method is used to register additional autosave containers to the _autosave_containers property.
236
+	 *
237
+	 * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
238
+	 *       automatically register the id for the post metabox as a container.
239
+	 * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
240
+	 *                    you would send along the id of a metabox container.
241
+	 * @return void
242
+	 */
243
+	protected function _register_autosave_containers($ids)
244
+	{
245
+		$this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
246
+	}
247
+
248
+
249
+
250
+	/**
251
+	 * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
252
+	 * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
253
+	 */
254
+	protected function _set_autosave_containers()
255
+	{
256
+		global $wp_meta_boxes;
257
+		$containers = array();
258
+		if (empty($wp_meta_boxes)) {
259
+			return;
260
+		}
261
+		$current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
262
+		foreach ($current_metaboxes as $box_context) {
263
+			foreach ($box_context as $box_details) {
264
+				foreach ($box_details as $box) {
265
+					if (
266
+						is_array($box['callback'])
267
+						&& (
268
+							$box['callback'][0] instanceof EE_Admin_Page
269
+							|| $box['callback'][0] instanceof EE_Admin_Hooks
270
+						)
271
+					) {
272
+						$containers[] = $box['id'];
273
+					}
274
+				}
275
+			}
276
+		}
277
+		$this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
278
+		//add hidden inputs container
279
+		$this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
280
+	}
281
+
282
+
283
+
284
+	protected function _load_autosave_scripts_styles()
285
+	{
286
+		/*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
287 287
         wp_enqueue_script('cpt-autosave');/**/ //todo re-enable when we start doing autosave again in 4.2
288 288
 
289
-        //filter _autosave_containers
290
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
291
-            $this->_autosave_containers, $this);
292
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
293
-            $containers, $this);
294
-
295
-        wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
296
-            $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
297
-
298
-        $unsaved_data_msg = array(
299
-            'eventmsg'     => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.",
300
-                'event_espresso'), $this->_cpt_object->labels->singular_name),
301
-            'inputChanged' => 0,
302
-        );
303
-        wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
304
-    }
305
-
306
-
307
-
308
-    public function load_page_dependencies()
309
-    {
310
-        try {
311
-            $this->_load_page_dependencies();
312
-        } catch (EE_Error $e) {
313
-            $e->get_error();
314
-        }
315
-    }
316
-
317
-
318
-
319
-    /**
320
-     * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
321
-     *
322
-     * @access protected
323
-     * @return void
324
-     */
325
-    protected function _load_page_dependencies()
326
-    {
327
-        //we only add stuff if this is a cpt_route!
328
-        if ( ! $this->_cpt_route) {
329
-            parent::_load_page_dependencies();
330
-            return;
331
-        }
332
-        // now let's do some automatic filters into the wp_system
333
-        // and we'll check to make sure the CHILD class
334
-        // automatically has the required methods in place.
335
-        // the following filters are for setting all the redirects
336
-        // on DEFAULT WP custom post type actions
337
-        // let's add a hidden input to the post-edit form
338
-        // so we know when we have to trigger our custom redirects!
339
-        // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
340
-        add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
341
-        // inject our Admin page nav tabs...
342
-        // let's make sure the nav tabs are set if they aren't already
343
-        // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
344
-        add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
345
-        // modify the post_updated messages array
346
-        add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
347
-        // add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
348
-        // cpts use the same format for shortlinks as posts!
349
-        add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
350
-        // This basically allows us to change the title of the "publish" metabox area
351
-        // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
352
-        if ( ! empty($this->_labels['publishbox'])) {
353
-            $box_label = is_array($this->_labels['publishbox'])
354
-                         && isset($this->_labels['publishbox'][$this->_req_action])
355
-                    ? $this->_labels['publishbox'][$this->_req_action]
356
-                    : $this->_labels['publishbox'];
357
-            add_meta_box(
358
-                'submitdiv',
359
-                $box_label,
360
-                'post_submit_meta_box',
361
-                $this->_cpt_routes[$this->_req_action],
362
-                'side',
363
-                'core'
364
-            );
365
-        }
366
-        //let's add page_templates metabox if this cpt added support for it.
367
-        if ($this->_supports_page_templates($this->_cpt_object->name)) {
368
-            add_meta_box(
369
-                'page_templates',
370
-                __('Page Template', 'event_espresso'),
371
-                array($this, 'page_template_meta_box'),
372
-                $this->_cpt_routes[$this->_req_action],
373
-                'side',
374
-                'default'
375
-            );
376
-        }
377
-        //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
378
-        if (method_exists($this, 'extra_permalink_field_buttons')) {
379
-            add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
380
-        }
381
-        //add preview button
382
-        add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
383
-        //insert our own post_stati dropdown
384
-        add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
385
-        //This allows adding additional information to the publish post submitbox on the wp post edit form
386
-        if (method_exists($this, 'extra_misc_actions_publish_box')) {
387
-            add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
388
-        }
389
-        // This allows for adding additional stuff after the title field on the wp post edit form.
390
-        // This is also before the wp_editor for post description field.
391
-        if (method_exists($this, 'edit_form_after_title')) {
392
-            add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
393
-        }
394
-        /**
395
-         * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
396
-         */
397
-        add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
398
-        parent::_load_page_dependencies();
399
-        // notice we are ALSO going to load the pagenow hook set for this route
400
-        // (see _before_page_setup for the reset of the pagenow global ).
401
-        // This is for any plugins that are doing things properly
402
-        // and hooking into the load page hook for core wp cpt routes.
403
-        global $pagenow;
404
-        do_action('load-' . $pagenow);
405
-        $this->modify_current_screen();
406
-        add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
407
-        //we route REALLY early.
408
-        try {
409
-            $this->_route_admin_request();
410
-        } catch (EE_Error $e) {
411
-            $e->get_error();
412
-        }
413
-    }
414
-
415
-
416
-
417
-    /**
418
-     * Since we don't want users going to default core wp routes, this will check any wp urls run through the
419
-     * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
420
-     * route instead.
421
-     *
422
-     * @param string $good_protocol_url The escaped url.
423
-     * @param string $original_url      The original url.
424
-     * @param string $_context          The context sent to the esc_url method.
425
-     * @return string possibly a new url for our route.
426
-     */
427
-    public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
428
-    {
429
-        $routes_to_match = array(
430
-            0 => array(
431
-                'edit.php?post_type=espresso_attendees',
432
-                'admin.php?page=espresso_registrations&action=contact_list',
433
-            ),
434
-            1 => array(
435
-                'edit.php?post_type=' . $this->_cpt_object->name,
436
-                'admin.php?page=' . $this->_cpt_object->name,
437
-            ),
438
-        );
439
-        foreach ($routes_to_match as $route_matches) {
440
-            if (strpos($good_protocol_url, $route_matches[0]) !== false) {
441
-                return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
442
-            }
443
-        }
444
-        return $good_protocol_url;
445
-    }
446
-
447
-
448
-    /**
449
-     * Determine whether the current cpt supports page templates or not.
450
-     *
451
-     * @since %VER%
452
-     * @param string $cpt_name The cpt slug we're checking on.
453
-     * @return bool True supported, false not.
454
-     * @throws InvalidArgumentException
455
-     * @throws InvalidDataTypeException
456
-     * @throws InvalidInterfaceException
457
-     */
458
-    private function _supports_page_templates($cpt_name)
459
-    {
460
-        /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
461
-        $custom_post_types = LoaderFactory::getLoader()->getShared(
462
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
463
-        );
464
-        $cpt_args = $custom_post_types->getDefinitions();
465
-        $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
466
-        $cpt_has_support = ! empty($cpt_args['page_templates']);
467
-
468
-        //if the installed version of WP is > 4.7 we do some additional checks.
469
-        if (RecommendedVersions::compareWordPressVersion('4.7','>=')) {
470
-            $post_templates = wp_get_theme()->get_post_templates();
471
-            //if there are $post_templates for this cpt, then we return false for this method because
472
-            //that means we aren't going to load our page template manager and leave that up to the native
473
-            //cpt template manager.
474
-            $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
475
-        }
476
-
477
-        return $cpt_has_support;
478
-    }
479
-
480
-
481
-    /**
482
-     * Callback for the page_templates metabox selector.
483
-     *
484
-     * @since %VER%
485
-     * @return void
486
-     */
487
-    public function page_template_meta_box()
488
-    {
489
-        global $post;
490
-        $template = '';
491
-
492
-        if (RecommendedVersions::compareWordPressVersion('4.7','>=')) {
493
-            $page_template_count = count(get_page_templates());
494
-        } else {
495
-            $page_template_count = count(get_page_templates($post));
496
-        };
497
-
498
-        if ($page_template_count) {
499
-            $page_template = get_post_meta($post->ID, '_wp_page_template', true);
500
-            $template      = ! empty($page_template) ? $page_template : '';
501
-        }
502
-        ?>
289
+		//filter _autosave_containers
290
+		$containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
291
+			$this->_autosave_containers, $this);
292
+		$containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
293
+			$containers, $this);
294
+
295
+		wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
296
+			$containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
297
+
298
+		$unsaved_data_msg = array(
299
+			'eventmsg'     => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.",
300
+				'event_espresso'), $this->_cpt_object->labels->singular_name),
301
+			'inputChanged' => 0,
302
+		);
303
+		wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
304
+	}
305
+
306
+
307
+
308
+	public function load_page_dependencies()
309
+	{
310
+		try {
311
+			$this->_load_page_dependencies();
312
+		} catch (EE_Error $e) {
313
+			$e->get_error();
314
+		}
315
+	}
316
+
317
+
318
+
319
+	/**
320
+	 * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
321
+	 *
322
+	 * @access protected
323
+	 * @return void
324
+	 */
325
+	protected function _load_page_dependencies()
326
+	{
327
+		//we only add stuff if this is a cpt_route!
328
+		if ( ! $this->_cpt_route) {
329
+			parent::_load_page_dependencies();
330
+			return;
331
+		}
332
+		// now let's do some automatic filters into the wp_system
333
+		// and we'll check to make sure the CHILD class
334
+		// automatically has the required methods in place.
335
+		// the following filters are for setting all the redirects
336
+		// on DEFAULT WP custom post type actions
337
+		// let's add a hidden input to the post-edit form
338
+		// so we know when we have to trigger our custom redirects!
339
+		// Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
340
+		add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
341
+		// inject our Admin page nav tabs...
342
+		// let's make sure the nav tabs are set if they aren't already
343
+		// if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
344
+		add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
345
+		// modify the post_updated messages array
346
+		add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
347
+		// add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE,
348
+		// cpts use the same format for shortlinks as posts!
349
+		add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
350
+		// This basically allows us to change the title of the "publish" metabox area
351
+		// on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
352
+		if ( ! empty($this->_labels['publishbox'])) {
353
+			$box_label = is_array($this->_labels['publishbox'])
354
+						 && isset($this->_labels['publishbox'][$this->_req_action])
355
+					? $this->_labels['publishbox'][$this->_req_action]
356
+					: $this->_labels['publishbox'];
357
+			add_meta_box(
358
+				'submitdiv',
359
+				$box_label,
360
+				'post_submit_meta_box',
361
+				$this->_cpt_routes[$this->_req_action],
362
+				'side',
363
+				'core'
364
+			);
365
+		}
366
+		//let's add page_templates metabox if this cpt added support for it.
367
+		if ($this->_supports_page_templates($this->_cpt_object->name)) {
368
+			add_meta_box(
369
+				'page_templates',
370
+				__('Page Template', 'event_espresso'),
371
+				array($this, 'page_template_meta_box'),
372
+				$this->_cpt_routes[$this->_req_action],
373
+				'side',
374
+				'default'
375
+			);
376
+		}
377
+		//this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
378
+		if (method_exists($this, 'extra_permalink_field_buttons')) {
379
+			add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
380
+		}
381
+		//add preview button
382
+		add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
383
+		//insert our own post_stati dropdown
384
+		add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
385
+		//This allows adding additional information to the publish post submitbox on the wp post edit form
386
+		if (method_exists($this, 'extra_misc_actions_publish_box')) {
387
+			add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
388
+		}
389
+		// This allows for adding additional stuff after the title field on the wp post edit form.
390
+		// This is also before the wp_editor for post description field.
391
+		if (method_exists($this, 'edit_form_after_title')) {
392
+			add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
393
+		}
394
+		/**
395
+		 * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
396
+		 */
397
+		add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
398
+		parent::_load_page_dependencies();
399
+		// notice we are ALSO going to load the pagenow hook set for this route
400
+		// (see _before_page_setup for the reset of the pagenow global ).
401
+		// This is for any plugins that are doing things properly
402
+		// and hooking into the load page hook for core wp cpt routes.
403
+		global $pagenow;
404
+		do_action('load-' . $pagenow);
405
+		$this->modify_current_screen();
406
+		add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
407
+		//we route REALLY early.
408
+		try {
409
+			$this->_route_admin_request();
410
+		} catch (EE_Error $e) {
411
+			$e->get_error();
412
+		}
413
+	}
414
+
415
+
416
+
417
+	/**
418
+	 * Since we don't want users going to default core wp routes, this will check any wp urls run through the
419
+	 * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
420
+	 * route instead.
421
+	 *
422
+	 * @param string $good_protocol_url The escaped url.
423
+	 * @param string $original_url      The original url.
424
+	 * @param string $_context          The context sent to the esc_url method.
425
+	 * @return string possibly a new url for our route.
426
+	 */
427
+	public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
428
+	{
429
+		$routes_to_match = array(
430
+			0 => array(
431
+				'edit.php?post_type=espresso_attendees',
432
+				'admin.php?page=espresso_registrations&action=contact_list',
433
+			),
434
+			1 => array(
435
+				'edit.php?post_type=' . $this->_cpt_object->name,
436
+				'admin.php?page=' . $this->_cpt_object->name,
437
+			),
438
+		);
439
+		foreach ($routes_to_match as $route_matches) {
440
+			if (strpos($good_protocol_url, $route_matches[0]) !== false) {
441
+				return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
442
+			}
443
+		}
444
+		return $good_protocol_url;
445
+	}
446
+
447
+
448
+	/**
449
+	 * Determine whether the current cpt supports page templates or not.
450
+	 *
451
+	 * @since %VER%
452
+	 * @param string $cpt_name The cpt slug we're checking on.
453
+	 * @return bool True supported, false not.
454
+	 * @throws InvalidArgumentException
455
+	 * @throws InvalidDataTypeException
456
+	 * @throws InvalidInterfaceException
457
+	 */
458
+	private function _supports_page_templates($cpt_name)
459
+	{
460
+		/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
461
+		$custom_post_types = LoaderFactory::getLoader()->getShared(
462
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
463
+		);
464
+		$cpt_args = $custom_post_types->getDefinitions();
465
+		$cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
466
+		$cpt_has_support = ! empty($cpt_args['page_templates']);
467
+
468
+		//if the installed version of WP is > 4.7 we do some additional checks.
469
+		if (RecommendedVersions::compareWordPressVersion('4.7','>=')) {
470
+			$post_templates = wp_get_theme()->get_post_templates();
471
+			//if there are $post_templates for this cpt, then we return false for this method because
472
+			//that means we aren't going to load our page template manager and leave that up to the native
473
+			//cpt template manager.
474
+			$cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
475
+		}
476
+
477
+		return $cpt_has_support;
478
+	}
479
+
480
+
481
+	/**
482
+	 * Callback for the page_templates metabox selector.
483
+	 *
484
+	 * @since %VER%
485
+	 * @return void
486
+	 */
487
+	public function page_template_meta_box()
488
+	{
489
+		global $post;
490
+		$template = '';
491
+
492
+		if (RecommendedVersions::compareWordPressVersion('4.7','>=')) {
493
+			$page_template_count = count(get_page_templates());
494
+		} else {
495
+			$page_template_count = count(get_page_templates($post));
496
+		};
497
+
498
+		if ($page_template_count) {
499
+			$page_template = get_post_meta($post->ID, '_wp_page_template', true);
500
+			$template      = ! empty($page_template) ? $page_template : '';
501
+		}
502
+		?>
503 503
         <p><strong><?php _e('Template') ?></strong></p>
504 504
         <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select
505 505
             name="page_template" id="page_template">
@@ -507,457 +507,457 @@  discard block
 block discarded – undo
507 507
         <?php page_template_dropdown($template); ?>
508 508
     </select>
509 509
         <?php
510
-    }
511
-
512
-
513
-
514
-    /**
515
-     * if this post is a draft or scheduled post then we provide a preview button for user to click
516
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
517
-     *
518
-     * @param  string $return    the current html
519
-     * @param  int    $id        the post id for the page
520
-     * @param  string $new_title What the title is
521
-     * @param  string $new_slug  what the slug is
522
-     * @return string            The new html string for the permalink area
523
-     */
524
-    public function preview_button_html($return, $id, $new_title, $new_slug)
525
-    {
526
-        $post = get_post($id);
527
-        if ('publish' !== get_post_status($post)) {
528
-            //include shims for the `get_preview_post_link` function
529
-            require_once( EE_CORE . 'wordpress-shims.php' );
530
-            $return .= '<span_id="view-post-btn"><a target="_blank" href="'
531
-                       . get_preview_post_link($id)
532
-                       . '" class="button button-small">'
533
-                       . __('Preview', 'event_espresso')
534
-                       . '</a></span>'
535
-                       . "\n";
536
-        }
537
-        return $return;
538
-    }
539
-
540
-
541
-
542
-    /**
543
-     * add our custom post stati dropdown on the wp post page for this cpt
544
-     *
545
-     * @return void
546
-     */
547
-    public function custom_post_stati_dropdown()
548
-    {
549
-
550
-        $statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
551
-        $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
552
-            ? $statuses[$this->_cpt_model_obj->status()]
553
-            : '';
554
-        $template_args    = array(
555
-            'cur_status'            => $this->_cpt_model_obj->status(),
556
-            'statuses'              => $statuses,
557
-            'cur_status_label'      => $cur_status_label,
558
-            'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
559
-        );
560
-        //we'll add a trash post status (WP doesn't add one for some reason)
561
-        if ($this->_cpt_model_obj->status() === 'trash') {
562
-            $template_args['cur_status_label'] = __('Trashed', 'event_espresso');
563
-            $statuses['trash']                 = __('Trashed', 'event_espresso');
564
-            $template_args['statuses']         = $statuses;
565
-        }
566
-
567
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
568
-        EEH_Template::display_template($template, $template_args);
569
-    }
570
-
571
-
572
-
573
-    public function setup_autosave_hooks()
574
-    {
575
-        $this->_set_autosave_containers();
576
-        $this->_load_autosave_scripts_styles();
577
-    }
578
-
579
-
580
-
581
-    /**
582
-     * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
583
-     * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
584
-     * for the nonce in here, but then this method looks for two things:
585
-     * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
586
-     * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
587
-     * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
588
-     * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
589
-     * template args.
590
-     *    1. $template_args['error'] = IF there is an error you can add the message in here.
591
-     *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
592
-     *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
593
-     *    $this->_template_args['data']['items'] = array(
594
-     *        'event-datetime-ids' => '1,2,3';
595
-     *    );
596
-     *    Keep in mind the following things:
597
-     *    - "where" index is for the input with the id as that string.
598
-     *    - "what" index is what will be used for the value of that input.
599
-     *
600
-     * @return void
601
-     */
602
-    public function do_extra_autosave_stuff()
603
-    {
604
-        //next let's check for the autosave nonce (we'll use _verify_nonce )
605
-        $nonce = isset($this->_req_data['autosavenonce'])
606
-                ? $this->_req_data['autosavenonce']
607
-                : null;
608
-        $this->_verify_nonce($nonce, 'autosave');
609
-        //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
610
-        if ( ! defined('DOING_AUTOSAVE')) {
611
-            define('DOING_AUTOSAVE', true);
612
-        }
613
-        //if we made it here then the nonce checked out.  Let's run our methods and actions
614
-        $autosave = "_ee_autosave_{$this->_current_view}";
615
-        if (method_exists($this, $autosave)) {
616
-            $this->$autosave();
617
-        } else {
618
-            $this->_template_args['success'] = true;
619
-        }
620
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
621
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
622
-        //now let's return json
623
-        $this->_return_json();
624
-    }
625
-
626
-
627
-
628
-    /**
629
-     * This takes care of setting up default routes and pages that utilize the core WP admin pages.
630
-     * Child classes can override the defaults (in cases for adding metaboxes etc.)
631
-     * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
632
-     *
633
-     * @access protected
634
-     * @throws EE_Error
635
-     * @return void
636
-     */
637
-    protected function _extend_page_config_for_cpt()
638
-    {
639
-        //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
640
-        if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) {
641
-            return;
642
-        }
643
-        //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
644
-        if ( ! empty($this->_cpt_object)) {
645
-            $this->_page_routes = array_merge(array(
646
-                'create_new' => '_create_new_cpt_item',
647
-                'edit'       => '_edit_cpt_item',
648
-            ), $this->_page_routes);
649
-            $this->_page_config = array_merge(array(
650
-                'create_new' => array(
651
-                    'nav'           => array(
652
-                        'label' => $this->_cpt_object->labels->add_new_item,
653
-                        'order' => 5,
654
-                    ),
655
-                    'require_nonce' => false,
656
-                ),
657
-                'edit'       => array(
658
-                    'nav'           => array(
659
-                        'label'      => $this->_cpt_object->labels->edit_item,
660
-                        'order'      => 5,
661
-                        'persistent' => false,
662
-                        'url'        => '',
663
-                    ),
664
-                    'require_nonce' => false,
665
-                ),
666
-            ),
667
-                $this->_page_config
668
-            );
669
-        }
670
-        //load the next section only if this is a matching cpt route as set in the cpt routes array.
671
-        if ( ! isset($this->_cpt_routes[$this->_req_action])) {
672
-            return;
673
-        }
674
-        $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
675
-        //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
676
-        if (empty($this->_cpt_object)) {
677
-            $msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'),
678
-                $this->page_slug, $this->_req_action, get_class($this));
679
-            throw new EE_Error($msg);
680
-        }
681
-        if ($this->_cpt_route) {
682
-            $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
683
-            $this->_set_model_object($id);
684
-        }
685
-    }
686
-
687
-
688
-    /**
689
-     * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
690
-     *
691
-     * @access protected
692
-     * @param int    $id       The id to retrieve the model object for. If empty we set a default object.
693
-     * @param bool   $ignore_route_check
694
-     * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
695
-     * @throws EE_Error
696
-     * @throws InvalidArgumentException
697
-     * @throws InvalidDataTypeException
698
-     * @throws InvalidInterfaceException
699
-     * @throws ReflectionException
700
-     */
701
-    protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
702
-    {
703
-        $model = null;
704
-        if (
705
-            empty($this->_cpt_model_names)
706
-            || (
707
-                ! $ignore_route_check
708
-                && ! isset($this->_cpt_routes[$this->_req_action])
709
-            ) || (
710
-                $this->_cpt_model_obj instanceof EE_CPT_Base
711
-                && $this->_cpt_model_obj->ID() === $id
712
-            )
713
-        ) {
714
-            //get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
715
-            return;
716
-        }
717
-        // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions
718
-        if ($ignore_route_check) {
719
-            $post_type   = get_post_type($id);
720
-            /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
721
-            $custom_post_types = LoaderFactory::getLoader()->getShared(
722
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
723
-            );
724
-            $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type);
725
-            if (isset($model_names[$post_type])) {
726
-                $model = EE_Registry::instance()->load_model($model_names[$post_type]);
727
-            }
728
-        } else {
729
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
730
-        }
731
-        if ($model instanceof EEM_Base) {
732
-            $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
733
-        }
734
-        do_action(
735
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
736
-            $this->_cpt_model_obj,
737
-            $req_type
738
-        );
739
-    }
740
-
741
-
742
-
743
-    /**
744
-     * admin_init_global
745
-     * This runs all the code that we want executed within the WP admin_init hook.
746
-     * This method executes for ALL EE Admin pages.
747
-     *
748
-     * @access public
749
-     * @return void
750
-     */
751
-    public function admin_init_global()
752
-    {
753
-        $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
754
-        //its possible this is a new save so let's catch that instead
755
-        $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
756
-        $post_type = $post ? $post->post_type : false;
757
-        $current_route = isset($this->_req_data['current_route'])
758
-            ? $this->_req_data['current_route']
759
-            : 'shouldneverwork';
760
-        $route_to_check = $post_type && isset($this->_cpt_routes[$current_route])
761
-            ? $this->_cpt_routes[$current_route]
762
-            : '';
763
-        add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
764
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
765
-        if ($post_type === $route_to_check) {
766
-            add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
767
-        }
768
-        //now let's filter redirect if we're on a revision page and the revision is for an event CPT.
769
-        $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
770
-        if ( ! empty($revision)) {
771
-            $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
772
-            //doing a restore?
773
-            if ( ! empty($action) && $action === 'restore') {
774
-                //get post for revision
775
-                $rev_post = get_post($revision);
776
-                $rev_parent = get_post($rev_post->post_parent);
777
-                //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
778
-                if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
779
-                    add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
780
-                    //restores of revisions
781
-                    add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
782
-                }
783
-            }
784
-        }
785
-        //NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
786
-        if ($post_type && $post_type === $route_to_check) {
787
-            //$post_id, $post
788
-            add_action('save_post', array($this, 'insert_update'), 10, 3);
789
-            //$post_id
790
-            add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
791
-            add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
792
-            add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
793
-            add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
794
-        }
795
-    }
796
-
797
-
798
-
799
-    /**
800
-     * Callback for the WordPress trashed_post hook.
801
-     * Execute some basic checks before calling the trash_cpt_item declared in the child class.
802
-     *
803
-     * @param int $post_id
804
-     * @throws \EE_Error
805
-     */
806
-    public function before_trash_cpt_item($post_id)
807
-    {
808
-        $this->_set_model_object($post_id, true, 'trash');
809
-        //if our cpt object isn't existent then get out immediately.
810
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
811
-            return;
812
-        }
813
-        $this->trash_cpt_item($post_id);
814
-    }
815
-
816
-
817
-
818
-    /**
819
-     * Callback for the WordPress untrashed_post hook.
820
-     * Execute some basic checks before calling the restore_cpt_method in the child class.
821
-     *
822
-     * @param $post_id
823
-     * @throws \EE_Error
824
-     */
825
-    public function before_restore_cpt_item($post_id)
826
-    {
827
-        $this->_set_model_object($post_id, true, 'restore');
828
-        //if our cpt object isn't existent then get out immediately.
829
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
830
-            return;
831
-        }
832
-        $this->restore_cpt_item($post_id);
833
-    }
834
-
835
-
836
-
837
-    /**
838
-     * Callback for the WordPress after_delete_post hook.
839
-     * Execute some basic checks before calling the delete_cpt_item method in the child class.
840
-     *
841
-     * @param $post_id
842
-     * @throws \EE_Error
843
-     */
844
-    public function before_delete_cpt_item($post_id)
845
-    {
846
-        $this->_set_model_object($post_id, true, 'delete');
847
-        //if our cpt object isn't existent then get out immediately.
848
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
849
-            return;
850
-        }
851
-        $this->delete_cpt_item($post_id);
852
-    }
853
-
854
-
855
-
856
-    /**
857
-     * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
858
-     * accordingly.
859
-     *
860
-     * @access public
861
-     * @throws EE_Error
862
-     * @return void
863
-     */
864
-    public function verify_cpt_object()
865
-    {
866
-        $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
867
-        // verify event object
868
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
869
-            throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
870
-                    'event_espresso'), $label));
871
-        }
872
-        //if auto-draft then throw an error
873
-        if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
874
-            EE_Error::overwrite_errors();
875
-            EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'),
876
-                    $label), __FILE__, __FUNCTION__, __LINE__);
877
-        }
878
-    }
879
-
880
-
881
-
882
-    /**
883
-     * admin_footer_scripts_global
884
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
885
-     * will apply on ALL EE_Admin pages.
886
-     *
887
-     * @access public
888
-     * @return void
889
-     */
890
-    public function admin_footer_scripts_global()
891
-    {
892
-        $this->_add_admin_page_ajax_loading_img();
893
-        $this->_add_admin_page_overlay();
894
-    }
895
-
896
-
897
-
898
-    /**
899
-     * add in any global scripts for cpt routes
900
-     *
901
-     * @return void
902
-     */
903
-    public function load_global_scripts_styles()
904
-    {
905
-        parent::load_global_scripts_styles();
906
-        if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
907
-            //setup custom post status object for localize script but only if we've got a cpt object
908
-            $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
909
-            if ( ! empty($statuses)) {
910
-                //get ALL statuses!
911
-                $statuses = $this->_cpt_model_obj->get_all_post_statuses();
912
-                //setup object
913
-                $ee_cpt_statuses = array();
914
-                foreach ($statuses as $status => $label) {
915
-                    $ee_cpt_statuses[$status] = array(
916
-                        'label'      => $label,
917
-                        'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
918
-                    );
919
-                }
920
-                wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
921
-            }
922
-        }
923
-    }
924
-
925
-
926
-
927
-    /**
928
-     * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
929
-     * insert/updates
930
-     *
931
-     * @param  int     $post_id ID of post being updated
932
-     * @param  WP_Post $post    Post object from WP
933
-     * @param  bool    $update  Whether this is an update or a new save.
934
-     * @return void
935
-     * @throws \EE_Error
936
-     */
937
-    public function insert_update($post_id, $post, $update)
938
-    {
939
-        //make sure that if this is a revision OR trash action that we don't do any updates!
940
-        if (
941
-            isset($this->_req_data['action'])
942
-            && (
943
-                $this->_req_data['action'] === 'restore'
944
-                || $this->_req_data['action'] === 'trash'
945
-            )
946
-        ) {
947
-            return;
948
-        }
949
-        $this->_set_model_object($post_id, true, 'insert_update');
950
-        //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
951
-        if ($update
952
-            && (
953
-                ! $this->_cpt_model_obj instanceof EE_CPT_Base
954
-                || $this->_cpt_model_obj->ID() !== $post_id
955
-            )
956
-        ) {
957
-            return;
958
-        }
959
-        //check for autosave and update our req_data property accordingly.
960
-        /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
510
+	}
511
+
512
+
513
+
514
+	/**
515
+	 * if this post is a draft or scheduled post then we provide a preview button for user to click
516
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
517
+	 *
518
+	 * @param  string $return    the current html
519
+	 * @param  int    $id        the post id for the page
520
+	 * @param  string $new_title What the title is
521
+	 * @param  string $new_slug  what the slug is
522
+	 * @return string            The new html string for the permalink area
523
+	 */
524
+	public function preview_button_html($return, $id, $new_title, $new_slug)
525
+	{
526
+		$post = get_post($id);
527
+		if ('publish' !== get_post_status($post)) {
528
+			//include shims for the `get_preview_post_link` function
529
+			require_once( EE_CORE . 'wordpress-shims.php' );
530
+			$return .= '<span_id="view-post-btn"><a target="_blank" href="'
531
+					   . get_preview_post_link($id)
532
+					   . '" class="button button-small">'
533
+					   . __('Preview', 'event_espresso')
534
+					   . '</a></span>'
535
+					   . "\n";
536
+		}
537
+		return $return;
538
+	}
539
+
540
+
541
+
542
+	/**
543
+	 * add our custom post stati dropdown on the wp post page for this cpt
544
+	 *
545
+	 * @return void
546
+	 */
547
+	public function custom_post_stati_dropdown()
548
+	{
549
+
550
+		$statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
551
+		$cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
552
+			? $statuses[$this->_cpt_model_obj->status()]
553
+			: '';
554
+		$template_args    = array(
555
+			'cur_status'            => $this->_cpt_model_obj->status(),
556
+			'statuses'              => $statuses,
557
+			'cur_status_label'      => $cur_status_label,
558
+			'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
559
+		);
560
+		//we'll add a trash post status (WP doesn't add one for some reason)
561
+		if ($this->_cpt_model_obj->status() === 'trash') {
562
+			$template_args['cur_status_label'] = __('Trashed', 'event_espresso');
563
+			$statuses['trash']                 = __('Trashed', 'event_espresso');
564
+			$template_args['statuses']         = $statuses;
565
+		}
566
+
567
+		$template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
568
+		EEH_Template::display_template($template, $template_args);
569
+	}
570
+
571
+
572
+
573
+	public function setup_autosave_hooks()
574
+	{
575
+		$this->_set_autosave_containers();
576
+		$this->_load_autosave_scripts_styles();
577
+	}
578
+
579
+
580
+
581
+	/**
582
+	 * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
583
+	 * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
584
+	 * for the nonce in here, but then this method looks for two things:
585
+	 * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
586
+	 * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
587
+	 * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
588
+	 * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
589
+	 * template args.
590
+	 *    1. $template_args['error'] = IF there is an error you can add the message in here.
591
+	 *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
592
+	 *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
593
+	 *    $this->_template_args['data']['items'] = array(
594
+	 *        'event-datetime-ids' => '1,2,3';
595
+	 *    );
596
+	 *    Keep in mind the following things:
597
+	 *    - "where" index is for the input with the id as that string.
598
+	 *    - "what" index is what will be used for the value of that input.
599
+	 *
600
+	 * @return void
601
+	 */
602
+	public function do_extra_autosave_stuff()
603
+	{
604
+		//next let's check for the autosave nonce (we'll use _verify_nonce )
605
+		$nonce = isset($this->_req_data['autosavenonce'])
606
+				? $this->_req_data['autosavenonce']
607
+				: null;
608
+		$this->_verify_nonce($nonce, 'autosave');
609
+		//make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
610
+		if ( ! defined('DOING_AUTOSAVE')) {
611
+			define('DOING_AUTOSAVE', true);
612
+		}
613
+		//if we made it here then the nonce checked out.  Let's run our methods and actions
614
+		$autosave = "_ee_autosave_{$this->_current_view}";
615
+		if (method_exists($this, $autosave)) {
616
+			$this->$autosave();
617
+		} else {
618
+			$this->_template_args['success'] = true;
619
+		}
620
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
621
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
622
+		//now let's return json
623
+		$this->_return_json();
624
+	}
625
+
626
+
627
+
628
+	/**
629
+	 * This takes care of setting up default routes and pages that utilize the core WP admin pages.
630
+	 * Child classes can override the defaults (in cases for adding metaboxes etc.)
631
+	 * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
632
+	 *
633
+	 * @access protected
634
+	 * @throws EE_Error
635
+	 * @return void
636
+	 */
637
+	protected function _extend_page_config_for_cpt()
638
+	{
639
+		//before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
640
+		if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) {
641
+			return;
642
+		}
643
+		//set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
644
+		if ( ! empty($this->_cpt_object)) {
645
+			$this->_page_routes = array_merge(array(
646
+				'create_new' => '_create_new_cpt_item',
647
+				'edit'       => '_edit_cpt_item',
648
+			), $this->_page_routes);
649
+			$this->_page_config = array_merge(array(
650
+				'create_new' => array(
651
+					'nav'           => array(
652
+						'label' => $this->_cpt_object->labels->add_new_item,
653
+						'order' => 5,
654
+					),
655
+					'require_nonce' => false,
656
+				),
657
+				'edit'       => array(
658
+					'nav'           => array(
659
+						'label'      => $this->_cpt_object->labels->edit_item,
660
+						'order'      => 5,
661
+						'persistent' => false,
662
+						'url'        => '',
663
+					),
664
+					'require_nonce' => false,
665
+				),
666
+			),
667
+				$this->_page_config
668
+			);
669
+		}
670
+		//load the next section only if this is a matching cpt route as set in the cpt routes array.
671
+		if ( ! isset($this->_cpt_routes[$this->_req_action])) {
672
+			return;
673
+		}
674
+		$this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
675
+		//add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
676
+		if (empty($this->_cpt_object)) {
677
+			$msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'),
678
+				$this->page_slug, $this->_req_action, get_class($this));
679
+			throw new EE_Error($msg);
680
+		}
681
+		if ($this->_cpt_route) {
682
+			$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
683
+			$this->_set_model_object($id);
684
+		}
685
+	}
686
+
687
+
688
+	/**
689
+	 * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
690
+	 *
691
+	 * @access protected
692
+	 * @param int    $id       The id to retrieve the model object for. If empty we set a default object.
693
+	 * @param bool   $ignore_route_check
694
+	 * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT
695
+	 * @throws EE_Error
696
+	 * @throws InvalidArgumentException
697
+	 * @throws InvalidDataTypeException
698
+	 * @throws InvalidInterfaceException
699
+	 * @throws ReflectionException
700
+	 */
701
+	protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '')
702
+	{
703
+		$model = null;
704
+		if (
705
+			empty($this->_cpt_model_names)
706
+			|| (
707
+				! $ignore_route_check
708
+				&& ! isset($this->_cpt_routes[$this->_req_action])
709
+			) || (
710
+				$this->_cpt_model_obj instanceof EE_CPT_Base
711
+				&& $this->_cpt_model_obj->ID() === $id
712
+			)
713
+		) {
714
+			//get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
715
+			return;
716
+		}
717
+		// if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions
718
+		if ($ignore_route_check) {
719
+			$post_type   = get_post_type($id);
720
+			/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
721
+			$custom_post_types = LoaderFactory::getLoader()->getShared(
722
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
723
+			);
724
+			$model_names = $custom_post_types->getCustomPostTypeModelNames($post_type);
725
+			if (isset($model_names[$post_type])) {
726
+				$model = EE_Registry::instance()->load_model($model_names[$post_type]);
727
+			}
728
+		} else {
729
+			$model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
730
+		}
731
+		if ($model instanceof EEM_Base) {
732
+			$this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
733
+		}
734
+		do_action(
735
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
736
+			$this->_cpt_model_obj,
737
+			$req_type
738
+		);
739
+	}
740
+
741
+
742
+
743
+	/**
744
+	 * admin_init_global
745
+	 * This runs all the code that we want executed within the WP admin_init hook.
746
+	 * This method executes for ALL EE Admin pages.
747
+	 *
748
+	 * @access public
749
+	 * @return void
750
+	 */
751
+	public function admin_init_global()
752
+	{
753
+		$post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
754
+		//its possible this is a new save so let's catch that instead
755
+		$post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
756
+		$post_type = $post ? $post->post_type : false;
757
+		$current_route = isset($this->_req_data['current_route'])
758
+			? $this->_req_data['current_route']
759
+			: 'shouldneverwork';
760
+		$route_to_check = $post_type && isset($this->_cpt_routes[$current_route])
761
+			? $this->_cpt_routes[$current_route]
762
+			: '';
763
+		add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
764
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
765
+		if ($post_type === $route_to_check) {
766
+			add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
767
+		}
768
+		//now let's filter redirect if we're on a revision page and the revision is for an event CPT.
769
+		$revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
770
+		if ( ! empty($revision)) {
771
+			$action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
772
+			//doing a restore?
773
+			if ( ! empty($action) && $action === 'restore') {
774
+				//get post for revision
775
+				$rev_post = get_post($revision);
776
+				$rev_parent = get_post($rev_post->post_parent);
777
+				//only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
778
+				if ($rev_parent && $rev_parent->post_type === $this->page_slug) {
779
+					add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
780
+					//restores of revisions
781
+					add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
782
+				}
783
+			}
784
+		}
785
+		//NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
786
+		if ($post_type && $post_type === $route_to_check) {
787
+			//$post_id, $post
788
+			add_action('save_post', array($this, 'insert_update'), 10, 3);
789
+			//$post_id
790
+			add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
791
+			add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
792
+			add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
793
+			add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
794
+		}
795
+	}
796
+
797
+
798
+
799
+	/**
800
+	 * Callback for the WordPress trashed_post hook.
801
+	 * Execute some basic checks before calling the trash_cpt_item declared in the child class.
802
+	 *
803
+	 * @param int $post_id
804
+	 * @throws \EE_Error
805
+	 */
806
+	public function before_trash_cpt_item($post_id)
807
+	{
808
+		$this->_set_model_object($post_id, true, 'trash');
809
+		//if our cpt object isn't existent then get out immediately.
810
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
811
+			return;
812
+		}
813
+		$this->trash_cpt_item($post_id);
814
+	}
815
+
816
+
817
+
818
+	/**
819
+	 * Callback for the WordPress untrashed_post hook.
820
+	 * Execute some basic checks before calling the restore_cpt_method in the child class.
821
+	 *
822
+	 * @param $post_id
823
+	 * @throws \EE_Error
824
+	 */
825
+	public function before_restore_cpt_item($post_id)
826
+	{
827
+		$this->_set_model_object($post_id, true, 'restore');
828
+		//if our cpt object isn't existent then get out immediately.
829
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
830
+			return;
831
+		}
832
+		$this->restore_cpt_item($post_id);
833
+	}
834
+
835
+
836
+
837
+	/**
838
+	 * Callback for the WordPress after_delete_post hook.
839
+	 * Execute some basic checks before calling the delete_cpt_item method in the child class.
840
+	 *
841
+	 * @param $post_id
842
+	 * @throws \EE_Error
843
+	 */
844
+	public function before_delete_cpt_item($post_id)
845
+	{
846
+		$this->_set_model_object($post_id, true, 'delete');
847
+		//if our cpt object isn't existent then get out immediately.
848
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
849
+			return;
850
+		}
851
+		$this->delete_cpt_item($post_id);
852
+	}
853
+
854
+
855
+
856
+	/**
857
+	 * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
858
+	 * accordingly.
859
+	 *
860
+	 * @access public
861
+	 * @throws EE_Error
862
+	 * @return void
863
+	 */
864
+	public function verify_cpt_object()
865
+	{
866
+		$label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
867
+		// verify event object
868
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
869
+			throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
870
+					'event_espresso'), $label));
871
+		}
872
+		//if auto-draft then throw an error
873
+		if ($this->_cpt_model_obj->get('status') === 'auto-draft') {
874
+			EE_Error::overwrite_errors();
875
+			EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'),
876
+					$label), __FILE__, __FUNCTION__, __LINE__);
877
+		}
878
+	}
879
+
880
+
881
+
882
+	/**
883
+	 * admin_footer_scripts_global
884
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
885
+	 * will apply on ALL EE_Admin pages.
886
+	 *
887
+	 * @access public
888
+	 * @return void
889
+	 */
890
+	public function admin_footer_scripts_global()
891
+	{
892
+		$this->_add_admin_page_ajax_loading_img();
893
+		$this->_add_admin_page_overlay();
894
+	}
895
+
896
+
897
+
898
+	/**
899
+	 * add in any global scripts for cpt routes
900
+	 *
901
+	 * @return void
902
+	 */
903
+	public function load_global_scripts_styles()
904
+	{
905
+		parent::load_global_scripts_styles();
906
+		if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
907
+			//setup custom post status object for localize script but only if we've got a cpt object
908
+			$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
909
+			if ( ! empty($statuses)) {
910
+				//get ALL statuses!
911
+				$statuses = $this->_cpt_model_obj->get_all_post_statuses();
912
+				//setup object
913
+				$ee_cpt_statuses = array();
914
+				foreach ($statuses as $status => $label) {
915
+					$ee_cpt_statuses[$status] = array(
916
+						'label'      => $label,
917
+						'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
918
+					);
919
+				}
920
+				wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
921
+			}
922
+		}
923
+	}
924
+
925
+
926
+
927
+	/**
928
+	 * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
929
+	 * insert/updates
930
+	 *
931
+	 * @param  int     $post_id ID of post being updated
932
+	 * @param  WP_Post $post    Post object from WP
933
+	 * @param  bool    $update  Whether this is an update or a new save.
934
+	 * @return void
935
+	 * @throws \EE_Error
936
+	 */
937
+	public function insert_update($post_id, $post, $update)
938
+	{
939
+		//make sure that if this is a revision OR trash action that we don't do any updates!
940
+		if (
941
+			isset($this->_req_data['action'])
942
+			&& (
943
+				$this->_req_data['action'] === 'restore'
944
+				|| $this->_req_data['action'] === 'trash'
945
+			)
946
+		) {
947
+			return;
948
+		}
949
+		$this->_set_model_object($post_id, true, 'insert_update');
950
+		//if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
951
+		if ($update
952
+			&& (
953
+				! $this->_cpt_model_obj instanceof EE_CPT_Base
954
+				|| $this->_cpt_model_obj->ID() !== $post_id
955
+			)
956
+		) {
957
+			return;
958
+		}
959
+		//check for autosave and update our req_data property accordingly.
960
+		/*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
961 961
             foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) {
962 962
 
963 963
                 foreach ( (array) $values as $key => $value ) {
@@ -967,542 +967,542 @@  discard block
 block discarded – undo
967 967
 
968 968
         }/**/ //TODO reactivate after autosave is implemented in 4.2
969 969
 
970
-        //take care of updating any selected page_template IF this cpt supports it.
971
-        if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
972
-            //wp version aware.
973
-            if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
974
-                $page_templates = wp_get_theme()->get_page_templates();
975
-            } else {
976
-                $post->page_template = $this->_req_data['page_template'];
977
-                $page_templates      = wp_get_theme()->get_page_templates($post);
978
-            }
979
-            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
980
-                EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
981
-            } else {
982
-                update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
983
-            }
984
-        }
985
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
986
-            return;
987
-        } //TODO we'll remove this after reimplementing autosave in 4.2
988
-        $this->_insert_update_cpt_item($post_id, $post);
989
-    }
990
-
991
-
992
-
993
-    /**
994
-     * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
995
-     * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
996
-     * so we don't have to check for our CPT.
997
-     *
998
-     * @param  int $post_id ID of the post
999
-     * @return void
1000
-     */
1001
-    public function dont_permanently_delete_ee_cpts($post_id)
1002
-    {
1003
-        //only do this if we're actually processing one of our CPTs
1004
-        //if our cpt object isn't existent then get out immediately.
1005
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1006
-            return;
1007
-        }
1008
-        delete_post_meta($post_id, '_wp_trash_meta_status');
1009
-        delete_post_meta($post_id, '_wp_trash_meta_time');
1010
-        //our cpts may have comments so let's take care of that too
1011
-        delete_post_meta($post_id, '_wp_trash_meta_comments_status');
1012
-    }
1013
-
1014
-
1015
-
1016
-    /**
1017
-     * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1018
-     * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1019
-     * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1020
-     *
1021
-     * @param  int $post_id     ID of cpt item
1022
-     * @param  int $revision_id ID of revision being restored
1023
-     * @return void
1024
-     */
1025
-    public function restore_revision($post_id, $revision_id)
1026
-    {
1027
-        $this->_restore_cpt_item($post_id, $revision_id);
1028
-        //global action
1029
-        do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1030
-        //class specific action so you can limit hooking into a specific page.
1031
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1032
-    }
1033
-
1034
-
1035
-
1036
-    /**
1037
-     * @see restore_revision() for details
1038
-     * @param  int $post_id     ID of cpt item
1039
-     * @param  int $revision_id ID of revision for item
1040
-     * @return void
1041
-     */
1042
-    abstract protected function _restore_cpt_item($post_id, $revision_id);
1043
-
1044
-
1045
-
1046
-    /**
1047
-     * Execution of this method is added to the end of the load_page_dependencies method in the parent
1048
-     * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1049
-     * To fix we have to reset the current_screen using the page_slug
1050
-     * (which is identical - or should be - to our registered_post_type id.)
1051
-     * Also, since the core WP file loads the admin_header.php for WP
1052
-     * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1053
-     * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1054
-     *
1055
-     * @return void
1056
-     */
1057
-    public function modify_current_screen()
1058
-    {
1059
-        //ONLY do this if the current page_route IS a cpt route
1060
-        if ( ! $this->_cpt_route) {
1061
-            return;
1062
-        }
1063
-        //routing things REALLY early b/c this is a cpt admin page
1064
-        set_current_screen($this->_cpt_routes[$this->_req_action]);
1065
-        $this->_current_screen       = get_current_screen();
1066
-        $this->_current_screen->base = 'event-espresso';
1067
-        $this->_add_help_tabs(); //we make sure we add any help tabs back in!
1068
-        /*try {
970
+		//take care of updating any selected page_template IF this cpt supports it.
971
+		if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
972
+			//wp version aware.
973
+			if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
974
+				$page_templates = wp_get_theme()->get_page_templates();
975
+			} else {
976
+				$post->page_template = $this->_req_data['page_template'];
977
+				$page_templates      = wp_get_theme()->get_page_templates($post);
978
+			}
979
+			if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
980
+				EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
981
+			} else {
982
+				update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
983
+			}
984
+		}
985
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
986
+			return;
987
+		} //TODO we'll remove this after reimplementing autosave in 4.2
988
+		$this->_insert_update_cpt_item($post_id, $post);
989
+	}
990
+
991
+
992
+
993
+	/**
994
+	 * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
995
+	 * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
996
+	 * so we don't have to check for our CPT.
997
+	 *
998
+	 * @param  int $post_id ID of the post
999
+	 * @return void
1000
+	 */
1001
+	public function dont_permanently_delete_ee_cpts($post_id)
1002
+	{
1003
+		//only do this if we're actually processing one of our CPTs
1004
+		//if our cpt object isn't existent then get out immediately.
1005
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
1006
+			return;
1007
+		}
1008
+		delete_post_meta($post_id, '_wp_trash_meta_status');
1009
+		delete_post_meta($post_id, '_wp_trash_meta_time');
1010
+		//our cpts may have comments so let's take care of that too
1011
+		delete_post_meta($post_id, '_wp_trash_meta_comments_status');
1012
+	}
1013
+
1014
+
1015
+
1016
+	/**
1017
+	 * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
1018
+	 * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
1019
+	 * in them. We also have our OWN action in here so addons can hook into the restore process easily.
1020
+	 *
1021
+	 * @param  int $post_id     ID of cpt item
1022
+	 * @param  int $revision_id ID of revision being restored
1023
+	 * @return void
1024
+	 */
1025
+	public function restore_revision($post_id, $revision_id)
1026
+	{
1027
+		$this->_restore_cpt_item($post_id, $revision_id);
1028
+		//global action
1029
+		do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1030
+		//class specific action so you can limit hooking into a specific page.
1031
+		do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1032
+	}
1033
+
1034
+
1035
+
1036
+	/**
1037
+	 * @see restore_revision() for details
1038
+	 * @param  int $post_id     ID of cpt item
1039
+	 * @param  int $revision_id ID of revision for item
1040
+	 * @return void
1041
+	 */
1042
+	abstract protected function _restore_cpt_item($post_id, $revision_id);
1043
+
1044
+
1045
+
1046
+	/**
1047
+	 * Execution of this method is added to the end of the load_page_dependencies method in the parent
1048
+	 * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
1049
+	 * To fix we have to reset the current_screen using the page_slug
1050
+	 * (which is identical - or should be - to our registered_post_type id.)
1051
+	 * Also, since the core WP file loads the admin_header.php for WP
1052
+	 * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
1053
+	 * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
1054
+	 *
1055
+	 * @return void
1056
+	 */
1057
+	public function modify_current_screen()
1058
+	{
1059
+		//ONLY do this if the current page_route IS a cpt route
1060
+		if ( ! $this->_cpt_route) {
1061
+			return;
1062
+		}
1063
+		//routing things REALLY early b/c this is a cpt admin page
1064
+		set_current_screen($this->_cpt_routes[$this->_req_action]);
1065
+		$this->_current_screen       = get_current_screen();
1066
+		$this->_current_screen->base = 'event-espresso';
1067
+		$this->_add_help_tabs(); //we make sure we add any help tabs back in!
1068
+		/*try {
1069 1069
             $this->_route_admin_request();
1070 1070
         } catch ( EE_Error $e ) {
1071 1071
             $e->get_error();
1072 1072
         }/**/
1073
-    }
1074
-
1075
-
1076
-
1077
-    /**
1078
-     * This allows child classes to modify the default editor title that appears when people add a new or edit an
1079
-     * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1080
-     * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1081
-     * default to be.
1082
-     *
1083
-     * @param string $title The new title (or existing if there is no editor_title defined)
1084
-     * @return string
1085
-     */
1086
-    public function add_custom_editor_default_title($title)
1087
-    {
1088
-        return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1089
-            ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1090
-            : $title;
1091
-    }
1092
-
1093
-
1094
-
1095
-    /**
1096
-     * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1097
-     *
1098
-     * @param string $shortlink   The already generated shortlink
1099
-     * @param int    $id          Post ID for this item
1100
-     * @param string $context     The context for the link
1101
-     * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1102
-     * @return string
1103
-     */
1104
-    public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1105
-    {
1106
-        if ( ! empty($id) && get_option('permalink_structure') !== '') {
1107
-            $post = get_post($id);
1108
-            if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1109
-                $shortlink = home_url('?p=' . $post->ID);
1110
-            }
1111
-        }
1112
-        return $shortlink;
1113
-    }
1114
-
1115
-
1116
-
1117
-    /**
1118
-     * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1119
-     * already run in modify_current_screen())
1120
-     *
1121
-     * @return void
1122
-     */
1123
-    public function route_admin_request()
1124
-    {
1125
-        if ($this->_cpt_route) {
1126
-            return;
1127
-        }
1128
-        try {
1129
-            $this->_route_admin_request();
1130
-        } catch (EE_Error $e) {
1131
-            $e->get_error();
1132
-        }
1133
-    }
1134
-
1135
-
1136
-
1137
-    /**
1138
-     * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1139
-     *
1140
-     * @return void
1141
-     */
1142
-    public function cpt_post_form_hidden_input()
1143
-    {
1144
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1145
-        //we're also going to add the route value and the current page so we can direct autosave parsing correctly
1146
-        echo '<div id="ee-cpt-hidden-inputs">';
1147
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1148
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1149
-        echo '</div>';
1150
-    }
1151
-
1152
-
1153
-
1154
-    /**
1155
-     * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1156
-     *
1157
-     * @param  string $location Original location url
1158
-     * @param  int    $status   Status for http header
1159
-     * @return string           new (or original) url to redirect to.
1160
-     */
1161
-    public function revision_redirect($location, $status)
1162
-    {
1163
-        //get revision
1164
-        $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1165
-        //can't do anything without revision so let's get out if not present
1166
-        if (empty($rev_id)) {
1167
-            return $location;
1168
-        }
1169
-        //get rev_post_data
1170
-        $rev = get_post($rev_id);
1171
-        $admin_url = $this->_admin_base_url;
1172
-        $query_args = array(
1173
-            'action'   => 'edit',
1174
-            'post'     => $rev->post_parent,
1175
-            'revision' => $rev_id,
1176
-            'message'  => 5,
1177
-        );
1178
-        $this->_process_notices($query_args, true);
1179
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1180
-    }
1181
-
1182
-
1183
-
1184
-    /**
1185
-     * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1186
-     *
1187
-     * @param  string $link    the original generated link
1188
-     * @param  int    $id      post id
1189
-     * @param  string $context optional, defaults to display.  How to write the '&'
1190
-     * @return string          the link
1191
-     */
1192
-    public function modify_edit_post_link($link, $id, $context)
1193
-    {
1194
-        $post = get_post($id);
1195
-        if ( ! isset($this->_req_data['action'])
1196
-             || ! isset($this->_cpt_routes[$this->_req_data['action']])
1197
-             || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1198
-        ) {
1199
-            return $link;
1200
-        }
1201
-        $query_args = array(
1202
-            'action' => isset($this->_cpt_edit_routes[$post->post_type])
1203
-                ? $this->_cpt_edit_routes[$post->post_type]
1204
-                : 'edit',
1205
-            'post'   => $id,
1206
-        );
1207
-        return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1208
-    }
1209
-
1210
-
1211
-    /**
1212
-     * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1213
-     * our routes.
1214
-     *
1215
-     * @param  string $delete_link  original delete link
1216
-     * @param  int    $post_id      id of cpt object
1217
-     * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1218
-     * @return string new delete link
1219
-     * @throws EE_Error
1220
-     */
1221
-    public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1222
-    {
1223
-        $post = get_post($post_id);
1224
-
1225
-        if (empty($this->_req_data['action'])
1226
-            || ! isset($this->_cpt_routes[$this->_req_data['action']])
1227
-            || ! $post instanceof WP_Post
1228
-            || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1229
-        ) {
1230
-            return $delete_link;
1231
-        }
1232
-        $this->_set_model_object($post->ID, true);
1233
-
1234
-        //returns something like `trash_event` or `trash_attendee` or `trash_venue`
1235
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1236
-
1237
-        return EE_Admin_Page::add_query_args_and_nonce(
1238
-            array(
1239
-                'page' => $this->_req_data['page'],
1240
-                'action' => $action,
1241
-                $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1242
-                    => $post->ID
1243
-            ),
1244
-            admin_url()
1245
-        );
1246
-    }
1247
-
1248
-
1249
-
1250
-    /**
1251
-     * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1252
-     * so that we can hijack the default redirect locations for wp custom post types
1253
-     * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1254
-     *
1255
-     * @param  string $location This is the incoming currently set redirect location
1256
-     * @param  string $post_id  This is the 'ID' value of the wp_posts table
1257
-     * @return string           the new location to redirect to
1258
-     */
1259
-    public function cpt_post_location_redirect($location, $post_id)
1260
-    {
1261
-        //we DO have a match so let's setup the url
1262
-        //we have to get the post to determine our route
1263
-        $post       = get_post($post_id);
1264
-        $edit_route = $this->_cpt_edit_routes[$post->post_type];
1265
-        //shared query_args
1266
-        $query_args = array('action' => $edit_route, 'post' => $post_id);
1267
-        $admin_url  = $this->_admin_base_url;
1268
-        if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1269
-            $status = get_post_status($post_id);
1270
-            if (isset($this->_req_data['publish'])) {
1271
-                switch ($status) {
1272
-                    case 'pending':
1273
-                        $message = 8;
1274
-                        break;
1275
-                    case 'future':
1276
-                        $message = 9;
1277
-                        break;
1278
-                    default:
1279
-                        $message = 6;
1280
-                }
1281
-            } else {
1282
-                $message = 'draft' === $status ? 10 : 1;
1283
-            }
1284
-        } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1285
-            $message = 2;
1286
-            //			$append = '#postcustom';
1287
-        } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1288
-            $message = 3;
1289
-            //			$append = '#postcustom';
1290
-        } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1291
-            $message = 7;
1292
-        } else {
1293
-            $message = 4;
1294
-        }
1295
-        //change the message if the post type is not viewable on the frontend
1296
-        $this->_cpt_object = get_post_type_object($post->post_type);
1297
-        $message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1298
-        $query_args = array_merge(array('message' => $message), $query_args);
1299
-        $this->_process_notices($query_args, true);
1300
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1301
-    }
1302
-
1303
-
1304
-
1305
-    /**
1306
-     * This method is called to inject nav tabs on core WP cpt pages
1307
-     *
1308
-     * @access public
1309
-     * @return void
1310
-     */
1311
-    public function inject_nav_tabs()
1312
-    {
1313
-        //can we hijack and insert the nav_tabs?
1314
-        $nav_tabs = $this->_get_main_nav_tabs();
1315
-        //first close off existing form tag
1316
-        $html = '>';
1317
-        $html .= $nav_tabs;
1318
-        //now let's handle the remaining tag ( missing ">" is CORRECT )
1319
-        $html .= '<span></span';
1320
-        echo $html;
1321
-    }
1322
-
1323
-
1324
-
1325
-    /**
1326
-     * This just sets up the post update messages when an update form is loaded
1327
-     *
1328
-     * @access public
1329
-     * @param  array $messages the original messages array
1330
-     * @return array           the new messages array
1331
-     */
1332
-    public function post_update_messages($messages)
1333
-    {
1334
-        global $post;
1335
-        $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1336
-        $id = empty($id) && is_object($post) ? $post->ID : null;
1337
-        //		$post_type = $post ? $post->post_type : false;
1338
-        /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1073
+	}
1074
+
1075
+
1076
+
1077
+	/**
1078
+	 * This allows child classes to modify the default editor title that appears when people add a new or edit an
1079
+	 * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1080
+	 * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1081
+	 * default to be.
1082
+	 *
1083
+	 * @param string $title The new title (or existing if there is no editor_title defined)
1084
+	 * @return string
1085
+	 */
1086
+	public function add_custom_editor_default_title($title)
1087
+	{
1088
+		return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1089
+			? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1090
+			: $title;
1091
+	}
1092
+
1093
+
1094
+
1095
+	/**
1096
+	 * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1097
+	 *
1098
+	 * @param string $shortlink   The already generated shortlink
1099
+	 * @param int    $id          Post ID for this item
1100
+	 * @param string $context     The context for the link
1101
+	 * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1102
+	 * @return string
1103
+	 */
1104
+	public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1105
+	{
1106
+		if ( ! empty($id) && get_option('permalink_structure') !== '') {
1107
+			$post = get_post($id);
1108
+			if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1109
+				$shortlink = home_url('?p=' . $post->ID);
1110
+			}
1111
+		}
1112
+		return $shortlink;
1113
+	}
1114
+
1115
+
1116
+
1117
+	/**
1118
+	 * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1119
+	 * already run in modify_current_screen())
1120
+	 *
1121
+	 * @return void
1122
+	 */
1123
+	public function route_admin_request()
1124
+	{
1125
+		if ($this->_cpt_route) {
1126
+			return;
1127
+		}
1128
+		try {
1129
+			$this->_route_admin_request();
1130
+		} catch (EE_Error $e) {
1131
+			$e->get_error();
1132
+		}
1133
+	}
1134
+
1135
+
1136
+
1137
+	/**
1138
+	 * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1139
+	 *
1140
+	 * @return void
1141
+	 */
1142
+	public function cpt_post_form_hidden_input()
1143
+	{
1144
+		echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1145
+		//we're also going to add the route value and the current page so we can direct autosave parsing correctly
1146
+		echo '<div id="ee-cpt-hidden-inputs">';
1147
+		echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1148
+		echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1149
+		echo '</div>';
1150
+	}
1151
+
1152
+
1153
+
1154
+	/**
1155
+	 * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1156
+	 *
1157
+	 * @param  string $location Original location url
1158
+	 * @param  int    $status   Status for http header
1159
+	 * @return string           new (or original) url to redirect to.
1160
+	 */
1161
+	public function revision_redirect($location, $status)
1162
+	{
1163
+		//get revision
1164
+		$rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1165
+		//can't do anything without revision so let's get out if not present
1166
+		if (empty($rev_id)) {
1167
+			return $location;
1168
+		}
1169
+		//get rev_post_data
1170
+		$rev = get_post($rev_id);
1171
+		$admin_url = $this->_admin_base_url;
1172
+		$query_args = array(
1173
+			'action'   => 'edit',
1174
+			'post'     => $rev->post_parent,
1175
+			'revision' => $rev_id,
1176
+			'message'  => 5,
1177
+		);
1178
+		$this->_process_notices($query_args, true);
1179
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1180
+	}
1181
+
1182
+
1183
+
1184
+	/**
1185
+	 * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1186
+	 *
1187
+	 * @param  string $link    the original generated link
1188
+	 * @param  int    $id      post id
1189
+	 * @param  string $context optional, defaults to display.  How to write the '&'
1190
+	 * @return string          the link
1191
+	 */
1192
+	public function modify_edit_post_link($link, $id, $context)
1193
+	{
1194
+		$post = get_post($id);
1195
+		if ( ! isset($this->_req_data['action'])
1196
+			 || ! isset($this->_cpt_routes[$this->_req_data['action']])
1197
+			 || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1198
+		) {
1199
+			return $link;
1200
+		}
1201
+		$query_args = array(
1202
+			'action' => isset($this->_cpt_edit_routes[$post->post_type])
1203
+				? $this->_cpt_edit_routes[$post->post_type]
1204
+				: 'edit',
1205
+			'post'   => $id,
1206
+		);
1207
+		return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1208
+	}
1209
+
1210
+
1211
+	/**
1212
+	 * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1213
+	 * our routes.
1214
+	 *
1215
+	 * @param  string $delete_link  original delete link
1216
+	 * @param  int    $post_id      id of cpt object
1217
+	 * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1218
+	 * @return string new delete link
1219
+	 * @throws EE_Error
1220
+	 */
1221
+	public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1222
+	{
1223
+		$post = get_post($post_id);
1224
+
1225
+		if (empty($this->_req_data['action'])
1226
+			|| ! isset($this->_cpt_routes[$this->_req_data['action']])
1227
+			|| ! $post instanceof WP_Post
1228
+			|| $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1229
+		) {
1230
+			return $delete_link;
1231
+		}
1232
+		$this->_set_model_object($post->ID, true);
1233
+
1234
+		//returns something like `trash_event` or `trash_attendee` or `trash_venue`
1235
+		$action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1236
+
1237
+		return EE_Admin_Page::add_query_args_and_nonce(
1238
+			array(
1239
+				'page' => $this->_req_data['page'],
1240
+				'action' => $action,
1241
+				$this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1242
+					=> $post->ID
1243
+			),
1244
+			admin_url()
1245
+		);
1246
+	}
1247
+
1248
+
1249
+
1250
+	/**
1251
+	 * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1252
+	 * so that we can hijack the default redirect locations for wp custom post types
1253
+	 * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1254
+	 *
1255
+	 * @param  string $location This is the incoming currently set redirect location
1256
+	 * @param  string $post_id  This is the 'ID' value of the wp_posts table
1257
+	 * @return string           the new location to redirect to
1258
+	 */
1259
+	public function cpt_post_location_redirect($location, $post_id)
1260
+	{
1261
+		//we DO have a match so let's setup the url
1262
+		//we have to get the post to determine our route
1263
+		$post       = get_post($post_id);
1264
+		$edit_route = $this->_cpt_edit_routes[$post->post_type];
1265
+		//shared query_args
1266
+		$query_args = array('action' => $edit_route, 'post' => $post_id);
1267
+		$admin_url  = $this->_admin_base_url;
1268
+		if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1269
+			$status = get_post_status($post_id);
1270
+			if (isset($this->_req_data['publish'])) {
1271
+				switch ($status) {
1272
+					case 'pending':
1273
+						$message = 8;
1274
+						break;
1275
+					case 'future':
1276
+						$message = 9;
1277
+						break;
1278
+					default:
1279
+						$message = 6;
1280
+				}
1281
+			} else {
1282
+				$message = 'draft' === $status ? 10 : 1;
1283
+			}
1284
+		} else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1285
+			$message = 2;
1286
+			//			$append = '#postcustom';
1287
+		} else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1288
+			$message = 3;
1289
+			//			$append = '#postcustom';
1290
+		} elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') {
1291
+			$message = 7;
1292
+		} else {
1293
+			$message = 4;
1294
+		}
1295
+		//change the message if the post type is not viewable on the frontend
1296
+		$this->_cpt_object = get_post_type_object($post->post_type);
1297
+		$message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1298
+		$query_args = array_merge(array('message' => $message), $query_args);
1299
+		$this->_process_notices($query_args, true);
1300
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1301
+	}
1302
+
1303
+
1304
+
1305
+	/**
1306
+	 * This method is called to inject nav tabs on core WP cpt pages
1307
+	 *
1308
+	 * @access public
1309
+	 * @return void
1310
+	 */
1311
+	public function inject_nav_tabs()
1312
+	{
1313
+		//can we hijack and insert the nav_tabs?
1314
+		$nav_tabs = $this->_get_main_nav_tabs();
1315
+		//first close off existing form tag
1316
+		$html = '>';
1317
+		$html .= $nav_tabs;
1318
+		//now let's handle the remaining tag ( missing ">" is CORRECT )
1319
+		$html .= '<span></span';
1320
+		echo $html;
1321
+	}
1322
+
1323
+
1324
+
1325
+	/**
1326
+	 * This just sets up the post update messages when an update form is loaded
1327
+	 *
1328
+	 * @access public
1329
+	 * @param  array $messages the original messages array
1330
+	 * @return array           the new messages array
1331
+	 */
1332
+	public function post_update_messages($messages)
1333
+	{
1334
+		global $post;
1335
+		$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1336
+		$id = empty($id) && is_object($post) ? $post->ID : null;
1337
+		//		$post_type = $post ? $post->post_type : false;
1338
+		/*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1339 1339
 
1340 1340
         $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/
1341
-        $messages[$post->post_type] = array(
1342
-            0 => '', //Unused. Messages start at index 1.
1343
-            1 => sprintf(
1344
-                __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1345
-                $this->_cpt_object->labels->singular_name,
1346
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1347
-                '</a>'
1348
-            ),
1349
-            2 => __('Custom field updated'),
1350
-            3 => __('Custom field deleted.'),
1351
-            4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1352
-            5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1353
-                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1354
-                : false,
1355
-            6 => sprintf(
1356
-                __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1357
-                $this->_cpt_object->labels->singular_name,
1358
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1359
-                '</a>'
1360
-            ),
1361
-            7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1362
-            8 => sprintf(
1363
-                __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1364
-                $this->_cpt_object->labels->singular_name,
1365
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1366
-                '</a>'
1367
-            ),
1368
-            9 => sprintf(
1369
-                __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1370
-                $this->_cpt_object->labels->singular_name,
1371
-                '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1372
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1373
-                '</a>'
1374
-            ),
1375
-            10 => sprintf(
1376
-                __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1377
-                $this->_cpt_object->labels->singular_name,
1378
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1379
-                '</a>'
1380
-            ),
1381
-        );
1382
-        return $messages;
1383
-    }
1384
-
1385
-
1386
-
1387
-    /**
1388
-     * default method for the 'create_new' route for cpt admin pages.
1389
-     * For reference what to include in here, see wp-admin/post-new.php
1390
-     *
1391
-     * @access  protected
1392
-     * @return void
1393
-     */
1394
-    protected function _create_new_cpt_item()
1395
-    {
1396
-        // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1397
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1398
-        $post_type        = $this->_cpt_routes[$this->_req_action];
1399
-        $post_type_object = $this->_cpt_object;
1400
-        $title            = $post_type_object->labels->add_new_item;
1401
-        $post    = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1402
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1403
-        //modify the default editor title field with default title.
1404
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1405
-        $this->loadEditorTemplate(true);
1406
-    }
1407
-
1408
-
1409
-    /**
1410
-     * Enqueues auto-save and loads the editor template
1411
-     *
1412
-     * @param bool $creating
1413
-     */
1414
-    private function loadEditorTemplate($creating = true) {
1415
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1416
-        //these vars are used by the template
1417
-        $editing = true;
1418
-        $post_ID = $post->ID;
1419
-        if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) {
1420
-            //only enqueue autosave when creating event (necessary to get permalink/url generated)
1421
-            //otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context.
1422
-            if ($creating) {
1423
-                wp_enqueue_script('autosave');
1424
-            } else {
1425
-                if (isset($this->_cpt_routes[$this->_req_data['action']])
1426
-                    && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1427
-                ) {
1428
-                    $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1429
-                        'create_new', $this);
1430
-                    $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array(
1431
-                        'action' => $create_new_action,
1432
-                        'page'   => $this->page_slug,
1433
-                    ), 'admin.php');
1434
-                }
1435
-            }
1436
-            include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1437
-        }
1438
-    }
1439
-
1440
-
1441
-
1442
-    public function add_new_admin_page_global()
1443
-    {
1444
-        $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1445
-        ?>
1341
+		$messages[$post->post_type] = array(
1342
+			0 => '', //Unused. Messages start at index 1.
1343
+			1 => sprintf(
1344
+				__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1345
+				$this->_cpt_object->labels->singular_name,
1346
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1347
+				'</a>'
1348
+			),
1349
+			2 => __('Custom field updated'),
1350
+			3 => __('Custom field deleted.'),
1351
+			4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1352
+			5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1353
+				$this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1354
+				: false,
1355
+			6 => sprintf(
1356
+				__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1357
+				$this->_cpt_object->labels->singular_name,
1358
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1359
+				'</a>'
1360
+			),
1361
+			7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1362
+			8 => sprintf(
1363
+				__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1364
+				$this->_cpt_object->labels->singular_name,
1365
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1366
+				'</a>'
1367
+			),
1368
+			9 => sprintf(
1369
+				__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1370
+				$this->_cpt_object->labels->singular_name,
1371
+				'<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1372
+				'<a target="_blank" href="' . esc_url(get_permalink($id)),
1373
+				'</a>'
1374
+			),
1375
+			10 => sprintf(
1376
+				__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1377
+				$this->_cpt_object->labels->singular_name,
1378
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1379
+				'</a>'
1380
+			),
1381
+		);
1382
+		return $messages;
1383
+	}
1384
+
1385
+
1386
+
1387
+	/**
1388
+	 * default method for the 'create_new' route for cpt admin pages.
1389
+	 * For reference what to include in here, see wp-admin/post-new.php
1390
+	 *
1391
+	 * @access  protected
1392
+	 * @return void
1393
+	 */
1394
+	protected function _create_new_cpt_item()
1395
+	{
1396
+		// gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1397
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1398
+		$post_type        = $this->_cpt_routes[$this->_req_action];
1399
+		$post_type_object = $this->_cpt_object;
1400
+		$title            = $post_type_object->labels->add_new_item;
1401
+		$post    = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1402
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1403
+		//modify the default editor title field with default title.
1404
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1405
+		$this->loadEditorTemplate(true);
1406
+	}
1407
+
1408
+
1409
+	/**
1410
+	 * Enqueues auto-save and loads the editor template
1411
+	 *
1412
+	 * @param bool $creating
1413
+	 */
1414
+	private function loadEditorTemplate($creating = true) {
1415
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1416
+		//these vars are used by the template
1417
+		$editing = true;
1418
+		$post_ID = $post->ID;
1419
+		if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) {
1420
+			//only enqueue autosave when creating event (necessary to get permalink/url generated)
1421
+			//otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context.
1422
+			if ($creating) {
1423
+				wp_enqueue_script('autosave');
1424
+			} else {
1425
+				if (isset($this->_cpt_routes[$this->_req_data['action']])
1426
+					&& ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1427
+				) {
1428
+					$create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1429
+						'create_new', $this);
1430
+					$post_new_file = EE_Admin_Page::add_query_args_and_nonce(array(
1431
+						'action' => $create_new_action,
1432
+						'page'   => $this->page_slug,
1433
+					), 'admin.php');
1434
+				}
1435
+			}
1436
+			include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1437
+		}
1438
+	}
1439
+
1440
+
1441
+
1442
+	public function add_new_admin_page_global()
1443
+	{
1444
+		$admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1445
+		?>
1446 1446
         <script type="text/javascript">
1447 1447
             adminpage = '<?php echo $admin_page; ?>';
1448 1448
         </script>
1449 1449
         <?php
1450
-    }
1451
-
1452
-
1453
-
1454
-    /**
1455
-     * default method for the 'edit' route for cpt admin pages
1456
-     * For reference on what to put in here, refer to wp-admin/post.php
1457
-     *
1458
-     * @access protected
1459
-     * @return string   template for edit cpt form
1460
-     */
1461
-    protected function _edit_cpt_item()
1462
-    {
1463
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1464
-        $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1465
-        $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1466
-        if (empty ($post)) {
1467
-            wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
1468
-        }
1469
-        if ( ! empty($_GET['get-post-lock'])) {
1470
-            wp_set_post_lock($post_id);
1471
-            wp_redirect(get_edit_post_link($post_id, 'url'));
1472
-            exit();
1473
-        }
1474
-
1475
-        // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1476
-        $post_type        = $this->_cpt_routes[$this->_req_action];
1477
-        $post_type_object = $this->_cpt_object;
1478
-
1479
-        if ( ! wp_check_post_lock($post->ID)) {
1480
-            wp_set_post_lock($post->ID);
1481
-        }
1482
-        add_action('admin_footer', '_admin_notice_post_locked');
1483
-        if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1484
-            wp_enqueue_script('admin-comments');
1485
-            enqueue_comment_hotkeys_js();
1486
-        }
1487
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1488
-        //modify the default editor title field with default title.
1489
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1490
-        $this->loadEditorTemplate(false);
1491
-    }
1492
-
1493
-
1494
-
1495
-    /**
1496
-     * some getters
1497
-     */
1498
-    /**
1499
-     * This returns the protected _cpt_model_obj property
1500
-     *
1501
-     * @return EE_CPT_Base
1502
-     */
1503
-    public function get_cpt_model_obj()
1504
-    {
1505
-        return $this->_cpt_model_obj;
1506
-    }
1450
+	}
1451
+
1452
+
1453
+
1454
+	/**
1455
+	 * default method for the 'edit' route for cpt admin pages
1456
+	 * For reference on what to put in here, refer to wp-admin/post.php
1457
+	 *
1458
+	 * @access protected
1459
+	 * @return string   template for edit cpt form
1460
+	 */
1461
+	protected function _edit_cpt_item()
1462
+	{
1463
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1464
+		$post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1465
+		$post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1466
+		if (empty ($post)) {
1467
+			wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
1468
+		}
1469
+		if ( ! empty($_GET['get-post-lock'])) {
1470
+			wp_set_post_lock($post_id);
1471
+			wp_redirect(get_edit_post_link($post_id, 'url'));
1472
+			exit();
1473
+		}
1474
+
1475
+		// template vars for WP_ADMIN_PATH . 'edit-form-advanced.php'
1476
+		$post_type        = $this->_cpt_routes[$this->_req_action];
1477
+		$post_type_object = $this->_cpt_object;
1478
+
1479
+		if ( ! wp_check_post_lock($post->ID)) {
1480
+			wp_set_post_lock($post->ID);
1481
+		}
1482
+		add_action('admin_footer', '_admin_notice_post_locked');
1483
+		if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1484
+			wp_enqueue_script('admin-comments');
1485
+			enqueue_comment_hotkeys_js();
1486
+		}
1487
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1488
+		//modify the default editor title field with default title.
1489
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1490
+		$this->loadEditorTemplate(false);
1491
+	}
1492
+
1493
+
1494
+
1495
+	/**
1496
+	 * some getters
1497
+	 */
1498
+	/**
1499
+	 * This returns the protected _cpt_model_obj property
1500
+	 *
1501
+	 * @return EE_CPT_Base
1502
+	 */
1503
+	public function get_cpt_model_obj()
1504
+	{
1505
+		return $this->_cpt_model_obj;
1506
+	}
1507 1507
 
1508 1508
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
      */
243 243
     protected function _register_autosave_containers($ids)
244 244
     {
245
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
245
+        $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
246 246
     }
247 247
 
248 248
 
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
         //filter _autosave_containers
290 290
         $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
291 291
             $this->_autosave_containers, $this);
292
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
292
+        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers',
293 293
             $containers, $this);
294 294
 
295 295
         wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
         // This is for any plugins that are doing things properly
402 402
         // and hooking into the load page hook for core wp cpt routes.
403 403
         global $pagenow;
404
-        do_action('load-' . $pagenow);
404
+        do_action('load-'.$pagenow);
405 405
         $this->modify_current_screen();
406 406
         add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
407 407
         //we route REALLY early.
@@ -432,8 +432,8 @@  discard block
 block discarded – undo
432 432
                 'admin.php?page=espresso_registrations&action=contact_list',
433 433
             ),
434 434
             1 => array(
435
-                'edit.php?post_type=' . $this->_cpt_object->name,
436
-                'admin.php?page=' . $this->_cpt_object->name,
435
+                'edit.php?post_type='.$this->_cpt_object->name,
436
+                'admin.php?page='.$this->_cpt_object->name,
437 437
             ),
438 438
         );
439 439
         foreach ($routes_to_match as $route_matches) {
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
         $cpt_has_support = ! empty($cpt_args['page_templates']);
467 467
 
468 468
         //if the installed version of WP is > 4.7 we do some additional checks.
469
-        if (RecommendedVersions::compareWordPressVersion('4.7','>=')) {
469
+        if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
470 470
             $post_templates = wp_get_theme()->get_post_templates();
471 471
             //if there are $post_templates for this cpt, then we return false for this method because
472 472
             //that means we aren't going to load our page template manager and leave that up to the native
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
         global $post;
490 490
         $template = '';
491 491
 
492
-        if (RecommendedVersions::compareWordPressVersion('4.7','>=')) {
492
+        if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) {
493 493
             $page_template_count = count(get_page_templates());
494 494
         } else {
495 495
             $page_template_count = count(get_page_templates($post));
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
         $post = get_post($id);
527 527
         if ('publish' !== get_post_status($post)) {
528 528
             //include shims for the `get_preview_post_link` function
529
-            require_once( EE_CORE . 'wordpress-shims.php' );
529
+            require_once(EE_CORE.'wordpress-shims.php');
530 530
             $return .= '<span_id="view-post-btn"><a target="_blank" href="'
531 531
                        . get_preview_post_link($id)
532 532
                        . '" class="button button-small">'
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
             $template_args['statuses']         = $statuses;
565 565
         }
566 566
 
567
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
567
+        $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php';
568 568
         EEH_Template::display_template($template, $template_args);
569 569
     }
570 570
 
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
             $this->_template_args['success'] = true;
619 619
         }
620 620
         do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
621
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
621
+        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this);
622 622
         //now let's return json
623 623
         $this->_return_json();
624 624
     }
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
         }
717 717
         // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions
718 718
         if ($ignore_route_check) {
719
-            $post_type   = get_post_type($id);
719
+            $post_type = get_post_type($id);
720 720
             /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
721 721
             $custom_post_types = LoaderFactory::getLoader()->getShared(
722 722
                 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
@@ -1028,7 +1028,7 @@  discard block
 block discarded – undo
1028 1028
         //global action
1029 1029
         do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
1030 1030
         //class specific action so you can limit hooking into a specific page.
1031
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
1031
+        do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id);
1032 1032
     }
1033 1033
 
1034 1034
 
@@ -1106,7 +1106,7 @@  discard block
 block discarded – undo
1106 1106
         if ( ! empty($id) && get_option('permalink_structure') !== '') {
1107 1107
             $post = get_post($id);
1108 1108
             if (isset($post->post_type) && $this->page_slug === $post->post_type) {
1109
-                $shortlink = home_url('?p=' . $post->ID);
1109
+                $shortlink = home_url('?p='.$post->ID);
1110 1110
             }
1111 1111
         }
1112 1112
         return $shortlink;
@@ -1141,11 +1141,11 @@  discard block
 block discarded – undo
1141 1141
      */
1142 1142
     public function cpt_post_form_hidden_input()
1143 1143
     {
1144
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1144
+        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />';
1145 1145
         //we're also going to add the route value and the current page so we can direct autosave parsing correctly
1146 1146
         echo '<div id="ee-cpt-hidden-inputs">';
1147
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1148
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1147
+        echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />';
1148
+        echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />';
1149 1149
         echo '</div>';
1150 1150
     }
1151 1151
 
@@ -1232,7 +1232,7 @@  discard block
 block discarded – undo
1232 1232
         $this->_set_model_object($post->ID, true);
1233 1233
 
1234 1234
         //returns something like `trash_event` or `trash_attendee` or `trash_venue`
1235
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1235
+        $action = 'trash_'.str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1236 1236
 
1237 1237
         return EE_Admin_Page::add_query_args_and_nonce(
1238 1238
             array(
@@ -1343,39 +1343,39 @@  discard block
 block discarded – undo
1343 1343
             1 => sprintf(
1344 1344
                 __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1345 1345
                 $this->_cpt_object->labels->singular_name,
1346
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1346
+                '<a href="'.esc_url(get_permalink($id)).'">',
1347 1347
                 '</a>'
1348 1348
             ),
1349 1349
             2 => __('Custom field updated'),
1350 1350
             3 => __('Custom field deleted.'),
1351 1351
             4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1352 1352
             5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1353
-                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1353
+                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int) $_GET['revision'], false))
1354 1354
                 : false,
1355 1355
             6 => sprintf(
1356 1356
                 __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1357 1357
                 $this->_cpt_object->labels->singular_name,
1358
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1358
+                '<a href="'.esc_url(get_permalink($id)).'">',
1359 1359
                 '</a>'
1360 1360
             ),
1361 1361
             7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1362 1362
             8 => sprintf(
1363 1363
                 __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1364 1364
                 $this->_cpt_object->labels->singular_name,
1365
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1365
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">',
1366 1366
                 '</a>'
1367 1367
             ),
1368 1368
             9 => sprintf(
1369 1369
                 __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1370 1370
                 $this->_cpt_object->labels->singular_name,
1371
-                '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1372
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1371
+                '<strong>'.date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)).'</strong>',
1372
+                '<a target="_blank" href="'.esc_url(get_permalink($id)),
1373 1373
                 '</a>'
1374 1374
             ),
1375 1375
             10 => sprintf(
1376 1376
                 __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1377 1377
                 $this->_cpt_object->labels->singular_name,
1378
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1378
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1379 1379
                 '</a>'
1380 1380
             ),
1381 1381
         );
@@ -1398,7 +1398,7 @@  discard block
 block discarded – undo
1398 1398
         $post_type        = $this->_cpt_routes[$this->_req_action];
1399 1399
         $post_type_object = $this->_cpt_object;
1400 1400
         $title            = $post_type_object->labels->add_new_item;
1401
-        $post    = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1401
+        $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1402 1402
         add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1403 1403
         //modify the default editor title field with default title.
1404 1404
         add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
@@ -1433,7 +1433,7 @@  discard block
 block discarded – undo
1433 1433
                     ), 'admin.php');
1434 1434
                 }
1435 1435
             }
1436
-            include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1436
+            include_once WP_ADMIN_PATH.'edit-form-advanced.php';
1437 1437
         }
1438 1438
     }
1439 1439
 
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since       4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 
64 64
 } else {
65
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
66
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
-        /**
68
-         * espresso_minimum_php_version_error
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
65
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
66
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
+		/**
68
+		 * espresso_minimum_php_version_error
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.62.rc.025');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.62.rc.025');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.
core/EE_System.core.php 1 patch
Indentation   +1306 added lines, -1306 removed lines patch added patch discarded remove patch
@@ -32,1312 +32,1312 @@
 block discarded – undo
32 32
 {
33 33
 
34 34
 
35
-    /**
36
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
37
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
38
-     */
39
-    const req_type_normal = 0;
40
-
41
-    /**
42
-     * Indicates this is a brand new installation of EE so we should install
43
-     * tables and default data etc
44
-     */
45
-    const req_type_new_activation = 1;
46
-
47
-    /**
48
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
49
-     * and we just exited maintenance mode). We MUST check the database is setup properly
50
-     * and that default data is setup too
51
-     */
52
-    const req_type_reactivation = 2;
53
-
54
-    /**
55
-     * indicates that EE has been upgraded since its previous request.
56
-     * We may have data migration scripts to call and will want to trigger maintenance mode
57
-     */
58
-    const req_type_upgrade = 3;
59
-
60
-    /**
61
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
62
-     */
63
-    const req_type_downgrade = 4;
64
-
65
-    /**
66
-     * @deprecated since version 4.6.0.dev.006
67
-     * Now whenever a new_activation is detected the request type is still just
68
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
69
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
70
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
71
-     * (Specifically, when the migration manager indicates migrations are finished
72
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
73
-     */
74
-    const req_type_activation_but_not_installed = 5;
75
-
76
-    /**
77
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
78
-     */
79
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
80
-
81
-
82
-    /**
83
-     * @var EE_System $_instance
84
-     */
85
-    private static $_instance;
86
-
87
-    /**
88
-     * @var EE_Registry $registry
89
-     */
90
-    private $registry;
91
-
92
-    /**
93
-     * @var LoaderInterface $loader
94
-     */
95
-    private $loader;
96
-
97
-    /**
98
-     * @var EE_Capabilities $capabilities
99
-     */
100
-    private $capabilities;
101
-
102
-    /**
103
-     * @var RequestInterface $request
104
-     */
105
-    private $request;
106
-
107
-    /**
108
-     * @var EE_Maintenance_Mode $maintenance_mode
109
-     */
110
-    private $maintenance_mode;
111
-
112
-    /**
113
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
114
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
115
-     *
116
-     * @var int $_req_type
117
-     */
118
-    private $_req_type;
119
-
120
-    /**
121
-     * Whether or not there was a non-micro version change in EE core version during this request
122
-     *
123
-     * @var boolean $_major_version_change
124
-     */
125
-    private $_major_version_change = false;
126
-
127
-    /**
128
-     * A Context DTO dedicated solely to identifying the current request type.
129
-     *
130
-     * @var RequestTypeContextCheckerInterface $request_type
131
-     */
132
-    private $request_type;
133
-
134
-
135
-
136
-    /**
137
-     * @singleton method used to instantiate class object
138
-     * @param EE_Registry|null         $registry
139
-     * @param LoaderInterface|null     $loader
140
-     * @param RequestInterface|null          $request
141
-     * @param EE_Maintenance_Mode|null $maintenance_mode
142
-     * @return EE_System
143
-     */
144
-    public static function instance(
145
-        EE_Registry $registry = null,
146
-        LoaderInterface $loader = null,
147
-        RequestInterface $request = null,
148
-        EE_Maintenance_Mode $maintenance_mode = null
149
-    ) {
150
-        // check if class object is instantiated
151
-        if (! self::$_instance instanceof EE_System) {
152
-            self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
153
-        }
154
-        return self::$_instance;
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     * resets the instance and returns it
161
-     *
162
-     * @return EE_System
163
-     */
164
-    public static function reset()
165
-    {
166
-        self::$_instance->_req_type = null;
167
-        //make sure none of the old hooks are left hanging around
168
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
169
-        //we need to reset the migration manager in order for it to detect DMSs properly
170
-        EE_Data_Migration_Manager::reset();
171
-        self::instance()->detect_activations_or_upgrades();
172
-        self::instance()->perform_activations_upgrades_and_migrations();
173
-        return self::instance();
174
-    }
175
-
176
-
177
-
178
-    /**
179
-     * sets hooks for running rest of system
180
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
181
-     * starting EE Addons from any other point may lead to problems
182
-     *
183
-     * @param EE_Registry         $registry
184
-     * @param LoaderInterface     $loader
185
-     * @param RequestInterface          $request
186
-     * @param EE_Maintenance_Mode $maintenance_mode
187
-     */
188
-    private function __construct(
189
-        EE_Registry $registry,
190
-        LoaderInterface $loader,
191
-        RequestInterface $request,
192
-        EE_Maintenance_Mode $maintenance_mode
193
-    ) {
194
-        $this->registry         = $registry;
195
-        $this->loader           = $loader;
196
-        $this->request          = $request;
197
-        $this->maintenance_mode = $maintenance_mode;
198
-        do_action('AHEE__EE_System__construct__begin', $this);
199
-        add_action(
200
-            'AHEE__EE_Bootstrap__load_espresso_addons',
201
-            array($this, 'loadCapabilities'),
202
-            5
203
-        );
204
-        add_action(
205
-            'AHEE__EE_Bootstrap__load_espresso_addons',
206
-            array($this, 'loadCommandBus'),
207
-            7
208
-        );
209
-        add_action(
210
-            'AHEE__EE_Bootstrap__load_espresso_addons',
211
-            array($this, 'loadPluginApi'),
212
-            9
213
-        );
214
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
215
-        add_action(
216
-            'AHEE__EE_Bootstrap__load_espresso_addons',
217
-            array($this, 'load_espresso_addons')
218
-        );
219
-        // when an ee addon is activated, we want to call the core hook(s) again
220
-        // because the newly-activated addon didn't get a chance to run at all
221
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
222
-        // detect whether install or upgrade
223
-        add_action(
224
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
225
-            array($this, 'detect_activations_or_upgrades'),
226
-            3
227
-        );
228
-        // load EE_Config, EE_Textdomain, etc
229
-        add_action(
230
-            'AHEE__EE_Bootstrap__load_core_configuration',
231
-            array($this, 'load_core_configuration'),
232
-            5
233
-        );
234
-        // load EE_Config, EE_Textdomain, etc
235
-        add_action(
236
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
237
-            array($this, 'register_shortcodes_modules_and_widgets'),
238
-            7
239
-        );
240
-        // you wanna get going? I wanna get going... let's get going!
241
-        add_action(
242
-            'AHEE__EE_Bootstrap__brew_espresso',
243
-            array($this, 'brew_espresso'),
244
-            9
245
-        );
246
-        //other housekeeping
247
-        //exclude EE critical pages from wp_list_pages
248
-        add_filter(
249
-            'wp_list_pages_excludes',
250
-            array($this, 'remove_pages_from_wp_list_pages'),
251
-            10
252
-        );
253
-        // ALL EE Addons should use the following hook point to attach their initial setup too
254
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
255
-        do_action('AHEE__EE_System__construct__complete', $this);
256
-    }
257
-
258
-
259
-    /**
260
-     * load and setup EE_Capabilities
261
-     *
262
-     * @return void
263
-     * @throws EE_Error
264
-     */
265
-    public function loadCapabilities()
266
-    {
267
-        $this->capabilities = $this->loader->getShared('EE_Capabilities');
268
-        add_action(
269
-            'AHEE__EE_Capabilities__init_caps__before_initialization',
270
-            function ()
271
-            {
272
-                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
273
-            }
274
-        );
275
-    }
276
-
277
-
278
-
279
-    /**
280
-     * create and cache the CommandBus, and also add middleware
281
-     * The CapChecker middleware requires the use of EE_Capabilities
282
-     * which is why we need to load the CommandBus after Caps are set up
283
-     *
284
-     * @return void
285
-     * @throws EE_Error
286
-     */
287
-    public function loadCommandBus()
288
-    {
289
-        $this->loader->getShared(
290
-            'CommandBusInterface',
291
-            array(
292
-                null,
293
-                apply_filters(
294
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
295
-                    array(
296
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
297
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
298
-                    )
299
-                ),
300
-            )
301
-        );
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * @return void
308
-     * @throws EE_Error
309
-     */
310
-    public function loadPluginApi()
311
-    {
312
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
313
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
314
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
315
-        $this->loader->getShared('EE_Request_Handler');
316
-    }
317
-
318
-
319
-    /**
320
-     * @param string $addon_name
321
-     * @param string $version_constant
322
-     * @param string $min_version_required
323
-     * @param string $load_callback
324
-     * @param string $plugin_file_constant
325
-     * @return void
326
-     */
327
-    private function deactivateIncompatibleAddon(
328
-        $addon_name,
329
-        $version_constant,
330
-        $min_version_required,
331
-        $load_callback,
332
-        $plugin_file_constant
333
-    ) {
334
-        if (! defined($version_constant)) {
335
-            return;
336
-        }
337
-        $addon_version = constant($version_constant);
338
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
339
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
340
-            if (! function_exists('deactivate_plugins')) {
341
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
342
-            }
343
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
344
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
345
-            EE_Error::add_error(
346
-                sprintf(
347
-                    esc_html__(
348
-                        'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
349
-                        'event_espresso'
350
-                    ),
351
-                    $addon_name,
352
-                    $min_version_required
353
-                ),
354
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
355
-            );
356
-            EE_Error::get_notices(false, true);
357
-        }
358
-    }
359
-
360
-
361
-    /**
362
-     * load_espresso_addons
363
-     * allow addons to load first so that they can set hooks for running DMS's, etc
364
-     * this is hooked into both:
365
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
366
-     *        which runs during the WP 'plugins_loaded' action at priority 5
367
-     *    and the WP 'activate_plugin' hook point
368
-     *
369
-     * @access public
370
-     * @return void
371
-     */
372
-    public function load_espresso_addons()
373
-    {
374
-        $this->deactivateIncompatibleAddon(
375
-            'Wait Lists',
376
-            'EE_WAIT_LISTS_VERSION',
377
-            '1.0.0.beta.074',
378
-            'load_espresso_wait_lists',
379
-            'EE_WAIT_LISTS_PLUGIN_FILE'
380
-        );
381
-        $this->deactivateIncompatibleAddon(
382
-            'Automated Upcoming Event Notifications',
383
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
384
-            '1.0.0.beta.091',
385
-            'load_espresso_automated_upcoming_event_notification',
386
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
387
-        );
388
-        do_action('AHEE__EE_System__load_espresso_addons');
389
-        //if the WP API basic auth plugin isn't already loaded, load it now.
390
-        //We want it for mobile apps. Just include the entire plugin
391
-        //also, don't load the basic auth when a plugin is getting activated, because
392
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
393
-        //and causes a fatal error
394
-        if (
395
-            $this->request->getRequestParam('activate') !== 'true'
396
-            && ! function_exists('json_basic_auth_handler')
397
-            && ! function_exists('json_basic_auth_error')
398
-            && ! in_array(
399
-                $this->request->getRequestParam('action'),
400
-                array('activate', 'activate-selected'),
401
-                true
402
-            )
403
-        ) {
404
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
405
-        }
406
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
407
-    }
408
-
409
-
410
-
411
-    /**
412
-     * detect_activations_or_upgrades
413
-     * Checks for activation or upgrade of core first;
414
-     * then also checks if any registered addons have been activated or upgraded
415
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
416
-     * which runs during the WP 'plugins_loaded' action at priority 3
417
-     *
418
-     * @access public
419
-     * @return void
420
-     */
421
-    public function detect_activations_or_upgrades()
422
-    {
423
-        //first off: let's make sure to handle core
424
-        $this->detect_if_activation_or_upgrade();
425
-        foreach ($this->registry->addons as $addon) {
426
-            if ($addon instanceof EE_Addon) {
427
-                //detect teh request type for that addon
428
-                $addon->detect_activation_or_upgrade();
429
-            }
430
-        }
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * detect_if_activation_or_upgrade
437
-     * Takes care of detecting whether this is a brand new install or code upgrade,
438
-     * and either setting up the DB or setting up maintenance mode etc.
439
-     *
440
-     * @access public
441
-     * @return void
442
-     */
443
-    public function detect_if_activation_or_upgrade()
444
-    {
445
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
446
-        // check if db has been updated, or if its a brand-new installation
447
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
448
-        $request_type       = $this->detect_req_type($espresso_db_update);
449
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
450
-        switch ($request_type) {
451
-            case EE_System::req_type_new_activation:
452
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
453
-                $this->_handle_core_version_change($espresso_db_update);
454
-                break;
455
-            case EE_System::req_type_reactivation:
456
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
457
-                $this->_handle_core_version_change($espresso_db_update);
458
-                break;
459
-            case EE_System::req_type_upgrade:
460
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
461
-                //migrations may be required now that we've upgraded
462
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
463
-                $this->_handle_core_version_change($espresso_db_update);
464
-                //				echo "done upgrade";die;
465
-                break;
466
-            case EE_System::req_type_downgrade:
467
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
468
-                //its possible migrations are no longer required
469
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
470
-                $this->_handle_core_version_change($espresso_db_update);
471
-                break;
472
-            case EE_System::req_type_normal:
473
-            default:
474
-                break;
475
-        }
476
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
477
-    }
478
-
479
-
480
-
481
-    /**
482
-     * Updates the list of installed versions and sets hooks for
483
-     * initializing the database later during the request
484
-     *
485
-     * @param array $espresso_db_update
486
-     */
487
-    private function _handle_core_version_change($espresso_db_update)
488
-    {
489
-        $this->update_list_of_installed_versions($espresso_db_update);
490
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
491
-        add_action(
492
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
493
-            array($this, 'initialize_db_if_no_migrations_required')
494
-        );
495
-    }
496
-
497
-
498
-
499
-    /**
500
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
501
-     * information about what versions of EE have been installed and activated,
502
-     * NOT necessarily the state of the database
503
-     *
504
-     * @param mixed $espresso_db_update           the value of the WordPress option.
505
-     *                                            If not supplied, fetches it from the options table
506
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
507
-     */
508
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
509
-    {
510
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
511
-        if (! $espresso_db_update) {
512
-            $espresso_db_update = get_option('espresso_db_update');
513
-        }
514
-        // check that option is an array
515
-        if (! is_array($espresso_db_update)) {
516
-            // if option is FALSE, then it never existed
517
-            if ($espresso_db_update === false) {
518
-                // make $espresso_db_update an array and save option with autoload OFF
519
-                $espresso_db_update = array();
520
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
521
-            } else {
522
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
523
-                $espresso_db_update = array($espresso_db_update => array());
524
-                update_option('espresso_db_update', $espresso_db_update);
525
-            }
526
-        } else {
527
-            $corrected_db_update = array();
528
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
529
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
530
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
531
-                    //the key is an int, and the value IS NOT an array
532
-                    //so it must be numerically-indexed, where values are versions installed...
533
-                    //fix it!
534
-                    $version_string                         = $should_be_array;
535
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
536
-                } else {
537
-                    //ok it checks out
538
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
539
-                }
540
-            }
541
-            $espresso_db_update = $corrected_db_update;
542
-            update_option('espresso_db_update', $espresso_db_update);
543
-        }
544
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
545
-        return $espresso_db_update;
546
-    }
547
-
548
-
549
-
550
-    /**
551
-     * Does the traditional work of setting up the plugin's database and adding default data.
552
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
553
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
554
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
555
-     * so that it will be done when migrations are finished
556
-     *
557
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
558
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
559
-     *                                       This is a resource-intensive job
560
-     *                                       so we prefer to only do it when necessary
561
-     * @return void
562
-     * @throws EE_Error
563
-     */
564
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
565
-    {
566
-        $request_type = $this->detect_req_type();
567
-        //only initialize system if we're not in maintenance mode.
568
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
569
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
570
-            $rewrite_rules = $this->loader->getShared(
571
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
572
-            );
573
-            $rewrite_rules->flush();
574
-            if ($verify_schema) {
575
-                EEH_Activation::initialize_db_and_folders();
576
-            }
577
-            EEH_Activation::initialize_db_content();
578
-            EEH_Activation::system_initialization();
579
-            if ($initialize_addons_too) {
580
-                $this->initialize_addons();
581
-            }
582
-        } else {
583
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
584
-        }
585
-        if ($request_type === EE_System::req_type_new_activation
586
-            || $request_type === EE_System::req_type_reactivation
587
-            || (
588
-                $request_type === EE_System::req_type_upgrade
589
-                && $this->is_major_version_change()
590
-            )
591
-        ) {
592
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
593
-        }
594
-    }
595
-
596
-
597
-
598
-    /**
599
-     * Initializes the db for all registered addons
600
-     *
601
-     * @throws EE_Error
602
-     */
603
-    public function initialize_addons()
604
-    {
605
-        //foreach registered addon, make sure its db is up-to-date too
606
-        foreach ($this->registry->addons as $addon) {
607
-            if ($addon instanceof EE_Addon) {
608
-                $addon->initialize_db_if_no_migrations_required();
609
-            }
610
-        }
611
-    }
612
-
613
-
614
-
615
-    /**
616
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
617
-     *
618
-     * @param    array  $version_history
619
-     * @param    string $current_version_to_add version to be added to the version history
620
-     * @return    boolean success as to whether or not this option was changed
621
-     */
622
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
623
-    {
624
-        if (! $version_history) {
625
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
626
-        }
627
-        if ($current_version_to_add === null) {
628
-            $current_version_to_add = espresso_version();
629
-        }
630
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
631
-        // re-save
632
-        return update_option('espresso_db_update', $version_history);
633
-    }
634
-
635
-
636
-
637
-    /**
638
-     * Detects if the current version indicated in the has existed in the list of
639
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
640
-     *
641
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
642
-     *                                  If not supplied, fetches it from the options table.
643
-     *                                  Also, caches its result so later parts of the code can also know whether
644
-     *                                  there's been an update or not. This way we can add the current version to
645
-     *                                  espresso_db_update, but still know if this is a new install or not
646
-     * @return int one of the constants on EE_System::req_type_
647
-     */
648
-    public function detect_req_type($espresso_db_update = null)
649
-    {
650
-        if ($this->_req_type === null) {
651
-            $espresso_db_update          = ! empty($espresso_db_update)
652
-                ? $espresso_db_update
653
-                : $this->fix_espresso_db_upgrade_option();
654
-            $this->_req_type             = EE_System::detect_req_type_given_activation_history(
655
-                $espresso_db_update,
656
-                'ee_espresso_activation', espresso_version()
657
-            );
658
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
659
-            $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
660
-        }
661
-        return $this->_req_type;
662
-    }
663
-
664
-
665
-
666
-    /**
667
-     * Returns whether or not there was a non-micro version change (ie, change in either
668
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
669
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
670
-     *
671
-     * @param $activation_history
672
-     * @return bool
673
-     */
674
-    private function _detect_major_version_change($activation_history)
675
-    {
676
-        $previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
677
-        $previous_version_parts = explode('.', $previous_version);
678
-        $current_version_parts  = explode('.', espresso_version());
679
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
680
-               && ($previous_version_parts[0] !== $current_version_parts[0]
681
-                   || $previous_version_parts[1] !== $current_version_parts[1]
682
-               );
683
-    }
684
-
685
-
686
-
687
-    /**
688
-     * Returns true if either the major or minor version of EE changed during this request.
689
-     * 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
690
-     *
691
-     * @return bool
692
-     */
693
-    public function is_major_version_change()
694
-    {
695
-        return $this->_major_version_change;
696
-    }
697
-
698
-
699
-
700
-    /**
701
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
702
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
703
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
704
-     * just activated to (for core that will always be espresso_version())
705
-     *
706
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
707
-     *                                                 ee plugin. for core that's 'espresso_db_update'
708
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
709
-     *                                                 indicate that this plugin was just activated
710
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
711
-     *                                                 espresso_version())
712
-     * @return int one of the constants on EE_System::req_type_*
713
-     */
714
-    public static function detect_req_type_given_activation_history(
715
-        $activation_history_for_addon,
716
-        $activation_indicator_option_name,
717
-        $version_to_upgrade_to
718
-    ) {
719
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
720
-        if ($activation_history_for_addon) {
721
-            //it exists, so this isn't a completely new install
722
-            //check if this version already in that list of previously installed versions
723
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
724
-                //it a version we haven't seen before
725
-                if ($version_is_higher === 1) {
726
-                    $req_type = EE_System::req_type_upgrade;
727
-                } else {
728
-                    $req_type = EE_System::req_type_downgrade;
729
-                }
730
-                delete_option($activation_indicator_option_name);
731
-            } else {
732
-                // its not an update. maybe a reactivation?
733
-                if (get_option($activation_indicator_option_name, false)) {
734
-                    if ($version_is_higher === -1) {
735
-                        $req_type = EE_System::req_type_downgrade;
736
-                    } elseif ($version_is_higher === 0) {
737
-                        //we've seen this version before, but it's an activation. must be a reactivation
738
-                        $req_type = EE_System::req_type_reactivation;
739
-                    } else {//$version_is_higher === 1
740
-                        $req_type = EE_System::req_type_upgrade;
741
-                    }
742
-                    delete_option($activation_indicator_option_name);
743
-                } else {
744
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
745
-                    if ($version_is_higher === -1) {
746
-                        $req_type = EE_System::req_type_downgrade;
747
-                    } elseif ($version_is_higher === 0) {
748
-                        //we've seen this version before and it's not an activation. its normal request
749
-                        $req_type = EE_System::req_type_normal;
750
-                    } else {//$version_is_higher === 1
751
-                        $req_type = EE_System::req_type_upgrade;
752
-                    }
753
-                }
754
-            }
755
-        } else {
756
-            //brand new install
757
-            $req_type = EE_System::req_type_new_activation;
758
-            delete_option($activation_indicator_option_name);
759
-        }
760
-        return $req_type;
761
-    }
762
-
763
-
764
-
765
-    /**
766
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
767
-     * the $activation_history_for_addon
768
-     *
769
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
770
-     *                                             sometimes containing 'unknown-date'
771
-     * @param string $version_to_upgrade_to        (current version)
772
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
773
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
774
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
775
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
776
-     */
777
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
778
-    {
779
-        //find the most recently-activated version
780
-        $most_recently_active_version =
781
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
782
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
783
-    }
784
-
785
-
786
-
787
-    /**
788
-     * Gets the most recently active version listed in the activation history,
789
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
790
-     *
791
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
792
-     *                                   sometimes containing 'unknown-date'
793
-     * @return string
794
-     */
795
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
796
-    {
797
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
798
-        $most_recently_active_version            = '0.0.0.dev.000';
799
-        if (is_array($activation_history)) {
800
-            foreach ($activation_history as $version => $times_activated) {
801
-                //check there is a record of when this version was activated. Otherwise,
802
-                //mark it as unknown
803
-                if (! $times_activated) {
804
-                    $times_activated = array('unknown-date');
805
-                }
806
-                if (is_string($times_activated)) {
807
-                    $times_activated = array($times_activated);
808
-                }
809
-                foreach ($times_activated as $an_activation) {
810
-                    if ($an_activation !== 'unknown-date'
811
-                        && $an_activation
812
-                           > $most_recently_active_version_activation) {
813
-                        $most_recently_active_version            = $version;
814
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
815
-                            ? '1970-01-01 00:00:00'
816
-                            : $an_activation;
817
-                    }
818
-                }
819
-            }
820
-        }
821
-        return $most_recently_active_version;
822
-    }
823
-
824
-
825
-
826
-    /**
827
-     * This redirects to the about EE page after activation
828
-     *
829
-     * @return void
830
-     */
831
-    public function redirect_to_about_ee()
832
-    {
833
-        $notices = EE_Error::get_notices(false);
834
-        //if current user is an admin and it's not an ajax or rest request
835
-        if (
836
-            ! isset($notices['errors'])
837
-            && $this->request->isAdmin()
838
-            && apply_filters(
839
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
840
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
841
-            )
842
-        ) {
843
-            $query_params = array('page' => 'espresso_about');
844
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
845
-                $query_params['new_activation'] = true;
846
-            }
847
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
848
-                $query_params['reactivation'] = true;
849
-            }
850
-            $url = add_query_arg($query_params, admin_url('admin.php'));
851
-            wp_safe_redirect($url);
852
-            exit();
853
-        }
854
-    }
855
-
856
-
857
-
858
-    /**
859
-     * load_core_configuration
860
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
861
-     * which runs during the WP 'plugins_loaded' action at priority 5
862
-     *
863
-     * @return void
864
-     * @throws ReflectionException
865
-     */
866
-    public function load_core_configuration()
867
-    {
868
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
869
-        $this->loader->getShared('EE_Load_Textdomain');
870
-        //load textdomain
871
-        EE_Load_Textdomain::load_textdomain();
872
-        // load and setup EE_Config and EE_Network_Config
873
-        $config = $this->loader->getShared('EE_Config');
874
-        $this->loader->getShared('EE_Network_Config');
875
-        // setup autoloaders
876
-        // enable logging?
877
-        if ($config->admin->use_full_logging) {
878
-            $this->loader->getShared('EE_Log');
879
-        }
880
-        // check for activation errors
881
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
882
-        if ($activation_errors) {
883
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
884
-            update_option('ee_plugin_activation_errors', false);
885
-        }
886
-        // get model names
887
-        $this->_parse_model_names();
888
-        //load caf stuff a chance to play during the activation process too.
889
-        $this->_maybe_brew_regular();
890
-        // configure custom post type definitions
891
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
892
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
893
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
894
-    }
895
-
896
-
897
-
898
-    /**
899
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
900
-     *
901
-     * @return void
902
-     * @throws ReflectionException
903
-     */
904
-    private function _parse_model_names()
905
-    {
906
-        //get all the files in the EE_MODELS folder that end in .model.php
907
-        $models                 = glob(EE_MODELS . '*.model.php');
908
-        $model_names            = array();
909
-        $non_abstract_db_models = array();
910
-        foreach ($models as $model) {
911
-            // get model classname
912
-            $classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
913
-            $short_name      = str_replace('EEM_', '', $classname);
914
-            $reflectionClass = new ReflectionClass($classname);
915
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
916
-                $non_abstract_db_models[ $short_name ] = $classname;
917
-            }
918
-            $model_names[ $short_name ] = $classname;
919
-        }
920
-        $this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
921
-        $this->registry->non_abstract_db_models = apply_filters(
922
-            'FHEE__EE_System__parse_implemented_model_names',
923
-            $non_abstract_db_models
924
-        );
925
-    }
926
-
927
-
928
-    /**
929
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
930
-     * that need to be setup before our EE_System launches.
931
-     *
932
-     * @return void
933
-     * @throws DomainException
934
-     * @throws InvalidArgumentException
935
-     * @throws InvalidDataTypeException
936
-     * @throws InvalidInterfaceException
937
-     * @throws InvalidClassException
938
-     * @throws InvalidFilePathException
939
-     */
940
-    private function _maybe_brew_regular()
941
-    {
942
-        /** @var Domain $domain */
943
-        $domain = DomainFactory::getShared(
944
-            new FullyQualifiedName(
945
-                'EventEspresso\core\domain\Domain'
946
-            ),
947
-            array(
948
-                new FilePath(EVENT_ESPRESSO_MAIN_FILE),
949
-                Version::fromString(espresso_version())
950
-            )
951
-        );
952
-        if ($domain->isCaffeinated()) {
953
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
954
-        }
955
-    }
956
-
957
-
958
-
959
-    /**
960
-     * register_shortcodes_modules_and_widgets
961
-     * generate lists of shortcodes and modules, then verify paths and classes
962
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
963
-     * which runs during the WP 'plugins_loaded' action at priority 7
964
-     *
965
-     * @access public
966
-     * @return void
967
-     * @throws Exception
968
-     */
969
-    public function register_shortcodes_modules_and_widgets()
970
-    {
971
-        try {
972
-            // load, register, and add shortcodes the new way
973
-            if ($this->request->isFrontend() || $this->request->isIframe()) {
974
-                $this->loader->getShared(
975
-                    'EventEspresso\core\services\shortcodes\ShortcodesManager',
976
-                    array(
977
-                        // and the old way, but we'll put it under control of the new system
978
-                        EE_Config::getLegacyShortcodesManager(),
979
-                    )
980
-                );
981
-            }
982
-            if (function_exists('register_block_type')) {
983
-                $editor_block_collection = $this->loader->getShared(
984
-                    'EventEspresso\core\domain\entities\editor\EditorBlockCollection'
985
-                );
986
-                // or the even newer newer new way
987
-                if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAdmin()) {
988
-                    $this->loader->getShared(
989
-                        'EventEspresso\core\services\editor\EditorBlockRegistrationManager',
990
-                        array($editor_block_collection, $this->request)
991
-                    );
992
-                }
993
-            }
994
-        } catch (Exception $exception) {
995
-            new ExceptionStackTraceDisplay($exception);
996
-        }
997
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
998
-        // check for addons using old hook point
999
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
1000
-            $this->_incompatible_addon_error();
1001
-        }
1002
-    }
1003
-
1004
-
1005
-
1006
-    /**
1007
-     * _incompatible_addon_error
1008
-     *
1009
-     * @access public
1010
-     * @return void
1011
-     */
1012
-    private function _incompatible_addon_error()
1013
-    {
1014
-        // get array of classes hooking into here
1015
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
1016
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
1017
-        );
1018
-        if (! empty($class_names)) {
1019
-            $msg = __(
1020
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
1021
-                'event_espresso'
1022
-            );
1023
-            $msg .= '<ul>';
1024
-            foreach ($class_names as $class_name) {
1025
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
1026
-                        array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
1027
-                        $class_name
1028
-                    ) . '</b></li>';
1029
-            }
1030
-            $msg .= '</ul>';
1031
-            $msg .= __(
1032
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1033
-                'event_espresso'
1034
-            );
1035
-            // save list of incompatible addons to wp-options for later use
1036
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
1037
-            if (is_admin()) {
1038
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1039
-            }
1040
-        }
1041
-    }
1042
-
1043
-
1044
-
1045
-    /**
1046
-     * brew_espresso
1047
-     * begins the process of setting hooks for initializing EE in the correct order
1048
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1049
-     * which runs during the WP 'plugins_loaded' action at priority 9
1050
-     *
1051
-     * @return void
1052
-     */
1053
-    public function brew_espresso()
1054
-    {
1055
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1056
-        // load some final core systems
1057
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
1058
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1059
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
1060
-        add_action('init', array($this, 'load_controllers'), 7);
1061
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
1062
-        add_action('init', array($this, 'initialize'), 10);
1063
-        add_action('init', array($this, 'initialize_last'), 100);
1064
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1065
-            // pew pew pew
1066
-            $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
1067
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1068
-        }
1069
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1070
-    }
1071
-
1072
-
1073
-
1074
-    /**
1075
-     *    set_hooks_for_core
1076
-     *
1077
-     * @access public
1078
-     * @return    void
1079
-     * @throws EE_Error
1080
-     */
1081
-    public function set_hooks_for_core()
1082
-    {
1083
-        $this->_deactivate_incompatible_addons();
1084
-        do_action('AHEE__EE_System__set_hooks_for_core');
1085
-        $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1086
-        //caps need to be initialized on every request so that capability maps are set.
1087
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1088
-        $this->registry->CAP->init_caps();
1089
-    }
1090
-
1091
-
1092
-
1093
-    /**
1094
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1095
-     * deactivates any addons considered incompatible with the current version of EE
1096
-     */
1097
-    private function _deactivate_incompatible_addons()
1098
-    {
1099
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
1100
-        if (! empty($incompatible_addons)) {
1101
-            $active_plugins = get_option('active_plugins', array());
1102
-            foreach ($active_plugins as $active_plugin) {
1103
-                foreach ($incompatible_addons as $incompatible_addon) {
1104
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1105
-                        unset($_GET['activate']);
1106
-                        espresso_deactivate_plugin($active_plugin);
1107
-                    }
1108
-                }
1109
-            }
1110
-        }
1111
-    }
1112
-
1113
-
1114
-
1115
-    /**
1116
-     *    perform_activations_upgrades_and_migrations
1117
-     *
1118
-     * @access public
1119
-     * @return    void
1120
-     */
1121
-    public function perform_activations_upgrades_and_migrations()
1122
-    {
1123
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1124
-    }
1125
-
1126
-
1127
-    /**
1128
-     * @return void
1129
-     * @throws DomainException
1130
-     */
1131
-    public function load_CPTs_and_session()
1132
-    {
1133
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1134
-        /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */
1135
-        $register_custom_taxonomies = $this->loader->getShared(
1136
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
1137
-        );
1138
-        $register_custom_taxonomies->registerCustomTaxonomies();
1139
-        /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
1140
-        $register_custom_post_types = $this->loader->getShared(
1141
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
1142
-        );
1143
-        $register_custom_post_types->registerCustomPostTypes();
1144
-        /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */
1145
-        $register_custom_taxonomy_terms = $this->loader->getShared(
1146
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
1147
-        );
1148
-        $register_custom_taxonomy_terms->registerCustomTaxonomyTerms();
1149
-        // load legacy Custom Post Types and Taxonomies
1150
-        $this->loader->getShared('EE_Register_CPTs');
1151
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1152
-    }
1153
-
1154
-
1155
-
1156
-    /**
1157
-     * load_controllers
1158
-     * this is the best place to load any additional controllers that needs access to EE core.
1159
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1160
-     * time
1161
-     *
1162
-     * @access public
1163
-     * @return void
1164
-     */
1165
-    public function load_controllers()
1166
-    {
1167
-        do_action('AHEE__EE_System__load_controllers__start');
1168
-        // let's get it started
1169
-        if (
1170
-            ! $this->maintenance_mode->level()
1171
-            && ($this->request->isFrontend() || $this->request->isFrontAjax())
1172
-        ) {
1173
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1174
-            $this->loader->getShared('EE_Front_Controller');
1175
-        } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1176
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1177
-            $this->loader->getShared('EE_Admin');
1178
-        }
1179
-        do_action('AHEE__EE_System__load_controllers__complete');
1180
-    }
1181
-
1182
-
1183
-
1184
-    /**
1185
-     * core_loaded_and_ready
1186
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1187
-     *
1188
-     * @access public
1189
-     * @return void
1190
-     */
1191
-    public function core_loaded_and_ready()
1192
-    {
1193
-        if (
1194
-            $this->request->isAdmin()
1195
-            || $this->request->isEeAjax()
1196
-            || $this->request->isFrontend()
1197
-        ) {
1198
-            $this->loader->getShared('EE_Session');
1199
-        }
1200
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1201
-        // load_espresso_template_tags
1202
-        if (
1203
-            is_readable(EE_PUBLIC . 'template_tags.php')
1204
-            && (
1205
-                $this->request->isFrontend()
1206
-                || $this->request->isAdmin()
1207
-                || $this->request->isIframe()
1208
-                || $this->request->isFeed()
1209
-            )
1210
-        ) {
1211
-            require_once EE_PUBLIC . 'template_tags.php';
1212
-        }
1213
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1214
-        if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1215
-            $this->loader->getShared('EventEspresso\core\services\assets\Registry');
1216
-        }
1217
-    }
1218
-
1219
-
1220
-
1221
-    /**
1222
-     * initialize
1223
-     * this is the best place to begin initializing client code
1224
-     *
1225
-     * @access public
1226
-     * @return void
1227
-     */
1228
-    public function initialize()
1229
-    {
1230
-        do_action('AHEE__EE_System__initialize');
1231
-    }
1232
-
1233
-
1234
-
1235
-    /**
1236
-     * initialize_last
1237
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1238
-     * initialize has done so
1239
-     *
1240
-     * @access public
1241
-     * @return void
1242
-     */
1243
-    public function initialize_last()
1244
-    {
1245
-        do_action('AHEE__EE_System__initialize_last');
1246
-        /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1247
-        $rewrite_rules = $this->loader->getShared(
1248
-            'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1249
-        );
1250
-        $rewrite_rules->flushRewriteRules();
1251
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1252
-    }
1253
-
1254
-
1255
-
1256
-    /**
1257
-     * @return void
1258
-     * @throws EE_Error
1259
-     */
1260
-    public function addEspressoToolbar()
1261
-    {
1262
-        $this->loader->getShared(
1263
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1264
-            array($this->registry->CAP)
1265
-        );
1266
-    }
1267
-
1268
-
1269
-
1270
-    /**
1271
-     * do_not_cache
1272
-     * sets no cache headers and defines no cache constants for WP plugins
1273
-     *
1274
-     * @access public
1275
-     * @return void
1276
-     */
1277
-    public static function do_not_cache()
1278
-    {
1279
-        // set no cache constants
1280
-        if (! defined('DONOTCACHEPAGE')) {
1281
-            define('DONOTCACHEPAGE', true);
1282
-        }
1283
-        if (! defined('DONOTCACHCEOBJECT')) {
1284
-            define('DONOTCACHCEOBJECT', true);
1285
-        }
1286
-        if (! defined('DONOTCACHEDB')) {
1287
-            define('DONOTCACHEDB', true);
1288
-        }
1289
-        // add no cache headers
1290
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1291
-        // plus a little extra for nginx and Google Chrome
1292
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1293
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1294
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1295
-    }
1296
-
1297
-
1298
-
1299
-    /**
1300
-     *    extra_nocache_headers
1301
-     *
1302
-     * @access    public
1303
-     * @param $headers
1304
-     * @return    array
1305
-     */
1306
-    public static function extra_nocache_headers($headers)
1307
-    {
1308
-        // for NGINX
1309
-        $headers['X-Accel-Expires'] = 0;
1310
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1311
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1312
-        return $headers;
1313
-    }
1314
-
1315
-
1316
-
1317
-    /**
1318
-     *    nocache_headers
1319
-     *
1320
-     * @access    public
1321
-     * @return    void
1322
-     */
1323
-    public static function nocache_headers()
1324
-    {
1325
-        nocache_headers();
1326
-    }
1327
-
1328
-
1329
-
1330
-    /**
1331
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1332
-     * never returned with the function.
1333
-     *
1334
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1335
-     * @return array
1336
-     */
1337
-    public function remove_pages_from_wp_list_pages($exclude_array)
1338
-    {
1339
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1340
-    }
35
+	/**
36
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
37
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
38
+	 */
39
+	const req_type_normal = 0;
40
+
41
+	/**
42
+	 * Indicates this is a brand new installation of EE so we should install
43
+	 * tables and default data etc
44
+	 */
45
+	const req_type_new_activation = 1;
46
+
47
+	/**
48
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
49
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
50
+	 * and that default data is setup too
51
+	 */
52
+	const req_type_reactivation = 2;
53
+
54
+	/**
55
+	 * indicates that EE has been upgraded since its previous request.
56
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
57
+	 */
58
+	const req_type_upgrade = 3;
59
+
60
+	/**
61
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
62
+	 */
63
+	const req_type_downgrade = 4;
64
+
65
+	/**
66
+	 * @deprecated since version 4.6.0.dev.006
67
+	 * Now whenever a new_activation is detected the request type is still just
68
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
69
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
70
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
71
+	 * (Specifically, when the migration manager indicates migrations are finished
72
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
73
+	 */
74
+	const req_type_activation_but_not_installed = 5;
75
+
76
+	/**
77
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
78
+	 */
79
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
80
+
81
+
82
+	/**
83
+	 * @var EE_System $_instance
84
+	 */
85
+	private static $_instance;
86
+
87
+	/**
88
+	 * @var EE_Registry $registry
89
+	 */
90
+	private $registry;
91
+
92
+	/**
93
+	 * @var LoaderInterface $loader
94
+	 */
95
+	private $loader;
96
+
97
+	/**
98
+	 * @var EE_Capabilities $capabilities
99
+	 */
100
+	private $capabilities;
101
+
102
+	/**
103
+	 * @var RequestInterface $request
104
+	 */
105
+	private $request;
106
+
107
+	/**
108
+	 * @var EE_Maintenance_Mode $maintenance_mode
109
+	 */
110
+	private $maintenance_mode;
111
+
112
+	/**
113
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
114
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
115
+	 *
116
+	 * @var int $_req_type
117
+	 */
118
+	private $_req_type;
119
+
120
+	/**
121
+	 * Whether or not there was a non-micro version change in EE core version during this request
122
+	 *
123
+	 * @var boolean $_major_version_change
124
+	 */
125
+	private $_major_version_change = false;
126
+
127
+	/**
128
+	 * A Context DTO dedicated solely to identifying the current request type.
129
+	 *
130
+	 * @var RequestTypeContextCheckerInterface $request_type
131
+	 */
132
+	private $request_type;
133
+
134
+
135
+
136
+	/**
137
+	 * @singleton method used to instantiate class object
138
+	 * @param EE_Registry|null         $registry
139
+	 * @param LoaderInterface|null     $loader
140
+	 * @param RequestInterface|null          $request
141
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
142
+	 * @return EE_System
143
+	 */
144
+	public static function instance(
145
+		EE_Registry $registry = null,
146
+		LoaderInterface $loader = null,
147
+		RequestInterface $request = null,
148
+		EE_Maintenance_Mode $maintenance_mode = null
149
+	) {
150
+		// check if class object is instantiated
151
+		if (! self::$_instance instanceof EE_System) {
152
+			self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
153
+		}
154
+		return self::$_instance;
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 * resets the instance and returns it
161
+	 *
162
+	 * @return EE_System
163
+	 */
164
+	public static function reset()
165
+	{
166
+		self::$_instance->_req_type = null;
167
+		//make sure none of the old hooks are left hanging around
168
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
169
+		//we need to reset the migration manager in order for it to detect DMSs properly
170
+		EE_Data_Migration_Manager::reset();
171
+		self::instance()->detect_activations_or_upgrades();
172
+		self::instance()->perform_activations_upgrades_and_migrations();
173
+		return self::instance();
174
+	}
175
+
176
+
177
+
178
+	/**
179
+	 * sets hooks for running rest of system
180
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
181
+	 * starting EE Addons from any other point may lead to problems
182
+	 *
183
+	 * @param EE_Registry         $registry
184
+	 * @param LoaderInterface     $loader
185
+	 * @param RequestInterface          $request
186
+	 * @param EE_Maintenance_Mode $maintenance_mode
187
+	 */
188
+	private function __construct(
189
+		EE_Registry $registry,
190
+		LoaderInterface $loader,
191
+		RequestInterface $request,
192
+		EE_Maintenance_Mode $maintenance_mode
193
+	) {
194
+		$this->registry         = $registry;
195
+		$this->loader           = $loader;
196
+		$this->request          = $request;
197
+		$this->maintenance_mode = $maintenance_mode;
198
+		do_action('AHEE__EE_System__construct__begin', $this);
199
+		add_action(
200
+			'AHEE__EE_Bootstrap__load_espresso_addons',
201
+			array($this, 'loadCapabilities'),
202
+			5
203
+		);
204
+		add_action(
205
+			'AHEE__EE_Bootstrap__load_espresso_addons',
206
+			array($this, 'loadCommandBus'),
207
+			7
208
+		);
209
+		add_action(
210
+			'AHEE__EE_Bootstrap__load_espresso_addons',
211
+			array($this, 'loadPluginApi'),
212
+			9
213
+		);
214
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
215
+		add_action(
216
+			'AHEE__EE_Bootstrap__load_espresso_addons',
217
+			array($this, 'load_espresso_addons')
218
+		);
219
+		// when an ee addon is activated, we want to call the core hook(s) again
220
+		// because the newly-activated addon didn't get a chance to run at all
221
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
222
+		// detect whether install or upgrade
223
+		add_action(
224
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
225
+			array($this, 'detect_activations_or_upgrades'),
226
+			3
227
+		);
228
+		// load EE_Config, EE_Textdomain, etc
229
+		add_action(
230
+			'AHEE__EE_Bootstrap__load_core_configuration',
231
+			array($this, 'load_core_configuration'),
232
+			5
233
+		);
234
+		// load EE_Config, EE_Textdomain, etc
235
+		add_action(
236
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
237
+			array($this, 'register_shortcodes_modules_and_widgets'),
238
+			7
239
+		);
240
+		// you wanna get going? I wanna get going... let's get going!
241
+		add_action(
242
+			'AHEE__EE_Bootstrap__brew_espresso',
243
+			array($this, 'brew_espresso'),
244
+			9
245
+		);
246
+		//other housekeeping
247
+		//exclude EE critical pages from wp_list_pages
248
+		add_filter(
249
+			'wp_list_pages_excludes',
250
+			array($this, 'remove_pages_from_wp_list_pages'),
251
+			10
252
+		);
253
+		// ALL EE Addons should use the following hook point to attach their initial setup too
254
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
255
+		do_action('AHEE__EE_System__construct__complete', $this);
256
+	}
257
+
258
+
259
+	/**
260
+	 * load and setup EE_Capabilities
261
+	 *
262
+	 * @return void
263
+	 * @throws EE_Error
264
+	 */
265
+	public function loadCapabilities()
266
+	{
267
+		$this->capabilities = $this->loader->getShared('EE_Capabilities');
268
+		add_action(
269
+			'AHEE__EE_Capabilities__init_caps__before_initialization',
270
+			function ()
271
+			{
272
+				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
273
+			}
274
+		);
275
+	}
276
+
277
+
278
+
279
+	/**
280
+	 * create and cache the CommandBus, and also add middleware
281
+	 * The CapChecker middleware requires the use of EE_Capabilities
282
+	 * which is why we need to load the CommandBus after Caps are set up
283
+	 *
284
+	 * @return void
285
+	 * @throws EE_Error
286
+	 */
287
+	public function loadCommandBus()
288
+	{
289
+		$this->loader->getShared(
290
+			'CommandBusInterface',
291
+			array(
292
+				null,
293
+				apply_filters(
294
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
295
+					array(
296
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
297
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
298
+					)
299
+				),
300
+			)
301
+		);
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * @return void
308
+	 * @throws EE_Error
309
+	 */
310
+	public function loadPluginApi()
311
+	{
312
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
313
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
314
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
315
+		$this->loader->getShared('EE_Request_Handler');
316
+	}
317
+
318
+
319
+	/**
320
+	 * @param string $addon_name
321
+	 * @param string $version_constant
322
+	 * @param string $min_version_required
323
+	 * @param string $load_callback
324
+	 * @param string $plugin_file_constant
325
+	 * @return void
326
+	 */
327
+	private function deactivateIncompatibleAddon(
328
+		$addon_name,
329
+		$version_constant,
330
+		$min_version_required,
331
+		$load_callback,
332
+		$plugin_file_constant
333
+	) {
334
+		if (! defined($version_constant)) {
335
+			return;
336
+		}
337
+		$addon_version = constant($version_constant);
338
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
339
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
340
+			if (! function_exists('deactivate_plugins')) {
341
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
342
+			}
343
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
344
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
345
+			EE_Error::add_error(
346
+				sprintf(
347
+					esc_html__(
348
+						'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
349
+						'event_espresso'
350
+					),
351
+					$addon_name,
352
+					$min_version_required
353
+				),
354
+				__FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
355
+			);
356
+			EE_Error::get_notices(false, true);
357
+		}
358
+	}
359
+
360
+
361
+	/**
362
+	 * load_espresso_addons
363
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
364
+	 * this is hooked into both:
365
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
366
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
367
+	 *    and the WP 'activate_plugin' hook point
368
+	 *
369
+	 * @access public
370
+	 * @return void
371
+	 */
372
+	public function load_espresso_addons()
373
+	{
374
+		$this->deactivateIncompatibleAddon(
375
+			'Wait Lists',
376
+			'EE_WAIT_LISTS_VERSION',
377
+			'1.0.0.beta.074',
378
+			'load_espresso_wait_lists',
379
+			'EE_WAIT_LISTS_PLUGIN_FILE'
380
+		);
381
+		$this->deactivateIncompatibleAddon(
382
+			'Automated Upcoming Event Notifications',
383
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
384
+			'1.0.0.beta.091',
385
+			'load_espresso_automated_upcoming_event_notification',
386
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
387
+		);
388
+		do_action('AHEE__EE_System__load_espresso_addons');
389
+		//if the WP API basic auth plugin isn't already loaded, load it now.
390
+		//We want it for mobile apps. Just include the entire plugin
391
+		//also, don't load the basic auth when a plugin is getting activated, because
392
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
393
+		//and causes a fatal error
394
+		if (
395
+			$this->request->getRequestParam('activate') !== 'true'
396
+			&& ! function_exists('json_basic_auth_handler')
397
+			&& ! function_exists('json_basic_auth_error')
398
+			&& ! in_array(
399
+				$this->request->getRequestParam('action'),
400
+				array('activate', 'activate-selected'),
401
+				true
402
+			)
403
+		) {
404
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
405
+		}
406
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
407
+	}
408
+
409
+
410
+
411
+	/**
412
+	 * detect_activations_or_upgrades
413
+	 * Checks for activation or upgrade of core first;
414
+	 * then also checks if any registered addons have been activated or upgraded
415
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
416
+	 * which runs during the WP 'plugins_loaded' action at priority 3
417
+	 *
418
+	 * @access public
419
+	 * @return void
420
+	 */
421
+	public function detect_activations_or_upgrades()
422
+	{
423
+		//first off: let's make sure to handle core
424
+		$this->detect_if_activation_or_upgrade();
425
+		foreach ($this->registry->addons as $addon) {
426
+			if ($addon instanceof EE_Addon) {
427
+				//detect teh request type for that addon
428
+				$addon->detect_activation_or_upgrade();
429
+			}
430
+		}
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * detect_if_activation_or_upgrade
437
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
438
+	 * and either setting up the DB or setting up maintenance mode etc.
439
+	 *
440
+	 * @access public
441
+	 * @return void
442
+	 */
443
+	public function detect_if_activation_or_upgrade()
444
+	{
445
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
446
+		// check if db has been updated, or if its a brand-new installation
447
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
448
+		$request_type       = $this->detect_req_type($espresso_db_update);
449
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
450
+		switch ($request_type) {
451
+			case EE_System::req_type_new_activation:
452
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
453
+				$this->_handle_core_version_change($espresso_db_update);
454
+				break;
455
+			case EE_System::req_type_reactivation:
456
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
457
+				$this->_handle_core_version_change($espresso_db_update);
458
+				break;
459
+			case EE_System::req_type_upgrade:
460
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
461
+				//migrations may be required now that we've upgraded
462
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
463
+				$this->_handle_core_version_change($espresso_db_update);
464
+				//				echo "done upgrade";die;
465
+				break;
466
+			case EE_System::req_type_downgrade:
467
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
468
+				//its possible migrations are no longer required
469
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
470
+				$this->_handle_core_version_change($espresso_db_update);
471
+				break;
472
+			case EE_System::req_type_normal:
473
+			default:
474
+				break;
475
+		}
476
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
477
+	}
478
+
479
+
480
+
481
+	/**
482
+	 * Updates the list of installed versions and sets hooks for
483
+	 * initializing the database later during the request
484
+	 *
485
+	 * @param array $espresso_db_update
486
+	 */
487
+	private function _handle_core_version_change($espresso_db_update)
488
+	{
489
+		$this->update_list_of_installed_versions($espresso_db_update);
490
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
491
+		add_action(
492
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
493
+			array($this, 'initialize_db_if_no_migrations_required')
494
+		);
495
+	}
496
+
497
+
498
+
499
+	/**
500
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
501
+	 * information about what versions of EE have been installed and activated,
502
+	 * NOT necessarily the state of the database
503
+	 *
504
+	 * @param mixed $espresso_db_update           the value of the WordPress option.
505
+	 *                                            If not supplied, fetches it from the options table
506
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
507
+	 */
508
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
509
+	{
510
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
511
+		if (! $espresso_db_update) {
512
+			$espresso_db_update = get_option('espresso_db_update');
513
+		}
514
+		// check that option is an array
515
+		if (! is_array($espresso_db_update)) {
516
+			// if option is FALSE, then it never existed
517
+			if ($espresso_db_update === false) {
518
+				// make $espresso_db_update an array and save option with autoload OFF
519
+				$espresso_db_update = array();
520
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
521
+			} else {
522
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
523
+				$espresso_db_update = array($espresso_db_update => array());
524
+				update_option('espresso_db_update', $espresso_db_update);
525
+			}
526
+		} else {
527
+			$corrected_db_update = array();
528
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
529
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
530
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
531
+					//the key is an int, and the value IS NOT an array
532
+					//so it must be numerically-indexed, where values are versions installed...
533
+					//fix it!
534
+					$version_string                         = $should_be_array;
535
+					$corrected_db_update[ $version_string ] = array('unknown-date');
536
+				} else {
537
+					//ok it checks out
538
+					$corrected_db_update[ $should_be_version_string ] = $should_be_array;
539
+				}
540
+			}
541
+			$espresso_db_update = $corrected_db_update;
542
+			update_option('espresso_db_update', $espresso_db_update);
543
+		}
544
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
545
+		return $espresso_db_update;
546
+	}
547
+
548
+
549
+
550
+	/**
551
+	 * Does the traditional work of setting up the plugin's database and adding default data.
552
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
553
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
554
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
555
+	 * so that it will be done when migrations are finished
556
+	 *
557
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
558
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
559
+	 *                                       This is a resource-intensive job
560
+	 *                                       so we prefer to only do it when necessary
561
+	 * @return void
562
+	 * @throws EE_Error
563
+	 */
564
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
565
+	{
566
+		$request_type = $this->detect_req_type();
567
+		//only initialize system if we're not in maintenance mode.
568
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
569
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
570
+			$rewrite_rules = $this->loader->getShared(
571
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
572
+			);
573
+			$rewrite_rules->flush();
574
+			if ($verify_schema) {
575
+				EEH_Activation::initialize_db_and_folders();
576
+			}
577
+			EEH_Activation::initialize_db_content();
578
+			EEH_Activation::system_initialization();
579
+			if ($initialize_addons_too) {
580
+				$this->initialize_addons();
581
+			}
582
+		} else {
583
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
584
+		}
585
+		if ($request_type === EE_System::req_type_new_activation
586
+			|| $request_type === EE_System::req_type_reactivation
587
+			|| (
588
+				$request_type === EE_System::req_type_upgrade
589
+				&& $this->is_major_version_change()
590
+			)
591
+		) {
592
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
593
+		}
594
+	}
595
+
596
+
597
+
598
+	/**
599
+	 * Initializes the db for all registered addons
600
+	 *
601
+	 * @throws EE_Error
602
+	 */
603
+	public function initialize_addons()
604
+	{
605
+		//foreach registered addon, make sure its db is up-to-date too
606
+		foreach ($this->registry->addons as $addon) {
607
+			if ($addon instanceof EE_Addon) {
608
+				$addon->initialize_db_if_no_migrations_required();
609
+			}
610
+		}
611
+	}
612
+
613
+
614
+
615
+	/**
616
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
617
+	 *
618
+	 * @param    array  $version_history
619
+	 * @param    string $current_version_to_add version to be added to the version history
620
+	 * @return    boolean success as to whether or not this option was changed
621
+	 */
622
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
623
+	{
624
+		if (! $version_history) {
625
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
626
+		}
627
+		if ($current_version_to_add === null) {
628
+			$current_version_to_add = espresso_version();
629
+		}
630
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
631
+		// re-save
632
+		return update_option('espresso_db_update', $version_history);
633
+	}
634
+
635
+
636
+
637
+	/**
638
+	 * Detects if the current version indicated in the has existed in the list of
639
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
640
+	 *
641
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
642
+	 *                                  If not supplied, fetches it from the options table.
643
+	 *                                  Also, caches its result so later parts of the code can also know whether
644
+	 *                                  there's been an update or not. This way we can add the current version to
645
+	 *                                  espresso_db_update, but still know if this is a new install or not
646
+	 * @return int one of the constants on EE_System::req_type_
647
+	 */
648
+	public function detect_req_type($espresso_db_update = null)
649
+	{
650
+		if ($this->_req_type === null) {
651
+			$espresso_db_update          = ! empty($espresso_db_update)
652
+				? $espresso_db_update
653
+				: $this->fix_espresso_db_upgrade_option();
654
+			$this->_req_type             = EE_System::detect_req_type_given_activation_history(
655
+				$espresso_db_update,
656
+				'ee_espresso_activation', espresso_version()
657
+			);
658
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
659
+			$this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
660
+		}
661
+		return $this->_req_type;
662
+	}
663
+
664
+
665
+
666
+	/**
667
+	 * Returns whether or not there was a non-micro version change (ie, change in either
668
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
669
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
670
+	 *
671
+	 * @param $activation_history
672
+	 * @return bool
673
+	 */
674
+	private function _detect_major_version_change($activation_history)
675
+	{
676
+		$previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
677
+		$previous_version_parts = explode('.', $previous_version);
678
+		$current_version_parts  = explode('.', espresso_version());
679
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
680
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
681
+				   || $previous_version_parts[1] !== $current_version_parts[1]
682
+			   );
683
+	}
684
+
685
+
686
+
687
+	/**
688
+	 * Returns true if either the major or minor version of EE changed during this request.
689
+	 * 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
690
+	 *
691
+	 * @return bool
692
+	 */
693
+	public function is_major_version_change()
694
+	{
695
+		return $this->_major_version_change;
696
+	}
697
+
698
+
699
+
700
+	/**
701
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
702
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
703
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
704
+	 * just activated to (for core that will always be espresso_version())
705
+	 *
706
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
707
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
708
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
709
+	 *                                                 indicate that this plugin was just activated
710
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
711
+	 *                                                 espresso_version())
712
+	 * @return int one of the constants on EE_System::req_type_*
713
+	 */
714
+	public static function detect_req_type_given_activation_history(
715
+		$activation_history_for_addon,
716
+		$activation_indicator_option_name,
717
+		$version_to_upgrade_to
718
+	) {
719
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
720
+		if ($activation_history_for_addon) {
721
+			//it exists, so this isn't a completely new install
722
+			//check if this version already in that list of previously installed versions
723
+			if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
724
+				//it a version we haven't seen before
725
+				if ($version_is_higher === 1) {
726
+					$req_type = EE_System::req_type_upgrade;
727
+				} else {
728
+					$req_type = EE_System::req_type_downgrade;
729
+				}
730
+				delete_option($activation_indicator_option_name);
731
+			} else {
732
+				// its not an update. maybe a reactivation?
733
+				if (get_option($activation_indicator_option_name, false)) {
734
+					if ($version_is_higher === -1) {
735
+						$req_type = EE_System::req_type_downgrade;
736
+					} elseif ($version_is_higher === 0) {
737
+						//we've seen this version before, but it's an activation. must be a reactivation
738
+						$req_type = EE_System::req_type_reactivation;
739
+					} else {//$version_is_higher === 1
740
+						$req_type = EE_System::req_type_upgrade;
741
+					}
742
+					delete_option($activation_indicator_option_name);
743
+				} else {
744
+					//we've seen this version before and the activation indicate doesn't show it was just activated
745
+					if ($version_is_higher === -1) {
746
+						$req_type = EE_System::req_type_downgrade;
747
+					} elseif ($version_is_higher === 0) {
748
+						//we've seen this version before and it's not an activation. its normal request
749
+						$req_type = EE_System::req_type_normal;
750
+					} else {//$version_is_higher === 1
751
+						$req_type = EE_System::req_type_upgrade;
752
+					}
753
+				}
754
+			}
755
+		} else {
756
+			//brand new install
757
+			$req_type = EE_System::req_type_new_activation;
758
+			delete_option($activation_indicator_option_name);
759
+		}
760
+		return $req_type;
761
+	}
762
+
763
+
764
+
765
+	/**
766
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
767
+	 * the $activation_history_for_addon
768
+	 *
769
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
770
+	 *                                             sometimes containing 'unknown-date'
771
+	 * @param string $version_to_upgrade_to        (current version)
772
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
773
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
774
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
775
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
776
+	 */
777
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
778
+	{
779
+		//find the most recently-activated version
780
+		$most_recently_active_version =
781
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
782
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
783
+	}
784
+
785
+
786
+
787
+	/**
788
+	 * Gets the most recently active version listed in the activation history,
789
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
790
+	 *
791
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
792
+	 *                                   sometimes containing 'unknown-date'
793
+	 * @return string
794
+	 */
795
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
796
+	{
797
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
798
+		$most_recently_active_version            = '0.0.0.dev.000';
799
+		if (is_array($activation_history)) {
800
+			foreach ($activation_history as $version => $times_activated) {
801
+				//check there is a record of when this version was activated. Otherwise,
802
+				//mark it as unknown
803
+				if (! $times_activated) {
804
+					$times_activated = array('unknown-date');
805
+				}
806
+				if (is_string($times_activated)) {
807
+					$times_activated = array($times_activated);
808
+				}
809
+				foreach ($times_activated as $an_activation) {
810
+					if ($an_activation !== 'unknown-date'
811
+						&& $an_activation
812
+						   > $most_recently_active_version_activation) {
813
+						$most_recently_active_version            = $version;
814
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
815
+							? '1970-01-01 00:00:00'
816
+							: $an_activation;
817
+					}
818
+				}
819
+			}
820
+		}
821
+		return $most_recently_active_version;
822
+	}
823
+
824
+
825
+
826
+	/**
827
+	 * This redirects to the about EE page after activation
828
+	 *
829
+	 * @return void
830
+	 */
831
+	public function redirect_to_about_ee()
832
+	{
833
+		$notices = EE_Error::get_notices(false);
834
+		//if current user is an admin and it's not an ajax or rest request
835
+		if (
836
+			! isset($notices['errors'])
837
+			&& $this->request->isAdmin()
838
+			&& apply_filters(
839
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
840
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
841
+			)
842
+		) {
843
+			$query_params = array('page' => 'espresso_about');
844
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
845
+				$query_params['new_activation'] = true;
846
+			}
847
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
848
+				$query_params['reactivation'] = true;
849
+			}
850
+			$url = add_query_arg($query_params, admin_url('admin.php'));
851
+			wp_safe_redirect($url);
852
+			exit();
853
+		}
854
+	}
855
+
856
+
857
+
858
+	/**
859
+	 * load_core_configuration
860
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
861
+	 * which runs during the WP 'plugins_loaded' action at priority 5
862
+	 *
863
+	 * @return void
864
+	 * @throws ReflectionException
865
+	 */
866
+	public function load_core_configuration()
867
+	{
868
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
869
+		$this->loader->getShared('EE_Load_Textdomain');
870
+		//load textdomain
871
+		EE_Load_Textdomain::load_textdomain();
872
+		// load and setup EE_Config and EE_Network_Config
873
+		$config = $this->loader->getShared('EE_Config');
874
+		$this->loader->getShared('EE_Network_Config');
875
+		// setup autoloaders
876
+		// enable logging?
877
+		if ($config->admin->use_full_logging) {
878
+			$this->loader->getShared('EE_Log');
879
+		}
880
+		// check for activation errors
881
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
882
+		if ($activation_errors) {
883
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
884
+			update_option('ee_plugin_activation_errors', false);
885
+		}
886
+		// get model names
887
+		$this->_parse_model_names();
888
+		//load caf stuff a chance to play during the activation process too.
889
+		$this->_maybe_brew_regular();
890
+		// configure custom post type definitions
891
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
892
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
893
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
894
+	}
895
+
896
+
897
+
898
+	/**
899
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
900
+	 *
901
+	 * @return void
902
+	 * @throws ReflectionException
903
+	 */
904
+	private function _parse_model_names()
905
+	{
906
+		//get all the files in the EE_MODELS folder that end in .model.php
907
+		$models                 = glob(EE_MODELS . '*.model.php');
908
+		$model_names            = array();
909
+		$non_abstract_db_models = array();
910
+		foreach ($models as $model) {
911
+			// get model classname
912
+			$classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
913
+			$short_name      = str_replace('EEM_', '', $classname);
914
+			$reflectionClass = new ReflectionClass($classname);
915
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
916
+				$non_abstract_db_models[ $short_name ] = $classname;
917
+			}
918
+			$model_names[ $short_name ] = $classname;
919
+		}
920
+		$this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
921
+		$this->registry->non_abstract_db_models = apply_filters(
922
+			'FHEE__EE_System__parse_implemented_model_names',
923
+			$non_abstract_db_models
924
+		);
925
+	}
926
+
927
+
928
+	/**
929
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
930
+	 * that need to be setup before our EE_System launches.
931
+	 *
932
+	 * @return void
933
+	 * @throws DomainException
934
+	 * @throws InvalidArgumentException
935
+	 * @throws InvalidDataTypeException
936
+	 * @throws InvalidInterfaceException
937
+	 * @throws InvalidClassException
938
+	 * @throws InvalidFilePathException
939
+	 */
940
+	private function _maybe_brew_regular()
941
+	{
942
+		/** @var Domain $domain */
943
+		$domain = DomainFactory::getShared(
944
+			new FullyQualifiedName(
945
+				'EventEspresso\core\domain\Domain'
946
+			),
947
+			array(
948
+				new FilePath(EVENT_ESPRESSO_MAIN_FILE),
949
+				Version::fromString(espresso_version())
950
+			)
951
+		);
952
+		if ($domain->isCaffeinated()) {
953
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
954
+		}
955
+	}
956
+
957
+
958
+
959
+	/**
960
+	 * register_shortcodes_modules_and_widgets
961
+	 * generate lists of shortcodes and modules, then verify paths and classes
962
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
963
+	 * which runs during the WP 'plugins_loaded' action at priority 7
964
+	 *
965
+	 * @access public
966
+	 * @return void
967
+	 * @throws Exception
968
+	 */
969
+	public function register_shortcodes_modules_and_widgets()
970
+	{
971
+		try {
972
+			// load, register, and add shortcodes the new way
973
+			if ($this->request->isFrontend() || $this->request->isIframe()) {
974
+				$this->loader->getShared(
975
+					'EventEspresso\core\services\shortcodes\ShortcodesManager',
976
+					array(
977
+						// and the old way, but we'll put it under control of the new system
978
+						EE_Config::getLegacyShortcodesManager(),
979
+					)
980
+				);
981
+			}
982
+			if (function_exists('register_block_type')) {
983
+				$editor_block_collection = $this->loader->getShared(
984
+					'EventEspresso\core\domain\entities\editor\EditorBlockCollection'
985
+				);
986
+				// or the even newer newer new way
987
+				if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAdmin()) {
988
+					$this->loader->getShared(
989
+						'EventEspresso\core\services\editor\EditorBlockRegistrationManager',
990
+						array($editor_block_collection, $this->request)
991
+					);
992
+				}
993
+			}
994
+		} catch (Exception $exception) {
995
+			new ExceptionStackTraceDisplay($exception);
996
+		}
997
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
998
+		// check for addons using old hook point
999
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
1000
+			$this->_incompatible_addon_error();
1001
+		}
1002
+	}
1003
+
1004
+
1005
+
1006
+	/**
1007
+	 * _incompatible_addon_error
1008
+	 *
1009
+	 * @access public
1010
+	 * @return void
1011
+	 */
1012
+	private function _incompatible_addon_error()
1013
+	{
1014
+		// get array of classes hooking into here
1015
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
1016
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
1017
+		);
1018
+		if (! empty($class_names)) {
1019
+			$msg = __(
1020
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
1021
+				'event_espresso'
1022
+			);
1023
+			$msg .= '<ul>';
1024
+			foreach ($class_names as $class_name) {
1025
+				$msg .= '<li><b>Event Espresso - ' . str_replace(
1026
+						array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
1027
+						$class_name
1028
+					) . '</b></li>';
1029
+			}
1030
+			$msg .= '</ul>';
1031
+			$msg .= __(
1032
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1033
+				'event_espresso'
1034
+			);
1035
+			// save list of incompatible addons to wp-options for later use
1036
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
1037
+			if (is_admin()) {
1038
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1039
+			}
1040
+		}
1041
+	}
1042
+
1043
+
1044
+
1045
+	/**
1046
+	 * brew_espresso
1047
+	 * begins the process of setting hooks for initializing EE in the correct order
1048
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1049
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1050
+	 *
1051
+	 * @return void
1052
+	 */
1053
+	public function brew_espresso()
1054
+	{
1055
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1056
+		// load some final core systems
1057
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
1058
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1059
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
1060
+		add_action('init', array($this, 'load_controllers'), 7);
1061
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
1062
+		add_action('init', array($this, 'initialize'), 10);
1063
+		add_action('init', array($this, 'initialize_last'), 100);
1064
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1065
+			// pew pew pew
1066
+			$this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
1067
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1068
+		}
1069
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1070
+	}
1071
+
1072
+
1073
+
1074
+	/**
1075
+	 *    set_hooks_for_core
1076
+	 *
1077
+	 * @access public
1078
+	 * @return    void
1079
+	 * @throws EE_Error
1080
+	 */
1081
+	public function set_hooks_for_core()
1082
+	{
1083
+		$this->_deactivate_incompatible_addons();
1084
+		do_action('AHEE__EE_System__set_hooks_for_core');
1085
+		$this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1086
+		//caps need to be initialized on every request so that capability maps are set.
1087
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1088
+		$this->registry->CAP->init_caps();
1089
+	}
1090
+
1091
+
1092
+
1093
+	/**
1094
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1095
+	 * deactivates any addons considered incompatible with the current version of EE
1096
+	 */
1097
+	private function _deactivate_incompatible_addons()
1098
+	{
1099
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
1100
+		if (! empty($incompatible_addons)) {
1101
+			$active_plugins = get_option('active_plugins', array());
1102
+			foreach ($active_plugins as $active_plugin) {
1103
+				foreach ($incompatible_addons as $incompatible_addon) {
1104
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1105
+						unset($_GET['activate']);
1106
+						espresso_deactivate_plugin($active_plugin);
1107
+					}
1108
+				}
1109
+			}
1110
+		}
1111
+	}
1112
+
1113
+
1114
+
1115
+	/**
1116
+	 *    perform_activations_upgrades_and_migrations
1117
+	 *
1118
+	 * @access public
1119
+	 * @return    void
1120
+	 */
1121
+	public function perform_activations_upgrades_and_migrations()
1122
+	{
1123
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1124
+	}
1125
+
1126
+
1127
+	/**
1128
+	 * @return void
1129
+	 * @throws DomainException
1130
+	 */
1131
+	public function load_CPTs_and_session()
1132
+	{
1133
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1134
+		/** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */
1135
+		$register_custom_taxonomies = $this->loader->getShared(
1136
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
1137
+		);
1138
+		$register_custom_taxonomies->registerCustomTaxonomies();
1139
+		/** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
1140
+		$register_custom_post_types = $this->loader->getShared(
1141
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
1142
+		);
1143
+		$register_custom_post_types->registerCustomPostTypes();
1144
+		/** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */
1145
+		$register_custom_taxonomy_terms = $this->loader->getShared(
1146
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
1147
+		);
1148
+		$register_custom_taxonomy_terms->registerCustomTaxonomyTerms();
1149
+		// load legacy Custom Post Types and Taxonomies
1150
+		$this->loader->getShared('EE_Register_CPTs');
1151
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1152
+	}
1153
+
1154
+
1155
+
1156
+	/**
1157
+	 * load_controllers
1158
+	 * this is the best place to load any additional controllers that needs access to EE core.
1159
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1160
+	 * time
1161
+	 *
1162
+	 * @access public
1163
+	 * @return void
1164
+	 */
1165
+	public function load_controllers()
1166
+	{
1167
+		do_action('AHEE__EE_System__load_controllers__start');
1168
+		// let's get it started
1169
+		if (
1170
+			! $this->maintenance_mode->level()
1171
+			&& ($this->request->isFrontend() || $this->request->isFrontAjax())
1172
+		) {
1173
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1174
+			$this->loader->getShared('EE_Front_Controller');
1175
+		} elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1176
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1177
+			$this->loader->getShared('EE_Admin');
1178
+		}
1179
+		do_action('AHEE__EE_System__load_controllers__complete');
1180
+	}
1181
+
1182
+
1183
+
1184
+	/**
1185
+	 * core_loaded_and_ready
1186
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1187
+	 *
1188
+	 * @access public
1189
+	 * @return void
1190
+	 */
1191
+	public function core_loaded_and_ready()
1192
+	{
1193
+		if (
1194
+			$this->request->isAdmin()
1195
+			|| $this->request->isEeAjax()
1196
+			|| $this->request->isFrontend()
1197
+		) {
1198
+			$this->loader->getShared('EE_Session');
1199
+		}
1200
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1201
+		// load_espresso_template_tags
1202
+		if (
1203
+			is_readable(EE_PUBLIC . 'template_tags.php')
1204
+			&& (
1205
+				$this->request->isFrontend()
1206
+				|| $this->request->isAdmin()
1207
+				|| $this->request->isIframe()
1208
+				|| $this->request->isFeed()
1209
+			)
1210
+		) {
1211
+			require_once EE_PUBLIC . 'template_tags.php';
1212
+		}
1213
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1214
+		if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1215
+			$this->loader->getShared('EventEspresso\core\services\assets\Registry');
1216
+		}
1217
+	}
1218
+
1219
+
1220
+
1221
+	/**
1222
+	 * initialize
1223
+	 * this is the best place to begin initializing client code
1224
+	 *
1225
+	 * @access public
1226
+	 * @return void
1227
+	 */
1228
+	public function initialize()
1229
+	{
1230
+		do_action('AHEE__EE_System__initialize');
1231
+	}
1232
+
1233
+
1234
+
1235
+	/**
1236
+	 * initialize_last
1237
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1238
+	 * initialize has done so
1239
+	 *
1240
+	 * @access public
1241
+	 * @return void
1242
+	 */
1243
+	public function initialize_last()
1244
+	{
1245
+		do_action('AHEE__EE_System__initialize_last');
1246
+		/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1247
+		$rewrite_rules = $this->loader->getShared(
1248
+			'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1249
+		);
1250
+		$rewrite_rules->flushRewriteRules();
1251
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1252
+	}
1253
+
1254
+
1255
+
1256
+	/**
1257
+	 * @return void
1258
+	 * @throws EE_Error
1259
+	 */
1260
+	public function addEspressoToolbar()
1261
+	{
1262
+		$this->loader->getShared(
1263
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1264
+			array($this->registry->CAP)
1265
+		);
1266
+	}
1267
+
1268
+
1269
+
1270
+	/**
1271
+	 * do_not_cache
1272
+	 * sets no cache headers and defines no cache constants for WP plugins
1273
+	 *
1274
+	 * @access public
1275
+	 * @return void
1276
+	 */
1277
+	public static function do_not_cache()
1278
+	{
1279
+		// set no cache constants
1280
+		if (! defined('DONOTCACHEPAGE')) {
1281
+			define('DONOTCACHEPAGE', true);
1282
+		}
1283
+		if (! defined('DONOTCACHCEOBJECT')) {
1284
+			define('DONOTCACHCEOBJECT', true);
1285
+		}
1286
+		if (! defined('DONOTCACHEDB')) {
1287
+			define('DONOTCACHEDB', true);
1288
+		}
1289
+		// add no cache headers
1290
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1291
+		// plus a little extra for nginx and Google Chrome
1292
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1293
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1294
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1295
+	}
1296
+
1297
+
1298
+
1299
+	/**
1300
+	 *    extra_nocache_headers
1301
+	 *
1302
+	 * @access    public
1303
+	 * @param $headers
1304
+	 * @return    array
1305
+	 */
1306
+	public static function extra_nocache_headers($headers)
1307
+	{
1308
+		// for NGINX
1309
+		$headers['X-Accel-Expires'] = 0;
1310
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1311
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1312
+		return $headers;
1313
+	}
1314
+
1315
+
1316
+
1317
+	/**
1318
+	 *    nocache_headers
1319
+	 *
1320
+	 * @access    public
1321
+	 * @return    void
1322
+	 */
1323
+	public static function nocache_headers()
1324
+	{
1325
+		nocache_headers();
1326
+	}
1327
+
1328
+
1329
+
1330
+	/**
1331
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1332
+	 * never returned with the function.
1333
+	 *
1334
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1335
+	 * @return array
1336
+	 */
1337
+	public function remove_pages_from_wp_list_pages($exclude_array)
1338
+	{
1339
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1340
+	}
1341 1341
 
1342 1342
 
1343 1343
 
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 1 patch
Indentation   +912 added lines, -912 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use EventEspresso\core\services\request\ResponseInterface;
9 9
 
10 10
 if (! defined('EVENT_ESPRESSO_VERSION')) {
11
-    exit('No direct script access allowed');
11
+	exit('No direct script access allowed');
12 12
 }
13 13
 
14 14
 
@@ -25,917 +25,917 @@  discard block
 block discarded – undo
25 25
 class EE_Dependency_Map
26 26
 {
27 27
 
28
-    /**
29
-     * This means that the requested class dependency is not present in the dependency map
30
-     */
31
-    const not_registered = 0;
32
-
33
-    /**
34
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
35
-     */
36
-    const load_new_object = 1;
37
-
38
-    /**
39
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
40
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
41
-     */
42
-    const load_from_cache = 2;
43
-
44
-    /**
45
-     * When registering a dependency,
46
-     * this indicates to keep any existing dependencies that already exist,
47
-     * and simply discard any new dependencies declared in the incoming data
48
-     */
49
-    const KEEP_EXISTING_DEPENDENCIES = 0;
50
-
51
-    /**
52
-     * When registering a dependency,
53
-     * this indicates to overwrite any existing dependencies that already exist using the incoming data
54
-     */
55
-    const OVERWRITE_DEPENDENCIES = 1;
56
-
57
-
58
-
59
-    /**
60
-     * @type EE_Dependency_Map $_instance
61
-     */
62
-    protected static $_instance;
63
-
64
-    /**
65
-     * @type RequestInterface $request
66
-     */
67
-    protected $request;
68
-
69
-    /**
70
-     * @type LegacyRequestInterface $legacy_request
71
-     */
72
-    protected $legacy_request;
73
-
74
-    /**
75
-     * @type ResponseInterface $response
76
-     */
77
-    protected $response;
78
-
79
-    /**
80
-     * @type LoaderInterface $loader
81
-     */
82
-    protected $loader;
83
-
84
-    /**
85
-     * @type array $_dependency_map
86
-     */
87
-    protected $_dependency_map = array();
88
-
89
-    /**
90
-     * @type array $_class_loaders
91
-     */
92
-    protected $_class_loaders = array();
93
-
94
-    /**
95
-     * @type array $_aliases
96
-     */
97
-    protected $_aliases = array();
98
-
99
-
100
-
101
-    /**
102
-     * EE_Dependency_Map constructor.
103
-     */
104
-    protected function __construct()
105
-    {
106
-        // add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
107
-        do_action('EE_Dependency_Map____construct');
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * @throws InvalidDataTypeException
114
-     * @throws InvalidInterfaceException
115
-     * @throws InvalidArgumentException
116
-     */
117
-    public function initialize()
118
-    {
119
-        $this->_register_core_dependencies();
120
-        $this->_register_core_class_loaders();
121
-        $this->_register_core_aliases();
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * @singleton method used to instantiate class object
128
-     * @return EE_Dependency_Map
129
-     */
130
-    public static function instance() {
131
-        // check if class object is instantiated, and instantiated properly
132
-        if (! self::$_instance instanceof EE_Dependency_Map) {
133
-            self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/);
134
-        }
135
-        return self::$_instance;
136
-    }
137
-
138
-
139
-    /**
140
-     * @param RequestInterface $request
141
-     */
142
-    public function setRequest(RequestInterface $request)
143
-    {
144
-        $this->request = $request;
145
-    }
146
-
147
-
148
-    /**
149
-     * @param LegacyRequestInterface $legacy_request
150
-     */
151
-    public function setLegacyRequest(LegacyRequestInterface $legacy_request)
152
-    {
153
-        $this->legacy_request = $legacy_request;
154
-    }
155
-
156
-
157
-    /**
158
-     * @param ResponseInterface $response
159
-     */
160
-    public function setResponse(ResponseInterface $response)
161
-    {
162
-        $this->response = $response;
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * @param LoaderInterface $loader
169
-     */
170
-    public function setLoader(LoaderInterface $loader)
171
-    {
172
-        $this->loader = $loader;
173
-    }
174
-
175
-
176
-
177
-    /**
178
-     * @param string $class
179
-     * @param array  $dependencies
180
-     * @param int    $overwrite
181
-     * @return bool
182
-     */
183
-    public static function register_dependencies(
184
-        $class,
185
-        array $dependencies,
186
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
187
-    ) {
188
-        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
189
-    }
190
-
191
-
192
-
193
-    /**
194
-     * Assigns an array of class names and corresponding load sources (new or cached)
195
-     * to the class specified by the first parameter.
196
-     * IMPORTANT !!!
197
-     * The order of elements in the incoming $dependencies array MUST match
198
-     * the order of the constructor parameters for the class in question.
199
-     * This is especially important when overriding any existing dependencies that are registered.
200
-     * the third parameter controls whether any duplicate dependencies are overwritten or not.
201
-     *
202
-     * @param string $class
203
-     * @param array  $dependencies
204
-     * @param int    $overwrite
205
-     * @return bool
206
-     */
207
-    public function registerDependencies(
208
-        $class,
209
-        array $dependencies,
210
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
211
-    ) {
212
-        $class = trim($class, '\\');
213
-        $registered = false;
214
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
215
-            self::$_instance->_dependency_map[ $class ] = array();
216
-        }
217
-        // we need to make sure that any aliases used when registering a dependency
218
-        // get resolved to the correct class name
219
-        foreach ($dependencies as $dependency => $load_source) {
220
-            $alias = self::$_instance->get_alias($dependency);
221
-            if (
222
-                $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
223
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
224
-            ) {
225
-                unset($dependencies[$dependency]);
226
-                $dependencies[$alias] = $load_source;
227
-                $registered = true;
228
-            }
229
-        }
230
-        // now add our two lists of dependencies together.
231
-        // using Union (+=) favours the arrays in precedence from left to right,
232
-        // so $dependencies is NOT overwritten because it is listed first
233
-        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
234
-        // Union is way faster than array_merge() but should be used with caution...
235
-        // especially with numerically indexed arrays
236
-        $dependencies += self::$_instance->_dependency_map[ $class ];
237
-        // now we need to ensure that the resulting dependencies
238
-        // array only has the entries that are required for the class
239
-        // so first count how many dependencies were originally registered for the class
240
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
241
-        // if that count is non-zero (meaning dependencies were already registered)
242
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
243
-            // then truncate the  final array to match that count
244
-            ? array_slice($dependencies, 0, $dependency_count)
245
-            // otherwise just take the incoming array because nothing previously existed
246
-            : $dependencies;
247
-        return $registered;
248
-    }
249
-
250
-
251
-
252
-    /**
253
-     * @param string $class_name
254
-     * @param string $loader
255
-     * @return bool
256
-     * @throws DomainException
257
-     */
258
-    public static function register_class_loader($class_name, $loader = 'load_core')
259
-    {
260
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
261
-            throw new DomainException(
262
-                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
263
-            );
264
-        }
265
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
266
-        if (
267
-            ! is_callable($loader)
268
-            && (
269
-                strpos($loader, 'load_') !== 0
270
-                || ! method_exists('EE_Registry', $loader)
271
-            )
272
-        ) {
273
-            throw new DomainException(
274
-                sprintf(
275
-                    esc_html__(
276
-                        '"%1$s" is not a valid loader method on EE_Registry.',
277
-                        'event_espresso'
278
-                    ),
279
-                    $loader
280
-                )
281
-            );
282
-        }
283
-        $class_name = self::$_instance->get_alias($class_name);
284
-        if (! isset(self::$_instance->_class_loaders[$class_name])) {
285
-            self::$_instance->_class_loaders[$class_name] = $loader;
286
-            return true;
287
-        }
288
-        return false;
289
-    }
290
-
291
-
292
-
293
-    /**
294
-     * @return array
295
-     */
296
-    public function dependency_map()
297
-    {
298
-        return $this->_dependency_map;
299
-    }
300
-
301
-
302
-
303
-    /**
304
-     * returns TRUE if dependency map contains a listing for the provided class name
305
-     *
306
-     * @param string $class_name
307
-     * @return boolean
308
-     */
309
-    public function has($class_name = '')
310
-    {
311
-        // all legacy models have the same dependencies
312
-        if (strpos($class_name, 'EEM_') === 0) {
313
-            $class_name = 'LEGACY_MODELS';
314
-        }
315
-        return isset($this->_dependency_map[$class_name]) ? true : false;
316
-    }
317
-
318
-
319
-
320
-    /**
321
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
322
-     *
323
-     * @param string $class_name
324
-     * @param string $dependency
325
-     * @return bool
326
-     */
327
-    public function has_dependency_for_class($class_name = '', $dependency = '')
328
-    {
329
-        // all legacy models have the same dependencies
330
-        if (strpos($class_name, 'EEM_') === 0) {
331
-            $class_name = 'LEGACY_MODELS';
332
-        }
333
-        $dependency = $this->get_alias($dependency);
334
-        return isset($this->_dependency_map[$class_name][$dependency])
335
-            ? true
336
-            : false;
337
-    }
338
-
339
-
340
-
341
-    /**
342
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
343
-     *
344
-     * @param string $class_name
345
-     * @param string $dependency
346
-     * @return int
347
-     */
348
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
349
-    {
350
-        // all legacy models have the same dependencies
351
-        if (strpos($class_name, 'EEM_') === 0) {
352
-            $class_name = 'LEGACY_MODELS';
353
-        }
354
-        $dependency = $this->get_alias($dependency);
355
-        return $this->has_dependency_for_class($class_name, $dependency)
356
-            ? $this->_dependency_map[$class_name][$dependency]
357
-            : EE_Dependency_Map::not_registered;
358
-    }
359
-
360
-
361
-
362
-    /**
363
-     * @param string $class_name
364
-     * @return string | Closure
365
-     */
366
-    public function class_loader($class_name)
367
-    {
368
-        // all legacy models use load_model()
369
-        if(strpos($class_name, 'EEM_') === 0){
370
-            return 'load_model';
371
-        }
372
-        $class_name = $this->get_alias($class_name);
373
-        return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
374
-    }
375
-
376
-
377
-
378
-    /**
379
-     * @return array
380
-     */
381
-    public function class_loaders()
382
-    {
383
-        return $this->_class_loaders;
384
-    }
385
-
386
-
387
-
388
-    /**
389
-     * adds an alias for a classname
390
-     *
391
-     * @param string $class_name the class name that should be used (concrete class to replace interface)
392
-     * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
393
-     * @param string $for_class  the class that has the dependency (is type hinting for the interface)
394
-     */
395
-    public function add_alias($class_name, $alias, $for_class = '')
396
-    {
397
-        if ($for_class !== '') {
398
-            if (! isset($this->_aliases[$for_class])) {
399
-                $this->_aliases[$for_class] = array();
400
-            }
401
-            $this->_aliases[$for_class][$class_name] = $alias;
402
-        }
403
-        $this->_aliases[$class_name] = $alias;
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * returns TRUE if the provided class name has an alias
410
-     *
411
-     * @param string $class_name
412
-     * @param string $for_class
413
-     * @return bool
414
-     */
415
-    public function has_alias($class_name = '', $for_class = '')
416
-    {
417
-        return isset($this->_aliases[$for_class][$class_name])
418
-               || (
419
-                   isset($this->_aliases[$class_name])
420
-                   && ! is_array($this->_aliases[$class_name])
421
-               );
422
-    }
423
-
424
-
425
-
426
-    /**
427
-     * returns alias for class name if one exists, otherwise returns the original classname
428
-     * functions recursively, so that multiple aliases can be used to drill down to a classname
429
-     *  for example:
430
-     *      if the following two entries were added to the _aliases array:
431
-     *          array(
432
-     *              'interface_alias'           => 'some\namespace\interface'
433
-     *              'some\namespace\interface'  => 'some\namespace\classname'
434
-     *          )
435
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
436
-     *      to load an instance of 'some\namespace\classname'
437
-     *
438
-     * @param string $class_name
439
-     * @param string $for_class
440
-     * @return string
441
-     */
442
-    public function get_alias($class_name = '', $for_class = '')
443
-    {
444
-        if (! $this->has_alias($class_name, $for_class)) {
445
-            return $class_name;
446
-        }
447
-        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
448
-            return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
449
-        }
450
-        return $this->get_alias($this->_aliases[$class_name]);
451
-    }
452
-
453
-
454
-
455
-    /**
456
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
457
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
458
-     * This is done by using the following class constants:
459
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
460
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
461
-     */
462
-    protected function _register_core_dependencies()
463
-    {
464
-        $this->_dependency_map = array(
465
-            'EE_Request_Handler'                                                                                          => array(
466
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
467
-            ),
468
-            'EE_System'                                                                                                   => array(
469
-                'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
470
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
471
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
472
-                'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
473
-            ),
474
-            'EE_Session'                                                                                                  => array(
475
-                'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
476
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
477
-                'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
478
-                'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
479
-            ),
480
-            'EE_Cart'                                                                                                     => array(
481
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
482
-            ),
483
-            'EE_Front_Controller'                                                                                         => array(
484
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
485
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
486
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
487
-            ),
488
-            'EE_Messenger_Collection_Loader'                                                                              => array(
489
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
490
-            ),
491
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
492
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
493
-            ),
494
-            'EE_Message_Resource_Manager'                                                                                 => array(
495
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
496
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
497
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
498
-            ),
499
-            'EE_Message_Factory'                                                                                          => array(
500
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
501
-            ),
502
-            'EE_messages'                                                                                                 => array(
503
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
504
-            ),
505
-            'EE_Messages_Generator'                                                                                       => array(
506
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
507
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
508
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
509
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
510
-            ),
511
-            'EE_Messages_Processor'                                                                                       => array(
512
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
513
-            ),
514
-            'EE_Messages_Queue'                                                                                           => array(
515
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
516
-            ),
517
-            'EE_Messages_Template_Defaults'                                                                               => array(
518
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
519
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
520
-            ),
521
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
522
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
523
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
524
-            ),
525
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
526
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
527
-            ),
528
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
529
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
530
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
531
-            ),
532
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
533
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
534
-            ),
535
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
536
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
537
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
538
-            ),
539
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
540
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
541
-            ),
542
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
543
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
544
-            ),
545
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
546
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
547
-            ),
548
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
549
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
550
-            ),
551
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
552
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
553
-            ),
554
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
555
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
556
-            ),
557
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
558
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
559
-            ),
560
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
561
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
562
-            ),
563
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
564
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
565
-            ),
566
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
567
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
568
-            ),
569
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
570
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
571
-            ),
572
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
573
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
574
-            ),
575
-            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
576
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
577
-            ),
578
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
579
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
580
-            ),
581
-            'EE_Data_Migration_Class_Base'                                                                                => array(
582
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
583
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
584
-            ),
585
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
586
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
587
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
588
-            ),
589
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
590
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
591
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
592
-            ),
593
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
594
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
595
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
596
-            ),
597
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
598
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
599
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
600
-            ),
601
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
602
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
603
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
604
-            ),
605
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
606
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
607
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
608
-            ),
609
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
610
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
611
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
612
-            ),
613
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
614
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
615
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
616
-            ),
617
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
618
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
619
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
620
-            ),
621
-            'EventEspresso\core\services\assets\I18nRegistry' => array(
622
-                array(),
623
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
624
-            ),
625
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
626
-                'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
627
-                'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
628
-                'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache,
629
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
630
-            ),
631
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
632
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
633
-            ),
634
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
635
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
636
-            ),
637
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
638
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
639
-            ),
640
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
641
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
642
-            ),
643
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
644
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
645
-            ),
646
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
647
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
648
-            ),
649
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
650
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
651
-            ),
652
-            'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
653
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
654
-            ),
655
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'                  => array(
656
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
657
-            ),
658
-            'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
659
-                'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
660
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
661
-            ),
662
-            'EventEspresso\core\domain\values\EmailAddress'                              => array(
663
-                null,
664
-                'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
665
-            ),
666
-            'EventEspresso\core\services\orm\ModelFieldFactory' => array(
667
-                'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
668
-            ),
669
-            'LEGACY_MODELS'                                                   => array(
670
-                null,
671
-                'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
672
-            ),
673
-            'EE_Module_Request_Router'                                               => array(
674
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
675
-            ),
676
-            'EE_Registration_Processor'                                              => array(
677
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
678
-            ),
679
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array(
680
-                null,
681
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
682
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
683
-            ),
684
-            'EventEspresso\core\services\editor\EditorBlockRegistrationManager'      => array(
685
-                'EventEspresso\core\domain\entities\editor\EditorBlockCollection' => EE_Dependency_Map::load_from_cache,
686
-                'EE_Request'                                                      => EE_Dependency_Map::load_from_cache,
687
-                'EventEspresso\core\domain\Domain'                                => EE_Dependency_Map::load_from_cache,
688
-                'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache
689
-            ),
690
-            'EE_Admin_Transactions_List_Table' => array(
691
-                null,
692
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
693
-            ),
694
-            'EventEspresso\core\services\licensing\LicenseService' => array(
695
-                'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache,
696
-                'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache
697
-            ),
698
-            'EventEspresso\core\domain\services\pue\Stats' => array(
699
-                'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
700
-                'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache,
701
-                'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache
702
-            ),
703
-            'EventEspresso\core\domain\services\pue\Config' => array(
704
-                'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
705
-                'EE_Config' => EE_Dependency_Map::load_from_cache
706
-            ),
707
-            'EventEspresso\core\domain\services\pue\StatsGatherer' => array(
708
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
709
-                'EEM_Event' => EE_Dependency_Map::load_from_cache,
710
-                'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
711
-                'EEM_Ticket' => EE_Dependency_Map::load_from_cache,
712
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache,
713
-                'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
714
-                'EE_Config' => EE_Dependency_Map::load_from_cache
715
-            ),
716
-            'EventEspresso\core\domain\services\admin\ExitModal' => array(
717
-                'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache
718
-            ),
719
-            'EventEspresso\core\domain\services\admin\PluginUpsells' => array(
720
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
721
-            ),
722
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array(
723
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
724
-                'EE_Session'             => EE_Dependency_Map::load_from_cache,
725
-            ),
726
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array(
727
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
728
-            ),
729
-            'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array(
730
-                'EE_Core_Config' => EE_Dependency_Map::load_from_cache,
731
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
732
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
733
-                'EEM_Ticket' => EE_Dependency_Map::load_from_cache,
734
-                'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
735
-            ),
736
-            'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array(
737
-                'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
738
-            ),
739
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array(
740
-                'EE_Core_Config' => EE_Dependency_Map::load_from_cache,
741
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
742
-            ),
743
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'   => array(
744
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
745
-            ),
746
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'   => array(
747
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
748
-            ),
749
-            'EE_CPT_Strategy'   => array(
750
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
751
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
752
-            ),
753
-        );
754
-    }
755
-
756
-
757
-
758
-    /**
759
-     * Registers how core classes are loaded.
760
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
761
-     *        'EE_Request_Handler' => 'load_core'
762
-     *        'EE_Messages_Queue'  => 'load_lib'
763
-     *        'EEH_Debug_Tools'    => 'load_helper'
764
-     * or, if greater control is required, by providing a custom closure. For example:
765
-     *        'Some_Class' => function () {
766
-     *            return new Some_Class();
767
-     *        },
768
-     * This is required for instantiating dependencies
769
-     * where an interface has been type hinted in a class constructor. For example:
770
-     *        'Required_Interface' => function () {
771
-     *            return new A_Class_That_Implements_Required_Interface();
772
-     *        },
773
-     *
774
-     * @throws InvalidInterfaceException
775
-     * @throws InvalidDataTypeException
776
-     * @throws InvalidArgumentException
777
-     */
778
-    protected function _register_core_class_loaders()
779
-    {
780
-        //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
781
-        //be used in a closure.
782
-        $request = &$this->request;
783
-        $response = &$this->response;
784
-        $legacy_request = &$this->legacy_request;
785
-        // $loader = &$this->loader;
786
-        $this->_class_loaders = array(
787
-            //load_core
788
-            'EE_Capabilities'          => 'load_core',
789
-            'EE_Encryption'            => 'load_core',
790
-            'EE_Front_Controller'      => 'load_core',
791
-            'EE_Module_Request_Router' => 'load_core',
792
-            'EE_Registry'              => 'load_core',
793
-            'EE_Request'               => function () use (&$legacy_request) {
794
-                return $legacy_request;
795
-            },
796
-            'EventEspresso\core\services\request\Request' => function () use (&$request) {
797
-                return $request;
798
-            },
799
-            'EventEspresso\core\services\request\Response' => function () use (&$response) {
800
-                return $response;
801
-            },
802
-            'EE_Request_Handler'       => 'load_core',
803
-            'EE_Session'               => 'load_core',
804
-            'EE_Cron_Tasks'            => 'load_core',
805
-            'EE_System'                => 'load_core',
806
-            'EE_Maintenance_Mode'      => 'load_core',
807
-            'EE_Register_CPTs'         => 'load_core',
808
-            'EE_Admin'                 => 'load_core',
809
-            'EE_CPT_Strategy'          => 'load_core',
810
-            //load_lib
811
-            'EE_Message_Resource_Manager'          => 'load_lib',
812
-            'EE_Message_Type_Collection'           => 'load_lib',
813
-            'EE_Message_Type_Collection_Loader'    => 'load_lib',
814
-            'EE_Messenger_Collection'              => 'load_lib',
815
-            'EE_Messenger_Collection_Loader'       => 'load_lib',
816
-            'EE_Messages_Processor'                => 'load_lib',
817
-            'EE_Message_Repository'                => 'load_lib',
818
-            'EE_Messages_Queue'                    => 'load_lib',
819
-            'EE_Messages_Data_Handler_Collection'  => 'load_lib',
820
-            'EE_Message_Template_Group_Collection' => 'load_lib',
821
-            'EE_Payment_Method_Manager'            => 'load_lib',
822
-            'EE_Messages_Generator'                => function () {
823
-                return EE_Registry::instance()->load_lib(
824
-                    'Messages_Generator',
825
-                    array(),
826
-                    false,
827
-                    false
828
-                );
829
-            },
830
-            'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
831
-                return EE_Registry::instance()->load_lib(
832
-                    'Messages_Template_Defaults',
833
-                    $arguments,
834
-                    false,
835
-                    false
836
-                );
837
-            },
838
-            //load_helper
839
-            'EEH_Parse_Shortcodes'                 => function () {
840
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
841
-                    return new EEH_Parse_Shortcodes();
842
-                }
843
-                return null;
844
-            },
845
-            'EE_Template_Config'                   => function () {
846
-                return EE_Config::instance()->template_settings;
847
-            },
848
-            'EE_Currency_Config'                   => function () {
849
-                return EE_Config::instance()->currency;
850
-            },
851
-            'EE_Registration_Config'                   => function () {
852
-                return EE_Config::instance()->registration;
853
-            },
854
-            'EE_Core_Config'                   => function () {
855
-                return EE_Config::instance()->core;
856
-            },
857
-            'EventEspresso\core\services\loaders\Loader' => function () {
858
-                return LoaderFactory::getLoader();
859
-            },
860
-            'EE_Network_Config' => function() {
861
-                return EE_Network_Config::instance();
862
-            },
863
-            'EE_Config' => function () {
864
-                return EE_Config::instance();
865
-            }
866
-        );
867
-    }
868
-
869
-
870
-
871
-    /**
872
-     * can be used for supplying alternate names for classes,
873
-     * or for connecting interface names to instantiable classes
874
-     */
875
-    protected function _register_core_aliases()
876
-    {
877
-        $this->_aliases = array(
878
-            'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
879
-            'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
880
-            'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
881
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
882
-            'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
883
-            'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
884
-            'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
885
-            'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
886
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
887
-            'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
888
-            'CreateRegCodeCommandHandler'                                                  => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
889
-            'CreateRegUrlLinkCommandHandler'                                               => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
890
-            'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
891
-            'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
892
-            'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
893
-            'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
894
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
895
-            'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
896
-            'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
897
-            'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
898
-            'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
899
-            'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
900
-            'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
901
-            'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
902
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
903
-            'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
904
-            'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
905
-            'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
906
-            'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
907
-            'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
908
-            'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
909
-            'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
910
-            'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
911
-            'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
912
-            'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
913
-            'NoticesContainerInterface'                                           => 'EventEspresso\core\services\notices\NoticesContainerInterface',
914
-            'EventEspresso\core\services\notices\NoticesContainerInterface'       => 'EventEspresso\core\services\notices\NoticesContainer',
915
-            'EventEspresso\core\services\request\RequestInterface'                => 'EventEspresso\core\services\request\Request',
916
-            'EventEspresso\core\services\request\ResponseInterface'               => 'EventEspresso\core\services\request\Response',
917
-            'EventEspresso\core\domain\DomainInterface'                           => 'EventEspresso\core\domain\Domain',
918
-        );
919
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
920
-            $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices';
921
-        }
922
-    }
923
-
924
-
925
-
926
-    /**
927
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
928
-     * request Primarily used by unit tests.
929
-     *
930
-     * @throws InvalidDataTypeException
931
-     * @throws InvalidInterfaceException
932
-     * @throws InvalidArgumentException
933
-     */
934
-    public function reset()
935
-    {
936
-        $this->_register_core_class_loaders();
937
-        $this->_register_core_dependencies();
938
-    }
28
+	/**
29
+	 * This means that the requested class dependency is not present in the dependency map
30
+	 */
31
+	const not_registered = 0;
32
+
33
+	/**
34
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
35
+	 */
36
+	const load_new_object = 1;
37
+
38
+	/**
39
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
40
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
41
+	 */
42
+	const load_from_cache = 2;
43
+
44
+	/**
45
+	 * When registering a dependency,
46
+	 * this indicates to keep any existing dependencies that already exist,
47
+	 * and simply discard any new dependencies declared in the incoming data
48
+	 */
49
+	const KEEP_EXISTING_DEPENDENCIES = 0;
50
+
51
+	/**
52
+	 * When registering a dependency,
53
+	 * this indicates to overwrite any existing dependencies that already exist using the incoming data
54
+	 */
55
+	const OVERWRITE_DEPENDENCIES = 1;
56
+
57
+
58
+
59
+	/**
60
+	 * @type EE_Dependency_Map $_instance
61
+	 */
62
+	protected static $_instance;
63
+
64
+	/**
65
+	 * @type RequestInterface $request
66
+	 */
67
+	protected $request;
68
+
69
+	/**
70
+	 * @type LegacyRequestInterface $legacy_request
71
+	 */
72
+	protected $legacy_request;
73
+
74
+	/**
75
+	 * @type ResponseInterface $response
76
+	 */
77
+	protected $response;
78
+
79
+	/**
80
+	 * @type LoaderInterface $loader
81
+	 */
82
+	protected $loader;
83
+
84
+	/**
85
+	 * @type array $_dependency_map
86
+	 */
87
+	protected $_dependency_map = array();
88
+
89
+	/**
90
+	 * @type array $_class_loaders
91
+	 */
92
+	protected $_class_loaders = array();
93
+
94
+	/**
95
+	 * @type array $_aliases
96
+	 */
97
+	protected $_aliases = array();
98
+
99
+
100
+
101
+	/**
102
+	 * EE_Dependency_Map constructor.
103
+	 */
104
+	protected function __construct()
105
+	{
106
+		// add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
107
+		do_action('EE_Dependency_Map____construct');
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * @throws InvalidDataTypeException
114
+	 * @throws InvalidInterfaceException
115
+	 * @throws InvalidArgumentException
116
+	 */
117
+	public function initialize()
118
+	{
119
+		$this->_register_core_dependencies();
120
+		$this->_register_core_class_loaders();
121
+		$this->_register_core_aliases();
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * @singleton method used to instantiate class object
128
+	 * @return EE_Dependency_Map
129
+	 */
130
+	public static function instance() {
131
+		// check if class object is instantiated, and instantiated properly
132
+		if (! self::$_instance instanceof EE_Dependency_Map) {
133
+			self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/);
134
+		}
135
+		return self::$_instance;
136
+	}
137
+
138
+
139
+	/**
140
+	 * @param RequestInterface $request
141
+	 */
142
+	public function setRequest(RequestInterface $request)
143
+	{
144
+		$this->request = $request;
145
+	}
146
+
147
+
148
+	/**
149
+	 * @param LegacyRequestInterface $legacy_request
150
+	 */
151
+	public function setLegacyRequest(LegacyRequestInterface $legacy_request)
152
+	{
153
+		$this->legacy_request = $legacy_request;
154
+	}
155
+
156
+
157
+	/**
158
+	 * @param ResponseInterface $response
159
+	 */
160
+	public function setResponse(ResponseInterface $response)
161
+	{
162
+		$this->response = $response;
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * @param LoaderInterface $loader
169
+	 */
170
+	public function setLoader(LoaderInterface $loader)
171
+	{
172
+		$this->loader = $loader;
173
+	}
174
+
175
+
176
+
177
+	/**
178
+	 * @param string $class
179
+	 * @param array  $dependencies
180
+	 * @param int    $overwrite
181
+	 * @return bool
182
+	 */
183
+	public static function register_dependencies(
184
+		$class,
185
+		array $dependencies,
186
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
187
+	) {
188
+		return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
189
+	}
190
+
191
+
192
+
193
+	/**
194
+	 * Assigns an array of class names and corresponding load sources (new or cached)
195
+	 * to the class specified by the first parameter.
196
+	 * IMPORTANT !!!
197
+	 * The order of elements in the incoming $dependencies array MUST match
198
+	 * the order of the constructor parameters for the class in question.
199
+	 * This is especially important when overriding any existing dependencies that are registered.
200
+	 * the third parameter controls whether any duplicate dependencies are overwritten or not.
201
+	 *
202
+	 * @param string $class
203
+	 * @param array  $dependencies
204
+	 * @param int    $overwrite
205
+	 * @return bool
206
+	 */
207
+	public function registerDependencies(
208
+		$class,
209
+		array $dependencies,
210
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
211
+	) {
212
+		$class = trim($class, '\\');
213
+		$registered = false;
214
+		if (empty(self::$_instance->_dependency_map[ $class ])) {
215
+			self::$_instance->_dependency_map[ $class ] = array();
216
+		}
217
+		// we need to make sure that any aliases used when registering a dependency
218
+		// get resolved to the correct class name
219
+		foreach ($dependencies as $dependency => $load_source) {
220
+			$alias = self::$_instance->get_alias($dependency);
221
+			if (
222
+				$overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
223
+				|| ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
224
+			) {
225
+				unset($dependencies[$dependency]);
226
+				$dependencies[$alias] = $load_source;
227
+				$registered = true;
228
+			}
229
+		}
230
+		// now add our two lists of dependencies together.
231
+		// using Union (+=) favours the arrays in precedence from left to right,
232
+		// so $dependencies is NOT overwritten because it is listed first
233
+		// ie: with A = B + C, entries in B take precedence over duplicate entries in C
234
+		// Union is way faster than array_merge() but should be used with caution...
235
+		// especially with numerically indexed arrays
236
+		$dependencies += self::$_instance->_dependency_map[ $class ];
237
+		// now we need to ensure that the resulting dependencies
238
+		// array only has the entries that are required for the class
239
+		// so first count how many dependencies were originally registered for the class
240
+		$dependency_count = count(self::$_instance->_dependency_map[ $class ]);
241
+		// if that count is non-zero (meaning dependencies were already registered)
242
+		self::$_instance->_dependency_map[ $class ] = $dependency_count
243
+			// then truncate the  final array to match that count
244
+			? array_slice($dependencies, 0, $dependency_count)
245
+			// otherwise just take the incoming array because nothing previously existed
246
+			: $dependencies;
247
+		return $registered;
248
+	}
249
+
250
+
251
+
252
+	/**
253
+	 * @param string $class_name
254
+	 * @param string $loader
255
+	 * @return bool
256
+	 * @throws DomainException
257
+	 */
258
+	public static function register_class_loader($class_name, $loader = 'load_core')
259
+	{
260
+		if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
261
+			throw new DomainException(
262
+				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
263
+			);
264
+		}
265
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
266
+		if (
267
+			! is_callable($loader)
268
+			&& (
269
+				strpos($loader, 'load_') !== 0
270
+				|| ! method_exists('EE_Registry', $loader)
271
+			)
272
+		) {
273
+			throw new DomainException(
274
+				sprintf(
275
+					esc_html__(
276
+						'"%1$s" is not a valid loader method on EE_Registry.',
277
+						'event_espresso'
278
+					),
279
+					$loader
280
+				)
281
+			);
282
+		}
283
+		$class_name = self::$_instance->get_alias($class_name);
284
+		if (! isset(self::$_instance->_class_loaders[$class_name])) {
285
+			self::$_instance->_class_loaders[$class_name] = $loader;
286
+			return true;
287
+		}
288
+		return false;
289
+	}
290
+
291
+
292
+
293
+	/**
294
+	 * @return array
295
+	 */
296
+	public function dependency_map()
297
+	{
298
+		return $this->_dependency_map;
299
+	}
300
+
301
+
302
+
303
+	/**
304
+	 * returns TRUE if dependency map contains a listing for the provided class name
305
+	 *
306
+	 * @param string $class_name
307
+	 * @return boolean
308
+	 */
309
+	public function has($class_name = '')
310
+	{
311
+		// all legacy models have the same dependencies
312
+		if (strpos($class_name, 'EEM_') === 0) {
313
+			$class_name = 'LEGACY_MODELS';
314
+		}
315
+		return isset($this->_dependency_map[$class_name]) ? true : false;
316
+	}
317
+
318
+
319
+
320
+	/**
321
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
322
+	 *
323
+	 * @param string $class_name
324
+	 * @param string $dependency
325
+	 * @return bool
326
+	 */
327
+	public function has_dependency_for_class($class_name = '', $dependency = '')
328
+	{
329
+		// all legacy models have the same dependencies
330
+		if (strpos($class_name, 'EEM_') === 0) {
331
+			$class_name = 'LEGACY_MODELS';
332
+		}
333
+		$dependency = $this->get_alias($dependency);
334
+		return isset($this->_dependency_map[$class_name][$dependency])
335
+			? true
336
+			: false;
337
+	}
338
+
339
+
340
+
341
+	/**
342
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
343
+	 *
344
+	 * @param string $class_name
345
+	 * @param string $dependency
346
+	 * @return int
347
+	 */
348
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
349
+	{
350
+		// all legacy models have the same dependencies
351
+		if (strpos($class_name, 'EEM_') === 0) {
352
+			$class_name = 'LEGACY_MODELS';
353
+		}
354
+		$dependency = $this->get_alias($dependency);
355
+		return $this->has_dependency_for_class($class_name, $dependency)
356
+			? $this->_dependency_map[$class_name][$dependency]
357
+			: EE_Dependency_Map::not_registered;
358
+	}
359
+
360
+
361
+
362
+	/**
363
+	 * @param string $class_name
364
+	 * @return string | Closure
365
+	 */
366
+	public function class_loader($class_name)
367
+	{
368
+		// all legacy models use load_model()
369
+		if(strpos($class_name, 'EEM_') === 0){
370
+			return 'load_model';
371
+		}
372
+		$class_name = $this->get_alias($class_name);
373
+		return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
374
+	}
375
+
376
+
377
+
378
+	/**
379
+	 * @return array
380
+	 */
381
+	public function class_loaders()
382
+	{
383
+		return $this->_class_loaders;
384
+	}
385
+
386
+
387
+
388
+	/**
389
+	 * adds an alias for a classname
390
+	 *
391
+	 * @param string $class_name the class name that should be used (concrete class to replace interface)
392
+	 * @param string $alias      the class name that would be type hinted for (abstract parent or interface)
393
+	 * @param string $for_class  the class that has the dependency (is type hinting for the interface)
394
+	 */
395
+	public function add_alias($class_name, $alias, $for_class = '')
396
+	{
397
+		if ($for_class !== '') {
398
+			if (! isset($this->_aliases[$for_class])) {
399
+				$this->_aliases[$for_class] = array();
400
+			}
401
+			$this->_aliases[$for_class][$class_name] = $alias;
402
+		}
403
+		$this->_aliases[$class_name] = $alias;
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * returns TRUE if the provided class name has an alias
410
+	 *
411
+	 * @param string $class_name
412
+	 * @param string $for_class
413
+	 * @return bool
414
+	 */
415
+	public function has_alias($class_name = '', $for_class = '')
416
+	{
417
+		return isset($this->_aliases[$for_class][$class_name])
418
+			   || (
419
+				   isset($this->_aliases[$class_name])
420
+				   && ! is_array($this->_aliases[$class_name])
421
+			   );
422
+	}
423
+
424
+
425
+
426
+	/**
427
+	 * returns alias for class name if one exists, otherwise returns the original classname
428
+	 * functions recursively, so that multiple aliases can be used to drill down to a classname
429
+	 *  for example:
430
+	 *      if the following two entries were added to the _aliases array:
431
+	 *          array(
432
+	 *              'interface_alias'           => 'some\namespace\interface'
433
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
434
+	 *          )
435
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
436
+	 *      to load an instance of 'some\namespace\classname'
437
+	 *
438
+	 * @param string $class_name
439
+	 * @param string $for_class
440
+	 * @return string
441
+	 */
442
+	public function get_alias($class_name = '', $for_class = '')
443
+	{
444
+		if (! $this->has_alias($class_name, $for_class)) {
445
+			return $class_name;
446
+		}
447
+		if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) {
448
+			return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class);
449
+		}
450
+		return $this->get_alias($this->_aliases[$class_name]);
451
+	}
452
+
453
+
454
+
455
+	/**
456
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
457
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
458
+	 * This is done by using the following class constants:
459
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
460
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
461
+	 */
462
+	protected function _register_core_dependencies()
463
+	{
464
+		$this->_dependency_map = array(
465
+			'EE_Request_Handler'                                                                                          => array(
466
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
467
+			),
468
+			'EE_System'                                                                                                   => array(
469
+				'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
470
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
471
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
472
+				'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
473
+			),
474
+			'EE_Session'                                                                                                  => array(
475
+				'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
476
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
477
+				'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
478
+				'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
479
+			),
480
+			'EE_Cart'                                                                                                     => array(
481
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
482
+			),
483
+			'EE_Front_Controller'                                                                                         => array(
484
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
485
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
486
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
487
+			),
488
+			'EE_Messenger_Collection_Loader'                                                                              => array(
489
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
490
+			),
491
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
492
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
493
+			),
494
+			'EE_Message_Resource_Manager'                                                                                 => array(
495
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
496
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
497
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
498
+			),
499
+			'EE_Message_Factory'                                                                                          => array(
500
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
501
+			),
502
+			'EE_messages'                                                                                                 => array(
503
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
504
+			),
505
+			'EE_Messages_Generator'                                                                                       => array(
506
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
507
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
508
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
509
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
510
+			),
511
+			'EE_Messages_Processor'                                                                                       => array(
512
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
513
+			),
514
+			'EE_Messages_Queue'                                                                                           => array(
515
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
516
+			),
517
+			'EE_Messages_Template_Defaults'                                                                               => array(
518
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
519
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
520
+			),
521
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
522
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
523
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
524
+			),
525
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
526
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
527
+			),
528
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
529
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
530
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
531
+			),
532
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
533
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
534
+			),
535
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
536
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
537
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
538
+			),
539
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
540
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
541
+			),
542
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
543
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
544
+			),
545
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
546
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
547
+			),
548
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
549
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
550
+			),
551
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
552
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
553
+			),
554
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
555
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
556
+			),
557
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
558
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
559
+			),
560
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
561
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
562
+			),
563
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
564
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
565
+			),
566
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
567
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
568
+			),
569
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
570
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
571
+			),
572
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
573
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
574
+			),
575
+			'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
576
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
577
+			),
578
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
579
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
580
+			),
581
+			'EE_Data_Migration_Class_Base'                                                                                => array(
582
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
583
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
584
+			),
585
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
586
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
587
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
588
+			),
589
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
590
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
591
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
592
+			),
593
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
594
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
595
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
596
+			),
597
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
598
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
599
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
600
+			),
601
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
602
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
603
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
604
+			),
605
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
606
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
607
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
608
+			),
609
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
610
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
611
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
612
+			),
613
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
614
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
615
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
616
+			),
617
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
618
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
619
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
620
+			),
621
+			'EventEspresso\core\services\assets\I18nRegistry' => array(
622
+				array(),
623
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
624
+			),
625
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
626
+				'EE_Template_Config' => EE_Dependency_Map::load_from_cache,
627
+				'EE_Currency_Config' => EE_Dependency_Map::load_from_cache,
628
+				'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache,
629
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
630
+			),
631
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
632
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
633
+			),
634
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
635
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
636
+			),
637
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
638
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
639
+			),
640
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
641
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
642
+			),
643
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
644
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
645
+			),
646
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
647
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
648
+			),
649
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
650
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
651
+			),
652
+			'EventEspresso\core\services\cache\BasicCacheManager'                        => array(
653
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
654
+			),
655
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'                  => array(
656
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
657
+			),
658
+			'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array(
659
+				'EE_Registration_Config'                                  => EE_Dependency_Map::load_from_cache,
660
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
661
+			),
662
+			'EventEspresso\core\domain\values\EmailAddress'                              => array(
663
+				null,
664
+				'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
665
+			),
666
+			'EventEspresso\core\services\orm\ModelFieldFactory' => array(
667
+				'EventEspresso\core\services\loaders\Loader'              => EE_Dependency_Map::load_from_cache,
668
+			),
669
+			'LEGACY_MODELS'                                                   => array(
670
+				null,
671
+				'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
672
+			),
673
+			'EE_Module_Request_Router'                                               => array(
674
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
675
+			),
676
+			'EE_Registration_Processor'                                              => array(
677
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
678
+			),
679
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array(
680
+				null,
681
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
682
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
683
+			),
684
+			'EventEspresso\core\services\editor\EditorBlockRegistrationManager'      => array(
685
+				'EventEspresso\core\domain\entities\editor\EditorBlockCollection' => EE_Dependency_Map::load_from_cache,
686
+				'EE_Request'                                                      => EE_Dependency_Map::load_from_cache,
687
+				'EventEspresso\core\domain\Domain'                                => EE_Dependency_Map::load_from_cache,
688
+				'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache
689
+			),
690
+			'EE_Admin_Transactions_List_Table' => array(
691
+				null,
692
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
693
+			),
694
+			'EventEspresso\core\services\licensing\LicenseService' => array(
695
+				'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache,
696
+				'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache
697
+			),
698
+			'EventEspresso\core\domain\services\pue\Stats' => array(
699
+				'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
700
+				'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache,
701
+				'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache
702
+			),
703
+			'EventEspresso\core\domain\services\pue\Config' => array(
704
+				'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
705
+				'EE_Config' => EE_Dependency_Map::load_from_cache
706
+			),
707
+			'EventEspresso\core\domain\services\pue\StatsGatherer' => array(
708
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
709
+				'EEM_Event' => EE_Dependency_Map::load_from_cache,
710
+				'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
711
+				'EEM_Ticket' => EE_Dependency_Map::load_from_cache,
712
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache,
713
+				'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
714
+				'EE_Config' => EE_Dependency_Map::load_from_cache
715
+			),
716
+			'EventEspresso\core\domain\services\admin\ExitModal' => array(
717
+				'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache
718
+			),
719
+			'EventEspresso\core\domain\services\admin\PluginUpsells' => array(
720
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache
721
+			),
722
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array(
723
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
724
+				'EE_Session'             => EE_Dependency_Map::load_from_cache,
725
+			),
726
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array(
727
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
728
+			),
729
+			'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array(
730
+				'EE_Core_Config' => EE_Dependency_Map::load_from_cache,
731
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
732
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
733
+				'EEM_Ticket' => EE_Dependency_Map::load_from_cache,
734
+				'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
735
+			),
736
+			'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array(
737
+				'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
738
+			),
739
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array(
740
+				'EE_Core_Config' => EE_Dependency_Map::load_from_cache,
741
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
742
+			),
743
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'   => array(
744
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
745
+			),
746
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'   => array(
747
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
748
+			),
749
+			'EE_CPT_Strategy'   => array(
750
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
751
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
752
+			),
753
+		);
754
+	}
755
+
756
+
757
+
758
+	/**
759
+	 * Registers how core classes are loaded.
760
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
761
+	 *        'EE_Request_Handler' => 'load_core'
762
+	 *        'EE_Messages_Queue'  => 'load_lib'
763
+	 *        'EEH_Debug_Tools'    => 'load_helper'
764
+	 * or, if greater control is required, by providing a custom closure. For example:
765
+	 *        'Some_Class' => function () {
766
+	 *            return new Some_Class();
767
+	 *        },
768
+	 * This is required for instantiating dependencies
769
+	 * where an interface has been type hinted in a class constructor. For example:
770
+	 *        'Required_Interface' => function () {
771
+	 *            return new A_Class_That_Implements_Required_Interface();
772
+	 *        },
773
+	 *
774
+	 * @throws InvalidInterfaceException
775
+	 * @throws InvalidDataTypeException
776
+	 * @throws InvalidArgumentException
777
+	 */
778
+	protected function _register_core_class_loaders()
779
+	{
780
+		//for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
781
+		//be used in a closure.
782
+		$request = &$this->request;
783
+		$response = &$this->response;
784
+		$legacy_request = &$this->legacy_request;
785
+		// $loader = &$this->loader;
786
+		$this->_class_loaders = array(
787
+			//load_core
788
+			'EE_Capabilities'          => 'load_core',
789
+			'EE_Encryption'            => 'load_core',
790
+			'EE_Front_Controller'      => 'load_core',
791
+			'EE_Module_Request_Router' => 'load_core',
792
+			'EE_Registry'              => 'load_core',
793
+			'EE_Request'               => function () use (&$legacy_request) {
794
+				return $legacy_request;
795
+			},
796
+			'EventEspresso\core\services\request\Request' => function () use (&$request) {
797
+				return $request;
798
+			},
799
+			'EventEspresso\core\services\request\Response' => function () use (&$response) {
800
+				return $response;
801
+			},
802
+			'EE_Request_Handler'       => 'load_core',
803
+			'EE_Session'               => 'load_core',
804
+			'EE_Cron_Tasks'            => 'load_core',
805
+			'EE_System'                => 'load_core',
806
+			'EE_Maintenance_Mode'      => 'load_core',
807
+			'EE_Register_CPTs'         => 'load_core',
808
+			'EE_Admin'                 => 'load_core',
809
+			'EE_CPT_Strategy'          => 'load_core',
810
+			//load_lib
811
+			'EE_Message_Resource_Manager'          => 'load_lib',
812
+			'EE_Message_Type_Collection'           => 'load_lib',
813
+			'EE_Message_Type_Collection_Loader'    => 'load_lib',
814
+			'EE_Messenger_Collection'              => 'load_lib',
815
+			'EE_Messenger_Collection_Loader'       => 'load_lib',
816
+			'EE_Messages_Processor'                => 'load_lib',
817
+			'EE_Message_Repository'                => 'load_lib',
818
+			'EE_Messages_Queue'                    => 'load_lib',
819
+			'EE_Messages_Data_Handler_Collection'  => 'load_lib',
820
+			'EE_Message_Template_Group_Collection' => 'load_lib',
821
+			'EE_Payment_Method_Manager'            => 'load_lib',
822
+			'EE_Messages_Generator'                => function () {
823
+				return EE_Registry::instance()->load_lib(
824
+					'Messages_Generator',
825
+					array(),
826
+					false,
827
+					false
828
+				);
829
+			},
830
+			'EE_Messages_Template_Defaults'        => function ($arguments = array()) {
831
+				return EE_Registry::instance()->load_lib(
832
+					'Messages_Template_Defaults',
833
+					$arguments,
834
+					false,
835
+					false
836
+				);
837
+			},
838
+			//load_helper
839
+			'EEH_Parse_Shortcodes'                 => function () {
840
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
841
+					return new EEH_Parse_Shortcodes();
842
+				}
843
+				return null;
844
+			},
845
+			'EE_Template_Config'                   => function () {
846
+				return EE_Config::instance()->template_settings;
847
+			},
848
+			'EE_Currency_Config'                   => function () {
849
+				return EE_Config::instance()->currency;
850
+			},
851
+			'EE_Registration_Config'                   => function () {
852
+				return EE_Config::instance()->registration;
853
+			},
854
+			'EE_Core_Config'                   => function () {
855
+				return EE_Config::instance()->core;
856
+			},
857
+			'EventEspresso\core\services\loaders\Loader' => function () {
858
+				return LoaderFactory::getLoader();
859
+			},
860
+			'EE_Network_Config' => function() {
861
+				return EE_Network_Config::instance();
862
+			},
863
+			'EE_Config' => function () {
864
+				return EE_Config::instance();
865
+			}
866
+		);
867
+	}
868
+
869
+
870
+
871
+	/**
872
+	 * can be used for supplying alternate names for classes,
873
+	 * or for connecting interface names to instantiable classes
874
+	 */
875
+	protected function _register_core_aliases()
876
+	{
877
+		$this->_aliases = array(
878
+			'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
879
+			'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
880
+			'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
881
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
882
+			'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
883
+			'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
884
+			'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
885
+			'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
886
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
887
+			'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
888
+			'CreateRegCodeCommandHandler'                                                  => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand',
889
+			'CreateRegUrlLinkCommandHandler'                                               => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand',
890
+			'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
891
+			'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
892
+			'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
893
+			'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
894
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
895
+			'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
896
+			'CreateTransactionCommandHandler'                                     => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
897
+			'CreateAttendeeCommandHandler'                                        => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
898
+			'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
899
+			'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
900
+			'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
901
+			'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
902
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
903
+			'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
904
+			'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
905
+			'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
906
+			'CommandFactoryInterface'                                                     => 'EventEspresso\core\services\commands\CommandFactoryInterface',
907
+			'EventEspresso\core\services\commands\CommandFactoryInterface'                => 'EventEspresso\core\services\commands\CommandFactory',
908
+			'EventEspresso\core\domain\services\session\SessionIdentifierInterface'       => 'EE_Session',
909
+			'EmailValidatorInterface'                                                     => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
910
+			'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
911
+			'NoticeConverterInterface'                                            => 'EventEspresso\core\services\notices\NoticeConverterInterface',
912
+			'EventEspresso\core\services\notices\NoticeConverterInterface'        => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
913
+			'NoticesContainerInterface'                                           => 'EventEspresso\core\services\notices\NoticesContainerInterface',
914
+			'EventEspresso\core\services\notices\NoticesContainerInterface'       => 'EventEspresso\core\services\notices\NoticesContainer',
915
+			'EventEspresso\core\services\request\RequestInterface'                => 'EventEspresso\core\services\request\Request',
916
+			'EventEspresso\core\services\request\ResponseInterface'               => 'EventEspresso\core\services\request\Response',
917
+			'EventEspresso\core\domain\DomainInterface'                           => 'EventEspresso\core\domain\Domain',
918
+		);
919
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
920
+			$this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices';
921
+		}
922
+	}
923
+
924
+
925
+
926
+	/**
927
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
928
+	 * request Primarily used by unit tests.
929
+	 *
930
+	 * @throws InvalidDataTypeException
931
+	 * @throws InvalidInterfaceException
932
+	 * @throws InvalidArgumentException
933
+	 */
934
+	public function reset()
935
+	{
936
+		$this->_register_core_class_loaders();
937
+		$this->_register_core_dependencies();
938
+	}
939 939
 
940 940
 
941 941
 }
Please login to merge, or discard this patch.