Completed
Branch EDTR/plugins-page-asset-manage... (186768)
by
unknown
51:19 queued 42:53
created
core/admin/EE_Admin.core.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice;
4
-use EventEspresso\core\domain\services\admin\ExitModal;
5 4
 use EventEspresso\core\exceptions\InvalidDataTypeException;
6 5
 use EventEspresso\core\exceptions\InvalidInterfaceException;
7 6
 use EventEspresso\core\interfaces\InterminableInterface;
Please login to merge, or discard this patch.
Indentation   +980 added lines, -980 removed lines patch added patch discarded remove patch
@@ -21,481 +21,481 @@  discard block
 block discarded – undo
21 21
 final class EE_Admin implements InterminableInterface
22 22
 {
23 23
 
24
-    /**
25
-     * @var EE_Admin $_instance
26
-     */
27
-    private static $_instance;
28
-
29
-    /**
30
-     * @var PersistentAdminNoticeManager $persistent_admin_notice_manager
31
-     */
32
-    private $persistent_admin_notice_manager;
33
-
34
-    /**
35
-     * @var LoaderInterface
36
-     */
37
-    protected $loader;
38
-
39
-    /**
40
-     * @var RequestInterface $request
41
-     */
42
-    protected $request;
43
-
44
-
45
-    /**
46
-     * @singleton method used to instantiate class object
47
-     * @return EE_Admin
48
-     */
49
-    public static function instance()
50
-    {
51
-        // check if class object is instantiated
52
-        if (! EE_Admin::$_instance instanceof EE_Admin) {
53
-            EE_Admin::$_instance = new EE_Admin();
54
-        }
55
-        return EE_Admin::$_instance;
56
-    }
57
-
58
-
59
-    /**
60
-     * @return EE_Admin
61
-     */
62
-    public static function reset()
63
-    {
64
-        EE_Admin::$_instance = null;
65
-        return EE_Admin::instance();
66
-    }
67
-
68
-
69
-    /**
70
-     * class constructor
71
-     *
72
-     * @throws EE_Error
73
-     * @throws InvalidDataTypeException
74
-     * @throws InvalidInterfaceException
75
-     * @throws InvalidArgumentException
76
-     */
77
-    protected function __construct()
78
-    {
79
-        /** @var EventEspresso\core\services\request\Request $request */
80
-        $this->request = $this->getLoader()->getShared('EventEspresso\core\services\request\Request');
81
-        // define global EE_Admin constants
82
-        $this->_define_all_constants();
83
-        // set autoloaders for our admin page classes based on included path information
84
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_ADMIN);
85
-        // reset Environment config (we only do this on admin page loads);
86
-        EE_Registry::instance()->CFG->environment->recheck_values();
87
-        // load EE_Request_Handler early
88
-        add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
89
-        add_action('admin_init', array($this, 'admin_init'), 100);
90
-        add_action('admin_notices', array($this, 'display_admin_notices'), 10);
91
-        add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
92
-        add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
93
-        if (! $this->request->isAjax()) {
94
-            // admin hooks
95
-            add_filter('plugin_action_links', [$this, 'filter_plugin_actions'], 10, 2);
96
-            add_filter('admin_footer_text', [$this, 'espresso_admin_footer']);
97
-            add_action('load-plugins.php', [$this, 'hookIntoWpPluginsPage']);
98
-            add_action('display_post_states', [$this, 'displayStateForCriticalPages'], 10, 2);
99
-            add_filter('plugin_row_meta', [$this, 'addLinksToPluginRowMeta'], 10, 2);
100
-        }
101
-        do_action('AHEE__EE_Admin__loaded');
102
-    }
103
-
104
-
105
-    /**
106
-     * _define_all_constants
107
-     * define constants that are set globally for all admin pages
108
-     *
109
-     * @return void
110
-     */
111
-    private function _define_all_constants()
112
-    {
113
-        if (! defined('EE_ADMIN_URL')) {
114
-            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
115
-            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
116
-            define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates/');
117
-            define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
118
-            define('WP_AJAX_URL', admin_url('admin-ajax.php'));
119
-        }
120
-    }
121
-
122
-
123
-    /**
124
-     * filter_plugin_actions - adds links to the Plugins page listing
125
-     *
126
-     * @param    array  $links
127
-     * @param    string $plugin
128
-     * @return    array
129
-     */
130
-    public function filter_plugin_actions($links, $plugin)
131
-    {
132
-        // set $main_file in stone
133
-        static $main_file;
134
-        // if $main_file is not set yet
135
-        if (! $main_file) {
136
-            $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
137
-        }
138
-        if ($plugin === $main_file) {
139
-            // compare current plugin to this one
140
-            if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
141
-                $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
142
-                                    . ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
143
-                                    . esc_html__('Maintenance Mode Active', 'event_espresso')
144
-                                    . '</a>';
145
-                array_unshift($links, $maintenance_link);
146
-            } else {
147
-                $org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
148
-                                     . esc_html__('Settings', 'event_espresso')
149
-                                     . '</a>';
150
-                $events_link = '<a href="admin.php?page=espresso_events">'
151
-                               . esc_html__('Events', 'event_espresso')
152
-                               . '</a>';
153
-                // add before other links
154
-                array_unshift($links, $org_settings_link, $events_link);
155
-            }
156
-        }
157
-        return $links;
158
-    }
159
-
160
-
161
-    /**
162
-     * hide_admin_pages_except_maintenance_mode
163
-     *
164
-     * @param array $admin_page_folder_names
165
-     * @return array
166
-     */
167
-    public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
168
-    {
169
-        return array(
170
-            'maintenance' => EE_ADMIN_PAGES . 'maintenance/',
171
-            'about'       => EE_ADMIN_PAGES . 'about/',
172
-            'support'     => EE_ADMIN_PAGES . 'support/',
173
-        );
174
-    }
175
-
176
-
177
-    /**
178
-     * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
179
-     * EE_Front_Controller's init phases have run
180
-     *
181
-     * @return void
182
-     * @throws EE_Error
183
-     * @throws InvalidArgumentException
184
-     * @throws InvalidDataTypeException
185
-     * @throws InvalidInterfaceException
186
-     * @throws ReflectionException
187
-     * @throws ServiceNotFoundException
188
-     */
189
-    public function init()
190
-    {
191
-        // only enable most of the EE_Admin IF we're not in full maintenance mode
192
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
193
-            $this->initModelsReady();
194
-        }
195
-        // run the admin page factory but ONLY if we are doing an ee admin ajax request
196
-        if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
197
-            try {
198
-                // this loads the controller for the admin pages which will setup routing etc
199
-                $this->loader->getShared('EE_Admin_Page_Loader');
200
-            } catch (EE_Error $e) {
201
-                $e->get_error();
202
-            }
203
-        }
204
-        add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
205
-        if (! $this->request->isAjax()) {
206
-            // make sure our CPTs and custom taxonomy metaboxes get shown for first time users
207
-            add_action('admin_head', [$this, 'enable_hidden_ee_nav_menu_metaboxes'], 10);
208
-            add_action('admin_head', [$this, 'register_custom_nav_menu_boxes'], 10);
209
-            // exclude EE critical pages from all nav menus and wp_list_pages
210
-            add_filter('nav_menu_meta_box_object', [$this, 'remove_pages_from_nav_menu'], 10);
211
-        }
212
-    }
213
-
214
-
215
-    /**
216
-     * Gets the loader (and if it wasn't previously set, sets it)
217
-     * @return LoaderInterface
218
-     * @throws InvalidArgumentException
219
-     * @throws InvalidDataTypeException
220
-     * @throws InvalidInterfaceException
221
-     */
222
-    protected function getLoader()
223
-    {
224
-        if (! $this->loader instanceof LoaderInterface) {
225
-            $this->loader = LoaderFactory::getLoader();
226
-        }
227
-        return $this->loader;
228
-    }
229
-
230
-
231
-    /**
232
-     * Method that's fired on admin requests (including admin ajax) but only when the models are usable
233
-     * (ie, the site isn't in maintenance mode)
234
-     *
235
-     * @return void
236
-     * @throws EE_Error
237
-     * @throws EE_Error
238
-     * @since 4.9.63.p
239
-     */
240
-    protected function initModelsReady()
241
-    {
242
-        // ok so we want to enable the entire admin
243
-        $this->persistent_admin_notice_manager = $this->loader->getShared(
244
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
245
-        );
246
-        $this->persistent_admin_notice_manager->setReturnUrl(
247
-            EE_Admin_Page::add_query_args_and_nonce(
248
-                array(
249
-                    'page'   => $this->request->getRequestParam('page', ''),
250
-                    'action' => $this->request->getRequestParam('action', ''),
251
-                ),
252
-                EE_ADMIN_URL
253
-            )
254
-        );
255
-        $this->maybeSetDatetimeWarningNotice();
256
-        // at a glance dashboard widget
257
-        add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
258
-        // filter for get_edit_post_link used on comments for custom post types
259
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
260
-    }
261
-
262
-
263
-    /**
264
-     *    get_persistent_admin_notices
265
-     *
266
-     * @access    public
267
-     * @return void
268
-     * @throws EE_Error
269
-     * @throws InvalidArgumentException
270
-     * @throws InvalidDataTypeException
271
-     * @throws InvalidInterfaceException
272
-     */
273
-    public function maybeSetDatetimeWarningNotice()
274
-    {
275
-        // add dismissable notice for datetime changes.  Only valid if site does not have a timezone_string set.
276
-        // @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
277
-        // with this.  But after enough time (indeterminate at this point) we can just remove this notice.
278
-        // this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
279
-        if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true)
280
-            && ! get_option('timezone_string')
281
-            && EEM_Event::instance()->count() > 0
282
-        ) {
283
-            new PersistentAdminNotice(
284
-                'datetime_fix_notice',
285
-                sprintf(
286
-                    esc_html__(
287
-                        '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times.  Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.',
288
-                        'event_espresso'
289
-                    ),
290
-                    '<strong>',
291
-                    '</strong>',
292
-                    '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
293
-                    '</a>',
294
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
295
-                        array(
296
-                            'page'   => 'espresso_maintenance_settings',
297
-                            'action' => 'datetime_tools',
298
-                        ),
299
-                        admin_url('admin.php')
300
-                    ) . '">'
301
-                ),
302
-                false,
303
-                'manage_options',
304
-                'datetime_fix_persistent_notice'
305
-            );
306
-        }
307
-    }
308
-
309
-
310
-    /**
311
-     * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
312
-     * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
313
-     * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
314
-     * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
315
-     * normal property on the post_type object.  It's found ONLY in this particular context.
316
-     *
317
-     * @param WP_Post $post_type WP post type object
318
-     * @return WP_Post
319
-     * @throws InvalidArgumentException
320
-     * @throws InvalidDataTypeException
321
-     * @throws InvalidInterfaceException
322
-     */
323
-    public function remove_pages_from_nav_menu($post_type)
324
-    {
325
-        // if this isn't the "pages" post type let's get out
326
-        if ($post_type->name !== 'page') {
327
-            return $post_type;
328
-        }
329
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
330
-        $post_type->_default_query = array(
331
-            'post__not_in' => $critical_pages,
332
-        );
333
-        return $post_type;
334
-    }
335
-
336
-
337
-    /**
338
-     * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
339
-     * metaboxes get shown as well
340
-     *
341
-     * @return void
342
-     */
343
-    public function enable_hidden_ee_nav_menu_metaboxes()
344
-    {
345
-        global $wp_meta_boxes, $pagenow;
346
-        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
347
-            return;
348
-        }
349
-        $user = wp_get_current_user();
350
-        // has this been done yet?
351
-        if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
352
-            return;
353
-        }
354
-
355
-        $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID);
356
-        $initial_meta_boxes = apply_filters(
357
-            'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
358
-            array(
359
-                'nav-menu-theme-locations',
360
-                'add-page',
361
-                'add-custom-links',
362
-                'add-category',
363
-                'add-espresso_events',
364
-                'add-espresso_venues',
365
-                'add-espresso_event_categories',
366
-                'add-espresso_venue_categories',
367
-                'add-post-type-post',
368
-                'add-post-type-page',
369
-            )
370
-        );
371
-
372
-        if (is_array($hidden_meta_boxes)) {
373
-            foreach ($hidden_meta_boxes as $key => $meta_box_id) {
374
-                if (in_array($meta_box_id, $initial_meta_boxes, true)) {
375
-                    unset($hidden_meta_boxes[ $key ]);
376
-                }
377
-            }
378
-        }
379
-        update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
380
-        update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
381
-    }
382
-
383
-
384
-    /**
385
-     * This method simply registers custom nav menu boxes for "nav_menus.php route"
386
-     * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
387
-     *
388
-     * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
389
-     *         addons etc.
390
-     * @return void
391
-     */
392
-    public function register_custom_nav_menu_boxes()
393
-    {
394
-        add_meta_box(
395
-            'add-extra-nav-menu-pages',
396
-            esc_html__('Event Espresso Pages', 'event_espresso'),
397
-            array($this, 'ee_cpt_archive_pages'),
398
-            'nav-menus',
399
-            'side',
400
-            'core'
401
-        );
402
-    }
403
-
404
-
405
-    /**
406
-     * Use this to edit the post link for our cpts so that the edit link points to the correct page.
407
-     *
408
-     * @since   4.3.0
409
-     * @param string $link the original link generated by wp
410
-     * @param int    $id   post id
411
-     * @return string  the (maybe) modified link
412
-     */
413
-    public function modify_edit_post_link($link, $id)
414
-    {
415
-        if (! $post = get_post($id)) {
416
-            return $link;
417
-        }
418
-        if ($post->post_type === 'espresso_attendees') {
419
-            $query_args = array(
420
-                'action' => 'edit_attendee',
421
-                'post'   => $id,
422
-            );
423
-            return EEH_URL::add_query_args_and_nonce(
424
-                $query_args,
425
-                admin_url('admin.php?page=espresso_registrations')
426
-            );
427
-        }
428
-        return $link;
429
-    }
430
-
431
-
432
-    public function ee_cpt_archive_pages()
433
-    {
434
-        global $nav_menu_selected_id;
435
-        $db_fields = false;
436
-        $walker = new Walker_Nav_Menu_Checklist($db_fields);
437
-        $current_tab = 'event-archives';
438
-        $removed_args = array(
439
-            'action',
440
-            'customlink-tab',
441
-            'edit-menu-item',
442
-            'menu-item',
443
-            'page-tab',
444
-            '_wpnonce',
445
-        );
446
-        ?>
24
+	/**
25
+	 * @var EE_Admin $_instance
26
+	 */
27
+	private static $_instance;
28
+
29
+	/**
30
+	 * @var PersistentAdminNoticeManager $persistent_admin_notice_manager
31
+	 */
32
+	private $persistent_admin_notice_manager;
33
+
34
+	/**
35
+	 * @var LoaderInterface
36
+	 */
37
+	protected $loader;
38
+
39
+	/**
40
+	 * @var RequestInterface $request
41
+	 */
42
+	protected $request;
43
+
44
+
45
+	/**
46
+	 * @singleton method used to instantiate class object
47
+	 * @return EE_Admin
48
+	 */
49
+	public static function instance()
50
+	{
51
+		// check if class object is instantiated
52
+		if (! EE_Admin::$_instance instanceof EE_Admin) {
53
+			EE_Admin::$_instance = new EE_Admin();
54
+		}
55
+		return EE_Admin::$_instance;
56
+	}
57
+
58
+
59
+	/**
60
+	 * @return EE_Admin
61
+	 */
62
+	public static function reset()
63
+	{
64
+		EE_Admin::$_instance = null;
65
+		return EE_Admin::instance();
66
+	}
67
+
68
+
69
+	/**
70
+	 * class constructor
71
+	 *
72
+	 * @throws EE_Error
73
+	 * @throws InvalidDataTypeException
74
+	 * @throws InvalidInterfaceException
75
+	 * @throws InvalidArgumentException
76
+	 */
77
+	protected function __construct()
78
+	{
79
+		/** @var EventEspresso\core\services\request\Request $request */
80
+		$this->request = $this->getLoader()->getShared('EventEspresso\core\services\request\Request');
81
+		// define global EE_Admin constants
82
+		$this->_define_all_constants();
83
+		// set autoloaders for our admin page classes based on included path information
84
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_ADMIN);
85
+		// reset Environment config (we only do this on admin page loads);
86
+		EE_Registry::instance()->CFG->environment->recheck_values();
87
+		// load EE_Request_Handler early
88
+		add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
89
+		add_action('admin_init', array($this, 'admin_init'), 100);
90
+		add_action('admin_notices', array($this, 'display_admin_notices'), 10);
91
+		add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
92
+		add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
93
+		if (! $this->request->isAjax()) {
94
+			// admin hooks
95
+			add_filter('plugin_action_links', [$this, 'filter_plugin_actions'], 10, 2);
96
+			add_filter('admin_footer_text', [$this, 'espresso_admin_footer']);
97
+			add_action('load-plugins.php', [$this, 'hookIntoWpPluginsPage']);
98
+			add_action('display_post_states', [$this, 'displayStateForCriticalPages'], 10, 2);
99
+			add_filter('plugin_row_meta', [$this, 'addLinksToPluginRowMeta'], 10, 2);
100
+		}
101
+		do_action('AHEE__EE_Admin__loaded');
102
+	}
103
+
104
+
105
+	/**
106
+	 * _define_all_constants
107
+	 * define constants that are set globally for all admin pages
108
+	 *
109
+	 * @return void
110
+	 */
111
+	private function _define_all_constants()
112
+	{
113
+		if (! defined('EE_ADMIN_URL')) {
114
+			define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
115
+			define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
116
+			define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates/');
117
+			define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
118
+			define('WP_AJAX_URL', admin_url('admin-ajax.php'));
119
+		}
120
+	}
121
+
122
+
123
+	/**
124
+	 * filter_plugin_actions - adds links to the Plugins page listing
125
+	 *
126
+	 * @param    array  $links
127
+	 * @param    string $plugin
128
+	 * @return    array
129
+	 */
130
+	public function filter_plugin_actions($links, $plugin)
131
+	{
132
+		// set $main_file in stone
133
+		static $main_file;
134
+		// if $main_file is not set yet
135
+		if (! $main_file) {
136
+			$main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
137
+		}
138
+		if ($plugin === $main_file) {
139
+			// compare current plugin to this one
140
+			if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
141
+				$maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
142
+									. ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
143
+									. esc_html__('Maintenance Mode Active', 'event_espresso')
144
+									. '</a>';
145
+				array_unshift($links, $maintenance_link);
146
+			} else {
147
+				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
148
+									 . esc_html__('Settings', 'event_espresso')
149
+									 . '</a>';
150
+				$events_link = '<a href="admin.php?page=espresso_events">'
151
+							   . esc_html__('Events', 'event_espresso')
152
+							   . '</a>';
153
+				// add before other links
154
+				array_unshift($links, $org_settings_link, $events_link);
155
+			}
156
+		}
157
+		return $links;
158
+	}
159
+
160
+
161
+	/**
162
+	 * hide_admin_pages_except_maintenance_mode
163
+	 *
164
+	 * @param array $admin_page_folder_names
165
+	 * @return array
166
+	 */
167
+	public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
168
+	{
169
+		return array(
170
+			'maintenance' => EE_ADMIN_PAGES . 'maintenance/',
171
+			'about'       => EE_ADMIN_PAGES . 'about/',
172
+			'support'     => EE_ADMIN_PAGES . 'support/',
173
+		);
174
+	}
175
+
176
+
177
+	/**
178
+	 * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
179
+	 * EE_Front_Controller's init phases have run
180
+	 *
181
+	 * @return void
182
+	 * @throws EE_Error
183
+	 * @throws InvalidArgumentException
184
+	 * @throws InvalidDataTypeException
185
+	 * @throws InvalidInterfaceException
186
+	 * @throws ReflectionException
187
+	 * @throws ServiceNotFoundException
188
+	 */
189
+	public function init()
190
+	{
191
+		// only enable most of the EE_Admin IF we're not in full maintenance mode
192
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
193
+			$this->initModelsReady();
194
+		}
195
+		// run the admin page factory but ONLY if we are doing an ee admin ajax request
196
+		if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
197
+			try {
198
+				// this loads the controller for the admin pages which will setup routing etc
199
+				$this->loader->getShared('EE_Admin_Page_Loader');
200
+			} catch (EE_Error $e) {
201
+				$e->get_error();
202
+			}
203
+		}
204
+		add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
205
+		if (! $this->request->isAjax()) {
206
+			// make sure our CPTs and custom taxonomy metaboxes get shown for first time users
207
+			add_action('admin_head', [$this, 'enable_hidden_ee_nav_menu_metaboxes'], 10);
208
+			add_action('admin_head', [$this, 'register_custom_nav_menu_boxes'], 10);
209
+			// exclude EE critical pages from all nav menus and wp_list_pages
210
+			add_filter('nav_menu_meta_box_object', [$this, 'remove_pages_from_nav_menu'], 10);
211
+		}
212
+	}
213
+
214
+
215
+	/**
216
+	 * Gets the loader (and if it wasn't previously set, sets it)
217
+	 * @return LoaderInterface
218
+	 * @throws InvalidArgumentException
219
+	 * @throws InvalidDataTypeException
220
+	 * @throws InvalidInterfaceException
221
+	 */
222
+	protected function getLoader()
223
+	{
224
+		if (! $this->loader instanceof LoaderInterface) {
225
+			$this->loader = LoaderFactory::getLoader();
226
+		}
227
+		return $this->loader;
228
+	}
229
+
230
+
231
+	/**
232
+	 * Method that's fired on admin requests (including admin ajax) but only when the models are usable
233
+	 * (ie, the site isn't in maintenance mode)
234
+	 *
235
+	 * @return void
236
+	 * @throws EE_Error
237
+	 * @throws EE_Error
238
+	 * @since 4.9.63.p
239
+	 */
240
+	protected function initModelsReady()
241
+	{
242
+		// ok so we want to enable the entire admin
243
+		$this->persistent_admin_notice_manager = $this->loader->getShared(
244
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
245
+		);
246
+		$this->persistent_admin_notice_manager->setReturnUrl(
247
+			EE_Admin_Page::add_query_args_and_nonce(
248
+				array(
249
+					'page'   => $this->request->getRequestParam('page', ''),
250
+					'action' => $this->request->getRequestParam('action', ''),
251
+				),
252
+				EE_ADMIN_URL
253
+			)
254
+		);
255
+		$this->maybeSetDatetimeWarningNotice();
256
+		// at a glance dashboard widget
257
+		add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
258
+		// filter for get_edit_post_link used on comments for custom post types
259
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
260
+	}
261
+
262
+
263
+	/**
264
+	 *    get_persistent_admin_notices
265
+	 *
266
+	 * @access    public
267
+	 * @return void
268
+	 * @throws EE_Error
269
+	 * @throws InvalidArgumentException
270
+	 * @throws InvalidDataTypeException
271
+	 * @throws InvalidInterfaceException
272
+	 */
273
+	public function maybeSetDatetimeWarningNotice()
274
+	{
275
+		// add dismissable notice for datetime changes.  Only valid if site does not have a timezone_string set.
276
+		// @todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
277
+		// with this.  But after enough time (indeterminate at this point) we can just remove this notice.
278
+		// this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
279
+		if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true)
280
+			&& ! get_option('timezone_string')
281
+			&& EEM_Event::instance()->count() > 0
282
+		) {
283
+			new PersistentAdminNotice(
284
+				'datetime_fix_notice',
285
+				sprintf(
286
+					esc_html__(
287
+						'%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times.  Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.',
288
+						'event_espresso'
289
+					),
290
+					'<strong>',
291
+					'</strong>',
292
+					'<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
293
+					'</a>',
294
+					'<a href="' . EE_Admin_Page::add_query_args_and_nonce(
295
+						array(
296
+							'page'   => 'espresso_maintenance_settings',
297
+							'action' => 'datetime_tools',
298
+						),
299
+						admin_url('admin.php')
300
+					) . '">'
301
+				),
302
+				false,
303
+				'manage_options',
304
+				'datetime_fix_persistent_notice'
305
+			);
306
+		}
307
+	}
308
+
309
+
310
+	/**
311
+	 * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
312
+	 * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
313
+	 * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
314
+	 * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
315
+	 * normal property on the post_type object.  It's found ONLY in this particular context.
316
+	 *
317
+	 * @param WP_Post $post_type WP post type object
318
+	 * @return WP_Post
319
+	 * @throws InvalidArgumentException
320
+	 * @throws InvalidDataTypeException
321
+	 * @throws InvalidInterfaceException
322
+	 */
323
+	public function remove_pages_from_nav_menu($post_type)
324
+	{
325
+		// if this isn't the "pages" post type let's get out
326
+		if ($post_type->name !== 'page') {
327
+			return $post_type;
328
+		}
329
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
330
+		$post_type->_default_query = array(
331
+			'post__not_in' => $critical_pages,
332
+		);
333
+		return $post_type;
334
+	}
335
+
336
+
337
+	/**
338
+	 * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
339
+	 * metaboxes get shown as well
340
+	 *
341
+	 * @return void
342
+	 */
343
+	public function enable_hidden_ee_nav_menu_metaboxes()
344
+	{
345
+		global $wp_meta_boxes, $pagenow;
346
+		if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
347
+			return;
348
+		}
349
+		$user = wp_get_current_user();
350
+		// has this been done yet?
351
+		if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
352
+			return;
353
+		}
354
+
355
+		$hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID);
356
+		$initial_meta_boxes = apply_filters(
357
+			'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
358
+			array(
359
+				'nav-menu-theme-locations',
360
+				'add-page',
361
+				'add-custom-links',
362
+				'add-category',
363
+				'add-espresso_events',
364
+				'add-espresso_venues',
365
+				'add-espresso_event_categories',
366
+				'add-espresso_venue_categories',
367
+				'add-post-type-post',
368
+				'add-post-type-page',
369
+			)
370
+		);
371
+
372
+		if (is_array($hidden_meta_boxes)) {
373
+			foreach ($hidden_meta_boxes as $key => $meta_box_id) {
374
+				if (in_array($meta_box_id, $initial_meta_boxes, true)) {
375
+					unset($hidden_meta_boxes[ $key ]);
376
+				}
377
+			}
378
+		}
379
+		update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
380
+		update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
381
+	}
382
+
383
+
384
+	/**
385
+	 * This method simply registers custom nav menu boxes for "nav_menus.php route"
386
+	 * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
387
+	 *
388
+	 * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
389
+	 *         addons etc.
390
+	 * @return void
391
+	 */
392
+	public function register_custom_nav_menu_boxes()
393
+	{
394
+		add_meta_box(
395
+			'add-extra-nav-menu-pages',
396
+			esc_html__('Event Espresso Pages', 'event_espresso'),
397
+			array($this, 'ee_cpt_archive_pages'),
398
+			'nav-menus',
399
+			'side',
400
+			'core'
401
+		);
402
+	}
403
+
404
+
405
+	/**
406
+	 * Use this to edit the post link for our cpts so that the edit link points to the correct page.
407
+	 *
408
+	 * @since   4.3.0
409
+	 * @param string $link the original link generated by wp
410
+	 * @param int    $id   post id
411
+	 * @return string  the (maybe) modified link
412
+	 */
413
+	public function modify_edit_post_link($link, $id)
414
+	{
415
+		if (! $post = get_post($id)) {
416
+			return $link;
417
+		}
418
+		if ($post->post_type === 'espresso_attendees') {
419
+			$query_args = array(
420
+				'action' => 'edit_attendee',
421
+				'post'   => $id,
422
+			);
423
+			return EEH_URL::add_query_args_and_nonce(
424
+				$query_args,
425
+				admin_url('admin.php?page=espresso_registrations')
426
+			);
427
+		}
428
+		return $link;
429
+	}
430
+
431
+
432
+	public function ee_cpt_archive_pages()
433
+	{
434
+		global $nav_menu_selected_id;
435
+		$db_fields = false;
436
+		$walker = new Walker_Nav_Menu_Checklist($db_fields);
437
+		$current_tab = 'event-archives';
438
+		$removed_args = array(
439
+			'action',
440
+			'customlink-tab',
441
+			'edit-menu-item',
442
+			'menu-item',
443
+			'page-tab',
444
+			'_wpnonce',
445
+		);
446
+		?>
447 447
         <div id="posttype-extra-nav-menu-pages" class="posttypediv">
448 448
             <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs">
449 449
                 <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>>
450 450
                     <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives"
451 451
                        href="<?php
452
-                        if ($nav_menu_selected_id) {
453
-                            echo esc_url(
454
-                                add_query_arg(
455
-                                    'extra-nav-menu-pages-tab',
456
-                                    'event-archives',
457
-                                    remove_query_arg($removed_args)
458
-                                )
459
-                            );
460
-                        }
461
-                        ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
452
+						if ($nav_menu_selected_id) {
453
+							echo esc_url(
454
+								add_query_arg(
455
+									'extra-nav-menu-pages-tab',
456
+									'event-archives',
457
+									remove_query_arg($removed_args)
458
+								)
459
+							);
460
+						}
461
+						?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
462 462
                         <?php esc_html_e('Event Archive Pages', 'event_espresso'); ?>
463 463
                     </a>
464 464
                 </li>
465 465
             </ul><!-- .posttype-tabs -->
466 466
 
467 467
             <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php
468
-            echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
469
-            ?>">
468
+			echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
469
+			?>">
470 470
                 <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear">
471 471
                     <?php
472
-                    $pages = $this->_get_extra_nav_menu_pages_items();
473
-                    $args['walker'] = $walker;
474
-                    echo walk_nav_menu_tree(
475
-                        array_map(
476
-                            array($this, '_setup_extra_nav_menu_pages_items'),
477
-                            $pages
478
-                        ),
479
-                        0,
480
-                        (object) $args
481
-                    );
482
-                    ?>
472
+					$pages = $this->_get_extra_nav_menu_pages_items();
473
+					$args['walker'] = $walker;
474
+					echo walk_nav_menu_tree(
475
+						array_map(
476
+							array($this, '_setup_extra_nav_menu_pages_items'),
477
+							$pages
478
+						),
479
+						0,
480
+						(object) $args
481
+					);
482
+					?>
483 483
                 </ul>
484 484
             </div><!-- /.tabs-panel -->
485 485
 
486 486
             <p class="button-controls">
487 487
                 <span class="list-controls">
488 488
                     <a href="<?php
489
-                             echo esc_url(
490
-                                 add_query_arg(
491
-                                     array(
492
-                                         'extra-nav-menu-pages-tab' => 'event-archives',
493
-                                         'selectall'                => 1,
494
-                                     ),
495
-                                     remove_query_arg($removed_args)
496
-                                 )
497
-                             );
498
-                        ?>#posttype-extra-nav-menu-pages" class="select-all"><?php esc_html_e('Select All', 'event_espresso'); ?></a>
489
+							 echo esc_url(
490
+								 add_query_arg(
491
+									 array(
492
+										 'extra-nav-menu-pages-tab' => 'event-archives',
493
+										 'selectall'                => 1,
494
+									 ),
495
+									 remove_query_arg($removed_args)
496
+								 )
497
+							 );
498
+						?>#posttype-extra-nav-menu-pages" class="select-all"><?php esc_html_e('Select All', 'event_espresso'); ?></a>
499 499
                 </span>
500 500
                 <span class="add-to-menu">
501 501
                     <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?>
@@ -508,528 +508,528 @@  discard block
 block discarded – undo
508 508
 
509 509
         </div><!-- /.posttypediv -->
510 510
         <?php
511
-    }
512
-
513
-
514
-    /**
515
-     * Returns an array of event archive nav items.
516
-     *
517
-     * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
518
-     *        method we use for getting the extra nav menu items
519
-     * @return array
520
-     */
521
-    private function _get_extra_nav_menu_pages_items()
522
-    {
523
-        $menuitems[] = array(
524
-            'title'       => esc_html__('Event List', 'event_espresso'),
525
-            'url'         => get_post_type_archive_link('espresso_events'),
526
-            'description' => esc_html__('Archive page for all events.', 'event_espresso'),
527
-        );
528
-        return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
529
-    }
530
-
531
-
532
-    /**
533
-     * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
534
-     * the properties and converts it to the menu item object.
535
-     *
536
-     * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
537
-     * @param $menu_item_values
538
-     * @return stdClass
539
-     */
540
-    private function _setup_extra_nav_menu_pages_items($menu_item_values)
541
-    {
542
-        $menu_item = new stdClass();
543
-        $keys = array(
544
-            'ID'               => 0,
545
-            'db_id'            => 0,
546
-            'menu_item_parent' => 0,
547
-            'object_id'        => -1,
548
-            'post_parent'      => 0,
549
-            'type'             => 'custom',
550
-            'object'           => '',
551
-            'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
552
-            'title'            => '',
553
-            'url'              => '',
554
-            'target'           => '',
555
-            'attr_title'       => '',
556
-            'description'      => '',
557
-            'classes'          => array(),
558
-            'xfn'              => '',
559
-        );
560
-
561
-        foreach ($keys as $key => $value) {
562
-            $menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value;
563
-        }
564
-        return $menu_item;
565
-    }
566
-
567
-
568
-    /**
569
-     * admin_init
570
-     *
571
-     * @return void
572
-     * @throws InvalidArgumentException
573
-     * @throws InvalidDataTypeException
574
-     * @throws InvalidInterfaceException
575
-     */
576
-    public function admin_init()
577
-    {
578
-        /**
579
-         * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
580
-         * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
581
-         * - check if doing post processing.
582
-         * - check if doing post processing of one of EE CPTs
583
-         * - instantiate the corresponding EE CPT model for the post_type being processed.
584
-         */
585
-        if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
586
-            /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
587
-            $custom_post_types = $this->loader->getShared(
588
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
589
-            );
590
-            $custom_post_types->getCustomPostTypeModels($_POST['post_type']);
591
-        }
592
-
593
-        if (! $this->request->isAjax()) {
594
-            /**
595
-             * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
596
-             * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
597
-             * Pages" tab in the EE General Settings Admin page.
598
-             * This is for user-proofing.
599
-             */
600
-            add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
601
-            if (EE_Maintenance_Mode::instance()->models_can_query()) {
602
-                $this->adminInitModelsReady();
603
-            }
604
-        }
605
-    }
606
-
607
-
608
-    /**
609
-     * Runs on admin_init but only if models are usable (ie, we're not in maintenance mode)
610
-     */
611
-    protected function adminInitModelsReady()
612
-    {
613
-        if (function_exists('wp_add_privacy_policy_content')) {
614
-            $this->loader->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager');
615
-        }
616
-    }
617
-
618
-
619
-    /**
620
-     * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
621
-     *
622
-     * @param string $output Current output.
623
-     * @return string
624
-     * @throws InvalidArgumentException
625
-     * @throws InvalidDataTypeException
626
-     * @throws InvalidInterfaceException
627
-     */
628
-    public function modify_dropdown_pages($output)
629
-    {
630
-        // get critical pages
631
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
632
-
633
-        // split current output by line break for easier parsing.
634
-        $split_output = explode("\n", $output);
635
-
636
-        // loop through to remove any critical pages from the array.
637
-        foreach ($critical_pages as $page_id) {
638
-            $needle = 'value="' . $page_id . '"';
639
-            foreach ($split_output as $key => $haystack) {
640
-                if (strpos($haystack, $needle) !== false) {
641
-                    unset($split_output[ $key ]);
642
-                }
643
-            }
644
-        }
645
-        // replace output with the new contents
646
-        return implode("\n", $split_output);
647
-    }
648
-
649
-
650
-    /**
651
-     * display_admin_notices
652
-     *
653
-     * @return void
654
-     */
655
-    public function display_admin_notices()
656
-    {
657
-        echo EE_Error::get_notices();
658
-    }
659
-
660
-
661
-    /**
662
-     * @param array $elements
663
-     * @return array
664
-     * @throws EE_Error
665
-     * @throws InvalidArgumentException
666
-     * @throws InvalidDataTypeException
667
-     * @throws InvalidInterfaceException
668
-     */
669
-    public function dashboard_glance_items($elements)
670
-    {
671
-        $elements = is_array($elements) ? $elements : array($elements);
672
-        $events = EEM_Event::instance()->count();
673
-        $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(
674
-            array('page' => 'espresso_events'),
675
-            admin_url('admin.php')
676
-        );
677
-        $items['events']['text'] = sprintf(
678
-            esc_html(
679
-                _n('%s Event', '%s Events', $events, 'event_espresso')
680
-            ),
681
-            number_format_i18n($events)
682
-        );
683
-        $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso');
684
-        $registrations = EEM_Registration::instance()->count(
685
-            array(
686
-                array(
687
-                    'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
688
-                ),
689
-            )
690
-        );
691
-        $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(
692
-            array('page' => 'espresso_registrations'),
693
-            admin_url('admin.php')
694
-        );
695
-        $items['registrations']['text'] = sprintf(
696
-            esc_html(
697
-                _n('%s Registration', '%s Registrations', $registrations, 'event_espresso')
698
-            ),
699
-            number_format_i18n($registrations)
700
-        );
701
-        $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
702
-
703
-        $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
704
-
705
-        foreach ($items as $type => $item_properties) {
706
-            $elements[] = sprintf(
707
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
708
-                $item_properties['url'],
709
-                $item_properties['title'],
710
-                $item_properties['text']
711
-            );
712
-        }
713
-        return $elements;
714
-    }
715
-
716
-
717
-    /**
718
-     * check_for_invalid_datetime_formats
719
-     * if an admin changes their date or time format settings on the WP General Settings admin page, verify that
720
-     * their selected format can be parsed by PHP
721
-     *
722
-     * @param    $value
723
-     * @param    $option
724
-     * @return    string
725
-     */
726
-    public function check_for_invalid_datetime_formats($value, $option)
727
-    {
728
-        // check for date_format or time_format
729
-        switch ($option) {
730
-            case 'date_format':
731
-                $date_time_format = $value . ' ' . get_option('time_format');
732
-                break;
733
-            case 'time_format':
734
-                $date_time_format = get_option('date_format') . ' ' . $value;
735
-                break;
736
-            default:
737
-                $date_time_format = false;
738
-        }
739
-        // do we have a date_time format to check ?
740
-        if ($date_time_format) {
741
-            $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
742
-
743
-            if (is_array($error_msg)) {
744
-                $msg = '<p>'
745
-                       . sprintf(
746
-                           esc_html__(
747
-                               'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
748
-                               'event_espresso'
749
-                           ),
750
-                           date($date_time_format),
751
-                           $date_time_format
752
-                       )
753
-                       . '</p><p><ul>';
754
-
755
-
756
-                foreach ($error_msg as $error) {
757
-                    $msg .= '<li>' . $error . '</li>';
758
-                }
759
-
760
-                $msg .= '</ul></p><p>'
761
-                        . sprintf(
762
-                            esc_html__(
763
-                                '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
764
-                                'event_espresso'
765
-                            ),
766
-                            '<span style="color:#D54E21;">',
767
-                            '</span>'
768
-                        )
769
-                        . '</p>';
770
-
771
-                // trigger WP settings error
772
-                add_settings_error(
773
-                    'date_format',
774
-                    'date_format',
775
-                    $msg
776
-                );
777
-
778
-                // set format to something valid
779
-                switch ($option) {
780
-                    case 'date_format':
781
-                        $value = 'F j, Y';
782
-                        break;
783
-                    case 'time_format':
784
-                        $value = 'g:i a';
785
-                        break;
786
-                }
787
-            }
788
-        }
789
-        return $value;
790
-    }
791
-
792
-
793
-    /**
794
-     * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
795
-     *
796
-     * @param $content
797
-     * @return    string
798
-     */
799
-    public function its_eSpresso($content)
800
-    {
801
-        return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
802
-    }
803
-
804
-
805
-    /**
806
-     * espresso_admin_footer
807
-     *
808
-     * @return    string
809
-     */
810
-    public function espresso_admin_footer()
811
-    {
812
-        return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
813
-    }
814
-
815
-
816
-    /**
817
-     * Hooks into the "post states" filter in a wp post type list table.
818
-     *
819
-     * @param array   $post_states
820
-     * @param WP_Post $post
821
-     * @return array
822
-     * @throws InvalidArgumentException
823
-     * @throws InvalidDataTypeException
824
-     * @throws InvalidInterfaceException
825
-     */
826
-    public function displayStateForCriticalPages($post_states, $post)
827
-    {
828
-        $post_states = (array) $post_states;
829
-        if (! $post instanceof WP_Post || $post->post_type !== 'page') {
830
-            return $post_states;
831
-        }
832
-        /** @var EE_Core_Config $config */
833
-        $config = $this->loader->getShared('EE_Config')->core;
834
-        if (in_array($post->ID, $config->get_critical_pages_array(), true)) {
835
-            $post_states[] = sprintf(
836
-                /* Translators: Using company name - Event Espresso Critical Page */
837
-                esc_html__('%s Critical Page', 'event_espresso'),
838
-                'Event Espresso'
839
-            );
840
-        }
841
-        return $post_states;
842
-    }
843
-
844
-
845
-    /**
846
-     * Show documentation links on the plugins page
847
-     *
848
-     * @param mixed $meta Plugin Row Meta
849
-     * @param mixed $file Plugin Base file
850
-     * @return array
851
-     */
852
-    public function addLinksToPluginRowMeta($meta, $file)
853
-    {
854
-        if (EE_PLUGIN_BASENAME === $file) {
855
-            $row_meta = array(
856
-                'docs' => '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4"'
857
-                          . ' aria-label="'
858
-                          . esc_attr__('View Event Espresso documentation', 'event_espresso')
859
-                          . '">'
860
-                          . esc_html__('Docs', 'event_espresso')
861
-                          . '</a>',
862
-                'api'  => '<a href="https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API"'
863
-                          . ' aria-label="'
864
-                          . esc_attr__('View Event Espresso API docs', 'event_espresso')
865
-                          . '">'
866
-                          . esc_html__('API docs', 'event_espresso')
867
-                          . '</a>',
868
-            );
869
-            return array_merge($meta, $row_meta);
870
-        }
871
-        return (array) $meta;
872
-    }
873
-
874
-     /**************************************************************************************/
875
-     /************************************* DEPRECATED *************************************/
876
-     /**************************************************************************************/
877
-
878
-
879
-    /**
880
-     * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
881
-     * EE_Admin_Page route is called.
882
-     *
883
-     * @return void
884
-     */
885
-    public function route_admin_request()
886
-    {
887
-    }
888
-
889
-
890
-    /**
891
-     * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
892
-     *
893
-     * @return void
894
-     */
895
-    public function wp_loaded()
896
-    {
897
-    }
898
-
899
-
900
-    /**
901
-     * static method for registering ee admin page.
902
-     * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
903
-     *
904
-     * @param       $page_basename
905
-     * @param       $page_path
906
-     * @param array $config
907
-     * @return void
908
-     * @throws EE_Error
909
-     * @see        EE_Register_Admin_Page::register()
910
-     * @since      4.3.0
911
-     * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
912
-     */
913
-    public static function register_ee_admin_page($page_basename, $page_path, $config = [])
914
-    {
915
-        EE_Error::doing_it_wrong(
916
-            __METHOD__,
917
-            sprintf(
918
-                esc_html__(
919
-                    'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
920
-                    'event_espresso'
921
-                ),
922
-                $page_basename
923
-            ),
924
-            '4.3'
925
-        );
926
-        if (class_exists('EE_Register_Admin_Page')) {
927
-            $config['page_path'] = $page_path;
928
-        }
929
-        EE_Register_Admin_Page::register($page_basename, $config);
930
-    }
931
-
932
-
933
-    /**
934
-     * @param int      $post_ID
935
-     * @param \WP_Post $post
936
-     * @return void
937
-     * @deprecated 4.8.41
938
-     */
939
-    public static function parse_post_content_on_save($post_ID, $post)
940
-    {
941
-        EE_Error::doing_it_wrong(
942
-            __METHOD__,
943
-            esc_html__('Usage is deprecated', 'event_espresso'),
944
-            '4.8.41'
945
-        );
946
-    }
947
-
948
-
949
-    /**
950
-     * @param  $option
951
-     * @param  $old_value
952
-     * @param  $value
953
-     * @return void
954
-     * @deprecated 4.8.41
955
-     */
956
-    public function reset_page_for_posts_on_change($option, $old_value, $value)
957
-    {
958
-        EE_Error::doing_it_wrong(
959
-            __METHOD__,
960
-            esc_html__('Usage is deprecated', 'event_espresso'),
961
-            '4.8.41'
962
-        );
963
-    }
964
-
965
-
966
-    /**
967
-     * @return void
968
-     * @deprecated 4.9.27
969
-     */
970
-    public function get_persistent_admin_notices()
971
-    {
972
-        EE_Error::doing_it_wrong(
973
-            __METHOD__,
974
-            sprintf(
975
-                esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
976
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
977
-            ),
978
-            '4.9.27'
979
-        );
980
-    }
981
-
982
-
983
-    /**
984
-     * @throws InvalidInterfaceException
985
-     * @throws InvalidDataTypeException
986
-     * @throws DomainException
987
-     * @deprecated 4.9.27
988
-     */
989
-    public function dismiss_ee_nag_notice_callback()
990
-    {
991
-        EE_Error::doing_it_wrong(
992
-            __METHOD__,
993
-            sprintf(
994
-                esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
995
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
996
-            ),
997
-            '4.9.27'
998
-        );
999
-        $this->persistent_admin_notice_manager->dismissNotice();
1000
-    }
1001
-
1002
-
1003
-    /**
1004
-     * @return void
1005
-     * @deprecated $VID:$
1006
-     */
1007
-    public function enqueue_admin_scripts()
1008
-    {
1009
-    }
1010
-
1011
-
1012
-
1013
-    /**
1014
-     * @deprecated $VID:$
1015
-     */
1016
-    public function get_request()
1017
-    {
1018
-        EE_Error::doing_it_wrong(
1019
-            __METHOD__,
1020
-            sprintf(
1021
-                esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1022
-                'EventEspresso\core\services\request\Request'
1023
-            ),
1024
-            '$VID:$'
1025
-        );
1026
-        EE_Registry::instance()->load_core('Request_Handler');
1027
-    }
1028
-
1029
-    /**
1030
-     * @deprecated $VID:$
1031
-     */
1032
-    public function hookIntoWpPluginsPage()
1033
-    {
1034
-    }
511
+	}
512
+
513
+
514
+	/**
515
+	 * Returns an array of event archive nav items.
516
+	 *
517
+	 * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
518
+	 *        method we use for getting the extra nav menu items
519
+	 * @return array
520
+	 */
521
+	private function _get_extra_nav_menu_pages_items()
522
+	{
523
+		$menuitems[] = array(
524
+			'title'       => esc_html__('Event List', 'event_espresso'),
525
+			'url'         => get_post_type_archive_link('espresso_events'),
526
+			'description' => esc_html__('Archive page for all events.', 'event_espresso'),
527
+		);
528
+		return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
529
+	}
530
+
531
+
532
+	/**
533
+	 * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
534
+	 * the properties and converts it to the menu item object.
535
+	 *
536
+	 * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
537
+	 * @param $menu_item_values
538
+	 * @return stdClass
539
+	 */
540
+	private function _setup_extra_nav_menu_pages_items($menu_item_values)
541
+	{
542
+		$menu_item = new stdClass();
543
+		$keys = array(
544
+			'ID'               => 0,
545
+			'db_id'            => 0,
546
+			'menu_item_parent' => 0,
547
+			'object_id'        => -1,
548
+			'post_parent'      => 0,
549
+			'type'             => 'custom',
550
+			'object'           => '',
551
+			'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
552
+			'title'            => '',
553
+			'url'              => '',
554
+			'target'           => '',
555
+			'attr_title'       => '',
556
+			'description'      => '',
557
+			'classes'          => array(),
558
+			'xfn'              => '',
559
+		);
560
+
561
+		foreach ($keys as $key => $value) {
562
+			$menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value;
563
+		}
564
+		return $menu_item;
565
+	}
566
+
567
+
568
+	/**
569
+	 * admin_init
570
+	 *
571
+	 * @return void
572
+	 * @throws InvalidArgumentException
573
+	 * @throws InvalidDataTypeException
574
+	 * @throws InvalidInterfaceException
575
+	 */
576
+	public function admin_init()
577
+	{
578
+		/**
579
+		 * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
580
+		 * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
581
+		 * - check if doing post processing.
582
+		 * - check if doing post processing of one of EE CPTs
583
+		 * - instantiate the corresponding EE CPT model for the post_type being processed.
584
+		 */
585
+		if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
586
+			/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
587
+			$custom_post_types = $this->loader->getShared(
588
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
589
+			);
590
+			$custom_post_types->getCustomPostTypeModels($_POST['post_type']);
591
+		}
592
+
593
+		if (! $this->request->isAjax()) {
594
+			/**
595
+			 * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
596
+			 * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
597
+			 * Pages" tab in the EE General Settings Admin page.
598
+			 * This is for user-proofing.
599
+			 */
600
+			add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
601
+			if (EE_Maintenance_Mode::instance()->models_can_query()) {
602
+				$this->adminInitModelsReady();
603
+			}
604
+		}
605
+	}
606
+
607
+
608
+	/**
609
+	 * Runs on admin_init but only if models are usable (ie, we're not in maintenance mode)
610
+	 */
611
+	protected function adminInitModelsReady()
612
+	{
613
+		if (function_exists('wp_add_privacy_policy_content')) {
614
+			$this->loader->getShared('EventEspresso\core\services\privacy\policy\PrivacyPolicyManager');
615
+		}
616
+	}
617
+
618
+
619
+	/**
620
+	 * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
621
+	 *
622
+	 * @param string $output Current output.
623
+	 * @return string
624
+	 * @throws InvalidArgumentException
625
+	 * @throws InvalidDataTypeException
626
+	 * @throws InvalidInterfaceException
627
+	 */
628
+	public function modify_dropdown_pages($output)
629
+	{
630
+		// get critical pages
631
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
632
+
633
+		// split current output by line break for easier parsing.
634
+		$split_output = explode("\n", $output);
635
+
636
+		// loop through to remove any critical pages from the array.
637
+		foreach ($critical_pages as $page_id) {
638
+			$needle = 'value="' . $page_id . '"';
639
+			foreach ($split_output as $key => $haystack) {
640
+				if (strpos($haystack, $needle) !== false) {
641
+					unset($split_output[ $key ]);
642
+				}
643
+			}
644
+		}
645
+		// replace output with the new contents
646
+		return implode("\n", $split_output);
647
+	}
648
+
649
+
650
+	/**
651
+	 * display_admin_notices
652
+	 *
653
+	 * @return void
654
+	 */
655
+	public function display_admin_notices()
656
+	{
657
+		echo EE_Error::get_notices();
658
+	}
659
+
660
+
661
+	/**
662
+	 * @param array $elements
663
+	 * @return array
664
+	 * @throws EE_Error
665
+	 * @throws InvalidArgumentException
666
+	 * @throws InvalidDataTypeException
667
+	 * @throws InvalidInterfaceException
668
+	 */
669
+	public function dashboard_glance_items($elements)
670
+	{
671
+		$elements = is_array($elements) ? $elements : array($elements);
672
+		$events = EEM_Event::instance()->count();
673
+		$items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(
674
+			array('page' => 'espresso_events'),
675
+			admin_url('admin.php')
676
+		);
677
+		$items['events']['text'] = sprintf(
678
+			esc_html(
679
+				_n('%s Event', '%s Events', $events, 'event_espresso')
680
+			),
681
+			number_format_i18n($events)
682
+		);
683
+		$items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso');
684
+		$registrations = EEM_Registration::instance()->count(
685
+			array(
686
+				array(
687
+					'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
688
+				),
689
+			)
690
+		);
691
+		$items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(
692
+			array('page' => 'espresso_registrations'),
693
+			admin_url('admin.php')
694
+		);
695
+		$items['registrations']['text'] = sprintf(
696
+			esc_html(
697
+				_n('%s Registration', '%s Registrations', $registrations, 'event_espresso')
698
+			),
699
+			number_format_i18n($registrations)
700
+		);
701
+		$items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
702
+
703
+		$items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
704
+
705
+		foreach ($items as $type => $item_properties) {
706
+			$elements[] = sprintf(
707
+				'<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
708
+				$item_properties['url'],
709
+				$item_properties['title'],
710
+				$item_properties['text']
711
+			);
712
+		}
713
+		return $elements;
714
+	}
715
+
716
+
717
+	/**
718
+	 * check_for_invalid_datetime_formats
719
+	 * if an admin changes their date or time format settings on the WP General Settings admin page, verify that
720
+	 * their selected format can be parsed by PHP
721
+	 *
722
+	 * @param    $value
723
+	 * @param    $option
724
+	 * @return    string
725
+	 */
726
+	public function check_for_invalid_datetime_formats($value, $option)
727
+	{
728
+		// check for date_format or time_format
729
+		switch ($option) {
730
+			case 'date_format':
731
+				$date_time_format = $value . ' ' . get_option('time_format');
732
+				break;
733
+			case 'time_format':
734
+				$date_time_format = get_option('date_format') . ' ' . $value;
735
+				break;
736
+			default:
737
+				$date_time_format = false;
738
+		}
739
+		// do we have a date_time format to check ?
740
+		if ($date_time_format) {
741
+			$error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
742
+
743
+			if (is_array($error_msg)) {
744
+				$msg = '<p>'
745
+					   . sprintf(
746
+						   esc_html__(
747
+							   'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
748
+							   'event_espresso'
749
+						   ),
750
+						   date($date_time_format),
751
+						   $date_time_format
752
+					   )
753
+					   . '</p><p><ul>';
754
+
755
+
756
+				foreach ($error_msg as $error) {
757
+					$msg .= '<li>' . $error . '</li>';
758
+				}
759
+
760
+				$msg .= '</ul></p><p>'
761
+						. sprintf(
762
+							esc_html__(
763
+								'%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
764
+								'event_espresso'
765
+							),
766
+							'<span style="color:#D54E21;">',
767
+							'</span>'
768
+						)
769
+						. '</p>';
770
+
771
+				// trigger WP settings error
772
+				add_settings_error(
773
+					'date_format',
774
+					'date_format',
775
+					$msg
776
+				);
777
+
778
+				// set format to something valid
779
+				switch ($option) {
780
+					case 'date_format':
781
+						$value = 'F j, Y';
782
+						break;
783
+					case 'time_format':
784
+						$value = 'g:i a';
785
+						break;
786
+				}
787
+			}
788
+		}
789
+		return $value;
790
+	}
791
+
792
+
793
+	/**
794
+	 * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
795
+	 *
796
+	 * @param $content
797
+	 * @return    string
798
+	 */
799
+	public function its_eSpresso($content)
800
+	{
801
+		return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
802
+	}
803
+
804
+
805
+	/**
806
+	 * espresso_admin_footer
807
+	 *
808
+	 * @return    string
809
+	 */
810
+	public function espresso_admin_footer()
811
+	{
812
+		return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
813
+	}
814
+
815
+
816
+	/**
817
+	 * Hooks into the "post states" filter in a wp post type list table.
818
+	 *
819
+	 * @param array   $post_states
820
+	 * @param WP_Post $post
821
+	 * @return array
822
+	 * @throws InvalidArgumentException
823
+	 * @throws InvalidDataTypeException
824
+	 * @throws InvalidInterfaceException
825
+	 */
826
+	public function displayStateForCriticalPages($post_states, $post)
827
+	{
828
+		$post_states = (array) $post_states;
829
+		if (! $post instanceof WP_Post || $post->post_type !== 'page') {
830
+			return $post_states;
831
+		}
832
+		/** @var EE_Core_Config $config */
833
+		$config = $this->loader->getShared('EE_Config')->core;
834
+		if (in_array($post->ID, $config->get_critical_pages_array(), true)) {
835
+			$post_states[] = sprintf(
836
+				/* Translators: Using company name - Event Espresso Critical Page */
837
+				esc_html__('%s Critical Page', 'event_espresso'),
838
+				'Event Espresso'
839
+			);
840
+		}
841
+		return $post_states;
842
+	}
843
+
844
+
845
+	/**
846
+	 * Show documentation links on the plugins page
847
+	 *
848
+	 * @param mixed $meta Plugin Row Meta
849
+	 * @param mixed $file Plugin Base file
850
+	 * @return array
851
+	 */
852
+	public function addLinksToPluginRowMeta($meta, $file)
853
+	{
854
+		if (EE_PLUGIN_BASENAME === $file) {
855
+			$row_meta = array(
856
+				'docs' => '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4"'
857
+						  . ' aria-label="'
858
+						  . esc_attr__('View Event Espresso documentation', 'event_espresso')
859
+						  . '">'
860
+						  . esc_html__('Docs', 'event_espresso')
861
+						  . '</a>',
862
+				'api'  => '<a href="https://github.com/eventespresso/event-espresso-core/tree/master/docs/C--REST-API"'
863
+						  . ' aria-label="'
864
+						  . esc_attr__('View Event Espresso API docs', 'event_espresso')
865
+						  . '">'
866
+						  . esc_html__('API docs', 'event_espresso')
867
+						  . '</a>',
868
+			);
869
+			return array_merge($meta, $row_meta);
870
+		}
871
+		return (array) $meta;
872
+	}
873
+
874
+	 /**************************************************************************************/
875
+	 /************************************* DEPRECATED *************************************/
876
+	 /**************************************************************************************/
877
+
878
+
879
+	/**
880
+	 * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
881
+	 * EE_Admin_Page route is called.
882
+	 *
883
+	 * @return void
884
+	 */
885
+	public function route_admin_request()
886
+	{
887
+	}
888
+
889
+
890
+	/**
891
+	 * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
892
+	 *
893
+	 * @return void
894
+	 */
895
+	public function wp_loaded()
896
+	{
897
+	}
898
+
899
+
900
+	/**
901
+	 * static method for registering ee admin page.
902
+	 * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
903
+	 *
904
+	 * @param       $page_basename
905
+	 * @param       $page_path
906
+	 * @param array $config
907
+	 * @return void
908
+	 * @throws EE_Error
909
+	 * @see        EE_Register_Admin_Page::register()
910
+	 * @since      4.3.0
911
+	 * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
912
+	 */
913
+	public static function register_ee_admin_page($page_basename, $page_path, $config = [])
914
+	{
915
+		EE_Error::doing_it_wrong(
916
+			__METHOD__,
917
+			sprintf(
918
+				esc_html__(
919
+					'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
920
+					'event_espresso'
921
+				),
922
+				$page_basename
923
+			),
924
+			'4.3'
925
+		);
926
+		if (class_exists('EE_Register_Admin_Page')) {
927
+			$config['page_path'] = $page_path;
928
+		}
929
+		EE_Register_Admin_Page::register($page_basename, $config);
930
+	}
931
+
932
+
933
+	/**
934
+	 * @param int      $post_ID
935
+	 * @param \WP_Post $post
936
+	 * @return void
937
+	 * @deprecated 4.8.41
938
+	 */
939
+	public static function parse_post_content_on_save($post_ID, $post)
940
+	{
941
+		EE_Error::doing_it_wrong(
942
+			__METHOD__,
943
+			esc_html__('Usage is deprecated', 'event_espresso'),
944
+			'4.8.41'
945
+		);
946
+	}
947
+
948
+
949
+	/**
950
+	 * @param  $option
951
+	 * @param  $old_value
952
+	 * @param  $value
953
+	 * @return void
954
+	 * @deprecated 4.8.41
955
+	 */
956
+	public function reset_page_for_posts_on_change($option, $old_value, $value)
957
+	{
958
+		EE_Error::doing_it_wrong(
959
+			__METHOD__,
960
+			esc_html__('Usage is deprecated', 'event_espresso'),
961
+			'4.8.41'
962
+		);
963
+	}
964
+
965
+
966
+	/**
967
+	 * @return void
968
+	 * @deprecated 4.9.27
969
+	 */
970
+	public function get_persistent_admin_notices()
971
+	{
972
+		EE_Error::doing_it_wrong(
973
+			__METHOD__,
974
+			sprintf(
975
+				esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
976
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
977
+			),
978
+			'4.9.27'
979
+		);
980
+	}
981
+
982
+
983
+	/**
984
+	 * @throws InvalidInterfaceException
985
+	 * @throws InvalidDataTypeException
986
+	 * @throws DomainException
987
+	 * @deprecated 4.9.27
988
+	 */
989
+	public function dismiss_ee_nag_notice_callback()
990
+	{
991
+		EE_Error::doing_it_wrong(
992
+			__METHOD__,
993
+			sprintf(
994
+				esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
995
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
996
+			),
997
+			'4.9.27'
998
+		);
999
+		$this->persistent_admin_notice_manager->dismissNotice();
1000
+	}
1001
+
1002
+
1003
+	/**
1004
+	 * @return void
1005
+	 * @deprecated $VID:$
1006
+	 */
1007
+	public function enqueue_admin_scripts()
1008
+	{
1009
+	}
1010
+
1011
+
1012
+
1013
+	/**
1014
+	 * @deprecated $VID:$
1015
+	 */
1016
+	public function get_request()
1017
+	{
1018
+		EE_Error::doing_it_wrong(
1019
+			__METHOD__,
1020
+			sprintf(
1021
+				esc_html__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1022
+				'EventEspresso\core\services\request\Request'
1023
+			),
1024
+			'$VID:$'
1025
+		);
1026
+		EE_Registry::instance()->load_core('Request_Handler');
1027
+	}
1028
+
1029
+	/**
1030
+	 * @deprecated $VID:$
1031
+	 */
1032
+	public function hookIntoWpPluginsPage()
1033
+	{
1034
+	}
1035 1035
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
     public static function instance()
50 50
     {
51 51
         // check if class object is instantiated
52
-        if (! EE_Admin::$_instance instanceof EE_Admin) {
52
+        if ( ! EE_Admin::$_instance instanceof EE_Admin) {
53 53
             EE_Admin::$_instance = new EE_Admin();
54 54
         }
55 55
         return EE_Admin::$_instance;
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
         add_action('admin_notices', array($this, 'display_admin_notices'), 10);
91 91
         add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
92 92
         add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
93
-        if (! $this->request->isAjax()) {
93
+        if ( ! $this->request->isAjax()) {
94 94
             // admin hooks
95 95
             add_filter('plugin_action_links', [$this, 'filter_plugin_actions'], 10, 2);
96 96
             add_filter('admin_footer_text', [$this, 'espresso_admin_footer']);
@@ -110,11 +110,11 @@  discard block
 block discarded – undo
110 110
      */
111 111
     private function _define_all_constants()
112 112
     {
113
-        if (! defined('EE_ADMIN_URL')) {
114
-            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
115
-            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
116
-            define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates/');
117
-            define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
113
+        if ( ! defined('EE_ADMIN_URL')) {
114
+            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/');
115
+            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/');
116
+            define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates/');
117
+            define('WP_ADMIN_PATH', ABSPATH.'wp-admin/');
118 118
             define('WP_AJAX_URL', admin_url('admin-ajax.php'));
119 119
         }
120 120
     }
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
         // set $main_file in stone
133 133
         static $main_file;
134 134
         // if $main_file is not set yet
135
-        if (! $main_file) {
135
+        if ( ! $main_file) {
136 136
             $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
137 137
         }
138 138
         if ($plugin === $main_file) {
@@ -167,9 +167,9 @@  discard block
 block discarded – undo
167 167
     public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
168 168
     {
169 169
         return array(
170
-            'maintenance' => EE_ADMIN_PAGES . 'maintenance/',
171
-            'about'       => EE_ADMIN_PAGES . 'about/',
172
-            'support'     => EE_ADMIN_PAGES . 'support/',
170
+            'maintenance' => EE_ADMIN_PAGES.'maintenance/',
171
+            'about'       => EE_ADMIN_PAGES.'about/',
172
+            'support'     => EE_ADMIN_PAGES.'support/',
173 173
         );
174 174
     }
175 175
 
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
             $this->initModelsReady();
194 194
         }
195 195
         // run the admin page factory but ONLY if we are doing an ee admin ajax request
196
-        if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
196
+        if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
197 197
             try {
198 198
                 // this loads the controller for the admin pages which will setup routing etc
199 199
                 $this->loader->getShared('EE_Admin_Page_Loader');
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
             }
203 203
         }
204 204
         add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
205
-        if (! $this->request->isAjax()) {
205
+        if ( ! $this->request->isAjax()) {
206 206
             // make sure our CPTs and custom taxonomy metaboxes get shown for first time users
207 207
             add_action('admin_head', [$this, 'enable_hidden_ee_nav_menu_metaboxes'], 10);
208 208
             add_action('admin_head', [$this, 'register_custom_nav_menu_boxes'], 10);
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
      */
222 222
     protected function getLoader()
223 223
     {
224
-        if (! $this->loader instanceof LoaderInterface) {
224
+        if ( ! $this->loader instanceof LoaderInterface) {
225 225
             $this->loader = LoaderFactory::getLoader();
226 226
         }
227 227
         return $this->loader;
@@ -291,13 +291,13 @@  discard block
 block discarded – undo
291 291
                     '</strong>',
292 292
                     '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
293 293
                     '</a>',
294
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
294
+                    '<a href="'.EE_Admin_Page::add_query_args_and_nonce(
295 295
                         array(
296 296
                             'page'   => 'espresso_maintenance_settings',
297 297
                             'action' => 'datetime_tools',
298 298
                         ),
299 299
                         admin_url('admin.php')
300
-                    ) . '">'
300
+                    ).'">'
301 301
                 ),
302 302
                 false,
303 303
                 'manage_options',
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
     public function enable_hidden_ee_nav_menu_metaboxes()
344 344
     {
345 345
         global $wp_meta_boxes, $pagenow;
346
-        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
346
+        if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
347 347
             return;
348 348
         }
349 349
         $user = wp_get_current_user();
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
         if (is_array($hidden_meta_boxes)) {
373 373
             foreach ($hidden_meta_boxes as $key => $meta_box_id) {
374 374
                 if (in_array($meta_box_id, $initial_meta_boxes, true)) {
375
-                    unset($hidden_meta_boxes[ $key ]);
375
+                    unset($hidden_meta_boxes[$key]);
376 376
                 }
377 377
             }
378 378
         }
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
      */
413 413
     public function modify_edit_post_link($link, $id)
414 414
     {
415
-        if (! $post = get_post($id)) {
415
+        if ( ! $post = get_post($id)) {
416 416
             return $link;
417 417
         }
418 418
         if ($post->post_type === 'espresso_attendees') {
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
         );
560 560
 
561 561
         foreach ($keys as $key => $value) {
562
-            $menu_item->{$key} = isset($menu_item_values[ $key ]) ? $menu_item_values[ $key ] : $value;
562
+            $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value;
563 563
         }
564 564
         return $menu_item;
565 565
     }
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
             $custom_post_types->getCustomPostTypeModels($_POST['post_type']);
591 591
         }
592 592
 
593
-        if (! $this->request->isAjax()) {
593
+        if ( ! $this->request->isAjax()) {
594 594
             /**
595 595
              * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
596 596
              * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
@@ -635,10 +635,10 @@  discard block
 block discarded – undo
635 635
 
636 636
         // loop through to remove any critical pages from the array.
637 637
         foreach ($critical_pages as $page_id) {
638
-            $needle = 'value="' . $page_id . '"';
638
+            $needle = 'value="'.$page_id.'"';
639 639
             foreach ($split_output as $key => $haystack) {
640 640
                 if (strpos($haystack, $needle) !== false) {
641
-                    unset($split_output[ $key ]);
641
+                    unset($split_output[$key]);
642 642
                 }
643 643
             }
644 644
         }
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
 
705 705
         foreach ($items as $type => $item_properties) {
706 706
             $elements[] = sprintf(
707
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
707
+                '<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>',
708 708
                 $item_properties['url'],
709 709
                 $item_properties['title'],
710 710
                 $item_properties['text']
@@ -728,10 +728,10 @@  discard block
 block discarded – undo
728 728
         // check for date_format or time_format
729 729
         switch ($option) {
730 730
             case 'date_format':
731
-                $date_time_format = $value . ' ' . get_option('time_format');
731
+                $date_time_format = $value.' '.get_option('time_format');
732 732
                 break;
733 733
             case 'time_format':
734
-                $date_time_format = get_option('date_format') . ' ' . $value;
734
+                $date_time_format = get_option('date_format').' '.$value;
735 735
                 break;
736 736
             default:
737 737
                 $date_time_format = false;
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
 
755 755
 
756 756
                 foreach ($error_msg as $error) {
757
-                    $msg .= '<li>' . $error . '</li>';
757
+                    $msg .= '<li>'.$error.'</li>';
758 758
                 }
759 759
 
760 760
                 $msg .= '</ul></p><p>'
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
     public function displayStateForCriticalPages($post_states, $post)
827 827
     {
828 828
         $post_states = (array) $post_states;
829
-        if (! $post instanceof WP_Post || $post->post_type !== 'page') {
829
+        if ( ! $post instanceof WP_Post || $post->post_type !== 'page') {
830 830
             return $post_states;
831 831
         }
832 832
         /** @var EE_Core_Config $config */
Please login to merge, or discard this patch.
core/domain/services/contexts/RequestTypeContextDetector.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
57 57
 
58 58
     /**
59 59
      * @param string $globalRouteCondition
60
-     * @param mixed  $default
60
+     * @param boolean  $default
61 61
      * @return mixed
62 62
      */
63 63
     private function getGlobalRouteCondition($globalRouteCondition, $default)
Please login to merge, or discard this patch.
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -18,201 +18,201 @@
 block discarded – undo
18 18
 class RequestTypeContextDetector
19 19
 {
20 20
 
21
-    /**
22
-     * @var RequestTypeContextFactoryInterface $factory
23
-     */
24
-    private $factory;
25
-
26
-    /**
27
-     * @var RequestInterface $request
28
-     */
29
-    private $request;
30
-
31
-    /**
32
-     * @var array $globalRouteConditions
33
-     */
34
-    private $globalRouteConditions;
35
-
36
-
37
-    /**
38
-     * RequestTypeContextDetector constructor.
39
-     *
40
-     * @param RequestInterface                   $request
41
-     * @param RequestTypeContextFactoryInterface $factory
42
-     * @param array                              $globalRouteConditions an array for injecting values that would
43
-     *                                                                  otherwise be defined as global constants
44
-     *                                                                  or other global variables for the current
45
-     *                                                                  request route such as DOING_AJAX
46
-     */
47
-    public function __construct(
48
-        RequestInterface $request,
49
-        RequestTypeContextFactoryInterface $factory,
50
-        array $globalRouteConditions = array()
51
-    ) {
52
-        $this->request = $request;
53
-        $this->factory = $factory;
54
-        $this->globalRouteConditions = $globalRouteConditions;
55
-    }
56
-
57
-
58
-    /**
59
-     * @param string $globalRouteCondition
60
-     * @param mixed  $default
61
-     * @return mixed
62
-     */
63
-    private function getGlobalRouteCondition($globalRouteCondition, $default)
64
-    {
65
-        return isset($this->globalRouteConditions[ $globalRouteCondition ])
66
-            ? $this->globalRouteConditions[ $globalRouteCondition ]
67
-            : $default;
68
-    }
69
-
70
-
71
-    /**
72
-     * @return RequestTypeContext
73
-     * @throws InvalidArgumentException
74
-     */
75
-    public function detectRequestTypeContext()
76
-    {
77
-        // Detect error scrapes
78
-        if ($this->getGlobalRouteCondition('EE_TESTS_DIR', false)) {
79
-            return $this->factory->create(RequestTypeContext::UNIT_TEST);
80
-        }
81
-        // Detect error scrapes
82
-        if ($this->request->getRequestParam('wp_scrape_key') !== null
83
-            && $this->request->getRequestParam('wp_scrape_nonce') !== null
84
-        ) {
85
-            return $this->factory->create(RequestTypeContext::WP_SCRAPE);
86
-        }
87
-        // Detect EE REST API
88
-        if ($this->isEspressoRestApiRequest()) {
89
-            return $this->factory->create(RequestTypeContext::API);
90
-        // Detect WP REST API
91
-        }
92
-        if ($this->isWordPressRestApiRequest()) {
93
-            return $this->factory->create(RequestTypeContext::WP_API);
94
-        }
95
-        // Detect EE GraphQL
96
-        if ($this->isEspressoGraphQLRequest()) {
97
-            return $this->factory->create(RequestTypeContext::GQL);
98
-        }
99
-        // Detect AJAX
100
-        if ($this->getGlobalRouteCondition('DOING_AJAX', false)) {
101
-            if (filter_var($this->request->getRequestParam('ee_front_ajax'), FILTER_VALIDATE_BOOLEAN)) {
102
-                return $this->factory->create(RequestTypeContext::AJAX_FRONT);
103
-            }
104
-            if (filter_var($this->request->getRequestParam('ee_admin_ajax'), FILTER_VALIDATE_BOOLEAN)) {
105
-                return $this->factory->create(RequestTypeContext::AJAX_ADMIN);
106
-            }
107
-            if ($this->request->getRequestParam('action') === 'heartbeat') {
108
-                return $this->factory->create(RequestTypeContext::AJAX_HEARTBEAT);
109
-            }
110
-            return $this->factory->create(RequestTypeContext::AJAX_OTHER);
111
-        }
112
-        // Detect WP_Cron
113
-        if ($this->isCronRequest()) {
114
-            return $this->factory->create(RequestTypeContext::CRON);
115
-        }
116
-        // Detect command line requests
117
-        if ($this->getGlobalRouteCondition('WP_CLI', false)) {
118
-            return $this->factory->create(RequestTypeContext::CLI);
119
-        }
120
-        // detect WordPress admin (ie: "Dashboard")
121
-        if ($this->getGlobalRouteCondition('is_admin', false)) {
122
-            return $this->factory->create(RequestTypeContext::ADMIN);
123
-        }
124
-        // Detect iFrames
125
-        if ($this->isIframeRoute()) {
126
-            return $this->factory->create(RequestTypeContext::IFRAME);
127
-        }
128
-        // Detect Feeds
129
-        if ($this->isFeedRequest()) {
130
-            return $this->factory->create(RequestTypeContext::FEED);
131
-        }
132
-        // and by process of elimination...
133
-        return $this->factory->create(RequestTypeContext::FRONTEND);
134
-    }
135
-
136
-
137
-    /**
138
-     * @return bool
139
-     */
140
-    private function isEspressoRestApiRequest()
141
-    {
142
-        // Check for URLs like http://mysite.com/?rest_route=/ee... and http://mysite.com/wp-json/ee/...
143
-        return strpos(
144
-            $this->request->getRequestParam('rest_route', false),
145
-            '/' . Domain::API_NAMESPACE
146
-        ) === 0
147
-            || $this->uriPathMatches(trim(rest_get_url_prefix(), '/') . '/' . Domain::API_NAMESPACE);
148
-    }
149
-
150
-
151
-    /**
152
-     * @return bool
153
-     */
154
-    private function isEspressoGraphQLRequest()
155
-    {
156
-        // Check for URLs like https://mysite.com/graphql
157
-        return $this->uriPathMatches(RequestTypeContext::GQL);
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * @return bool
164
-     */
165
-    private function isWordPressRestApiRequest()
166
-    {
167
-        // Check for URLs like http://mysite.com/?rest_route=/.. and http://mysite.com/wp-json/...
168
-        return $this->request->getRequestParam('rest_route', false)
169
-            || $this->uriPathMatches(trim(rest_get_url_prefix(), '/'));
170
-    }
171
-
172
-
173
-    /**
174
-     * @return bool
175
-     */
176
-    private function isCronRequest()
177
-    {
178
-        return $this->uriPathMatches('wp-cron.php');
179
-    }
180
-
181
-
182
-    /**
183
-     * @return bool
184
-     */
185
-    private function isFeedRequest()
186
-    {
187
-        return $this->uriPathMatches('feed');
188
-    }
189
-
190
-
191
-    /**
192
-     * @param string $component
193
-     * @return bool
194
-     */
195
-    private function uriPathMatches($component)
196
-    {
197
-        $request_uri = $this->request->requestUri(true);
198
-        $parts = explode('?', $request_uri);
199
-        $path = trim(reset($parts), '/');
200
-        return strpos($path, $component) === 0;
201
-    }
202
-
203
-
204
-    /**
205
-     * @return bool
206
-     */
207
-    private function isIframeRoute()
208
-    {
209
-        $is_iframe_route = apply_filters(
210
-            'FHEE__EventEspresso_core_domain_services_contexts_RequestTypeContextDetector__isIframeRoute',
211
-            $this->request->getRequestParam('event_list', '') === 'iframe'
212
-            || $this->request->getRequestParam('ticket_selector', '') === 'iframe'
213
-            || $this->request->getRequestParam('calendar', '') === 'iframe',
214
-            $this
215
-        );
216
-        return filter_var($is_iframe_route, FILTER_VALIDATE_BOOLEAN);
217
-    }
21
+	/**
22
+	 * @var RequestTypeContextFactoryInterface $factory
23
+	 */
24
+	private $factory;
25
+
26
+	/**
27
+	 * @var RequestInterface $request
28
+	 */
29
+	private $request;
30
+
31
+	/**
32
+	 * @var array $globalRouteConditions
33
+	 */
34
+	private $globalRouteConditions;
35
+
36
+
37
+	/**
38
+	 * RequestTypeContextDetector constructor.
39
+	 *
40
+	 * @param RequestInterface                   $request
41
+	 * @param RequestTypeContextFactoryInterface $factory
42
+	 * @param array                              $globalRouteConditions an array for injecting values that would
43
+	 *                                                                  otherwise be defined as global constants
44
+	 *                                                                  or other global variables for the current
45
+	 *                                                                  request route such as DOING_AJAX
46
+	 */
47
+	public function __construct(
48
+		RequestInterface $request,
49
+		RequestTypeContextFactoryInterface $factory,
50
+		array $globalRouteConditions = array()
51
+	) {
52
+		$this->request = $request;
53
+		$this->factory = $factory;
54
+		$this->globalRouteConditions = $globalRouteConditions;
55
+	}
56
+
57
+
58
+	/**
59
+	 * @param string $globalRouteCondition
60
+	 * @param mixed  $default
61
+	 * @return mixed
62
+	 */
63
+	private function getGlobalRouteCondition($globalRouteCondition, $default)
64
+	{
65
+		return isset($this->globalRouteConditions[ $globalRouteCondition ])
66
+			? $this->globalRouteConditions[ $globalRouteCondition ]
67
+			: $default;
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return RequestTypeContext
73
+	 * @throws InvalidArgumentException
74
+	 */
75
+	public function detectRequestTypeContext()
76
+	{
77
+		// Detect error scrapes
78
+		if ($this->getGlobalRouteCondition('EE_TESTS_DIR', false)) {
79
+			return $this->factory->create(RequestTypeContext::UNIT_TEST);
80
+		}
81
+		// Detect error scrapes
82
+		if ($this->request->getRequestParam('wp_scrape_key') !== null
83
+			&& $this->request->getRequestParam('wp_scrape_nonce') !== null
84
+		) {
85
+			return $this->factory->create(RequestTypeContext::WP_SCRAPE);
86
+		}
87
+		// Detect EE REST API
88
+		if ($this->isEspressoRestApiRequest()) {
89
+			return $this->factory->create(RequestTypeContext::API);
90
+		// Detect WP REST API
91
+		}
92
+		if ($this->isWordPressRestApiRequest()) {
93
+			return $this->factory->create(RequestTypeContext::WP_API);
94
+		}
95
+		// Detect EE GraphQL
96
+		if ($this->isEspressoGraphQLRequest()) {
97
+			return $this->factory->create(RequestTypeContext::GQL);
98
+		}
99
+		// Detect AJAX
100
+		if ($this->getGlobalRouteCondition('DOING_AJAX', false)) {
101
+			if (filter_var($this->request->getRequestParam('ee_front_ajax'), FILTER_VALIDATE_BOOLEAN)) {
102
+				return $this->factory->create(RequestTypeContext::AJAX_FRONT);
103
+			}
104
+			if (filter_var($this->request->getRequestParam('ee_admin_ajax'), FILTER_VALIDATE_BOOLEAN)) {
105
+				return $this->factory->create(RequestTypeContext::AJAX_ADMIN);
106
+			}
107
+			if ($this->request->getRequestParam('action') === 'heartbeat') {
108
+				return $this->factory->create(RequestTypeContext::AJAX_HEARTBEAT);
109
+			}
110
+			return $this->factory->create(RequestTypeContext::AJAX_OTHER);
111
+		}
112
+		// Detect WP_Cron
113
+		if ($this->isCronRequest()) {
114
+			return $this->factory->create(RequestTypeContext::CRON);
115
+		}
116
+		// Detect command line requests
117
+		if ($this->getGlobalRouteCondition('WP_CLI', false)) {
118
+			return $this->factory->create(RequestTypeContext::CLI);
119
+		}
120
+		// detect WordPress admin (ie: "Dashboard")
121
+		if ($this->getGlobalRouteCondition('is_admin', false)) {
122
+			return $this->factory->create(RequestTypeContext::ADMIN);
123
+		}
124
+		// Detect iFrames
125
+		if ($this->isIframeRoute()) {
126
+			return $this->factory->create(RequestTypeContext::IFRAME);
127
+		}
128
+		// Detect Feeds
129
+		if ($this->isFeedRequest()) {
130
+			return $this->factory->create(RequestTypeContext::FEED);
131
+		}
132
+		// and by process of elimination...
133
+		return $this->factory->create(RequestTypeContext::FRONTEND);
134
+	}
135
+
136
+
137
+	/**
138
+	 * @return bool
139
+	 */
140
+	private function isEspressoRestApiRequest()
141
+	{
142
+		// Check for URLs like http://mysite.com/?rest_route=/ee... and http://mysite.com/wp-json/ee/...
143
+		return strpos(
144
+			$this->request->getRequestParam('rest_route', false),
145
+			'/' . Domain::API_NAMESPACE
146
+		) === 0
147
+			|| $this->uriPathMatches(trim(rest_get_url_prefix(), '/') . '/' . Domain::API_NAMESPACE);
148
+	}
149
+
150
+
151
+	/**
152
+	 * @return bool
153
+	 */
154
+	private function isEspressoGraphQLRequest()
155
+	{
156
+		// Check for URLs like https://mysite.com/graphql
157
+		return $this->uriPathMatches(RequestTypeContext::GQL);
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * @return bool
164
+	 */
165
+	private function isWordPressRestApiRequest()
166
+	{
167
+		// Check for URLs like http://mysite.com/?rest_route=/.. and http://mysite.com/wp-json/...
168
+		return $this->request->getRequestParam('rest_route', false)
169
+			|| $this->uriPathMatches(trim(rest_get_url_prefix(), '/'));
170
+	}
171
+
172
+
173
+	/**
174
+	 * @return bool
175
+	 */
176
+	private function isCronRequest()
177
+	{
178
+		return $this->uriPathMatches('wp-cron.php');
179
+	}
180
+
181
+
182
+	/**
183
+	 * @return bool
184
+	 */
185
+	private function isFeedRequest()
186
+	{
187
+		return $this->uriPathMatches('feed');
188
+	}
189
+
190
+
191
+	/**
192
+	 * @param string $component
193
+	 * @return bool
194
+	 */
195
+	private function uriPathMatches($component)
196
+	{
197
+		$request_uri = $this->request->requestUri(true);
198
+		$parts = explode('?', $request_uri);
199
+		$path = trim(reset($parts), '/');
200
+		return strpos($path, $component) === 0;
201
+	}
202
+
203
+
204
+	/**
205
+	 * @return bool
206
+	 */
207
+	private function isIframeRoute()
208
+	{
209
+		$is_iframe_route = apply_filters(
210
+			'FHEE__EventEspresso_core_domain_services_contexts_RequestTypeContextDetector__isIframeRoute',
211
+			$this->request->getRequestParam('event_list', '') === 'iframe'
212
+			|| $this->request->getRequestParam('ticket_selector', '') === 'iframe'
213
+			|| $this->request->getRequestParam('calendar', '') === 'iframe',
214
+			$this
215
+		);
216
+		return filter_var($is_iframe_route, FILTER_VALIDATE_BOOLEAN);
217
+	}
218 218
 }
Please login to merge, or discard this patch.
core/EE_System.core.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,6 @@
 block discarded – undo
16 16
 use EventEspresso\core\services\loaders\LoaderInterface;
17 17
 use EventEspresso\core\services\request\RequestInterface;
18 18
 use EventEspresso\core\services\route_match\RouteHandler;
19
-use EventEspresso\core\services\route_match\RouteMatchSpecificationManager;
20 19
 
21 20
 /**
22 21
  * EE_System
Please login to merge, or discard this patch.
Indentation   +1249 added lines, -1249 removed lines patch added patch discarded remove patch
@@ -29,1253 +29,1253 @@
 block discarded – undo
29 29
 final class EE_System implements ResettableInterface
30 30
 {
31 31
 
32
-    /**
33
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
34
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
35
-     */
36
-    const req_type_normal = 0;
37
-
38
-    /**
39
-     * Indicates this is a brand new installation of EE so we should install
40
-     * tables and default data etc
41
-     */
42
-    const req_type_new_activation = 1;
43
-
44
-    /**
45
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
46
-     * and we just exited maintenance mode). We MUST check the database is setup properly
47
-     * and that default data is setup too
48
-     */
49
-    const req_type_reactivation = 2;
50
-
51
-    /**
52
-     * indicates that EE has been upgraded since its previous request.
53
-     * We may have data migration scripts to call and will want to trigger maintenance mode
54
-     */
55
-    const req_type_upgrade = 3;
56
-
57
-    /**
58
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
59
-     */
60
-    const req_type_downgrade = 4;
61
-
62
-    /**
63
-     * @deprecated since version 4.6.0.dev.006
64
-     * Now whenever a new_activation is detected the request type is still just
65
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
66
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
67
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
68
-     * (Specifically, when the migration manager indicates migrations are finished
69
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
70
-     */
71
-    const req_type_activation_but_not_installed = 5;
72
-
73
-    /**
74
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
75
-     */
76
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
77
-
78
-    /**
79
-     * @var EE_System $_instance
80
-     */
81
-    private static $_instance;
82
-
83
-    /**
84
-     * @var EE_Registry $registry
85
-     */
86
-    private $registry;
87
-
88
-    /**
89
-     * @var LoaderInterface $loader
90
-     */
91
-    private $loader;
92
-
93
-    /**
94
-     * @var EE_Capabilities $capabilities
95
-     */
96
-    private $capabilities;
97
-
98
-    /**
99
-     * @var EE_Maintenance_Mode $maintenance_mode
100
-     */
101
-    private $maintenance_mode;
102
-
103
-    /**
104
-     * @var RequestInterface $request
105
-     */
106
-    private $request;
107
-
108
-    /**
109
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
110
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
111
-     *
112
-     * @var int $_req_type
113
-     */
114
-    private $_req_type;
115
-
116
-
117
-    /**
118
-     * @var RouteHandler $router
119
-     */
120
-    private $router;
121
-
122
-    /**
123
-     * Whether or not there was a non-micro version change in EE core version during this request
124
-     *
125
-     * @var boolean $_major_version_change
126
-     */
127
-    private $_major_version_change = false;
128
-
129
-    /**
130
-     * A Context DTO dedicated solely to identifying the current request type.
131
-     *
132
-     * @var RequestTypeContextCheckerInterface $request_type
133
-     */
134
-    private $request_type;
135
-
136
-
137
-    /**
138
-     * @singleton method used to instantiate class object
139
-     * @param EE_Registry|null         $registry
140
-     * @param LoaderInterface|null     $loader
141
-     * @param RequestInterface|null    $request
142
-     * @param EE_Maintenance_Mode|null $maintenance_mode
143
-     * @return EE_System
144
-     */
145
-    public static function instance(
146
-        EE_Registry $registry = null,
147
-        LoaderInterface $loader = null,
148
-        RequestInterface $request = null,
149
-        EE_Maintenance_Mode $maintenance_mode = null
150
-    ) {
151
-        // check if class object is instantiated
152
-        if (! self::$_instance instanceof EE_System) {
153
-            self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
154
-        }
155
-        return self::$_instance;
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
-     * sets hooks for running rest of system
179
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
180
-     * starting EE Addons from any other point may lead to problems
181
-     *
182
-     * @param EE_Registry         $registry
183
-     * @param LoaderInterface     $loader
184
-     * @param RequestInterface    $request
185
-     * @param EE_Maintenance_Mode $maintenance_mode
186
-     */
187
-    private function __construct(
188
-        EE_Registry $registry,
189
-        LoaderInterface $loader,
190
-        RequestInterface $request,
191
-        EE_Maintenance_Mode $maintenance_mode
192
-    ) {
193
-        $this->registry = $registry;
194
-        $this->loader = $loader;
195
-        $this->request = $request;
196
-        $this->maintenance_mode = $maintenance_mode;
197
-        do_action('AHEE__EE_System__construct__begin', $this);
198
-        add_action(
199
-            'AHEE__EE_Bootstrap__load_espresso_addons',
200
-            array($this, 'loadCapabilities'),
201
-            5
202
-        );
203
-        add_action(
204
-            'AHEE__EE_Bootstrap__load_espresso_addons',
205
-            array($this, 'loadCommandBus'),
206
-            7
207
-        );
208
-        add_action(
209
-            'AHEE__EE_Bootstrap__load_espresso_addons',
210
-            array($this, 'loadPluginApi'),
211
-            9
212
-        );
213
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
214
-        add_action(
215
-            'AHEE__EE_Bootstrap__load_espresso_addons',
216
-            array($this, 'load_espresso_addons')
217
-        );
218
-        // when an ee addon is activated, we want to call the core hook(s) again
219
-        // because the newly-activated addon didn't get a chance to run at all
220
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
221
-        // detect whether install or upgrade
222
-        add_action(
223
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
224
-            array($this, 'detect_activations_or_upgrades'),
225
-            3
226
-        );
227
-        // load EE_Config, EE_Textdomain, etc
228
-        add_action(
229
-            'AHEE__EE_Bootstrap__load_core_configuration',
230
-            array($this, 'load_core_configuration'),
231
-            5
232
-        );
233
-        // load specifications for matching routes to current request
234
-        add_action(
235
-            'AHEE__EE_Bootstrap__load_core_configuration',
236
-            array($this, 'loadRouteMatchSpecifications')
237
-        );
238
-        // load EE_Config, EE_Textdomain, etc
239
-        add_action(
240
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
241
-            array($this, 'register_shortcodes_modules_and_widgets'),
242
-            7
243
-        );
244
-        // you wanna get going? I wanna get going... let's get going!
245
-        add_action(
246
-            'AHEE__EE_Bootstrap__brew_espresso',
247
-            array($this, 'brew_espresso'),
248
-            9
249
-        );
250
-        // other housekeeping
251
-        // exclude EE critical pages from wp_list_pages
252
-        add_filter(
253
-            'wp_list_pages_excludes',
254
-            array($this, 'remove_pages_from_wp_list_pages'),
255
-            10
256
-        );
257
-        // ALL EE Addons should use the following hook point to attach their initial setup too
258
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
259
-        do_action('AHEE__EE_System__construct__complete', $this);
260
-    }
261
-
262
-
263
-    /**
264
-     * load and setup EE_Capabilities
265
-     *
266
-     * @return void
267
-     */
268
-    public function loadCapabilities()
269
-    {
270
-        $this->capabilities = $this->loader->getShared('EE_Capabilities');
271
-        add_action(
272
-            'AHEE__EE_Capabilities__init_caps__before_initialization',
273
-            function () {
274
-                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
275
-            }
276
-        );
277
-    }
278
-
279
-
280
-    /**
281
-     * create and cache the CommandBus, and also add middleware
282
-     * The CapChecker middleware requires the use of EE_Capabilities
283
-     * which is why we need to load the CommandBus after Caps are set up
284
-     *
285
-     * @return void
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
-     * @return void
307
-     * @throws EE_Error
308
-     */
309
-    public function loadPluginApi()
310
-    {
311
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
312
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
313
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
314
-        $this->loader->getShared('EE_Request_Handler');
315
-    }
316
-
317
-
318
-    /**
319
-     * @param string $addon_name
320
-     * @param string $version_constant
321
-     * @param string $min_version_required
322
-     * @param string $load_callback
323
-     * @param string $plugin_file_constant
324
-     * @return void
325
-     */
326
-    private function deactivateIncompatibleAddon(
327
-        $addon_name,
328
-        $version_constant,
329
-        $min_version_required,
330
-        $load_callback,
331
-        $plugin_file_constant
332
-    ) {
333
-        if (! defined($version_constant)) {
334
-            return;
335
-        }
336
-        $addon_version = constant($version_constant);
337
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
338
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
339
-            if (! function_exists('deactivate_plugins')) {
340
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
341
-            }
342
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
343
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
344
-            EE_Error::add_error(
345
-                sprintf(
346
-                    esc_html__(
347
-                        '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.',
348
-                        'event_espresso'
349
-                    ),
350
-                    $addon_name,
351
-                    $min_version_required
352
-                ),
353
-                __FILE__,
354
-                __FUNCTION__ . "({$addon_name})",
355
-                __LINE__
356
-            );
357
-            EE_Error::get_notices(false, true);
358
-        }
359
-    }
360
-
361
-
362
-    /**
363
-     * load_espresso_addons
364
-     * allow addons to load first so that they can set hooks for running DMS's, etc
365
-     * this is hooked into both:
366
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
367
-     *        which runs during the WP 'plugins_loaded' action at priority 5
368
-     *    and the WP 'activate_plugin' hook point
369
-     *
370
-     * @access public
371
-     * @return void
372
-     */
373
-    public function load_espresso_addons()
374
-    {
375
-        $this->deactivateIncompatibleAddon(
376
-            'Wait Lists',
377
-            'EE_WAIT_LISTS_VERSION',
378
-            '1.0.0.beta.074',
379
-            'load_espresso_wait_lists',
380
-            'EE_WAIT_LISTS_PLUGIN_FILE'
381
-        );
382
-        $this->deactivateIncompatibleAddon(
383
-            'Automated Upcoming Event Notifications',
384
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
385
-            '1.0.0.beta.091',
386
-            'load_espresso_automated_upcoming_event_notification',
387
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
388
-        );
389
-        do_action('AHEE__EE_System__load_espresso_addons');
390
-        // if the WP API basic auth plugin isn't already loaded, load it now.
391
-        // We want it for mobile apps. Just include the entire plugin
392
-        // also, don't load the basic auth when a plugin is getting activated, because
393
-        // it could be the basic auth plugin, and it doesn't check if its methods are already defined
394
-        // and causes a fatal error
395
-        if (($this->request->isWordPressApi() || $this->request->isApi())
396
-            && $this->request->getRequestParam('activate') !== 'true'
397
-            && ! function_exists('json_basic_auth_handler')
398
-            && ! function_exists('json_basic_auth_error')
399
-            && ! in_array(
400
-                $this->request->getRequestParam('action'),
401
-                array('activate', 'activate-selected'),
402
-                true
403
-            )
404
-        ) {
405
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php';
406
-        }
407
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
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
-     * detect_if_activation_or_upgrade
436
-     * Takes care of detecting whether this is a brand new install or code upgrade,
437
-     * and either setting up the DB or setting up maintenance mode etc.
438
-     *
439
-     * @access public
440
-     * @return void
441
-     */
442
-    public function detect_if_activation_or_upgrade()
443
-    {
444
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
445
-        // check if db has been updated, or if its a brand-new installation
446
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
447
-        $request_type = $this->detect_req_type($espresso_db_update);
448
-        // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
449
-        switch ($request_type) {
450
-            case EE_System::req_type_new_activation:
451
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
452
-                $this->_handle_core_version_change($espresso_db_update);
453
-                break;
454
-            case EE_System::req_type_reactivation:
455
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
456
-                $this->_handle_core_version_change($espresso_db_update);
457
-                break;
458
-            case EE_System::req_type_upgrade:
459
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
460
-                // migrations may be required now that we've upgraded
461
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
462
-                $this->_handle_core_version_change($espresso_db_update);
463
-                break;
464
-            case EE_System::req_type_downgrade:
465
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
466
-                // its possible migrations are no longer required
467
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
468
-                $this->_handle_core_version_change($espresso_db_update);
469
-                break;
470
-            case EE_System::req_type_normal:
471
-            default:
472
-                break;
473
-        }
474
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
475
-    }
476
-
477
-
478
-    /**
479
-     * Updates the list of installed versions and sets hooks for
480
-     * initializing the database later during the request
481
-     *
482
-     * @param array $espresso_db_update
483
-     */
484
-    private function _handle_core_version_change($espresso_db_update)
485
-    {
486
-        $this->update_list_of_installed_versions($espresso_db_update);
487
-        // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
488
-        add_action(
489
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
490
-            array($this, 'initialize_db_if_no_migrations_required')
491
-        );
492
-    }
493
-
494
-
495
-    /**
496
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
497
-     * information about what versions of EE have been installed and activated,
498
-     * NOT necessarily the state of the database
499
-     *
500
-     * @param mixed $espresso_db_update           the value of the WordPress option.
501
-     *                                            If not supplied, fetches it from the options table
502
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
503
-     */
504
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
505
-    {
506
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
507
-        if (! $espresso_db_update) {
508
-            $espresso_db_update = get_option('espresso_db_update');
509
-        }
510
-        // check that option is an array
511
-        if (! is_array($espresso_db_update)) {
512
-            // if option is FALSE, then it never existed
513
-            if ($espresso_db_update === false) {
514
-                // make $espresso_db_update an array and save option with autoload OFF
515
-                $espresso_db_update = array();
516
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
517
-            } else {
518
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
519
-                $espresso_db_update = array($espresso_db_update => array());
520
-                update_option('espresso_db_update', $espresso_db_update);
521
-            }
522
-        } else {
523
-            $corrected_db_update = array();
524
-            // if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
525
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
526
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
527
-                    // the key is an int, and the value IS NOT an array
528
-                    // so it must be numerically-indexed, where values are versions installed...
529
-                    // fix it!
530
-                    $version_string = $should_be_array;
531
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
532
-                } else {
533
-                    // ok it checks out
534
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
535
-                }
536
-            }
537
-            $espresso_db_update = $corrected_db_update;
538
-            update_option('espresso_db_update', $espresso_db_update);
539
-        }
540
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
541
-        return $espresso_db_update;
542
-    }
543
-
544
-
545
-    /**
546
-     * Does the traditional work of setting up the plugin's database and adding default data.
547
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
548
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
549
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
550
-     * so that it will be done when migrations are finished
551
-     *
552
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
553
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
554
-     *                                       This is a resource-intensive job
555
-     *                                       so we prefer to only do it when necessary
556
-     * @return void
557
-     * @throws EE_Error
558
-     */
559
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
560
-    {
561
-        $request_type = $this->detect_req_type();
562
-        // only initialize system if we're not in maintenance mode.
563
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
564
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
565
-            $rewrite_rules = $this->loader->getShared(
566
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
567
-            );
568
-            $rewrite_rules->flush();
569
-            if ($verify_schema) {
570
-                EEH_Activation::initialize_db_and_folders();
571
-            }
572
-            EEH_Activation::initialize_db_content();
573
-            EEH_Activation::system_initialization();
574
-            if ($initialize_addons_too) {
575
-                $this->initialize_addons();
576
-            }
577
-        } else {
578
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
579
-        }
580
-        if ($request_type === EE_System::req_type_new_activation
581
-            || $request_type === EE_System::req_type_reactivation
582
-            || (
583
-                $request_type === EE_System::req_type_upgrade
584
-                && $this->is_major_version_change()
585
-            )
586
-        ) {
587
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
588
-        }
589
-    }
590
-
591
-
592
-    /**
593
-     * Initializes the db for all registered addons
594
-     *
595
-     * @throws EE_Error
596
-     */
597
-    public function initialize_addons()
598
-    {
599
-        // foreach registered addon, make sure its db is up-to-date too
600
-        foreach ($this->registry->addons as $addon) {
601
-            if ($addon instanceof EE_Addon) {
602
-                $addon->initialize_db_if_no_migrations_required();
603
-            }
604
-        }
605
-    }
606
-
607
-
608
-    /**
609
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
610
-     *
611
-     * @param    array  $version_history
612
-     * @param    string $current_version_to_add version to be added to the version history
613
-     * @return    boolean success as to whether or not this option was changed
614
-     */
615
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
616
-    {
617
-        if (! $version_history) {
618
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
619
-        }
620
-        if ($current_version_to_add === null) {
621
-            $current_version_to_add = espresso_version();
622
-        }
623
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
624
-        // re-save
625
-        return update_option('espresso_db_update', $version_history);
626
-    }
627
-
628
-
629
-    /**
630
-     * Detects if the current version indicated in the has existed in the list of
631
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
632
-     *
633
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
634
-     *                                  If not supplied, fetches it from the options table.
635
-     *                                  Also, caches its result so later parts of the code can also know whether
636
-     *                                  there's been an update or not. This way we can add the current version to
637
-     *                                  espresso_db_update, but still know if this is a new install or not
638
-     * @return int one of the constants on EE_System::req_type_
639
-     */
640
-    public function detect_req_type($espresso_db_update = null)
641
-    {
642
-        if ($this->_req_type === null) {
643
-            $espresso_db_update = ! empty($espresso_db_update)
644
-                ? $espresso_db_update
645
-                : $this->fix_espresso_db_upgrade_option();
646
-            $this->_req_type = EE_System::detect_req_type_given_activation_history(
647
-                $espresso_db_update,
648
-                'ee_espresso_activation',
649
-                espresso_version()
650
-            );
651
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
652
-            $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
653
-        }
654
-        return $this->_req_type;
655
-    }
656
-
657
-
658
-    /**
659
-     * Returns whether or not there was a non-micro version change (ie, change in either
660
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
661
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
662
-     *
663
-     * @param $activation_history
664
-     * @return bool
665
-     */
666
-    private function _detect_major_version_change($activation_history)
667
-    {
668
-        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
669
-        $previous_version_parts = explode('.', $previous_version);
670
-        $current_version_parts = explode('.', espresso_version());
671
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
672
-               && (
673
-                   $previous_version_parts[0] !== $current_version_parts[0]
674
-                   || $previous_version_parts[1] !== $current_version_parts[1]
675
-               );
676
-    }
677
-
678
-
679
-    /**
680
-     * Returns true if either the major or minor version of EE changed during this request.
681
-     * 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
682
-     *
683
-     * @return bool
684
-     */
685
-    public function is_major_version_change()
686
-    {
687
-        return $this->_major_version_change;
688
-    }
689
-
690
-
691
-    /**
692
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
693
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
694
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
695
-     * just activated to (for core that will always be espresso_version())
696
-     *
697
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
698
-     *                                                 ee plugin. for core that's 'espresso_db_update'
699
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
700
-     *                                                 indicate that this plugin was just activated
701
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
702
-     *                                                 espresso_version())
703
-     * @return int one of the constants on EE_System::req_type_*
704
-     */
705
-    public static function detect_req_type_given_activation_history(
706
-        $activation_history_for_addon,
707
-        $activation_indicator_option_name,
708
-        $version_to_upgrade_to
709
-    ) {
710
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
711
-        if ($activation_history_for_addon) {
712
-            // it exists, so this isn't a completely new install
713
-            // check if this version already in that list of previously installed versions
714
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
715
-                // it a version we haven't seen before
716
-                if ($version_is_higher === 1) {
717
-                    $req_type = EE_System::req_type_upgrade;
718
-                } else {
719
-                    $req_type = EE_System::req_type_downgrade;
720
-                }
721
-                delete_option($activation_indicator_option_name);
722
-            } else {
723
-                // its not an update. maybe a reactivation?
724
-                if (get_option($activation_indicator_option_name, false)) {
725
-                    if ($version_is_higher === -1) {
726
-                        $req_type = EE_System::req_type_downgrade;
727
-                    } elseif ($version_is_higher === 0) {
728
-                        // we've seen this version before, but it's an activation. must be a reactivation
729
-                        $req_type = EE_System::req_type_reactivation;
730
-                    } else {// $version_is_higher === 1
731
-                        $req_type = EE_System::req_type_upgrade;
732
-                    }
733
-                    delete_option($activation_indicator_option_name);
734
-                } else {
735
-                    // we've seen this version before and the activation indicate doesn't show it was just activated
736
-                    if ($version_is_higher === -1) {
737
-                        $req_type = EE_System::req_type_downgrade;
738
-                    } elseif ($version_is_higher === 0) {
739
-                        // we've seen this version before and it's not an activation. its normal request
740
-                        $req_type = EE_System::req_type_normal;
741
-                    } else {// $version_is_higher === 1
742
-                        $req_type = EE_System::req_type_upgrade;
743
-                    }
744
-                }
745
-            }
746
-        } else {
747
-            // brand new install
748
-            $req_type = EE_System::req_type_new_activation;
749
-            delete_option($activation_indicator_option_name);
750
-        }
751
-        return $req_type;
752
-    }
753
-
754
-
755
-    /**
756
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
757
-     * the $activation_history_for_addon
758
-     *
759
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
760
-     *                                             sometimes containing 'unknown-date'
761
-     * @param string $version_to_upgrade_to        (current version)
762
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
763
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
764
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
765
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
766
-     */
767
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
768
-    {
769
-        // find the most recently-activated version
770
-        $most_recently_active_version =
771
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
772
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
773
-    }
774
-
775
-
776
-    /**
777
-     * Gets the most recently active version listed in the activation history,
778
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
779
-     *
780
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
781
-     *                                   sometimes containing 'unknown-date'
782
-     * @return string
783
-     */
784
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
785
-    {
786
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
787
-        $most_recently_active_version = '0.0.0.dev.000';
788
-        if (is_array($activation_history)) {
789
-            foreach ($activation_history as $version => $times_activated) {
790
-                // check there is a record of when this version was activated. Otherwise,
791
-                // mark it as unknown
792
-                if (! $times_activated) {
793
-                    $times_activated = array('unknown-date');
794
-                }
795
-                if (is_string($times_activated)) {
796
-                    $times_activated = array($times_activated);
797
-                }
798
-                foreach ($times_activated as $an_activation) {
799
-                    if ($an_activation !== 'unknown-date'
800
-                        && $an_activation
801
-                           > $most_recently_active_version_activation) {
802
-                        $most_recently_active_version = $version;
803
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
804
-                            ? '1970-01-01 00:00:00'
805
-                            : $an_activation;
806
-                    }
807
-                }
808
-            }
809
-        }
810
-        return $most_recently_active_version;
811
-    }
812
-
813
-
814
-    /**
815
-     * This redirects to the about EE page after activation
816
-     *
817
-     * @return void
818
-     */
819
-    public function redirect_to_about_ee()
820
-    {
821
-        $notices = EE_Error::get_notices(false);
822
-        // if current user is an admin and it's not an ajax or rest request
823
-        if (! isset($notices['errors'])
824
-            && $this->request->isAdmin()
825
-            && apply_filters(
826
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
827
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
828
-            )
829
-        ) {
830
-            $query_params = array('page' => 'espresso_about');
831
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
832
-                $query_params['new_activation'] = true;
833
-            }
834
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
835
-                $query_params['reactivation'] = true;
836
-            }
837
-            $url = add_query_arg($query_params, admin_url('admin.php'));
838
-            wp_safe_redirect($url);
839
-            exit();
840
-        }
841
-    }
842
-
843
-
844
-    /**
845
-     * load_core_configuration
846
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
847
-     * which runs during the WP 'plugins_loaded' action at priority 5
848
-     *
849
-     * @return void
850
-     * @throws ReflectionException
851
-     * @throws Exception
852
-     */
853
-    public function load_core_configuration()
854
-    {
855
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
856
-        $this->loader->getShared('EE_Load_Textdomain');
857
-        // load textdomain
858
-        EE_Load_Textdomain::load_textdomain();
859
-        // load caf stuff a chance to play during the activation process too.
860
-        $this->_maybe_brew_regular();
861
-        // load and setup EE_Config and EE_Network_Config
862
-        $config = $this->loader->getShared('EE_Config');
863
-        $this->loader->getShared('EE_Network_Config');
864
-        // setup autoloaders
865
-        // enable logging?
866
-        if ($config->admin->use_remote_logging) {
867
-            $this->loader->getShared('EE_Log');
868
-        }
869
-        // check for activation errors
870
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
871
-        if ($activation_errors) {
872
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
873
-            update_option('ee_plugin_activation_errors', false);
874
-        }
875
-        // get model names
876
-        $this->_parse_model_names();
877
-        // configure custom post type definitions
878
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
879
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
880
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
881
-    }
882
-
883
-
884
-    /**
885
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
886
-     *
887
-     * @return void
888
-     * @throws ReflectionException
889
-     */
890
-    private function _parse_model_names()
891
-    {
892
-        // get all the files in the EE_MODELS folder that end in .model.php
893
-        $models = glob(EE_MODELS . '*.model.php');
894
-        $model_names = array();
895
-        $non_abstract_db_models = array();
896
-        foreach ($models as $model) {
897
-            // get model classname
898
-            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
899
-            $short_name = str_replace('EEM_', '', $classname);
900
-            $reflectionClass = new ReflectionClass($classname);
901
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
902
-                $non_abstract_db_models[ $short_name ] = $classname;
903
-            }
904
-            $model_names[ $short_name ] = $classname;
905
-        }
906
-        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
907
-        $this->registry->non_abstract_db_models = apply_filters(
908
-            'FHEE__EE_System__parse_implemented_model_names',
909
-            $non_abstract_db_models
910
-        );
911
-    }
912
-
913
-
914
-    /**
915
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
916
-     * that need to be setup before our EE_System launches.
917
-     *
918
-     * @return void
919
-     * @throws DomainException
920
-     * @throws InvalidArgumentException
921
-     * @throws InvalidDataTypeException
922
-     * @throws InvalidInterfaceException
923
-     * @throws InvalidClassException
924
-     * @throws InvalidFilePathException
925
-     */
926
-    private function _maybe_brew_regular()
927
-    {
928
-        /** @var Domain $domain */
929
-        $domain = DomainFactory::getShared(
930
-            new FullyQualifiedName(
931
-                'EventEspresso\core\domain\Domain'
932
-            ),
933
-            array(
934
-                new FilePath(EVENT_ESPRESSO_MAIN_FILE),
935
-                Version::fromString(espresso_version()),
936
-            )
937
-        );
938
-        if ($domain->isCaffeinated()) {
939
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
940
-        }
941
-    }
942
-
943
-
944
-    /**
945
-     * @since 4.9.71.p
946
-     * @throws Exception
947
-     */
948
-    public function loadRouteMatchSpecifications()
949
-    {
950
-        try {
951
-            $this->router = $this->loader->getShared('EventEspresso\core\services\route_match\RouteHandler');
952
-        } catch (Exception $exception) {
953
-            new ExceptionStackTraceDisplay($exception);
954
-        }
955
-        do_action('AHEE__EE_System__loadRouteMatchSpecifications');
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
-        $this->router->handleShortcodesRequest();
972
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
973
-        // check for addons using old hook point
974
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
975
-            $this->_incompatible_addon_error();
976
-        }
977
-    }
978
-
979
-
980
-    /**
981
-     * _incompatible_addon_error
982
-     *
983
-     * @access public
984
-     * @return void
985
-     */
986
-    private function _incompatible_addon_error()
987
-    {
988
-        // get array of classes hooking into here
989
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
990
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
991
-        );
992
-        if (! empty($class_names)) {
993
-            $msg = __(
994
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
995
-                'event_espresso'
996
-            );
997
-            $msg .= '<ul>';
998
-            foreach ($class_names as $class_name) {
999
-                $msg .= '<li><b>Event Espresso - '
1000
-                        . str_replace(
1001
-                            array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'),
1002
-                            '',
1003
-                            $class_name
1004
-                        ) . '</b></li>';
1005
-            }
1006
-            $msg .= '</ul>';
1007
-            $msg .= __(
1008
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1009
-                'event_espresso'
1010
-            );
1011
-            // save list of incompatible addons to wp-options for later use
1012
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
1013
-            if (is_admin()) {
1014
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1015
-            }
1016
-        }
1017
-    }
1018
-
1019
-
1020
-    /**
1021
-     * brew_espresso
1022
-     * begins the process of setting hooks for initializing EE in the correct order
1023
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1024
-     * which runs during the WP 'plugins_loaded' action at priority 9
1025
-     *
1026
-     * @return void
1027
-     * @throws Exception
1028
-     */
1029
-    public function brew_espresso()
1030
-    {
1031
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1032
-        // load some final core systems
1033
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
1034
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1035
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
1036
-        add_action('init', array($this, 'load_controllers'), 7);
1037
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
1038
-        add_action('init', array($this, 'initialize'), 10);
1039
-        add_action('init', array($this, 'initialize_last'), 100);
1040
-        $this->router->handlePueRequest();
1041
-        $this->router->handleGQLRequest();
1042
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1043
-    }
1044
-
1045
-
1046
-    /**
1047
-     *    set_hooks_for_core
1048
-     *
1049
-     * @access public
1050
-     * @return    void
1051
-     * @throws EE_Error
1052
-     */
1053
-    public function set_hooks_for_core()
1054
-    {
1055
-        $this->_deactivate_incompatible_addons();
1056
-        do_action('AHEE__EE_System__set_hooks_for_core');
1057
-        $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1058
-        // caps need to be initialized on every request so that capability maps are set.
1059
-        // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1060
-        $this->registry->CAP->init_caps();
1061
-    }
1062
-
1063
-
1064
-    /**
1065
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1066
-     * deactivates any addons considered incompatible with the current version of EE
1067
-     */
1068
-    private function _deactivate_incompatible_addons()
1069
-    {
1070
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
1071
-        if (! empty($incompatible_addons)) {
1072
-            $active_plugins = get_option('active_plugins', array());
1073
-            foreach ($active_plugins as $active_plugin) {
1074
-                foreach ($incompatible_addons as $incompatible_addon) {
1075
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1076
-                        unset($_GET['activate']);
1077
-                        espresso_deactivate_plugin($active_plugin);
1078
-                    }
1079
-                }
1080
-            }
1081
-        }
1082
-    }
1083
-
1084
-
1085
-    /**
1086
-     *    perform_activations_upgrades_and_migrations
1087
-     *
1088
-     * @access public
1089
-     * @return    void
1090
-     */
1091
-    public function perform_activations_upgrades_and_migrations()
1092
-    {
1093
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1094
-    }
1095
-
1096
-
1097
-    /**
1098
-     * @return void
1099
-     * @throws DomainException
1100
-     */
1101
-    public function load_CPTs_and_session()
1102
-    {
1103
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1104
-        /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */
1105
-        $register_custom_taxonomies = $this->loader->getShared(
1106
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
1107
-        );
1108
-        $register_custom_taxonomies->registerCustomTaxonomies();
1109
-        /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
1110
-        $register_custom_post_types = $this->loader->getShared(
1111
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
1112
-        );
1113
-        $register_custom_post_types->registerCustomPostTypes();
1114
-        /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */
1115
-        $register_custom_taxonomy_terms = $this->loader->getShared(
1116
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
1117
-        );
1118
-        $register_custom_taxonomy_terms->registerCustomTaxonomyTerms();
1119
-        // load legacy Custom Post Types and Taxonomies
1120
-        $this->loader->getShared('EE_Register_CPTs');
1121
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1122
-    }
1123
-
1124
-
1125
-    /**
1126
-     * load_controllers
1127
-     * this is the best place to load any additional controllers that needs access to EE core.
1128
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1129
-     * time
1130
-     *
1131
-     * @access public
1132
-     * @return void
1133
-     * @throws Exception
1134
-     */
1135
-    public function load_controllers()
1136
-    {
1137
-        do_action('AHEE__EE_System__load_controllers__start');
1138
-        // let's get it started
1139
-        $this->router->handleControllerRequest();
1140
-        do_action('AHEE__EE_System__load_controllers__complete');
1141
-    }
1142
-
1143
-
1144
-    /**
1145
-     * core_loaded_and_ready
1146
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1147
-     *
1148
-     * @access public
1149
-     * @return void
1150
-     * @throws Exception
1151
-     */
1152
-    public function core_loaded_and_ready()
1153
-    {
1154
-        $this->router->handleAssetManagerRequest();
1155
-        $this->router->handleSessionRequest();
1156
-        // integrate WP_Query with the EE models
1157
-        $this->loader->getShared('EE_CPT_Strategy');
1158
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1159
-        // always load template tags, because it's faster than checking if it's a front-end request, and many page
1160
-        // builders require these even on the front-end
1161
-        require_once EE_PUBLIC . 'template_tags.php';
1162
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1163
-    }
1164
-
1165
-
1166
-    /**
1167
-     * initialize
1168
-     * this is the best place to begin initializing client code
1169
-     *
1170
-     * @access public
1171
-     * @return void
1172
-     */
1173
-    public function initialize()
1174
-    {
1175
-        do_action('AHEE__EE_System__initialize');
1176
-    }
1177
-
1178
-
1179
-    /**
1180
-     * initialize_last
1181
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1182
-     * initialize has done so
1183
-     *
1184
-     * @access public
1185
-     * @return void
1186
-     * @throws Exception
1187
-     */
1188
-    public function initialize_last()
1189
-    {
1190
-        do_action('AHEE__EE_System__initialize_last');
1191
-        /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1192
-        $rewrite_rules = $this->loader->getShared(
1193
-            'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1194
-        );
1195
-        $rewrite_rules->flushRewriteRules();
1196
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1197
-        $this->router->handlePersonalDataRequest();
1198
-    }
1199
-
1200
-
1201
-    /**
1202
-     * @return void
1203
-     */
1204
-    public function addEspressoToolbar()
1205
-    {
1206
-        $this->loader->getShared(
1207
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1208
-            array($this->registry->CAP)
1209
-        );
1210
-    }
1211
-
1212
-
1213
-    /**
1214
-     * do_not_cache
1215
-     * sets no cache headers and defines no cache constants for WP plugins
1216
-     *
1217
-     * @access public
1218
-     * @return void
1219
-     */
1220
-    public static function do_not_cache()
1221
-    {
1222
-        // set no cache constants
1223
-        if (! defined('DONOTCACHEPAGE')) {
1224
-            define('DONOTCACHEPAGE', true);
1225
-        }
1226
-        if (! defined('DONOTCACHCEOBJECT')) {
1227
-            define('DONOTCACHCEOBJECT', true);
1228
-        }
1229
-        if (! defined('DONOTCACHEDB')) {
1230
-            define('DONOTCACHEDB', true);
1231
-        }
1232
-        // add no cache headers
1233
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1234
-        // plus a little extra for nginx and Google Chrome
1235
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1236
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1237
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1238
-    }
1239
-
1240
-
1241
-    /**
1242
-     *    extra_nocache_headers
1243
-     *
1244
-     * @access    public
1245
-     * @param $headers
1246
-     * @return    array
1247
-     */
1248
-    public static function extra_nocache_headers($headers)
1249
-    {
1250
-        // for NGINX
1251
-        $headers['X-Accel-Expires'] = 0;
1252
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1253
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1254
-        return $headers;
1255
-    }
1256
-
1257
-
1258
-    /**
1259
-     *    nocache_headers
1260
-     *
1261
-     * @access    public
1262
-     * @return    void
1263
-     */
1264
-    public static function nocache_headers()
1265
-    {
1266
-        nocache_headers();
1267
-    }
1268
-
1269
-
1270
-    /**
1271
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1272
-     * never returned with the function.
1273
-     *
1274
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1275
-     * @return array
1276
-     */
1277
-    public function remove_pages_from_wp_list_pages($exclude_array)
1278
-    {
1279
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1280
-    }
32
+	/**
33
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
34
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
35
+	 */
36
+	const req_type_normal = 0;
37
+
38
+	/**
39
+	 * Indicates this is a brand new installation of EE so we should install
40
+	 * tables and default data etc
41
+	 */
42
+	const req_type_new_activation = 1;
43
+
44
+	/**
45
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
46
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
47
+	 * and that default data is setup too
48
+	 */
49
+	const req_type_reactivation = 2;
50
+
51
+	/**
52
+	 * indicates that EE has been upgraded since its previous request.
53
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
54
+	 */
55
+	const req_type_upgrade = 3;
56
+
57
+	/**
58
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
59
+	 */
60
+	const req_type_downgrade = 4;
61
+
62
+	/**
63
+	 * @deprecated since version 4.6.0.dev.006
64
+	 * Now whenever a new_activation is detected the request type is still just
65
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
66
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
67
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
68
+	 * (Specifically, when the migration manager indicates migrations are finished
69
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
70
+	 */
71
+	const req_type_activation_but_not_installed = 5;
72
+
73
+	/**
74
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
75
+	 */
76
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
77
+
78
+	/**
79
+	 * @var EE_System $_instance
80
+	 */
81
+	private static $_instance;
82
+
83
+	/**
84
+	 * @var EE_Registry $registry
85
+	 */
86
+	private $registry;
87
+
88
+	/**
89
+	 * @var LoaderInterface $loader
90
+	 */
91
+	private $loader;
92
+
93
+	/**
94
+	 * @var EE_Capabilities $capabilities
95
+	 */
96
+	private $capabilities;
97
+
98
+	/**
99
+	 * @var EE_Maintenance_Mode $maintenance_mode
100
+	 */
101
+	private $maintenance_mode;
102
+
103
+	/**
104
+	 * @var RequestInterface $request
105
+	 */
106
+	private $request;
107
+
108
+	/**
109
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
110
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
111
+	 *
112
+	 * @var int $_req_type
113
+	 */
114
+	private $_req_type;
115
+
116
+
117
+	/**
118
+	 * @var RouteHandler $router
119
+	 */
120
+	private $router;
121
+
122
+	/**
123
+	 * Whether or not there was a non-micro version change in EE core version during this request
124
+	 *
125
+	 * @var boolean $_major_version_change
126
+	 */
127
+	private $_major_version_change = false;
128
+
129
+	/**
130
+	 * A Context DTO dedicated solely to identifying the current request type.
131
+	 *
132
+	 * @var RequestTypeContextCheckerInterface $request_type
133
+	 */
134
+	private $request_type;
135
+
136
+
137
+	/**
138
+	 * @singleton method used to instantiate class object
139
+	 * @param EE_Registry|null         $registry
140
+	 * @param LoaderInterface|null     $loader
141
+	 * @param RequestInterface|null    $request
142
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
143
+	 * @return EE_System
144
+	 */
145
+	public static function instance(
146
+		EE_Registry $registry = null,
147
+		LoaderInterface $loader = null,
148
+		RequestInterface $request = null,
149
+		EE_Maintenance_Mode $maintenance_mode = null
150
+	) {
151
+		// check if class object is instantiated
152
+		if (! self::$_instance instanceof EE_System) {
153
+			self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
154
+		}
155
+		return self::$_instance;
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
+	 * sets hooks for running rest of system
179
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
180
+	 * starting EE Addons from any other point may lead to problems
181
+	 *
182
+	 * @param EE_Registry         $registry
183
+	 * @param LoaderInterface     $loader
184
+	 * @param RequestInterface    $request
185
+	 * @param EE_Maintenance_Mode $maintenance_mode
186
+	 */
187
+	private function __construct(
188
+		EE_Registry $registry,
189
+		LoaderInterface $loader,
190
+		RequestInterface $request,
191
+		EE_Maintenance_Mode $maintenance_mode
192
+	) {
193
+		$this->registry = $registry;
194
+		$this->loader = $loader;
195
+		$this->request = $request;
196
+		$this->maintenance_mode = $maintenance_mode;
197
+		do_action('AHEE__EE_System__construct__begin', $this);
198
+		add_action(
199
+			'AHEE__EE_Bootstrap__load_espresso_addons',
200
+			array($this, 'loadCapabilities'),
201
+			5
202
+		);
203
+		add_action(
204
+			'AHEE__EE_Bootstrap__load_espresso_addons',
205
+			array($this, 'loadCommandBus'),
206
+			7
207
+		);
208
+		add_action(
209
+			'AHEE__EE_Bootstrap__load_espresso_addons',
210
+			array($this, 'loadPluginApi'),
211
+			9
212
+		);
213
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
214
+		add_action(
215
+			'AHEE__EE_Bootstrap__load_espresso_addons',
216
+			array($this, 'load_espresso_addons')
217
+		);
218
+		// when an ee addon is activated, we want to call the core hook(s) again
219
+		// because the newly-activated addon didn't get a chance to run at all
220
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
221
+		// detect whether install or upgrade
222
+		add_action(
223
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
224
+			array($this, 'detect_activations_or_upgrades'),
225
+			3
226
+		);
227
+		// load EE_Config, EE_Textdomain, etc
228
+		add_action(
229
+			'AHEE__EE_Bootstrap__load_core_configuration',
230
+			array($this, 'load_core_configuration'),
231
+			5
232
+		);
233
+		// load specifications for matching routes to current request
234
+		add_action(
235
+			'AHEE__EE_Bootstrap__load_core_configuration',
236
+			array($this, 'loadRouteMatchSpecifications')
237
+		);
238
+		// load EE_Config, EE_Textdomain, etc
239
+		add_action(
240
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
241
+			array($this, 'register_shortcodes_modules_and_widgets'),
242
+			7
243
+		);
244
+		// you wanna get going? I wanna get going... let's get going!
245
+		add_action(
246
+			'AHEE__EE_Bootstrap__brew_espresso',
247
+			array($this, 'brew_espresso'),
248
+			9
249
+		);
250
+		// other housekeeping
251
+		// exclude EE critical pages from wp_list_pages
252
+		add_filter(
253
+			'wp_list_pages_excludes',
254
+			array($this, 'remove_pages_from_wp_list_pages'),
255
+			10
256
+		);
257
+		// ALL EE Addons should use the following hook point to attach their initial setup too
258
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
259
+		do_action('AHEE__EE_System__construct__complete', $this);
260
+	}
261
+
262
+
263
+	/**
264
+	 * load and setup EE_Capabilities
265
+	 *
266
+	 * @return void
267
+	 */
268
+	public function loadCapabilities()
269
+	{
270
+		$this->capabilities = $this->loader->getShared('EE_Capabilities');
271
+		add_action(
272
+			'AHEE__EE_Capabilities__init_caps__before_initialization',
273
+			function () {
274
+				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
275
+			}
276
+		);
277
+	}
278
+
279
+
280
+	/**
281
+	 * create and cache the CommandBus, and also add middleware
282
+	 * The CapChecker middleware requires the use of EE_Capabilities
283
+	 * which is why we need to load the CommandBus after Caps are set up
284
+	 *
285
+	 * @return void
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
+	 * @return void
307
+	 * @throws EE_Error
308
+	 */
309
+	public function loadPluginApi()
310
+	{
311
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
312
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
313
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
314
+		$this->loader->getShared('EE_Request_Handler');
315
+	}
316
+
317
+
318
+	/**
319
+	 * @param string $addon_name
320
+	 * @param string $version_constant
321
+	 * @param string $min_version_required
322
+	 * @param string $load_callback
323
+	 * @param string $plugin_file_constant
324
+	 * @return void
325
+	 */
326
+	private function deactivateIncompatibleAddon(
327
+		$addon_name,
328
+		$version_constant,
329
+		$min_version_required,
330
+		$load_callback,
331
+		$plugin_file_constant
332
+	) {
333
+		if (! defined($version_constant)) {
334
+			return;
335
+		}
336
+		$addon_version = constant($version_constant);
337
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
338
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
339
+			if (! function_exists('deactivate_plugins')) {
340
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
341
+			}
342
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
343
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
344
+			EE_Error::add_error(
345
+				sprintf(
346
+					esc_html__(
347
+						'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.',
348
+						'event_espresso'
349
+					),
350
+					$addon_name,
351
+					$min_version_required
352
+				),
353
+				__FILE__,
354
+				__FUNCTION__ . "({$addon_name})",
355
+				__LINE__
356
+			);
357
+			EE_Error::get_notices(false, true);
358
+		}
359
+	}
360
+
361
+
362
+	/**
363
+	 * load_espresso_addons
364
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
365
+	 * this is hooked into both:
366
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
367
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
368
+	 *    and the WP 'activate_plugin' hook point
369
+	 *
370
+	 * @access public
371
+	 * @return void
372
+	 */
373
+	public function load_espresso_addons()
374
+	{
375
+		$this->deactivateIncompatibleAddon(
376
+			'Wait Lists',
377
+			'EE_WAIT_LISTS_VERSION',
378
+			'1.0.0.beta.074',
379
+			'load_espresso_wait_lists',
380
+			'EE_WAIT_LISTS_PLUGIN_FILE'
381
+		);
382
+		$this->deactivateIncompatibleAddon(
383
+			'Automated Upcoming Event Notifications',
384
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
385
+			'1.0.0.beta.091',
386
+			'load_espresso_automated_upcoming_event_notification',
387
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
388
+		);
389
+		do_action('AHEE__EE_System__load_espresso_addons');
390
+		// if the WP API basic auth plugin isn't already loaded, load it now.
391
+		// We want it for mobile apps. Just include the entire plugin
392
+		// also, don't load the basic auth when a plugin is getting activated, because
393
+		// it could be the basic auth plugin, and it doesn't check if its methods are already defined
394
+		// and causes a fatal error
395
+		if (($this->request->isWordPressApi() || $this->request->isApi())
396
+			&& $this->request->getRequestParam('activate') !== 'true'
397
+			&& ! function_exists('json_basic_auth_handler')
398
+			&& ! function_exists('json_basic_auth_error')
399
+			&& ! in_array(
400
+				$this->request->getRequestParam('action'),
401
+				array('activate', 'activate-selected'),
402
+				true
403
+			)
404
+		) {
405
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php';
406
+		}
407
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
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
+	 * detect_if_activation_or_upgrade
436
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
437
+	 * and either setting up the DB or setting up maintenance mode etc.
438
+	 *
439
+	 * @access public
440
+	 * @return void
441
+	 */
442
+	public function detect_if_activation_or_upgrade()
443
+	{
444
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
445
+		// check if db has been updated, or if its a brand-new installation
446
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
447
+		$request_type = $this->detect_req_type($espresso_db_update);
448
+		// EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
449
+		switch ($request_type) {
450
+			case EE_System::req_type_new_activation:
451
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
452
+				$this->_handle_core_version_change($espresso_db_update);
453
+				break;
454
+			case EE_System::req_type_reactivation:
455
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
456
+				$this->_handle_core_version_change($espresso_db_update);
457
+				break;
458
+			case EE_System::req_type_upgrade:
459
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
460
+				// migrations may be required now that we've upgraded
461
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
462
+				$this->_handle_core_version_change($espresso_db_update);
463
+				break;
464
+			case EE_System::req_type_downgrade:
465
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
466
+				// its possible migrations are no longer required
467
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
468
+				$this->_handle_core_version_change($espresso_db_update);
469
+				break;
470
+			case EE_System::req_type_normal:
471
+			default:
472
+				break;
473
+		}
474
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
475
+	}
476
+
477
+
478
+	/**
479
+	 * Updates the list of installed versions and sets hooks for
480
+	 * initializing the database later during the request
481
+	 *
482
+	 * @param array $espresso_db_update
483
+	 */
484
+	private function _handle_core_version_change($espresso_db_update)
485
+	{
486
+		$this->update_list_of_installed_versions($espresso_db_update);
487
+		// get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
488
+		add_action(
489
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
490
+			array($this, 'initialize_db_if_no_migrations_required')
491
+		);
492
+	}
493
+
494
+
495
+	/**
496
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
497
+	 * information about what versions of EE have been installed and activated,
498
+	 * NOT necessarily the state of the database
499
+	 *
500
+	 * @param mixed $espresso_db_update           the value of the WordPress option.
501
+	 *                                            If not supplied, fetches it from the options table
502
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
503
+	 */
504
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
505
+	{
506
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
507
+		if (! $espresso_db_update) {
508
+			$espresso_db_update = get_option('espresso_db_update');
509
+		}
510
+		// check that option is an array
511
+		if (! is_array($espresso_db_update)) {
512
+			// if option is FALSE, then it never existed
513
+			if ($espresso_db_update === false) {
514
+				// make $espresso_db_update an array and save option with autoload OFF
515
+				$espresso_db_update = array();
516
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
517
+			} else {
518
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
519
+				$espresso_db_update = array($espresso_db_update => array());
520
+				update_option('espresso_db_update', $espresso_db_update);
521
+			}
522
+		} else {
523
+			$corrected_db_update = array();
524
+			// if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
525
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
526
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
527
+					// the key is an int, and the value IS NOT an array
528
+					// so it must be numerically-indexed, where values are versions installed...
529
+					// fix it!
530
+					$version_string = $should_be_array;
531
+					$corrected_db_update[ $version_string ] = array('unknown-date');
532
+				} else {
533
+					// ok it checks out
534
+					$corrected_db_update[ $should_be_version_string ] = $should_be_array;
535
+				}
536
+			}
537
+			$espresso_db_update = $corrected_db_update;
538
+			update_option('espresso_db_update', $espresso_db_update);
539
+		}
540
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
541
+		return $espresso_db_update;
542
+	}
543
+
544
+
545
+	/**
546
+	 * Does the traditional work of setting up the plugin's database and adding default data.
547
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
548
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
549
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
550
+	 * so that it will be done when migrations are finished
551
+	 *
552
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
553
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
554
+	 *                                       This is a resource-intensive job
555
+	 *                                       so we prefer to only do it when necessary
556
+	 * @return void
557
+	 * @throws EE_Error
558
+	 */
559
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
560
+	{
561
+		$request_type = $this->detect_req_type();
562
+		// only initialize system if we're not in maintenance mode.
563
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
564
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
565
+			$rewrite_rules = $this->loader->getShared(
566
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
567
+			);
568
+			$rewrite_rules->flush();
569
+			if ($verify_schema) {
570
+				EEH_Activation::initialize_db_and_folders();
571
+			}
572
+			EEH_Activation::initialize_db_content();
573
+			EEH_Activation::system_initialization();
574
+			if ($initialize_addons_too) {
575
+				$this->initialize_addons();
576
+			}
577
+		} else {
578
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
579
+		}
580
+		if ($request_type === EE_System::req_type_new_activation
581
+			|| $request_type === EE_System::req_type_reactivation
582
+			|| (
583
+				$request_type === EE_System::req_type_upgrade
584
+				&& $this->is_major_version_change()
585
+			)
586
+		) {
587
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
588
+		}
589
+	}
590
+
591
+
592
+	/**
593
+	 * Initializes the db for all registered addons
594
+	 *
595
+	 * @throws EE_Error
596
+	 */
597
+	public function initialize_addons()
598
+	{
599
+		// foreach registered addon, make sure its db is up-to-date too
600
+		foreach ($this->registry->addons as $addon) {
601
+			if ($addon instanceof EE_Addon) {
602
+				$addon->initialize_db_if_no_migrations_required();
603
+			}
604
+		}
605
+	}
606
+
607
+
608
+	/**
609
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
610
+	 *
611
+	 * @param    array  $version_history
612
+	 * @param    string $current_version_to_add version to be added to the version history
613
+	 * @return    boolean success as to whether or not this option was changed
614
+	 */
615
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
616
+	{
617
+		if (! $version_history) {
618
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
619
+		}
620
+		if ($current_version_to_add === null) {
621
+			$current_version_to_add = espresso_version();
622
+		}
623
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
624
+		// re-save
625
+		return update_option('espresso_db_update', $version_history);
626
+	}
627
+
628
+
629
+	/**
630
+	 * Detects if the current version indicated in the has existed in the list of
631
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
632
+	 *
633
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
634
+	 *                                  If not supplied, fetches it from the options table.
635
+	 *                                  Also, caches its result so later parts of the code can also know whether
636
+	 *                                  there's been an update or not. This way we can add the current version to
637
+	 *                                  espresso_db_update, but still know if this is a new install or not
638
+	 * @return int one of the constants on EE_System::req_type_
639
+	 */
640
+	public function detect_req_type($espresso_db_update = null)
641
+	{
642
+		if ($this->_req_type === null) {
643
+			$espresso_db_update = ! empty($espresso_db_update)
644
+				? $espresso_db_update
645
+				: $this->fix_espresso_db_upgrade_option();
646
+			$this->_req_type = EE_System::detect_req_type_given_activation_history(
647
+				$espresso_db_update,
648
+				'ee_espresso_activation',
649
+				espresso_version()
650
+			);
651
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
652
+			$this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
653
+		}
654
+		return $this->_req_type;
655
+	}
656
+
657
+
658
+	/**
659
+	 * Returns whether or not there was a non-micro version change (ie, change in either
660
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
661
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
662
+	 *
663
+	 * @param $activation_history
664
+	 * @return bool
665
+	 */
666
+	private function _detect_major_version_change($activation_history)
667
+	{
668
+		$previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
669
+		$previous_version_parts = explode('.', $previous_version);
670
+		$current_version_parts = explode('.', espresso_version());
671
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
672
+			   && (
673
+				   $previous_version_parts[0] !== $current_version_parts[0]
674
+				   || $previous_version_parts[1] !== $current_version_parts[1]
675
+			   );
676
+	}
677
+
678
+
679
+	/**
680
+	 * Returns true if either the major or minor version of EE changed during this request.
681
+	 * 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
682
+	 *
683
+	 * @return bool
684
+	 */
685
+	public function is_major_version_change()
686
+	{
687
+		return $this->_major_version_change;
688
+	}
689
+
690
+
691
+	/**
692
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
693
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
694
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
695
+	 * just activated to (for core that will always be espresso_version())
696
+	 *
697
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
698
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
699
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
700
+	 *                                                 indicate that this plugin was just activated
701
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
702
+	 *                                                 espresso_version())
703
+	 * @return int one of the constants on EE_System::req_type_*
704
+	 */
705
+	public static function detect_req_type_given_activation_history(
706
+		$activation_history_for_addon,
707
+		$activation_indicator_option_name,
708
+		$version_to_upgrade_to
709
+	) {
710
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
711
+		if ($activation_history_for_addon) {
712
+			// it exists, so this isn't a completely new install
713
+			// check if this version already in that list of previously installed versions
714
+			if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
715
+				// it a version we haven't seen before
716
+				if ($version_is_higher === 1) {
717
+					$req_type = EE_System::req_type_upgrade;
718
+				} else {
719
+					$req_type = EE_System::req_type_downgrade;
720
+				}
721
+				delete_option($activation_indicator_option_name);
722
+			} else {
723
+				// its not an update. maybe a reactivation?
724
+				if (get_option($activation_indicator_option_name, false)) {
725
+					if ($version_is_higher === -1) {
726
+						$req_type = EE_System::req_type_downgrade;
727
+					} elseif ($version_is_higher === 0) {
728
+						// we've seen this version before, but it's an activation. must be a reactivation
729
+						$req_type = EE_System::req_type_reactivation;
730
+					} else {// $version_is_higher === 1
731
+						$req_type = EE_System::req_type_upgrade;
732
+					}
733
+					delete_option($activation_indicator_option_name);
734
+				} else {
735
+					// we've seen this version before and the activation indicate doesn't show it was just activated
736
+					if ($version_is_higher === -1) {
737
+						$req_type = EE_System::req_type_downgrade;
738
+					} elseif ($version_is_higher === 0) {
739
+						// we've seen this version before and it's not an activation. its normal request
740
+						$req_type = EE_System::req_type_normal;
741
+					} else {// $version_is_higher === 1
742
+						$req_type = EE_System::req_type_upgrade;
743
+					}
744
+				}
745
+			}
746
+		} else {
747
+			// brand new install
748
+			$req_type = EE_System::req_type_new_activation;
749
+			delete_option($activation_indicator_option_name);
750
+		}
751
+		return $req_type;
752
+	}
753
+
754
+
755
+	/**
756
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
757
+	 * the $activation_history_for_addon
758
+	 *
759
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
760
+	 *                                             sometimes containing 'unknown-date'
761
+	 * @param string $version_to_upgrade_to        (current version)
762
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
763
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
764
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
765
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
766
+	 */
767
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
768
+	{
769
+		// find the most recently-activated version
770
+		$most_recently_active_version =
771
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
772
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
773
+	}
774
+
775
+
776
+	/**
777
+	 * Gets the most recently active version listed in the activation history,
778
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
779
+	 *
780
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
781
+	 *                                   sometimes containing 'unknown-date'
782
+	 * @return string
783
+	 */
784
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
785
+	{
786
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
787
+		$most_recently_active_version = '0.0.0.dev.000';
788
+		if (is_array($activation_history)) {
789
+			foreach ($activation_history as $version => $times_activated) {
790
+				// check there is a record of when this version was activated. Otherwise,
791
+				// mark it as unknown
792
+				if (! $times_activated) {
793
+					$times_activated = array('unknown-date');
794
+				}
795
+				if (is_string($times_activated)) {
796
+					$times_activated = array($times_activated);
797
+				}
798
+				foreach ($times_activated as $an_activation) {
799
+					if ($an_activation !== 'unknown-date'
800
+						&& $an_activation
801
+						   > $most_recently_active_version_activation) {
802
+						$most_recently_active_version = $version;
803
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
804
+							? '1970-01-01 00:00:00'
805
+							: $an_activation;
806
+					}
807
+				}
808
+			}
809
+		}
810
+		return $most_recently_active_version;
811
+	}
812
+
813
+
814
+	/**
815
+	 * This redirects to the about EE page after activation
816
+	 *
817
+	 * @return void
818
+	 */
819
+	public function redirect_to_about_ee()
820
+	{
821
+		$notices = EE_Error::get_notices(false);
822
+		// if current user is an admin and it's not an ajax or rest request
823
+		if (! isset($notices['errors'])
824
+			&& $this->request->isAdmin()
825
+			&& apply_filters(
826
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
827
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
828
+			)
829
+		) {
830
+			$query_params = array('page' => 'espresso_about');
831
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
832
+				$query_params['new_activation'] = true;
833
+			}
834
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
835
+				$query_params['reactivation'] = true;
836
+			}
837
+			$url = add_query_arg($query_params, admin_url('admin.php'));
838
+			wp_safe_redirect($url);
839
+			exit();
840
+		}
841
+	}
842
+
843
+
844
+	/**
845
+	 * load_core_configuration
846
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
847
+	 * which runs during the WP 'plugins_loaded' action at priority 5
848
+	 *
849
+	 * @return void
850
+	 * @throws ReflectionException
851
+	 * @throws Exception
852
+	 */
853
+	public function load_core_configuration()
854
+	{
855
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
856
+		$this->loader->getShared('EE_Load_Textdomain');
857
+		// load textdomain
858
+		EE_Load_Textdomain::load_textdomain();
859
+		// load caf stuff a chance to play during the activation process too.
860
+		$this->_maybe_brew_regular();
861
+		// load and setup EE_Config and EE_Network_Config
862
+		$config = $this->loader->getShared('EE_Config');
863
+		$this->loader->getShared('EE_Network_Config');
864
+		// setup autoloaders
865
+		// enable logging?
866
+		if ($config->admin->use_remote_logging) {
867
+			$this->loader->getShared('EE_Log');
868
+		}
869
+		// check for activation errors
870
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
871
+		if ($activation_errors) {
872
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
873
+			update_option('ee_plugin_activation_errors', false);
874
+		}
875
+		// get model names
876
+		$this->_parse_model_names();
877
+		// configure custom post type definitions
878
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
879
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
880
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
881
+	}
882
+
883
+
884
+	/**
885
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
886
+	 *
887
+	 * @return void
888
+	 * @throws ReflectionException
889
+	 */
890
+	private function _parse_model_names()
891
+	{
892
+		// get all the files in the EE_MODELS folder that end in .model.php
893
+		$models = glob(EE_MODELS . '*.model.php');
894
+		$model_names = array();
895
+		$non_abstract_db_models = array();
896
+		foreach ($models as $model) {
897
+			// get model classname
898
+			$classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
899
+			$short_name = str_replace('EEM_', '', $classname);
900
+			$reflectionClass = new ReflectionClass($classname);
901
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
902
+				$non_abstract_db_models[ $short_name ] = $classname;
903
+			}
904
+			$model_names[ $short_name ] = $classname;
905
+		}
906
+		$this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
907
+		$this->registry->non_abstract_db_models = apply_filters(
908
+			'FHEE__EE_System__parse_implemented_model_names',
909
+			$non_abstract_db_models
910
+		);
911
+	}
912
+
913
+
914
+	/**
915
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
916
+	 * that need to be setup before our EE_System launches.
917
+	 *
918
+	 * @return void
919
+	 * @throws DomainException
920
+	 * @throws InvalidArgumentException
921
+	 * @throws InvalidDataTypeException
922
+	 * @throws InvalidInterfaceException
923
+	 * @throws InvalidClassException
924
+	 * @throws InvalidFilePathException
925
+	 */
926
+	private function _maybe_brew_regular()
927
+	{
928
+		/** @var Domain $domain */
929
+		$domain = DomainFactory::getShared(
930
+			new FullyQualifiedName(
931
+				'EventEspresso\core\domain\Domain'
932
+			),
933
+			array(
934
+				new FilePath(EVENT_ESPRESSO_MAIN_FILE),
935
+				Version::fromString(espresso_version()),
936
+			)
937
+		);
938
+		if ($domain->isCaffeinated()) {
939
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
940
+		}
941
+	}
942
+
943
+
944
+	/**
945
+	 * @since 4.9.71.p
946
+	 * @throws Exception
947
+	 */
948
+	public function loadRouteMatchSpecifications()
949
+	{
950
+		try {
951
+			$this->router = $this->loader->getShared('EventEspresso\core\services\route_match\RouteHandler');
952
+		} catch (Exception $exception) {
953
+			new ExceptionStackTraceDisplay($exception);
954
+		}
955
+		do_action('AHEE__EE_System__loadRouteMatchSpecifications');
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
+		$this->router->handleShortcodesRequest();
972
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
973
+		// check for addons using old hook point
974
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
975
+			$this->_incompatible_addon_error();
976
+		}
977
+	}
978
+
979
+
980
+	/**
981
+	 * _incompatible_addon_error
982
+	 *
983
+	 * @access public
984
+	 * @return void
985
+	 */
986
+	private function _incompatible_addon_error()
987
+	{
988
+		// get array of classes hooking into here
989
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
990
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
991
+		);
992
+		if (! empty($class_names)) {
993
+			$msg = __(
994
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
995
+				'event_espresso'
996
+			);
997
+			$msg .= '<ul>';
998
+			foreach ($class_names as $class_name) {
999
+				$msg .= '<li><b>Event Espresso - '
1000
+						. str_replace(
1001
+							array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'),
1002
+							'',
1003
+							$class_name
1004
+						) . '</b></li>';
1005
+			}
1006
+			$msg .= '</ul>';
1007
+			$msg .= __(
1008
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1009
+				'event_espresso'
1010
+			);
1011
+			// save list of incompatible addons to wp-options for later use
1012
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
1013
+			if (is_admin()) {
1014
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1015
+			}
1016
+		}
1017
+	}
1018
+
1019
+
1020
+	/**
1021
+	 * brew_espresso
1022
+	 * begins the process of setting hooks for initializing EE in the correct order
1023
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1024
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1025
+	 *
1026
+	 * @return void
1027
+	 * @throws Exception
1028
+	 */
1029
+	public function brew_espresso()
1030
+	{
1031
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1032
+		// load some final core systems
1033
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
1034
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1035
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
1036
+		add_action('init', array($this, 'load_controllers'), 7);
1037
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
1038
+		add_action('init', array($this, 'initialize'), 10);
1039
+		add_action('init', array($this, 'initialize_last'), 100);
1040
+		$this->router->handlePueRequest();
1041
+		$this->router->handleGQLRequest();
1042
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1043
+	}
1044
+
1045
+
1046
+	/**
1047
+	 *    set_hooks_for_core
1048
+	 *
1049
+	 * @access public
1050
+	 * @return    void
1051
+	 * @throws EE_Error
1052
+	 */
1053
+	public function set_hooks_for_core()
1054
+	{
1055
+		$this->_deactivate_incompatible_addons();
1056
+		do_action('AHEE__EE_System__set_hooks_for_core');
1057
+		$this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1058
+		// caps need to be initialized on every request so that capability maps are set.
1059
+		// @see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1060
+		$this->registry->CAP->init_caps();
1061
+	}
1062
+
1063
+
1064
+	/**
1065
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1066
+	 * deactivates any addons considered incompatible with the current version of EE
1067
+	 */
1068
+	private function _deactivate_incompatible_addons()
1069
+	{
1070
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
1071
+		if (! empty($incompatible_addons)) {
1072
+			$active_plugins = get_option('active_plugins', array());
1073
+			foreach ($active_plugins as $active_plugin) {
1074
+				foreach ($incompatible_addons as $incompatible_addon) {
1075
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1076
+						unset($_GET['activate']);
1077
+						espresso_deactivate_plugin($active_plugin);
1078
+					}
1079
+				}
1080
+			}
1081
+		}
1082
+	}
1083
+
1084
+
1085
+	/**
1086
+	 *    perform_activations_upgrades_and_migrations
1087
+	 *
1088
+	 * @access public
1089
+	 * @return    void
1090
+	 */
1091
+	public function perform_activations_upgrades_and_migrations()
1092
+	{
1093
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1094
+	}
1095
+
1096
+
1097
+	/**
1098
+	 * @return void
1099
+	 * @throws DomainException
1100
+	 */
1101
+	public function load_CPTs_and_session()
1102
+	{
1103
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1104
+		/** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */
1105
+		$register_custom_taxonomies = $this->loader->getShared(
1106
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
1107
+		);
1108
+		$register_custom_taxonomies->registerCustomTaxonomies();
1109
+		/** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
1110
+		$register_custom_post_types = $this->loader->getShared(
1111
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
1112
+		);
1113
+		$register_custom_post_types->registerCustomPostTypes();
1114
+		/** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */
1115
+		$register_custom_taxonomy_terms = $this->loader->getShared(
1116
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
1117
+		);
1118
+		$register_custom_taxonomy_terms->registerCustomTaxonomyTerms();
1119
+		// load legacy Custom Post Types and Taxonomies
1120
+		$this->loader->getShared('EE_Register_CPTs');
1121
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1122
+	}
1123
+
1124
+
1125
+	/**
1126
+	 * load_controllers
1127
+	 * this is the best place to load any additional controllers that needs access to EE core.
1128
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1129
+	 * time
1130
+	 *
1131
+	 * @access public
1132
+	 * @return void
1133
+	 * @throws Exception
1134
+	 */
1135
+	public function load_controllers()
1136
+	{
1137
+		do_action('AHEE__EE_System__load_controllers__start');
1138
+		// let's get it started
1139
+		$this->router->handleControllerRequest();
1140
+		do_action('AHEE__EE_System__load_controllers__complete');
1141
+	}
1142
+
1143
+
1144
+	/**
1145
+	 * core_loaded_and_ready
1146
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1147
+	 *
1148
+	 * @access public
1149
+	 * @return void
1150
+	 * @throws Exception
1151
+	 */
1152
+	public function core_loaded_and_ready()
1153
+	{
1154
+		$this->router->handleAssetManagerRequest();
1155
+		$this->router->handleSessionRequest();
1156
+		// integrate WP_Query with the EE models
1157
+		$this->loader->getShared('EE_CPT_Strategy');
1158
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1159
+		// always load template tags, because it's faster than checking if it's a front-end request, and many page
1160
+		// builders require these even on the front-end
1161
+		require_once EE_PUBLIC . 'template_tags.php';
1162
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1163
+	}
1164
+
1165
+
1166
+	/**
1167
+	 * initialize
1168
+	 * this is the best place to begin initializing client code
1169
+	 *
1170
+	 * @access public
1171
+	 * @return void
1172
+	 */
1173
+	public function initialize()
1174
+	{
1175
+		do_action('AHEE__EE_System__initialize');
1176
+	}
1177
+
1178
+
1179
+	/**
1180
+	 * initialize_last
1181
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1182
+	 * initialize has done so
1183
+	 *
1184
+	 * @access public
1185
+	 * @return void
1186
+	 * @throws Exception
1187
+	 */
1188
+	public function initialize_last()
1189
+	{
1190
+		do_action('AHEE__EE_System__initialize_last');
1191
+		/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1192
+		$rewrite_rules = $this->loader->getShared(
1193
+			'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1194
+		);
1195
+		$rewrite_rules->flushRewriteRules();
1196
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1197
+		$this->router->handlePersonalDataRequest();
1198
+	}
1199
+
1200
+
1201
+	/**
1202
+	 * @return void
1203
+	 */
1204
+	public function addEspressoToolbar()
1205
+	{
1206
+		$this->loader->getShared(
1207
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1208
+			array($this->registry->CAP)
1209
+		);
1210
+	}
1211
+
1212
+
1213
+	/**
1214
+	 * do_not_cache
1215
+	 * sets no cache headers and defines no cache constants for WP plugins
1216
+	 *
1217
+	 * @access public
1218
+	 * @return void
1219
+	 */
1220
+	public static function do_not_cache()
1221
+	{
1222
+		// set no cache constants
1223
+		if (! defined('DONOTCACHEPAGE')) {
1224
+			define('DONOTCACHEPAGE', true);
1225
+		}
1226
+		if (! defined('DONOTCACHCEOBJECT')) {
1227
+			define('DONOTCACHCEOBJECT', true);
1228
+		}
1229
+		if (! defined('DONOTCACHEDB')) {
1230
+			define('DONOTCACHEDB', true);
1231
+		}
1232
+		// add no cache headers
1233
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1234
+		// plus a little extra for nginx and Google Chrome
1235
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1236
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1237
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1238
+	}
1239
+
1240
+
1241
+	/**
1242
+	 *    extra_nocache_headers
1243
+	 *
1244
+	 * @access    public
1245
+	 * @param $headers
1246
+	 * @return    array
1247
+	 */
1248
+	public static function extra_nocache_headers($headers)
1249
+	{
1250
+		// for NGINX
1251
+		$headers['X-Accel-Expires'] = 0;
1252
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1253
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1254
+		return $headers;
1255
+	}
1256
+
1257
+
1258
+	/**
1259
+	 *    nocache_headers
1260
+	 *
1261
+	 * @access    public
1262
+	 * @return    void
1263
+	 */
1264
+	public static function nocache_headers()
1265
+	{
1266
+		nocache_headers();
1267
+	}
1268
+
1269
+
1270
+	/**
1271
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1272
+	 * never returned with the function.
1273
+	 *
1274
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1275
+	 * @return array
1276
+	 */
1277
+	public function remove_pages_from_wp_list_pages($exclude_array)
1278
+	{
1279
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1280
+	}
1281 1281
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
         EE_Maintenance_Mode $maintenance_mode = null
150 150
     ) {
151 151
         // check if class object is instantiated
152
-        if (! self::$_instance instanceof EE_System) {
152
+        if ( ! self::$_instance instanceof EE_System) {
153 153
             self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
154 154
         }
155 155
         return self::$_instance;
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
         $this->capabilities = $this->loader->getShared('EE_Capabilities');
271 271
         add_action(
272 272
             'AHEE__EE_Capabilities__init_caps__before_initialization',
273
-            function () {
273
+            function() {
274 274
                 LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
275 275
             }
276 276
         );
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
     {
311 311
         // set autoloaders for all of the classes implementing EEI_Plugin_API
312 312
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
313
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
313
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
314 314
         $this->loader->getShared('EE_Request_Handler');
315 315
     }
316 316
 
@@ -330,14 +330,14 @@  discard block
 block discarded – undo
330 330
         $load_callback,
331 331
         $plugin_file_constant
332 332
     ) {
333
-        if (! defined($version_constant)) {
333
+        if ( ! defined($version_constant)) {
334 334
             return;
335 335
         }
336 336
         $addon_version = constant($version_constant);
337 337
         if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
338 338
             remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
339
-            if (! function_exists('deactivate_plugins')) {
340
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
339
+            if ( ! function_exists('deactivate_plugins')) {
340
+                require_once ABSPATH.'wp-admin/includes/plugin.php';
341 341
             }
342 342
             deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
343 343
             unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
                     $min_version_required
352 352
                 ),
353 353
                 __FILE__,
354
-                __FUNCTION__ . "({$addon_name})",
354
+                __FUNCTION__."({$addon_name})",
355 355
                 __LINE__
356 356
             );
357 357
             EE_Error::get_notices(false, true);
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
                 true
403 403
             )
404 404
         ) {
405
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php';
405
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth/basic-auth.php';
406 406
         }
407 407
         do_action('AHEE__EE_System__load_espresso_addons__complete');
408 408
     }
@@ -504,11 +504,11 @@  discard block
 block discarded – undo
504 504
     private function fix_espresso_db_upgrade_option($espresso_db_update = null)
505 505
     {
506 506
         do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
507
-        if (! $espresso_db_update) {
507
+        if ( ! $espresso_db_update) {
508 508
             $espresso_db_update = get_option('espresso_db_update');
509 509
         }
510 510
         // check that option is an array
511
-        if (! is_array($espresso_db_update)) {
511
+        if ( ! is_array($espresso_db_update)) {
512 512
             // if option is FALSE, then it never existed
513 513
             if ($espresso_db_update === false) {
514 514
                 // make $espresso_db_update an array and save option with autoload OFF
@@ -528,10 +528,10 @@  discard block
 block discarded – undo
528 528
                     // so it must be numerically-indexed, where values are versions installed...
529 529
                     // fix it!
530 530
                     $version_string = $should_be_array;
531
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
531
+                    $corrected_db_update[$version_string] = array('unknown-date');
532 532
                 } else {
533 533
                     // ok it checks out
534
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
534
+                    $corrected_db_update[$should_be_version_string] = $should_be_array;
535 535
                 }
536 536
             }
537 537
             $espresso_db_update = $corrected_db_update;
@@ -614,13 +614,13 @@  discard block
 block discarded – undo
614 614
      */
615 615
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
616 616
     {
617
-        if (! $version_history) {
617
+        if ( ! $version_history) {
618 618
             $version_history = $this->fix_espresso_db_upgrade_option($version_history);
619 619
         }
620 620
         if ($current_version_to_add === null) {
621 621
             $current_version_to_add = espresso_version();
622 622
         }
623
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
623
+        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
624 624
         // re-save
625 625
         return update_option('espresso_db_update', $version_history);
626 626
     }
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
         if ($activation_history_for_addon) {
712 712
             // it exists, so this isn't a completely new install
713 713
             // check if this version already in that list of previously installed versions
714
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
714
+            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
715 715
                 // it a version we haven't seen before
716 716
                 if ($version_is_higher === 1) {
717 717
                     $req_type = EE_System::req_type_upgrade;
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
             foreach ($activation_history as $version => $times_activated) {
790 790
                 // check there is a record of when this version was activated. Otherwise,
791 791
                 // mark it as unknown
792
-                if (! $times_activated) {
792
+                if ( ! $times_activated) {
793 793
                     $times_activated = array('unknown-date');
794 794
                 }
795 795
                 if (is_string($times_activated)) {
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
     {
821 821
         $notices = EE_Error::get_notices(false);
822 822
         // if current user is an admin and it's not an ajax or rest request
823
-        if (! isset($notices['errors'])
823
+        if ( ! isset($notices['errors'])
824 824
             && $this->request->isAdmin()
825 825
             && apply_filters(
826 826
                 'FHEE__EE_System__redirect_to_about_ee__do_redirect',
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
     private function _parse_model_names()
891 891
     {
892 892
         // get all the files in the EE_MODELS folder that end in .model.php
893
-        $models = glob(EE_MODELS . '*.model.php');
893
+        $models = glob(EE_MODELS.'*.model.php');
894 894
         $model_names = array();
895 895
         $non_abstract_db_models = array();
896 896
         foreach ($models as $model) {
@@ -899,9 +899,9 @@  discard block
 block discarded – undo
899 899
             $short_name = str_replace('EEM_', '', $classname);
900 900
             $reflectionClass = new ReflectionClass($classname);
901 901
             if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
902
-                $non_abstract_db_models[ $short_name ] = $classname;
902
+                $non_abstract_db_models[$short_name] = $classname;
903 903
             }
904
-            $model_names[ $short_name ] = $classname;
904
+            $model_names[$short_name] = $classname;
905 905
         }
906 906
         $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
907 907
         $this->registry->non_abstract_db_models = apply_filters(
@@ -936,7 +936,7 @@  discard block
 block discarded – undo
936 936
             )
937 937
         );
938 938
         if ($domain->isCaffeinated()) {
939
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
939
+            require_once EE_CAFF_PATH.'brewing_regular.php';
940 940
         }
941 941
     }
942 942
 
@@ -989,7 +989,7 @@  discard block
 block discarded – undo
989 989
         $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
990 990
             'AHEE__EE_System__register_shortcodes_modules_and_addons'
991 991
         );
992
-        if (! empty($class_names)) {
992
+        if ( ! empty($class_names)) {
993 993
             $msg = __(
994 994
                 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
995 995
                 'event_espresso'
@@ -1001,7 +1001,7 @@  discard block
 block discarded – undo
1001 1001
                             array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'),
1002 1002
                             '',
1003 1003
                             $class_name
1004
-                        ) . '</b></li>';
1004
+                        ).'</b></li>';
1005 1005
             }
1006 1006
             $msg .= '</ul>';
1007 1007
             $msg .= __(
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
     private function _deactivate_incompatible_addons()
1069 1069
     {
1070 1070
         $incompatible_addons = get_option('ee_incompatible_addons', array());
1071
-        if (! empty($incompatible_addons)) {
1071
+        if ( ! empty($incompatible_addons)) {
1072 1072
             $active_plugins = get_option('active_plugins', array());
1073 1073
             foreach ($active_plugins as $active_plugin) {
1074 1074
                 foreach ($incompatible_addons as $incompatible_addon) {
@@ -1158,7 +1158,7 @@  discard block
 block discarded – undo
1158 1158
         do_action('AHEE__EE_System__core_loaded_and_ready');
1159 1159
         // always load template tags, because it's faster than checking if it's a front-end request, and many page
1160 1160
         // builders require these even on the front-end
1161
-        require_once EE_PUBLIC . 'template_tags.php';
1161
+        require_once EE_PUBLIC.'template_tags.php';
1162 1162
         do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1163 1163
     }
1164 1164
 
@@ -1220,13 +1220,13 @@  discard block
 block discarded – undo
1220 1220
     public static function do_not_cache()
1221 1221
     {
1222 1222
         // set no cache constants
1223
-        if (! defined('DONOTCACHEPAGE')) {
1223
+        if ( ! defined('DONOTCACHEPAGE')) {
1224 1224
             define('DONOTCACHEPAGE', true);
1225 1225
         }
1226
-        if (! defined('DONOTCACHCEOBJECT')) {
1226
+        if ( ! defined('DONOTCACHCEOBJECT')) {
1227 1227
             define('DONOTCACHCEOBJECT', true);
1228 1228
         }
1229
-        if (! defined('DONOTCACHEDB')) {
1229
+        if ( ! defined('DONOTCACHEDB')) {
1230 1230
             define('DONOTCACHEDB', true);
1231 1231
         }
1232 1232
         // add no cache headers
Please login to merge, or discard this patch.
modules/events_archive/EED_Events_Archive.module.php 1 patch
Indentation   +1110 added lines, -1110 removed lines patch added patch discarded remove patch
@@ -16,1105 +16,1105 @@  discard block
 block discarded – undo
16 16
 class EED_Events_Archive extends EED_Module
17 17
 {
18 18
 
19
-    const EVENT_DETAILS_PRIORITY = 100;
20
-
21
-    const EVENT_DATETIMES_PRIORITY = 110;
22
-
23
-    const EVENT_TICKETS_PRIORITY = 120;
24
-
25
-    const EVENT_VENUES_PRIORITY = 130;
26
-
27
-
28
-    public static $espresso_event_list_ID = 0;
29
-
30
-    public static $espresso_grid_event_lists = array();
31
-
32
-    /**
33
-     * @type bool $using_get_the_excerpt
34
-     */
35
-    protected static $using_get_the_excerpt = false;
36
-
37
-    /**
38
-     * Used to flag when the event list is being called from an external iframe.
39
-     *
40
-     * @var bool $iframe
41
-     */
42
-    protected static $iframe = false;
43
-
44
-    /**
45
-     * @var EventListIframeEmbedButton $_iframe_embed_button
46
-     */
47
-    private static $_iframe_embed_button;
48
-
49
-    /**
50
-     * @type EE_Template_Part_Manager $template_parts
51
-     */
52
-    protected $template_parts;
53
-
54
-
55
-    /**
56
-     * @return EED_Events_Archive
57
-     */
58
-    public static function instance()
59
-    {
60
-        return parent::get_instance(__CLASS__);
61
-    }
62
-
63
-
64
-    /**
65
-     * set_hooks - for hooking into EE Core, other modules, etc
66
-     *
67
-     * @return void
68
-     * @throws InvalidArgumentException
69
-     * @throws InvalidDataTypeException
70
-     * @throws InvalidInterfaceException
71
-     */
72
-    public static function set_hooks()
73
-    {
74
-        /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */
75
-        $custom_post_type_definitions = LoaderFactory::getLoader()->getShared(
76
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
77
-        );
78
-        $custom_post_types = $custom_post_type_definitions->getDefinitions();
79
-        EE_Config::register_route(
80
-            $custom_post_types['espresso_events']['plural_slug'],
81
-            'Events_Archive',
82
-            'run'
83
-        );
84
-        EE_Config::register_route(
85
-            'event_list',
86
-            'Events_Archive',
87
-            'event_list'
88
-        );
89
-        EE_Config::register_route(
90
-            'iframe',
91
-            'Events_Archive',
92
-            'event_list_iframe',
93
-            'event_list'
94
-        );
95
-        add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2);
96
-    }
97
-
98
-
99
-    /**
100
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
101
-     *
102
-     * @access    public
103
-     * @return    void
104
-     */
105
-    public static function set_hooks_admin()
106
-    {
107
-        add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2);
108
-        // hook into the end of the \EE_Admin_Page::_load_page_dependencies()
109
-        // to load assets for "espresso_events" page on the "default" route (action)
110
-        add_action(
111
-            'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default',
112
-            array('EED_Events_Archive', 'event_list_iframe_embed_button'),
113
-            10
114
-        );
115
-    }
116
-
117
-
118
-    /**
119
-     *    set_definitions
120
-     *
121
-     * @access    public
122
-     * @return    void
123
-     */
124
-    public static function set_definitions()
125
-    {
126
-        define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
127
-        define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/');
128
-    }
129
-
130
-
131
-    /**
132
-     * set up EE_Events_Archive_Config
133
-     */
134
-    protected function set_config()
135
-    {
136
-        $this->set_config_section('template_settings');
137
-        $this->set_config_class('EE_Events_Archive_Config');
138
-        $this->set_config_name('EED_Events_Archive');
139
-    }
140
-
141
-
142
-    /**
143
-     * @return EventListIframeEmbedButton
144
-     */
145
-    public static function get_iframe_embed_button()
146
-    {
147
-        if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) {
148
-            self::$_iframe_embed_button = new EventListIframeEmbedButton();
149
-        }
150
-        return self::$_iframe_embed_button;
151
-    }
152
-
153
-
154
-    /**
155
-     * event_list_iframe_embed_button
156
-     *
157
-     * @return    void
158
-     * @throws EE_Error
159
-     */
160
-    public static function event_list_iframe_embed_button()
161
-    {
162
-        $iframe_embed_button = EED_Events_Archive::get_iframe_embed_button();
163
-        $iframe_embed_button->addEmbedButton();
164
-    }
165
-
166
-
167
-    /**
168
-     *    initialize_template_parts
169
-     *
170
-     * @access    public
171
-     * @param EE_Events_Archive_Config $config
172
-     * @return EE_Template_Part_Manager
173
-     * @throws EE_Error
174
-     */
175
-    public function initialize_template_parts(EE_Events_Archive_Config $config = null)
176
-    {
177
-        $config = $config instanceof EE_Events_Archive_Config ? $config : $this->config();
178
-        EEH_Autoloader::register_template_part_autoloaders();
179
-        $template_parts = new EE_Template_Part_Manager();
180
-        $template_parts->add_template_part(
181
-            'tickets',
182
-            __('Ticket Selector', 'event_espresso'),
183
-            'content-espresso_events-tickets.php',
184
-            $config->display_order_tickets
185
-        );
186
-        $template_parts->add_template_part(
187
-            'datetimes',
188
-            __('Dates and Times', 'event_espresso'),
189
-            'content-espresso_events-datetimes.php',
190
-            $config->display_order_datetimes
191
-        );
192
-        $template_parts->add_template_part(
193
-            'event',
194
-            __('Event Description', 'event_espresso'),
195
-            'content-espresso_events-details.php',
196
-            $config->display_order_event
197
-        );
198
-        $template_parts->add_template_part(
199
-            'venue',
200
-            __('Venue Information', 'event_espresso'),
201
-            'content-espresso_events-venues.php',
202
-            $config->display_order_venue
203
-        );
204
-        do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts);
205
-        return $template_parts;
206
-    }
207
-
208
-
209
-    /**
210
-     *    run - initial module setup - this gets called by the EE_Front_Controller if the module route is found in the
211
-     *    incoming request
212
-     *
213
-     * @access    public
214
-     * @param WP $WP
215
-     * @return    void
216
-     */
217
-    public function run($WP)
218
-    {
219
-        do_action('AHEE__EED_Events_Archive__before_run');
220
-        // ensure valid EE_Events_Archive_Config() object exists
221
-        $this->set_config();
222
-        /** @type EE_Events_Archive_Config $config */
223
-        $config = $this->config();
224
-        // load other required components
225
-        $this->load_event_list_assets();
226
-        // filter the WP posts_join, posts_where, and posts_orderby SQL clauses
227
-        // add query filters
228
-        EEH_Event_Query::add_query_filters();
229
-        // set params that will get used by the filters
230
-        EEH_Event_Query::set_query_params(
231
-            '',    // month
232
-            '',    // category
233
-            $config->display_expired_events,    // show_expired
234
-            'start_date',    // orderby
235
-            'ASC'    // sort
236
-        );
237
-        // check what template is loaded
238
-        add_filter('template_include', array($this, 'template_include'), 999, 1);
239
-    }
240
-
241
-
242
-    /**
243
-     * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting
244
-     *
245
-     * @return    void
246
-     */
247
-    public function event_list()
248
-    {
249
-        // ensure valid EE_Events_Archive_Config() object exists
250
-        $this->set_config();
251
-        // load other required components
252
-        $this->load_event_list_assets();
253
-    }
254
-
255
-
256
-    /**
257
-     * @access    public
258
-     * @return    void
259
-     * @throws EE_Error
260
-     * @throws DomainException
261
-     */
262
-    public function event_list_iframe()
263
-    {
264
-        EED_Events_Archive::$iframe = true;
265
-        $event_list_iframe = new EventsArchiveIframe($this);
266
-        $event_list_iframe->display();
267
-    }
268
-
269
-
270
-    /**
271
-     * @access public
272
-     * @return string
273
-     */
274
-    public static function is_iframe()
275
-    {
276
-        return EED_Events_Archive::$iframe;
277
-    }
278
-
279
-
280
-    /**
281
-     * @access public
282
-     * @return string
283
-     */
284
-    public static function link_target()
285
-    {
286
-        return EED_Events_Archive::$iframe ? ' target="_blank"' : '';
287
-    }
288
-
289
-
290
-    /**
291
-     *    template_include
292
-     *
293
-     * @access    public
294
-     * @param string $template
295
-     * @return    string
296
-     */
297
-    public function template_include($template = '')
298
-    {
299
-        // don't add content filter for dedicated EE child themes or private posts
300
-        if (! EEH_Template::is_espresso_theme()) {
301
-            /** @type EE_Events_Archive_Config $config */
302
-            $config = $this->config();
303
-            // add status banner ?
304
-            if ($config->display_status_banner) {
305
-                add_filter('the_title', array('EED_Events_Archive', 'the_title'), 100, 2);
306
-            }
307
-            // if NOT a custom template
308
-            if (apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false)
309
-                || EE_Registry::instance()
310
-                              ->load_core('Front_Controller')
311
-                              ->get_selected_template() !== 'archive-espresso_events.php'
312
-            ) {
313
-                // don't display entry meta because the existing theme will take care of that
314
-                add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true');
315
-                // load functions.php file for the theme (loaded by WP if using child theme)
316
-                EEH_Template::load_espresso_theme_functions();
317
-                // because we don't know if the theme is using the_excerpt()
318
-                add_filter(
319
-                    'the_excerpt',
320
-                    array('EED_Events_Archive', 'event_details'),
321
-                    EED_Events_Archive::EVENT_DETAILS_PRIORITY
322
-                );
323
-                // or the_content
324
-                add_filter(
325
-                    'the_content',
326
-                    array('EED_Events_Archive', 'event_details'),
327
-                    EED_Events_Archive::EVENT_DETAILS_PRIORITY
328
-                );
329
-                // and just in case they are running get_the_excerpt() which DESTROYS things
330
-                add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1);
331
-                // don't display entry meta because the existing theme will take care of that
332
-                add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
333
-            }
334
-        }
335
-        return $template;
336
-    }
337
-
338
-
339
-    /**
340
-     *    get_the_excerpt - kinda hacky, but if a theme is using get_the_excerpt(), then we need to remove our filters
341
-     *    on the_content()
342
-     *
343
-     * @access    public
344
-     * @param        string $excerpt
345
-     * @return        string
346
-     */
347
-    public static function get_the_excerpt($excerpt = '')
348
-    {
349
-        if (post_password_required()) {
350
-            return $excerpt;
351
-        }
352
-        if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) {
353
-            remove_filter(
354
-                'the_excerpt',
355
-                array('EED_Events_Archive', 'event_details'),
356
-                EED_Events_Archive::EVENT_DETAILS_PRIORITY
357
-            );
358
-            remove_filter(
359
-                'the_content',
360
-                array('EED_Events_Archive', 'event_details'),
361
-                EED_Events_Archive::EVENT_DETAILS_PRIORITY
362
-            );
363
-            $excerpt = EED_Events_Archive::event_details($excerpt);
364
-        } else {
365
-            EED_Events_Archive::$using_get_the_excerpt = true;
366
-            add_filter('wp_trim_excerpt', array('EED_Events_Archive', 'end_get_the_excerpt'), 999, 1);
367
-        }
368
-        return $excerpt;
369
-    }
370
-
371
-
372
-    /**
373
-     * end_get_the_excerpt
374
-     *
375
-     * @access public
376
-     * @param  string $text
377
-     * @return string
378
-     */
379
-    public static function end_get_the_excerpt($text = '')
380
-    {
381
-        EED_Events_Archive::$using_get_the_excerpt = false;
382
-        return $text;
383
-    }
384
-
385
-
386
-    /**
387
-     *    the_title
388
-     *
389
-     * @access        public
390
-     * @param        string $title
391
-     * @param        string $id
392
-     * @return        string
393
-     */
394
-    public static function the_title($title = '', $id = '')
395
-    {
396
-        global $post;
397
-        if ($post instanceof WP_Post) {
398
-            return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID) . $title : $title;
399
-        }
400
-        return $title;
401
-    }
402
-
403
-
404
-    /**
405
-     *    event_details
406
-     *
407
-     * @access    public
408
-     * @param        string $content
409
-     * @return        string
410
-     */
411
-    public static function event_details($content)
412
-    {
413
-        global $post;
414
-        static $current_post_ID = 0;
415
-        if ($current_post_ID !== $post->ID
416
-            && $post->post_type === 'espresso_events'
417
-            && ! EED_Events_Archive::$using_get_the_excerpt
418
-            && ! post_password_required()
419
-            && (
420
-                apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false)
421
-                || ! apply_filters('FHEE__content_espresso_events__template_loaded', false)
422
-            )
423
-        ) {
424
-            // Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
425
-            // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
426
-            // BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
427
-            // We want to allow those plugins to still do their thing and have access to our content, but depending on
428
-            // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
429
-            // so the following allows this filter to be applied multiple times, but only once for real
430
-            $current_post_ID = did_action('loop_start') ? $post->ID : 0;
431
-            if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) {
432
-                $content = EED_Events_Archive::use_sortable_display_order();
433
-            } else {
434
-                $content = EED_Events_Archive::use_filterable_display_order();
435
-            }
436
-        }
437
-        return $content;
438
-    }
439
-
440
-
441
-    /**
442
-     *    use_sortable_display_order
443
-     *
444
-     * @access    protected
445
-     * @return string
446
-     */
447
-    protected static function use_sortable_display_order()
448
-    {
449
-        // no further password checks required atm
450
-        add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true');
451
-        // we need to first remove this callback from being applied to the_content() or the_excerpt()
452
-        // (otherwise it will recurse and blow up the interweb)
453
-        remove_filter(
454
-            'the_excerpt',
455
-            array('EED_Events_Archive', 'event_details'),
456
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
457
-        );
458
-        remove_filter(
459
-            'the_content',
460
-            array('EED_Events_Archive', 'event_details'),
461
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
462
-        );
463
-        remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1);
464
-        // now add additional content depending on whether event is using the_excerpt() or the_content()
465
-        EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts();
466
-        $content = EEH_Template::locate_template('content-espresso_events-details.php');
467
-        $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content);
468
-        // re-add our main filters (or else the next event won't have them)
469
-        add_filter(
470
-            'the_excerpt',
471
-            array('EED_Events_Archive', 'event_details'),
472
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
473
-        );
474
-        add_filter(
475
-            'the_content',
476
-            array('EED_Events_Archive', 'event_details'),
477
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
478
-        );
479
-        add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1);
480
-        remove_filter(
481
-            'FHEE__EED_Events_Archive__event_details__no_post_password_required',
482
-            '__return_true'
483
-        );
484
-        return $content;
485
-    }
486
-
487
-
488
-    /**
489
-     *    use_filterable_display_order
490
-     *
491
-     * @access    protected
492
-     * @return    string
493
-     */
494
-    protected static function use_filterable_display_order()
495
-    {
496
-        // we need to first remove this callback from being applied to the_content()
497
-        // (otherwise it will recurse and blow up the interweb)
498
-        remove_filter(
499
-            'the_excerpt',
500
-            array('EED_Events_Archive', 'event_details'),
501
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
502
-        );
503
-        remove_filter(
504
-            'the_content',
505
-            array('EED_Events_Archive', 'event_details'),
506
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
507
-        );
508
-        remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1);
509
-        // now add additional content depending on whether event is using the_excerpt() or the_content()
510
-        EED_Events_Archive::_add_additional_excerpt_filters();
511
-        EED_Events_Archive::_add_additional_content_filters();
512
-        do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters');
513
-        // now load our template
514
-        $content = EEH_Template::locate_template('content-espresso_events-details.php');
515
-        // re-add our main filters (or else the next event won't have them)
516
-        add_filter(
517
-            'the_excerpt',
518
-            array('EED_Events_Archive', 'event_details'),
519
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
520
-        );
521
-        add_filter(
522
-            'the_content',
523
-            array('EED_Events_Archive', 'event_details'),
524
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
525
-        );
526
-        add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1);
527
-        // but remove the other filters so that they don't get applied to the next post
528
-        EED_Events_Archive::_remove_additional_events_archive_filters();
529
-        do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters');
530
-        // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
531
-        // return ! empty( $template ) ? $template : $content;
532
-        return $content;
533
-    }
534
-
535
-
536
-    /**
537
-     *    event_datetimes - adds datetimes ABOVE content
538
-     *
539
-     * @access    public
540
-     * @param        string $content
541
-     * @return        string
542
-     */
543
-    public static function event_datetimes($content)
544
-    {
545
-        if (post_password_required()) {
546
-            return $content;
547
-        }
548
-        return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
549
-    }
550
-
551
-
552
-    /**
553
-     *    event_tickets - adds tickets ABOVE content (which includes datetimes)
554
-     *
555
-     * @access    public
556
-     * @param        string $content
557
-     * @return        string
558
-     */
559
-    public static function event_tickets($content)
560
-    {
561
-        if (post_password_required()) {
562
-            return $content;
563
-        }
564
-        return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
565
-    }
566
-
567
-
568
-    /**
569
-     *    event_venues - adds venues BELOW content
570
-     *
571
-     * @access    public
572
-     * @param    string $content
573
-     * @return    string
574
-     */
575
-    public static function event_venue($content)
576
-    {
577
-        return EED_Events_Archive::event_venues($content);
578
-    }
579
-
580
-
581
-    /**
582
-     *    event_venues - adds venues BELOW content
583
-     *
584
-     * @access    public
585
-     * @param        string $content
586
-     * @return        string
587
-     */
588
-    public static function event_venues($content)
589
-    {
590
-        if (post_password_required()) {
591
-            return $content;
592
-        }
593
-        return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
594
-    }
595
-
596
-
597
-    /**
598
-     *    _add_additional_content_filters
599
-     *
600
-     * @access    private
601
-     * @return        void
602
-     */
603
-    private static function _add_additional_excerpt_filters()
604
-    {
605
-        add_filter(
606
-            'the_excerpt',
607
-            array('EED_Events_Archive', 'event_datetimes'),
608
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
609
-        );
610
-        add_filter(
611
-            'the_excerpt',
612
-            array('EED_Events_Archive', 'event_tickets'),
613
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
614
-        );
615
-        add_filter(
616
-            'the_excerpt',
617
-            array('EED_Events_Archive', 'event_venues'),
618
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
619
-        );
620
-    }
621
-
622
-
623
-    /**
624
-     *    _add_additional_content_filters
625
-     *
626
-     * @access    private
627
-     * @return        void
628
-     */
629
-    private static function _add_additional_content_filters()
630
-    {
631
-        add_filter(
632
-            'the_content',
633
-            array('EED_Events_Archive', 'event_datetimes'),
634
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
635
-        );
636
-        add_filter(
637
-            'the_content',
638
-            array('EED_Events_Archive', 'event_tickets'),
639
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
640
-        );
641
-        add_filter(
642
-            'the_content',
643
-            array('EED_Events_Archive', 'event_venues'),
644
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
645
-        );
646
-    }
647
-
648
-
649
-    /**
650
-     *    _remove_additional_events_archive_filters
651
-     *
652
-     * @access    private
653
-     * @return        void
654
-     */
655
-    private static function _remove_additional_events_archive_filters()
656
-    {
657
-        remove_filter(
658
-            'the_excerpt',
659
-            array('EED_Events_Archive', 'event_datetimes'),
660
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
661
-        );
662
-        remove_filter(
663
-            'the_excerpt',
664
-            array('EED_Events_Archive', 'event_tickets'),
665
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
666
-        );
667
-        remove_filter(
668
-            'the_excerpt',
669
-            array('EED_Events_Archive', 'event_venues'),
670
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
671
-        );
672
-        remove_filter(
673
-            'the_content',
674
-            array('EED_Events_Archive', 'event_datetimes'),
675
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
676
-        );
677
-        remove_filter(
678
-            'the_content',
679
-            array('EED_Events_Archive', 'event_tickets'),
680
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
681
-        );
682
-        remove_filter(
683
-            'the_content',
684
-            array('EED_Events_Archive', 'event_venues'),
685
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
686
-        );
687
-    }
688
-
689
-
690
-    /**
691
-     *    remove_all_events_archive_filters
692
-     *
693
-     * @access    public
694
-     * @return        void
695
-     */
696
-    public static function remove_all_events_archive_filters()
697
-    {
698
-        // remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
699
-        remove_filter('the_title', array('EED_Events_Archive', 'the_title'), 1);
700
-        remove_filter(
701
-            'the_excerpt',
702
-            array('EED_Events_Archive', 'event_details'),
703
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
704
-        );
705
-        remove_filter(
706
-            'the_excerpt',
707
-            array('EED_Events_Archive', 'event_datetimes'),
708
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
709
-        );
710
-        remove_filter(
711
-            'the_excerpt',
712
-            array('EED_Events_Archive', 'event_tickets'),
713
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
714
-        );
715
-        remove_filter(
716
-            'the_excerpt',
717
-            array('EED_Events_Archive', 'event_venues'),
718
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
719
-        );
720
-        remove_filter(
721
-            'the_content',
722
-            array('EED_Events_Archive', 'event_details'),
723
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
724
-        );
725
-        remove_filter(
726
-            'the_content',
727
-            array('EED_Events_Archive', 'event_datetimes'),
728
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
729
-        );
730
-        remove_filter(
731
-            'the_content',
732
-            array('EED_Events_Archive', 'event_tickets'),
733
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
734
-        );
735
-        remove_filter(
736
-            'the_content',
737
-            array('EED_Events_Archive', 'event_venues'),
738
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
739
-        );
740
-        // don't display entry meta because the existing theme will take care of that
741
-        remove_filter(
742
-            'FHEE__content_espresso_events_details_template__display_entry_meta',
743
-            '__return_false'
744
-        );
745
-    }
746
-
747
-
748
-    /**
749
-     *    load_event_list_assets
750
-     *
751
-     * @access    public
752
-     * @return    void
753
-     */
754
-    public function load_event_list_assets()
755
-    {
756
-        do_action('AHEE__EED_Events_Archive__before_load_assets');
757
-        add_filter('FHEE_load_EE_Session', '__return_true');
758
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
759
-        add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
760
-        if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
761
-            add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
762
-        }
763
-    }
764
-
765
-
766
-    /**
767
-     *    wp_enqueue_scripts
768
-     *
769
-     * @access    public
770
-     * @return    void
771
-     * @throws EE_Error
772
-     */
773
-    public function wp_enqueue_scripts()
774
-    {
775
-        // get some style
776
-        if (apply_filters('FHEE_enable_default_espresso_css', false)) {
777
-            // first check uploads folder
778
-            if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) {
779
-                wp_register_style(
780
-                    $this->theme,
781
-                    get_stylesheet_directory_uri() . $this->theme . '/style.css',
782
-                    array('dashicons', 'espresso_default')
783
-                );
784
-            } else {
785
-            }
786
-            wp_enqueue_style($this->theme);
787
-        }
788
-    }
789
-
790
-
791
-    /**
792
-     *    template_settings_form
793
-     *
794
-     * @access    public
795
-     * @static
796
-     * @return    string
797
-     */
798
-    public static function template_settings_form()
799
-    {
800
-        $template_settings = EE_Registry::instance()->CFG->template_settings;
801
-        $template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive)
802
-            ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config();
803
-        $template_settings->EED_Events_Archive = apply_filters(
804
-            'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
805
-            $template_settings->EED_Events_Archive
806
-        );
807
-        $events_archive_settings = array(
808
-            'display_status_banner' => 0,
809
-            'display_description' => 1,
810
-            'display_ticket_selector' => 0,
811
-            'display_datetimes' => 1,
812
-            'display_venue' => 0,
813
-            'display_expired_events' => 0,
814
-        );
815
-        $events_archive_settings = array_merge(
816
-            $events_archive_settings,
817
-            (array) $template_settings->EED_Events_Archive
818
-        );
819
-        EEH_Template::display_template(
820
-            EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
821
-            $events_archive_settings
822
-        );
823
-    }
824
-
825
-
826
-    /**
827
-     *    update_template_settings
828
-     *
829
-     * @access    public
830
-     * @param    EE_Template_Config $CFG
831
-     * @param    EE_Request_Handler $REQ
832
-     * @return    EE_Template_Config
833
-     */
834
-    public static function update_template_settings($CFG, $REQ)
835
-    {
836
-        $CFG->EED_Events_Archive = new EE_Events_Archive_Config();
837
-        // unless we are resetting the config...
838
-        if (! isset($REQ['EED_Events_Archive_reset_event_list_settings'])
839
-            || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1
840
-        ) {
841
-            $CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner'])
842
-                ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0;
843
-            $CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description'])
844
-                ? absint($REQ['EED_Events_Archive_display_description']) : 1;
845
-            $CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector'])
846
-                ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0;
847
-            $CFG->EED_Events_Archive->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint(
848
-                $REQ['EED_Events_Archive_display_datetimes']
849
-            ) : 1;
850
-            $CFG->EED_Events_Archive->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint(
851
-                $REQ['EED_Events_Archive_display_venue']
852
-            ) : 0;
853
-            $CFG->EED_Events_Archive->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events'])
854
-                ? absint($REQ['EED_Events_Archive_display_expired_events']) : 0;
855
-        }
856
-        return $CFG;
857
-    }
858
-
859
-
860
-    /**
861
-     *    event_list_css
862
-     *
863
-     * @access    public
864
-     * @param string $extra_class
865
-     * @return    string
866
-     */
867
-    public static function event_list_css($extra_class = '')
868
-    {
869
-        $event_list_css = ! empty($extra_class) ? array($extra_class) : array();
870
-        $event_list_css[] = 'espresso-event-list-event';
871
-        return implode(' ', $event_list_css);
872
-    }
873
-
874
-
875
-    /**
876
-     *    event_categories
877
-     *
878
-     * @access    public
879
-     * @return    array
880
-     */
881
-    public static function event_categories()
882
-    {
883
-        return EE_Registry::instance()->load_model('Term')->get_all_ee_categories();
884
-    }
885
-
886
-
887
-    /**
888
-     *    display_description
889
-     *
890
-     * @access    public
891
-     * @param $value
892
-     * @return    bool
893
-     */
894
-    public static function display_description($value)
895
-    {
896
-        $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
897
-        $display_description = isset($config->display_description) ? $config->display_description : 1;
898
-        return $display_description === $value ? true : false;
899
-    }
900
-
901
-
902
-    /**
903
-     *    display_ticket_selector
904
-     *
905
-     * @access    public
906
-     * @return    bool
907
-     */
908
-    public static function display_ticket_selector()
909
-    {
910
-        $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
911
-        return isset($config->display_ticket_selector) && $config->display_ticket_selector ? true : false;
912
-    }
913
-
914
-
915
-    /**
916
-     *    display_venue
917
-     *
918
-     * @access    public
919
-     * @return    bool
920
-     */
921
-    public static function display_venue()
922
-    {
923
-        $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
924
-        return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name() ? true : false;
925
-    }
926
-
927
-
928
-    /**
929
-     *    display_datetimes
930
-     *
931
-     * @access    public
932
-     * @return    bool
933
-     */
934
-    public static function display_datetimes()
935
-    {
936
-        $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
937
-        return isset($config->display_datetimes) && $config->display_datetimes ? true : false;
938
-    }
939
-
940
-
941
-    /**
942
-     *    event_list_title
943
-     *
944
-     * @access    public
945
-     * @return    string
946
-     */
947
-    public static function event_list_title()
948
-    {
949
-        return apply_filters(
950
-            'FHEE__archive_espresso_events_template__upcoming_events_h1',
951
-            __('Upcoming Events', 'event_espresso')
952
-        );
953
-    }
954
-
955
-
956
-    // GRAVEYARD
957
-
958
-
959
-    /**
960
-     * @since 4.4.0
961
-     */
962
-    public static function _doing_it_wrong_notice($function = '')
963
-    {
964
-        EE_Error::doing_it_wrong(
965
-            __FUNCTION__,
966
-            sprintf(
967
-                __(
968
-                    'EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s',
969
-                    'event_espresso'
970
-                ),
971
-                $function,
972
-                '<br />',
973
-                '4.6.0'
974
-            ),
975
-            '4.4.0'
976
-        );
977
-    }
978
-
979
-
980
-    /**
981
-     * @deprecated
982
-     * @since 4.4.0
983
-     */
984
-    public function get_post_data()
985
-    {
986
-        EEH_Event_Query::set_query_params();
987
-    }
988
-
989
-
990
-    /**
991
-     * @throws EE_Error
992
-     * @since 4.4.0
993
-     * @deprecated
994
-     */
995
-    public function posts_fields($SQL, WP_Query $wp_query)
996
-    {
997
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
998
-        return EEH_Event_Query::posts_fields($SQL, $wp_query);
999
-    }
1000
-
1001
-
1002
-    /**
1003
-     * @throws EE_Error
1004
-     * @since 4.4.0
1005
-     * @deprecated
1006
-     */
1007
-    public static function posts_fields_sql_for_orderby($orderby_params = array())
1008
-    {
1009
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1010
-        return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params);
1011
-    }
1012
-
1013
-
1014
-    /**
1015
-     * @throws EE_Error
1016
-     * @since 4.4.0
1017
-     * @deprecated
1018
-     */
1019
-    public function posts_join($SQL, WP_Query $wp_query)
1020
-    {
1021
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1022
-        return EEH_Event_Query::posts_join($SQL, $wp_query);
1023
-    }
1024
-
1025
-
1026
-    /**
1027
-     * @deprecated
1028
-     * @since 4.4.0
1029
-     */
1030
-    public static function posts_join_sql_for_terms($join_terms = null)
1031
-    {
1032
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1033
-        return EEH_Event_Query::posts_join_sql_for_terms($join_terms);
1034
-    }
1035
-
1036
-
1037
-    /**
1038
-     * @throws EE_Error
1039
-     * @since 4.4.0
1040
-     * @deprecated
1041
-     */
1042
-    public static function posts_join_for_orderby($orderby_params = array())
1043
-    {
1044
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1045
-        return EEH_Event_Query::posts_join_for_orderby($orderby_params);
1046
-    }
1047
-
1048
-
1049
-    /**
1050
-     * @throws EE_Error
1051
-     * @since 4.4.0
1052
-     * @deprecated
1053
-     */
1054
-    public function posts_where($SQL, WP_Query $wp_query)
1055
-    {
1056
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1057
-        return EEH_Event_Query::posts_where($SQL, $wp_query);
1058
-    }
1059
-
1060
-
1061
-    /**
1062
-     * @throws EE_Error
1063
-     * @since 4.4.0
1064
-     * @deprecated
1065
-     */
1066
-    public static function posts_where_sql_for_show_expired($show_expired = false)
1067
-    {
1068
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1069
-        return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired);
1070
-    }
1071
-
1072
-
1073
-    /**
1074
-     * @deprecated
1075
-     * @since 4.4.0
1076
-     */
1077
-    public static function posts_where_sql_for_event_category_slug($event_category_slug = null)
1078
-    {
1079
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1080
-        return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug);
1081
-    }
1082
-
1083
-
1084
-    /**
1085
-     * @throws EE_Error
1086
-     * @since 4.4.0
1087
-     * @deprecated
1088
-     */
1089
-    public static function posts_where_sql_for_event_list_month($month = null)
1090
-    {
1091
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1092
-        return EEH_Event_Query::posts_where_sql_for_event_list_month($month);
1093
-    }
1094
-
1095
-
1096
-    /**
1097
-     * @throws EE_Error
1098
-     * @since 4.4.0
1099
-     * @deprecated
1100
-     */
1101
-    public function posts_orderby($SQL, WP_Query $wp_query)
1102
-    {
1103
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1104
-        return EEH_Event_Query::posts_orderby($SQL, $wp_query);
1105
-    }
1106
-
1107
-
1108
-    /**
1109
-     * @throws EE_Error
1110
-     * @since 4.4.0
1111
-     * @deprecated
1112
-     */
1113
-    public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC')
1114
-    {
1115
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1116
-        return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort);
1117
-    }
19
+	const EVENT_DETAILS_PRIORITY = 100;
20
+
21
+	const EVENT_DATETIMES_PRIORITY = 110;
22
+
23
+	const EVENT_TICKETS_PRIORITY = 120;
24
+
25
+	const EVENT_VENUES_PRIORITY = 130;
26
+
27
+
28
+	public static $espresso_event_list_ID = 0;
29
+
30
+	public static $espresso_grid_event_lists = array();
31
+
32
+	/**
33
+	 * @type bool $using_get_the_excerpt
34
+	 */
35
+	protected static $using_get_the_excerpt = false;
36
+
37
+	/**
38
+	 * Used to flag when the event list is being called from an external iframe.
39
+	 *
40
+	 * @var bool $iframe
41
+	 */
42
+	protected static $iframe = false;
43
+
44
+	/**
45
+	 * @var EventListIframeEmbedButton $_iframe_embed_button
46
+	 */
47
+	private static $_iframe_embed_button;
48
+
49
+	/**
50
+	 * @type EE_Template_Part_Manager $template_parts
51
+	 */
52
+	protected $template_parts;
53
+
54
+
55
+	/**
56
+	 * @return EED_Events_Archive
57
+	 */
58
+	public static function instance()
59
+	{
60
+		return parent::get_instance(__CLASS__);
61
+	}
62
+
63
+
64
+	/**
65
+	 * set_hooks - for hooking into EE Core, other modules, etc
66
+	 *
67
+	 * @return void
68
+	 * @throws InvalidArgumentException
69
+	 * @throws InvalidDataTypeException
70
+	 * @throws InvalidInterfaceException
71
+	 */
72
+	public static function set_hooks()
73
+	{
74
+		/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */
75
+		$custom_post_type_definitions = LoaderFactory::getLoader()->getShared(
76
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
77
+		);
78
+		$custom_post_types = $custom_post_type_definitions->getDefinitions();
79
+		EE_Config::register_route(
80
+			$custom_post_types['espresso_events']['plural_slug'],
81
+			'Events_Archive',
82
+			'run'
83
+		);
84
+		EE_Config::register_route(
85
+			'event_list',
86
+			'Events_Archive',
87
+			'event_list'
88
+		);
89
+		EE_Config::register_route(
90
+			'iframe',
91
+			'Events_Archive',
92
+			'event_list_iframe',
93
+			'event_list'
94
+		);
95
+		add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2);
96
+	}
97
+
98
+
99
+	/**
100
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
101
+	 *
102
+	 * @access    public
103
+	 * @return    void
104
+	 */
105
+	public static function set_hooks_admin()
106
+	{
107
+		add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2);
108
+		// hook into the end of the \EE_Admin_Page::_load_page_dependencies()
109
+		// to load assets for "espresso_events" page on the "default" route (action)
110
+		add_action(
111
+			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default',
112
+			array('EED_Events_Archive', 'event_list_iframe_embed_button'),
113
+			10
114
+		);
115
+	}
116
+
117
+
118
+	/**
119
+	 *    set_definitions
120
+	 *
121
+	 * @access    public
122
+	 * @return    void
123
+	 */
124
+	public static function set_definitions()
125
+	{
126
+		define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
127
+		define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/');
128
+	}
129
+
130
+
131
+	/**
132
+	 * set up EE_Events_Archive_Config
133
+	 */
134
+	protected function set_config()
135
+	{
136
+		$this->set_config_section('template_settings');
137
+		$this->set_config_class('EE_Events_Archive_Config');
138
+		$this->set_config_name('EED_Events_Archive');
139
+	}
140
+
141
+
142
+	/**
143
+	 * @return EventListIframeEmbedButton
144
+	 */
145
+	public static function get_iframe_embed_button()
146
+	{
147
+		if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) {
148
+			self::$_iframe_embed_button = new EventListIframeEmbedButton();
149
+		}
150
+		return self::$_iframe_embed_button;
151
+	}
152
+
153
+
154
+	/**
155
+	 * event_list_iframe_embed_button
156
+	 *
157
+	 * @return    void
158
+	 * @throws EE_Error
159
+	 */
160
+	public static function event_list_iframe_embed_button()
161
+	{
162
+		$iframe_embed_button = EED_Events_Archive::get_iframe_embed_button();
163
+		$iframe_embed_button->addEmbedButton();
164
+	}
165
+
166
+
167
+	/**
168
+	 *    initialize_template_parts
169
+	 *
170
+	 * @access    public
171
+	 * @param EE_Events_Archive_Config $config
172
+	 * @return EE_Template_Part_Manager
173
+	 * @throws EE_Error
174
+	 */
175
+	public function initialize_template_parts(EE_Events_Archive_Config $config = null)
176
+	{
177
+		$config = $config instanceof EE_Events_Archive_Config ? $config : $this->config();
178
+		EEH_Autoloader::register_template_part_autoloaders();
179
+		$template_parts = new EE_Template_Part_Manager();
180
+		$template_parts->add_template_part(
181
+			'tickets',
182
+			__('Ticket Selector', 'event_espresso'),
183
+			'content-espresso_events-tickets.php',
184
+			$config->display_order_tickets
185
+		);
186
+		$template_parts->add_template_part(
187
+			'datetimes',
188
+			__('Dates and Times', 'event_espresso'),
189
+			'content-espresso_events-datetimes.php',
190
+			$config->display_order_datetimes
191
+		);
192
+		$template_parts->add_template_part(
193
+			'event',
194
+			__('Event Description', 'event_espresso'),
195
+			'content-espresso_events-details.php',
196
+			$config->display_order_event
197
+		);
198
+		$template_parts->add_template_part(
199
+			'venue',
200
+			__('Venue Information', 'event_espresso'),
201
+			'content-espresso_events-venues.php',
202
+			$config->display_order_venue
203
+		);
204
+		do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts);
205
+		return $template_parts;
206
+	}
207
+
208
+
209
+	/**
210
+	 *    run - initial module setup - this gets called by the EE_Front_Controller if the module route is found in the
211
+	 *    incoming request
212
+	 *
213
+	 * @access    public
214
+	 * @param WP $WP
215
+	 * @return    void
216
+	 */
217
+	public function run($WP)
218
+	{
219
+		do_action('AHEE__EED_Events_Archive__before_run');
220
+		// ensure valid EE_Events_Archive_Config() object exists
221
+		$this->set_config();
222
+		/** @type EE_Events_Archive_Config $config */
223
+		$config = $this->config();
224
+		// load other required components
225
+		$this->load_event_list_assets();
226
+		// filter the WP posts_join, posts_where, and posts_orderby SQL clauses
227
+		// add query filters
228
+		EEH_Event_Query::add_query_filters();
229
+		// set params that will get used by the filters
230
+		EEH_Event_Query::set_query_params(
231
+			'',    // month
232
+			'',    // category
233
+			$config->display_expired_events,    // show_expired
234
+			'start_date',    // orderby
235
+			'ASC'    // sort
236
+		);
237
+		// check what template is loaded
238
+		add_filter('template_include', array($this, 'template_include'), 999, 1);
239
+	}
240
+
241
+
242
+	/**
243
+	 * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting
244
+	 *
245
+	 * @return    void
246
+	 */
247
+	public function event_list()
248
+	{
249
+		// ensure valid EE_Events_Archive_Config() object exists
250
+		$this->set_config();
251
+		// load other required components
252
+		$this->load_event_list_assets();
253
+	}
254
+
255
+
256
+	/**
257
+	 * @access    public
258
+	 * @return    void
259
+	 * @throws EE_Error
260
+	 * @throws DomainException
261
+	 */
262
+	public function event_list_iframe()
263
+	{
264
+		EED_Events_Archive::$iframe = true;
265
+		$event_list_iframe = new EventsArchiveIframe($this);
266
+		$event_list_iframe->display();
267
+	}
268
+
269
+
270
+	/**
271
+	 * @access public
272
+	 * @return string
273
+	 */
274
+	public static function is_iframe()
275
+	{
276
+		return EED_Events_Archive::$iframe;
277
+	}
278
+
279
+
280
+	/**
281
+	 * @access public
282
+	 * @return string
283
+	 */
284
+	public static function link_target()
285
+	{
286
+		return EED_Events_Archive::$iframe ? ' target="_blank"' : '';
287
+	}
288
+
289
+
290
+	/**
291
+	 *    template_include
292
+	 *
293
+	 * @access    public
294
+	 * @param string $template
295
+	 * @return    string
296
+	 */
297
+	public function template_include($template = '')
298
+	{
299
+		// don't add content filter for dedicated EE child themes or private posts
300
+		if (! EEH_Template::is_espresso_theme()) {
301
+			/** @type EE_Events_Archive_Config $config */
302
+			$config = $this->config();
303
+			// add status banner ?
304
+			if ($config->display_status_banner) {
305
+				add_filter('the_title', array('EED_Events_Archive', 'the_title'), 100, 2);
306
+			}
307
+			// if NOT a custom template
308
+			if (apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false)
309
+				|| EE_Registry::instance()
310
+							  ->load_core('Front_Controller')
311
+							  ->get_selected_template() !== 'archive-espresso_events.php'
312
+			) {
313
+				// don't display entry meta because the existing theme will take care of that
314
+				add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true');
315
+				// load functions.php file for the theme (loaded by WP if using child theme)
316
+				EEH_Template::load_espresso_theme_functions();
317
+				// because we don't know if the theme is using the_excerpt()
318
+				add_filter(
319
+					'the_excerpt',
320
+					array('EED_Events_Archive', 'event_details'),
321
+					EED_Events_Archive::EVENT_DETAILS_PRIORITY
322
+				);
323
+				// or the_content
324
+				add_filter(
325
+					'the_content',
326
+					array('EED_Events_Archive', 'event_details'),
327
+					EED_Events_Archive::EVENT_DETAILS_PRIORITY
328
+				);
329
+				// and just in case they are running get_the_excerpt() which DESTROYS things
330
+				add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1);
331
+				// don't display entry meta because the existing theme will take care of that
332
+				add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
333
+			}
334
+		}
335
+		return $template;
336
+	}
337
+
338
+
339
+	/**
340
+	 *    get_the_excerpt - kinda hacky, but if a theme is using get_the_excerpt(), then we need to remove our filters
341
+	 *    on the_content()
342
+	 *
343
+	 * @access    public
344
+	 * @param        string $excerpt
345
+	 * @return        string
346
+	 */
347
+	public static function get_the_excerpt($excerpt = '')
348
+	{
349
+		if (post_password_required()) {
350
+			return $excerpt;
351
+		}
352
+		if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) {
353
+			remove_filter(
354
+				'the_excerpt',
355
+				array('EED_Events_Archive', 'event_details'),
356
+				EED_Events_Archive::EVENT_DETAILS_PRIORITY
357
+			);
358
+			remove_filter(
359
+				'the_content',
360
+				array('EED_Events_Archive', 'event_details'),
361
+				EED_Events_Archive::EVENT_DETAILS_PRIORITY
362
+			);
363
+			$excerpt = EED_Events_Archive::event_details($excerpt);
364
+		} else {
365
+			EED_Events_Archive::$using_get_the_excerpt = true;
366
+			add_filter('wp_trim_excerpt', array('EED_Events_Archive', 'end_get_the_excerpt'), 999, 1);
367
+		}
368
+		return $excerpt;
369
+	}
370
+
371
+
372
+	/**
373
+	 * end_get_the_excerpt
374
+	 *
375
+	 * @access public
376
+	 * @param  string $text
377
+	 * @return string
378
+	 */
379
+	public static function end_get_the_excerpt($text = '')
380
+	{
381
+		EED_Events_Archive::$using_get_the_excerpt = false;
382
+		return $text;
383
+	}
384
+
385
+
386
+	/**
387
+	 *    the_title
388
+	 *
389
+	 * @access        public
390
+	 * @param        string $title
391
+	 * @param        string $id
392
+	 * @return        string
393
+	 */
394
+	public static function the_title($title = '', $id = '')
395
+	{
396
+		global $post;
397
+		if ($post instanceof WP_Post) {
398
+			return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID) . $title : $title;
399
+		}
400
+		return $title;
401
+	}
402
+
403
+
404
+	/**
405
+	 *    event_details
406
+	 *
407
+	 * @access    public
408
+	 * @param        string $content
409
+	 * @return        string
410
+	 */
411
+	public static function event_details($content)
412
+	{
413
+		global $post;
414
+		static $current_post_ID = 0;
415
+		if ($current_post_ID !== $post->ID
416
+			&& $post->post_type === 'espresso_events'
417
+			&& ! EED_Events_Archive::$using_get_the_excerpt
418
+			&& ! post_password_required()
419
+			&& (
420
+				apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false)
421
+				|| ! apply_filters('FHEE__content_espresso_events__template_loaded', false)
422
+			)
423
+		) {
424
+			// Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
425
+			// Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
426
+			// BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
427
+			// We want to allow those plugins to still do their thing and have access to our content, but depending on
428
+			// how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
429
+			// so the following allows this filter to be applied multiple times, but only once for real
430
+			$current_post_ID = did_action('loop_start') ? $post->ID : 0;
431
+			if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) {
432
+				$content = EED_Events_Archive::use_sortable_display_order();
433
+			} else {
434
+				$content = EED_Events_Archive::use_filterable_display_order();
435
+			}
436
+		}
437
+		return $content;
438
+	}
439
+
440
+
441
+	/**
442
+	 *    use_sortable_display_order
443
+	 *
444
+	 * @access    protected
445
+	 * @return string
446
+	 */
447
+	protected static function use_sortable_display_order()
448
+	{
449
+		// no further password checks required atm
450
+		add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true');
451
+		// we need to first remove this callback from being applied to the_content() or the_excerpt()
452
+		// (otherwise it will recurse and blow up the interweb)
453
+		remove_filter(
454
+			'the_excerpt',
455
+			array('EED_Events_Archive', 'event_details'),
456
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
457
+		);
458
+		remove_filter(
459
+			'the_content',
460
+			array('EED_Events_Archive', 'event_details'),
461
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
462
+		);
463
+		remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1);
464
+		// now add additional content depending on whether event is using the_excerpt() or the_content()
465
+		EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts();
466
+		$content = EEH_Template::locate_template('content-espresso_events-details.php');
467
+		$content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content);
468
+		// re-add our main filters (or else the next event won't have them)
469
+		add_filter(
470
+			'the_excerpt',
471
+			array('EED_Events_Archive', 'event_details'),
472
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
473
+		);
474
+		add_filter(
475
+			'the_content',
476
+			array('EED_Events_Archive', 'event_details'),
477
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
478
+		);
479
+		add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1);
480
+		remove_filter(
481
+			'FHEE__EED_Events_Archive__event_details__no_post_password_required',
482
+			'__return_true'
483
+		);
484
+		return $content;
485
+	}
486
+
487
+
488
+	/**
489
+	 *    use_filterable_display_order
490
+	 *
491
+	 * @access    protected
492
+	 * @return    string
493
+	 */
494
+	protected static function use_filterable_display_order()
495
+	{
496
+		// we need to first remove this callback from being applied to the_content()
497
+		// (otherwise it will recurse and blow up the interweb)
498
+		remove_filter(
499
+			'the_excerpt',
500
+			array('EED_Events_Archive', 'event_details'),
501
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
502
+		);
503
+		remove_filter(
504
+			'the_content',
505
+			array('EED_Events_Archive', 'event_details'),
506
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
507
+		);
508
+		remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1);
509
+		// now add additional content depending on whether event is using the_excerpt() or the_content()
510
+		EED_Events_Archive::_add_additional_excerpt_filters();
511
+		EED_Events_Archive::_add_additional_content_filters();
512
+		do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters');
513
+		// now load our template
514
+		$content = EEH_Template::locate_template('content-espresso_events-details.php');
515
+		// re-add our main filters (or else the next event won't have them)
516
+		add_filter(
517
+			'the_excerpt',
518
+			array('EED_Events_Archive', 'event_details'),
519
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
520
+		);
521
+		add_filter(
522
+			'the_content',
523
+			array('EED_Events_Archive', 'event_details'),
524
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
525
+		);
526
+		add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1);
527
+		// but remove the other filters so that they don't get applied to the next post
528
+		EED_Events_Archive::_remove_additional_events_archive_filters();
529
+		do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters');
530
+		// we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
531
+		// return ! empty( $template ) ? $template : $content;
532
+		return $content;
533
+	}
534
+
535
+
536
+	/**
537
+	 *    event_datetimes - adds datetimes ABOVE content
538
+	 *
539
+	 * @access    public
540
+	 * @param        string $content
541
+	 * @return        string
542
+	 */
543
+	public static function event_datetimes($content)
544
+	{
545
+		if (post_password_required()) {
546
+			return $content;
547
+		}
548
+		return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
549
+	}
550
+
551
+
552
+	/**
553
+	 *    event_tickets - adds tickets ABOVE content (which includes datetimes)
554
+	 *
555
+	 * @access    public
556
+	 * @param        string $content
557
+	 * @return        string
558
+	 */
559
+	public static function event_tickets($content)
560
+	{
561
+		if (post_password_required()) {
562
+			return $content;
563
+		}
564
+		return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
565
+	}
566
+
567
+
568
+	/**
569
+	 *    event_venues - adds venues BELOW content
570
+	 *
571
+	 * @access    public
572
+	 * @param    string $content
573
+	 * @return    string
574
+	 */
575
+	public static function event_venue($content)
576
+	{
577
+		return EED_Events_Archive::event_venues($content);
578
+	}
579
+
580
+
581
+	/**
582
+	 *    event_venues - adds venues BELOW content
583
+	 *
584
+	 * @access    public
585
+	 * @param        string $content
586
+	 * @return        string
587
+	 */
588
+	public static function event_venues($content)
589
+	{
590
+		if (post_password_required()) {
591
+			return $content;
592
+		}
593
+		return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
594
+	}
595
+
596
+
597
+	/**
598
+	 *    _add_additional_content_filters
599
+	 *
600
+	 * @access    private
601
+	 * @return        void
602
+	 */
603
+	private static function _add_additional_excerpt_filters()
604
+	{
605
+		add_filter(
606
+			'the_excerpt',
607
+			array('EED_Events_Archive', 'event_datetimes'),
608
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
609
+		);
610
+		add_filter(
611
+			'the_excerpt',
612
+			array('EED_Events_Archive', 'event_tickets'),
613
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
614
+		);
615
+		add_filter(
616
+			'the_excerpt',
617
+			array('EED_Events_Archive', 'event_venues'),
618
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
619
+		);
620
+	}
621
+
622
+
623
+	/**
624
+	 *    _add_additional_content_filters
625
+	 *
626
+	 * @access    private
627
+	 * @return        void
628
+	 */
629
+	private static function _add_additional_content_filters()
630
+	{
631
+		add_filter(
632
+			'the_content',
633
+			array('EED_Events_Archive', 'event_datetimes'),
634
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
635
+		);
636
+		add_filter(
637
+			'the_content',
638
+			array('EED_Events_Archive', 'event_tickets'),
639
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
640
+		);
641
+		add_filter(
642
+			'the_content',
643
+			array('EED_Events_Archive', 'event_venues'),
644
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
645
+		);
646
+	}
647
+
648
+
649
+	/**
650
+	 *    _remove_additional_events_archive_filters
651
+	 *
652
+	 * @access    private
653
+	 * @return        void
654
+	 */
655
+	private static function _remove_additional_events_archive_filters()
656
+	{
657
+		remove_filter(
658
+			'the_excerpt',
659
+			array('EED_Events_Archive', 'event_datetimes'),
660
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
661
+		);
662
+		remove_filter(
663
+			'the_excerpt',
664
+			array('EED_Events_Archive', 'event_tickets'),
665
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
666
+		);
667
+		remove_filter(
668
+			'the_excerpt',
669
+			array('EED_Events_Archive', 'event_venues'),
670
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
671
+		);
672
+		remove_filter(
673
+			'the_content',
674
+			array('EED_Events_Archive', 'event_datetimes'),
675
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
676
+		);
677
+		remove_filter(
678
+			'the_content',
679
+			array('EED_Events_Archive', 'event_tickets'),
680
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
681
+		);
682
+		remove_filter(
683
+			'the_content',
684
+			array('EED_Events_Archive', 'event_venues'),
685
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
686
+		);
687
+	}
688
+
689
+
690
+	/**
691
+	 *    remove_all_events_archive_filters
692
+	 *
693
+	 * @access    public
694
+	 * @return        void
695
+	 */
696
+	public static function remove_all_events_archive_filters()
697
+	{
698
+		// remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
699
+		remove_filter('the_title', array('EED_Events_Archive', 'the_title'), 1);
700
+		remove_filter(
701
+			'the_excerpt',
702
+			array('EED_Events_Archive', 'event_details'),
703
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
704
+		);
705
+		remove_filter(
706
+			'the_excerpt',
707
+			array('EED_Events_Archive', 'event_datetimes'),
708
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
709
+		);
710
+		remove_filter(
711
+			'the_excerpt',
712
+			array('EED_Events_Archive', 'event_tickets'),
713
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
714
+		);
715
+		remove_filter(
716
+			'the_excerpt',
717
+			array('EED_Events_Archive', 'event_venues'),
718
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
719
+		);
720
+		remove_filter(
721
+			'the_content',
722
+			array('EED_Events_Archive', 'event_details'),
723
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
724
+		);
725
+		remove_filter(
726
+			'the_content',
727
+			array('EED_Events_Archive', 'event_datetimes'),
728
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
729
+		);
730
+		remove_filter(
731
+			'the_content',
732
+			array('EED_Events_Archive', 'event_tickets'),
733
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
734
+		);
735
+		remove_filter(
736
+			'the_content',
737
+			array('EED_Events_Archive', 'event_venues'),
738
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
739
+		);
740
+		// don't display entry meta because the existing theme will take care of that
741
+		remove_filter(
742
+			'FHEE__content_espresso_events_details_template__display_entry_meta',
743
+			'__return_false'
744
+		);
745
+	}
746
+
747
+
748
+	/**
749
+	 *    load_event_list_assets
750
+	 *
751
+	 * @access    public
752
+	 * @return    void
753
+	 */
754
+	public function load_event_list_assets()
755
+	{
756
+		do_action('AHEE__EED_Events_Archive__before_load_assets');
757
+		add_filter('FHEE_load_EE_Session', '__return_true');
758
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
759
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
760
+		if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
761
+			add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
762
+		}
763
+	}
764
+
765
+
766
+	/**
767
+	 *    wp_enqueue_scripts
768
+	 *
769
+	 * @access    public
770
+	 * @return    void
771
+	 * @throws EE_Error
772
+	 */
773
+	public function wp_enqueue_scripts()
774
+	{
775
+		// get some style
776
+		if (apply_filters('FHEE_enable_default_espresso_css', false)) {
777
+			// first check uploads folder
778
+			if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) {
779
+				wp_register_style(
780
+					$this->theme,
781
+					get_stylesheet_directory_uri() . $this->theme . '/style.css',
782
+					array('dashicons', 'espresso_default')
783
+				);
784
+			} else {
785
+			}
786
+			wp_enqueue_style($this->theme);
787
+		}
788
+	}
789
+
790
+
791
+	/**
792
+	 *    template_settings_form
793
+	 *
794
+	 * @access    public
795
+	 * @static
796
+	 * @return    string
797
+	 */
798
+	public static function template_settings_form()
799
+	{
800
+		$template_settings = EE_Registry::instance()->CFG->template_settings;
801
+		$template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive)
802
+			? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config();
803
+		$template_settings->EED_Events_Archive = apply_filters(
804
+			'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
805
+			$template_settings->EED_Events_Archive
806
+		);
807
+		$events_archive_settings = array(
808
+			'display_status_banner' => 0,
809
+			'display_description' => 1,
810
+			'display_ticket_selector' => 0,
811
+			'display_datetimes' => 1,
812
+			'display_venue' => 0,
813
+			'display_expired_events' => 0,
814
+		);
815
+		$events_archive_settings = array_merge(
816
+			$events_archive_settings,
817
+			(array) $template_settings->EED_Events_Archive
818
+		);
819
+		EEH_Template::display_template(
820
+			EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
821
+			$events_archive_settings
822
+		);
823
+	}
824
+
825
+
826
+	/**
827
+	 *    update_template_settings
828
+	 *
829
+	 * @access    public
830
+	 * @param    EE_Template_Config $CFG
831
+	 * @param    EE_Request_Handler $REQ
832
+	 * @return    EE_Template_Config
833
+	 */
834
+	public static function update_template_settings($CFG, $REQ)
835
+	{
836
+		$CFG->EED_Events_Archive = new EE_Events_Archive_Config();
837
+		// unless we are resetting the config...
838
+		if (! isset($REQ['EED_Events_Archive_reset_event_list_settings'])
839
+			|| absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1
840
+		) {
841
+			$CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner'])
842
+				? absint($REQ['EED_Events_Archive_display_status_banner']) : 0;
843
+			$CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description'])
844
+				? absint($REQ['EED_Events_Archive_display_description']) : 1;
845
+			$CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector'])
846
+				? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0;
847
+			$CFG->EED_Events_Archive->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint(
848
+				$REQ['EED_Events_Archive_display_datetimes']
849
+			) : 1;
850
+			$CFG->EED_Events_Archive->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint(
851
+				$REQ['EED_Events_Archive_display_venue']
852
+			) : 0;
853
+			$CFG->EED_Events_Archive->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events'])
854
+				? absint($REQ['EED_Events_Archive_display_expired_events']) : 0;
855
+		}
856
+		return $CFG;
857
+	}
858
+
859
+
860
+	/**
861
+	 *    event_list_css
862
+	 *
863
+	 * @access    public
864
+	 * @param string $extra_class
865
+	 * @return    string
866
+	 */
867
+	public static function event_list_css($extra_class = '')
868
+	{
869
+		$event_list_css = ! empty($extra_class) ? array($extra_class) : array();
870
+		$event_list_css[] = 'espresso-event-list-event';
871
+		return implode(' ', $event_list_css);
872
+	}
873
+
874
+
875
+	/**
876
+	 *    event_categories
877
+	 *
878
+	 * @access    public
879
+	 * @return    array
880
+	 */
881
+	public static function event_categories()
882
+	{
883
+		return EE_Registry::instance()->load_model('Term')->get_all_ee_categories();
884
+	}
885
+
886
+
887
+	/**
888
+	 *    display_description
889
+	 *
890
+	 * @access    public
891
+	 * @param $value
892
+	 * @return    bool
893
+	 */
894
+	public static function display_description($value)
895
+	{
896
+		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
897
+		$display_description = isset($config->display_description) ? $config->display_description : 1;
898
+		return $display_description === $value ? true : false;
899
+	}
900
+
901
+
902
+	/**
903
+	 *    display_ticket_selector
904
+	 *
905
+	 * @access    public
906
+	 * @return    bool
907
+	 */
908
+	public static function display_ticket_selector()
909
+	{
910
+		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
911
+		return isset($config->display_ticket_selector) && $config->display_ticket_selector ? true : false;
912
+	}
913
+
914
+
915
+	/**
916
+	 *    display_venue
917
+	 *
918
+	 * @access    public
919
+	 * @return    bool
920
+	 */
921
+	public static function display_venue()
922
+	{
923
+		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
924
+		return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name() ? true : false;
925
+	}
926
+
927
+
928
+	/**
929
+	 *    display_datetimes
930
+	 *
931
+	 * @access    public
932
+	 * @return    bool
933
+	 */
934
+	public static function display_datetimes()
935
+	{
936
+		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
937
+		return isset($config->display_datetimes) && $config->display_datetimes ? true : false;
938
+	}
939
+
940
+
941
+	/**
942
+	 *    event_list_title
943
+	 *
944
+	 * @access    public
945
+	 * @return    string
946
+	 */
947
+	public static function event_list_title()
948
+	{
949
+		return apply_filters(
950
+			'FHEE__archive_espresso_events_template__upcoming_events_h1',
951
+			__('Upcoming Events', 'event_espresso')
952
+		);
953
+	}
954
+
955
+
956
+	// GRAVEYARD
957
+
958
+
959
+	/**
960
+	 * @since 4.4.0
961
+	 */
962
+	public static function _doing_it_wrong_notice($function = '')
963
+	{
964
+		EE_Error::doing_it_wrong(
965
+			__FUNCTION__,
966
+			sprintf(
967
+				__(
968
+					'EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s',
969
+					'event_espresso'
970
+				),
971
+				$function,
972
+				'<br />',
973
+				'4.6.0'
974
+			),
975
+			'4.4.0'
976
+		);
977
+	}
978
+
979
+
980
+	/**
981
+	 * @deprecated
982
+	 * @since 4.4.0
983
+	 */
984
+	public function get_post_data()
985
+	{
986
+		EEH_Event_Query::set_query_params();
987
+	}
988
+
989
+
990
+	/**
991
+	 * @throws EE_Error
992
+	 * @since 4.4.0
993
+	 * @deprecated
994
+	 */
995
+	public function posts_fields($SQL, WP_Query $wp_query)
996
+	{
997
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
998
+		return EEH_Event_Query::posts_fields($SQL, $wp_query);
999
+	}
1000
+
1001
+
1002
+	/**
1003
+	 * @throws EE_Error
1004
+	 * @since 4.4.0
1005
+	 * @deprecated
1006
+	 */
1007
+	public static function posts_fields_sql_for_orderby($orderby_params = array())
1008
+	{
1009
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1010
+		return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params);
1011
+	}
1012
+
1013
+
1014
+	/**
1015
+	 * @throws EE_Error
1016
+	 * @since 4.4.0
1017
+	 * @deprecated
1018
+	 */
1019
+	public function posts_join($SQL, WP_Query $wp_query)
1020
+	{
1021
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1022
+		return EEH_Event_Query::posts_join($SQL, $wp_query);
1023
+	}
1024
+
1025
+
1026
+	/**
1027
+	 * @deprecated
1028
+	 * @since 4.4.0
1029
+	 */
1030
+	public static function posts_join_sql_for_terms($join_terms = null)
1031
+	{
1032
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1033
+		return EEH_Event_Query::posts_join_sql_for_terms($join_terms);
1034
+	}
1035
+
1036
+
1037
+	/**
1038
+	 * @throws EE_Error
1039
+	 * @since 4.4.0
1040
+	 * @deprecated
1041
+	 */
1042
+	public static function posts_join_for_orderby($orderby_params = array())
1043
+	{
1044
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1045
+		return EEH_Event_Query::posts_join_for_orderby($orderby_params);
1046
+	}
1047
+
1048
+
1049
+	/**
1050
+	 * @throws EE_Error
1051
+	 * @since 4.4.0
1052
+	 * @deprecated
1053
+	 */
1054
+	public function posts_where($SQL, WP_Query $wp_query)
1055
+	{
1056
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1057
+		return EEH_Event_Query::posts_where($SQL, $wp_query);
1058
+	}
1059
+
1060
+
1061
+	/**
1062
+	 * @throws EE_Error
1063
+	 * @since 4.4.0
1064
+	 * @deprecated
1065
+	 */
1066
+	public static function posts_where_sql_for_show_expired($show_expired = false)
1067
+	{
1068
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1069
+		return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired);
1070
+	}
1071
+
1072
+
1073
+	/**
1074
+	 * @deprecated
1075
+	 * @since 4.4.0
1076
+	 */
1077
+	public static function posts_where_sql_for_event_category_slug($event_category_slug = null)
1078
+	{
1079
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1080
+		return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug);
1081
+	}
1082
+
1083
+
1084
+	/**
1085
+	 * @throws EE_Error
1086
+	 * @since 4.4.0
1087
+	 * @deprecated
1088
+	 */
1089
+	public static function posts_where_sql_for_event_list_month($month = null)
1090
+	{
1091
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1092
+		return EEH_Event_Query::posts_where_sql_for_event_list_month($month);
1093
+	}
1094
+
1095
+
1096
+	/**
1097
+	 * @throws EE_Error
1098
+	 * @since 4.4.0
1099
+	 * @deprecated
1100
+	 */
1101
+	public function posts_orderby($SQL, WP_Query $wp_query)
1102
+	{
1103
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1104
+		return EEH_Event_Query::posts_orderby($SQL, $wp_query);
1105
+	}
1106
+
1107
+
1108
+	/**
1109
+	 * @throws EE_Error
1110
+	 * @since 4.4.0
1111
+	 * @deprecated
1112
+	 */
1113
+	public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC')
1114
+	{
1115
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1116
+		return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort);
1117
+	}
1118 1118
 }
1119 1119
 
1120 1120
 
@@ -1123,9 +1123,9 @@  discard block
 block discarded – undo
1123 1123
  */
1124 1124
 function espresso_get_event_list_ID()
1125 1125
 {
1126
-    EED_Events_Archive::$espresso_event_list_ID++;
1127
-    EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID;
1128
-    return EED_Events_Archive::$espresso_event_list_ID;
1126
+	EED_Events_Archive::$espresso_event_list_ID++;
1127
+	EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID;
1128
+	return EED_Events_Archive::$espresso_event_list_ID;
1129 1129
 }
1130 1130
 
1131 1131
 /**
@@ -1133,7 +1133,7 @@  discard block
 block discarded – undo
1133 1133
  */
1134 1134
 function espresso_event_list_title()
1135 1135
 {
1136
-    return EED_Events_Archive::event_list_title();
1136
+	return EED_Events_Archive::event_list_title();
1137 1137
 }
1138 1138
 
1139 1139
 /**
@@ -1142,7 +1142,7 @@  discard block
 block discarded – undo
1142 1142
  */
1143 1143
 function espresso_event_list_css($extra_class = '')
1144 1144
 {
1145
-    return EED_Events_Archive::event_list_css($extra_class);
1145
+	return EED_Events_Archive::event_list_css($extra_class);
1146 1146
 }
1147 1147
 
1148 1148
 /**
@@ -1150,7 +1150,7 @@  discard block
 block discarded – undo
1150 1150
  */
1151 1151
 function espresso_get_event_categories()
1152 1152
 {
1153
-    return EED_Events_Archive::event_categories();
1153
+	return EED_Events_Archive::event_categories();
1154 1154
 }
1155 1155
 
1156 1156
 /**
@@ -1158,7 +1158,7 @@  discard block
 block discarded – undo
1158 1158
  */
1159 1159
 function espresso_display_full_description_in_event_list()
1160 1160
 {
1161
-    return EED_Events_Archive::display_description(2);
1161
+	return EED_Events_Archive::display_description(2);
1162 1162
 }
1163 1163
 
1164 1164
 /**
@@ -1166,7 +1166,7 @@  discard block
 block discarded – undo
1166 1166
  */
1167 1167
 function espresso_display_excerpt_in_event_list()
1168 1168
 {
1169
-    return EED_Events_Archive::display_description(1);
1169
+	return EED_Events_Archive::display_description(1);
1170 1170
 }
1171 1171
 
1172 1172
 /**
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
  */
1175 1175
 function espresso_display_ticket_selector_in_event_list()
1176 1176
 {
1177
-    return EED_Events_Archive::display_ticket_selector();
1177
+	return EED_Events_Archive::display_ticket_selector();
1178 1178
 }
1179 1179
 
1180 1180
 /**
@@ -1182,7 +1182,7 @@  discard block
 block discarded – undo
1182 1182
  */
1183 1183
 function espresso_display_venue_in_event_list()
1184 1184
 {
1185
-    return EED_Events_Archive::display_venue();
1185
+	return EED_Events_Archive::display_venue();
1186 1186
 }
1187 1187
 
1188 1188
 /**
@@ -1190,5 +1190,5 @@  discard block
 block discarded – undo
1190 1190
  */
1191 1191
 function espresso_display_datetimes_in_event_list()
1192 1192
 {
1193
-    return EED_Events_Archive::display_datetimes();
1193
+	return EED_Events_Archive::display_datetimes();
1194 1194
 }
Please login to merge, or discard this patch.
modules/event_single/EED_Event_Single.module.php 1 patch
Indentation   +468 added lines, -468 removed lines patch added patch discarded remove patch
@@ -14,473 +14,473 @@  discard block
 block discarded – undo
14 14
 class EED_Event_Single extends EED_Module
15 15
 {
16 16
 
17
-    const EVENT_DETAILS_PRIORITY = 100;
18
-    const EVENT_DATETIMES_PRIORITY = 110;
19
-    const EVENT_TICKETS_PRIORITY = 120;
20
-    const EVENT_VENUES_PRIORITY = 130;
21
-
22
-    /**
23
-     * @type bool $using_get_the_excerpt
24
-     */
25
-    protected static $using_get_the_excerpt = false;
26
-
27
-
28
-    /**
29
-     * @type EE_Template_Part_Manager $template_parts
30
-     */
31
-    protected $template_parts;
32
-
33
-
34
-    /**
35
-     * @return EED_Module|EED_Event_Single
36
-     */
37
-    public static function instance()
38
-    {
39
-        return parent::get_instance(__CLASS__);
40
-    }
41
-
42
-
43
-    /**
44
-     * set_hooks - for hooking into EE Core, other modules, etc
45
-     *
46
-     * @return void
47
-     * @throws InvalidArgumentException
48
-     * @throws InvalidDataTypeException
49
-     * @throws InvalidInterfaceException
50
-     */
51
-    public static function set_hooks()
52
-    {
53
-        add_filter('FHEE_run_EE_wp', '__return_true');
54
-        add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
55
-        /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */
56
-        $custom_post_type_definitions = LoaderFactory::getLoader()->getShared(
57
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
58
-        );
59
-        $custom_post_types = $custom_post_type_definitions->getDefinitions();
60
-        EE_Config::register_route(
61
-            $custom_post_types['espresso_events']['singular_slug'],
62
-            'Event_Single',
63
-            'run'
64
-        );
65
-    }
66
-
67
-    /**
68
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
69
-     *
70
-     * @return    void
71
-     */
72
-    public static function set_hooks_admin()
73
-    {
74
-        add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
75
-    }
76
-
77
-
78
-    /**
79
-     * set_definitions
80
-     *
81
-     * @static
82
-     * @return void
83
-     */
84
-    public static function set_definitions()
85
-    {
86
-        define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
87
-        define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/');
88
-    }
89
-
90
-
91
-    /**
92
-     * set_config
93
-     *
94
-     * @void
95
-     */
96
-    protected function set_config()
97
-    {
98
-        $this->set_config_section('template_settings');
99
-        $this->set_config_class('EE_Event_Single_Config');
100
-        $this->set_config_name('EED_Event_Single');
101
-    }
102
-
103
-
104
-    /**
105
-     * initialize_template_parts
106
-     *
107
-     * @param EE_Config_Base|EE_Event_Single_Config $config
108
-     * @return EE_Template_Part_Manager
109
-     * @throws EE_Error
110
-     */
111
-    public function initialize_template_parts(EE_Event_Single_Config $config = null)
112
-    {
113
-        /** @type EE_Event_Single_Config $config */
114
-        $config = $config instanceof EE_Event_Single_Config ? $config : $this->config();
115
-        EEH_Autoloader::register_template_part_autoloaders();
116
-        $template_parts = new EE_Template_Part_Manager();
117
-        $template_parts->add_template_part(
118
-            'tickets',
119
-            __('Ticket Selector', 'event_espresso'),
120
-            'content-espresso_events-tickets.php',
121
-            $config->display_order_tickets
122
-        );
123
-        $template_parts->add_template_part(
124
-            'datetimes',
125
-            __('Dates and Times', 'event_espresso'),
126
-            'content-espresso_events-datetimes.php',
127
-            $config->display_order_datetimes
128
-        );
129
-        $template_parts->add_template_part(
130
-            'event',
131
-            __('Event Description', 'event_espresso'),
132
-            'content-espresso_events-details.php',
133
-            $config->display_order_event
134
-        );
135
-        $template_parts->add_template_part(
136
-            'venue',
137
-            __('Venue Information', 'event_espresso'),
138
-            'content-espresso_events-venues.php',
139
-            $config->display_order_venue
140
-        );
141
-        do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts);
142
-        return $template_parts;
143
-    }
144
-
145
-
146
-    /**
147
-     * run - initial module setup
148
-     *
149
-     * @param WP $WP
150
-     * @return    void
151
-     */
152
-    public function run($WP)
153
-    {
154
-        // ensure valid EE_Events_Single_Config() object exists
155
-        $this->set_config();
156
-        // check what template is loaded
157
-        add_filter('template_include', array($this, 'template_include'), 999, 1);
158
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
159
-        // load css
160
-        add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
161
-    }
162
-
163
-
164
-    /**
165
-     * template_include
166
-     *
167
-     * @param    string $template
168
-     * @return    string
169
-     */
170
-    public function template_include($template)
171
-    {
172
-        global $post;
173
-        /** @type EE_Event_Single_Config $config */
174
-        $config = $this->config();
175
-        if ($config->display_status_banner_single) {
176
-            add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2);
177
-        }
178
-        // not a custom template?
179
-        if (! post_password_required($post)
180
-            && (
181
-                apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false)
182
-                || EE_Registry::instance()
183
-                              ->load_core('Front_Controller')
184
-                              ->get_selected_template() !== 'single-espresso_events.php'
185
-            )
186
-
187
-        ) {
188
-            EEH_Template::load_espresso_theme_functions();
189
-            // then add extra event data via hooks
190
-            add_action('loop_start', array('EED_Event_Single', 'loop_start'));
191
-            add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1);
192
-            add_filter(
193
-                'the_content',
194
-                array('EED_Event_Single', 'event_details'),
195
-                EED_Event_Single::EVENT_DETAILS_PRIORITY
196
-            );
197
-            add_action('loop_end', array('EED_Event_Single', 'loop_end'));
198
-            // don't display entry meta because the existing theme will take car of that
199
-            add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
200
-        }
201
-        return $template;
202
-    }
203
-
204
-
205
-    /**
206
-     * loop_start
207
-     *
208
-     * @param    array $wp_query_array an array containing the WP_Query object
209
-     * @return    void
210
-     */
211
-    public static function loop_start($wp_query_array)
212
-    {
213
-        global $post;
214
-        do_action('AHEE_event_details_before_post', $post, $wp_query_array);
215
-    }
216
-
217
-
218
-    /**
219
-     * the_title
220
-     *
221
-     * @param    string $title
222
-     * @param    int    $id
223
-     * @return    string
224
-     */
225
-    public static function the_title($title = '', $id = 0)
226
-    {
227
-        global $post;
228
-        return in_the_loop() && $post->ID === (int) $id
229
-            ? espresso_event_status_banner($post->ID) . $title
230
-            : $title;
231
-    }
232
-
233
-
234
-    /**
235
-     * get_the_excerpt
236
-     * kinda hacky, but if a theme is using get_the_excerpt(),
237
-     * then we need to remove our filters on the_content()
238
-     *
239
-     * @param        string $excerpt
240
-     * @return        string
241
-     */
242
-    public static function get_the_excerpt($excerpt = '')
243
-    {
244
-        EED_Event_Single::$using_get_the_excerpt = true;
245
-        add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1);
246
-        return $excerpt;
247
-    }
248
-
249
-
250
-    /**
251
-     * end_get_the_excerpt
252
-     *
253
-     * @param  string $text
254
-     * @return string
255
-     */
256
-    public static function end_get_the_excerpt($text = '')
257
-    {
258
-        EED_Event_Single::$using_get_the_excerpt = false;
259
-        return $text;
260
-    }
261
-
262
-
263
-    /**
264
-     * event_details
265
-     *
266
-     * @param    string $content
267
-     * @return    string
268
-     */
269
-    public static function event_details($content)
270
-    {
271
-        global $post;
272
-        static $current_post_ID = 0;
273
-        if ($current_post_ID !== $post->ID
274
-            && $post->post_type === 'espresso_events'
275
-            && ! EED_Event_Single::$using_get_the_excerpt
276
-            && ! post_password_required()
277
-        ) {
278
-            // Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
279
-            // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
280
-            // BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
281
-            // We want to allow those plugins to still do their thing and have access to our content, but depending on
282
-            // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
283
-            // so the following allows this filter to be applied multiple times, but only once for real
284
-            $current_post_ID = did_action('loop_start') ? $post->ID : 0;
285
-            if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) {
286
-                // we need to first remove this callback from being applied to the_content()
287
-                // (otherwise it will recurse and blow up the interweb)
288
-                remove_filter(
289
-                    'the_content',
290
-                    array('EED_Event_Single', 'event_details'),
291
-                    EED_Event_Single::EVENT_DETAILS_PRIORITY
292
-                );
293
-                EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts(
294
-                );
295
-                $content = EEH_Template::locate_template('content-espresso_events-details.php');
296
-                $content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content);
297
-                add_filter(
298
-                    'the_content',
299
-                    array('EED_Event_Single', 'event_details'),
300
-                    EED_Event_Single::EVENT_DETAILS_PRIORITY
301
-                );
302
-            } else {
303
-                $content = EED_Event_Single::use_filterable_display_order();
304
-            }
305
-        }
306
-        return $content;
307
-    }
308
-
309
-
310
-    /**
311
-     * use_filterable_display_order
312
-     *
313
-     * @return string
314
-     */
315
-    protected static function use_filterable_display_order()
316
-    {
317
-        // since the 'content-espresso_events-details.php' template might be used directly from within a theme,
318
-        // it uses the_content() for displaying the $post->post_content
319
-        // so in order to load a template that uses the_content()
320
-        // from within a callback being used to filter the_content(),
321
-        // we need to first remove this callback from being applied to the_content()
322
-        // (otherwise it will recurse and blow up the interweb)
323
-        remove_filter(
324
-            'the_content',
325
-            array('EED_Event_Single', 'event_details'),
326
-            EED_Event_Single::EVENT_DETAILS_PRIORITY
327
-        );
328
-        // now add additional content
329
-        add_filter(
330
-            'the_content',
331
-            array('EED_Event_Single', 'event_datetimes'),
332
-            EED_Event_Single::EVENT_DATETIMES_PRIORITY,
333
-            1
334
-        );
335
-        add_filter(
336
-            'the_content',
337
-            array('EED_Event_Single', 'event_tickets'),
338
-            EED_Event_Single::EVENT_TICKETS_PRIORITY,
339
-            1
340
-        );
341
-        add_filter(
342
-            'the_content',
343
-            array('EED_Event_Single', 'event_venues'),
344
-            EED_Event_Single::EVENT_VENUES_PRIORITY,
345
-            1
346
-        );
347
-        do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters');
348
-        // now load our template
349
-        $content = EEH_Template::locate_template('content-espresso_events-details.php');
350
-        // now add our filter back in, plus some others
351
-        add_filter(
352
-            'the_content',
353
-            array('EED_Event_Single', 'event_details'),
354
-            EED_Event_Single::EVENT_DETAILS_PRIORITY
355
-        );
356
-        remove_filter(
357
-            'the_content',
358
-            array('EED_Event_Single', 'event_datetimes'),
359
-            EED_Event_Single::EVENT_DATETIMES_PRIORITY
360
-        );
361
-        remove_filter(
362
-            'the_content',
363
-            array('EED_Event_Single', 'event_tickets'),
364
-            EED_Event_Single::EVENT_TICKETS_PRIORITY
365
-        );
366
-        remove_filter(
367
-            'the_content',
368
-            array('EED_Event_Single', 'event_venues'),
369
-            EED_Event_Single::EVENT_VENUES_PRIORITY
370
-        );
371
-        do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters');
372
-        // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
373
-        return $content;
374
-    }
375
-
376
-
377
-    /**
378
-     * event_datetimes - adds datetimes ABOVE content
379
-     *
380
-     * @param        string $content
381
-     * @return        string
382
-     */
383
-    public static function event_datetimes($content)
384
-    {
385
-        return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
386
-    }
387
-
388
-
389
-    /**
390
-     * event_tickets - adds tickets ABOVE content (which includes datetimes)
391
-     *
392
-     * @param        string $content
393
-     * @return        string
394
-     */
395
-    public static function event_tickets($content)
396
-    {
397
-        return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
398
-    }
399
-
400
-
401
-    /**
402
-     * event_venues
403
-     *
404
-     * @param    string $content
405
-     * @return    string
406
-     */
407
-    public static function event_venue($content)
408
-    {
409
-        return EED_Event_Single::event_venues($content);
410
-    }
411
-
412
-
413
-    /**
414
-     * event_venues - adds venues BELOW content
415
-     *
416
-     * @param        string $content
417
-     * @return        string
418
-     */
419
-    public static function event_venues($content)
420
-    {
421
-        return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
422
-    }
423
-
424
-
425
-    /**
426
-     * loop_end
427
-     *
428
-     * @param        array $wp_query_array an array containing the WP_Query object
429
-     * @return        void
430
-     */
431
-    public static function loop_end($wp_query_array)
432
-    {
433
-        global $post;
434
-        do_action('AHEE_event_details_after_post', $post, $wp_query_array);
435
-    }
436
-
437
-
438
-    /**
439
-     * wp_enqueue_scripts
440
-     *
441
-     * @return    void
442
-     */
443
-    public function wp_enqueue_scripts()
444
-    {
445
-        // get some style
446
-        if (apply_filters('FHEE_enable_default_espresso_css', true)
447
-            && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true)
448
-        ) {
449
-            // first check uploads folder
450
-            if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) {
451
-                wp_register_style(
452
-                    $this->theme,
453
-                    get_stylesheet_directory_uri() . $this->theme . '/style.css',
454
-                    array('dashicons', 'espresso_default')
455
-                );
456
-            } else {
457
-                wp_register_style(
458
-                    $this->theme,
459
-                    EE_TEMPLATES_URL . $this->theme . '/style.css',
460
-                    array('dashicons', 'espresso_default')
461
-                );
462
-            }
463
-            wp_enqueue_script($this->theme);
464
-            if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
465
-                add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
466
-            }
467
-        }
468
-    }
469
-
470
-
471
-    /**
472
-     * display_venue
473
-     *
474
-     * @return    bool
475
-     */
476
-    public static function display_venue()
477
-    {
478
-        /** @type EE_Event_Single_Config $config */
479
-        $config = EED_Event_Single::instance()->config();
480
-        $display_venue = $config->display_venue === null ? true : $config->display_venue;
481
-        $venue_name = EEH_Venue_View::venue_name();
482
-        return $display_venue && ! empty($venue_name);
483
-    }
17
+	const EVENT_DETAILS_PRIORITY = 100;
18
+	const EVENT_DATETIMES_PRIORITY = 110;
19
+	const EVENT_TICKETS_PRIORITY = 120;
20
+	const EVENT_VENUES_PRIORITY = 130;
21
+
22
+	/**
23
+	 * @type bool $using_get_the_excerpt
24
+	 */
25
+	protected static $using_get_the_excerpt = false;
26
+
27
+
28
+	/**
29
+	 * @type EE_Template_Part_Manager $template_parts
30
+	 */
31
+	protected $template_parts;
32
+
33
+
34
+	/**
35
+	 * @return EED_Module|EED_Event_Single
36
+	 */
37
+	public static function instance()
38
+	{
39
+		return parent::get_instance(__CLASS__);
40
+	}
41
+
42
+
43
+	/**
44
+	 * set_hooks - for hooking into EE Core, other modules, etc
45
+	 *
46
+	 * @return void
47
+	 * @throws InvalidArgumentException
48
+	 * @throws InvalidDataTypeException
49
+	 * @throws InvalidInterfaceException
50
+	 */
51
+	public static function set_hooks()
52
+	{
53
+		add_filter('FHEE_run_EE_wp', '__return_true');
54
+		add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
55
+		/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */
56
+		$custom_post_type_definitions = LoaderFactory::getLoader()->getShared(
57
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
58
+		);
59
+		$custom_post_types = $custom_post_type_definitions->getDefinitions();
60
+		EE_Config::register_route(
61
+			$custom_post_types['espresso_events']['singular_slug'],
62
+			'Event_Single',
63
+			'run'
64
+		);
65
+	}
66
+
67
+	/**
68
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
69
+	 *
70
+	 * @return    void
71
+	 */
72
+	public static function set_hooks_admin()
73
+	{
74
+		add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
75
+	}
76
+
77
+
78
+	/**
79
+	 * set_definitions
80
+	 *
81
+	 * @static
82
+	 * @return void
83
+	 */
84
+	public static function set_definitions()
85
+	{
86
+		define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
87
+		define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/');
88
+	}
89
+
90
+
91
+	/**
92
+	 * set_config
93
+	 *
94
+	 * @void
95
+	 */
96
+	protected function set_config()
97
+	{
98
+		$this->set_config_section('template_settings');
99
+		$this->set_config_class('EE_Event_Single_Config');
100
+		$this->set_config_name('EED_Event_Single');
101
+	}
102
+
103
+
104
+	/**
105
+	 * initialize_template_parts
106
+	 *
107
+	 * @param EE_Config_Base|EE_Event_Single_Config $config
108
+	 * @return EE_Template_Part_Manager
109
+	 * @throws EE_Error
110
+	 */
111
+	public function initialize_template_parts(EE_Event_Single_Config $config = null)
112
+	{
113
+		/** @type EE_Event_Single_Config $config */
114
+		$config = $config instanceof EE_Event_Single_Config ? $config : $this->config();
115
+		EEH_Autoloader::register_template_part_autoloaders();
116
+		$template_parts = new EE_Template_Part_Manager();
117
+		$template_parts->add_template_part(
118
+			'tickets',
119
+			__('Ticket Selector', 'event_espresso'),
120
+			'content-espresso_events-tickets.php',
121
+			$config->display_order_tickets
122
+		);
123
+		$template_parts->add_template_part(
124
+			'datetimes',
125
+			__('Dates and Times', 'event_espresso'),
126
+			'content-espresso_events-datetimes.php',
127
+			$config->display_order_datetimes
128
+		);
129
+		$template_parts->add_template_part(
130
+			'event',
131
+			__('Event Description', 'event_espresso'),
132
+			'content-espresso_events-details.php',
133
+			$config->display_order_event
134
+		);
135
+		$template_parts->add_template_part(
136
+			'venue',
137
+			__('Venue Information', 'event_espresso'),
138
+			'content-espresso_events-venues.php',
139
+			$config->display_order_venue
140
+		);
141
+		do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts);
142
+		return $template_parts;
143
+	}
144
+
145
+
146
+	/**
147
+	 * run - initial module setup
148
+	 *
149
+	 * @param WP $WP
150
+	 * @return    void
151
+	 */
152
+	public function run($WP)
153
+	{
154
+		// ensure valid EE_Events_Single_Config() object exists
155
+		$this->set_config();
156
+		// check what template is loaded
157
+		add_filter('template_include', array($this, 'template_include'), 999, 1);
158
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
159
+		// load css
160
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
161
+	}
162
+
163
+
164
+	/**
165
+	 * template_include
166
+	 *
167
+	 * @param    string $template
168
+	 * @return    string
169
+	 */
170
+	public function template_include($template)
171
+	{
172
+		global $post;
173
+		/** @type EE_Event_Single_Config $config */
174
+		$config = $this->config();
175
+		if ($config->display_status_banner_single) {
176
+			add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2);
177
+		}
178
+		// not a custom template?
179
+		if (! post_password_required($post)
180
+			&& (
181
+				apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false)
182
+				|| EE_Registry::instance()
183
+							  ->load_core('Front_Controller')
184
+							  ->get_selected_template() !== 'single-espresso_events.php'
185
+			)
186
+
187
+		) {
188
+			EEH_Template::load_espresso_theme_functions();
189
+			// then add extra event data via hooks
190
+			add_action('loop_start', array('EED_Event_Single', 'loop_start'));
191
+			add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1);
192
+			add_filter(
193
+				'the_content',
194
+				array('EED_Event_Single', 'event_details'),
195
+				EED_Event_Single::EVENT_DETAILS_PRIORITY
196
+			);
197
+			add_action('loop_end', array('EED_Event_Single', 'loop_end'));
198
+			// don't display entry meta because the existing theme will take car of that
199
+			add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
200
+		}
201
+		return $template;
202
+	}
203
+
204
+
205
+	/**
206
+	 * loop_start
207
+	 *
208
+	 * @param    array $wp_query_array an array containing the WP_Query object
209
+	 * @return    void
210
+	 */
211
+	public static function loop_start($wp_query_array)
212
+	{
213
+		global $post;
214
+		do_action('AHEE_event_details_before_post', $post, $wp_query_array);
215
+	}
216
+
217
+
218
+	/**
219
+	 * the_title
220
+	 *
221
+	 * @param    string $title
222
+	 * @param    int    $id
223
+	 * @return    string
224
+	 */
225
+	public static function the_title($title = '', $id = 0)
226
+	{
227
+		global $post;
228
+		return in_the_loop() && $post->ID === (int) $id
229
+			? espresso_event_status_banner($post->ID) . $title
230
+			: $title;
231
+	}
232
+
233
+
234
+	/**
235
+	 * get_the_excerpt
236
+	 * kinda hacky, but if a theme is using get_the_excerpt(),
237
+	 * then we need to remove our filters on the_content()
238
+	 *
239
+	 * @param        string $excerpt
240
+	 * @return        string
241
+	 */
242
+	public static function get_the_excerpt($excerpt = '')
243
+	{
244
+		EED_Event_Single::$using_get_the_excerpt = true;
245
+		add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1);
246
+		return $excerpt;
247
+	}
248
+
249
+
250
+	/**
251
+	 * end_get_the_excerpt
252
+	 *
253
+	 * @param  string $text
254
+	 * @return string
255
+	 */
256
+	public static function end_get_the_excerpt($text = '')
257
+	{
258
+		EED_Event_Single::$using_get_the_excerpt = false;
259
+		return $text;
260
+	}
261
+
262
+
263
+	/**
264
+	 * event_details
265
+	 *
266
+	 * @param    string $content
267
+	 * @return    string
268
+	 */
269
+	public static function event_details($content)
270
+	{
271
+		global $post;
272
+		static $current_post_ID = 0;
273
+		if ($current_post_ID !== $post->ID
274
+			&& $post->post_type === 'espresso_events'
275
+			&& ! EED_Event_Single::$using_get_the_excerpt
276
+			&& ! post_password_required()
277
+		) {
278
+			// Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
279
+			// Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
280
+			// BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
281
+			// We want to allow those plugins to still do their thing and have access to our content, but depending on
282
+			// how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
283
+			// so the following allows this filter to be applied multiple times, but only once for real
284
+			$current_post_ID = did_action('loop_start') ? $post->ID : 0;
285
+			if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) {
286
+				// we need to first remove this callback from being applied to the_content()
287
+				// (otherwise it will recurse and blow up the interweb)
288
+				remove_filter(
289
+					'the_content',
290
+					array('EED_Event_Single', 'event_details'),
291
+					EED_Event_Single::EVENT_DETAILS_PRIORITY
292
+				);
293
+				EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts(
294
+				);
295
+				$content = EEH_Template::locate_template('content-espresso_events-details.php');
296
+				$content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content);
297
+				add_filter(
298
+					'the_content',
299
+					array('EED_Event_Single', 'event_details'),
300
+					EED_Event_Single::EVENT_DETAILS_PRIORITY
301
+				);
302
+			} else {
303
+				$content = EED_Event_Single::use_filterable_display_order();
304
+			}
305
+		}
306
+		return $content;
307
+	}
308
+
309
+
310
+	/**
311
+	 * use_filterable_display_order
312
+	 *
313
+	 * @return string
314
+	 */
315
+	protected static function use_filterable_display_order()
316
+	{
317
+		// since the 'content-espresso_events-details.php' template might be used directly from within a theme,
318
+		// it uses the_content() for displaying the $post->post_content
319
+		// so in order to load a template that uses the_content()
320
+		// from within a callback being used to filter the_content(),
321
+		// we need to first remove this callback from being applied to the_content()
322
+		// (otherwise it will recurse and blow up the interweb)
323
+		remove_filter(
324
+			'the_content',
325
+			array('EED_Event_Single', 'event_details'),
326
+			EED_Event_Single::EVENT_DETAILS_PRIORITY
327
+		);
328
+		// now add additional content
329
+		add_filter(
330
+			'the_content',
331
+			array('EED_Event_Single', 'event_datetimes'),
332
+			EED_Event_Single::EVENT_DATETIMES_PRIORITY,
333
+			1
334
+		);
335
+		add_filter(
336
+			'the_content',
337
+			array('EED_Event_Single', 'event_tickets'),
338
+			EED_Event_Single::EVENT_TICKETS_PRIORITY,
339
+			1
340
+		);
341
+		add_filter(
342
+			'the_content',
343
+			array('EED_Event_Single', 'event_venues'),
344
+			EED_Event_Single::EVENT_VENUES_PRIORITY,
345
+			1
346
+		);
347
+		do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters');
348
+		// now load our template
349
+		$content = EEH_Template::locate_template('content-espresso_events-details.php');
350
+		// now add our filter back in, plus some others
351
+		add_filter(
352
+			'the_content',
353
+			array('EED_Event_Single', 'event_details'),
354
+			EED_Event_Single::EVENT_DETAILS_PRIORITY
355
+		);
356
+		remove_filter(
357
+			'the_content',
358
+			array('EED_Event_Single', 'event_datetimes'),
359
+			EED_Event_Single::EVENT_DATETIMES_PRIORITY
360
+		);
361
+		remove_filter(
362
+			'the_content',
363
+			array('EED_Event_Single', 'event_tickets'),
364
+			EED_Event_Single::EVENT_TICKETS_PRIORITY
365
+		);
366
+		remove_filter(
367
+			'the_content',
368
+			array('EED_Event_Single', 'event_venues'),
369
+			EED_Event_Single::EVENT_VENUES_PRIORITY
370
+		);
371
+		do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters');
372
+		// we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
373
+		return $content;
374
+	}
375
+
376
+
377
+	/**
378
+	 * event_datetimes - adds datetimes ABOVE content
379
+	 *
380
+	 * @param        string $content
381
+	 * @return        string
382
+	 */
383
+	public static function event_datetimes($content)
384
+	{
385
+		return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
386
+	}
387
+
388
+
389
+	/**
390
+	 * event_tickets - adds tickets ABOVE content (which includes datetimes)
391
+	 *
392
+	 * @param        string $content
393
+	 * @return        string
394
+	 */
395
+	public static function event_tickets($content)
396
+	{
397
+		return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
398
+	}
399
+
400
+
401
+	/**
402
+	 * event_venues
403
+	 *
404
+	 * @param    string $content
405
+	 * @return    string
406
+	 */
407
+	public static function event_venue($content)
408
+	{
409
+		return EED_Event_Single::event_venues($content);
410
+	}
411
+
412
+
413
+	/**
414
+	 * event_venues - adds venues BELOW content
415
+	 *
416
+	 * @param        string $content
417
+	 * @return        string
418
+	 */
419
+	public static function event_venues($content)
420
+	{
421
+		return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
422
+	}
423
+
424
+
425
+	/**
426
+	 * loop_end
427
+	 *
428
+	 * @param        array $wp_query_array an array containing the WP_Query object
429
+	 * @return        void
430
+	 */
431
+	public static function loop_end($wp_query_array)
432
+	{
433
+		global $post;
434
+		do_action('AHEE_event_details_after_post', $post, $wp_query_array);
435
+	}
436
+
437
+
438
+	/**
439
+	 * wp_enqueue_scripts
440
+	 *
441
+	 * @return    void
442
+	 */
443
+	public function wp_enqueue_scripts()
444
+	{
445
+		// get some style
446
+		if (apply_filters('FHEE_enable_default_espresso_css', true)
447
+			&& apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true)
448
+		) {
449
+			// first check uploads folder
450
+			if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) {
451
+				wp_register_style(
452
+					$this->theme,
453
+					get_stylesheet_directory_uri() . $this->theme . '/style.css',
454
+					array('dashicons', 'espresso_default')
455
+				);
456
+			} else {
457
+				wp_register_style(
458
+					$this->theme,
459
+					EE_TEMPLATES_URL . $this->theme . '/style.css',
460
+					array('dashicons', 'espresso_default')
461
+				);
462
+			}
463
+			wp_enqueue_script($this->theme);
464
+			if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
465
+				add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
466
+			}
467
+		}
468
+	}
469
+
470
+
471
+	/**
472
+	 * display_venue
473
+	 *
474
+	 * @return    bool
475
+	 */
476
+	public static function display_venue()
477
+	{
478
+		/** @type EE_Event_Single_Config $config */
479
+		$config = EED_Event_Single::instance()->config();
480
+		$display_venue = $config->display_venue === null ? true : $config->display_venue;
481
+		$venue_name = EEH_Venue_View::venue_name();
482
+		return $display_venue && ! empty($venue_name);
483
+	}
484 484
 }
485 485
 
486 486
 
@@ -492,5 +492,5 @@  discard block
 block discarded – undo
492 492
  */
493 493
 function espresso_display_venue_in_event_details()
494 494
 {
495
-    return EED_Event_Single::display_venue();
495
+	return EED_Event_Single::display_venue();
496 496
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Autoloader.helper.php 2 patches
Indentation   +291 added lines, -291 removed lines patch added patch discarded remove patch
@@ -17,295 +17,295 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     *    instance of the EE_System object
22
-     *
23
-     * @var    $_instance
24
-     * @access    private
25
-     */
26
-    private static $_instance = null;
27
-
28
-    /**
29
-    *   $_autoloaders
30
-    *   @var array $_autoloaders
31
-    *   @access     private
32
-    */
33
-    private static $_autoloaders;
34
-
35
-    /**
36
-     * set to "paths" to display autoloader class => path mappings
37
-     * set to "times" to display autoloader loading times
38
-     * set to "all" to display both
39
-     *
40
-     * @var string $debug
41
-     * @access    private
42
-     */
43
-    public static $debug = false;
44
-
45
-
46
-    /**
47
-     *    class constructor
48
-     *
49
-     * @access    private
50
-     * @throws EE_Error
51
-     */
52
-    private function __construct()
53
-    {
54
-        if (EEH_Autoloader::$_autoloaders === null) {
55
-            EEH_Autoloader::$_autoloaders = array();
56
-            $this->_register_custom_autoloaders();
57
-            spl_autoload_register(array( $this, 'espresso_autoloader' ));
58
-        }
59
-    }
60
-
61
-
62
-
63
-    /**
64
-     * @access public
65
-     * @return EEH_Autoloader
66
-     */
67
-    public static function instance()
68
-    {
69
-        // check if class object is instantiated
70
-        if (! EEH_Autoloader::$_instance instanceof EEH_Autoloader) {
71
-            EEH_Autoloader::$_instance = new EEH_Autoloader();
72
-        }
73
-        return EEH_Autoloader::$_instance;
74
-    }
75
-
76
-
77
-
78
-    /**
79
-     *    espresso_autoloader
80
-     *
81
-     * @access    public
82
-     * @param   $class_name
83
-     * @internal  param $className
84
-     * @internal  param string $class_name - simple class name ie: session
85
-     * @return  void
86
-     */
87
-    public static function espresso_autoloader($class_name)
88
-    {
89
-        if (isset(EEH_Autoloader::$_autoloaders[ $class_name ])) {
90
-            require_once(EEH_Autoloader::$_autoloaders[ $class_name ]);
91
-        }
92
-    }
93
-
94
-
95
-
96
-    /**
97
-     *    register_autoloader
98
-     *
99
-     * @access    public
100
-     * @param array | string $class_paths - array of key => value pairings between class names and paths
101
-     * @param bool           $read_check  true if we need to check whether the file is readable or not.
102
-     * @param bool           $debug **deprecated**
103
-     * @throws EE_Error
104
-     */
105
-    public static function register_autoloader($class_paths, $read_check = true, $debug = false)
106
-    {
107
-        $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths );
108
-        foreach ($class_paths as $class => $path) {
109
-            // skip all files that are not PHP
110
-            if (substr($path, strlen($path) - 3) !== 'php') {
111
-                continue;
112
-            }
113
-            // don't give up! you gotta...
114
-            // get some class
115
-            if (empty($class)) {
116
-                throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path));
117
-            }
118
-            // one day you will find the path young grasshopper
119
-            if (empty($path)) {
120
-                throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class));
121
-            }
122
-            // is file readable ?
123
-            if ($read_check && ! is_readable($path)) {
124
-                throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path));
125
-            }
126
-            if (! isset(EEH_Autoloader::$_autoloaders[ $class ])) {
127
-                EEH_Autoloader::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path);
128
-                if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) {
129
-                    EEH_Debug_Tools::printr(EEH_Autoloader::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
130
-                }
131
-            }
132
-        }
133
-    }
134
-
135
-
136
-
137
-
138
-    /**
139
-     *  get_autoloaders
140
-     *
141
-     *  @access public
142
-     *  @return array
143
-     */
144
-    public static function get_autoloaders()
145
-    {
146
-        return EEH_Autoloader::$_autoloaders;
147
-    }
148
-
149
-
150
-    /**
151
-     *  register core, model and class 'autoloaders'
152
-     *
153
-     * @access private
154
-     * @return void
155
-     * @throws EE_Error
156
-     */
157
-    private function _register_custom_autoloaders()
158
-    {
159
-        EEH_Autoloader::$debug = '';
160
-        EEH_Autoloader::register_helpers_autoloaders();
161
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces');
162
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
163
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
164
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
165
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
166
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
167
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
168
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
169
-            Benchmark::displayResults();
170
-        }
171
-    }
172
-
173
-
174
-    /**
175
-     *    register core, model and class 'autoloaders'
176
-     *
177
-     * @access public
178
-     * @throws EE_Error
179
-     */
180
-    public static function register_helpers_autoloaders()
181
-    {
182
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
183
-    }
184
-
185
-
186
-
187
-
188
-    /**
189
-     *  register core, model and class 'autoloaders'
190
-     *
191
-     *  @access public
192
-     *  @return void
193
-     */
194
-    public static function register_form_sections_autoloaders()
195
-    {
196
-        // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true );
197
-    }
198
-
199
-
200
-    /**
201
-     *  register core, model and class 'autoloaders'
202
-     *
203
-     * @access public
204
-     * @return void
205
-     * @throws EE_Error
206
-     */
207
-    public static function register_line_item_display_autoloaders()
208
-    {
209
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
210
-    }
211
-
212
-
213
-    /**
214
-     *  register core, model and class 'autoloaders'
215
-     *
216
-     * @access public
217
-     * @return void
218
-     * @throws EE_Error
219
-     */
220
-    public static function register_line_item_filter_autoloaders()
221
-    {
222
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
223
-    }
224
-
225
-
226
-    /**
227
-     *  register template part 'autoloaders'
228
-     *
229
-     * @access public
230
-     * @return void
231
-     * @throws EE_Error
232
-     */
233
-    public static function register_template_part_autoloaders()
234
-    {
235
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
236
-    }
237
-
238
-
239
-    /**
240
-     * @return void
241
-     * @throws EE_Error
242
-     */
243
-    public static function register_business_classes()
244
-    {
245
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business');
246
-    }
247
-
248
-
249
-
250
-    /**
251
-     * Assumes all the files in this folder have the normal naming scheme (namely that their classname
252
-     * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list.
253
-     * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly.
254
-     * Yes this has to scan the directory for files, but it only does it once -- not on EACH
255
-     * time the autoloader is used
256
-     *
257
-     * @param string $folder name, with or without trailing /, doesn't matter
258
-     * @param bool   $recursive
259
-     * @param bool   $debug  **deprecated**
260
-     * @throws EE_Error
261
-     */
262
-    public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false)
263
-    {
264
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) {
265
-            Benchmark::startTimer(basename($folder));
266
-        }
267
-        // make sure last char is a /
268
-        $folder .= $folder[ strlen($folder)-1 ] !== '/' ? '/' : '';
269
-        $class_to_filepath_map = array();
270
-        $exclude = array( 'index' );
271
-        // get all the files in that folder that end in php
272
-        $filepaths = glob($folder.'*');
273
-
274
-        if (empty($filepaths)) {
275
-            return;
276
-        }
277
-
278
-        foreach ($filepaths as $filepath) {
279
-            if (substr($filepath, -4, 4) === '.php') {
280
-                $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
281
-                if (! in_array($class_name, $exclude)) {
282
-                    $class_to_filepath_map [ $class_name ] = $filepath;
283
-                }
284
-            } elseif ($recursive) {
285
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
286
-            }
287
-        }
288
-        // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories.
289
-        EEH_Autoloader::register_autoloader($class_to_filepath_map, false, $debug);
290
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
291
-            Benchmark::stopTimer(basename($folder));
292
-        }
293
-    }
294
-
295
-
296
-
297
-    /**
298
-     * add_alias
299
-     * register additional autoloader based on variation of the classname for an existing autoloader
300
-     *
301
-     * @access    public
302
-     * @param string $class_name - simple class name ie: EE_Session
303
-     * @param string $alias - variation on class name ie: EE_session, session, etc
304
-     */
305
-    public static function add_alias($class_name, $alias)
306
-    {
307
-        if (isset(EEH_Autoloader::$_autoloaders[ $class_name ])) {
308
-            EEH_Autoloader::$_autoloaders[ $alias ] = EEH_Autoloader::$_autoloaders[ $class_name ];
309
-        }
310
-    }
20
+	/**
21
+	 *    instance of the EE_System object
22
+	 *
23
+	 * @var    $_instance
24
+	 * @access    private
25
+	 */
26
+	private static $_instance = null;
27
+
28
+	/**
29
+	 *   $_autoloaders
30
+	 *   @var array $_autoloaders
31
+	 *   @access     private
32
+	 */
33
+	private static $_autoloaders;
34
+
35
+	/**
36
+	 * set to "paths" to display autoloader class => path mappings
37
+	 * set to "times" to display autoloader loading times
38
+	 * set to "all" to display both
39
+	 *
40
+	 * @var string $debug
41
+	 * @access    private
42
+	 */
43
+	public static $debug = false;
44
+
45
+
46
+	/**
47
+	 *    class constructor
48
+	 *
49
+	 * @access    private
50
+	 * @throws EE_Error
51
+	 */
52
+	private function __construct()
53
+	{
54
+		if (EEH_Autoloader::$_autoloaders === null) {
55
+			EEH_Autoloader::$_autoloaders = array();
56
+			$this->_register_custom_autoloaders();
57
+			spl_autoload_register(array( $this, 'espresso_autoloader' ));
58
+		}
59
+	}
60
+
61
+
62
+
63
+	/**
64
+	 * @access public
65
+	 * @return EEH_Autoloader
66
+	 */
67
+	public static function instance()
68
+	{
69
+		// check if class object is instantiated
70
+		if (! EEH_Autoloader::$_instance instanceof EEH_Autoloader) {
71
+			EEH_Autoloader::$_instance = new EEH_Autoloader();
72
+		}
73
+		return EEH_Autoloader::$_instance;
74
+	}
75
+
76
+
77
+
78
+	/**
79
+	 *    espresso_autoloader
80
+	 *
81
+	 * @access    public
82
+	 * @param   $class_name
83
+	 * @internal  param $className
84
+	 * @internal  param string $class_name - simple class name ie: session
85
+	 * @return  void
86
+	 */
87
+	public static function espresso_autoloader($class_name)
88
+	{
89
+		if (isset(EEH_Autoloader::$_autoloaders[ $class_name ])) {
90
+			require_once(EEH_Autoloader::$_autoloaders[ $class_name ]);
91
+		}
92
+	}
93
+
94
+
95
+
96
+	/**
97
+	 *    register_autoloader
98
+	 *
99
+	 * @access    public
100
+	 * @param array | string $class_paths - array of key => value pairings between class names and paths
101
+	 * @param bool           $read_check  true if we need to check whether the file is readable or not.
102
+	 * @param bool           $debug **deprecated**
103
+	 * @throws EE_Error
104
+	 */
105
+	public static function register_autoloader($class_paths, $read_check = true, $debug = false)
106
+	{
107
+		$class_paths = is_array($class_paths) ? $class_paths : array( $class_paths );
108
+		foreach ($class_paths as $class => $path) {
109
+			// skip all files that are not PHP
110
+			if (substr($path, strlen($path) - 3) !== 'php') {
111
+				continue;
112
+			}
113
+			// don't give up! you gotta...
114
+			// get some class
115
+			if (empty($class)) {
116
+				throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path));
117
+			}
118
+			// one day you will find the path young grasshopper
119
+			if (empty($path)) {
120
+				throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class));
121
+			}
122
+			// is file readable ?
123
+			if ($read_check && ! is_readable($path)) {
124
+				throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path));
125
+			}
126
+			if (! isset(EEH_Autoloader::$_autoloaders[ $class ])) {
127
+				EEH_Autoloader::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path);
128
+				if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) {
129
+					EEH_Debug_Tools::printr(EEH_Autoloader::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
130
+				}
131
+			}
132
+		}
133
+	}
134
+
135
+
136
+
137
+
138
+	/**
139
+	 *  get_autoloaders
140
+	 *
141
+	 *  @access public
142
+	 *  @return array
143
+	 */
144
+	public static function get_autoloaders()
145
+	{
146
+		return EEH_Autoloader::$_autoloaders;
147
+	}
148
+
149
+
150
+	/**
151
+	 *  register core, model and class 'autoloaders'
152
+	 *
153
+	 * @access private
154
+	 * @return void
155
+	 * @throws EE_Error
156
+	 */
157
+	private function _register_custom_autoloaders()
158
+	{
159
+		EEH_Autoloader::$debug = '';
160
+		EEH_Autoloader::register_helpers_autoloaders();
161
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces');
162
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
163
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
164
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
165
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
166
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
167
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
168
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
169
+			Benchmark::displayResults();
170
+		}
171
+	}
172
+
173
+
174
+	/**
175
+	 *    register core, model and class 'autoloaders'
176
+	 *
177
+	 * @access public
178
+	 * @throws EE_Error
179
+	 */
180
+	public static function register_helpers_autoloaders()
181
+	{
182
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
183
+	}
184
+
185
+
186
+
187
+
188
+	/**
189
+	 *  register core, model and class 'autoloaders'
190
+	 *
191
+	 *  @access public
192
+	 *  @return void
193
+	 */
194
+	public static function register_form_sections_autoloaders()
195
+	{
196
+		// EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true );
197
+	}
198
+
199
+
200
+	/**
201
+	 *  register core, model and class 'autoloaders'
202
+	 *
203
+	 * @access public
204
+	 * @return void
205
+	 * @throws EE_Error
206
+	 */
207
+	public static function register_line_item_display_autoloaders()
208
+	{
209
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
210
+	}
211
+
212
+
213
+	/**
214
+	 *  register core, model and class 'autoloaders'
215
+	 *
216
+	 * @access public
217
+	 * @return void
218
+	 * @throws EE_Error
219
+	 */
220
+	public static function register_line_item_filter_autoloaders()
221
+	{
222
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
223
+	}
224
+
225
+
226
+	/**
227
+	 *  register template part 'autoloaders'
228
+	 *
229
+	 * @access public
230
+	 * @return void
231
+	 * @throws EE_Error
232
+	 */
233
+	public static function register_template_part_autoloaders()
234
+	{
235
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
236
+	}
237
+
238
+
239
+	/**
240
+	 * @return void
241
+	 * @throws EE_Error
242
+	 */
243
+	public static function register_business_classes()
244
+	{
245
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business');
246
+	}
247
+
248
+
249
+
250
+	/**
251
+	 * Assumes all the files in this folder have the normal naming scheme (namely that their classname
252
+	 * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list.
253
+	 * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly.
254
+	 * Yes this has to scan the directory for files, but it only does it once -- not on EACH
255
+	 * time the autoloader is used
256
+	 *
257
+	 * @param string $folder name, with or without trailing /, doesn't matter
258
+	 * @param bool   $recursive
259
+	 * @param bool   $debug  **deprecated**
260
+	 * @throws EE_Error
261
+	 */
262
+	public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false)
263
+	{
264
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) {
265
+			Benchmark::startTimer(basename($folder));
266
+		}
267
+		// make sure last char is a /
268
+		$folder .= $folder[ strlen($folder)-1 ] !== '/' ? '/' : '';
269
+		$class_to_filepath_map = array();
270
+		$exclude = array( 'index' );
271
+		// get all the files in that folder that end in php
272
+		$filepaths = glob($folder.'*');
273
+
274
+		if (empty($filepaths)) {
275
+			return;
276
+		}
277
+
278
+		foreach ($filepaths as $filepath) {
279
+			if (substr($filepath, -4, 4) === '.php') {
280
+				$class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
281
+				if (! in_array($class_name, $exclude)) {
282
+					$class_to_filepath_map [ $class_name ] = $filepath;
283
+				}
284
+			} elseif ($recursive) {
285
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
286
+			}
287
+		}
288
+		// we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories.
289
+		EEH_Autoloader::register_autoloader($class_to_filepath_map, false, $debug);
290
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
291
+			Benchmark::stopTimer(basename($folder));
292
+		}
293
+	}
294
+
295
+
296
+
297
+	/**
298
+	 * add_alias
299
+	 * register additional autoloader based on variation of the classname for an existing autoloader
300
+	 *
301
+	 * @access    public
302
+	 * @param string $class_name - simple class name ie: EE_Session
303
+	 * @param string $alias - variation on class name ie: EE_session, session, etc
304
+	 */
305
+	public static function add_alias($class_name, $alias)
306
+	{
307
+		if (isset(EEH_Autoloader::$_autoloaders[ $class_name ])) {
308
+			EEH_Autoloader::$_autoloaders[ $alias ] = EEH_Autoloader::$_autoloaders[ $class_name ];
309
+		}
310
+	}
311 311
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
         if (EEH_Autoloader::$_autoloaders === null) {
55 55
             EEH_Autoloader::$_autoloaders = array();
56 56
             $this->_register_custom_autoloaders();
57
-            spl_autoload_register(array( $this, 'espresso_autoloader' ));
57
+            spl_autoload_register(array($this, 'espresso_autoloader'));
58 58
         }
59 59
     }
60 60
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
     public static function instance()
68 68
     {
69 69
         // check if class object is instantiated
70
-        if (! EEH_Autoloader::$_instance instanceof EEH_Autoloader) {
70
+        if ( ! EEH_Autoloader::$_instance instanceof EEH_Autoloader) {
71 71
             EEH_Autoloader::$_instance = new EEH_Autoloader();
72 72
         }
73 73
         return EEH_Autoloader::$_instance;
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
      */
87 87
     public static function espresso_autoloader($class_name)
88 88
     {
89
-        if (isset(EEH_Autoloader::$_autoloaders[ $class_name ])) {
90
-            require_once(EEH_Autoloader::$_autoloaders[ $class_name ]);
89
+        if (isset(EEH_Autoloader::$_autoloaders[$class_name])) {
90
+            require_once(EEH_Autoloader::$_autoloaders[$class_name]);
91 91
         }
92 92
     }
93 93
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
      */
105 105
     public static function register_autoloader($class_paths, $read_check = true, $debug = false)
106 106
     {
107
-        $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths );
107
+        $class_paths = is_array($class_paths) ? $class_paths : array($class_paths);
108 108
         foreach ($class_paths as $class => $path) {
109 109
             // skip all files that are not PHP
110 110
             if (substr($path, strlen($path) - 3) !== 'php') {
@@ -123,10 +123,10 @@  discard block
 block discarded – undo
123 123
             if ($read_check && ! is_readable($path)) {
124 124
                 throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path));
125 125
             }
126
-            if (! isset(EEH_Autoloader::$_autoloaders[ $class ])) {
127
-                EEH_Autoloader::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path);
128
-                if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) {
129
-                    EEH_Debug_Tools::printr(EEH_Autoloader::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
126
+            if ( ! isset(EEH_Autoloader::$_autoloaders[$class])) {
127
+                EEH_Autoloader::$_autoloaders[$class] = str_replace(array('/', '\\'), '/', $path);
128
+                if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) {
129
+                    EEH_Debug_Tools::printr(EEH_Autoloader::$_autoloaders[$class], $class, __FILE__, __LINE__);
130 130
                 }
131 131
             }
132 132
         }
@@ -158,13 +158,13 @@  discard block
 block discarded – undo
158 158
     {
159 159
         EEH_Autoloader::$debug = '';
160 160
         EEH_Autoloader::register_helpers_autoloaders();
161
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces');
161
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces');
162 162
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
163 163
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
164 164
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
165 165
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
166 166
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
167
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
167
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'messages');
168 168
         if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
169 169
             Benchmark::displayResults();
170 170
         }
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
      */
207 207
     public static function register_line_item_display_autoloaders()
208 208
     {
209
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
209
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_display', true);
210 210
     }
211 211
 
212 212
 
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      */
220 220
     public static function register_line_item_filter_autoloaders()
221 221
     {
222
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
222
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_filters', true);
223 223
     }
224 224
 
225 225
 
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
      */
233 233
     public static function register_template_part_autoloaders()
234 234
     {
235
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
235
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'template_parts', true);
236 236
     }
237 237
 
238 238
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
      */
243 243
     public static function register_business_classes()
244 244
     {
245
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business');
245
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'business');
246 246
     }
247 247
 
248 248
 
@@ -265,9 +265,9 @@  discard block
 block discarded – undo
265 265
             Benchmark::startTimer(basename($folder));
266 266
         }
267 267
         // make sure last char is a /
268
-        $folder .= $folder[ strlen($folder)-1 ] !== '/' ? '/' : '';
268
+        $folder .= $folder[strlen($folder) - 1] !== '/' ? '/' : '';
269 269
         $class_to_filepath_map = array();
270
-        $exclude = array( 'index' );
270
+        $exclude = array('index');
271 271
         // get all the files in that folder that end in php
272 272
         $filepaths = glob($folder.'*');
273 273
 
@@ -278,8 +278,8 @@  discard block
 block discarded – undo
278 278
         foreach ($filepaths as $filepath) {
279 279
             if (substr($filepath, -4, 4) === '.php') {
280 280
                 $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
281
-                if (! in_array($class_name, $exclude)) {
282
-                    $class_to_filepath_map [ $class_name ] = $filepath;
281
+                if ( ! in_array($class_name, $exclude)) {
282
+                    $class_to_filepath_map [$class_name] = $filepath;
283 283
                 }
284 284
             } elseif ($recursive) {
285 285
                 EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
@@ -304,8 +304,8 @@  discard block
 block discarded – undo
304 304
      */
305 305
     public static function add_alias($class_name, $alias)
306 306
     {
307
-        if (isset(EEH_Autoloader::$_autoloaders[ $class_name ])) {
308
-            EEH_Autoloader::$_autoloaders[ $alias ] = EEH_Autoloader::$_autoloaders[ $class_name ];
307
+        if (isset(EEH_Autoloader::$_autoloaders[$class_name])) {
308
+            EEH_Autoloader::$_autoloaders[$alias] = EEH_Autoloader::$_autoloaders[$class_name];
309 309
         }
310 310
     }
311 311
 }
Please login to merge, or discard this patch.
core/services/route_match/RouteHandler.php 2 patches
Indentation   +315 added lines, -315 removed lines patch added patch discarded remove patch
@@ -21,319 +21,319 @@
 block discarded – undo
21 21
 class RouteHandler
22 22
 {
23 23
 
24
-    /**
25
-     * @var LoaderInterface
26
-     */
27
-    private $loader;
28
-
29
-    /**
30
-     * @var EE_Maintenance_Mode $maintenance_mode
31
-     */
32
-    private $maintenance_mode;
33
-
34
-    /**
35
-     * @var RequestInterface $request
36
-     */
37
-    private $request;
38
-
39
-    /**
40
-     * @var RouteMatchSpecificationManager $route_manager
41
-     */
42
-    private $route_manager;
43
-
44
-    /**
45
-     * AdminRouter constructor.
46
-     *
47
-     * @param LoaderInterface  $loader
48
-     * @param EE_Maintenance_Mode $maintenance_mode
49
-     * @param RequestInterface $request
50
-     * @param RouteMatchSpecificationManager $route_manager
51
-     */
52
-    public function __construct(
53
-        LoaderInterface $loader,
54
-        EE_Maintenance_Mode $maintenance_mode,
55
-        RequestInterface $request,
56
-        RouteMatchSpecificationManager $route_manager
57
-    ) {
58
-        $this->loader = $loader;
59
-        $this->maintenance_mode = $maintenance_mode;
60
-        $this->request = $request;
61
-        $this->route_manager = $route_manager;
62
-    }
63
-
64
-
65
-    /**
66
-     * @throws Exception
67
-     * @since $VID:$
68
-     */
69
-    public function handleAssetManagerRequest()
70
-    {
71
-        try {
72
-            if (! $this->request->isAdmin()
73
-                && ! $this->request->isFrontend()
74
-                && ! $this->request->isIframe()
75
-                && ! $this->request->isWordPressApi()
76
-            ) {
77
-                return;
78
-            }
79
-            $this->loader->getShared('EventEspresso\core\services\assets\Registry');
80
-            $this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager');
81
-            if ($this->canLoadBlocks()) {
82
-                $this->loader->getShared(
83
-                    'EventEspresso\core\services\editor\BlockRegistrationManager'
84
-                );
85
-            }
86
-        } catch (Exception $exception) {
87
-            new ExceptionStackTraceDisplay($exception);
88
-        }
89
-    }
90
-
91
-
92
-    /**
93
-     * Return whether blocks can be registered/loaded or not.
94
-     *
95
-     * @return bool
96
-     * @since $VID:$
97
-     */
98
-    private function canLoadBlocks()
99
-    {
100
-        return apply_filters('FHEE__EE_System__canLoadBlocks', true)
101
-               && function_exists('register_block_type')
102
-               // don't load blocks if in the Divi page builder editor context
103
-               // @see https://github.com/eventespresso/event-espresso-core/issues/814
104
-               && ! $this->request->getRequestParam('et_fb', false);
105
-    }
106
-
107
-
108
-    /**
109
-     * @throws Exception
110
-     * @since $VID:$
111
-     */
112
-    public function handleControllerRequest()
113
-    {
114
-        try {
115
-            $this->handleAdminRequest();
116
-            $this->handleFrontendRequest();
117
-            $this->handleWordPressHeartbeatRequest();
118
-            $this->handleWordPressPluginsPage();
119
-        } catch (Exception $exception) {
120
-            new ExceptionStackTraceDisplay($exception);
121
-        }
122
-    }
123
-
124
-
125
-    /**
126
-     * @throws Exception
127
-     * @since $VID:$
128
-     */
129
-    private function handleAdminRequest()
130
-    {
131
-        try {
132
-            if (! $this->request->isAdmin() || $this->request->isAdminAjax()) {
133
-                return;
134
-            }
135
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
136
-            $this->loader->getShared('EE_Admin');
137
-
138
-            EE_Dependency_Map::register_dependencies(
139
-                'EventEspresso\core\domain\services\assets\EspressoAdminAssetManager',
140
-                [
141
-                    'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
142
-                    'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
143
-                    'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
144
-                ]
145
-            );
146
-            $this->loader->getShared('EventEspresso\core\domain\services\assets\EspressoAdminAssetManager');
147
-        } catch (Exception $exception) {
148
-            new ExceptionStackTraceDisplay($exception);
149
-        }
150
-    }
151
-
152
-
153
-    /**
154
-     * @throws Exception
155
-     * @since $VID:$
156
-     */
157
-    private function handleFrontendRequest()
158
-    {
159
-        try {
160
-            // don't load frontend if M-Mode is active or request is not browser HTTP
161
-            if ($this->maintenance_mode->level() || ! $this->request->isFrontend() || ! $this->request->isFrontAjax()) {
162
-                return;
163
-            }
164
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
165
-            $this->loader->getShared('EE_Front_Controller');
166
-        } catch (Exception $exception) {
167
-            new ExceptionStackTraceDisplay($exception);
168
-        }
169
-    }
170
-
171
-
172
-    /**
173
-     * @return bool
174
-     * @since $VID:$
175
-     */
176
-    private function isGQLRequest()
177
-    {
178
-        return PHP_VERSION_ID < 70000
179
-               && (
180
-                   $this->request->isGQL()
181
-                   || $this->request->isUnitTest()
182
-                   || $this->route_manager->routeMatchesCurrentRequest(
183
-                       'EventEspresso\core\domain\entities\route_match\specifications\admin\EspressoEventEditor'
184
-                   )
185
-               );
186
-    }
187
-
188
-
189
-    /**
190
-     * @throws Exception
191
-     * @since $VID:$
192
-     */
193
-    public function handleGQLRequest()
194
-    {
195
-        try {
196
-            if (! $this->isGQLRequest()) {
197
-                return;
198
-            }
199
-            if (! class_exists('WPGraphQL')) {
200
-                require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php';
201
-            }
202
-            // load handler for EE GraphQL requests
203
-            $graphQL_manager = $this->loader->getShared(
204
-                'EventEspresso\core\services\graphql\GraphQLManager'
205
-            );
206
-            $graphQL_manager->init();
207
-        } catch (Exception $exception) {
208
-            new ExceptionStackTraceDisplay($exception);
209
-        }
210
-    }
211
-
212
-
213
-    /**
214
-     * @throws Exception
215
-     * @since $VID:$
216
-     */
217
-    public function handlePersonalDataRequest()
218
-    {
219
-        try {
220
-            // don't load frontend if M-Mode is active or request is not browser HTTP
221
-            if (! $this->request->isAdmin()
222
-                || ! $this->request->isAjax()
223
-                || ! $this->maintenance_mode->models_can_query()
224
-            ) {
225
-                return;
226
-            }
227
-            $this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager');
228
-            $this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager');
229
-        } catch (Exception $exception) {
230
-            new ExceptionStackTraceDisplay($exception);
231
-        }
232
-    }
233
-
234
-
235
-    /**
236
-     * @throws Exception
237
-     * @since $VID:$
238
-     */
239
-    public function handlePueRequest()
240
-    {
241
-        try {
242
-            if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
243
-                // pew pew pew
244
-                $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
245
-                do_action('AHEE__EE_System__brew_espresso__after_pue_init');
246
-            }
247
-        } catch (Exception $exception) {
248
-            new ExceptionStackTraceDisplay($exception);
249
-        }
250
-    }
251
-
252
-
253
-    /**
254
-     * @throws Exception
255
-     * @since $VID:$
256
-     */
257
-    public function handleSessionRequest()
258
-    {
259
-        try {
260
-            if (! $this->request->isAdmin() && ! $this->request->isEeAjax() && ! $this->request->isFrontend()) {
261
-                return;
262
-            }
263
-            $this->loader->getShared('EE_Session');
264
-        } catch (Exception $exception) {
265
-            new ExceptionStackTraceDisplay($exception);
266
-        }
267
-    }
268
-
269
-
270
-    /**
271
-     * @throws Exception
272
-     * @since $VID:$
273
-     */
274
-    public function handleShortcodesRequest()
275
-    {
276
-        try {
277
-            if (! $this->request->isFrontend() && ! $this->request->isIframe() && ! $this->request->isAjax()) {
278
-                return;
279
-            }
280
-            // load, register, and add shortcodes the new way
281
-            $this->loader->getShared(
282
-                'EventEspresso\core\services\shortcodes\ShortcodesManager',
283
-                [
284
-                    // and the old way, but we'll put it under control of the new system
285
-                    EE_Config::getLegacyShortcodesManager(),
286
-                ]
287
-            );
288
-        } catch (Exception $exception) {
289
-            new ExceptionStackTraceDisplay($exception);
290
-        }
291
-    }
292
-
293
-
294
-    /**
295
-     * @throws Exception
296
-     * @since $VID:$
297
-     */
298
-    public function handleWordPressHeartbeatRequest()
299
-    {
300
-        try {
301
-            if (! $this->request->isWordPressHeartbeat()) {
302
-                return;
303
-            }
304
-            $this->loader->getShared('EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat');
305
-        } catch (Exception $exception) {
306
-            new ExceptionStackTraceDisplay($exception);
307
-        }
308
-    }
309
-
310
-
311
-    /**
312
-     * @throws Exception
313
-     * @since $VID:$
314
-     */
315
-    public function handleWordPressPluginsPage()
316
-    {
317
-        try {
318
-            if (! $this->request->isAdmin()
319
-                || ! $this->route_manager->routeMatchesCurrentRequest(
320
-                    'EventEspresso\core\domain\entities\route_match\specifications\admin\WordPressPluginsPage'
321
-                )
322
-            ) {
323
-                return;
324
-            }
325
-            EE_Dependency_Map::register_dependencies(
326
-                'EventEspresso\core\domain\services\assets\WordpressPluginsPageAssetManager',
327
-                [
328
-                    'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
329
-                    'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
330
-                    'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
331
-                    'EventEspresso\core\domain\services\admin\ExitModal' => EE_Dependency_Map::load_from_cache,
332
-                ]
333
-            );
334
-            $this->loader->getShared('EventEspresso\core\domain\services\assets\WordpressPluginsPageAssetManager');
335
-        } catch (Exception $exception) {
336
-            new ExceptionStackTraceDisplay($exception);
337
-        }
338
-    }
24
+	/**
25
+	 * @var LoaderInterface
26
+	 */
27
+	private $loader;
28
+
29
+	/**
30
+	 * @var EE_Maintenance_Mode $maintenance_mode
31
+	 */
32
+	private $maintenance_mode;
33
+
34
+	/**
35
+	 * @var RequestInterface $request
36
+	 */
37
+	private $request;
38
+
39
+	/**
40
+	 * @var RouteMatchSpecificationManager $route_manager
41
+	 */
42
+	private $route_manager;
43
+
44
+	/**
45
+	 * AdminRouter constructor.
46
+	 *
47
+	 * @param LoaderInterface  $loader
48
+	 * @param EE_Maintenance_Mode $maintenance_mode
49
+	 * @param RequestInterface $request
50
+	 * @param RouteMatchSpecificationManager $route_manager
51
+	 */
52
+	public function __construct(
53
+		LoaderInterface $loader,
54
+		EE_Maintenance_Mode $maintenance_mode,
55
+		RequestInterface $request,
56
+		RouteMatchSpecificationManager $route_manager
57
+	) {
58
+		$this->loader = $loader;
59
+		$this->maintenance_mode = $maintenance_mode;
60
+		$this->request = $request;
61
+		$this->route_manager = $route_manager;
62
+	}
63
+
64
+
65
+	/**
66
+	 * @throws Exception
67
+	 * @since $VID:$
68
+	 */
69
+	public function handleAssetManagerRequest()
70
+	{
71
+		try {
72
+			if (! $this->request->isAdmin()
73
+				&& ! $this->request->isFrontend()
74
+				&& ! $this->request->isIframe()
75
+				&& ! $this->request->isWordPressApi()
76
+			) {
77
+				return;
78
+			}
79
+			$this->loader->getShared('EventEspresso\core\services\assets\Registry');
80
+			$this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager');
81
+			if ($this->canLoadBlocks()) {
82
+				$this->loader->getShared(
83
+					'EventEspresso\core\services\editor\BlockRegistrationManager'
84
+				);
85
+			}
86
+		} catch (Exception $exception) {
87
+			new ExceptionStackTraceDisplay($exception);
88
+		}
89
+	}
90
+
91
+
92
+	/**
93
+	 * Return whether blocks can be registered/loaded or not.
94
+	 *
95
+	 * @return bool
96
+	 * @since $VID:$
97
+	 */
98
+	private function canLoadBlocks()
99
+	{
100
+		return apply_filters('FHEE__EE_System__canLoadBlocks', true)
101
+			   && function_exists('register_block_type')
102
+			   // don't load blocks if in the Divi page builder editor context
103
+			   // @see https://github.com/eventespresso/event-espresso-core/issues/814
104
+			   && ! $this->request->getRequestParam('et_fb', false);
105
+	}
106
+
107
+
108
+	/**
109
+	 * @throws Exception
110
+	 * @since $VID:$
111
+	 */
112
+	public function handleControllerRequest()
113
+	{
114
+		try {
115
+			$this->handleAdminRequest();
116
+			$this->handleFrontendRequest();
117
+			$this->handleWordPressHeartbeatRequest();
118
+			$this->handleWordPressPluginsPage();
119
+		} catch (Exception $exception) {
120
+			new ExceptionStackTraceDisplay($exception);
121
+		}
122
+	}
123
+
124
+
125
+	/**
126
+	 * @throws Exception
127
+	 * @since $VID:$
128
+	 */
129
+	private function handleAdminRequest()
130
+	{
131
+		try {
132
+			if (! $this->request->isAdmin() || $this->request->isAdminAjax()) {
133
+				return;
134
+			}
135
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
136
+			$this->loader->getShared('EE_Admin');
137
+
138
+			EE_Dependency_Map::register_dependencies(
139
+				'EventEspresso\core\domain\services\assets\EspressoAdminAssetManager',
140
+				[
141
+					'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
142
+					'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
143
+					'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
144
+				]
145
+			);
146
+			$this->loader->getShared('EventEspresso\core\domain\services\assets\EspressoAdminAssetManager');
147
+		} catch (Exception $exception) {
148
+			new ExceptionStackTraceDisplay($exception);
149
+		}
150
+	}
151
+
152
+
153
+	/**
154
+	 * @throws Exception
155
+	 * @since $VID:$
156
+	 */
157
+	private function handleFrontendRequest()
158
+	{
159
+		try {
160
+			// don't load frontend if M-Mode is active or request is not browser HTTP
161
+			if ($this->maintenance_mode->level() || ! $this->request->isFrontend() || ! $this->request->isFrontAjax()) {
162
+				return;
163
+			}
164
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
165
+			$this->loader->getShared('EE_Front_Controller');
166
+		} catch (Exception $exception) {
167
+			new ExceptionStackTraceDisplay($exception);
168
+		}
169
+	}
170
+
171
+
172
+	/**
173
+	 * @return bool
174
+	 * @since $VID:$
175
+	 */
176
+	private function isGQLRequest()
177
+	{
178
+		return PHP_VERSION_ID < 70000
179
+			   && (
180
+				   $this->request->isGQL()
181
+				   || $this->request->isUnitTest()
182
+				   || $this->route_manager->routeMatchesCurrentRequest(
183
+					   'EventEspresso\core\domain\entities\route_match\specifications\admin\EspressoEventEditor'
184
+				   )
185
+			   );
186
+	}
187
+
188
+
189
+	/**
190
+	 * @throws Exception
191
+	 * @since $VID:$
192
+	 */
193
+	public function handleGQLRequest()
194
+	{
195
+		try {
196
+			if (! $this->isGQLRequest()) {
197
+				return;
198
+			}
199
+			if (! class_exists('WPGraphQL')) {
200
+				require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php';
201
+			}
202
+			// load handler for EE GraphQL requests
203
+			$graphQL_manager = $this->loader->getShared(
204
+				'EventEspresso\core\services\graphql\GraphQLManager'
205
+			);
206
+			$graphQL_manager->init();
207
+		} catch (Exception $exception) {
208
+			new ExceptionStackTraceDisplay($exception);
209
+		}
210
+	}
211
+
212
+
213
+	/**
214
+	 * @throws Exception
215
+	 * @since $VID:$
216
+	 */
217
+	public function handlePersonalDataRequest()
218
+	{
219
+		try {
220
+			// don't load frontend if M-Mode is active or request is not browser HTTP
221
+			if (! $this->request->isAdmin()
222
+				|| ! $this->request->isAjax()
223
+				|| ! $this->maintenance_mode->models_can_query()
224
+			) {
225
+				return;
226
+			}
227
+			$this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager');
228
+			$this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager');
229
+		} catch (Exception $exception) {
230
+			new ExceptionStackTraceDisplay($exception);
231
+		}
232
+	}
233
+
234
+
235
+	/**
236
+	 * @throws Exception
237
+	 * @since $VID:$
238
+	 */
239
+	public function handlePueRequest()
240
+	{
241
+		try {
242
+			if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
243
+				// pew pew pew
244
+				$this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
245
+				do_action('AHEE__EE_System__brew_espresso__after_pue_init');
246
+			}
247
+		} catch (Exception $exception) {
248
+			new ExceptionStackTraceDisplay($exception);
249
+		}
250
+	}
251
+
252
+
253
+	/**
254
+	 * @throws Exception
255
+	 * @since $VID:$
256
+	 */
257
+	public function handleSessionRequest()
258
+	{
259
+		try {
260
+			if (! $this->request->isAdmin() && ! $this->request->isEeAjax() && ! $this->request->isFrontend()) {
261
+				return;
262
+			}
263
+			$this->loader->getShared('EE_Session');
264
+		} catch (Exception $exception) {
265
+			new ExceptionStackTraceDisplay($exception);
266
+		}
267
+	}
268
+
269
+
270
+	/**
271
+	 * @throws Exception
272
+	 * @since $VID:$
273
+	 */
274
+	public function handleShortcodesRequest()
275
+	{
276
+		try {
277
+			if (! $this->request->isFrontend() && ! $this->request->isIframe() && ! $this->request->isAjax()) {
278
+				return;
279
+			}
280
+			// load, register, and add shortcodes the new way
281
+			$this->loader->getShared(
282
+				'EventEspresso\core\services\shortcodes\ShortcodesManager',
283
+				[
284
+					// and the old way, but we'll put it under control of the new system
285
+					EE_Config::getLegacyShortcodesManager(),
286
+				]
287
+			);
288
+		} catch (Exception $exception) {
289
+			new ExceptionStackTraceDisplay($exception);
290
+		}
291
+	}
292
+
293
+
294
+	/**
295
+	 * @throws Exception
296
+	 * @since $VID:$
297
+	 */
298
+	public function handleWordPressHeartbeatRequest()
299
+	{
300
+		try {
301
+			if (! $this->request->isWordPressHeartbeat()) {
302
+				return;
303
+			}
304
+			$this->loader->getShared('EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat');
305
+		} catch (Exception $exception) {
306
+			new ExceptionStackTraceDisplay($exception);
307
+		}
308
+	}
309
+
310
+
311
+	/**
312
+	 * @throws Exception
313
+	 * @since $VID:$
314
+	 */
315
+	public function handleWordPressPluginsPage()
316
+	{
317
+		try {
318
+			if (! $this->request->isAdmin()
319
+				|| ! $this->route_manager->routeMatchesCurrentRequest(
320
+					'EventEspresso\core\domain\entities\route_match\specifications\admin\WordPressPluginsPage'
321
+				)
322
+			) {
323
+				return;
324
+			}
325
+			EE_Dependency_Map::register_dependencies(
326
+				'EventEspresso\core\domain\services\assets\WordpressPluginsPageAssetManager',
327
+				[
328
+					'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
329
+					'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
330
+					'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
331
+					'EventEspresso\core\domain\services\admin\ExitModal' => EE_Dependency_Map::load_from_cache,
332
+				]
333
+			);
334
+			$this->loader->getShared('EventEspresso\core\domain\services\assets\WordpressPluginsPageAssetManager');
335
+		} catch (Exception $exception) {
336
+			new ExceptionStackTraceDisplay($exception);
337
+		}
338
+	}
339 339
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
     public function handleAssetManagerRequest()
70 70
     {
71 71
         try {
72
-            if (! $this->request->isAdmin()
72
+            if ( ! $this->request->isAdmin()
73 73
                 && ! $this->request->isFrontend()
74 74
                 && ! $this->request->isIframe()
75 75
                 && ! $this->request->isWordPressApi()
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
     private function handleAdminRequest()
130 130
     {
131 131
         try {
132
-            if (! $this->request->isAdmin() || $this->request->isAdminAjax()) {
132
+            if ( ! $this->request->isAdmin() || $this->request->isAdminAjax()) {
133 133
                 return;
134 134
             }
135 135
             do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
@@ -193,11 +193,11 @@  discard block
 block discarded – undo
193 193
     public function handleGQLRequest()
194 194
     {
195 195
         try {
196
-            if (! $this->isGQLRequest()) {
196
+            if ( ! $this->isGQLRequest()) {
197 197
                 return;
198 198
             }
199
-            if (! class_exists('WPGraphQL')) {
200
-                require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php';
199
+            if ( ! class_exists('WPGraphQL')) {
200
+                require_once EE_THIRD_PARTY.'wp-graphql/wp-graphql.php';
201 201
             }
202 202
             // load handler for EE GraphQL requests
203 203
             $graphQL_manager = $this->loader->getShared(
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
     {
219 219
         try {
220 220
             // don't load frontend if M-Mode is active or request is not browser HTTP
221
-            if (! $this->request->isAdmin()
221
+            if ( ! $this->request->isAdmin()
222 222
                 || ! $this->request->isAjax()
223 223
                 || ! $this->maintenance_mode->models_can_query()
224 224
             ) {
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
     public function handleSessionRequest()
258 258
     {
259 259
         try {
260
-            if (! $this->request->isAdmin() && ! $this->request->isEeAjax() && ! $this->request->isFrontend()) {
260
+            if ( ! $this->request->isAdmin() && ! $this->request->isEeAjax() && ! $this->request->isFrontend()) {
261 261
                 return;
262 262
             }
263 263
             $this->loader->getShared('EE_Session');
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
     public function handleShortcodesRequest()
275 275
     {
276 276
         try {
277
-            if (! $this->request->isFrontend() && ! $this->request->isIframe() && ! $this->request->isAjax()) {
277
+            if ( ! $this->request->isFrontend() && ! $this->request->isIframe() && ! $this->request->isAjax()) {
278 278
                 return;
279 279
             }
280 280
             // load, register, and add shortcodes the new way
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
     public function handleWordPressHeartbeatRequest()
299 299
     {
300 300
         try {
301
-            if (! $this->request->isWordPressHeartbeat()) {
301
+            if ( ! $this->request->isWordPressHeartbeat()) {
302 302
                 return;
303 303
             }
304 304
             $this->loader->getShared('EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat');
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
     public function handleWordPressPluginsPage()
316 316
     {
317 317
         try {
318
-            if (! $this->request->isAdmin()
318
+            if ( ! $this->request->isAdmin()
319 319
                 || ! $this->route_manager->routeMatchesCurrentRequest(
320 320
                     'EventEspresso\core\domain\entities\route_match\specifications\admin\WordPressPluginsPage'
321 321
                 )
Please login to merge, or discard this patch.
core/services/request/Request.php 1 patch
Indentation   +671 added lines, -671 removed lines patch added patch discarded remove patch
@@ -17,675 +17,675 @@
 block discarded – undo
17 17
 class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface
18 18
 {
19 19
 
20
-    /**
21
-     * $_GET parameters
22
-     *
23
-     * @var array $get
24
-     */
25
-    private $get;
26
-
27
-    /**
28
-     * $_POST parameters
29
-     *
30
-     * @var array $post
31
-     */
32
-    private $post;
33
-
34
-    /**
35
-     * $_COOKIE parameters
36
-     *
37
-     * @var array $cookie
38
-     */
39
-    private $cookie;
40
-
41
-    /**
42
-     * $_SERVER parameters
43
-     *
44
-     * @var array $server
45
-     */
46
-    private $server;
47
-
48
-    /**
49
-     * $_FILES parameters
50
-     *
51
-     * @var array $files
52
-     */
53
-    private $files;
54
-
55
-    /**
56
-     * $_REQUEST parameters
57
-     *
58
-     * @var array $request
59
-     */
60
-    private $request;
61
-
62
-    /**
63
-     * @var RequestTypeContextCheckerInterface
64
-     */
65
-    private $request_type;
66
-
67
-    /**
68
-     * IP address for request
69
-     *
70
-     * @var string $ip_address
71
-     */
72
-    private $ip_address;
73
-
74
-    /**
75
-     * @var string $user_agent
76
-     */
77
-    private $user_agent;
78
-
79
-    /**
80
-     * true if current user appears to be some kind of bot
81
-     *
82
-     * @var bool $is_bot
83
-     */
84
-    private $is_bot;
85
-
86
-
87
-    /**
88
-     * @param array $get
89
-     * @param array $post
90
-     * @param array $cookie
91
-     * @param array $server
92
-     * @param array $files
93
-     */
94
-    public function __construct(array $get, array $post, array $cookie, array $server, array $files = array())
95
-    {
96
-        // grab request vars
97
-        $this->get = $get;
98
-        $this->post = $post;
99
-        $this->cookie = $cookie;
100
-        $this->server = $server;
101
-        $this->files = $files;
102
-        $this->request = array_merge($this->get, $this->post);
103
-        $this->ip_address = $this->visitorIp();
104
-    }
105
-
106
-
107
-    /**
108
-     * @param RequestTypeContextCheckerInterface $type
109
-     */
110
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
111
-    {
112
-        $this->request_type = $type;
113
-    }
114
-
115
-
116
-    /**
117
-     * @return array
118
-     */
119
-    public function getParams()
120
-    {
121
-        return $this->get;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return array
127
-     */
128
-    public function postParams()
129
-    {
130
-        return $this->post;
131
-    }
132
-
133
-
134
-    /**
135
-     * @return array
136
-     */
137
-    public function cookieParams()
138
-    {
139
-        return $this->cookie;
140
-    }
141
-
142
-
143
-    /**
144
-     * @return array
145
-     */
146
-    public function serverParams()
147
-    {
148
-        return $this->server;
149
-    }
150
-
151
-
152
-    /**
153
-     * @return array
154
-     */
155
-    public function filesParams()
156
-    {
157
-        return $this->files;
158
-    }
159
-
160
-
161
-    /**
162
-     * returns contents of $_REQUEST
163
-     *
164
-     * @return array
165
-     */
166
-    public function requestParams()
167
-    {
168
-        return $this->request;
169
-    }
170
-
171
-
172
-    /**
173
-     * @param      $key
174
-     * @param      $value
175
-     * @param bool $override_ee
176
-     * @return    void
177
-     */
178
-    public function setRequestParam($key, $value, $override_ee = false)
179
-    {
180
-        // don't allow "ee" to be overwritten unless explicitly instructed to do so
181
-        if ($key !== 'ee'
182
-            || ($key === 'ee' && empty($this->request['ee']))
183
-            || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
184
-        ) {
185
-            $this->request[ $key ] = $value;
186
-        }
187
-    }
188
-
189
-
190
-    /**
191
-     * returns   the value for a request param if the given key exists
192
-     *
193
-     * @param       $key
194
-     * @param null  $default
195
-     * @return mixed
196
-     */
197
-    public function getRequestParam($key, $default = null)
198
-    {
199
-        return $this->requestParameterDrillDown($key, $default, 'get');
200
-    }
201
-
202
-
203
-    /**
204
-     * check if param exists
205
-     *
206
-     * @param       $key
207
-     * @return bool
208
-     */
209
-    public function requestParamIsSet($key)
210
-    {
211
-        return $this->requestParameterDrillDown($key);
212
-    }
213
-
214
-
215
-    /**
216
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
217
-     * and return the value for the first match found
218
-     * wildcards can be either of the following:
219
-     *      ? to represent a single character of any type
220
-     *      * to represent one or more characters of any type
221
-     *
222
-     * @param string     $pattern
223
-     * @param null|mixed $default
224
-     * @return mixed
225
-     */
226
-    public function getMatch($pattern, $default = null)
227
-    {
228
-        return $this->requestParameterDrillDown($pattern, $default, 'match');
229
-    }
230
-
231
-
232
-    /**
233
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
234
-     * wildcards can be either of the following:
235
-     *      ? to represent a single character of any type
236
-     *      * to represent one or more characters of any type
237
-     * returns true if a match is found or false if not
238
-     *
239
-     * @param string $pattern
240
-     * @return bool
241
-     */
242
-    public function matches($pattern)
243
-    {
244
-        return $this->requestParameterDrillDown($pattern, null, 'match') !== null;
245
-    }
246
-
247
-
248
-    /**
249
-     * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
250
-     * @param string $pattern               A string including wildcards to be converted to a regex pattern
251
-     *                                      and used to search through the current request's parameter keys
252
-     * @param array  $request_params        The array of request parameters to search through
253
-     * @param mixed  $default               [optional] The value to be returned if no match is found.
254
-     *                                      Default is null
255
-     * @param string $return                [optional] Controls what kind of value is returned.
256
-     *                                      Options are:
257
-     *                                      'bool' will return true or false if match is found or not
258
-     *                                      'key' will return the first key found that matches the supplied pattern
259
-     *                                      'value' will return the value for the first request parameter
260
-     *                                      whose key matches the supplied pattern
261
-     *                                      Default is 'value'
262
-     * @return boolean|string
263
-     */
264
-    private function match($pattern, array $request_params, $default = null, $return = 'value')
265
-    {
266
-        $return = in_array($return, array('bool', 'key', 'value'), true)
267
-            ? $return
268
-            : 'is_set';
269
-        // replace wildcard chars with regex chars
270
-        $pattern = str_replace(
271
-            array("\*", "\?"),
272
-            array('.*', '.'),
273
-            preg_quote($pattern, '/')
274
-        );
275
-        foreach ($request_params as $key => $request_param) {
276
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
277
-                // return value for request param
278
-                if ($return === 'value') {
279
-                    return $request_params[ $key ];
280
-                }
281
-                // or actual key or true just to indicate it was found
282
-                return $return === 'key' ? $key : true;
283
-            }
284
-        }
285
-        // match not found so return default value or false
286
-        return $return === 'value' ? $default : false;
287
-    }
288
-
289
-
290
-    /**
291
-     * the supplied key can be a simple string to represent a "top-level" request parameter
292
-     * or represent a key for a request parameter that is nested deeper within the request parameter array,
293
-     * by using square brackets to surround keys for deeper array elements.
294
-     * For example :
295
-     * if the supplied $key was: "first[second][third]"
296
-     * then this will attempt to drill down into the request parameter array to find a value.
297
-     * Given the following request parameters:
298
-     *  array(
299
-     *      'first' => array(
300
-     *          'second' => array(
301
-     *              'third' => 'has a value'
302
-     *          )
303
-     *      )
304
-     *  )
305
-     * would return true if default parameters were set
306
-     *
307
-     * @param string $callback
308
-     * @param        $key
309
-     * @param null   $default
310
-     * @param array  $request_params
311
-     * @return bool|mixed|null
312
-     */
313
-    private function requestParameterDrillDown(
314
-        $key,
315
-        $default = null,
316
-        $callback = 'is_set',
317
-        array $request_params = array()
318
-    ) {
319
-        $callback = in_array($callback, array('is_set', 'get', 'match'), true)
320
-            ? $callback
321
-            : 'is_set';
322
-        $request_params = ! empty($request_params)
323
-            ? $request_params
324
-            : $this->request;
325
-        // does incoming key represent an array like 'first[second][third]'  ?
326
-        if (strpos($key, '[') !== false) {
327
-            // turn it into an actual array
328
-            $key = str_replace(']', '', $key);
329
-            $keys = explode('[', $key);
330
-            $key = array_shift($keys);
331
-            if ($callback === 'match') {
332
-                $real_key = $this->match($key, $request_params, $default, 'key');
333
-                $key = $real_key ? $real_key : $key;
334
-            }
335
-            // check if top level key exists
336
-            if (isset($request_params[ $key ])) {
337
-                // build a new key to pass along like: 'second[third]'
338
-                // or just 'second' depending on depth of keys
339
-                $key_string = array_shift($keys);
340
-                if (! empty($keys)) {
341
-                    $key_string .= '[' . implode('][', $keys) . ']';
342
-                }
343
-                return $this->requestParameterDrillDown(
344
-                    $key_string,
345
-                    $default,
346
-                    $callback,
347
-                    $request_params[ $key ]
348
-                );
349
-            }
350
-        }
351
-        if ($callback === 'is_set') {
352
-            return isset($request_params[ $key ]);
353
-        }
354
-        if ($callback === 'match') {
355
-            return $this->match($key, $request_params, $default);
356
-        }
357
-        return isset($request_params[ $key ])
358
-            ? $request_params[ $key ]
359
-            : $default;
360
-    }
361
-
362
-
363
-    /**
364
-     * remove param
365
-     *
366
-     * @param      $key
367
-     * @param bool $unset_from_global_too
368
-     */
369
-    public function unSetRequestParam($key, $unset_from_global_too = false)
370
-    {
371
-        // because unset may not actually remove var
372
-        $this->request[ $key ] = null;
373
-        unset($this->request[ $key ]);
374
-        if ($unset_from_global_too) {
375
-            unset($_REQUEST[ $key ]);
376
-        }
377
-    }
378
-
379
-
380
-    /**
381
-     * remove params
382
-     *
383
-     * @param array $keys
384
-     * @param bool  $unset_from_global_too
385
-     */
386
-    public function unSetRequestParams(array $keys, $unset_from_global_too = false)
387
-    {
388
-        foreach ($keys as $key) {
389
-            $this->unSetRequestParam($key, $unset_from_global_too);
390
-        }
391
-    }
392
-
393
-
394
-    /**
395
-     * @return string
396
-     */
397
-    public function ipAddress()
398
-    {
399
-        return $this->ip_address;
400
-    }
401
-
402
-
403
-    /**
404
-     * attempt to get IP address of current visitor from server
405
-     * plz see: http://stackoverflow.com/a/2031935/1475279
406
-     *
407
-     * @access public
408
-     * @return string
409
-     */
410
-    private function visitorIp()
411
-    {
412
-        $visitor_ip = '0.0.0.0';
413
-        $server_keys = array(
414
-            'HTTP_CLIENT_IP',
415
-            'HTTP_X_FORWARDED_FOR',
416
-            'HTTP_X_FORWARDED',
417
-            'HTTP_X_CLUSTER_CLIENT_IP',
418
-            'HTTP_FORWARDED_FOR',
419
-            'HTTP_FORWARDED',
420
-            'REMOTE_ADDR',
421
-        );
422
-        foreach ($server_keys as $key) {
423
-            if (isset($this->server[ $key ])) {
424
-                foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
425
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
426
-                        $visitor_ip = $ip;
427
-                    }
428
-                }
429
-            }
430
-        }
431
-        return $visitor_ip;
432
-    }
433
-
434
-
435
-    /**
436
-     * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
437
-     * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
438
-     *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
439
-     *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
440
-     * @return string
441
-     */
442
-    public function requestUri($relativeToWpRoot = false)
443
-    {
444
-        $request_uri = filter_input(
445
-            INPUT_SERVER,
446
-            'REQUEST_URI',
447
-            FILTER_SANITIZE_URL,
448
-            FILTER_NULL_ON_FAILURE
449
-        );
450
-        if (empty($request_uri)) {
451
-            // fallback sanitization if the above fails
452
-            $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
453
-        }
454
-        if ($relativeToWpRoot) {
455
-            $home_path = untrailingslashit(
456
-                parse_url(
457
-                    home_url(),
458
-                    PHP_URL_PATH
459
-                )
460
-            );
461
-            $request_uri = str_replace(
462
-                $home_path,
463
-                '',
464
-                $request_uri
465
-            );
466
-        }
467
-        return $request_uri;
468
-    }
469
-
470
-    /**
471
-     * @return string
472
-     */
473
-    public function userAgent()
474
-    {
475
-        return $this->user_agent;
476
-    }
477
-
478
-
479
-    /**
480
-     * @param string $user_agent
481
-     */
482
-    public function setUserAgent($user_agent = '')
483
-    {
484
-        if ($user_agent === '' || ! is_string($user_agent)) {
485
-            $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
486
-        }
487
-        $this->user_agent = $user_agent;
488
-    }
489
-
490
-
491
-    /**
492
-     * @return bool
493
-     */
494
-    public function isBot()
495
-    {
496
-        return $this->is_bot;
497
-    }
498
-
499
-
500
-    /**
501
-     * @param bool $is_bot
502
-     */
503
-    public function setIsBot($is_bot)
504
-    {
505
-        $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
506
-    }
507
-
508
-
509
-    /**
510
-     * @return bool
511
-     */
512
-    public function isActivation()
513
-    {
514
-        return $this->request_type->isActivation();
515
-    }
516
-
517
-
518
-    /**
519
-     * @param $is_activation
520
-     * @return bool
521
-     */
522
-    public function setIsActivation($is_activation)
523
-    {
524
-        return $this->request_type->setIsActivation($is_activation);
525
-    }
526
-
527
-
528
-    /**
529
-     * @return bool
530
-     */
531
-    public function isAdmin()
532
-    {
533
-        return $this->request_type->isAdmin();
534
-    }
535
-
536
-
537
-    /**
538
-     * @return bool
539
-     */
540
-    public function isAdminAjax()
541
-    {
542
-        return $this->request_type->isAdminAjax();
543
-    }
544
-
545
-
546
-    /**
547
-     * @return bool
548
-     */
549
-    public function isAjax()
550
-    {
551
-        return $this->request_type->isAjax();
552
-    }
553
-
554
-
555
-    /**
556
-     * @return bool
557
-     */
558
-    public function isEeAjax()
559
-    {
560
-        return $this->request_type->isEeAjax();
561
-    }
562
-
563
-
564
-    /**
565
-     * @return bool
566
-     */
567
-    public function isOtherAjax()
568
-    {
569
-        return $this->request_type->isOtherAjax();
570
-    }
571
-
572
-
573
-    /**
574
-     * @return bool
575
-     */
576
-    public function isApi()
577
-    {
578
-        return $this->request_type->isApi();
579
-    }
580
-
581
-
582
-    /**
583
-     * @return bool
584
-     */
585
-    public function isCli()
586
-    {
587
-        return $this->request_type->isCli();
588
-    }
589
-
590
-
591
-    /**
592
-     * @return bool
593
-     */
594
-    public function isCron()
595
-    {
596
-        return $this->request_type->isCron();
597
-    }
598
-
599
-
600
-    /**
601
-     * @return bool
602
-     */
603
-    public function isFeed()
604
-    {
605
-        return $this->request_type->isFeed();
606
-    }
607
-
608
-
609
-    /**
610
-     * @return bool
611
-     */
612
-    public function isFrontend()
613
-    {
614
-        return $this->request_type->isFrontend();
615
-    }
616
-
617
-
618
-    /**
619
-     * @return bool
620
-     */
621
-    public function isFrontAjax()
622
-    {
623
-        return $this->request_type->isFrontAjax();
624
-    }
625
-
626
-
627
-    /**
628
-     * @return bool
629
-     */
630
-    public function isGQL()
631
-    {
632
-        return $this->request_type->isGQL();
633
-    }
634
-
635
-
636
-    /**
637
-     * @return bool
638
-     */
639
-    public function isIframe()
640
-    {
641
-        return $this->request_type->isIframe();
642
-    }
643
-
644
-
645
-
646
-    /**
647
-     * @return bool
648
-     */
649
-    public function isUnitTest()
650
-    {
651
-        return $this->request_type->isUnitTest();
652
-    }
653
-
654
-
655
-    /**
656
-     * @return bool
657
-     */
658
-    public function isWordPressApi()
659
-    {
660
-        return $this->request_type->isWordPressApi();
661
-    }
662
-
663
-
664
-
665
-    /**
666
-     * @return bool
667
-     */
668
-    public function isWordPressHeartbeat()
669
-    {
670
-        return $this->request_type->isWordPressHeartbeat();
671
-    }
672
-
673
-
674
-
675
-    /**
676
-     * @return bool
677
-     */
678
-    public function isWordPressScrape()
679
-    {
680
-        return $this->request_type->isWordPressScrape();
681
-    }
682
-
683
-
684
-    /**
685
-     * @return string
686
-     */
687
-    public function slug()
688
-    {
689
-        return $this->request_type->slug();
690
-    }
20
+	/**
21
+	 * $_GET parameters
22
+	 *
23
+	 * @var array $get
24
+	 */
25
+	private $get;
26
+
27
+	/**
28
+	 * $_POST parameters
29
+	 *
30
+	 * @var array $post
31
+	 */
32
+	private $post;
33
+
34
+	/**
35
+	 * $_COOKIE parameters
36
+	 *
37
+	 * @var array $cookie
38
+	 */
39
+	private $cookie;
40
+
41
+	/**
42
+	 * $_SERVER parameters
43
+	 *
44
+	 * @var array $server
45
+	 */
46
+	private $server;
47
+
48
+	/**
49
+	 * $_FILES parameters
50
+	 *
51
+	 * @var array $files
52
+	 */
53
+	private $files;
54
+
55
+	/**
56
+	 * $_REQUEST parameters
57
+	 *
58
+	 * @var array $request
59
+	 */
60
+	private $request;
61
+
62
+	/**
63
+	 * @var RequestTypeContextCheckerInterface
64
+	 */
65
+	private $request_type;
66
+
67
+	/**
68
+	 * IP address for request
69
+	 *
70
+	 * @var string $ip_address
71
+	 */
72
+	private $ip_address;
73
+
74
+	/**
75
+	 * @var string $user_agent
76
+	 */
77
+	private $user_agent;
78
+
79
+	/**
80
+	 * true if current user appears to be some kind of bot
81
+	 *
82
+	 * @var bool $is_bot
83
+	 */
84
+	private $is_bot;
85
+
86
+
87
+	/**
88
+	 * @param array $get
89
+	 * @param array $post
90
+	 * @param array $cookie
91
+	 * @param array $server
92
+	 * @param array $files
93
+	 */
94
+	public function __construct(array $get, array $post, array $cookie, array $server, array $files = array())
95
+	{
96
+		// grab request vars
97
+		$this->get = $get;
98
+		$this->post = $post;
99
+		$this->cookie = $cookie;
100
+		$this->server = $server;
101
+		$this->files = $files;
102
+		$this->request = array_merge($this->get, $this->post);
103
+		$this->ip_address = $this->visitorIp();
104
+	}
105
+
106
+
107
+	/**
108
+	 * @param RequestTypeContextCheckerInterface $type
109
+	 */
110
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
111
+	{
112
+		$this->request_type = $type;
113
+	}
114
+
115
+
116
+	/**
117
+	 * @return array
118
+	 */
119
+	public function getParams()
120
+	{
121
+		return $this->get;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return array
127
+	 */
128
+	public function postParams()
129
+	{
130
+		return $this->post;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @return array
136
+	 */
137
+	public function cookieParams()
138
+	{
139
+		return $this->cookie;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @return array
145
+	 */
146
+	public function serverParams()
147
+	{
148
+		return $this->server;
149
+	}
150
+
151
+
152
+	/**
153
+	 * @return array
154
+	 */
155
+	public function filesParams()
156
+	{
157
+		return $this->files;
158
+	}
159
+
160
+
161
+	/**
162
+	 * returns contents of $_REQUEST
163
+	 *
164
+	 * @return array
165
+	 */
166
+	public function requestParams()
167
+	{
168
+		return $this->request;
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param      $key
174
+	 * @param      $value
175
+	 * @param bool $override_ee
176
+	 * @return    void
177
+	 */
178
+	public function setRequestParam($key, $value, $override_ee = false)
179
+	{
180
+		// don't allow "ee" to be overwritten unless explicitly instructed to do so
181
+		if ($key !== 'ee'
182
+			|| ($key === 'ee' && empty($this->request['ee']))
183
+			|| ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
184
+		) {
185
+			$this->request[ $key ] = $value;
186
+		}
187
+	}
188
+
189
+
190
+	/**
191
+	 * returns   the value for a request param if the given key exists
192
+	 *
193
+	 * @param       $key
194
+	 * @param null  $default
195
+	 * @return mixed
196
+	 */
197
+	public function getRequestParam($key, $default = null)
198
+	{
199
+		return $this->requestParameterDrillDown($key, $default, 'get');
200
+	}
201
+
202
+
203
+	/**
204
+	 * check if param exists
205
+	 *
206
+	 * @param       $key
207
+	 * @return bool
208
+	 */
209
+	public function requestParamIsSet($key)
210
+	{
211
+		return $this->requestParameterDrillDown($key);
212
+	}
213
+
214
+
215
+	/**
216
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
217
+	 * and return the value for the first match found
218
+	 * wildcards can be either of the following:
219
+	 *      ? to represent a single character of any type
220
+	 *      * to represent one or more characters of any type
221
+	 *
222
+	 * @param string     $pattern
223
+	 * @param null|mixed $default
224
+	 * @return mixed
225
+	 */
226
+	public function getMatch($pattern, $default = null)
227
+	{
228
+		return $this->requestParameterDrillDown($pattern, $default, 'match');
229
+	}
230
+
231
+
232
+	/**
233
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
234
+	 * wildcards can be either of the following:
235
+	 *      ? to represent a single character of any type
236
+	 *      * to represent one or more characters of any type
237
+	 * returns true if a match is found or false if not
238
+	 *
239
+	 * @param string $pattern
240
+	 * @return bool
241
+	 */
242
+	public function matches($pattern)
243
+	{
244
+		return $this->requestParameterDrillDown($pattern, null, 'match') !== null;
245
+	}
246
+
247
+
248
+	/**
249
+	 * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
250
+	 * @param string $pattern               A string including wildcards to be converted to a regex pattern
251
+	 *                                      and used to search through the current request's parameter keys
252
+	 * @param array  $request_params        The array of request parameters to search through
253
+	 * @param mixed  $default               [optional] The value to be returned if no match is found.
254
+	 *                                      Default is null
255
+	 * @param string $return                [optional] Controls what kind of value is returned.
256
+	 *                                      Options are:
257
+	 *                                      'bool' will return true or false if match is found or not
258
+	 *                                      'key' will return the first key found that matches the supplied pattern
259
+	 *                                      'value' will return the value for the first request parameter
260
+	 *                                      whose key matches the supplied pattern
261
+	 *                                      Default is 'value'
262
+	 * @return boolean|string
263
+	 */
264
+	private function match($pattern, array $request_params, $default = null, $return = 'value')
265
+	{
266
+		$return = in_array($return, array('bool', 'key', 'value'), true)
267
+			? $return
268
+			: 'is_set';
269
+		// replace wildcard chars with regex chars
270
+		$pattern = str_replace(
271
+			array("\*", "\?"),
272
+			array('.*', '.'),
273
+			preg_quote($pattern, '/')
274
+		);
275
+		foreach ($request_params as $key => $request_param) {
276
+			if (preg_match('/^' . $pattern . '$/is', $key)) {
277
+				// return value for request param
278
+				if ($return === 'value') {
279
+					return $request_params[ $key ];
280
+				}
281
+				// or actual key or true just to indicate it was found
282
+				return $return === 'key' ? $key : true;
283
+			}
284
+		}
285
+		// match not found so return default value or false
286
+		return $return === 'value' ? $default : false;
287
+	}
288
+
289
+
290
+	/**
291
+	 * the supplied key can be a simple string to represent a "top-level" request parameter
292
+	 * or represent a key for a request parameter that is nested deeper within the request parameter array,
293
+	 * by using square brackets to surround keys for deeper array elements.
294
+	 * For example :
295
+	 * if the supplied $key was: "first[second][third]"
296
+	 * then this will attempt to drill down into the request parameter array to find a value.
297
+	 * Given the following request parameters:
298
+	 *  array(
299
+	 *      'first' => array(
300
+	 *          'second' => array(
301
+	 *              'third' => 'has a value'
302
+	 *          )
303
+	 *      )
304
+	 *  )
305
+	 * would return true if default parameters were set
306
+	 *
307
+	 * @param string $callback
308
+	 * @param        $key
309
+	 * @param null   $default
310
+	 * @param array  $request_params
311
+	 * @return bool|mixed|null
312
+	 */
313
+	private function requestParameterDrillDown(
314
+		$key,
315
+		$default = null,
316
+		$callback = 'is_set',
317
+		array $request_params = array()
318
+	) {
319
+		$callback = in_array($callback, array('is_set', 'get', 'match'), true)
320
+			? $callback
321
+			: 'is_set';
322
+		$request_params = ! empty($request_params)
323
+			? $request_params
324
+			: $this->request;
325
+		// does incoming key represent an array like 'first[second][third]'  ?
326
+		if (strpos($key, '[') !== false) {
327
+			// turn it into an actual array
328
+			$key = str_replace(']', '', $key);
329
+			$keys = explode('[', $key);
330
+			$key = array_shift($keys);
331
+			if ($callback === 'match') {
332
+				$real_key = $this->match($key, $request_params, $default, 'key');
333
+				$key = $real_key ? $real_key : $key;
334
+			}
335
+			// check if top level key exists
336
+			if (isset($request_params[ $key ])) {
337
+				// build a new key to pass along like: 'second[third]'
338
+				// or just 'second' depending on depth of keys
339
+				$key_string = array_shift($keys);
340
+				if (! empty($keys)) {
341
+					$key_string .= '[' . implode('][', $keys) . ']';
342
+				}
343
+				return $this->requestParameterDrillDown(
344
+					$key_string,
345
+					$default,
346
+					$callback,
347
+					$request_params[ $key ]
348
+				);
349
+			}
350
+		}
351
+		if ($callback === 'is_set') {
352
+			return isset($request_params[ $key ]);
353
+		}
354
+		if ($callback === 'match') {
355
+			return $this->match($key, $request_params, $default);
356
+		}
357
+		return isset($request_params[ $key ])
358
+			? $request_params[ $key ]
359
+			: $default;
360
+	}
361
+
362
+
363
+	/**
364
+	 * remove param
365
+	 *
366
+	 * @param      $key
367
+	 * @param bool $unset_from_global_too
368
+	 */
369
+	public function unSetRequestParam($key, $unset_from_global_too = false)
370
+	{
371
+		// because unset may not actually remove var
372
+		$this->request[ $key ] = null;
373
+		unset($this->request[ $key ]);
374
+		if ($unset_from_global_too) {
375
+			unset($_REQUEST[ $key ]);
376
+		}
377
+	}
378
+
379
+
380
+	/**
381
+	 * remove params
382
+	 *
383
+	 * @param array $keys
384
+	 * @param bool  $unset_from_global_too
385
+	 */
386
+	public function unSetRequestParams(array $keys, $unset_from_global_too = false)
387
+	{
388
+		foreach ($keys as $key) {
389
+			$this->unSetRequestParam($key, $unset_from_global_too);
390
+		}
391
+	}
392
+
393
+
394
+	/**
395
+	 * @return string
396
+	 */
397
+	public function ipAddress()
398
+	{
399
+		return $this->ip_address;
400
+	}
401
+
402
+
403
+	/**
404
+	 * attempt to get IP address of current visitor from server
405
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
406
+	 *
407
+	 * @access public
408
+	 * @return string
409
+	 */
410
+	private function visitorIp()
411
+	{
412
+		$visitor_ip = '0.0.0.0';
413
+		$server_keys = array(
414
+			'HTTP_CLIENT_IP',
415
+			'HTTP_X_FORWARDED_FOR',
416
+			'HTTP_X_FORWARDED',
417
+			'HTTP_X_CLUSTER_CLIENT_IP',
418
+			'HTTP_FORWARDED_FOR',
419
+			'HTTP_FORWARDED',
420
+			'REMOTE_ADDR',
421
+		);
422
+		foreach ($server_keys as $key) {
423
+			if (isset($this->server[ $key ])) {
424
+				foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
425
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
426
+						$visitor_ip = $ip;
427
+					}
428
+				}
429
+			}
430
+		}
431
+		return $visitor_ip;
432
+	}
433
+
434
+
435
+	/**
436
+	 * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
437
+	 * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
438
+	 *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
439
+	 *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
440
+	 * @return string
441
+	 */
442
+	public function requestUri($relativeToWpRoot = false)
443
+	{
444
+		$request_uri = filter_input(
445
+			INPUT_SERVER,
446
+			'REQUEST_URI',
447
+			FILTER_SANITIZE_URL,
448
+			FILTER_NULL_ON_FAILURE
449
+		);
450
+		if (empty($request_uri)) {
451
+			// fallback sanitization if the above fails
452
+			$request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
453
+		}
454
+		if ($relativeToWpRoot) {
455
+			$home_path = untrailingslashit(
456
+				parse_url(
457
+					home_url(),
458
+					PHP_URL_PATH
459
+				)
460
+			);
461
+			$request_uri = str_replace(
462
+				$home_path,
463
+				'',
464
+				$request_uri
465
+			);
466
+		}
467
+		return $request_uri;
468
+	}
469
+
470
+	/**
471
+	 * @return string
472
+	 */
473
+	public function userAgent()
474
+	{
475
+		return $this->user_agent;
476
+	}
477
+
478
+
479
+	/**
480
+	 * @param string $user_agent
481
+	 */
482
+	public function setUserAgent($user_agent = '')
483
+	{
484
+		if ($user_agent === '' || ! is_string($user_agent)) {
485
+			$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
486
+		}
487
+		$this->user_agent = $user_agent;
488
+	}
489
+
490
+
491
+	/**
492
+	 * @return bool
493
+	 */
494
+	public function isBot()
495
+	{
496
+		return $this->is_bot;
497
+	}
498
+
499
+
500
+	/**
501
+	 * @param bool $is_bot
502
+	 */
503
+	public function setIsBot($is_bot)
504
+	{
505
+		$this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
506
+	}
507
+
508
+
509
+	/**
510
+	 * @return bool
511
+	 */
512
+	public function isActivation()
513
+	{
514
+		return $this->request_type->isActivation();
515
+	}
516
+
517
+
518
+	/**
519
+	 * @param $is_activation
520
+	 * @return bool
521
+	 */
522
+	public function setIsActivation($is_activation)
523
+	{
524
+		return $this->request_type->setIsActivation($is_activation);
525
+	}
526
+
527
+
528
+	/**
529
+	 * @return bool
530
+	 */
531
+	public function isAdmin()
532
+	{
533
+		return $this->request_type->isAdmin();
534
+	}
535
+
536
+
537
+	/**
538
+	 * @return bool
539
+	 */
540
+	public function isAdminAjax()
541
+	{
542
+		return $this->request_type->isAdminAjax();
543
+	}
544
+
545
+
546
+	/**
547
+	 * @return bool
548
+	 */
549
+	public function isAjax()
550
+	{
551
+		return $this->request_type->isAjax();
552
+	}
553
+
554
+
555
+	/**
556
+	 * @return bool
557
+	 */
558
+	public function isEeAjax()
559
+	{
560
+		return $this->request_type->isEeAjax();
561
+	}
562
+
563
+
564
+	/**
565
+	 * @return bool
566
+	 */
567
+	public function isOtherAjax()
568
+	{
569
+		return $this->request_type->isOtherAjax();
570
+	}
571
+
572
+
573
+	/**
574
+	 * @return bool
575
+	 */
576
+	public function isApi()
577
+	{
578
+		return $this->request_type->isApi();
579
+	}
580
+
581
+
582
+	/**
583
+	 * @return bool
584
+	 */
585
+	public function isCli()
586
+	{
587
+		return $this->request_type->isCli();
588
+	}
589
+
590
+
591
+	/**
592
+	 * @return bool
593
+	 */
594
+	public function isCron()
595
+	{
596
+		return $this->request_type->isCron();
597
+	}
598
+
599
+
600
+	/**
601
+	 * @return bool
602
+	 */
603
+	public function isFeed()
604
+	{
605
+		return $this->request_type->isFeed();
606
+	}
607
+
608
+
609
+	/**
610
+	 * @return bool
611
+	 */
612
+	public function isFrontend()
613
+	{
614
+		return $this->request_type->isFrontend();
615
+	}
616
+
617
+
618
+	/**
619
+	 * @return bool
620
+	 */
621
+	public function isFrontAjax()
622
+	{
623
+		return $this->request_type->isFrontAjax();
624
+	}
625
+
626
+
627
+	/**
628
+	 * @return bool
629
+	 */
630
+	public function isGQL()
631
+	{
632
+		return $this->request_type->isGQL();
633
+	}
634
+
635
+
636
+	/**
637
+	 * @return bool
638
+	 */
639
+	public function isIframe()
640
+	{
641
+		return $this->request_type->isIframe();
642
+	}
643
+
644
+
645
+
646
+	/**
647
+	 * @return bool
648
+	 */
649
+	public function isUnitTest()
650
+	{
651
+		return $this->request_type->isUnitTest();
652
+	}
653
+
654
+
655
+	/**
656
+	 * @return bool
657
+	 */
658
+	public function isWordPressApi()
659
+	{
660
+		return $this->request_type->isWordPressApi();
661
+	}
662
+
663
+
664
+
665
+	/**
666
+	 * @return bool
667
+	 */
668
+	public function isWordPressHeartbeat()
669
+	{
670
+		return $this->request_type->isWordPressHeartbeat();
671
+	}
672
+
673
+
674
+
675
+	/**
676
+	 * @return bool
677
+	 */
678
+	public function isWordPressScrape()
679
+	{
680
+		return $this->request_type->isWordPressScrape();
681
+	}
682
+
683
+
684
+	/**
685
+	 * @return string
686
+	 */
687
+	public function slug()
688
+	{
689
+		return $this->request_type->slug();
690
+	}
691 691
 }
Please login to merge, or discard this patch.
core/services/request/middleware/SetRequestTypeContextChecker.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -18,42 +18,42 @@
 block discarded – undo
18 18
 class SetRequestTypeContextChecker extends Middleware
19 19
 {
20 20
 
21
-    /**
22
-     * converts a Request to a Response
23
-     *
24
-     * @param RequestInterface  $request
25
-     * @param ResponseInterface $response
26
-     * @return ResponseInterface
27
-     * @throws InvalidArgumentException
28
-     */
29
-    public function handleRequest(RequestInterface $request, ResponseInterface $response)
30
-    {
31
-        $this->request  = $request;
32
-        $this->response = $response;
33
-        /** @var RequestTypeContextDetector $request_type_context_detector */
34
-        $request_type_context_detector = $this->loader->getShared(
35
-            'EventEspresso\core\domain\services\contexts\RequestTypeContextDetector',
36
-            array(
37
-                $this->request,
38
-                $this->loader->getShared(
39
-                    'EventEspresso\core\domain\services\contexts\RequestTypeContextFactory',
40
-                    array($this->loader)
41
-                ),
42
-                array(
43
-                    'DOING_AJAX' => defined('DOING_AJAX') && DOING_AJAX,
44
-                    'EE_TESTS_DIR' => defined('EE_TESTS_DIR'),
45
-                    'WP_CLI'     => defined('WP_CLI') && WP_CLI,
46
-                    'is_admin'   => is_admin(),
47
-                )
48
-            )
49
-        );
50
-        $request_type_context          = $request_type_context_detector->detectRequestTypeContext();
51
-        $request_type_context_checker  = $this->loader->getShared(
52
-            'EventEspresso\core\domain\services\contexts\RequestTypeContextChecker',
53
-            array($request_type_context)
54
-        );
55
-        $this->request->setRequestTypeContextChecker($request_type_context_checker);
56
-        $this->response = $this->processRequestStack($this->request, $this->response);
57
-        return $this->response;
58
-    }
21
+	/**
22
+	 * converts a Request to a Response
23
+	 *
24
+	 * @param RequestInterface  $request
25
+	 * @param ResponseInterface $response
26
+	 * @return ResponseInterface
27
+	 * @throws InvalidArgumentException
28
+	 */
29
+	public function handleRequest(RequestInterface $request, ResponseInterface $response)
30
+	{
31
+		$this->request  = $request;
32
+		$this->response = $response;
33
+		/** @var RequestTypeContextDetector $request_type_context_detector */
34
+		$request_type_context_detector = $this->loader->getShared(
35
+			'EventEspresso\core\domain\services\contexts\RequestTypeContextDetector',
36
+			array(
37
+				$this->request,
38
+				$this->loader->getShared(
39
+					'EventEspresso\core\domain\services\contexts\RequestTypeContextFactory',
40
+					array($this->loader)
41
+				),
42
+				array(
43
+					'DOING_AJAX' => defined('DOING_AJAX') && DOING_AJAX,
44
+					'EE_TESTS_DIR' => defined('EE_TESTS_DIR'),
45
+					'WP_CLI'     => defined('WP_CLI') && WP_CLI,
46
+					'is_admin'   => is_admin(),
47
+				)
48
+			)
49
+		);
50
+		$request_type_context          = $request_type_context_detector->detectRequestTypeContext();
51
+		$request_type_context_checker  = $this->loader->getShared(
52
+			'EventEspresso\core\domain\services\contexts\RequestTypeContextChecker',
53
+			array($request_type_context)
54
+		);
55
+		$this->request->setRequestTypeContextChecker($request_type_context_checker);
56
+		$this->response = $this->processRequestStack($this->request, $this->response);
57
+		return $this->response;
58
+	}
59 59
 }
Please login to merge, or discard this patch.