Completed
Branch FET-9972-sold-out-event-email (67180a)
by
unknown
14:34
created
shortcodes/espresso_thank_you/EES_Espresso_Thank_You.shortcode.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -426,9 +426,9 @@  discard block
 block discarded – undo
426 426
 		do_action( 'AHEE__EES_Espresso_Thank_You__init_end', $this->_current_txn );
427 427
 		// set no cache headers and constants
428 428
 		EE_System::do_not_cache();
429
-        add_action('shutdown', array($this, 'check_for_sold_out_events'), 10);
429
+		add_action('shutdown', array($this, 'check_for_sold_out_events'), 10);
430 430
 
431
-    }
431
+	}
432 432
 
433 433
 
434 434
 
@@ -973,30 +973,30 @@  discard block
 block discarded – undo
973 973
 
974 974
 
975 975
 
976
-    /**
977
-     * check_for_sold_out_events
978
-     * after all is said and done on this page,
979
-     * this method collects the event ids from this transactions registrations,
980
-     * then queries the database to get info regarding the number of approved registrations
981
-     * and registration limits for each event's datetimes.
982
-     * If any datetime appears to be sold out, then a heavily filtered email is sent out.
983
-     */
984
-    public function check_for_sold_out_events()
985
-    {
986
-        if (defined('DOING_AJAX') && DOING_AJAX) {
987
-            return;
988
-        }
989
-        $events = array();
990
-        foreach( (array)$this->_current_txn->registrations() as $registration) {
991
-            if ($registration instanceof \EE_Registration) {
992
-                $events[] = $registration->event_ID();
993
-            }
994
-        }
995
-        if ( ! empty($events)) {
996
-            global $wpdb;
997
-            $events = $wpdb->get_results(
998
-                $wpdb->prepare(
999
-                    "SELECT
976
+	/**
977
+	 * check_for_sold_out_events
978
+	 * after all is said and done on this page,
979
+	 * this method collects the event ids from this transactions registrations,
980
+	 * then queries the database to get info regarding the number of approved registrations
981
+	 * and registration limits for each event's datetimes.
982
+	 * If any datetime appears to be sold out, then a heavily filtered email is sent out.
983
+	 */
984
+	public function check_for_sold_out_events()
985
+	{
986
+		if (defined('DOING_AJAX') && DOING_AJAX) {
987
+			return;
988
+		}
989
+		$events = array();
990
+		foreach( (array)$this->_current_txn->registrations() as $registration) {
991
+			if ($registration instanceof \EE_Registration) {
992
+				$events[] = $registration->event_ID();
993
+			}
994
+		}
995
+		if ( ! empty($events)) {
996
+			global $wpdb;
997
+			$events = $wpdb->get_results(
998
+				$wpdb->prepare(
999
+					"SELECT
1000 1000
                       e.ID AS Event_ID,
1001 1001
                       e.post_title AS Event_Name,
1002 1002
                       d.DTT_ID AS Datetime_ID,
@@ -1018,50 +1018,50 @@  discard block
 block discarded – undo
1018 1018
                       AND e.ID IN (%s)                    
1019 1019
                     GROUP BY d.DTT_ID
1020 1020
                     ORDER BY d.DTT_ID ASC",
1021
-                    implode(', ', $events)
1022
-                )
1023
-            );
1024
-            foreach ($events as $event) {
1025
-                if (
1026
-                    isset($event->Datetime_Reg_Limit, $event->Approved_Registrations_Count)
1027
-                    && $event->Datetime_Reg_Limit <= $event->Approved_Registrations_Count
1028
-                ) {
1029
-                    do_action('AHEE__EES_Espresso_Thank_You__check_for_sold_out_events', $event);
1030
-                    if(
1031
-                        apply_filters(
1032
-                            'AFEE__EES_Espresso_Thank_You__check_for_sold_out_events__send_sold_out_event_email',
1033
-                            true
1034
-                        )
1035
-                    ) {
1036
-                        wp_mail(
1037
-                            apply_filters(
1038
-                                'AFEE__EES_Espresso_Thank_You__check_for_sold_out_events__sold_out_event_email_recipient',
1039
-                                EE_Config::instance()->organization->email
1040
-                            ),
1041
-                            apply_filters(
1042
-                                'AFEE__EES_Espresso_Thank_You__check_for_sold_out_events__sold_out_event_email_subject',
1043
-                                __('Sold Out Event', 'event_espresso')
1044
-                            ),
1045
-                            apply_filters(
1046
-                                'AFEE__EES_Espresso_Thank_You__check_for_sold_out_events__sold_out_event_email_message',
1047
-                                sprintf(
1048
-                                    __('The "%1$s" event (ID:%2$d) has %3$d approved registrations which matches the datetime registration limit of %4$d for the "%5$s" datetime (ID:%6$d)',
1049
-                                            'event_espresso'),
1050
-                                    $event->Event_Name,
1051
-                                    $event->Event_ID,
1052
-                                    $event->Approved_Registrations_Count,
1053
-                                    $event->Datetime_Reg_Limit,
1054
-                                    $event->Datetime_Name,
1055
-                                    $event->Datetime_ID
1056
-                                ),
1057
-                                $event
1058
-                            )
1059
-                        );
1060
-                    }
1061
-                }
1062
-            }
1063
-        }
1064
-    }
1021
+					implode(', ', $events)
1022
+				)
1023
+			);
1024
+			foreach ($events as $event) {
1025
+				if (
1026
+					isset($event->Datetime_Reg_Limit, $event->Approved_Registrations_Count)
1027
+					&& $event->Datetime_Reg_Limit <= $event->Approved_Registrations_Count
1028
+				) {
1029
+					do_action('AHEE__EES_Espresso_Thank_You__check_for_sold_out_events', $event);
1030
+					if(
1031
+						apply_filters(
1032
+							'AFEE__EES_Espresso_Thank_You__check_for_sold_out_events__send_sold_out_event_email',
1033
+							true
1034
+						)
1035
+					) {
1036
+						wp_mail(
1037
+							apply_filters(
1038
+								'AFEE__EES_Espresso_Thank_You__check_for_sold_out_events__sold_out_event_email_recipient',
1039
+								EE_Config::instance()->organization->email
1040
+							),
1041
+							apply_filters(
1042
+								'AFEE__EES_Espresso_Thank_You__check_for_sold_out_events__sold_out_event_email_subject',
1043
+								__('Sold Out Event', 'event_espresso')
1044
+							),
1045
+							apply_filters(
1046
+								'AFEE__EES_Espresso_Thank_You__check_for_sold_out_events__sold_out_event_email_message',
1047
+								sprintf(
1048
+									__('The "%1$s" event (ID:%2$d) has %3$d approved registrations which matches the datetime registration limit of %4$d for the "%5$s" datetime (ID:%6$d)',
1049
+											'event_espresso'),
1050
+									$event->Event_Name,
1051
+									$event->Event_ID,
1052
+									$event->Approved_Registrations_Count,
1053
+									$event->Datetime_Reg_Limit,
1054
+									$event->Datetime_Name,
1055
+									$event->Datetime_ID
1056
+								),
1057
+								$event
1058
+							)
1059
+						);
1060
+					}
1061
+				}
1062
+			}
1063
+		}
1064
+	}
1065 1065
 
