Completed
Branch FET-8385-datetime-ticket-selec... (dbda12)
by
unknown
194:55 queued 183:27
created
core/business/EE_Registration_Processor.class.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 			}
216 216
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
217 217
 			if ( ! EE_Processor_Base::$IPN ) {
218
-                // otherwise, send out notifications
218
+				// otherwise, send out notifications
219 219
 				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
220 220
 			}
221 221
 			// DEBUG LOG
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 			}
263 263
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
264 264
 			if ( ! EE_Processor_Base::$IPN ) {
265
-                // otherwise, send out notifications
265
+				// otherwise, send out notifications
266 266
 				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
267 267
 			}
268 268
 			// DEBUG LOG
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 			}
350 350
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
351 351
 			if ( ! EE_Processor_Base::$IPN ) {
352
-                // otherwise, send out notifications
352
+				// otherwise, send out notifications
353 353
 				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
354 354
 			}
355 355
 			// DEBUG LOG
@@ -390,10 +390,10 @@  discard block
 block discarded – undo
390 390
 			// 	false,
391 391
 			// 	'EE_Transaction: ' . $registration->transaction()->ID()
392 392
 			// );
393
-            if ( ! $registration->is_primary_registrant()) {
394
-                return;
395
-            }
396
-            do_action(
393
+			if ( ! $registration->is_primary_registrant()) {
394
+				return;
395
+			}
396
+			do_action(
397 397
 				'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
398 398
 				$registration,
399 399
 				$additional_details
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 		// set new  REG_Status
429 429
 		$this->set_new_reg_status( $registration->ID(), $registration->status_ID() );
430 430
 		return $this->reg_status_updated( $registration->ID() )
431
-		       && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved
431
+			   && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved
432 432
 			? true
433 433
 			: false;
434 434
 	}
Please login to merge, or discard this patch.
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\domain\entities\RegUrlLink;
4 4
 use EventEspresso\core\domain\services\registration\CreateRegistrationService;
5 5
 
6
-if ( ! defined( 'EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
7
-EE_Registry::instance()->load_class( 'Processor_Base' );
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
7
+EE_Registry::instance()->load_class('Processor_Base');
8 8
 
9 9
 /**
10 10
  * Class EE_Registration_Processor
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public static function instance() {
68 68
 		// check if class object is instantiated
69
-		if ( ! self::$_instance instanceof EE_Registration_Processor ) {
69
+		if ( ! self::$_instance instanceof EE_Registration_Processor) {
70 70
 			self::$_instance = new self();
71 71
 		}
72 72
 		return self::$_instance;
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 	 * @param int $REG_ID
87 87
 	 * @return string
88 88
 	 */
89
-	public function old_reg_status( $REG_ID ) {
90
-		return isset( $this->_old_reg_status[ $REG_ID ] ) ? $this->_old_reg_status[ $REG_ID ] : null;
89
+	public function old_reg_status($REG_ID) {
90
+		return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null;
91 91
 	}
92 92
 
93 93
 
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
 	 * @param int $REG_ID
97 97
 	 * @param string $old_reg_status
98 98
 	 */
99
-	public function set_old_reg_status( $REG_ID, $old_reg_status ) {
99
+	public function set_old_reg_status($REG_ID, $old_reg_status) {
100 100
 		// only set the first time
101
-		if ( ! isset( $this->_old_reg_status[ $REG_ID ] ) ) {
102
-			$this->_old_reg_status[ $REG_ID ] = $old_reg_status;
101
+		if ( ! isset($this->_old_reg_status[$REG_ID])) {
102
+			$this->_old_reg_status[$REG_ID] = $old_reg_status;
103 103
 		}
104 104
 	}
105 105
 
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
 	 * @param int $REG_ID
110 110
 	 * @return string
111 111
 	 */
112
-	public function new_reg_status( $REG_ID ) {
113
-		return isset( $this->_new_reg_status[ $REG_ID ] ) ? $this->_new_reg_status[ $REG_ID ] : null;
112
+	public function new_reg_status($REG_ID) {
113
+		return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null;
114 114
 	}
115 115
 
116 116
 
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
 	 * @param int $REG_ID
120 120
 	 * @param string $new_reg_status
121 121
 	 */
122
-	public function set_new_reg_status( $REG_ID, $new_reg_status ) {
123
-		$this->_new_reg_status[ $REG_ID ] = $new_reg_status;
122
+	public function set_new_reg_status($REG_ID, $new_reg_status) {
123
+		$this->_new_reg_status[$REG_ID] = $new_reg_status;
124 124
 	}
125 125
 
126 126
 
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 * @param int $REG_ID
132 132
 	 * @return bool
133 133
 	 */
134
-	public function reg_status_updated( $REG_ID ) {
135
-		return $this->new_reg_status( $REG_ID ) !== $this->old_reg_status( $REG_ID ) ? true : false;
134
+	public function reg_status_updated($REG_ID) {
135
+		return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID) ? true : false;
136 136
 	}
137 137
 
138 138
 
@@ -141,13 +141,13 @@  discard block
 block discarded – undo
141 141
 	 * @param \EE_Registration $registration
142 142
 	 * @throws \EE_Error
143 143
 	 */
144
-	public function update_registration_status_and_trigger_notifications( \EE_Registration $registration ) {
145
-		$this->toggle_incomplete_registration_status_to_default( $registration, false );
146
-		$this->toggle_registration_status_for_default_approved_events( $registration, false );
147
-		$this->toggle_registration_status_if_no_monies_owing( $registration, false );
144
+	public function update_registration_status_and_trigger_notifications(\EE_Registration $registration) {
145
+		$this->toggle_incomplete_registration_status_to_default($registration, false);
146
+		$this->toggle_registration_status_for_default_approved_events($registration, false);
147
+		$this->toggle_registration_status_if_no_monies_owing($registration, false);
148 148
 		$registration->save();
149 149
 		// trigger notifications
150
-		$this->trigger_registration_update_notifications( $registration );
150
+		$this->trigger_registration_update_notifications($registration);
151 151
 	}
152 152
 
153 153
 
@@ -162,18 +162,18 @@  discard block
 block discarded – undo
162 162
 	 * @return boolean
163 163
 	 * @throws \EE_Error
164 164
 	 */
165
-	public function manually_update_registration_status( EE_Registration $registration, $new_reg_status = '', $save = true ) {
165
+	public function manually_update_registration_status(EE_Registration $registration, $new_reg_status = '', $save = true) {
166 166
 		// set initial REG_Status
167
-		$this->set_old_reg_status( $registration->ID(), $registration->status_ID() );
167
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
168 168
 		// set incoming REG_Status
169
-		$this->set_new_reg_status( $registration->ID(), $new_reg_status );
169
+		$this->set_new_reg_status($registration->ID(), $new_reg_status);
170 170
 		// toggle reg status but only if it has changed and the user can do so
171 171
 		if (
172
-			$this->reg_status_updated( $registration->ID() ) &&
173
-			EE_Registry::instance()->CAP->current_user_can( 'ee_edit_registration', 'toggle_registration_status', $registration->ID() )
172
+			$this->reg_status_updated($registration->ID()) &&
173
+			EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'toggle_registration_status', $registration->ID())
174 174
 		) {
175 175
 			// change status to new value
176
-			if ( $registration->set_status( $this->new_reg_status( $registration->ID() ) ) && $save ) {
176
+			if ($registration->set_status($this->new_reg_status($registration->ID())) && $save) {
177 177
 				$registration->save();
178 178
 			}
179 179
 			return TRUE;
@@ -193,30 +193,30 @@  discard block
 block discarded – undo
193 193
 	 * @return void
194 194
 	 * @throws \EE_Error
195 195
 	 */
196
-	public function toggle_incomplete_registration_status_to_default( EE_Registration $registration, $save = TRUE ) {
196
+	public function toggle_incomplete_registration_status_to_default(EE_Registration $registration, $save = TRUE) {
197 197
 		$existing_reg_status = $registration->status_ID();
198 198
 		// set initial REG_Status
199
-		$this->set_old_reg_status( $registration->ID(), $existing_reg_status );
199
+		$this->set_old_reg_status($registration->ID(), $existing_reg_status);
200 200
 		// is the registration currently incomplete ?
201
-		if ( $registration->status_ID() === EEM_Registration::status_id_incomplete ) {
201
+		if ($registration->status_ID() === EEM_Registration::status_id_incomplete) {
202 202
 			// grab default reg status for the event, if set
203 203
 			$event_default_registration_status = $registration->event()->default_registration_status();
204 204
 			// if no default reg status is set for the event, then use the global value
205
-			$STS_ID = ! empty( $event_default_registration_status )
205
+			$STS_ID = ! empty($event_default_registration_status)
206 206
 				? $event_default_registration_status
207 207
 				: EE_Registry::instance()->CFG->registration->default_STS_ID;
208 208
 			// if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered
209 209
 			$STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment : $STS_ID;
210 210
 			// set incoming REG_Status
211
-			$this->set_new_reg_status( $registration->ID(), $STS_ID );
212
-			$registration->set_status( $STS_ID );
213
-			if ( $save ) {
211
+			$this->set_new_reg_status($registration->ID(), $STS_ID);
212
+			$registration->set_status($STS_ID);
213
+			if ($save) {
214 214
 				$registration->save();
215 215
 			}
216 216
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
217
-			if ( ! EE_Processor_Base::$IPN ) {
217
+			if ( ! EE_Processor_Base::$IPN) {
218 218
                 // otherwise, send out notifications
219
-				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
219
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
220 220
 			}
221 221
 			// DEBUG LOG
222 222
 			//$this->log(
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
 	 * @return boolean
242 242
 	 * @throws \EE_Error
243 243
 	 */
244
-	public function toggle_registration_status_for_default_approved_events( EE_Registration $registration, $save = TRUE ) {
244
+	public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = TRUE) {
245 245
 		$reg_status = $registration->status_ID();
246 246
 		// set initial REG_Status
247
-		$this->set_old_reg_status( $registration->ID(), $reg_status );
247
+		$this->set_old_reg_status($registration->ID(), $reg_status);
248 248
 		// if not already, toggle reg status to approved IF the event default reg status is approved
249 249
 		// ( as long as the registration wasn't cancelled or declined at some point )
250 250
 		if (
@@ -254,16 +254,16 @@  discard block
 block discarded – undo
254 254
 			$registration->event()->default_registration_status() === EEM_Registration::status_id_approved
255 255
 		) {
256 256
 			// set incoming REG_Status
257
-			$this->set_new_reg_status( $registration->ID(), EEM_Registration::status_id_approved );
257
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
258 258
 			// toggle status to approved
259
-			$registration->set_status( EEM_Registration::status_id_approved );
260
-			if ( $save ) {
259
+			$registration->set_status(EEM_Registration::status_id_approved);
260
+			if ($save) {
261 261
 				$registration->save();
262 262
 			}
263 263
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
264
-			if ( ! EE_Processor_Base::$IPN ) {
264
+			if ( ! EE_Processor_Base::$IPN) {
265 265
                 // otherwise, send out notifications
266
-				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
266
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
267 267
 			}
268 268
 			// DEBUG LOG
269 269
 			//$this->log(
@@ -291,19 +291,19 @@  discard block
 block discarded – undo
291 291
 	 * @return bool
292 292
 	 * @throws \EE_Error
293 293
 	 */
294
-	public function toggle_registration_status_if_no_monies_owing( EE_Registration $registration, $save = TRUE, $additional_details = array() ) {
294
+	public function toggle_registration_status_if_no_monies_owing(EE_Registration $registration, $save = TRUE, $additional_details = array()) {
295 295
 		// set initial REG_Status
296
-		$this->set_old_reg_status( $registration->ID(), $registration->status_ID() );
296
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
297 297
 		//EEH_Debug_Tools::printr( $additional_details, '$additional_details', __FILE__, __LINE__ );
298 298
 		// was a payment just made ?
299 299
 		if (
300
-			isset( $additional_details[ 'payment_updates' ], $additional_details[ 'last_payment' ] ) &&
301
-			$additional_details[ 'payment_updates' ] &&
302
-			$additional_details[ 'last_payment' ] instanceof EE_Payment
300
+			isset($additional_details['payment_updates'], $additional_details['last_payment']) &&
301
+			$additional_details['payment_updates'] &&
302
+			$additional_details['last_payment'] instanceof EE_Payment
303 303
 		) {
304
-			$payment = $additional_details[ 'last_payment' ];
304
+			$payment = $additional_details['last_payment'];
305 305
 			$total_paid = 0;
306
-			foreach ( self::$_amount_paid as $reg => $amount_paid ) {
306
+			foreach (self::$_amount_paid as $reg => $amount_paid) {
307 307
 				$total_paid += $amount_paid;
308 308
 			}
309 309
 		} else {
@@ -327,30 +327,30 @@  discard block
 block discarded – undo
327 327
 					$registration->transaction()->is_completed() ||
328 328
 					$registration->transaction()->is_overpaid() ||
329 329
 					$registration->transaction()->is_free() ||
330
-					apply_filters( 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', false, $registration )
330
+					apply_filters('FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', false, $registration)
331 331
 				) || (
332 332
 					$payment instanceof EE_Payment &&
333 333
 					$payment->is_approved() &&
334 334
 					// this specific registration has not yet been paid for
335
-					! isset( self::$_amount_paid[ $registration->ID() ] ) &&
335
+					! isset(self::$_amount_paid[$registration->ID()]) &&
336 336
 					// payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
337 337
 					$payment->amount() - $total_paid >= $registration->final_price()
338 338
 				)
339 339
 			)
340 340
 		) {
341 341
 			// mark as paid
342
-			self::$_amount_paid[ $registration->ID() ] = $registration->final_price();
342
+			self::$_amount_paid[$registration->ID()] = $registration->final_price();
343 343
 			// track new REG_Status
344
-			$this->set_new_reg_status( $registration->ID(), EEM_Registration::status_id_approved );
344
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
345 345
 			// toggle status to approved
346
-			$registration->set_status( EEM_Registration::status_id_approved );
347
-			if ( $save ) {
346
+			$registration->set_status(EEM_Registration::status_id_approved);
347
+			if ($save) {
348 348
 				$registration->save();
349 349
 			}
350 350
 			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
351
-			if ( ! EE_Processor_Base::$IPN ) {
351
+			if ( ! EE_Processor_Base::$IPN) {
352 352
                 // otherwise, send out notifications
353
-				add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 );
353
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
354 354
 			}
355 355
 			// DEBUG LOG
356 356
 			//$this->log(
@@ -376,10 +376,10 @@  discard block
 block discarded – undo
376 376
 	 * @param array 	$additional_details
377 377
 	 * @return void
378 378
 	 */
379
-	public function trigger_registration_update_notifications( $registration, $additional_details = array() ) {
379
+	public function trigger_registration_update_notifications($registration, $additional_details = array()) {
380 380
 		try {
381
-			if ( ! $registration instanceof EE_Registration ) {
382
-				throw new EE_Error( __( 'An invalid registration was received.', 'event_espresso' ) );
381
+			if ( ! $registration instanceof EE_Registration) {
382
+				throw new EE_Error(__('An invalid registration was received.', 'event_espresso'));
383 383
 			}
384 384
 			// EE_Registry::instance()->load_helper( 'Debug_Tools' );
385 385
 			// EEH_Debug_Tools::log(
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
 				$registration,
399 399
 				$additional_details
400 400
 			);
401
-		} catch( Exception $e ) {
402
-			EE_Error::add_error( $e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine() );
401
+		} catch (Exception $e) {
402
+			EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine());
403 403
 		}
404 404
 	}
405 405
 
@@ -413,22 +413,22 @@  discard block
 block discarded – undo
413 413
 	 * @return bool
414 414
 	 * @throws \EE_Error
415 415
 	 */
416
-	public function update_registration_after_checkout_or_payment(  EE_Registration $registration, $additional_details = array() ) {
416
+	public function update_registration_after_checkout_or_payment(EE_Registration $registration, $additional_details = array()) {
417 417
 		// set initial REG_Status
418
-		$this->set_old_reg_status( $registration->ID(), $registration->status_ID() );
418
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
419 419
 
420 420
 		// if the registration status gets updated, then save the registration
421 421
 		if (
422
-			$this->toggle_registration_status_for_default_approved_events( $registration, false )
423
-			|| $this->toggle_registration_status_if_no_monies_owing( $registration, false, $additional_details )
422
+			$this->toggle_registration_status_for_default_approved_events($registration, false)
423
+			|| $this->toggle_registration_status_if_no_monies_owing($registration, false, $additional_details)
424 424
 		) {
425 425
 			$registration->save();
426 426
 		}
427 427
 
428 428
 		// set new  REG_Status
429
-		$this->set_new_reg_status( $registration->ID(), $registration->status_ID() );
430
-		return $this->reg_status_updated( $registration->ID() )
431
-		       && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved
429
+		$this->set_new_reg_status($registration->ID(), $registration->status_ID());
430
+		return $this->reg_status_updated($registration->ID())
431
+		       && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved
432 432
 			? true
433 433
 			: false;
434 434
 	}
@@ -444,20 +444,20 @@  discard block
 block discarded – undo
444 444
 	 * @return void
445 445
 	 * @throws \EE_Error
446 446
 	 */
447
-	public function update_registration_final_prices( $transaction, $save_regs = true ) {
448
-		$reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $transaction->total_line_item() );
449
-		foreach( $transaction->registrations() as $registration ) {
447
+	public function update_registration_final_prices($transaction, $save_regs = true) {
448
+		$reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item($transaction->total_line_item());
449
+		foreach ($transaction->registrations() as $registration) {
450 450
 			/** @var EE_Line_Item $line_item */
451
-			$line_item = EEM_Line_Item::instance()->get_line_item_for_registration( $registration );
452
-			if( isset( $reg_final_price_per_ticket_line_item[ $line_item->ID() ] ) ) {
453
-				$registration->set_final_price( $reg_final_price_per_ticket_line_item[ $line_item->ID() ] );
454
-				if( $save_regs ) {
451
+			$line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
452
+			if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) {
453
+				$registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]);
454
+				if ($save_regs) {
455 455
 					$registration->save();
456 456
 				}
457 457
 			}
458 458
 		}
459 459
 		//and make sure there's no rounding problem
460
-		$this->fix_reg_final_price_rounding_issue( $transaction );
460
+		$this->fix_reg_final_price_rounding_issue($transaction);
461 461
 	}
462 462
 
463 463
 
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 	 * @return boolean success verifying that there is NO difference after this method is done
478 478
 	 * @throws \EE_Error
479 479
 	 */
480
-	public function fix_reg_final_price_rounding_issue( $transaction ) {
480
+	public function fix_reg_final_price_rounding_issue($transaction) {
481 481
 		$reg_final_price_sum = EEM_Registration::instance()->sum(
482 482
 			array(
483 483
 				array(
@@ -486,9 +486,9 @@  discard block
 block discarded – undo
486 486
 			),
487 487
 			'REG_final_price'
488 488
 		);
489
-		$diff =  $transaction->total() - (float) $reg_final_price_sum;
489
+		$diff = $transaction->total() - (float) $reg_final_price_sum;
490 490
 		//ok then, just grab one of the registrations
491
-		if( $diff !== 0 ) {
491
+		if ($diff !== 0) {
492 492
 			$a_reg = EEM_Registration::instance()->get_one(
493 493
 					array(
494 494
 						array(
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 					));
498 498
 			$success = $a_reg instanceof EE_Registration
499 499
 				? $a_reg->save(
500
-					array( 'REG_final_price' => $a_reg->final_price() + $diff )
500
+					array('REG_final_price' => $a_reg->final_price() + $diff)
501 501
 				)
502 502
 				: false;
503 503
 			return $success ? true : false;
@@ -522,13 +522,13 @@  discard block
 block discarded – undo
522 522
 		$update_reg = true
523 523
 	) {
524 524
 		// these reg statuses should not be considered in any calculations involving monies owing
525
-		$closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses
525
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
526 526
 			: EEM_Registration::closed_reg_statuses();
527
-		if ( ! in_array( $registration->status_ID(), $closed_reg_statuses ) ) {
527
+		if ( ! in_array($registration->status_ID(), $closed_reg_statuses)) {
528 528
 			return false;
529 529
 		}
530 530
 		$registration->set_final_price(0);
531
-		if ( $update_reg ) {
531
+		if ($update_reg) {
532 532
 			$registration->save();
533 533
 		}
534 534
 		return true;
@@ -551,23 +551,23 @@  discard block
 block discarded – undo
551 551
 		$update_reg = true
552 552
 	) {
553 553
 		// these reg statuses should not be considered in any calculations involving monies owing
554
-		$closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses
554
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
555 555
 			: EEM_Registration::closed_reg_statuses();
556
-		if ( in_array( $registration->status_ID(), $closed_reg_statuses ) ) {
556
+		if (in_array($registration->status_ID(), $closed_reg_statuses)) {
557 557
 			return false;
558 558
 		}
559 559
 		$ticket = $registration->ticket();
560
-		if ( ! $ticket instanceof EE_Ticket ) {
560
+		if ( ! $ticket instanceof EE_Ticket) {
561 561
 			throw new EE_Error(
562 562
 				sprintf(
563
-					__( 'The Ticket for Registration %1$d was not found or is invalid.',
564
-						'event_espresso' ),
563
+					__('The Ticket for Registration %1$d was not found or is invalid.',
564
+						'event_espresso'),
565 565
 					$registration->ticket_ID()
566 566
 				)
567 567
 			);
568 568
 		}
569
-		$registration->set_final_price( $ticket->price() );
570
-		if ( $update_reg ) {
569
+		$registration->set_final_price($ticket->price());
570
+		if ($update_reg) {
571 571
 			$registration->save();
572 572
 		}
573 573
 		return true;
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 		$total_ticket_count = 1
606 606
 	) {
607 607
 		EE_Error::doing_it_wrong(
608
-			__CLASS__ . '::' . __FUNCTION__,
608
+			__CLASS__.'::'.__FUNCTION__,
609 609
 			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
610 610
 				'\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'),
611 611
 			'4.9.1',
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
 	public function generate_reg_url_link($att_nmbr, $item)
649 649
 	{
650 650
 		EE_Error::doing_it_wrong(
651
-			__CLASS__ . '::' . __FUNCTION__,
651
+			__CLASS__.'::'.__FUNCTION__,
652 652
 			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
653 653
 				'EventEspresso\core\domain\entities\RegUrlLink'),
654 654
 			'4.9.1',
@@ -668,11 +668,11 @@  discard block
 block discarded – undo
668 668
 	 * @return string
669 669
 	 * @throws \EE_Error
670 670
 	 */
671
-	public function generate_reg_code( EE_Registration $registration ) {
671
+	public function generate_reg_code(EE_Registration $registration) {
672 672
 		EE_Error::doing_it_wrong(
673
-			__CLASS__ . '::' . __FUNCTION__,
673
+			__CLASS__.'::'.__FUNCTION__,
674 674
 			sprintf(
675
-				__( 'This method is deprecated. Please use "%s" instead', 'event_espresso' ),
675
+				__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
676 676
 				'EventEspresso\core\domain\entities\RegCode'
677 677
 			),
678 678
 			'4.9.1',
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
 		return apply_filters(
682 682
 			'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code',
683 683
 			new RegCode(
684
-				RegUrlLink::fromRegistration( $registration ),
684
+				RegUrlLink::fromRegistration($registration),
685 685
 				$registration->transaction(),
686 686
 				$registration->ticket()
687 687
 			),
Please login to merge, or discard this patch.
finalize_registration/EE_SPCO_Reg_Step_Finalize_Registration.class.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -56,10 +56,10 @@  discard block
 block discarded – undo
56 56
 
57 57
 
58 58
 
59
-    /**
60
-     * @return string
61
-     * @throws \EE_Error
62
-     */
59
+	/**
60
+	 * @return string
61
+	 * @throws \EE_Error
62
+	 */
63 63
 	public function generate_reg_form() {
64 64
 		// create empty form so that things don't break
65 65
 		$this->reg_form = new EE_Form_Section_Proper();
@@ -68,26 +68,26 @@  discard block
 block discarded – undo
68 68
 
69 69
 
70 70
 
71
-    /**
72
-     * @return boolean
73
-     * @throws \RuntimeException
74
-     * @throws \EE_Error
75
-     */
71
+	/**
72
+	 * @return boolean
73
+	 * @throws \RuntimeException
74
+	 * @throws \EE_Error
75
+	 */
76 76
 	public function process_reg_step() {
77
-        // ensure all data gets refreshed from the db
77
+		// ensure all data gets refreshed from the db
78 78
 		$this->checkout->refresh_all_entities( true );
79 79
 		// ensures that all details and statuses for transaction, registration, and payments are updated
80 80
 		$txn_update_params = $this->_finalize_transaction();
81
-        // maybe send messages
82
-        $this->_set_notification_triggers();
83
-        // send messages
84
-        /** @type EE_Registration_Processor $registration_processor */
85
-        $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
86
-        $registration_processor->trigger_registration_update_notifications(
87
-            $this->checkout->transaction->primary_registration(),
88
-            $txn_update_params
89
-        );
90
-        // set a hook point
81
+		// maybe send messages
82
+		$this->_set_notification_triggers();
83
+		// send messages
84
+		/** @type EE_Registration_Processor $registration_processor */
85
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
86
+		$registration_processor->trigger_registration_update_notifications(
87
+			$this->checkout->transaction->primary_registration(),
88
+			$txn_update_params
89
+		);
90
+		// set a hook point
91 91
 		do_action(
92 92
 			'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed',
93 93
 			$this->checkout,
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 		if (
105 105
 			! (
106 106
 				$this->checkout->payment_method instanceof EE_Payment_Method
107
-		        && $this->checkout->payment_method->is_off_site()
107
+				&& $this->checkout->payment_method->is_off_site()
108 108
 			)
109 109
 		) {
110 110
 			// mark this reg step as completed
@@ -116,14 +116,14 @@  discard block
 block discarded – undo
116 116
 
117 117
 
118 118
 
119
-    /**
120
-     * _finalize_transaction
121
-     * ensures that all details and statuses for transaction, registration, and payments are updated
122
-     *
123
-     * @return array
124
-     * @throws \RuntimeException
125
-     * @throws \EE_Error
126
-     */
119
+	/**
120
+	 * _finalize_transaction
121
+	 * ensures that all details and statuses for transaction, registration, and payments are updated
122
+	 *
123
+	 * @return array
124
+	 * @throws \RuntimeException
125
+	 * @throws \EE_Error
126
+	 */
127 127
 	protected function _finalize_transaction() {
128 128
 		/** @type EE_Transaction_Processor $transaction_processor */
129 129
 		$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
@@ -139,17 +139,17 @@  discard block
 block discarded – undo
139 139
 		}
140 140
 		// maybe update status, but don't save transaction just yet
141 141
 		$this->checkout->transaction->update_status_based_on_total_paid( false );
142
-        // this will result in the base session properties getting saved to the TXN_Session_data field
142
+		// this will result in the base session properties getting saved to the TXN_Session_data field
143 143
 		$this->checkout->transaction->set_txn_session_data(
144 144
 			EE_Registry::instance()->SSN->get_session_data( null, true )
145 145
 		);
146
-        // update the TXN if payment conditions have changed, but do NOT trigger notifications,
147
-        // because we will do that in process_reg_step() after setting some more triggers
146
+		// update the TXN if payment conditions have changed, but do NOT trigger notifications,
147
+		// because we will do that in process_reg_step() after setting some more triggers
148 148
 		return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
149 149
 			$this->checkout->transaction,
150 150
 			$this->checkout->payment,
151 151
 			$this->checkout->reg_cache_where_params,
152
-            false
152
+			false
153 153
 		);
154 154
 	}
155 155
 
@@ -167,43 +167,43 @@  discard block
 block discarded – undo
167 167
 	protected function _set_notification_triggers() {
168 168
 
169 169
 		if ( $this->checkout->payment_method instanceof EE_Payment_Method ) {
170
-		    // let's start with the assumption that we need to trigger notifications
171
-            // then toggle this to false for conditions where we know we don't need to
172
-		    $deliver_notifications = true;
173
-            if (
174
-                // if SPCO revisit
175
-                filter_var($this->checkout->revisit, FILTER_VALIDATE_BOOLEAN)
176
-                // and TXN or REG statuses have NOT changed due to a payment
177
-                && ! (
178
-                    $this->checkout->transaction->txn_status_updated()
179
-                    || $this->checkout->any_reg_status_updated()
180
-                )
181
-            ) {
182
-                $deliver_notifications = false;
183
-            }
184
-            if ($this->checkout->payment_method->is_off_site()) {
185
-                /** @var EE_Gateway $gateway */
186
-                $gateway = $this->checkout->payment_method->type_obj()->get_gateway();
187
-                // and the gateway uses a separate request to process the IPN
188
-                if (
189
-                    $gateway instanceof EE_Offsite_Gateway
190
-                    && $gateway->handle_IPN_in_this_request(\EE_Registry::instance()->REQ->params(), true)
191
-                ) {
192
-                    // IPN request will handle triggering notifications
193
-                    $deliver_notifications = false;
194
-                    // no really... don't send any notices in this request
195
-                    remove_all_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications');
196
-                    add_filter(
197
-                        'FHEE__EED_Messages___maybe_registration__deliver_notifications',
198
-                        '__return_false',
199
-                        15
200
-                    );
201
-                }
202
-            }
203
-            if ($deliver_notifications) {
204
-                // send out notifications
205
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
206
-            }
170
+			// let's start with the assumption that we need to trigger notifications
171
+			// then toggle this to false for conditions where we know we don't need to
172
+			$deliver_notifications = true;
173
+			if (
174
+				// if SPCO revisit
175
+				filter_var($this->checkout->revisit, FILTER_VALIDATE_BOOLEAN)
176
+				// and TXN or REG statuses have NOT changed due to a payment
177
+				&& ! (
178
+					$this->checkout->transaction->txn_status_updated()
179
+					|| $this->checkout->any_reg_status_updated()
180
+				)
181
+			) {
182
+				$deliver_notifications = false;
183
+			}
184
+			if ($this->checkout->payment_method->is_off_site()) {
185
+				/** @var EE_Gateway $gateway */
186
+				$gateway = $this->checkout->payment_method->type_obj()->get_gateway();
187
+				// and the gateway uses a separate request to process the IPN
188
+				if (
189
+					$gateway instanceof EE_Offsite_Gateway
190
+					&& $gateway->handle_IPN_in_this_request(\EE_Registry::instance()->REQ->params(), true)
191
+				) {
192
+					// IPN request will handle triggering notifications
193
+					$deliver_notifications = false;
194
+					// no really... don't send any notices in this request
195
+					remove_all_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications');
196
+					add_filter(
197
+						'FHEE__EED_Messages___maybe_registration__deliver_notifications',
198
+						'__return_false',
199
+						15
200
+					);
201
+				}
202
+			}
203
+			if ($deliver_notifications) {
204
+				// send out notifications
205
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
206
+			}
207 207
 		}
208 208
 	}
209 209
 
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 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
 
@@ -21,9 +21,9 @@  discard block
 block discarded – undo
21 21
 	 * @access    public
22 22
 	 * @param    EE_Checkout $checkout
23 23
 	 */
24
-	public function __construct( EE_Checkout $checkout ) {
24
+	public function __construct(EE_Checkout $checkout) {
25 25
 		$this->_slug = 'finalize_registration';
26
-		$this->_name = __( 'Finalize Registration', 'event_espresso' );
26
+		$this->_name = __('Finalize Registration', 'event_espresso');
27 27
 		$this->_submit_button_text = $this->_name;
28 28
 		$this->_template = '';
29 29
 		$this->checkout = $checkout;
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 */
47 47
 	public function initialize_reg_step() {
48 48
 		// there's actually no reg form to process if this is the final step
49
-		if ( $this->is_current_step() ) {
49
+		if ($this->is_current_step()) {
50 50
 			$this->checkout->step = $_REQUEST['step'] = $this->slug();
51 51
 			$this->checkout->action = $_REQUEST['action'] = 'process_reg_step';
52 52
 			$this->checkout->generate_reg_form = false;
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
      */
76 76
 	public function process_reg_step() {
77 77
         // ensure all data gets refreshed from the db
78
-		$this->checkout->refresh_all_entities( true );
78
+		$this->checkout->refresh_all_entities(true);
79 79
 		// ensures that all details and statuses for transaction, registration, and payments are updated
80 80
 		$txn_update_params = $this->_finalize_transaction();
81 81
         // maybe send messages
@@ -94,13 +94,13 @@  discard block
 block discarded – undo
94 94
 			$txn_update_params
95 95
 		);
96 96
 		// check if transaction has a primary registrant and that it has a related Attendee object
97
-		if ( ! $this->_validate_primary_registrant() ) {
97
+		if ( ! $this->_validate_primary_registrant()) {
98 98
 			return false;
99 99
 		}
100 100
 		// you don't have to go home but you can't stay here !
101 101
 		$this->checkout->redirect = true;
102 102
 		$this->checkout->continue_reg = true;
103
-		$this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url );
103
+		$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
104 104
 		if (
105 105
 			! (
106 106
 				$this->checkout->payment_method instanceof EE_Payment_Method
@@ -126,22 +126,22 @@  discard block
 block discarded – undo
126 126
      */
127 127
 	protected function _finalize_transaction() {
128 128
 		/** @type EE_Transaction_Processor $transaction_processor */
129
-		$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
129
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
130 130
 		//set revisit flag in txn processor
131
-		$transaction_processor->set_revisit( $this->checkout->revisit );
131
+		$transaction_processor->set_revisit($this->checkout->revisit);
132 132
 		// at this point we'll consider a TXN to not have been abandoned
133 133
 		$this->checkout->transaction->toggle_abandoned_transaction_status();
134
-		if ( $this->checkout->cart instanceof EE_Cart ) {
134
+		if ($this->checkout->cart instanceof EE_Cart) {
135 135
 			// save TXN data to the cart
136 136
 			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn(
137 137
 				$this->checkout->transaction->ID()
138 138
 			);
139 139
 		}
140 140
 		// maybe update status, but don't save transaction just yet
141
-		$this->checkout->transaction->update_status_based_on_total_paid( false );
141
+		$this->checkout->transaction->update_status_based_on_total_paid(false);
142 142
         // this will result in the base session properties getting saved to the TXN_Session_data field
143 143
 		$this->checkout->transaction->set_txn_session_data(
144
-			EE_Registry::instance()->SSN->get_session_data( null, true )
144
+			EE_Registry::instance()->SSN->get_session_data(null, true)
145 145
 		);
146 146
         // update the TXN if payment conditions have changed, but do NOT trigger notifications,
147 147
         // because we will do that in process_reg_step() after setting some more triggers
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	 */
167 167
 	protected function _set_notification_triggers() {
168 168
 
169
-		if ( $this->checkout->payment_method instanceof EE_Payment_Method ) {
169
+		if ($this->checkout->payment_method instanceof EE_Payment_Method) {
170 170
 		    // let's start with the assumption that we need to trigger notifications
171 171
             // then toggle this to false for conditions where we know we don't need to
172 172
 		    $deliver_notifications = true;
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
 	 * @throws \EE_Error
217 217
 	 */
218 218
 	protected function _validate_primary_registrant() {
219
-		if ( ! $this->checkout->transaction_has_primary_registrant() ) {
219
+		if ( ! $this->checkout->transaction_has_primary_registrant()) {
220 220
 			EE_Error::add_error(
221
-				__( 'A valid Primary Registration for this Transaction could not be found.', 'event_espresso' ),
221
+				__('A valid Primary Registration for this Transaction could not be found.', 'event_espresso'),
222 222
 				__FILE__,
223 223
 				__FUNCTION__,
224 224
 				__LINE__
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 		}
230 230
 		// setup URL for redirect
231 231
 		$this->checkout->redirect_url = add_query_arg(
232
-			array( 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link() ),
232
+			array('e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link()),
233 233
 			$this->checkout->thank_you_page_url
234 234
 		);
235 235
 		return true;
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 	 */
243 243
 	public function update_reg_step() {
244 244
 		EE_Error::doing_it_wrong(
245
-			__CLASS__ . '::' . __FILE__,
245
+			__CLASS__.'::'.__FILE__,
246 246
 			__(
247 247
 				'Can not call update_reg_step() on the Finalize Registration reg step.',
248 248
 				'event_espresso'
Please login to merge, or discard this patch.
core/EE_Addon.core.php 2 patches
Spacing   +83 added lines, -83 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
  *
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	 *    class constructor
96 96
 	 */
97 97
 	public function __construct() {
98
-		add_action( 'AHEE__EE_System__load_controllers__load_admin_controllers', array( $this, 'admin_init' ) );
98
+		add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init'));
99 99
 	}
100 100
 
101 101
 
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 	/**
104 104
 	 * @param mixed $version
105 105
 	 */
106
-	public function set_version( $version = NULL ) {
106
+	public function set_version($version = NULL) {
107 107
 		$this->_version = $version;
108 108
 	}
109 109
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	/**
122 122
 	 * @param mixed $min_core_version
123 123
 	 */
124
-	public function set_min_core_version( $min_core_version = NULL ) {
124
+	public function set_min_core_version($min_core_version = NULL) {
125 125
 		$this->_min_core_version = $min_core_version;
126 126
 	}
127 127
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	 * @param string $addon_name
143 143
 	 * @return boolean
144 144
 	 */
145
-	public function set_name( $addon_name ) {
145
+	public function set_name($addon_name) {
146 146
 		return $this->_addon_name = $addon_name;
147 147
 	}
148 148
 
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 	/**
171 171
 	 * @param string $plugin_basename
172 172
 	 */
173
-	public function set_plugin_basename( $plugin_basename ) {
173
+	public function set_plugin_basename($plugin_basename) {
174 174
 
175 175
 		$this->_plugin_basename = $plugin_basename;
176 176
 	}
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 	/**
191 191
 	 * @param string $plugin_slug
192 192
 	 */
193
-	public function set_plugin_slug( $plugin_slug ) {
193
+	public function set_plugin_slug($plugin_slug) {
194 194
 
195 195
 		$this->_plugin_slug = $plugin_slug;
196 196
 	}
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 	/**
211 211
 	 * @param string $plugin_action_slug
212 212
 	 */
213
-	public function set_plugin_action_slug( $plugin_action_slug ) {
213
+	public function set_plugin_action_slug($plugin_action_slug) {
214 214
 
215 215
 		$this->_plugin_action_slug = $plugin_action_slug;
216 216
 	}
@@ -230,9 +230,9 @@  discard block
 block discarded – undo
230 230
 	/**
231 231
 	 * @param array $plugins_page_row
232 232
 	 */
233
-	public function set_plugins_page_row( $plugins_page_row = array() ) {
233
+	public function set_plugins_page_row($plugins_page_row = array()) {
234 234
 		// sigh.... check for example content that I stupidly merged to master and remove it if found
235
-		if ( ! is_array( $plugins_page_row ) && strpos( $plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>' ) !== false ) {
235
+		if ( ! is_array($plugins_page_row) && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false) {
236 236
 			$plugins_page_row = '';
237 237
 		}
238 238
 		$this->_plugins_page_row = $plugins_page_row;
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 		do_action("AHEE__{$classname}__new_install");
251 251
 		do_action('AHEE__EE_Addon__new_install', $this);
252 252
 		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
253
-		add_action( 'AHEE__EE_System__perform_activations_upgrades_and_migrations', array( $this, 'initialize_db_if_no_migrations_required' ) );
253
+		add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', array($this, 'initialize_db_if_no_migrations_required'));
254 254
 	}
255 255
 
256 256
 
@@ -265,18 +265,18 @@  discard block
 block discarded – undo
265 265
 		do_action("AHEE__{$classname}__reactivation");
266 266
 		do_action('AHEE__EE_Addon__reactivation', $this);
267 267
 		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
268
-		add_action( 'AHEE__EE_System__perform_activations_upgrades_and_migrations', array( $this, 'initialize_db_if_no_migrations_required' ) );
268
+		add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', array($this, 'initialize_db_if_no_migrations_required'));
269 269
 	}
270 270
 
271 271
 
272 272
 
273
-	public function deactivation(){
273
+	public function deactivation() {
274 274
 		$classname = get_class($this);
275 275
 //		echo "Deactivating $classname";die;
276 276
 		do_action("AHEE__{$classname}__deactivation");
277 277
 		do_action('AHEE__EE_Addon__deactivation', $this);
278 278
 		//check if the site no longer needs to be in maintenance mode
279
-		EE_Register_Addon::deregister( $this->name() );
279
+		EE_Register_Addon::deregister($this->name());
280 280
 		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
281 281
 	}
282 282
 
@@ -292,16 +292,16 @@  discard block
 block discarded – undo
292 292
      * @return void
293 293
      * @throws \EE_Error
294 294
      */
295
-	public function initialize_db_if_no_migrations_required( $verify_schema = true ) {
296
-		if( $verify_schema === '' ) {
295
+	public function initialize_db_if_no_migrations_required($verify_schema = true) {
296
+		if ($verify_schema === '') {
297 297
 			//wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
298 298
 			//(ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it
299 299
 			//calls them with an argument of an empty string (ie ""), which evaluates to false
300 300
 			//so we need to treat the empty string as if nothing had been passed, and should instead use the default
301 301
 			$verify_schema = true;
302 302
 		}
303
-		if ( EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance ) {
304
-			if( $verify_schema ) {
303
+		if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
304
+			if ($verify_schema) {
305 305
 				$this->initialize_db();
306 306
 			}
307 307
 			$this->initialize_default_data();
@@ -319,15 +319,15 @@  discard block
 block discarded – undo
319 319
 			 * other data needs to be verified)
320 320
 			 */
321 321
 			EEH_Activation::initialize_db_content();
322
-			update_option( 'ee_flush_rewrite_rules', TRUE );
322
+			update_option('ee_flush_rewrite_rules', TRUE);
323 323
 			//in case there are lots of addons being activated at once, let's force garbage collection
324 324
 			//to help avoid memory limit errors
325 325
 			//EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true );
326 326
 			gc_collect_cycles();
327
-		}else{
327
+		} else {
328 328
 			//ask the data migration manager to init this addon's data
329 329
 			//when migrations are finished because we can't do it now
330
-			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for( $this->name() );
330
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name());
331 331
 		}
332 332
 	}
333 333
 
@@ -341,15 +341,15 @@  discard block
 block discarded – undo
341 341
 	 */
342 342
 	public function initialize_db() {
343 343
 		//find the migration script that sets the database to be compatible with the code
344
-		$current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms( $this->name() );
345
-		if( $current_dms_name ){
346
-			$current_data_migration_script = EE_Registry::instance()->load_dms( $current_dms_name );
347
-			$current_data_migration_script->set_migrating( FALSE );
344
+		$current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name());
345
+		if ($current_dms_name) {
346
+			$current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name);
347
+			$current_data_migration_script->set_migrating(FALSE);
348 348
 			$current_data_migration_script->schema_changes_before_migration();
349 349
 			$current_data_migration_script->schema_changes_after_migration();
350
-			if ( $current_data_migration_script->get_errors() ) {
351
-				foreach( $current_data_migration_script->get_errors() as $error ) {
352
-					EE_Error::add_error( $error, __FILE__, __FUNCTION__, __LINE__ );
350
+			if ($current_data_migration_script->get_errors()) {
351
+				foreach ($current_data_migration_script->get_errors() as $error) {
352
+					EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
353 353
 				}
354 354
 			}
355 355
 		}
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 		 * default data)
382 382
 		 * @param EE_Addon $addon the addon that called this
383 383
 		 */
384
-		do_action( 'AHEE__EE_Addon__initialize_default_data__begin', $this );
384
+		do_action('AHEE__EE_Addon__initialize_default_data__begin', $this);
385 385
 		//override to insert default data. It is safe to use the models here
386 386
 		//because the site should not be in maintenance mode
387 387
 	}
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
402 402
 		//also it's possible there is new default data that needs to be added
403 403
 		add_action(
404
-		    'AHEE__EE_System__perform_activations_upgrades_and_migrations', array( $this, 'initialize_db_if_no_migrations_required' )
404
+		    'AHEE__EE_System__perform_activations_upgrades_and_migrations', array($this, 'initialize_db_if_no_migrations_required')
405 405
         );
406 406
 	}
407 407
 
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
 		do_action("AHEE__{$classname}__downgrade");
416 416
 		do_action('AHEE__EE_Addon__downgrade', $this);
417 417
 		//it's possible there's old default data that needs to be double-checked
418
-		add_action( 'AHEE__EE_System__perform_activations_upgrades_and_migrations', array( $this, 'initialize_db_if_no_migrations_required' ) );
418
+		add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', array($this, 'initialize_db_if_no_migrations_required'));
419 419
 	}
420 420
 
421 421
 
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 	 * plugin activation only. In the future, we'll want to do it on plugin updates too
427 427
 	 * @return bool
428 428
 	 */
429
-	public function set_db_update_option_name(){
429
+	public function set_db_update_option_name() {
430 430
 		EE_Error::doing_it_wrong(__FUNCTION__, __('EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option', 'event_espresso'), '4.3.0.alpha.016');
431 431
 		//let's just handle this on the next request, ok? right now we're just not really ready
432 432
 		return $this->set_activation_indicator_option();
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 	 */
455 455
 	public function set_activation_indicator_option() {
456 456
 		// let's just handle this on the next request, ok? right now we're just not really ready
457
-		return update_option( $this->get_activation_indicator_option_name(), TRUE );
457
+		return update_option($this->get_activation_indicator_option_name(), TRUE);
458 458
 	}
459 459
 
460 460
 
@@ -462,8 +462,8 @@  discard block
 block discarded – undo
462 462
 	 * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
463 463
 	 * @return string
464 464
 	 */
465
-	public function get_activation_indicator_option_name(){
466
-		return 'ee_activation_' . $this->name();
465
+	public function get_activation_indicator_option_name() {
466
+		return 'ee_activation_'.$this->name();
467 467
 	}
468 468
 
469 469
 
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
 	 * Used by EE_System to set the request type of this addon. Should not be used by addon developers
474 474
 	 * @param int $req_type
475 475
 	 */
476
-	public function set_req_type( $req_type ) {
476
+	public function set_req_type($req_type) {
477 477
 		$this->_req_type = $req_type;
478 478
 	}
479 479
 
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 	 * of addons
485 485
 	 */
486 486
 	public function detect_req_type() {
487
-		if( ! $this->_req_type ){
487
+		if ( ! $this->_req_type) {
488 488
 			$this->detect_activation_or_upgrade();
489 489
 		}
490 490
 		return $this->_req_type;
@@ -497,36 +497,36 @@  discard block
 block discarded – undo
497 497
 	 * Should only be called once per request
498 498
 	 * @return void
499 499
 	 */
500
-	public function detect_activation_or_upgrade(){
500
+	public function detect_activation_or_upgrade() {
501 501
 		$activation_history_for_addon = $this->get_activation_history();
502 502
 //		d($activation_history_for_addon);
503 503
 		$request_type = EE_System::detect_req_type_given_activation_history($activation_history_for_addon, $this->get_activation_indicator_option_name(), $this->version());
504 504
 		$this->set_req_type($request_type);
505 505
 		$classname = get_class($this);
506
-		switch($request_type){
506
+		switch ($request_type) {
507 507
 			case EE_System::req_type_new_activation:
508
-				do_action( "AHEE__{$classname}__detect_activations_or_upgrades__new_activation" );
509
-				do_action( 'AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this );
508
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation");
509
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this);
510 510
 				$this->new_install();
511
-				$this->update_list_of_installed_versions( $activation_history_for_addon );
511
+				$this->update_list_of_installed_versions($activation_history_for_addon);
512 512
 				break;
513 513
 			case EE_System::req_type_reactivation:
514
-				do_action( "AHEE__{$classname}__detect_activations_or_upgrades__reactivation" );
515
-				do_action( 'AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this );
514
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation");
515
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this);
516 516
 				$this->reactivation();
517
-				$this->update_list_of_installed_versions( $activation_history_for_addon );
517
+				$this->update_list_of_installed_versions($activation_history_for_addon);
518 518
 				break;
519 519
 			case EE_System::req_type_upgrade:
520
-				do_action( "AHEE__{$classname}__detect_activations_or_upgrades__upgrade" );
521
-				do_action( 'AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this );
520
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade");
521
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this);
522 522
 				$this->upgrade();
523
-				$this->update_list_of_installed_versions($activation_history_for_addon );
523
+				$this->update_list_of_installed_versions($activation_history_for_addon);
524 524
 				break;
525 525
 			case EE_System::req_type_downgrade:
526
-				do_action( "AHEE__{$classname}__detect_activations_or_upgrades__downgrade" );
527
-				do_action( 'AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this );
526
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade");
527
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this);
528 528
 				$this->downgrade();
529
-				$this->update_list_of_installed_versions($activation_history_for_addon );
529
+				$this->update_list_of_installed_versions($activation_history_for_addon);
530 530
 				break;
531 531
 			case EE_System::req_type_normal:
532 532
 			default:
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
 				break;
535 535
 		}
536 536
 
537
-		do_action( "AHEE__{$classname}__detect_if_activation_or_upgrade__complete" );
537
+		do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete");
538 538
 	}
539 539
 
540 540
 	/**
@@ -543,17 +543,17 @@  discard block
 block discarded – undo
543 543
 	 * @param string $current_version_to_add
544 544
 	 * @return boolean success
545 545
 	 */
546
-	public function update_list_of_installed_versions($version_history = NULL,$current_version_to_add = NULL) {
547
-		if( ! $version_history ) {
546
+	public function update_list_of_installed_versions($version_history = NULL, $current_version_to_add = NULL) {
547
+		if ( ! $version_history) {
548 548
 			$version_history = $this->get_activation_history();
549 549
 		}
550
-		if( $current_version_to_add === NULL){
550
+		if ($current_version_to_add === NULL) {
551 551
 			$current_version_to_add = $this->version();
552 552
 		}
553
-		$version_history[ $current_version_to_add ][] = date( 'Y-m-d H:i:s',time() );
553
+		$version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
554 554
 		// resave
555 555
 //		echo "updating list of installed versions:".$this->get_activation_history_option_name();d($version_history);
556
-		return update_option( $this->get_activation_history_option_name(), $version_history );
556
+		return update_option($this->get_activation_history_option_name(), $version_history);
557 557
 	}
558 558
 
559 559
 	/**
@@ -561,8 +561,8 @@  discard block
 block discarded – undo
561 561
 	 * of this addon
562 562
 	 * @return string
563 563
 	 */
564
-	public function get_activation_history_option_name(){
565
-		return self::ee_addon_version_history_option_prefix . $this->name();
564
+	public function get_activation_history_option_name() {
565
+		return self::ee_addon_version_history_option_prefix.$this->name();
566 566
 	}
567 567
 
568 568
 
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
 	 * Gets the wp option which stores the activation history for this addon
572 572
 	 * @return array
573 573
 	 */
574
-	public function get_activation_history(){
574
+	public function get_activation_history() {
575 575
 		return get_option($this->get_activation_history_option_name(), NULL);
576 576
 	}
577 577
 
@@ -580,8 +580,8 @@  discard block
 block discarded – undo
580 580
 	/**
581 581
 	 * @param string $config_section
582 582
 	 */
583
-	public function set_config_section( $config_section = '' ) {
584
-		$this->_config_section = ! empty( $config_section ) ? $config_section : 'addons';
583
+	public function set_config_section($config_section = '') {
584
+		$this->_config_section = ! empty($config_section) ? $config_section : 'addons';
585 585
 	}
586 586
 	/**
587 587
 	 *	filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc.
@@ -594,14 +594,14 @@  discard block
 block discarded – undo
594 594
 	 * Sets the filepath to the main plugin file
595 595
 	 * @param string $filepath
596 596
 	 */
597
-	public function set_main_plugin_file( $filepath ) {
597
+	public function set_main_plugin_file($filepath) {
598 598
 		$this->_main_plugin_file = $filepath;
599 599
 	}
600 600
 	/**
601 601
 	 * gets the filepath to teh main file
602 602
 	 * @return string
603 603
 	 */
604
-	public function get_main_plugin_file(){
604
+	public function get_main_plugin_file() {
605 605
 		return $this->_main_plugin_file;
606 606
 	}
607 607
 
@@ -611,15 +611,15 @@  discard block
 block discarded – undo
611 611
 	 * @return string
612 612
 	 */
613 613
 	public function get_main_plugin_file_basename() {
614
-		return plugin_basename( $this->get_main_plugin_file() );
614
+		return plugin_basename($this->get_main_plugin_file());
615 615
 	}
616 616
 
617 617
 	/**
618 618
 	 * Gets the folder name which contains the main plugin file
619 619
 	 * @return string
620 620
 	 */
621
-	public function get_main_plugin_file_dirname(){
622
-		return dirname( $this->get_main_plugin_file() );
621
+	public function get_main_plugin_file_dirname() {
622
+		return dirname($this->get_main_plugin_file());
623 623
 	}
624 624
 
625 625
 
@@ -628,11 +628,11 @@  discard block
 block discarded – undo
628 628
      *
629 629
      * @return void
630 630
 	 */
631
-	public function admin_init(){
631
+	public function admin_init() {
632 632
 		// is admin and not in M-Mode ?
633
-		if ( is_admin() && ! EE_Maintenance_Mode::instance()->level() ) {
634
-			add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
635
-			add_filter( 'after_plugin_row_' . $this->_plugin_basename, array( $this, 'after_plugin_row' ), 10, 3 );
633
+		if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
634
+			add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
635
+			add_filter('after_plugin_row_'.$this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
636 636
 		}
637 637
 	}
638 638
 
@@ -647,10 +647,10 @@  discard block
 block discarded – undo
647 647
 	 * @param $file
648 648
 	 * @return array
649 649
 	 */
650
-	public function plugin_action_links( $links, $file ) {
651
-		if ( $file === $this->plugin_basename() && $this->plugin_action_slug() !== '' ) {
650
+	public function plugin_action_links($links, $file) {
651
+		if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
652 652
 			// before other links
653
-			array_unshift( $links, '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' . __( 'Settings' ) . '</a>' );
653
+			array_unshift($links, '<a href="admin.php?page='.$this->plugin_action_slug().'">'.__('Settings').'</a>');
654 654
 		}
655 655
 		return $links;
656 656
 	}
@@ -668,17 +668,17 @@  discard block
 block discarded – undo
668 668
 	 * @param $status
669 669
 	 * @return void
670 670
 	 */
671
-	public function after_plugin_row( $plugin_file, $plugin_data, $status ) {
671
+	public function after_plugin_row($plugin_file, $plugin_data, $status) {
672 672
 
673 673
 		$after_plugin_row = '';
674
-		if ( $plugin_file === $this->plugin_basename() && $this->get_plugins_page_row() !== '' ) {
674
+		if ($plugin_file === $this->plugin_basename() && $this->get_plugins_page_row() !== '') {
675 675
 			$class = $status ? 'active' : 'inactive';
676 676
 			$plugins_page_row = $this->get_plugins_page_row();
677
-			$link_text = isset( $plugins_page_row[ 'link_text' ] ) ? $plugins_page_row[ 'link_text' ] : '';
678
-			$link_url = isset( $plugins_page_row[ 'link_url' ] ) ? $plugins_page_row[ 'link_url' ] : '';
679
-			$description = isset( $plugins_page_row[ 'description' ] ) ? $plugins_page_row[ 'description' ] : $plugins_page_row;
680
-			if ( ! empty( $link_text ) && ! empty( $link_url ) && ! empty( $description )) {
681
-				$after_plugin_row .= '<tr id="' . sanitize_title( $plugin_file ) . '-ee-addon" class="' . $class . '">';
677
+			$link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
678
+			$link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
679
+			$description = isset($plugins_page_row['description']) ? $plugins_page_row['description'] : $plugins_page_row;
680
+			if ( ! empty($link_text) && ! empty($link_url) && ! empty($description)) {
681
+				$after_plugin_row .= '<tr id="'.sanitize_title($plugin_file).'-ee-addon" class="'.$class.'">';
682 682
 				$after_plugin_row .= '<th class="check-column" scope="row"></th>';
683 683
 				$after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
684 684
 				$after_plugin_row .= '<style>
@@ -720,7 +720,7 @@  discard block
 block discarded – undo
720 720
 </style>';
721 721
 				$after_plugin_row .= '
722 722
 <p class="ee-addon-upsell-info-dv">
723
-	<a class="ee-button" href="' . $link_url . '">' . $link_text . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span></a>
723
+	<a class="ee-button" href="' . $link_url.'">'.$link_text.' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span></a>
724 724
 </p>';
725 725
 				$after_plugin_row .= '</td>';
726 726
 				$after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
Please login to merge, or discard this patch.
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -282,16 +282,16 @@  discard block
 block discarded – undo
282 282
 
283 283
 
284 284
 
285
-    /**
286
-     * Takes care of double-checking that we're not in maintenance mode, and then
287
-     * initializing this addon's necessary initial data. This is called by default on new activations
288
-     * and reactivations
289
-     *
290
-     * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
291
-     *                               This is a resource-intensive job so we prefer to only do it when necessary
292
-     * @return void
293
-     * @throws \EE_Error
294
-     */
285
+	/**
286
+	 * Takes care of double-checking that we're not in maintenance mode, and then
287
+	 * initializing this addon's necessary initial data. This is called by default on new activations
288
+	 * and reactivations
289
+	 *
290
+	 * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
291
+	 *                               This is a resource-intensive job so we prefer to only do it when necessary
292
+	 * @return void
293
+	 * @throws \EE_Error
294
+	 */
295 295
 	public function initialize_db_if_no_migrations_required( $verify_schema = true ) {
296 296
 		if( $verify_schema === '' ) {
297 297
 			//wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name
@@ -307,11 +307,11 @@  discard block
 block discarded – undo
307 307
 			$this->initialize_default_data();
308 308
 			//@todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe
309 309
 			EE_Data_Migration_Manager::instance()->update_current_database_state_to(
310
-			    array(
311
-			        'slug' => $this->name(),
312
-                    'version' => $this->version()
313
-                )
314
-            );
310
+				array(
311
+					'slug' => $this->name(),
312
+					'version' => $this->version()
313
+				)
314
+			);
315 315
 			/* make sure core's data is a-ok
316 316
 			 * (at the time of writing, we especially want to verify all the caps are present
317 317
 			 * because payment method type capabilities are added dynamically, and it's
@@ -355,11 +355,11 @@  discard block
 block discarded – undo
355 355
 		}
356 356
 		//if not DMS was found that should be ok. This addon just doesn't require any database changes
357 357
 		EE_Data_Migration_Manager::instance()->update_current_database_state_to(
358
-		    array(
359
-		        'slug' => $this->name(),
360
-                'version' => $this->version()
361
-            )
362
-        );
358
+			array(
359
+				'slug' => $this->name(),
360
+				'version' => $this->version()
361
+			)
362
+		);
363 363
 	}
364 364
 
365 365
 
@@ -401,8 +401,8 @@  discard block
 block discarded – undo
401 401
 		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
402 402
 		//also it's possible there is new default data that needs to be added
403 403
 		add_action(
404
-		    'AHEE__EE_System__perform_activations_upgrades_and_migrations', array( $this, 'initialize_db_if_no_migrations_required' )
405
-        );
404
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations', array( $this, 'initialize_db_if_no_migrations_required' )
405
+		);
406 406
 	}
407 407
 
408 408
 
@@ -624,9 +624,9 @@  discard block
 block discarded – undo
624 624
 
625 625
 
626 626
 	/**
627
-     * sets hooks used in the admin
628
-     *
629
-     * @return void
627
+	 * sets hooks used in the admin
628
+	 *
629
+	 * @return void
630 630
 	 */
631 631
 	public function admin_init(){
632 632
 		// is admin and not in M-Mode ?
@@ -737,16 +737,16 @@  discard block
 block discarded – undo
737 737
 
738 738
 
739 739
 
740
-    /**
741
-     * a safe space for addons to add additional logic like setting hooks
742
-     * that will run immediately after addon registration
743
-     * making this a great place for code that needs to be "omnipresent"
744
-     *
745
-     * @since 4.9.26
746
-     */
740
+	/**
741
+	 * a safe space for addons to add additional logic like setting hooks
742
+	 * that will run immediately after addon registration
743
+	 * making this a great place for code that needs to be "omnipresent"
744
+	 *
745
+	 * @since 4.9.26
746
+	 */
747 747
 	public function after_registration()
748
-    {
749
-        // cricket chirp... cricket chirp...
748
+	{
749
+		// cricket chirp... cricket chirp...
750 750
 	}
751 751
 
752 752
 
Please login to merge, or discard this patch.
core/entities/models/JsonModelSchema.php 3 patches
Doc Comments   -2 removed lines patch added patch discarded remove patch
@@ -39,7 +39,6 @@  discard block
 block discarded – undo
39 39
 
40 40
     /**
41 41
      * Return the schema for a given model from a given model.
42
-     * @param \EEM_Base $model
43 42
      * @return array
44 43
      */
45 44
     public function getModelSchema()
@@ -103,7 +102,6 @@  discard block
 block discarded – undo
103 102
 
104 103
     /**
105 104
      * Outputs the schema header for a model.
106
-     * @param \EEM_Base $model
107 105
      * @return array
108 106
      */
109 107
     public function getInitialSchemaStructure()
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      *
34 34
      * @param \EEM_Base $model
35 35
      */
36
-    public function __construct(EEM_Base $model){
36
+    public function __construct(EEM_Base $model) {
37 37
         $this->model = $model;
38 38
     }
39 39
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
     public function getModelSchemaForFields(array $model_fields, array $schema)
61 61
     {
62 62
         foreach ($model_fields as $field => $model_field) {
63
-            if (! $model_field instanceof EE_Model_Field_Base) {
63
+            if ( ! $model_field instanceof EE_Model_Field_Base) {
64 64
                 continue;
65 65
             }
66 66
             $schema['properties'][$field] = $model_field->getSchema();
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
     public function getModelSchemaForRelations(array $relations_on_model, array $schema)
92 92
     {
93 93
         foreach ($relations_on_model as $model_name => $relation) {
94
-            if (! $relation instanceof EE_Model_Relation_Base) {
94
+            if ( ! $relation instanceof EE_Model_Relation_Base) {
95 95
                 continue;
96 96
             }
97 97
             $model_name_for_schema = EEH_Inflector::pluralize_and_lower($model_name);
Please login to merge, or discard this patch.
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -24,116 +24,116 @@
 block discarded – undo
24 24
 class JsonModelSchema
25 25
 {
26 26
 
27
-    /**
28
-     * @var \EEM_Base
29
-     */
30
-    protected $model;
31
-
32
-    /**
33
-     * JsonModelSchema constructor.
34
-     *
35
-     * @param \EEM_Base $model
36
-     */
37
-    public function __construct(EEM_Base $model){
38
-        $this->model = $model;
39
-    }
40
-
41
-    /**
42
-     * Return the schema for a given model from a given model.
43
-     * @param \EEM_Base $model
44
-     * @return array
45
-     */
46
-    public function getModelSchema()
47
-    {
48
-        return $this->getModelSchemaForRelations(
49
-            $this->model->relation_settings(),
50
-            $this->getModelSchemaForFields(
51
-                $this->model->field_settings(),
52
-                $this->getInitialSchemaStructure()
53
-            )
54
-        );
55
-    }
56
-
57
-
58
-    /**
59
-     * Get the schema for a given set of model fields.
60
-     * @param \EE_Model_Field_Base[]     $model_fields
61
-     * @return array
62
-     */
63
-    public function getModelSchemaForFields(array $model_fields, array $schema)
64
-    {
65
-        foreach ($model_fields as $field => $model_field) {
66
-            if (! $model_field instanceof EE_Model_Field_Base) {
67
-                continue;
68
-            }
69
-            $schema['properties'][$field] = $model_field->getSchema();
70
-
71
-            //if this is a primary key field add the primary key item
72
-            if ($model_field instanceof EE_Primary_Key_Field_Base) {
73
-                $schema['properties'][$field]['primary_key'] = true;
74
-            }
75
-
76
-            //if this is a foreign key field add the foreign key item
77
-            if ($model_field instanceof EE_Foreign_Key_Field_Base) {
78
-                $schema['properties'][$field]['foreign_key'] = array(
79
-                    'description' => esc_html__('This is a foreign key the points to the given models.', 'event_espresso'),
80
-                    'type' => 'array',
81
-                    'enum' => $model_field->get_model_class_names_pointed_to()
82
-                );
83
-            }
84
-        }
85
-        return $schema;
86
-    }
87
-
88
-
89
-    /**
90
-     * Get the schema for a given set of model relations
91
-     * @param EE_Model_Relation_Base[] $relations_on_model
92
-     * @return array
93
-     */
94
-    public function getModelSchemaForRelations(array $relations_on_model, array $schema)
95
-    {
96
-        foreach ($relations_on_model as $model_name => $relation) {
97
-            if (! $relation instanceof EE_Model_Relation_Base) {
98
-                continue;
99
-            }
100
-            $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation
101
-                ? strtolower($model_name)
102
-                : EEH_Inflector::pluralize_and_lower($model_name);
103
-            $schema['properties'][$model_name_for_schema] = $relation->getSchema();
104
-            $schema['properties'][$model_name_for_schema]['relation_model'] = $model_name;
105
-        }
106
-        return $schema;
107
-    }
108
-
109
-
110
-    /**
111
-     * Outputs the schema header for a model.
112
-     * @param \EEM_Base $model
113
-     * @return array
114
-     */
115
-    public function getInitialSchemaStructure()
116
-    {
117
-        return array(
118
-            '$schema' => 'http://json-schema.org/draft-04/schema#',
119
-            'title' => $this->model->get_this_model_name(),
120
-            'type' => 'object',
121
-            'properties' => array()
122
-        );
123
-    }
124
-
125
-
126
-    /**
127
-     * Allows one to just use the object as a string to get the json.
128
-     * eg.
129
-     *
130
-     * $json_schema = new JsonModelSchema(EEM_Event::instance());
131
-     * echo $json_schema; //outputs the schema as a json formatted string.
132
-     *
133
-     * @return bool|false|mixed|string
134
-     */
135
-    public function __toString()
136
-    {
137
-        return wp_json_encode($this->getModelSchema());
138
-    }
27
+	/**
28
+	 * @var \EEM_Base
29
+	 */
30
+	protected $model;
31
+
32
+	/**
33
+	 * JsonModelSchema constructor.
34
+	 *
35
+	 * @param \EEM_Base $model
36
+	 */
37
+	public function __construct(EEM_Base $model){
38
+		$this->model = $model;
39
+	}
40
+
41
+	/**
42
+	 * Return the schema for a given model from a given model.
43
+	 * @param \EEM_Base $model
44
+	 * @return array
45
+	 */
46
+	public function getModelSchema()
47
+	{
48
+		return $this->getModelSchemaForRelations(
49
+			$this->model->relation_settings(),
50
+			$this->getModelSchemaForFields(
51
+				$this->model->field_settings(),
52
+				$this->getInitialSchemaStructure()
53
+			)
54
+		);
55
+	}
56
+
57
+
58
+	/**
59
+	 * Get the schema for a given set of model fields.
60
+	 * @param \EE_Model_Field_Base[]     $model_fields
61
+	 * @return array
62
+	 */
63
+	public function getModelSchemaForFields(array $model_fields, array $schema)
64
+	{
65
+		foreach ($model_fields as $field => $model_field) {
66
+			if (! $model_field instanceof EE_Model_Field_Base) {
67
+				continue;
68
+			}
69
+			$schema['properties'][$field] = $model_field->getSchema();
70
+
71
+			//if this is a primary key field add the primary key item
72
+			if ($model_field instanceof EE_Primary_Key_Field_Base) {
73
+				$schema['properties'][$field]['primary_key'] = true;
74
+			}
75
+
76
+			//if this is a foreign key field add the foreign key item
77
+			if ($model_field instanceof EE_Foreign_Key_Field_Base) {
78
+				$schema['properties'][$field]['foreign_key'] = array(
79
+					'description' => esc_html__('This is a foreign key the points to the given models.', 'event_espresso'),
80
+					'type' => 'array',
81
+					'enum' => $model_field->get_model_class_names_pointed_to()
82
+				);
83
+			}
84
+		}
85
+		return $schema;
86
+	}
87
+
88
+
89
+	/**
90
+	 * Get the schema for a given set of model relations
91
+	 * @param EE_Model_Relation_Base[] $relations_on_model
92
+	 * @return array
93
+	 */
94
+	public function getModelSchemaForRelations(array $relations_on_model, array $schema)
95
+	{
96
+		foreach ($relations_on_model as $model_name => $relation) {
97
+			if (! $relation instanceof EE_Model_Relation_Base) {
98
+				continue;
99
+			}
100
+			$model_name_for_schema = $relation instanceof EE_Belongs_To_Relation
101
+				? strtolower($model_name)
102
+				: EEH_Inflector::pluralize_and_lower($model_name);
103
+			$schema['properties'][$model_name_for_schema] = $relation->getSchema();
104
+			$schema['properties'][$model_name_for_schema]['relation_model'] = $model_name;
105
+		}
106
+		return $schema;
107
+	}
108
+
109
+
110
+	/**
111
+	 * Outputs the schema header for a model.
112
+	 * @param \EEM_Base $model
113
+	 * @return array
114
+	 */
115
+	public function getInitialSchemaStructure()
116
+	{
117
+		return array(
118
+			'$schema' => 'http://json-schema.org/draft-04/schema#',
119
+			'title' => $this->model->get_this_model_name(),
120
+			'type' => 'object',
121
+			'properties' => array()
122
+		);
123
+	}
124
+
125
+
126
+	/**
127
+	 * Allows one to just use the object as a string to get the json.
128
+	 * eg.
129
+	 *
130
+	 * $json_schema = new JsonModelSchema(EEM_Event::instance());
131
+	 * echo $json_schema; //outputs the schema as a json formatted string.
132
+	 *
133
+	 * @return bool|false|mixed|string
134
+	 */
135
+	public function __toString()
136
+	{
137
+		return wp_json_encode($this->getModelSchema());
138
+	}
139 139
 }
Please login to merge, or discard this patch.
modules/core_rest_api/EED_Core_Rest_Api.module.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -157,13 +157,13 @@  discard block
 block discarded – undo
157 157
      */
158 158
     protected static function _set_hooks_for_changes()
159 159
     {
160
-        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
160
+        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES.'rest_api'.DS.'changes'), false);
161 161
         foreach ($folder_contents as $classname_in_namespace => $filepath) {
162 162
             //ignore the base parent class
163 163
             if ($classname_in_namespace === 'Changes_In_Base') {
164 164
                 continue;
165 165
             }
166
-            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
166
+            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\'.$classname_in_namespace;
167 167
             if (class_exists($full_classname)) {
168 168
                 $instance_of_class = new $full_classname;
169 169
                 if ($instance_of_class instanceof EventEspresso\core\libraries\rest_api\changes\Changes_In_Base) {
@@ -195,11 +195,11 @@  discard block
 block discarded – undo
195 195
                         $model_name = isset($route['schema_callback'][0])
196 196
                             ? $route['schema_callback'][0]
197 197
                             : '';
198
-                        $version = isset( $route['schema_callback'][1])
198
+                        $version = isset($route['schema_callback'][1])
199 199
                             ? $route['schema_callback'][1]
200 200
                             : '';
201
-                        if (! empty($model_name) && ! empty($version)) {
202
-                            $route_args['schema'] = function () use ($model_name, $version) {
201
+                        if ( ! empty($model_name) && ! empty($version)) {
202
+                            $route_args['schema'] = function() use ($model_name, $version) {
203 203
                                 return EventEspresso\core\libraries\rest_api\controllers\model\Read::handle_schema_request(
204 204
                                     $model_name,
205 205
                                     $version
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
     {
246 246
         //delete the saved EE REST API routes
247 247
         foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
248
-            delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
248
+            delete_option(EED_Core_Rest_Api::saved_routes_option_names.$version);
249 249
         }
250 250
     }
251 251
 
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
     {
265 265
         $ee_routes = array();
266 266
         foreach (self::versions_served() as $version => $hidden_endpoints) {
267
-            $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version($version,
267
+            $ee_routes[self::ee_api_namespace.$version] = self::_get_ee_route_data_for_version($version,
268 268
                 $hidden_endpoints);
269 269
         }
270 270
         return $ee_routes;
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
      */
283 283
     protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
284 284
     {
285
-        $ee_routes = get_option(self::saved_routes_option_names . $version, null);
285
+        $ee_routes = get_option(self::saved_routes_option_names.$version, null);
286 286
         if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
287 287
             $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
288 288
         }
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
                 $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
311 311
             )
312 312
         );
313
-        $option_name = self::saved_routes_option_names . $version;
313
+        $option_name = self::saved_routes_option_names.$version;
314 314
         if (get_option($option_name)) {
315 315
             update_option($option_name, $routes, true);
316 316
         } else {
@@ -387,13 +387,13 @@  discard block
 block discarded – undo
387 387
             $model = \EE_Registry::instance()->load_model($model_name);
388 388
 
389 389
             //if this isn't a valid model then let's skip iterate to the next item in the loop.
390
-            if (! $model instanceof EEM_Base) {
390
+            if ( ! $model instanceof EEM_Base) {
391 391
                 continue;
392 392
             }
393 393
 
394 394
             //yes we could just register one route for ALL models, but then they wouldn't show up in the index
395 395
             $plural_model_route = EEH_Inflector::pluralize_and_lower($model_name);
396
-            $singular_model_route = $plural_model_route . '/(?P<id>\d+)';
396
+            $singular_model_route = $plural_model_route.'/(?P<id>\d+)';
397 397
             $model_routes[$plural_model_route] = array(
398 398
                 array(
399 399
                     'callback'        => array(
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
                     'hidden_endpoint' => $hidden_endpoint,
405 405
                     'args'            => $this->_get_read_query_params($model, $version),
406 406
                     '_links'          => array(
407
-                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
407
+                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace.$version.$singular_model_route),
408 408
                     ),
409 409
                     'schema_callback' => array($model_name, $version)
410 410
                 ),
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
                     $relation_name,
441 441
                     $relation_obj
442 442
                 );
443
-                $model_routes[$singular_model_route . '/' . $related_model_name_endpoint_part] = array(
443
+                $model_routes[$singular_model_route.'/'.$related_model_name_endpoint_part] = array(
444 444
                     array(
445 445
                         'callback'        => array(
446 446
                             'EventEspresso\core\libraries\rest_api\controllers\model\Read',
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
     {
477 477
         $routes = array();
478 478
         foreach (self::versions_served() as $version => $hidden_endpoint) {
479
-            $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version($version,
479
+            $routes[self::ee_api_namespace.$version] = $this->_get_rpc_route_data_for_version($version,
480 480
                 $hidden_endpoint);
481 481
         }
482 482
         return $routes;
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
     {
608 608
         $config_routes = array();
609 609
         foreach (self::versions_served() as $version => $hidden_endpoint) {
610
-            $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version($version,
610
+            $config_routes[self::ee_api_namespace.$version] = $this->_get_config_route_data_for_version($version,
611 611
                 $hidden_endpoint);
612 612
         }
613 613
         return $config_routes;
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
     {
661 661
         $meta_routes = array();
662 662
         foreach (self::versions_served() as $version => $hidden_endpoint) {
663
-            $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version($version,
663
+            $meta_routes[self::ee_api_namespace.$version] = $this->_get_meta_route_data_for_version($version,
664 664
                 $hidden_endpoint);
665 665
         }
666 666
         return $meta_routes;
@@ -715,7 +715,7 @@  discard block
 block discarded – undo
715 715
                     if (($route['hidden_endpoint'] && $force_show_ee_namespace === '')
716 716
                         || ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
717 717
                     ) {
718
-                        $full_route = '/' . ltrim($namespace, '/') . '/' . ltrim($endpoint, '/');
718
+                        $full_route = '/'.ltrim($namespace, '/').'/'.ltrim($endpoint, '/');
719 719
                         unset($route_data[$full_route]);
720 720
                     }
721 721
                 }
Please login to merge, or discard this patch.
Indentation   +837 added lines, -837 removed lines patch added patch discarded remove patch
@@ -18,844 +18,844 @@
 block discarded – undo
18 18
 class EED_Core_Rest_Api extends \EED_Module
19 19
 {
20 20
 
21
-    const ee_api_namespace           = 'ee/v';
21
+	const ee_api_namespace           = 'ee/v';
22 22
 
23
-    const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/';
24
-
25
-    const saved_routes_option_names  = 'ee_core_routes';
26
-
27
-    /**
28
-     * string used in _links response bodies to make them globally unique.
29
-     *
30
-     * @see http://v2.wp-api.org/extending/linking/
31
-     */
32
-    const ee_api_link_namespace = 'https://api.eventespresso.com/';
33
-
34
-    /**
35
-     * @var Calculated_Model_Fields
36
-     */
37
-    protected static $_field_calculator = null;
38
-
39
-
40
-
41
-    /**
42
-     * @return EED_Core_Rest_Api
43
-     */
44
-    public static function instance()
45
-    {
46
-        self::$_field_calculator = new Calculated_Model_Fields();
47
-        return parent::get_instance(__CLASS__);
48
-    }
49
-
50
-
51
-
52
-    /**
53
-     *    set_hooks - for hooking into EE Core, other modules, etc
54
-     *
55
-     * @access    public
56
-     * @return    void
57
-     */
58
-    public static function set_hooks()
59
-    {
60
-        self::set_hooks_both();
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
67
-     *
68
-     * @access    public
69
-     * @return    void
70
-     */
71
-    public static function set_hooks_admin()
72
-    {
73
-        self::set_hooks_both();
74
-    }
75
-
76
-
77
-
78
-    public static function set_hooks_both()
79
-    {
80
-        add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10);
81
-        add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5);
82
-        add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2);
83
-        add_filter('rest_index',
84
-            array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filter_ee_metadata_into_index'));
85
-        EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change();
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     * sets up hooks which only need to be included as part of REST API requests;
92
-     * other requests like to the frontend or admin etc don't need them
93
-     */
94
-    public static function set_hooks_rest_api()
95
-    {
96
-        //set hooks which account for changes made to the API
97
-        EED_Core_Rest_Api::_set_hooks_for_changes();
98
-        EED_Core_Rest_Api::maybe_notify_of_basic_auth_removal();
99
-    }
100
-
101
-
102
-
103
-    /**
104
-     * public wrapper of _set_hooks_for_changes.
105
-     * Loads all the hooks which make requests to old versions of the API
106
-     * appear the same as they always did
107
-     */
108
-    public static function set_hooks_for_changes()
109
-    {
110
-        self::_set_hooks_for_changes();
111
-    }
112
-
113
-
114
-
115
-    /**
116
-     * If the user appears to be using WP API basic auth, tell them (via a persistent
117
-     * admin notice and an email) that we're going to remove it soon, so they should
118
-     * replace it with application passwords.
119
-     */
120
-    public static function maybe_notify_of_basic_auth_removal()
121
-    {
122
-        if (
123
-        apply_filters(
124
-            'FHEE__EED_Core_Rest_Api__maybe_notify_of_basic_auth_removal__override',
125
-            ! isset($_SERVER['PHP_AUTH_USER'])
126
-            && ! isset($_SERVER['HTTP_AUTHORIZATION'])
127
-        )
128
-        ) {
129
-            //sure it's a WP API request, but they aren't using basic auth, so don't bother them
130
-            return;
131
-        }
132
-        //ok they're using the WP API with Basic Auth
133
-        $message = sprintf(
134
-            __('We noticed you\'re using the WP API, which is used by the Event Espresso 4 mobile apps. Because of security and compatibility concerns, we will soon be removing our default authentication mechanism, WP API Basic Auth, from Event Espresso. It is recommended you instead install the %1$sWP Application Passwords plugin%2$s and use it with the EE4 Mobile apps. See %3$sour mobile app documentation%2$s for more information. %4$sIf you have installed the WP API Basic Auth plugin separately, or are not using the Event Espresso 4 mobile apps, you can disregard this message.%4$sThe Event Espresso Team',
135
-                'event_espresso'),
136
-            '<a href="https://wordpress.org/plugins/application-passwords/">',
137
-            '</a>',
138
-            '<a href="https://eventespresso.com/wiki/ee4-event-apps/#authentication">',
139
-            '<br/>'
140
-        );
141
-        EE_Error::add_persistent_admin_notice('using_basic_auth', $message);
142
-        if ( ! get_option('ee_notified_admin_on_basic_auth_removal', false)) {
143
-            add_option('ee_notified_admin_on_basic_auth_removal', true);
144
-            //piggy back off EE_Error::set_content_type, which sets the content type to HTML
145
-            add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
146
-            //and send the message to the site admin too
147
-            wp_mail(get_option('admin_email'),
148
-                __('Notice of Removal of WP API Basic Auth From Event Espresso 4', 'event_espresso'), $message);
149
-            remove_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
150
-        }
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * Loads all the hooks which make requests to old versions of the API
157
-     * appear the same as they always did
158
-     */
159
-    protected static function _set_hooks_for_changes()
160
-    {
161
-        $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
162
-        foreach ($folder_contents as $classname_in_namespace => $filepath) {
163
-            //ignore the base parent class
164
-            if ($classname_in_namespace === 'Changes_In_Base') {
165
-                continue;
166
-            }
167
-            $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
168
-            if (class_exists($full_classname)) {
169
-                $instance_of_class = new $full_classname;
170
-                if ($instance_of_class instanceof Changes_In_Base) {
171
-                    $instance_of_class->set_hooks();
172
-                }
173
-            }
174
-        }
175
-    }
176
-
177
-
178
-
179
-    /**
180
-     * Filters the WP routes to add our EE-related ones. This takes a bit of time
181
-     * so we actually prefer to only do it when an EE plugin is activated or upgraded
182
-     */
183
-    public static function register_routes()
184
-    {
185
-        foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
186
-            foreach ($relative_urls as $endpoint => $routes) {
187
-                foreach ($routes as $route) {
188
-                    $route_args = array(
189
-                        array(
190
-                            'callback' => $route['callback'],
191
-                            'methods'  => $route['methods'],
192
-                            'args'     => isset($route['args']) ? $route['args'] : array(),
193
-                        )
194
-                    );
195
-                    if (isset($route['schema_callback'])) {
196
-                        $model_name = isset($route['schema_callback'][0])
197
-                            ? $route['schema_callback'][0]
198
-                            : '';
199
-                        $version = isset( $route['schema_callback'][1])
200
-                            ? $route['schema_callback'][1]
201
-                            : '';
202
-                        if (! empty($model_name) && ! empty($version)) {
203
-                            $route_args['schema'] = function () use ($model_name, $version) {
204
-                                return ModelRead::handle_schema_request(
205
-                                    $model_name,
206
-                                    $version
207
-                                );
208
-                            };
209
-                        }
210
-                    }
211
-                    register_rest_route(
212
-                        $namespace,
213
-                        $endpoint,
214
-                        $route_args
215
-                    );
216
-                }
217
-            }
218
-        }
219
-    }
220
-
221
-
222
-
223
-    /**
224
-     * Checks if there was a version change or something that merits invalidating the cached
225
-     * route data. If so, invalidates the cached route data so that it gets refreshed
226
-     * next time the WP API is used
227
-     */
228
-    public static function invalidate_cached_route_data_on_version_change()
229
-    {
230
-        if (EE_System::instance()->detect_req_type() != EE_System::req_type_normal) {
231
-            EED_Core_Rest_Api::invalidate_cached_route_data();
232
-        }
233
-        foreach (EE_Registry::instance()->addons as $addon) {
234
-            if ($addon instanceof EE_Addon && $addon->detect_req_type() != EE_System::req_type_normal) {
235
-                EED_Core_Rest_Api::invalidate_cached_route_data();
236
-            }
237
-        }
238
-    }
239
-
240
-
241
-
242
-    /**
243
-     * Removes the cached route data so it will get refreshed next time the WP API is used
244
-     */
245
-    public static function invalidate_cached_route_data()
246
-    {
247
-        //delete the saved EE REST API routes
248
-        foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
249
-            delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
250
-        }
251
-    }
252
-
253
-
254
-
255
-    /**
256
-     * Gets the EE route data
257
-     *
258
-     * @return array top-level key is the namespace, next-level key is the route and its value is array{
259
-     * @type string|array $callback
260
-     * @type string       $methods
261
-     * @type boolean      $hidden_endpoint
262
-     * }
263
-     */
264
-    public static function get_ee_route_data()
265
-    {
266
-        $ee_routes = array();
267
-        foreach (self::versions_served() as $version => $hidden_endpoints) {
268
-            $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version($version,
269
-                $hidden_endpoints);
270
-        }
271
-        return $ee_routes;
272
-    }
273
-
274
-
275
-
276
-    /**
277
-     * Gets the EE route data from the wp options if it exists already,
278
-     * otherwise re-generates it and saves it to the option
279
-     *
280
-     * @param string  $version
281
-     * @param boolean $hidden_endpoints
282
-     * @return array
283
-     */
284
-    protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
285
-    {
286
-        $ee_routes = get_option(self::saved_routes_option_names . $version, null);
287
-        if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
288
-            $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
289
-        }
290
-        return $ee_routes;
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     * Saves the EE REST API route data to a wp option and returns it
297
-     *
298
-     * @param string  $version
299
-     * @param boolean $hidden_endpoints
300
-     * @return mixed|null|void
301
-     */
302
-    protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false)
303
-    {
304
-        $instance = self::instance();
305
-        $routes = apply_filters(
306
-            'EED_Core_Rest_Api__save_ee_route_data_for_version__routes',
307
-            array_replace_recursive(
308
-                $instance->_get_config_route_data_for_version($version, $hidden_endpoints),
309
-                $instance->_get_meta_route_data_for_version($version, $hidden_endpoints),
310
-                $instance->_get_model_route_data_for_version($version, $hidden_endpoints),
311
-                $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
312
-            )
313
-        );
314
-        $option_name = self::saved_routes_option_names . $version;
315
-        if (get_option($option_name)) {
316
-            update_option($option_name, $routes, true);
317
-        } else {
318
-            add_option($option_name, $routes, null, 'no');
319
-        }
320
-        return $routes;
321
-    }
322
-
323
-
324
-
325
-    /**
326
-     * Calculates all the EE routes and saves it to a wordpress option so we don't
327
-     * need to calculate it on every request
328
-     *
329
-     * @deprecated since version 4.9.1
330
-     * @return void
331
-     */
332
-    public static function save_ee_routes()
333
-    {
334
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
335
-            $instance = self::instance();
336
-            $routes = apply_filters(
337
-                'EED_Core_Rest_Api__save_ee_routes__routes',
338
-                array_replace_recursive(
339
-                    $instance->_register_config_routes(),
340
-                    $instance->_register_meta_routes(),
341
-                    $instance->_register_model_routes(),
342
-                    $instance->_register_rpc_routes()
343
-                )
344
-            );
345
-            update_option(self::saved_routes_option_names, $routes, true);
346
-        }
347
-    }
348
-
349
-
350
-
351
-    /**
352
-     * Gets all the route information relating to EE models
353
-     *
354
-     * @return array @see get_ee_route_data
355
-     * @deprecated since version 4.9.1
356
-     */
357
-    protected function _register_model_routes()
358
-    {
359
-        $model_routes = array();
360
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
361
-            $model_routes[EED_Core_Rest_Api::ee_api_namespace
362
-                          . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
363
-        }
364
-        return $model_routes;
365
-    }
366
-
367
-
368
-
369
-    /**
370
-     * Gets the route data for EE models in the specified version
371
-     *
372
-     * @param string  $version
373
-     * @param boolean $hidden_endpoint
374
-     * @return array
375
-     */
376
-    protected function _get_model_route_data_for_version($version, $hidden_endpoint = false)
377
-    {
378
-        $model_version_info = new Model_Version_Info($version);
379
-        $models_to_register = apply_filters(
380
-            'FHEE__EED_Core_REST_API___register_model_routes',
381
-            $model_version_info->models_for_requested_version()
382
-        );
383
-        //let's not bother having endpoints for extra metas
384
-        unset($models_to_register['Extra_Meta']);
385
-        unset($models_to_register['Extra_Join']);
386
-        $model_routes = array();
387
-        foreach ($models_to_register as $model_name => $model_classname) {
388
-            $model = \EE_Registry::instance()->load_model($model_name);
389
-
390
-            //if this isn't a valid model then let's skip iterate to the next item in the loop.
391
-            if (! $model instanceof EEM_Base) {
392
-                continue;
393
-            }
394
-
395
-            //yes we could just register one route for ALL models, but then they wouldn't show up in the index
396
-            $plural_model_route = EEH_Inflector::pluralize_and_lower($model_name);
397
-            $singular_model_route = $plural_model_route . '/(?P<id>\d+)';
398
-            $model_routes[$plural_model_route] = array(
399
-                array(
400
-                    'callback'        => array(
401
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
402
-                        'handle_request_get_all',
403
-                    ),
404
-                    'methods'         => WP_REST_Server::READABLE,
405
-                    'hidden_endpoint' => $hidden_endpoint,
406
-                    'args'            => $this->_get_read_query_params($model, $version),
407
-                    '_links'          => array(
408
-                        'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
409
-                    ),
410
-                    'schema_callback' => array($model_name, $version)
411
-                ),
412
-                //						array(
413
-                //							'callback' => array(
414
-                //								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
415
-                //								'handle_request_create_one' ),
416
-                //							'methods' => WP_REST_Server::CREATABLE,
417
-                //							'hidden_endpoint' => $hidden_endpoint
418
-                //						)
419
-            );
420
-            $model_routes[$singular_model_route] = array(
421
-                array(
422
-                    'callback'        => array(
423
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Read',
424
-                        'handle_request_get_one',
425
-                    ),
426
-                    'methods'         => WP_REST_Server::READABLE,
427
-                    'hidden_endpoint' => $hidden_endpoint,
428
-                    'args'            => $this->_get_response_selection_query_params($model, $version),
429
-                ),
430
-                //						array(
431
-                //							'callback' => array(
432
-                //								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
433
-                //								'handle_request_edit_one' ),
434
-                //							'methods' => WP_REST_Server::EDITABLE,
435
-                //							'hidden_endpoint' => $hidden_endpoint
436
-                //							),
437
-            );
438
-            //@todo: also handle  DELETE for a single item
439
-            foreach ($model_version_info->relation_settings($model) as $relation_name => $relation_obj) {
440
-                $related_model_name_endpoint_part = ModelRead::get_related_entity_name(
441
-                    $relation_name,
442
-                    $relation_obj
443
-                );
444
-                $model_routes[$singular_model_route . '/' . $related_model_name_endpoint_part] = array(
445
-                    array(
446
-                        'callback'        => array(
447
-                            'EventEspresso\core\libraries\rest_api\controllers\model\Read',
448
-                            'handle_request_get_related',
449
-                        ),
450
-                        'methods'         => WP_REST_Server::READABLE,
451
-                        'hidden_endpoint' => $hidden_endpoint,
452
-                        'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
453
-                    ),
454
-                    //							array(
455
-                    //								'callback' => array(
456
-                    //									'EventEspresso\core\libraries\rest_api\controllers\model\Write',
457
-                    //									'handle_request_create_or_update_related' ),
458
-                    //								'methods' => WP_REST_Server::EDITABLE,
459
-                    //								'hidden_endpoint' => $hidden_endpoint
460
-                    //							)
461
-                );
462
-                //@todo: handle delete related and possibly remove relation (not sure hwo to distinguish)
463
-            }
464
-        }
465
-        return $model_routes;
466
-    }
467
-
468
-
469
-
470
-    /**
471
-     * Adds all the RPC-style routes (remote procedure call-like routes, ie
472
-     * routes that don't conform to the traditional REST CRUD-style).
473
-     *
474
-     * @deprecated since 4.9.1
475
-     */
476
-    protected function _register_rpc_routes()
477
-    {
478
-        $routes = array();
479
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
480
-            $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version($version,
481
-                $hidden_endpoint);
482
-        }
483
-        return $routes;
484
-    }
485
-
486
-
487
-
488
-    /**
489
-     * @param string  $version
490
-     * @param boolean $hidden_endpoint
491
-     * @return array
492
-     */
493
-    protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false)
494
-    {
495
-        $this_versions_routes = array();
496
-        //checkin endpoint
497
-        $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array(
498
-            array(
499
-                'callback'        => array(
500
-                    'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin',
501
-                    'handle_request_toggle_checkin',
502
-                ),
503
-                'methods'         => WP_REST_Server::CREATABLE,
504
-                'hidden_endpoint' => $hidden_endpoint,
505
-                'args'            => array(
506
-                    'force' => array(
507
-                        'required'    => false,
508
-                        'default'     => false,
509
-                        'description' => __('Whether to force toggle checkin, or to verify the registration status and allowed ticket uses',
510
-                            'event_espresso'),
511
-                    ),
512
-                ),
513
-            ),
514
-        );
515
-        return apply_filters(
516
-            'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
517
-            $this_versions_routes,
518
-            $version,
519
-            $hidden_endpoint
520
-        );
521
-    }
522
-
523
-
524
-
525
-    /**
526
-     * Gets the query params that can be used when request one or many
527
-     *
528
-     * @param EEM_Base $model
529
-     * @param string   $version
530
-     * @return array
531
-     */
532
-    protected function _get_response_selection_query_params(\EEM_Base $model, $version)
533
-    {
534
-        return apply_filters(
535
-            'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
536
-            array(
537
-                'include'   => array(
538
-                    'required' => false,
539
-                    'default'  => '*',
540
-                ),
541
-                'calculate' => array(
542
-                    'required' => false,
543
-                    'default'  => '',
544
-                    'enum'     => self::$_field_calculator->retrieve_calculated_fields_for_model($model),
545
-                ),
546
-            ),
547
-            $model,
548
-            $version
549
-        );
550
-    }
551
-
552
-
553
-
554
-    /**
555
-     * Gets info about reading query params that are acceptable
556
-     *
557
-     * @param \EEM_Base $model eg 'Event' or 'Venue'
558
-     * @param  string   $version
559
-     * @return array    describing the args acceptable when querying this model
560
-     * @throws \EE_Error
561
-     */
562
-    protected function _get_read_query_params(\EEM_Base $model, $version)
563
-    {
564
-        $default_orderby = array();
565
-        foreach ($model->get_combined_primary_key_fields() as $key_field) {
566
-            $default_orderby[$key_field->get_name()] = 'ASC';
567
-        }
568
-        return array_merge(
569
-            $this->_get_response_selection_query_params($model, $version),
570
-            array(
571
-                'where'    => array(
572
-                    'required' => false,
573
-                    'default'  => array(),
574
-                ),
575
-                'limit'    => array(
576
-                    'required' => false,
577
-                    'default'  => EED_Core_Rest_Api::get_default_query_limit(),
578
-                ),
579
-                'order_by' => array(
580
-                    'required' => false,
581
-                    'default'  => $default_orderby,
582
-                ),
583
-                'group_by' => array(
584
-                    'required' => false,
585
-                    'default'  => null,
586
-                ),
587
-                'having'   => array(
588
-                    'required' => false,
589
-                    'default'  => null,
590
-                ),
591
-                'caps'     => array(
592
-                    'required' => false,
593
-                    'default'  => EEM_Base::caps_read,
594
-                ),
595
-            )
596
-        );
597
-    }
598
-
599
-
600
-
601
-    /**
602
-     * Gets routes for the config
603
-     *
604
-     * @return array @see _register_model_routes
605
-     * @deprecated since version 4.9.1
606
-     */
607
-    protected function _register_config_routes()
608
-    {
609
-        $config_routes = array();
610
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
611
-            $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version($version,
612
-                $hidden_endpoint);
613
-        }
614
-        return $config_routes;
615
-    }
616
-
617
-
618
-
619
-    /**
620
-     * Gets routes for the config for the specified version
621
-     *
622
-     * @param string  $version
623
-     * @param boolean $hidden_endpoint
624
-     * @return array
625
-     */
626
-    protected function _get_config_route_data_for_version($version, $hidden_endpoint)
627
-    {
628
-        return array(
629
-            'config'    => array(
630
-                array(
631
-                    'callback'        => array(
632
-                        'EventEspresso\core\libraries\rest_api\controllers\config\Read',
633
-                        'handle_request',
634
-                    ),
635
-                    'methods'         => WP_REST_Server::READABLE,
636
-                    'hidden_endpoint' => $hidden_endpoint,
637
-                ),
638
-            ),
639
-            'site_info' => array(
640
-                array(
641
-                    'callback'        => array(
642
-                        'EventEspresso\core\libraries\rest_api\controllers\config\Read',
643
-                        'handle_request_site_info',
644
-                    ),
645
-                    'methods'         => WP_REST_Server::READABLE,
646
-                    'hidden_endpoint' => $hidden_endpoint,
647
-                ),
648
-            ),
649
-        );
650
-    }
651
-
652
-
653
-
654
-    /**
655
-     * Gets the meta info routes
656
-     *
657
-     * @return array @see _register_model_routes
658
-     * @deprecated since version 4.9.1
659
-     */
660
-    protected function _register_meta_routes()
661
-    {
662
-        $meta_routes = array();
663
-        foreach (self::versions_served() as $version => $hidden_endpoint) {
664
-            $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version($version,
665
-                $hidden_endpoint);
666
-        }
667
-        return $meta_routes;
668
-    }
669
-
670
-
671
-
672
-    /**
673
-     * @param string  $version
674
-     * @param boolean $hidden_endpoint
675
-     * @return array
676
-     */
677
-    protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false)
678
-    {
679
-        return array(
680
-            'resources' => array(
681
-                array(
682
-                    'callback'        => array(
683
-                        'EventEspresso\core\libraries\rest_api\controllers\model\Meta',
684
-                        'handle_request_models_meta',
685
-                    ),
686
-                    'methods'         => WP_REST_Server::READABLE,
687
-                    'hidden_endpoint' => $hidden_endpoint,
688
-                ),
689
-            ),
690
-        );
691
-    }
692
-
693
-
694
-
695
-    /**
696
-     * Tries to hide old 4.6 endpoints from the
697
-     *
698
-     * @param array $route_data
699
-     * @return array
700
-     */
701
-    public static function hide_old_endpoints($route_data)
702
-    {
703
-        //allow API clients to override which endpoints get hidden, in case
704
-        //they want to discover particular endpoints
705
-        //also, we don't have access to the request so we have to just grab it from the superglobal
706
-        $force_show_ee_namespace = ltrim(
707
-            EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''),
708
-            '/'
709
-        );
710
-        foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
711
-            foreach ($relative_urls as $endpoint => $routes) {
712
-                foreach ($routes as $route) {
713
-                    //by default, hide "hidden_endpoint"s, unless the request indicates
714
-                    //to $force_show_ee_namespace, in which case only show that one
715
-                    //namespace's endpoints (and hide all others)
716
-                    if (($route['hidden_endpoint'] && $force_show_ee_namespace === '')
717
-                        || ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
718
-                    ) {
719
-                        $full_route = '/' . ltrim($namespace, '/') . '/' . ltrim($endpoint, '/');
720
-                        unset($route_data[$full_route]);
721
-                    }
722
-                }
723
-            }
724
-        }
725
-        return $route_data;
726
-    }
727
-
728
-
729
-
730
-    /**
731
-     * Returns an array describing which versions of core support serving requests for.
732
-     * Keys are core versions' major and minor version, and values are the
733
-     * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like
734
-     * data by just removing a few models and fields from the responses. However, 4.15 might remove
735
-     * the answers table entirely, in which case it would be very difficult for
736
-     * it to serve 4.6-style responses.
737
-     * Versions of core that are missing from this array are unknowns.
738
-     * previous ver
739
-     *
740
-     * @return array
741
-     */
742
-    public static function version_compatibilities()
743
-    {
744
-        return apply_filters(
745
-            'FHEE__EED_Core_REST_API__version_compatibilities',
746
-            array(
747
-                '4.8.29' => '4.8.29',
748
-                '4.8.33' => '4.8.29',
749
-                '4.8.34' => '4.8.29',
750
-                '4.8.36' => '4.8.29',
751
-            )
752
-        );
753
-    }
754
-
755
-
756
-
757
-    /**
758
-     * Gets the latest API version served. Eg if there
759
-     * are two versions served of the API, 4.8.29 and 4.8.32, and
760
-     * we are on core version 4.8.34, it will return the string "4.8.32"
761
-     *
762
-     * @return string
763
-     */
764
-    public static function latest_rest_api_version()
765
-    {
766
-        $versions_served = \EED_Core_Rest_Api::versions_served();
767
-        $versions_served_keys = array_keys($versions_served);
768
-        return end($versions_served_keys);
769
-    }
770
-
771
-
772
-
773
-    /**
774
-     * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of
775
-     * EE the API can serve requests for. Eg, if we are on 4.15 of core, and
776
-     * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ).
777
-     * We also indicate whether or not this version should be put in the index or not
778
-     *
779
-     * @return array keys are API version numbers (just major and minor numbers), and values
780
-     * are whether or not they should be hidden
781
-     */
782
-    public static function versions_served()
783
-    {
784
-        $versions_served = array();
785
-        $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities();
786
-        $lowest_compatible_version = end($possibly_served_versions);
787
-        reset($possibly_served_versions);
788
-        $versions_served_historically = array_keys($possibly_served_versions);
789
-        $latest_version = end($versions_served_historically);
790
-        reset($versions_served_historically);
791
-        //for each version of core we have ever served:
792
-        foreach ($versions_served_historically as $key_versioned_endpoint) {
793
-            //if it's not above the current core version, and it's compatible with the current version of core
794
-            if ($key_versioned_endpoint == $latest_version) {
795
-                //don't hide the latest version in the index
796
-                $versions_served[$key_versioned_endpoint] = false;
797
-            } else if (
798
-                $key_versioned_endpoint < EED_Core_Rest_Api::core_version()
799
-                && $key_versioned_endpoint >= $lowest_compatible_version
800
-            ) {
801
-                //include, but hide, previous versions which are still supported
802
-                $versions_served[$key_versioned_endpoint] = true;
803
-            } elseif (
804
-            apply_filters(
805
-                'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
806
-                false,
807
-                $possibly_served_versions
808
-            )
809
-            ) {
810
-                //if a version is no longer supported, don't include it in index or list of versions served
811
-                $versions_served[$key_versioned_endpoint] = true;
812
-            }
813
-        }
814
-        return $versions_served;
815
-    }
816
-
817
-
818
-
819
-    /**
820
-     * Gets the major and minor version of EE core's version string
821
-     *
822
-     * @return string
823
-     */
824
-    public static function core_version()
825
-    {
826
-        return apply_filters('FHEE__EED_Core_REST_API__core_version',
827
-            implode('.', array_slice(explode('.', espresso_version()), 0, 3)));
828
-    }
829
-
830
-
831
-
832
-    /**
833
-     * Gets the default limit that should be used when querying for resources
834
-     *
835
-     * @return int
836
-     */
837
-    public static function get_default_query_limit()
838
-    {
839
-        //we actually don't use a const because we want folks to always use
840
-        //this method, not the const directly
841
-        return apply_filters(
842
-            'FHEE__EED_Core_Rest_Api__get_default_query_limit',
843
-            50
844
-        );
845
-    }
846
-
847
-
848
-
849
-    /**
850
-     *    run - initial module setup
851
-     *
852
-     * @access    public
853
-     * @param  WP $WP
854
-     * @return    void
855
-     */
856
-    public function run($WP)
857
-    {
858
-    }
23
+	const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/';
24
+
25
+	const saved_routes_option_names  = 'ee_core_routes';
26
+
27
+	/**
28
+	 * string used in _links response bodies to make them globally unique.
29
+	 *
30
+	 * @see http://v2.wp-api.org/extending/linking/
31
+	 */
32
+	const ee_api_link_namespace = 'https://api.eventespresso.com/';
33
+
34
+	/**
35
+	 * @var Calculated_Model_Fields
36
+	 */
37
+	protected static $_field_calculator = null;
38
+
39
+
40
+
41
+	/**
42
+	 * @return EED_Core_Rest_Api
43
+	 */
44
+	public static function instance()
45
+	{
46
+		self::$_field_calculator = new Calculated_Model_Fields();
47
+		return parent::get_instance(__CLASS__);
48
+	}
49
+
50
+
51
+
52
+	/**
53
+	 *    set_hooks - for hooking into EE Core, other modules, etc
54
+	 *
55
+	 * @access    public
56
+	 * @return    void
57
+	 */
58
+	public static function set_hooks()
59
+	{
60
+		self::set_hooks_both();
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
67
+	 *
68
+	 * @access    public
69
+	 * @return    void
70
+	 */
71
+	public static function set_hooks_admin()
72
+	{
73
+		self::set_hooks_both();
74
+	}
75
+
76
+
77
+
78
+	public static function set_hooks_both()
79
+	{
80
+		add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10);
81
+		add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5);
82
+		add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2);
83
+		add_filter('rest_index',
84
+			array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filter_ee_metadata_into_index'));
85
+		EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change();
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 * sets up hooks which only need to be included as part of REST API requests;
92
+	 * other requests like to the frontend or admin etc don't need them
93
+	 */
94
+	public static function set_hooks_rest_api()
95
+	{
96
+		//set hooks which account for changes made to the API
97
+		EED_Core_Rest_Api::_set_hooks_for_changes();
98
+		EED_Core_Rest_Api::maybe_notify_of_basic_auth_removal();
99
+	}
100
+
101
+
102
+
103
+	/**
104
+	 * public wrapper of _set_hooks_for_changes.
105
+	 * Loads all the hooks which make requests to old versions of the API
106
+	 * appear the same as they always did
107
+	 */
108
+	public static function set_hooks_for_changes()
109
+	{
110
+		self::_set_hooks_for_changes();
111
+	}
112
+
113
+
114
+
115
+	/**
116
+	 * If the user appears to be using WP API basic auth, tell them (via a persistent
117
+	 * admin notice and an email) that we're going to remove it soon, so they should
118
+	 * replace it with application passwords.
119
+	 */
120
+	public static function maybe_notify_of_basic_auth_removal()
121
+	{
122
+		if (
123
+		apply_filters(
124
+			'FHEE__EED_Core_Rest_Api__maybe_notify_of_basic_auth_removal__override',
125
+			! isset($_SERVER['PHP_AUTH_USER'])
126
+			&& ! isset($_SERVER['HTTP_AUTHORIZATION'])
127
+		)
128
+		) {
129
+			//sure it's a WP API request, but they aren't using basic auth, so don't bother them
130
+			return;
131
+		}
132
+		//ok they're using the WP API with Basic Auth
133
+		$message = sprintf(
134
+			__('We noticed you\'re using the WP API, which is used by the Event Espresso 4 mobile apps. Because of security and compatibility concerns, we will soon be removing our default authentication mechanism, WP API Basic Auth, from Event Espresso. It is recommended you instead install the %1$sWP Application Passwords plugin%2$s and use it with the EE4 Mobile apps. See %3$sour mobile app documentation%2$s for more information. %4$sIf you have installed the WP API Basic Auth plugin separately, or are not using the Event Espresso 4 mobile apps, you can disregard this message.%4$sThe Event Espresso Team',
135
+				'event_espresso'),
136
+			'<a href="https://wordpress.org/plugins/application-passwords/">',
137
+			'</a>',
138
+			'<a href="https://eventespresso.com/wiki/ee4-event-apps/#authentication">',
139
+			'<br/>'
140
+		);
141
+		EE_Error::add_persistent_admin_notice('using_basic_auth', $message);
142
+		if ( ! get_option('ee_notified_admin_on_basic_auth_removal', false)) {
143
+			add_option('ee_notified_admin_on_basic_auth_removal', true);
144
+			//piggy back off EE_Error::set_content_type, which sets the content type to HTML
145
+			add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
146
+			//and send the message to the site admin too
147
+			wp_mail(get_option('admin_email'),
148
+				__('Notice of Removal of WP API Basic Auth From Event Espresso 4', 'event_espresso'), $message);
149
+			remove_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
150
+		}
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * Loads all the hooks which make requests to old versions of the API
157
+	 * appear the same as they always did
158
+	 */
159
+	protected static function _set_hooks_for_changes()
160
+	{
161
+		$folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false);
162
+		foreach ($folder_contents as $classname_in_namespace => $filepath) {
163
+			//ignore the base parent class
164
+			if ($classname_in_namespace === 'Changes_In_Base') {
165
+				continue;
166
+			}
167
+			$full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace;
168
+			if (class_exists($full_classname)) {
169
+				$instance_of_class = new $full_classname;
170
+				if ($instance_of_class instanceof Changes_In_Base) {
171
+					$instance_of_class->set_hooks();
172
+				}
173
+			}
174
+		}
175
+	}
176
+
177
+
178
+
179
+	/**
180
+	 * Filters the WP routes to add our EE-related ones. This takes a bit of time
181
+	 * so we actually prefer to only do it when an EE plugin is activated or upgraded
182
+	 */
183
+	public static function register_routes()
184
+	{
185
+		foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
186
+			foreach ($relative_urls as $endpoint => $routes) {
187
+				foreach ($routes as $route) {
188
+					$route_args = array(
189
+						array(
190
+							'callback' => $route['callback'],
191
+							'methods'  => $route['methods'],
192
+							'args'     => isset($route['args']) ? $route['args'] : array(),
193
+						)
194
+					);
195
+					if (isset($route['schema_callback'])) {
196
+						$model_name = isset($route['schema_callback'][0])
197
+							? $route['schema_callback'][0]
198
+							: '';
199
+						$version = isset( $route['schema_callback'][1])
200
+							? $route['schema_callback'][1]
201
+							: '';
202
+						if (! empty($model_name) && ! empty($version)) {
203
+							$route_args['schema'] = function () use ($model_name, $version) {
204
+								return ModelRead::handle_schema_request(
205
+									$model_name,
206
+									$version
207
+								);
208
+							};
209
+						}
210
+					}
211
+					register_rest_route(
212
+						$namespace,
213
+						$endpoint,
214
+						$route_args
215
+					);
216
+				}
217
+			}
218
+		}
219
+	}
220
+
221
+
222
+
223
+	/**
224
+	 * Checks if there was a version change or something that merits invalidating the cached
225
+	 * route data. If so, invalidates the cached route data so that it gets refreshed
226
+	 * next time the WP API is used
227
+	 */
228
+	public static function invalidate_cached_route_data_on_version_change()
229
+	{
230
+		if (EE_System::instance()->detect_req_type() != EE_System::req_type_normal) {
231
+			EED_Core_Rest_Api::invalidate_cached_route_data();
232
+		}
233
+		foreach (EE_Registry::instance()->addons as $addon) {
234
+			if ($addon instanceof EE_Addon && $addon->detect_req_type() != EE_System::req_type_normal) {
235
+				EED_Core_Rest_Api::invalidate_cached_route_data();
236
+			}
237
+		}
238
+	}
239
+
240
+
241
+
242
+	/**
243
+	 * Removes the cached route data so it will get refreshed next time the WP API is used
244
+	 */
245
+	public static function invalidate_cached_route_data()
246
+	{
247
+		//delete the saved EE REST API routes
248
+		foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) {
249
+			delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version);
250
+		}
251
+	}
252
+
253
+
254
+
255
+	/**
256
+	 * Gets the EE route data
257
+	 *
258
+	 * @return array top-level key is the namespace, next-level key is the route and its value is array{
259
+	 * @type string|array $callback
260
+	 * @type string       $methods
261
+	 * @type boolean      $hidden_endpoint
262
+	 * }
263
+	 */
264
+	public static function get_ee_route_data()
265
+	{
266
+		$ee_routes = array();
267
+		foreach (self::versions_served() as $version => $hidden_endpoints) {
268
+			$ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version($version,
269
+				$hidden_endpoints);
270
+		}
271
+		return $ee_routes;
272
+	}
273
+
274
+
275
+
276
+	/**
277
+	 * Gets the EE route data from the wp options if it exists already,
278
+	 * otherwise re-generates it and saves it to the option
279
+	 *
280
+	 * @param string  $version
281
+	 * @param boolean $hidden_endpoints
282
+	 * @return array
283
+	 */
284
+	protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false)
285
+	{
286
+		$ee_routes = get_option(self::saved_routes_option_names . $version, null);
287
+		if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) {
288
+			$ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints);
289
+		}
290
+		return $ee_routes;
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 * Saves the EE REST API route data to a wp option and returns it
297
+	 *
298
+	 * @param string  $version
299
+	 * @param boolean $hidden_endpoints
300
+	 * @return mixed|null|void
301
+	 */
302
+	protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false)
303
+	{
304
+		$instance = self::instance();
305
+		$routes = apply_filters(
306
+			'EED_Core_Rest_Api__save_ee_route_data_for_version__routes',
307
+			array_replace_recursive(
308
+				$instance->_get_config_route_data_for_version($version, $hidden_endpoints),
309
+				$instance->_get_meta_route_data_for_version($version, $hidden_endpoints),
310
+				$instance->_get_model_route_data_for_version($version, $hidden_endpoints),
311
+				$instance->_get_rpc_route_data_for_version($version, $hidden_endpoints)
312
+			)
313
+		);
314
+		$option_name = self::saved_routes_option_names . $version;
315
+		if (get_option($option_name)) {
316
+			update_option($option_name, $routes, true);
317
+		} else {
318
+			add_option($option_name, $routes, null, 'no');
319
+		}
320
+		return $routes;
321
+	}
322
+
323
+
324
+
325
+	/**
326
+	 * Calculates all the EE routes and saves it to a wordpress option so we don't
327
+	 * need to calculate it on every request
328
+	 *
329
+	 * @deprecated since version 4.9.1
330
+	 * @return void
331
+	 */
332
+	public static function save_ee_routes()
333
+	{
334
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
335
+			$instance = self::instance();
336
+			$routes = apply_filters(
337
+				'EED_Core_Rest_Api__save_ee_routes__routes',
338
+				array_replace_recursive(
339
+					$instance->_register_config_routes(),
340
+					$instance->_register_meta_routes(),
341
+					$instance->_register_model_routes(),
342
+					$instance->_register_rpc_routes()
343
+				)
344
+			);
345
+			update_option(self::saved_routes_option_names, $routes, true);
346
+		}
347
+	}
348
+
349
+
350
+
351
+	/**
352
+	 * Gets all the route information relating to EE models
353
+	 *
354
+	 * @return array @see get_ee_route_data
355
+	 * @deprecated since version 4.9.1
356
+	 */
357
+	protected function _register_model_routes()
358
+	{
359
+		$model_routes = array();
360
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
361
+			$model_routes[EED_Core_Rest_Api::ee_api_namespace
362
+						  . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint);
363
+		}
364
+		return $model_routes;
365
+	}
366
+
367
+
368
+
369
+	/**
370
+	 * Gets the route data for EE models in the specified version
371
+	 *
372
+	 * @param string  $version
373
+	 * @param boolean $hidden_endpoint
374
+	 * @return array
375
+	 */
376
+	protected function _get_model_route_data_for_version($version, $hidden_endpoint = false)
377
+	{
378
+		$model_version_info = new Model_Version_Info($version);
379
+		$models_to_register = apply_filters(
380
+			'FHEE__EED_Core_REST_API___register_model_routes',
381
+			$model_version_info->models_for_requested_version()
382
+		);
383
+		//let's not bother having endpoints for extra metas
384
+		unset($models_to_register['Extra_Meta']);
385
+		unset($models_to_register['Extra_Join']);
386
+		$model_routes = array();
387
+		foreach ($models_to_register as $model_name => $model_classname) {
388
+			$model = \EE_Registry::instance()->load_model($model_name);
389
+
390
+			//if this isn't a valid model then let's skip iterate to the next item in the loop.
391
+			if (! $model instanceof EEM_Base) {
392
+				continue;
393
+			}
394
+
395
+			//yes we could just register one route for ALL models, but then they wouldn't show up in the index
396
+			$plural_model_route = EEH_Inflector::pluralize_and_lower($model_name);
397
+			$singular_model_route = $plural_model_route . '/(?P<id>\d+)';
398
+			$model_routes[$plural_model_route] = array(
399
+				array(
400
+					'callback'        => array(
401
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
402
+						'handle_request_get_all',
403
+					),
404
+					'methods'         => WP_REST_Server::READABLE,
405
+					'hidden_endpoint' => $hidden_endpoint,
406
+					'args'            => $this->_get_read_query_params($model, $version),
407
+					'_links'          => array(
408
+						'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route),
409
+					),
410
+					'schema_callback' => array($model_name, $version)
411
+				),
412
+				//						array(
413
+				//							'callback' => array(
414
+				//								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
415
+				//								'handle_request_create_one' ),
416
+				//							'methods' => WP_REST_Server::CREATABLE,
417
+				//							'hidden_endpoint' => $hidden_endpoint
418
+				//						)
419
+			);
420
+			$model_routes[$singular_model_route] = array(
421
+				array(
422
+					'callback'        => array(
423
+						'EventEspresso\core\libraries\rest_api\controllers\model\Read',
424
+						'handle_request_get_one',
425
+					),
426
+					'methods'         => WP_REST_Server::READABLE,
427
+					'hidden_endpoint' => $hidden_endpoint,
428
+					'args'            => $this->_get_response_selection_query_params($model, $version),
429
+				),
430
+				//						array(
431
+				//							'callback' => array(
432
+				//								'EventEspresso\core\libraries\rest_api\controllers\model\Write',
433
+				//								'handle_request_edit_one' ),
434
+				//							'methods' => WP_REST_Server::EDITABLE,
435
+				//							'hidden_endpoint' => $hidden_endpoint
436
+				//							),
437
+			);
438
+			//@todo: also handle  DELETE for a single item
439
+			foreach ($model_version_info->relation_settings($model) as $relation_name => $relation_obj) {
440
+				$related_model_name_endpoint_part = ModelRead::get_related_entity_name(
441
+					$relation_name,
442
+					$relation_obj
443
+				);
444
+				$model_routes[$singular_model_route . '/' . $related_model_name_endpoint_part] = array(
445
+					array(
446
+						'callback'        => array(
447
+							'EventEspresso\core\libraries\rest_api\controllers\model\Read',
448
+							'handle_request_get_related',
449
+						),
450
+						'methods'         => WP_REST_Server::READABLE,
451
+						'hidden_endpoint' => $hidden_endpoint,
452
+						'args'            => $this->_get_read_query_params($relation_obj->get_other_model(), $version),
453
+					),
454
+					//							array(
455
+					//								'callback' => array(
456
+					//									'EventEspresso\core\libraries\rest_api\controllers\model\Write',
457
+					//									'handle_request_create_or_update_related' ),
458
+					//								'methods' => WP_REST_Server::EDITABLE,
459
+					//								'hidden_endpoint' => $hidden_endpoint
460
+					//							)
461
+				);
462
+				//@todo: handle delete related and possibly remove relation (not sure hwo to distinguish)
463
+			}
464
+		}
465
+		return $model_routes;
466
+	}
467
+
468
+
469
+
470
+	/**
471
+	 * Adds all the RPC-style routes (remote procedure call-like routes, ie
472
+	 * routes that don't conform to the traditional REST CRUD-style).
473
+	 *
474
+	 * @deprecated since 4.9.1
475
+	 */
476
+	protected function _register_rpc_routes()
477
+	{
478
+		$routes = array();
479
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
480
+			$routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version($version,
481
+				$hidden_endpoint);
482
+		}
483
+		return $routes;
484
+	}
485
+
486
+
487
+
488
+	/**
489
+	 * @param string  $version
490
+	 * @param boolean $hidden_endpoint
491
+	 * @return array
492
+	 */
493
+	protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false)
494
+	{
495
+		$this_versions_routes = array();
496
+		//checkin endpoint
497
+		$this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array(
498
+			array(
499
+				'callback'        => array(
500
+					'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin',
501
+					'handle_request_toggle_checkin',
502
+				),
503
+				'methods'         => WP_REST_Server::CREATABLE,
504
+				'hidden_endpoint' => $hidden_endpoint,
505
+				'args'            => array(
506
+					'force' => array(
507
+						'required'    => false,
508
+						'default'     => false,
509
+						'description' => __('Whether to force toggle checkin, or to verify the registration status and allowed ticket uses',
510
+							'event_espresso'),
511
+					),
512
+				),
513
+			),
514
+		);
515
+		return apply_filters(
516
+			'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes',
517
+			$this_versions_routes,
518
+			$version,
519
+			$hidden_endpoint
520
+		);
521
+	}
522
+
523
+
524
+
525
+	/**
526
+	 * Gets the query params that can be used when request one or many
527
+	 *
528
+	 * @param EEM_Base $model
529
+	 * @param string   $version
530
+	 * @return array
531
+	 */
532
+	protected function _get_response_selection_query_params(\EEM_Base $model, $version)
533
+	{
534
+		return apply_filters(
535
+			'FHEE__EED_Core_Rest_Api___get_response_selection_query_params',
536
+			array(
537
+				'include'   => array(
538
+					'required' => false,
539
+					'default'  => '*',
540
+				),
541
+				'calculate' => array(
542
+					'required' => false,
543
+					'default'  => '',
544
+					'enum'     => self::$_field_calculator->retrieve_calculated_fields_for_model($model),
545
+				),
546
+			),
547
+			$model,
548
+			$version
549
+		);
550
+	}
551
+
552
+
553
+
554
+	/**
555
+	 * Gets info about reading query params that are acceptable
556
+	 *
557
+	 * @param \EEM_Base $model eg 'Event' or 'Venue'
558
+	 * @param  string   $version
559
+	 * @return array    describing the args acceptable when querying this model
560
+	 * @throws \EE_Error
561
+	 */
562
+	protected function _get_read_query_params(\EEM_Base $model, $version)
563
+	{
564
+		$default_orderby = array();
565
+		foreach ($model->get_combined_primary_key_fields() as $key_field) {
566
+			$default_orderby[$key_field->get_name()] = 'ASC';
567
+		}
568
+		return array_merge(
569
+			$this->_get_response_selection_query_params($model, $version),
570
+			array(
571
+				'where'    => array(
572
+					'required' => false,
573
+					'default'  => array(),
574
+				),
575
+				'limit'    => array(
576
+					'required' => false,
577
+					'default'  => EED_Core_Rest_Api::get_default_query_limit(),
578
+				),
579
+				'order_by' => array(
580
+					'required' => false,
581
+					'default'  => $default_orderby,
582
+				),
583
+				'group_by' => array(
584
+					'required' => false,
585
+					'default'  => null,
586
+				),
587
+				'having'   => array(
588
+					'required' => false,
589
+					'default'  => null,
590
+				),
591
+				'caps'     => array(
592
+					'required' => false,
593
+					'default'  => EEM_Base::caps_read,
594
+				),
595
+			)
596
+		);
597
+	}
598
+
599
+
600
+
601
+	/**
602
+	 * Gets routes for the config
603
+	 *
604
+	 * @return array @see _register_model_routes
605
+	 * @deprecated since version 4.9.1
606
+	 */
607
+	protected function _register_config_routes()
608
+	{
609
+		$config_routes = array();
610
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
611
+			$config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version($version,
612
+				$hidden_endpoint);
613
+		}
614
+		return $config_routes;
615
+	}
616
+
617
+
618
+
619
+	/**
620
+	 * Gets routes for the config for the specified version
621
+	 *
622
+	 * @param string  $version
623
+	 * @param boolean $hidden_endpoint
624
+	 * @return array
625
+	 */
626
+	protected function _get_config_route_data_for_version($version, $hidden_endpoint)
627
+	{
628
+		return array(
629
+			'config'    => array(
630
+				array(
631
+					'callback'        => array(
632
+						'EventEspresso\core\libraries\rest_api\controllers\config\Read',
633
+						'handle_request',
634
+					),
635
+					'methods'         => WP_REST_Server::READABLE,
636
+					'hidden_endpoint' => $hidden_endpoint,
637
+				),
638
+			),
639
+			'site_info' => array(
640
+				array(
641
+					'callback'        => array(
642
+						'EventEspresso\core\libraries\rest_api\controllers\config\Read',
643
+						'handle_request_site_info',
644
+					),
645
+					'methods'         => WP_REST_Server::READABLE,
646
+					'hidden_endpoint' => $hidden_endpoint,
647
+				),
648
+			),
649
+		);
650
+	}
651
+
652
+
653
+
654
+	/**
655
+	 * Gets the meta info routes
656
+	 *
657
+	 * @return array @see _register_model_routes
658
+	 * @deprecated since version 4.9.1
659
+	 */
660
+	protected function _register_meta_routes()
661
+	{
662
+		$meta_routes = array();
663
+		foreach (self::versions_served() as $version => $hidden_endpoint) {
664
+			$meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version($version,
665
+				$hidden_endpoint);
666
+		}
667
+		return $meta_routes;
668
+	}
669
+
670
+
671
+
672
+	/**
673
+	 * @param string  $version
674
+	 * @param boolean $hidden_endpoint
675
+	 * @return array
676
+	 */
677
+	protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false)
678
+	{
679
+		return array(
680
+			'resources' => array(
681
+				array(
682
+					'callback'        => array(
683
+						'EventEspresso\core\libraries\rest_api\controllers\model\Meta',
684
+						'handle_request_models_meta',
685
+					),
686
+					'methods'         => WP_REST_Server::READABLE,
687
+					'hidden_endpoint' => $hidden_endpoint,
688
+				),
689
+			),
690
+		);
691
+	}
692
+
693
+
694
+
695
+	/**
696
+	 * Tries to hide old 4.6 endpoints from the
697
+	 *
698
+	 * @param array $route_data
699
+	 * @return array
700
+	 */
701
+	public static function hide_old_endpoints($route_data)
702
+	{
703
+		//allow API clients to override which endpoints get hidden, in case
704
+		//they want to discover particular endpoints
705
+		//also, we don't have access to the request so we have to just grab it from the superglobal
706
+		$force_show_ee_namespace = ltrim(
707
+			EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''),
708
+			'/'
709
+		);
710
+		foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) {
711
+			foreach ($relative_urls as $endpoint => $routes) {
712
+				foreach ($routes as $route) {
713
+					//by default, hide "hidden_endpoint"s, unless the request indicates
714
+					//to $force_show_ee_namespace, in which case only show that one
715
+					//namespace's endpoints (and hide all others)
716
+					if (($route['hidden_endpoint'] && $force_show_ee_namespace === '')
717
+						|| ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace)
718
+					) {
719
+						$full_route = '/' . ltrim($namespace, '/') . '/' . ltrim($endpoint, '/');
720
+						unset($route_data[$full_route]);
721
+					}
722
+				}
723
+			}
724
+		}
725
+		return $route_data;
726
+	}
727
+
728
+
729
+
730
+	/**
731
+	 * Returns an array describing which versions of core support serving requests for.
732
+	 * Keys are core versions' major and minor version, and values are the
733
+	 * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like
734
+	 * data by just removing a few models and fields from the responses. However, 4.15 might remove
735
+	 * the answers table entirely, in which case it would be very difficult for
736
+	 * it to serve 4.6-style responses.
737
+	 * Versions of core that are missing from this array are unknowns.
738
+	 * previous ver
739
+	 *
740
+	 * @return array
741
+	 */
742
+	public static function version_compatibilities()
743
+	{
744
+		return apply_filters(
745
+			'FHEE__EED_Core_REST_API__version_compatibilities',
746
+			array(
747
+				'4.8.29' => '4.8.29',
748
+				'4.8.33' => '4.8.29',
749
+				'4.8.34' => '4.8.29',
750
+				'4.8.36' => '4.8.29',
751
+			)
752
+		);
753
+	}
754
+
755
+
756
+
757
+	/**
758
+	 * Gets the latest API version served. Eg if there
759
+	 * are two versions served of the API, 4.8.29 and 4.8.32, and
760
+	 * we are on core version 4.8.34, it will return the string "4.8.32"
761
+	 *
762
+	 * @return string
763
+	 */
764
+	public static function latest_rest_api_version()
765
+	{
766
+		$versions_served = \EED_Core_Rest_Api::versions_served();
767
+		$versions_served_keys = array_keys($versions_served);
768
+		return end($versions_served_keys);
769
+	}
770
+
771
+
772
+
773
+	/**
774
+	 * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of
775
+	 * EE the API can serve requests for. Eg, if we are on 4.15 of core, and
776
+	 * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ).
777
+	 * We also indicate whether or not this version should be put in the index or not
778
+	 *
779
+	 * @return array keys are API version numbers (just major and minor numbers), and values
780
+	 * are whether or not they should be hidden
781
+	 */
782
+	public static function versions_served()
783
+	{
784
+		$versions_served = array();
785
+		$possibly_served_versions = EED_Core_Rest_Api::version_compatibilities();
786
+		$lowest_compatible_version = end($possibly_served_versions);
787
+		reset($possibly_served_versions);
788
+		$versions_served_historically = array_keys($possibly_served_versions);
789
+		$latest_version = end($versions_served_historically);
790
+		reset($versions_served_historically);
791
+		//for each version of core we have ever served:
792
+		foreach ($versions_served_historically as $key_versioned_endpoint) {
793
+			//if it's not above the current core version, and it's compatible with the current version of core
794
+			if ($key_versioned_endpoint == $latest_version) {
795
+				//don't hide the latest version in the index
796
+				$versions_served[$key_versioned_endpoint] = false;
797
+			} else if (
798
+				$key_versioned_endpoint < EED_Core_Rest_Api::core_version()
799
+				&& $key_versioned_endpoint >= $lowest_compatible_version
800
+			) {
801
+				//include, but hide, previous versions which are still supported
802
+				$versions_served[$key_versioned_endpoint] = true;
803
+			} elseif (
804
+			apply_filters(
805
+				'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions',
806
+				false,
807
+				$possibly_served_versions
808
+			)
809
+			) {
810
+				//if a version is no longer supported, don't include it in index or list of versions served
811
+				$versions_served[$key_versioned_endpoint] = true;
812
+			}
813
+		}
814
+		return $versions_served;
815
+	}
816
+
817
+
818
+
819
+	/**
820
+	 * Gets the major and minor version of EE core's version string
821
+	 *
822
+	 * @return string
823
+	 */
824
+	public static function core_version()
825
+	{
826
+		return apply_filters('FHEE__EED_Core_REST_API__core_version',
827
+			implode('.', array_slice(explode('.', espresso_version()), 0, 3)));
828
+	}
829
+
830
+
831
+
832
+	/**
833
+	 * Gets the default limit that should be used when querying for resources
834
+	 *
835
+	 * @return int
836
+	 */
837
+	public static function get_default_query_limit()
838
+	{
839
+		//we actually don't use a const because we want folks to always use
840
+		//this method, not the const directly
841
+		return apply_filters(
842
+			'FHEE__EED_Core_Rest_Api__get_default_query_limit',
843
+			50
844
+		);
845
+	}
846
+
847
+
848
+
849
+	/**
850
+	 *    run - initial module setup
851
+	 *
852
+	 * @access    public
853
+	 * @param  WP $WP
854
+	 * @return    void
855
+	 */
856
+	public function run($WP)
857
+	{
858
+	}
859 859
 
860 860
 
861 861
 
Please login to merge, or discard this patch.
core/entities/interfaces/HasSchemaInterface.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -5,63 +5,63 @@
 block discarded – undo
5 5
 
6 6
 interface HasSchemaInterface
7 7
 {
8
-    /**
9
-     * Returns whatever is set as the nicename for the object.
10
-     *
11
-     * @return string
12
-     */
13
-    public function getSchemaDescription();
8
+	/**
9
+	 * Returns whatever is set as the nicename for the object.
10
+	 *
11
+	 * @return string
12
+	 */
13
+	public function getSchemaDescription();
14 14
 
15 15
 
16
-    /**
17
-     * Returns whatever is set as the $_schema_type property for the object.
18
-     * Note: this will automatically add 'null' to the schema if the object is_nullable()
19
-     *
20
-     * @return string|array
21
-     */
22
-    public function getSchemaType();
16
+	/**
17
+	 * Returns whatever is set as the $_schema_type property for the object.
18
+	 * Note: this will automatically add 'null' to the schema if the object is_nullable()
19
+	 *
20
+	 * @return string|array
21
+	 */
22
+	public function getSchemaType();
23 23
 
24 24
 
25
-    /**
26
-     * This is usually present when the $_schema_type property is 'object'.  Any child classes will need to override
27
-     * this method and return the properties for the schema.
28
-     * The reason this is not a property on the class is because there may be filters set on the values for the property
29
-     * that won't be exposed on construct.  For example enum type schemas may have the enum values filtered.
30
-     *
31
-     * @return array
32
-     */
33
-    public function getSchemaProperties();
25
+	/**
26
+	 * This is usually present when the $_schema_type property is 'object'.  Any child classes will need to override
27
+	 * this method and return the properties for the schema.
28
+	 * The reason this is not a property on the class is because there may be filters set on the values for the property
29
+	 * that won't be exposed on construct.  For example enum type schemas may have the enum values filtered.
30
+	 *
31
+	 * @return array
32
+	 */
33
+	public function getSchemaProperties();
34 34
 
35
-    /**
36
-     * If a child class has enum values, they should override this method and provide a simple array
37
-     * of the enum values.
38
-     * The reason this is not a property on the class is because there may be filterable enum values that
39
-     * are set on the instantiated object that could be filtered after construct.
40
-     *
41
-     * @return array
42
-     */
43
-    public function getSchemaEnum();
35
+	/**
36
+	 * If a child class has enum values, they should override this method and provide a simple array
37
+	 * of the enum values.
38
+	 * The reason this is not a property on the class is because there may be filterable enum values that
39
+	 * are set on the instantiated object that could be filtered after construct.
40
+	 *
41
+	 * @return array
42
+	 */
43
+	public function getSchemaEnum();
44 44
 
45
-    /**
46
-     * This returns the value of the $_schema_format property on the object.
47
-     *
48
-     * @return string
49
-     */
50
-    public function getSchemaFormat();
45
+	/**
46
+	 * This returns the value of the $_schema_format property on the object.
47
+	 *
48
+	 * @return string
49
+	 */
50
+	public function getSchemaFormat();
51 51
 
52
-    /**
53
-     * This returns the value of the $_schema_readonly property on the object.
54
-     *
55
-     * @return bool
56
-     */
57
-    public function getSchemaReadonly();
52
+	/**
53
+	 * This returns the value of the $_schema_readonly property on the object.
54
+	 *
55
+	 * @return bool
56
+	 */
57
+	public function getSchemaReadonly();
58 58
 
59 59
 
60
-    /**
61
-     * This returns elements used to represent this field in the json schema.
62
-     *
63
-     * @link http://json-schema.org/
64
-     * @return array
65
-     */
66
-    public function getSchema();
60
+	/**
61
+	 * This returns elements used to represent this field in the json schema.
62
+	 *
63
+	 * @link http://json-schema.org/
64
+	 * @return array
65
+	 */
66
+	public function getSchema();
67 67
 }
68 68
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_models/fields/EE_Text_Field_Base.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -7,36 +7,36 @@
 block discarded – undo
7 7
 abstract class EE_Text_Field_Base extends EE_Model_Field_Base
8 8
 {
9 9
 
10
-    function prepare_for_get($value_of_field_on_model_object)
11
-    {
12
-        return is_string($value_of_field_on_model_object) ? stripslashes($value_of_field_on_model_object) : $value_of_field_on_model_object;
13
-    }
10
+	function prepare_for_get($value_of_field_on_model_object)
11
+	{
12
+		return is_string($value_of_field_on_model_object) ? stripslashes($value_of_field_on_model_object) : $value_of_field_on_model_object;
13
+	}
14 14
 
15
-    /**
16
-     * Accepts schema of 'form_input' which formats the string for echoing in form input's value.
17
-     *
18
-     * @param string $value_on_field_to_be_outputted
19
-     * @param string $schema
20
-     * @return string
21
-     */
22
-    function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
23
-    {
24
-        if ($schema == 'form_input') {
25
-            $value_on_field_to_be_outputted = htmlentities($value_on_field_to_be_outputted, ENT_QUOTES, 'UTF-8');
26
-        }
27
-        return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema);
28
-    }
15
+	/**
16
+	 * Accepts schema of 'form_input' which formats the string for echoing in form input's value.
17
+	 *
18
+	 * @param string $value_on_field_to_be_outputted
19
+	 * @param string $schema
20
+	 * @return string
21
+	 */
22
+	function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
23
+	{
24
+		if ($schema == 'form_input') {
25
+			$value_on_field_to_be_outputted = htmlentities($value_on_field_to_be_outputted, ENT_QUOTES, 'UTF-8');
26
+		}
27
+		return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema);
28
+	}
29 29
 
30
-    /**
31
-     * In form inputs, we should have called htmlentities and addslashes on form inputs,
32
-     * so we need to undo that on setting of these fields
33
-     *
34
-     * @param string $value_inputted_for_field_on_model_object
35
-     * @return string
36
-     */
37
-    function prepare_for_set($value_inputted_for_field_on_model_object)
38
-    {
39
-        return stripslashes(html_entity_decode(parent::prepare_for_set($value_inputted_for_field_on_model_object),
40
-            ENT_QUOTES, 'UTF-8'));
41
-    }
30
+	/**
31
+	 * In form inputs, we should have called htmlentities and addslashes on form inputs,
32
+	 * so we need to undo that on setting of these fields
33
+	 *
34
+	 * @param string $value_inputted_for_field_on_model_object
35
+	 * @return string
36
+	 */
37
+	function prepare_for_set($value_inputted_for_field_on_model_object)
38
+	{
39
+		return stripslashes(html_entity_decode(parent::prepare_for_set($value_inputted_for_field_on_model_object),
40
+			ENT_QUOTES, 'UTF-8'));
41
+	}
42 42
 }
43 43
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_models/fields/EE_Primary_Key_String_Field.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -4,22 +4,22 @@
 block discarded – undo
4 4
 class EE_Primary_Key_String_Field extends EE_Primary_Key_Field_Base
5 5
 {
6 6
 
7
-    public function __construct($table_column, $nicename)
8
-    {
9
-        parent::__construct($table_column, $nicename, null);
10
-    }
7
+	public function __construct($table_column, $nicename)
8
+	{
9
+		parent::__construct($table_column, $nicename, null);
10
+	}
11 11
 
12
-    /**
13
-     * removes all tags when setting
14
-     *
15
-     * @param string $value_inputted_for_field_on_model_object
16
-     * @return string
17
-     */
18
-    function prepare_for_set($value_inputted_for_field_on_model_object)
19
-    {
20
-        if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
21
-            $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
22
-        }
23
-        return wp_strip_all_tags($value_inputted_for_field_on_model_object);
24
-    }
12
+	/**
13
+	 * removes all tags when setting
14
+	 *
15
+	 * @param string $value_inputted_for_field_on_model_object
16
+	 * @return string
17
+	 */
18
+	function prepare_for_set($value_inputted_for_field_on_model_object)
19
+	{
20
+		if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
21
+			$value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
22
+		}
23
+		return wp_strip_all_tags($value_inputted_for_field_on_model_object);
24
+	}
25 25
 }
26 26
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_models/fields/EE_Foreign_Key_String_Field.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -4,17 +4,17 @@
 block discarded – undo
4 4
 class EE_Foreign_Key_String_Field extends EE_Foreign_Key_Field_Base
5 5
 {
6 6
 
7
-    /**
8
-     * removes all tags when setting
9
-     *
10
-     * @param string $value_inputted_for_field_on_model_object
11
-     * @return string
12
-     */
13
-    function prepare_for_set($value_inputted_for_field_on_model_object)
14
-    {
15
-        if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
16
-            $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
17
-        }
18
-        return strtoupper(wp_strip_all_tags($value_inputted_for_field_on_model_object));
19
-    }
7
+	/**
8
+	 * removes all tags when setting
9
+	 *
10
+	 * @param string $value_inputted_for_field_on_model_object
11
+	 * @return string
12
+	 */
13
+	function prepare_for_set($value_inputted_for_field_on_model_object)
14
+	{
15
+		if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
16
+			$value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
17
+		}
18
+		return strtoupper(wp_strip_all_tags($value_inputted_for_field_on_model_object));
19
+	}
20 20
 }
21 21
\ No newline at end of file
Please login to merge, or discard this patch.