Completed
Branch fix/kses-12 (92838c)
by
unknown
09:57 queued 07:44
created
core/EE_Front_Controller.core.php 1 patch
Indentation   +509 added lines, -509 removed lines patch added patch discarded remove patch
@@ -18,513 +18,513 @@
 block discarded – undo
18 18
 final class EE_Front_Controller
19 19
 {
20 20
 
21
-    /**
22
-     * @var string
23
-     */
24
-    private $_template_path;
25
-
26
-    /**
27
-     * @var string
28
-     */
29
-    private $_template;
30
-
31
-    /**
32
-     * @type EE_Registry
33
-     */
34
-    protected $Registry;
35
-
36
-    /**
37
-     * @type EE_Request_Handler
38
-     */
39
-    protected $Request_Handler;
40
-
41
-    /**
42
-     * @type EE_Module_Request_Router
43
-     */
44
-    protected $Module_Request_Router;
45
-
46
-    /**
47
-     * @type CurrentPage
48
-     */
49
-    protected $current_page;
50
-
51
-
52
-    /**
53
-     *    class constructor
54
-     *    should fire after shortcode, module, addon, or other plugin's default priority init phases have run
55
-     *
56
-     * @access    public
57
-     * @param EE_Registry              $Registry
58
-     * @param CurrentPage              $EspressoPage
59
-     * @param EE_Module_Request_Router $Module_Request_Router
60
-     */
61
-    public function __construct(
62
-        EE_Registry $Registry,
63
-        CurrentPage $EspressoPage,
64
-        EE_Module_Request_Router $Module_Request_Router
65
-    ) {
66
-        $this->Registry              = $Registry;
67
-        $this->current_page          = $EspressoPage;
68
-        $this->Module_Request_Router = $Module_Request_Router;
69
-        // load other resources and begin to actually run shortcodes and modules
70
-        // analyse the incoming WP request
71
-        add_action('parse_request', array($this, 'get_request'), 1, 1);
72
-        // process request with module factory
73
-        add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1);
74
-        // before headers sent
75
-        add_action('wp', array($this, 'wp'), 5);
76
-        // primarily used to process any content shortcodes
77
-        add_action('template_redirect', array($this, 'templateRedirect'), 999);
78
-        // header
79
-        add_action('wp_head', array($this, 'header_meta_tag'), 5);
80
-        add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10);
81
-        add_filter('template_include', array($this, 'template_include'), 1);
82
-        // display errors
83
-        add_action('loop_start', array($this, 'display_errors'), 2);
84
-        // the content
85
-        // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 );
86
-        // exclude our private cpt comments
87
-        add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1);
88
-        // make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://)
89
-        add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1);
90
-        // action hook EE
91
-        do_action('AHEE__EE_Front_Controller__construct__done', $this);
92
-    }
93
-
94
-
95
-    /**
96
-     * @return EE_Request_Handler
97
-     * @deprecated 4.10.14.p
98
-     */
99
-    public function Request_Handler()
100
-    {
101
-        if (! $this->Request_Handler instanceof EE_Request_Handler) {
102
-            $this->Request_Handler = LoaderFactory::getLoader()->getShared('EE_Request_Handler');
103
-        }
104
-        return $this->Request_Handler;
105
-    }
106
-
107
-
108
-    /**
109
-     * @return EE_Module_Request_Router
110
-     */
111
-    public function Module_Request_Router()
112
-    {
113
-        return $this->Module_Request_Router;
114
-    }
115
-
116
-
117
-    /**
118
-     * @return LegacyShortcodesManager
119
-     * @deprecated 4.10.14.p
120
-     */
121
-    public function getLegacyShortcodesManager()
122
-    {
123
-        return EE_Config::getLegacyShortcodesManager();
124
-    }
125
-
126
-
127
-
128
-
129
-
130
-    /***********************************************        INIT ACTION HOOK         ***********************************************/
131
-    /**
132
-     * filter_wp_comments
133
-     * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment
134
-     * widgets/queries done on frontend
135
-     *
136
-     * @param  array $clauses array of comment clauses setup by WP_Comment_Query
137
-     * @return array array of comment clauses with modifications.
138
-     * @throws InvalidArgumentException
139
-     * @throws InvalidDataTypeException
140
-     * @throws InvalidInterfaceException
141
-     */
142
-    public function filter_wp_comments($clauses)
143
-    {
144
-        global $wpdb;
145
-        if (strpos($clauses['join'], $wpdb->posts) !== false) {
146
-            /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
147
-            $custom_post_types = LoaderFactory::getLoader()->getShared(
148
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
149
-            );
150
-            $cpts = $custom_post_types->getPrivateCustomPostTypes();
151
-            foreach ($cpts as $cpt => $details) {
152
-                $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt);
153
-            }
154
-        }
155
-        return $clauses;
156
-    }
157
-
158
-
159
-    /**
160
-     * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend
161
-     *
162
-     * @param  string $url incoming url
163
-     * @return string         final assembled url
164
-     */
165
-    public function maybe_force_admin_ajax_ssl($url)
166
-    {
167
-        if (is_ssl() && preg_match('/admin-ajax.php/', $url)) {
168
-            $url = str_replace('http://', 'https://', $url);
169
-        }
170
-        return $url;
171
-    }
172
-
173
-
174
-
175
-
176
-
177
-
178
-    /***********************************************        WP_LOADED ACTION HOOK         ***********************************************/
179
-
180
-
181
-    /**
182
-     *    wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their
183
-     *    default priority init phases have run
184
-     *
185
-     * @access    public
186
-     * @return    void
187
-     */
188
-    public function wp_loaded()
189
-    {
190
-    }
191
-
192
-
193
-
194
-
195
-
196
-    /***********************************************        PARSE_REQUEST HOOK         ***********************************************/
197
-    /**
198
-     *    _get_request
199
-     *
200
-     * @access public
201
-     * @param WP $WP
202
-     * @return void
203
-     */
204
-    public function get_request(WP $WP)
205
-    {
206
-        do_action('AHEE__EE_Front_Controller__get_request__start');
207
-        $this->current_page->parseQueryVars($WP);
208
-        do_action('AHEE__EE_Front_Controller__get_request__complete');
209
-        remove_action('parse_request', [$this, 'get_request'], 1);
210
-    }
211
-
212
-
213
-    /**
214
-     *    pre_get_posts - basically a module factory for instantiating modules and selecting the final view template
215
-     *
216
-     * @access    public
217
-     * @param WP_Query $WP_Query
218
-     * @return    void
219
-     * @throws EE_Error
220
-     * @throws ReflectionException
221
-     */
222
-    public function pre_get_posts($WP_Query)
223
-    {
224
-        // only load Module_Request_Router if this is the main query
225
-        if (
226
-            $this->Module_Request_Router instanceof EE_Module_Request_Router
227
-            && $WP_Query->is_main_query()
228
-        ) {
229
-            // cycle thru module routes
230
-            while ($route = $this->Module_Request_Router->get_route($WP_Query)) {
231
-                // determine module and method for route
232
-                $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]);
233
-                if ($module instanceof EED_Module) {
234
-                    // get registered view for route
235
-                    $this->_template_path = $this->Module_Request_Router->get_view($route);
236
-                    // grab module name
237
-                    $module_name = $module->module_name();
238
-                    // map the module to the module objects
239
-                    $this->Registry->modules->{$module_name} = $module;
240
-                }
241
-            }
242
-        }
243
-    }
244
-
245
-
246
-
247
-
248
-
249
-    /***********************************************        WP HOOK         ***********************************************/
250
-
251
-
252
-    /**
253
-     *    wp - basically last chance to do stuff before headers sent
254
-     *
255
-     * @access    public
256
-     * @return    void
257
-     */
258
-    public function wp()
259
-    {
260
-    }
261
-
262
-
263
-
264
-    /***********************     GET_HEADER && WP_HEAD HOOK     ***********************/
265
-
266
-
267
-    /**
268
-     * callback for the "template_redirect" hook point
269
-     * checks sidebars for EE widgets
270
-     * loads resources and assets accordingly
271
-     *
272
-     * @return void
273
-     */
274
-    public function templateRedirect()
275
-    {
276
-        global $wp_query;
277
-        if (empty($wp_query->posts)) {
278
-            return;
279
-        }
280
-        // if we already know this is an espresso page, then load assets
281
-        $load_assets = $this->current_page->isEspressoPage();
282
-        // if we are already loading assets then just move along, otherwise check for widgets
283
-        $load_assets = $load_assets || $this->espresso_widgets_in_active_sidebars();
284
-        if ($load_assets) {
285
-            add_action('wp_enqueue_scripts', array($this, 'enqueueStyle'), 10);
286
-            add_action('wp_print_footer_scripts', array($this, 'enqueueScripts'), 10);
287
-        }
288
-    }
289
-
290
-
291
-    /**
292
-     * builds list of active widgets then scans active sidebars looking for them
293
-     * returns true is an EE widget is found in an active sidebar
294
-     * Please Note: this does NOT mean that the sidebar or widget
295
-     * is actually in use in a given template, as that is unfortunately not known
296
-     * until a sidebar and it's widgets are actually loaded
297
-     *
298
-     * @return boolean
299
-     */
300
-    private function espresso_widgets_in_active_sidebars()
301
-    {
302
-        $espresso_widgets = array();
303
-        foreach ($this->Registry->widgets as $widget_class => $widget) {
304
-            $id_base = EspressoWidget::getIdBase($widget_class);
305
-            if (is_active_widget(false, false, $id_base)) {
306
-                $espresso_widgets[] = $id_base;
307
-            }
308
-        }
309
-        $all_sidebar_widgets = wp_get_sidebars_widgets();
310
-        foreach ($all_sidebar_widgets as $sidebar_widgets) {
311
-            if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) {
312
-                foreach ($sidebar_widgets as $sidebar_widget) {
313
-                    foreach ($espresso_widgets as $espresso_widget) {
314
-                        if (strpos($sidebar_widget, $espresso_widget) !== false) {
315
-                            return true;
316
-                        }
317
-                    }
318
-                }
319
-            }
320
-        }
321
-        return false;
322
-    }
323
-
324
-
325
-    /**
326
-     *    header_meta_tag
327
-     *
328
-     * @access    public
329
-     * @return    void
330
-     */
331
-    public function header_meta_tag()
332
-    {
333
-        print(
334
-        apply_filters(
335
-            'FHEE__EE_Front_Controller__header_meta_tag',
336
-            '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n"
337
-        )
338
-        );
339
-
340
-        // let's exclude all event type taxonomy term archive pages from search engine indexing
341
-        // @see https://events.codebasehq.com/projects/event-espresso/tickets/10249
342
-        // also exclude all critical pages from indexing
343
-        if (
344
-            (
345
-                is_tax('espresso_event_type')
346
-                && get_option('blog_public') !== '0'
347
-            )
348
-            || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array())
349
-        ) {
350
-            print(
351
-            apply_filters(
352
-                'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type',
353
-                '<meta name="robots" content="noindex,follow" />' . "\n"
354
-            )
355
-            );
356
-        }
357
-    }
358
-
359
-
360
-    /**
361
-     * wp_print_scripts
362
-     *
363
-     * @return void
364
-     * @throws EE_Error
365
-     */
366
-    public function wp_print_scripts()
367
-    {
368
-        global $post;
369
-        if (
370
-            isset($post->EE_Event)
371
-            && $post->EE_Event instanceof EE_Event
372
-            && get_post_type() === 'espresso_events'
373
-            && is_singular()
374
-        ) {
375
-            EEH_Schema::add_json_linked_data_for_event($post->EE_Event);
376
-        }
377
-    }
378
-
379
-
380
-    public function enqueueStyle()
381
-    {
382
-        wp_enqueue_style('espresso_default');
383
-        wp_enqueue_style('espresso_custom_css');
384
-    }
385
-
386
-
387
-
388
-    /***********************************************        WP_FOOTER         ***********************************************/
389
-
390
-
391
-    public function enqueueScripts()
392
-    {
393
-        wp_enqueue_script('espresso_core');
394
-    }
395
-
396
-
397
-    /**
398
-     * display_errors
399
-     *
400
-     * @access public
401
-     * @return void
402
-     * @throws DomainException
403
-     */
404
-    public function display_errors()
405
-    {
406
-        static $shown_already = false;
407
-        do_action('AHEE__EE_Front_Controller__display_errors__begin');
408
-        if (
409
-            ! $shown_already
410
-            && apply_filters('FHEE__EE_Front_Controller__display_errors', true)
411
-            && is_main_query()
412
-            && ! is_feed()
413
-            && in_the_loop()
414
-            && $this->current_page->isEspressoPage()
415
-        ) {
416
-            $shown_already = true;
417
-            if (did_action('wp_head')) {
418
-                echo $this->printNotices();
419
-            } else {
420
-                // block enabled themes run their query loop before headers are sent
421
-                // so we need to add our notices onto the beginning of the content
422
-                add_filter('the_content', [$this, 'prependNotices'], 1, 1);
423
-            }
424
-        }
425
-        do_action('AHEE__EE_Front_Controller__display_errors__end');
426
-    }
427
-
428
-
429
-    /**
430
-     * @param string $the_content
431
-     * @return string
432
-     * @since $VID:$
433
-     */
434
-    public function prependNotices($the_content)
435
-    {
436
-        $notices = $this->printNotices();
437
-        return $notices ? $notices . $the_content : $the_content;
438
-    }
439
-
440
-
441
-    /**
442
-     * @return false|string
443
-     * @since $VID:$
444
-     */
445
-    public function printNotices()
446
-    {
447
-        ob_start();
448
-        echo wp_kses(EE_Error::get_notices(), AllowedTags::getWithFormTags());
449
-        EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php');
450
-        return ob_get_clean();
451
-    }
452
-
453
-
454
-
455
-    /***********************************************        UTILITIES         ***********************************************/
456
-
457
-
458
-    /**
459
-     * @param string $template_include_path
460
-     * @return string
461
-     * @throws EE_Error
462
-     * @throws ReflectionException
463
-     */
464
-    public function template_include($template_include_path = null)
465
-    {
466
-        if ($this->current_page->isEspressoPage()) {
467
-            // despite all helpers having autoloaders set, we need to manually load the template loader
468
-            // because there are some side effects in that class for triggering template tag functions
469
-            $this->Registry->load_helper('EEH_Template');
470
-            $this->_template_path = ! empty($this->_template_path)
471
-                ? basename($this->_template_path)
472
-                : basename(
473
-                    $template_include_path
474
-                );
475
-            $template_path = EEH_Template::locate_template($this->_template_path, array(), false);
476
-            $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path;
477
-            $this->_template = basename($this->_template_path);
478
-            return $this->_template_path;
479
-        }
480
-        return $template_include_path;
481
-    }
482
-
483
-
484
-    /**
485
-     * @param bool $with_path
486
-     * @return    string
487
-     */
488
-    public function get_selected_template($with_path = false)
489
-    {
490
-        return $with_path ? $this->_template_path : $this->_template;
491
-    }
492
-
493
-
494
-    /**
495
-     * @param string $shortcode_class
496
-     * @param WP     $wp
497
-     * @throws ReflectionException
498
-     * @deprecated 4.9.26
499
-     */
500
-    public function initialize_shortcode($shortcode_class = '', WP $wp = null)
501
-    {
502
-        EE_Error::doing_it_wrong(
503
-            __METHOD__,
504
-            esc_html__(
505
-                'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.',
506
-                'event_espresso'
507
-            ),
508
-            '4.9.26'
509
-        );
510
-        $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp);
511
-    }
512
-
513
-
514
-    /**
515
-     * @return void
516
-     * @deprecated 4.9.57.p
517
-     */
518
-    public function loadPersistentAdminNoticeManager()
519
-    {
520
-    }
521
-
522
-
523
-    /**
524
-     * @return void
525
-     * @deprecated 4.9.64.p
526
-     */
527
-    public function employ_CPT_Strategy()
528
-    {
529
-    }
21
+	/**
22
+	 * @var string
23
+	 */
24
+	private $_template_path;
25
+
26
+	/**
27
+	 * @var string
28
+	 */
29
+	private $_template;
30
+
31
+	/**
32
+	 * @type EE_Registry
33
+	 */
34
+	protected $Registry;
35
+
36
+	/**
37
+	 * @type EE_Request_Handler
38
+	 */
39
+	protected $Request_Handler;
40
+
41
+	/**
42
+	 * @type EE_Module_Request_Router
43
+	 */
44
+	protected $Module_Request_Router;
45
+
46
+	/**
47
+	 * @type CurrentPage
48
+	 */
49
+	protected $current_page;
50
+
51
+
52
+	/**
53
+	 *    class constructor
54
+	 *    should fire after shortcode, module, addon, or other plugin's default priority init phases have run
55
+	 *
56
+	 * @access    public
57
+	 * @param EE_Registry              $Registry
58
+	 * @param CurrentPage              $EspressoPage
59
+	 * @param EE_Module_Request_Router $Module_Request_Router
60
+	 */
61
+	public function __construct(
62
+		EE_Registry $Registry,
63
+		CurrentPage $EspressoPage,
64
+		EE_Module_Request_Router $Module_Request_Router
65
+	) {
66
+		$this->Registry              = $Registry;
67
+		$this->current_page          = $EspressoPage;
68
+		$this->Module_Request_Router = $Module_Request_Router;
69
+		// load other resources and begin to actually run shortcodes and modules
70
+		// analyse the incoming WP request
71
+		add_action('parse_request', array($this, 'get_request'), 1, 1);
72
+		// process request with module factory
73
+		add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1);
74
+		// before headers sent
75
+		add_action('wp', array($this, 'wp'), 5);
76
+		// primarily used to process any content shortcodes
77
+		add_action('template_redirect', array($this, 'templateRedirect'), 999);
78
+		// header
79
+		add_action('wp_head', array($this, 'header_meta_tag'), 5);
80
+		add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10);
81
+		add_filter('template_include', array($this, 'template_include'), 1);
82
+		// display errors
83
+		add_action('loop_start', array($this, 'display_errors'), 2);
84
+		// the content
85
+		// add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 );
86
+		// exclude our private cpt comments
87
+		add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1);
88
+		// make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://)
89
+		add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1);
90
+		// action hook EE
91
+		do_action('AHEE__EE_Front_Controller__construct__done', $this);
92
+	}
93
+
94
+
95
+	/**
96
+	 * @return EE_Request_Handler
97
+	 * @deprecated 4.10.14.p
98
+	 */
99
+	public function Request_Handler()
100
+	{
101
+		if (! $this->Request_Handler instanceof EE_Request_Handler) {
102
+			$this->Request_Handler = LoaderFactory::getLoader()->getShared('EE_Request_Handler');
103
+		}
104
+		return $this->Request_Handler;
105
+	}
106
+
107
+
108
+	/**
109
+	 * @return EE_Module_Request_Router
110
+	 */
111
+	public function Module_Request_Router()
112
+	{
113
+		return $this->Module_Request_Router;
114
+	}
115
+
116
+
117
+	/**
118
+	 * @return LegacyShortcodesManager
119
+	 * @deprecated 4.10.14.p
120
+	 */
121
+	public function getLegacyShortcodesManager()
122
+	{
123
+		return EE_Config::getLegacyShortcodesManager();
124
+	}
125
+
126
+
127
+
128
+
129
+
130
+	/***********************************************        INIT ACTION HOOK         ***********************************************/
131
+	/**
132
+	 * filter_wp_comments
133
+	 * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment
134
+	 * widgets/queries done on frontend
135
+	 *
136
+	 * @param  array $clauses array of comment clauses setup by WP_Comment_Query
137
+	 * @return array array of comment clauses with modifications.
138
+	 * @throws InvalidArgumentException
139
+	 * @throws InvalidDataTypeException
140
+	 * @throws InvalidInterfaceException
141
+	 */
142
+	public function filter_wp_comments($clauses)
143
+	{
144
+		global $wpdb;
145
+		if (strpos($clauses['join'], $wpdb->posts) !== false) {
146
+			/** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */
147
+			$custom_post_types = LoaderFactory::getLoader()->getShared(
148
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
149
+			);
150
+			$cpts = $custom_post_types->getPrivateCustomPostTypes();
151
+			foreach ($cpts as $cpt => $details) {
152
+				$clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt);
153
+			}
154
+		}
155
+		return $clauses;
156
+	}
157
+
158
+
159
+	/**
160
+	 * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend
161
+	 *
162
+	 * @param  string $url incoming url
163
+	 * @return string         final assembled url
164
+	 */
165
+	public function maybe_force_admin_ajax_ssl($url)
166
+	{
167
+		if (is_ssl() && preg_match('/admin-ajax.php/', $url)) {
168
+			$url = str_replace('http://', 'https://', $url);
169
+		}
170
+		return $url;
171
+	}
172
+
173
+
174
+
175
+
176
+
177
+
178
+	/***********************************************        WP_LOADED ACTION HOOK         ***********************************************/
179
+
180
+
181
+	/**
182
+	 *    wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their
183
+	 *    default priority init phases have run
184
+	 *
185
+	 * @access    public
186
+	 * @return    void
187
+	 */
188
+	public function wp_loaded()
189
+	{
190
+	}
191
+
192
+
193
+
194
+
195
+
196
+	/***********************************************        PARSE_REQUEST HOOK         ***********************************************/
197
+	/**
198
+	 *    _get_request
199
+	 *
200
+	 * @access public
201
+	 * @param WP $WP
202
+	 * @return void
203
+	 */
204
+	public function get_request(WP $WP)
205
+	{
206
+		do_action('AHEE__EE_Front_Controller__get_request__start');
207
+		$this->current_page->parseQueryVars($WP);
208
+		do_action('AHEE__EE_Front_Controller__get_request__complete');
209
+		remove_action('parse_request', [$this, 'get_request'], 1);
210
+	}
211
+
212
+
213
+	/**
214
+	 *    pre_get_posts - basically a module factory for instantiating modules and selecting the final view template
215
+	 *
216
+	 * @access    public
217
+	 * @param WP_Query $WP_Query
218
+	 * @return    void
219
+	 * @throws EE_Error
220
+	 * @throws ReflectionException
221
+	 */
222
+	public function pre_get_posts($WP_Query)
223
+	{
224
+		// only load Module_Request_Router if this is the main query
225
+		if (
226
+			$this->Module_Request_Router instanceof EE_Module_Request_Router
227
+			&& $WP_Query->is_main_query()
228
+		) {
229
+			// cycle thru module routes
230
+			while ($route = $this->Module_Request_Router->get_route($WP_Query)) {
231
+				// determine module and method for route
232
+				$module = $this->Module_Request_Router->resolve_route($route[0], $route[1]);
233
+				if ($module instanceof EED_Module) {
234
+					// get registered view for route
235
+					$this->_template_path = $this->Module_Request_Router->get_view($route);
236
+					// grab module name
237
+					$module_name = $module->module_name();
238
+					// map the module to the module objects
239
+					$this->Registry->modules->{$module_name} = $module;
240
+				}
241
+			}
242
+		}
243
+	}
244
+
245
+
246
+
247
+
248
+
249
+	/***********************************************        WP HOOK         ***********************************************/
250
+
251
+
252
+	/**
253
+	 *    wp - basically last chance to do stuff before headers sent
254
+	 *
255
+	 * @access    public
256
+	 * @return    void
257
+	 */
258
+	public function wp()
259
+	{
260
+	}
261
+
262
+
263
+
264
+	/***********************     GET_HEADER && WP_HEAD HOOK     ***********************/
265
+
266
+
267
+	/**
268
+	 * callback for the "template_redirect" hook point
269
+	 * checks sidebars for EE widgets
270
+	 * loads resources and assets accordingly
271
+	 *
272
+	 * @return void
273
+	 */
274
+	public function templateRedirect()
275
+	{
276
+		global $wp_query;
277
+		if (empty($wp_query->posts)) {
278
+			return;
279
+		}
280
+		// if we already know this is an espresso page, then load assets
281
+		$load_assets = $this->current_page->isEspressoPage();
282
+		// if we are already loading assets then just move along, otherwise check for widgets
283
+		$load_assets = $load_assets || $this->espresso_widgets_in_active_sidebars();
284
+		if ($load_assets) {
285
+			add_action('wp_enqueue_scripts', array($this, 'enqueueStyle'), 10);
286
+			add_action('wp_print_footer_scripts', array($this, 'enqueueScripts'), 10);
287
+		}
288
+	}
289
+
290
+
291
+	/**
292
+	 * builds list of active widgets then scans active sidebars looking for them
293
+	 * returns true is an EE widget is found in an active sidebar
294
+	 * Please Note: this does NOT mean that the sidebar or widget
295
+	 * is actually in use in a given template, as that is unfortunately not known
296
+	 * until a sidebar and it's widgets are actually loaded
297
+	 *
298
+	 * @return boolean
299
+	 */
300
+	private function espresso_widgets_in_active_sidebars()
301
+	{
302
+		$espresso_widgets = array();
303
+		foreach ($this->Registry->widgets as $widget_class => $widget) {
304
+			$id_base = EspressoWidget::getIdBase($widget_class);
305
+			if (is_active_widget(false, false, $id_base)) {
306
+				$espresso_widgets[] = $id_base;
307
+			}
308
+		}
309
+		$all_sidebar_widgets = wp_get_sidebars_widgets();
310
+		foreach ($all_sidebar_widgets as $sidebar_widgets) {
311
+			if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) {
312
+				foreach ($sidebar_widgets as $sidebar_widget) {
313
+					foreach ($espresso_widgets as $espresso_widget) {
314
+						if (strpos($sidebar_widget, $espresso_widget) !== false) {
315
+							return true;
316
+						}
317
+					}
318
+				}
319
+			}
320
+		}
321
+		return false;
322
+	}
323
+
324
+
325
+	/**
326
+	 *    header_meta_tag
327
+	 *
328
+	 * @access    public
329
+	 * @return    void
330
+	 */
331
+	public function header_meta_tag()
332
+	{
333
+		print(
334
+		apply_filters(
335
+			'FHEE__EE_Front_Controller__header_meta_tag',
336
+			'<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n"
337
+		)
338
+		);
339
+
340
+		// let's exclude all event type taxonomy term archive pages from search engine indexing
341
+		// @see https://events.codebasehq.com/projects/event-espresso/tickets/10249
342
+		// also exclude all critical pages from indexing
343
+		if (
344
+			(
345
+				is_tax('espresso_event_type')
346
+				&& get_option('blog_public') !== '0'
347
+			)
348
+			|| is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array())
349
+		) {
350
+			print(
351
+			apply_filters(
352
+				'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type',
353
+				'<meta name="robots" content="noindex,follow" />' . "\n"
354
+			)
355
+			);
356
+		}
357
+	}
358
+
359
+
360
+	/**
361
+	 * wp_print_scripts
362
+	 *
363
+	 * @return void
364
+	 * @throws EE_Error
365
+	 */
366
+	public function wp_print_scripts()
367
+	{
368
+		global $post;
369
+		if (
370
+			isset($post->EE_Event)
371
+			&& $post->EE_Event instanceof EE_Event
372
+			&& get_post_type() === 'espresso_events'
373
+			&& is_singular()
374
+		) {
375
+			EEH_Schema::add_json_linked_data_for_event($post->EE_Event);
376
+		}
377
+	}
378
+
379
+
380
+	public function enqueueStyle()
381
+	{
382
+		wp_enqueue_style('espresso_default');
383
+		wp_enqueue_style('espresso_custom_css');
384
+	}
385
+
386
+
387
+
388
+	/***********************************************        WP_FOOTER         ***********************************************/
389
+
390
+
391
+	public function enqueueScripts()
392
+	{
393
+		wp_enqueue_script('espresso_core');
394
+	}
395
+
396
+
397
+	/**
398
+	 * display_errors
399
+	 *
400
+	 * @access public
401
+	 * @return void
402
+	 * @throws DomainException
403
+	 */
404
+	public function display_errors()
405
+	{
406
+		static $shown_already = false;
407
+		do_action('AHEE__EE_Front_Controller__display_errors__begin');
408
+		if (
409
+			! $shown_already
410
+			&& apply_filters('FHEE__EE_Front_Controller__display_errors', true)
411
+			&& is_main_query()
412
+			&& ! is_feed()
413
+			&& in_the_loop()
414
+			&& $this->current_page->isEspressoPage()
415
+		) {
416
+			$shown_already = true;
417
+			if (did_action('wp_head')) {
418
+				echo $this->printNotices();
419
+			} else {
420
+				// block enabled themes run their query loop before headers are sent
421
+				// so we need to add our notices onto the beginning of the content
422
+				add_filter('the_content', [$this, 'prependNotices'], 1, 1);
423
+			}
424
+		}
425
+		do_action('AHEE__EE_Front_Controller__display_errors__end');
426
+	}
427
+
428
+
429
+	/**
430
+	 * @param string $the_content
431
+	 * @return string
432
+	 * @since $VID:$
433
+	 */
434
+	public function prependNotices($the_content)
435
+	{
436
+		$notices = $this->printNotices();
437
+		return $notices ? $notices . $the_content : $the_content;
438
+	}
439
+
440
+
441
+	/**
442
+	 * @return false|string
443
+	 * @since $VID:$
444
+	 */
445
+	public function printNotices()
446
+	{
447
+		ob_start();
448
+		echo wp_kses(EE_Error::get_notices(), AllowedTags::getWithFormTags());
449
+		EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php');
450
+		return ob_get_clean();
451
+	}
452
+
453
+
454
+
455
+	/***********************************************        UTILITIES         ***********************************************/
456
+
457
+
458
+	/**
459
+	 * @param string $template_include_path
460
+	 * @return string
461
+	 * @throws EE_Error
462
+	 * @throws ReflectionException
463
+	 */
464
+	public function template_include($template_include_path = null)
465
+	{
466
+		if ($this->current_page->isEspressoPage()) {
467
+			// despite all helpers having autoloaders set, we need to manually load the template loader
468
+			// because there are some side effects in that class for triggering template tag functions
469
+			$this->Registry->load_helper('EEH_Template');
470
+			$this->_template_path = ! empty($this->_template_path)
471
+				? basename($this->_template_path)
472
+				: basename(
473
+					$template_include_path
474
+				);
475
+			$template_path = EEH_Template::locate_template($this->_template_path, array(), false);
476
+			$this->_template_path = ! empty($template_path) ? $template_path : $template_include_path;
477
+			$this->_template = basename($this->_template_path);
478
+			return $this->_template_path;
479
+		}
480
+		return $template_include_path;
481
+	}
482
+
483
+
484
+	/**
485
+	 * @param bool $with_path
486
+	 * @return    string
487
+	 */
488
+	public function get_selected_template($with_path = false)
489
+	{
490
+		return $with_path ? $this->_template_path : $this->_template;
491
+	}
492
+
493
+
494
+	/**
495
+	 * @param string $shortcode_class
496
+	 * @param WP     $wp
497
+	 * @throws ReflectionException
498
+	 * @deprecated 4.9.26
499
+	 */
500
+	public function initialize_shortcode($shortcode_class = '', WP $wp = null)
501
+	{
502
+		EE_Error::doing_it_wrong(
503
+			__METHOD__,
504
+			esc_html__(
505
+				'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.',
506
+				'event_espresso'
507
+			),
508
+			'4.9.26'
509
+		);
510
+		$this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp);
511
+	}
512
+
513
+
514
+	/**
515
+	 * @return void
516
+	 * @deprecated 4.9.57.p
517
+	 */
518
+	public function loadPersistentAdminNoticeManager()
519
+	{
520
+	}
521
+
522
+
523
+	/**
524
+	 * @return void
525
+	 * @deprecated 4.9.64.p
526
+	 */
527
+	public function employ_CPT_Strategy()
528
+	{
529
+	}
530 530
 }
Please login to merge, or discard this patch.