Completed
Branch BUG/work-with-wp-41305 (a37570)
by
unknown
36:08 queued 26:52
created
core/CPTs/EE_CPT_Strategy.core.php 2 patches
Indentation   +443 added lines, -443 removed lines patch added patch discarded remove patch
@@ -16,447 +16,447 @@
 block discarded – undo
16 16
 class EE_CPT_Strategy extends EE_Base
17 17
 {
18 18
 
19
-    /**
20
-     * @var EE_CPT_Strategy $_instance
21
-     */
22
-    private static $_instance;
23
-
24
-    /**
25
-     * the current page, if it utilizes CPTs
26
-     *
27
-     * @var array $CPT
28
-     */
29
-    protected $CPT;
30
-
31
-    /**
32
-     * return value from CustomPostTypeDefinitions::getDefinitions()
33
-     *
34
-     * @var array $_CPTs
35
-     */
36
-    protected $_CPTs = array();
37
-
38
-    /**
39
-     * @var array $_CPT_taxonomies
40
-     */
41
-    protected $_CPT_taxonomies = array();
42
-
43
-    /**
44
-     * @var array $_CPT_terms
45
-     */
46
-    protected $_CPT_terms = array();
47
-
48
-    /**
49
-     * @var array $_CPT_endpoints
50
-     */
51
-    protected $_CPT_endpoints = array();
52
-
53
-    /**
54
-     * @var EEM_Base $CPT_model
55
-     */
56
-    protected $CPT_model;
57
-
58
-    /**
59
-     * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier
60
-     */
61
-    protected $query_modifier;
62
-
63
-
64
-    /**
65
-     * @singleton method used to instantiate class object
66
-     * @param CustomPostTypeDefinitions|null $custom_post_types
67
-     * @param CustomTaxonomyDefinitions|null $taxonomies
68
-     * @return EE_CPT_Strategy
69
-     */
70
-    public static function instance(
71
-        CustomPostTypeDefinitions $custom_post_types = null,
72
-        CustomTaxonomyDefinitions $taxonomies = null
73
-    ) {
74
-        // check if class object is instantiated
75
-        if (! self::$_instance instanceof EE_CPT_Strategy
76
-            && $custom_post_types instanceof CustomPostTypeDefinitions
77
-            && $taxonomies instanceof CustomTaxonomyDefinitions
78
-        ) {
79
-            self::$_instance = new self($custom_post_types, $taxonomies);
80
-        }
81
-        return self::$_instance;
82
-    }
83
-
84
-
85
-    /**
86
-     * @param CustomPostTypeDefinitions $custom_post_types
87
-     * @param CustomTaxonomyDefinitions $taxonomies
88
-     */
89
-    protected function __construct(
90
-        CustomPostTypeDefinitions $custom_post_types,
91
-        CustomTaxonomyDefinitions $taxonomies
92
-    ) {
93
-        // get CPT data
94
-        $this->_CPTs = $custom_post_types->getDefinitions();
95
-        $this->_CPT_endpoints = $this->_set_CPT_endpoints();
96
-        $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions();
97
-        add_action('pre_get_posts', array($this, 'pre_get_posts'), 5);
98
-    }
99
-
100
-
101
-    /**
102
-     * @return array
103
-     */
104
-    public function get_CPT_endpoints()
105
-    {
106
-        return $this->_CPT_endpoints;
107
-    }
108
-
109
-
110
-    /**
111
-     * @return array
112
-     */
113
-    public function get_CPT_taxonomies()
114
-    {
115
-        return $this->_CPT_taxonomies;
116
-    }
117
-
118
-
119
-    /**
120
-     * add CPT "slugs" to array of default espresso "pages"
121
-     *
122
-     * @return array
123
-     */
124
-    private function _set_CPT_endpoints()
125
-    {
126
-        $_CPT_endpoints = array();
127
-        if (is_array($this->_CPTs)) {
128
-            foreach ($this->_CPTs as $CPT_type => $CPT) {
129
-                if (isset($CPT['plural_slug'])) {
130
-                    $_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type;
131
-                }
132
-            }
133
-        }
134
-        return $_CPT_endpoints;
135
-    }
136
-
137
-
138
-    /**
139
-     * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to
140
-     * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and
141
-     * adding EE objects to the post to facilitate further querying of related data etc)
142
-     *
143
-     * @param WP_Query $WP_Query
144
-     * @return void
145
-     * @throws \EE_Error
146
-     * @throws \InvalidArgumentException
147
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
148
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
149
-     */
150
-    public function pre_get_posts($WP_Query)
151
-    {
152
-        // check that post-type is set
153
-        if (! $WP_Query instanceof WP_Query) {
154
-            return;
155
-        }
156
-        // add our conditionals
157
-        $this->_set_EE_tags_on_WP_Query($WP_Query);
158
-        // check for terms
159
-        $this->_set_post_type_for_terms($WP_Query);
160
-        // make sure paging is always set
161
-        $this->_set_paging($WP_Query);
162
-        // is a taxonomy set ?
163
-        $this->_set_CPT_taxonomies_on_WP_Query($WP_Query);
164
-        // loop thru post_types if set
165
-        $this->_process_WP_Query_post_types($WP_Query);
166
-    }
167
-
168
-
169
-    /**
170
-     * @param WP_Query $WP_Query
171
-     * @return void
172
-     */
173
-    private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query)
174
-    {
175
-        $WP_Query->is_espresso_event_single = false;
176
-        $WP_Query->is_espresso_event_archive = false;
177
-        $WP_Query->is_espresso_event_taxonomy = false;
178
-        $WP_Query->is_espresso_venue_single = false;
179
-        $WP_Query->is_espresso_venue_archive = false;
180
-        $WP_Query->is_espresso_venue_taxonomy = false;
181
-    }
182
-
183
-
184
-    /**
185
-     * @return void
186
-     * @throws EE_Error
187
-     * @throws InvalidArgumentException
188
-     * @throws InvalidDataTypeException
189
-     * @throws InvalidInterfaceException
190
-     */
191
-    private function _set_CPT_terms()
192
-    {
193
-        if (empty($this->_CPT_terms)) {
194
-            $terms = EEM_Term::instance()->get_all_CPT_post_tags();
195
-            foreach ($terms as $term) {
196
-                if ($term instanceof EE_Term) {
197
-                    $this->_CPT_terms[ $term->slug() ] = $term;
198
-                }
199
-            }
200
-        }
201
-    }
202
-
203
-
204
-    /**
205
-     * @param WP_Query $WP_Query
206
-     * @return void
207
-     * @throws EE_Error
208
-     * @throws InvalidArgumentException
209
-     * @throws InvalidDataTypeException
210
-     * @throws InvalidInterfaceException
211
-     */
212
-    private function _set_post_type_for_terms(WP_Query $WP_Query)
213
-    {
214
-        // is a tag set ?
215
-        if (isset($WP_Query->query['tag'])) {
216
-            // get term for tag
217
-            $term = EEM_Term::instance()->get_post_tag_for_event_or_venue($WP_Query->query['tag']);
218
-            // verify the term
219
-            if ($term instanceof EE_Term) {
220
-                $term->post_type = array_merge(array('post', 'page'), (array) $term->post_type);
221
-                $term->post_type = apply_filters(
222
-                    'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type',
223
-                    $term->post_type,
224
-                    $term
225
-                );
226
-                // if a post type is already set
227
-                if (isset($WP_Query->query_vars['post_type'])) {
228
-                    // add to existing array
229
-                    $term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type);
230
-                }
231
-                // just set post_type to our CPT
232
-                $WP_Query->set('post_type', array_unique($term->post_type));
233
-            }
234
-        }
235
-    }
236
-
237
-
238
-    /**
239
-     * @param WP_Query $WP_Query
240
-     * @return void
241
-     */
242
-    public function _set_paging($WP_Query)
243
-    {
244
-        if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) {
245
-            $page = get_query_var('page') ? get_query_var('page') : null;
246
-            $paged = get_query_var('paged') ? get_query_var('paged') : $page;
247
-            $WP_Query->set('paged', $paged);
248
-        }
249
-    }
250
-
251
-
252
-    /**
253
-     * @param \WP_Query $WP_Query
254
-     */
255
-    protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query)
256
-    {
257
-        // is a taxonomy set ?
258
-        if ($WP_Query->is_tax) {
259
-            // loop thru our taxonomies
260
-            foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) {
261
-                // check if one of our taxonomies is set as a query var
262
-                if (isset($WP_Query->query[ $CPT_taxonomy ])) {
263
-                    // but which CPT does that correspond to??? hmmm... guess we gotta go looping
264
-                    foreach ($this->_CPTs as $post_type => $CPT) {
265
-                        // verify our CPT has args, is public and has taxonomies set
266
-                        if (isset($CPT['args']['public'])
267
-                            && $CPT['args']['public']
268
-                            && ! empty($CPT['args']['taxonomies'])
269
-                            && in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true)
270
-                        ) {
271
-                            // if so, then add this CPT post_type to the current query's array of post_types'
272
-                            $WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type'])
273
-                                ? (array) $WP_Query->query_vars['post_type']
274
-                                : array();
275
-                            $WP_Query->query_vars['post_type'][] = $post_type;
276
-                            switch ($post_type) {
277
-                                case 'espresso_events':
278
-                                    $WP_Query->is_espresso_event_taxonomy = true;
279
-                                    break;
280
-                                case 'espresso_venues':
281
-                                    $WP_Query->is_espresso_venue_taxonomy = true;
282
-                                    break;
283
-                                default:
284
-                                    do_action(
285
-                                        'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type',
286
-                                        $WP_Query,
287
-                                        $this
288
-                                    );
289
-                            }
290
-                        }
291
-                    }
292
-                }
293
-            }
294
-        }
295
-    }
296
-
297
-
298
-    /**
299
-     * @param \WP_Query $WP_Query
300
-     * @throws InvalidArgumentException
301
-     * @throws InvalidDataTypeException
302
-     * @throws InvalidInterfaceException
303
-     */
304
-    protected function _process_WP_Query_post_types(WP_Query $WP_Query)
305
-    {
306
-        if (isset($WP_Query->query_vars['post_type'])) {
307
-            // loop thru post_types as array
308
-            foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) {
309
-                // is current query for an EE CPT ?
310
-                if (isset($this->_CPTs[ $post_type ])) {
311
-                    // is EE on or off ?
312
-                    if (EE_Maintenance_Mode::instance()->level()) {
313
-                        // reroute CPT template view to maintenance_mode.template.php
314
-                        if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) {
315
-                            add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999);
316
-                        }
317
-                        if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) {
318
-                            add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1);
319
-                        }
320
-                        return;
321
-                    }
322
-                    $this->_generate_CptQueryModifier($WP_Query, $post_type);
323
-                }
324
-            }
325
-        }
326
-    }
327
-
328
-
329
-    /**
330
-     * @param \WP_Query $WP_Query
331
-     * @param string    $post_type
332
-     * @throws InvalidArgumentException
333
-     * @throws InvalidDataTypeException
334
-     * @throws InvalidInterfaceException
335
-     */
336
-    protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type)
337
-    {
338
-        $this->query_modifier = LoaderFactory::getLoader()->getShared(
339
-            'EventEspresso\core\CPTs\CptQueryModifier',
340
-            array(
341
-                $post_type,
342
-                $this->_CPTs[ $post_type ],
343
-                $WP_Query,
344
-            )
345
-        );
346
-        $this->_CPT_taxonomies = $this->query_modifier->taxonomies();
347
-    }
348
-
349
-
350
-    /**
351
-     * inject_EE_shortcode_placeholder
352
-     * in order to display the M-Mode notice on our CPT routes,
353
-     * we need to first inject what looks like one of our shortcodes,
354
-     * so that it can be replaced with the actual M-Mode notice
355
-     *
356
-     * @return string
357
-     */
358
-    public function inject_EE_shortcode_placeholder()
359
-    {
360
-        return '[ESPRESSO_';
361
-    }
362
-
363
-
364
-    /**
365
-     * @deprecated
366
-     * @since  4.8.41
367
-     * @return void
368
-     */
369
-    public function _possibly_set_ee_request_var()
370
-    {
371
-        $this->query_modifier->setRequestVarsIfCpt();
372
-    }
373
-
374
-
375
-    /**
376
-     * @deprecated
377
-     * @since  4.8.41
378
-     * @param  $SQL
379
-     * @return string
380
-     */
381
-    public function posts_fields($SQL)
382
-    {
383
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
384
-            return $this->query_modifier->postsFields($SQL);
385
-        }
386
-        return $SQL;
387
-    }
388
-
389
-
390
-    /**
391
-     * @deprecated
392
-     * @since  4.8.41
393
-     * @param  $SQL
394
-     * @return string
395
-     */
396
-    public function posts_join($SQL)
397
-    {
398
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
399
-            return $this->query_modifier->postsJoin($SQL);
400
-        }
401
-        return $SQL;
402
-    }
403
-
404
-
405
-    /**
406
-     * @deprecated
407
-     * @since  4.8.41
408
-     * @param  \WP_Post[] $posts
409
-     * @return \WP_Post[]
410
-     */
411
-    public function the_posts($posts)
412
-    {
413
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
414
-            $this->query_modifier->thePosts($posts);
415
-        }
416
-        return $posts;
417
-    }
418
-
419
-
420
-    /**
421
-     * @deprecated
422
-     * @since  4.8.41
423
-     * @param $url
424
-     * @param $ID
425
-     * @return string
426
-     */
427
-    public function get_edit_post_link($url, $ID)
428
-    {
429
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
430
-            return $this->query_modifier->getEditPostLink($url, $ID);
431
-        }
432
-        return '';
433
-    }
434
-
435
-
436
-    /**
437
-     * @deprecated
438
-     * @since  4.8.41
439
-     * @param null $WP_Query
440
-     */
441
-    protected function _do_template_filters($WP_Query = null)
442
-    {
443
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
444
-            $this->query_modifier->addTemplateFilters();
445
-        }
446
-    }
447
-
448
-
449
-    /**
450
-     * @deprecated
451
-     * @since  4.8.41
452
-     * @param string $current_template Existing default template path derived for this page call.
453
-     * @return string the path to the full template file.
454
-     */
455
-    public function single_cpt_template($current_template)
456
-    {
457
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
458
-            return $this->query_modifier->singleCptTemplate($current_template);
459
-        }
460
-        return $current_template;
461
-    }
19
+	/**
20
+	 * @var EE_CPT_Strategy $_instance
21
+	 */
22
+	private static $_instance;
23
+
24
+	/**
25
+	 * the current page, if it utilizes CPTs
26
+	 *
27
+	 * @var array $CPT
28
+	 */
29
+	protected $CPT;
30
+
31
+	/**
32
+	 * return value from CustomPostTypeDefinitions::getDefinitions()
33
+	 *
34
+	 * @var array $_CPTs
35
+	 */
36
+	protected $_CPTs = array();
37
+
38
+	/**
39
+	 * @var array $_CPT_taxonomies
40
+	 */
41
+	protected $_CPT_taxonomies = array();
42
+
43
+	/**
44
+	 * @var array $_CPT_terms
45
+	 */
46
+	protected $_CPT_terms = array();
47
+
48
+	/**
49
+	 * @var array $_CPT_endpoints
50
+	 */
51
+	protected $_CPT_endpoints = array();
52
+
53
+	/**
54
+	 * @var EEM_Base $CPT_model
55
+	 */
56
+	protected $CPT_model;
57
+
58
+	/**
59
+	 * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier
60
+	 */
61
+	protected $query_modifier;
62
+
63
+
64
+	/**
65
+	 * @singleton method used to instantiate class object
66
+	 * @param CustomPostTypeDefinitions|null $custom_post_types
67
+	 * @param CustomTaxonomyDefinitions|null $taxonomies
68
+	 * @return EE_CPT_Strategy
69
+	 */
70
+	public static function instance(
71
+		CustomPostTypeDefinitions $custom_post_types = null,
72
+		CustomTaxonomyDefinitions $taxonomies = null
73
+	) {
74
+		// check if class object is instantiated
75
+		if (! self::$_instance instanceof EE_CPT_Strategy
76
+			&& $custom_post_types instanceof CustomPostTypeDefinitions
77
+			&& $taxonomies instanceof CustomTaxonomyDefinitions
78
+		) {
79
+			self::$_instance = new self($custom_post_types, $taxonomies);
80
+		}
81
+		return self::$_instance;
82
+	}
83
+
84
+
85
+	/**
86
+	 * @param CustomPostTypeDefinitions $custom_post_types
87
+	 * @param CustomTaxonomyDefinitions $taxonomies
88
+	 */
89
+	protected function __construct(
90
+		CustomPostTypeDefinitions $custom_post_types,
91
+		CustomTaxonomyDefinitions $taxonomies
92
+	) {
93
+		// get CPT data
94
+		$this->_CPTs = $custom_post_types->getDefinitions();
95
+		$this->_CPT_endpoints = $this->_set_CPT_endpoints();
96
+		$this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions();
97
+		add_action('pre_get_posts', array($this, 'pre_get_posts'), 5);
98
+	}
99
+
100
+
101
+	/**
102
+	 * @return array
103
+	 */
104
+	public function get_CPT_endpoints()
105
+	{
106
+		return $this->_CPT_endpoints;
107
+	}
108
+
109
+
110
+	/**
111
+	 * @return array
112
+	 */
113
+	public function get_CPT_taxonomies()
114
+	{
115
+		return $this->_CPT_taxonomies;
116
+	}
117
+
118
+
119
+	/**
120
+	 * add CPT "slugs" to array of default espresso "pages"
121
+	 *
122
+	 * @return array
123
+	 */
124
+	private function _set_CPT_endpoints()
125
+	{
126
+		$_CPT_endpoints = array();
127
+		if (is_array($this->_CPTs)) {
128
+			foreach ($this->_CPTs as $CPT_type => $CPT) {
129
+				if (isset($CPT['plural_slug'])) {
130
+					$_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type;
131
+				}
132
+			}
133
+		}
134
+		return $_CPT_endpoints;
135
+	}
136
+
137
+
138
+	/**
139
+	 * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to
140
+	 * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and
141
+	 * adding EE objects to the post to facilitate further querying of related data etc)
142
+	 *
143
+	 * @param WP_Query $WP_Query
144
+	 * @return void
145
+	 * @throws \EE_Error
146
+	 * @throws \InvalidArgumentException
147
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
148
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
149
+	 */
150
+	public function pre_get_posts($WP_Query)
151
+	{
152
+		// check that post-type is set
153
+		if (! $WP_Query instanceof WP_Query) {
154
+			return;
155
+		}
156
+		// add our conditionals
157
+		$this->_set_EE_tags_on_WP_Query($WP_Query);
158
+		// check for terms
159
+		$this->_set_post_type_for_terms($WP_Query);
160
+		// make sure paging is always set
161
+		$this->_set_paging($WP_Query);
162
+		// is a taxonomy set ?
163
+		$this->_set_CPT_taxonomies_on_WP_Query($WP_Query);
164
+		// loop thru post_types if set
165
+		$this->_process_WP_Query_post_types($WP_Query);
166
+	}
167
+
168
+
169
+	/**
170
+	 * @param WP_Query $WP_Query
171
+	 * @return void
172
+	 */
173
+	private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query)
174
+	{
175
+		$WP_Query->is_espresso_event_single = false;
176
+		$WP_Query->is_espresso_event_archive = false;
177
+		$WP_Query->is_espresso_event_taxonomy = false;
178
+		$WP_Query->is_espresso_venue_single = false;
179
+		$WP_Query->is_espresso_venue_archive = false;
180
+		$WP_Query->is_espresso_venue_taxonomy = false;
181
+	}
182
+
183
+
184
+	/**
185
+	 * @return void
186
+	 * @throws EE_Error
187
+	 * @throws InvalidArgumentException
188
+	 * @throws InvalidDataTypeException
189
+	 * @throws InvalidInterfaceException
190
+	 */
191
+	private function _set_CPT_terms()
192
+	{
193
+		if (empty($this->_CPT_terms)) {
194
+			$terms = EEM_Term::instance()->get_all_CPT_post_tags();
195
+			foreach ($terms as $term) {
196
+				if ($term instanceof EE_Term) {
197
+					$this->_CPT_terms[ $term->slug() ] = $term;
198
+				}
199
+			}
200
+		}
201
+	}
202
+
203
+
204
+	/**
205
+	 * @param WP_Query $WP_Query
206
+	 * @return void
207
+	 * @throws EE_Error
208
+	 * @throws InvalidArgumentException
209
+	 * @throws InvalidDataTypeException
210
+	 * @throws InvalidInterfaceException
211
+	 */
212
+	private function _set_post_type_for_terms(WP_Query $WP_Query)
213
+	{
214
+		// is a tag set ?
215
+		if (isset($WP_Query->query['tag'])) {
216
+			// get term for tag
217
+			$term = EEM_Term::instance()->get_post_tag_for_event_or_venue($WP_Query->query['tag']);
218
+			// verify the term
219
+			if ($term instanceof EE_Term) {
220
+				$term->post_type = array_merge(array('post', 'page'), (array) $term->post_type);
221
+				$term->post_type = apply_filters(
222
+					'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type',
223
+					$term->post_type,
224
+					$term
225
+				);
226
+				// if a post type is already set
227
+				if (isset($WP_Query->query_vars['post_type'])) {
228
+					// add to existing array
229
+					$term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type);
230
+				}
231
+				// just set post_type to our CPT
232
+				$WP_Query->set('post_type', array_unique($term->post_type));
233
+			}
234
+		}
235
+	}
236
+
237
+
238
+	/**
239
+	 * @param WP_Query $WP_Query
240
+	 * @return void
241
+	 */
242
+	public function _set_paging($WP_Query)
243
+	{
244
+		if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) {
245
+			$page = get_query_var('page') ? get_query_var('page') : null;
246
+			$paged = get_query_var('paged') ? get_query_var('paged') : $page;
247
+			$WP_Query->set('paged', $paged);
248
+		}
249
+	}
250
+
251
+
252
+	/**
253
+	 * @param \WP_Query $WP_Query
254
+	 */
255
+	protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query)
256
+	{
257
+		// is a taxonomy set ?
258
+		if ($WP_Query->is_tax) {
259
+			// loop thru our taxonomies
260
+			foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) {
261
+				// check if one of our taxonomies is set as a query var
262
+				if (isset($WP_Query->query[ $CPT_taxonomy ])) {
263
+					// but which CPT does that correspond to??? hmmm... guess we gotta go looping
264
+					foreach ($this->_CPTs as $post_type => $CPT) {
265
+						// verify our CPT has args, is public and has taxonomies set
266
+						if (isset($CPT['args']['public'])
267
+							&& $CPT['args']['public']
268
+							&& ! empty($CPT['args']['taxonomies'])
269
+							&& in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true)
270
+						) {
271
+							// if so, then add this CPT post_type to the current query's array of post_types'
272
+							$WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type'])
273
+								? (array) $WP_Query->query_vars['post_type']
274
+								: array();
275
+							$WP_Query->query_vars['post_type'][] = $post_type;
276
+							switch ($post_type) {
277
+								case 'espresso_events':
278
+									$WP_Query->is_espresso_event_taxonomy = true;
279
+									break;
280
+								case 'espresso_venues':
281
+									$WP_Query->is_espresso_venue_taxonomy = true;
282
+									break;
283
+								default:
284
+									do_action(
285
+										'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type',
286
+										$WP_Query,
287
+										$this
288
+									);
289
+							}
290
+						}
291
+					}
292
+				}
293
+			}
294
+		}
295
+	}
296
+
297
+
298
+	/**
299
+	 * @param \WP_Query $WP_Query
300
+	 * @throws InvalidArgumentException
301
+	 * @throws InvalidDataTypeException
302
+	 * @throws InvalidInterfaceException
303
+	 */
304
+	protected function _process_WP_Query_post_types(WP_Query $WP_Query)
305
+	{
306
+		if (isset($WP_Query->query_vars['post_type'])) {
307
+			// loop thru post_types as array
308
+			foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) {
309
+				// is current query for an EE CPT ?
310
+				if (isset($this->_CPTs[ $post_type ])) {
311
+					// is EE on or off ?
312
+					if (EE_Maintenance_Mode::instance()->level()) {
313
+						// reroute CPT template view to maintenance_mode.template.php
314
+						if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) {
315
+							add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999);
316
+						}
317
+						if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) {
318
+							add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1);
319
+						}
320
+						return;
321
+					}
322
+					$this->_generate_CptQueryModifier($WP_Query, $post_type);
323
+				}
324
+			}
325
+		}
326
+	}
327
+
328
+
329
+	/**
330
+	 * @param \WP_Query $WP_Query
331
+	 * @param string    $post_type
332
+	 * @throws InvalidArgumentException
333
+	 * @throws InvalidDataTypeException
334
+	 * @throws InvalidInterfaceException
335
+	 */
336
+	protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type)
337
+	{
338
+		$this->query_modifier = LoaderFactory::getLoader()->getShared(
339
+			'EventEspresso\core\CPTs\CptQueryModifier',
340
+			array(
341
+				$post_type,
342
+				$this->_CPTs[ $post_type ],
343
+				$WP_Query,
344
+			)
345
+		);
346
+		$this->_CPT_taxonomies = $this->query_modifier->taxonomies();
347
+	}
348
+
349
+
350
+	/**
351
+	 * inject_EE_shortcode_placeholder
352
+	 * in order to display the M-Mode notice on our CPT routes,
353
+	 * we need to first inject what looks like one of our shortcodes,
354
+	 * so that it can be replaced with the actual M-Mode notice
355
+	 *
356
+	 * @return string
357
+	 */
358
+	public function inject_EE_shortcode_placeholder()
359
+	{
360
+		return '[ESPRESSO_';
361
+	}
362
+
363
+
364
+	/**
365
+	 * @deprecated
366
+	 * @since  4.8.41
367
+	 * @return void
368
+	 */
369
+	public function _possibly_set_ee_request_var()
370
+	{
371
+		$this->query_modifier->setRequestVarsIfCpt();
372
+	}
373
+
374
+
375
+	/**
376
+	 * @deprecated
377
+	 * @since  4.8.41
378
+	 * @param  $SQL
379
+	 * @return string
380
+	 */
381
+	public function posts_fields($SQL)
382
+	{
383
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
384
+			return $this->query_modifier->postsFields($SQL);
385
+		}
386
+		return $SQL;
387
+	}
388
+
389
+
390
+	/**
391
+	 * @deprecated
392
+	 * @since  4.8.41
393
+	 * @param  $SQL
394
+	 * @return string
395
+	 */
396
+	public function posts_join($SQL)
397
+	{
398
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
399
+			return $this->query_modifier->postsJoin($SQL);
400
+		}
401
+		return $SQL;
402
+	}
403
+
404
+
405
+	/**
406
+	 * @deprecated
407
+	 * @since  4.8.41
408
+	 * @param  \WP_Post[] $posts
409
+	 * @return \WP_Post[]
410
+	 */
411
+	public function the_posts($posts)
412
+	{
413
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
414
+			$this->query_modifier->thePosts($posts);
415
+		}
416
+		return $posts;
417
+	}
418
+
419
+
420
+	/**
421
+	 * @deprecated
422
+	 * @since  4.8.41
423
+	 * @param $url
424
+	 * @param $ID
425
+	 * @return string
426
+	 */
427
+	public function get_edit_post_link($url, $ID)
428
+	{
429
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
430
+			return $this->query_modifier->getEditPostLink($url, $ID);
431
+		}
432
+		return '';
433
+	}
434
+
435
+
436
+	/**
437
+	 * @deprecated
438
+	 * @since  4.8.41
439
+	 * @param null $WP_Query
440
+	 */
441
+	protected function _do_template_filters($WP_Query = null)
442
+	{
443
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
444
+			$this->query_modifier->addTemplateFilters();
445
+		}
446
+	}
447
+
448
+
449
+	/**
450
+	 * @deprecated
451
+	 * @since  4.8.41
452
+	 * @param string $current_template Existing default template path derived for this page call.
453
+	 * @return string the path to the full template file.
454
+	 */
455
+	public function single_cpt_template($current_template)
456
+	{
457
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
458
+			return $this->query_modifier->singleCptTemplate($current_template);
459
+		}
460
+		return $current_template;
461
+	}
462 462
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
         CustomTaxonomyDefinitions $taxonomies = null
