Completed
Branch BUG-9647-cpt-queries (308763)
by
unknown
1209:38 queued 1195:13
created
core/CPTs/EE_CPT_Strategy.core.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');}
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); }
2 2
 /**
3 3
  * CPT_Strategy
4 4
  *
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	public static function instance() {
71 71
 		// check if class object is instantiated
72
-		if ( ! self::$_instance instanceof EE_CPT_Strategy ) {
72
+		if ( ! self::$_instance instanceof EE_CPT_Strategy) {
73 73
 			self::$_instance = new self();
74 74
 		}
75 75
 		return self::$_instance;
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 		$this->_CPTs = EE_Register_CPTs::get_CPTs();
87 87
 		$this->_CPT_endpoints = $this->_set_CPT_endpoints();
88 88
 		$this->_CPT_taxonomies = EE_Register_CPTs::get_taxonomies();
89
-		add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ), 5 );
89
+		add_action('pre_get_posts', array($this, 'pre_get_posts'), 5);
90 90
 	}
91 91
 
92 92
 
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 	 */
121 121
 	private function _set_CPT_endpoints() {
122 122
 		$_CPT_endpoints = array();
123
-		if ( is_array( $this->_CPTs )) {
124
-			foreach ( $this->_CPTs as $CPT_type => $CPT ) {
125
-				$_CPT_endpoints [ $CPT['plural_slug'] ] = $CPT_type;
123
+		if (is_array($this->_CPTs)) {
124
+			foreach ($this->_CPTs as $CPT_type => $CPT) {
125
+				$_CPT_endpoints [$CPT['plural_slug']] = $CPT_type;
126 126
 			}
127 127
 		}
128 128
 		return $_CPT_endpoints;
@@ -140,21 +140,21 @@  discard block
 block discarded – undo
140 140
 	 * @param WP_Query $WP_Query
141 141
 	 * @return void
142 142
 	 */
143
-	public function pre_get_posts( $WP_Query ) {
143
+	public function pre_get_posts($WP_Query) {
144 144
 		// check that post-type is set
145
-		if ( ! $WP_Query instanceof WP_Query ) {
145
+		if ( ! $WP_Query instanceof WP_Query) {
146 146
 			return;
147 147
 		}
148 148
 		// add our conditionals
149
-		$this->_set_EE_tags_on_WP_Query( $WP_Query );
149
+		$this->_set_EE_tags_on_WP_Query($WP_Query);
150 150
 		// check for terms
151
-		$this->_set_post_type_for_terms( $WP_Query );
151
+		$this->_set_post_type_for_terms($WP_Query);
152 152
 		// make sure paging is always set
153
-		$this->_set_paging( $WP_Query );
153
+		$this->_set_paging($WP_Query);
154 154
 		// is a taxonomy set ?
155
-		$this->_set_CPT_taxonomies_on_WP_Query( $WP_Query );
155
+		$this->_set_CPT_taxonomies_on_WP_Query($WP_Query);
156 156
 		// loop thru post_types if set
157
-		$this->_process_WP_Query_post_types( $WP_Query );
157
+		$this->_process_WP_Query_post_types($WP_Query);
158 158
 	}
159 159
 
160 160
 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 * @param WP_Query $WP_Query
166 166
 	 * @return void
167 167
 	 */
168
-	private function _set_EE_tags_on_WP_Query( WP_Query $WP_Query) {
168
+	private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query) {
169 169
 		$WP_Query->is_espresso_event_single = FALSE;
170 170
 		$WP_Query->is_espresso_event_archive = FALSE;
171 171
 		$WP_Query->is_espresso_event_taxonomy = FALSE;
@@ -183,11 +183,11 @@  discard block
 block discarded – undo
183 183
 	 * @return void
184 184
 	 */
185 185
 	private function _set_CPT_terms() {
186
-		if ( empty( $this->_CPT_terms )) {
186
+		if (empty($this->_CPT_terms)) {
187 187
 			$terms = EEM_Term::instance()->get_all_CPT_post_tags();
188
-			foreach ( $terms as $term ) {
189
-				if ( $term instanceof EE_Term ) {
190
-					$this->_CPT_terms[ $term->slug() ] = $term;
188
+			foreach ($terms as $term) {
189
+				if ($term instanceof EE_Term) {
190
+					$this->_CPT_terms[$term->slug()] = $term;
191 191
 				}
192 192
 			}
193 193
 		}
@@ -202,24 +202,24 @@  discard block
 block discarded – undo
202 202
 	 * @param $WP_Query
203 203
 	 * @return void
204 204
 	 */
205
-	private function _set_post_type_for_terms( WP_Query $WP_Query ) {
205
+	private function _set_post_type_for_terms(WP_Query $WP_Query) {
206 206
 		// is a tag set ?
207
-		if ( isset( $WP_Query->query['tag'] )) {
207
+		if (isset($WP_Query->query['tag'])) {
208 208
 			// set post_tags
209 209
 			$this->_set_CPT_terms();
210 210
 			// is this tag archive term in the list of terms used by our CPTs ?
211
-			$term = isset ( $this->_CPT_terms[ $WP_Query->query['tag'] ] ) ? $this->_CPT_terms[ $WP_Query->query['tag'] ] : NULL;
211
+			$term = isset ($this->_CPT_terms[$WP_Query->query['tag']]) ? $this->_CPT_terms[$WP_Query->query['tag']] : NULL;
212 212
 			// verify the term
213
-			if ( $term instanceof EE_Term ) {
214
-				$term->post_type  = array_merge( array( 'post', 'page' ), (array)$term->post_type );
215
-				$term->post_type = apply_filters( 'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type', $term->post_type, $term );
213
+			if ($term instanceof EE_Term) {
214
+				$term->post_type = array_merge(array('post', 'page'), (array) $term->post_type);
215
+				$term->post_type = apply_filters('FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type', $term->post_type, $term);
216 216
 				// if a post type is already set
217
-				if ( isset( $WP_Query->query_vars['post_type'] )) {
217
+				if (isset($WP_Query->query_vars['post_type'])) {
218 218
 						// add to existing array
219
-						$term->post_type = array_merge ( (array)$WP_Query->query_vars['post_type'], $term->post_type );
219
+						$term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type);
220 220
 				}
221 221
 				// just set post_type to our CPT
222
-				$WP_Query->set( 'post_type', array_unique( $term->post_type ) );
222
+				$WP_Query->set('post_type', array_unique($term->post_type));
223 223
 			}
224 224
 		}
225 225
 	}
@@ -233,11 +233,11 @@  discard block
 block discarded – undo
233 233
 	 * @param WP_Query $WP_Query
234 234
 	 * @return void
235 235
 	 */
236
-	public function _set_paging( $WP_Query ) {
237
-		if ( $WP_Query->is_main_query() && apply_filters( 'FHEE__EE_CPT_Strategy___set_paging', TRUE )) {
236
+	public function _set_paging($WP_Query) {
237
+		if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', TRUE)) {
238 238
 			$page = get_query_var('page') ? get_query_var('page') : NULL;
239 239
 			$paged = get_query_var('paged') ? get_query_var('paged') : $page;
240
-			$WP_Query->set( 'paged', $paged );
240
+			$WP_Query->set('paged', $paged);
241 241
 		}
242 242
 	}
243 243
 
@@ -247,28 +247,28 @@  discard block
 block discarded – undo
247 247
 	 * @access protected
248 248
 	 * @param \WP_Query $WP_Query
249 249
 	 */
250
-	protected function _set_CPT_taxonomies_on_WP_Query( WP_Query $WP_Query ) {
250
+	protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query) {
251 251
 		// is a taxonomy set ?
252
-		if ( $WP_Query->is_tax ) {
252
+		if ($WP_Query->is_tax) {
253 253
 			// loop thru our taxonomies
254
-			foreach ( $this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details ) {
254
+			foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) {
255 255
 				// check if one of our taxonomies is set as a query var
256
-				if ( isset( $WP_Query->query[ $CPT_taxonomy ] ) ) {
256
+				if (isset($WP_Query->query[$CPT_taxonomy])) {
257 257
 					// but which CPT does that correspond to??? hmmm... guess we gotta go looping
258
-					foreach ( $this->_CPTs as $post_type => $CPT ) {
258
+					foreach ($this->_CPTs as $post_type => $CPT) {
259 259
 						// verify our CPT has args, is public and has taxonomies set
260 260
 						if (
261
-							isset( $CPT['args'], $CPT['args']['public'] )
261
+							isset($CPT['args'], $CPT['args']['public'])
262 262
 							&& $CPT['args']['public']
263
-							&& ! empty( $CPT['args']['taxonomies'] )
264
-							&& in_array( $CPT_taxonomy, $CPT['args']['taxonomies'] )
263
+							&& ! empty($CPT['args']['taxonomies'])
264
+							&& in_array($CPT_taxonomy, $CPT['args']['taxonomies'])
265 265
 						) {
266 266
 							// if so, then add this CPT post_type to the current query's array of post_types'
267
-							$WP_Query->query_vars['post_type'] = isset( $WP_Query->query_vars['post_type'] )
267
+							$WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type'])
268 268
 								? (array) $WP_Query->query_vars['post_type']
269 269
 								: array();
270 270
 							$WP_Query->query_vars['post_type'][] = $post_type;
271
-							switch ( $post_type ) {
271
+							switch ($post_type) {
272 272
 								case 'espresso_events' :
273 273
 									$WP_Query->is_espresso_event_taxonomy = true;
274 274
 									break;
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 									break;
278 278
 								default :
279 279
 									do_action(
280
-										'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type',
280
+										'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_'.$post_type.'_post_type',
281 281
 										$WP_Query,
282 282
 										$this
283 283
 									);
@@ -295,24 +295,24 @@  discard block
 block discarded – undo
295 295
 	 * @access public
296 296
 	 * @param \WP_Query $WP_Query
297 297
 	 */
298
-	protected function _process_WP_Query_post_types( WP_Query $WP_Query ) {
299
-		if ( isset( $WP_Query->query_vars['post_type'] ) ) {
298
+	protected function _process_WP_Query_post_types(WP_Query $WP_Query) {
299
+		if (isset($WP_Query->query_vars['post_type'])) {
300 300
 			// loop thru post_types as array
301
-			foreach ( (array) $WP_Query->query_vars['post_type'] as $post_type ) {
301
+			foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) {
302 302
 				// is current query for an EE CPT ?
303
-				if ( isset( $this->_CPTs[ $post_type ] ) ) {
303
+				if (isset($this->_CPTs[$post_type])) {
304 304
 					// is EE on or off ?
305
-					if ( EE_Maintenance_Mode::instance()->level() ) {
305
+					if (EE_Maintenance_Mode::instance()->level()) {
306 306
 						// reroute CPT template view to maintenance_mode.template.php
307
-						if ( ! has_filter( 'template_include', array( 'EE_Maintenance_Mode', 'template_include' ) ) ) {
308
-							add_filter( 'template_include', array( 'EE_Maintenance_Mode', 'template_include' ), 99999 );
307
+						if ( ! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) {
308
+							add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999);
309 309
 						}
310
-						if ( has_filter( 'the_content', array( EE_Maintenance_Mode::instance(), 'the_content' ) ) ) {
311
-							add_filter( 'the_content', array( $this, 'inject_EE_shortcode_placeholder' ), 1 );
310
+						if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) {
311
+							add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1);
312 312
 						}
313 313
 						return;
314 314
 					}
315
-					$this->_generate_CptQueryModifier( $WP_Query, $post_type );
315
+					$this->_generate_CptQueryModifier($WP_Query, $post_type);
316 316
 				}
317 317
 			}
318 318
 		}
@@ -324,10 +324,10 @@  discard block
 block discarded – undo
324 324
 	 * @param \WP_Query $WP_Query
325 325
 	 * @param string    $post_type
326 326
 	 */
327
-	protected function _generate_CptQueryModifier( WP_Query $WP_Query, $post_type ) {
327
+	protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type) {
328 328
 		$this->query_modifier = new EventEspresso\Core\CPTs\CptQueryModifier(
329 329
 			$post_type,
330
-			$this->_CPTs[ $post_type ],
330
+			$this->_CPTs[$post_type],
331 331
 			$WP_Query,
332 332
 			EE_Registry::instance()->REQ
333 333
 		);
@@ -370,9 +370,9 @@  discard block
 block discarded – undo
370 370
 	 * @param  $SQL
371 371
 	 * @return string
372 372
 	 */
373
-	public function posts_fields( $SQL ) {
374
-		if ( $this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier ) {
375
-			return $this->query_modifier->postsFields( $SQL );
373
+	public function posts_fields($SQL) {
374
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
375
+			return $this->query_modifier->postsFields($SQL);
376 376
 		}
377 377
 		return $SQL;
378 378
 	}
@@ -386,9 +386,9 @@  discard block
 block discarded – undo
386 386
 	 * @param  $SQL
387 387
 	 * @return string
388 388
 	 */
389
-	public function posts_join( $SQL ) {
390
-		if ( $this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier ) {
391
-			return $this->query_modifier->postsJoin( $SQL );
389
+	public function posts_join($SQL) {
390
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
391
+			return $this->query_modifier->postsJoin($SQL);
392 392
 		}
393 393
 		return $SQL;
394 394
 	}
@@ -402,9 +402,9 @@  discard block
 block discarded – undo
402 402
 	 * @param  \WP_Post[] $posts
403 403
 	 * @return \WP_Post[]
404 404
 	 */
405
-	public function the_posts( $posts ) {
406
-		if ( $this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier ) {
407
-			$this->query_modifier->thePosts( $posts );
405
+	public function the_posts($posts) {
406
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
407
+			$this->query_modifier->thePosts($posts);
408 408
 		}
409 409
 		return $posts;
410 410
 	}
@@ -419,9 +419,9 @@  discard block
 block discarded – undo
419 419
 	 * @param $ID
420 420
 	 * @return string
421 421
 	 */
422
-	public function get_edit_post_link( $url, $ID ) {
423
-		if ( $this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier ) {
424
-			return $this->query_modifier->getEditPostLink( $url, $ID );
422
+	public function get_edit_post_link($url, $ID) {
423
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
424
+			return $this->query_modifier->getEditPostLink($url, $ID);
425 425
 		}
426 426
 		return '';
427 427
 	}
@@ -434,8 +434,8 @@  discard block
 block discarded – undo
434 434
 	 * @access public
435 435
 	 * @param null $WP_Query
436 436
 	 */
437
-	protected function _do_template_filters( $WP_Query = null ) {
438
-		if ( $this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier ) {
437
+	protected function _do_template_filters($WP_Query = null) {
438
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
439 439
 			$this->query_modifier->addTemplateFilters();
440 440
 		}
441 441
 	}
@@ -449,9 +449,9 @@  discard block
 block discarded – undo
449 449
 	 * @param string $current_template Existing default template path derived for this page call.
450 450
 	 * @return string the path to the full template file.
451 451
 	 */
452
-	public function single_cpt_template( $current_template ) {
453
-		if ( $this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier ) {
454
-			return $this->query_modifier->singleCptTemplate( $current_template );
452
+	public function single_cpt_template($current_template) {
453
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
454
+			return $this->query_modifier->singleCptTemplate($current_template);
455 455
 		}
456 456
 		return $current_template;
457 457
 	}
Please login to merge, or discard this patch.
core/CPTs/CptQueryModifier.php 1 patch
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\Core\CPTs;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-	exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
 		\WP_Query $WP_Query,
81 81
 		\EE_Request_Handler $request
82 82
 	) {
83
-		$this->setRequest( $request );
84
-		$this->setWpQuery( $WP_Query );
85
-		$this->setPostType( $post_type );
86
-		$this->setCptDetails( $cpt_details );
83
+		$this->setRequest($request);
84
+		$this->setWpQuery($WP_Query);
85
+		$this->setPostType($post_type);
86
+		$this->setCptDetails($cpt_details);
87 87
 		$this->init();
88 88
 	}
89 89
 
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 	/**
102 102
 	 * @param string $post_type
103 103
 	 */
104
-	protected function setPostType( $post_type ) {
104
+	protected function setPostType($post_type) {
105 105
 		$this->post_type = $post_type;
106 106
 	}
107 107
 
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	/**
120 120
 	 * @param array $cpt_details
121 121
 	 */
122
-	protected function setCptDetails( $cpt_details ) {
122
+	protected function setCptDetails($cpt_details) {
123 123
 		$this->cpt_details = $cpt_details;
124 124
 	}
125 125
 
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	/**
138 138
 	 * @param \EE_Table_Base[] $model_tables
139 139
 	 */
140
-	protected function setModelTables( $model_tables ) {
140
+	protected function setModelTables($model_tables) {
141 141
 		$this->model_tables = $model_tables;
142 142
 	}
143 143
 
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 	 * @return array
148 148
 	 */
149 149
 	public function taxonomies() {
150
-		if ( empty( $this->taxonomies ) ) {
150
+		if (empty($this->taxonomies)) {
151 151
 			$this->initializeTaxonomies();
152 152
 		}
153 153
 		return $this->taxonomies;
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	/**
159 159
 	 * @param array $taxonomies
160 160
 	 */
161
-	protected function setTaxonomies( array $taxonomies ) {
161
+	protected function setTaxonomies(array $taxonomies) {
162 162
 		$this->taxonomies = $taxonomies;
163 163
 	}
164 164
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 	/**
177 177
 	 * @param \EE_Secondary_Table $meta_table
178 178
 	 */
179
-	public function setMetaTable( \EE_Secondary_Table $meta_table ) {
179
+	public function setMetaTable(\EE_Secondary_Table $meta_table) {
180 180
 		$this->meta_table = $meta_table;
181 181
 	}
182 182
 
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 	/**
195 195
 	 * @param \EEM_Base $CPT_model
196 196
 	 */
197
-	protected function setModel( \EEM_Base $CPT_model ) {
197
+	protected function setModel(\EEM_Base $CPT_model) {
198 198
 		$this->model = $CPT_model;
199 199
 	}
200 200
 
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 	/**
213 213
 	 * @param \EE_Request_Handler $request
214 214
 	 */
215
-	protected function setRequest( \EE_Request_Handler $request ) {
215
+	protected function setRequest(\EE_Request_Handler $request) {
216 216
 		$this->request = $request;
217 217
 	}
218 218
 
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 	/**
231 231
 	 * @param \WP_Query $wp_query
232 232
 	 */
233
-	public function setWpQuery( \WP_Query $wp_query ) {
233
+	public function setWpQuery(\WP_Query $wp_query) {
234 234
 		$this->wp_query = $wp_query;
235 235
 	}
236 236
 
@@ -245,22 +245,22 @@  discard block
 block discarded – undo
245 245
 	protected function initializeTaxonomies() {
246 246
 		// check if taxonomies have already been set and that this CPT has taxonomies registered for it
247 247
 		if (
248
-			empty( $this->taxonomies )
249
-			&& isset( $this->cpt_details['args'], $this->cpt_details['args']['taxonomies'] )
248
+			empty($this->taxonomies)
249
+			&& isset($this->cpt_details['args'], $this->cpt_details['args']['taxonomies'])
250 250
 		) {
251 251
 			// if so then grab them, but we want the taxonomy name as the key
252
-			$taxonomies = array_flip( $this->cpt_details['args']['taxonomies'] );
252
+			$taxonomies = array_flip($this->cpt_details['args']['taxonomies']);
253 253
 			// then grab the list of ALL taxonomies
254 254
 			$all_taxonomies = \EE_Register_CPTs::get_taxonomies();
255
-			foreach ( $taxonomies as $taxonomy => &$details ) {
255
+			foreach ($taxonomies as $taxonomy => &$details) {
256 256
 				// add details to our taxonomies if they exist
257
-				$details = isset( $all_taxonomies[ $taxonomy ] )
258
-					? $all_taxonomies[ $taxonomy ]
257
+				$details = isset($all_taxonomies[$taxonomy])
258
+					? $all_taxonomies[$taxonomy]
259 259
 					: array();
260 260
 			}
261 261
 			// ALWAYS unset() variables that were passed by reference
262
-			unset( $details );
263
-			$this->setTaxonomies( $taxonomies );
262
+			unset($details);
263
+			$this->setTaxonomies($taxonomies);
264 264
 		}
265 265
 	}
266 266
 
@@ -270,11 +270,11 @@  discard block
 block discarded – undo
270 270
 		$this->setAdditionalCptDetails();
271 271
 		$this->setRequestVarsIfCpt();
272 272
 		// convert post_type to model name
273
-		$model_name = str_replace( 'EE_', '', $this->cpt_details['class_name'] );
273
+		$model_name = str_replace('EE_', '', $this->cpt_details['class_name']);
274 274
 		// load all tables related to CPT
275
-		$this->setupModelsAndTables( $model_name );
275
+		$this->setupModelsAndTables($model_name);
276 276
 		// load and instantiate CPT_*_Strategy
277
-		$CPT_Strategy = $this->cptStrategyClass( $model_name );
277
+		$CPT_Strategy = $this->cptStrategyClass($model_name);
278 278
 		// !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
279 279
 		// here's the list of available filters in the WP_Query object
280 280
 		// 'posts_where_paged'
@@ -285,17 +285,17 @@  discard block
 block discarded – undo
285 285
 		// 'post_limits'
286 286
 		// 'posts_fields'
287 287
 		// 'posts_join'
288
-		add_filter( 'posts_fields', array( $this, 'postsFields' ) );
289
-		add_filter( 'posts_join', array( $this, 'postsJoin' ) );
288
+		add_filter('posts_fields', array($this, 'postsFields'));
289
+		add_filter('posts_join', array($this, 'postsJoin'));
290 290
 		add_filter(
291
-			'get_' . $this->post_type . '_metadata',
292
-			array( $CPT_Strategy, 'get_EE_post_type_metadata' ),
291
+			'get_'.$this->post_type.'_metadata',
292
+			array($CPT_Strategy, 'get_EE_post_type_metadata'),
293 293
 			1,
294 294
 			4
295 295
 		);
296
-		add_filter( 'the_posts', array( $this, 'thePosts' ), 1, 1 );
297
-		if ( $this->wp_query->is_main_query() ) {
298
-			add_filter( 'get_edit_post_link', array( $this, 'getEditPostLink' ), 10, 2 );
296
+		add_filter('the_posts', array($this, 'thePosts'), 1, 1);
297
+		if ($this->wp_query->is_main_query()) {
298
+			add_filter('get_edit_post_link', array($this, 'getEditPostLink'), 10, 2);
299 299
 			$this->addTemplateFilters();
300 300
 		}
301 301
 	}
@@ -312,18 +312,18 @@  discard block
 block discarded – undo
312 312
 		// the post or category or term that is triggering EE
313 313
 		$this->cpt_details['espresso_page'] = $this->request->is_espresso_page();
314 314
 		// requested post name
315
-		$this->cpt_details['post_name'] = $this->request->get( 'post_name' );
315
+		$this->cpt_details['post_name'] = $this->request->get('post_name');
316 316
 		// add support for viewing 'private', 'draft', or 'pending' posts
317 317
 		if (
318
-			isset( $this->wp_query->query_vars['p'] )
318
+			isset($this->wp_query->query_vars['p'])
319 319
 			&& $this->wp_query->query_vars['p'] !== 0
320 320
 			&& is_user_logged_in()
321
-			&& current_user_can( 'edit_post', $this->wp_query->query_vars['p'] )
321
+			&& current_user_can('edit_post', $this->wp_query->query_vars['p'])
322 322
 		) {
323 323
 			// we can just inject directly into the WP_Query object
324
-			$this->wp_query->query['post_status'] = array( 'publish', 'private', 'draft', 'pending' );
324
+			$this->wp_query->query['post_status'] = array('publish', 'private', 'draft', 'pending');
325 325
 			// now set the main 'ee' request var so that the appropriate module can load the appropriate template(s)
326
-			$this->request->set( 'ee', $this->cpt_details['singular_slug'] );
326
+			$this->request->set('ee', $this->cpt_details['singular_slug']);
327 327
 		}
328 328
 	}
329 329
 
@@ -340,15 +340,15 @@  discard block
 block discarded – undo
340 340
 	 */
341 341
 	public function setRequestVarsIfCpt() {
342 342
 		// check if ee action var has been set
343
-		if ( ! $this->request->is_set( 'ee' ) ) {
343
+		if ( ! $this->request->is_set('ee')) {
344 344
 			// check that route exists for CPT archive slug
345
-			if ( is_archive() && \EE_Config::get_route( $this->cpt_details['plural_slug'] ) ) {
345
+			if (is_archive() && \EE_Config::get_route($this->cpt_details['plural_slug'])) {
346 346
 				// ie: set "ee" to "events"
347
-				$this->request->set( 'ee', $this->cpt_details['plural_slug'] );
347
+				$this->request->set('ee', $this->cpt_details['plural_slug']);
348 348
 				// or does it match a single page CPT like /event/
349
-			} else if ( is_single() && \EE_Config::get_route( $this->cpt_details['singular_slug'] ) ) {
349
+			} else if (is_single() && \EE_Config::get_route($this->cpt_details['singular_slug'])) {
350 350
 				// ie: set "ee" to "event"
351
-				$this->request->set( 'ee', $this->cpt_details['singular_slug'] );
351
+				$this->request->set('ee', $this->cpt_details['singular_slug']);
352 352
 			}
353 353
 		}
354 354
 	}
@@ -362,11 +362,11 @@  discard block
 block discarded – undo
362 362
 	 * @param string $model_name
363 363
 	 * @throws \EE_Error
364 364
 	 */
365
-	protected function setupModelsAndTables( $model_name ) {
365
+	protected function setupModelsAndTables($model_name) {
366 366
 		// get CPT table data via CPT Model
367
-		$model = \EE_Registry::instance()->load_model( $model_name );
368
-		if ( ! $model instanceof \EEM_Base ) {
369
-			throw new \EE_Error (
367
+		$model = \EE_Registry::instance()->load_model($model_name);
368
+		if ( ! $model instanceof \EEM_Base) {
369
+			throw new \EE_Error(
370 370
 				sprintf(
371 371
 					__(
372 372
 						'The "%1$s" model could not be loaded.',
@@ -376,14 +376,14 @@  discard block
 block discarded – undo
376 376
 				)
377 377
 			);
378 378
 		}
379
-		$this->setModel( $model );
380
-		$this->setModelTables( $this->model->get_tables() );
379
+		$this->setModel($model);
380
+		$this->setModelTables($this->model->get_tables());
381 381
 		// is there a Meta Table for this CPT?
382 382
 		if (
383
-			isset( $this->cpt_details['tables'][ $model_name . '_Meta' ] )
384
-			&& $this->cpt_details['tables'][ $model_name . '_Meta' ] instanceof \EE_Secondary_Table
383
+			isset($this->cpt_details['tables'][$model_name.'_Meta'])
384
+			&& $this->cpt_details['tables'][$model_name.'_Meta'] instanceof \EE_Secondary_Table
385 385
 		) {
386
-			$this->setMetaTable( $this->cpt_details['tables'][ $model_name . '_Meta' ] );
386
+			$this->setMetaTable($this->cpt_details['tables'][$model_name.'_Meta']);
387 387
 		}
388 388
 	}
389 389
 
@@ -396,18 +396,18 @@  discard block
 block discarded – undo
396 396
 	 * @param  string $model_name
397 397
 	 * @return string
398 398
 	 */
399
-	protected function cptStrategyClass( $model_name ) {
399
+	protected function cptStrategyClass($model_name) {
400 400
 		// creates classname like:  CPT_Event_Strategy
401
-		$CPT_Strategy_class_name = 'CPT_' . $model_name . '_Strategy';
401
+		$CPT_Strategy_class_name = 'CPT_'.$model_name.'_Strategy';
402 402
 		// load and instantiate
403 403
 		$CPT_Strategy = \EE_Registry::instance()->load_core(
404 404
 			$CPT_Strategy_class_name,
405
-			array( 'WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details )
405
+			array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
406 406
 		);
407
-		if ( $CPT_Strategy === null ) {
407
+		if ($CPT_Strategy === null) {
408 408
 			$CPT_Strategy = \EE_Registry::instance()->load_core(
409 409
 				'CPT_Default_Strategy',
410
-				array( 'WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details )
410
+				array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
411 411
 			);
412 412
 		}
413 413
 		return $CPT_Strategy;
@@ -422,13 +422,13 @@  discard block
 block discarded – undo
422 422
 	 * @param  $SQL
423 423
 	 * @return string
424 424
 	 */
425
-	public function postsFields( $SQL ) {
425
+	public function postsFields($SQL) {
426 426
 		// does this CPT have a meta table ?
427
-		if ( $this->meta_table instanceof \EE_Secondary_Table ) {
427
+		if ($this->meta_table instanceof \EE_Secondary_Table) {
428 428
 			// adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement
429
-			$SQL .= ', ' . $this->meta_table->get_table_name() . '.* ';
429
+			$SQL .= ', '.$this->meta_table->get_table_name().'.* ';
430 430
 		}
431
-		remove_filter( 'posts_fields', array( $this, 'postsFields' ) );
431
+		remove_filter('posts_fields', array($this, 'postsFields'));
432 432
 		return $SQL;
433 433
 	}
434 434
 
@@ -441,9 +441,9 @@  discard block
 block discarded – undo
441 441
 	 * @param  $SQL
442 442
 	 * @return string
443 443
 	 */
444
-	public function postsJoin( $SQL ) {
444
+	public function postsJoin($SQL) {
445 445
 		// does this CPT have a meta table ?
446
-		if ( $this->meta_table instanceof \EE_Secondary_Table ) {
446
+		if ($this->meta_table instanceof \EE_Secondary_Table) {
447 447
 			global $wpdb;
448 448
 			// adds something like " LEFT JOIN wp_esp_event_meta ON ( wp_esp_event_meta.EVT_ID = wp_posts.ID ) " to WP Query JOIN statement
449 449
 			$SQL .= ' LEFT JOIN '
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
 			        . $wpdb->posts
457 457
 			        . '.ID ) ';
458 458
 		}
459
-		remove_filter( 'posts_join', array( $this, 'postsJoin' ) );
459
+		remove_filter('posts_join', array($this, 'postsJoin'));
460 460
 		return $SQL;
461 461
 	}
462 462
 
@@ -469,17 +469,17 @@  discard block
 block discarded – undo
469 469
 	 * @param  \WP_Post[] $posts
470 470
 	 * @return \WP_Post[]
471 471
 	 */
472
-	public function thePosts( $posts ) {
472
+	public function thePosts($posts) {
473 473
 		$CPT_class = $this->cpt_details['class_name'];
474 474
 		// loop thru posts
475
-		if ( is_array( $posts ) && $this->model instanceof \EEM_CPT_Base ) {
476
-			foreach ( $posts as $key => $post ) {
477
-				if ( $post->post_type === $this->post_type ) {
478
-					$post->{$CPT_class} = $this->model->instantiate_class_from_post_object( $post );
475
+		if (is_array($posts) && $this->model instanceof \EEM_CPT_Base) {
476
+			foreach ($posts as $key => $post) {
477
+				if ($post->post_type === $this->post_type) {
478
+					$post->{$CPT_class} = $this->model->instantiate_class_from_post_object($post);
479 479
 				}
480 480
 			}
481 481
 		}
482
-		remove_filter( 'the_posts', array( $this, 'thePosts' ), 1 );
482
+		remove_filter('the_posts', array($this, 'thePosts'), 1);
483 483
 		return $posts;
484 484
 	}
485 485
 
@@ -490,17 +490,17 @@  discard block
 block discarded – undo
490 490
 	 * @param $ID
491 491
 	 * @return string
492 492
 	 */
493
-	public function getEditPostLink( $url, $ID ) {
493
+	public function getEditPostLink($url, $ID) {
494 494
 		// need to make sure we only edit links if our cpt
495 495
 		global $post;
496
-		if ( ! $post instanceof \WP_Post || $post->post_type !== $this->post_type ) {
496
+		if ( ! $post instanceof \WP_Post || $post->post_type !== $this->post_type) {
497 497
 			return $url;
498 498
 		}
499 499
 		//k made it here so all is good.
500 500
 		return wp_nonce_url(
501 501
 			add_query_arg(
502
-				array( 'page' => $this->post_type, 'post' => $ID, 'action' => 'edit' ),
503
-				admin_url( 'admin.php' )
502
+				array('page' => $this->post_type, 'post' => $ID, 'action' => 'edit'),
503
+				admin_url('admin.php')
504 504
 			),
505 505
 			'edit',
506 506
 			'edit_nonce'
@@ -517,9 +517,9 @@  discard block
 block discarded – undo
517 517
 	 */
518 518
 	public function addTemplateFilters() {
519 519
 		// if requested cpt supports page_templates and it's the main query
520
-		if ( ! empty( $this->cpt_details['args']['page_templates'] ) && $this->wp_query->is_main_query() ) {
520
+		if ( ! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
521 521
 			// then let's hook into the appropriate query_template hook
522
-			add_filter( 'single_template', array( $this, 'singleCptTemplate' ) );
522
+			add_filter('single_template', array($this, 'singleCptTemplate'));
523 523
 		}
524 524
 	}
525 525
 
@@ -533,20 +533,20 @@  discard block
 block discarded – undo
533 533
 	 * @param string $current_template Existing default template path derived for this page call.
534 534
 	 * @return string the path to the full template file.
535 535
 	 */
536
-	public function singleCptTemplate( $current_template ) {
536
+	public function singleCptTemplate($current_template) {
537 537
 		$object = get_queried_object();
538 538
 		//does this called object HAVE a page template set that is something other than the default.
539
-		$template = get_post_meta( $object->ID, '_wp_page_template', true );
539
+		$template = get_post_meta($object->ID, '_wp_page_template', true);
540 540
 		//exit early if default or not set or invalid path (accounts for theme changes)
541 541
 		if (
542 542
 			$template === 'default'
543
-			|| empty( $template )
544
-			|| ! is_readable( get_stylesheet_directory() . '/' . $template )
543
+			|| empty($template)
544
+			|| ! is_readable(get_stylesheet_directory().'/'.$template)
545 545
 		) {
546 546
 			return $current_template;
547 547
 		}
548 548
 		//made it here so we SHOULD be able to just locate the template and then return it.
549
-		return locate_template( array( $template ) );
549
+		return locate_template(array($template));
550 550
 	}
551 551
 
552 552
 
Please login to merge, or discard this patch.