1066 1066
 }
1067 1067
 // End of file EES_Espresso_Thank_You.shortcode.php
Please login to merge, or discard this patch.
Spacing   +137 added lines, -137 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
 
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 * @return    void
92 92
 	 */
93 93
 	public static function set_hooks() {
94
-		add_action( 'wp_loaded', array( 'EES_Espresso_Thank_You', 'set_definitions' ), 2 );
94
+		add_action('wp_loaded', array('EES_Espresso_Thank_You', 'set_definitions'), 2);
95 95
 	}
96 96
 
97 97
 
@@ -104,22 +104,22 @@  discard block
 block discarded – undo
104 104
 	 */
105 105
 	public static function set_hooks_admin() {
106 106
 		// AJAX for IPN monitoring
107
-		add_filter( 'heartbeat_received', array( 'EES_Espresso_Thank_You', 'thank_you_page_IPN_monitor' ), 10, 3 );
107
+		add_filter('heartbeat_received', array('EES_Espresso_Thank_You', 'thank_you_page_IPN_monitor'), 10, 3);
108 108
 		add_filter(
109 109
 			'heartbeat_nopriv_received',
110
-			array( 'EES_Espresso_Thank_You', 'thank_you_page_IPN_monitor' ),
110
+			array('EES_Espresso_Thank_You', 'thank_you_page_IPN_monitor'),
111 111
 			10,
112 112
 			3
113 113
 		);
114 114
 		add_action(
115 115
 			'wp_ajax_espresso_resend_reg_confirmation_email',
116
-			array( 'EES_Espresso_Thank_You', 'resend_reg_confirmation_email' ),
116
+			array('EES_Espresso_Thank_You', 'resend_reg_confirmation_email'),
117 117
 			10,
118 118
 			2
119 119
 		);
120 120
 		add_action(
121 121
 			'wp_ajax_nopriv_espresso_resend_reg_confirmation_email',
122
-			array( 'EES_Espresso_Thank_You', 'resend_reg_confirmation_email' ),
122
+			array('EES_Espresso_Thank_You', 'resend_reg_confirmation_email'),
123 123
 			10,
124 124
 			2
125 125
 		);
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
 	 * @return    void
135 135
 	 */
136 136
 	public static function set_definitions() {
137
-		define( 'THANK_YOU_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS );
138
-		define( 'THANK_YOU_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ ) ) . 'templates' . DS );
137
+		define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS);
138
+		define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS);
139 139
 	}
140 140
 
141 141
 
@@ -147,13 +147,13 @@  discard block
 block discarded – undo
147 147
 	 * @return    EE_Transaction
148 148
 	 */
149 149
 	public function get_txn() {
150
-		if ( $this->_current_txn instanceof EE_Transaction ) {
150
+		if ($this->_current_txn instanceof EE_Transaction) {
151 151
 			return $this->_current_txn;
152 152
 		}
153
-		$TXN_model = EE_Registry::instance()->load_model( 'Transaction' );
154
-		if ( ! $TXN_model instanceof EEM_Transaction ) {
153
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
154
+		if ( ! $TXN_model instanceof EEM_Transaction) {
155 155
 			EE_Error::add_error(
156
-				__( 'The transaction model could not be established.', 'event_espresso' ),
156
+				__('The transaction model could not be established.', 'event_espresso'),
157 157
 				__FILE__,
158 158
 				__FUNCTION__,
159 159
 				__LINE__
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
 			return null;
162 162
 		}
163 163
 		//get the transaction. yes, we may have just loaded it, but it may have been updated, or this may be via an ajax request
164
-		$this->_current_txn = $TXN_model->get_transaction_from_reg_url_link( $this->_reg_url_link );
164
+		$this->_current_txn = $TXN_model->get_transaction_from_reg_url_link($this->_reg_url_link);
165 165
 		// verify TXN
166
-		if ( WP_DEBUG && ! $this->_current_txn instanceof EE_Transaction ) {
166
+		if (WP_DEBUG && ! $this->_current_txn instanceof EE_Transaction) {
167 167
 			EE_Error::add_error(
168 168
 				__(
169 169
 					'No transaction information could be retrieved or the transaction data is not of the correct type.',
@@ -187,16 +187,16 @@  discard block
 block discarded – undo
187 187
 	 * @param int $since
188 188
 	 * @return    mixed array of EE_Payment || FALSE
189 189
 	 */
190
-	public function get_txn_payments( $since = 0 ) {
191
-		if ( ! $this->get_txn() ) {
190
+	public function get_txn_payments($since = 0) {
191
+		if ( ! $this->get_txn()) {
192 192
 			return false;
193 193
 		}
194
-		$args = array( 'order_by' => array( 'PAY_timestamp' => 'ASC' ) );
195
-		if ( $since > 0 ) {
196
-			$args[0] = array( 'PAY_timestamp' => array( '>', $since ) );
194
+		$args = array('order_by' => array('PAY_timestamp' => 'ASC'));
195
+		if ($since > 0) {
196
+			$args[0] = array('PAY_timestamp' => array('>', $since));
197 197
 		}
198 198
 		// get array of payments with most recent first
199
-		return $this->_current_txn->payments( $args );
199
+		return $this->_current_txn->payments($args);
200 200
 	}
201 201
 
202 202
 
@@ -208,11 +208,11 @@  discard block
 block discarded – undo
208 208
 	 * @return    void
209 209
 	 */
210 210
 	private function _get_reg_url_link() {
211
-		if ( ! empty( $this->_reg_url_link ) ) {
211
+		if ( ! empty($this->_reg_url_link)) {
212 212
 			return;
213 213
 		}
214 214
 		// only do thank you page stuff if we have a REG_url_link in the url
215
-		if ( WP_DEBUG && ! EE_Registry::instance()->REQ->is_set( 'e_reg_url_link' ) ) {
215
+		if (WP_DEBUG && ! EE_Registry::instance()->REQ->is_set('e_reg_url_link')) {
216 216
 			EE_Error::add_error(
217 217
 				__(
218 218
 					'No transaction information could be retrieved because the registration URL link is missing or invalid.',
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 			return;
226 226
 		}
227 227
 		// check for reg_url_link
228
-		$this->_reg_url_link = EE_Registry::instance()->REQ->get( 'e_reg_url_link' );
228
+		$this->_reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link');
229 229
 	}
230 230
 
231 231
 
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
 	 * @param    string $reg_url_link
238 238
 	 * @return    string
239 239
 	 */
240
-	public function set_reg_url_link( $reg_url_link = null ) {
241
-		$this->_reg_url_link = ! empty( $reg_url_link ) ? $reg_url_link : $this->_reg_url_link;
240
+	public function set_reg_url_link($reg_url_link = null) {
241
+		$this->_reg_url_link = ! empty($reg_url_link) ? $reg_url_link : $this->_reg_url_link;
242 242
 	}
243 243
 
244 244
 
@@ -251,28 +251,28 @@  discard block
 block discarded – undo
251 251
 	 * @param    WP $WP
252 252
 	 * @return    void
253 253
 	 */
254
-	public function run( WP $WP ) {
254
+	public function run(WP $WP) {
255 255
 		// remove site_url() from thank you page URL
256
-		$thank_you_page_URL = substr( EE_Registry::instance()->CFG->core->thank_you_page_url(), strlen( home_url() ) );
256
+		$thank_you_page_URL = substr(EE_Registry::instance()->CFG->core->thank_you_page_url(), strlen(home_url()));
257 257
 		// remove other non-essential details from URL
258
-		$thank_you_page_URL = trim( parse_url( $thank_you_page_URL, PHP_URL_PATH ), '/' );
258
+		$thank_you_page_URL = trim(parse_url($thank_you_page_URL, PHP_URL_PATH), '/');
259 259
 		// ensure this shortcode doesn't trigger on anything BUT the thank you page
260
-		if ( isset( $WP->request ) && trim( $WP->request, '/' ) !== $thank_you_page_URL ) {
260
+		if (isset($WP->request) && trim($WP->request, '/') !== $thank_you_page_URL) {
261 261
 			return;
262 262
 		} else if (
263
-			isset( $WP->query_vars['page_id'] )
264
-			&& (int)$WP->query_vars['page_id'] !== (int)EE_Registry::instance()->CFG->core->thank_you_page_id
263
+			isset($WP->query_vars['page_id'])
264
+			&& (int) $WP->query_vars['page_id'] !== (int) EE_Registry::instance()->CFG->core->thank_you_page_id
265 265
 		) {
266 266
 			return;
267 267
 		}
268 268
 		$this->_get_reg_url_link();
269 269
 		// resend_reg_confirmation_email ?
270
-		if ( EE_Registry::instance()->REQ->is_set( 'resend' ) ) {
270
+		if (EE_Registry::instance()->REQ->is_set('resend')) {
271 271
 			EES_Espresso_Thank_You::resend_reg_confirmation_email();
272 272
 		}
273 273
 		// load assets
274
-		add_action( 'wp_enqueue_scripts', array( $this, 'load_js' ), 10 );
275
-		EE_Registry::instance()->SSN->clear_session( __CLASS__, __FUNCTION__ );
274
+		add_action('wp_enqueue_scripts', array($this, 'load_js'), 10);
275
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
276 276
 		$this->_translate_strings();
277 277
 	}
278 278
 
@@ -326,12 +326,12 @@  discard block
 block discarded – undo
326 326
 	public function load_js() {
327 327
 		wp_register_script(
328 328
 			'thank_you_page',
329
-			THANK_YOU_ASSETS_URL . 'thank_you_page.js',
330
-			array( 'espresso_core', 'heartbeat' ),
329
+			THANK_YOU_ASSETS_URL.'thank_you_page.js',
330
+			array('espresso_core', 'heartbeat'),
331 331
 			EVENT_ESPRESSO_VERSION,
332 332
 			true
333 333
 		);
334
-		wp_enqueue_script( 'thank_you_page' );
334
+		wp_enqueue_script('thank_you_page');
335 335
 	}
336 336
 
337 337
 
@@ -345,9 +345,9 @@  discard block
 block discarded – undo
345 345
 	 */
346 346
 	public function init() {
347 347
 		$this->_get_reg_url_link();
348
-		if ( ! $this->get_txn() ) {
348
+		if ( ! $this->get_txn()) {
349 349
 			echo EEH_HTML::div(
350
-				EEH_HTML::h4( __( 'We\'re sorry...', 'event_espresso' ), '', '' ) .
350
+				EEH_HTML::h4(__('We\'re sorry...', 'event_espresso'), '', '').
351 351
 				sprintf(
352 352
 					__(
353 353
 						'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s',
@@ -361,8 +361,8 @@  discard block
 block discarded – undo
361 361
 			return null;
362 362
 		}
363 363
 		// if we've made it to the Thank You page, then let's toggle any "Failed" transactions to "Incomplete"
364
-		if ( $this->_current_txn->status_ID() === EEM_Transaction::failed_status_code ) {
365
-			$this->_current_txn->set_status( EEM_Transaction::incomplete_status_code );
364
+		if ($this->_current_txn->status_ID() === EEM_Transaction::failed_status_code) {
365
+			$this->_current_txn->set_status(EEM_Transaction::incomplete_status_code);
366 366
 			$this->_current_txn->save();
367 367
 		}
368 368
 		$this->_primary_registrant = $this->_current_txn->primary_registration() instanceof EE_Registration
@@ -375,15 +375,15 @@  discard block
 block discarded – undo
375 375
 		);
376 376
 		$this->_show_try_pay_again_link = $show_try_pay_again_link_default;
377 377
 		// txn status ?
378
-		if ( $this->_current_txn->is_completed() ) {
378
+		if ($this->_current_txn->is_completed()) {
379 379
 			$this->_show_try_pay_again_link = $show_try_pay_again_link_default;
380 380
 		} else if (
381 381
 			$this->_current_txn->is_incomplete()
382
-			&& ( $this->_primary_registrant->is_approved()
383
-			|| $this->_primary_registrant->is_pending_payment() )
382
+			&& ($this->_primary_registrant->is_approved()
383
+			|| $this->_primary_registrant->is_pending_payment())
384 384
 		) {
385 385
 			$this->_show_try_pay_again_link = true;
386
-		} else if ( $this->_primary_registrant->is_approved() || $this->_primary_registrant->is_pending_payment() ) {
386
+		} else if ($this->_primary_registrant->is_approved() || $this->_primary_registrant->is_pending_payment()) {
387 387
 			// its pending
388 388
 			$this->_show_try_pay_again_link = isset(
389 389
 				EE_Registry::instance()->CFG->registration->show_pending_payment_options
@@ -409,21 +409,21 @@  discard block
 block discarded – undo
409 409
 		}
410 410
 		// link to SPCO
411 411
 		$revisit_spco_url = add_query_arg(
412
-			array( 'ee' => '_register', 'revisit' => true, 'e_reg_url_link' => $this->_reg_url_link ),
412
+			array('ee' => '_register', 'revisit' => true, 'e_reg_url_link' => $this->_reg_url_link),
413 413
 			EE_Registry::instance()->CFG->core->reg_page_url()
414 414
 		);
415 415
 		// link to SPCO payment_options
416 416
 		$this->_SPCO_payment_options_url = $this->_primary_registrant instanceof EE_Registration
417 417
 			? $this->_primary_registrant->payment_overview_url()
418 418
 			: add_query_arg(
419
-				array( 'step' => 'payment_options' ),
419
+				array('step' => 'payment_options'),
420 420
 				$revisit_spco_url
421 421
 			);
422 422
 		// link to SPCO attendee_information
423 423
 		$this->_SPCO_attendee_information_url = $this->_primary_registrant instanceof EE_Registration
424 424
 			? $this->_primary_registrant->edit_attendee_information_url()
425 425
 			: false;
426
-		do_action( 'AHEE__EES_Espresso_Thank_You__init_end', $this->_current_txn );
426
+		do_action('AHEE__EES_Espresso_Thank_You__init_end', $this->_current_txn);
427 427
 		// set no cache headers and constants
428 428
 		EE_System::do_not_cache();
429 429
         add_action('shutdown', array($this, 'check_for_sold_out_events'), 10);
@@ -440,15 +440,15 @@  discard block
 block discarded – undo
440 440
 	 * @return    string
441 441
 	 * @throws \EE_Error
442 442
 	 */
443
-	public function process_shortcode( $attributes = array() ) {
443
+	public function process_shortcode($attributes = array()) {
444 444
 		$this->init();
445
-		if ( ! $this->_current_txn instanceof EE_Transaction ) {
445
+		if ( ! $this->_current_txn instanceof EE_Transaction) {
446 446
 			return EE_Error::get_notices();
447 447
 		}
448 448
 		//EEH_Debug_Tools::log( __CLASS__, __FUNCTION__, __LINE__, array( $this->_current_txn ), true, 	'EE_Transaction: ' . $this->_current_txn->ID() );
449 449
 		// link to receipt
450
-		$template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url( 'html' );
451
-		if ( ! empty( $template_args['TXN_receipt_url'] ) ) {
450
+		$template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url('html');
451
+		if ( ! empty($template_args['TXN_receipt_url'])) {
452 452
 			$template_args['order_conf_desc'] = __(
453 453
 				'%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.',
454 454
 				'event_espresso'
@@ -460,13 +460,13 @@  discard block
 block discarded – undo
460 460
 			);
461 461
 		}
462 462
 		$template_args['transaction'] = $this->_current_txn;
463
-		$template_args['revisit'] = EE_Registry::instance()->REQ->get( 'revisit', false );
464
-		add_action( 'AHEE__thank_you_page_overview_template__content', array( $this, 'get_registration_details' ) );
465
-		if ( $this->_is_primary && ! $this->_current_txn->is_free() ) {
466
-			add_action( 'AHEE__thank_you_page_overview_template__content', array( $this, 'get_ajax_content' ) );
463
+		$template_args['revisit'] = EE_Registry::instance()->REQ->get('revisit', false);
464
+		add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_registration_details'));
465
+		if ($this->_is_primary && ! $this->_current_txn->is_free()) {
466
+			add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content'));
467 467
 		}
468 468
 		return EEH_Template::locate_template(
469
-			THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php',
469
+			THANK_YOU_TEMPLATES_PATH.'thank-you-page-overview.template.php',
470 470
 			$template_args,
471 471
 			true,
472 472
 			true
@@ -487,15 +487,15 @@  discard block
 block discarded – undo
487 487
 	 * @return    array
488 488
 	 * @throws \EE_Error
489 489
 	 */
490
-	public static function thank_you_page_IPN_monitor( $response = array(), $data = array() ) {
490
+	public static function thank_you_page_IPN_monitor($response = array(), $data = array()) {
491 491
 		// does this heartbeat contain our data ?
492
-		if ( ! isset( $data['espresso_thank_you_page'] ) ) {
492
+		if ( ! isset($data['espresso_thank_you_page'])) {
493 493
 			return $response;
494 494
 		}
495 495
 		// check for reg_url_link in the incoming heartbeat data
496
-		if ( ! isset( $data['espresso_thank_you_page']['e_reg_url_link'] ) ) {
496
+		if ( ! isset($data['espresso_thank_you_page']['e_reg_url_link'])) {
497 497
 			$response['espresso_thank_you_page'] = array(
498
-			'errors' => ! empty( $notices['errors'] )
498
+			'errors' => ! empty($notices['errors'])
499 499
 				? $notices['errors']
500 500
 				: __(
501 501
 					'No transaction information could be retrieved because the registration URL link is missing or invalid.',
@@ -510,15 +510,15 @@  discard block
 block discarded – undo
510 510
 		EES_Espresso_Thank_You::set_definitions();
511 511
 		/** @var $espresso_thank_you_page EES_Espresso_Thank_You */
512 512
 		$espresso_thank_you_page = EES_Espresso_Thank_You::instance();
513
-		$espresso_thank_you_page->set_reg_url_link( $data['espresso_thank_you_page']['e_reg_url_link'] );
513
+		$espresso_thank_you_page->set_reg_url_link($data['espresso_thank_you_page']['e_reg_url_link']);
514 514
 		$espresso_thank_you_page->init();
515 515
 		//get TXN
516 516
 		$TXN = $espresso_thank_you_page->get_txn();
517 517
 		// no TXN? then get out
518
-		if ( ! $TXN instanceof EE_Transaction ) {
518
+		if ( ! $TXN instanceof EE_Transaction) {
519 519
 			$notices = EE_Error::get_notices();
520 520
 			$response['espresso_thank_you_page'] = array(
521
-			'errors' => ! empty( $notices['errors'] )
521
+			'errors' => ! empty($notices['errors'])
522 522
 				? $notices['errors']
523 523
 				: sprintf(
524 524
 					__(
@@ -531,13 +531,13 @@  discard block
 block discarded – undo
531 531
 			return $response;
532 532
 		}
533 533
 		// grab transient of TXN's status
534
-		$txn_status = isset( $data['espresso_thank_you_page']['txn_status'] )
534
+		$txn_status = isset($data['espresso_thank_you_page']['txn_status'])
535 535
 			? $data['espresso_thank_you_page']['txn_status']
536 536
 			: null;
537 537
 		// has the TXN status changed since we last checked (or empty because this is the first time running through this code)?
538
-		if ( $txn_status !== $TXN->status_ID() ) {
538
+		if ($txn_status !== $TXN->status_ID()) {
539 539
 			// switch between two possible basic outcomes
540
-			switch ( $TXN->status_ID() ) {
540
+			switch ($TXN->status_ID()) {
541 541
 				// TXN has been updated in some way
542 542
 				case EEM_Transaction::overpaid_status_code:
543 543
 				case EEM_Transaction::complete_status_code:
@@ -552,25 +552,25 @@  discard block
 block discarded – undo
552 552
 				case EEM_Transaction::failed_status_code:
553 553
 				default:
554 554
 					// keep on waiting...
555
-					return $espresso_thank_you_page->_update_server_wait_time( $data['espresso_thank_you_page'] );
555
+					return $espresso_thank_you_page->_update_server_wait_time($data['espresso_thank_you_page']);
556 556
 			}
557 557
 			// or is the TXN still failed (never been updated) ???
558
-		} else if ( $TXN->failed() ) {
558
+		} else if ($TXN->failed()) {
559 559
 			// keep on waiting...
560
-			return $espresso_thank_you_page->_update_server_wait_time( $data['espresso_thank_you_page'] );
560
+			return $espresso_thank_you_page->_update_server_wait_time($data['espresso_thank_you_page']);
561 561
 		}
562 562
 		// TXN is happening so let's get the payments now
563 563
 		// if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked
564
-		$since = isset( $data['espresso_thank_you_page']['get_payments_since'] )
564
+		$since = isset($data['espresso_thank_you_page']['get_payments_since'])
565 565
 			? $data['espresso_thank_you_page']['get_payments_since']
566 566
 			: 0;
567 567
 		// then check for payments
568
-		$payments = $espresso_thank_you_page->get_txn_payments( $since );
568
+		$payments = $espresso_thank_you_page->get_txn_payments($since);
569 569
 		// has a payment been processed ?
570
-		if ( ! empty( $payments ) || $espresso_thank_you_page->_is_offline_payment_method ) {
571
-			if ( $since ) {
570
+		if ( ! empty($payments) || $espresso_thank_you_page->_is_offline_payment_method) {
571
+			if ($since) {
572 572
 				$response['espresso_thank_you_page'] = array(
573
-					'new_payments'        => $espresso_thank_you_page->get_new_payments( $payments ),
573
+					'new_payments'        => $espresso_thank_you_page->get_new_payments($payments),
574 574
 					'transaction_details' => $espresso_thank_you_page->get_transaction_details(),
575 575
 					'txn_status'          => $TXN->status_ID()
576 576
 				);
@@ -596,9 +596,9 @@  discard block
 block discarded – undo
596 596
 	 * @param    array $thank_you_page_data thank you page portion of the incoming JSON array from the WP heartbeat data
597 597
 	 * @return    array
598 598
 	 */
599
-	private function _update_server_wait_time( $thank_you_page_data = array() ) {
599
+	private function _update_server_wait_time($thank_you_page_data = array()) {
600 600
 		$response['espresso_thank_you_page'] = array(
601
-			'still_waiting' => isset( $thank_you_page_data['initial_access'] )
601
+			'still_waiting' => isset($thank_you_page_data['initial_access'])
602 602
 				? time() - $thank_you_page_data['initial_access']
603 603
 				: 0,
604 604
 			'txn_status'    => $this->_current_txn->status_ID()
@@ -623,17 +623,17 @@  discard block
 block discarded – undo
623 623
 		$template_args['is_primary'] = $this->_is_primary;
624 624
 		$template_args['SPCO_attendee_information_url'] = $this->_SPCO_attendee_information_url;
625 625
 		$template_args['resend_reg_confirmation_url'] = add_query_arg(
626
-			array( 'token' => $this->_reg_url_link, 'resend_reg_confirmation' => 'true' ),
626
+			array('token' => $this->_reg_url_link, 'resend_reg_confirmation' => 'true'),
627 627
 			EE_Registry::instance()->CFG->core->thank_you_page_url()
628 628
 		);
629 629
 		// verify template arguments
630
-		EEH_Template_Validator::verify_instanceof( $template_args['transaction'], '$transaction', 'EE_Transaction' );
630
+		EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
631 631
 		EEH_Template_Validator::verify_isnt_null(
632 632
 			$template_args['SPCO_attendee_information_url'],
633 633
 			'$SPCO_attendee_information_url'
634 634
 		);
635 635
 		echo EEH_Template::locate_template(
636
-			THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php',
636
+			THANK_YOU_TEMPLATES_PATH.'thank-you-page-registration-details.template.php',
637 637
 			$template_args,
638 638
 			true,
639 639
 			true
@@ -646,16 +646,16 @@  discard block
 block discarded – undo
646 646
 	 *    resend_reg_confirmation_email
647 647
 	 */
648 648
 	public static function resend_reg_confirmation_email() {
649
-		EE_Registry::instance()->load_core( 'Request_Handler' );
650
-		$reg_url_link = EE_Registry::instance()->REQ->get( 'token' );
649
+		EE_Registry::instance()->load_core('Request_Handler');
650
+		$reg_url_link = EE_Registry::instance()->REQ->get('token');
651 651
 		// was a REG_ID passed ?
652
-		if ( $reg_url_link ) {
653
-			$registration = EE_Registry::instance()->load_model( 'Registration' )->get_one(
654
-				array( array( 'REG_url_link' => $reg_url_link ) )
652
+		if ($reg_url_link) {
653
+			$registration = EE_Registry::instance()->load_model('Registration')->get_one(
654
+				array(array('REG_url_link' => $reg_url_link))
655 655
 			);
656
-			if ( $registration instanceof EE_Registration ) {
656
+			if ($registration instanceof EE_Registration) {
657 657
 				// resend email
658
-				EED_Messages::process_resend( array( '_REG_ID' => $registration->ID() ) );
658
+				EED_Messages::process_resend(array('_REG_ID' => $registration->ID()));
659 659
 			} else {
660 660
 				EE_Error::add_error(
661 661
 					__(
@@ -679,16 +679,16 @@  discard block
 block discarded – undo
679 679
 			);
680 680
 		}
681 681
 		// request sent via AJAX ?
682
-		if ( EE_FRONT_AJAX ) {
683
-			echo json_encode( EE_Error::get_notices( false ) );
682
+		if (EE_FRONT_AJAX) {
683
+			echo json_encode(EE_Error::get_notices(false));
684 684
 			die();
685 685
 			// or was JS disabled ?
686 686
 		} else {
687 687
 			// save errors so that they get picked up on the next request
688
-			EE_Error::get_notices( true, true );
688
+			EE_Error::get_notices(true, true);
689 689
 			wp_safe_redirect(
690 690
 				add_query_arg(
691
-					array( 'e_reg_url_link' => $reg_url_link ),
691
+					array('e_reg_url_link' => $reg_url_link),
692 692
 					EE_Registry::instance()->CFG->core->thank_you_page_url()
693 693
 				)
694 694
 			);
@@ -704,26 +704,26 @@  discard block
 block discarded – undo
704 704
 	 * @return    void
705 705
 	 */
706 706
 	public function get_ajax_content() {
707
-		if ( ! $this->get_txn() ) {
707
+		if ( ! $this->get_txn()) {
708 708
 			return;
709 709
 		}
710 710
 		// first determine which event(s) require pre-approval or not
711 711
 		$events = array();
712 712
 		$events_requiring_pre_approval = array();
713
-		foreach ( $this->_current_txn->registrations() as $registration ) {
714
-			if ( $registration instanceof EE_Registration ) {
713
+		foreach ($this->_current_txn->registrations() as $registration) {
714
+			if ($registration instanceof EE_Registration) {
715 715
 				$event = $registration->event();
716
-				if ( $event instanceof EE_Event ) {
717
-					if ( $registration->is_not_approved() && $registration->event() instanceof EE_Event ) {
718
-						$events_requiring_pre_approval[ $event->ID() ] = $event;
716
+				if ($event instanceof EE_Event) {
717
+					if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) {
718
+						$events_requiring_pre_approval[$event->ID()] = $event;
719 719
 					} else {
720
-						$events[ $event->ID() ] = $event;
720
+						$events[$event->ID()] = $event;
721 721
 					}
722 722
 				}
723 723
 			}
724 724
 		}
725
-		$this->display_details_for_events_requiring_pre_approval( $events_requiring_pre_approval );
726
-		$this->display_details_for_events( $events );
725
+		$this->display_details_for_events_requiring_pre_approval($events_requiring_pre_approval);
726
+		$this->display_details_for_events($events);
727 727
 	}
728 728
 
729 729
 
@@ -735,8 +735,8 @@  discard block
 block discarded – undo
735 735
 	 * @param EE_Event[] $events
736 736
 	 * @return string
737 737
 	 */
738
-	public function display_details_for_events( $events = array() ) {
739
-		if ( ! empty( $events ) ) {
738
+	public function display_details_for_events($events = array()) {
739
+		if ( ! empty($events)) {
740 740
 			?>
741 741
 			<div id="espresso-thank-you-page-ajax-content-dv">
742 742
 				<div id="espresso-thank-you-page-ajax-transaction-dv"></div>
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
 							'event_espresso'
749 749
 							); ?></span>
750 750
 					</div>
751
-					<?php if ( ! $this->_is_offline_payment_method && ! $this->_payments_closed ) : ?>
751
+					<?php if ( ! $this->_is_offline_payment_method && ! $this->_payments_closed) : ?>
752 752
 						<p id="ee-ajax-loading-pg" class="highlight-bg small-text clear">
753 753
 							<?php echo apply_filters(
754 754
 								'EES_Espresso_Thank_You__get_ajax_content__waiting_for_IPN_msg',
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
 							); ?>
760 760
 							<br/>
761 761
 							<span class="jst-rght ee-block small-text lt-grey-text">
762
-								<?php _e( 'current wait time ', 'event_espresso' ); ?>
762
+								<?php _e('current wait time ', 'event_espresso'); ?>
763 763
 							<span id="espresso-thank-you-page-ajax-time-dv">00:00:00</span></span>
764 764
 						</p>
765 765
 					<?php endif; ?>
@@ -779,11 +779,11 @@  discard block
 block discarded – undo
779 779
 	 * @param EE_Event[] $events
780 780
 	 * @return string
781 781
 	 */
782
-	public function display_details_for_events_requiring_pre_approval( $events = array() ) {
783
-		if ( ! empty( $events ) ) {
782
+	public function display_details_for_events_requiring_pre_approval($events = array()) {
783
+		if ( ! empty($events)) {
784 784
 			?>
785 785
 			<div id="espresso-thank-you-page-not-approved-message-dv">
786
-				<h4 class="orange-text"><?php _e( 'Important Notice:', 'event_espresso' ); ?></h4>
786
+				<h4 class="orange-text"><?php _e('Important Notice:', 'event_espresso'); ?></h4>
787 787
 				<p id="events-requiring-pre-approval-pg" class="small-text">
788 788
 					<?php echo apply_filters(
789 789
 						'AHEE__EES_Espresso_Thank_You__get_ajax_content__not_approved_message',
@@ -794,8 +794,8 @@  discard block
 block discarded – undo
794 794
 					); ?>
795 795
 				</p>
796 796
 				<ul class="events-requiring-pre-approval-ul">
797
-					<?php foreach ( $events as $event ) {
798
-						if ( $event instanceof EE_Event ) {
797
+					<?php foreach ($events as $event) {
798
+						if ($event instanceof EE_Event) {
799 799
 							echo '<li><span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>',
800 800
 								$event->name(),
801 801
 								'</li>';
@@ -822,12 +822,12 @@  discard block
 block discarded – undo
822 822
 		$template_args = array();
823 823
 		$template_args['transaction'] = $this->_current_txn;
824 824
 		$template_args['reg_url_link'] = $this->_reg_url_link;
825
-		$template_args['primary_registrant_name'] = $this->_primary_registrant->attendee()->full_name( true );
825
+		$template_args['primary_registrant_name'] = $this->_primary_registrant->attendee()->full_name(true);
826 826
 		// link to SPCO payment_options
827 827
 		$template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link;
828 828
 		$template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url;
829 829
 		// verify template arguments
830
-		EEH_Template_Validator::verify_instanceof( $template_args['transaction'], '$transaction', 'EE_Transaction' );
830
+		EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
831 831
 		EEH_Template_Validator::verify_isnt_null(
832 832
 			$template_args['show_try_pay_again_link'],
833 833
 			'$show_try_pay_again_link'
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
 			'$SPCO_payment_options_url'
838 838
 		);
839 839
 		return EEH_Template::locate_template(
840
-			THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php',
840
+			THANK_YOU_TEMPLATES_PATH.'thank-you-page-transaction-details.template.php',
841 841
 			$template_args,
842 842
 			true,
843 843
 			true
@@ -854,9 +854,9 @@  discard block
 block discarded – undo
854 854
 	 * @return    string
855 855
 	 * @throws \EE_Error
856 856
 	 */
857
-	public function get_payment_row_html( $payment = null ) {
857
+	public function get_payment_row_html($payment = null) {
858 858
 		$html = '';
859
-		if ( $payment instanceof EE_Payment ) {
859
+		if ($payment instanceof EE_Payment) {
860 860
 			if (
861 861
 				$payment->payment_method() instanceof EE_Payment_Method
862 862
 				&& $payment->status() === EEM_Payment::status_id_failed
@@ -865,31 +865,31 @@  discard block
 block discarded – undo
865 865
 				// considering the registrant has made it to the Thank You page,
866 866
 				// any failed payments may actually be pending and the IPN is just slow
867 867
 				// so let's
868
-				$payment->set_status( EEM_Payment::status_id_pending );
868
+				$payment->set_status(EEM_Payment::status_id_pending);
869 869
 			}
870 870
 			$payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined
871
-				? '<br /><span class="small-text">' . $payment->gateway_response() . '</span>'
871
+				? '<br /><span class="small-text">'.$payment->gateway_response().'</span>'
872 872
 				: '';
873 873
 			$html .= '
874 874
 				<tr>
875 875
 					<td>
876
-						' . $payment->timestamp() . '
876
+						' . $payment->timestamp().'
877 877
 					</td>
878 878
 					<td>
879 879
 						' . (
880 880
 								$payment->payment_method() instanceof EE_Payment_Method
881 881
 									? $payment->payment_method()->name()
882
-									: __( 'Unknown', 'event_espresso' )
883
-							) . '
882
+									: __('Unknown', 'event_espresso')
883
+							).'
884 884
 					</td>
885 885
 					<td class="jst-rght">
886
-						' . EEH_Template::format_currency( $payment->amount() ) . '
886
+						' . EEH_Template::format_currency($payment->amount()).'
887 887
 					</td>
888 888
 					<td class="jst-rght" style="line-height:1;">
889
-						' . $payment->pretty_status( true ) . $payment_declined_msg . '
889
+						' . $payment->pretty_status(true).$payment_declined_msg.'
890 890
 					</td>
891 891
 				</tr>';
892
-			do_action( 'AHEE__thank_you_page_payment_details_template__after_each_payment', $payment );
892
+			do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment);
893 893
 		}
894 894
 		return $html;
895 895
 	}
@@ -904,14 +904,14 @@  discard block
 block discarded – undo
904 904
 	 * @return    string
905 905
 	 * @throws \EE_Error
906 906
 	 */
907
-	public function get_payment_details( $payments = array() ) {
907
+	public function get_payment_details($payments = array()) {
908 908
 		//prepare variables for displaying
909 909
 		$template_args = array();
910 910
 		$template_args['transaction'] = $this->_current_txn;
911 911
 		$template_args['reg_url_link'] = $this->_reg_url_link;
912 912
 		$template_args['payments'] = array();
913
-		foreach ( $payments as $payment ) {
914
-			$template_args['payments'][] = $this->get_payment_row_html( $payment );
913
+		foreach ($payments as $payment) {
914
+			$template_args['payments'][] = $this->get_payment_row_html($payment);
915 915
 		}
916 916
 		//create a hacky payment object, but dont save it
917 917
 		$payment = EE_Payment::new_instance(
@@ -924,8 +924,8 @@  discard block
 block discarded – undo
924 924
 			)
925 925
 		);
926 926
 		$payment_method = $this->_current_txn->payment_method();
927
-		if ( $payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base ) {
928
-			$template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content( $payment );
927
+		if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base) {
928
+			$template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content($payment);
929 929
 		} else {
930 930
 			$template_args['gateway_content'] = '';
931 931
 		}
@@ -933,19 +933,19 @@  discard block
 block discarded – undo
933 933
 		$template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link;
934 934
 		$template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url;
935 935
 		// verify template arguments
936
-		EEH_Template_Validator::verify_instanceof( $template_args['transaction'], '$transaction', 'EE_Transaction' );
937
-		EEH_Template_Validator::verify_isnt_null( $template_args['payments'], '$payments' );
936
+		EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
937
+		EEH_Template_Validator::verify_isnt_null($template_args['payments'], '$payments');
938 938
 		EEH_Template_Validator::verify_isnt_null(
939 939
 			$template_args['show_try_pay_again_link'],
940 940
 			'$show_try_pay_again_link'
941 941
 		);
942
-		EEH_Template_Validator::verify_isnt_null( $template_args['gateway_content'], '$gateway_content' );
942
+		EEH_Template_Validator::verify_isnt_null($template_args['gateway_content'], '$gateway_content');
943 943
 		EEH_Template_Validator::verify_isnt_null(
944 944
 			$template_args['SPCO_payment_options_url'],
945 945
 			'$SPCO_payment_options_url'
946 946
 		);
947 947
 		return EEH_Template::locate_template(
948
-			THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php',
948
+			THANK_YOU_TEMPLATES_PATH.'thank-you-page-payment-details.template.php',
949 949
 			$template_args,
950 950
 			true,
951 951
 			true
@@ -962,11 +962,11 @@  discard block
 block discarded – undo
962 962
 	 * @return    string
963 963
 	 * @throws \EE_Error
964 964
 	 */
965
-	public function get_new_payments( $payments = array() ) {
965
+	public function get_new_payments($payments = array()) {
966 966
 		$payments_html = '';
967 967
 		//prepare variables for displaying
968
-		foreach ( $payments as $payment ) {
969
-			$payments_html .= $this->get_payment_row_html( $payment );
968
+		foreach ($payments as $payment) {
969
+			$payments_html .= $this->get_payment_row_html($payment);
970 970
 		}
971 971
 		return $payments_html;
972 972
 	}
@@ -987,7 +987,7 @@  discard block
 block discarded – undo
987 987
             return;
988 988
         }
989 989
         $events = array();
990
-        foreach( (array)$this->_current_txn->registrations() as $registration) {
990
+        foreach ((array) $this->_current_txn->registrations() as $registration) {
991 991
             if ($registration instanceof \EE_Registration) {
992 992
                 $events[] = $registration->event_ID();
993 993
             }
@@ -1027,7 +1027,7 @@  discard block
 block discarded – undo
1027 1027
                     && $event->Datetime_Reg_Limit <= $event->Approved_Registrations_Count
1028 1028
                 ) {
1029 1029
                     do_action('AHEE__EES_Espresso_Thank_You__check_for_sold_out_events', $event);
1030
-                    if(
1030
+                    if (
1031 1031
                         apply_filters(
1032 1032
                             'AFEE__EES_Espresso_Thank_You__check_for_sold_out_events__send_sold_out_event_email',
1033 1033
                             true
Please login to merge, or discard this patch.