73 73
     ) {
74 74
         // check if class object is instantiated
75
-        if (! self::$_instance instanceof EE_CPT_Strategy
75
+        if ( ! self::$_instance instanceof EE_CPT_Strategy
76 76
             && $custom_post_types instanceof CustomPostTypeDefinitions
77 77
             && $taxonomies instanceof CustomTaxonomyDefinitions
78 78
         ) {
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
         if (is_array($this->_CPTs)) {
128 128
             foreach ($this->_CPTs as $CPT_type => $CPT) {
129 129
                 if (isset($CPT['plural_slug'])) {
130
-                    $_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type;
130
+                    $_CPT_endpoints [(string) $CPT['plural_slug']] = $CPT_type;
131 131
                 }
132 132
             }
133 133
         }
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
     public function pre_get_posts($WP_Query)
151 151
     {
152 152
         // check that post-type is set
153
-        if (! $WP_Query instanceof WP_Query) {
153
+        if ( ! $WP_Query instanceof WP_Query) {
154 154
             return;
155 155
         }
156 156
         // add our conditionals
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
             $terms = EEM_Term::instance()->get_all_CPT_post_tags();
195 195
             foreach ($terms as $term) {
196 196
                 if ($term instanceof EE_Term) {
197
-                    $this->_CPT_terms[ $term->slug() ] = $term;
197
+                    $this->_CPT_terms[$term->slug()] = $term;
198 198
                 }
199 199
             }
200 200
         }
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
             // loop thru our taxonomies
260 260
             foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) {
261 261
                 // check if one of our taxonomies is set as a query var
262
-                if (isset($WP_Query->query[ $CPT_taxonomy ])) {
262
+                if (isset($WP_Query->query[$CPT_taxonomy])) {
263 263
                     // but which CPT does that correspond to??? hmmm... guess we gotta go looping
264 264
                     foreach ($this->_CPTs as $post_type => $CPT) {
265 265
                         // verify our CPT has args, is public and has taxonomies set
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
                                     break;
283 283
                                 default:
284 284
                                     do_action(
285
-                                        'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type',
285
+                                        'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_'.$post_type.'_post_type',
286 286
                                         $WP_Query,
287 287
                                         $this
288 288
                                     );
@@ -307,11 +307,11 @@  discard block
 block discarded – undo
307 307
             // loop thru post_types as array
308 308
             foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) {
309 309
                 // is current query for an EE CPT ?
310
-                if (isset($this->_CPTs[ $post_type ])) {
310
+                if (isset($this->_CPTs[$post_type])) {
311 311
                     // is EE on or off ?
312 312
                     if (EE_Maintenance_Mode::instance()->level()) {
313 313
                         // reroute CPT template view to maintenance_mode.template.php
314
-                        if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) {
314
+                        if ( ! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) {
315 315
                             add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999);
316 316
                         }
317 317
                         if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) {
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
             'EventEspresso\core\CPTs\CptQueryModifier',
340 340
             array(
341 341
                 $post_type,
342
-                $this->_CPTs[ $post_type ],
342
+                $this->_CPTs[$post_type],
343 343
                 $WP_Query,
344 344
             )
345 345
         );
Please login to merge, or discard this patch.