Completed
Branch FET-10768-extract-admin-bar (b7d0e4)
by
unknown
118:19 queued 106:50
created
admin/extend/registrations/EE_Event_Registrations_List_Table.class.php 1 patch
Spacing   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -42,51 +42,51 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @param \Registrations_Admin_Page $admin_page
44 44
 	 */
45
-	public function __construct( $admin_page ) {
46
-		parent::__construct( $admin_page );
45
+	public function __construct($admin_page) {
46
+		parent::__construct($admin_page);
47 47
 		$this->_status = $this->_admin_page->get_registration_status_array();
48 48
 	}
49 49
 
50 50
 
51 51
 
52 52
 	protected function _setup_data() {
53
-		$this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees( $this->_per_page )
54
-			: $this->_admin_page->get_event_attendees( $this->_per_page, false, true );
53
+		$this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page)
54
+			: $this->_admin_page->get_event_attendees($this->_per_page, false, true);
55 55
 		$this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees(
56 56
 			$this->_per_page,
57 57
 			true
58
-		) : $this->_admin_page->get_event_attendees( $this->_per_page, true, true );
58
+		) : $this->_admin_page->get_event_attendees($this->_per_page, true, true);
59 59
 	}
60 60
 
61 61
 
62 62
 
63 63
 	protected function _set_properties() {
64
-		$evt_id = isset( $this->_req_data['event_id'] ) ? $this->_req_data['event_id'] : null;
64
+		$evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
65 65
 		$this->_wp_list_args = array(
66
-			'singular' => __( 'registrant', 'event_espresso' ),
67
-			'plural'   => __( 'registrants', 'event_espresso' ),
66
+			'singular' => __('registrant', 'event_espresso'),
67
+			'plural'   => __('registrants', 'event_espresso'),
68 68
 			'ajax'     => true,
69 69
 			'screen'   => $this->_admin_page->get_current_screen()->id,
70 70
 		);
71 71
 		$columns = array();
72 72
 		//$columns['_Reg_Status'] = '';
73
-		if ( ! empty( $evt_id ) ) {
73
+		if ( ! empty($evt_id)) {
74 74
 			$columns['cb'] = '<input type="checkbox" />'; //Render a checkbox instead of text
75 75
 			$this->_has_checkbox_column = true;
76 76
 		}
77 77
 		$this->_columns = array(
78 78
 			'_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>',
79
-			'ATT_name'            => __( 'Registrant', 'event_espresso' ),
80
-			'ATT_email'           => __( 'Email Address', 'event_espresso' ),
81
-			'Event'               => __( 'Event', 'event_espresso' ),
82
-			'PRC_name'            => __( 'TKT Option', 'event_espresso' ),
83
-			'_REG_final_price'    => __( 'Price', 'event_espresso' ),
84
-			'TXN_paid'            => __( 'Paid', 'event_espresso' ),
85
-			'TXN_total'           => __( 'Total', 'event_espresso' ),
79
+			'ATT_name'            => __('Registrant', 'event_espresso'),
80
+			'ATT_email'           => __('Email Address', 'event_espresso'),
81
+			'Event'               => __('Event', 'event_espresso'),
82
+			'PRC_name'            => __('TKT Option', 'event_espresso'),
83
+			'_REG_final_price'    => __('Price', 'event_espresso'),
84
+			'TXN_paid'            => __('Paid', 'event_espresso'),
85
+			'TXN_total'           => __('Total', 'event_espresso'),
86 86
 		);
87
-		$this->_columns = array_merge( $columns, $this->_columns );
87
+		$this->_columns = array_merge($columns, $this->_columns);
88 88
 		$this->_primary_column = '_REG_att_checked_in';
89
-		if ( ! empty( $evt_id )
89
+		if ( ! empty($evt_id)
90 90
 		     && EE_Registry::instance()->CAP->current_user_can(
91 91
 				'ee_read_registrations',
92 92
 				'espresso_registrations_registrations_reports',
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 					'extra_request' =>
100 100
 						array(
101 101
 							'EVT_ID'     => $evt_id,
102
-							'return_url' => urlencode( "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}" ),
102
+							'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
103 103
 						),
104 104
 				),
105 105
 			);
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
                     true,
141 141
                     $this
142 142
                 )
143
-                ? array( 'ATT_lname' => true )
144
-                : array( 'ATT_fname' => true ),
145
-			'Event'    => array( 'Event.EVT.Name' => false ),
143
+                ? array('ATT_lname' => true)
144
+                : array('ATT_fname' => true),
145
+			'Event'    => array('Event.EVT.Name' => false),
146 146
 		);
147 147
 		$this->_hidden_columns = array();
148
-		$this->_evt = EEM_Event::instance()->get_one_by_ID( $evt_id );
148
+		$this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id);
149 149
 		$this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array();
150 150
 	}
151 151
 
@@ -155,11 +155,11 @@  discard block
 block discarded – undo
155 155
 	 * @param \EE_Registration $item
156 156
 	 * @return string
157 157
 	 */
158
-	protected function _get_row_class( $item ) {
159
-		$class = parent::_get_row_class( $item );
158
+	protected function _get_row_class($item) {
159
+		$class = parent::_get_row_class($item);
160 160
 		//add status class
161
-		$class .= ' ee-status-strip reg-status-' . $item->status_ID();
162
-		if ( $this->_has_checkbox_column ) {
161
+		$class .= ' ee-status-strip reg-status-'.$item->status_ID();
162
+		if ($this->_has_checkbox_column) {
163 163
 			$class .= ' has-checkbox-column';
164 164
 		}
165 165
 		return $class;
@@ -173,61 +173,61 @@  discard block
 block discarded – undo
173 173
 	 */
174 174
 	protected function _get_table_filters() {
175 175
 		$filters = $where = array();
176
-		$current_EVT_ID = isset( $this->_req_data['event_id'] ) ? (int) $this->_req_data['event_id'] : 0;
177
-		if ( empty( $this->_dtts_for_event ) || count( $this->_dtts_for_event ) === 1 ) {
176
+		$current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0;
177
+		if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) {
178 178
 			//this means we don't have an event so let's setup a filter dropdown for all the events to select
179 179
 			//note possible capability restrictions
180
-			if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_private_events', 'get_events' ) ) {
181
-				$where['status**'] = array( '!=', 'private' );
180
+			if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
181
+				$where['status**'] = array('!=', 'private');
182 182
 			}
183
-			if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_events', 'get_events' ) ) {
183
+			if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
184 184
 				$where['EVT_wp_user'] = get_current_user_id();
185 185
 			}
186 186
 			$events = EEM_Event::instance()->get_all(
187 187
 				array(
188 188
 					$where,
189
-					'order_by' => array( 'Datetime.DTT_EVT_start' => 'DESC' ),
189
+					'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'),
190 190
 				)
191 191
 			);
192 192
 			$evts[] = array(
193 193
 				'id'   => 0,
194
-				'text' => __( 'To toggle Check-in status, select an event', 'event_espresso' ),
194
+				'text' => __('To toggle Check-in status, select an event', 'event_espresso'),
195 195
 			);
196 196
 			$checked = 'checked';
197 197
 			/** @var EE_Event $evt */
198
-			foreach ( $events as $evt ) {
198
+			foreach ($events as $evt) {
199 199
 				//any registrations for this event?
200
-				if ( ! $evt->get_count_of_all_registrations() ) {
200
+				if ( ! $evt->get_count_of_all_registrations()) {
201 201
 					continue;
202 202
 				}
203 203
                                 $evts[] = array(
204 204
 					'id'    => $evt->ID(),
205
-					'text'  => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get( 'EVT_name' ), $evt),
205
+					'text'  => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get('EVT_name'), $evt),
206 206
 					'class' => $evt->is_expired() ? 'ee-expired-event' : '',
207 207
 				);
208
-				if ( $evt->ID() === $current_EVT_ID && $evt->is_expired() ) {
208
+				if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) {
209 209
 					$checked = '';
210 210
 				}
211 211
 			}
212 212
 			$event_filter = '<div class="ee-event-filter">';
213
-			$event_filter .= EEH_Form_Fields::select_input( 'event_id', $evts, $current_EVT_ID );
213
+			$event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID);
214 214
 			$event_filter .= '<span class="ee-event-filter-toggle">';
215
-			$event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> ';
216
-			$event_filter .= __( 'Hide Expired Events', 'event_espresso' );
215
+			$event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" '.$checked.'> ';
216
+			$event_filter .= __('Hide Expired Events', 'event_espresso');
217 217
 			$event_filter .= '</span>';
218 218
 			$event_filter .= '</div>';
219 219
 			$filters[] = $event_filter;
220 220
 		}
221
-		if ( ! empty( $this->_dtts_for_event ) ) {
221
+		if ( ! empty($this->_dtts_for_event)) {
222 222
 			//DTT datetimes filter
223
-			$this->_cur_dtt_id = isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : 0;
224
-			if ( count( $this->_dtts_for_event ) > 1 ) {
225
-				$dtts[0] = __( 'To toggle check-in status, select a datetime.', 'event_espresso' );
226
-				foreach ( $this->_dtts_for_event as $dtt ) {
223
+			$this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0;
224
+			if (count($this->_dtts_for_event) > 1) {
225
+				$dtts[0] = __('To toggle check-in status, select a datetime.', 'event_espresso');
226
+				foreach ($this->_dtts_for_event as $dtt) {
227 227
                     $datetime_string = $dtt->name();
228
-                    $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : '';
229
-					$datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string;
230
-					$dtts[ $dtt->ID() ] = $datetime_string;
228
+                    $datetime_string = ! empty($datetime_string) ? ' ('.$datetime_string.')' : '';
229
+					$datetime_string = $dtt->start_date_and_time().' - '.$dtt->end_date_and_time().$datetime_string;
230
+					$dtts[$dtt->ID()] = $datetime_string;
231 231
 				}
232 232
 				$input = new EE_Select_Input(
233 233
 					$dtts,
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 					)
239 239
 				);
240 240
 				$filters[] = $input->get_html_for_input();
241
-				$filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">';
241
+				$filters[] = '<input type="hidden" name="event_id" value="'.$current_EVT_ID.'">';
242 242
 			}
243 243
 		}
244 244
 		return $filters;
@@ -257,22 +257,22 @@  discard block
 block discarded – undo
257 257
 	 * @throws \EE_Error
258 258
 	 */
259 259
 	protected function _get_total_event_attendees() {
260
-		$EVT_ID = isset( $this->_req_data['event_id'] ) ? absint( $this->_req_data['event_id'] ) : false;
260
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
261 261
 		$DTT_ID = $this->_cur_dtt_id;
262 262
 		$query_params = array();
263
-		if ( $EVT_ID ) {
263
+		if ($EVT_ID) {
264 264
 			$query_params[0]['EVT_ID'] = $EVT_ID;
265 265
 		}
266 266
 		//if DTT is included we only show for that datetime.  Otherwise we're showing for all datetimes (the event).
267
-		if ( $DTT_ID ) {
267
+		if ($DTT_ID) {
268 268
 			$query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID;
269 269
 		}
270 270
 		$status_ids_array = apply_filters(
271 271
 			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
272
-			array( EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved )
272
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
273 273
 		);
274
-		$query_params[0]['STS_ID'] = array( 'IN', $status_ids_array );
275
-		return EEM_Registration::instance()->count( $query_params );
274
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
275
+		return EEM_Registration::instance()->count($query_params);
276 276
 	}
277 277
 
278 278
 
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
 	 * @param \EE_Registration $item
282 282
 	 * @return string
283 283
 	 */
284
-	public function column__Reg_Status( EE_Registration $item ) {
285
-		return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>';
284
+	public function column__Reg_Status(EE_Registration $item) {
285
+		return '<span class="ee-status-strip ee-status-strip-td reg-status-'.$item->status_ID().'"></span>';
286 286
 	}
287 287
 
288 288
 
@@ -292,8 +292,8 @@  discard block
 block discarded – undo
292 292
 	 * @return string
293 293
 	 * @throws \EE_Error
294 294
 	 */
295
-	public function column_cb( $item ) {
296
-		return sprintf( '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID() );
295
+	public function column_cb($item) {
296
+		return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID());
297 297
 	}
298 298
 
299 299
 
@@ -305,20 +305,20 @@  discard block
 block discarded – undo
305 305
 	 * @return string
306 306
 	 * @throws \EE_Error
307 307
 	 */
308
-	public function column__REG_att_checked_in( EE_Registration $item ) {
308
+	public function column__REG_att_checked_in(EE_Registration $item) {
309 309
 		$attendee = $item->attendee();
310 310
 		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
311 311
 
312
-		if ( $this->_cur_dtt_id === 0 && count( $this->_dtts_for_event ) === 1 ) {
312
+		if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) {
313 313
 			$latest_related_datetime = $item->get_latest_related_datetime();
314
-			if ( $latest_related_datetime instanceof EE_Datetime ) {
314
+			if ($latest_related_datetime instanceof EE_Datetime) {
315 315
 				$this->_cur_dtt_id = $latest_related_datetime->ID();
316 316
 			}
317 317
 		}
318 318
 
319
-		$checkinstatus = $item->check_in_status_for_datetime( $this->_cur_dtt_id );
320
-		$nonce = wp_create_nonce( 'checkin_nonce' );
321
-		$toggle_active = ! empty ( $this->_cur_dtt_id )
319
+		$checkinstatus = $item->check_in_status_for_datetime($this->_cur_dtt_id);
320
+		$nonce = wp_create_nonce('checkin_nonce');
321
+		$toggle_active = ! empty ($this->_cur_dtt_id)
322 322
 		                 && EE_Registry::instance()->CAP->current_user_can(
323 323
 			'ee_edit_checkin',
324 324
 			'espresso_registrations_toggle_checkin_status',
@@ -326,11 +326,11 @@  discard block
 block discarded – undo
326 326
 		)
327 327
 			? ' clickable trigger-checkin'
328 328
 			: '';
329
-		$mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
330
-		return '<span class="checkin-icons checkedin-status-' . $checkinstatus . $toggle_active . '"'
331
-		       . ' data-_regid="' . $item->ID() . '"'
332
-		       . ' data-dttid="' . $this->_cur_dtt_id . '"'
333
-		       . ' data-nonce="' . $nonce . '">'
329
+		$mobile_view_content = ' <span class="show-on-mobile-view-only">'.$attendee_name.'</span>';
330
+		return '<span class="checkin-icons checkedin-status-'.$checkinstatus.$toggle_active.'"'
331
+		       . ' data-_regid="'.$item->ID().'"'
332
+		       . ' data-dttid="'.$this->_cur_dtt_id.'"'
333
+		       . ' data-nonce="'.$nonce.'">'
334 334
 		       . '</span>'
335 335
 		       . $mobile_view_content;
336 336
 	}
@@ -342,21 +342,21 @@  discard block
 block discarded – undo
342 342
 	 * @return mixed|string|void
343 343
 	 * @throws \EE_Error
344 344
 	 */
345
-	public function column_ATT_name( EE_Registration $item ) {
345
+	public function column_ATT_name(EE_Registration $item) {
346 346
 		$attendee = $item->attendee();
347
-		if ( ! $attendee instanceof EE_Attendee ) {
348
-			return __( 'No contact record for this registration.', 'event_espresso' );
347
+		if ( ! $attendee instanceof EE_Attendee) {
348
+			return __('No contact record for this registration.', 'event_espresso');
349 349
 		}
350 350
 		// edit attendee link
351 351
 		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
352
-			array( 'action' => 'view_registration', '_REG_ID' => $item->ID() ),
352
+			array('action' => 'view_registration', '_REG_ID' => $item->ID()),
353 353
 			REG_ADMIN_URL
354 354
 		);
355 355
 		$name_link = EE_Registry::instance()->CAP->current_user_can(
356 356
 			'ee_edit_contacts',
357 357
 			'espresso_registrations_edit_attendee'
358 358
 		)
359
-			? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">'
359
+			? '<a href="'.$edit_lnk_url.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">'
360 360
 			    . $item->attendee()->full_name()
361 361
 			    . '</a>'
362 362
 			: $item->attendee()->full_name();
@@ -364,10 +364,10 @@  discard block
 block discarded – undo
364 364
 			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>	'
365 365
 			: '';
366 366
 		//add group details
367
-		$name_link .= '&nbsp;' . sprintf( __( '(%s of %s)', 'event_espresso' ), $item->count(), $item->group_size() );
367
+		$name_link .= '&nbsp;'.sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size());
368 368
 		//add regcode
369 369
 		$link = EE_Admin_Page::add_query_args_and_nonce(
370
-			array( 'action' => 'view_registration', '_REG_ID' => $item->ID() ),
370
+			array('action' => 'view_registration', '_REG_ID' => $item->ID()),
371 371
 			REG_ADMIN_URL
372 372
 		);
373 373
 		$name_link .= '<br>';
@@ -376,50 +376,50 @@  discard block
 block discarded – undo
376 376
 			'view_registration',
377 377
 			$item->ID()
378 378
 		)
379
-			? '<a href="' . $link . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">'
379
+			? '<a href="'.$link.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">'
380 380
 			  . $item->reg_code()
381 381
 			  . '</a>'
382 382
 			: $item->reg_code();
383 383
 		//status
384 384
 		$name_link .= '<br><span class="ee-status-text-small">';
385
-		$name_link .= EEH_Template::pretty_status( $item->status_ID(), false, 'sentence' );
385
+		$name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence');
386 386
 		$name_link .= '</span>';
387 387
 		$actions = array();
388 388
 		$DTT_ID = $this->_cur_dtt_id;
389
-		$latest_related_datetime = empty( $DTT_ID ) && ! empty( $this->_req_data['event_id'] ) && $item instanceof EE_Registration
389
+		$latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration
390 390
 			? $item->get_latest_related_datetime()
391 391
 			: null;
392 392
 		$DTT_ID = $latest_related_datetime instanceof EE_Datetime
393 393
 			? $latest_related_datetime->ID()
394 394
 			: $DTT_ID;
395
-		if ( ! empty( $DTT_ID )
395
+		if ( ! empty($DTT_ID)
396 396
 		     && EE_Registry::instance()->CAP->current_user_can(
397 397
 				'ee_read_checkins',
398 398
 				'espresso_registrations_registration_checkins'
399 399
 			)
400 400
 		) {
401 401
 			$checkin_list_url = EE_Admin_Page::add_query_args_and_nonce(
402
-				array( 'action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID )
402
+				array('action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID)
403 403
 			);
404 404
 			// get the timestamps for this registration's checkins, related to the selected datetime
405
-			$timestamps = $item->get_many_related( 'Checkin', array( array( 'DTT_ID' => $DTT_ID ) ) );
406
-			if( ! empty( $timestamps ) ) {
405
+			$timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID)));
406
+			if ( ! empty($timestamps)) {
407 407
 				// get the last timestamp
408
-				$last_timestamp = end( $timestamps );
408
+				$last_timestamp = end($timestamps);
409 409
 				// checked in or checked out?
410
-				$checkin_status = $last_timestamp->get( 'CHK_in' ) 
411
-					? esc_html__( 'Checked In', 'event_espresso' )
412
-					: esc_html__( 'Checked Out', 'event_espresso' );
410
+				$checkin_status = $last_timestamp->get('CHK_in') 
411
+					? esc_html__('Checked In', 'event_espresso')
412
+					: esc_html__('Checked Out', 'event_espresso');
413 413
 				// get timestamp string
414
-				$timestamp_string = $last_timestamp->get_datetime( 'CHK_timestamp' );
415
-				$actions['checkin'] = '<a href="' . $checkin_list_url . '" title="' . esc_attr__(
414
+				$timestamp_string = $last_timestamp->get_datetime('CHK_timestamp');
415
+				$actions['checkin'] = '<a href="'.$checkin_list_url.'" title="'.esc_attr__(
416 416
 						'View this registrant\'s check-ins/checkouts for the datetime',
417 417
 						'event_espresso'
418
-					) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>';
418
+					).'">'.$checkin_status.': '.$timestamp_string.'</a>';
419 419
 			}
420 420
 		} 
421
-		return ( ! empty( $DTT_ID ) && ! empty( $timestamps ) ) 
422
-			? sprintf( '%1$s %2$s', $name_link, $this->row_actions( $actions, true ) ) 
421
+		return ( ! empty($DTT_ID) && ! empty($timestamps)) 
422
+			? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true)) 
423 423
 			: $name_link;
424 424
 	}
425 425
 
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 	 * @param \EE_Registration $item
430 430
 	 * @return string
431 431
 	 */
432
-	public function column_ATT_email( EE_Registration $item ) {
432
+	public function column_ATT_email(EE_Registration $item) {
433 433
 		$attendee = $item->attendee();
434 434
 		return $attendee instanceof EE_Attendee ? $attendee->email() : '';
435 435
 	}
@@ -441,22 +441,22 @@  discard block
 block discarded – undo
441 441
 	 * @return bool|string
442 442
 	 * @throws \EE_Error
443 443
 	 */
444
-	public function column_Event( EE_Registration $item ) {
444
+	public function column_Event(EE_Registration $item) {
445 445
 		try {
446 446
 			$event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event();
447 447
 			$chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
448
-				array( 'action' => 'event_registrations', 'event_id' => $event->ID() ),
448
+				array('action' => 'event_registrations', 'event_id' => $event->ID()),
449 449
 				REG_ADMIN_URL
450 450
 			);
451 451
 			$event_label = EE_Registry::instance()->CAP->current_user_can(
452 452
 				'ee_read_checkins',
453 453
 				'espresso_registrations_registration_checkins'
454
-			) ? '<a href="' . $chkin_lnk_url . '" title="' . esc_attr__(
454
+			) ? '<a href="'.$chkin_lnk_url.'" title="'.esc_attr__(
455 455
 					'View Checkins for this Event',
456 456
 					'event_espresso'
457
-				) . '">' . $event->name() . '</a>' : $event->name();
458
-		} catch ( \EventEspresso\core\exceptions\EntityNotFoundException $e ) {
459
-			$event_label = esc_html__( 'Unknown', 'event_espresso' );
457
+				).'">'.$event->name().'</a>' : $event->name();
458
+		} catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) {
459
+			$event_label = esc_html__('Unknown', 'event_espresso');
460 460
 		}
461 461
 		return $event_label;
462 462
 	}
@@ -467,8 +467,8 @@  discard block
 block discarded – undo
467 467
 	 * @param \EE_Registration $item
468 468
 	 * @return mixed|string|void
469 469
 	 */
470
-	public function column_PRC_name( EE_Registration $item ) {
471
-		return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __( "Unknown", "event_espresso" );
470
+	public function column_PRC_name(EE_Registration $item) {
471
+		return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __("Unknown", "event_espresso");
472 472
 	}
473 473
 
474 474
 
@@ -479,8 +479,8 @@  discard block
 block discarded – undo
479 479
 	 * @param \EE_Registration $item
480 480
 	 * @return string
481 481
 	 */
482
-	public function column__REG_final_price( EE_Registration $item ) {
483
-		return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>';
482
+	public function column__REG_final_price(EE_Registration $item) {
483
+		return '<span class="reg-pad-rght">'.' '.$item->pretty_final_price().'</span>';
484 484
 	}
485 485
 
486 486
 
@@ -492,13 +492,13 @@  discard block
 block discarded – undo
492 492
 	 * @return string
493 493
 	 * @throws \EE_Error
494 494
 	 */
495
-	public function column_TXN_paid( EE_Registration $item ) {
496
-		if ( $item->count() === 1 ) {
497
-			if ( $item->transaction()->paid() >= $item->transaction()->total() ) {
495
+	public function column_TXN_paid(EE_Registration $item) {
496
+		if ($item->count() === 1) {
497
+			if ($item->transaction()->paid() >= $item->transaction()->total()) {
498 498
 				return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
499 499
 			} else {
500 500
 				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
501
-					array( 'action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID() ),
501
+					array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()),
502 502
 					TXN_ADMIN_URL
503 503
 				);
504 504
 				return EE_Registry::instance()->CAP->current_user_can(
@@ -511,13 +511,13 @@  discard block
 block discarded – undo
511 511
 				    . '" href="'
512 512
 				    . $view_txn_lnk_url
513 513
 				    . '"  title="'
514
-				    . esc_attr__( 'View Transaction', 'event_espresso' )
514
+				    . esc_attr__('View Transaction', 'event_espresso')
515 515
 				    . '">
516 516
 						'
517 517
 				    . $item->transaction()->pretty_paid()
518 518
 				    . '
519 519
 					</a>
520
-				<span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
520
+				<span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>';
521 521
 			}
522 522
 		} else {
523 523
 			return '<span class="reg-pad-rght"></span>';
@@ -533,13 +533,13 @@  discard block
 block discarded – undo
533 533
 	 * @return string
534 534
 	 * @throws \EE_Error
535 535
 	 */
536
-	public function column_TXN_total( EE_Registration $item ) {
536
+	public function column_TXN_total(EE_Registration $item) {
537 537
 		$txn = $item->transaction();
538
-		$view_txn_url = add_query_arg( array( 'action' => 'view_transaction', 'TXN_ID' => $txn->ID() ), TXN_ADMIN_URL );
539
-		if ( $item->get( 'REG_count' ) === 1 ) {
538
+		$view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL);
539
+		if ($item->get('REG_count') === 1) {
540 540
 			$line_total_obj = $txn->total_line_item();
541 541
 			$txn_total = $line_total_obj instanceof EE_Line_Item
542
-				? $line_total_obj->get_pretty( 'LIN_total' )
542
+				? $line_total_obj->get_pretty('LIN_total')
543 543
 				: __(
544 544
 					'View Transaction',
545 545
 					'event_espresso'
@@ -550,10 +550,10 @@  discard block
 block discarded – undo
550 550
 			) ? '<a href="'
551 551
 			    . $view_txn_url
552 552
 			    . '" title="'
553
-			    . esc_attr__( 'View Transaction', 'event_espresso' )
553
+			    . esc_attr__('View Transaction', 'event_espresso')
554 554
 			    . '"><span class="reg-pad-rght">'
555 555
 			    . $txn_total
556
-			    . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
556
+			    . '</span></a>' : '<span class="reg-pad-rght">'.$txn_total.'</span>';
557 557
 		} else {
558 558
 			return '<span class="reg-pad-rght"></span>';
559 559
 		}
Please login to merge, or discard this patch.
modules/venues_archive/EED_Venues_Archive.module.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -39,14 +39,14 @@
 block discarded – undo
39 39
 	 *  @return 	void
40 40
 	 */
41 41
 	public static function set_hooks() {
42
-        $post_type = get_post_type_object('espresso_venues');
43
-        $custom_post_types = EE_Register_CPTs::get_CPTs();
44
-        EE_Config::register_route(
45
-            $custom_post_types['espresso_venues']['plural_slug'],
46
-            'Venues_Archive',
47
-            'run'
48
-        );
49
-    }
42
+		$post_type = get_post_type_object('espresso_venues');
43
+		$custom_post_types = EE_Register_CPTs::get_CPTs();
44
+		EE_Config::register_route(
45
+			$custom_post_types['espresso_venues']['plural_slug'],
46
+			'Venues_Archive',
47
+			'run'
48
+		);
49
+	}
50 50
 
51 51
 	/**
52 52
 	 * 	set_hooks_admin - for hooking into EE Admin Core, other modules, etc
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	 * @return EED_Venues_Archive
28 28
 	 */
29 29
 	public static function instance() {
30
-		return parent::get_instance( __CLASS__ );
30
+		return parent::get_instance(__CLASS__);
31 31
 	}
32 32
 
33 33
 
@@ -65,10 +65,10 @@  discard block
 block discarded – undo
65 65
 	 * @access    public
66 66
 	 * @param \WP $WP
67 67
 	 */
68
-	public function run( $WP ) {
68
+	public function run($WP) {
69 69
 		// check what template is loaded
70
-		add_filter( 'template_include',  array( $this, 'template_include' ), 999, 1 );
71
-		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 );
70
+		add_filter('template_include', array($this, 'template_include'), 999, 1);
71
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
72 72
 	}
73 73
 
74 74
 
@@ -80,18 +80,18 @@  discard block
 block discarded – undo
80 80
 	 * @param  string $template
81 81
 	 * @return string
82 82
 	 */
83
-	public function template_include( $template ) {
83
+	public function template_include($template) {
84 84
 		// not a custom template?
85
-		if ( EE_Registry::instance()->load_core( 'Front_Controller', array(), false, true )->get_selected_template() != 'archive-espresso_venues.php' ) {
85
+		if (EE_Registry::instance()->load_core('Front_Controller', array(), false, true)->get_selected_template() != 'archive-espresso_venues.php') {
86 86
 			EEH_Template::load_espresso_theme_functions();
87 87
 			// then add extra event data via hooks
88
-			add_filter( 'the_title', array( $this, 'the_title' ), 100, 1 );
88
+			add_filter('the_title', array($this, 'the_title'), 100, 1);
89 89
 			// don't know if theme uses the_excerpt
90
-			add_filter( 'the_excerpt', array( $this, 'venue_details' ), 100 );
90
+			add_filter('the_excerpt', array($this, 'venue_details'), 100);
91 91
 			// or the_content
92
-			add_filter( 'the_content', array( $this, 'venue_details' ), 100 );
92
+			add_filter('the_content', array($this, 'venue_details'), 100);
93 93
 			// don't display entry meta because the existing theme will take care of that
94
-			add_filter( 'FHEE__content_espresso_venues_details_template__display_entry_meta', '__return_false' );
94
+			add_filter('FHEE__content_espresso_venues_details_template__display_entry_meta', '__return_false');
95 95
 		}
96 96
 		return $template;
97 97
 	}
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 * @param  string $title
106 106
 	 * @return string
107 107
 	 */
108
-	public function the_title( $title = '' ) {
108
+	public function the_title($title = '') {
109 109
 		return $title;
110 110
 	}
111 111
 
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	 * @param  string $content
118 118
 	 * @return string
119 119
 	 */
120
-	public function venue_details( $content ) {
120
+	public function venue_details($content) {
121 121
 		global $post;
122 122
 		if (
123 123
 			$post->post_type == 'espresso_venues'
@@ -127,22 +127,22 @@  discard block
 block discarded – undo
127 127
 			// it uses the_content() for displaying the $post->post_content
128 128
 			// so in order to load a template that uses the_content() from within a callback being used to filter the_content(),
129 129
 			// we need to first remove this callback from being applied to the_content() (otherwise it will recurse and blow up the interweb)
130
-			remove_filter( 'the_excerpt', array( $this, 'venue_details' ), 100 );
131
-			remove_filter( 'the_content', array( $this, 'venue_details' ), 100 );
130
+			remove_filter('the_excerpt', array($this, 'venue_details'), 100);
131
+			remove_filter('the_content', array($this, 'venue_details'), 100);
132 132
 			// add filters we want
133
-			add_filter( 'the_content', array( $this, 'venue_location' ), 110 );
134
-			add_filter( 'the_excerpt', array( $this, 'venue_location' ), 110 );
133
+			add_filter('the_content', array($this, 'venue_location'), 110);
134
+			add_filter('the_excerpt', array($this, 'venue_location'), 110);
135 135
 			// now load our template
136
-			$template = EEH_Template::locate_template( 'content-espresso_venues-details.php' );
136
+			$template = EEH_Template::locate_template('content-espresso_venues-details.php');
137 137
 			//now add our filter back in, plus some others
138
-			add_filter( 'the_excerpt', array( $this, 'venue_details' ), 100 );
139
-			add_filter( 'the_content', array( $this, 'venue_details' ), 100 );
138
+			add_filter('the_excerpt', array($this, 'venue_details'), 100);
139
+			add_filter('the_content', array($this, 'venue_details'), 100);
140 140
 			// remove other filters we added so they won't get applied to the next post
141
-			remove_filter( 'the_content', array( $this, 'venue_location' ), 110 );
142
-			remove_filter( 'the_excerpt', array( $this, 'venue_location' ), 110 );
141
+			remove_filter('the_content', array($this, 'venue_location'), 110);
142
+			remove_filter('the_excerpt', array($this, 'venue_location'), 110);
143 143
 			// we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
144 144
 		}
145
-		return ! empty( $template ) ? $template : $content;
145
+		return ! empty($template) ? $template : $content;
146 146
 	}
147 147
 
148 148
 
@@ -154,8 +154,8 @@  discard block
 block discarded – undo
154 154
 	 * @param  string $content
155 155
 	 * @return string
156 156
 	 */
157
-	public function venue_location( $content ) {
158
-		return $content . EEH_Template::locate_template( 'content-espresso_venues-location.php' );
157
+	public function venue_location($content) {
158
+		return $content.EEH_Template::locate_template('content-espresso_venues-location.php');
159 159
 	}
160 160
 
161 161
 
@@ -169,14 +169,14 @@  discard block
 block discarded – undo
169 169
 	 */
170 170
 	public function wp_enqueue_scripts() {
171 171
 		// get some style
172
-		if ( apply_filters( 'FHEE_enable_default_espresso_css', TRUE ) && is_archive() ) {
172
+		if (apply_filters('FHEE_enable_default_espresso_css', TRUE) && is_archive()) {
173 173
 			// first check theme folder
174
-			if ( is_readable( get_stylesheet_directory() . $this->theme . DS . 'style.css' )) {
175
-				wp_register_style( $this->theme, get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', array( 'dashicons', 'espresso_default' ) );
176
-			} else if ( is_readable( EE_TEMPLATES . $this->theme . DS . 'style.css' )) {
177
-				wp_register_style( $this->theme, EE_TEMPLATES_URL . $this->theme . DS . 'style.css', array( 'dashicons', 'espresso_default' ) );
174
+			if (is_readable(get_stylesheet_directory().$this->theme.DS.'style.css')) {
175
+				wp_register_style($this->theme, get_stylesheet_directory_uri().$this->theme.DS.'style.css', array('dashicons', 'espresso_default'));
176
+			} else if (is_readable(EE_TEMPLATES.$this->theme.DS.'style.css')) {
177
+				wp_register_style($this->theme, EE_TEMPLATES_URL.$this->theme.DS.'style.css', array('dashicons', 'espresso_default'));
178 178
 			}
179
-			wp_enqueue_style( $this->theme );
179
+			wp_enqueue_style($this->theme);
180 180
 		}
181 181
 	}
182 182
 
Please login to merge, or discard this patch.
modules/venue_single/EED_Venue_Single.module.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -32,20 +32,20 @@
 block discarded – undo
32 32
 
33 33
 
34 34
 
35
-    /**
35
+	/**
36 36
 	 * 	set_hooks - for hooking into EE Core, other modules, etc
37 37
 	 *
38 38
 	 *  @access 	public
39 39
 	 *  @return 	void
40 40
 	 */
41 41
 	public static function set_hooks() {
42
-        $custom_post_types = EE_Register_CPTs::get_CPTs();
43
-        EE_Config::register_route(
44
-            $custom_post_types['espresso_venues']['singular_slug'],
45
-            'Venue_Single',
46
-            'run'
47
-        );
48
-    }
42
+		$custom_post_types = EE_Register_CPTs::get_CPTs();
43
+		EE_Config::register_route(
44
+			$custom_post_types['espresso_venues']['singular_slug'],
45
+			'Venue_Single',
46
+			'run'
47
+		);
48
+	}
49 49
 
50 50
 	/**
51 51
 	 * 	set_hooks_admin - for hooking into EE Admin Core, other modules, etc
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	 * @return EED_Venue_Single
28 28
 	 */
29 29
 	public static function instance() {
30
-		return parent::get_instance( __CLASS__ );
30
+		return parent::get_instance(__CLASS__);
31 31
 	}
32 32
 
33 33
 
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
 	 * @access    public
65 65
 	 * @param \WP $WP
66 66
 	 */
67
-	public function run( $WP ) {
67
+	public function run($WP) {
68 68
 		// check what template is loaded
69
-		add_filter( 'template_include',  array( $this, 'template_include' ), 999, 1 );
70
-		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 );
69
+		add_filter('template_include', array($this, 'template_include'), 999, 1);
70
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
71 71
 	}
72 72
 
73 73
 
@@ -79,15 +79,15 @@  discard block
 block discarded – undo
79 79
 	 * @param  string $template
80 80
 	 * @return string
81 81
 	 */
82
-	public function template_include( $template ) {
82
+	public function template_include($template) {
83 83
 		// not a custom template?
84
-		if ( EE_Registry::instance()->load_core( 'Front_Controller', array(), false, true )->get_selected_template() != 'single-espresso_venues.php' ) {
84
+		if (EE_Registry::instance()->load_core('Front_Controller', array(), false, true)->get_selected_template() != 'single-espresso_venues.php') {
85 85
 			EEH_Template::load_espresso_theme_functions();
86 86
 			// then add extra event data via hooks
87
-			add_filter( 'the_title', array( $this, 'the_title' ), 100, 1 );
88
-			add_filter( 'the_content', array( $this, 'venue_details' ), 100 );
87
+			add_filter('the_title', array($this, 'the_title'), 100, 1);
88
+			add_filter('the_content', array($this, 'venue_details'), 100);
89 89
 			// don't display entry meta because the existing theme will take car of that
90
-			add_filter( 'FHEE__content_espresso_venues_details_template__display_entry_meta', '__return_false' );
90
+			add_filter('FHEE__content_espresso_venues_details_template__display_entry_meta', '__return_false');
91 91
 		}
92 92
 		return $template;
93 93
 	}
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 	 * @param  string $title
102 102
 	 * @return string
103 103
 	 */
104
-	public function the_title( $title = '' ) {
104
+	public function the_title($title = '') {
105 105
 		return $title;
106 106
 	}
107 107
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 	 * @param  string $content
114 114
 	 * @return string
115 115
 	 */
116
-	public function venue_details( $content ) {
116
+	public function venue_details($content) {
117 117
 		global $post;
118 118
 		if (
119 119
 			$post->post_type == 'espresso_venues'
@@ -123,16 +123,16 @@  discard block
 block discarded – undo
123 123
 			// it uses the_content() for displaying the $post->post_content
124 124
 			// so in order to load a template that uses the_content() from within a callback being used to filter the_content(),
125 125
 			// we need to first remove this callback from being applied to the_content() (otherwise it will recurse and blow up the interweb)
126
-			remove_filter( 'the_content', array( $this, 'venue_details' ), 100 );
126
+			remove_filter('the_content', array($this, 'venue_details'), 100);
127 127
 			// add filters we want
128
-			add_filter( 'the_content', array( $this, 'venue_location' ), 110 );
128
+			add_filter('the_content', array($this, 'venue_location'), 110);
129 129
 			// now load our template
130
-			$template = EEH_Template::locate_template( 'content-espresso_venues-details.php' );
130
+			$template = EEH_Template::locate_template('content-espresso_venues-details.php');
131 131
 			// remove other filters we added so they won't get applied to the next post
132
-			remove_filter( 'the_content', array( $this, 'venue_location' ), 110 );
132
+			remove_filter('the_content', array($this, 'venue_location'), 110);
133 133
 		}
134 134
 		// we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
135
-		return ! empty( $template ) ? $template : $content;
135
+		return ! empty($template) ? $template : $content;
136 136
 	}
137 137
 
138 138
 
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
 	 * @param  string $content
145 145
 	 * @return string
146 146
 	 */
147
-	public function venue_location( $content ) {
148
-		return $content . EEH_Template::locate_template( 'content-espresso_venues-location.php' );
147
+	public function venue_location($content) {
148
+		return $content.EEH_Template::locate_template('content-espresso_venues-location.php');
149 149
 	}
150 150
 
151 151
 
@@ -158,16 +158,16 @@  discard block
 block discarded – undo
158 158
 	 */
159 159
 	public function wp_enqueue_scripts() {
160 160
 		// get some style
161
-		if ( apply_filters( 'FHEE_enable_default_espresso_css', TRUE ) && is_single() ) {
161
+		if (apply_filters('FHEE_enable_default_espresso_css', TRUE) && is_single()) {
162 162
 			// first check theme folder
163
-			if ( is_readable( get_stylesheet_directory() . $this->theme . DS . 'style.css' )) {
164
-				wp_register_style( $this->theme, get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', array( 'dashicons', 'espresso_default' ) );
165
-			} else if ( is_readable( EE_TEMPLATES . $this->theme . DS . 'style.css' )) {
166
-				wp_register_style( $this->theme, EE_TEMPLATES_URL . $this->theme . DS . 'style.css', array( 'dashicons', 'espresso_default' ) );
163
+			if (is_readable(get_stylesheet_directory().$this->theme.DS.'style.css')) {
164
+				wp_register_style($this->theme, get_stylesheet_directory_uri().$this->theme.DS.'style.css', array('dashicons', 'espresso_default'));
165
+			} else if (is_readable(EE_TEMPLATES.$this->theme.DS.'style.css')) {
166
+				wp_register_style($this->theme, EE_TEMPLATES_URL.$this->theme.DS.'style.css', array('dashicons', 'espresso_default'));
167 167
 			}
168
-			wp_enqueue_style( $this->theme );
169
-			if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) {
170
-				add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 );
168
+			wp_enqueue_style($this->theme);
169
+			if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
170
+				add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
171 171
 			}
172 172
 		}
173 173
 	}
Please login to merge, or discard this patch.
modules/event_single/EED_Event_Single.module.php 1 patch
Indentation   +462 added lines, -462 removed lines patch added patch discarded remove patch
@@ -13,467 +13,467 @@  discard block
 block discarded – undo
13 13
 class EED_Event_Single extends EED_Module
14 14
 {
15 15
 
16
-    const EVENT_DETAILS_PRIORITY = 100;
17
-    const EVENT_DATETIMES_PRIORITY = 110;
18
-    const EVENT_TICKETS_PRIORITY = 120;
19
-    const EVENT_VENUES_PRIORITY = 130;
20
-
21
-    /**
22
-     * @type bool $using_get_the_excerpt
23
-     */
24
-    protected static $using_get_the_excerpt = false;
25
-
26
-
27
-    /**
28
-     * @type EE_Template_Part_Manager $template_parts
29
-     */
30
-    protected $template_parts;
31
-
32
-
33
-    /**
34
-     * @return EED_Module|EED_Event_Single
35
-     */
36
-    public static function instance()
37
-    {
38
-        return parent::get_instance(__CLASS__);
39
-    }
40
-
41
-
42
-    /**
43
-     * set_hooks - for hooking into EE Core, other modules, etc
44
-     *
45
-     * @return    void
46
-     */
47
-    public static function set_hooks()
48
-    {
49
-        add_filter('FHEE_run_EE_wp', '__return_true');
50
-        add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
51
-        $custom_post_types = EE_Register_CPTs::get_CPTs();
52
-        EE_Config::register_route(
53
-            $custom_post_types['espresso_events']['singular_slug'],
54
-            'Event_Single',
55
-            'run'
56
-        );
57
-    }
58
-
59
-    /**
60
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
61
-     *
62
-     * @return    void
63
-     */
64
-    public static function set_hooks_admin()
65
-    {
66
-        add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
67
-    }
68
-
69
-
70
-    /**
71
-     * set_definitions
72
-     *
73
-     * @static
74
-     * @return void
75
-     */
76
-    public static function set_definitions()
77
-    {
78
-        define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
79
-        define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates' . DS);
80
-    }
81
-
82
-
83
-    /**
84
-     * set_config
85
-     *
86
-     * @void
87
-     */
88
-    protected function set_config()
89
-    {
90
-        $this->set_config_section('template_settings');
91
-        $this->set_config_class('EE_Event_Single_Config');
92
-        $this->set_config_name('EED_Event_Single');
93
-    }
94
-
95
-
96
-    /**
97
-     * initialize_template_parts
98
-     *
99
-     * @param EE_Config_Base|EE_Event_Single_Config $config
100
-     * @return EE_Template_Part_Manager
101
-     */
102
-    public function initialize_template_parts(EE_Event_Single_Config $config = null)
103
-    {
104
-        /** @type EE_Event_Single_Config $config */
105
-        $config = $config instanceof EE_Event_Single_Config ? $config : $this->config();
106
-        EEH_Autoloader::instance()->register_template_part_autoloaders();
107
-        $template_parts = new EE_Template_Part_Manager();
108
-        $template_parts->add_template_part(
109
-            'tickets',
110
-            __('Ticket Selector', 'event_espresso'),
111
-            'content-espresso_events-tickets.php',
112
-            $config->display_order_tickets
113
-        );
114
-        $template_parts->add_template_part(
115
-            'datetimes',
116
-            __('Dates and Times', 'event_espresso'),
117
-            'content-espresso_events-datetimes.php',
118
-            $config->display_order_datetimes
119
-        );
120
-        $template_parts->add_template_part(
121
-            'event',
122
-            __('Event Description', 'event_espresso'),
123
-            'content-espresso_events-details.php',
124
-            $config->display_order_event
125
-        );
126
-        $template_parts->add_template_part(
127
-            'venue',
128
-            __('Venue Information', 'event_espresso'),
129
-            'content-espresso_events-venues.php',
130
-            $config->display_order_venue
131
-        );
132
-        do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts);
133
-        return $template_parts;
134
-    }
135
-
136
-
137
-    /**
138
-     * run - initial module setup
139
-     *
140
-     * @param WP $WP
141
-     * @return    void
142
-     */
143
-    public function run($WP)
144
-    {
145
-        // ensure valid EE_Events_Single_Config() object exists
146
-        $this->set_config();
147
-        // check what template is loaded
148
-        add_filter('template_include', array($this, 'template_include'), 999, 1);
149
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
150
-        // load css
151
-        add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
152
-    }
153
-
154
-
155
-    /**
156
-     * template_include
157
-     *
158
-     * @param    string $template
159
-     * @return    string
160
-     */
161
-    public function template_include($template)
162
-    {
163
-        global $post;
164
-        /** @type EE_Event_Single_Config $config */
165
-        $config = $this->config();
166
-        if ($config->display_status_banner_single) {
167
-            add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2);
168
-        }
169
-        // not a custom template?
170
-        if (
171
-            !post_password_required($post)
172
-            && (
173
-                apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false)
174
-                || EE_Registry::instance()
175
-                    ->load_core('Front_Controller')
176
-                    ->get_selected_template() !== 'single-espresso_events.php'
177
-            )
178
-
179
-        ) {
180
-            EEH_Template::load_espresso_theme_functions();
181
-            // then add extra event data via hooks
182
-            add_action('loop_start', array('EED_Event_Single', 'loop_start'));
183
-            add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1);
184
-            add_filter(
185
-                'the_content',
186
-                array('EED_Event_Single', 'event_details'),
187
-                EED_Event_Single::EVENT_DETAILS_PRIORITY
188
-            );
189
-            add_action('loop_end', array('EED_Event_Single', 'loop_end'));
190
-            // don't display entry meta because the existing theme will take car of that
191
-            add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
192
-        }
193
-        return $template;
194
-    }
195
-
196
-
197
-    /**
198
-     * loop_start
199
-     *
200
-     * @param    array $wp_query_array an array containing the WP_Query object
201
-     * @return    void
202
-     */
203
-    public static function loop_start($wp_query_array)
204
-    {
205
-        global $post;
206
-        do_action('AHEE_event_details_before_post', $post, $wp_query_array);
207
-    }
208
-
209
-
210
-    /**
211
-     * the_title
212
-     *
213
-     * @param    string $title
214
-     * @param    int $id
215
-     * @return    string
216
-     */
217
-    public static function the_title($title = '', $id = 0)
218
-    {
219
-        global $post;
220
-        return in_the_loop() && $post->ID === (int)$id
221
-            ? espresso_event_status_banner($post->ID) . $title
222
-            : $title;
223
-    }
224
-
225
-
226
-    /**
227
-     * get_the_excerpt
228
-     * kinda hacky, but if a theme is using get_the_excerpt(),
229
-     * then we need to remove our filters on the_content()
230
-     *
231
-     * @param        string $excerpt
232
-     * @return        string
233
-     */
234
-    public static function get_the_excerpt($excerpt = '')
235
-    {
236
-        EED_Event_Single::$using_get_the_excerpt = true;
237
-        add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1);
238
-        return $excerpt;
239
-    }
240
-
241
-
242
-    /**
243
-     * end_get_the_excerpt
244
-     *
245
-     * @param  string $text
246
-     * @return string
247
-     */
248
-    public static function end_get_the_excerpt($text = '')
249
-    {
250
-        EED_Event_Single::$using_get_the_excerpt = false;
251
-        return $text;
252
-    }
253
-
254
-
255
-    /**
256
-     * event_details
257
-     *
258
-     * @param    string $content
259
-     * @return    string
260
-     */
261
-    public static function event_details($content)
262
-    {
263
-        global $post;
264
-        static $current_post_ID = 0;
265
-        if (
266
-            $current_post_ID !== $post->ID
267
-            && $post->post_type === 'espresso_events'
268
-            && !EED_Event_Single::$using_get_the_excerpt
269
-            && !post_password_required()
270
-        ) {
271
-            // Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
272
-            // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
273
-            // BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
274
-            // We want to allow those plugins to still do their thing and have access to our content, but depending on
275
-            // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
276
-            // so the following allows this filter to be applied multiple times, but only once for real
277
-            $current_post_ID = did_action('loop_start') ? $post->ID : 0;
278
-            if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) {
279
-                // we need to first remove this callback from being applied to the_content()
280
-                // (otherwise it will recurse and blow up the interweb)
281
-                remove_filter(
282
-                    'the_content',
283
-                    array('EED_Event_Single', 'event_details'),
284
-                    EED_Event_Single::EVENT_DETAILS_PRIORITY
285
-                );
286
-                EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts();
287
-                $content = EEH_Template::locate_template('content-espresso_events-details.php');
288
-                $content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content);
289
-                add_filter(
290
-                    'the_content',
291
-                    array('EED_Event_Single', 'event_details'),
292
-                    EED_Event_Single::EVENT_DETAILS_PRIORITY
293
-                );
294
-            } else {
295
-                $content = EED_Event_Single::use_filterable_display_order();
296
-            }
297
-        }
298
-        return $content;
299
-    }
300
-
301
-
302
-    /**
303
-     * use_filterable_display_order
304
-     *
305
-     * @return string
306
-     */
307
-    protected static function use_filterable_display_order()
308
-    {
309
-        // since the 'content-espresso_events-details.php' template might be used directly from within a theme,
310
-        // it uses the_content() for displaying the $post->post_content
311
-        // so in order to load a template that uses the_content()
312
-        // from within a callback being used to filter the_content(),
313
-        // we need to first remove this callback from being applied to the_content()
314
-        // (otherwise it will recurse and blow up the interweb)
315
-        remove_filter(
316
-            'the_content',
317
-            array('EED_Event_Single', 'event_details'),
318
-            EED_Event_Single::EVENT_DETAILS_PRIORITY
319
-        );
320
-        //now add additional content
321
-        add_filter(
322
-            'the_content',
323
-            array('EED_Event_Single', 'event_datetimes'),
324
-            EED_Event_Single::EVENT_DATETIMES_PRIORITY,
325
-            1
326
-        );
327
-        add_filter(
328
-            'the_content',
329
-            array('EED_Event_Single', 'event_tickets'),
330
-            EED_Event_Single::EVENT_TICKETS_PRIORITY,
331
-            1
332
-        );
333
-        add_filter(
334
-            'the_content',
335
-            array('EED_Event_Single', 'event_venues'),
336
-            EED_Event_Single::EVENT_VENUES_PRIORITY,
337
-            1
338
-        );
339
-        do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters');
340
-        // now load our template
341
-        $content = EEH_Template::locate_template('content-espresso_events-details.php');
342
-        //now add our filter back in, plus some others
343
-        add_filter(
344
-            'the_content',
345
-            array('EED_Event_Single', 'event_details'),
346
-            EED_Event_Single::EVENT_DETAILS_PRIORITY
347
-        );
348
-        remove_filter(
349
-            'the_content',
350
-            array('EED_Event_Single', 'event_datetimes'),
351
-            EED_Event_Single::EVENT_DATETIMES_PRIORITY
352
-        );
353
-        remove_filter(
354
-            'the_content',
355
-            array('EED_Event_Single', 'event_tickets'),
356
-            EED_Event_Single::EVENT_TICKETS_PRIORITY
357
-        );
358
-        remove_filter(
359
-            'the_content',
360
-            array('EED_Event_Single', 'event_venues'),
361
-            EED_Event_Single::EVENT_VENUES_PRIORITY
362
-        );
363
-        do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters');
364
-        // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
365
-        return $content;
366
-    }
367
-
368
-
369
-    /**
370
-     * event_datetimes - adds datetimes ABOVE content
371
-     *
372
-     * @param        string $content
373
-     * @return        string
374
-     */
375
-    public static function event_datetimes($content)
376
-    {
377
-        return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
378
-    }
379
-
380
-
381
-    /**
382
-     * event_tickets - adds tickets ABOVE content (which includes datetimes)
383
-     *
384
-     * @param        string $content
385
-     * @return        string
386
-     */
387
-    public static function event_tickets($content)
388
-    {
389
-        return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
390
-    }
391
-
392
-
393
-    /**
394
-     * event_venues
395
-     *
396
-     * @param    string $content
397
-     * @return    string
398
-     */
399
-    public static function event_venue($content)
400
-    {
401
-        return EED_Event_Single::event_venues($content);
402
-    }
403
-
404
-
405
-    /**
406
-     * event_venues - adds venues BELOW content
407
-     *
408
-     * @param        string $content
409
-     * @return        string
410
-     */
411
-    public static function event_venues($content)
412
-    {
413
-        return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
414
-    }
415
-
416
-
417
-    /**
418
-     * loop_end
419
-     *
420
-     * @param        array $wp_query_array an array containing the WP_Query object
421
-     * @return        void
422
-     */
423
-    public static function loop_end($wp_query_array)
424
-    {
425
-        global $post;
426
-        do_action('AHEE_event_details_after_post', $post, $wp_query_array);
427
-    }
428
-
429
-
430
-    /**
431
-     * wp_enqueue_scripts
432
-     *
433
-     * @return    void
434
-     */
435
-    public function wp_enqueue_scripts()
436
-    {
437
-        // get some style
438
-        if (
439
-            apply_filters('FHEE_enable_default_espresso_css', TRUE)
440
-            && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', TRUE)
441
-        ) {
442
-            // first check uploads folder
443
-            if (is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) {
444
-                wp_register_style(
445
-                    $this->theme,
446
-                    get_stylesheet_directory_uri() . $this->theme . DS . 'style.css',
447
-                    array('dashicons', 'espresso_default')
448
-                );
449
-            } else {
450
-                wp_register_style(
451
-                    $this->theme,
452
-                    EE_TEMPLATES_URL . $this->theme . DS . 'style.css',
453
-                    array('dashicons', 'espresso_default')
454
-                );
455
-            }
456
-            wp_enqueue_script($this->theme);
457
-            if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
458
-                add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
459
-            }
460
-        }
461
-    }
462
-
463
-
464
-    /**
465
-     * display_venue
466
-     *
467
-     * @return    bool
468
-     */
469
-    public static function display_venue()
470
-    {
471
-        /** @type EE_Event_Single_Config $config */
472
-        $config = EED_Event_Single::instance()->config();
473
-        $display_venue = $config->display_venue === null ? true : $config->display_venue;
474
-        $venue_name = EEH_Venue_View::venue_name();
475
-        return $display_venue && !empty($venue_name);
476
-    }
16
+	const EVENT_DETAILS_PRIORITY = 100;
17
+	const EVENT_DATETIMES_PRIORITY = 110;
18
+	const EVENT_TICKETS_PRIORITY = 120;
19
+	const EVENT_VENUES_PRIORITY = 130;
20
+
21
+	/**
22
+	 * @type bool $using_get_the_excerpt
23
+	 */
24
+	protected static $using_get_the_excerpt = false;
25
+
26
+
27
+	/**
28
+	 * @type EE_Template_Part_Manager $template_parts
29
+	 */
30
+	protected $template_parts;
31
+
32
+
33
+	/**
34
+	 * @return EED_Module|EED_Event_Single
35
+	 */
36
+	public static function instance()
37
+	{
38
+		return parent::get_instance(__CLASS__);
39
+	}
40
+
41
+
42
+	/**
43
+	 * set_hooks - for hooking into EE Core, other modules, etc
44
+	 *
45
+	 * @return    void
46
+	 */
47
+	public static function set_hooks()
48
+	{
49
+		add_filter('FHEE_run_EE_wp', '__return_true');
50
+		add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
51
+		$custom_post_types = EE_Register_CPTs::get_CPTs();
52
+		EE_Config::register_route(
53
+			$custom_post_types['espresso_events']['singular_slug'],
54
+			'Event_Single',
55
+			'run'
56
+		);
57
+	}
58
+
59
+	/**
60
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
61
+	 *
62
+	 * @return    void
63
+	 */
64
+	public static function set_hooks_admin()
65
+	{
66
+		add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2);
67
+	}
68
+
69
+
70
+	/**
71
+	 * set_definitions
72
+	 *
73
+	 * @static
74
+	 * @return void
75
+	 */
76
+	public static function set_definitions()
77
+	{
78
+		define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
79
+		define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates' . DS);
80
+	}
81
+
82
+
83
+	/**
84
+	 * set_config
85
+	 *
86
+	 * @void
87
+	 */
88
+	protected function set_config()
89
+	{
90
+		$this->set_config_section('template_settings');
91
+		$this->set_config_class('EE_Event_Single_Config');
92
+		$this->set_config_name('EED_Event_Single');
93
+	}
94
+
95
+
96
+	/**
97
+	 * initialize_template_parts
98
+	 *
99
+	 * @param EE_Config_Base|EE_Event_Single_Config $config
100
+	 * @return EE_Template_Part_Manager
101
+	 */
102
+	public function initialize_template_parts(EE_Event_Single_Config $config = null)
103
+	{
104
+		/** @type EE_Event_Single_Config $config */
105
+		$config = $config instanceof EE_Event_Single_Config ? $config : $this->config();
106
+		EEH_Autoloader::instance()->register_template_part_autoloaders();
107
+		$template_parts = new EE_Template_Part_Manager();
108
+		$template_parts->add_template_part(
109
+			'tickets',
110
+			__('Ticket Selector', 'event_espresso'),
111
+			'content-espresso_events-tickets.php',
112
+			$config->display_order_tickets
113
+		);
114
+		$template_parts->add_template_part(
115
+			'datetimes',
116
+			__('Dates and Times', 'event_espresso'),
117
+			'content-espresso_events-datetimes.php',
118
+			$config->display_order_datetimes
119
+		);
120
+		$template_parts->add_template_part(
121
+			'event',
122
+			__('Event Description', 'event_espresso'),
123
+			'content-espresso_events-details.php',
124
+			$config->display_order_event
125
+		);
126
+		$template_parts->add_template_part(
127
+			'venue',
128
+			__('Venue Information', 'event_espresso'),
129
+			'content-espresso_events-venues.php',
130
+			$config->display_order_venue
131
+		);
132
+		do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts);
133
+		return $template_parts;
134
+	}
135
+
136
+
137
+	/**
138
+	 * run - initial module setup
139
+	 *
140
+	 * @param WP $WP
141
+	 * @return    void
142
+	 */
143
+	public function run($WP)
144
+	{
145
+		// ensure valid EE_Events_Single_Config() object exists
146
+		$this->set_config();
147
+		// check what template is loaded
148
+		add_filter('template_include', array($this, 'template_include'), 999, 1);
149
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
150
+		// load css
151
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
152
+	}
153
+
154
+
155
+	/**
156
+	 * template_include
157
+	 *
158
+	 * @param    string $template
159
+	 * @return    string
160
+	 */
161
+	public function template_include($template)
162
+	{
163
+		global $post;
164
+		/** @type EE_Event_Single_Config $config */
165
+		$config = $this->config();
166
+		if ($config->display_status_banner_single) {
167
+			add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2);
168
+		}
169
+		// not a custom template?
170
+		if (
171
+			!post_password_required($post)
172
+			&& (
173
+				apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false)
174
+				|| EE_Registry::instance()
175
+					->load_core('Front_Controller')
176
+					->get_selected_template() !== 'single-espresso_events.php'
177
+			)
178
+
179
+		) {
180
+			EEH_Template::load_espresso_theme_functions();
181
+			// then add extra event data via hooks
182
+			add_action('loop_start', array('EED_Event_Single', 'loop_start'));
183
+			add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1);
184
+			add_filter(
185
+				'the_content',
186
+				array('EED_Event_Single', 'event_details'),
187
+				EED_Event_Single::EVENT_DETAILS_PRIORITY
188
+			);
189
+			add_action('loop_end', array('EED_Event_Single', 'loop_end'));
190
+			// don't display entry meta because the existing theme will take car of that
191
+			add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
192
+		}
193
+		return $template;
194
+	}
195
+
196
+
197
+	/**
198
+	 * loop_start
199
+	 *
200
+	 * @param    array $wp_query_array an array containing the WP_Query object
201
+	 * @return    void
202
+	 */
203
+	public static function loop_start($wp_query_array)
204
+	{
205
+		global $post;
206
+		do_action('AHEE_event_details_before_post', $post, $wp_query_array);
207
+	}
208
+
209
+
210
+	/**
211
+	 * the_title
212
+	 *
213
+	 * @param    string $title
214
+	 * @param    int $id
215
+	 * @return    string
216
+	 */
217
+	public static function the_title($title = '', $id = 0)
218
+	{
219
+		global $post;
220
+		return in_the_loop() && $post->ID === (int)$id
221
+			? espresso_event_status_banner($post->ID) . $title
222
+			: $title;
223
+	}
224
+
225
+
226
+	/**
227
+	 * get_the_excerpt
228
+	 * kinda hacky, but if a theme is using get_the_excerpt(),
229
+	 * then we need to remove our filters on the_content()
230
+	 *
231
+	 * @param        string $excerpt
232
+	 * @return        string
233
+	 */
234
+	public static function get_the_excerpt($excerpt = '')
235
+	{
236
+		EED_Event_Single::$using_get_the_excerpt = true;
237
+		add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1);
238
+		return $excerpt;
239
+	}
240
+
241
+
242
+	/**
243
+	 * end_get_the_excerpt
244
+	 *
245
+	 * @param  string $text
246
+	 * @return string
247
+	 */
248
+	public static function end_get_the_excerpt($text = '')
249
+	{
250
+		EED_Event_Single::$using_get_the_excerpt = false;
251
+		return $text;
252
+	}
253
+
254
+
255
+	/**
256
+	 * event_details
257
+	 *
258
+	 * @param    string $content
259
+	 * @return    string
260
+	 */
261
+	public static function event_details($content)
262
+	{
263
+		global $post;
264
+		static $current_post_ID = 0;
265
+		if (
266
+			$current_post_ID !== $post->ID
267
+			&& $post->post_type === 'espresso_events'
268
+			&& !EED_Event_Single::$using_get_the_excerpt
269
+			&& !post_password_required()
270
+		) {
271
+			// Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
272
+			// Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
273
+			// BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
274
+			// We want to allow those plugins to still do their thing and have access to our content, but depending on
275
+			// how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
276
+			// so the following allows this filter to be applied multiple times, but only once for real
277
+			$current_post_ID = did_action('loop_start') ? $post->ID : 0;
278
+			if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) {
279
+				// we need to first remove this callback from being applied to the_content()
280
+				// (otherwise it will recurse and blow up the interweb)
281
+				remove_filter(
282
+					'the_content',
283
+					array('EED_Event_Single', 'event_details'),
284
+					EED_Event_Single::EVENT_DETAILS_PRIORITY
285
+				);
286
+				EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts();
287
+				$content = EEH_Template::locate_template('content-espresso_events-details.php');
288
+				$content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content);
289
+				add_filter(
290
+					'the_content',
291
+					array('EED_Event_Single', 'event_details'),
292
+					EED_Event_Single::EVENT_DETAILS_PRIORITY
293
+				);
294
+			} else {
295
+				$content = EED_Event_Single::use_filterable_display_order();
296
+			}
297
+		}
298
+		return $content;
299
+	}
300
+
301
+
302
+	/**
303
+	 * use_filterable_display_order
304
+	 *
305
+	 * @return string
306
+	 */
307
+	protected static function use_filterable_display_order()
308
+	{
309
+		// since the 'content-espresso_events-details.php' template might be used directly from within a theme,
310
+		// it uses the_content() for displaying the $post->post_content
311
+		// so in order to load a template that uses the_content()
312
+		// from within a callback being used to filter the_content(),
313
+		// we need to first remove this callback from being applied to the_content()
314
+		// (otherwise it will recurse and blow up the interweb)
315
+		remove_filter(
316
+			'the_content',
317
+			array('EED_Event_Single', 'event_details'),
318
+			EED_Event_Single::EVENT_DETAILS_PRIORITY
319
+		);
320
+		//now add additional content
321
+		add_filter(
322
+			'the_content',
323
+			array('EED_Event_Single', 'event_datetimes'),
324
+			EED_Event_Single::EVENT_DATETIMES_PRIORITY,
325
+			1
326
+		);
327
+		add_filter(
328
+			'the_content',
329
+			array('EED_Event_Single', 'event_tickets'),
330
+			EED_Event_Single::EVENT_TICKETS_PRIORITY,
331
+			1
332
+		);
333
+		add_filter(
334
+			'the_content',
335
+			array('EED_Event_Single', 'event_venues'),
336
+			EED_Event_Single::EVENT_VENUES_PRIORITY,
337
+			1
338
+		);
339
+		do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters');
340
+		// now load our template
341
+		$content = EEH_Template::locate_template('content-espresso_events-details.php');
342
+		//now add our filter back in, plus some others
343
+		add_filter(
344
+			'the_content',
345
+			array('EED_Event_Single', 'event_details'),
346
+			EED_Event_Single::EVENT_DETAILS_PRIORITY
347
+		);
348
+		remove_filter(
349
+			'the_content',
350
+			array('EED_Event_Single', 'event_datetimes'),
351
+			EED_Event_Single::EVENT_DATETIMES_PRIORITY
352
+		);
353
+		remove_filter(
354
+			'the_content',
355
+			array('EED_Event_Single', 'event_tickets'),
356
+			EED_Event_Single::EVENT_TICKETS_PRIORITY
357
+		);
358
+		remove_filter(
359
+			'the_content',
360
+			array('EED_Event_Single', 'event_venues'),
361
+			EED_Event_Single::EVENT_VENUES_PRIORITY
362
+		);
363
+		do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters');
364
+		// we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
365
+		return $content;
366
+	}
367
+
368
+
369
+	/**
370
+	 * event_datetimes - adds datetimes ABOVE content
371
+	 *
372
+	 * @param        string $content
373
+	 * @return        string
374
+	 */
375
+	public static function event_datetimes($content)
376
+	{
377
+		return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
378
+	}
379
+
380
+
381
+	/**
382
+	 * event_tickets - adds tickets ABOVE content (which includes datetimes)
383
+	 *
384
+	 * @param        string $content
385
+	 * @return        string
386
+	 */
387
+	public static function event_tickets($content)
388
+	{
389
+		return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
390
+	}
391
+
392
+
393
+	/**
394
+	 * event_venues
395
+	 *
396
+	 * @param    string $content
397
+	 * @return    string
398
+	 */
399
+	public static function event_venue($content)
400
+	{
401
+		return EED_Event_Single::event_venues($content);
402
+	}
403
+
404
+
405
+	/**
406
+	 * event_venues - adds venues BELOW content
407
+	 *
408
+	 * @param        string $content
409
+	 * @return        string
410
+	 */
411
+	public static function event_venues($content)
412
+	{
413
+		return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
414
+	}
415
+
416
+
417
+	/**
418
+	 * loop_end
419
+	 *
420
+	 * @param        array $wp_query_array an array containing the WP_Query object
421
+	 * @return        void
422
+	 */
423
+	public static function loop_end($wp_query_array)
424
+	{
425
+		global $post;
426
+		do_action('AHEE_event_details_after_post', $post, $wp_query_array);
427
+	}
428
+
429
+
430
+	/**
431
+	 * wp_enqueue_scripts
432
+	 *
433
+	 * @return    void
434
+	 */
435
+	public function wp_enqueue_scripts()
436
+	{
437
+		// get some style
438
+		if (
439
+			apply_filters('FHEE_enable_default_espresso_css', TRUE)
440
+			&& apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', TRUE)
441
+		) {
442
+			// first check uploads folder
443
+			if (is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) {
444
+				wp_register_style(
445
+					$this->theme,
446
+					get_stylesheet_directory_uri() . $this->theme . DS . 'style.css',
447
+					array('dashicons', 'espresso_default')
448
+				);
449
+			} else {
450
+				wp_register_style(
451
+					$this->theme,
452
+					EE_TEMPLATES_URL . $this->theme . DS . 'style.css',
453
+					array('dashicons', 'espresso_default')
454
+				);
455
+			}
456
+			wp_enqueue_script($this->theme);
457
+			if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
458
+				add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
459
+			}
460
+		}
461
+	}
462
+
463
+
464
+	/**
465
+	 * display_venue
466
+	 *
467
+	 * @return    bool
468
+	 */
469
+	public static function display_venue()
470
+	{
471
+		/** @type EE_Event_Single_Config $config */
472
+		$config = EED_Event_Single::instance()->config();
473
+		$display_venue = $config->display_venue === null ? true : $config->display_venue;
474
+		$venue_name = EEH_Venue_View::venue_name();
475
+		return $display_venue && !empty($venue_name);
476
+	}
477 477
 
478 478
 
479 479
 }
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
  */
488 488
 function espresso_display_venue_in_event_details()
489 489
 {
490
-    return EED_Event_Single::display_venue();
490
+	return EED_Event_Single::display_venue();
491 491
 }
492 492
 
493 493
 
Please login to merge, or discard this patch.
modules/events_archive/EED_Events_Archive.module.php 2 patches
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -14,13 +14,13 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class EED_Events_Archive  extends EED_Module {
16 16
 
17
-    const EVENT_DETAILS_PRIORITY = 100;
18
-    const EVENT_DATETIMES_PRIORITY = 110;
19
-    const EVENT_TICKETS_PRIORITY = 120;
20
-    const EVENT_VENUES_PRIORITY = 130;
17
+	const EVENT_DETAILS_PRIORITY = 100;
18
+	const EVENT_DATETIMES_PRIORITY = 110;
19
+	const EVENT_TICKETS_PRIORITY = 120;
20
+	const EVENT_VENUES_PRIORITY = 130;
21 21
 
22 22
 
23
-    public static $espresso_event_list_ID = 0;
23
+	public static $espresso_event_list_ID = 0;
24 24
 	public static $espresso_grid_event_lists = array();
25 25
 
26 26
 	/**
@@ -28,19 +28,19 @@  discard block
 block discarded – undo
28 28
 	 */
29 29
 	protected static $using_get_the_excerpt = false;
30 30
 
31
-    /**
32
-     * Used to flag when the event list is being called from an external iframe.
33
-     *
34
-     * @var bool $iframe
35
-     */
36
-    protected static $iframe = false;
31
+	/**
32
+	 * Used to flag when the event list is being called from an external iframe.
33
+	 *
34
+	 * @var bool $iframe
35
+	 */
36
+	protected static $iframe = false;
37 37
 
38
-    /**
38
+	/**
39 39
 	 * @var \EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton $_iframe_embed_button
40 40
 	 */
41 41
 	private static $_iframe_embed_button;
42 42
 
43
-    /**
43
+	/**
44 44
 	 * @type EE_Template_Part_Manager $template_parts
45 45
 	 */
46 46
 	protected $template_parts;
@@ -63,24 +63,24 @@  discard block
 block discarded – undo
63 63
 	 *  @return 	void
64 64
 	 */
65 65
 	public static function set_hooks() {
66
-        $custom_post_types = EE_Register_CPTs::get_CPTs();
67
-        EE_Config::register_route(
68
-            $custom_post_types['espresso_events']['plural_slug'],
69
-            'Events_Archive',
70
-            'run'
71
-        );
72
-        EE_Config::register_route(
73
-            'event_list',
74
-            'Events_Archive',
75
-            'event_list'
76
-        );
77
-        EE_Config::register_route(
78
-            'iframe',
79
-            'Events_Archive',
80
-            'event_list_iframe',
81
-            'event_list'
82
-        );
83
-        add_action( 'wp_loaded', array( 'EED_Events_Archive', 'set_definitions' ), 2 );
66
+		$custom_post_types = EE_Register_CPTs::get_CPTs();
67
+		EE_Config::register_route(
68
+			$custom_post_types['espresso_events']['plural_slug'],
69
+			'Events_Archive',
70
+			'run'
71
+		);
72
+		EE_Config::register_route(
73
+			'event_list',
74
+			'Events_Archive',
75
+			'event_list'
76
+		);
77
+		EE_Config::register_route(
78
+			'iframe',
79
+			'Events_Archive',
80
+			'event_list_iframe',
81
+			'event_list'
82
+		);
83
+		add_action( 'wp_loaded', array( 'EED_Events_Archive', 'set_definitions' ), 2 );
84 84
 	}
85 85
 
86 86
 	/**
@@ -224,9 +224,9 @@  discard block
 block discarded – undo
224 224
 
225 225
 
226 226
 	/**
227
-     * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting
228
-     *
229
-     * @return    void
227
+	 * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting
228
+	 *
229
+	 * @return    void
230 230
 	 */
231 231
 	public function event_list() {
232 232
 		// ensure valid EE_Events_Archive_Config() object exists
@@ -237,36 +237,36 @@  discard block
 block discarded – undo
237 237
 
238 238
 
239 239
 
240
-    /**
241
-     * @access    public
242
-     * @return    void
243
-     * @throws \EE_Error
244
-     * @throws \DomainException
245
-     */
240
+	/**
241
+	 * @access    public
242
+	 * @return    void
243
+	 * @throws \EE_Error
244
+	 * @throws \DomainException
245
+	 */
246 246
 	public function event_list_iframe() {
247
-        \EED_Events_Archive::$iframe = true;
247
+		\EED_Events_Archive::$iframe = true;
248 248
 		$event_list_iframe = new EventsArchiveIframe( $this );
249 249
 		$event_list_iframe->display();
250 250
 	}
251 251
 
252 252
 
253 253
 
254
-    /**
255
-     * @access public
256
-     * @return string
257
-     */
254
+	/**
255
+	 * @access public
256
+	 * @return string
257
+	 */
258 258
 	public static function is_iframe() {
259
-        return \EED_Events_Archive::$iframe;
259
+		return \EED_Events_Archive::$iframe;
260 260
 	}
261 261
 
262 262
 
263 263
 
264
-    /**
265
-     * @access public
266
-     * @return string
267
-     */
264
+	/**
265
+	 * @access public
266
+	 * @return string
267
+	 */
268 268
 	public static function link_target() {
269
-        return \EED_Events_Archive::$iframe ? ' target="_blank"' : '';
269
+		return \EED_Events_Archive::$iframe ? ' target="_blank"' : '';
270 270
 	}
271 271
 
272 272
 
@@ -294,10 +294,10 @@  discard block
 block discarded – undo
294 294
 			}
295 295
 			// if NOT a custom template
296 296
 			if (
297
-                apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false)
297
+				apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false)
298 298
 				|| EE_Registry::instance()
299
-                    ->load_core( 'Front_Controller' )
300
-                    ->get_selected_template() !== 'archive-espresso_events.php'
299
+					->load_core( 'Front_Controller' )
300
+					->get_selected_template() !== 'archive-espresso_events.php'
301 301
 			) {
302 302
 				// don't display entry meta because the existing theme will take care of that
303 303
 				add_filter( 'FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true' );
@@ -305,16 +305,16 @@  discard block
 block discarded – undo
305 305
 				EEH_Template::load_espresso_theme_functions();
306 306
 				// because we don't know if the theme is using the_excerpt()
307 307
 				add_filter(
308
-				    'the_excerpt',
309
-                    array( 'EED_Events_Archive', 'event_details' ),
310
-                    EED_Events_Archive::EVENT_DETAILS_PRIORITY
311
-                );
308
+					'the_excerpt',
309
+					array( 'EED_Events_Archive', 'event_details' ),
310
+					EED_Events_Archive::EVENT_DETAILS_PRIORITY
311
+				);
312 312
 				// or the_content
313 313
 				add_filter(
314
-				    'the_content',
315
-                    array( 'EED_Events_Archive', 'event_details' ),
316
-                    EED_Events_Archive::EVENT_DETAILS_PRIORITY
317
-                );
314
+					'the_content',
315
+					array( 'EED_Events_Archive', 'event_details' ),
316
+					EED_Events_Archive::EVENT_DETAILS_PRIORITY
317
+				);
318 318
 				// and just in case they are running get_the_excerpt() which DESTROYS things
319 319
 				add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
320 320
 				// don't display entry meta because the existing theme will take care of that
@@ -339,15 +339,15 @@  discard block
 block discarded – undo
339 339
 		}
340 340
 		if ( apply_filters( 'FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false ) ) {
341 341
 			remove_filter(
342
-			    'the_excerpt',
343
-                array( 'EED_Events_Archive', 'event_details' ),
344
-                EED_Events_Archive::EVENT_DETAILS_PRIORITY
345
-            );
342
+				'the_excerpt',
343
+				array( 'EED_Events_Archive', 'event_details' ),
344
+				EED_Events_Archive::EVENT_DETAILS_PRIORITY
345
+			);
346 346
 			remove_filter(
347
-			    'the_content',
348
-                array( 'EED_Events_Archive', 'event_details' ),
349
-                EED_Events_Archive::EVENT_DETAILS_PRIORITY
350
-            );
347
+				'the_content',
348
+				array( 'EED_Events_Archive', 'event_details' ),
349
+				EED_Events_Archive::EVENT_DETAILS_PRIORITY
350
+			);
351 351
 			$excerpt = EED_Events_Archive::event_details( $excerpt );
352 352
 		} else {
353 353
 			EED_Events_Archive::$using_get_the_excerpt = true;
@@ -438,17 +438,17 @@  discard block
 block discarded – undo
438 438
 		// no further password checks required atm
439 439
 		add_filter( 'FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true' );
440 440
 		// we need to first remove this callback from being applied to the_content() or the_excerpt()
441
-        // (otherwise it will recurse and blow up the interweb)
441
+		// (otherwise it will recurse and blow up the interweb)
442 442
 		remove_filter(
443
-		    'the_excerpt',
444
-            array( 'EED_Events_Archive', 'event_details' ),
445
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
446
-        );
443
+			'the_excerpt',
444
+			array( 'EED_Events_Archive', 'event_details' ),
445
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
446
+		);
447 447
 		remove_filter(
448
-		    'the_content',
449
-            array( 'EED_Events_Archive', 'event_details' ),
450
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
451
-        );
448
+			'the_content',
449
+			array( 'EED_Events_Archive', 'event_details' ),
450
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
451
+		);
452 452
 		remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
453 453
 		// now add additional content depending on whether event is using the_excerpt() or the_content()
454 454
 		EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts();
@@ -456,20 +456,20 @@  discard block
 block discarded – undo
456 456
 		$content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters( $content );
457 457
 		// re-add our main filters (or else the next event won't have them)
458 458
 		add_filter(
459
-		    'the_excerpt',
460
-            array( 'EED_Events_Archive', 'event_details' ),
461
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
462
-        );
459
+			'the_excerpt',
460
+			array( 'EED_Events_Archive', 'event_details' ),
461
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
462
+		);
463 463
 		add_filter(
464
-		    'the_content',
465
-            array( 'EED_Events_Archive', 'event_details' ),
466
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
467
-        );
464
+			'the_content',
465
+			array( 'EED_Events_Archive', 'event_details' ),
466
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
467
+		);
468 468
 		add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
469 469
 		remove_filter(
470
-		    'FHEE__EED_Events_Archive__event_details__no_post_password_required',
471
-            '__return_true'
472
-        );
470
+			'FHEE__EED_Events_Archive__event_details__no_post_password_required',
471
+			'__return_true'
472
+		);
473 473
 		return $content;
474 474
 	}
475 475
 
@@ -485,15 +485,15 @@  discard block
 block discarded – undo
485 485
 		// we need to first remove this callback from being applied to the_content()
486 486
 		// (otherwise it will recurse and blow up the interweb)
487 487
 		remove_filter(
488
-		    'the_excerpt',
489
-            array( 'EED_Events_Archive', 'event_details' ),
490
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
491
-        );
488
+			'the_excerpt',
489
+			array( 'EED_Events_Archive', 'event_details' ),
490
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
491
+		);
492 492
 		remove_filter(
493
-		    'the_content',
494
-            array( 'EED_Events_Archive', 'event_details' ),
495
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
496
-        );
493
+			'the_content',
494
+			array( 'EED_Events_Archive', 'event_details' ),
495
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
496
+		);
497 497
 		remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
498 498
 		//now add additional content depending on whether event is using the_excerpt() or the_content()
499 499
 		EED_Events_Archive::_add_additional_excerpt_filters();
@@ -503,15 +503,15 @@  discard block
 block discarded – undo
503 503
 		$content = EEH_Template::locate_template( 'content-espresso_events-details.php' );
504 504
 		// re-add our main filters (or else the next event won't have them)
505 505
 		add_filter(
506
-		    'the_excerpt',
507
-            array( 'EED_Events_Archive', 'event_details' ),
508
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
509
-        );
506
+			'the_excerpt',
507
+			array( 'EED_Events_Archive', 'event_details' ),
508
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
509
+		);
510 510
 		add_filter(
511
-		    'the_content',
512
-            array( 'EED_Events_Archive', 'event_details' ),
513
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
514
-        );
511
+			'the_content',
512
+			array( 'EED_Events_Archive', 'event_details' ),
513
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
514
+		);
515 515
 		add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
516 516
 		// but remove the other filters so that they don't get applied to the next post
517 517
 		EED_Events_Archive::_remove_additional_events_archive_filters();
@@ -588,20 +588,20 @@  discard block
 block discarded – undo
588 588
 	 */
589 589
 	private static function _add_additional_excerpt_filters() {
590 590
 		add_filter(
591
-		    'the_excerpt',
592
-            array( 'EED_Events_Archive', 'event_datetimes' ),
593
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
594
-        );
591
+			'the_excerpt',
592
+			array( 'EED_Events_Archive', 'event_datetimes' ),
593
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
594
+		);
595 595
 		add_filter(
596
-		    'the_excerpt',
597
-            array( 'EED_Events_Archive', 'event_tickets' ),
598
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
599
-        );
596
+			'the_excerpt',
597
+			array( 'EED_Events_Archive', 'event_tickets' ),
598
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
599
+		);
600 600
 		add_filter(
601
-		    'the_excerpt',
602
-            array( 'EED_Events_Archive', 'event_venues' ),
603
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
604
-        );
601
+			'the_excerpt',
602
+			array( 'EED_Events_Archive', 'event_venues' ),
603
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
604
+		);
605 605
 	}
606 606
 
607 607
 
@@ -614,20 +614,20 @@  discard block
 block discarded – undo
614 614
 	 */
615 615
 	private static function _add_additional_content_filters() {
616 616
 		add_filter(
617
-		    'the_content',
618
-            array( 'EED_Events_Archive', 'event_datetimes' ),
619
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
620
-        );
617
+			'the_content',
618
+			array( 'EED_Events_Archive', 'event_datetimes' ),
619
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
620
+		);
621 621
 		add_filter(
622
-		    'the_content',
623
-            array( 'EED_Events_Archive', 'event_tickets' ),
624
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
625
-        );
622
+			'the_content',
623
+			array( 'EED_Events_Archive', 'event_tickets' ),
624
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
625
+		);
626 626
 		add_filter(
627
-		    'the_content',
628
-            array( 'EED_Events_Archive', 'event_venues' ),
629
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
630
-        );
627
+			'the_content',
628
+			array( 'EED_Events_Archive', 'event_venues' ),
629
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
630
+		);
631 631
 	}
632 632
 
633 633
 
@@ -640,35 +640,35 @@  discard block
 block discarded – undo
640 640
 	 */
641 641
 	private static function _remove_additional_events_archive_filters() {
642 642
 		remove_filter(
643
-		    'the_excerpt',
644
-            array( 'EED_Events_Archive', 'event_datetimes' ),
645
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
646
-        );
643
+			'the_excerpt',
644
+			array( 'EED_Events_Archive', 'event_datetimes' ),
645
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
646
+		);
647 647
 		remove_filter(
648
-		    'the_excerpt',
649
-            array( 'EED_Events_Archive', 'event_tickets' ),
650
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
651
-        );
648
+			'the_excerpt',
649
+			array( 'EED_Events_Archive', 'event_tickets' ),
650
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
651
+		);
652 652
 		remove_filter(
653
-		    'the_excerpt',
654
-            array( 'EED_Events_Archive', 'event_venues' ),
655
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
656
-        );
653
+			'the_excerpt',
654
+			array( 'EED_Events_Archive', 'event_venues' ),
655
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
656
+		);
657 657
 		remove_filter(
658
-		    'the_content',
659
-            array( 'EED_Events_Archive', 'event_datetimes' ),
660
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
661
-        );
658
+			'the_content',
659
+			array( 'EED_Events_Archive', 'event_datetimes' ),
660
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
661
+		);
662 662
 		remove_filter(
663
-		    'the_content',
664
-            array( 'EED_Events_Archive', 'event_tickets' ),
665
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
666
-        );
663
+			'the_content',
664
+			array( 'EED_Events_Archive', 'event_tickets' ),
665
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
666
+		);
667 667
 		remove_filter(
668
-		    'the_content',
669
-            array( 'EED_Events_Archive', 'event_venues' ),
670
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
671
-        );
668
+			'the_content',
669
+			array( 'EED_Events_Archive', 'event_venues' ),
670
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
671
+		);
672 672
 	}
673 673
 
674 674
 
@@ -683,50 +683,50 @@  discard block
 block discarded – undo
683 683
 		//remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
684 684
 		remove_filter( 'the_title', array( 'EED_Events_Archive', 'the_title' ), 1 );
685 685
 		remove_filter(
686
-		    'the_excerpt',
687
-            array( 'EED_Events_Archive', 'event_details' ),
688
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
689
-        );
686
+			'the_excerpt',
687
+			array( 'EED_Events_Archive', 'event_details' ),
688
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
689
+		);
690 690
 		remove_filter(
691
-		    'the_excerpt',
692
-            array( 'EED_Events_Archive', 'event_datetimes' ),
693
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
694
-        );
691
+			'the_excerpt',
692
+			array( 'EED_Events_Archive', 'event_datetimes' ),
693
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
694
+		);
695 695
 		remove_filter(
696
-		    'the_excerpt',
697
-            array( 'EED_Events_Archive', 'event_tickets' ),
698
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
699
-        );
696
+			'the_excerpt',
697
+			array( 'EED_Events_Archive', 'event_tickets' ),
698
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
699
+		);
700 700
 		remove_filter(
701
-		    'the_excerpt',
702
-            array( 'EED_Events_Archive', 'event_venues' ),
703
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
704
-        );
701
+			'the_excerpt',
702
+			array( 'EED_Events_Archive', 'event_venues' ),
703
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
704
+		);
705 705
 		remove_filter(
706
-		    'the_content',
707
-            array( 'EED_Events_Archive', 'event_details' ),
708
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
709
-        );
706
+			'the_content',
707
+			array( 'EED_Events_Archive', 'event_details' ),
708
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
709
+		);
710 710
 		remove_filter(
711
-		    'the_content',
712
-            array( 'EED_Events_Archive', 'event_datetimes' ),
713
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
714
-        );
711
+			'the_content',
712
+			array( 'EED_Events_Archive', 'event_datetimes' ),
713
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
714
+		);
715 715
 		remove_filter(
716
-		    'the_content',
717
-            array( 'EED_Events_Archive', 'event_tickets' ),
718
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
719
-        );
716
+			'the_content',
717
+			array( 'EED_Events_Archive', 'event_tickets' ),
718
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
719
+		);
720 720
 		remove_filter(
721
-		    'the_content',
722
-            array( 'EED_Events_Archive', 'event_venues' ),
723
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
724
-        );
721
+			'the_content',
722
+			array( 'EED_Events_Archive', 'event_venues' ),
723
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
724
+		);
725 725
 		// don't display entry meta because the existing theme will take care of that
726 726
 		remove_filter(
727
-		    'FHEE__content_espresso_events_details_template__display_entry_meta',
728
-            '__return_false'
729
-        );
727
+			'FHEE__content_espresso_events_details_template__display_entry_meta',
728
+			'__return_false'
729
+		);
730 730
 	}
731 731
 
732 732
 
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
 	 *  @return 	void
742 742
 	 */
743 743
 	public function load_event_list_assets() {
744
-        do_action( 'AHEE__EED_Events_Archive__before_load_assets' );
744
+		do_action( 'AHEE__EED_Events_Archive__before_load_assets' );
745 745
 		add_filter( 'FHEE_load_EE_Session', '__return_true' );
746 746
 		add_filter( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true' );
747 747
 		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 );
Please login to merge, or discard this patch.
Spacing   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton;
4 4
 use EventEspresso\modules\events_archive\EventsArchiveIframe;
5 5
 
6
-defined( 'EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed');
6
+defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed');
7 7
 
8 8
 /**
9 9
  * Event List
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 * @return EED_Events_Archive
52 52
 	 */
53 53
 	public static function instance() {
54
-		return parent::get_instance( __CLASS__ );
54
+		return parent::get_instance(__CLASS__);
55 55
 	}
56 56
 
57 57
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
             'event_list_iframe',
81 81
             'event_list'
82 82
         );
83
-        add_action( 'wp_loaded', array( 'EED_Events_Archive', 'set_definitions' ), 2 );
83
+        add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2);
84 84
 	}
85 85
 
86 86
 	/**
@@ -90,12 +90,12 @@  discard block
 block discarded – undo
90 90
 	 *  @return 	void
91 91
 	 */
92 92
 	public static function set_hooks_admin() {
93
-		add_action( 'wp_loaded', array( 'EED_Events_Archive', 'set_definitions' ), 2 );
93
+		add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2);
94 94
 		// hook into the end of the \EE_Admin_Page::_load_page_dependencies()
95 95
 		// to load assets for "espresso_events" page on the "default" route (action)
96 96
 		add_action(
97 97
 			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default',
98
-			array( 'EED_Events_Archive', 'event_list_iframe_embed_button' ),
98
+			array('EED_Events_Archive', 'event_list_iframe_embed_button'),
99 99
 			10
100 100
 		);
101 101
 	}
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
 	 *  @return 	void
111 111
 	 */
112 112
 	public static function set_definitions() {
113
-		define( 'EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS );
114
-		define( 'EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS );
113
+		define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS);
114
+		define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS);
115 115
 	}
116 116
 
117 117
 
@@ -119,10 +119,10 @@  discard block
 block discarded – undo
119 119
 	/**
120 120
 	 * set up EE_Events_Archive_Config
121 121
 	 */
122
-	protected function set_config(){
123
-		$this->set_config_section( 'template_settings' );
124
-		$this->set_config_class( 'EE_Events_Archive_Config' );
125
-		$this->set_config_name( 'EED_Events_Archive' );
122
+	protected function set_config() {
123
+		$this->set_config_section('template_settings');
124
+		$this->set_config_class('EE_Events_Archive_Config');
125
+		$this->set_config_name('EED_Events_Archive');
126 126
 	}
127 127
 
128 128
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 	 * @return EventListIframeEmbedButton
132 132
 	 */
133 133
 	public static function get_iframe_embed_button() {
134
-		if ( ! self::$_iframe_embed_button instanceof EventListIframeEmbedButton ) {
134
+		if ( ! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) {
135 135
 			self::$_iframe_embed_button = new EventListIframeEmbedButton();
136 136
 		}
137 137
 		return self::$_iframe_embed_button;
@@ -157,35 +157,35 @@  discard block
 block discarded – undo
157 157
 	 * @param \EE_Events_Archive_Config $config
158 158
 	 * @return \EE_Template_Part_Manager
159 159
 	 */
160
-	public function initialize_template_parts( EE_Events_Archive_Config $config = null ) {
160
+	public function initialize_template_parts(EE_Events_Archive_Config $config = null) {
161 161
 		$config = $config instanceof EE_Events_Archive_Config ? $config : $this->config();
162 162
 		EEH_Autoloader::instance()->register_template_part_autoloaders();
163 163
 		$template_parts = new EE_Template_Part_Manager();
164 164
 		$template_parts->add_template_part(
165 165
 			'tickets',
166
-			__( 'Ticket Selector', 'event_espresso' ),
166
+			__('Ticket Selector', 'event_espresso'),
167 167
 			'content-espresso_events-tickets.php',
168 168
 			$config->display_order_tickets
169 169
 		);
170 170
 		$template_parts->add_template_part(
171 171
 			'datetimes',
172
-			__( 'Dates and Times', 'event_espresso' ),
172
+			__('Dates and Times', 'event_espresso'),
173 173
 			'content-espresso_events-datetimes.php',
174 174
 			$config->display_order_datetimes
175 175
 		);
176 176
 		$template_parts->add_template_part(
177 177
 			'event',
178
-			__( 'Event Description', 'event_espresso' ),
178
+			__('Event Description', 'event_espresso'),
179 179
 			'content-espresso_events-details.php',
180 180
 			$config->display_order_event
181 181
 		);
182 182
 		$template_parts->add_template_part(
183 183
 			'venue',
184
-			__( 'Venue Information', 'event_espresso' ),
184
+			__('Venue Information', 'event_espresso'),
185 185
 			'content-espresso_events-venues.php',
186 186
 			$config->display_order_venue
187 187
 		);
188
-		do_action( 'AHEE__EED_Event_Archive__initialize_template_parts', $template_parts );
188
+		do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts);
189 189
 		return $template_parts;
190 190
 	}
191 191
 
@@ -198,8 +198,8 @@  discard block
 block discarded – undo
198 198
 	 * @param WP $WP
199 199
 	 * @return    void
200 200
 	 */
201
-	public function run( $WP ) {
202
-		do_action( 'AHEE__EED_Events_Archive__before_run' );
201
+	public function run($WP) {
202
+		do_action('AHEE__EED_Events_Archive__before_run');
203 203
 		// ensure valid EE_Events_Archive_Config() object exists
204 204
 		$this->set_config();
205 205
 		/** @type EE_Events_Archive_Config $config */
@@ -211,14 +211,14 @@  discard block
 block discarded – undo
211 211
 		EEH_Event_Query::add_query_filters();
212 212
 		// set params that will get used by the filters
213 213
 		EEH_Event_Query::set_query_params(
214
-			'', 	// month
215
-			'', 	// category
216
-			$config->display_expired_events, 	// show_expired
217
-			'start_date', 	// orderby
214
+			'', // month
215
+			'', // category
216
+			$config->display_expired_events, // show_expired
217
+			'start_date', // orderby
218 218
 			'ASC' 	// sort
219 219
 		);
220 220
 		// check what template is loaded
221
-		add_filter( 'template_include',  array( $this, 'template_include' ), 999, 1 );
221
+		add_filter('template_include', array($this, 'template_include'), 999, 1);
222 222
 	}
223 223
 
224 224
 
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
      */
246 246
 	public function event_list_iframe() {
247 247
         \EED_Events_Archive::$iframe = true;
248
-		$event_list_iframe = new EventsArchiveIframe( $this );
248
+		$event_list_iframe = new EventsArchiveIframe($this);
249 249
 		$event_list_iframe->display();
250 250
 	}
251 251
 
@@ -283,42 +283,42 @@  discard block
 block discarded – undo
283 283
 	 * @param string $template
284 284
 	 * @return    string
285 285
 	 */
286
-	public function template_include( $template = '' ) {
286
+	public function template_include($template = '') {
287 287
 		// don't add content filter for dedicated EE child themes or private posts
288
-		if ( ! EEH_Template::is_espresso_theme() ) {
288
+		if ( ! EEH_Template::is_espresso_theme()) {
289 289
 			/** @type EE_Events_Archive_Config $config */
290 290
 			$config = $this->config();
291 291
 			// add status banner ?
292
-			if ( $config->display_status_banner ) {
293
-				add_filter( 'the_title', array( 'EED_Events_Archive', 'the_title' ), 100, 2 );
292
+			if ($config->display_status_banner) {
293
+				add_filter('the_title', array('EED_Events_Archive', 'the_title'), 100, 2);
294 294
 			}
295 295
 			// if NOT a custom template
296 296
 			if (
297 297
                 apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false)
298 298
 				|| EE_Registry::instance()
299
-                    ->load_core( 'Front_Controller' )
299
+                    ->load_core('Front_Controller')
300 300
                     ->get_selected_template() !== 'archive-espresso_events.php'
301 301
 			) {
302 302
 				// don't display entry meta because the existing theme will take care of that
303
-				add_filter( 'FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true' );
303
+				add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true');
304 304
 			// load functions.php file for the theme (loaded by WP if using child theme)
305 305
 				EEH_Template::load_espresso_theme_functions();
306 306
 				// because we don't know if the theme is using the_excerpt()
307 307
 				add_filter(
308 308
 				    'the_excerpt',
309
-                    array( 'EED_Events_Archive', 'event_details' ),
309
+                    array('EED_Events_Archive', 'event_details'),
310 310
                     EED_Events_Archive::EVENT_DETAILS_PRIORITY
311 311
                 );
312 312
 				// or the_content
313 313
 				add_filter(
314 314
 				    'the_content',
315
-                    array( 'EED_Events_Archive', 'event_details' ),
315
+                    array('EED_Events_Archive', 'event_details'),
316 316
                     EED_Events_Archive::EVENT_DETAILS_PRIORITY
317 317
                 );
318 318
 				// and just in case they are running get_the_excerpt() which DESTROYS things
319
-				add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
319
+				add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1);
320 320
 				// don't display entry meta because the existing theme will take care of that
321
-				add_filter( 'FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false' );
321
+				add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
322 322
 			}
323 323
 		}
324 324
 		return $template;
@@ -333,25 +333,25 @@  discard block
 block discarded – undo
333 333
 	 * 	@param		string 	$excerpt
334 334
 	 * 	@return 		string
335 335
 	 */
336
-	public static function get_the_excerpt( $excerpt = '' ) {
337
-		if ( post_password_required() ) {
336
+	public static function get_the_excerpt($excerpt = '') {
337
+		if (post_password_required()) {
338 338
 			return $excerpt;
339 339
 		}
340
-		if ( apply_filters( 'FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false ) ) {
340
+		if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) {
341 341
 			remove_filter(
342 342
 			    'the_excerpt',
343
-                array( 'EED_Events_Archive', 'event_details' ),
343
+                array('EED_Events_Archive', 'event_details'),
344 344
                 EED_Events_Archive::EVENT_DETAILS_PRIORITY
345 345
             );
346 346
 			remove_filter(
347 347
 			    'the_content',
348
-                array( 'EED_Events_Archive', 'event_details' ),
348
+                array('EED_Events_Archive', 'event_details'),
349 349
                 EED_Events_Archive::EVENT_DETAILS_PRIORITY
350 350
             );
351
-			$excerpt = EED_Events_Archive::event_details( $excerpt );
351
+			$excerpt = EED_Events_Archive::event_details($excerpt);
352 352
 		} else {
353 353
 			EED_Events_Archive::$using_get_the_excerpt = true;
354
-			add_filter( 'wp_trim_excerpt', array( 'EED_Events_Archive', 'end_get_the_excerpt' ), 999, 1 );
354
+			add_filter('wp_trim_excerpt', array('EED_Events_Archive', 'end_get_the_excerpt'), 999, 1);
355 355
 		}
356 356
 		return $excerpt;
357 357
 	}
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 	 * @param  string $text
366 366
 	 * @return string
367 367
 	 */
368
-	public static function end_get_the_excerpt( $text = '' ) {
368
+	public static function end_get_the_excerpt($text = '') {
369 369
 		EED_Events_Archive::$using_get_the_excerpt = false;
370 370
 		return $text;
371 371
 	}
@@ -380,10 +380,10 @@  discard block
 block discarded – undo
380 380
 	 * @param 		string 		$id
381 381
 	 * @return 		string
382 382
 	 */
383
-	public static function the_title( $title = '', $id = '' ) {
383
+	public static function the_title($title = '', $id = '') {
384 384
 	global $post;
385
-	if ( $post instanceof WP_Post ) {
386
-		return in_the_loop() && $post->ID == $id ? espresso_event_status_banner( $post->ID  ) . $title :  $title;
385
+	if ($post instanceof WP_Post) {
386
+		return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID).$title : $title;
387 387
 	}
388 388
 	return $title;
389 389
 }
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
 	 * 	@param		string 	$content
398 398
 	 * 	@return 		string
399 399
 	 */
400
-	public static function event_details( $content ) {
400
+	public static function event_details($content) {
401 401
 		global $post;
402 402
 		static $current_post_ID = 0;
403 403
 		if (
@@ -406,8 +406,8 @@  discard block
 block discarded – undo
406 406
 			&& ! EED_Events_Archive::$using_get_the_excerpt
407 407
 			&& ! post_password_required()
408 408
 			&& (
409
-				apply_filters( 'FHEE__EES_Espresso_Events__process_shortcode__true', false )
410
-				|| ! apply_filters( 'FHEE__content_espresso_events__template_loaded', false )
409
+				apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false)
410
+				|| ! apply_filters('FHEE__content_espresso_events__template_loaded', false)
411 411
 			)
412 412
 		) {
413 413
 			// Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
@@ -416,8 +416,8 @@  discard block
 block discarded – undo
416 416
 			// We want to allow those plugins to still do their thing and have access to our content, but depending on
417 417
 			// how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
418 418
 			// so the following allows this filter to be applied multiple times, but only once for real
419
-			$current_post_ID = did_action( 'loop_start' ) ? $post->ID : 0;
420
-			if ( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order ) {
419
+			$current_post_ID = did_action('loop_start') ? $post->ID : 0;
420
+			if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) {
421 421
 				$content = \EED_Events_Archive::use_sortable_display_order();
422 422
 			} else {
423 423
 				$content = \EED_Events_Archive::use_filterable_display_order();
@@ -436,36 +436,36 @@  discard block
 block discarded – undo
436 436
 	 */
437 437
 	protected static function use_sortable_display_order() {
438 438
 		// no further password checks required atm
439
-		add_filter( 'FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true' );
439
+		add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true');
440 440
 		// we need to first remove this callback from being applied to the_content() or the_excerpt()
441 441
         // (otherwise it will recurse and blow up the interweb)
442 442
 		remove_filter(
443 443
 		    'the_excerpt',
444
-            array( 'EED_Events_Archive', 'event_details' ),
444
+            array('EED_Events_Archive', 'event_details'),
445 445
             EED_Events_Archive::EVENT_DETAILS_PRIORITY
446 446
         );
447 447
 		remove_filter(
448 448
 		    'the_content',
449
-            array( 'EED_Events_Archive', 'event_details' ),
449
+            array('EED_Events_Archive', 'event_details'),
450 450
             EED_Events_Archive::EVENT_DETAILS_PRIORITY
451 451
         );
452
-		remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
452
+		remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1);
453 453
 		// now add additional content depending on whether event is using the_excerpt() or the_content()
454 454
 		EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts();
455
-		$content = EEH_Template::locate_template( 'content-espresso_events-details.php' );
456
-		$content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters( $content );
455
+		$content = EEH_Template::locate_template('content-espresso_events-details.php');
456
+		$content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content);
457 457
 		// re-add our main filters (or else the next event won't have them)
458 458
 		add_filter(
459 459
 		    'the_excerpt',
460
-            array( 'EED_Events_Archive', 'event_details' ),
460
+            array('EED_Events_Archive', 'event_details'),
461 461
             EED_Events_Archive::EVENT_DETAILS_PRIORITY
462 462
         );
463 463
 		add_filter(
464 464
 		    'the_content',
465
-            array( 'EED_Events_Archive', 'event_details' ),
465
+            array('EED_Events_Archive', 'event_details'),
466 466
             EED_Events_Archive::EVENT_DETAILS_PRIORITY
467 467
         );
468
-		add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
468
+		add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1);
469 469
 		remove_filter(
470 470
 		    'FHEE__EED_Events_Archive__event_details__no_post_password_required',
471 471
             '__return_true'
@@ -486,36 +486,36 @@  discard block
 block discarded – undo
486 486
 		// (otherwise it will recurse and blow up the interweb)
487 487
 		remove_filter(
488 488
 		    'the_excerpt',
489
-            array( 'EED_Events_Archive', 'event_details' ),
489
+            array('EED_Events_Archive', 'event_details'),
490 490
             EED_Events_Archive::EVENT_DETAILS_PRIORITY
491 491
         );
492 492
 		remove_filter(
493 493
 		    'the_content',
494
-            array( 'EED_Events_Archive', 'event_details' ),
494
+            array('EED_Events_Archive', 'event_details'),
495 495
             EED_Events_Archive::EVENT_DETAILS_PRIORITY
496 496
         );
497
-		remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
497
+		remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1);
498 498
 		//now add additional content depending on whether event is using the_excerpt() or the_content()
499 499
 		EED_Events_Archive::_add_additional_excerpt_filters();
500 500
 		EED_Events_Archive::_add_additional_content_filters();
501
-		do_action( 'AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters' );
501
+		do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters');
502 502
 		// now load our template
503
-		$content = EEH_Template::locate_template( 'content-espresso_events-details.php' );
503
+		$content = EEH_Template::locate_template('content-espresso_events-details.php');
504 504
 		// re-add our main filters (or else the next event won't have them)
505 505
 		add_filter(
506 506
 		    'the_excerpt',
507
-            array( 'EED_Events_Archive', 'event_details' ),
507
+            array('EED_Events_Archive', 'event_details'),
508 508
             EED_Events_Archive::EVENT_DETAILS_PRIORITY
509 509
         );
510 510
 		add_filter(
511 511
 		    'the_content',
512
-            array( 'EED_Events_Archive', 'event_details' ),
512
+            array('EED_Events_Archive', 'event_details'),
513 513
             EED_Events_Archive::EVENT_DETAILS_PRIORITY
514 514
         );
515
-		add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
515
+		add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1);
516 516
 		// but remove the other filters so that they don't get applied to the next post
517 517
 		EED_Events_Archive::_remove_additional_events_archive_filters();
518
-		do_action( 'AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters' );
518
+		do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters');
519 519
 		// we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
520 520
 		//return ! empty( $template ) ? $template : $content;
521 521
 		return $content;
@@ -530,11 +530,11 @@  discard block
 block discarded – undo
530 530
 	 * 	@param		string 	$content
531 531
 	 *  	@return 		string
532 532
 	 */
533
-	public static function event_datetimes( $content ) {
534
-		if ( post_password_required() ) {
533
+	public static function event_datetimes($content) {
534
+		if (post_password_required()) {
535 535
 			return $content;
536 536
 		}
537
-		return EEH_Template::locate_template( 'content-espresso_events-datetimes.php' ) . $content;
537
+		return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content;
538 538
 	}
539 539
 
540 540
 	/**
@@ -544,11 +544,11 @@  discard block
 block discarded – undo
544 544
 	 * 	@param		string 	$content
545 545
 	 *  	@return 		string
546 546
 	 */
547
-	public static function event_tickets( $content ) {
548
-		if ( post_password_required() ) {
547
+	public static function event_tickets($content) {
548
+		if (post_password_required()) {
549 549
 			return $content;
550 550
 		}
551
-		return EEH_Template::locate_template( 'content-espresso_events-tickets.php' ) . $content;
551
+		return EEH_Template::locate_template('content-espresso_events-tickets.php').$content;
552 552
 	}
553 553
 
554 554
 
@@ -560,8 +560,8 @@  discard block
 block discarded – undo
560 560
 	 * @param    string $content
561 561
 	 * @return    string
562 562
 	 */
563
-	public static function event_venue( $content ) {
564
-		return EED_Events_Archive::event_venues( $content );
563
+	public static function event_venue($content) {
564
+		return EED_Events_Archive::event_venues($content);
565 565
 	}
566 566
 
567 567
 	/**
@@ -571,11 +571,11 @@  discard block
 block discarded – undo
571 571
 	 * 	@param		string 	$content
572 572
 	 *  	@return 		string
573 573
 	 */
574
-	public static function event_venues( $content ) {
575
-		if ( post_password_required() ) {
574
+	public static function event_venues($content) {
575
+		if (post_password_required()) {
576 576
 			return $content;
577 577
 		}
578
-		return $content . EEH_Template::locate_template( 'content-espresso_events-venues.php' );
578
+		return $content.EEH_Template::locate_template('content-espresso_events-venues.php');
579 579
 	}
580 580
 
581 581
 
@@ -589,17 +589,17 @@  discard block
 block discarded – undo
589 589
 	private static function _add_additional_excerpt_filters() {
590 590
 		add_filter(
591 591
 		    'the_excerpt',
592
-            array( 'EED_Events_Archive', 'event_datetimes' ),
592
+            array('EED_Events_Archive', 'event_datetimes'),
593 593
             EED_Events_Archive::EVENT_DATETIMES_PRIORITY
594 594
         );
595 595
 		add_filter(
596 596
 		    'the_excerpt',
597
-            array( 'EED_Events_Archive', 'event_tickets' ),
597
+            array('EED_Events_Archive', 'event_tickets'),
598 598
             EED_Events_Archive::EVENT_TICKETS_PRIORITY
599 599
         );
600 600
 		add_filter(
601 601
 		    'the_excerpt',
602
-            array( 'EED_Events_Archive', 'event_venues' ),
602
+            array('EED_Events_Archive', 'event_venues'),
603 603
             EED_Events_Archive::EVENT_VENUES_PRIORITY
604 604
         );
605 605
 	}
@@ -615,17 +615,17 @@  discard block
 block discarded – undo
615 615
 	private static function _add_additional_content_filters() {
616 616
 		add_filter(
617 617
 		    'the_content',
618
-            array( 'EED_Events_Archive', 'event_datetimes' ),
618
+            array('EED_Events_Archive', 'event_datetimes'),
619 619
             EED_Events_Archive::EVENT_DATETIMES_PRIORITY
620 620
         );
621 621
 		add_filter(
622 622
 		    'the_content',
623
-            array( 'EED_Events_Archive', 'event_tickets' ),
623
+            array('EED_Events_Archive', 'event_tickets'),
624 624
             EED_Events_Archive::EVENT_TICKETS_PRIORITY
625 625
         );
626 626
 		add_filter(
627 627
 		    'the_content',
628
-            array( 'EED_Events_Archive', 'event_venues' ),
628
+            array('EED_Events_Archive', 'event_venues'),
629 629
             EED_Events_Archive::EVENT_VENUES_PRIORITY
630 630
         );
631 631
 	}
@@ -641,32 +641,32 @@  discard block
 block discarded – undo
641 641
 	private static function _remove_additional_events_archive_filters() {
642 642
 		remove_filter(
643 643
 		    'the_excerpt',
644
-            array( 'EED_Events_Archive', 'event_datetimes' ),
644
+            array('EED_Events_Archive', 'event_datetimes'),
645 645
             EED_Events_Archive::EVENT_DATETIMES_PRIORITY
646 646
         );
647 647
 		remove_filter(
648 648
 		    'the_excerpt',
649
-            array( 'EED_Events_Archive', 'event_tickets' ),
649
+            array('EED_Events_Archive', 'event_tickets'),
650 650
             EED_Events_Archive::EVENT_TICKETS_PRIORITY
651 651
         );
652 652
 		remove_filter(
653 653
 		    'the_excerpt',
654
-            array( 'EED_Events_Archive', 'event_venues' ),
654
+            array('EED_Events_Archive', 'event_venues'),
655 655
             EED_Events_Archive::EVENT_VENUES_PRIORITY
656 656
         );
657 657
 		remove_filter(
658 658
 		    'the_content',
659
-            array( 'EED_Events_Archive', 'event_datetimes' ),
659
+            array('EED_Events_Archive', 'event_datetimes'),
660 660
             EED_Events_Archive::EVENT_DATETIMES_PRIORITY
661 661
         );
662 662
 		remove_filter(
663 663
 		    'the_content',
664
-            array( 'EED_Events_Archive', 'event_tickets' ),
664
+            array('EED_Events_Archive', 'event_tickets'),
665 665
             EED_Events_Archive::EVENT_TICKETS_PRIORITY
666 666
         );
667 667
 		remove_filter(
668 668
 		    'the_content',
669
-            array( 'EED_Events_Archive', 'event_venues' ),
669
+            array('EED_Events_Archive', 'event_venues'),
670 670
             EED_Events_Archive::EVENT_VENUES_PRIORITY
671 671
         );
672 672
 	}
@@ -681,45 +681,45 @@  discard block
 block discarded – undo
681 681
 	 */
682 682
 	public static function remove_all_events_archive_filters() {
683 683
 		//remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
684
-		remove_filter( 'the_title', array( 'EED_Events_Archive', 'the_title' ), 1 );
684
+		remove_filter('the_title', array('EED_Events_Archive', 'the_title'), 1);
685 685
 		remove_filter(
686 686
 		    'the_excerpt',
687
-            array( 'EED_Events_Archive', 'event_details' ),
687
+            array('EED_Events_Archive', 'event_details'),
688 688
             EED_Events_Archive::EVENT_DETAILS_PRIORITY
689 689
         );
690 690
 		remove_filter(
691 691
 		    'the_excerpt',
692
-            array( 'EED_Events_Archive', 'event_datetimes' ),
692
+            array('EED_Events_Archive', 'event_datetimes'),
693 693
             EED_Events_Archive::EVENT_DATETIMES_PRIORITY
694 694
         );
695 695
 		remove_filter(
696 696
 		    'the_excerpt',
697
-            array( 'EED_Events_Archive', 'event_tickets' ),
697
+            array('EED_Events_Archive', 'event_tickets'),
698 698
             EED_Events_Archive::EVENT_TICKETS_PRIORITY
699 699
         );
700 700
 		remove_filter(
701 701
 		    'the_excerpt',
702
-            array( 'EED_Events_Archive', 'event_venues' ),
702
+            array('EED_Events_Archive', 'event_venues'),
703 703
             EED_Events_Archive::EVENT_VENUES_PRIORITY
704 704
         );
705 705
 		remove_filter(
706 706
 		    'the_content',
707
-            array( 'EED_Events_Archive', 'event_details' ),
707
+            array('EED_Events_Archive', 'event_details'),
708 708
             EED_Events_Archive::EVENT_DETAILS_PRIORITY
709 709
         );
710 710
 		remove_filter(
711 711
 		    'the_content',
712
-            array( 'EED_Events_Archive', 'event_datetimes' ),
712
+            array('EED_Events_Archive', 'event_datetimes'),
713 713
             EED_Events_Archive::EVENT_DATETIMES_PRIORITY
714 714
         );
715 715
 		remove_filter(
716 716
 		    'the_content',
717
-            array( 'EED_Events_Archive', 'event_tickets' ),
717
+            array('EED_Events_Archive', 'event_tickets'),
718 718
             EED_Events_Archive::EVENT_TICKETS_PRIORITY
719 719
         );
720 720
 		remove_filter(
721 721
 		    'the_content',
722
-            array( 'EED_Events_Archive', 'event_venues' ),
722
+            array('EED_Events_Archive', 'event_venues'),
723 723
             EED_Events_Archive::EVENT_VENUES_PRIORITY
724 724
         );
725 725
 		// don't display entry meta because the existing theme will take care of that
@@ -741,12 +741,12 @@  discard block
 block discarded – undo
741 741
 	 *  @return 	void
742 742
 	 */
743 743
 	public function load_event_list_assets() {
744
-        do_action( 'AHEE__EED_Events_Archive__before_load_assets' );
745
-		add_filter( 'FHEE_load_EE_Session', '__return_true' );
746
-		add_filter( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true' );
747
-		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 );
748
-		if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) {
749
-			add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 );
744
+        do_action('AHEE__EED_Events_Archive__before_load_assets');
745
+		add_filter('FHEE_load_EE_Session', '__return_true');
746
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
747
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
748
+		if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
749
+			add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
750 750
 		}
751 751
 	}
752 752
 
@@ -763,13 +763,13 @@  discard block
 block discarded – undo
763 763
 	 */
764 764
 	public function wp_enqueue_scripts() {
765 765
 		// get some style
766
-		if ( apply_filters( 'FHEE_enable_default_espresso_css', FALSE ) ) {
766
+		if (apply_filters('FHEE_enable_default_espresso_css', FALSE)) {
767 767
 			// first check uploads folder
768
-			if ( EEH_File::is_readable( get_stylesheet_directory() . $this->theme . DS . 'style.css' )) {
769
-				wp_register_style( $this->theme, get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', array( 'dashicons', 'espresso_default' ));
768
+			if (EEH_File::is_readable(get_stylesheet_directory().$this->theme.DS.'style.css')) {
769
+				wp_register_style($this->theme, get_stylesheet_directory_uri().$this->theme.DS.'style.css', array('dashicons', 'espresso_default'));
770 770
 			} else {
771 771
 		}
772
-		wp_enqueue_style( $this->theme );
772
+		wp_enqueue_style($this->theme);
773 773
 
774 774
 	}
775 775
 }
@@ -787,8 +787,8 @@  discard block
 block discarded – undo
787 787
 	 */
788 788
 	public static function template_settings_form() {
789 789
 	$template_settings = EE_Registry::instance()->CFG->template_settings;
790
-	$template_settings->EED_Events_Archive = isset( $template_settings->EED_Events_Archive ) ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config();
791
-	$template_settings->EED_Events_Archive = apply_filters( 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', $template_settings->EED_Events_Archive );
790
+	$template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive) ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config();
791
+	$template_settings->EED_Events_Archive = apply_filters('FHEE__EED_Events_Archive__template_settings_form__event_list_config', $template_settings->EED_Events_Archive);
792 792
 	$events_archive_settings = array(
793 793
 		'display_status_banner' => 0,
794 794
 		'display_description' => 1,
@@ -797,8 +797,8 @@  discard block
 block discarded – undo
797 797
 		'display_venue' => 0,
798 798
 		'display_expired_events' => 0
799 799
 	);
800
-	$events_archive_settings = array_merge( $events_archive_settings, (array)$template_settings->EED_Events_Archive );
801
-	EEH_Template::display_template( EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $events_archive_settings );
800
+	$events_archive_settings = array_merge($events_archive_settings, (array) $template_settings->EED_Events_Archive);
801
+	EEH_Template::display_template(EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php', $events_archive_settings);
802 802
 }
803 803
 
804 804
 
@@ -814,16 +814,16 @@  discard block
 block discarded – undo
814 814
 	 *  @param 	EE_Request_Handler $REQ
815 815
 	 *  @return 	EE_Template_Config
816 816
 	 */
817
-	public static function update_template_settings( $CFG, $REQ ) {
817
+	public static function update_template_settings($CFG, $REQ) {
818 818
 		$CFG->EED_Events_Archive = new EE_Events_Archive_Config();
819 819
 		// unless we are resetting the config...
820
-		if ( ! isset( $REQ['EED_Events_Archive_reset_event_list_settings'] ) || absint( $REQ['EED_Events_Archive_reset_event_list_settings'] ) !== 1 ) {
821
-			$CFG->EED_Events_Archive->display_status_banner = isset( $REQ['EED_Events_Archive_display_status_banner'] ) ? absint( $REQ['EED_Events_Archive_display_status_banner'] ) : 0;
822
-			$CFG->EED_Events_Archive->display_description = isset( $REQ['EED_Events_Archive_display_description'] ) ? absint( $REQ['EED_Events_Archive_display_description'] ) : 1;
823
-			$CFG->EED_Events_Archive->display_ticket_selector = isset( $REQ['EED_Events_Archive_display_ticket_selector'] ) ? absint( $REQ['EED_Events_Archive_display_ticket_selector'] ) : 0;
824
-			$CFG->EED_Events_Archive->display_datetimes = isset( $REQ['EED_Events_Archive_display_datetimes'] ) ? absint( $REQ['EED_Events_Archive_display_datetimes'] ) : 1;
825
-			$CFG->EED_Events_Archive->display_venue = isset( $REQ['EED_Events_Archive_display_venue'] ) ? absint( $REQ['EED_Events_Archive_display_venue'] ) : 0;
826
-			$CFG->EED_Events_Archive->display_expired_events = isset( $REQ['EED_Events_Archive_display_expired_events'] ) ? absint( $REQ['EED_Events_Archive_display_expired_events'] ) : 0;			}
820
+		if ( ! isset($REQ['EED_Events_Archive_reset_event_list_settings']) || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1) {
821
+			$CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0;
822
+			$CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description']) ? absint($REQ['EED_Events_Archive_display_description']) : 1;
823
+			$CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0;
824
+			$CFG->EED_Events_Archive->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint($REQ['EED_Events_Archive_display_datetimes']) : 1;
825
+			$CFG->EED_Events_Archive->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint($REQ['EED_Events_Archive_display_venue']) : 0;
826
+			$CFG->EED_Events_Archive->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events']) ? absint($REQ['EED_Events_Archive_display_expired_events']) : 0; }
827 827
 		return $CFG;
828 828
 	}
829 829
 
@@ -836,10 +836,10 @@  discard block
 block discarded – undo
836 836
 	 * @param string $extra_class
837 837
 	 * @return    string
838 838
 	 */
839
-	public static function event_list_css( $extra_class = '' ) {
840
-		$event_list_css = ! empty( $extra_class ) ? array( $extra_class ) : array();
839
+	public static function event_list_css($extra_class = '') {
840
+		$event_list_css = ! empty($extra_class) ? array($extra_class) : array();
841 841
 		$event_list_css[] = 'espresso-event-list-event';
842
-		return implode( ' ', $event_list_css );
842
+		return implode(' ', $event_list_css);
843 843
 	}
844 844
 
845 845
 
@@ -866,9 +866,9 @@  discard block
 block discarded – undo
866 866
 	 * @param $value
867 867
 	 * @return    bool
868 868
 	 */
869
-	public static function display_description( $value ) {
869
+	public static function display_description($value) {
870 870
 		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
871
-		$display_description= isset( $config->display_description ) ? $config->display_description : 1;
871
+		$display_description = isset($config->display_description) ? $config->display_description : 1;
872 872
 		return $display_description === $value ? TRUE : FALSE;
873 873
 	}
874 874
 
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
 	 */
882 882
 	public static function display_ticket_selector() {
883 883
 		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
884
-		return isset( $config->display_ticket_selector ) && $config->display_ticket_selector ? TRUE : FALSE;
884
+		return isset($config->display_ticket_selector) && $config->display_ticket_selector ? TRUE : FALSE;
885 885
 	}
886 886
 
887 887
 
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
 	 */
895 895
 	public static function display_venue() {
896 896
 		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
897
-		return isset( $config->display_venue ) && $config->display_venue && EEH_Venue_View::venue_name() ? TRUE : FALSE;
897
+		return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name() ? TRUE : FALSE;
898 898
 	}
899 899
 
900 900
 
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
 	 */
907 907
 	public static function display_datetimes() {
908 908
 		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
909
-		return isset( $config->display_datetimes ) && $config->display_datetimes ? TRUE : FALSE;
909
+		return isset($config->display_datetimes) && $config->display_datetimes ? TRUE : FALSE;
910 910
 }
911 911
 
912 912
 
@@ -921,7 +921,7 @@  discard block
 block discarded – undo
921 921
 	 *  @return 	string
922 922
 	 */
923 923
 	public static function event_list_title() {
924
-		return apply_filters( 'FHEE__archive_espresso_events_template__upcoming_events_h1', __( 'Upcoming Events', 'event_espresso' ));
924
+		return apply_filters('FHEE__archive_espresso_events_template__upcoming_events_h1', __('Upcoming Events', 'event_espresso'));
925 925
 	}
926 926
 
927 927
 
@@ -930,11 +930,11 @@  discard block
 block discarded – undo
930 930
 	/**
931 931
 	 * 	@since 4.4.0
932 932
 	 */
933
-	public static function _doing_it_wrong_notice( $function = '' ) {
933
+	public static function _doing_it_wrong_notice($function = '') {
934 934
 		EE_Error::doing_it_wrong(
935 935
 			__FUNCTION__,
936 936
 			sprintf(
937
-				__( 'EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s', 'event_espresso' ),
937
+				__('EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s', 'event_espresso'),
938 938
 				$function,
939 939
 				'<br />',
940 940
 				'4.6.0'
@@ -956,89 +956,89 @@  discard block
 block discarded – undo
956 956
 	 * 	@deprecated
957 957
 	 * 	@since 4.4.0
958 958
 	 */
959
-	public function posts_fields( $SQL, WP_Query $wp_query ) {
960
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
961
-		return EEH_Event_Query::posts_fields( $SQL, $wp_query );
959
+	public function posts_fields($SQL, WP_Query $wp_query) {
960
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
961
+		return EEH_Event_Query::posts_fields($SQL, $wp_query);
962 962
 	}
963 963
 	/**
964 964
 	 * 	@deprecated
965 965
 	 * 	@since 4.4.0
966 966
 	 */
967
-	public static function posts_fields_sql_for_orderby( $orderby_params = array() ) {
968
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
969
-		return EEH_Event_Query::posts_fields_sql_for_orderby( $orderby_params );
967
+	public static function posts_fields_sql_for_orderby($orderby_params = array()) {
968
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
969
+		return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params);
970 970
 	}
971 971
 	/**
972 972
 	 * 	@deprecated
973 973
 	 * 	@since 4.4.0
974 974
 	 */
975
-	public function posts_join( $SQL, WP_Query $wp_query ) {
976
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
977
-		return EEH_Event_Query::posts_join( $SQL, $wp_query );
975
+	public function posts_join($SQL, WP_Query $wp_query) {
976
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
977
+		return EEH_Event_Query::posts_join($SQL, $wp_query);
978 978
 	}
979 979
 	/**
980 980
 	 * 	@deprecated
981 981
 	 * 	@since 4.4.0
982 982
 	 */
983
-	public static function posts_join_sql_for_terms( $join_terms = NULL ) {
984
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
985
-		return EEH_Event_Query::posts_join_sql_for_terms( $join_terms );
983
+	public static function posts_join_sql_for_terms($join_terms = NULL) {
984
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
985
+		return EEH_Event_Query::posts_join_sql_for_terms($join_terms);
986 986
 	}
987 987
 	/**
988 988
 	 * 	@deprecated
989 989
 	 * 	@since 4.4.0
990 990
 	 */
991
-	public static function posts_join_for_orderby( $orderby_params = array() ) {
992
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
993
-		return EEH_Event_Query::posts_join_for_orderby( $orderby_params );
991
+	public static function posts_join_for_orderby($orderby_params = array()) {
992
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
993
+		return EEH_Event_Query::posts_join_for_orderby($orderby_params);
994 994
 	}
995 995
 	/**
996 996
 	 * 	@deprecated
997 997
 	 * 	@since 4.4.0
998 998
 	 */
999
-	public function posts_where( $SQL, WP_Query $wp_query ) {
1000
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
1001
-		return EEH_Event_Query::posts_where( $SQL, $wp_query );
999
+	public function posts_where($SQL, WP_Query $wp_query) {
1000
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1001
+		return EEH_Event_Query::posts_where($SQL, $wp_query);
1002 1002
 	}
1003 1003
 	/**
1004 1004
 	 * 	@deprecated
1005 1005
 	 * 	@since 4.4.0
1006 1006
 	 */
1007
-	public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) {
1008
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
1009
-		return EEH_Event_Query::posts_where_sql_for_show_expired( $show_expired );
1007
+	public static function posts_where_sql_for_show_expired($show_expired = FALSE) {
1008
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1009
+		return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired);
1010 1010
 	}
1011 1011
 	/**
1012 1012
 	 * 	@deprecated
1013 1013
 	 * 	@since 4.4.0
1014 1014
 	 */
1015
-	public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) {
1016
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
1017
-		return EEH_Event_Query::posts_where_sql_for_event_category_slug( $event_category_slug );
1015
+	public static function posts_where_sql_for_event_category_slug($event_category_slug = NULL) {
1016
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1017
+		return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug);
1018 1018
 	}
1019 1019
 	/**
1020 1020
 	 * 	@deprecated
1021 1021
 	 * 	@since 4.4.0
1022 1022
 	 */
1023
-	public static function posts_where_sql_for_event_list_month( $month = NULL ) {
1024
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
1025
-		return EEH_Event_Query::posts_where_sql_for_event_list_month( $month );
1023
+	public static function posts_where_sql_for_event_list_month($month = NULL) {
1024
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1025
+		return EEH_Event_Query::posts_where_sql_for_event_list_month($month);
1026 1026
 	}
1027 1027
 	/**
1028 1028
 	 * 	@deprecated
1029 1029
 	 * 	@since 4.4.0
1030 1030
 	 */
1031
-	public function posts_orderby( $SQL, WP_Query $wp_query ) {
1032
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
1033
-		return EEH_Event_Query::posts_orderby( $SQL, $wp_query );
1031
+	public function posts_orderby($SQL, WP_Query $wp_query) {
1032
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1033
+		return EEH_Event_Query::posts_orderby($SQL, $wp_query);
1034 1034
 	}
1035 1035
 	/**
1036 1036
 	 * 	@deprecated
1037 1037
 	 * 	@since 4.4.0
1038 1038
 	 */
1039
-	public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) {
1040
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
1041
-		return EEH_Event_Query::posts_orderby_sql( $orderby_params, $sort );
1039
+	public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') {
1040
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1041
+		return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort);
1042 1042
 	}
1043 1043
 
1044 1044
 
@@ -1069,8 +1069,8 @@  discard block
 block discarded – undo
1069 1069
  * @param string $extra_class
1070 1070
  * @return string
1071 1071
  */
1072
-function espresso_event_list_css( $extra_class = '' ) {
1073
-	return EED_Events_Archive::event_list_css( $extra_class );
1072
+function espresso_event_list_css($extra_class = '') {
1073
+	return EED_Events_Archive::event_list_css($extra_class);
1074 1074
 }
1075 1075
 
1076 1076
 /**
@@ -1084,14 +1084,14 @@  discard block
 block discarded – undo
1084 1084
  * @return bool
1085 1085
  */
1086 1086
 function espresso_display_full_description_in_event_list() {
1087
-	return EED_Events_Archive::display_description( 2 );
1087
+	return EED_Events_Archive::display_description(2);
1088 1088
 }
1089 1089
 
1090 1090
 /**
1091 1091
  * @return bool
1092 1092
  */
1093 1093
 function espresso_display_excerpt_in_event_list() {
1094
-	return EED_Events_Archive::display_description( 1 );
1094
+	return EED_Events_Archive::display_description(1);
1095 1095
 }
1096 1096
 
1097 1097
 /**
Please login to merge, or discard this patch.
core/CPTs/EE_Register_CPTs.core.php 1 patch
Indentation   +616 added lines, -616 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -14,604 +14,604 @@  discard block
 block discarded – undo
14 14
 class EE_Register_CPTs
15 15
 {
16 16
 
17
-    /**
18
-     * This property is used to hold an array of EE_default_term objects assigned to a custom post type when the post
19
-     * for that post type is published with no terms set for the taxonomy.
20
-     *
21
-     * @var array of EE_Default_Term objects
22
-     */
23
-    protected $_default_terms = array();
24
-
25
-
26
-
27
-    /**
28
-     *    constructor
29
-     * instantiated at init priority 5
30
-     */
31
-    public function __construct()
32
-    {
33
-        // register taxonomies
34
-        $taxonomies = self::get_taxonomies();
35
-        foreach ($taxonomies as $taxonomy => $tax) {
36
-            $this->register_taxonomy($taxonomy, $tax['singular_name'], $tax['plural_name'], $tax['args']);
37
-        }
38
-        // register CPTs
39
-        $CPTs = self::get_CPTs();
40
-        foreach ($CPTs as $CPT_name => $CPT) {
41
-            $this->register_CPT($CPT_name, $CPT['singular_name'], $CPT['plural_name'], $CPT['args'],
42
-                $CPT['singular_slug'], $CPT['plural_slug']);
43
-        }
44
-        // setup default terms in any of our taxonomies (but only if we're in admin).
45
-        // Why not added via register_activation_hook?
46
-        // Because it's possible that in future iterations of EE we may add new defaults for specialized taxonomies
47
-        // (think event_types) and register_activation_hook only reliably runs when a user manually activates the plugin.
48
-        // Keep in mind that this will READ these terms if they are deleted by the user.  Hence MUST use terms.
49
-        // if ( is_admin() ) {
50
-        // 	$this->set_must_use_event_types();
51
-        // }
52
-        //set default terms
53
-        $this->set_default_term('espresso_event_type', 'single-event', array('espresso_events'));
54
-        add_action('AHEE__EE_System__initialize_last', array(__CLASS__, 'maybe_flush_rewrite_rules'), 10);
55
-        // hook into save_post so that we can make sure that the default terms get saved on publish of registered cpts
56
-        // IF they don't have a term for that taxonomy set.
57
-        add_action('save_post', array($this, 'save_default_term'), 100, 2);
58
-        // remove no html restrictions from core wp saving of term descriptions.
59
-        // Note. this will affect only registered EE taxonomies.
60
-        $this->_allow_html_descriptions_for_ee_taxonomies();
61
-        do_action('AHEE__EE_Register_CPTs__construct_end', $this);
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
68
-     *
69
-     * @since 4.5.0
70
-     * @return void
71
-     */
72
-    public static function maybe_flush_rewrite_rules()
73
-    {
74
-        if (get_option('ee_flush_rewrite_rules', true)) {
75
-            flush_rewrite_rules();
76
-            update_option('ee_flush_rewrite_rules', false);
77
-        }
78
-    }
79
-
80
-
81
-
82
-    /**
83
-     * By default, WordPress strips all html from term taxonomy description content.  The purpose of this method is to
84
-     * remove that restriction and ensure that we still run ee term taxonomy descriptions through some full html
85
-     * sanitization equivalent to the post content field.
86
-     *
87
-     * @since 4.7.8
88
-     */
89
-    protected function _allow_html_descriptions_for_ee_taxonomies()
90
-    {
91
-        // first remove default filter for term description but we have to do this earlier
92
-        // before wp sets their own filter
93
-        // because they just set a global filter on all term descriptions before the custom term description filter.
94
-        // Really sux.
95
-        add_filter('pre_term_description', array($this, 'ee_filter_ee_term_description_not_wp'), 1, 2);
96
-    }
97
-
98
-
99
-
100
-    /**
101
-     * Callback for pre_term_description hook.
102
-     *
103
-     * @param string $description The description content.
104
-     * @param string $taxonomy    The taxonomy name for the taxonomy being filtered.
105
-     * @return string
106
-     */
107
-    public function ee_filter_ee_term_description_not_wp($description, $taxonomy)
108
-    {
109
-        //get a list of EE taxonomies
110
-        $ee_taxonomies = array_keys(self::get_taxonomies());
111
-        //only do our own thing if the taxonomy listed is an ee taxonomy.
112
-        if (in_array($taxonomy, $ee_taxonomies, true)) {
113
-            //remove default wp filter
114
-            remove_filter('pre_term_description', 'wp_filter_kses');
115
-            //sanitize THIS content.
116
-            $description = wp_kses($description, wp_kses_allowed_html('post'));
117
-        }
118
-        return $description;
119
-    }
120
-
121
-
122
-
123
-    /**
124
-     *    get_taxonomies
125
-     *
126
-     * @access    public
127
-     * @return    array
128
-     */
129
-    public static function get_taxonomies()
130
-    {
131
-        // define taxonomies
132
-        return apply_filters('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array(
133
-            'espresso_event_categories' => array(
134
-                'singular_name' => __("Event Category", "event_espresso"),
135
-                'plural_name'   => __("Event Categories", "event_espresso"),
136
-                'args'          => array(
137
-                    'public'            => true,
138
-                    'show_in_nav_menus' => true,
139
-                    'show_in_rest'      => true,
140
-                    'capabilities'      => array(
141
-                        'manage_terms' => 'ee_manage_event_categories',
142
-                        'edit_terms'   => 'ee_edit_event_category',
143
-                        'delete_terms' => 'ee_delete_event_category',
144
-                        'assign_terms' => 'ee_assign_event_category',
145
-                    ),
146
-                    'rewrite'           => array('slug' => __('event-category', 'event_espresso')),
147
-                ),
148
-            ),
149
-            'espresso_venue_categories' => array(
150
-                'singular_name' => __("Venue Category", "event_espresso"),
151
-                'plural_name'   => __("Venue Categories", "event_espresso"),
152
-                'args'          => array(
153
-                    'public'            => true,
154
-                    'show_in_nav_menus' => false, //by default this doesn't show for decaf
155
-                    'show_in_rest'      => true,
156
-                    'capabilities'      => array(
157
-                        'manage_terms' => 'ee_manage_venue_categories',
158
-                        'edit_terms'   => 'ee_edit_venue_category',
159
-                        'delete_terms' => 'ee_delete_venue_category',
160
-                        'assign_terms' => 'ee_assign_venue_category',
161
-                    ),
162
-                    'rewrite'           => array('slug' => __('venue-category', 'event_espresso')),
163
-                ),
164
-            ),
165
-            'espresso_event_type'       => array(
166
-                'singular_name' => __("Event Type", "event_espresso"),
167
-                'plural_name'   => __("Event Types", "event_espresso"),
168
-                'args'          => array(
169
-                    'public'       => true,
170
-                    'show_ui'      => false,
171
-                    'show_in_rest' => true,
172
-                    'capabilities' => array(
173
-                        'manage_terms' => 'ee_read_event_type',
174
-                        'edit_terms'   => 'ee_edit_event_type',
175
-                        'delete_terms' => 'ee_delete_event_type',
176
-                        'assign_terms' => 'ee_assign_event_type',
177
-                    ),
178
-                    'rewrite'      => array('slug' => __('event-type', 'event_espresso')),
179
-                    'hierarchical' => true,
180
-                ),
181
-            ),
182
-        ));
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * This returns the corresponding model name for cpts registered by EE.
189
-     *
190
-     * @since 4.6.16.rc.000
191
-     * @param string $post_type_slug              If a slug is included, then attempt to retrieve the model name for
192
-     *                                            the given cpt slug.  Otherwise if empty, then we'll return all cpt
193
-     *                                            model names for cpts registered in EE.
194
-     * @return array           Empty array if no matching model names for the given slug or an array of model
195
-     *                                            names indexed by post type slug.
196
-     */
197
-    public static function get_cpt_model_names($post_type_slug = '')
198
-    {
199
-        $cpts = self::get_CPTs();
200
-        //first if slug passed in...
201
-        if ( ! empty($post_type_slug)) {
202
-            //match?
203
-            if (
204
-                ! isset($cpts[$post_type_slug])
205
-                || (isset($cpts[$post_type_slug]) && empty($cpts[$post_type_slug]['class_name']))
206
-            ) {
207
-                return array();
208
-            }
209
-            //k let's get the model name for this cpt.
210
-            return array($post_type_slug => str_replace('EE', 'EEM', $cpts[$post_type_slug]['class_name']));
211
-        }
212
-        //if we made it here then we're returning an array of cpt model names indexed by post_type_slug.
213
-        $cpt_models = array();
214
-        foreach ($cpts as $slug => $args) {
215
-            if ( ! empty($args['class_name'])) {
216
-                $cpt_models[$slug] = str_replace('EE', 'EEM', $args['class_name']);
217
-            }
218
-        }
219
-        return $cpt_models;
220
-    }
221
-
222
-
223
-
224
-    /**
225
-     * This instantiates cpt models related to the cpts registered via EE.
226
-     *
227
-     * @since 4.6.16.rc.000
228
-     * @param string $post_type_slug If valid slug is provided, then will instantiate the model only for
229
-     *                               the cpt matching the given slug.  Otherwise all cpt models will be
230
-     *                               instantiated (if possible).
231
-     * @return EEM_CPT_Base[]        successful instantiation will return an array of successfully instantiated
232
-     *                               EEM models indexed by post slug.
233
-     */
234
-    public static function instantiate_cpt_models($post_type_slug = '')
235
-    {
236
-        $cpt_model_names = self::get_cpt_model_names($post_type_slug);
237
-        $instantiated = array();
238
-        foreach ($cpt_model_names as $slug => $model_name) {
239
-            $instance = EE_Registry::instance()->load_model(str_replace('EEM_', '', $model_name));
240
-            if ($instance instanceof EEM_CPT_Base) {
241
-                $instantiated[$slug] = $instance;
242
-            }
243
-        }
244
-        return $instantiated;
245
-    }
246
-
247
-
248
-
249
-    /**
250
-     *    get_CPTs
251
-     *
252
-     * @access    public
253
-     * @return    array
254
-     */
255
-    public static function get_CPTs()
256
-    {
257
-        // define CPTs
258
-        // NOTE the ['args']['page_templates'] array index is something specific to our CPTs
259
-        // and not part of the WP custom post type api.
260
-        return apply_filters('FHEE__EE_Register_CPTs__get_CPTs__cpts', array(
261
-            'espresso_events'    => array(
262
-                'singular_name' => __("Event", "event_espresso"),
263
-                'plural_name'   => __("Events", "event_espresso"),
264
-                'singular_slug' => __("event", "event_espresso"),
265
-                'plural_slug'   => EE_Registry::instance()->CFG->core->event_cpt_slug,
266
-                'class_name'    => 'EE_Event',
267
-                'args'          => array(
268
-                    'public'            => true,
269
-                    'show_in_nav_menus' => true,
270
-                    'capability_type'   => 'event',
271
-                    'capabilities'      => array(
272
-                        'edit_post'              => 'ee_edit_event',
273
-                        'read_post'              => 'ee_read_event',
274
-                        'delete_post'            => 'ee_delete_event',
275
-                        'edit_posts'             => 'ee_edit_events',
276
-                        'edit_others_posts'      => 'ee_edit_others_events',
277
-                        'publish_posts'          => 'ee_publish_events',
278
-                        'read_private_posts'     => 'ee_read_private_events',
279
-                        'delete_posts'           => 'ee_delete_events',
280
-                        'delete_private_posts'   => 'ee_delete_private_events',
281
-                        'delete_published_posts' => 'ee_delete_published_events',
282
-                        'delete_others_posts'    => 'ee_delete_others_events',
283
-                        'edit_private_posts'     => 'ee_edit_private_events',
284
-                        'edit_published_posts'   => 'ee_edit_published_events',
285
-                    ),
286
-                    'taxonomies'        => array(
287
-                        'espresso_event_categories',
288
-                        'espresso_event_type',
289
-                        'post_tag',
290
-                    ),
291
-                    'page_templates'    => true,
292
-                ),
293
-            ),
294
-            'espresso_venues'    => array(
295
-                'singular_name' => __("Venue", "event_espresso"),
296
-                'plural_name'   => __("Venues", "event_espresso"),
297
-                'singular_slug' => __("venue", "event_espresso"),
298
-                'plural_slug'   => __("venues", "event_espresso"),
299
-                'class_name'    => 'EE_Venue',
300
-                'args'          => array(
301
-                    'public'            => true,
302
-                    'show_in_nav_menus' => false, //by default this doesn't show for decaf,
303
-                    'capability_type'   => 'venue',
304
-                    'capabilities'      => array(
305
-                        'edit_post'              => 'ee_edit_venue',
306
-                        'read_post'              => 'ee_read_venue',
307
-                        'delete_post'            => 'ee_delete_venue',
308
-                        'edit_posts'             => 'ee_edit_venues',
309
-                        'edit_others_posts'      => 'ee_edit_others_venues',
310
-                        'publish_posts'          => 'ee_publish_venues',
311
-                        'read_private_posts'     => 'ee_read_private_venues',
312
-                        'delete_posts'           => 'ee_delete_venues',
313
-                        'delete_private_posts'   => 'ee_delete_private_venues',
314
-                        'delete_published_posts' => 'ee_delete_published_venues',
315
-                        'delete_others_posts'    => 'ee_edit_others_venues',
316
-                        'edit_private_posts'     => 'ee_edit_private_venues',
317
-                        'edit_published_posts'   => 'ee_edit_published_venues',
318
-                    ),
319
-                    'taxonomies'        => array(
320
-                        'espresso_venue_categories',
321
-                        'post_tag',
322
-                    ),
323
-                    'page_templates'    => true,
324
-                ),
325
-            ),
326
-            'espresso_attendees' => array(
327
-                'singular_name' => __("Contact", "event_espresso"),
328
-                'plural_name'   => __("Contacts", "event_espresso"),
329
-                'singular_slug' => __("contact", "event_espresso"),
330
-                'plural_slug'   => __("contacts", "event_espresso"),
331
-                'class_name'    => 'EE_Attendee',
332
-                'args'          => array(
333
-                    'public'             => false,
334
-                    'publicly_queryable' => false,
335
-                    'hierarchical'       => false,
336
-                    'has_archive'        => false,
337
-                    'taxonomies'         => array('post_tag'),
338
-                    'capability_type'    => 'contact',
339
-                    'capabilities'       => array(
340
-                        'edit_post'              => 'ee_edit_contact',
341
-                        'read_post'              => 'ee_read_contact',
342
-                        'delete_post'            => 'ee_delete_contact',
343
-                        'edit_posts'             => 'ee_edit_contacts',
344
-                        'edit_others_posts'      => 'ee_edit_contacts',
345
-                        'publish_posts'          => 'ee_edit_contacts',
346
-                        'read_private_posts'     => 'ee_edit_contacts',
347
-                        'delete_posts'           => 'ee_delete_contacts',
348
-                        'delete_private_posts'   => 'ee_delete_contacts',
349
-                        'delete_published_posts' => 'ee_delete_contacts',
350
-                        'delete_others_posts'    => 'ee_delete_contacts',
351
-                        'edit_private_posts'     => 'ee_edit_contacts',
352
-                        'edit_published_posts'   => 'ee_edit_contacts',
353
-                    ),
354
-                    'supports'           => array('editor', 'thumbnail', 'excerpt', 'custom-fields', 'comments'),
355
-                ),
356
-            ),
357
-        ));
358
-    }
359
-
360
-
361
-
362
-    /**
363
-     * This basically goes through the CPT array and returns only CPT's
364
-     * that have the ['args']['public'] option set as false
365
-     *
366
-     * @return array
367
-     */
368
-    public static function get_private_CPTs()
369
-    {
370
-        $CPTs = self::get_CPTs();
371
-        $private_CPTs = array();
372
-        foreach ($CPTs as $CPT => $details) {
373
-            if (empty($details['args']['public'])) {
374
-                $private_CPTs[$CPT] = $details;
375
-            }
376
-        }
377
-        return $private_CPTs;
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     * Registers a custom taxonomy. Should be called before registering custom post types,
384
-     * otherwise you should link the taxonomy to the custom post type using 'register_taxonomy_for_object_type'.
385
-     *
386
-     * @param string $taxonomy_name , eg 'books'
387
-     * @param string $singular_name internationalized singular name
388
-     * @param string $plural_name   internationalized plural name
389
-     * @param array  $override_args like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy
390
-     */
391
-    public function register_taxonomy($taxonomy_name, $singular_name, $plural_name, $override_args = array())
392
-    {
393
-        $args = array(
394
-            'hierarchical'      => true,
395
-            'labels'            => array(
396
-                'name'          => $plural_name,
397
-                'singular_name' => $singular_name,
398
-            ),
399
-            'show_ui'           => true,
400
-            'show_ee_ui'        => true,
401
-            'show_admin_column' => true,
402
-            'query_var'         => true,
403
-            'show_in_nav_menus' => false,
404
-            'map_meta_cap'      => true
405
-            //'rewrite'           => array( 'slug' => 'genre' ),
406
-        );
407
-        if ($override_args) {
408
-            if (isset($override_args['labels'])) {
409
-                $labels = array_merge($args['labels'], $override_args['labels']);
410
-                $args['labels'] = $labels;
411
-            }
412
-            $args = array_merge($args, $override_args);
413
-        }
414
-        register_taxonomy($taxonomy_name, null, $args);
415
-    }
416
-
417
-
418
-
419
-    /**
420
-     * Registers a new custom post type. Sets default settings given only the following params.
421
-     *
422
-     * @param string $post_type     the actual post type name
423
-     *                              (VERY IMPORTANT: this much match what the slug is for admin pages related to this
424
-     *                              cpt Also any models must use this slug as well)
425
-     * @param string $singular_name a pre-internationalized string for the singular name of the objects
426
-     * @param string $plural_name   a pre-internalized string for the plural name of the objects
427
-     * @param array  $override_args exactly like $args as described in
428
-     *                              http://codex.wordpress.org/Function_Reference/register_post_type The default values
429
-     *                              set in this function will be overridden by whatever you set in $override_args
430
-     * @param string $singular_slug
431
-     * @param string $plural_slug
432
-     * @return void , but registers the custom post type
433
-     */
434
-    public function register_CPT(
435
-        $post_type,
436
-        $singular_name,
437
-        $plural_name,
438
-        $override_args = array(),
439
-        $singular_slug = '',
440
-        $plural_slug = ''
441
-    ) {
442
-        $labels = array(
443
-            'name'               => $plural_name,
444
-            'singular_name'      => $singular_name,
445
-            'singular_slug'      => $singular_slug,
446
-            'plural_slug'        => $plural_slug,
447
-            'add_new'            => sprintf(__("Add %s", "event_espresso"), $singular_name),
448
-            'add_new_item'       => sprintf(__("Add New %s", "event_espresso"), $singular_name),
449
-            'edit_item'          => sprintf(__("Edit %s", "event_espresso"), $singular_name),
450
-            'new_item'           => sprintf(__("New %s", "event_espresso"), $singular_name),
451
-            'all_items'          => sprintf(__("All %s", "event_espresso"), $plural_name),
452
-            'view_item'          => sprintf(__("View %s", "event_espresso"), $singular_name),
453
-            'search_items'       => sprintf(__("Search %s", "event_espresso"), $plural_name),
454
-            'not_found'          => sprintf(__("No %s found", "event_espresso"), $plural_name),
455
-            'not_found_in_trash' => sprintf(__("No %s found in Trash", "event_espresso"), $plural_name),
456
-            'parent_item_colon'  => '',
457
-            'menu_name'          => sprintf(__("%s", "event_espresso"), $plural_name),
458
-        );
459
-        //verify plural slug and singular slug, if they aren't we'll use $singular_name and $plural_name
460
-        // $singular_slug = ! empty($singular_slug) ? $singular_slug : $singular_name;
461
-        $plural_slug = ! empty($plural_slug) ? $plural_slug : $plural_name;
462
-        //note the page_templates arg in the supports index is something specific to EE.
463
-        //  WordPress doesn't actually have that in their register_post_type api.
464
-        $args = array(
465
-            'labels'             => $labels,
466
-            'public'             => true,
467
-            'publicly_queryable' => true,
468
-            'show_ui'            => false,
469
-            'show_ee_ui'         => true,
470
-            'show_in_menu'       => false,
471
-            'show_in_nav_menus'  => false,
472
-            'query_var'          => true,
473
-            'rewrite'            => apply_filters(
474
-                'FHEE__EE_Register_CPTs__register_CPT__rewrite',
475
-                array('slug' => $plural_slug),
476
-                $post_type
477
-            ),
478
-            'capability_type'    => 'post',
479
-            'map_meta_cap'       => true,
480
-            'has_archive'        => true,
481
-            'hierarchical'       => false,
482
-            'menu_position'      => null,
483
-            'supports'           => array(
484
-                'title',
485
-                'editor',
486
-                'author',
487
-                'thumbnail',
488
-                'excerpt',
489
-                'custom-fields',
490
-                'comments',
491
-            ),
492
-        );
493
-        if ($override_args) {
494
-            if (isset($override_args['labels'])) {
495
-                $labels = array_merge($args['labels'], $override_args['labels']);
496
-            }
497
-            $args = array_merge($args, $override_args);
498
-            $args['labels'] = $labels;
499
-        }
500
-        register_post_type($post_type, $args);
501
-    }
502
-
503
-
504
-
505
-    public function set_must_use_event_types()
506
-    {
507
-        $term_details = array(
508
-            //Attendee's register for the first date-time only
509
-            'single-event'    => array(
510
-                __('Single Event', 'event_espresso'),
511
-                __('A single event that spans one or more consecutive days.', 'event_espresso'),
512
-            ),
513
-            //example: a party or two-day long workshop
514
-            //Attendee's can register for any of the date-times
515
-            'multi-event'     => array(
516
-                __('Multi Event', 'event_espresso'),
517
-                __('Multiple, separate, but related events that occur on consecutive days.', 'event_espresso'),
518
-            ),
519
-            //example: a three day music festival or week long conference
520
-            //Attendee's register for the first date-time only
521
-            'event-series'    => array(
522
-                __('Event Series', 'event_espresso'),
523
-                __(' Multiple events that occur over multiple non-consecutive days.', 'event_espresso'),
524
-            ),
525
-            //example: an 8 week introduction to basket weaving course
526
-            //Attendee's can register for any of the date-times.
527
-            'recurring-event' => array(
528
-                __('Recurring Event', 'event_espresso'),
529
-                __('Multiple events that occur over multiple non-consecutive days.', 'event_espresso'),
530
-            ),
531
-            //example: a yoga class
532
-            'ongoing' => array(
533
-                __('Ongoing Event', 'event_espresso'),
534
-                __('An "event" that people can purchase tickets to gain access for anytime for this event regardless of date times on the event',
535
-                    'event_espresso'),
536
-            )
537
-            //example: access to a museum
538
-            //'walk-in' => array( __('Walk In', 'event_espresso'), __('Single datetime and single entry recurring events. Attendees register for one or multiple datetimes individually.', 'event_espresso') ),
539
-            //'reservation' => array( __('Reservation', 'event_espresso'), __('Reservations are created by specifying available datetimes and quantities. Attendees choose from the available datetimes and specify the quantity available (if the maximum is greater than 1)') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1
540
-            // 'multiple-session' => array( __('Multiple Session', 'event_espresso'), __('Multiple event, multiple datetime, hierarchically organized, custom entry events. Attendees may be required to register for a parent event before being allowed to register for child events. Attendees can register for any combination of child events as long as the datetimes do not conflict. Parent and child events may have additional fees or registration questions.') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1
541
-            //'appointment' => array( __('Appointments', 'event_espresso'), __('Time slotted events where datetimes are generally in hours or minutes. For example, attendees can register for a single 15 minute or 1 hour time slot and this type of availability frequently reoccurs.', 'event_espresso') )
542
-        );
543
-        $this->set_must_use_terms('espresso_event_type', $term_details);
544
-    }
545
-
546
-
547
-
548
-    /**
549
-     * wrapper method for handling the setting up of initial terms in the db (if they don't already exist).
550
-     * Note this should ONLY be used for terms that always must be present.  Be aware that if an initial term is
551
-     * deleted then it WILL be recreated.
552
-     *
553
-     * @param string $taxonomy     The name of the taxonomy
554
-     * @param array  $term_details An array of term details indexed by slug and containing Name of term, and
555
-     *                             description as the elements in the array
556
-     * @return void
557
-     */
558
-    public function set_must_use_terms($taxonomy, $term_details)
559
-    {
560
-        $term_details = (array)$term_details;
561
-        foreach ($term_details as $slug => $details) {
562
-            if ( ! term_exists($slug, $taxonomy)) {
563
-                $insert_arr = array(
564
-                    'slug'        => $slug,
565
-                    'description' => $details[1],
566
-                );
567
-                wp_insert_term($details[0], $taxonomy, $insert_arr);
568
-            }
569
-        }
570
-    }
571
-
572
-
573
-
574
-    /**
575
-     * Allows us to set what the default will be for terms when a cpt is PUBLISHED.
576
-     *
577
-     * @param string $taxonomy  The taxonomy we're using for the default term
578
-     * @param string $term_slug The slug of the term that will be the default.
579
-     * @param array  $cpt_slugs An array of custom post types we want the default assigned to
580
-     */
581
-    public function set_default_term($taxonomy, $term_slug, $cpt_slugs = array())
582
-    {
583
-        $this->_default_terms[][$term_slug] = new EE_Default_Term($taxonomy, $term_slug, $cpt_slugs);
584
-    }
585
-
586
-
587
-
588
-    /**
589
-     * hooked into the wp 'save_post' action hook for setting our default terms found in the $_default_terms property
590
-     *
591
-     * @param  int    $post_id ID of CPT being saved
592
-     * @param  object $post    Post object
593
-     * @return void
594
-     */
595
-    public function save_default_term($post_id, $post)
596
-    {
597
-        if (empty($this->_default_terms)) {
598
-            return;
599
-        } //no default terms set so lets just exit.
600
-        foreach ($this->_default_terms as $defaults) {
601
-            foreach ($defaults as $default_obj) {
602
-                if ($post->post_status === 'publish' && in_array($post->post_type, $default_obj->cpt_slugs, true)) {
603
-                    //note some error proofing going on here to save unnecessary db queries
604
-                    $taxonomies = get_object_taxonomies($post->post_type);
605
-                    foreach ((array)$taxonomies as $taxonomy) {
606
-                        $terms = wp_get_post_terms($post_id, $taxonomy);
607
-                        if (empty($terms) && $taxonomy === $default_obj->taxonomy) {
608
-                            wp_set_object_terms($post_id, array($default_obj->term_slug), $taxonomy);
609
-                        }
610
-                    }
611
-                }
612
-            }
613
-        }
614
-    }
17
+	/**
18
+	 * This property is used to hold an array of EE_default_term objects assigned to a custom post type when the post
19
+	 * for that post type is published with no terms set for the taxonomy.
20
+	 *
21
+	 * @var array of EE_Default_Term objects
22
+	 */
23
+	protected $_default_terms = array();
24
+
25
+
26
+
27
+	/**
28
+	 *    constructor
29
+	 * instantiated at init priority 5
30
+	 */
31
+	public function __construct()
32
+	{
33
+		// register taxonomies
34
+		$taxonomies = self::get_taxonomies();
35
+		foreach ($taxonomies as $taxonomy => $tax) {
36
+			$this->register_taxonomy($taxonomy, $tax['singular_name'], $tax['plural_name'], $tax['args']);
37
+		}
38
+		// register CPTs
39
+		$CPTs = self::get_CPTs();
40
+		foreach ($CPTs as $CPT_name => $CPT) {
41
+			$this->register_CPT($CPT_name, $CPT['singular_name'], $CPT['plural_name'], $CPT['args'],
42
+				$CPT['singular_slug'], $CPT['plural_slug']);
43
+		}
44
+		// setup default terms in any of our taxonomies (but only if we're in admin).
45
+		// Why not added via register_activation_hook?
46
+		// Because it's possible that in future iterations of EE we may add new defaults for specialized taxonomies
47
+		// (think event_types) and register_activation_hook only reliably runs when a user manually activates the plugin.
48
+		// Keep in mind that this will READ these terms if they are deleted by the user.  Hence MUST use terms.
49
+		// if ( is_admin() ) {
50
+		// 	$this->set_must_use_event_types();
51
+		// }
52
+		//set default terms
53
+		$this->set_default_term('espresso_event_type', 'single-event', array('espresso_events'));
54
+		add_action('AHEE__EE_System__initialize_last', array(__CLASS__, 'maybe_flush_rewrite_rules'), 10);
55
+		// hook into save_post so that we can make sure that the default terms get saved on publish of registered cpts
56
+		// IF they don't have a term for that taxonomy set.
57
+		add_action('save_post', array($this, 'save_default_term'), 100, 2);
58
+		// remove no html restrictions from core wp saving of term descriptions.
59
+		// Note. this will affect only registered EE taxonomies.
60
+		$this->_allow_html_descriptions_for_ee_taxonomies();
61
+		do_action('AHEE__EE_Register_CPTs__construct_end', $this);
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
68
+	 *
69
+	 * @since 4.5.0
70
+	 * @return void
71
+	 */
72
+	public static function maybe_flush_rewrite_rules()
73
+	{
74
+		if (get_option('ee_flush_rewrite_rules', true)) {
75
+			flush_rewrite_rules();
76
+			update_option('ee_flush_rewrite_rules', false);
77
+		}
78
+	}
79
+
80
+
81
+
82
+	/**
83
+	 * By default, WordPress strips all html from term taxonomy description content.  The purpose of this method is to
84
+	 * remove that restriction and ensure that we still run ee term taxonomy descriptions through some full html
85
+	 * sanitization equivalent to the post content field.
86
+	 *
87
+	 * @since 4.7.8
88
+	 */
89
+	protected function _allow_html_descriptions_for_ee_taxonomies()
90
+	{
91
+		// first remove default filter for term description but we have to do this earlier
92
+		// before wp sets their own filter
93
+		// because they just set a global filter on all term descriptions before the custom term description filter.
94
+		// Really sux.
95
+		add_filter('pre_term_description', array($this, 'ee_filter_ee_term_description_not_wp'), 1, 2);
96
+	}
97
+
98
+
99
+
100
+	/**
101
+	 * Callback for pre_term_description hook.
102
+	 *
103
+	 * @param string $description The description content.
104
+	 * @param string $taxonomy    The taxonomy name for the taxonomy being filtered.
105
+	 * @return string
106
+	 */
107
+	public function ee_filter_ee_term_description_not_wp($description, $taxonomy)
108
+	{
109
+		//get a list of EE taxonomies
110
+		$ee_taxonomies = array_keys(self::get_taxonomies());
111
+		//only do our own thing if the taxonomy listed is an ee taxonomy.
112
+		if (in_array($taxonomy, $ee_taxonomies, true)) {
113
+			//remove default wp filter
114
+			remove_filter('pre_term_description', 'wp_filter_kses');
115
+			//sanitize THIS content.
116
+			$description = wp_kses($description, wp_kses_allowed_html('post'));
117
+		}
118
+		return $description;
119
+	}
120
+
121
+
122
+
123
+	/**
124
+	 *    get_taxonomies
125
+	 *
126
+	 * @access    public
127
+	 * @return    array
128
+	 */
129
+	public static function get_taxonomies()
130
+	{
131
+		// define taxonomies
132
+		return apply_filters('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array(
133
+			'espresso_event_categories' => array(
134
+				'singular_name' => __("Event Category", "event_espresso"),
135
+				'plural_name'   => __("Event Categories", "event_espresso"),
136
+				'args'          => array(
137
+					'public'            => true,
138
+					'show_in_nav_menus' => true,
139
+					'show_in_rest'      => true,
140
+					'capabilities'      => array(
141
+						'manage_terms' => 'ee_manage_event_categories',
142
+						'edit_terms'   => 'ee_edit_event_category',
143
+						'delete_terms' => 'ee_delete_event_category',
144
+						'assign_terms' => 'ee_assign_event_category',
145
+					),
146
+					'rewrite'           => array('slug' => __('event-category', 'event_espresso')),
147
+				),
148
+			),
149
+			'espresso_venue_categories' => array(
150
+				'singular_name' => __("Venue Category", "event_espresso"),
151
+				'plural_name'   => __("Venue Categories", "event_espresso"),
152
+				'args'          => array(
153
+					'public'            => true,
154
+					'show_in_nav_menus' => false, //by default this doesn't show for decaf
155
+					'show_in_rest'      => true,
156
+					'capabilities'      => array(
157
+						'manage_terms' => 'ee_manage_venue_categories',
158
+						'edit_terms'   => 'ee_edit_venue_category',
159
+						'delete_terms' => 'ee_delete_venue_category',
160
+						'assign_terms' => 'ee_assign_venue_category',
161
+					),
162
+					'rewrite'           => array('slug' => __('venue-category', 'event_espresso')),
163
+				),
164
+			),
165
+			'espresso_event_type'       => array(
166
+				'singular_name' => __("Event Type", "event_espresso"),
167
+				'plural_name'   => __("Event Types", "event_espresso"),
168
+				'args'          => array(
169
+					'public'       => true,
170
+					'show_ui'      => false,
171
+					'show_in_rest' => true,
172
+					'capabilities' => array(
173
+						'manage_terms' => 'ee_read_event_type',
174
+						'edit_terms'   => 'ee_edit_event_type',
175
+						'delete_terms' => 'ee_delete_event_type',
176
+						'assign_terms' => 'ee_assign_event_type',
177
+					),
178
+					'rewrite'      => array('slug' => __('event-type', 'event_espresso')),
179
+					'hierarchical' => true,
180
+				),
181
+			),
182
+		));
183
+	}
184
+
185
+
186
+
187
+	/**
188
+	 * This returns the corresponding model name for cpts registered by EE.
189
+	 *
190
+	 * @since 4.6.16.rc.000
191
+	 * @param string $post_type_slug              If a slug is included, then attempt to retrieve the model name for
192
+	 *                                            the given cpt slug.  Otherwise if empty, then we'll return all cpt
193
+	 *                                            model names for cpts registered in EE.
194
+	 * @return array           Empty array if no matching model names for the given slug or an array of model
195
+	 *                                            names indexed by post type slug.
196
+	 */
197
+	public static function get_cpt_model_names($post_type_slug = '')
198
+	{
199
+		$cpts = self::get_CPTs();
200
+		//first if slug passed in...
201
+		if ( ! empty($post_type_slug)) {
202
+			//match?
203
+			if (
204
+				! isset($cpts[$post_type_slug])
205
+				|| (isset($cpts[$post_type_slug]) && empty($cpts[$post_type_slug]['class_name']))
206
+			) {
207
+				return array();
208
+			}
209
+			//k let's get the model name for this cpt.
210
+			return array($post_type_slug => str_replace('EE', 'EEM', $cpts[$post_type_slug]['class_name']));
211
+		}
212
+		//if we made it here then we're returning an array of cpt model names indexed by post_type_slug.
213
+		$cpt_models = array();
214
+		foreach ($cpts as $slug => $args) {
215
+			if ( ! empty($args['class_name'])) {
216
+				$cpt_models[$slug] = str_replace('EE', 'EEM', $args['class_name']);
217
+			}
218
+		}
219
+		return $cpt_models;
220
+	}
221
+
222
+
223
+
224
+	/**
225
+	 * This instantiates cpt models related to the cpts registered via EE.
226
+	 *
227
+	 * @since 4.6.16.rc.000
228
+	 * @param string $post_type_slug If valid slug is provided, then will instantiate the model only for
229
+	 *                               the cpt matching the given slug.  Otherwise all cpt models will be
230
+	 *                               instantiated (if possible).
231
+	 * @return EEM_CPT_Base[]        successful instantiation will return an array of successfully instantiated
232
+	 *                               EEM models indexed by post slug.
233
+	 */
234
+	public static function instantiate_cpt_models($post_type_slug = '')
235
+	{
236
+		$cpt_model_names = self::get_cpt_model_names($post_type_slug);
237
+		$instantiated = array();
238
+		foreach ($cpt_model_names as $slug => $model_name) {
239
+			$instance = EE_Registry::instance()->load_model(str_replace('EEM_', '', $model_name));
240
+			if ($instance instanceof EEM_CPT_Base) {
241
+				$instantiated[$slug] = $instance;
242
+			}
243
+		}
244
+		return $instantiated;
245
+	}
246
+
247
+
248
+
249
+	/**
250
+	 *    get_CPTs
251
+	 *
252
+	 * @access    public
253
+	 * @return    array
254
+	 */
255
+	public static function get_CPTs()
256
+	{
257
+		// define CPTs
258
+		// NOTE the ['args']['page_templates'] array index is something specific to our CPTs
259
+		// and not part of the WP custom post type api.
260
+		return apply_filters('FHEE__EE_Register_CPTs__get_CPTs__cpts', array(
261
+			'espresso_events'    => array(
262
+				'singular_name' => __("Event", "event_espresso"),
263
+				'plural_name'   => __("Events", "event_espresso"),
264
+				'singular_slug' => __("event", "event_espresso"),
265
+				'plural_slug'   => EE_Registry::instance()->CFG->core->event_cpt_slug,
266
+				'class_name'    => 'EE_Event',
267
+				'args'          => array(
268
+					'public'            => true,
269
+					'show_in_nav_menus' => true,
270
+					'capability_type'   => 'event',
271
+					'capabilities'      => array(
272
+						'edit_post'              => 'ee_edit_event',
273
+						'read_post'              => 'ee_read_event',
274
+						'delete_post'            => 'ee_delete_event',
275
+						'edit_posts'             => 'ee_edit_events',
276
+						'edit_others_posts'      => 'ee_edit_others_events',
277
+						'publish_posts'          => 'ee_publish_events',
278
+						'read_private_posts'     => 'ee_read_private_events',
279
+						'delete_posts'           => 'ee_delete_events',
280
+						'delete_private_posts'   => 'ee_delete_private_events',
281
+						'delete_published_posts' => 'ee_delete_published_events',
282
+						'delete_others_posts'    => 'ee_delete_others_events',
283
+						'edit_private_posts'     => 'ee_edit_private_events',
284
+						'edit_published_posts'   => 'ee_edit_published_events',
285
+					),
286
+					'taxonomies'        => array(
287
+						'espresso_event_categories',
288
+						'espresso_event_type',
289
+						'post_tag',
290
+					),
291
+					'page_templates'    => true,
292
+				),
293
+			),
294
+			'espresso_venues'    => array(
295
+				'singular_name' => __("Venue", "event_espresso"),
296
+				'plural_name'   => __("Venues", "event_espresso"),
297
+				'singular_slug' => __("venue", "event_espresso"),
298
+				'plural_slug'   => __("venues", "event_espresso"),
299
+				'class_name'    => 'EE_Venue',
300
+				'args'          => array(
301
+					'public'            => true,
302
+					'show_in_nav_menus' => false, //by default this doesn't show for decaf,
303
+					'capability_type'   => 'venue',
304
+					'capabilities'      => array(
305
+						'edit_post'              => 'ee_edit_venue',
306
+						'read_post'              => 'ee_read_venue',
307
+						'delete_post'            => 'ee_delete_venue',
308
+						'edit_posts'             => 'ee_edit_venues',
309
+						'edit_others_posts'      => 'ee_edit_others_venues',
310
+						'publish_posts'          => 'ee_publish_venues',
311
+						'read_private_posts'     => 'ee_read_private_venues',
312
+						'delete_posts'           => 'ee_delete_venues',
313
+						'delete_private_posts'   => 'ee_delete_private_venues',
314
+						'delete_published_posts' => 'ee_delete_published_venues',
315
+						'delete_others_posts'    => 'ee_edit_others_venues',
316
+						'edit_private_posts'     => 'ee_edit_private_venues',
317
+						'edit_published_posts'   => 'ee_edit_published_venues',
318
+					),
319
+					'taxonomies'        => array(
320
+						'espresso_venue_categories',
321
+						'post_tag',
322
+					),
323
+					'page_templates'    => true,
324
+				),
325
+			),
326
+			'espresso_attendees' => array(
327
+				'singular_name' => __("Contact", "event_espresso"),
328
+				'plural_name'   => __("Contacts", "event_espresso"),
329
+				'singular_slug' => __("contact", "event_espresso"),
330
+				'plural_slug'   => __("contacts", "event_espresso"),
331
+				'class_name'    => 'EE_Attendee',
332
+				'args'          => array(
333
+					'public'             => false,
334
+					'publicly_queryable' => false,
335
+					'hierarchical'       => false,
336
+					'has_archive'        => false,
337
+					'taxonomies'         => array('post_tag'),
338
+					'capability_type'    => 'contact',
339
+					'capabilities'       => array(
340
+						'edit_post'              => 'ee_edit_contact',
341
+						'read_post'              => 'ee_read_contact',
342
+						'delete_post'            => 'ee_delete_contact',
343
+						'edit_posts'             => 'ee_edit_contacts',
344
+						'edit_others_posts'      => 'ee_edit_contacts',
345
+						'publish_posts'          => 'ee_edit_contacts',
346
+						'read_private_posts'     => 'ee_edit_contacts',
347
+						'delete_posts'           => 'ee_delete_contacts',
348
+						'delete_private_posts'   => 'ee_delete_contacts',
349
+						'delete_published_posts' => 'ee_delete_contacts',
350
+						'delete_others_posts'    => 'ee_delete_contacts',
351
+						'edit_private_posts'     => 'ee_edit_contacts',
352
+						'edit_published_posts'   => 'ee_edit_contacts',
353
+					),
354
+					'supports'           => array('editor', 'thumbnail', 'excerpt', 'custom-fields', 'comments'),
355
+				),
356
+			),
357
+		));
358
+	}
359
+
360
+
361
+
362
+	/**
363
+	 * This basically goes through the CPT array and returns only CPT's
364
+	 * that have the ['args']['public'] option set as false
365
+	 *
366
+	 * @return array
367
+	 */
368
+	public static function get_private_CPTs()
369
+	{
370
+		$CPTs = self::get_CPTs();
371
+		$private_CPTs = array();
372
+		foreach ($CPTs as $CPT => $details) {
373
+			if (empty($details['args']['public'])) {
374
+				$private_CPTs[$CPT] = $details;
375
+			}
376
+		}
377
+		return $private_CPTs;
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 * Registers a custom taxonomy. Should be called before registering custom post types,
384
+	 * otherwise you should link the taxonomy to the custom post type using 'register_taxonomy_for_object_type'.
385
+	 *
386
+	 * @param string $taxonomy_name , eg 'books'
387
+	 * @param string $singular_name internationalized singular name
388
+	 * @param string $plural_name   internationalized plural name
389
+	 * @param array  $override_args like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy
390
+	 */
391
+	public function register_taxonomy($taxonomy_name, $singular_name, $plural_name, $override_args = array())
392
+	{
393
+		$args = array(
394
+			'hierarchical'      => true,
395
+			'labels'            => array(
396
+				'name'          => $plural_name,
397
+				'singular_name' => $singular_name,
398
+			),
399
+			'show_ui'           => true,
400
+			'show_ee_ui'        => true,
401
+			'show_admin_column' => true,
402
+			'query_var'         => true,
403
+			'show_in_nav_menus' => false,
404
+			'map_meta_cap'      => true
405
+			//'rewrite'           => array( 'slug' => 'genre' ),
406
+		);
407
+		if ($override_args) {
408
+			if (isset($override_args['labels'])) {
409
+				$labels = array_merge($args['labels'], $override_args['labels']);
410
+				$args['labels'] = $labels;
411
+			}
412
+			$args = array_merge($args, $override_args);
413
+		}
414
+		register_taxonomy($taxonomy_name, null, $args);
415
+	}
416
+
417
+
418
+
419
+	/**
420
+	 * Registers a new custom post type. Sets default settings given only the following params.
421
+	 *
422
+	 * @param string $post_type     the actual post type name
423
+	 *                              (VERY IMPORTANT: this much match what the slug is for admin pages related to this
424
+	 *                              cpt Also any models must use this slug as well)
425
+	 * @param string $singular_name a pre-internationalized string for the singular name of the objects
426
+	 * @param string $plural_name   a pre-internalized string for the plural name of the objects
427
+	 * @param array  $override_args exactly like $args as described in
428
+	 *                              http://codex.wordpress.org/Function_Reference/register_post_type The default values
429
+	 *                              set in this function will be overridden by whatever you set in $override_args
430
+	 * @param string $singular_slug
431
+	 * @param string $plural_slug
432
+	 * @return void , but registers the custom post type
433
+	 */
434
+	public function register_CPT(
435
+		$post_type,
436
+		$singular_name,
437
+		$plural_name,
438
+		$override_args = array(),
439
+		$singular_slug = '',
440
+		$plural_slug = ''
441
+	) {
442
+		$labels = array(
443
+			'name'               => $plural_name,
444
+			'singular_name'      => $singular_name,
445
+			'singular_slug'      => $singular_slug,
446
+			'plural_slug'        => $plural_slug,
447
+			'add_new'            => sprintf(__("Add %s", "event_espresso"), $singular_name),
448
+			'add_new_item'       => sprintf(__("Add New %s", "event_espresso"), $singular_name),
449
+			'edit_item'          => sprintf(__("Edit %s", "event_espresso"), $singular_name),
450
+			'new_item'           => sprintf(__("New %s", "event_espresso"), $singular_name),
451
+			'all_items'          => sprintf(__("All %s", "event_espresso"), $plural_name),
452
+			'view_item'          => sprintf(__("View %s", "event_espresso"), $singular_name),
453
+			'search_items'       => sprintf(__("Search %s", "event_espresso"), $plural_name),
454
+			'not_found'          => sprintf(__("No %s found", "event_espresso"), $plural_name),
455
+			'not_found_in_trash' => sprintf(__("No %s found in Trash", "event_espresso"), $plural_name),
456
+			'parent_item_colon'  => '',
457
+			'menu_name'          => sprintf(__("%s", "event_espresso"), $plural_name),
458
+		);
459
+		//verify plural slug and singular slug, if they aren't we'll use $singular_name and $plural_name
460
+		// $singular_slug = ! empty($singular_slug) ? $singular_slug : $singular_name;
461
+		$plural_slug = ! empty($plural_slug) ? $plural_slug : $plural_name;
462
+		//note the page_templates arg in the supports index is something specific to EE.
463
+		//  WordPress doesn't actually have that in their register_post_type api.
464
+		$args = array(
465
+			'labels'             => $labels,
466
+			'public'             => true,
467
+			'publicly_queryable' => true,
468
+			'show_ui'            => false,
469
+			'show_ee_ui'         => true,
470
+			'show_in_menu'       => false,
471
+			'show_in_nav_menus'  => false,
472
+			'query_var'          => true,
473
+			'rewrite'            => apply_filters(
474
+				'FHEE__EE_Register_CPTs__register_CPT__rewrite',
475
+				array('slug' => $plural_slug),
476
+				$post_type
477
+			),
478
+			'capability_type'    => 'post',
479
+			'map_meta_cap'       => true,
480
+			'has_archive'        => true,
481
+			'hierarchical'       => false,
482
+			'menu_position'      => null,
483
+			'supports'           => array(
484
+				'title',
485
+				'editor',
486
+				'author',
487
+				'thumbnail',
488
+				'excerpt',
489
+				'custom-fields',
490
+				'comments',
491
+			),
492
+		);
493
+		if ($override_args) {
494
+			if (isset($override_args['labels'])) {
495
+				$labels = array_merge($args['labels'], $override_args['labels']);
496
+			}
497
+			$args = array_merge($args, $override_args);
498
+			$args['labels'] = $labels;
499
+		}
500
+		register_post_type($post_type, $args);
501
+	}
502
+
503
+
504
+
505
+	public function set_must_use_event_types()
506
+	{
507
+		$term_details = array(
508
+			//Attendee's register for the first date-time only
509
+			'single-event'    => array(
510
+				__('Single Event', 'event_espresso'),
511
+				__('A single event that spans one or more consecutive days.', 'event_espresso'),
512
+			),
513
+			//example: a party or two-day long workshop
514
+			//Attendee's can register for any of the date-times
515
+			'multi-event'     => array(
516
+				__('Multi Event', 'event_espresso'),
517
+				__('Multiple, separate, but related events that occur on consecutive days.', 'event_espresso'),
518
+			),
519
+			//example: a three day music festival or week long conference
520
+			//Attendee's register for the first date-time only
521
+			'event-series'    => array(
522
+				__('Event Series', 'event_espresso'),
523
+				__(' Multiple events that occur over multiple non-consecutive days.', 'event_espresso'),
524
+			),
525
+			//example: an 8 week introduction to basket weaving course
526
+			//Attendee's can register for any of the date-times.
527
+			'recurring-event' => array(
528
+				__('Recurring Event', 'event_espresso'),
529
+				__('Multiple events that occur over multiple non-consecutive days.', 'event_espresso'),
530
+			),
531
+			//example: a yoga class
532
+			'ongoing' => array(
533
+				__('Ongoing Event', 'event_espresso'),
534
+				__('An "event" that people can purchase tickets to gain access for anytime for this event regardless of date times on the event',
535
+					'event_espresso'),
536
+			)
537
+			//example: access to a museum
538
+			//'walk-in' => array( __('Walk In', 'event_espresso'), __('Single datetime and single entry recurring events. Attendees register for one or multiple datetimes individually.', 'event_espresso') ),
539
+			//'reservation' => array( __('Reservation', 'event_espresso'), __('Reservations are created by specifying available datetimes and quantities. Attendees choose from the available datetimes and specify the quantity available (if the maximum is greater than 1)') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1
540
+			// 'multiple-session' => array( __('Multiple Session', 'event_espresso'), __('Multiple event, multiple datetime, hierarchically organized, custom entry events. Attendees may be required to register for a parent event before being allowed to register for child events. Attendees can register for any combination of child events as long as the datetimes do not conflict. Parent and child events may have additional fees or registration questions.') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1
541
+			//'appointment' => array( __('Appointments', 'event_espresso'), __('Time slotted events where datetimes are generally in hours or minutes. For example, attendees can register for a single 15 minute or 1 hour time slot and this type of availability frequently reoccurs.', 'event_espresso') )
542
+		);
543
+		$this->set_must_use_terms('espresso_event_type', $term_details);
544
+	}
545
+
546
+
547
+
548
+	/**
549
+	 * wrapper method for handling the setting up of initial terms in the db (if they don't already exist).
550
+	 * Note this should ONLY be used for terms that always must be present.  Be aware that if an initial term is
551
+	 * deleted then it WILL be recreated.
552
+	 *
553
+	 * @param string $taxonomy     The name of the taxonomy
554
+	 * @param array  $term_details An array of term details indexed by slug and containing Name of term, and
555
+	 *                             description as the elements in the array
556
+	 * @return void
557
+	 */
558
+	public function set_must_use_terms($taxonomy, $term_details)
559
+	{
560
+		$term_details = (array)$term_details;
561
+		foreach ($term_details as $slug => $details) {
562
+			if ( ! term_exists($slug, $taxonomy)) {
563
+				$insert_arr = array(
564
+					'slug'        => $slug,
565
+					'description' => $details[1],
566
+				);
567
+				wp_insert_term($details[0], $taxonomy, $insert_arr);
568
+			}
569
+		}
570
+	}
571
+
572
+
573
+
574
+	/**
575
+	 * Allows us to set what the default will be for terms when a cpt is PUBLISHED.
576
+	 *
577
+	 * @param string $taxonomy  The taxonomy we're using for the default term
578
+	 * @param string $term_slug The slug of the term that will be the default.
579
+	 * @param array  $cpt_slugs An array of custom post types we want the default assigned to
580
+	 */
581
+	public function set_default_term($taxonomy, $term_slug, $cpt_slugs = array())
582
+	{
583
+		$this->_default_terms[][$term_slug] = new EE_Default_Term($taxonomy, $term_slug, $cpt_slugs);
584
+	}
585
+
586
+
587
+
588
+	/**
589
+	 * hooked into the wp 'save_post' action hook for setting our default terms found in the $_default_terms property
590
+	 *
591
+	 * @param  int    $post_id ID of CPT being saved
592
+	 * @param  object $post    Post object
593
+	 * @return void
594
+	 */
595
+	public function save_default_term($post_id, $post)
596
+	{
597
+		if (empty($this->_default_terms)) {
598
+			return;
599
+		} //no default terms set so lets just exit.
600
+		foreach ($this->_default_terms as $defaults) {
601
+			foreach ($defaults as $default_obj) {
602
+				if ($post->post_status === 'publish' && in_array($post->post_type, $default_obj->cpt_slugs, true)) {
603
+					//note some error proofing going on here to save unnecessary db queries
604
+					$taxonomies = get_object_taxonomies($post->post_type);
605
+					foreach ((array)$taxonomies as $taxonomy) {
606
+						$terms = wp_get_post_terms($post_id, $taxonomy);
607
+						if (empty($terms) && $taxonomy === $default_obj->taxonomy) {
608
+							wp_set_object_terms($post_id, array($default_obj->term_slug), $taxonomy);
609
+						}
610
+					}
611
+				}
612
+			}
613
+		}
614
+	}
615 615
 
616 616
 }
617 617
 
@@ -625,27 +625,27 @@  discard block
 block discarded – undo
625 625
 {
626 626
 
627 627
 
628
-    //props holding the items
629
-    public $taxonomy  = '';
628
+	//props holding the items
629
+	public $taxonomy  = '';
630 630
 
631
-    public $cpt_slugs = array();
631
+	public $cpt_slugs = array();
632 632
 
633
-    public $term_slug = '';
633
+	public $term_slug = '';
634 634
 
635 635
 
636 636
 
637
-    /**
638
-     * constructor
639
-     *
640
-     * @param string $taxonomy  The taxonomy the default term belongs to
641
-     * @param string $term_slug The slug of the term that will be the default.
642
-     * @param array  $cpt_slugs The custom post type the default term gets saved with
643
-     */
644
-    public function __construct($taxonomy, $term_slug, $cpt_slugs = array())
645
-    {
646
-        $this->taxonomy = $taxonomy;
647
-        $this->cpt_slugs = (array)$cpt_slugs;
648
-        $this->term_slug = $term_slug;
649
-    }
637
+	/**
638
+	 * constructor
639
+	 *
640
+	 * @param string $taxonomy  The taxonomy the default term belongs to
641
+	 * @param string $term_slug The slug of the term that will be the default.
642
+	 * @param array  $cpt_slugs The custom post type the default term gets saved with
643
+	 */
644
+	public function __construct($taxonomy, $term_slug, $cpt_slugs = array())
645
+	{
646
+		$this->taxonomy = $taxonomy;
647
+		$this->cpt_slugs = (array)$cpt_slugs;
648
+		$this->term_slug = $term_slug;
649
+	}
650 650
 
651 651
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_CPT.core.php 2 patches
Indentation   +1376 added lines, -1376 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 /**
@@ -24,445 +24,445 @@  discard block
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * This gets set in _setup_cpt
29
-     * It will contain the object for the custom post type.
30
-     *
31
-     * @var object
32
-     */
33
-    protected $_cpt_object;
34
-
35
-
36
-
37
-    /**
38
-     * a boolean flag to set whether the current route is a cpt route or not.
39
-     *
40
-     * @var bool
41
-     */
42
-    protected $_cpt_route = false;
43
-
44
-
45
-
46
-    /**
47
-     * This property allows cpt classes to define multiple routes as cpt routes.
48
-     * //in this array we define what the custom post type for this route is.
49
-     * array(
50
-     * 'route_name' => 'custom_post_type_slug'
51
-     * )
52
-     *
53
-     * @var array
54
-     */
55
-    protected $_cpt_routes = array();
56
-
27
+	/**
28
+	 * This gets set in _setup_cpt
29
+	 * It will contain the object for the custom post type.
30
+	 *
31
+	 * @var object
32
+	 */
33
+	protected $_cpt_object;
34
+
35
+
36
+
37
+	/**
38
+	 * a boolean flag to set whether the current route is a cpt route or not.
39
+	 *
40
+	 * @var bool
41
+	 */
42
+	protected $_cpt_route = false;
43
+
44
+
45
+
46
+	/**
47
+	 * This property allows cpt classes to define multiple routes as cpt routes.
48
+	 * //in this array we define what the custom post type for this route is.
49
+	 * array(
50
+	 * 'route_name' => 'custom_post_type_slug'
51
+	 * )
52
+	 *
53
+	 * @var array
54
+	 */
55
+	protected $_cpt_routes = array();
56
+
57 57
 
58 58
 
59
-    /**
60
-     * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
61
-     * in this format:
62
-     * array(
63
-     * 'post_type_slug' => 'edit_route'
64
-     * )
65
-     *
66
-     * @var array
67
-     */
68
-    protected $_cpt_edit_routes = array();
69
-
70
-
71
-
72
-    /**
73
-     * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
-     * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
-     * _cpt_model_names property should be in the following format: array(
76
-     * 'route_defined_by_action_param' => 'Model_Name')
77
-     *
78
-     * @var array $_cpt_model_names
79
-     */
80
-    protected $_cpt_model_names = array();
81
-
82
-
83
-    /**
84
-     * @var EE_CPT_Base
85
-     */
86
-    protected $_cpt_model_obj = false;
87
-
88
-
89
-
90
-    /**
91
-     * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
92
-     * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
93
-     * the _register_autosave_containers() method so that we don't override any other containers already registered.
94
-     * Registration of containers should be done before load_page_dependencies() is run.
95
-     *
96
-     * @var array()
97
-     */
98
-    protected $_autosave_containers = array();
99
-    protected $_autosave_fields = array();
100
-
101
-    /**
102
-     * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
103
-     * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
104
-     *
105
-     * @var array
106
-     */
107
-    protected $_pagenow_map = null;
108
-
109
-
110
-
111
-    /**
112
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
113
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
114
-     * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
115
-     * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
116
-     * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
117
-     *
118
-     * @access protected
119
-     * @abstract
120
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
121
-     * @param  object $post    The post object of the cpt that was saved.
122
-     * @return void
123
-     */
124
-    abstract protected function _insert_update_cpt_item($post_id, $post);
125
-
126
-
127
-
128
-    /**
129
-     * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
130
-     *
131
-     * @abstract
132
-     * @access public
133
-     * @param  string $post_id The ID of the cpt that was trashed
134
-     * @return void
135
-     */
136
-    abstract public function trash_cpt_item($post_id);
137
-
138
-
139
-
140
-    /**
141
-     * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
142
-     *
143
-     * @param  string $post_id theID of the cpt that was untrashed
144
-     * @return void
145
-     */
146
-    abstract public function restore_cpt_item($post_id);
147
-
148
-
149
-
150
-    /**
151
-     * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
152
-     * from the db
153
-     *
154
-     * @param  string $post_id the ID of the cpt that was deleted
155
-     * @return void
156
-     */
157
-    abstract public function delete_cpt_item($post_id);
158
-
159
-
160
-
161
-    /**
162
-     * Just utilizing the method EE_Admin exposes for doing things before page setup.
163
-     *
164
-     * @access protected
165
-     * @return void
166
-     */
167
-    protected function _before_page_setup()
168
-    {
169
-        $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
170
-        $this->_cpt_routes = array_merge(array(
171
-            'create_new' => $this->page_slug,
172
-            'edit'       => $this->page_slug,
173
-            'trash'      => $this->page_slug,
174
-        ), $this->_cpt_routes);
175
-        //let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
176
-        $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']])
177
-            ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
178
-            : get_post_type_object($page);
179
-        //tweak pagenow for page loading.
180
-        if ( ! $this->_pagenow_map) {
181
-            $this->_pagenow_map = array(
182
-                'create_new' => 'post-new.php',
183
-                'edit'       => 'post.php',
184
-                'trash'      => 'post.php',
185
-            );
186
-        }
187
-        add_action('current_screen', array($this, 'modify_pagenow'));
188
-        //TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
189
-        //get current page from autosave
190
-        $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
191
-            ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
192
-            : null;
193
-        $this->_current_page = isset($this->_req_data['current_page'])
194
-            ? $this->_req_data['current_page']
195
-            : $current_page;
196
-        //autosave... make sure its only for the correct page
197
-        if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
198
-            //setup autosave ajax hook
199
-            //add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
200
-        }
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * Simply ensure that we simulate the correct post route for cpt screens
207
-     *
208
-     * @param WP_Screen $current_screen
209
-     * @return void
210
-     */
211
-    public function modify_pagenow($current_screen)
212
-    {
213
-        global $pagenow, $hook_suffix;
214
-        //possibly reset pagenow.
215
-        if ( ! empty($this->_req_data['page'])
216
-             && $this->_req_data['page'] == $this->page_slug
217
-             && ! empty($this->_req_data['action'])
218
-             && isset($this->_pagenow_map[$this->_req_data['action']])
219
-        ) {
220
-            $pagenow = $this->_pagenow_map[$this->_req_data['action']];
221
-            $hook_suffix = $pagenow;
222
-        }
223
-    }
224
-
225
-
226
-
227
-    /**
228
-     * This method is used to register additional autosave containers to the _autosave_containers property.
229
-     *
230
-     * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
231
-     *       automatically register the id for the post metabox as a container.
232
-     * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
233
-     *                    you would send along the id of a metabox container.
234
-     * @return void
235
-     */
236
-    protected function _register_autosave_containers($ids)
237
-    {
238
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
245
-     * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
246
-     */
247
-    protected function _set_autosave_containers()
248
-    {
249
-        global $wp_meta_boxes;
250
-        $containers = array();
251
-        if (empty($wp_meta_boxes)) {
252
-            return;
253
-        }
254
-        $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
255
-        foreach ($current_metaboxes as $box_context) {
256
-            foreach ($box_context as $box_details) {
257
-                foreach ($box_details as $box) {
258
-                    if (is_array($box['callback'])
259
-                        && ($box['callback'][0] instanceof EE_Admin_Page
260
-                            || $box['callback'][0] instanceof EE_Admin_Hooks)
261
-                    ) {
262
-                        $containers[] = $box['id'];
263
-                    }
264
-                }
265
-            }
266
-        }
267
-        $this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
268
-        //add hidden inputs container
269
-        $this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
270
-    }
271
-
272
-
273
-
274
-    protected function _load_autosave_scripts_styles()
275
-    {
276
-        /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
59
+	/**
60
+	 * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
61
+	 * in this format:
62
+	 * array(
63
+	 * 'post_type_slug' => 'edit_route'
64
+	 * )
65
+	 *
66
+	 * @var array
67
+	 */
68
+	protected $_cpt_edit_routes = array();
69
+
70
+
71
+
72
+	/**
73
+	 * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
+	 * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
+	 * _cpt_model_names property should be in the following format: array(
76
+	 * 'route_defined_by_action_param' => 'Model_Name')
77
+	 *
78
+	 * @var array $_cpt_model_names
79
+	 */
80
+	protected $_cpt_model_names = array();
81
+
82
+
83
+	/**
84
+	 * @var EE_CPT_Base
85
+	 */
86
+	protected $_cpt_model_obj = false;
87
+
88
+
89
+
90
+	/**
91
+	 * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
92
+	 * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
93
+	 * the _register_autosave_containers() method so that we don't override any other containers already registered.
94
+	 * Registration of containers should be done before load_page_dependencies() is run.
95
+	 *
96
+	 * @var array()
97
+	 */
98
+	protected $_autosave_containers = array();
99
+	protected $_autosave_fields = array();
100
+
101
+	/**
102
+	 * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
103
+	 * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
104
+	 *
105
+	 * @var array
106
+	 */
107
+	protected $_pagenow_map = null;
108
+
109
+
110
+
111
+	/**
112
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
113
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
114
+	 * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
115
+	 * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
116
+	 * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
117
+	 *
118
+	 * @access protected
119
+	 * @abstract
120
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
121
+	 * @param  object $post    The post object of the cpt that was saved.
122
+	 * @return void
123
+	 */
124
+	abstract protected function _insert_update_cpt_item($post_id, $post);
125
+
126
+
127
+
128
+	/**
129
+	 * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
130
+	 *
131
+	 * @abstract
132
+	 * @access public
133
+	 * @param  string $post_id The ID of the cpt that was trashed
134
+	 * @return void
135
+	 */
136
+	abstract public function trash_cpt_item($post_id);
137
+
138
+
139
+
140
+	/**
141
+	 * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
142
+	 *
143
+	 * @param  string $post_id theID of the cpt that was untrashed
144
+	 * @return void
145
+	 */
146
+	abstract public function restore_cpt_item($post_id);
147
+
148
+
149
+
150
+	/**
151
+	 * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
152
+	 * from the db
153
+	 *
154
+	 * @param  string $post_id the ID of the cpt that was deleted
155
+	 * @return void
156
+	 */
157
+	abstract public function delete_cpt_item($post_id);
158
+
159
+
160
+
161
+	/**
162
+	 * Just utilizing the method EE_Admin exposes for doing things before page setup.
163
+	 *
164
+	 * @access protected
165
+	 * @return void
166
+	 */
167
+	protected function _before_page_setup()
168
+	{
169
+		$page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
170
+		$this->_cpt_routes = array_merge(array(
171
+			'create_new' => $this->page_slug,
172
+			'edit'       => $this->page_slug,
173
+			'trash'      => $this->page_slug,
174
+		), $this->_cpt_routes);
175
+		//let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
176
+		$this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']])
177
+			? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
178
+			: get_post_type_object($page);
179
+		//tweak pagenow for page loading.
180
+		if ( ! $this->_pagenow_map) {
181
+			$this->_pagenow_map = array(
182
+				'create_new' => 'post-new.php',
183
+				'edit'       => 'post.php',
184
+				'trash'      => 'post.php',
185
+			);
186
+		}
187
+		add_action('current_screen', array($this, 'modify_pagenow'));
188
+		//TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
189
+		//get current page from autosave
190
+		$current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
191
+			? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
192
+			: null;
193
+		$this->_current_page = isset($this->_req_data['current_page'])
194
+			? $this->_req_data['current_page']
195
+			: $current_page;
196
+		//autosave... make sure its only for the correct page
197
+		if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
198
+			//setup autosave ajax hook
199
+			//add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
200
+		}
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * Simply ensure that we simulate the correct post route for cpt screens
207
+	 *
208
+	 * @param WP_Screen $current_screen
209
+	 * @return void
210
+	 */
211
+	public function modify_pagenow($current_screen)
212
+	{
213
+		global $pagenow, $hook_suffix;
214
+		//possibly reset pagenow.
215
+		if ( ! empty($this->_req_data['page'])
216
+			 && $this->_req_data['page'] == $this->page_slug
217
+			 && ! empty($this->_req_data['action'])
218
+			 && isset($this->_pagenow_map[$this->_req_data['action']])
219
+		) {
220
+			$pagenow = $this->_pagenow_map[$this->_req_data['action']];
221
+			$hook_suffix = $pagenow;
222
+		}
223
+	}
224
+
225
+
226
+
227
+	/**
228
+	 * This method is used to register additional autosave containers to the _autosave_containers property.
229
+	 *
230
+	 * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
231
+	 *       automatically register the id for the post metabox as a container.
232
+	 * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
233
+	 *                    you would send along the id of a metabox container.
234
+	 * @return void
235
+	 */
236
+	protected function _register_autosave_containers($ids)
237
+	{
238
+		$this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
245
+	 * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
246
+	 */
247
+	protected function _set_autosave_containers()
248
+	{
249
+		global $wp_meta_boxes;
250
+		$containers = array();
251
+		if (empty($wp_meta_boxes)) {
252
+			return;
253
+		}
254
+		$current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
255
+		foreach ($current_metaboxes as $box_context) {
256
+			foreach ($box_context as $box_details) {
257
+				foreach ($box_details as $box) {
258
+					if (is_array($box['callback'])
259
+						&& ($box['callback'][0] instanceof EE_Admin_Page
260
+							|| $box['callback'][0] instanceof EE_Admin_Hooks)
261
+					) {
262
+						$containers[] = $box['id'];
263
+					}
264
+				}
265
+			}
266
+		}
267
+		$this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
268
+		//add hidden inputs container
269
+		$this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
270
+	}
271
+
272
+
273
+
274
+	protected function _load_autosave_scripts_styles()
275
+	{
276
+		/*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
277 277
         wp_enqueue_script('cpt-autosave');/**/ //todo re-enable when we start doing autosave again in 4.2
278 278
 
279
-        //filter _autosave_containers
280
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
281
-            $this->_autosave_containers, $this);
282
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
283
-            $containers, $this);
284
-
285
-        wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
286
-            $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
287
-
288
-        $unsaved_data_msg = array(
289
-            'eventmsg'     => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.",
290
-                'event_espresso'), $this->_cpt_object->labels->singular_name),
291
-            'inputChanged' => 0,
292
-        );
293
-        wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
294
-    }
295
-
296
-
297
-
298
-    public function load_page_dependencies()
299
-    {
300
-        try {
301
-            $this->_load_page_dependencies();
302
-        } catch (EE_Error $e) {
303
-            $e->get_error();
304
-        }
305
-    }
306
-
307
-
308
-
309
-    /**
310
-     * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
311
-     *
312
-     * @access protected
313
-     * @return void
314
-     */
315
-    protected function _load_page_dependencies()
316
-    {
317
-        //we only add stuff if this is a cpt_route!
318
-        if ( ! $this->_cpt_route) {
319
-            parent::_load_page_dependencies();
320
-            return;
321
-        }
322
-        //now let's do some automatic filters into the wp_system and we'll check to make sure the CHILD class automatically has the required methods in place.
323
-        //the following filters are for setting all the redirects on DEFAULT WP custom post type actions
324
-        //let's add a hidden input to the post-edit form so we know when we have to trigger our custom redirects!  Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
325
-        add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
326
-        //inject our Admin page nav tabs...
327
-        //let's make sure the nav tabs are set if they aren't already
328
-        //if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
329
-        add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
330
-        //modify the post_updated messages array
331
-        add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
332
-        //add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE, cpts use the same format for shortlinks as posts!
333
-        add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
334
-        //This basically allows us to change the title of the "publish" metabox area on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
335
-        if ( ! empty($this->_labels['publishbox'])) {
336
-            $box_label = is_array($this->_labels['publishbox'])
337
-                         && isset($this->_labels['publishbox'][$this->_req_action])
338
-                ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
339
-            remove_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
340
-                'side', 'core');
341
-            add_meta_box('submitdiv', $box_label, 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
342
-                'side', 'core');
343
-        }
344
-        //let's add page_templates metabox if this cpt added support for it.
345
-        if ($this->_supports_page_templates($this->_cpt_object->name)) {
346
-            add_meta_box('page_templates', __('Page Template', 'event_espresso'),
347
-                array($this, 'page_template_meta_box'), $this->_cpt_routes[$this->_req_action], 'side', 'default');
348
-        }
349
-        //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
350
-        if (method_exists($this, 'extra_permalink_field_buttons')) {
351
-            add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
352
-        }
353
-        //add preview button
354
-        add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
355
-        //insert our own post_stati dropdown
356
-        add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
357
-        //This allows adding additional information to the publish post submitbox on the wp post edit form
358
-        if (method_exists($this, 'extra_misc_actions_publish_box')) {
359
-            add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
360
-        }
361
-        //This allows for adding additional stuff after the title field on the wp post edit form.  This is also before the wp_editor for post description field.
362
-        if (method_exists($this, 'edit_form_after_title')) {
363
-            add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
364
-        }
365
-        /**
366
-         * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
367
-         */
368
-        add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
369
-        parent::_load_page_dependencies();
370
-        //notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes.
371
-        global $pagenow;
372
-        do_action('load-' . $pagenow);
373
-        $this->modify_current_screen();
374
-        add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
375
-        //we route REALLY early.
376
-        try {
377
-            $this->_route_admin_request();
378
-        } catch (EE_Error $e) {
379
-            $e->get_error();
380
-        }
381
-    }
382
-
383
-
384
-
385
-    /**
386
-     * Since we don't want users going to default core wp routes, this will check any wp urls run through the
387
-     * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
388
-     * route instead.
389
-     *
390
-     * @param string $good_protocol_url The escaped url.
391
-     * @param string $original_url      The original url.
392
-     * @param string $_context          The context sendt to the esc_url method.
393
-     * @return string possibly a new url for our route.
394
-     */
395
-    public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
396
-    {
397
-        $routes_to_match = array(
398
-            0 => array(
399
-                'edit.php?post_type=espresso_attendees',
400
-                'admin.php?page=espresso_registrations&action=contact_list',
401
-            ),
402
-            1 => array(
403
-                'edit.php?post_type=' . $this->_cpt_object->name,
404
-                'admin.php?page=' . $this->_cpt_object->name,
405
-            ),
406
-        );
407
-        foreach ($routes_to_match as $route_matches) {
408
-            if (strpos($good_protocol_url, $route_matches[0]) !== false) {
409
-                return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
410
-            }
411
-        }
412
-        return $good_protocol_url;
413
-    }
414
-
415
-
416
-
417
-    /**
418
-     * Determine whether the current cpt supports page templates or not.
419
-     *
420
-     * @since %VER%
421
-     * @param string $cpt_name The cpt slug we're checking on.
422
-     * @return bool True supported, false not.
423
-     */
424
-    private function _supports_page_templates($cpt_name)
425
-    {
426
-
427
-        $cpt_args = EE_Register_CPTs::get_CPTs();
428
-        $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
429
-        $cpt_has_support = ! empty($cpt_args['page_templates']);
430
-
431
-        //if the installed version of WP is > 4.7 we do some additional checks.
432
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
433
-            $post_templates = wp_get_theme()->get_post_templates();
434
-            //if there are $post_templates for this cpt, then we return false for this method because
435
-            //that means we aren't going to load our page template manager and leave that up to the native
436
-            //cpt template manager.
437
-            $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
438
-        }
439
-
440
-        return $cpt_has_support;
441
-    }
442
-
443
-
444
-    /**
445
-     * Callback for the page_templates metabox selector.
446
-     *
447
-     * @since %VER%
448
-     * @return string html
449
-     */
450
-    public function page_template_meta_box()
451
-    {
452
-        global $post;
453
-        $template = '';
454
-
455
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
456
-            $page_template_count = count(get_page_templates());
457
-        } else {
458
-            $page_template_count = count(get_page_templates($post));
459
-        };
460
-
461
-        if ($page_template_count) {
462
-            $page_template = get_post_meta($post->ID, '_wp_page_template', true);
463
-            $template      = ! empty($page_template) ? $page_template : '';
464
-        }
465
-        ?>
279
+		//filter _autosave_containers
280
+		$containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
281
+			$this->_autosave_containers, $this);
282
+		$containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
283
+			$containers, $this);
284
+
285
+		wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
286
+			$containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
287
+
288
+		$unsaved_data_msg = array(
289
+			'eventmsg'     => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.",
290
+				'event_espresso'), $this->_cpt_object->labels->singular_name),
291
+			'inputChanged' => 0,
292
+		);
293
+		wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
294
+	}
295
+
296
+
297
+
298
+	public function load_page_dependencies()
299
+	{
300
+		try {
301
+			$this->_load_page_dependencies();
302
+		} catch (EE_Error $e) {
303
+			$e->get_error();
304
+		}
305
+	}
306
+
307
+
308
+
309
+	/**
310
+	 * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
311
+	 *
312
+	 * @access protected
313
+	 * @return void
314
+	 */
315
+	protected function _load_page_dependencies()
316
+	{
317
+		//we only add stuff if this is a cpt_route!
318
+		if ( ! $this->_cpt_route) {
319
+			parent::_load_page_dependencies();
320
+			return;
321
+		}
322
+		//now let's do some automatic filters into the wp_system and we'll check to make sure the CHILD class automatically has the required methods in place.
323
+		//the following filters are for setting all the redirects on DEFAULT WP custom post type actions
324
+		//let's add a hidden input to the post-edit form so we know when we have to trigger our custom redirects!  Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
325
+		add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
326
+		//inject our Admin page nav tabs...
327
+		//let's make sure the nav tabs are set if they aren't already
328
+		//if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
329
+		add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
330
+		//modify the post_updated messages array
331
+		add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
332
+		//add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE, cpts use the same format for shortlinks as posts!
333
+		add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
334
+		//This basically allows us to change the title of the "publish" metabox area on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
335
+		if ( ! empty($this->_labels['publishbox'])) {
336
+			$box_label = is_array($this->_labels['publishbox'])
337
+						 && isset($this->_labels['publishbox'][$this->_req_action])
338
+				? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
339
+			remove_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
340
+				'side', 'core');
341
+			add_meta_box('submitdiv', $box_label, 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
342
+				'side', 'core');
343
+		}
344
+		//let's add page_templates metabox if this cpt added support for it.
345
+		if ($this->_supports_page_templates($this->_cpt_object->name)) {
346
+			add_meta_box('page_templates', __('Page Template', 'event_espresso'),
347
+				array($this, 'page_template_meta_box'), $this->_cpt_routes[$this->_req_action], 'side', 'default');
348
+		}
349
+		//this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
350
+		if (method_exists($this, 'extra_permalink_field_buttons')) {
351
+			add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
352
+		}
353
+		//add preview button
354
+		add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
355
+		//insert our own post_stati dropdown
356
+		add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
357
+		//This allows adding additional information to the publish post submitbox on the wp post edit form
358
+		if (method_exists($this, 'extra_misc_actions_publish_box')) {
359
+			add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
360
+		}
361
+		//This allows for adding additional stuff after the title field on the wp post edit form.  This is also before the wp_editor for post description field.
362
+		if (method_exists($this, 'edit_form_after_title')) {
363
+			add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
364
+		}
365
+		/**
366
+		 * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
367
+		 */
368
+		add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
369
+		parent::_load_page_dependencies();
370
+		//notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes.
371
+		global $pagenow;
372
+		do_action('load-' . $pagenow);
373
+		$this->modify_current_screen();
374
+		add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
375
+		//we route REALLY early.
376
+		try {
377
+			$this->_route_admin_request();
378
+		} catch (EE_Error $e) {
379
+			$e->get_error();
380
+		}
381
+	}
382
+
383
+
384
+
385
+	/**
386
+	 * Since we don't want users going to default core wp routes, this will check any wp urls run through the
387
+	 * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
388
+	 * route instead.
389
+	 *
390
+	 * @param string $good_protocol_url The escaped url.
391
+	 * @param string $original_url      The original url.
392
+	 * @param string $_context          The context sendt to the esc_url method.
393
+	 * @return string possibly a new url for our route.
394
+	 */
395
+	public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
396
+	{
397
+		$routes_to_match = array(
398
+			0 => array(
399
+				'edit.php?post_type=espresso_attendees',
400
+				'admin.php?page=espresso_registrations&action=contact_list',
401
+			),
402
+			1 => array(
403
+				'edit.php?post_type=' . $this->_cpt_object->name,
404
+				'admin.php?page=' . $this->_cpt_object->name,
405
+			),
406
+		);
407
+		foreach ($routes_to_match as $route_matches) {
408
+			if (strpos($good_protocol_url, $route_matches[0]) !== false) {
409
+				return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
410
+			}
411
+		}
412
+		return $good_protocol_url;
413
+	}
414
+
415
+
416
+
417
+	/**
418
+	 * Determine whether the current cpt supports page templates or not.
419
+	 *
420
+	 * @since %VER%
421
+	 * @param string $cpt_name The cpt slug we're checking on.
422
+	 * @return bool True supported, false not.
423
+	 */
424
+	private function _supports_page_templates($cpt_name)
425
+	{
426
+
427
+		$cpt_args = EE_Register_CPTs::get_CPTs();
428
+		$cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
429
+		$cpt_has_support = ! empty($cpt_args['page_templates']);
430
+
431
+		//if the installed version of WP is > 4.7 we do some additional checks.
432
+		if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
433
+			$post_templates = wp_get_theme()->get_post_templates();
434
+			//if there are $post_templates for this cpt, then we return false for this method because
435
+			//that means we aren't going to load our page template manager and leave that up to the native
436
+			//cpt template manager.
437
+			$cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
438
+		}
439
+
440
+		return $cpt_has_support;
441
+	}
442
+
443
+
444
+	/**
445
+	 * Callback for the page_templates metabox selector.
446
+	 *
447
+	 * @since %VER%
448
+	 * @return string html
449
+	 */
450
+	public function page_template_meta_box()
451
+	{
452
+		global $post;
453
+		$template = '';
454
+
455
+		if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
456
+			$page_template_count = count(get_page_templates());
457
+		} else {
458
+			$page_template_count = count(get_page_templates($post));
459
+		};
460
+
461
+		if ($page_template_count) {
462
+			$page_template = get_post_meta($post->ID, '_wp_page_template', true);
463
+			$template      = ! empty($page_template) ? $page_template : '';
464
+		}
465
+		?>
466 466
         <p><strong><?php _e('Template') ?></strong></p>
467 467
         <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select
468 468
             name="page_template" id="page_template">
@@ -470,435 +470,435 @@  discard block
 block discarded – undo
470 470
         <?php page_template_dropdown($template); ?>
471 471
     </select>
472 472
         <?php
473
-    }
474
-
475
-
476
-
477
-    /**
478
-     * if this post is a draft or scheduled post then we provide a preview button for user to click
479
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
480
-     *
481
-     * @param  string $return    the current html
482
-     * @param  int    $id        the post id for the page
483
-     * @param  string $new_title What the title is
484
-     * @param  string $new_slug  what the slug is
485
-     * @return string            The new html string for the permalink area
486
-     */
487
-    public function preview_button_html($return, $id, $new_title, $new_slug)
488
-    {
489
-        $post = get_post($id);
490
-        if ('publish' != get_post_status($post)) {
491
-            //include shims for the `get_preview_post_link` function
492
-            require_once( EE_CORE . 'wordpress-shims.php' );
493
-            $return .= '<span_id="view-post-btn"><a target="_blank" href="'
494
-                       . get_preview_post_link($id)
495
-                       . '" class="button button-small">'
496
-                       . __('Preview', 'event_espresso')
497
-                       . '</a></span>'
498
-                       . "\n";
499
-        }
500
-        return $return;
501
-    }
502
-
503
-
504
-
505
-    /**
506
-     * add our custom post stati dropdown on the wp post page for this cpt
507
-     *
508
-     * @return string html for dropdown
509
-     */
510
-    public function custom_post_stati_dropdown()
511
-    {
512
-
513
-        $statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
514
-        $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
515
-            ? $statuses[$this->_cpt_model_obj->status()]
516
-            : '';
517
-        $template_args    = array(
518
-            'cur_status'            => $this->_cpt_model_obj->status(),
519
-            'statuses'              => $statuses,
520
-            'cur_status_label'      => $cur_status_label,
521
-            'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
522
-        );
523
-        //we'll add a trash post status (WP doesn't add one for some reason)
524
-        if ($this->_cpt_model_obj->status() == 'trash') {
525
-            $template_args['cur_status_label'] = __('Trashed', 'event_espresso');
526
-            $statuses['trash']                 = __('Trashed', 'event_espresso');
527
-            $template_args['statuses']         = $statuses;
528
-        }
529
-
530
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
531
-        EEH_Template::display_template($template, $template_args);
532
-    }
533
-
534
-
535
-
536
-    public function setup_autosave_hooks()
537
-    {
538
-        $this->_set_autosave_containers();
539
-        $this->_load_autosave_scripts_styles();
540
-    }
541
-
542
-
543
-
544
-    /**
545
-     * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
546
-     * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
547
-     * for the nonce in here, but then this method looks for two things:
548
-     * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
549
-     * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
550
-     * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
551
-     * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
552
-     * template args.
553
-     *    1. $template_args['error'] = IF there is an error you can add the message in here.
554
-     *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
555
-     *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
556
-     *    $this->_template_args['data']['items'] = array(
557
-     *        'event-datetime-ids' => '1,2,3';
558
-     *    );
559
-     *    Keep in mind the following things:
560
-     *    - "where" index is for the input with the id as that string.
561
-     *    - "what" index is what will be used for the value of that input.
562
-     *
563
-     * @return void
564
-     */
565
-    public function do_extra_autosave_stuff()
566
-    {
567
-        //next let's check for the autosave nonce (we'll use _verify_nonce )
568
-        $nonce = isset($this->_req_data['autosavenonce']) ? $this->_req_data['autosavenonce'] : null;
569
-        $this->_verify_nonce($nonce, 'autosave');
570
-        //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
571
-        if ( ! defined('DOING_AUTOSAVE')) {
572
-            define('DOING_AUTOSAVE', true);
573
-        }
574
-        //if we made it here then the nonce checked out.  Let's run our methods and actions
575
-        if (method_exists($this, '_ee_autosave_' . $this->_current_view)) {
576
-            call_user_func(array($this, '_ee_autosave_' . $this->_current_view));
577
-        } else {
578
-            $this->_template_args['success'] = true;
579
-        }
580
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
581
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
582
-        //now let's return json
583
-        $this->_return_json();
584
-    }
585
-
586
-
587
-
588
-    /**
589
-     * This takes care of setting up default routes and pages that utilize the core WP admin pages.
590
-     * Child classes can override the defaults (in cases for adding metaboxes etc.)
591
-     * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
592
-     *
593
-     * @access protected
594
-     * @throws EE_Error
595
-     * @return void
596
-     */
597
-    protected function _extend_page_config_for_cpt()
598
-    {
599
-        //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
600
-        if ((isset($this->_req_data['page']) && $this->_req_data['page'] != $this->page_slug)) {
601
-            return;
602
-        }
603
-        //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
604
-        if ( ! empty($this->_cpt_object)) {
605
-            $this->_page_routes = array_merge(array(
606
-                'create_new' => '_create_new_cpt_item',
607
-                'edit'       => '_edit_cpt_item',
608
-            ), $this->_page_routes);
609
-            $this->_page_config = array_merge(array(
610
-                'create_new' => array(
611
-                    'nav'           => array(
612
-                        'label' => $this->_cpt_object->labels->add_new_item,
613
-                        'order' => 5,
614
-                    ),
615
-                    'require_nonce' => false,
616
-                ),
617
-                'edit'       => array(
618
-                    'nav'           => array(
619
-                        'label'      => $this->_cpt_object->labels->edit_item,
620
-                        'order'      => 5,
621
-                        'persistent' => false,
622
-                        'url'        => '',
623
-                    ),
624
-                    'require_nonce' => false,
625
-                ),
626
-            ),
627
-                $this->_page_config
628
-            );
629
-        }
630
-        //load the next section only if this is a matching cpt route as set in the cpt routes array.
631
-        if ( ! isset($this->_cpt_routes[$this->_req_action])) {
632
-            return;
633
-        }
634
-        $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
635
-        //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
636
-        if (empty($this->_cpt_object)) {
637
-            $msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'),
638
-                $this->page_slug, $this->_req_action, get_class($this));
639
-            throw new EE_Error($msg);
640
-        }
641
-        if ($this->_cpt_route) {
642
-            $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
643
-            $this->_set_model_object($id);
644
-        }
645
-    }
646
-
647
-
648
-
649
-    /**
650
-     * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
651
-     *
652
-     * @access protected
653
-     * @param int  $id The id to retrieve the model object for. If empty we set a default object.
654
-     * @param bool $ignore_route_check
655
-     */
656
-    protected function _set_model_object($id = null, $ignore_route_check = false)
657
-    {
658
-        $model = null;
659
-        if (
660
-            empty($this->_cpt_model_names)
661
-            || (
662
-                ! $ignore_route_check
663
-                && ! isset($this->_cpt_routes[$this->_req_action])
664
-            ) || (
665
-                $this->_cpt_model_obj instanceof EE_CPT_Base
666
-                && $this->_cpt_model_obj->ID() === $id
667
-            )
668
-        ) {
669
-            //get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
670
-            return;
671
-        }
672
-        //if ignore_route_check is true, then get the model name via EE_Register_CPTs
673
-        if ($ignore_route_check) {
674
-            $model_names = EE_Register_CPTs::get_cpt_model_names();
675
-            $post_type   = get_post_type($id);
676
-            if (isset($model_names[$post_type])) {
677
-                $model = EE_Registry::instance()->load_model($model_names[$post_type]);
678
-            }
679
-        } else {
680
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
681
-        }
682
-        if ($model instanceof EEM_Base) {
683
-            $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
684
-        }
685
-        do_action('AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object');
686
-    }
687
-
688
-
689
-
690
-    /**
691
-     * admin_init_global
692
-     * This runs all the code that we want executed within the WP admin_init hook.
693
-     * This method executes for ALL EE Admin pages.
694
-     *
695
-     * @access public
696
-     * @return void
697
-     */
698
-    public function admin_init_global()
699
-    {
700
-        $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
701
-        //its possible this is a new save so let's catch that instead
702
-        $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
703
-        $post_type = $post ? $post->post_type : false;
704
-        $current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route']
705
-            : 'shouldneverwork';
706
-        $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route]
707
-            : '';
708
-        add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
709
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
710
-        if ($post_type === $route_to_check) {
711
-            add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
712
-        }
713
-        //now let's filter redirect if we're on a revision page and the revision is for an event CPT.
714
-        $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
715
-        if ( ! empty($revision)) {
716
-            $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
717
-            //doing a restore?
718
-            if ( ! empty($action) && $action == 'restore') {
719
-                //get post for revision
720
-                $rev_post = get_post($revision);
721
-                $rev_parent = get_post($rev_post->post_parent);
722
-                //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
723
-                if ($rev_parent && $rev_parent->post_type == $this->page_slug) {
724
-                    add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
725
-                    //restores of revisions
726
-                    add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
727
-                }
728
-            }
729
-        }
730
-        //NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
731
-        if ($post_type && $post_type === $route_to_check) {
732
-            //$post_id, $post
733
-            add_action('save_post', array($this, 'insert_update'), 10, 3);
734
-            //$post_id
735
-            add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
736
-            add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
737
-            add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
738
-            add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
739
-        }
740
-    }
741
-
742
-
743
-
744
-    /**
745
-     * Callback for the WordPress trashed_post hook.
746
-     * Execute some basic checks before calling the trash_cpt_item declared in the child class.
747
-     *
748
-     * @param int $post_id
749
-     */
750
-    public function before_trash_cpt_item($post_id)
751
-    {
752
-        $this->_set_model_object($post_id, true);
753
-        //if our cpt object isn't existent then get out immediately.
754
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
755
-            return;
756
-        }
757
-        $this->trash_cpt_item($post_id);
758
-    }
759
-
760
-
761
-
762
-    /**
763
-     * Callback for the WordPress untrashed_post hook.
764
-     * Execute some basic checks before calling the restore_cpt_method in the child class.
765
-     *
766
-     * @param $post_id
767
-     */
768
-    public function before_restore_cpt_item($post_id)
769
-    {
770
-        $this->_set_model_object($post_id, true);
771
-        //if our cpt object isn't existent then get out immediately.
772
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
773
-            return;
774
-        }
775
-        $this->restore_cpt_item($post_id);
776
-    }
777
-
778
-
779
-
780
-    /**
781
-     * Callback for the WordPress after_delete_post hook.
782
-     * Execute some basic checks before calling the delete_cpt_item method in the child class.
783
-     *
784
-     * @param $post_id
785
-     */
786
-    public function before_delete_cpt_item($post_id)
787
-    {
788
-        $this->_set_model_object($post_id, true);
789
-        //if our cpt object isn't existent then get out immediately.
790
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
791
-            return;
792
-        }
793
-        $this->delete_cpt_item($post_id);
794
-    }
795
-
796
-
797
-
798
-    /**
799
-     * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
800
-     * accordingly.
801
-     *
802
-     * @access public
803
-     * @throws EE_Error
804
-     * @return void
805
-     */
806
-    public function verify_cpt_object()
807
-    {
808
-        $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
809
-        // verify event object
810
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
811
-            throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
812
-                'event_espresso'), $label));
813
-        }
814
-        //if auto-draft then throw an error
815
-        if ($this->_cpt_model_obj->get('status') == 'auto-draft') {
816
-            EE_Error::overwrite_errors();
817
-            EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'),
818
-                $label), __FILE__, __FUNCTION__, __LINE__);
819
-        }
820
-    }
821
-
822
-
823
-
824
-    /**
825
-     * admin_footer_scripts_global
826
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
827
-     * will apply on ALL EE_Admin pages.
828
-     *
829
-     * @access public
830
-     * @return void
831
-     */
832
-    public function admin_footer_scripts_global()
833
-    {
834
-        $this->_add_admin_page_ajax_loading_img();
835
-        $this->_add_admin_page_overlay();
836
-    }
837
-
838
-
839
-
840
-    /**
841
-     * add in any global scripts for cpt routes
842
-     *
843
-     * @return void
844
-     */
845
-    public function load_global_scripts_styles()
846
-    {
847
-        parent::load_global_scripts_styles();
848
-        if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
849
-            //setup custom post status object for localize script but only if we've got a cpt object
850
-            $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
851
-            if ( ! empty($statuses)) {
852
-                //get ALL statuses!
853
-                $statuses = $this->_cpt_model_obj->get_all_post_statuses();
854
-                //setup object
855
-                $ee_cpt_statuses = array();
856
-                foreach ($statuses as $status => $label) {
857
-                    $ee_cpt_statuses[$status] = array(
858
-                        'label'      => $label,
859
-                        'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
860
-                    );
861
-                }
862
-                wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
863
-            }
864
-        }
865
-    }
866
-
867
-
868
-
869
-    /**
870
-     * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
871
-     * insert/updates
872
-     *
873
-     * @param  int     $post_id ID of post being updated
874
-     * @param  WP_Post $post    Post object from WP
875
-     * @param  bool    $update  Whether this is an update or a new save.
876
-     * @return void
877
-     */
878
-    public function insert_update($post_id, $post, $update)
879
-    {
880
-        //make sure that if this is a revision OR trash action that we don't do any updates!
881
-        if (
882
-            isset($this->_req_data['action'])
883
-            && (
884
-                $this->_req_data['action'] == 'restore'
885
-                || $this->_req_data['action'] == 'trash'
886
-            )
887
-        ) {
888
-            return;
889
-        }
890
-        $this->_set_model_object($post_id, true);
891
-        //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
892
-        if ($update
893
-            && (
894
-                ! $this->_cpt_model_obj instanceof EE_CPT_Base
895
-                || $this->_cpt_model_obj->ID() !== $post_id
896
-            )
897
-        ) {
898
-            return;
899
-        }
900
-        //check for autosave and update our req_data property accordingly.
901
-        /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
473
+	}
474
+
475
+
476
+
477
+	/**
478
+	 * if this post is a draft or scheduled post then we provide a preview button for user to click
479
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
480
+	 *
481
+	 * @param  string $return    the current html
482
+	 * @param  int    $id        the post id for the page
483
+	 * @param  string $new_title What the title is
484
+	 * @param  string $new_slug  what the slug is
485
+	 * @return string            The new html string for the permalink area
486
+	 */
487
+	public function preview_button_html($return, $id, $new_title, $new_slug)
488
+	{
489
+		$post = get_post($id);
490
+		if ('publish' != get_post_status($post)) {
491
+			//include shims for the `get_preview_post_link` function
492
+			require_once( EE_CORE . 'wordpress-shims.php' );
493
+			$return .= '<span_id="view-post-btn"><a target="_blank" href="'
494
+					   . get_preview_post_link($id)
495
+					   . '" class="button button-small">'
496
+					   . __('Preview', 'event_espresso')
497
+					   . '</a></span>'
498
+					   . "\n";
499
+		}
500
+		return $return;
501
+	}
502
+
503
+
504
+
505
+	/**
506
+	 * add our custom post stati dropdown on the wp post page for this cpt
507
+	 *
508
+	 * @return string html for dropdown
509
+	 */
510
+	public function custom_post_stati_dropdown()
511
+	{
512
+
513
+		$statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
514
+		$cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
515
+			? $statuses[$this->_cpt_model_obj->status()]
516
+			: '';
517
+		$template_args    = array(
518
+			'cur_status'            => $this->_cpt_model_obj->status(),
519
+			'statuses'              => $statuses,
520
+			'cur_status_label'      => $cur_status_label,
521
+			'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
522
+		);
523
+		//we'll add a trash post status (WP doesn't add one for some reason)
524
+		if ($this->_cpt_model_obj->status() == 'trash') {
525
+			$template_args['cur_status_label'] = __('Trashed', 'event_espresso');
526
+			$statuses['trash']                 = __('Trashed', 'event_espresso');
527
+			$template_args['statuses']         = $statuses;
528
+		}
529
+
530
+		$template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
531
+		EEH_Template::display_template($template, $template_args);
532
+	}
533
+
534
+
535
+
536
+	public function setup_autosave_hooks()
537
+	{
538
+		$this->_set_autosave_containers();
539
+		$this->_load_autosave_scripts_styles();
540
+	}
541
+
542
+
543
+
544
+	/**
545
+	 * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
546
+	 * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
547
+	 * for the nonce in here, but then this method looks for two things:
548
+	 * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
549
+	 * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
550
+	 * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
551
+	 * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
552
+	 * template args.
553
+	 *    1. $template_args['error'] = IF there is an error you can add the message in here.
554
+	 *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
555
+	 *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
556
+	 *    $this->_template_args['data']['items'] = array(
557
+	 *        'event-datetime-ids' => '1,2,3';
558
+	 *    );
559
+	 *    Keep in mind the following things:
560
+	 *    - "where" index is for the input with the id as that string.
561
+	 *    - "what" index is what will be used for the value of that input.
562
+	 *
563
+	 * @return void
564
+	 */
565
+	public function do_extra_autosave_stuff()
566
+	{
567
+		//next let's check for the autosave nonce (we'll use _verify_nonce )
568
+		$nonce = isset($this->_req_data['autosavenonce']) ? $this->_req_data['autosavenonce'] : null;
569
+		$this->_verify_nonce($nonce, 'autosave');
570
+		//make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
571
+		if ( ! defined('DOING_AUTOSAVE')) {
572
+			define('DOING_AUTOSAVE', true);
573
+		}
574
+		//if we made it here then the nonce checked out.  Let's run our methods and actions
575
+		if (method_exists($this, '_ee_autosave_' . $this->_current_view)) {
576
+			call_user_func(array($this, '_ee_autosave_' . $this->_current_view));
577
+		} else {
578
+			$this->_template_args['success'] = true;
579
+		}
580
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
581
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
582
+		//now let's return json
583
+		$this->_return_json();
584
+	}
585
+
586
+
587
+
588
+	/**
589
+	 * This takes care of setting up default routes and pages that utilize the core WP admin pages.
590
+	 * Child classes can override the defaults (in cases for adding metaboxes etc.)
591
+	 * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
592
+	 *
593
+	 * @access protected
594
+	 * @throws EE_Error
595
+	 * @return void
596
+	 */
597
+	protected function _extend_page_config_for_cpt()
598
+	{
599
+		//before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
600
+		if ((isset($this->_req_data['page']) && $this->_req_data['page'] != $this->page_slug)) {
601
+			return;
602
+		}
603
+		//set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
604
+		if ( ! empty($this->_cpt_object)) {
605
+			$this->_page_routes = array_merge(array(
606
+				'create_new' => '_create_new_cpt_item',
607
+				'edit'       => '_edit_cpt_item',
608
+			), $this->_page_routes);
609
+			$this->_page_config = array_merge(array(
610
+				'create_new' => array(
611
+					'nav'           => array(
612
+						'label' => $this->_cpt_object->labels->add_new_item,
613
+						'order' => 5,
614
+					),
615
+					'require_nonce' => false,
616
+				),
617
+				'edit'       => array(
618
+					'nav'           => array(
619
+						'label'      => $this->_cpt_object->labels->edit_item,
620
+						'order'      => 5,
621
+						'persistent' => false,
622
+						'url'        => '',
623
+					),
624
+					'require_nonce' => false,
625
+				),
626
+			),
627
+				$this->_page_config
628
+			);
629
+		}
630
+		//load the next section only if this is a matching cpt route as set in the cpt routes array.
631
+		if ( ! isset($this->_cpt_routes[$this->_req_action])) {
632
+			return;
633
+		}
634
+		$this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
635
+		//add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
636
+		if (empty($this->_cpt_object)) {
637
+			$msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'),
638
+				$this->page_slug, $this->_req_action, get_class($this));
639
+			throw new EE_Error($msg);
640
+		}
641
+		if ($this->_cpt_route) {
642
+			$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
643
+			$this->_set_model_object($id);
644
+		}
645
+	}
646
+
647
+
648
+
649
+	/**
650
+	 * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
651
+	 *
652
+	 * @access protected
653
+	 * @param int  $id The id to retrieve the model object for. If empty we set a default object.
654
+	 * @param bool $ignore_route_check
655
+	 */
656
+	protected function _set_model_object($id = null, $ignore_route_check = false)
657
+	{
658
+		$model = null;
659
+		if (
660
+			empty($this->_cpt_model_names)
661
+			|| (
662
+				! $ignore_route_check
663
+				&& ! isset($this->_cpt_routes[$this->_req_action])
664
+			) || (
665
+				$this->_cpt_model_obj instanceof EE_CPT_Base
666
+				&& $this->_cpt_model_obj->ID() === $id
667
+			)
668
+		) {
669
+			//get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
670
+			return;
671
+		}
672
+		//if ignore_route_check is true, then get the model name via EE_Register_CPTs
673
+		if ($ignore_route_check) {
674
+			$model_names = EE_Register_CPTs::get_cpt_model_names();
675
+			$post_type   = get_post_type($id);
676
+			if (isset($model_names[$post_type])) {
677
+				$model = EE_Registry::instance()->load_model($model_names[$post_type]);
678
+			}
679
+		} else {
680
+			$model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
681
+		}
682
+		if ($model instanceof EEM_Base) {
683
+			$this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
684
+		}
685
+		do_action('AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object');
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 * admin_init_global
692
+	 * This runs all the code that we want executed within the WP admin_init hook.
693
+	 * This method executes for ALL EE Admin pages.
694
+	 *
695
+	 * @access public
696
+	 * @return void
697
+	 */
698
+	public function admin_init_global()
699
+	{
700
+		$post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
701
+		//its possible this is a new save so let's catch that instead
702
+		$post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
703
+		$post_type = $post ? $post->post_type : false;
704
+		$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route']
705
+			: 'shouldneverwork';
706
+		$route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route]
707
+			: '';
708
+		add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
709
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
710
+		if ($post_type === $route_to_check) {
711
+			add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
712
+		}
713
+		//now let's filter redirect if we're on a revision page and the revision is for an event CPT.
714
+		$revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
715
+		if ( ! empty($revision)) {
716
+			$action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
717
+			//doing a restore?
718
+			if ( ! empty($action) && $action == 'restore') {
719
+				//get post for revision
720
+				$rev_post = get_post($revision);
721
+				$rev_parent = get_post($rev_post->post_parent);
722
+				//only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
723
+				if ($rev_parent && $rev_parent->post_type == $this->page_slug) {
724
+					add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
725
+					//restores of revisions
726
+					add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
727
+				}
728
+			}
729
+		}
730
+		//NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
731
+		if ($post_type && $post_type === $route_to_check) {
732
+			//$post_id, $post
733
+			add_action('save_post', array($this, 'insert_update'), 10, 3);
734
+			//$post_id
735
+			add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
736
+			add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
737
+			add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
738
+			add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
739
+		}
740
+	}
741
+
742
+
743
+
744
+	/**
745
+	 * Callback for the WordPress trashed_post hook.
746
+	 * Execute some basic checks before calling the trash_cpt_item declared in the child class.
747
+	 *
748
+	 * @param int $post_id
749
+	 */
750
+	public function before_trash_cpt_item($post_id)
751
+	{
752
+		$this->_set_model_object($post_id, true);
753
+		//if our cpt object isn't existent then get out immediately.
754
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
755
+			return;
756
+		}
757
+		$this->trash_cpt_item($post_id);
758
+	}
759
+
760
+
761
+
762
+	/**
763
+	 * Callback for the WordPress untrashed_post hook.
764
+	 * Execute some basic checks before calling the restore_cpt_method in the child class.
765
+	 *
766
+	 * @param $post_id
767
+	 */
768
+	public function before_restore_cpt_item($post_id)
769
+	{
770
+		$this->_set_model_object($post_id, true);
771
+		//if our cpt object isn't existent then get out immediately.
772
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
773
+			return;
774
+		}
775
+		$this->restore_cpt_item($post_id);
776
+	}
777
+
778
+
779
+
780
+	/**
781
+	 * Callback for the WordPress after_delete_post hook.
782
+	 * Execute some basic checks before calling the delete_cpt_item method in the child class.
783
+	 *
784
+	 * @param $post_id
785
+	 */
786
+	public function before_delete_cpt_item($post_id)
787
+	{
788
+		$this->_set_model_object($post_id, true);
789
+		//if our cpt object isn't existent then get out immediately.
790
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
791
+			return;
792
+		}
793
+		$this->delete_cpt_item($post_id);
794
+	}
795
+
796
+
797
+
798
+	/**
799
+	 * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
800
+	 * accordingly.
801
+	 *
802
+	 * @access public
803
+	 * @throws EE_Error
804
+	 * @return void
805
+	 */
806
+	public function verify_cpt_object()
807
+	{
808
+		$label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
809
+		// verify event object
810
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
811
+			throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
812
+				'event_espresso'), $label));
813
+		}
814
+		//if auto-draft then throw an error
815
+		if ($this->_cpt_model_obj->get('status') == 'auto-draft') {
816
+			EE_Error::overwrite_errors();
817
+			EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'),
818
+				$label), __FILE__, __FUNCTION__, __LINE__);
819
+		}
820
+	}
821
+
822
+
823
+
824
+	/**
825
+	 * admin_footer_scripts_global
826
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
827
+	 * will apply on ALL EE_Admin pages.
828
+	 *
829
+	 * @access public
830
+	 * @return void
831
+	 */
832
+	public function admin_footer_scripts_global()
833
+	{
834
+		$this->_add_admin_page_ajax_loading_img();
835
+		$this->_add_admin_page_overlay();
836
+	}
837
+
838
+
839
+
840
+	/**
841
+	 * add in any global scripts for cpt routes
842
+	 *
843
+	 * @return void
844
+	 */
845
+	public function load_global_scripts_styles()
846
+	{
847
+		parent::load_global_scripts_styles();
848
+		if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
849
+			//setup custom post status object for localize script but only if we've got a cpt object
850
+			$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
851
+			if ( ! empty($statuses)) {
852
+				//get ALL statuses!
853
+				$statuses = $this->_cpt_model_obj->get_all_post_statuses();
854
+				//setup object
855
+				$ee_cpt_statuses = array();
856
+				foreach ($statuses as $status => $label) {
857
+					$ee_cpt_statuses[$status] = array(
858
+						'label'      => $label,
859
+						'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
860
+					);
861
+				}
862
+				wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
863
+			}
864
+		}
865
+	}
866
+
867
+
868
+
869
+	/**
870
+	 * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
871
+	 * insert/updates
872
+	 *
873
+	 * @param  int     $post_id ID of post being updated
874
+	 * @param  WP_Post $post    Post object from WP
875
+	 * @param  bool    $update  Whether this is an update or a new save.
876
+	 * @return void
877
+	 */
878
+	public function insert_update($post_id, $post, $update)
879
+	{
880
+		//make sure that if this is a revision OR trash action that we don't do any updates!
881
+		if (
882
+			isset($this->_req_data['action'])
883
+			&& (
884
+				$this->_req_data['action'] == 'restore'
885
+				|| $this->_req_data['action'] == 'trash'
886
+			)
887
+		) {
888
+			return;
889
+		}
890
+		$this->_set_model_object($post_id, true);
891
+		//if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
892
+		if ($update
893
+			&& (
894
+				! $this->_cpt_model_obj instanceof EE_CPT_Base
895
+				|| $this->_cpt_model_obj->ID() !== $post_id
896
+			)
897
+		) {
898
+			return;
899
+		}
900
+		//check for autosave and update our req_data property accordingly.
901
+		/*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
902 902
             foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) {
903 903
 
904 904
                 foreach ( (array) $values as $key => $value ) {
@@ -908,526 +908,526 @@  discard block
 block discarded – undo
908 908
 
909 909
         }/**/ //TODO reactivate after autosave is implemented in 4.2
910 910
 
911
-        //take care of updating any selected page_template IF this cpt supports it.
912
-        if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
913
-            //wp version aware.
914
-            if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
915
-                $page_templates = wp_get_theme()->get_page_templates();
916
-            } else {
917
-                $post->page_template = $this->_req_data['page_template'];
918
-                $page_templates      = wp_get_theme()->get_page_templates($post);
919
-            }
920
-            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
921
-                EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
922
-            } else {
923
-                update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
924
-            }
925
-        }
926
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
927
-            return;
928
-        } //TODO we'll remove this after reimplementing autosave in 4.2
929
-        $this->_insert_update_cpt_item($post_id, $post);
930
-    }
931
-
932
-
933
-
934
-    /**
935
-     * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
936
-     * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
937
-     * so we don't have to check for our CPT.
938
-     *
939
-     * @param  int $post_id ID of the post
940
-     * @return void
941
-     */
942
-    public function dont_permanently_delete_ee_cpts($post_id)
943
-    {
944
-        //only do this if we're actually processing one of our CPTs
945
-        //if our cpt object isn't existent then get out immediately.
946
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
947
-            return;
948
-        }
949
-        delete_post_meta($post_id, '_wp_trash_meta_status');
950
-        delete_post_meta($post_id, '_wp_trash_meta_time');
951
-        //our cpts may have comments so let's take care of that too
952
-        delete_post_meta($post_id, '_wp_trash_meta_comments_status');
953
-    }
954
-
955
-
956
-
957
-    /**
958
-     * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
959
-     * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
960
-     * in them.  We also have our OWN action in here so addons can hook into the restore process easily.
961
-     *
962
-     * @param  int $post_id     ID of cpt item
963
-     * @param  int $revision_id ID of revision being restored
964
-     * @return void
965
-     */
966
-    public function restore_revision($post_id, $revision_id)
967
-    {
968
-        $this->_restore_cpt_item($post_id, $revision_id);
969
-        //global action
970
-        do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
971
-        //class specific action so you can limit hooking into a specific page.
972
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
973
-    }
974
-
975
-
976
-
977
-    /**
978
-     * @see restore_revision() for details
979
-     * @param  int $post_id     ID of cpt item
980
-     * @param  int $revision_id ID of revision for item
981
-     * @return void
982
-     */
983
-    abstract protected function _restore_cpt_item($post_id, $revision_id);
984
-
985
-
986
-
987
-    /**
988
-     * Execution of this method is added to the end of the load_page_dependencies method in the parent
989
-     * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
990
-     * To fix we have to reset the current_screen using the page_slug
991
-     * (which is identical - or should be - to our registered_post_type id.)
992
-     * Also, since the core WP file loads the admin_header.php for WP
993
-     * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
994
-     * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
995
-     *
996
-     * @return void
997
-     */
998
-    public function modify_current_screen()
999
-    {
1000
-        //ONLY do this if the current page_route IS a cpt route
1001
-        if ( ! $this->_cpt_route) {
1002
-            return;
1003
-        }
1004
-        //routing things REALLY early b/c this is a cpt admin page
1005
-        set_current_screen($this->_cpt_routes[$this->_req_action]);
1006
-        $this->_current_screen       = get_current_screen();
1007
-        $this->_current_screen->base = 'event-espresso';
1008
-        $this->_add_help_tabs(); //we make sure we add any help tabs back in!
1009
-        /*try {
911
+		//take care of updating any selected page_template IF this cpt supports it.
912
+		if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
913
+			//wp version aware.
914
+			if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
915
+				$page_templates = wp_get_theme()->get_page_templates();
916
+			} else {
917
+				$post->page_template = $this->_req_data['page_template'];
918
+				$page_templates      = wp_get_theme()->get_page_templates($post);
919
+			}
920
+			if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
921
+				EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
922
+			} else {
923
+				update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
924
+			}
925
+		}
926
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
927
+			return;
928
+		} //TODO we'll remove this after reimplementing autosave in 4.2
929
+		$this->_insert_update_cpt_item($post_id, $post);
930
+	}
931
+
932
+
933
+
934
+	/**
935
+	 * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
936
+	 * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
937
+	 * so we don't have to check for our CPT.
938
+	 *
939
+	 * @param  int $post_id ID of the post
940
+	 * @return void
941
+	 */
942
+	public function dont_permanently_delete_ee_cpts($post_id)
943
+	{
944
+		//only do this if we're actually processing one of our CPTs
945
+		//if our cpt object isn't existent then get out immediately.
946
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
947
+			return;
948
+		}
949
+		delete_post_meta($post_id, '_wp_trash_meta_status');
950
+		delete_post_meta($post_id, '_wp_trash_meta_time');
951
+		//our cpts may have comments so let's take care of that too
952
+		delete_post_meta($post_id, '_wp_trash_meta_comments_status');
953
+	}
954
+
955
+
956
+
957
+	/**
958
+	 * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
959
+	 * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
960
+	 * in them.  We also have our OWN action in here so addons can hook into the restore process easily.
961
+	 *
962
+	 * @param  int $post_id     ID of cpt item
963
+	 * @param  int $revision_id ID of revision being restored
964
+	 * @return void
965
+	 */
966
+	public function restore_revision($post_id, $revision_id)
967
+	{
968
+		$this->_restore_cpt_item($post_id, $revision_id);
969
+		//global action
970
+		do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
971
+		//class specific action so you can limit hooking into a specific page.
972
+		do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
973
+	}
974
+
975
+
976
+
977
+	/**
978
+	 * @see restore_revision() for details
979
+	 * @param  int $post_id     ID of cpt item
980
+	 * @param  int $revision_id ID of revision for item
981
+	 * @return void
982
+	 */
983
+	abstract protected function _restore_cpt_item($post_id, $revision_id);
984
+
985
+
986
+
987
+	/**
988
+	 * Execution of this method is added to the end of the load_page_dependencies method in the parent
989
+	 * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
990
+	 * To fix we have to reset the current_screen using the page_slug
991
+	 * (which is identical - or should be - to our registered_post_type id.)
992
+	 * Also, since the core WP file loads the admin_header.php for WP
993
+	 * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
994
+	 * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
995
+	 *
996
+	 * @return void
997
+	 */
998
+	public function modify_current_screen()
999
+	{
1000
+		//ONLY do this if the current page_route IS a cpt route
1001
+		if ( ! $this->_cpt_route) {
1002
+			return;
1003
+		}
1004
+		//routing things REALLY early b/c this is a cpt admin page
1005
+		set_current_screen($this->_cpt_routes[$this->_req_action]);
1006
+		$this->_current_screen       = get_current_screen();
1007
+		$this->_current_screen->base = 'event-espresso';
1008
+		$this->_add_help_tabs(); //we make sure we add any help tabs back in!
1009
+		/*try {
1010 1010
             $this->_route_admin_request();
1011 1011
         } catch ( EE_Error $e ) {
1012 1012
             $e->get_error();
1013 1013
         }/**/
1014
-    }
1015
-
1016
-
1017
-
1018
-    /**
1019
-     * This allows child classes to modify the default editor title that appears when people add a new or edit an
1020
-     * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1021
-     * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1022
-     * default to be.
1023
-     *
1024
-     * @param string $title The new title (or existing if there is no editor_title defined)
1025
-     * @return string
1026
-     */
1027
-    public function add_custom_editor_default_title($title)
1028
-    {
1029
-        return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1030
-            ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1031
-            : $title;
1032
-    }
1033
-
1034
-
1035
-
1036
-    /**
1037
-     * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1038
-     *
1039
-     * @param string $shortlink   The already generated shortlink
1040
-     * @param int    $id          Post ID for this item
1041
-     * @param string $context     The context for the link
1042
-     * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1043
-     * @return string
1044
-     */
1045
-    public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1046
-    {
1047
-        if ( ! empty($id) && '' != get_option('permalink_structure')) {
1048
-            $post = get_post($id);
1049
-            if (isset($post->post_type) && $this->page_slug == $post->post_type) {
1050
-                $shortlink = home_url('?p=' . $post->ID);
1051
-            }
1052
-        }
1053
-        return $shortlink;
1054
-    }
1055
-
1056
-
1057
-
1058
-    /**
1059
-     * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1060
-     * already run in modify_current_screen())
1061
-     *
1062
-     * @return void
1063
-     */
1064
-    public function route_admin_request()
1065
-    {
1066
-        if ($this->_cpt_route) {
1067
-            return;
1068
-        }
1069
-        try {
1070
-            $this->_route_admin_request();
1071
-        } catch (EE_Error $e) {
1072
-            $e->get_error();
1073
-        }
1074
-    }
1075
-
1076
-
1077
-
1078
-    /**
1079
-     * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1080
-     *
1081
-     * @return string html
1082
-     */
1083
-    public function cpt_post_form_hidden_input()
1084
-    {
1085
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1086
-        //we're also going to add the route value and the current page so we can direct autosave parsing correctly
1087
-        echo '<div id="ee-cpt-hidden-inputs">';
1088
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1089
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1090
-        echo '</div>';
1091
-    }
1092
-
1093
-
1094
-
1095
-    /**
1096
-     * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1097
-     *
1098
-     * @param  string $location Original location url
1099
-     * @param  int    $status   Status for http header
1100
-     * @return string           new (or original) url to redirect to.
1101
-     */
1102
-    public function revision_redirect($location, $status)
1103
-    {
1104
-        //get revision
1105
-        $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1106
-        //can't do anything without revision so let's get out if not present
1107
-        if (empty($rev_id)) {
1108
-            return $location;
1109
-        }
1110
-        //get rev_post_data
1111
-        $rev = get_post($rev_id);
1112
-        $admin_url = $this->_admin_base_url;
1113
-        $query_args = array(
1114
-            'action'   => 'edit',
1115
-            'post'     => $rev->post_parent,
1116
-            'revision' => $rev_id,
1117
-            'message'  => 5,
1118
-        );
1119
-        $this->_process_notices($query_args, true);
1120
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1121
-    }
1122
-
1123
-
1124
-
1125
-    /**
1126
-     * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1127
-     *
1128
-     * @param  string $link    the original generated link
1129
-     * @param  int    $id      post id
1130
-     * @param  string $context optional, defaults to display.  How to write the '&'
1131
-     * @return string          the link
1132
-     */
1133
-    public function modify_edit_post_link($link, $id, $context)
1134
-    {
1135
-        $post = get_post($id);
1136
-        if ( ! isset($this->_req_data['action'])
1137
-             || ! isset($this->_cpt_routes[$this->_req_data['action']])
1138
-             || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1139
-        ) {
1140
-            return $link;
1141
-        }
1142
-        $query_args = array(
1143
-            'action' => isset($this->_cpt_edit_routes[$post->post_type])
1144
-                ? $this->_cpt_edit_routes[$post->post_type]
1145
-                : 'edit',
1146
-            'post'   => $id,
1147
-        );
1148
-        return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1149
-    }
1150
-
1151
-
1152
-    /**
1153
-     * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1154
-     * our routes.
1155
-     *
1156
-     * @param  string $delete_link  original delete link
1157
-     * @param  int    $post_id      id of cpt object
1158
-     * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1159
-     * @return string new delete link
1160
-     * @throws EE_Error
1161
-     */
1162
-    public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1163
-    {
1164
-        $post = get_post($post_id);
1165
-
1166
-        if (! isset($this->_req_data['action'])
1167
-            || ! $post instanceof WP_Post
1168
-            || (isset($this->_cpt_routes[$this->_req_data['action']])
1169
-                 && $post->post_type !== $this->_cpt_routes[$this->_req_data['action']])
1170
-        ) {
1171
-            return $delete_link;
1172
-        }
1173
-        $this->_set_model_object($post->ID, true);
1174
-        //returns something like `trash_event` or `trash_attendee` or `trash_venue`
1175
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1176
-
1177
-        return EE_Admin_Page::add_query_args_and_nonce(
1178
-            array(
1179
-                'page' => $this->_req_data['page'],
1180
-                'action' => $action,
1181
-                $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1182
-                    => $post->ID
1183
-            ),
1184
-            admin_url()
1185
-        );
1186
-    }
1187
-
1188
-
1189
-
1190
-    /**
1191
-     * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1192
-     * so that we can hijack the default redirect locations for wp custom post types
1193
-     * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1194
-     *
1195
-     * @param  string $location This is the incoming currently set redirect location
1196
-     * @param  string $post_id  This is the 'ID' value of the wp_posts table
1197
-     * @return string           the new location to redirect to
1198
-     */
1199
-    public function cpt_post_location_redirect($location, $post_id)
1200
-    {
1201
-        //we DO have a match so let's setup the url
1202
-        //we have to get the post to determine our route
1203
-        $post       = get_post($post_id);
1204
-        $edit_route = $this->_cpt_edit_routes[$post->post_type];
1205
-        //shared query_args
1206
-        $query_args = array('action' => $edit_route, 'post' => $post_id);
1207
-        $admin_url  = $this->_admin_base_url;
1208
-        if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1209
-            $status = get_post_status($post_id);
1210
-            if (isset($this->_req_data['publish'])) {
1211
-                switch ($status) {
1212
-                    case 'pending':
1213
-                        $message = 8;
1214
-                        break;
1215
-                    case 'future':
1216
-                        $message = 9;
1217
-                        break;
1218
-                    default:
1219
-                        $message = 6;
1220
-                }
1221
-            } else {
1222
-                $message = 'draft' == $status ? 10 : 1;
1223
-            }
1224
-        } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1225
-            $message = 2;
1226
-            //			$append = '#postcustom';
1227
-        } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1228
-            $message = 3;
1229
-            //			$append = '#postcustom';
1230
-        } elseif ($this->_req_data['action'] == 'post-quickpress-save-cont') {
1231
-            $message = 7;
1232
-        } else {
1233
-            $message = 4;
1234
-        }
1235
-        //change the message if the post type is not viewable on the frontend
1236
-        $this->_cpt_object = get_post_type_object($post->post_type);
1237
-        $message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1238
-        $query_args = array_merge(array('message' => $message), $query_args);
1239
-        $this->_process_notices($query_args, true);
1240
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1241
-    }
1242
-
1243
-
1244
-
1245
-    /**
1246
-     * This method is called to inject nav tabs on core WP cpt pages
1247
-     *
1248
-     * @access public
1249
-     * @return string html
1250
-     */
1251
-    public function inject_nav_tabs()
1252
-    {
1253
-        //can we hijack and insert the nav_tabs?
1254
-        $nav_tabs = $this->_get_main_nav_tabs();
1255
-        //first close off existing form tag
1256
-        $html = '>';
1257
-        $html .= $nav_tabs;
1258
-        //now let's handle the remaining tag ( missing ">" is CORRECT )
1259
-        $html .= '<span></span';
1260
-        echo $html;
1261
-    }
1262
-
1263
-
1264
-
1265
-    /**
1266
-     * This just sets up the post update messages when an update form is loaded
1267
-     *
1268
-     * @access public
1269
-     * @param  array $messages the original messages array
1270
-     * @return array           the new messages array
1271
-     */
1272
-    public function post_update_messages($messages)
1273
-    {
1274
-        global $post;
1275
-        $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1276
-        $id = empty($id) && is_object($post) ? $post->ID : null;
1277
-        //		$post_type = $post ? $post->post_type : false;
1278
-        /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1014
+	}
1015
+
1016
+
1017
+
1018
+	/**
1019
+	 * This allows child classes to modify the default editor title that appears when people add a new or edit an
1020
+	 * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1021
+	 * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1022
+	 * default to be.
1023
+	 *
1024
+	 * @param string $title The new title (or existing if there is no editor_title defined)
1025
+	 * @return string
1026
+	 */
1027
+	public function add_custom_editor_default_title($title)
1028
+	{
1029
+		return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1030
+			? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1031
+			: $title;
1032
+	}
1033
+
1034
+
1035
+
1036
+	/**
1037
+	 * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1038
+	 *
1039
+	 * @param string $shortlink   The already generated shortlink
1040
+	 * @param int    $id          Post ID for this item
1041
+	 * @param string $context     The context for the link
1042
+	 * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1043
+	 * @return string
1044
+	 */
1045
+	public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1046
+	{
1047
+		if ( ! empty($id) && '' != get_option('permalink_structure')) {
1048
+			$post = get_post($id);
1049
+			if (isset($post->post_type) && $this->page_slug == $post->post_type) {
1050
+				$shortlink = home_url('?p=' . $post->ID);
1051
+			}
1052
+		}
1053
+		return $shortlink;
1054
+	}
1055
+
1056
+
1057
+
1058
+	/**
1059
+	 * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1060
+	 * already run in modify_current_screen())
1061
+	 *
1062
+	 * @return void
1063
+	 */
1064
+	public function route_admin_request()
1065
+	{
1066
+		if ($this->_cpt_route) {
1067
+			return;
1068
+		}
1069
+		try {
1070
+			$this->_route_admin_request();
1071
+		} catch (EE_Error $e) {
1072
+			$e->get_error();
1073
+		}
1074
+	}
1075
+
1076
+
1077
+
1078
+	/**
1079
+	 * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1080
+	 *
1081
+	 * @return string html
1082
+	 */
1083
+	public function cpt_post_form_hidden_input()
1084
+	{
1085
+		echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1086
+		//we're also going to add the route value and the current page so we can direct autosave parsing correctly
1087
+		echo '<div id="ee-cpt-hidden-inputs">';
1088
+		echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1089
+		echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1090
+		echo '</div>';
1091
+	}
1092
+
1093
+
1094
+
1095
+	/**
1096
+	 * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1097
+	 *
1098
+	 * @param  string $location Original location url
1099
+	 * @param  int    $status   Status for http header
1100
+	 * @return string           new (or original) url to redirect to.
1101
+	 */
1102
+	public function revision_redirect($location, $status)
1103
+	{
1104
+		//get revision
1105
+		$rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1106
+		//can't do anything without revision so let's get out if not present
1107
+		if (empty($rev_id)) {
1108
+			return $location;
1109
+		}
1110
+		//get rev_post_data
1111
+		$rev = get_post($rev_id);
1112
+		$admin_url = $this->_admin_base_url;
1113
+		$query_args = array(
1114
+			'action'   => 'edit',
1115
+			'post'     => $rev->post_parent,
1116
+			'revision' => $rev_id,
1117
+			'message'  => 5,
1118
+		);
1119
+		$this->_process_notices($query_args, true);
1120
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1121
+	}
1122
+
1123
+
1124
+
1125
+	/**
1126
+	 * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1127
+	 *
1128
+	 * @param  string $link    the original generated link
1129
+	 * @param  int    $id      post id
1130
+	 * @param  string $context optional, defaults to display.  How to write the '&'
1131
+	 * @return string          the link
1132
+	 */
1133
+	public function modify_edit_post_link($link, $id, $context)
1134
+	{
1135
+		$post = get_post($id);
1136
+		if ( ! isset($this->_req_data['action'])
1137
+			 || ! isset($this->_cpt_routes[$this->_req_data['action']])
1138
+			 || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1139
+		) {
1140
+			return $link;
1141
+		}
1142
+		$query_args = array(
1143
+			'action' => isset($this->_cpt_edit_routes[$post->post_type])
1144
+				? $this->_cpt_edit_routes[$post->post_type]
1145
+				: 'edit',
1146
+			'post'   => $id,
1147
+		);
1148
+		return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1149
+	}
1150
+
1151
+
1152
+	/**
1153
+	 * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1154
+	 * our routes.
1155
+	 *
1156
+	 * @param  string $delete_link  original delete link
1157
+	 * @param  int    $post_id      id of cpt object
1158
+	 * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1159
+	 * @return string new delete link
1160
+	 * @throws EE_Error
1161
+	 */
1162
+	public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1163
+	{
1164
+		$post = get_post($post_id);
1165
+
1166
+		if (! isset($this->_req_data['action'])
1167
+			|| ! $post instanceof WP_Post
1168
+			|| (isset($this->_cpt_routes[$this->_req_data['action']])
1169
+				 && $post->post_type !== $this->_cpt_routes[$this->_req_data['action']])
1170
+		) {
1171
+			return $delete_link;
1172
+		}
1173
+		$this->_set_model_object($post->ID, true);
1174
+		//returns something like `trash_event` or `trash_attendee` or `trash_venue`
1175
+		$action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1176
+
1177
+		return EE_Admin_Page::add_query_args_and_nonce(
1178
+			array(
1179
+				'page' => $this->_req_data['page'],
1180
+				'action' => $action,
1181
+				$this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1182
+					=> $post->ID
1183
+			),
1184
+			admin_url()
1185
+		);
1186
+	}
1187
+
1188
+
1189
+
1190
+	/**
1191
+	 * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1192
+	 * so that we can hijack the default redirect locations for wp custom post types
1193
+	 * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1194
+	 *
1195
+	 * @param  string $location This is the incoming currently set redirect location
1196
+	 * @param  string $post_id  This is the 'ID' value of the wp_posts table
1197
+	 * @return string           the new location to redirect to
1198
+	 */
1199
+	public function cpt_post_location_redirect($location, $post_id)
1200
+	{
1201
+		//we DO have a match so let's setup the url
1202
+		//we have to get the post to determine our route
1203
+		$post       = get_post($post_id);
1204
+		$edit_route = $this->_cpt_edit_routes[$post->post_type];
1205
+		//shared query_args
1206
+		$query_args = array('action' => $edit_route, 'post' => $post_id);
1207
+		$admin_url  = $this->_admin_base_url;
1208
+		if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1209
+			$status = get_post_status($post_id);
1210
+			if (isset($this->_req_data['publish'])) {
1211
+				switch ($status) {
1212
+					case 'pending':
1213
+						$message = 8;
1214
+						break;
1215
+					case 'future':
1216
+						$message = 9;
1217
+						break;
1218
+					default:
1219
+						$message = 6;
1220
+				}
1221
+			} else {
1222
+				$message = 'draft' == $status ? 10 : 1;
1223
+			}
1224
+		} else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1225
+			$message = 2;
1226
+			//			$append = '#postcustom';
1227
+		} else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1228
+			$message = 3;
1229
+			//			$append = '#postcustom';
1230
+		} elseif ($this->_req_data['action'] == 'post-quickpress-save-cont') {
1231
+			$message = 7;
1232
+		} else {
1233
+			$message = 4;
1234
+		}
1235
+		//change the message if the post type is not viewable on the frontend
1236
+		$this->_cpt_object = get_post_type_object($post->post_type);
1237
+		$message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1238
+		$query_args = array_merge(array('message' => $message), $query_args);
1239
+		$this->_process_notices($query_args, true);
1240
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1241
+	}
1242
+
1243
+
1244
+
1245
+	/**
1246
+	 * This method is called to inject nav tabs on core WP cpt pages
1247
+	 *
1248
+	 * @access public
1249
+	 * @return string html
1250
+	 */
1251
+	public function inject_nav_tabs()
1252
+	{
1253
+		//can we hijack and insert the nav_tabs?
1254
+		$nav_tabs = $this->_get_main_nav_tabs();
1255
+		//first close off existing form tag
1256
+		$html = '>';
1257
+		$html .= $nav_tabs;
1258
+		//now let's handle the remaining tag ( missing ">" is CORRECT )
1259
+		$html .= '<span></span';
1260
+		echo $html;
1261
+	}
1262
+
1263
+
1264
+
1265
+	/**
1266
+	 * This just sets up the post update messages when an update form is loaded
1267
+	 *
1268
+	 * @access public
1269
+	 * @param  array $messages the original messages array
1270
+	 * @return array           the new messages array
1271
+	 */
1272
+	public function post_update_messages($messages)
1273
+	{
1274
+		global $post;
1275
+		$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1276
+		$id = empty($id) && is_object($post) ? $post->ID : null;
1277
+		//		$post_type = $post ? $post->post_type : false;
1278
+		/*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1279 1279
 
1280 1280
         $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/
1281
-        $messages[$post->post_type] = array(
1282
-            0 => '', //Unused. Messages start at index 1.
1283
-            1 => sprintf(
1284
-                __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1285
-                $this->_cpt_object->labels->singular_name,
1286
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1287
-                '</a>'
1288
-            ),
1289
-            2 => __('Custom field updated'),
1290
-            3 => __('Custom field deleted.'),
1291
-            4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1292
-            5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1293
-                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1294
-                : false,
1295
-            6 => sprintf(
1296
-                __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1297
-                $this->_cpt_object->labels->singular_name,
1298
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1299
-                '</a>'
1300
-            ),
1301
-            7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1302
-            8 => sprintf(
1303
-                __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1304
-                $this->_cpt_object->labels->singular_name,
1305
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1306
-                '</a>'
1307
-            ),
1308
-            9 => sprintf(
1309
-                __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1310
-                $this->_cpt_object->labels->singular_name,
1311
-                '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1312
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1313
-                '</a>'
1314
-            ),
1315
-            10 => sprintf(
1316
-                __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1317
-                $this->_cpt_object->labels->singular_name,
1318
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1319
-                '</a>'
1320
-            ),
1321
-        );
1322
-        return $messages;
1323
-    }
1324
-
1325
-
1326
-
1327
-    /**
1328
-     * default method for the 'create_new' route for cpt admin pages.
1329
-     * For reference what to include in here, see wp-admin/post-new.php
1330
-     *
1331
-     * @access  protected
1332
-     * @return string template for add new cpt form
1333
-     */
1334
-    protected function _create_new_cpt_item()
1335
-    {
1336
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1337
-        $post_type        = $this->_cpt_routes[$this->_req_action];
1338
-        $post_type_object = $this->_cpt_object;
1339
-        $title            = $post_type_object->labels->add_new_item;
1340
-        $editing          = true;
1341
-        wp_enqueue_script('autosave');
1342
-        $post    = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1343
-        $post_ID = $post->ID;
1344
-        $is_IE   = $is_IE;
1345
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1346
-        //modify the default editor title field with default title.
1347
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1348
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1349
-    }
1350
-
1351
-
1352
-
1353
-    public function add_new_admin_page_global()
1354
-    {
1355
-        $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1356
-        ?>
1281
+		$messages[$post->post_type] = array(
1282
+			0 => '', //Unused. Messages start at index 1.
1283
+			1 => sprintf(
1284
+				__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1285
+				$this->_cpt_object->labels->singular_name,
1286
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1287
+				'</a>'
1288
+			),
1289
+			2 => __('Custom field updated'),
1290
+			3 => __('Custom field deleted.'),
1291
+			4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1292
+			5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1293
+				$this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1294
+				: false,
1295
+			6 => sprintf(
1296
+				__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1297
+				$this->_cpt_object->labels->singular_name,
1298
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1299
+				'</a>'
1300
+			),
1301
+			7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1302
+			8 => sprintf(
1303
+				__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1304
+				$this->_cpt_object->labels->singular_name,
1305
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1306
+				'</a>'
1307
+			),
1308
+			9 => sprintf(
1309
+				__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1310
+				$this->_cpt_object->labels->singular_name,
1311
+				'<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1312
+				'<a target="_blank" href="' . esc_url(get_permalink($id)),
1313
+				'</a>'
1314
+			),
1315
+			10 => sprintf(
1316
+				__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1317
+				$this->_cpt_object->labels->singular_name,
1318
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1319
+				'</a>'
1320
+			),
1321
+		);
1322
+		return $messages;
1323
+	}
1324
+
1325
+
1326
+
1327
+	/**
1328
+	 * default method for the 'create_new' route for cpt admin pages.
1329
+	 * For reference what to include in here, see wp-admin/post-new.php
1330
+	 *
1331
+	 * @access  protected
1332
+	 * @return string template for add new cpt form
1333
+	 */
1334
+	protected function _create_new_cpt_item()
1335
+	{
1336
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1337
+		$post_type        = $this->_cpt_routes[$this->_req_action];
1338
+		$post_type_object = $this->_cpt_object;
1339
+		$title            = $post_type_object->labels->add_new_item;
1340
+		$editing          = true;
1341
+		wp_enqueue_script('autosave');
1342
+		$post    = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1343
+		$post_ID = $post->ID;
1344
+		$is_IE   = $is_IE;
1345
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1346
+		//modify the default editor title field with default title.
1347
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1348
+		include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1349
+	}
1350
+
1351
+
1352
+
1353
+	public function add_new_admin_page_global()
1354
+	{
1355
+		$admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1356
+		?>
1357 1357
         <script type="text/javascript">
1358 1358
             adminpage = '<?php echo $admin_page; ?>';
1359 1359
         </script>
1360 1360
         <?php
1361
-    }
1362
-
1363
-
1364
-
1365
-    /**
1366
-     * default method for the 'edit' route for cpt admin pages
1367
-     * For reference on what to put in here, refer to wp-admin/post.php
1368
-     *
1369
-     * @access protected
1370
-     * @return string   template for edit cpt form
1371
-     */
1372
-    protected function _edit_cpt_item()
1373
-    {
1374
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1375
-        $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1376
-        $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1377
-        if (empty ($post)) {
1378
-            wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
1379
-        }
1380
-        if ( ! empty($_GET['get-post-lock'])) {
1381
-            wp_set_post_lock($post_id);
1382
-            wp_redirect(get_edit_post_link($post_id, 'url'));
1383
-            exit();
1384
-        }
1385
-
1386
-        // template vars
1387
-        $editing          = true;
1388
-        $post_ID          = $post_id;
1389
-        $post_type        = $this->_cpt_routes[$this->_req_action];
1390
-        $post_type_object = $this->_cpt_object;
1391
-
1392
-        if ( ! wp_check_post_lock($post->ID)) {
1393
-            $active_post_lock = wp_set_post_lock($post->ID);
1394
-            //wp_enqueue_script('autosave');
1395
-        }
1396
-        $title = $this->_cpt_object->labels->edit_item;
1397
-        add_action('admin_footer', '_admin_notice_post_locked');
1398
-        if (isset($this->_cpt_routes[$this->_req_data['action']])
1399
-            && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1400
-        ) {
1401
-            $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1402
-                'create_new', $this);
1403
-            $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array(
1404
-                'action' => $create_new_action,
1405
-                'page'   => $this->page_slug,
1406
-            ), 'admin.php');
1407
-        }
1408
-        if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1409
-            wp_enqueue_script('admin-comments');
1410
-            enqueue_comment_hotkeys_js();
1411
-        }
1412
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1413
-        //modify the default editor title field with default title.
1414
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1415
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1416
-    }
1417
-
1418
-
1419
-
1420
-    /**
1421
-     * some getters
1422
-     */
1423
-    /**
1424
-     * This returns the protected _cpt_model_obj property
1425
-     *
1426
-     * @return EE_CPT_Base
1427
-     */
1428
-    public function get_cpt_model_obj()
1429
-    {
1430
-        return $this->_cpt_model_obj;
1431
-    }
1361
+	}
1362
+
1363
+
1364
+
1365
+	/**
1366
+	 * default method for the 'edit' route for cpt admin pages
1367
+	 * For reference on what to put in here, refer to wp-admin/post.php
1368
+	 *
1369
+	 * @access protected
1370
+	 * @return string   template for edit cpt form
1371
+	 */
1372
+	protected function _edit_cpt_item()
1373
+	{
1374
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1375
+		$post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1376
+		$post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1377
+		if (empty ($post)) {
1378
+			wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
1379
+		}
1380
+		if ( ! empty($_GET['get-post-lock'])) {
1381
+			wp_set_post_lock($post_id);
1382
+			wp_redirect(get_edit_post_link($post_id, 'url'));
1383
+			exit();
1384
+		}
1385
+
1386
+		// template vars
1387
+		$editing          = true;
1388
+		$post_ID          = $post_id;
1389
+		$post_type        = $this->_cpt_routes[$this->_req_action];
1390
+		$post_type_object = $this->_cpt_object;
1391
+
1392
+		if ( ! wp_check_post_lock($post->ID)) {
1393
+			$active_post_lock = wp_set_post_lock($post->ID);
1394
+			//wp_enqueue_script('autosave');
1395
+		}
1396
+		$title = $this->_cpt_object->labels->edit_item;
1397
+		add_action('admin_footer', '_admin_notice_post_locked');
1398
+		if (isset($this->_cpt_routes[$this->_req_data['action']])
1399
+			&& ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1400
+		) {
1401
+			$create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1402
+				'create_new', $this);
1403
+			$post_new_file = EE_Admin_Page::add_query_args_and_nonce(array(
1404
+				'action' => $create_new_action,
1405
+				'page'   => $this->page_slug,
1406
+			), 'admin.php');
1407
+		}
1408
+		if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1409
+			wp_enqueue_script('admin-comments');
1410
+			enqueue_comment_hotkeys_js();
1411
+		}
1412
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1413
+		//modify the default editor title field with default title.
1414
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1415
+		include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1416
+	}
1417
+
1418
+
1419
+
1420
+	/**
1421
+	 * some getters
1422
+	 */
1423
+	/**
1424
+	 * This returns the protected _cpt_model_obj property
1425
+	 *
1426
+	 * @return EE_CPT_Base
1427
+	 */
1428
+	public function get_cpt_model_obj()
1429
+	{
1430
+		return $this->_cpt_model_obj;
1431
+	}
1432 1432
 
1433 1433
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
      */
236 236
     protected function _register_autosave_containers($ids)
237 237
     {
238
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
238
+        $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
239 239
     }
240 240
 
241 241
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
         //filter _autosave_containers
280 280
         $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
281 281
             $this->_autosave_containers, $this);
282
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
282
+        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers',
283 283
             $containers, $this);
284 284
 
285 285
         wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
         parent::_load_page_dependencies();
370 370
         //notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes.
371 371
         global $pagenow;
372
-        do_action('load-' . $pagenow);
372
+        do_action('load-'.$pagenow);
373 373
         $this->modify_current_screen();
374 374
         add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
375 375
         //we route REALLY early.
@@ -400,8 +400,8 @@  discard block
 block discarded – undo
400 400
                 'admin.php?page=espresso_registrations&action=contact_list',
401 401
             ),
402 402
             1 => array(
403
-                'edit.php?post_type=' . $this->_cpt_object->name,
404
-                'admin.php?page=' . $this->_cpt_object->name,
403
+                'edit.php?post_type='.$this->_cpt_object->name,
404
+                'admin.php?page='.$this->_cpt_object->name,
405 405
             ),
406 406
         );
407 407
         foreach ($routes_to_match as $route_matches) {
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
         $cpt_has_support = ! empty($cpt_args['page_templates']);
430 430
 
431 431
         //if the installed version of WP is > 4.7 we do some additional checks.
432
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
432
+        if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
433 433
             $post_templates = wp_get_theme()->get_post_templates();
434 434
             //if there are $post_templates for this cpt, then we return false for this method because
435 435
             //that means we aren't going to load our page template manager and leave that up to the native
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
         global $post;
453 453
         $template = '';
454 454
 
455
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
455
+        if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
456 456
             $page_template_count = count(get_page_templates());
457 457
         } else {
458 458
             $page_template_count = count(get_page_templates($post));
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
         $post = get_post($id);
490 490
         if ('publish' != get_post_status($post)) {
491 491
             //include shims for the `get_preview_post_link` function
492
-            require_once( EE_CORE . 'wordpress-shims.php' );
492
+            require_once(EE_CORE.'wordpress-shims.php');
493 493
             $return .= '<span_id="view-post-btn"><a target="_blank" href="'
494 494
                        . get_preview_post_link($id)
495 495
                        . '" class="button button-small">'
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
             $template_args['statuses']         = $statuses;
528 528
         }
529 529
 
530
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
530
+        $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php';
531 531
         EEH_Template::display_template($template, $template_args);
532 532
     }
533 533
 
@@ -572,13 +572,13 @@  discard block
 block discarded – undo
572 572
             define('DOING_AUTOSAVE', true);
573 573
         }
574 574
         //if we made it here then the nonce checked out.  Let's run our methods and actions
575
-        if (method_exists($this, '_ee_autosave_' . $this->_current_view)) {
576
-            call_user_func(array($this, '_ee_autosave_' . $this->_current_view));
575
+        if (method_exists($this, '_ee_autosave_'.$this->_current_view)) {
576
+            call_user_func(array($this, '_ee_autosave_'.$this->_current_view));
577 577
         } else {
578 578
             $this->_template_args['success'] = true;
579 579
         }
580 580
         do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
581
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
581
+        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this);
582 582
         //now let's return json
583 583
         $this->_return_json();
584 584
     }
@@ -969,7 +969,7 @@  discard block
 block discarded – undo
969 969
         //global action
970 970
         do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
971 971
         //class specific action so you can limit hooking into a specific page.
972
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
972
+        do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id);
973 973
     }
974 974
 
975 975
 
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
         if ( ! empty($id) && '' != get_option('permalink_structure')) {
1048 1048
             $post = get_post($id);
1049 1049
             if (isset($post->post_type) && $this->page_slug == $post->post_type) {
1050
-                $shortlink = home_url('?p=' . $post->ID);
1050
+                $shortlink = home_url('?p='.$post->ID);
1051 1051
             }
1052 1052
         }
1053 1053
         return $shortlink;
@@ -1082,11 +1082,11 @@  discard block
 block discarded – undo
1082 1082
      */
1083 1083
     public function cpt_post_form_hidden_input()
1084 1084
     {
1085
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1085
+        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />';
1086 1086
         //we're also going to add the route value and the current page so we can direct autosave parsing correctly
1087 1087
         echo '<div id="ee-cpt-hidden-inputs">';
1088
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1089
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1088
+        echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />';
1089
+        echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />';
1090 1090
         echo '</div>';
1091 1091
     }
1092 1092
 
@@ -1163,7 +1163,7 @@  discard block
 block discarded – undo
1163 1163
     {
1164 1164
         $post = get_post($post_id);
1165 1165
 
1166
-        if (! isset($this->_req_data['action'])
1166
+        if ( ! isset($this->_req_data['action'])
1167 1167
             || ! $post instanceof WP_Post
1168 1168
             || (isset($this->_cpt_routes[$this->_req_data['action']])
1169 1169
                  && $post->post_type !== $this->_cpt_routes[$this->_req_data['action']])
@@ -1172,7 +1172,7 @@  discard block
 block discarded – undo
1172 1172
         }
1173 1173
         $this->_set_model_object($post->ID, true);
1174 1174
         //returns something like `trash_event` or `trash_attendee` or `trash_venue`
1175
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1175
+        $action = 'trash_'.str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1176 1176
 
1177 1177
         return EE_Admin_Page::add_query_args_and_nonce(
1178 1178
             array(
@@ -1283,39 +1283,39 @@  discard block
 block discarded – undo
1283 1283
             1 => sprintf(
1284 1284
                 __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1285 1285
                 $this->_cpt_object->labels->singular_name,
1286
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1286
+                '<a href="'.esc_url(get_permalink($id)).'">',
1287 1287
                 '</a>'
1288 1288
             ),
1289 1289
             2 => __('Custom field updated'),
1290 1290
             3 => __('Custom field deleted.'),
1291 1291
             4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1292 1292
             5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1293
-                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1293
+                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int) $_GET['revision'], false))
1294 1294
                 : false,
1295 1295
             6 => sprintf(
1296 1296
                 __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1297 1297
                 $this->_cpt_object->labels->singular_name,
1298
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1298
+                '<a href="'.esc_url(get_permalink($id)).'">',
1299 1299
                 '</a>'
1300 1300
             ),
1301 1301
             7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1302 1302
             8 => sprintf(
1303 1303
                 __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1304 1304
                 $this->_cpt_object->labels->singular_name,
1305
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1305
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">',
1306 1306
                 '</a>'
1307 1307
             ),
1308 1308
             9 => sprintf(
1309 1309
                 __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1310 1310
                 $this->_cpt_object->labels->singular_name,
1311
-                '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1312
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1311
+                '<strong>'.date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)).'</strong>',
1312
+                '<a target="_blank" href="'.esc_url(get_permalink($id)),
1313 1313
                 '</a>'
1314 1314
             ),
1315 1315
             10 => sprintf(
1316 1316
                 __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1317 1317
                 $this->_cpt_object->labels->singular_name,
1318
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1318
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1319 1319
                 '</a>'
1320 1320
             ),
1321 1321
         );
@@ -1345,7 +1345,7 @@  discard block
 block discarded – undo
1345 1345
         add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1346 1346
         //modify the default editor title field with default title.
1347 1347
         add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1348
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1348
+        include_once WP_ADMIN_PATH.'edit-form-advanced.php';
1349 1349
     }
1350 1350
 
1351 1351
 
@@ -1412,7 +1412,7 @@  discard block
 block discarded – undo
1412 1412
         add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1413 1413
         //modify the default editor title field with default title.
1414 1414
         add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1415
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1415
+        include_once WP_ADMIN_PATH.'edit-form-advanced.php';
1416 1416
     }
1417 1417
 
1418 1418
 
Please login to merge, or discard this patch.
core/libraries/messages/EE_Message_Resource_Manager.lib.php 2 patches
Indentation   +1112 added lines, -1112 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -17,1117 +17,1117 @@  discard block
 block discarded – undo
17 17
 class EE_Message_Resource_Manager
18 18
 {
19 19
 
20
-    /**
21
-     * This option in the database is used to keep a record of message types that have been activated for a messenger
22
-     * at some point in the history of the site.  It is utilized by the implementation of the 'force' flag in
23
-     * EE_Register_Message_Type.  The force flag is an indication of whether a message type should be activated by
24
-     * default when the message type is registered.  However, if a user has explicitly deactivated a message type, then
25
-     * the force flag is ignored.  The method by which the code knows whether to ignore this flag is via this option.
26
-     * Note, that this is NOT a historical record.  Its entirely possible for a message type to have been activated for
27
-     * a messenger and yet not have a record in this option.  This occurs when a message type is inactivated through an
28
-     * automated process (when an add-on registering the message type deactivates, or when some other code calls the
29
-     * EE_Registery_Message_Type::deregister method) and the related record(s) is(are) removed from this option to ensure
30
-     * the "force" flag is respected if that message type is later re-registered.
31
-     *
32
-     * This option should NOT be used to determine the current "active" state of a message type for a given messenger.
33
-     *
34
-     * The name of this option (and related methods/properties) is due to matching the original intended purpose for the
35
-     * option that got superseded by later behaviour requirements.
36
-     */
37
-    const HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME = 'ee_has_activated_messenger';
38
-
39
-    /**
40
-     * @type boolean $_initialized
41
-     */
42
-    protected $_initialized = false;
43
-
44
-    /**
45
-     * @type EE_Messenger_Collection $_messenger_collection_loader
46
-     */
47
-    protected $_messenger_collection_loader;
48
-
49
-    /**
50
-     * @type EE_Message_Type_Collection $_message_type_collection_loader
51
-     */
52
-    protected $_message_type_collection_loader;
53
-
54
-    /**
55
-     * @type EEM_Message_Template_Group $_message_template_group_model
56
-     */
57
-    protected $_message_template_group_model;
58
-
59
-    /**
60
-     * @type EE_messenger[]
61
-     */
62
-    protected $_installed_messengers = array();
63
-
64
-    /**
65
-     * @type EE_message_type[]
66
-     */
67
-    protected $_installed_message_types = array();
68
-
69
-    /**
70
-     * Array of active messengers.
71
-     * Format is this:
72
-     * array(
73
-     *      'messenger_name' => EE_messenger
74
-     * )
75
-     *
76
-     * @type EE_messenger[]
77
-     */
78
-    protected $_active_messengers = array();
79
-
80
-    /**
81
-     * Formatted array of active message types grouped per messenger.
82
-     * Format is this:
83
-     * array(
84
-     *      'messenger_name' => array(
85
-     *          'settings' => array(
86
-     *              '{messenger_name}-message_types' => array(
87
-     *                  'message_type_name' => array() //variable array of settings corresponding to message type.
88
-     *              )
89
-     *          )
90
-     *      )
91
-     * )
92
-     *
93
-     * @type array
94
-     */
95
-    protected $_active_message_types = array();
96
-
97
-
98
-    /**
99
-     * This holds the array of messengers and their corresponding message types that have
100
-     * been activated on a site at some point.  This is an important record that helps the messages system
101
-     * not accidentally reactivate something that was intentionally deactivated by a user.
102
-     *
103
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
104
-     *
105
-     * @type array
106
-     */
107
-    protected $_has_activated_messengers_and_message_types = array();
108
-
109
-    /**
110
-     * An array of unique message type contexts across all active message types.
111
-     * The array will be indexed by either 'slugs' or 'all'.
112
-     * The slugs index contains an array indexed by unique context slugs with the latest label representation for that
113
-     * slug. array(
114
-     *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
115
-     * );
116
-     * The all index returns an array in this format:
117
-     * array(
118
-     *      'message_type_name' => array(
119
-     *          'context_slug' => array(
120
-     *              'label' => 'localized label for context',
121
-     *              'description' => 'localized description for context'
122
-     *          )
123
-     *      )
124
-     * );
125
-     *
126
-     * @type array
127
-     */
128
-    protected $_contexts = array();
129
-
130
-
131
-    /**
132
-     * EE_Message_Resource_Manager constructor.
133
-     *
134
-     * @param \EE_Messenger_Collection_Loader    $Messenger_Collection_Loader
135
-     * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader
136
-     * @param \EEM_Message_Template_Group        $Message_Template_Group_Model
137
-     */
138
-    function __construct(
139
-        EE_Messenger_Collection_Loader $Messenger_Collection_Loader,
140
-        EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader,
141
-        EEM_Message_Template_Group $Message_Template_Group_Model
142
-    ) {
143
-        $this->_messenger_collection_loader    = $Messenger_Collection_Loader;
144
-        $this->_message_type_collection_loader = $Message_Type_Collection_Loader;
145
-        $this->_message_template_group_model   = $Message_Template_Group_Model;
146
-    }
147
-
148
-
149
-    /**
150
-     * @return void
151
-     */
152
-    protected function _initialize_collections()
153
-    {
154
-        if ($this->_initialized) {
155
-            return;
156
-        }
157
-        $this->_initialized = true;
158
-        $this->_messenger_collection_loader->load_messengers_from_folder();
159
-        $this->_message_type_collection_loader->load_message_types_from_folder();
160
-        $this->get_has_activated_messengers_option(true);
161
-        $this->_set_active_messengers_and_message_types();
162
-    }
163
-
164
-
165
-    /**
166
-     * @return EE_Messenger_Collection
167
-     */
168
-    public function messenger_collection()
169
-    {
170
-        $this->_initialize_collections();
171
-        return $this->_messenger_collection_loader->messenger_collection();
172
-    }
173
-
174
-
175
-    /**
176
-     * @return EE_messenger[]
177
-     */
178
-    public function active_messengers()
179
-    {
180
-        $this->_initialize_collections();
181
-        return $this->_active_messengers;
182
-    }
183
-
184
-
185
-    /**
186
-     * @param string $messenger_name
187
-     * @return \EE_messenger
188
-     */
189
-    public function get_messenger($messenger_name)
190
-    {
191
-        return $this->messenger_collection()->get_by_info($messenger_name);
192
-    }
193
-
194
-
195
-    /**
196
-     * This returns the corresponding EE_messenger object for the given string if it is active.
197
-     *
198
-     * @param string $messenger
199
-     * @return EE_messenger | null
200
-     */
201
-    public function get_active_messenger($messenger)
202
-    {
203
-        $this->_initialize_collections();
204
-        return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null;
205
-    }
206
-
207
-
208
-    /**
209
-     * @return \EE_messenger[]
210
-     */
211
-    public function installed_messengers()
212
-    {
213
-        if (empty($this->_installed_messengers)) {
214
-            $this->_installed_messengers = array();
215
-            $this->messenger_collection()->rewind();
216
-            while ($this->messenger_collection()->valid()) {
217
-                $this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current();
218
-                $this->messenger_collection()->next();
219
-            }
220
-        }
221
-        return $this->_installed_messengers;
222
-    }
223
-
224
-
225
-    /**
226
-     * @param string $messenger_name
227
-     * @return \EE_messenger
228
-     * @throws \EE_Error
229
-     */
230
-    public function valid_messenger($messenger_name)
231
-    {
232
-        $messenger = $this->get_messenger($messenger_name);
233
-        if ($messenger instanceof EE_messenger) {
234
-            return $messenger;
235
-        }
236
-        throw new EE_Error(
237
-            sprintf(
238
-                __('The "%1$s" messenger is either invalid or not installed', 'event_espresso'),
239
-                $messenger_name
240
-            )
241
-        );
242
-    }
243
-
244
-
245
-    /**
246
-     * @return EE_Message_Type_Collection
247
-     */
248
-    public function message_type_collection()
249
-    {
250
-        $this->_initialize_collections();
251
-        return $this->_message_type_collection_loader->message_type_collection();
252
-    }
253
-
254
-
255
-    /**
256
-     * @return array
257
-     */
258
-    public function active_message_types()
259
-    {
260
-        $this->_initialize_collections();
261
-        return $this->_active_message_types;
262
-    }
263
-
264
-
265
-    /**
266
-     * @param string $message_type_name
267
-     * @return \EE_message_type
268
-     */
269
-    public function get_message_type($message_type_name)
270
-    {
271
-        return $this->message_type_collection()->get_by_info($message_type_name);
272
-    }
273
-
274
-
275
-    /**
276
-     * This returns the EE_message_type from the active message types array ( if present );
277
-     *
278
-     * @param string $messenger_name
279
-     * @param string $message_type_name
280
-     * @return \EE_message_type|null
281
-     */
282
-    public function get_active_message_type_for_messenger($messenger_name, $message_type_name)
283
-    {
284
-        return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
285
-            ? $this->get_message_type($message_type_name)
286
-            : null;
287
-    }
288
-
289
-
290
-    /**
291
-     * Returns whether the given message type is active for the given messenger.
292
-     *
293
-     * @param string $messenger_name
294
-     * @param string $message_type_name
295
-     * @return bool
296
-     */
297
-    public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
298
-    {
299
-        $this->_initialize_collections();
300
-        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
301
-    }
302
-
303
-
304
-    /**
305
-     * Returns whether the given messenger is active.
306
-     *
307
-     * @param string $messenger_name the name of the messenger to check if active.
308
-     * @return bool
309
-     */
310
-    public function is_messenger_active($messenger_name)
311
-    {
312
-        $this->_initialize_collections();
313
-        return ! empty($this->_active_message_types[$messenger_name]);
314
-    }
315
-
316
-
317
-    /**
318
-     * This returns any settings that might be on a message type for a messenger
319
-     *
320
-     * @param string $messenger_name    The slug of the messenger
321
-     * @param string $message_type_name The slug of the message type getting the settings for.
322
-     * @return array
323
-     */
324
-    public function get_message_type_settings_for_messenger($messenger_name, $message_type_name)
325
-    {
326
-        $settings = array();
327
-        if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
328
-            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
329
-                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
330
-                : array();
331
-        }
332
-        return $settings;
333
-    }
334
-
335
-
336
-    /**
337
-     * Returns whether the given messenger name has active message types on it.
338
-     * Infers whether the messenger is active or not as well.
339
-     *
340
-     * @param string $messenger_name
341
-     * @return bool
342
-     */
343
-    public function messenger_has_active_message_types($messenger_name)
344
-    {
345
-        $this->_initialize_collections();
346
-        return
347
-            ! empty($this->_active_message_types[$messenger_name])
348
-            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
349
-    }
350
-
351
-
352
-    /**
353
-     * This checks the _active_message_types property for any active message types
354
-     * that are present for the given messenger and returns them.
355
-     *
356
-     * @since 4.9.0
357
-     * @param string $messenger_name The messenger being checked
358
-     * @return EE_message_type[]|array    (empty array if no active_message_types)
359
-     */
360
-    public function get_active_message_types_for_messenger($messenger_name)
361
-    {
362
-        $message_types = array();
363
-        if (! $this->messenger_has_active_message_types($messenger_name)) {
364
-            return $message_types;
365
-        }
366
-        $installed_message_types = $this->installed_message_types();
367
-        foreach ($installed_message_types as $message_type_name => $message_type) {
368
-            if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
369
-                $message_types[$message_type_name] = $message_type;
370
-            }
371
-        }
372
-        return $message_types;
373
-    }
374
-
375
-
376
-    /**
377
-     * This does NOT return the _active_message_types property but
378
-     * simply returns an array of active message type names from that property.
379
-     * (The _active_message_types property is indexed by messenger and active message_types per messenger).
380
-     *
381
-     * @return array message_type references (string)
382
-     */
383
-    public function list_of_active_message_types()
384
-    {
385
-        $active_message_type_names = array();
386
-        $this->_initialize_collections();
387
-        foreach ($this->_active_message_types as $messenger => $messenger_settings) {
388
-            if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
389
-                continue;
390
-            }
391
-            foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
392
-                if (! in_array($message_type_name, $active_message_type_names)) {
393
-                    $active_message_type_names[] = $message_type_name;
394
-                }
395
-            }
396
-        }
397
-        return $active_message_type_names;
398
-    }
399
-
400
-
401
-    /**
402
-     * Same as list_of_active_message_types() except this returns actual EE_message_type objects
403
-     *
404
-     * @since 4.9.0
405
-     * @return \EE_message_type[]
406
-     */
407
-    public function get_active_message_type_objects()
408
-    {
409
-        $active_message_types      = array();
410
-        $installed_message_types   = $this->installed_message_types();
411
-        $active_message_type_names = $this->list_of_active_message_types();
412
-        foreach ($active_message_type_names as $active_message_type_name) {
413
-            if (isset($installed_message_types[$active_message_type_name])) {
414
-                $active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name];
415
-            }
416
-        }
417
-        return $active_message_types;
418
-    }
419
-
420
-
421
-    /**
422
-     * @return \EE_message_type[]
423
-     */
424
-    public function installed_message_types()
425
-    {
426
-        if (empty($this->_installed_message_types)) {
427
-            $this->message_type_collection()->rewind();
428
-            while ($this->message_type_collection()->valid()) {
429
-                $this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current();
430
-                $this->message_type_collection()->next();
431
-            }
432
-        }
433
-        return $this->_installed_message_types;
434
-    }
435
-
436
-
437
-    /**
438
-     * @param string $message_type_name
439
-     * @return \EE_message_type
440
-     * @throws \EE_Error
441
-     */
442
-    public function valid_message_type($message_type_name)
443
-    {
444
-        $message_type = $this->get_message_type($message_type_name);
445
-        if ($message_type instanceof EE_message_type) {
446
-            return $message_type;
447
-        }
448
-        throw new EE_Error(
449
-            sprintf(
450
-                __('The "%1$s" message type is either invalid or not installed', 'event_espresso'),
451
-                $message_type_name
452
-            )
453
-        );
454
-    }
455
-
456
-
457
-    /**
458
-     * valid_message_type_for_messenger
459
-     *
460
-     * @param EE_messenger $messenger
461
-     * @param string       $message_type_name
462
-     * @return boolean
463
-     * @throws \EE_Error
464
-     */
465
-    public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
466
-    {
467
-        $valid_message_types = $messenger->get_valid_message_types();
468
-        if (! in_array($message_type_name, $valid_message_types)) {
469
-            throw new EE_Error(
470
-                sprintf(
471
-                    __(
472
-                        'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger.  Double-check the spelling and verify that message type has been registered as a valid type with the messenger.',
473
-                        'event_espresso'
474
-                    ),
475
-                    $message_type_name,
476
-                    __METHOD__,
477
-                    $messenger->name
478
-                )
479
-            );
480
-        }
481
-        return true;
482
-    }
483
-
484
-
485
-    /**
486
-     * Used to return active messengers array stored in the wp options table.
487
-     * If no value is present in the option then an empty array is returned.
488
-     *
489
-     * @param   bool $reset     If true then we ignore whether the option is cached on the _active_message_types
490
-     *                          property and pull directly from the db.  Otherwise whatever is currently on the
491
-     *                          $_active_message_types property is pulled.
492
-     * @return array
493
-     */
494
-    public function get_active_messengers_option($reset = false)
495
-    {
496
-        if ($reset) {
497
-            $this->_active_message_types = get_option('ee_active_messengers', array());
498
-        }
499
-        return $this->_active_message_types;
500
-    }
501
-
502
-
503
-    /**
504
-     * Used to update the active messengers array stored in the wp options table.
505
-     *
506
-     * @param array $active_messenger_settings Incoming data to save.  If empty, then the internal cached property
507
-     *                                         representing this data is used.
508
-     * @return bool FALSE if not updated, TRUE if updated.
509
-     */
510
-    public function update_active_messengers_option($active_messenger_settings = array())
511
-    {
512
-        $active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings;
513
-        //make sure _active_message_types is updated (this is the internal cache for the settings).
514
-        $this->_active_message_types = $active_messenger_settings;
515
-        return update_option('ee_active_messengers', $active_messenger_settings);
516
-    }
517
-
518
-
519
-    /**
520
-     * Used to return has activated message types for messengers array stored in the wp options table.
521
-     * If no value is present in the option then an empty array is returned.
522
-     * The value is cached on the $_has_activated_messengers_and_message_types property for future calls.
523
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
524
-     *
525
-     * @param   bool $reset Used to indicate that any cached value should be ignored.
526
-     * @return array
527
-     */
528
-    public function get_has_activated_messengers_option($reset = false)
529
-    {
530
-        if ($reset || empty($this->_has_activated_messengers_and_message_types)) {
531
-            $this->_has_activated_messengers_and_message_types = get_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, array());
532
-        }
533
-        return $this->_has_activated_messengers_and_message_types;
534
-    }
535
-
536
-
537
-    /**
538
-     * Used to update the has activated option in the db.
539
-     *
540
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
541
-     *
542
-     * @param array $has_activated_messengers Incoming data to save.  If empty, then the internal cached property
543
-     *                                        representing this data is used.
544
-     * @return bool FALSE if not updated, TRUE if updated.
545
-     */
546
-    public function update_has_activated_messengers_option($has_activated_messengers = array())
547
-    {
548
-        //make sure the option has been retrieved from first so we don't overwrite it accidentally.
549
-        if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) {
550
-            $this->get_has_activated_messengers_option();
551
-        }
552
-        $has_activated_messengers = empty($has_activated_messengers)
553
-            ? $this->_has_activated_messengers_and_message_types
554
-            : $has_activated_messengers;
555
-        return update_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, $has_activated_messengers);
556
-    }
557
-
558
-
559
-    /**
560
-     * wrapper for _set_active_messengers_and_message_types()
561
-     */
562
-    public function reset_active_messengers_and_message_types()
563
-    {
564
-        $this->_set_active_messengers_and_message_types();
565
-    }
566
-
567
-
568
-    /**
569
-     * Generate list of active messengers and message types from collection.
570
-     * This sets up the active messengers from what is present in the database.
571
-     */
572
-    protected function _set_active_messengers_and_message_types()
573
-    {
574
-        //echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n";
575
-        // list of activated messengers as set via the admin
576
-        // note calling `get_active_messengers_options` also initializes the _active_message_types property.
577
-        $this->get_active_messengers_option(true);
578
-        $this->ensure_messengers_are_active(array(), false, true);
579
-        $this->update_active_messengers_option();
580
-        $this->update_has_activated_messengers_option();
581
-    }
582
-
583
-
584
-    /**
585
-     * Ensures that the specified messenger is currently active.
586
-     * If not, activates it and its default message types.
587
-     *
588
-     * @param string $messenger_name
589
-     * @param bool   $update_option Whether to update the option in the db or not.
590
-     * @return boolean true if either already active or successfully activated.
591
-     */
592
-    public function ensure_messenger_is_active($messenger_name, $update_option = true)
593
-    {
594
-        if (! isset($this->_active_messengers[$messenger_name])) {
595
-            try {
596
-                $this->activate_messenger($messenger_name, array(), $update_option);
597
-            } catch (EE_Error $e) {
598
-                EE_Error::add_error(
599
-                    $e->getMessage(),
600
-                    __FILE__,
601
-                    __FUNCTION__,
602
-                    __LINE__
603
-                );
604
-                return false;
605
-            }
606
-        }
607
-        return true;
608
-    }
609
-
610
-
611
-    /**
612
-     * This ensures the given array of messenger names is active in the system.
613
-     * Note, this method will not activate any NEW message types for the messenger when it is called. Instead,
614
-     * it will automatically activate the default message types for the messenger if its not active.
615
-     *
616
-     * @param array $messenger_names  Array of messenger names for messengers to be activated.  If an empty array
617
-     *                                (default) then will attempt to set the active messengers from the
618
-     *                                activated_messengers option
619
-     *                                (stored in $_active_message_types property).
620
-     * @param bool  $update_option    Whether to update the related active messengers option.
621
-     * @param bool  $verify           Whether to verify the messengers are installed before activating. Note if this is
622
-     *                                set to true and a messenger is indicated as active, but is NOT installed, then it
623
-     *                                will automatically be deactivated.
624
-     */
625
-    public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false)
626
-    {
627
-        $messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names;
628
-
629
-        $not_installed = array();
630
-        foreach ($messenger_names as $messenger_name) {
631
-            if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) {
632
-                $not_installed[] = $messenger_name;
633
-                $this->deactivate_messenger($messenger_name);
634
-                continue;
635
-            }
636
-            $this->ensure_messenger_is_active($messenger_name, $update_option);
637
-        }
638
-
639
-        if (! empty($not_installed)) {
640
-            EE_Error::add_error(
641
-                sprintf(
642
-                    __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
643
-                    '<br />',
644
-                    implode(', ', $not_installed)
645
-                ),
646
-                __FILE__, __FUNCTION__, __LINE__
647
-            );
648
-        }
649
-    }
650
-
651
-
652
-    /**
653
-     * Ensures that the specified message type for the given messenger is currently active, if not activates it.
654
-     * This ALSO ensures that the given messenger is active as well!
655
-     *
656
-     * @param string $message_type_name message type name.
657
-     * @param        $messenger_name
658
-     * @param bool   $update_option     Whether to update the option in the db or not.
659
-     * @return bool  Returns true if already is active or if was activated successfully.
660
-     * @throws \EE_Error
661
-     */
662
-    public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true)
663
-    {
664
-        // grab the messenger to work with.
665
-        $messenger = $this->valid_messenger($messenger_name);
666
-        if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) {
667
-            //ensure messenger is active (that's an inherent coupling between active message types and the
668
-            //messenger they are being activated for.
669
-            try {
670
-                if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
671
-                    //all is good so let's just get it active
672
-                    $this->activate_messenger($messenger_name, array($message_type_name), $update_option);
673
-                }
674
-            } catch (EE_Error $e) {
675
-                EE_Error::add_error(
676
-                    $e->getMessage(),
677
-                    __FILE__,
678
-                    __FUNCTION__,
679
-                    __LINE__
680
-                );
681
-                return false;
682
-            }
683
-        }
684
-        return true;
685
-    }
686
-
687
-
688
-    /**
689
-     * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a
690
-     * messenger are active in one go.
691
-     *
692
-     * @param array  $message_type_names Array of message type names to ensure are active.
693
-     * @param string $messenger_name     The name of the messenger that the message types are to be activated on.
694
-     * @param bool   $update_option      Whether to persist the activation to the database or not (default true).
695
-     */
696
-    public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
697
-    {
698
-        $message_type_names = (array)$message_type_names;
699
-        foreach ($message_type_names as $message_type_name) {
700
-            // note, intentionally not updating option here because we're in a loop.
701
-            // We'll follow the instructions of the incoming $update_option argument after the loop.
702
-            $this->ensure_message_type_is_active($message_type_name, $messenger_name, false);
703
-        }
704
-        if ($update_option) {
705
-            $this->update_active_messengers_option();
706
-            $this->update_has_activated_messengers_option();
707
-        }
708
-    }
709
-
710
-
711
-    /**
712
-     * Activates the specified messenger.
713
-     *
714
-     * @param string $messenger_name
715
-     * @param array  $message_type_names        An array of message type names to activate with this messenger.
716
-     *                                          If included we do NOT setup the default message types
717
-     *                                          (assuming they are already setup.)
718
-     * @param bool   $update_active_messengers_option
719
-     * @return array of generated templates
720
-     * @throws \EE_Error
721
-     */
722
-    public function activate_messenger(
723
-        $messenger_name,
724
-        $message_type_names = array(),
725
-        $update_active_messengers_option = true
726
-    ) {
727
-        $templates = array();
728
-        // grab the messenger to work with.
729
-        $messenger = $this->messenger_collection()->get_by_info($messenger_name);
730
-        // it's inactive. Activate it.
731
-        if ($messenger instanceof EE_messenger) {
732
-            $this->_active_messengers[$messenger->name] = $messenger;
733
-            //activate incoming message types set to be activated with messenger.
734
-            $message_type_names = $this->_activate_message_types($messenger, $message_type_names);
735
-            // setup any initial settings for the messenger if necessary.
736
-            $this->add_settings_for_messenger($messenger->name);
737
-            if ($update_active_messengers_option) {
738
-                $this->update_active_messengers_option();
739
-                $this->update_has_activated_messengers_option();
740
-            }
741
-            //generate new templates if necessary and ensure all related templates that are already in the database are
742
-            //marked active.  Note, this will also deactivate a message type for a messenger if the template
743
-            //cannot be successfully created during its attempt (only happens for global template attempts).
744
-            if (! empty($message_type_names)) {
745
-                $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
746
-                EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
747
-            }
748
-        }
749
-        return $templates;
750
-    }
751
-
752
-
753
-    /**
754
-     * Activates given message types for the given EE_messenger object.
755
-     * Note: (very important) This method does not persist the activation to the database.
756
-     * See code implementing this method in this class for examples of how to persist.
757
-     *
758
-     * @param \EE_messenger $messenger
759
-     * @param  array        $message_type_names
760
-     * @return array
761
-     */
762
-    protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array())
763
-    {
764
-        //If $message_type_names is empty, AND $this->_active_message_types is empty, then that means
765
-        //things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
766
-        //So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
767
-        //only override _active_message_types when an explicit array of $message_type_names has been provided.
768
-        $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
769
-            ? $messenger->get_default_message_types()
770
-            : (array)$message_type_names;
771
-
772
-        //now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
773
-        if (! isset($this->_active_message_types[$messenger->name])) {
774
-            $this->_active_message_types[$messenger->name]['settings'] = array();
775
-        }
776
-
777
-        if ($message_type_names) {
778
-            // cycle thru message types
779
-            foreach ($message_type_names as $message_type_name) {
780
-                //only register the message type as active IF it isn't already active
781
-                //and if its actually installed.
782
-                if (
783
-                ! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
784
-                ) {
785
-                    $this->add_settings_for_message_type($messenger->name, $message_type_name);
786
-                    $this->_set_messenger_has_activated_message_type(
787
-                        $messenger,
788
-                        $message_type_name
789
-                    );
790
-                }
791
-            }
792
-        }
793
-        return $message_type_names;
794
-    }
795
-
796
-
797
-    /**
798
-     * add_settings_for_message_type
799
-     * NOTE This does NOT automatically persist any settings to the db.  Client code should call
800
-     * $this->update_active_messengers_option to persist.
801
-     *
802
-     * @param  string $messenger_name    The name of the messenger adding the settings for
803
-     * @param  string $message_type_name The name of the message type adding the settings for
804
-     * @param  array  $new_settings      Any new settings being set for the message type and messenger
805
-     */
806
-    public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array())
807
-    {
808
-        // get installed message type from collection
809
-        $message_type      = $this->message_type_collection()->get_by_info($message_type_name);
810
-        $existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name);
811
-        //we need to setup any initial settings for message types
812
-        if ($message_type instanceof EE_message_type) {
813
-            $default_settings = $message_type->get_admin_settings_fields();
814
-            foreach ($default_settings as $field => $values) {
815
-                if (isset($new_settings[$field])) {
816
-                    $existing_settings[$field] = $new_settings[$field];
817
-                    continue;
818
-                }
819
-                if (! isset($existing_settings[$field])) {
820
-                    $existing_settings[$field] = $values['default'];
821
-                }
822
-            }
823
-        }
824
-        $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
825
-    }
826
-
827
-
828
-    /**
829
-     * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger
830
-     * and message type.
831
-     *
832
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
833
-     *
834
-     * @access protected
835
-     * @param \EE_messenger $messenger
836
-     * @param string        $message_type_name
837
-     */
838
-    protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name)
839
-    {
840
-
841
-        //if _has_activated_messengers_and_message_types is empty then lets ensure its initialized
842
-        if (empty($this->_has_activated_messengers_and_message_types)) {
843
-            $this->get_has_activated_messengers_option();
844
-        }
845
-
846
-        // make sure this messenger has a record in the has_activated array
847
-        if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
848
-            $this->_has_activated_messengers_and_message_types[$messenger->name] = array();
849
-        }
850
-        // check if message type has already been added
851
-        if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
852
-            $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
853
-        }
854
-    }
855
-
856
-
857
-    /**
858
-     * add_settings_for_messenger
859
-     * NOTE This does NOT automatically persist any settings to the db.  Client code should call
860
-     * $this->update_active_messengers_option to persist.
861
-     *
862
-     * @param string $messenger_name The name of the messenger the settings is being added for.
863
-     * @param array  $new_settings   An array of settings to update the existing settings.
864
-     */
865
-    public function add_settings_for_messenger($messenger_name, $new_settings = array())
866
-    {
867
-        $messenger = $this->get_messenger($messenger_name);
868
-        if ($messenger instanceof EE_messenger) {
869
-            $msgr_settings = $messenger->get_admin_settings_fields();
870
-            if (! empty($msgr_settings)) {
871
-                foreach ($msgr_settings as $field => $value) {
872
-                    //is there a new setting for this?
873
-                    if (isset($new_settings[$field])) {
874
-                        $this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field];
875
-                        continue;
876
-                    }
877
-                    //only set the default if it isn't already set.
878
-                    if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
879
-                        $this->_active_message_types[$messenger->name]['settings'][$field] = $value;
880
-                    }
881
-                }
882
-            }
883
-        }
884
-    }
885
-
886
-
887
-    /**
888
-     * deactivate_messenger
889
-     *
890
-     * @param  string|EE_messenger $messenger_name name of messenger
891
-     * @return void
892
-     */
893
-    public function deactivate_messenger($messenger_name)
894
-    {
895
-        $this->_initialize_collections();
896
-        if ($messenger_name instanceof EE_messenger) {
897
-            $messenger_name = $messenger_name->name;
898
-        }
899
-        unset($this->_active_messengers[$messenger_name]);
900
-        unset($this->_active_message_types[$messenger_name]);
901
-        $this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
902
-        $this->update_active_messengers_option();
903
-    }
904
-
905
-
906
-    /**
907
-     * Deactivates a message type (note this will deactivate across all messenger's it is active on.
908
-     *
909
-     * @param  string $message_type_name     name of message type being deactivated
910
-     * @param bool    $set_has_active_record By default we always record the has_active record when deactivating a message
911
-     *                                       type.  However, this can be overridden if we don't want this set (usually when
912
-     *                                       this is called as a part of deregistration of a custom message type)
913
-     */
914
-    public function deactivate_message_type($message_type_name, $set_has_active_record = true)
915
-    {
916
-        $this->_initialize_collections();
917
-        if ($message_type_name instanceof EE_message_type) {
918
-            $message_type_name = $message_type_name->name;
919
-        }
920
-        foreach ($this->_active_message_types as $messenger_name => $settings) {
921
-            unset(
922
-                $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
923
-            );
924
-
925
-            //we always record (even on deactivation) that a message type has been activated because there should at
926
-            //least be a record in the "has_activated" option that it WAS active at one point.
927
-            if ($set_has_active_record) {
928
-                $messenger = $this->get_messenger($messenger_name);
929
-                $this->_set_messenger_has_activated_message_type($messenger, $message_type_name);
930
-            }
931
-        }
932
-        $this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name);
933
-        $this->update_active_messengers_option();
934
-        $this->update_has_activated_messengers_option();
935
-    }
936
-
937
-
938
-    /**
939
-     * Deactivates a message type for a specific messenger as opposed to all messengers.
940
-     *
941
-     * @param string $message_type_name Name of message type being deactivated.
942
-     * @param string $messenger_name    Name of messenger the message type is being deactivated for.
943
-     */
944
-    public function deactivate_message_type_for_messenger($message_type_name, $messenger_name)
945
-    {
946
-        $this->_initialize_collections();
947
-        if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
948
-            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
949
-        }
950
-        $this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
951
-            array($message_type_name));
952
-        $this->update_active_messengers_option();
953
-    }
954
-
955
-
956
-    /**
957
-     * Used to verify if a message can be sent for the given messenger and message type
958
-     * and that it is a generating messenger (used for generating message templates).
959
-     *
960
-     * @param EE_messenger    $messenger    messenger used in trigger
961
-     * @param EE_message_type $message_type message type used in trigger
962
-     * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
963
-     */
964
-    public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
965
-    {
966
-        //get the $messengers the message type says it can be used with.
967
-        foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) {
968
-            if (
969
-                $messenger->name === $generating_messenger
970
-                && $this->is_message_type_active_for_messenger($messenger->name, $message_type->name)
971
-            ) {
972
-                return true;
973
-            }
974
-        }
975
-        return false;
976
-    }
977
-
978
-
979
-    /**
980
-     * This returns all the contexts that are registered by all message types.
981
-     * If $slugs_only is true,
982
-     * then just an array indexed by unique context slugs with the latest label representation for that slug.
983
-     * array(
984
-     *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
985
-     * );
986
-     * If $slugs_only is false, then the format is:
987
-     * array(
988
-     *      'message_type_name' => array(
989
-     *          'context_slug' => array(
990
-     *              'label' => 'localized label for context',
991
-     *              'description' => 'localized description for context'
992
-     *          )
993
-     *      )
994
-     * );
995
-     * Keep in mind that although different message types may share the same context slugs,
996
-     * it is possible that the context is described differently by the message type.
997
-     *
998
-     * @since 4.9.0
999
-     * @param   bool $slugs_only Whether to return an array of just slugs and labels (true)
1000
-     *                           or all contexts indexed by message type.
1001
-     * @return array
1002
-     */
1003
-    public function get_all_contexts($slugs_only = true)
1004
-    {
1005
-        $key = $slugs_only ? 'slugs' : 'all';
1006
-        // check if contexts has been setup yet.
1007
-        if (empty($this->_contexts[$key])) {
1008
-            // So let's get all active message type objects and loop through to get all unique contexts
1009
-            foreach ($this->get_active_message_type_objects() as $message_type) {
1010
-                if ($message_type instanceof EE_message_type) {
1011
-                    $message_type_contexts = $message_type->get_contexts();
1012
-                    if ($slugs_only) {
1013
-                        foreach ($message_type_contexts as $context => $context_details) {
1014
-                            $this->_contexts[$key][$context] = $context_details['label'];
1015
-                        }
1016
-                    } else {
1017
-                        $this->_contexts[$key][$message_type->name] = $message_type_contexts;
1018
-                    }
1019
-                }
1020
-            }
1021
-        }
1022
-        return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array();
1023
-    }
1024
-
1025
-
1026
-    /**
1027
-     * This checks the internal record of what message types are considered "active" and verifies that
1028
-     * there is an installed class definition for that message type.  If the active message type does not have a
1029
-     * corresponding accessible message type class then it will be deactivated from all messengers it is active on and
1030
-     * any related message templates will be inactivated as well.
1031
-     *
1032
-     * @return bool   true means all active message types are valid, false means at least one message type was
1033
-     *                deactivated.
1034
-     */
1035
-    public function validate_active_message_types_are_installed()
1036
-    {
1037
-        $list_of_active_message_type_names = $this->list_of_active_message_types();
1038
-        $installed_message_types           = $this->installed_message_types();
1039
-        $all_message_types_valid           = true;
1040
-        //loop through list of active message types and verify they are installed.
1041
-        foreach ($list_of_active_message_type_names as $message_type_name) {
1042
-            if (! isset($installed_message_types[$message_type_name])) {
1043
-                $this->remove_message_type_has_been_activated_from_all_messengers(
1044
-                    $message_type_name,
1045
-                    true
1046
-                );
1047
-                $this->deactivate_message_type($message_type_name, false);
1048
-                $all_message_types_valid = false;
1049
-            }
1050
-        }
1051
-        return $all_message_types_valid;
1052
-    }
1053
-
1054
-
1055
-    /**
1056
-     * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been
1057
-     * activated for the given messenger.  This can be called by client code on plugin updates etc to determine whether
1058
-     * to attempt automatically reactivating message types that should be activated by default or not.
1059
-     *
1060
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1061
-     *
1062
-     * @param $message_type_name
1063
-     * @param $messenger_name
1064
-     * @return bool
1065
-     */
1066
-    public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1067
-    {
1068
-        $has_activated = $this->get_has_activated_messengers_option();
1069
-        return isset($has_activated[$messenger_name])
1070
-               && in_array($message_type_name, $has_activated[$messenger_name]);
1071
-    }
1072
-
1073
-
1074
-    /**
1075
-     * This method unsets a message type from the given messenger has activated option.
1076
-     *
1077
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1078
-     *
1079
-     * @param string $message_type_name
1080
-     * @param string $messenger_name
1081
-     * @param bool   $consider_current_state  Whether to consider whether the  message type is currently active or not.
1082
-     *                                        If it is currently active, then remove.  Otherwise leave it alone.
1083
-     */
1084
-    public function remove_message_type_has_been_activated_for_messenger(
1085
-        $message_type_name,
1086
-        $messenger_name,
1087
-        $consider_current_state = false
1088
-    ) {
1089
-        if ($consider_current_state
1090
-            && ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
1091
-        ) {
1092
-            //when consider current state is true, this means we don't want to change anything on the "has_activated"
1093
-            //record if the message type is currently active for this messenger.  This is used when we want to retain
1094
-            //the record for user initiated inactivations of the message type.
1095
-            return;
1096
-        }
1097
-        $has_activated = $this->get_has_activated_messengers_option();
1098
-        $key_for_message_type = isset($has_activated[$messenger_name])
1099
-            ? array_search($message_type_name, $has_activated[$messenger_name], true)
1100
-            : false;
1101
-        if ($key_for_message_type !== false) {
1102
-            unset($has_activated[$messenger_name][$key_for_message_type]);
1103
-            $this->update_has_activated_messengers_option($has_activated);
1104
-            //reset the internal cached property
1105
-            $this->get_has_activated_messengers_option(true);
1106
-        }
1107
-    }
1108
-
1109
-
1110
-    /**
1111
-     * Removes a message type active record from all messengers it is attached to.
1112
-     *
1113
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1114
-     *
1115
-     * @param      $message_type_name
1116
-     * @param bool $consider_current_state  Whether to consider whether the  message type is currently active or not.
1117
-     *                                      If it is currently active, then remove.  Otherwise leave it alone.
1118
-     */
1119
-    public function remove_message_type_has_been_activated_from_all_messengers(
1120
-        $message_type_name,
1121
-        $consider_current_state = false
1122
-    ) {
1123
-        foreach(array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1124
-            $this->remove_message_type_has_been_activated_for_messenger(
1125
-                $message_type_name,
1126
-                $messenger_name,
1127
-                $consider_current_state
1128
-            );
1129
-        }
1130
-    }
20
+	/**
21
+	 * This option in the database is used to keep a record of message types that have been activated for a messenger
22
+	 * at some point in the history of the site.  It is utilized by the implementation of the 'force' flag in
23
+	 * EE_Register_Message_Type.  The force flag is an indication of whether a message type should be activated by
24
+	 * default when the message type is registered.  However, if a user has explicitly deactivated a message type, then
25
+	 * the force flag is ignored.  The method by which the code knows whether to ignore this flag is via this option.
26
+	 * Note, that this is NOT a historical record.  Its entirely possible for a message type to have been activated for
27
+	 * a messenger and yet not have a record in this option.  This occurs when a message type is inactivated through an
28
+	 * automated process (when an add-on registering the message type deactivates, or when some other code calls the
29
+	 * EE_Registery_Message_Type::deregister method) and the related record(s) is(are) removed from this option to ensure
30
+	 * the "force" flag is respected if that message type is later re-registered.
31
+	 *
32
+	 * This option should NOT be used to determine the current "active" state of a message type for a given messenger.
33
+	 *
34
+	 * The name of this option (and related methods/properties) is due to matching the original intended purpose for the
35
+	 * option that got superseded by later behaviour requirements.
36
+	 */
37
+	const HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME = 'ee_has_activated_messenger';
38
+
39
+	/**
40
+	 * @type boolean $_initialized
41
+	 */
42
+	protected $_initialized = false;
43
+
44
+	/**
45
+	 * @type EE_Messenger_Collection $_messenger_collection_loader
46
+	 */
47
+	protected $_messenger_collection_loader;
48
+
49
+	/**
50
+	 * @type EE_Message_Type_Collection $_message_type_collection_loader
51
+	 */
52
+	protected $_message_type_collection_loader;
53
+
54
+	/**
55
+	 * @type EEM_Message_Template_Group $_message_template_group_model
56
+	 */
57
+	protected $_message_template_group_model;
58
+
59
+	/**
60
+	 * @type EE_messenger[]
61
+	 */
62
+	protected $_installed_messengers = array();
63
+
64
+	/**
65
+	 * @type EE_message_type[]
66
+	 */
67
+	protected $_installed_message_types = array();
68
+
69
+	/**
70
+	 * Array of active messengers.
71
+	 * Format is this:
72
+	 * array(
73
+	 *      'messenger_name' => EE_messenger
74
+	 * )
75
+	 *
76
+	 * @type EE_messenger[]
77
+	 */
78
+	protected $_active_messengers = array();
79
+
80
+	/**
81
+	 * Formatted array of active message types grouped per messenger.
82
+	 * Format is this:
83
+	 * array(
84
+	 *      'messenger_name' => array(
85
+	 *          'settings' => array(
86
+	 *              '{messenger_name}-message_types' => array(
87
+	 *                  'message_type_name' => array() //variable array of settings corresponding to message type.
88
+	 *              )
89
+	 *          )
90
+	 *      )
91
+	 * )
92
+	 *
93
+	 * @type array
94
+	 */
95
+	protected $_active_message_types = array();
96
+
97
+
98
+	/**
99
+	 * This holds the array of messengers and their corresponding message types that have
100
+	 * been activated on a site at some point.  This is an important record that helps the messages system
101
+	 * not accidentally reactivate something that was intentionally deactivated by a user.
102
+	 *
103
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
104
+	 *
105
+	 * @type array
106
+	 */
107
+	protected $_has_activated_messengers_and_message_types = array();
108
+
109
+	/**
110
+	 * An array of unique message type contexts across all active message types.
111
+	 * The array will be indexed by either 'slugs' or 'all'.
112
+	 * The slugs index contains an array indexed by unique context slugs with the latest label representation for that
113
+	 * slug. array(
114
+	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
115
+	 * );
116
+	 * The all index returns an array in this format:
117
+	 * array(
118
+	 *      'message_type_name' => array(
119
+	 *          'context_slug' => array(
120
+	 *              'label' => 'localized label for context',
121
+	 *              'description' => 'localized description for context'
122
+	 *          )
123
+	 *      )
124
+	 * );
125
+	 *
126
+	 * @type array
127
+	 */
128
+	protected $_contexts = array();
129
+
130
+
131
+	/**
132
+	 * EE_Message_Resource_Manager constructor.
133
+	 *
134
+	 * @param \EE_Messenger_Collection_Loader    $Messenger_Collection_Loader
135
+	 * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader
136
+	 * @param \EEM_Message_Template_Group        $Message_Template_Group_Model
137
+	 */
138
+	function __construct(
139
+		EE_Messenger_Collection_Loader $Messenger_Collection_Loader,
140
+		EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader,
141
+		EEM_Message_Template_Group $Message_Template_Group_Model
142
+	) {
143
+		$this->_messenger_collection_loader    = $Messenger_Collection_Loader;
144
+		$this->_message_type_collection_loader = $Message_Type_Collection_Loader;
145
+		$this->_message_template_group_model   = $Message_Template_Group_Model;
146
+	}
147
+
148
+
149
+	/**
150
+	 * @return void
151
+	 */
152
+	protected function _initialize_collections()
153
+	{
154
+		if ($this->_initialized) {
155
+			return;
156
+		}
157
+		$this->_initialized = true;
158
+		$this->_messenger_collection_loader->load_messengers_from_folder();
159
+		$this->_message_type_collection_loader->load_message_types_from_folder();
160
+		$this->get_has_activated_messengers_option(true);
161
+		$this->_set_active_messengers_and_message_types();
162
+	}
163
+
164
+
165
+	/**
166
+	 * @return EE_Messenger_Collection
167
+	 */
168
+	public function messenger_collection()
169
+	{
170
+		$this->_initialize_collections();
171
+		return $this->_messenger_collection_loader->messenger_collection();
172
+	}
173
+
174
+
175
+	/**
176
+	 * @return EE_messenger[]
177
+	 */
178
+	public function active_messengers()
179
+	{
180
+		$this->_initialize_collections();
181
+		return $this->_active_messengers;
182
+	}
183
+
184
+
185
+	/**
186
+	 * @param string $messenger_name
187
+	 * @return \EE_messenger
188
+	 */
189
+	public function get_messenger($messenger_name)
190
+	{
191
+		return $this->messenger_collection()->get_by_info($messenger_name);
192
+	}
193
+
194
+
195
+	/**
196
+	 * This returns the corresponding EE_messenger object for the given string if it is active.
197
+	 *
198
+	 * @param string $messenger
199
+	 * @return EE_messenger | null
200
+	 */
201
+	public function get_active_messenger($messenger)
202
+	{
203
+		$this->_initialize_collections();
204
+		return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null;
205
+	}
206
+
207
+
208
+	/**
209
+	 * @return \EE_messenger[]
210
+	 */
211
+	public function installed_messengers()
212
+	{
213
+		if (empty($this->_installed_messengers)) {
214
+			$this->_installed_messengers = array();
215
+			$this->messenger_collection()->rewind();
216
+			while ($this->messenger_collection()->valid()) {
217
+				$this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current();
218
+				$this->messenger_collection()->next();
219
+			}
220
+		}
221
+		return $this->_installed_messengers;
222
+	}
223
+
224
+
225
+	/**
226
+	 * @param string $messenger_name
227
+	 * @return \EE_messenger
228
+	 * @throws \EE_Error
229
+	 */
230
+	public function valid_messenger($messenger_name)
231
+	{
232
+		$messenger = $this->get_messenger($messenger_name);
233
+		if ($messenger instanceof EE_messenger) {
234
+			return $messenger;
235
+		}
236
+		throw new EE_Error(
237
+			sprintf(
238
+				__('The "%1$s" messenger is either invalid or not installed', 'event_espresso'),
239
+				$messenger_name
240
+			)
241
+		);
242
+	}
243
+
244
+
245
+	/**
246
+	 * @return EE_Message_Type_Collection
247
+	 */
248
+	public function message_type_collection()
249
+	{
250
+		$this->_initialize_collections();
251
+		return $this->_message_type_collection_loader->message_type_collection();
252
+	}
253
+
254
+
255
+	/**
256
+	 * @return array
257
+	 */
258
+	public function active_message_types()
259
+	{
260
+		$this->_initialize_collections();
261
+		return $this->_active_message_types;
262
+	}
263
+
264
+
265
+	/**
266
+	 * @param string $message_type_name
267
+	 * @return \EE_message_type
268
+	 */
269
+	public function get_message_type($message_type_name)
270
+	{
271
+		return $this->message_type_collection()->get_by_info($message_type_name);
272
+	}
273
+
274
+
275
+	/**
276
+	 * This returns the EE_message_type from the active message types array ( if present );
277
+	 *
278
+	 * @param string $messenger_name
279
+	 * @param string $message_type_name
280
+	 * @return \EE_message_type|null
281
+	 */
282
+	public function get_active_message_type_for_messenger($messenger_name, $message_type_name)
283
+	{
284
+		return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
285
+			? $this->get_message_type($message_type_name)
286
+			: null;
287
+	}
288
+
289
+
290
+	/**
291
+	 * Returns whether the given message type is active for the given messenger.
292
+	 *
293
+	 * @param string $messenger_name
294
+	 * @param string $message_type_name
295
+	 * @return bool
296
+	 */
297
+	public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
298
+	{
299
+		$this->_initialize_collections();
300
+		return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
301
+	}
302
+
303
+
304
+	/**
305
+	 * Returns whether the given messenger is active.
306
+	 *
307
+	 * @param string $messenger_name the name of the messenger to check if active.
308
+	 * @return bool
309
+	 */
310
+	public function is_messenger_active($messenger_name)
311
+	{
312
+		$this->_initialize_collections();
313
+		return ! empty($this->_active_message_types[$messenger_name]);
314
+	}
315
+
316
+
317
+	/**
318
+	 * This returns any settings that might be on a message type for a messenger
319
+	 *
320
+	 * @param string $messenger_name    The slug of the messenger
321
+	 * @param string $message_type_name The slug of the message type getting the settings for.
322
+	 * @return array
323
+	 */
324
+	public function get_message_type_settings_for_messenger($messenger_name, $message_type_name)
325
+	{
326
+		$settings = array();
327
+		if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
328
+			$settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
329
+				? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
330
+				: array();
331
+		}
332
+		return $settings;
333
+	}
334
+
335
+
336
+	/**
337
+	 * Returns whether the given messenger name has active message types on it.
338
+	 * Infers whether the messenger is active or not as well.
339
+	 *
340
+	 * @param string $messenger_name
341
+	 * @return bool
342
+	 */
343
+	public function messenger_has_active_message_types($messenger_name)
344
+	{
345
+		$this->_initialize_collections();
346
+		return
347
+			! empty($this->_active_message_types[$messenger_name])
348
+			&& ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
349
+	}
350
+
351
+
352
+	/**
353
+	 * This checks the _active_message_types property for any active message types
354
+	 * that are present for the given messenger and returns them.
355
+	 *
356
+	 * @since 4.9.0
357
+	 * @param string $messenger_name The messenger being checked
358
+	 * @return EE_message_type[]|array    (empty array if no active_message_types)
359
+	 */
360
+	public function get_active_message_types_for_messenger($messenger_name)
361
+	{
362
+		$message_types = array();
363
+		if (! $this->messenger_has_active_message_types($messenger_name)) {
364
+			return $message_types;
365
+		}
366
+		$installed_message_types = $this->installed_message_types();
367
+		foreach ($installed_message_types as $message_type_name => $message_type) {
368
+			if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
369
+				$message_types[$message_type_name] = $message_type;
370
+			}
371
+		}
372
+		return $message_types;
373
+	}
374
+
375
+
376
+	/**
377
+	 * This does NOT return the _active_message_types property but
378
+	 * simply returns an array of active message type names from that property.
379
+	 * (The _active_message_types property is indexed by messenger and active message_types per messenger).
380
+	 *
381
+	 * @return array message_type references (string)
382
+	 */
383
+	public function list_of_active_message_types()
384
+	{
385
+		$active_message_type_names = array();
386
+		$this->_initialize_collections();
387
+		foreach ($this->_active_message_types as $messenger => $messenger_settings) {
388
+			if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
389
+				continue;
390
+			}
391
+			foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
392
+				if (! in_array($message_type_name, $active_message_type_names)) {
393
+					$active_message_type_names[] = $message_type_name;
394
+				}
395
+			}
396
+		}
397
+		return $active_message_type_names;
398
+	}
399
+
400
+
401
+	/**
402
+	 * Same as list_of_active_message_types() except this returns actual EE_message_type objects
403
+	 *
404
+	 * @since 4.9.0
405
+	 * @return \EE_message_type[]
406
+	 */
407
+	public function get_active_message_type_objects()
408
+	{
409
+		$active_message_types      = array();
410
+		$installed_message_types   = $this->installed_message_types();
411
+		$active_message_type_names = $this->list_of_active_message_types();
412
+		foreach ($active_message_type_names as $active_message_type_name) {
413
+			if (isset($installed_message_types[$active_message_type_name])) {
414
+				$active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name];
415
+			}
416
+		}
417
+		return $active_message_types;
418
+	}
419
+
420
+
421
+	/**
422
+	 * @return \EE_message_type[]
423
+	 */
424
+	public function installed_message_types()
425
+	{
426
+		if (empty($this->_installed_message_types)) {
427
+			$this->message_type_collection()->rewind();
428
+			while ($this->message_type_collection()->valid()) {
429
+				$this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current();
430
+				$this->message_type_collection()->next();
431
+			}
432
+		}
433
+		return $this->_installed_message_types;
434
+	}
435
+
436
+
437
+	/**
438
+	 * @param string $message_type_name
439
+	 * @return \EE_message_type
440
+	 * @throws \EE_Error
441
+	 */
442
+	public function valid_message_type($message_type_name)
443
+	{
444
+		$message_type = $this->get_message_type($message_type_name);
445
+		if ($message_type instanceof EE_message_type) {
446
+			return $message_type;
447
+		}
448
+		throw new EE_Error(
449
+			sprintf(
450
+				__('The "%1$s" message type is either invalid or not installed', 'event_espresso'),
451
+				$message_type_name
452
+			)
453
+		);
454
+	}
455
+
456
+
457
+	/**
458
+	 * valid_message_type_for_messenger
459
+	 *
460
+	 * @param EE_messenger $messenger
461
+	 * @param string       $message_type_name
462
+	 * @return boolean
463
+	 * @throws \EE_Error
464
+	 */
465
+	public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
466
+	{
467
+		$valid_message_types = $messenger->get_valid_message_types();
468
+		if (! in_array($message_type_name, $valid_message_types)) {
469
+			throw new EE_Error(
470
+				sprintf(
471
+					__(
472
+						'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger.  Double-check the spelling and verify that message type has been registered as a valid type with the messenger.',
473
+						'event_espresso'
474
+					),
475
+					$message_type_name,
476
+					__METHOD__,
477
+					$messenger->name
478
+				)
479
+			);
480
+		}
481
+		return true;
482
+	}
483
+
484
+
485
+	/**
486
+	 * Used to return active messengers array stored in the wp options table.
487
+	 * If no value is present in the option then an empty array is returned.
488
+	 *
489
+	 * @param   bool $reset     If true then we ignore whether the option is cached on the _active_message_types
490
+	 *                          property and pull directly from the db.  Otherwise whatever is currently on the
491
+	 *                          $_active_message_types property is pulled.
492
+	 * @return array
493
+	 */
494
+	public function get_active_messengers_option($reset = false)
495
+	{
496
+		if ($reset) {
497
+			$this->_active_message_types = get_option('ee_active_messengers', array());
498
+		}
499
+		return $this->_active_message_types;
500
+	}
501
+
502
+
503
+	/**
504
+	 * Used to update the active messengers array stored in the wp options table.
505
+	 *
506
+	 * @param array $active_messenger_settings Incoming data to save.  If empty, then the internal cached property
507
+	 *                                         representing this data is used.
508
+	 * @return bool FALSE if not updated, TRUE if updated.
509
+	 */
510
+	public function update_active_messengers_option($active_messenger_settings = array())
511
+	{
512
+		$active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings;
513
+		//make sure _active_message_types is updated (this is the internal cache for the settings).
514
+		$this->_active_message_types = $active_messenger_settings;
515
+		return update_option('ee_active_messengers', $active_messenger_settings);
516
+	}
517
+
518
+
519
+	/**
520
+	 * Used to return has activated message types for messengers array stored in the wp options table.
521
+	 * If no value is present in the option then an empty array is returned.
522
+	 * The value is cached on the $_has_activated_messengers_and_message_types property for future calls.
523
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
524
+	 *
525
+	 * @param   bool $reset Used to indicate that any cached value should be ignored.
526
+	 * @return array
527
+	 */
528
+	public function get_has_activated_messengers_option($reset = false)
529
+	{
530
+		if ($reset || empty($this->_has_activated_messengers_and_message_types)) {
531
+			$this->_has_activated_messengers_and_message_types = get_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, array());
532
+		}
533
+		return $this->_has_activated_messengers_and_message_types;
534
+	}
535
+
536
+
537
+	/**
538
+	 * Used to update the has activated option in the db.
539
+	 *
540
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
541
+	 *
542
+	 * @param array $has_activated_messengers Incoming data to save.  If empty, then the internal cached property
543
+	 *                                        representing this data is used.
544
+	 * @return bool FALSE if not updated, TRUE if updated.
545
+	 */
546
+	public function update_has_activated_messengers_option($has_activated_messengers = array())
547
+	{
548
+		//make sure the option has been retrieved from first so we don't overwrite it accidentally.
549
+		if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) {
550
+			$this->get_has_activated_messengers_option();
551
+		}
552
+		$has_activated_messengers = empty($has_activated_messengers)
553
+			? $this->_has_activated_messengers_and_message_types
554
+			: $has_activated_messengers;
555
+		return update_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, $has_activated_messengers);
556
+	}
557
+
558
+
559
+	/**
560
+	 * wrapper for _set_active_messengers_and_message_types()
561
+	 */
562
+	public function reset_active_messengers_and_message_types()
563
+	{
564
+		$this->_set_active_messengers_and_message_types();
565
+	}
566
+
567
+
568
+	/**
569
+	 * Generate list of active messengers and message types from collection.
570
+	 * This sets up the active messengers from what is present in the database.
571
+	 */
572
+	protected function _set_active_messengers_and_message_types()
573
+	{
574
+		//echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n";
575
+		// list of activated messengers as set via the admin
576
+		// note calling `get_active_messengers_options` also initializes the _active_message_types property.
577
+		$this->get_active_messengers_option(true);
578
+		$this->ensure_messengers_are_active(array(), false, true);
579
+		$this->update_active_messengers_option();
580
+		$this->update_has_activated_messengers_option();
581
+	}
582
+
583
+
584
+	/**
585
+	 * Ensures that the specified messenger is currently active.
586
+	 * If not, activates it and its default message types.
587
+	 *
588
+	 * @param string $messenger_name
589
+	 * @param bool   $update_option Whether to update the option in the db or not.
590
+	 * @return boolean true if either already active or successfully activated.
591
+	 */
592
+	public function ensure_messenger_is_active($messenger_name, $update_option = true)
593
+	{
594
+		if (! isset($this->_active_messengers[$messenger_name])) {
595
+			try {
596
+				$this->activate_messenger($messenger_name, array(), $update_option);
597
+			} catch (EE_Error $e) {
598
+				EE_Error::add_error(
599
+					$e->getMessage(),
600
+					__FILE__,
601
+					__FUNCTION__,
602
+					__LINE__
603
+				);
604
+				return false;
605
+			}
606
+		}
607
+		return true;
608
+	}
609
+
610
+
611
+	/**
612
+	 * This ensures the given array of messenger names is active in the system.
613
+	 * Note, this method will not activate any NEW message types for the messenger when it is called. Instead,
614
+	 * it will automatically activate the default message types for the messenger if its not active.
615
+	 *
616
+	 * @param array $messenger_names  Array of messenger names for messengers to be activated.  If an empty array
617
+	 *                                (default) then will attempt to set the active messengers from the
618
+	 *                                activated_messengers option
619
+	 *                                (stored in $_active_message_types property).
620
+	 * @param bool  $update_option    Whether to update the related active messengers option.
621
+	 * @param bool  $verify           Whether to verify the messengers are installed before activating. Note if this is
622
+	 *                                set to true and a messenger is indicated as active, but is NOT installed, then it
623
+	 *                                will automatically be deactivated.
624
+	 */
625
+	public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false)
626
+	{
627
+		$messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names;
628
+
629
+		$not_installed = array();
630
+		foreach ($messenger_names as $messenger_name) {
631
+			if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) {
632
+				$not_installed[] = $messenger_name;
633
+				$this->deactivate_messenger($messenger_name);
634
+				continue;
635
+			}
636
+			$this->ensure_messenger_is_active($messenger_name, $update_option);
637
+		}
638
+
639
+		if (! empty($not_installed)) {
640
+			EE_Error::add_error(
641
+				sprintf(
642
+					__('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
643
+					'<br />',
644
+					implode(', ', $not_installed)
645
+				),
646
+				__FILE__, __FUNCTION__, __LINE__
647
+			);
648
+		}
649
+	}
650
+
651
+
652
+	/**
653
+	 * Ensures that the specified message type for the given messenger is currently active, if not activates it.
654
+	 * This ALSO ensures that the given messenger is active as well!
655
+	 *
656
+	 * @param string $message_type_name message type name.
657
+	 * @param        $messenger_name
658
+	 * @param bool   $update_option     Whether to update the option in the db or not.
659
+	 * @return bool  Returns true if already is active or if was activated successfully.
660
+	 * @throws \EE_Error
661
+	 */
662
+	public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true)
663
+	{
664
+		// grab the messenger to work with.
665
+		$messenger = $this->valid_messenger($messenger_name);
666
+		if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) {
667
+			//ensure messenger is active (that's an inherent coupling between active message types and the
668
+			//messenger they are being activated for.
669
+			try {
670
+				if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
671
+					//all is good so let's just get it active
672
+					$this->activate_messenger($messenger_name, array($message_type_name), $update_option);
673
+				}
674
+			} catch (EE_Error $e) {
675
+				EE_Error::add_error(
676
+					$e->getMessage(),
677
+					__FILE__,
678
+					__FUNCTION__,
679
+					__LINE__
680
+				);
681
+				return false;
682
+			}
683
+		}
684
+		return true;
685
+	}
686
+
687
+
688
+	/**
689
+	 * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a
690
+	 * messenger are active in one go.
691
+	 *
692
+	 * @param array  $message_type_names Array of message type names to ensure are active.
693
+	 * @param string $messenger_name     The name of the messenger that the message types are to be activated on.
694
+	 * @param bool   $update_option      Whether to persist the activation to the database or not (default true).
695
+	 */
696
+	public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
697
+	{
698
+		$message_type_names = (array)$message_type_names;
699
+		foreach ($message_type_names as $message_type_name) {
700
+			// note, intentionally not updating option here because we're in a loop.
701
+			// We'll follow the instructions of the incoming $update_option argument after the loop.
702
+			$this->ensure_message_type_is_active($message_type_name, $messenger_name, false);
703
+		}
704
+		if ($update_option) {
705
+			$this->update_active_messengers_option();
706
+			$this->update_has_activated_messengers_option();
707
+		}
708
+	}
709
+
710
+
711
+	/**
712
+	 * Activates the specified messenger.
713
+	 *
714
+	 * @param string $messenger_name
715
+	 * @param array  $message_type_names        An array of message type names to activate with this messenger.
716
+	 *                                          If included we do NOT setup the default message types
717
+	 *                                          (assuming they are already setup.)
718
+	 * @param bool   $update_active_messengers_option
719
+	 * @return array of generated templates
720
+	 * @throws \EE_Error
721
+	 */
722
+	public function activate_messenger(
723
+		$messenger_name,
724
+		$message_type_names = array(),
725
+		$update_active_messengers_option = true
726
+	) {
727
+		$templates = array();
728
+		// grab the messenger to work with.
729
+		$messenger = $this->messenger_collection()->get_by_info($messenger_name);
730
+		// it's inactive. Activate it.
731
+		if ($messenger instanceof EE_messenger) {
732
+			$this->_active_messengers[$messenger->name] = $messenger;
733
+			//activate incoming message types set to be activated with messenger.
734
+			$message_type_names = $this->_activate_message_types($messenger, $message_type_names);
735
+			// setup any initial settings for the messenger if necessary.
736
+			$this->add_settings_for_messenger($messenger->name);
737
+			if ($update_active_messengers_option) {
738
+				$this->update_active_messengers_option();
739
+				$this->update_has_activated_messengers_option();
740
+			}
741
+			//generate new templates if necessary and ensure all related templates that are already in the database are
742
+			//marked active.  Note, this will also deactivate a message type for a messenger if the template
743
+			//cannot be successfully created during its attempt (only happens for global template attempts).
744
+			if (! empty($message_type_names)) {
745
+				$templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
746
+				EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
747
+			}
748
+		}
749
+		return $templates;
750
+	}
751
+
752
+
753
+	/**
754
+	 * Activates given message types for the given EE_messenger object.
755
+	 * Note: (very important) This method does not persist the activation to the database.
756
+	 * See code implementing this method in this class for examples of how to persist.
757
+	 *
758
+	 * @param \EE_messenger $messenger
759
+	 * @param  array        $message_type_names
760
+	 * @return array
761
+	 */
762
+	protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array())
763
+	{
764
+		//If $message_type_names is empty, AND $this->_active_message_types is empty, then that means
765
+		//things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
766
+		//So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
767
+		//only override _active_message_types when an explicit array of $message_type_names has been provided.
768
+		$message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
769
+			? $messenger->get_default_message_types()
770
+			: (array)$message_type_names;
771
+
772
+		//now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
773
+		if (! isset($this->_active_message_types[$messenger->name])) {
774
+			$this->_active_message_types[$messenger->name]['settings'] = array();
775
+		}
776
+
777
+		if ($message_type_names) {
778
+			// cycle thru message types
779
+			foreach ($message_type_names as $message_type_name) {
780
+				//only register the message type as active IF it isn't already active
781
+				//and if its actually installed.
782
+				if (
783
+				! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
784
+				) {
785
+					$this->add_settings_for_message_type($messenger->name, $message_type_name);
786
+					$this->_set_messenger_has_activated_message_type(
787
+						$messenger,
788
+						$message_type_name
789
+					);
790
+				}
791
+			}
792
+		}
793
+		return $message_type_names;
794
+	}
795
+
796
+
797
+	/**
798
+	 * add_settings_for_message_type
799
+	 * NOTE This does NOT automatically persist any settings to the db.  Client code should call
800
+	 * $this->update_active_messengers_option to persist.
801
+	 *
802
+	 * @param  string $messenger_name    The name of the messenger adding the settings for
803
+	 * @param  string $message_type_name The name of the message type adding the settings for
804
+	 * @param  array  $new_settings      Any new settings being set for the message type and messenger
805
+	 */
806
+	public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array())
807
+	{
808
+		// get installed message type from collection
809
+		$message_type      = $this->message_type_collection()->get_by_info($message_type_name);
810
+		$existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name);
811
+		//we need to setup any initial settings for message types
812
+		if ($message_type instanceof EE_message_type) {
813
+			$default_settings = $message_type->get_admin_settings_fields();
814
+			foreach ($default_settings as $field => $values) {
815
+				if (isset($new_settings[$field])) {
816
+					$existing_settings[$field] = $new_settings[$field];
817
+					continue;
818
+				}
819
+				if (! isset($existing_settings[$field])) {
820
+					$existing_settings[$field] = $values['default'];
821
+				}
822
+			}
823
+		}
824
+		$this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
825
+	}
826
+
827
+
828
+	/**
829
+	 * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger
830
+	 * and message type.
831
+	 *
832
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
833
+	 *
834
+	 * @access protected
835
+	 * @param \EE_messenger $messenger
836
+	 * @param string        $message_type_name
837
+	 */
838
+	protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name)
839
+	{
840
+
841
+		//if _has_activated_messengers_and_message_types is empty then lets ensure its initialized
842
+		if (empty($this->_has_activated_messengers_and_message_types)) {
843
+			$this->get_has_activated_messengers_option();
844
+		}
845
+
846
+		// make sure this messenger has a record in the has_activated array
847
+		if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
848
+			$this->_has_activated_messengers_and_message_types[$messenger->name] = array();
849
+		}
850
+		// check if message type has already been added
851
+		if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
852
+			$this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
853
+		}
854
+	}
855
+
856
+
857
+	/**
858
+	 * add_settings_for_messenger
859
+	 * NOTE This does NOT automatically persist any settings to the db.  Client code should call
860
+	 * $this->update_active_messengers_option to persist.
861
+	 *
862
+	 * @param string $messenger_name The name of the messenger the settings is being added for.
863
+	 * @param array  $new_settings   An array of settings to update the existing settings.
864
+	 */
865
+	public function add_settings_for_messenger($messenger_name, $new_settings = array())
866
+	{
867
+		$messenger = $this->get_messenger($messenger_name);
868
+		if ($messenger instanceof EE_messenger) {
869
+			$msgr_settings = $messenger->get_admin_settings_fields();
870
+			if (! empty($msgr_settings)) {
871
+				foreach ($msgr_settings as $field => $value) {
872
+					//is there a new setting for this?
873
+					if (isset($new_settings[$field])) {
874
+						$this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field];
875
+						continue;
876
+					}
877
+					//only set the default if it isn't already set.
878
+					if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
879
+						$this->_active_message_types[$messenger->name]['settings'][$field] = $value;
880
+					}
881
+				}
882
+			}
883
+		}
884
+	}
885
+
886
+
887
+	/**
888
+	 * deactivate_messenger
889
+	 *
890
+	 * @param  string|EE_messenger $messenger_name name of messenger
891
+	 * @return void
892
+	 */
893
+	public function deactivate_messenger($messenger_name)
894
+	{
895
+		$this->_initialize_collections();
896
+		if ($messenger_name instanceof EE_messenger) {
897
+			$messenger_name = $messenger_name->name;
898
+		}
899
+		unset($this->_active_messengers[$messenger_name]);
900
+		unset($this->_active_message_types[$messenger_name]);
901
+		$this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
902
+		$this->update_active_messengers_option();
903
+	}
904
+
905
+
906
+	/**
907
+	 * Deactivates a message type (note this will deactivate across all messenger's it is active on.
908
+	 *
909
+	 * @param  string $message_type_name     name of message type being deactivated
910
+	 * @param bool    $set_has_active_record By default we always record the has_active record when deactivating a message
911
+	 *                                       type.  However, this can be overridden if we don't want this set (usually when
912
+	 *                                       this is called as a part of deregistration of a custom message type)
913
+	 */
914
+	public function deactivate_message_type($message_type_name, $set_has_active_record = true)
915
+	{
916
+		$this->_initialize_collections();
917
+		if ($message_type_name instanceof EE_message_type) {
918
+			$message_type_name = $message_type_name->name;
919
+		}
920
+		foreach ($this->_active_message_types as $messenger_name => $settings) {
921
+			unset(
922
+				$this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
923
+			);
924
+
925
+			//we always record (even on deactivation) that a message type has been activated because there should at
926
+			//least be a record in the "has_activated" option that it WAS active at one point.
927
+			if ($set_has_active_record) {
928
+				$messenger = $this->get_messenger($messenger_name);
929
+				$this->_set_messenger_has_activated_message_type($messenger, $message_type_name);
930
+			}
931
+		}
932
+		$this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name);
933
+		$this->update_active_messengers_option();
934
+		$this->update_has_activated_messengers_option();
935
+	}
936
+
937
+
938
+	/**
939
+	 * Deactivates a message type for a specific messenger as opposed to all messengers.
940
+	 *
941
+	 * @param string $message_type_name Name of message type being deactivated.
942
+	 * @param string $messenger_name    Name of messenger the message type is being deactivated for.
943
+	 */
944
+	public function deactivate_message_type_for_messenger($message_type_name, $messenger_name)
945
+	{
946
+		$this->_initialize_collections();
947
+		if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
948
+			unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
949
+		}
950
+		$this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
951
+			array($message_type_name));
952
+		$this->update_active_messengers_option();
953
+	}
954
+
955
+
956
+	/**
957
+	 * Used to verify if a message can be sent for the given messenger and message type
958
+	 * and that it is a generating messenger (used for generating message templates).
959
+	 *
960
+	 * @param EE_messenger    $messenger    messenger used in trigger
961
+	 * @param EE_message_type $message_type message type used in trigger
962
+	 * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
963
+	 */
964
+	public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
965
+	{
966
+		//get the $messengers the message type says it can be used with.
967
+		foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) {
968
+			if (
969
+				$messenger->name === $generating_messenger
970
+				&& $this->is_message_type_active_for_messenger($messenger->name, $message_type->name)
971
+			) {
972
+				return true;
973
+			}
974
+		}
975
+		return false;
976
+	}
977
+
978
+
979
+	/**
980
+	 * This returns all the contexts that are registered by all message types.
981
+	 * If $slugs_only is true,
982
+	 * then just an array indexed by unique context slugs with the latest label representation for that slug.
983
+	 * array(
984
+	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
985
+	 * );
986
+	 * If $slugs_only is false, then the format is:
987
+	 * array(
988
+	 *      'message_type_name' => array(
989
+	 *          'context_slug' => array(
990
+	 *              'label' => 'localized label for context',
991
+	 *              'description' => 'localized description for context'
992
+	 *          )
993
+	 *      )
994
+	 * );
995
+	 * Keep in mind that although different message types may share the same context slugs,
996
+	 * it is possible that the context is described differently by the message type.
997
+	 *
998
+	 * @since 4.9.0
999
+	 * @param   bool $slugs_only Whether to return an array of just slugs and labels (true)
1000
+	 *                           or all contexts indexed by message type.
1001
+	 * @return array
1002
+	 */
1003
+	public function get_all_contexts($slugs_only = true)
1004
+	{
1005
+		$key = $slugs_only ? 'slugs' : 'all';
1006
+		// check if contexts has been setup yet.
1007
+		if (empty($this->_contexts[$key])) {
1008
+			// So let's get all active message type objects and loop through to get all unique contexts
1009
+			foreach ($this->get_active_message_type_objects() as $message_type) {
1010
+				if ($message_type instanceof EE_message_type) {
1011
+					$message_type_contexts = $message_type->get_contexts();
1012
+					if ($slugs_only) {
1013
+						foreach ($message_type_contexts as $context => $context_details) {
1014
+							$this->_contexts[$key][$context] = $context_details['label'];
1015
+						}
1016
+					} else {
1017
+						$this->_contexts[$key][$message_type->name] = $message_type_contexts;
1018
+					}
1019
+				}
1020
+			}
1021
+		}
1022
+		return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array();
1023
+	}
1024
+
1025
+
1026
+	/**
1027
+	 * This checks the internal record of what message types are considered "active" and verifies that
1028
+	 * there is an installed class definition for that message type.  If the active message type does not have a
1029
+	 * corresponding accessible message type class then it will be deactivated from all messengers it is active on and
1030
+	 * any related message templates will be inactivated as well.
1031
+	 *
1032
+	 * @return bool   true means all active message types are valid, false means at least one message type was
1033
+	 *                deactivated.
1034
+	 */
1035
+	public function validate_active_message_types_are_installed()
1036
+	{
1037
+		$list_of_active_message_type_names = $this->list_of_active_message_types();
1038
+		$installed_message_types           = $this->installed_message_types();
1039
+		$all_message_types_valid           = true;
1040
+		//loop through list of active message types and verify they are installed.
1041
+		foreach ($list_of_active_message_type_names as $message_type_name) {
1042
+			if (! isset($installed_message_types[$message_type_name])) {
1043
+				$this->remove_message_type_has_been_activated_from_all_messengers(
1044
+					$message_type_name,
1045
+					true
1046
+				);
1047
+				$this->deactivate_message_type($message_type_name, false);
1048
+				$all_message_types_valid = false;
1049
+			}
1050
+		}
1051
+		return $all_message_types_valid;
1052
+	}
1053
+
1054
+
1055
+	/**
1056
+	 * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been
1057
+	 * activated for the given messenger.  This can be called by client code on plugin updates etc to determine whether
1058
+	 * to attempt automatically reactivating message types that should be activated by default or not.
1059
+	 *
1060
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1061
+	 *
1062
+	 * @param $message_type_name
1063
+	 * @param $messenger_name
1064
+	 * @return bool
1065
+	 */
1066
+	public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1067
+	{
1068
+		$has_activated = $this->get_has_activated_messengers_option();
1069
+		return isset($has_activated[$messenger_name])
1070
+			   && in_array($message_type_name, $has_activated[$messenger_name]);
1071
+	}
1072
+
1073
+
1074
+	/**
1075
+	 * This method unsets a message type from the given messenger has activated option.
1076
+	 *
1077
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1078
+	 *
1079
+	 * @param string $message_type_name
1080
+	 * @param string $messenger_name
1081
+	 * @param bool   $consider_current_state  Whether to consider whether the  message type is currently active or not.
1082
+	 *                                        If it is currently active, then remove.  Otherwise leave it alone.
1083
+	 */
1084
+	public function remove_message_type_has_been_activated_for_messenger(
1085
+		$message_type_name,
1086
+		$messenger_name,
1087
+		$consider_current_state = false
1088
+	) {
1089
+		if ($consider_current_state
1090
+			&& ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
1091
+		) {
1092
+			//when consider current state is true, this means we don't want to change anything on the "has_activated"
1093
+			//record if the message type is currently active for this messenger.  This is used when we want to retain
1094
+			//the record for user initiated inactivations of the message type.
1095
+			return;
1096
+		}
1097
+		$has_activated = $this->get_has_activated_messengers_option();
1098
+		$key_for_message_type = isset($has_activated[$messenger_name])
1099
+			? array_search($message_type_name, $has_activated[$messenger_name], true)
1100
+			: false;
1101
+		if ($key_for_message_type !== false) {
1102
+			unset($has_activated[$messenger_name][$key_for_message_type]);
1103
+			$this->update_has_activated_messengers_option($has_activated);
1104
+			//reset the internal cached property
1105
+			$this->get_has_activated_messengers_option(true);
1106
+		}
1107
+	}
1108
+
1109
+
1110
+	/**
1111
+	 * Removes a message type active record from all messengers it is attached to.
1112
+	 *
1113
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1114
+	 *
1115
+	 * @param      $message_type_name
1116
+	 * @param bool $consider_current_state  Whether to consider whether the  message type is currently active or not.
1117
+	 *                                      If it is currently active, then remove.  Otherwise leave it alone.
1118
+	 */
1119
+	public function remove_message_type_has_been_activated_from_all_messengers(
1120
+		$message_type_name,
1121
+		$consider_current_state = false
1122
+	) {
1123
+		foreach(array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1124
+			$this->remove_message_type_has_been_activated_for_messenger(
1125
+				$message_type_name,
1126
+				$messenger_name,
1127
+				$consider_current_state
1128
+			);
1129
+		}
1130
+	}
1131 1131
 }
1132 1132
 // End of file EE_Message_Resource_Manager.lib.php
1133 1133
 // Location: /EE_Message_Resource_Manager.lib.php
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (! defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
5 5
 }
6 6
 
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
     public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
298 298
     {
299 299
         $this->_initialize_collections();
300
-        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
300
+        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]);
301 301
     }
302 302
 
303 303
 
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
     {
326 326
         $settings = array();
327 327
         if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
328
-            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
329
-                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
328
+            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'])
329
+                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings']
330 330
                 : array();
331 331
         }
332 332
         return $settings;
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
         $this->_initialize_collections();
346 346
         return
347 347
             ! empty($this->_active_message_types[$messenger_name])
348
-            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
348
+            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types']);
349 349
     }
350 350
 
351 351
 
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
     public function get_active_message_types_for_messenger($messenger_name)
361 361
     {
362 362
         $message_types = array();
363
-        if (! $this->messenger_has_active_message_types($messenger_name)) {
363
+        if ( ! $this->messenger_has_active_message_types($messenger_name)) {
364 364
             return $message_types;
365 365
         }
366 366
         $installed_message_types = $this->installed_message_types();
@@ -385,11 +385,11 @@  discard block
 block discarded – undo
385 385
         $active_message_type_names = array();
386 386
         $this->_initialize_collections();
387 387
         foreach ($this->_active_message_types as $messenger => $messenger_settings) {
388
-            if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
388
+            if ( ! isset($messenger_settings['settings'][$messenger.'-message_types'])) {
389 389
                 continue;
390 390
             }
391
-            foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
392
-                if (! in_array($message_type_name, $active_message_type_names)) {
391
+            foreach ($messenger_settings['settings'][$messenger.'-message_types'] as $message_type_name => $message_type_config) {
392
+                if ( ! in_array($message_type_name, $active_message_type_names)) {
393 393
                     $active_message_type_names[] = $message_type_name;
394 394
                 }
395 395
             }
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
     public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
466 466
     {
467 467
         $valid_message_types = $messenger->get_valid_message_types();
468
-        if (! in_array($message_type_name, $valid_message_types)) {
468
+        if ( ! in_array($message_type_name, $valid_message_types)) {
469 469
             throw new EE_Error(
470 470
                 sprintf(
471 471
                     __(
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
      */
592 592
     public function ensure_messenger_is_active($messenger_name, $update_option = true)
593 593
     {
594
-        if (! isset($this->_active_messengers[$messenger_name])) {
594
+        if ( ! isset($this->_active_messengers[$messenger_name])) {
595 595
             try {
596 596
                 $this->activate_messenger($messenger_name, array(), $update_option);
597 597
             } catch (EE_Error $e) {
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
             $this->ensure_messenger_is_active($messenger_name, $update_option);
637 637
         }
638 638
 
639
-        if (! empty($not_installed)) {
639
+        if ( ! empty($not_installed)) {
640 640
             EE_Error::add_error(
641 641
                 sprintf(
642 642
                     __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
             //ensure messenger is active (that's an inherent coupling between active message types and the
668 668
             //messenger they are being activated for.
669 669
             try {
670
-                if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
670
+                if ( ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
671 671
                     //all is good so let's just get it active
672 672
                     $this->activate_messenger($messenger_name, array($message_type_name), $update_option);
673 673
                 }
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
      */
696 696
     public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
697 697
     {
698
-        $message_type_names = (array)$message_type_names;
698
+        $message_type_names = (array) $message_type_names;
699 699
         foreach ($message_type_names as $message_type_name) {
700 700
             // note, intentionally not updating option here because we're in a loop.
701 701
             // We'll follow the instructions of the incoming $update_option argument after the loop.
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
             //generate new templates if necessary and ensure all related templates that are already in the database are
742 742
             //marked active.  Note, this will also deactivate a message type for a messenger if the template
743 743
             //cannot be successfully created during its attempt (only happens for global template attempts).
744
-            if (! empty($message_type_names)) {
744
+            if ( ! empty($message_type_names)) {
745 745
                 $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
746 746
                 EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
747 747
             }
@@ -767,10 +767,10 @@  discard block
 block discarded – undo
767 767
         //only override _active_message_types when an explicit array of $message_type_names has been provided.
768 768
         $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
769 769
             ? $messenger->get_default_message_types()
770
-            : (array)$message_type_names;
770
+            : (array) $message_type_names;
771 771
 
772 772
         //now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
773
-        if (! isset($this->_active_message_types[$messenger->name])) {
773
+        if ( ! isset($this->_active_message_types[$messenger->name])) {
774 774
             $this->_active_message_types[$messenger->name]['settings'] = array();
775 775
         }
776 776
 
@@ -816,12 +816,12 @@  discard block
 block discarded – undo
816 816
                     $existing_settings[$field] = $new_settings[$field];
817 817
                     continue;
818 818
                 }
819
-                if (! isset($existing_settings[$field])) {
819
+                if ( ! isset($existing_settings[$field])) {
820 820
                     $existing_settings[$field] = $values['default'];
821 821
                 }
822 822
             }
823 823
         }
824
-        $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
824
+        $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'] = $existing_settings;
825 825
     }
826 826
 
827 827
 
@@ -844,11 +844,11 @@  discard block
 block discarded – undo
844 844
         }
845 845
 
846 846
         // make sure this messenger has a record in the has_activated array
847
-        if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
847
+        if ( ! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
848 848
             $this->_has_activated_messengers_and_message_types[$messenger->name] = array();
849 849
         }
850 850
         // check if message type has already been added
851
-        if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
851
+        if ( ! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
852 852
             $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
853 853
         }
854 854
     }
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
         $messenger = $this->get_messenger($messenger_name);
868 868
         if ($messenger instanceof EE_messenger) {
869 869
             $msgr_settings = $messenger->get_admin_settings_fields();
870
-            if (! empty($msgr_settings)) {
870
+            if ( ! empty($msgr_settings)) {
871 871
                 foreach ($msgr_settings as $field => $value) {
872 872
                     //is there a new setting for this?
873 873
                     if (isset($new_settings[$field])) {
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
                         continue;
876 876
                     }
877 877
                     //only set the default if it isn't already set.
878
-                    if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
878
+                    if ( ! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
879 879
                         $this->_active_message_types[$messenger->name]['settings'][$field] = $value;
880 880
                     }
881 881
                 }
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
         }
920 920
         foreach ($this->_active_message_types as $messenger_name => $settings) {
921 921
             unset(
922
-                $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
922
+                $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]
923 923
             );
924 924
 
925 925
             //we always record (even on deactivation) that a message type has been activated because there should at
@@ -945,7 +945,7 @@  discard block
 block discarded – undo
945 945
     {
946 946
         $this->_initialize_collections();
947 947
         if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
948
-            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
948
+            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]);
949 949
         }
950 950
         $this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
951 951
             array($message_type_name));
@@ -1039,7 +1039,7 @@  discard block
 block discarded – undo
1039 1039
         $all_message_types_valid           = true;
1040 1040
         //loop through list of active message types and verify they are installed.
1041 1041
         foreach ($list_of_active_message_type_names as $message_type_name) {
1042
-            if (! isset($installed_message_types[$message_type_name])) {
1042
+            if ( ! isset($installed_message_types[$message_type_name])) {
1043 1043
                 $this->remove_message_type_has_been_activated_from_all_messengers(
1044 1044
                     $message_type_name,
1045 1045
                     true
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
         $message_type_name,
1121 1121
         $consider_current_state = false
1122 1122
     ) {
1123
-        foreach(array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1123
+        foreach (array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1124 1124
             $this->remove_message_type_has_been_activated_for_messenger(
1125 1125
                 $message_type_name,
1126 1126
                 $messenger_name,
Please login to merge, or discard this patch.
admin_pages/maintenance/templates/ee_data_reset_and_delete.template.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@  discard block
 block discarded – undo
7 7
 /** @var string $delete_db_url */
8 8
 ?>
9 9
 <h2>
10
-	<?php esc_html_e( 'Reset/Delete Data for Event Espresso', 'event_espresso' );?>
10
+	<?php esc_html_e('Reset/Delete Data for Event Espresso', 'event_espresso'); ?>
11 11
 </h2>
12 12
 <br />
13 13
 
14 14
 <div class="padding">
15
-	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Ticket and Datetime Reserved Counts', 'event_espresso');?></h4>
16
-	<p><?php esc_html_e('Use this to reset the counts for ticket and datetime reservations.', 'event_espresso');?></p>
15
+	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Ticket and Datetime Reserved Counts', 'event_espresso'); ?></h4>
16
+	<p><?php esc_html_e('Use this to reset the counts for ticket and datetime reservations.', 'event_espresso'); ?></p>
17 17
 	<div class="float-right"><?php echo $reset_reservations_button; ?></div>
18 18
 	<div class="clear"></div>
19 19
 </div>
@@ -22,8 +22,8 @@  discard block
 block discarded – undo
22 22
 
23 23
 <!-- reset DB url is here. Just need to make it look pretty and unhide it-->
24 24
 <div class="padding">
25
-	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Event Espresso Capabilities', 'event_espresso');?></h4>
26
-	<p><?php esc_html_e('Use this to reset the capabilities on WP roles to the defaults as defined via EE_Capabilities.  Note this reset does not REMOVE any existing capabilities, it just ensures that all the defaults are ADDED to the roles.', 'event_espresso');?></p>
25
+	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Event Espresso Capabilities', 'event_espresso'); ?></h4>
26
+	<p><?php esc_html_e('Use this to reset the capabilities on WP roles to the defaults as defined via EE_Capabilities.  Note this reset does not REMOVE any existing capabilities, it just ensures that all the defaults are ADDED to the roles.', 'event_espresso'); ?></p>
27 27
 	<div class="float-right"><?php echo $reset_capabilities_button; ?></div>
28 28
 	<div class="clear"></div>
29 29
 </div>
@@ -31,29 +31,29 @@  discard block
 block discarded – undo
31 31
 <br />
32 32
 
33 33
 <div class="padding">
34
-	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Event Espresso Data', 'event_espresso');?></h4>
35
-    <p><?php esc_html_e(' This will reset data for Event Espresso 4, and for all active add-ons. Inactive add-ons will not be affected.', 'event_espresso');?></p>
36
-    <p><?php esc_html_e('Your Event Espresso data will return to its default settings. The rest of your website will be unaffected.', 'event_espresso');?></p>
37
-	<div class="float-right"><a class="button button-primary" href="<?php echo $reset_db_url;?>"><?php esc_html_e('Reset Event Espresso Tables', 'event_espresso');?></a></div>
34
+	<h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Event Espresso Data', 'event_espresso'); ?></h4>
35
+    <p><?php esc_html_e(' This will reset data for Event Espresso 4, and for all active add-ons. Inactive add-ons will not be affected.', 'event_espresso'); ?></p>
36
+    <p><?php esc_html_e('Your Event Espresso data will return to its default settings. The rest of your website will be unaffected.', 'event_espresso'); ?></p>
37
+	<div class="float-right"><a class="button button-primary" href="<?php echo $reset_db_url; ?>"><?php esc_html_e('Reset Event Espresso Tables', 'event_espresso'); ?></a></div>
38 38
 	<div class="clear"></div>
39 39
 </div>
40 40
 <br />
41 41
 <br />
42 42
 
43 43
 <div class="padding">
44
-	<h4 class="espresso-header"><span class="dashicons dashicons-post-trash ee-icon-size-22"></span><?php esc_html_e('Permanently Delete ALL Event Espresso Data', 'event_espresso');?></h4>
44
+	<h4 class="espresso-header"><span class="dashicons dashicons-post-trash ee-icon-size-22"></span><?php esc_html_e('Permanently Delete ALL Event Espresso Data', 'event_espresso'); ?></h4>
45 45
     <p><?php esc_html_e(' This will delete data for Event Espresso 4, and all currently active add-ons. Event Espresso will then be deactivated. You may need to manually deactivate each add-on individually.',
46
-            'event_espresso');?></p>
47
-	<p><?php esc_html_e('If you know for certain that you will no longer be using Event Espresso and you wish to remove ALL traces of the plugin from your system, then perform the following steps.', 'event_espresso');?></p>
48
-	<p class="important-notice"><?php printf( esc_html__('Please note: %sThis is permanent and can NOT be undone.%s', 'event_espresso'), '<em>', '</em>' ); ?><br/></p>
46
+            'event_espresso'); ?></p>
47
+	<p><?php esc_html_e('If you know for certain that you will no longer be using Event Espresso and you wish to remove ALL traces of the plugin from your system, then perform the following steps.', 'event_espresso'); ?></p>
48
+	<p class="important-notice"><?php printf(esc_html__('Please note: %sThis is permanent and can NOT be undone.%s', 'event_espresso'), '<em>', '</em>'); ?><br/></p>
49 49
 	<ol>
50
-		<li><?php  printf( esc_html__('First, click the button below to permanently delete all Event Espresso tables, records, and options from your WordPress database . If you receive a "500 Internal Server Error" or a blank white screen, it means the server has timed out due to the large number of records being updated. This is not a cause for concern. Simply %1$srefresh the page%2$s and the Database Update will continue where it left off.', 'event_espresso'), '<strong>', '</strong>' );?></li>
51
-		<li><?php printf( esc_html__('Then, locate Event Espresso on the WordPress Plugins page, and click on %sDelete%s', 'event_espresso'), '<strong>', '</strong>' ); ?></li>
52
-        <li><?php printf( esc_html__('Once you are on the Delete Plugin page, click on %sYes, Delete these files and data%s', 'event_espresso'), '<strong>', '</strong>' ); ?></li>
53
-		<li><?php printf( esc_html__('Note: Event Espresso 4 categories are %snot%s deleted by this script', 'event_espresso'), '<strong>', '</strong>' ); ?>
50
+		<li><?php  printf(esc_html__('First, click the button below to permanently delete all Event Espresso tables, records, and options from your WordPress database . If you receive a "500 Internal Server Error" or a blank white screen, it means the server has timed out due to the large number of records being updated. This is not a cause for concern. Simply %1$srefresh the page%2$s and the Database Update will continue where it left off.', 'event_espresso'), '<strong>', '</strong>'); ?></li>
51
+		<li><?php printf(esc_html__('Then, locate Event Espresso on the WordPress Plugins page, and click on %sDelete%s', 'event_espresso'), '<strong>', '</strong>'); ?></li>
52
+        <li><?php printf(esc_html__('Once you are on the Delete Plugin page, click on %sYes, Delete these files and data%s', 'event_espresso'), '<strong>', '</strong>'); ?></li>
53
+		<li><?php printf(esc_html__('Note: Event Espresso 4 categories are %snot%s deleted by this script', 'event_espresso'), '<strong>', '</strong>'); ?>
54 54
 		<br><a href="<?php echo admin_url('edit-tags.php?taxonomy=espresso_event_categories'); ?>"><?php esc_html_e('You can go here to delete Event Espresso categories', 'event_espresso'); ?></a></li>
55 55
 	</ol>
56
-	<div class="float-right"><a href="<?php echo $delete_db_url; ?>" id="delete-all-data-btn" class="button-primary"><?php esc_html_e('Permanently Delete All Event Espresso Data', 'event_espresso');?></a></div>
56
+	<div class="float-right"><a href="<?php echo $delete_db_url; ?>" id="delete-all-data-btn" class="button-primary"><?php esc_html_e('Permanently Delete All Event Espresso Data', 'event_espresso'); ?></a></div>
57 57
 	<div class="clear"></div>
58 58
 </div>
59 59
 <br/>
Please login to merge, or discard this patch.