Completed
Branch FET-10325-remove-caffeinated-m... (66fc06)
by
unknown
172:00 queued 161:47
created
core/helpers/EEH_Activation.helper.php 2 patches
Spacing   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 	 * @return \EventEspresso\core\services\database\TableAnalysis
62 62
 	 */
63 63
 	public static function getTableAnalysis() {
64
-		if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis ) {
65
-			self::$table_analysis = EE_Registry::instance()->create( 'TableAnalysis', array(), true );
64
+		if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
65
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
66 66
 		}
67 67
 		return self::$table_analysis;
68 68
 	}
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 	 * @return \EventEspresso\core\services\database\TableManager
74 74
 	 */
75 75
 	public static function getTableManager() {
76
-		if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager ) {
77
-			self::$table_manager = EE_Registry::instance()->create( 'TableManager', array(), true );
76
+		if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
77
+			self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
78 78
 		}
79 79
 		return self::$table_manager;
80 80
 	}
@@ -89,8 +89,8 @@  discard block
 block discarded – undo
89 89
 	 * @param $table_name
90 90
 	 * @return string
91 91
 	 */
92
-	public static function ensure_table_name_has_prefix( $table_name ) {
93
-		return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix( $table_name );
92
+	public static function ensure_table_name_has_prefix($table_name) {
93
+		return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
94 94
 	}
95 95
 
96 96
 
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 * @return boolean success, whether the database and folders are setup properly
119 119
 	 * @throws \EE_Error
120 120
 	 */
121
-	public static function initialize_db_and_folders(){
121
+	public static function initialize_db_and_folders() {
122 122
 		$good_filesystem = EEH_Activation::create_upload_directories();
123 123
 		$good_db = EEH_Activation::create_database_tables();
124 124
 		return $good_filesystem && $good_db;
@@ -134,9 +134,9 @@  discard block
 block discarded – undo
134 134
 	 *
135 135
 	 * @throws \EE_Error
136 136
 	 */
137
-	public static function initialize_db_content(){
137
+	public static function initialize_db_content() {
138 138
 		//let's avoid doing all this logic repeatedly, especially when addons are requesting it
139
-		if( EEH_Activation::$_initialized_db_content_already_in_this_request ) {
139
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
140 140
 			return;
141 141
 		}
142 142
 		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
@@ -153,9 +153,9 @@  discard block
 block discarded – undo
153 153
 		EEH_Activation::remove_cron_tasks();
154 154
 		EEH_Activation::create_cron_tasks();
155 155
 		// remove all TXN locks since that is being done via extra meta now
156
-		delete_option( 'ee_locked_transactions' );
156
+		delete_option('ee_locked_transactions');
157 157
 		//also, check for CAF default db content
158
-		do_action( 'AHEE__EEH_Activation__initialize_db_content' );
158
+		do_action('AHEE__EEH_Activation__initialize_db_content');
159 159
 		//also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
160 160
 		//which users really won't care about on initial activation
161 161
 		EE_Error::overwrite_success();
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 	 * @return array
176 176
 	 * @throws \EE_Error
177 177
 	 */
178
-	public static function get_cron_tasks( $which_to_include ) {
178
+	public static function get_cron_tasks($which_to_include) {
179 179
 		$cron_tasks = apply_filters(
180 180
 			'FHEE__EEH_Activation__get_cron_tasks',
181 181
 			array(
@@ -184,16 +184,16 @@  discard block
 block discarded – undo
184 184
 				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
185 185
 			)
186 186
 		);
187
-		if ( $which_to_include === 'old' ) {
187
+		if ($which_to_include === 'old') {
188 188
 			$cron_tasks = array_filter(
189 189
 				$cron_tasks,
190
-				function ( $value ) {
190
+				function($value) {
191 191
 					return $value === EEH_Activation::cron_task_no_longer_in_use;
192 192
 				}
193 193
 			);
194
-		} elseif ( $which_to_include === 'current' ) {
195
-			$cron_tasks = array_filter( $cron_tasks );
196
-		} elseif ( WP_DEBUG && $which_to_include !== 'all' ) {
194
+		} elseif ($which_to_include === 'current') {
195
+			$cron_tasks = array_filter($cron_tasks);
196
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
197 197
 			throw new EE_Error(
198 198
 				sprintf(
199 199
 					__(
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
 	 */
217 217
 	public static function create_cron_tasks() {
218 218
 
219
-		foreach( EEH_Activation::get_cron_tasks( 'current' ) as $hook_name => $frequency ) {
220
-			if( ! wp_next_scheduled( $hook_name ) ) {
221
-				wp_schedule_event( time(), $frequency, $hook_name );
219
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
220
+			if ( ! wp_next_scheduled($hook_name)) {
221
+				wp_schedule_event(time(), $frequency, $hook_name);
222 222
 			}
223 223
 		}
224 224
 
@@ -232,10 +232,10 @@  discard block
 block discarded – undo
232 232
 	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
233 233
 	 * @throws \EE_Error
234 234
 	 */
235
-	public static function remove_cron_tasks( $remove_all = true ) {
235
+	public static function remove_cron_tasks($remove_all = true) {
236 236
 		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
237 237
 		$crons = _get_cron_array();
238
-		$crons = is_array( $crons ) ? $crons : array();
238
+		$crons = is_array($crons) ? $crons : array();
239 239
 		/* reminder of what $crons look like:
240 240
 		 * Top-level keys are timestamps, and their values are arrays.
241 241
 		 * The 2nd level arrays have keys with each of the cron task hook names to run at that time
@@ -253,23 +253,23 @@  discard block
 block discarded – undo
253 253
 		 *					...
254 254
 		 *      ...
255 255
 		 */
256
-		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks( $cron_tasks_to_remove );
257
-		foreach ( $crons as $timestamp => $hooks_to_fire_at_time ) {
258
-			if ( is_array( $hooks_to_fire_at_time ) ) {
259
-				foreach ( $hooks_to_fire_at_time as $hook_name => $hook_actions ) {
260
-					if ( isset( $ee_cron_tasks_to_remove[ $hook_name ] )
261
-					     && is_array( $ee_cron_tasks_to_remove[ $hook_name ] )
256
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
257
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
258
+			if (is_array($hooks_to_fire_at_time)) {
259
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
260
+					if (isset($ee_cron_tasks_to_remove[$hook_name])
261
+					     && is_array($ee_cron_tasks_to_remove[$hook_name])
262 262
 					) {
263
-						unset( $crons[ $timestamp ][ $hook_name ] );
263
+						unset($crons[$timestamp][$hook_name]);
264 264
 					}
265 265
 				}
266 266
 				//also take care of any empty cron timestamps.
267
-				if ( empty( $hooks_to_fire_at_time ) ) {
268
-					unset( $crons[ $timestamp ] );
267
+				if (empty($hooks_to_fire_at_time)) {
268
+					unset($crons[$timestamp]);
269 269
 				}
270 270
 			}
271 271
 		}
272
-		_set_cron_array( $crons );
272
+		_set_cron_array($crons);
273 273
 	}
274 274
 
275 275
 
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 	 */
285 285
 	public static function CPT_initialization() {
286 286
 		// register Custom Post Types
287
-		EE_Registry::instance()->load_core( 'Register_CPTs' );
287
+		EE_Registry::instance()->load_core('Register_CPTs');
288 288
 		flush_rewrite_rules();
289 289
 	}
290 290
 
@@ -320,28 +320,28 @@  discard block
 block discarded – undo
320 320
 	 */
321 321
 	public static function load_calendar_config() {
322 322
 		// grab array of all plugin folders and loop thru it
323
-		$plugins = glob( WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR );
324
-		if ( empty( $plugins ) ) {
323
+		$plugins = glob(WP_PLUGIN_DIR.DS.'*', GLOB_ONLYDIR);
324
+		if (empty($plugins)) {
325 325
 			return;
326 326
 		}
327
-		foreach ( $plugins as $plugin_path ) {
327
+		foreach ($plugins as $plugin_path) {
328 328
 			// grab plugin folder name from path
329
-			$plugin = basename( $plugin_path );
329
+			$plugin = basename($plugin_path);
330 330
 			// drill down to Espresso plugins
331 331
 			// then to calendar related plugins
332 332
 			if (
333
-				strpos( $plugin, 'espresso' ) !== FALSE
334
-				|| strpos( $plugin, 'Espresso' ) !== FALSE
335
-				|| strpos( $plugin, 'ee4' ) !== FALSE
336
-				|| strpos( $plugin, 'EE4' ) !== FALSE
337
-				|| strpos( $plugin, 'calendar' ) !== false
333
+				strpos($plugin, 'espresso') !== FALSE
334
+				|| strpos($plugin, 'Espresso') !== FALSE
335
+				|| strpos($plugin, 'ee4') !== FALSE
336
+				|| strpos($plugin, 'EE4') !== FALSE
337
+				|| strpos($plugin, 'calendar') !== false
338 338
 			) {
339 339
 				// this is what we are looking for
340
-				$calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
340
+				$calendar_config = $plugin_path.DS.'EE_Calendar_Config.php';
341 341
 				// does it exist in this folder ?
342
-				if ( is_readable( $calendar_config )) {
342
+				if (is_readable($calendar_config)) {
343 343
 					// YEAH! let's load it
344
-					require_once( $calendar_config );
344
+					require_once($calendar_config);
345 345
 				}
346 346
 			}
347 347
 		}
@@ -389,8 +389,8 @@  discard block
 block discarded – undo
389 389
 	 */
390 390
 	public static function deactivate_event_espresso() {
391 391
 		// check permissions
392
-		if ( current_user_can( 'activate_plugins' )) {
393
-			deactivate_plugins( EE_PLUGIN_BASENAME, TRUE );
392
+		if (current_user_can('activate_plugins')) {
393
+			deactivate_plugins(EE_PLUGIN_BASENAME, TRUE);
394 394
 		}
395 395
 	}
396 396
 
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
     public static function get_page_by_ee_shortcode($ee_shortcode)
514 514
     {
515 515
         global $wpdb;
516
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
516
+        $shortcode_and_opening_bracket = '['.$ee_shortcode;
517 517
         $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
518 518
         if ($post_id) {
519 519
             return get_post($post_id);
@@ -533,32 +533,32 @@  discard block
 block discarded – undo
533 533
 	 * @param array $critical_page
534 534
 	 * @return array
535 535
 	 */
536
-	public static function create_critical_page( $critical_page ) {
536
+	public static function create_critical_page($critical_page) {
537 537
 
538 538
 		$post_args = array(
539 539
 			'post_title' => $critical_page['name'],
540 540
 			'post_status' => 'publish',
541 541
 			'post_type' => 'page',
542 542
 			'comment_status' => 'closed',
543
-			'post_content' => '[' . $critical_page['code'] . ']'
543
+			'post_content' => '['.$critical_page['code'].']'
544 544
 		);
545 545
 
546
-		$post_id = wp_insert_post( $post_args );
547
-		if ( ! $post_id ) {
546
+		$post_id = wp_insert_post($post_args);
547
+		if ( ! $post_id) {
548 548
 			$msg = sprintf(
549
-				__( 'The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso' ),
549
+				__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
550 550
 				$critical_page['name']
551 551
 			);
552
-			EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
552
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
553 553
 			return $critical_page;
554 554
 		}
555 555
 		// get newly created post's details
556
-		if ( ! $critical_page['post'] = get_post( $post_id )) {
556
+		if ( ! $critical_page['post'] = get_post($post_id)) {
557 557
 			$msg = sprintf(
558
-				__( 'The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso' ),
558
+				__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
559 559
 				$critical_page['name']
560 560
 			);
561
-			EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
561
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
562 562
 		}
563 563
 
564 564
 		return $critical_page;
@@ -633,15 +633,15 @@  discard block
 block discarded – undo
633 633
         $pre_filtered_id = apply_filters('FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', false,
634 634
             $role_to_check);
635 635
         if ($pre_filtered_id !== false) {
636
-            return (int)$pre_filtered_id;
636
+            return (int) $pre_filtered_id;
637 637
         }
638 638
         $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
639 639
         $query = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
640
-            '%' . $role_to_check . '%');
640
+            '%'.$role_to_check.'%');
641 641
         $user_id = $wpdb->get_var($query);
642 642
         $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
643
-        if ($user_id && (int)$user_id) {
644
-            self::$_default_creator_id = (int)$user_id;
643
+        if ($user_id && (int) $user_id) {
644
+            self::$_default_creator_id = (int) $user_id;
645 645
             return self::$_default_creator_id;
646 646
         } else {
647 647
             return null;
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
         }
677 677
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
678 678
         if ( ! function_exists('dbDelta')) {
679
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
679
+            require_once(ABSPATH.'wp-admin/includes/upgrade.php');
680 680
         }
681 681
         $tableAnalysis = \EEH_Activation::getTableAnalysis();
682 682
         $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
@@ -739,8 +739,8 @@  discard block
 block discarded – undo
739 739
 	 * @param string $table_name, without prefixed $wpdb->prefix
740 740
 	 * @return array of database column names
741 741
 	 */
742
-	public static function get_fields_on_table( $table_name = NULL ) {
743
-		return \EEH_Activation::getTableManager()->getTableColumns( $table_name );
742
+	public static function get_fields_on_table($table_name = NULL) {
743
+		return \EEH_Activation::getTableManager()->getTableColumns($table_name);
744 744
 	}
745 745
 
746 746
 
@@ -754,8 +754,8 @@  discard block
 block discarded – undo
754 754
 	 * @param string $table_name
755 755
 	 * @return bool
756 756
 	 */
757
-	public static function db_table_is_empty( $table_name ) {
758
-		return \EEH_Activation::getTableAnalysis()->tableIsEmpty( $table_name );
757
+	public static function db_table_is_empty($table_name) {
758
+		return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
759 759
 }
760 760
 
761 761
 
@@ -768,9 +768,9 @@  discard block
 block discarded – undo
768 768
 	 * @param string $table_name
769 769
 	 * @return bool | int
770 770
 	 */
771
-	public static function delete_db_table_if_empty( $table_name ) {
772
-		if ( \EEH_Activation::getTableAnalysis()->tableIsEmpty( $table_name ) ) {
773
-			return \EEH_Activation::getTableManager()->dropTable( $table_name );
771
+	public static function delete_db_table_if_empty($table_name) {
772
+		if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
773
+			return \EEH_Activation::getTableManager()->dropTable($table_name);
774 774
 		}
775 775
 		return false;
776 776
 	}
@@ -786,8 +786,8 @@  discard block
 block discarded – undo
786 786
 	 * @param string $table_name
787 787
 	 * @return bool | int
788 788
 	 */
789
-	public static function delete_unused_db_table( $table_name ) {
790
-		return \EEH_Activation::getTableManager()->dropTable( $table_name );
789
+	public static function delete_unused_db_table($table_name) {
790
+		return \EEH_Activation::getTableManager()->dropTable($table_name);
791 791
 	}
792 792
 
793 793
 
@@ -802,8 +802,8 @@  discard block
 block discarded – undo
802 802
 	 * @param string $index_name
803 803
 	 * @return bool | int
804 804
 	 */
805
-	public static function drop_index( $table_name, $index_name ) {
806
-		return \EEH_Activation::getTableManager()->dropIndex( $table_name, $index_name );
805
+	public static function drop_index($table_name, $index_name) {
806
+		return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
807 807
 	}
808 808
 
809 809
 
@@ -878,7 +878,7 @@  discard block
 block discarded – undo
878 878
                     case 1:
879 879
                         $QSG_values = array(
880 880
                             'QSG_name'            => __('Personal Information', 'event_espresso'),
881
-                            'QSG_identifier'      => 'personal-information-' . time(),
881
+                            'QSG_identifier'      => 'personal-information-'.time(),
882 882
                             'QSG_desc'            => '',
883 883
                             'QSG_order'           => 1,
884 884
                             'QSG_show_group_name' => 1,
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
                     case 2:
891 891
                         $QSG_values = array(
892 892
                             'QSG_name'            => __('Address Information', 'event_espresso'),
893
-                            'QSG_identifier'      => 'address-information-' . time(),
893
+                            'QSG_identifier'      => 'address-information-'.time(),
894 894
                             'QSG_desc'            => '',
895 895
                             'QSG_order'           => 2,
896 896
                             'QSG_show_group_name' => 1,
@@ -1155,11 +1155,11 @@  discard block
 block discarded – undo
1155 1155
 	 *
1156 1156
 	 * @throws \EE_Error
1157 1157
 	 */
1158
-	public static function insert_default_payment_methods(){
1159
-		if( ! EEM_Payment_Method::instance()->count_active( EEM_Payment_Method::scope_cart ) ){
1160
-			EE_Registry::instance()->load_lib( 'Payment_Method_Manager' );
1161
-			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type( 'Invoice' );
1162
-		}else{
1158
+	public static function insert_default_payment_methods() {
1159
+		if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1160
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1161
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1162
+		} else {
1163 1163
 			EEM_Payment_Method::instance()->verify_button_urls();
1164 1164
 		}
1165 1165
 	}
@@ -1175,7 +1175,7 @@  discard block
 block discarded – undo
1175 1175
 
1176 1176
 		global $wpdb;
1177 1177
 
1178
-		if ( \EEH_Activation::getTableAnalysis()->tableExists( EEM_Status::instance()->table() ) ) {
1178
+		if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1179 1179
 
1180 1180
 			$table_name = EEM_Status::instance()->table();
1181 1181
 
@@ -1251,33 +1251,33 @@  discard block
 block discarded – undo
1251 1251
 		$folders = array(
1252 1252
 				EVENT_ESPRESSO_TEMPLATE_DIR,
1253 1253
 				EVENT_ESPRESSO_GATEWAY_DIR,
1254
-				EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1255
-				EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1256
-				EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/'
1254
+				EVENT_ESPRESSO_UPLOAD_DIR.'logs/',
1255
+				EVENT_ESPRESSO_UPLOAD_DIR.'css/',
1256
+				EVENT_ESPRESSO_UPLOAD_DIR.'tickets/'
1257 1257
 		);
1258
-		foreach ( $folders as $folder ) {
1258
+		foreach ($folders as $folder) {
1259 1259
 			try {
1260
-				EEH_File::ensure_folder_exists_and_is_writable( $folder );
1261
-				@ chmod( $folder, 0755 );
1262
-			} catch( EE_Error $e ){
1260
+				EEH_File::ensure_folder_exists_and_is_writable($folder);
1261
+				@ chmod($folder, 0755);
1262
+			} catch (EE_Error $e) {
1263 1263
 				EE_Error::add_error(
1264 1264
 					sprintf(
1265
-						__(  'Could not create the folder at "%1$s" because: %2$s', 'event_espresso' ),
1265
+						__('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1266 1266
 						$folder,
1267
-						'<br />' . $e->getMessage()
1267
+						'<br />'.$e->getMessage()
1268 1268
 					),
1269 1269
 					__FILE__, __FUNCTION__, __LINE__
1270 1270
 				);
1271 1271
 				//indicate we'll need to fix this later
1272
-				update_option( EEH_Activation::upload_directories_incomplete_option_name, true );
1272
+				update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1273 1273
 				return FALSE;
1274 1274
 			}
1275 1275
 		}
1276 1276
 		//just add the .htaccess file to the logs directory to begin with. Even if logging
1277 1277
 		//is disabled, there might be activation errors recorded in there
1278
-		EEH_File::add_htaccess_deny_from_all( EVENT_ESPRESSO_UPLOAD_DIR . 'logs/' );
1278
+		EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs/');
1279 1279
 		//remember EE's folders are all good
1280
-		delete_option( EEH_Activation::upload_directories_incomplete_option_name );
1280
+		delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1281 1281
 		return TRUE;
1282 1282
 	}
1283 1283
 
@@ -1290,7 +1290,7 @@  discard block
 block discarded – undo
1290 1290
 	 * @return boolean
1291 1291
 	 */
1292 1292
 	public static function upload_directories_incomplete() {
1293
-		return get_option( EEH_Activation::upload_directories_incomplete_option_name, false );
1293
+		return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1294 1294
 	}
1295 1295
 
1296 1296
 
@@ -1307,7 +1307,7 @@  discard block
 block discarded – undo
1307 1307
 	 */
1308 1308
 	public static function generate_default_message_templates() {
1309 1309
 		/** @type EE_Message_Resource_Manager $message_resource_manager */
1310
-		$message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' );
1310
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1311 1311
 		/*
1312 1312
 		 * This first method is taking care of ensuring any default messengers
1313 1313
 		 * that should be made active and have templates generated are done.
@@ -1457,18 +1457,18 @@  discard block
 block discarded – undo
1457 1457
 		$has_activated = $message_resource_manager->get_has_activated_messengers_option();
1458 1458
 
1459 1459
 		$messengers_to_generate = array();
1460
-		foreach ( $installed_messengers as $installed_messenger ) {
1460
+		foreach ($installed_messengers as $installed_messenger) {
1461 1461
 			//if installed messenger is a messenger that should be activated on install
1462 1462
 			//and is not already active
1463 1463
 			//and has never been activated
1464 1464
 			if (
1465 1465
 				! $installed_messenger->activate_on_install
1466
-				|| isset( $active_messengers[ $installed_messenger->name ] )
1467
-				|| isset( $has_activated[ $installed_messenger->name ] )
1466
+				|| isset($active_messengers[$installed_messenger->name])
1467
+				|| isset($has_activated[$installed_messenger->name])
1468 1468
 			) {
1469 1469
 				continue;
1470 1470
 			}
1471
-			$messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1471
+			$messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1472 1472
 		}
1473 1473
 		return $messengers_to_generate;
1474 1474
 	}
@@ -1493,9 +1493,9 @@  discard block
 block discarded – undo
1493 1493
 	 */
1494 1494
 	public static function validate_messages_system() {
1495 1495
 		/** @type EE_Message_Resource_Manager $message_resource_manager */
1496
-		$message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' );
1496
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1497 1497
 		$message_resource_manager->validate_active_message_types_are_installed();
1498
-		do_action( 'AHEE__EEH_Activation__validate_messages_system' );
1498
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1499 1499
 	}
1500 1500
 
1501 1501
 
@@ -1508,12 +1508,12 @@  discard block
 block discarded – undo
1508 1508
 	 * 	@static
1509 1509
 	 * 	@return void
1510 1510
 	 */
1511
-	public static function create_no_ticket_prices_array(){
1511
+	public static function create_no_ticket_prices_array() {
1512 1512
 		// this creates an array for tracking events that have no active ticket prices created
1513 1513
 		// this allows us to warn admins of the situation so that it can be corrected
1514
-		$espresso_no_ticket_prices = get_option( 'ee_no_ticket_prices', FALSE );
1515
-		if ( ! $espresso_no_ticket_prices ) {
1516
-			add_option( 'ee_no_ticket_prices', array(), '', FALSE );
1514
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', FALSE);
1515
+		if ( ! $espresso_no_ticket_prices) {
1516
+			add_option('ee_no_ticket_prices', array(), '', FALSE);
1517 1517
 		}
1518 1518
 	}
1519 1519
 
@@ -1538,24 +1538,24 @@  discard block
 block discarded – undo
1538 1538
 	 * @global wpdb $wpdb
1539 1539
 	 * @throws \EE_Error
1540 1540
 	 */
1541
-	public static function delete_all_espresso_cpt_data(){
1541
+	public static function delete_all_espresso_cpt_data() {
1542 1542
 		global $wpdb;
1543 1543
 		//get all the CPT post_types
1544 1544
 		$ee_post_types = array();
1545
-		foreach(EE_Registry::instance()->non_abstract_db_models as $model_name){
1546
-			if ( method_exists( $model_name, 'instance' )) {
1547
-				$model_obj = call_user_func( array( $model_name, 'instance' ));
1548
-				if ( $model_obj instanceof EEM_CPT_Base ) {
1549
-					$ee_post_types[] = $wpdb->prepare("%s",$model_obj->post_type());
1545
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1546
+			if (method_exists($model_name, 'instance')) {
1547
+				$model_obj = call_user_func(array($model_name, 'instance'));
1548
+				if ($model_obj instanceof EEM_CPT_Base) {
1549
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1550 1550
 				}
1551 1551
 			}
1552 1552
 		}
1553 1553
 		//get all our CPTs
1554
-		$query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",",$ee_post_types).")";
1554
+		$query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")";
1555 1555
 		$cpt_ids = $wpdb->get_col($query);
1556 1556
 		//delete each post meta and term relations too
1557
-		foreach($cpt_ids as $post_id){
1558
-			wp_delete_post($post_id,true);
1557
+		foreach ($cpt_ids as $post_id) {
1558
+			wp_delete_post($post_id, true);
1559 1559
 		}
1560 1560
 	}
1561 1561
 
@@ -1567,12 +1567,12 @@  discard block
 block discarded – undo
1567 1567
 	public static function drop_espresso_tables() {
1568 1568
 		$tables = array();
1569 1569
 		// load registry
1570
-		foreach( EE_Registry::instance()->non_abstract_db_models as $model_name ){
1571
-			if ( method_exists( $model_name, 'instance' )) {
1572
-				$model_obj = call_user_func( array( $model_name, 'instance' ));
1573
-				if ( $model_obj instanceof EEM_Base ) {
1574
-					foreach ( $model_obj->get_tables() as $table ) {
1575
-						if ( strpos( $table->get_table_name(), 'esp_' )
1570
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1571
+			if (method_exists($model_name, 'instance')) {
1572
+				$model_obj = call_user_func(array($model_name, 'instance'));
1573
+				if ($model_obj instanceof EEM_Base) {
1574
+					foreach ($model_obj->get_tables() as $table) {
1575
+						if (strpos($table->get_table_name(), 'esp_')
1576 1576
 							&&
1577 1577
 							(
1578 1578
 								is_main_site()//main site? nuke them all
@@ -1595,10 +1595,10 @@  discard block
 block discarded – undo
1595 1595
 			'esp_promotion_rule',
1596 1596
 			'esp_rule'
1597 1597
 		);
1598
-		foreach( $tables_without_models as $table ){
1598
+		foreach ($tables_without_models as $table) {
1599 1599
 			$tables[] = $table;
1600 1600
 		}
1601
-		return \EEH_Activation::getTableManager()->dropTables( $tables );
1601
+		return \EEH_Activation::getTableManager()->dropTables($tables);
1602 1602
 	}
1603 1603
 
1604 1604
 
@@ -1690,7 +1690,7 @@  discard block
 block discarded – undo
1690 1690
         if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1691 1691
             $db_update_sans_ee4 = array();
1692 1692
             foreach ($espresso_db_update as $version => $times_activated) {
1693
-                if ((string)$version[0] === '3') {//if its NON EE4
1693
+                if ((string) $version[0] === '3') {//if its NON EE4
1694 1694
                     $db_update_sans_ee4[$version] = $times_activated;
1695 1695
                 }
1696 1696
             }
@@ -1715,10 +1715,10 @@  discard block
 block discarded – undo
1715 1715
 	 */
1716 1716
 	public static function last_wpdb_error_code() {
1717 1717
 		global $wpdb;
1718
-		if( $wpdb->use_mysqli ) {
1719
-			return mysqli_errno( $wpdb->dbh );
1718
+		if ($wpdb->use_mysqli) {
1719
+			return mysqli_errno($wpdb->dbh);
1720 1720
 		} else {
1721
-			return mysql_errno( $wpdb->dbh );
1721
+			return mysql_errno($wpdb->dbh);
1722 1722
 		}
1723 1723
 	}
1724 1724
 
@@ -1729,14 +1729,14 @@  discard block
 block discarded – undo
1729 1729
 	 * @param string $table_name with or without $wpdb->prefix
1730 1730
 	 * @return boolean
1731 1731
 	 */
1732
-	public static function table_exists( $table_name ){
1733
-		return \EEH_Activation::getTableAnalysis()->tableExists( $table_name );
1732
+	public static function table_exists($table_name) {
1733
+		return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1734 1734
 	}
1735 1735
 
1736 1736
 	/**
1737 1737
 	 * Resets the cache on EEH_Activation
1738 1738
 	 */
1739
-	public static function reset(){
1739
+	public static function reset() {
1740 1740
 		self::$_default_creator_id = NULL;
1741 1741
 		self::$_initialized_db_content_already_in_this_request = false;
1742 1742
 	}
Please login to merge, or discard this patch.
Indentation   +917 added lines, -917 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -14,36 +14,36 @@  discard block
 block discarded – undo
14 14
 class EEH_Activation
15 15
 {
16 16
 
17
-    /**
18
-     * constant used to indicate a cron task is no longer in use
19
-     */
20
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
21
-
22
-    /**
23
-     * option name that will indicate whether or not we still
24
-     * need to create EE's folders in the uploads directory
25
-     * (because if EE was installed without file system access,
26
-     * we need to request credentials before we can create them)
27
-     */
28
-    const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
29
-
30
-    /**
31
-     * WP_User->ID
32
-     *
33
-     * @var int
34
-     */
35
-    private static $_default_creator_id;
36
-
37
-    /**
38
-     * indicates whether or not we've already verified core's default data during this request,
39
-     * because after migrations are done, any addons activated while in maintenance mode
40
-     * will want to setup their own default data, and they might hook into core's default data
41
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
42
-     * This prevents doing that for EVERY single addon.
43
-     *
44
-     * @var boolean
45
-     */
46
-    protected static $_initialized_db_content_already_in_this_request = false;
17
+	/**
18
+	 * constant used to indicate a cron task is no longer in use
19
+	 */
20
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
21
+
22
+	/**
23
+	 * option name that will indicate whether or not we still
24
+	 * need to create EE's folders in the uploads directory
25
+	 * (because if EE was installed without file system access,
26
+	 * we need to request credentials before we can create them)
27
+	 */
28
+	const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
29
+
30
+	/**
31
+	 * WP_User->ID
32
+	 *
33
+	 * @var int
34
+	 */
35
+	private static $_default_creator_id;
36
+
37
+	/**
38
+	 * indicates whether or not we've already verified core's default data during this request,
39
+	 * because after migrations are done, any addons activated while in maintenance mode
40
+	 * will want to setup their own default data, and they might hook into core's default data
41
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
42
+	 * This prevents doing that for EVERY single addon.
43
+	 *
44
+	 * @var boolean
45
+	 */
46
+	protected static $_initialized_db_content_already_in_this_request = false;
47 47
 
48 48
 	/**
49 49
 	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 			if ( is_array( $hooks_to_fire_at_time ) ) {
259 259
 				foreach ( $hooks_to_fire_at_time as $hook_name => $hook_actions ) {
260 260
 					if ( isset( $ee_cron_tasks_to_remove[ $hook_name ] )
261
-					     && is_array( $ee_cron_tasks_to_remove[ $hook_name ] )
261
+						 && is_array( $ee_cron_tasks_to_remove[ $hook_name ] )
262 262
 					) {
263 263
 						unset( $crons[ $timestamp ][ $hook_name ] );
264 264
 					}
@@ -290,26 +290,26 @@  discard block
 block discarded – undo
290 290
 
291 291
 
292 292
 
293
-    /**
294
-     *    reset_and_update_config
295
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
296
-     * If there is old calendar config data saved, then it will get converted on activation.
297
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
298
-     *
299
-     * @access public
300
-     * @static
301
-     * @return void
302
-     */
303
-    public static function reset_and_update_config()
304
-    {
305
-        do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
306
-        add_filter('FHEE__EE_Config___load_core_config__config_settings',
307
-            array('EEH_Activation', 'migrate_old_config_data'), 10, 3);
308
-        //EE_Config::reset();
309
-        if ( ! EE_Config::logging_enabled()) {
310
-            delete_option(EE_Config::LOG_NAME);
311
-        }
312
-    }
293
+	/**
294
+	 *    reset_and_update_config
295
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
296
+	 * If there is old calendar config data saved, then it will get converted on activation.
297
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
298
+	 *
299
+	 * @access public
300
+	 * @static
301
+	 * @return void
302
+	 */
303
+	public static function reset_and_update_config()
304
+	{
305
+		do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
306
+		add_filter('FHEE__EE_Config___load_core_config__config_settings',
307
+			array('EEH_Activation', 'migrate_old_config_data'), 10, 3);
308
+		//EE_Config::reset();
309
+		if ( ! EE_Config::logging_enabled()) {
310
+			delete_option(EE_Config::LOG_NAME);
311
+		}
312
+	}
313 313
 
314 314
 
315 315
 	/**
@@ -349,34 +349,34 @@  discard block
 block discarded – undo
349 349
 
350 350
 
351 351
 
352
-    /**
353
-     *    _migrate_old_config_data
354
-     *
355
-     * @access    public
356
-     * @param array|stdClass $settings
357
-     * @param string         $config
358
-     * @param \EE_Config     $EE_Config
359
-     * @return \stdClass
360
-     */
361
-    public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
362
-    {
363
-        $convert_from_array = array('addons');
364
-        // in case old settings were saved as an array
365
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
366
-            // convert existing settings to an object
367
-            $config_array = $settings;
368
-            $settings = new stdClass();
369
-            foreach ($config_array as $key => $value) {
370
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
371
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
372
-                } else {
373
-                    $settings->{$key} = $value;
374
-                }
375
-            }
376
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
377
-        }
378
-        return $settings;
379
-    }
352
+	/**
353
+	 *    _migrate_old_config_data
354
+	 *
355
+	 * @access    public
356
+	 * @param array|stdClass $settings
357
+	 * @param string         $config
358
+	 * @param \EE_Config     $EE_Config
359
+	 * @return \stdClass
360
+	 */
361
+	public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
362
+	{
363
+		$convert_from_array = array('addons');
364
+		// in case old settings were saved as an array
365
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
366
+			// convert existing settings to an object
367
+			$config_array = $settings;
368
+			$settings = new stdClass();
369
+			foreach ($config_array as $key => $value) {
370
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
371
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
372
+				} else {
373
+					$settings->{$key} = $value;
374
+				}
375
+			}
376
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
377
+		}
378
+		return $settings;
379
+	}
380 380
 
381 381
 
382 382
 
@@ -398,130 +398,130 @@  discard block
 block discarded – undo
398 398
 
399 399
 
400 400
 
401
-    /**
402
-     * verify_default_pages_exist
403
-     *
404
-     * @access public
405
-     * @static
406
-     * @return void
407
-     */
408
-    public static function verify_default_pages_exist()
409
-    {
410
-        $critical_page_problem = false;
411
-        $critical_pages = array(
412
-            array(
413
-                'id'   => 'reg_page_id',
414
-                'name' => __('Registration Checkout', 'event_espresso'),
415
-                'post' => null,
416
-                'code' => 'ESPRESSO_CHECKOUT',
417
-            ),
418
-            array(
419
-                'id'   => 'txn_page_id',
420
-                'name' => __('Transactions', 'event_espresso'),
421
-                'post' => null,
422
-                'code' => 'ESPRESSO_TXN_PAGE',
423
-            ),
424
-            array(
425
-                'id'   => 'thank_you_page_id',
426
-                'name' => __('Thank You', 'event_espresso'),
427
-                'post' => null,
428
-                'code' => 'ESPRESSO_THANK_YOU',
429
-            ),
430
-            array(
431
-                'id'   => 'cancel_page_id',
432
-                'name' => __('Registration Cancelled', 'event_espresso'),
433
-                'post' => null,
434
-                'code' => 'ESPRESSO_CANCELLED',
435
-            ),
436
-        );
437
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
438
-        foreach ($critical_pages as $critical_page) {
439
-            // is critical page ID set in config ?
440
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
441
-                // attempt to find post by ID
442
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
443
-            }
444
-            // no dice?
445
-            if ($critical_page['post'] === null) {
446
-                // attempt to find post by title
447
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
448
-                // still nothing?
449
-                if ($critical_page['post'] === null) {
450
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
451
-                    // REALLY? Still nothing ??!?!?
452
-                    if ($critical_page['post'] === null) {
453
-                        $msg = __('The Event Espresso critical page configuration settings could not be updated.',
454
-                            'event_espresso');
455
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
456
-                        break;
457
-                    }
458
-                }
459
-            }
460
-            // track post_shortcodes
461
-            if ($critical_page['post']) {
462
-                EEH_Activation::_track_critical_page_post_shortcodes($critical_page);
463
-            }
464
-            // check that Post ID matches critical page ID in config
465
-            if (
466
-                isset($critical_page['post']->ID)
467
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
468
-            ) {
469
-                //update Config with post ID
470
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
471
-                if ( ! EE_Config::instance()->update_espresso_config(false, false)) {
472
-                    $msg = __('The Event Espresso critical page configuration settings could not be updated.',
473
-                        'event_espresso');
474
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
475
-                }
476
-            }
477
-            $critical_page_problem =
478
-                ! isset($critical_page['post']->post_status)
479
-                || $critical_page['post']->post_status !== 'publish'
480
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
481
-                    ? true
482
-                    : $critical_page_problem;
483
-        }
484
-        if ($critical_page_problem) {
485
-            $msg = sprintf(
486
-                __('A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
487
-                    'event_espresso'),
488
-                '<a href="'
489
-                . admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
490
-                . '">'
491
-                . __('Event Espresso Critical Pages Settings', 'event_espresso')
492
-                . '</a>'
493
-            );
494
-            EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
495
-        }
496
-        if (EE_Error::has_notices()) {
497
-            EE_Error::get_notices(false, true, true);
498
-        }
499
-    }
500
-
501
-
502
-
503
-    /**
504
-     * Returns the first post which uses the specified shortcode
505
-     *
506
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
507
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
508
-     *                             "[ESPRESSO_THANK_YOU"
509
-     *                             (we don't search for the closing shortcode bracket because they might have added
510
-     *                             parameter to the shortcode
511
-     * @return WP_Post or NULl
512
-     */
513
-    public static function get_page_by_ee_shortcode($ee_shortcode)
514
-    {
515
-        global $wpdb;
516
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
517
-        $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
518
-        if ($post_id) {
519
-            return get_post($post_id);
520
-        } else {
521
-            return null;
522
-        }
401
+	/**
402
+	 * verify_default_pages_exist
403
+	 *
404
+	 * @access public
405
+	 * @static
406
+	 * @return void
407
+	 */
408
+	public static function verify_default_pages_exist()
409
+	{
410
+		$critical_page_problem = false;
411
+		$critical_pages = array(
412
+			array(
413
+				'id'   => 'reg_page_id',
414
+				'name' => __('Registration Checkout', 'event_espresso'),
415
+				'post' => null,
416
+				'code' => 'ESPRESSO_CHECKOUT',
417
+			),
418
+			array(
419
+				'id'   => 'txn_page_id',
420
+				'name' => __('Transactions', 'event_espresso'),
421
+				'post' => null,
422
+				'code' => 'ESPRESSO_TXN_PAGE',
423
+			),
424
+			array(
425
+				'id'   => 'thank_you_page_id',
426
+				'name' => __('Thank You', 'event_espresso'),
427
+				'post' => null,
428
+				'code' => 'ESPRESSO_THANK_YOU',
429
+			),
430
+			array(
431
+				'id'   => 'cancel_page_id',
432
+				'name' => __('Registration Cancelled', 'event_espresso'),
433
+				'post' => null,
434
+				'code' => 'ESPRESSO_CANCELLED',
435
+			),
436
+		);
437
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
438
+		foreach ($critical_pages as $critical_page) {
439
+			// is critical page ID set in config ?
440
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
441
+				// attempt to find post by ID
442
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
443
+			}
444
+			// no dice?
445
+			if ($critical_page['post'] === null) {
446
+				// attempt to find post by title
447
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
448
+				// still nothing?
449
+				if ($critical_page['post'] === null) {
450
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
451
+					// REALLY? Still nothing ??!?!?
452
+					if ($critical_page['post'] === null) {
453
+						$msg = __('The Event Espresso critical page configuration settings could not be updated.',
454
+							'event_espresso');
455
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
456
+						break;
457
+					}
458
+				}
459
+			}
460
+			// track post_shortcodes
461
+			if ($critical_page['post']) {
462
+				EEH_Activation::_track_critical_page_post_shortcodes($critical_page);
463
+			}
464
+			// check that Post ID matches critical page ID in config
465
+			if (
466
+				isset($critical_page['post']->ID)
467
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
468
+			) {
469
+				//update Config with post ID
470
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
471
+				if ( ! EE_Config::instance()->update_espresso_config(false, false)) {
472
+					$msg = __('The Event Espresso critical page configuration settings could not be updated.',
473
+						'event_espresso');
474
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
475
+				}
476
+			}
477
+			$critical_page_problem =
478
+				! isset($critical_page['post']->post_status)
479
+				|| $critical_page['post']->post_status !== 'publish'
480
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
481
+					? true
482
+					: $critical_page_problem;
483
+		}
484
+		if ($critical_page_problem) {
485
+			$msg = sprintf(
486
+				__('A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
487
+					'event_espresso'),
488
+				'<a href="'
489
+				. admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
490
+				. '">'
491
+				. __('Event Espresso Critical Pages Settings', 'event_espresso')
492
+				. '</a>'
493
+			);
494
+			EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
495
+		}
496
+		if (EE_Error::has_notices()) {
497
+			EE_Error::get_notices(false, true, true);
498
+		}
499
+	}
500
+
501
+
502
+
503
+	/**
504
+	 * Returns the first post which uses the specified shortcode
505
+	 *
506
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
507
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
508
+	 *                             "[ESPRESSO_THANK_YOU"
509
+	 *                             (we don't search for the closing shortcode bracket because they might have added
510
+	 *                             parameter to the shortcode
511
+	 * @return WP_Post or NULl
512
+	 */
513
+	public static function get_page_by_ee_shortcode($ee_shortcode)
514
+	{
515
+		global $wpdb;
516
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
517
+		$post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
518
+		if ($post_id) {
519
+			return get_post($post_id);
520
+		} else {
521
+			return null;
522
+		}
523 523
 //		return $post_id;
524
-    }
524
+	}
525 525
 
526 526
 
527 527
 
@@ -569,165 +569,165 @@  discard block
 block discarded – undo
569 569
 
570 570
 
571 571
 
572
-    /**
573
-     *    This function adds a critical page's shortcode to the post_shortcodes array
574
-     *
575
-     * @access private
576
-     * @static
577
-     * @param array $critical_page
578
-     * @return void
579
-     */
580
-    private static function _track_critical_page_post_shortcodes($critical_page = array())
581
-    {
582
-        // check the goods
583
-        if ( ! $critical_page['post'] instanceof WP_Post) {
584
-            $msg = sprintf(
585
-                __('The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.',
586
-                    'event_espresso'),
587
-                $critical_page['name']
588
-            );
589
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
590
-            return;
591
-        }
592
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
593
-        // map shortcode to post
594
-        $EE_Core_Config->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] = $critical_page['post']->ID;
595
-        // and make sure it's NOT added to the WP "Posts Page"
596
-        // name of the WP Posts Page
597
-        $posts_page = EE_Config::get_page_for_posts();
598
-        if (isset($EE_Core_Config->post_shortcodes[$posts_page])) {
599
-            unset($EE_Core_Config->post_shortcodes[$posts_page][$critical_page['code']]);
600
-        }
601
-        if ($posts_page !== 'posts' && isset($EE_Core_Config->post_shortcodes['posts'])) {
602
-            unset($EE_Core_Config->post_shortcodes['posts'][$critical_page['code']]);
603
-        }
604
-        // update post_shortcode CFG
605
-        if ( ! EE_Config::instance()->update_espresso_config(false, false)) {
606
-            $msg = sprintf(
607
-                __('The Event Espresso critical page shortcode for the %s page could not be configured properly.',
608
-                    'event_espresso'),
609
-                $critical_page['name']
610
-            );
611
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
612
-        }
613
-    }
614
-
615
-
616
-
617
-    /**
618
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
619
-     * The role being used to check is filterable.
620
-     *
621
-     * @since  4.6.0
622
-     * @global WPDB $wpdb
623
-     * @return mixed null|int WP_user ID or NULL
624
-     */
625
-    public static function get_default_creator_id()
626
-    {
627
-        global $wpdb;
628
-        if ( ! empty(self::$_default_creator_id)) {
629
-            return self::$_default_creator_id;
630
-        }/**/
631
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
632
-        //let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
633
-        $pre_filtered_id = apply_filters('FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', false,
634
-            $role_to_check);
635
-        if ($pre_filtered_id !== false) {
636
-            return (int)$pre_filtered_id;
637
-        }
638
-        $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
639
-        $query = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
640
-            '%' . $role_to_check . '%');
641
-        $user_id = $wpdb->get_var($query);
642
-        $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
643
-        if ($user_id && (int)$user_id) {
644
-            self::$_default_creator_id = (int)$user_id;
645
-            return self::$_default_creator_id;
646
-        } else {
647
-            return null;
648
-        }
649
-    }
650
-
651
-
652
-
653
-    /**
654
-     * used by EE and EE addons during plugin activation to create tables.
655
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
656
-     * but includes extra logic regarding activations.
657
-     *
658
-     * @access public
659
-     * @static
660
-     * @param string  $table_name              without the $wpdb->prefix
661
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
662
-     *                                         table query)
663
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
664
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
665
-     *                                         and new once this function is done (ie, you really do want to CREATE a
666
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
667
-     *                                         you just want to verify the table exists and matches this definition
668
-     *                                         (and if it HAS data in it you want to leave it be)
669
-     * @return void
670
-     * @throws EE_Error if there are database errors
671
-     */
672
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
673
-    {
674
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
675
-            return;
676
-        }
677
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
678
-        if ( ! function_exists('dbDelta')) {
679
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
680
-        }
681
-        $tableAnalysis = \EEH_Activation::getTableAnalysis();
682
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
683
-        // do we need to first delete an existing version of this table ?
684
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
685
-            // ok, delete the table... but ONLY if it's empty
686
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
687
-            // table is NOT empty, are you SURE you want to delete this table ???
688
-            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
689
-                \EEH_Activation::getTableManager()->dropTable($wp_table_name);
690
-            } else if ( ! $deleted_safely) {
691
-                // so we should be more cautious rather than just dropping tables so easily
692
-                error_log(
693
-                    sprintf(
694
-                        __(
695
-                            'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
696
-                            'event_espresso'
697
-                        ),
698
-                        $wp_table_name,
699
-                        '<br/>',
700
-                        'espresso_db_update'
701
-                    )
702
-                );
703
-            }
704
-        }
705
-        $engine = str_replace('ENGINE=', '', $engine);
706
-        \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     *    add_column_if_it_doesn't_exist
713
-     *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
714
-     *
715
-     * @access     public
716
-     * @static
717
-     * @deprecated instead use TableManager::addColumn()
718
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
719
-     * @param string $column_name
720
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
721
-     *                            'VARCHAR(10)'
722
-     * @return bool|int
723
-     */
724
-    public static function add_column_if_it_doesnt_exist(
725
-        $table_name,
726
-        $column_name,
727
-        $column_info = 'INT UNSIGNED NOT NULL'
728
-    ) {
729
-        return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
730
-    }
572
+	/**
573
+	 *    This function adds a critical page's shortcode to the post_shortcodes array
574
+	 *
575
+	 * @access private
576
+	 * @static
577
+	 * @param array $critical_page
578
+	 * @return void
579
+	 */
580
+	private static function _track_critical_page_post_shortcodes($critical_page = array())
581
+	{
582
+		// check the goods
583
+		if ( ! $critical_page['post'] instanceof WP_Post) {
584
+			$msg = sprintf(
585
+				__('The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.',
586
+					'event_espresso'),
587
+				$critical_page['name']
588
+			);
589
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
590
+			return;
591
+		}
592
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
593
+		// map shortcode to post
594
+		$EE_Core_Config->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] = $critical_page['post']->ID;
595
+		// and make sure it's NOT added to the WP "Posts Page"
596
+		// name of the WP Posts Page
597
+		$posts_page = EE_Config::get_page_for_posts();
598
+		if (isset($EE_Core_Config->post_shortcodes[$posts_page])) {
599
+			unset($EE_Core_Config->post_shortcodes[$posts_page][$critical_page['code']]);
600
+		}
601
+		if ($posts_page !== 'posts' && isset($EE_Core_Config->post_shortcodes['posts'])) {
602
+			unset($EE_Core_Config->post_shortcodes['posts'][$critical_page['code']]);
603
+		}
604
+		// update post_shortcode CFG
605
+		if ( ! EE_Config::instance()->update_espresso_config(false, false)) {
606
+			$msg = sprintf(
607
+				__('The Event Espresso critical page shortcode for the %s page could not be configured properly.',
608
+					'event_espresso'),
609
+				$critical_page['name']
610
+			);
611
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
612
+		}
613
+	}
614
+
615
+
616
+
617
+	/**
618
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
619
+	 * The role being used to check is filterable.
620
+	 *
621
+	 * @since  4.6.0
622
+	 * @global WPDB $wpdb
623
+	 * @return mixed null|int WP_user ID or NULL
624
+	 */
625
+	public static function get_default_creator_id()
626
+	{
627
+		global $wpdb;
628
+		if ( ! empty(self::$_default_creator_id)) {
629
+			return self::$_default_creator_id;
630
+		}/**/
631
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
632
+		//let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
633
+		$pre_filtered_id = apply_filters('FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', false,
634
+			$role_to_check);
635
+		if ($pre_filtered_id !== false) {
636
+			return (int)$pre_filtered_id;
637
+		}
638
+		$capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
639
+		$query = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
640
+			'%' . $role_to_check . '%');
641
+		$user_id = $wpdb->get_var($query);
642
+		$user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
643
+		if ($user_id && (int)$user_id) {
644
+			self::$_default_creator_id = (int)$user_id;
645
+			return self::$_default_creator_id;
646
+		} else {
647
+			return null;
648
+		}
649
+	}
650
+
651
+
652
+
653
+	/**
654
+	 * used by EE and EE addons during plugin activation to create tables.
655
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
656
+	 * but includes extra logic regarding activations.
657
+	 *
658
+	 * @access public
659
+	 * @static
660
+	 * @param string  $table_name              without the $wpdb->prefix
661
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
662
+	 *                                         table query)
663
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
664
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
665
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
666
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
667
+	 *                                         you just want to verify the table exists and matches this definition
668
+	 *                                         (and if it HAS data in it you want to leave it be)
669
+	 * @return void
670
+	 * @throws EE_Error if there are database errors
671
+	 */
672
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
673
+	{
674
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
675
+			return;
676
+		}
677
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
678
+		if ( ! function_exists('dbDelta')) {
679
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
680
+		}
681
+		$tableAnalysis = \EEH_Activation::getTableAnalysis();
682
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
683
+		// do we need to first delete an existing version of this table ?
684
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
685
+			// ok, delete the table... but ONLY if it's empty
686
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
687
+			// table is NOT empty, are you SURE you want to delete this table ???
688
+			if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
689
+				\EEH_Activation::getTableManager()->dropTable($wp_table_name);
690
+			} else if ( ! $deleted_safely) {
691
+				// so we should be more cautious rather than just dropping tables so easily
692
+				error_log(
693
+					sprintf(
694
+						__(
695
+							'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
696
+							'event_espresso'
697
+						),
698
+						$wp_table_name,
699
+						'<br/>',
700
+						'espresso_db_update'
701
+					)
702
+				);
703
+			}
704
+		}
705
+		$engine = str_replace('ENGINE=', '', $engine);
706
+		\EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 *    add_column_if_it_doesn't_exist
713
+	 *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
714
+	 *
715
+	 * @access     public
716
+	 * @static
717
+	 * @deprecated instead use TableManager::addColumn()
718
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
719
+	 * @param string $column_name
720
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
721
+	 *                            'VARCHAR(10)'
722
+	 * @return bool|int
723
+	 */
724
+	public static function add_column_if_it_doesnt_exist(
725
+		$table_name,
726
+		$column_name,
727
+		$column_info = 'INT UNSIGNED NOT NULL'
728
+	) {
729
+		return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
730
+	}
731 731
 
732 732
 
733 733
 
@@ -764,13 +764,13 @@  discard block
 block discarded – undo
764 764
 
765 765
 
766 766
 /**
767
-	 * delete_db_table_if_empty
768
-	 *
769
-	 * @access public
770
-	 * @static
771
-	 * @param string $table_name
772
-	 * @return bool | int
773
-	 */
767
+ * delete_db_table_if_empty
768
+ *
769
+ * @access public
770
+ * @static
771
+ * @param string $table_name
772
+ * @return bool | int
773
+ */
774 774
 	public static function delete_db_table_if_empty( $table_name ) {
775 775
 		if ( \EEH_Activation::getTableAnalysis()->tableIsEmpty( $table_name ) ) {
776 776
 			return \EEH_Activation::getTableManager()->dropTable( $table_name );
@@ -811,344 +811,344 @@  discard block
 block discarded – undo
811 811
 
812 812
 
813 813
 
814
-    /**
815
-     * create_database_tables
816
-     *
817
-     * @access public
818
-     * @static
819
-     * @throws EE_Error
820
-     * @return boolean success (whether database is setup properly or not)
821
-     */
822
-    public static function create_database_tables()
823
-    {
824
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
825
-        //find the migration script that sets the database to be compatible with the code
826
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
827
-        if ($dms_name) {
828
-            $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
829
-            $current_data_migration_script->set_migrating(false);
830
-            $current_data_migration_script->schema_changes_before_migration();
831
-            $current_data_migration_script->schema_changes_after_migration();
832
-            if ($current_data_migration_script->get_errors()) {
833
-                if (WP_DEBUG) {
834
-                    foreach ($current_data_migration_script->get_errors() as $error) {
835
-                        EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
836
-                    }
837
-                } else {
838
-                    EE_Error::add_error(__('There were errors creating the Event Espresso database tables and Event Espresso has been deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
839
-                        'event_espresso'));
840
-                }
841
-                return false;
842
-            }
843
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to();
844
-        } else {
845
-            EE_Error::add_error(__('Could not determine most up-to-date data migration script from which to pull database schema structure. So database is probably not setup properly',
846
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
847
-            return false;
848
-        }
849
-        return true;
850
-    }
851
-
852
-
853
-
854
-    /**
855
-     * initialize_system_questions
856
-     *
857
-     * @access public
858
-     * @static
859
-     * @return void
860
-     */
861
-    public static function initialize_system_questions()
862
-    {
863
-        // QUESTION GROUPS
864
-        global $wpdb;
865
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
866
-        $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
867
-        // what we have
868
-        $question_groups = $wpdb->get_col($SQL);
869
-        // check the response
870
-        $question_groups = is_array($question_groups) ? $question_groups : array();
871
-        // what we should have
872
-        $QSG_systems = array(1, 2);
873
-        // loop thru what we should have and compare to what we have
874
-        foreach ($QSG_systems as $QSG_system) {
875
-            // reset values array
876
-            $QSG_values = array();
877
-            // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
878
-            if ( ! in_array("$QSG_system", $question_groups)) {
879
-                // add it
880
-                switch ($QSG_system) {
881
-                    case 1:
882
-                        $QSG_values = array(
883
-                            'QSG_name'            => __('Personal Information', 'event_espresso'),
884
-                            'QSG_identifier'      => 'personal-information-' . time(),
885
-                            'QSG_desc'            => '',
886
-                            'QSG_order'           => 1,
887
-                            'QSG_show_group_name' => 1,
888
-                            'QSG_show_group_desc' => 1,
889
-                            'QSG_system'          => EEM_Question_Group::system_personal,
890
-                            'QSG_deleted'         => 0,
891
-                        );
892
-                        break;
893
-                    case 2:
894
-                        $QSG_values = array(
895
-                            'QSG_name'            => __('Address Information', 'event_espresso'),
896
-                            'QSG_identifier'      => 'address-information-' . time(),
897
-                            'QSG_desc'            => '',
898
-                            'QSG_order'           => 2,
899
-                            'QSG_show_group_name' => 1,
900
-                            'QSG_show_group_desc' => 1,
901
-                            'QSG_system'          => EEM_Question_Group::system_address,
902
-                            'QSG_deleted'         => 0,
903
-                        );
904
-                        break;
905
-                }
906
-                // make sure we have some values before inserting them
907
-                if ( ! empty($QSG_values)) {
908
-                    // insert system question
909
-                    $wpdb->insert(
910
-                        $table_name,
911
-                        $QSG_values,
912
-                        array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
913
-                    );
914
-                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
915
-                }
916
-            }
917
-        }
918
-        // QUESTIONS
919
-        global $wpdb;
920
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
921
-        $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
922
-        // what we have
923
-        $questions = $wpdb->get_col($SQL);
924
-        // what we should have
925
-        $QST_systems = array(
926
-            'fname',
927
-            'lname',
928
-            'email',
929
-            'address',
930
-            'address2',
931
-            'city',
932
-            'country',
933
-            'state',
934
-            'zip',
935
-            'phone',
936
-        );
937
-        $order_for_group_1 = 1;
938
-        $order_for_group_2 = 1;
939
-        // loop thru what we should have and compare to what we have
940
-        foreach ($QST_systems as $QST_system) {
941
-            // reset values array
942
-            $QST_values = array();
943
-            // if we don't have what we should have
944
-            if ( ! in_array($QST_system, $questions)) {
945
-                // add it
946
-                switch ($QST_system) {
947
-                    case 'fname':
948
-                        $QST_values = array(
949
-                            'QST_display_text'  => __('First Name', 'event_espresso'),
950
-                            'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
951
-                            'QST_system'        => 'fname',
952
-                            'QST_type'          => 'TEXT',
953
-                            'QST_required'      => 1,
954
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
955
-                            'QST_order'         => 1,
956
-                            'QST_admin_only'    => 0,
957
-                            'QST_max'           => EEM_Question::instance()
958
-                                                               ->absolute_max_for_system_question($QST_system),
959
-                            'QST_wp_user'       => self::get_default_creator_id(),
960
-                            'QST_deleted'       => 0,
961
-                        );
962
-                        break;
963
-                    case 'lname':
964
-                        $QST_values = array(
965
-                            'QST_display_text'  => __('Last Name', 'event_espresso'),
966
-                            'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
967
-                            'QST_system'        => 'lname',
968
-                            'QST_type'          => 'TEXT',
969
-                            'QST_required'      => 1,
970
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
971
-                            'QST_order'         => 2,
972
-                            'QST_admin_only'    => 0,
973
-                            'QST_max'           => EEM_Question::instance()
974
-                                                               ->absolute_max_for_system_question($QST_system),
975
-                            'QST_wp_user'       => self::get_default_creator_id(),
976
-                            'QST_deleted'       => 0,
977
-                        );
978
-                        break;
979
-                    case 'email':
980
-                        $QST_values = array(
981
-                            'QST_display_text'  => __('Email Address', 'event_espresso'),
982
-                            'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
983
-                            'QST_system'        => 'email',
984
-                            'QST_type'          => 'EMAIL',
985
-                            'QST_required'      => 1,
986
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
987
-                            'QST_order'         => 3,
988
-                            'QST_admin_only'    => 0,
989
-                            'QST_max'           => EEM_Question::instance()
990
-                                                               ->absolute_max_for_system_question($QST_system),
991
-                            'QST_wp_user'       => self::get_default_creator_id(),
992
-                            'QST_deleted'       => 0,
993
-                        );
994
-                        break;
995
-                    case 'address':
996
-                        $QST_values = array(
997
-                            'QST_display_text'  => __('Address', 'event_espresso'),
998
-                            'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
999
-                            'QST_system'        => 'address',
1000
-                            'QST_type'          => 'TEXT',
1001
-                            'QST_required'      => 0,
1002
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1003
-                            'QST_order'         => 4,
1004
-                            'QST_admin_only'    => 0,
1005
-                            'QST_max'           => EEM_Question::instance()
1006
-                                                               ->absolute_max_for_system_question($QST_system),
1007
-                            'QST_wp_user'       => self::get_default_creator_id(),
1008
-                            'QST_deleted'       => 0,
1009
-                        );
1010
-                        break;
1011
-                    case 'address2':
1012
-                        $QST_values = array(
1013
-                            'QST_display_text'  => __('Address2', 'event_espresso'),
1014
-                            'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1015
-                            'QST_system'        => 'address2',
1016
-                            'QST_type'          => 'TEXT',
1017
-                            'QST_required'      => 0,
1018
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1019
-                            'QST_order'         => 5,
1020
-                            'QST_admin_only'    => 0,
1021
-                            'QST_max'           => EEM_Question::instance()
1022
-                                                               ->absolute_max_for_system_question($QST_system),
1023
-                            'QST_wp_user'       => self::get_default_creator_id(),
1024
-                            'QST_deleted'       => 0,
1025
-                        );
1026
-                        break;
1027
-                    case 'city':
1028
-                        $QST_values = array(
1029
-                            'QST_display_text'  => __('City', 'event_espresso'),
1030
-                            'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1031
-                            'QST_system'        => 'city',
1032
-                            'QST_type'          => 'TEXT',
1033
-                            'QST_required'      => 0,
1034
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1035
-                            'QST_order'         => 6,
1036
-                            'QST_admin_only'    => 0,
1037
-                            'QST_max'           => EEM_Question::instance()
1038
-                                                               ->absolute_max_for_system_question($QST_system),
1039
-                            'QST_wp_user'       => self::get_default_creator_id(),
1040
-                            'QST_deleted'       => 0,
1041
-                        );
1042
-                        break;
1043
-                    case 'country' :
1044
-                        $QST_values = array(
1045
-                            'QST_display_text'  => __('Country', 'event_espresso'),
1046
-                            'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1047
-                            'QST_system'        => 'country',
1048
-                            'QST_type'          => 'COUNTRY',
1049
-                            'QST_required'      => 0,
1050
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1051
-                            'QST_order'         => 7,
1052
-                            'QST_admin_only'    => 0,
1053
-                            'QST_wp_user'       => self::get_default_creator_id(),
1054
-                            'QST_deleted'       => 0,
1055
-                        );
1056
-                        break;
1057
-                    case 'state':
1058
-                        $QST_values = array(
1059
-                            'QST_display_text'  => __('State/Province', 'event_espresso'),
1060
-                            'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1061
-                            'QST_system'        => 'state',
1062
-                            'QST_type'          => 'STATE',
1063
-                            'QST_required'      => 0,
1064
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1065
-                            'QST_order'         => 8,
1066
-                            'QST_admin_only'    => 0,
1067
-                            'QST_wp_user'       => self::get_default_creator_id(),
1068
-                            'QST_deleted'       => 0,
1069
-                        );
1070
-                        break;
1071
-                    case 'zip':
1072
-                        $QST_values = array(
1073
-                            'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1074
-                            'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1075
-                            'QST_system'        => 'zip',
1076
-                            'QST_type'          => 'TEXT',
1077
-                            'QST_required'      => 0,
1078
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1079
-                            'QST_order'         => 9,
1080
-                            'QST_admin_only'    => 0,
1081
-                            'QST_max'           => EEM_Question::instance()
1082
-                                                               ->absolute_max_for_system_question($QST_system),
1083
-                            'QST_wp_user'       => self::get_default_creator_id(),
1084
-                            'QST_deleted'       => 0,
1085
-                        );
1086
-                        break;
1087
-                    case 'phone':
1088
-                        $QST_values = array(
1089
-                            'QST_display_text'  => __('Phone Number', 'event_espresso'),
1090
-                            'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1091
-                            'QST_system'        => 'phone',
1092
-                            'QST_type'          => 'TEXT',
1093
-                            'QST_required'      => 0,
1094
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1095
-                            'QST_order'         => 10,
1096
-                            'QST_admin_only'    => 0,
1097
-                            'QST_max'           => EEM_Question::instance()
1098
-                                                               ->absolute_max_for_system_question($QST_system),
1099
-                            'QST_wp_user'       => self::get_default_creator_id(),
1100
-                            'QST_deleted'       => 0,
1101
-                        );
1102
-                        break;
1103
-                }
1104
-                if ( ! empty($QST_values)) {
1105
-                    // insert system question
1106
-                    $wpdb->insert(
1107
-                        $table_name,
1108
-                        $QST_values,
1109
-                        array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1110
-                    );
1111
-                    $QST_ID = $wpdb->insert_id;
1112
-                    // QUESTION GROUP QUESTIONS
1113
-                    if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1114
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1115
-                    } else {
1116
-                        $system_question_we_want = EEM_Question_Group::system_address;
1117
-                    }
1118
-                    if (isset($QSG_IDs[$system_question_we_want])) {
1119
-                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1120
-                    } else {
1121
-                        $id_col = EEM_Question_Group::instance()
1122
-                                                    ->get_col(array(array('QSG_system' => $system_question_we_want)));
1123
-                        if (is_array($id_col)) {
1124
-                            $QSG_ID = reset($id_col);
1125
-                        } else {
1126
-                            //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1127
-                            EE_Log::instance()->log(
1128
-                                __FILE__,
1129
-                                __FUNCTION__,
1130
-                                sprintf(
1131
-                                    __('Could not associate question %1$s to a question group because no system question group existed',
1132
-                                        'event_espresso'),
1133
-                                    $QST_ID),
1134
-                                'error');
1135
-                            continue;
1136
-                        }
1137
-                    }
1138
-                    // add system questions to groups
1139
-                    $wpdb->insert(
1140
-                        \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1141
-                        array(
1142
-                            'QSG_ID'    => $QSG_ID,
1143
-                            'QST_ID'    => $QST_ID,
1144
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1145
-                        ),
1146
-                        array('%d', '%d', '%d')
1147
-                    );
1148
-                }
1149
-            }
1150
-        }
1151
-    }
814
+	/**
815
+	 * create_database_tables
816
+	 *
817
+	 * @access public
818
+	 * @static
819
+	 * @throws EE_Error
820
+	 * @return boolean success (whether database is setup properly or not)
821
+	 */
822
+	public static function create_database_tables()
823
+	{
824
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
825
+		//find the migration script that sets the database to be compatible with the code
826
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
827
+		if ($dms_name) {
828
+			$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
829
+			$current_data_migration_script->set_migrating(false);
830
+			$current_data_migration_script->schema_changes_before_migration();
831
+			$current_data_migration_script->schema_changes_after_migration();
832
+			if ($current_data_migration_script->get_errors()) {
833
+				if (WP_DEBUG) {
834
+					foreach ($current_data_migration_script->get_errors() as $error) {
835
+						EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
836
+					}
837
+				} else {
838
+					EE_Error::add_error(__('There were errors creating the Event Espresso database tables and Event Espresso has been deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
839
+						'event_espresso'));
840
+				}
841
+				return false;
842
+			}
843
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to();
844
+		} else {
845
+			EE_Error::add_error(__('Could not determine most up-to-date data migration script from which to pull database schema structure. So database is probably not setup properly',
846
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
847
+			return false;
848
+		}
849
+		return true;
850
+	}
851
+
852
+
853
+
854
+	/**
855
+	 * initialize_system_questions
856
+	 *
857
+	 * @access public
858
+	 * @static
859
+	 * @return void
860
+	 */
861
+	public static function initialize_system_questions()
862
+	{
863
+		// QUESTION GROUPS
864
+		global $wpdb;
865
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
866
+		$SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
867
+		// what we have
868
+		$question_groups = $wpdb->get_col($SQL);
869
+		// check the response
870
+		$question_groups = is_array($question_groups) ? $question_groups : array();
871
+		// what we should have
872
+		$QSG_systems = array(1, 2);
873
+		// loop thru what we should have and compare to what we have
874
+		foreach ($QSG_systems as $QSG_system) {
875
+			// reset values array
876
+			$QSG_values = array();
877
+			// if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
878
+			if ( ! in_array("$QSG_system", $question_groups)) {
879
+				// add it
880
+				switch ($QSG_system) {
881
+					case 1:
882
+						$QSG_values = array(
883
+							'QSG_name'            => __('Personal Information', 'event_espresso'),
884
+							'QSG_identifier'      => 'personal-information-' . time(),
885
+							'QSG_desc'            => '',
886
+							'QSG_order'           => 1,
887
+							'QSG_show_group_name' => 1,
888
+							'QSG_show_group_desc' => 1,
889
+							'QSG_system'          => EEM_Question_Group::system_personal,
890
+							'QSG_deleted'         => 0,
891
+						);
892
+						break;
893
+					case 2:
894
+						$QSG_values = array(
895
+							'QSG_name'            => __('Address Information', 'event_espresso'),
896
+							'QSG_identifier'      => 'address-information-' . time(),
897
+							'QSG_desc'            => '',
898
+							'QSG_order'           => 2,
899
+							'QSG_show_group_name' => 1,
900
+							'QSG_show_group_desc' => 1,
901
+							'QSG_system'          => EEM_Question_Group::system_address,
902
+							'QSG_deleted'         => 0,
903
+						);
904
+						break;
905
+				}
906
+				// make sure we have some values before inserting them
907
+				if ( ! empty($QSG_values)) {
908
+					// insert system question
909
+					$wpdb->insert(
910
+						$table_name,
911
+						$QSG_values,
912
+						array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
913
+					);
914
+					$QSG_IDs[$QSG_system] = $wpdb->insert_id;
915
+				}
916
+			}
917
+		}
918
+		// QUESTIONS
919
+		global $wpdb;
920
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
921
+		$SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
922
+		// what we have
923
+		$questions = $wpdb->get_col($SQL);
924
+		// what we should have
925
+		$QST_systems = array(
926
+			'fname',
927
+			'lname',
928
+			'email',
929
+			'address',
930
+			'address2',
931
+			'city',
932
+			'country',
933
+			'state',
934
+			'zip',
935
+			'phone',
936
+		);
937
+		$order_for_group_1 = 1;
938
+		$order_for_group_2 = 1;
939
+		// loop thru what we should have and compare to what we have
940
+		foreach ($QST_systems as $QST_system) {
941
+			// reset values array
942
+			$QST_values = array();
943
+			// if we don't have what we should have
944
+			if ( ! in_array($QST_system, $questions)) {
945
+				// add it
946
+				switch ($QST_system) {
947
+					case 'fname':
948
+						$QST_values = array(
949
+							'QST_display_text'  => __('First Name', 'event_espresso'),
950
+							'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
951
+							'QST_system'        => 'fname',
952
+							'QST_type'          => 'TEXT',
953
+							'QST_required'      => 1,
954
+							'QST_required_text' => __('This field is required', 'event_espresso'),
955
+							'QST_order'         => 1,
956
+							'QST_admin_only'    => 0,
957
+							'QST_max'           => EEM_Question::instance()
958
+															   ->absolute_max_for_system_question($QST_system),
959
+							'QST_wp_user'       => self::get_default_creator_id(),
960
+							'QST_deleted'       => 0,
961
+						);
962
+						break;
963
+					case 'lname':
964
+						$QST_values = array(
965
+							'QST_display_text'  => __('Last Name', 'event_espresso'),
966
+							'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
967
+							'QST_system'        => 'lname',
968
+							'QST_type'          => 'TEXT',
969
+							'QST_required'      => 1,
970
+							'QST_required_text' => __('This field is required', 'event_espresso'),
971
+							'QST_order'         => 2,
972
+							'QST_admin_only'    => 0,
973
+							'QST_max'           => EEM_Question::instance()
974
+															   ->absolute_max_for_system_question($QST_system),
975
+							'QST_wp_user'       => self::get_default_creator_id(),
976
+							'QST_deleted'       => 0,
977
+						);
978
+						break;
979
+					case 'email':
980
+						$QST_values = array(
981
+							'QST_display_text'  => __('Email Address', 'event_espresso'),
982
+							'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
983
+							'QST_system'        => 'email',
984
+							'QST_type'          => 'EMAIL',
985
+							'QST_required'      => 1,
986
+							'QST_required_text' => __('This field is required', 'event_espresso'),
987
+							'QST_order'         => 3,
988
+							'QST_admin_only'    => 0,
989
+							'QST_max'           => EEM_Question::instance()
990
+															   ->absolute_max_for_system_question($QST_system),
991
+							'QST_wp_user'       => self::get_default_creator_id(),
992
+							'QST_deleted'       => 0,
993
+						);
994
+						break;
995
+					case 'address':
996
+						$QST_values = array(
997
+							'QST_display_text'  => __('Address', 'event_espresso'),
998
+							'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
999
+							'QST_system'        => 'address',
1000
+							'QST_type'          => 'TEXT',
1001
+							'QST_required'      => 0,
1002
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1003
+							'QST_order'         => 4,
1004
+							'QST_admin_only'    => 0,
1005
+							'QST_max'           => EEM_Question::instance()
1006
+															   ->absolute_max_for_system_question($QST_system),
1007
+							'QST_wp_user'       => self::get_default_creator_id(),
1008
+							'QST_deleted'       => 0,
1009
+						);
1010
+						break;
1011
+					case 'address2':
1012
+						$QST_values = array(
1013
+							'QST_display_text'  => __('Address2', 'event_espresso'),
1014
+							'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1015
+							'QST_system'        => 'address2',
1016
+							'QST_type'          => 'TEXT',
1017
+							'QST_required'      => 0,
1018
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1019
+							'QST_order'         => 5,
1020
+							'QST_admin_only'    => 0,
1021
+							'QST_max'           => EEM_Question::instance()
1022
+															   ->absolute_max_for_system_question($QST_system),
1023
+							'QST_wp_user'       => self::get_default_creator_id(),
1024
+							'QST_deleted'       => 0,
1025
+						);
1026
+						break;
1027
+					case 'city':
1028
+						$QST_values = array(
1029
+							'QST_display_text'  => __('City', 'event_espresso'),
1030
+							'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1031
+							'QST_system'        => 'city',
1032
+							'QST_type'          => 'TEXT',
1033
+							'QST_required'      => 0,
1034
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1035
+							'QST_order'         => 6,
1036
+							'QST_admin_only'    => 0,
1037
+							'QST_max'           => EEM_Question::instance()
1038
+															   ->absolute_max_for_system_question($QST_system),
1039
+							'QST_wp_user'       => self::get_default_creator_id(),
1040
+							'QST_deleted'       => 0,
1041
+						);
1042
+						break;
1043
+					case 'country' :
1044
+						$QST_values = array(
1045
+							'QST_display_text'  => __('Country', 'event_espresso'),
1046
+							'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1047
+							'QST_system'        => 'country',
1048
+							'QST_type'          => 'COUNTRY',
1049
+							'QST_required'      => 0,
1050
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1051
+							'QST_order'         => 7,
1052
+							'QST_admin_only'    => 0,
1053
+							'QST_wp_user'       => self::get_default_creator_id(),
1054
+							'QST_deleted'       => 0,
1055
+						);
1056
+						break;
1057
+					case 'state':
1058
+						$QST_values = array(
1059
+							'QST_display_text'  => __('State/Province', 'event_espresso'),
1060
+							'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1061
+							'QST_system'        => 'state',
1062
+							'QST_type'          => 'STATE',
1063
+							'QST_required'      => 0,
1064
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1065
+							'QST_order'         => 8,
1066
+							'QST_admin_only'    => 0,
1067
+							'QST_wp_user'       => self::get_default_creator_id(),
1068
+							'QST_deleted'       => 0,
1069
+						);
1070
+						break;
1071
+					case 'zip':
1072
+						$QST_values = array(
1073
+							'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1074
+							'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1075
+							'QST_system'        => 'zip',
1076
+							'QST_type'          => 'TEXT',
1077
+							'QST_required'      => 0,
1078
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1079
+							'QST_order'         => 9,
1080
+							'QST_admin_only'    => 0,
1081
+							'QST_max'           => EEM_Question::instance()
1082
+															   ->absolute_max_for_system_question($QST_system),
1083
+							'QST_wp_user'       => self::get_default_creator_id(),
1084
+							'QST_deleted'       => 0,
1085
+						);
1086
+						break;
1087
+					case 'phone':
1088
+						$QST_values = array(
1089
+							'QST_display_text'  => __('Phone Number', 'event_espresso'),
1090
+							'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1091
+							'QST_system'        => 'phone',
1092
+							'QST_type'          => 'TEXT',
1093
+							'QST_required'      => 0,
1094
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1095
+							'QST_order'         => 10,
1096
+							'QST_admin_only'    => 0,
1097
+							'QST_max'           => EEM_Question::instance()
1098
+															   ->absolute_max_for_system_question($QST_system),
1099
+							'QST_wp_user'       => self::get_default_creator_id(),
1100
+							'QST_deleted'       => 0,
1101
+						);
1102
+						break;
1103
+				}
1104
+				if ( ! empty($QST_values)) {
1105
+					// insert system question
1106
+					$wpdb->insert(
1107
+						$table_name,
1108
+						$QST_values,
1109
+						array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1110
+					);
1111
+					$QST_ID = $wpdb->insert_id;
1112
+					// QUESTION GROUP QUESTIONS
1113
+					if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1114
+						$system_question_we_want = EEM_Question_Group::system_personal;
1115
+					} else {
1116
+						$system_question_we_want = EEM_Question_Group::system_address;
1117
+					}
1118
+					if (isset($QSG_IDs[$system_question_we_want])) {
1119
+						$QSG_ID = $QSG_IDs[$system_question_we_want];
1120
+					} else {
1121
+						$id_col = EEM_Question_Group::instance()
1122
+													->get_col(array(array('QSG_system' => $system_question_we_want)));
1123
+						if (is_array($id_col)) {
1124
+							$QSG_ID = reset($id_col);
1125
+						} else {
1126
+							//ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1127
+							EE_Log::instance()->log(
1128
+								__FILE__,
1129
+								__FUNCTION__,
1130
+								sprintf(
1131
+									__('Could not associate question %1$s to a question group because no system question group existed',
1132
+										'event_espresso'),
1133
+									$QST_ID),
1134
+								'error');
1135
+							continue;
1136
+						}
1137
+					}
1138
+					// add system questions to groups
1139
+					$wpdb->insert(
1140
+						\EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1141
+						array(
1142
+							'QSG_ID'    => $QSG_ID,
1143
+							'QST_ID'    => $QST_ID,
1144
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1145
+						),
1146
+						array('%d', '%d', '%d')
1147
+					);
1148
+				}
1149
+			}
1150
+		}
1151
+	}
1152 1152
 
1153 1153
 
1154 1154
 
@@ -1334,111 +1334,111 @@  discard block
 block discarded – undo
1334 1334
 
1335 1335
 
1336 1336
 
1337
-    /**
1338
-     * @param \EE_Message_Resource_Manager $message_resource_manager
1339
-     * @return array|bool
1340
-     * @throws \EE_Error
1341
-     */
1342
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1343
-        EE_Message_Resource_Manager $message_resource_manager
1344
-    ) {
1345
-        /** @type EE_messenger[] $active_messengers */
1346
-        $active_messengers = $message_resource_manager->active_messengers();
1347
-        $installed_message_types = $message_resource_manager->installed_message_types();
1348
-        $templates_created = false;
1349
-        foreach ($active_messengers as $active_messenger) {
1350
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1351
-            $default_message_type_names_to_activate = array();
1352
-            // looping through each default message type reported by the messenger
1353
-            // and setup the actual message types to activate.
1354
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1355
-                // if already active or has already been activated before we skip
1356
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1357
-                // we also skip if the message type is not installed.
1358
-                if (
1359
-                    $message_resource_manager->has_message_type_been_activated_for_messenger($default_message_type_name_for_messenger,
1360
-                        $active_messenger->name)
1361
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1362
-                        $active_messenger->name,
1363
-                        $default_message_type_name_for_messenger
1364
-                    )
1365
-                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1366
-                ) {
1367
-                    continue;
1368
-                }
1369
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1370
-            }
1371
-            //let's activate!
1372
-            $message_resource_manager->ensure_message_types_are_active(
1373
-                $default_message_type_names_to_activate,
1374
-                $active_messenger->name,
1375
-                false
1376
-            );
1377
-            //activate the templates for these message types
1378
-            if ( ! empty($default_message_type_names_to_activate)) {
1379
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1380
-                    $active_messenger->name,
1381
-                    $default_message_type_names_for_messenger,
1382
-                    '',
1383
-                    true
1384
-                );
1385
-            }
1386
-        }
1387
-        return $templates_created;
1388
-    }
1389
-
1390
-
1391
-
1392
-    /**
1393
-     * This will activate and generate default messengers and default message types for those messengers.
1394
-     *
1395
-     * @param EE_message_Resource_Manager $message_resource_manager
1396
-     * @return array|bool  True means there were default messengers and message type templates generated.
1397
-     *                     False means that there were no templates generated
1398
-     *                     (which could simply mean there are no default message types for a messenger).
1399
-     * @throws EE_Error
1400
-     */
1401
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1402
-        EE_Message_Resource_Manager $message_resource_manager
1403
-    ) {
1404
-        /** @type EE_messenger[] $messengers_to_generate */
1405
-        $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1406
-        $installed_message_types = $message_resource_manager->installed_message_types();
1407
-        $templates_generated = false;
1408
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1409
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1410
-            //verify the default message types match an installed message type.
1411
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1412
-                if (
1413
-                    ! isset($installed_message_types[$name])
1414
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger($name,
1415
-                        $messenger_to_generate->name)
1416
-                ) {
1417
-                    unset($default_message_type_names_for_messenger[$key]);
1418
-                }
1419
-            }
1420
-            // in previous iterations, the active_messengers option in the db
1421
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1422
-            // This comment is left here just in case we discover that we _do_ need to update before
1423
-            // passing off to create templates (after the refactor is done).
1424
-            // @todo remove this comment when determined not necessary.
1425
-            $message_resource_manager->activate_messenger(
1426
-                $messenger_to_generate->name,
1427
-                $default_message_type_names_for_messenger,
1428
-                false
1429
-            );
1430
-            //create any templates needing created (or will reactivate templates already generated as necessary).
1431
-            if ( ! empty($default_message_type_names_for_messenger)) {
1432
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1433
-                    $messenger_to_generate->name,
1434
-                    $default_message_type_names_for_messenger,
1435
-                    '',
1436
-                    true
1437
-                );
1438
-            }
1439
-        }
1440
-        return $templates_generated;
1441
-    }
1337
+	/**
1338
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
1339
+	 * @return array|bool
1340
+	 * @throws \EE_Error
1341
+	 */
1342
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1343
+		EE_Message_Resource_Manager $message_resource_manager
1344
+	) {
1345
+		/** @type EE_messenger[] $active_messengers */
1346
+		$active_messengers = $message_resource_manager->active_messengers();
1347
+		$installed_message_types = $message_resource_manager->installed_message_types();
1348
+		$templates_created = false;
1349
+		foreach ($active_messengers as $active_messenger) {
1350
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1351
+			$default_message_type_names_to_activate = array();
1352
+			// looping through each default message type reported by the messenger
1353
+			// and setup the actual message types to activate.
1354
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1355
+				// if already active or has already been activated before we skip
1356
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1357
+				// we also skip if the message type is not installed.
1358
+				if (
1359
+					$message_resource_manager->has_message_type_been_activated_for_messenger($default_message_type_name_for_messenger,
1360
+						$active_messenger->name)
1361
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1362
+						$active_messenger->name,
1363
+						$default_message_type_name_for_messenger
1364
+					)
1365
+					|| ! isset($installed_message_types[$default_message_type_name_for_messenger])
1366
+				) {
1367
+					continue;
1368
+				}
1369
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1370
+			}
1371
+			//let's activate!
1372
+			$message_resource_manager->ensure_message_types_are_active(
1373
+				$default_message_type_names_to_activate,
1374
+				$active_messenger->name,
1375
+				false
1376
+			);
1377
+			//activate the templates for these message types
1378
+			if ( ! empty($default_message_type_names_to_activate)) {
1379
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1380
+					$active_messenger->name,
1381
+					$default_message_type_names_for_messenger,
1382
+					'',
1383
+					true
1384
+				);
1385
+			}
1386
+		}
1387
+		return $templates_created;
1388
+	}
1389
+
1390
+
1391
+
1392
+	/**
1393
+	 * This will activate and generate default messengers and default message types for those messengers.
1394
+	 *
1395
+	 * @param EE_message_Resource_Manager $message_resource_manager
1396
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1397
+	 *                     False means that there were no templates generated
1398
+	 *                     (which could simply mean there are no default message types for a messenger).
1399
+	 * @throws EE_Error
1400
+	 */
1401
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1402
+		EE_Message_Resource_Manager $message_resource_manager
1403
+	) {
1404
+		/** @type EE_messenger[] $messengers_to_generate */
1405
+		$messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1406
+		$installed_message_types = $message_resource_manager->installed_message_types();
1407
+		$templates_generated = false;
1408
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1409
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1410
+			//verify the default message types match an installed message type.
1411
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1412
+				if (
1413
+					! isset($installed_message_types[$name])
1414
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger($name,
1415
+						$messenger_to_generate->name)
1416
+				) {
1417
+					unset($default_message_type_names_for_messenger[$key]);
1418
+				}
1419
+			}
1420
+			// in previous iterations, the active_messengers option in the db
1421
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1422
+			// This comment is left here just in case we discover that we _do_ need to update before
1423
+			// passing off to create templates (after the refactor is done).
1424
+			// @todo remove this comment when determined not necessary.
1425
+			$message_resource_manager->activate_messenger(
1426
+				$messenger_to_generate->name,
1427
+				$default_message_type_names_for_messenger,
1428
+				false
1429
+			);
1430
+			//create any templates needing created (or will reactivate templates already generated as necessary).
1431
+			if ( ! empty($default_message_type_names_for_messenger)) {
1432
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1433
+					$messenger_to_generate->name,
1434
+					$default_message_type_names_for_messenger,
1435
+					'',
1436
+					true
1437
+				);
1438
+			}
1439
+		}
1440
+		return $templates_generated;
1441
+	}
1442 1442
 
1443 1443
 
1444 1444
 
@@ -1606,111 +1606,111 @@  discard block
 block discarded – undo
1606 1606
 
1607 1607
 
1608 1608
 
1609
-    /**
1610
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1611
-     * each table name provided has a wpdb prefix attached, and that it exists.
1612
-     * Returns the list actually deleted
1613
-     *
1614
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1615
-     * @global WPDB $wpdb
1616
-     * @param array $table_names
1617
-     * @return array of table names which we deleted
1618
-     */
1619
-    public static function drop_tables($table_names)
1620
-    {
1621
-        return \EEH_Activation::getTableManager()->dropTables($table_names);
1622
-    }
1623
-
1624
-
1625
-
1626
-    /**
1627
-     * plugin_uninstall
1628
-     *
1629
-     * @access public
1630
-     * @static
1631
-     * @param bool $remove_all
1632
-     * @return void
1633
-     */
1634
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1635
-    {
1636
-        global $wpdb;
1637
-        self::drop_espresso_tables();
1638
-        $wp_options_to_delete = array(
1639
-            'ee_no_ticket_prices'                => true,
1640
-            'ee_active_messengers'               => true,
1641
-            'ee_has_activated_messenger'         => true,
1642
-            'ee_flush_rewrite_rules'             => true,
1643
-            'ee_config'                          => false,
1644
-            'ee_data_migration_current_db_state' => true,
1645
-            'ee_data_migration_mapping_'         => false,
1646
-            'ee_data_migration_script_'          => false,
1647
-            'ee_data_migrations'                 => true,
1648
-            'ee_dms_map'                         => false,
1649
-            'ee_notices'                         => true,
1650
-            'lang_file_check_'                   => false,
1651
-            'ee_maintenance_mode'                => true,
1652
-            'ee_ueip_optin'                      => true,
1653
-            'ee_ueip_has_notified'               => true,
1654
-            'ee_plugin_activation_errors'        => true,
1655
-            'ee_id_mapping_from'                 => false,
1656
-            'espresso_persistent_admin_notices'  => true,
1657
-            'ee_encryption_key'                  => true,
1658
-            'pue_force_upgrade_'                 => false,
1659
-            'pue_json_error_'                    => false,
1660
-            'pue_install_key_'                   => false,
1661
-            'pue_verification_error_'            => false,
1662
-            'pu_dismissed_upgrade_'              => false,
1663
-            'external_updates-'                  => false,
1664
-            'ee_extra_data'                      => true,
1665
-            'ee_ssn_'                            => false,
1666
-            'ee_rss_'                            => false,
1667
-            'ee_rte_n_tx_'                       => false,
1668
-            'ee_pers_admin_notices'              => true,
1669
-            'ee_job_parameters_'                 => false,
1670
-            'ee_upload_directories_incomplete'   => true,
1671
-            'ee_verified_db_collations'          => true,
1672
-        );
1673
-        if (is_main_site()) {
1674
-            $wp_options_to_delete['ee_network_config'] = true;
1675
-        }
1676
-        $undeleted_options = array();
1677
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1678
-            if ($no_wildcard) {
1679
-                if ( ! delete_option($option_name)) {
1680
-                    $undeleted_options[] = $option_name;
1681
-                }
1682
-            } else {
1683
-                $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1684
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1685
-                    if ( ! delete_option($option_name_from_wildcard)) {
1686
-                        $undeleted_options[] = $option_name_from_wildcard;
1687
-                    }
1688
-                }
1689
-            }
1690
-        }
1691
-        //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1692
-        remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1693
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1694
-            $db_update_sans_ee4 = array();
1695
-            foreach ($espresso_db_update as $version => $times_activated) {
1696
-                if ((string)$version[0] === '3') {//if its NON EE4
1697
-                    $db_update_sans_ee4[$version] = $times_activated;
1698
-                }
1699
-            }
1700
-            update_option('espresso_db_update', $db_update_sans_ee4);
1701
-        }
1702
-        $errors = '';
1703
-        if ( ! empty($undeleted_options)) {
1704
-            $errors .= sprintf(
1705
-                __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1706
-                '<br/>',
1707
-                implode(',<br/>', $undeleted_options)
1708
-            );
1709
-        }
1710
-        if ( ! empty($errors)) {
1711
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1712
-        }
1713
-    }
1609
+	/**
1610
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1611
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1612
+	 * Returns the list actually deleted
1613
+	 *
1614
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1615
+	 * @global WPDB $wpdb
1616
+	 * @param array $table_names
1617
+	 * @return array of table names which we deleted
1618
+	 */
1619
+	public static function drop_tables($table_names)
1620
+	{
1621
+		return \EEH_Activation::getTableManager()->dropTables($table_names);
1622
+	}
1623
+
1624
+
1625
+
1626
+	/**
1627
+	 * plugin_uninstall
1628
+	 *
1629
+	 * @access public
1630
+	 * @static
1631
+	 * @param bool $remove_all
1632
+	 * @return void
1633
+	 */
1634
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1635
+	{
1636
+		global $wpdb;
1637
+		self::drop_espresso_tables();
1638
+		$wp_options_to_delete = array(
1639
+			'ee_no_ticket_prices'                => true,
1640
+			'ee_active_messengers'               => true,
1641
+			'ee_has_activated_messenger'         => true,
1642
+			'ee_flush_rewrite_rules'             => true,
1643
+			'ee_config'                          => false,
1644
+			'ee_data_migration_current_db_state' => true,
1645
+			'ee_data_migration_mapping_'         => false,
1646
+			'ee_data_migration_script_'          => false,
1647
+			'ee_data_migrations'                 => true,
1648
+			'ee_dms_map'                         => false,
1649
+			'ee_notices'                         => true,
1650
+			'lang_file_check_'                   => false,
1651
+			'ee_maintenance_mode'                => true,
1652
+			'ee_ueip_optin'                      => true,
1653
+			'ee_ueip_has_notified'               => true,
1654
+			'ee_plugin_activation_errors'        => true,
1655
+			'ee_id_mapping_from'                 => false,
1656
+			'espresso_persistent_admin_notices'  => true,
1657
+			'ee_encryption_key'                  => true,
1658
+			'pue_force_upgrade_'                 => false,
1659
+			'pue_json_error_'                    => false,
1660
+			'pue_install_key_'                   => false,
1661
+			'pue_verification_error_'            => false,
1662
+			'pu_dismissed_upgrade_'              => false,
1663
+			'external_updates-'                  => false,
1664
+			'ee_extra_data'                      => true,
1665
+			'ee_ssn_'                            => false,
1666
+			'ee_rss_'                            => false,
1667
+			'ee_rte_n_tx_'                       => false,
1668
+			'ee_pers_admin_notices'              => true,
1669
+			'ee_job_parameters_'                 => false,
1670
+			'ee_upload_directories_incomplete'   => true,
1671
+			'ee_verified_db_collations'          => true,
1672
+		);
1673
+		if (is_main_site()) {
1674
+			$wp_options_to_delete['ee_network_config'] = true;
1675
+		}
1676
+		$undeleted_options = array();
1677
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1678
+			if ($no_wildcard) {
1679
+				if ( ! delete_option($option_name)) {
1680
+					$undeleted_options[] = $option_name;
1681
+				}
1682
+			} else {
1683
+				$option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1684
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1685
+					if ( ! delete_option($option_name_from_wildcard)) {
1686
+						$undeleted_options[] = $option_name_from_wildcard;
1687
+					}
1688
+				}
1689
+			}
1690
+		}
1691
+		//also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1692
+		remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1693
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1694
+			$db_update_sans_ee4 = array();
1695
+			foreach ($espresso_db_update as $version => $times_activated) {
1696
+				if ((string)$version[0] === '3') {//if its NON EE4
1697
+					$db_update_sans_ee4[$version] = $times_activated;
1698
+				}
1699
+			}
1700
+			update_option('espresso_db_update', $db_update_sans_ee4);
1701
+		}
1702
+		$errors = '';
1703
+		if ( ! empty($undeleted_options)) {
1704
+			$errors .= sprintf(
1705
+				__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1706
+				'<br/>',
1707
+				implode(',<br/>', $undeleted_options)
1708
+			);
1709
+		}
1710
+		if ( ! empty($errors)) {
1711
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1712
+		}
1713
+	}
1714 1714
 
1715 1715
 	/**
1716 1716
 	 * Gets the mysql error code from the last used query by wpdb
Please login to merge, or discard this patch.
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 2 patches
Indentation   +1688 added lines, -1688 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\exceptions\InvalidEntityException;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -17,1693 +17,1693 @@  discard block
 block discarded – undo
17 17
 class EED_Single_Page_Checkout extends EED_Module
18 18
 {
19 19
 
20
-    /**
21
-     * $_initialized - has the SPCO controller already been initialized ?
22
-     *
23
-     * @access private
24
-     * @var bool $_initialized
25
-     */
26
-    private static $_initialized = false;
27
-
28
-
29
-    /**
30
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
31
-     *
32
-     * @access private
33
-     * @var bool $_valid_checkout
34
-     */
35
-    private static $_checkout_verified = true;
36
-
37
-    /**
38
-     *    $_reg_steps_array - holds initial array of reg steps
39
-     *
40
-     * @access private
41
-     * @var array $_reg_steps_array
42
-     */
43
-    private static $_reg_steps_array = array();
44
-
45
-    /**
46
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
47
-     *
48
-     * @access public
49
-     * @var EE_Checkout $checkout
50
-     */
51
-    public $checkout;
52
-
53
-
54
-
55
-    /**
56
-     * @return EED_Single_Page_Checkout
57
-     */
58
-    public static function instance()
59
-    {
60
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
61
-        return parent::get_instance(__CLASS__);
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * @return EE_CART
68
-     */
69
-    public function cart()
70
-    {
71
-        return $this->checkout->cart;
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * @return EE_Transaction
78
-     */
79
-    public function transaction()
80
-    {
81
-        return $this->checkout->transaction;
82
-    }
83
-
84
-
85
-
86
-    /**
87
-     *    set_hooks - for hooking into EE Core, other modules, etc
88
-     *
89
-     * @access    public
90
-     * @return    void
91
-     * @throws \EE_Error
92
-     */
93
-    public static function set_hooks()
94
-    {
95
-        EED_Single_Page_Checkout::set_definitions();
96
-    }
97
-
98
-
99
-
100
-    /**
101
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
102
-     *
103
-     * @access    public
104
-     * @return    void
105
-     * @throws \EE_Error
106
-     */
107
-    public static function set_hooks_admin()
108
-    {
109
-        EED_Single_Page_Checkout::set_definitions();
110
-        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
111
-            // hook into the top of pre_get_posts to set the reg step routing, which gives other modules or plugins a chance to modify the reg steps, but just before the routes get called
112
-            add_action('pre_get_posts', array('EED_Single_Page_Checkout', 'load_reg_steps'), 1);
113
-            return;
114
-        }
115
-        // going to start an output buffer in case anything gets accidentally output that might disrupt our JSON response
116
-        ob_start();
117
-        EED_Single_Page_Checkout::load_request_handler();
118
-        EED_Single_Page_Checkout::load_reg_steps();
119
-        // set ajax hooks
120
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
121
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
122
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
123
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
124
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
125
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     *    process ajax request
132
-     *
133
-     * @param string $ajax_action
134
-     * @throws \EE_Error
135
-     */
136
-    public static function process_ajax_request($ajax_action)
137
-    {
138
-        EE_Registry::instance()->REQ->set('action', $ajax_action);
139
-        EED_Single_Page_Checkout::instance()->_initialize();
140
-    }
141
-
142
-
143
-
144
-    /**
145
-     *    ajax display registration step
146
-     *
147
-     * @throws \EE_Error
148
-     */
149
-    public static function display_reg_step()
150
-    {
151
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
152
-    }
153
-
154
-
155
-
156
-    /**
157
-     *    ajax process registration step
158
-     *
159
-     * @throws \EE_Error
160
-     */
161
-    public static function process_reg_step()
162
-    {
163
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     *    ajax process registration step
170
-     *
171
-     * @throws \EE_Error
172
-     */
173
-    public static function update_reg_step()
174
-    {
175
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
176
-    }
177
-
178
-
179
-
180
-    /**
181
-     *   update_checkout
182
-     *
183
-     * @access public
184
-     * @return void
185
-     * @throws \EE_Error
186
-     */
187
-    public static function update_checkout()
188
-    {
189
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
190
-    }
191
-
192
-
193
-
194
-    /**
195
-     *    load_request_handler
196
-     *
197
-     * @access    public
198
-     * @return    void
199
-     */
200
-    public static function load_request_handler()
201
-    {
202
-        // load core Request_Handler class
203
-        if ( ! isset(EE_Registry::instance()->REQ)) {
204
-            EE_Registry::instance()->load_core('Request_Handler');
205
-        }
206
-    }
207
-
208
-
209
-
210
-    /**
211
-     *    set_definitions
212
-     *
213
-     * @access    public
214
-     * @return    void
215
-     * @throws \EE_Error
216
-     */
217
-    public static function set_definitions()
218
-    {
219
-        define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS);
220
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
221
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
222
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
223
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
224
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
225
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
226
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
227
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
228
-            __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
229
-                'event_espresso'),
230
-            '<h4 class="important-notice">',
231
-            '</h4>',
232
-            '<br />',
233
-            '<p>',
234
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
235
-            '">',
236
-            '</a>',
237
-            '</p>'
238
-        );
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * load_reg_steps
245
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
246
-     *
247
-     * @access    private
248
-     * @throws EE_Error
249
-     * @return void
250
-     */
251
-    public static function load_reg_steps()
252
-    {
253
-        static $reg_steps_loaded = false;
254
-        if ($reg_steps_loaded) {
255
-            return;
256
-        }
257
-        // filter list of reg_steps
258
-        $reg_steps_to_load = (array)apply_filters(
259
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
260
-            EED_Single_Page_Checkout::get_reg_steps()
261
-        );
262
-        // sort by key (order)
263
-        ksort($reg_steps_to_load);
264
-        // loop through folders
265
-        foreach ($reg_steps_to_load as $order => $reg_step) {
266
-            // we need a
267
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
268
-                // copy over to the reg_steps_array
269
-                EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
270
-                // register custom key route for each reg step
271
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
272
-                EE_Config::register_route($reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step');
273
-                // add AJAX or other hooks
274
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
275
-                    // setup autoloaders if necessary
276
-                    if ( ! class_exists($reg_step['class_name'])) {
277
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder($reg_step['file_path'], true);
278
-                    }
279
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
280
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
281
-                    }
282
-                }
283
-            }
284
-        }
285
-        $reg_steps_loaded = true;
286
-    }
287
-
288
-
289
-
290
-    /**
291
-     *    get_reg_steps
292
-     *
293
-     * @access    public
294
-     * @return    array
295
-     */
296
-    public static function get_reg_steps()
297
-    {
298
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
299
-        if (empty($reg_steps)) {
300
-            $reg_steps = array(
301
-                10  => array(
302
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
303
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
304
-                    'slug'       => 'attendee_information',
305
-                    'has_hooks'  => false,
306
-                ),
307
-                20  => array(
308
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
309
-                    'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
310
-                    'slug'       => 'registration_confirmation',
311
-                    'has_hooks'  => false,
312
-                ),
313
-                30  => array(
314
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
315
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
316
-                    'slug'       => 'payment_options',
317
-                    'has_hooks'  => true,
318
-                ),
319
-                999 => array(
320
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
321
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
322
-                    'slug'       => 'finalize_registration',
323
-                    'has_hooks'  => false,
324
-                ),
325
-            );
326
-        }
327
-        return $reg_steps;
328
-    }
329
-
330
-
331
-
332
-    /**
333
-     *    registration_checkout_for_admin
334
-     *
335
-     * @access    public
336
-     * @return    string
337
-     * @throws \EE_Error
338
-     */
339
-    public static function registration_checkout_for_admin()
340
-    {
341
-        EED_Single_Page_Checkout::load_reg_steps();
342
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
343
-        EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
344
-        EE_Registry::instance()->REQ->set('process_form_submission', false);
345
-        EED_Single_Page_Checkout::instance()->_initialize();
346
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
347
-        return EE_Registry::instance()->REQ->get_output();
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * process_registration_from_admin
354
-     *
355
-     * @access public
356
-     * @return \EE_Transaction
357
-     * @throws \EE_Error
358
-     */
359
-    public static function process_registration_from_admin()
360
-    {
361
-        EED_Single_Page_Checkout::load_reg_steps();
362
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
363
-        EE_Registry::instance()->REQ->set('action', 'process_reg_step');
364
-        EE_Registry::instance()->REQ->set('process_form_submission', true);
365
-        EED_Single_Page_Checkout::instance()->_initialize();
366
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
367
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
368
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
369
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
370
-                if ($final_reg_step->process_reg_step()) {
371
-                    $final_reg_step->set_completed();
372
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
373
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
374
-                }
375
-            }
376
-        }
377
-        return null;
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     *    run
384
-     *
385
-     * @access    public
386
-     * @param WP_Query $WP_Query
387
-     * @return    void
388
-     * @throws \EE_Error
389
-     */
390
-    public function run($WP_Query)
391
-    {
392
-        if (
393
-            $WP_Query instanceof WP_Query
394
-            && $WP_Query->is_main_query()
395
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
396
-            && $this->_is_reg_checkout()
397
-        ) {
398
-            $this->_initialize();
399
-        }
400
-    }
401
-
402
-
403
-
404
-    /**
405
-     * determines whether current url matches reg page url
406
-     *
407
-     * @return bool
408
-     */
409
-    protected function _is_reg_checkout()
410
-    {
411
-        // get current permalink for reg page without any extra query args
412
-        $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
413
-        // get request URI for current request, but without the scheme or host
414
-        $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
415
-        $current_request_uri = html_entity_decode($current_request_uri);
416
-        // get array of query args from the current request URI
417
-        $query_args = \EEH_URL::get_query_string($current_request_uri);
418
-        // grab page id if it is set
419
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
420
-        // and remove the page id from the query args (we will re-add it later)
421
-        unset($query_args['page_id']);
422
-        // now strip all query args from current request URI
423
-        $current_request_uri = remove_query_arg(array_flip($query_args), $current_request_uri);
424
-        // and re-add the page id if it was set
425
-        if ($page_id) {
426
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
427
-        }
428
-        // remove slashes and ?
429
-        $current_request_uri = trim($current_request_uri, '?/');
430
-        // is current request URI part of the known full reg page URL ?
431
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
432
-    }
433
-
434
-
435
-
436
-    /**
437
-     *    run
438
-     *
439
-     * @access    public
440
-     * @param WP_Query $WP_Query
441
-     * @return    void
442
-     * @throws \EE_Error
443
-     */
444
-    public static function init($WP_Query)
445
-    {
446
-        EED_Single_Page_Checkout::instance()->run($WP_Query);
447
-    }
448
-
449
-
450
-
451
-    /**
452
-     *    _initialize - initial module setup
453
-     *
454
-     * @access    private
455
-     * @throws EE_Error
456
-     * @return    void
457
-     */
458
-    private function _initialize()
459
-    {
460
-        // ensure SPCO doesn't run twice
461
-        if (EED_Single_Page_Checkout::$_initialized) {
462
-            return;
463
-        }
464
-        try {
465
-            $this->_verify_session();
466
-            // setup the EE_Checkout object
467
-            $this->checkout = $this->_initialize_checkout();
468
-            // filter checkout
469
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
470
-            // get the $_GET
471
-            $this->_get_request_vars();
472
-            if ($this->_block_bots()) {
473
-                return;
474
-            }
475
-            // filter continue_reg
476
-            $this->checkout->continue_reg = apply_filters('FHEE__EED_Single_Page_Checkout__init___continue_reg', true, $this->checkout);
477
-            // load the reg steps array
478
-            if ( ! $this->_load_and_instantiate_reg_steps()) {
479
-                EED_Single_Page_Checkout::$_initialized = true;
480
-                return;
481
-            }
482
-            // set the current step
483
-            $this->checkout->set_current_step($this->checkout->step);
484
-            // and the next step
485
-            $this->checkout->set_next_step();
486
-            // verify that everything has been setup correctly
487
-            if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
488
-                EED_Single_Page_Checkout::$_initialized = true;
489
-                return;
490
-            }
491
-            // lock the transaction
492
-            $this->checkout->transaction->lock();
493
-            // make sure all of our cached objects are added to their respective model entity mappers
494
-            $this->checkout->refresh_all_entities();
495
-            // set amount owing
496
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
497
-            // initialize each reg step, which gives them the chance to potentially alter the process
498
-            $this->_initialize_reg_steps();
499
-            // DEBUG LOG
500
-            //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
501
-            // get reg form
502
-            if( ! $this->_check_form_submission()) {
503
-                EED_Single_Page_Checkout::$_initialized = true;
504
-                return;
505
-            }
506
-            // checkout the action!!!
507
-            $this->_process_form_action();
508
-            // add some style and make it dance
509
-            $this->add_styles_and_scripts();
510
-            // kk... SPCO has successfully run
511
-            EED_Single_Page_Checkout::$_initialized = true;
512
-            // set no cache headers and constants
513
-            EE_System::do_not_cache();
514
-            // add anchor
515
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
516
-            // remove transaction lock
517
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
518
-        } catch (Exception $e) {
519
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
520
-        }
521
-    }
522
-
523
-
524
-
525
-    /**
526
-     *    _verify_session
527
-     * checks that the session is valid and not expired
528
-     *
529
-     * @access    private
530
-     * @throws EE_Error
531
-     */
532
-    private function _verify_session()
533
-    {
534
-        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
535
-            throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
536
-        }
537
-        // is session still valid ?
538
-        if (EE_Registry::instance()->SSN->expired() && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '') {
539
-            $this->checkout = new EE_Checkout();
540
-            EE_Registry::instance()->SSN->reset_cart();
541
-            EE_Registry::instance()->SSN->reset_checkout();
542
-            EE_Registry::instance()->SSN->reset_transaction();
543
-            EE_Error::add_attention(EE_Registry::$i18n_js_strings['registration_expiration_notice'], __FILE__,
544
-                __FUNCTION__, __LINE__);
545
-            EE_Registry::instance()->SSN->reset_expired();
546
-        }
547
-    }
548
-
549
-
550
-
551
-    /**
552
-     *    _initialize_checkout
553
-     * loads and instantiates EE_Checkout
554
-     *
555
-     * @access    private
556
-     * @throws EE_Error
557
-     * @return EE_Checkout
558
-     */
559
-    private function _initialize_checkout()
560
-    {
561
-        // look in session for existing checkout
562
-        /** @type EE_Checkout $checkout */
563
-        $checkout = EE_Registry::instance()->SSN->checkout();
564
-        // verify
565
-        if ( ! $checkout instanceof EE_Checkout) {
566
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
567
-            $checkout = EE_Registry::instance()->load_file(SPCO_INC_PATH, 'EE_Checkout', 'class', array(), false);
568
-        } else {
569
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
570
-                $this->unlock_transaction();
571
-                wp_safe_redirect($checkout->redirect_url);
572
-                exit();
573
-            }
574
-        }
575
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
576
-        // verify again
577
-        if ( ! $checkout instanceof EE_Checkout) {
578
-            throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
579
-        }
580
-        // reset anything that needs a clean slate for each request
581
-        $checkout->reset_for_current_request();
582
-        return $checkout;
583
-    }
584
-
585
-
586
-
587
-    /**
588
-     *    _get_request_vars
589
-     *
590
-     * @access    private
591
-     * @return    void
592
-     * @throws \EE_Error
593
-     */
594
-    private function _get_request_vars()
595
-    {
596
-        // load classes
597
-        EED_Single_Page_Checkout::load_request_handler();
598
-        //make sure this request is marked as belonging to EE
599
-        EE_Registry::instance()->REQ->set_espresso_page(true);
600
-        // which step is being requested ?
601
-        $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
602
-        // which step is being edited ?
603
-        $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
604
-        // and what we're doing on the current step
605
-        $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
606
-        // timestamp
607
-        $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
608
-        // returning to edit ?
609
-        $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
610
-        // or some other kind of revisit ?
611
-        $this->checkout->revisit = EE_Registry::instance()->REQ->get('revisit', false);
612
-        // and whether or not to generate a reg form for this request
613
-        $this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get('generate_reg_form', true);        // TRUE 	FALSE
614
-        // and whether or not to process a reg form submission for this request
615
-        $this->checkout->process_form_submission = EE_Registry::instance()->REQ->get(
616
-            'process_form_submission',
617
-            $this->checkout->action === 'process_reg_step'
618
-        ); // TRUE 	FALSE
619
-        $this->checkout->process_form_submission = $this->checkout->action !== 'display_spco_reg_step'
620
-            ? $this->checkout->process_form_submission
621
-            : false;        // TRUE 	FALSE
622
-        // $this->_display_request_vars();
623
-    }
624
-
625
-
626
-
627
-    /**
628
-     *  _display_request_vars
629
-     *
630
-     * @access    protected
631
-     * @return    void
632
-     */
633
-    protected function _display_request_vars()
634
-    {
635
-        if ( ! WP_DEBUG) {
636
-            return;
637
-        }
638
-        EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
639
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
640
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
641
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
642
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
643
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
644
-        EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
645
-        EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
646
-    }
647
-
648
-
649
-
650
-    /**
651
-     * _block_bots
652
-     * checks that the incoming request has either of the following set:
653
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
654
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
655
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
656
-     * then where you coming from man?
657
-     *
658
-     * @return boolean
659
-     */
660
-    private function _block_bots()
661
-    {
662
-        $invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
663
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
664
-            return true;
665
-        }
666
-        return false;
667
-    }
668
-
669
-
670
-
671
-    /**
672
-     *    _get_first_step
673
-     *  gets slug for first step in $_reg_steps_array
674
-     *
675
-     * @access    private
676
-     * @throws EE_Error
677
-     * @return    array
678
-     */
679
-    private function _get_first_step()
680
-    {
681
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
682
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
683
-    }
684
-
685
-
686
-
687
-    /**
688
-     *    _load_and_instantiate_reg_steps
689
-     *  instantiates each reg step based on the loaded reg_steps array
690
-     *
691
-     * @access    private
692
-     * @throws EE_Error
693
-     * @return    bool
694
-     */
695
-    private function _load_and_instantiate_reg_steps()
696
-    {
697
-        // have reg_steps already been instantiated ?
698
-        if (
699
-            empty($this->checkout->reg_steps)
700
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
701
-        ) {
702
-            // if not, then loop through raw reg steps array
703
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
704
-                if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
705
-                    return false;
706
-                }
707
-            }
708
-            EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
709
-            EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
710
-            // skip the registration_confirmation page ?
711
-            if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
712
-                // just remove it from the reg steps array
713
-                $this->checkout->remove_reg_step('registration_confirmation', false);
714
-            } else if (
715
-                isset($this->checkout->reg_steps['registration_confirmation'])
716
-                && EE_Registry::instance()->CFG->registration->reg_confirmation_last
717
-            ) {
718
-                // set the order to something big like 100
719
-                $this->checkout->set_reg_step_order('registration_confirmation', 100);
720
-            }
721
-            // filter the array for good luck
722
-            $this->checkout->reg_steps = apply_filters(
723
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
724
-                $this->checkout->reg_steps
725
-            );
726
-            // finally re-sort based on the reg step class order properties
727
-            $this->checkout->sort_reg_steps();
728
-        } else {
729
-            foreach ($this->checkout->reg_steps as $reg_step) {
730
-                // set all current step stati to FALSE
731
-                $reg_step->set_is_current_step(false);
732
-            }
733
-        }
734
-        if (empty($this->checkout->reg_steps)) {
735
-            EE_Error::add_error(__('No Reg Steps were loaded..', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
736
-            return false;
737
-        }
738
-        // make reg step details available to JS
739
-        $this->checkout->set_reg_step_JSON_info();
740
-        return true;
741
-    }
742
-
743
-
744
-
745
-    /**
746
-     *     _load_and_instantiate_reg_step
747
-     *
748
-     * @access    private
749
-     * @param array $reg_step
750
-     * @param int   $order
751
-     * @return bool
752
-     */
753
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
754
-    {
755
-        // we need a file_path, class_name, and slug to add a reg step
756
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
757
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
758
-            if (
759
-                $this->checkout->reg_url_link
760
-                && $this->checkout->step !== $reg_step['slug']
761
-                && $reg_step['slug'] !== 'finalize_registration'
762
-            ) {
763
-                return true;
764
-            }
765
-            // instantiate step class using file path and class name
766
-            $reg_step_obj = EE_Registry::instance()->load_file(
767
-                $reg_step['file_path'],
768
-                $reg_step['class_name'],
769
-                'class',
770
-                $this->checkout,
771
-                false
772
-            );
773
-            // did we gets the goods ?
774
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
775
-                // set reg step order based on config
776
-                $reg_step_obj->set_order($order);
777
-                // add instantiated reg step object to the master reg steps array
778
-                $this->checkout->add_reg_step($reg_step_obj);
779
-            } else {
780
-                EE_Error::add_error(
781
-                    __('The current step could not be set.', 'event_espresso'),
782
-                    __FILE__, __FUNCTION__, __LINE__
783
-                );
784
-                return false;
785
-            }
786
-        } else {
787
-            if (WP_DEBUG) {
788
-                EE_Error::add_error(
789
-                    sprintf(
790
-                        __('A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso'),
791
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
792
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
793
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
794
-                        '<ul>',
795
-                        '<li>',
796
-                        '</li>',
797
-                        '</ul>'
798
-                    ),
799
-                    __FILE__, __FUNCTION__, __LINE__
800
-                );
801
-            }
802
-            return false;
803
-        }
804
-        return true;
805
-    }
806
-
807
-
808
-
809
-    /**
810
-     * _verify_transaction_and_get_registrations
811
-     *
812
-     * @access private
813
-     * @return bool
814
-     */
815
-    private function _verify_transaction_and_get_registrations()
816
-    {
817
-        // was there already a valid transaction in the checkout from the session ?
818
-        if ( ! $this->checkout->transaction instanceof EE_Transaction) {
819
-            // get transaction from db or session
820
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
821
-                ? $this->_get_transaction_and_cart_for_previous_visit()
822
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
823
-            if ( ! $this->checkout->transaction instanceof EE_Transaction) {
824
-                EE_Error::add_error(
825
-                    __('Your Registration and Transaction information could not be retrieved from the db.',
826
-                        'event_espresso'),
827
-                    __FILE__, __FUNCTION__, __LINE__
828
-                );
829
-                $this->checkout->transaction = EE_Transaction::new_instance();
830
-                // add some style and make it dance
831
-                $this->add_styles_and_scripts();
832
-                EED_Single_Page_Checkout::$_initialized = true;
833
-                return false;
834
-            }
835
-            // and the registrations for the transaction
836
-            $this->_get_registrations($this->checkout->transaction);
837
-        }
838
-        return true;
839
-    }
840
-
841
-
842
-
843
-    /**
844
-     * _get_transaction_and_cart_for_previous_visit
845
-     *
846
-     * @access private
847
-     * @return mixed EE_Transaction|NULL
848
-     */
849
-    private function _get_transaction_and_cart_for_previous_visit()
850
-    {
851
-        /** @var $TXN_model EEM_Transaction */
852
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
853
-        // because the reg_url_link is present in the request, this is a return visit to SPCO, so we'll get the transaction data from the db
854
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
855
-        // verify transaction
856
-        if ($transaction instanceof EE_Transaction) {
857
-            // and get the cart that was used for that transaction
858
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
859
-            return $transaction;
860
-        } else {
861
-            EE_Error::add_error(__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
862
-            return null;
863
-        }
864
-    }
865
-
866
-
867
-
868
-    /**
869
-     * _get_cart_for_transaction
870
-     *
871
-     * @access private
872
-     * @param EE_Transaction $transaction
873
-     * @return EE_Cart
874
-     */
875
-    private function _get_cart_for_transaction($transaction)
876
-    {
877
-        return $this->checkout->get_cart_for_transaction($transaction);
878
-    }
879
-
880
-
881
-
882
-    /**
883
-     * get_cart_for_transaction
884
-     *
885
-     * @access public
886
-     * @param EE_Transaction $transaction
887
-     * @return EE_Cart
888
-     */
889
-    public function get_cart_for_transaction(EE_Transaction $transaction)
890
-    {
891
-        return $this->checkout->get_cart_for_transaction($transaction);
892
-    }
893
-
894
-
895
-
896
-    /**
897
-     * _get_transaction_and_cart_for_current_session
898
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
899
-     *
900
-     * @access private
901
-     * @return EE_Transaction
902
-     * @throws \EE_Error
903
-     */
904
-    private function _get_cart_for_current_session_and_setup_new_transaction()
905
-    {
906
-        //  if there's no transaction, then this is the FIRST visit to SPCO
907
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
908
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
909
-        // and then create a new transaction
910
-        $transaction = $this->_initialize_transaction();
911
-        // verify transaction
912
-        if ($transaction instanceof EE_Transaction) {
913
-            // save it so that we have an ID for other objects to use
914
-            $transaction->save();
915
-            // and save TXN data to the cart
916
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
917
-        } else {
918
-            EE_Error::add_error(__('A Valid Transaction could not be initialized.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
919
-        }
920
-        return $transaction;
921
-    }
922
-
923
-
924
-
925
-    /**
926
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
927
-     *
928
-     * @access private
929
-     * @return mixed EE_Transaction|NULL
930
-     */
931
-    private function _initialize_transaction()
932
-    {
933
-        try {
934
-            // ensure cart totals have been calculated
935
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
936
-            // grab the cart grand total
937
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
938
-            // create new TXN
939
-            $transaction = EE_Transaction::new_instance(
940
-                array(
941
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
942
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
943
-                    'TXN_paid'      => 0,
944
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
945
-                )
946
-            );
947
-            // save it so that we have an ID for other objects to use
948
-            $transaction->save();
949
-            // set cron job for following up on TXNs after their session has expired
950
-            EE_Cron_Tasks::schedule_expired_transaction_check(
951
-                EE_Registry::instance()->SSN->expiration() + 1,
952
-                $transaction->ID()
953
-            );
954
-            return $transaction;
955
-        } catch (Exception $e) {
956
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
957
-        }
958
-        return null;
959
-    }
960
-
961
-
962
-
963
-    /**
964
-     * _get_registrations
965
-     *
966
-     * @access private
967
-     * @param EE_Transaction $transaction
968
-     * @return void
969
-     * @throws \EventEspresso\core\exceptions\InvalidEntityException
970
-     * @throws \EE_Error
971
-     */
972
-    private function _get_registrations(EE_Transaction $transaction)
973
-    {
974
-        // first step: grab the registrants  { : o
975
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true);
976
-        // verify registrations have been set
977
-        if (empty($registrations)) {
978
-            // if no cached registrations, then check the db
979
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
980
-            // still nothing ? well as long as this isn't a revisit
981
-            if (empty($registrations) && ! $this->checkout->revisit) {
982
-                // generate new registrations from scratch
983
-                $registrations = $this->_initialize_registrations($transaction);
984
-            }
985
-        }
986
-        // sort by their original registration order
987
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
988
-        // then loop thru the array
989
-        foreach ($registrations as $registration) {
990
-            // verify each registration
991
-            if ($registration instanceof EE_Registration) {
992
-                // we display all attendee info for the primary registrant
993
-                if ($this->checkout->reg_url_link === $registration->reg_url_link()
994
-                    && $registration->is_primary_registrant()
995
-                ) {
996
-                    $this->checkout->primary_revisit = true;
997
-                    break;
998
-                } else if ($this->checkout->revisit
999
-                           && $this->checkout->reg_url_link !== $registration->reg_url_link()
1000
-                ) {
1001
-                    // but hide info if it doesn't belong to you
1002
-                    $transaction->clear_cache('Registration', $registration->ID());
1003
-                }
1004
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1005
-            }
1006
-        }
1007
-    }
1008
-
1009
-
1010
-
1011
-    /**
1012
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1013
-     *
1014
-     * @access private
1015
-     * @param EE_Transaction $transaction
1016
-     * @return    array
1017
-     * @throws \EventEspresso\core\exceptions\InvalidEntityException
1018
-     * @throws \EE_Error
1019
-     */
1020
-    private function _initialize_registrations(EE_Transaction $transaction)
1021
-    {
1022
-        $att_nmbr = 0;
1023
-        $registrations = array();
1024
-        if ($transaction instanceof EE_Transaction) {
1025
-            /** @type EE_Registration_Processor $registration_processor */
1026
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1027
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1028
-            // now let's add the cart items to the $transaction
1029
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1030
-                //do the following for each ticket of this type they selected
1031
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1032
-                    $att_nmbr++;
1033
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1034
-                    $CreateRegistrationCommand = EE_Registry::instance()
1035
-                                                            ->create(
1036
-                                                                'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1037
-                                                                array(
1038
-                                                                    $transaction,
1039
-                                                                    $line_item,
1040
-                                                                    $att_nmbr,
1041
-                                                                    $this->checkout->total_ticket_count,
1042
-                                                                )
1043
-                                                            );
1044
-                    // override capabilities for frontend registrations
1045
-                    if ( ! is_admin()) {
1046
-                        $CreateRegistrationCommand->setCapCheck(
1047
-                            new PublicCapabilities('', 'create_new_registration')
1048
-                        );
1049
-                    }
1050
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1051
-                    if ( ! $registration instanceof EE_Registration) {
1052
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1053
-                    }
1054
-                    $registrations[ $registration->ID() ] = $registration;
1055
-                }
1056
-            }
1057
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1058
-        }
1059
-        return $registrations;
1060
-    }
1061
-
1062
-
1063
-
1064
-    /**
1065
-     * sorts registrations by REG_count
1066
-     *
1067
-     * @access public
1068
-     * @param EE_Registration $reg_A
1069
-     * @param EE_Registration $reg_B
1070
-     * @return int
1071
-     */
1072
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1073
-    {
1074
-        // this shouldn't ever happen within the same TXN, but oh well
1075
-        if ($reg_A->count() === $reg_B->count()) {
1076
-            return 0;
1077
-        }
1078
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1079
-    }
1080
-
1081
-
1082
-
1083
-    /**
1084
-     *    _final_verifications
1085
-     * just makes sure that everything is set up correctly before proceeding
1086
-     *
1087
-     * @access    private
1088
-     * @return    bool
1089
-     * @throws \EE_Error
1090
-     */
1091
-    private function _final_verifications()
1092
-    {
1093
-        // filter checkout
1094
-        $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout);
1095
-        //verify that current step is still set correctly
1096
-        if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1097
-            EE_Error::add_error(
1098
-                __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'),
1099
-                __FILE__,
1100
-                __FUNCTION__,
1101
-                __LINE__
1102
-            );
1103
-            return false;
1104
-        }
1105
-        // if returning to SPCO, then verify that primary registrant is set
1106
-        if ( ! empty($this->checkout->reg_url_link)) {
1107
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1108
-            if ( ! $valid_registrant instanceof EE_Registration) {
1109
-                EE_Error::add_error(
1110
-                    __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'),
1111
-                    __FILE__,
1112
-                    __FUNCTION__,
1113
-                    __LINE__
1114
-                );
1115
-                return false;
1116
-            }
1117
-            $valid_registrant = null;
1118
-            foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1119
-                if (
1120
-                    $registration instanceof EE_Registration
1121
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1122
-                ) {
1123
-                    $valid_registrant = $registration;
1124
-                }
1125
-            }
1126
-            if ( ! $valid_registrant instanceof EE_Registration) {
1127
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1128
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1129
-                    // clear the session, mark the checkout as unverified, and try again
1130
-                    EE_Registry::instance()->SSN->clear_session();
1131
-                    EED_Single_Page_Checkout::$_initialized = false;
1132
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1133
-                    $this->_initialize();
1134
-                    EE_Error::reset_notices();
1135
-                    return false;
1136
-                }
1137
-                EE_Error::add_error(
1138
-                    __('We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso'),
1139
-                    __FILE__,
1140
-                    __FUNCTION__,
1141
-                    __LINE__
1142
-                );
1143
-                return false;
1144
-            }
1145
-        }
1146
-        // now that things have been kinda sufficiently verified,
1147
-        // let's add the checkout to the session so that's available other systems
1148
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1149
-        return true;
1150
-    }
1151
-
1152
-
1153
-
1154
-    /**
1155
-     *    _initialize_reg_steps
1156
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1157
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1158
-     *
1159
-     * @access    private
1160
-     * @param bool $reinitializing
1161
-     * @throws \EE_Error
1162
-     */
1163
-    private function _initialize_reg_steps($reinitializing = false)
1164
-    {
1165
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1166
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1167
-        foreach ($this->checkout->reg_steps as $reg_step) {
1168
-            if ( ! $reg_step->initialize_reg_step()) {
1169
-                // if not initialized then maybe this step is being removed...
1170
-                if ( ! $reinitializing && $reg_step->is_current_step()) {
1171
-                    // if it was the current step, then we need to start over here
1172
-                    $this->_initialize_reg_steps(true);
1173
-                    return;
1174
-                }
1175
-                continue;
1176
-            }
1177
-            // add css and JS for current step
1178
-            $reg_step->enqueue_styles_and_scripts();
1179
-            // i18n
1180
-            $reg_step->translate_js_strings();
1181
-            if ($reg_step->is_current_step()) {
1182
-                // the text that appears on the reg step form submit button
1183
-                $reg_step->set_submit_button_text();
1184
-            }
1185
-        }
1186
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1187
-        do_action("AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step);
1188
-    }
1189
-
1190
-
1191
-
1192
-    /**
1193
-     * _check_form_submission
1194
-     *
1195
-     * @access private
1196
-     * @return boolean
1197
-     */
1198
-    private function _check_form_submission()
1199
-    {
1200
-        //does this request require the reg form to be generated ?
1201
-        if ($this->checkout->generate_reg_form) {
1202
-            // ever heard that song by Blue Rodeo ?
1203
-            try {
1204
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1205
-                // if not displaying a form, then check for form submission
1206
-                if (
1207
-                    $this->checkout->process_form_submission
1208
-                    && $this->checkout->current_step->reg_form->was_submitted()
1209
-                ) {
1210
-                    // clear out any old data in case this step is being run again
1211
-                    $this->checkout->current_step->set_valid_data(array());
1212
-                    // capture submitted form data
1213
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1214
-                        apply_filters('FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout)
1215
-                    );
1216
-                    // validate submitted form data
1217
-                    if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1218
-                        // thou shall not pass !!!
1219
-                        $this->checkout->continue_reg = false;
1220
-                        // any form validation errors?
1221
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1222
-                            $submission_error_messages = array();
1223
-                            // bad, bad, bad registrant
1224
-                            foreach ($this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error) {
1225
-                                if ($validation_error instanceof EE_Validation_Error) {
1226
-                                    $submission_error_messages[] = sprintf(
1227
-                                        __('%s : %s', 'event_espresso'),
1228
-                                        $validation_error->get_form_section()->html_label_text(),
1229
-                                        $validation_error->getMessage()
1230
-                                    );
1231
-                                }
1232
-                            }
1233
-                            EE_Error::add_error(implode('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__);
1234
-                        }
1235
-                        // well not really... what will happen is we'll just get redirected back to redo the current step
1236
-                        $this->go_to_next_step();
1237
-                        return false;
1238
-                    }
1239
-                }
1240
-            } catch (EE_Error $e) {
1241
-                $e->get_error();
1242
-            }
1243
-        }
1244
-        return true;
1245
-    }
1246
-
1247
-
1248
-
1249
-    /**
1250
-     * _process_action
1251
-     *
1252
-     * @access private
1253
-     * @return void
1254
-     * @throws \EE_Error
1255
-     */
1256
-    private function _process_form_action()
1257
-    {
1258
-        // what cha wanna do?
1259
-        switch ($this->checkout->action) {
1260
-            // AJAX next step reg form
1261
-            case 'display_spco_reg_step' :
1262
-                $this->checkout->redirect = false;
1263
-                if (EE_Registry::instance()->REQ->ajax) {
1264
-                    $this->checkout->json_response->set_reg_step_html($this->checkout->current_step->display_reg_form());
1265
-                }
1266
-                break;
1267
-            default :
1268
-                // meh... do one of those other steps first
1269
-                if ( ! empty($this->checkout->action) && is_callable(array($this->checkout->current_step, $this->checkout->action))) {
1270
-                    // dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1271
-                    do_action("AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step);
1272
-                    // call action on current step
1273
-                    if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1274
-                        // good registrant, you get to proceed
1275
-                        if (
1276
-                            $this->checkout->current_step->success_message() !== ''
1277
-                            && apply_filters(
1278
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1279
-                                false
1280
-                            )
1281
-                        ) {
1282
-                            EE_Error::add_success(
1283
-                                $this->checkout->current_step->success_message()
1284
-                                . '<br />' . $this->checkout->next_step->_instructions()
1285
-                            );
1286
-                        }
1287
-                        // pack it up, pack it in...
1288
-                        $this->_setup_redirect();
1289
-                    }
1290
-                    // dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1291
-                    do_action("AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step);
1292
-                } else {
1293
-                    EE_Error::add_error(
1294
-                        sprintf(
1295
-                            __('The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso'),
1296
-                            $this->checkout->action,
1297
-                            $this->checkout->current_step->name()
1298
-                        ),
1299
-                        __FILE__,
1300
-                        __FUNCTION__,
1301
-                        __LINE__
1302
-                    );
1303
-                }
1304
-            // end default
1305
-        }
1306
-        // store our progress so far
1307
-        $this->checkout->stash_transaction_and_checkout();
1308
-        // advance to the next step! If you pass GO, collect $200
1309
-        $this->go_to_next_step();
1310
-    }
1311
-
1312
-
1313
-
1314
-    /**
1315
-     *        add_styles_and_scripts
1316
-     *
1317
-     * @access        public
1318
-     * @return        void
1319
-     */
1320
-    public function add_styles_and_scripts()
1321
-    {
1322
-        // i18n
1323
-        $this->translate_js_strings();
1324
-        if ($this->checkout->admin_request) {
1325
-            add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1326
-        } else {
1327
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1328
-        }
1329
-    }
1330
-
1331
-
1332
-
1333
-    /**
1334
-     *        translate_js_strings
1335
-     *
1336
-     * @access        public
1337
-     * @return        void
1338
-     */
1339
-    public function translate_js_strings()
1340
-    {
1341
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1342
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1343
-        EE_Registry::$i18n_js_strings['server_error'] = __('An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso');
1344
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = __('An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso');
1345
-        EE_Registry::$i18n_js_strings['validation_error'] = __('There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso');
1346
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = __('There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso');
1347
-        EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso');
1348
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = __('We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', 'event_espresso');
1349
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1350
-            __('Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso'),
1351
-            '<br/>',
1352
-            '<br/>'
1353
-        );
1354
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1355
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1356
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1357
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1358
-        EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1359
-        EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1360
-        EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1361
-        EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1362
-        EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1363
-        EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1364
-        EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1365
-        EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1366
-        EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1367
-        EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1368
-        EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1369
-        EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1370
-        EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1371
-        EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1372
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
1373
-            __(
1374
-                '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
1375
-                'event_espresso'
1376
-            ),
1377
-            '<h4 class="important-notice">',
1378
-            '</h4>',
1379
-            '<br />',
1380
-            '<p>',
1381
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1382
-            '">',
1383
-            '</a>',
1384
-            '</p>'
1385
-        );
1386
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters('FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true);
1387
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1388
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1389
-        );
1390
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1391
-            'M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1392
-        );
1393
-    }
1394
-
1395
-
1396
-
1397
-    /**
1398
-     *    enqueue_styles_and_scripts
1399
-     *
1400
-     * @access        public
1401
-     * @return        void
1402
-     * @throws \EE_Error
1403
-     */
1404
-    public function enqueue_styles_and_scripts()
1405
-    {
1406
-        // load css
1407
-        wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION);
1408
-        wp_enqueue_style('single_page_checkout');
1409
-        // load JS
1410
-        wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js', array('jquery'), '1.0.1', true);
1411
-        wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js', array('jquery_plugin'), '2.0.2', true);
1412
-        wp_register_script('single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true);
1413
-        $this->checkout->registration_form->enqueue_js();
1414
-        $this->checkout->current_step->reg_form->enqueue_js();
1415
-        wp_enqueue_script('single_page_checkout');
1416
-        /**
1417
-         * global action hook for enqueueing styles and scripts with
1418
-         * spco calls.
1419
-         */
1420
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1421
-        /**
1422
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1423
-         * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1424
-         */
1425
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this);
1426
-    }
1427
-
1428
-
1429
-
1430
-    /**
1431
-     *    display the Registration Single Page Checkout Form
1432
-     *
1433
-     * @access    private
1434
-     * @return    void
1435
-     * @throws \EE_Error
1436
-     */
1437
-    private function _display_spco_reg_form()
1438
-    {
1439
-        // if registering via the admin, just display the reg form for the current step
1440
-        if ($this->checkout->admin_request) {
1441
-            EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1442
-        } else {
1443
-            // add powered by EE msg
1444
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1445
-            $empty_cart = count($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)) < 1
1446
-                ? true
1447
-                : false;
1448
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1449
-            $cookies_not_set_msg = '';
1450
-            if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) {
1451
-                $cookies_not_set_msg = apply_filters(
1452
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1453
-                    sprintf(
1454
-                        __(
1455
-                            '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1456
-                            'event_espresso'
1457
-                        ),
1458
-                        '<div class="ee-attention">',
1459
-                        '</div>',
1460
-                        '<h6 class="important-notice">',
1461
-                        '</h6>',
1462
-                        '<p>',
1463
-                        '</p>',
1464
-                        '<br />',
1465
-                        '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1466
-                        '</a>'
1467
-                    )
1468
-                );
1469
-            }
1470
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1471
-                array(
1472
-                    'name'            => 'single-page-checkout',
1473
-                    'html_id'         => 'ee-single-page-checkout-dv',
1474
-                    'layout_strategy' =>
1475
-                        new EE_Template_Layout(
1476
-                            array(
1477
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1478
-                                'template_args'        => array(
1479
-                                    'empty_cart'              => $empty_cart,
1480
-                                    'revisit'                 => $this->checkout->revisit,
1481
-                                    'reg_steps'               => $this->checkout->reg_steps,
1482
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1483
-                                        ? $this->checkout->next_step->slug()
1484
-                                        : '',
1485
-                                    'cancel_page_url'         => $this->checkout->cancel_page_url,
1486
-                                    'empty_msg'               => apply_filters(
1487
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1488
-                                        sprintf(
1489
-                                            __('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1490
-                                                'event_espresso'),
1491
-                                            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1492
-                                            '">',
1493
-                                            '</a>'
1494
-                                        )
1495
-                                    ),
1496
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1497
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1498
-                                    'session_expiration'      =>
1499
-                                        date('M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)),
1500
-                                ),
1501
-                            )
1502
-                        ),
1503
-                )
1504
-            );
1505
-            // load template and add to output sent that gets filtered into the_content()
1506
-            EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1507
-        }
1508
-    }
1509
-
1510
-
1511
-
1512
-    /**
1513
-     *    add_extra_finalize_registration_inputs
1514
-     *
1515
-     * @access    public
1516
-     * @param $next_step
1517
-     * @internal  param string $label
1518
-     * @return void
1519
-     */
1520
-    public function add_extra_finalize_registration_inputs($next_step)
1521
-    {
1522
-        if ($next_step === 'finalize_registration') {
1523
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1524
-        }
1525
-    }
1526
-
1527
-
1528
-
1529
-    /**
1530
-     *    display_registration_footer
1531
-     *
1532
-     * @access    public
1533
-     * @return    string
1534
-     */
1535
-    public static function display_registration_footer()
1536
-    {
1537
-        if (
1538
-        apply_filters(
1539
-            'FHEE__EE_Front__Controller__show_reg_footer',
1540
-            EE_Registry::instance()->CFG->admin->show_reg_footer
1541
-        )
1542
-        ) {
1543
-            add_filter(
1544
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1545
-                function ($url) {
1546
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1547
-                }
1548
-            );
1549
-            echo apply_filters(
1550
-                'FHEE__EE_Front_Controller__display_registration_footer',
1551
-                \EEH_Template::powered_by_event_espresso(
1552
-                    '',
1553
-                    'espresso-registration-footer-dv',
1554
-                    array('utm_content' => 'registration_checkout')
1555
-                )
1556
-            );
1557
-        }
1558
-        return '';
1559
-    }
1560
-
1561
-
1562
-
1563
-    /**
1564
-     *    unlock_transaction
1565
-     *
1566
-     * @access    public
1567
-     * @return    void
1568
-     * @throws \EE_Error
1569
-     */
1570
-    public function unlock_transaction()
1571
-    {
1572
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1573
-            $this->checkout->transaction->unlock();
1574
-        }
1575
-    }
1576
-
1577
-
1578
-
1579
-    /**
1580
-     *        _setup_redirect
1581
-     *
1582
-     * @access    private
1583
-     * @return void
1584
-     */
1585
-    private function _setup_redirect()
1586
-    {
1587
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1588
-            $this->checkout->redirect = true;
1589
-            if (empty($this->checkout->redirect_url)) {
1590
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1591
-            }
1592
-            $this->checkout->redirect_url = apply_filters(
1593
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1594
-                $this->checkout->redirect_url,
1595
-                $this->checkout
1596
-            );
1597
-        }
1598
-    }
1599
-
1600
-
1601
-
1602
-    /**
1603
-     *   handle ajax message responses and redirects
1604
-     *
1605
-     * @access public
1606
-     * @return void
1607
-     * @throws \EE_Error
1608
-     */
1609
-    public function go_to_next_step()
1610
-    {
1611
-        if (EE_Registry::instance()->REQ->ajax) {
1612
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1613
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1614
-        }
1615
-        $this->unlock_transaction();
1616
-        // just return for these conditions
1617
-        if (
1618
-            $this->checkout->admin_request
1619
-            || $this->checkout->action === 'redirect_form'
1620
-            || $this->checkout->action === 'update_checkout'
1621
-        ) {
1622
-            return;
1623
-        }
1624
-        // AJAX response
1625
-        $this->_handle_json_response();
1626
-        // redirect to next step or the Thank You page
1627
-        $this->_handle_html_redirects();
1628
-        // hmmm... must be something wrong, so let's just display the form again !
1629
-        $this->_display_spco_reg_form();
1630
-    }
1631
-
1632
-
1633
-
1634
-    /**
1635
-     *   _handle_json_response
1636
-     *
1637
-     * @access protected
1638
-     * @return void
1639
-     */
1640
-    protected function _handle_json_response()
1641
-    {
1642
-        // if this is an ajax request
1643
-        if (EE_Registry::instance()->REQ->ajax) {
1644
-            // DEBUG LOG
1645
-            //$this->checkout->log(
1646
-            //	__CLASS__, __FUNCTION__, __LINE__,
1647
-            //	array(
1648
-            //		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1649
-            //		'redirect'                   => $this->checkout->redirect,
1650
-            //		'continue_reg'               => $this->checkout->continue_reg,
1651
-            //	)
1652
-            //);
1653
-            $this->checkout->json_response->set_registration_time_limit(
1654
-                $this->checkout->get_registration_time_limit()
1655
-            );
1656
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1657
-            // just send the ajax (
1658
-            $json_response = apply_filters(
1659
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1660
-                $this->checkout->json_response
1661
-            );
1662
-            echo $json_response;
1663
-            exit();
1664
-        }
1665
-    }
1666
-
1667
-
1668
-
1669
-    /**
1670
-     *   _handle_redirects
1671
-     *
1672
-     * @access protected
1673
-     * @return void
1674
-     */
1675
-    protected function _handle_html_redirects()
1676
-    {
1677
-        // going somewhere ?
1678
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1679
-            // store notices in a transient
1680
-            EE_Error::get_notices(false, true, true);
1681
-            // DEBUG LOG
1682
-            //$this->checkout->log(
1683
-            //	__CLASS__, __FUNCTION__, __LINE__,
1684
-            //	array(
1685
-            //		'headers_sent' => headers_sent(),
1686
-            //		'redirect_url'     => $this->checkout->redirect_url,
1687
-            //		'headers_list'    => headers_list(),
1688
-            //	)
1689
-            //);
1690
-            wp_safe_redirect($this->checkout->redirect_url);
1691
-            exit();
1692
-        }
1693
-    }
1694
-
1695
-
1696
-
1697
-    /**
1698
-     *   set_checkout_anchor
1699
-     *
1700
-     * @access public
1701
-     * @return void
1702
-     */
1703
-    public function set_checkout_anchor()
1704
-    {
1705
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1706
-    }
20
+	/**
21
+	 * $_initialized - has the SPCO controller already been initialized ?
22
+	 *
23
+	 * @access private
24
+	 * @var bool $_initialized
25
+	 */
26
+	private static $_initialized = false;
27
+
28
+
29
+	/**
30
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
31
+	 *
32
+	 * @access private
33
+	 * @var bool $_valid_checkout
34
+	 */
35
+	private static $_checkout_verified = true;
36
+
37
+	/**
38
+	 *    $_reg_steps_array - holds initial array of reg steps
39
+	 *
40
+	 * @access private
41
+	 * @var array $_reg_steps_array
42
+	 */
43
+	private static $_reg_steps_array = array();
44
+
45
+	/**
46
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
47
+	 *
48
+	 * @access public
49
+	 * @var EE_Checkout $checkout
50
+	 */
51
+	public $checkout;
52
+
53
+
54
+
55
+	/**
56
+	 * @return EED_Single_Page_Checkout
57
+	 */
58
+	public static function instance()
59
+	{
60
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
61
+		return parent::get_instance(__CLASS__);
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * @return EE_CART
68
+	 */
69
+	public function cart()
70
+	{
71
+		return $this->checkout->cart;
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * @return EE_Transaction
78
+	 */
79
+	public function transaction()
80
+	{
81
+		return $this->checkout->transaction;
82
+	}
83
+
84
+
85
+
86
+	/**
87
+	 *    set_hooks - for hooking into EE Core, other modules, etc
88
+	 *
89
+	 * @access    public
90
+	 * @return    void
91
+	 * @throws \EE_Error
92
+	 */
93
+	public static function set_hooks()
94
+	{
95
+		EED_Single_Page_Checkout::set_definitions();
96
+	}
97
+
98
+
99
+
100
+	/**
101
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
102
+	 *
103
+	 * @access    public
104
+	 * @return    void
105
+	 * @throws \EE_Error
106
+	 */
107
+	public static function set_hooks_admin()
108
+	{
109
+		EED_Single_Page_Checkout::set_definitions();
110
+		if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
111
+			// hook into the top of pre_get_posts to set the reg step routing, which gives other modules or plugins a chance to modify the reg steps, but just before the routes get called
112
+			add_action('pre_get_posts', array('EED_Single_Page_Checkout', 'load_reg_steps'), 1);
113
+			return;
114
+		}
115
+		// going to start an output buffer in case anything gets accidentally output that might disrupt our JSON response
116
+		ob_start();
117
+		EED_Single_Page_Checkout::load_request_handler();
118
+		EED_Single_Page_Checkout::load_reg_steps();
119
+		// set ajax hooks
120
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
121
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
122
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
123
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
124
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
125
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 *    process ajax request
132
+	 *
133
+	 * @param string $ajax_action
134
+	 * @throws \EE_Error
135
+	 */
136
+	public static function process_ajax_request($ajax_action)
137
+	{
138
+		EE_Registry::instance()->REQ->set('action', $ajax_action);
139
+		EED_Single_Page_Checkout::instance()->_initialize();
140
+	}
141
+
142
+
143
+
144
+	/**
145
+	 *    ajax display registration step
146
+	 *
147
+	 * @throws \EE_Error
148
+	 */
149
+	public static function display_reg_step()
150
+	{
151
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
152
+	}
153
+
154
+
155
+
156
+	/**
157
+	 *    ajax process registration step
158
+	 *
159
+	 * @throws \EE_Error
160
+	 */
161
+	public static function process_reg_step()
162
+	{
163
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 *    ajax process registration step
170
+	 *
171
+	 * @throws \EE_Error
172
+	 */
173
+	public static function update_reg_step()
174
+	{
175
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
176
+	}
177
+
178
+
179
+
180
+	/**
181
+	 *   update_checkout
182
+	 *
183
+	 * @access public
184
+	 * @return void
185
+	 * @throws \EE_Error
186
+	 */
187
+	public static function update_checkout()
188
+	{
189
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
190
+	}
191
+
192
+
193
+
194
+	/**
195
+	 *    load_request_handler
196
+	 *
197
+	 * @access    public
198
+	 * @return    void
199
+	 */
200
+	public static function load_request_handler()
201
+	{
202
+		// load core Request_Handler class
203
+		if ( ! isset(EE_Registry::instance()->REQ)) {
204
+			EE_Registry::instance()->load_core('Request_Handler');
205
+		}
206
+	}
207
+
208
+
209
+
210
+	/**
211
+	 *    set_definitions
212
+	 *
213
+	 * @access    public
214
+	 * @return    void
215
+	 * @throws \EE_Error
216
+	 */
217
+	public static function set_definitions()
218
+	{
219
+		define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS);
220
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
221
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
222
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
223
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
224
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
225
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
226
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
227
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
228
+			__('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
229
+				'event_espresso'),
230
+			'<h4 class="important-notice">',
231
+			'</h4>',
232
+			'<br />',
233
+			'<p>',
234
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
235
+			'">',
236
+			'</a>',
237
+			'</p>'
238
+		);
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * load_reg_steps
245
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
246
+	 *
247
+	 * @access    private
248
+	 * @throws EE_Error
249
+	 * @return void
250
+	 */
251
+	public static function load_reg_steps()
252
+	{
253
+		static $reg_steps_loaded = false;
254
+		if ($reg_steps_loaded) {
255
+			return;
256
+		}
257
+		// filter list of reg_steps
258
+		$reg_steps_to_load = (array)apply_filters(
259
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
260
+			EED_Single_Page_Checkout::get_reg_steps()
261
+		);
262
+		// sort by key (order)
263
+		ksort($reg_steps_to_load);
264
+		// loop through folders
265
+		foreach ($reg_steps_to_load as $order => $reg_step) {
266
+			// we need a
267
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
268
+				// copy over to the reg_steps_array
269
+				EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
270
+				// register custom key route for each reg step
271
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
272
+				EE_Config::register_route($reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step');
273
+				// add AJAX or other hooks
274
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
275
+					// setup autoloaders if necessary
276
+					if ( ! class_exists($reg_step['class_name'])) {
277
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder($reg_step['file_path'], true);
278
+					}
279
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
280
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
281
+					}
282
+				}
283
+			}
284
+		}
285
+		$reg_steps_loaded = true;
286
+	}
287
+
288
+
289
+
290
+	/**
291
+	 *    get_reg_steps
292
+	 *
293
+	 * @access    public
294
+	 * @return    array
295
+	 */
296
+	public static function get_reg_steps()
297
+	{
298
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
299
+		if (empty($reg_steps)) {
300
+			$reg_steps = array(
301
+				10  => array(
302
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
303
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
304
+					'slug'       => 'attendee_information',
305
+					'has_hooks'  => false,
306
+				),
307
+				20  => array(
308
+					'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
309
+					'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
310
+					'slug'       => 'registration_confirmation',
311
+					'has_hooks'  => false,
312
+				),
313
+				30  => array(
314
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
315
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
316
+					'slug'       => 'payment_options',
317
+					'has_hooks'  => true,
318
+				),
319
+				999 => array(
320
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
321
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
322
+					'slug'       => 'finalize_registration',
323
+					'has_hooks'  => false,
324
+				),
325
+			);
326
+		}
327
+		return $reg_steps;
328
+	}
329
+
330
+
331
+
332
+	/**
333
+	 *    registration_checkout_for_admin
334
+	 *
335
+	 * @access    public
336
+	 * @return    string
337
+	 * @throws \EE_Error
338
+	 */
339
+	public static function registration_checkout_for_admin()
340
+	{
341
+		EED_Single_Page_Checkout::load_reg_steps();
342
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
343
+		EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
344
+		EE_Registry::instance()->REQ->set('process_form_submission', false);
345
+		EED_Single_Page_Checkout::instance()->_initialize();
346
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
347
+		return EE_Registry::instance()->REQ->get_output();
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * process_registration_from_admin
354
+	 *
355
+	 * @access public
356
+	 * @return \EE_Transaction
357
+	 * @throws \EE_Error
358
+	 */
359
+	public static function process_registration_from_admin()
360
+	{
361
+		EED_Single_Page_Checkout::load_reg_steps();
362
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
363
+		EE_Registry::instance()->REQ->set('action', 'process_reg_step');
364
+		EE_Registry::instance()->REQ->set('process_form_submission', true);
365
+		EED_Single_Page_Checkout::instance()->_initialize();
366
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
367
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
368
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
369
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
370
+				if ($final_reg_step->process_reg_step()) {
371
+					$final_reg_step->set_completed();
372
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
373
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
374
+				}
375
+			}
376
+		}
377
+		return null;
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 *    run
384
+	 *
385
+	 * @access    public
386
+	 * @param WP_Query $WP_Query
387
+	 * @return    void
388
+	 * @throws \EE_Error
389
+	 */
390
+	public function run($WP_Query)
391
+	{
392
+		if (
393
+			$WP_Query instanceof WP_Query
394
+			&& $WP_Query->is_main_query()
395
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
396
+			&& $this->_is_reg_checkout()
397
+		) {
398
+			$this->_initialize();
399
+		}
400
+	}
401
+
402
+
403
+
404
+	/**
405
+	 * determines whether current url matches reg page url
406
+	 *
407
+	 * @return bool
408
+	 */
409
+	protected function _is_reg_checkout()
410
+	{
411
+		// get current permalink for reg page without any extra query args
412
+		$reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
413
+		// get request URI for current request, but without the scheme or host
414
+		$current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
415
+		$current_request_uri = html_entity_decode($current_request_uri);
416
+		// get array of query args from the current request URI
417
+		$query_args = \EEH_URL::get_query_string($current_request_uri);
418
+		// grab page id if it is set
419
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
420
+		// and remove the page id from the query args (we will re-add it later)
421
+		unset($query_args['page_id']);
422
+		// now strip all query args from current request URI
423
+		$current_request_uri = remove_query_arg(array_flip($query_args), $current_request_uri);
424
+		// and re-add the page id if it was set
425
+		if ($page_id) {
426
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
427
+		}
428
+		// remove slashes and ?
429
+		$current_request_uri = trim($current_request_uri, '?/');
430
+		// is current request URI part of the known full reg page URL ?
431
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
432
+	}
433
+
434
+
435
+
436
+	/**
437
+	 *    run
438
+	 *
439
+	 * @access    public
440
+	 * @param WP_Query $WP_Query
441
+	 * @return    void
442
+	 * @throws \EE_Error
443
+	 */
444
+	public static function init($WP_Query)
445
+	{
446
+		EED_Single_Page_Checkout::instance()->run($WP_Query);
447
+	}
448
+
449
+
450
+
451
+	/**
452
+	 *    _initialize - initial module setup
453
+	 *
454
+	 * @access    private
455
+	 * @throws EE_Error
456
+	 * @return    void
457
+	 */
458
+	private function _initialize()
459
+	{
460
+		// ensure SPCO doesn't run twice
461
+		if (EED_Single_Page_Checkout::$_initialized) {
462
+			return;
463
+		}
464
+		try {
465
+			$this->_verify_session();
466
+			// setup the EE_Checkout object
467
+			$this->checkout = $this->_initialize_checkout();
468
+			// filter checkout
469
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
470
+			// get the $_GET
471
+			$this->_get_request_vars();
472
+			if ($this->_block_bots()) {
473
+				return;
474
+			}
475
+			// filter continue_reg
476
+			$this->checkout->continue_reg = apply_filters('FHEE__EED_Single_Page_Checkout__init___continue_reg', true, $this->checkout);
477
+			// load the reg steps array
478
+			if ( ! $this->_load_and_instantiate_reg_steps()) {
479
+				EED_Single_Page_Checkout::$_initialized = true;
480
+				return;
481
+			}
482
+			// set the current step
483
+			$this->checkout->set_current_step($this->checkout->step);
484
+			// and the next step
485
+			$this->checkout->set_next_step();
486
+			// verify that everything has been setup correctly
487
+			if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
488
+				EED_Single_Page_Checkout::$_initialized = true;
489
+				return;
490
+			}
491
+			// lock the transaction
492
+			$this->checkout->transaction->lock();
493
+			// make sure all of our cached objects are added to their respective model entity mappers
494
+			$this->checkout->refresh_all_entities();
495
+			// set amount owing
496
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
497
+			// initialize each reg step, which gives them the chance to potentially alter the process
498
+			$this->_initialize_reg_steps();
499
+			// DEBUG LOG
500
+			//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
501
+			// get reg form
502
+			if( ! $this->_check_form_submission()) {
503
+				EED_Single_Page_Checkout::$_initialized = true;
504
+				return;
505
+			}
506
+			// checkout the action!!!
507
+			$this->_process_form_action();
508
+			// add some style and make it dance
509
+			$this->add_styles_and_scripts();
510
+			// kk... SPCO has successfully run
511
+			EED_Single_Page_Checkout::$_initialized = true;
512
+			// set no cache headers and constants
513
+			EE_System::do_not_cache();
514
+			// add anchor
515
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
516
+			// remove transaction lock
517
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
518
+		} catch (Exception $e) {
519
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
520
+		}
521
+	}
522
+
523
+
524
+
525
+	/**
526
+	 *    _verify_session
527
+	 * checks that the session is valid and not expired
528
+	 *
529
+	 * @access    private
530
+	 * @throws EE_Error
531
+	 */
532
+	private function _verify_session()
533
+	{
534
+		if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
535
+			throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
536
+		}
537
+		// is session still valid ?
538
+		if (EE_Registry::instance()->SSN->expired() && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '') {
539
+			$this->checkout = new EE_Checkout();
540
+			EE_Registry::instance()->SSN->reset_cart();
541
+			EE_Registry::instance()->SSN->reset_checkout();
542
+			EE_Registry::instance()->SSN->reset_transaction();
543
+			EE_Error::add_attention(EE_Registry::$i18n_js_strings['registration_expiration_notice'], __FILE__,
544
+				__FUNCTION__, __LINE__);
545
+			EE_Registry::instance()->SSN->reset_expired();
546
+		}
547
+	}
548
+
549
+
550
+
551
+	/**
552
+	 *    _initialize_checkout
553
+	 * loads and instantiates EE_Checkout
554
+	 *
555
+	 * @access    private
556
+	 * @throws EE_Error
557
+	 * @return EE_Checkout
558
+	 */
559
+	private function _initialize_checkout()
560
+	{
561
+		// look in session for existing checkout
562
+		/** @type EE_Checkout $checkout */
563
+		$checkout = EE_Registry::instance()->SSN->checkout();
564
+		// verify
565
+		if ( ! $checkout instanceof EE_Checkout) {
566
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
567
+			$checkout = EE_Registry::instance()->load_file(SPCO_INC_PATH, 'EE_Checkout', 'class', array(), false);
568
+		} else {
569
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
570
+				$this->unlock_transaction();
571
+				wp_safe_redirect($checkout->redirect_url);
572
+				exit();
573
+			}
574
+		}
575
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
576
+		// verify again
577
+		if ( ! $checkout instanceof EE_Checkout) {
578
+			throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
579
+		}
580
+		// reset anything that needs a clean slate for each request
581
+		$checkout->reset_for_current_request();
582
+		return $checkout;
583
+	}
584
+
585
+
586
+
587
+	/**
588
+	 *    _get_request_vars
589
+	 *
590
+	 * @access    private
591
+	 * @return    void
592
+	 * @throws \EE_Error
593
+	 */
594
+	private function _get_request_vars()
595
+	{
596
+		// load classes
597
+		EED_Single_Page_Checkout::load_request_handler();
598
+		//make sure this request is marked as belonging to EE
599
+		EE_Registry::instance()->REQ->set_espresso_page(true);
600
+		// which step is being requested ?
601
+		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
602
+		// which step is being edited ?
603
+		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
604
+		// and what we're doing on the current step
605
+		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
606
+		// timestamp
607
+		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
608
+		// returning to edit ?
609
+		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
610
+		// or some other kind of revisit ?
611
+		$this->checkout->revisit = EE_Registry::instance()->REQ->get('revisit', false);
612
+		// and whether or not to generate a reg form for this request
613
+		$this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get('generate_reg_form', true);        // TRUE 	FALSE
614
+		// and whether or not to process a reg form submission for this request
615
+		$this->checkout->process_form_submission = EE_Registry::instance()->REQ->get(
616
+			'process_form_submission',
617
+			$this->checkout->action === 'process_reg_step'
618
+		); // TRUE 	FALSE
619
+		$this->checkout->process_form_submission = $this->checkout->action !== 'display_spco_reg_step'
620
+			? $this->checkout->process_form_submission
621
+			: false;        // TRUE 	FALSE
622
+		// $this->_display_request_vars();
623
+	}
624
+
625
+
626
+
627
+	/**
628
+	 *  _display_request_vars
629
+	 *
630
+	 * @access    protected
631
+	 * @return    void
632
+	 */
633
+	protected function _display_request_vars()
634
+	{
635
+		if ( ! WP_DEBUG) {
636
+			return;
637
+		}
638
+		EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
639
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
640
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
641
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
642
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
643
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
644
+		EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
645
+		EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
646
+	}
647
+
648
+
649
+
650
+	/**
651
+	 * _block_bots
652
+	 * checks that the incoming request has either of the following set:
653
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
654
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
655
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
656
+	 * then where you coming from man?
657
+	 *
658
+	 * @return boolean
659
+	 */
660
+	private function _block_bots()
661
+	{
662
+		$invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
663
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
664
+			return true;
665
+		}
666
+		return false;
667
+	}
668
+
669
+
670
+
671
+	/**
672
+	 *    _get_first_step
673
+	 *  gets slug for first step in $_reg_steps_array
674
+	 *
675
+	 * @access    private
676
+	 * @throws EE_Error
677
+	 * @return    array
678
+	 */
679
+	private function _get_first_step()
680
+	{
681
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
682
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
683
+	}
684
+
685
+
686
+
687
+	/**
688
+	 *    _load_and_instantiate_reg_steps
689
+	 *  instantiates each reg step based on the loaded reg_steps array
690
+	 *
691
+	 * @access    private
692
+	 * @throws EE_Error
693
+	 * @return    bool
694
+	 */
695
+	private function _load_and_instantiate_reg_steps()
696
+	{
697
+		// have reg_steps already been instantiated ?
698
+		if (
699
+			empty($this->checkout->reg_steps)
700
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
701
+		) {
702
+			// if not, then loop through raw reg steps array
703
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
704
+				if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
705
+					return false;
706
+				}
707
+			}
708
+			EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true;
709
+			EE_Registry::instance()->CFG->registration->reg_confirmation_last = true;
710
+			// skip the registration_confirmation page ?
711
+			if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
712
+				// just remove it from the reg steps array
713
+				$this->checkout->remove_reg_step('registration_confirmation', false);
714
+			} else if (
715
+				isset($this->checkout->reg_steps['registration_confirmation'])
716
+				&& EE_Registry::instance()->CFG->registration->reg_confirmation_last
717
+			) {
718
+				// set the order to something big like 100
719
+				$this->checkout->set_reg_step_order('registration_confirmation', 100);
720
+			}
721
+			// filter the array for good luck
722
+			$this->checkout->reg_steps = apply_filters(
723
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
724
+				$this->checkout->reg_steps
725
+			);
726
+			// finally re-sort based on the reg step class order properties
727
+			$this->checkout->sort_reg_steps();
728
+		} else {
729
+			foreach ($this->checkout->reg_steps as $reg_step) {
730
+				// set all current step stati to FALSE
731
+				$reg_step->set_is_current_step(false);
732
+			}
733
+		}
734
+		if (empty($this->checkout->reg_steps)) {
735
+			EE_Error::add_error(__('No Reg Steps were loaded..', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
736
+			return false;
737
+		}
738
+		// make reg step details available to JS
739
+		$this->checkout->set_reg_step_JSON_info();
740
+		return true;
741
+	}
742
+
743
+
744
+
745
+	/**
746
+	 *     _load_and_instantiate_reg_step
747
+	 *
748
+	 * @access    private
749
+	 * @param array $reg_step
750
+	 * @param int   $order
751
+	 * @return bool
752
+	 */
753
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
754
+	{
755
+		// we need a file_path, class_name, and slug to add a reg step
756
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
757
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
758
+			if (
759
+				$this->checkout->reg_url_link
760
+				&& $this->checkout->step !== $reg_step['slug']
761
+				&& $reg_step['slug'] !== 'finalize_registration'
762
+			) {
763
+				return true;
764
+			}
765
+			// instantiate step class using file path and class name
766
+			$reg_step_obj = EE_Registry::instance()->load_file(
767
+				$reg_step['file_path'],
768
+				$reg_step['class_name'],
769
+				'class',
770
+				$this->checkout,
771
+				false
772
+			);
773
+			// did we gets the goods ?
774
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
775
+				// set reg step order based on config
776
+				$reg_step_obj->set_order($order);
777
+				// add instantiated reg step object to the master reg steps array
778
+				$this->checkout->add_reg_step($reg_step_obj);
779
+			} else {
780
+				EE_Error::add_error(
781
+					__('The current step could not be set.', 'event_espresso'),
782
+					__FILE__, __FUNCTION__, __LINE__
783
+				);
784
+				return false;
785
+			}
786
+		} else {
787
+			if (WP_DEBUG) {
788
+				EE_Error::add_error(
789
+					sprintf(
790
+						__('A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso'),
791
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
792
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
793
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
794
+						'<ul>',
795
+						'<li>',
796
+						'</li>',
797
+						'</ul>'
798
+					),
799
+					__FILE__, __FUNCTION__, __LINE__
800
+				);
801
+			}
802
+			return false;
803
+		}
804
+		return true;
805
+	}
806
+
807
+
808
+
809
+	/**
810
+	 * _verify_transaction_and_get_registrations
811
+	 *
812
+	 * @access private
813
+	 * @return bool
814
+	 */
815
+	private function _verify_transaction_and_get_registrations()
816
+	{
817
+		// was there already a valid transaction in the checkout from the session ?
818
+		if ( ! $this->checkout->transaction instanceof EE_Transaction) {
819
+			// get transaction from db or session
820
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
821
+				? $this->_get_transaction_and_cart_for_previous_visit()
822
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
823
+			if ( ! $this->checkout->transaction instanceof EE_Transaction) {
824
+				EE_Error::add_error(
825
+					__('Your Registration and Transaction information could not be retrieved from the db.',
826
+						'event_espresso'),
827
+					__FILE__, __FUNCTION__, __LINE__
828
+				);
829
+				$this->checkout->transaction = EE_Transaction::new_instance();
830
+				// add some style and make it dance
831
+				$this->add_styles_and_scripts();
832
+				EED_Single_Page_Checkout::$_initialized = true;
833
+				return false;
834
+			}
835
+			// and the registrations for the transaction
836
+			$this->_get_registrations($this->checkout->transaction);
837
+		}
838
+		return true;
839
+	}
840
+
841
+
842
+
843
+	/**
844
+	 * _get_transaction_and_cart_for_previous_visit
845
+	 *
846
+	 * @access private
847
+	 * @return mixed EE_Transaction|NULL
848
+	 */
849
+	private function _get_transaction_and_cart_for_previous_visit()
850
+	{
851
+		/** @var $TXN_model EEM_Transaction */
852
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
853
+		// because the reg_url_link is present in the request, this is a return visit to SPCO, so we'll get the transaction data from the db
854
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
855
+		// verify transaction
856
+		if ($transaction instanceof EE_Transaction) {
857
+			// and get the cart that was used for that transaction
858
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
859
+			return $transaction;
860
+		} else {
861
+			EE_Error::add_error(__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
862
+			return null;
863
+		}
864
+	}
865
+
866
+
867
+
868
+	/**
869
+	 * _get_cart_for_transaction
870
+	 *
871
+	 * @access private
872
+	 * @param EE_Transaction $transaction
873
+	 * @return EE_Cart
874
+	 */
875
+	private function _get_cart_for_transaction($transaction)
876
+	{
877
+		return $this->checkout->get_cart_for_transaction($transaction);
878
+	}
879
+
880
+
881
+
882
+	/**
883
+	 * get_cart_for_transaction
884
+	 *
885
+	 * @access public
886
+	 * @param EE_Transaction $transaction
887
+	 * @return EE_Cart
888
+	 */
889
+	public function get_cart_for_transaction(EE_Transaction $transaction)
890
+	{
891
+		return $this->checkout->get_cart_for_transaction($transaction);
892
+	}
893
+
894
+
895
+
896
+	/**
897
+	 * _get_transaction_and_cart_for_current_session
898
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
899
+	 *
900
+	 * @access private
901
+	 * @return EE_Transaction
902
+	 * @throws \EE_Error
903
+	 */
904
+	private function _get_cart_for_current_session_and_setup_new_transaction()
905
+	{
906
+		//  if there's no transaction, then this is the FIRST visit to SPCO
907
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
908
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
909
+		// and then create a new transaction
910
+		$transaction = $this->_initialize_transaction();
911
+		// verify transaction
912
+		if ($transaction instanceof EE_Transaction) {
913
+			// save it so that we have an ID for other objects to use
914
+			$transaction->save();
915
+			// and save TXN data to the cart
916
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
917
+		} else {
918
+			EE_Error::add_error(__('A Valid Transaction could not be initialized.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
919
+		}
920
+		return $transaction;
921
+	}
922
+
923
+
924
+
925
+	/**
926
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
927
+	 *
928
+	 * @access private
929
+	 * @return mixed EE_Transaction|NULL
930
+	 */
931
+	private function _initialize_transaction()
932
+	{
933
+		try {
934
+			// ensure cart totals have been calculated
935
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
936
+			// grab the cart grand total
937
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
938
+			// create new TXN
939
+			$transaction = EE_Transaction::new_instance(
940
+				array(
941
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
942
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
943
+					'TXN_paid'      => 0,
944
+					'STS_ID'        => EEM_Transaction::failed_status_code,
945
+				)
946
+			);
947
+			// save it so that we have an ID for other objects to use
948
+			$transaction->save();
949
+			// set cron job for following up on TXNs after their session has expired
950
+			EE_Cron_Tasks::schedule_expired_transaction_check(
951
+				EE_Registry::instance()->SSN->expiration() + 1,
952
+				$transaction->ID()
953
+			);
954
+			return $transaction;
955
+		} catch (Exception $e) {
956
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
957
+		}
958
+		return null;
959
+	}
960
+
961
+
962
+
963
+	/**
964
+	 * _get_registrations
965
+	 *
966
+	 * @access private
967
+	 * @param EE_Transaction $transaction
968
+	 * @return void
969
+	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
970
+	 * @throws \EE_Error
971
+	 */
972
+	private function _get_registrations(EE_Transaction $transaction)
973
+	{
974
+		// first step: grab the registrants  { : o
975
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true);
976
+		// verify registrations have been set
977
+		if (empty($registrations)) {
978
+			// if no cached registrations, then check the db
979
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
980
+			// still nothing ? well as long as this isn't a revisit
981
+			if (empty($registrations) && ! $this->checkout->revisit) {
982
+				// generate new registrations from scratch
983
+				$registrations = $this->_initialize_registrations($transaction);
984
+			}
985
+		}
986
+		// sort by their original registration order
987
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
988
+		// then loop thru the array
989
+		foreach ($registrations as $registration) {
990
+			// verify each registration
991
+			if ($registration instanceof EE_Registration) {
992
+				// we display all attendee info for the primary registrant
993
+				if ($this->checkout->reg_url_link === $registration->reg_url_link()
994
+					&& $registration->is_primary_registrant()
995
+				) {
996
+					$this->checkout->primary_revisit = true;
997
+					break;
998
+				} else if ($this->checkout->revisit
999
+						   && $this->checkout->reg_url_link !== $registration->reg_url_link()
1000
+				) {
1001
+					// but hide info if it doesn't belong to you
1002
+					$transaction->clear_cache('Registration', $registration->ID());
1003
+				}
1004
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1005
+			}
1006
+		}
1007
+	}
1008
+
1009
+
1010
+
1011
+	/**
1012
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1013
+	 *
1014
+	 * @access private
1015
+	 * @param EE_Transaction $transaction
1016
+	 * @return    array
1017
+	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
1018
+	 * @throws \EE_Error
1019
+	 */
1020
+	private function _initialize_registrations(EE_Transaction $transaction)
1021
+	{
1022
+		$att_nmbr = 0;
1023
+		$registrations = array();
1024
+		if ($transaction instanceof EE_Transaction) {
1025
+			/** @type EE_Registration_Processor $registration_processor */
1026
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1027
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1028
+			// now let's add the cart items to the $transaction
1029
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1030
+				//do the following for each ticket of this type they selected
1031
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1032
+					$att_nmbr++;
1033
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1034
+					$CreateRegistrationCommand = EE_Registry::instance()
1035
+															->create(
1036
+																'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1037
+																array(
1038
+																	$transaction,
1039
+																	$line_item,
1040
+																	$att_nmbr,
1041
+																	$this->checkout->total_ticket_count,
1042
+																)
1043
+															);
1044
+					// override capabilities for frontend registrations
1045
+					if ( ! is_admin()) {
1046
+						$CreateRegistrationCommand->setCapCheck(
1047
+							new PublicCapabilities('', 'create_new_registration')
1048
+						);
1049
+					}
1050
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1051
+					if ( ! $registration instanceof EE_Registration) {
1052
+						throw new InvalidEntityException($registration, 'EE_Registration');
1053
+					}
1054
+					$registrations[ $registration->ID() ] = $registration;
1055
+				}
1056
+			}
1057
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1058
+		}
1059
+		return $registrations;
1060
+	}
1061
+
1062
+
1063
+
1064
+	/**
1065
+	 * sorts registrations by REG_count
1066
+	 *
1067
+	 * @access public
1068
+	 * @param EE_Registration $reg_A
1069
+	 * @param EE_Registration $reg_B
1070
+	 * @return int
1071
+	 */
1072
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1073
+	{
1074
+		// this shouldn't ever happen within the same TXN, but oh well
1075
+		if ($reg_A->count() === $reg_B->count()) {
1076
+			return 0;
1077
+		}
1078
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1079
+	}
1080
+
1081
+
1082
+
1083
+	/**
1084
+	 *    _final_verifications
1085
+	 * just makes sure that everything is set up correctly before proceeding
1086
+	 *
1087
+	 * @access    private
1088
+	 * @return    bool
1089
+	 * @throws \EE_Error
1090
+	 */
1091
+	private function _final_verifications()
1092
+	{
1093
+		// filter checkout
1094
+		$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout);
1095
+		//verify that current step is still set correctly
1096
+		if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1097
+			EE_Error::add_error(
1098
+				__('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'),
1099
+				__FILE__,
1100
+				__FUNCTION__,
1101
+				__LINE__
1102
+			);
1103
+			return false;
1104
+		}
1105
+		// if returning to SPCO, then verify that primary registrant is set
1106
+		if ( ! empty($this->checkout->reg_url_link)) {
1107
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1108
+			if ( ! $valid_registrant instanceof EE_Registration) {
1109
+				EE_Error::add_error(
1110
+					__('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'),
1111
+					__FILE__,
1112
+					__FUNCTION__,
1113
+					__LINE__
1114
+				);
1115
+				return false;
1116
+			}
1117
+			$valid_registrant = null;
1118
+			foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1119
+				if (
1120
+					$registration instanceof EE_Registration
1121
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1122
+				) {
1123
+					$valid_registrant = $registration;
1124
+				}
1125
+			}
1126
+			if ( ! $valid_registrant instanceof EE_Registration) {
1127
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1128
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1129
+					// clear the session, mark the checkout as unverified, and try again
1130
+					EE_Registry::instance()->SSN->clear_session();
1131
+					EED_Single_Page_Checkout::$_initialized = false;
1132
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1133
+					$this->_initialize();
1134
+					EE_Error::reset_notices();
1135
+					return false;
1136
+				}
1137
+				EE_Error::add_error(
1138
+					__('We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso'),
1139
+					__FILE__,
1140
+					__FUNCTION__,
1141
+					__LINE__
1142
+				);
1143
+				return false;
1144
+			}
1145
+		}
1146
+		// now that things have been kinda sufficiently verified,
1147
+		// let's add the checkout to the session so that's available other systems
1148
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1149
+		return true;
1150
+	}
1151
+
1152
+
1153
+
1154
+	/**
1155
+	 *    _initialize_reg_steps
1156
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1157
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1158
+	 *
1159
+	 * @access    private
1160
+	 * @param bool $reinitializing
1161
+	 * @throws \EE_Error
1162
+	 */
1163
+	private function _initialize_reg_steps($reinitializing = false)
1164
+	{
1165
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1166
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1167
+		foreach ($this->checkout->reg_steps as $reg_step) {
1168
+			if ( ! $reg_step->initialize_reg_step()) {
1169
+				// if not initialized then maybe this step is being removed...
1170
+				if ( ! $reinitializing && $reg_step->is_current_step()) {
1171
+					// if it was the current step, then we need to start over here
1172
+					$this->_initialize_reg_steps(true);
1173
+					return;
1174
+				}
1175
+				continue;
1176
+			}
1177
+			// add css and JS for current step
1178
+			$reg_step->enqueue_styles_and_scripts();
1179
+			// i18n
1180
+			$reg_step->translate_js_strings();
1181
+			if ($reg_step->is_current_step()) {
1182
+				// the text that appears on the reg step form submit button
1183
+				$reg_step->set_submit_button_text();
1184
+			}
1185
+		}
1186
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1187
+		do_action("AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step);
1188
+	}
1189
+
1190
+
1191
+
1192
+	/**
1193
+	 * _check_form_submission
1194
+	 *
1195
+	 * @access private
1196
+	 * @return boolean
1197
+	 */
1198
+	private function _check_form_submission()
1199
+	{
1200
+		//does this request require the reg form to be generated ?
1201
+		if ($this->checkout->generate_reg_form) {
1202
+			// ever heard that song by Blue Rodeo ?
1203
+			try {
1204
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1205
+				// if not displaying a form, then check for form submission
1206
+				if (
1207
+					$this->checkout->process_form_submission
1208
+					&& $this->checkout->current_step->reg_form->was_submitted()
1209
+				) {
1210
+					// clear out any old data in case this step is being run again
1211
+					$this->checkout->current_step->set_valid_data(array());
1212
+					// capture submitted form data
1213
+					$this->checkout->current_step->reg_form->receive_form_submission(
1214
+						apply_filters('FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout)
1215
+					);
1216
+					// validate submitted form data
1217
+					if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1218
+						// thou shall not pass !!!
1219
+						$this->checkout->continue_reg = false;
1220
+						// any form validation errors?
1221
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1222
+							$submission_error_messages = array();
1223
+							// bad, bad, bad registrant
1224
+							foreach ($this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error) {
1225
+								if ($validation_error instanceof EE_Validation_Error) {
1226
+									$submission_error_messages[] = sprintf(
1227
+										__('%s : %s', 'event_espresso'),
1228
+										$validation_error->get_form_section()->html_label_text(),
1229
+										$validation_error->getMessage()
1230
+									);
1231
+								}
1232
+							}
1233
+							EE_Error::add_error(implode('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__);
1234
+						}
1235
+						// well not really... what will happen is we'll just get redirected back to redo the current step
1236
+						$this->go_to_next_step();
1237
+						return false;
1238
+					}
1239
+				}
1240
+			} catch (EE_Error $e) {
1241
+				$e->get_error();
1242
+			}
1243
+		}
1244
+		return true;
1245
+	}
1246
+
1247
+
1248
+
1249
+	/**
1250
+	 * _process_action
1251
+	 *
1252
+	 * @access private
1253
+	 * @return void
1254
+	 * @throws \EE_Error
1255
+	 */
1256
+	private function _process_form_action()
1257
+	{
1258
+		// what cha wanna do?
1259
+		switch ($this->checkout->action) {
1260
+			// AJAX next step reg form
1261
+			case 'display_spco_reg_step' :
1262
+				$this->checkout->redirect = false;
1263
+				if (EE_Registry::instance()->REQ->ajax) {
1264
+					$this->checkout->json_response->set_reg_step_html($this->checkout->current_step->display_reg_form());
1265
+				}
1266
+				break;
1267
+			default :
1268
+				// meh... do one of those other steps first
1269
+				if ( ! empty($this->checkout->action) && is_callable(array($this->checkout->current_step, $this->checkout->action))) {
1270
+					// dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1271
+					do_action("AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step);
1272
+					// call action on current step
1273
+					if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1274
+						// good registrant, you get to proceed
1275
+						if (
1276
+							$this->checkout->current_step->success_message() !== ''
1277
+							&& apply_filters(
1278
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1279
+								false
1280
+							)
1281
+						) {
1282
+							EE_Error::add_success(
1283
+								$this->checkout->current_step->success_message()
1284
+								. '<br />' . $this->checkout->next_step->_instructions()
1285
+							);
1286
+						}
1287
+						// pack it up, pack it in...
1288
+						$this->_setup_redirect();
1289
+					}
1290
+					// dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1291
+					do_action("AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step);
1292
+				} else {
1293
+					EE_Error::add_error(
1294
+						sprintf(
1295
+							__('The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso'),
1296
+							$this->checkout->action,
1297
+							$this->checkout->current_step->name()
1298
+						),
1299
+						__FILE__,
1300
+						__FUNCTION__,
1301
+						__LINE__
1302
+					);
1303
+				}
1304
+			// end default
1305
+		}
1306
+		// store our progress so far
1307
+		$this->checkout->stash_transaction_and_checkout();
1308
+		// advance to the next step! If you pass GO, collect $200
1309
+		$this->go_to_next_step();
1310
+	}
1311
+
1312
+
1313
+
1314
+	/**
1315
+	 *        add_styles_and_scripts
1316
+	 *
1317
+	 * @access        public
1318
+	 * @return        void
1319
+	 */
1320
+	public function add_styles_and_scripts()
1321
+	{
1322
+		// i18n
1323
+		$this->translate_js_strings();
1324
+		if ($this->checkout->admin_request) {
1325
+			add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1326
+		} else {
1327
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1328
+		}
1329
+	}
1330
+
1331
+
1332
+
1333
+	/**
1334
+	 *        translate_js_strings
1335
+	 *
1336
+	 * @access        public
1337
+	 * @return        void
1338
+	 */
1339
+	public function translate_js_strings()
1340
+	{
1341
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1342
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1343
+		EE_Registry::$i18n_js_strings['server_error'] = __('An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso');
1344
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = __('An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso');
1345
+		EE_Registry::$i18n_js_strings['validation_error'] = __('There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso');
1346
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = __('There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso');
1347
+		EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso');
1348
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = __('We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', 'event_espresso');
1349
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1350
+			__('Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso'),
1351
+			'<br/>',
1352
+			'<br/>'
1353
+		);
1354
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1355
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1356
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1357
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1358
+		EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1359
+		EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1360
+		EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1361
+		EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1362
+		EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1363
+		EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1364
+		EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1365
+		EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1366
+		EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1367
+		EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1368
+		EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1369
+		EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1370
+		EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1371
+		EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1372
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
1373
+			__(
1374
+				'%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
1375
+				'event_espresso'
1376
+			),
1377
+			'<h4 class="important-notice">',
1378
+			'</h4>',
1379
+			'<br />',
1380
+			'<p>',
1381
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1382
+			'">',
1383
+			'</a>',
1384
+			'</p>'
1385
+		);
1386
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters('FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true);
1387
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1388
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1389
+		);
1390
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1391
+			'M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1392
+		);
1393
+	}
1394
+
1395
+
1396
+
1397
+	/**
1398
+	 *    enqueue_styles_and_scripts
1399
+	 *
1400
+	 * @access        public
1401
+	 * @return        void
1402
+	 * @throws \EE_Error
1403
+	 */
1404
+	public function enqueue_styles_and_scripts()
1405
+	{
1406
+		// load css
1407
+		wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION);
1408
+		wp_enqueue_style('single_page_checkout');
1409
+		// load JS
1410
+		wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js', array('jquery'), '1.0.1', true);
1411
+		wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js', array('jquery_plugin'), '2.0.2', true);
1412
+		wp_register_script('single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true);
1413
+		$this->checkout->registration_form->enqueue_js();
1414
+		$this->checkout->current_step->reg_form->enqueue_js();
1415
+		wp_enqueue_script('single_page_checkout');
1416
+		/**
1417
+		 * global action hook for enqueueing styles and scripts with
1418
+		 * spco calls.
1419
+		 */
1420
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1421
+		/**
1422
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1423
+		 * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1424
+		 */
1425
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this);
1426
+	}
1427
+
1428
+
1429
+
1430
+	/**
1431
+	 *    display the Registration Single Page Checkout Form
1432
+	 *
1433
+	 * @access    private
1434
+	 * @return    void
1435
+	 * @throws \EE_Error
1436
+	 */
1437
+	private function _display_spco_reg_form()
1438
+	{
1439
+		// if registering via the admin, just display the reg form for the current step
1440
+		if ($this->checkout->admin_request) {
1441
+			EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1442
+		} else {
1443
+			// add powered by EE msg
1444
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1445
+			$empty_cart = count($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)) < 1
1446
+				? true
1447
+				: false;
1448
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1449
+			$cookies_not_set_msg = '';
1450
+			if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) {
1451
+				$cookies_not_set_msg = apply_filters(
1452
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1453
+					sprintf(
1454
+						__(
1455
+							'%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1456
+							'event_espresso'
1457
+						),
1458
+						'<div class="ee-attention">',
1459
+						'</div>',
1460
+						'<h6 class="important-notice">',
1461
+						'</h6>',
1462
+						'<p>',
1463
+						'</p>',
1464
+						'<br />',
1465
+						'<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1466
+						'</a>'
1467
+					)
1468
+				);
1469
+			}
1470
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1471
+				array(
1472
+					'name'            => 'single-page-checkout',
1473
+					'html_id'         => 'ee-single-page-checkout-dv',
1474
+					'layout_strategy' =>
1475
+						new EE_Template_Layout(
1476
+							array(
1477
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1478
+								'template_args'        => array(
1479
+									'empty_cart'              => $empty_cart,
1480
+									'revisit'                 => $this->checkout->revisit,
1481
+									'reg_steps'               => $this->checkout->reg_steps,
1482
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1483
+										? $this->checkout->next_step->slug()
1484
+										: '',
1485
+									'cancel_page_url'         => $this->checkout->cancel_page_url,
1486
+									'empty_msg'               => apply_filters(
1487
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1488
+										sprintf(
1489
+											__('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1490
+												'event_espresso'),
1491
+											'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1492
+											'">',
1493
+											'</a>'
1494
+										)
1495
+									),
1496
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1497
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1498
+									'session_expiration'      =>
1499
+										date('M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)),
1500
+								),
1501
+							)
1502
+						),
1503
+				)
1504
+			);
1505
+			// load template and add to output sent that gets filtered into the_content()
1506
+			EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1507
+		}
1508
+	}
1509
+
1510
+
1511
+
1512
+	/**
1513
+	 *    add_extra_finalize_registration_inputs
1514
+	 *
1515
+	 * @access    public
1516
+	 * @param $next_step
1517
+	 * @internal  param string $label
1518
+	 * @return void
1519
+	 */
1520
+	public function add_extra_finalize_registration_inputs($next_step)
1521
+	{
1522
+		if ($next_step === 'finalize_registration') {
1523
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1524
+		}
1525
+	}
1526
+
1527
+
1528
+
1529
+	/**
1530
+	 *    display_registration_footer
1531
+	 *
1532
+	 * @access    public
1533
+	 * @return    string
1534
+	 */
1535
+	public static function display_registration_footer()
1536
+	{
1537
+		if (
1538
+		apply_filters(
1539
+			'FHEE__EE_Front__Controller__show_reg_footer',
1540
+			EE_Registry::instance()->CFG->admin->show_reg_footer
1541
+		)
1542
+		) {
1543
+			add_filter(
1544
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1545
+				function ($url) {
1546
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1547
+				}
1548
+			);
1549
+			echo apply_filters(
1550
+				'FHEE__EE_Front_Controller__display_registration_footer',
1551
+				\EEH_Template::powered_by_event_espresso(
1552
+					'',
1553
+					'espresso-registration-footer-dv',
1554
+					array('utm_content' => 'registration_checkout')
1555
+				)
1556
+			);
1557
+		}
1558
+		return '';
1559
+	}
1560
+
1561
+
1562
+
1563
+	/**
1564
+	 *    unlock_transaction
1565
+	 *
1566
+	 * @access    public
1567
+	 * @return    void
1568
+	 * @throws \EE_Error
1569
+	 */
1570
+	public function unlock_transaction()
1571
+	{
1572
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1573
+			$this->checkout->transaction->unlock();
1574
+		}
1575
+	}
1576
+
1577
+
1578
+
1579
+	/**
1580
+	 *        _setup_redirect
1581
+	 *
1582
+	 * @access    private
1583
+	 * @return void
1584
+	 */
1585
+	private function _setup_redirect()
1586
+	{
1587
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1588
+			$this->checkout->redirect = true;
1589
+			if (empty($this->checkout->redirect_url)) {
1590
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1591
+			}
1592
+			$this->checkout->redirect_url = apply_filters(
1593
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1594
+				$this->checkout->redirect_url,
1595
+				$this->checkout
1596
+			);
1597
+		}
1598
+	}
1599
+
1600
+
1601
+
1602
+	/**
1603
+	 *   handle ajax message responses and redirects
1604
+	 *
1605
+	 * @access public
1606
+	 * @return void
1607
+	 * @throws \EE_Error
1608
+	 */
1609
+	public function go_to_next_step()
1610
+	{
1611
+		if (EE_Registry::instance()->REQ->ajax) {
1612
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1613
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1614
+		}
1615
+		$this->unlock_transaction();
1616
+		// just return for these conditions
1617
+		if (
1618
+			$this->checkout->admin_request
1619
+			|| $this->checkout->action === 'redirect_form'
1620
+			|| $this->checkout->action === 'update_checkout'
1621
+		) {
1622
+			return;
1623
+		}
1624
+		// AJAX response
1625
+		$this->_handle_json_response();
1626
+		// redirect to next step or the Thank You page
1627
+		$this->_handle_html_redirects();
1628
+		// hmmm... must be something wrong, so let's just display the form again !
1629
+		$this->_display_spco_reg_form();
1630
+	}
1631
+
1632
+
1633
+
1634
+	/**
1635
+	 *   _handle_json_response
1636
+	 *
1637
+	 * @access protected
1638
+	 * @return void
1639
+	 */
1640
+	protected function _handle_json_response()
1641
+	{
1642
+		// if this is an ajax request
1643
+		if (EE_Registry::instance()->REQ->ajax) {
1644
+			// DEBUG LOG
1645
+			//$this->checkout->log(
1646
+			//	__CLASS__, __FUNCTION__, __LINE__,
1647
+			//	array(
1648
+			//		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1649
+			//		'redirect'                   => $this->checkout->redirect,
1650
+			//		'continue_reg'               => $this->checkout->continue_reg,
1651
+			//	)
1652
+			//);
1653
+			$this->checkout->json_response->set_registration_time_limit(
1654
+				$this->checkout->get_registration_time_limit()
1655
+			);
1656
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1657
+			// just send the ajax (
1658
+			$json_response = apply_filters(
1659
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1660
+				$this->checkout->json_response
1661
+			);
1662
+			echo $json_response;
1663
+			exit();
1664
+		}
1665
+	}
1666
+
1667
+
1668
+
1669
+	/**
1670
+	 *   _handle_redirects
1671
+	 *
1672
+	 * @access protected
1673
+	 * @return void
1674
+	 */
1675
+	protected function _handle_html_redirects()
1676
+	{
1677
+		// going somewhere ?
1678
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1679
+			// store notices in a transient
1680
+			EE_Error::get_notices(false, true, true);
1681
+			// DEBUG LOG
1682
+			//$this->checkout->log(
1683
+			//	__CLASS__, __FUNCTION__, __LINE__,
1684
+			//	array(
1685
+			//		'headers_sent' => headers_sent(),
1686
+			//		'redirect_url'     => $this->checkout->redirect_url,
1687
+			//		'headers_list'    => headers_list(),
1688
+			//	)
1689
+			//);
1690
+			wp_safe_redirect($this->checkout->redirect_url);
1691
+			exit();
1692
+		}
1693
+	}
1694
+
1695
+
1696
+
1697
+	/**
1698
+	 *   set_checkout_anchor
1699
+	 *
1700
+	 * @access public
1701
+	 * @return void
1702
+	 */
1703
+	public function set_checkout_anchor()
1704
+	{
1705
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1706
+	}
1707 1707
 
1708 1708
 
1709 1709
 
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -216,13 +216,13 @@  discard block
 block discarded – undo
216 216
      */
217 217
     public static function set_definitions()
218 218
     {
219
-        define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS);
220
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
221
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
222
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
223
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
224
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
225
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
219
+        define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS);
220
+        define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS);
221
+        define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS);
222
+        define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS);
223
+        define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS);
224
+        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS);
225
+        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS);
226 226
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
227 227
         EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf(
228 228
             __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s',
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
             '</h4>',
232 232
             '<br />',
233 233
             '<p>',
234
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
234
+            '<a href="'.get_post_type_archive_link('espresso_events').'" title="',
235 235
             '">',
236 236
             '</a>',
237 237
             '</p>'
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
             return;
256 256
         }
257 257
         // filter list of reg_steps
258
-        $reg_steps_to_load = (array)apply_filters(
258
+        $reg_steps_to_load = (array) apply_filters(
259 259
             'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
260 260
             EED_Single_Page_Checkout::get_reg_steps()
261 261
         );
@@ -299,25 +299,25 @@  discard block
 block discarded – undo
299 299
         if (empty($reg_steps)) {
300 300
             $reg_steps = array(
301 301
                 10  => array(
302
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
302
+                    'file_path'  => SPCO_REG_STEPS_PATH.'attendee_information',
303 303
                     'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
304 304
                     'slug'       => 'attendee_information',
305 305
                     'has_hooks'  => false,
306 306
                 ),
307 307
                 20  => array(
308
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'registration_confirmation',
308
+                    'file_path'  => SPCO_REG_STEPS_PATH.'registration_confirmation',
309 309
                     'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation',
310 310
                     'slug'       => 'registration_confirmation',
311 311
                     'has_hooks'  => false,
312 312
                 ),
313 313
                 30  => array(
314
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
314
+                    'file_path'  => SPCO_REG_STEPS_PATH.'payment_options',
315 315
                     'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
316 316
                     'slug'       => 'payment_options',
317 317
                     'has_hooks'  => true,
318 318
                 ),
319 319
                 999 => array(
320
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
320
+                    'file_path'  => SPCO_REG_STEPS_PATH.'finalize_registration',
321 321
                     'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
322 322
                     'slug'       => 'finalize_registration',
323 323
                     'has_hooks'  => false,
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
             // DEBUG LOG
500 500
             //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
501 501
             // get reg form
502
-            if( ! $this->_check_form_submission()) {
502
+            if ( ! $this->_check_form_submission()) {
503 503
                 EED_Single_Page_Checkout::$_initialized = true;
504 504
                 return;
505 505
             }
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
         // or some other kind of revisit ?
611 611
         $this->checkout->revisit = EE_Registry::instance()->REQ->get('revisit', false);
612 612
         // and whether or not to generate a reg form for this request
613
-        $this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get('generate_reg_form', true);        // TRUE 	FALSE
613
+        $this->checkout->generate_reg_form = EE_Registry::instance()->REQ->get('generate_reg_form', true); // TRUE 	FALSE
614 614
         // and whether or not to process a reg form submission for this request
615 615
         $this->checkout->process_form_submission = EE_Registry::instance()->REQ->get(
616 616
             'process_form_submission',
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
         ); // TRUE 	FALSE
619 619
         $this->checkout->process_form_submission = $this->checkout->action !== 'display_spco_reg_step'
620 620
             ? $this->checkout->process_form_submission
621
-            : false;        // TRUE 	FALSE
621
+            : false; // TRUE 	FALSE
622 622
         // $this->_display_request_vars();
623 623
     }
624 624
 
@@ -1051,7 +1051,7 @@  discard block
 block discarded – undo
1051 1051
                     if ( ! $registration instanceof EE_Registration) {
1052 1052
                         throw new InvalidEntityException($registration, 'EE_Registration');
1053 1053
                     }
1054
-                    $registrations[ $registration->ID() ] = $registration;
1054
+                    $registrations[$registration->ID()] = $registration;
1055 1055
                 }
1056 1056
             }
1057 1057
             $registration_processor->fix_reg_final_price_rounding_issue($transaction);
@@ -1281,7 +1281,7 @@  discard block
 block discarded – undo
1281 1281
                         ) {
1282 1282
                             EE_Error::add_success(
1283 1283
                                 $this->checkout->current_step->success_message()
1284
-                                . '<br />' . $this->checkout->next_step->_instructions()
1284
+                                . '<br />'.$this->checkout->next_step->_instructions()
1285 1285
                             );
1286 1286
                         }
1287 1287
                         // pack it up, pack it in...
@@ -1378,7 +1378,7 @@  discard block
 block discarded – undo
1378 1378
             '</h4>',
1379 1379
             '<br />',
1380 1380
             '<p>',
1381
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1381
+            '<a href="'.get_post_type_archive_link('espresso_events').'" title="',
1382 1382
             '">',
1383 1383
             '</a>',
1384 1384
             '</p>'
@@ -1404,12 +1404,12 @@  discard block
 block discarded – undo
1404 1404
     public function enqueue_styles_and_scripts()
1405 1405
     {
1406 1406
         // load css
1407
-        wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION);
1407
+        wp_register_style('single_page_checkout', SPCO_CSS_URL.'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION);
1408 1408
         wp_enqueue_style('single_page_checkout');
1409 1409
         // load JS
1410
-        wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js', array('jquery'), '1.0.1', true);
1411
-        wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js', array('jquery_plugin'), '2.0.2', true);
1412
-        wp_register_script('single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true);
1410
+        wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL.'jquery	.plugin.min.js', array('jquery'), '1.0.1', true);
1411
+        wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL.'jquery	.countdown.min.js', array('jquery_plugin'), '2.0.2', true);
1412
+        wp_register_script('single_page_checkout', SPCO_JS_URL.'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true);
1413 1413
         $this->checkout->registration_form->enqueue_js();
1414 1414
         $this->checkout->current_step->reg_form->enqueue_js();
1415 1415
         wp_enqueue_script('single_page_checkout');
@@ -1422,7 +1422,7 @@  discard block
 block discarded – undo
1422 1422
          * dynamic action hook for enqueueing styles and scripts with spco calls.
1423 1423
          * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1424 1424
          */
1425
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this);
1425
+        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(), $this);
1426 1426
     }
1427 1427
 
1428 1428
 
@@ -1474,7 +1474,7 @@  discard block
 block discarded – undo
1474 1474
                     'layout_strategy' =>
1475 1475
                         new EE_Template_Layout(
1476 1476
                             array(
1477
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1477
+                                'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php',
1478 1478
                                 'template_args'        => array(
1479 1479
                                     'empty_cart'              => $empty_cart,
1480 1480
                                     'revisit'                 => $this->checkout->revisit,
@@ -1488,7 +1488,7 @@  discard block
 block discarded – undo
1488 1488
                                         sprintf(
1489 1489
                                             __('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1490 1490
                                                 'event_espresso'),
1491
-                                            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1491
+                                            '<a href="'.get_post_type_archive_link('espresso_events').'" title="',
1492 1492
                                             '">',
1493 1493
                                             '</a>'
1494 1494
                                         )
@@ -1542,7 +1542,7 @@  discard block
 block discarded – undo
1542 1542
         ) {
1543 1543
             add_filter(
1544 1544
                 'FHEE__EEH_Template__powered_by_event_espresso__url',
1545
-                function ($url) {
1545
+                function($url) {
1546 1546
                     return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1547 1547
                 }
1548 1548
             );
Please login to merge, or discard this patch.
core/services/assets/Registry.php 2 patches
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -16,164 +16,164 @@
 block discarded – undo
16 16
 class Registry
17 17
 {
18 18
 
19
-    /**
20
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
21
-     * @var array
22
-     */
23
-    protected $jsdata = array();
24
-
25
-
26
-    /**
27
-     * Registry constructor.
28
-     * Hooking into WP actions for script registry.
29
-     */
30
-    public function __construct()
31
-    {
32
-        add_action('wp_enqueue_scripts', array($this, 'scripts'), 100);
33
-        add_action('admin_enqueue_scripts', array($this, 'scripts'), 100);
34
-    }
35
-
36
-
37
-    /**
38
-     * Callback for the WP script actions.
39
-     * Used to register globally accessible core scripts.
40
-     * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
41
-     */
42
-    public function scripts()
43
-    {
44
-        wp_register_script(
45
-            'eejs-core',
46
-            EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js',
47
-            array(),
48
-            espresso_version(),
49
-            true
50
-        );
51
-        wp_localize_script('eejs-core', 'eejs', array('data'=>$this->jsdata));
52
-    }
53
-
54
-
55
-    /**
56
-     * Used to add data to eejs.data object.
57
-     *
58
-     * Note:  Overriding existing data is not allowed.
59
-     *
60
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
61
-     * If the data you add is something like this:
62
-     *
63
-     * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
64
-     *
65
-     * It will be exposed in the page source as:
66
-     *
67
-     * eejs.data.my_plugin_data.foo == gar
68
-     *
69
-     * @param string $key          Key used to access your data
70
-     * @param string|array $value  Value to attach to key
71
-     * @throws \InvalidArgumentException
72
-     */
73
-    public function addData($key, $value)
74
-    {
75
-        if ($this->verifyDataNotExisting($key)) {
76
-            $this->jsdata[$key] = $value;
77
-        }
78
-    }
79
-
80
-
81
-    /**
82
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
83
-     * elements in an array.
84
-     *
85
-     * When you use this method, the value you include will be appended to the end of an array on $key.
86
-     *
87
-     * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript object
88
-     * like this,
89
-     *
90
-     * eejs.data.test = [
91
-     *     my_data,
92
-     * ]
93
-     *
94
-     * If there has already been a scalar value attached to the data object given key, then
95
-     * this will throw an exception.
96
-     *
97
-     * @param string $key          Key to attach data to.
98
-     * @param string|array $value  Value being registered.
99
-     * @throws InvalidArgumentException
100
-     */
101
-    public function pushData($key, $value)
102
-    {
103
-        if (isset($this->jsdata[$key])
104
-            && ! is_array($this->jsdata[$key])
105
-        ) {
106
-            throw new invalidArgumentException(
107
-                sprintf(
108
-                    __(
109
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
19
+	/**
20
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
21
+	 * @var array
22
+	 */
23
+	protected $jsdata = array();
24
+
25
+
26
+	/**
27
+	 * Registry constructor.
28
+	 * Hooking into WP actions for script registry.
29
+	 */
30
+	public function __construct()
31
+	{
32
+		add_action('wp_enqueue_scripts', array($this, 'scripts'), 100);
33
+		add_action('admin_enqueue_scripts', array($this, 'scripts'), 100);
34
+	}
35
+
36
+
37
+	/**
38
+	 * Callback for the WP script actions.
39
+	 * Used to register globally accessible core scripts.
40
+	 * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
41
+	 */
42
+	public function scripts()
43
+	{
44
+		wp_register_script(
45
+			'eejs-core',
46
+			EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js',
47
+			array(),
48
+			espresso_version(),
49
+			true
50
+		);
51
+		wp_localize_script('eejs-core', 'eejs', array('data'=>$this->jsdata));
52
+	}
53
+
54
+
55
+	/**
56
+	 * Used to add data to eejs.data object.
57
+	 *
58
+	 * Note:  Overriding existing data is not allowed.
59
+	 *
60
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
61
+	 * If the data you add is something like this:
62
+	 *
63
+	 * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
64
+	 *
65
+	 * It will be exposed in the page source as:
66
+	 *
67
+	 * eejs.data.my_plugin_data.foo == gar
68
+	 *
69
+	 * @param string $key          Key used to access your data
70
+	 * @param string|array $value  Value to attach to key
71
+	 * @throws \InvalidArgumentException
72
+	 */
73
+	public function addData($key, $value)
74
+	{
75
+		if ($this->verifyDataNotExisting($key)) {
76
+			$this->jsdata[$key] = $value;
77
+		}
78
+	}
79
+
80
+
81
+	/**
82
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
83
+	 * elements in an array.
84
+	 *
85
+	 * When you use this method, the value you include will be appended to the end of an array on $key.
86
+	 *
87
+	 * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript object
88
+	 * like this,
89
+	 *
90
+	 * eejs.data.test = [
91
+	 *     my_data,
92
+	 * ]
93
+	 *
94
+	 * If there has already been a scalar value attached to the data object given key, then
95
+	 * this will throw an exception.
96
+	 *
97
+	 * @param string $key          Key to attach data to.
98
+	 * @param string|array $value  Value being registered.
99
+	 * @throws InvalidArgumentException
100
+	 */
101
+	public function pushData($key, $value)
102
+	{
103
+		if (isset($this->jsdata[$key])
104
+			&& ! is_array($this->jsdata[$key])
105
+		) {
106
+			throw new invalidArgumentException(
107
+				sprintf(
108
+					__(
109
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
110 110
                          push values to this data element when it is an array.',
111
-                        'event_espresso'
112
-                    ),
113
-                    $key,
114
-                    __METHOD__
115
-                )
116
-            );
117
-        }
118
-
119
-        $this->jsdata[$key][] = $value;
120
-    }
121
-
122
-
123
-    /**
124
-     * Retrieve registered data.
125
-     *
126
-     * @param string $key           Name of key to attach data to.
127
-     * @return mixed                If there is no for the given key, then false is returned.
128
-     */
129
-    public function getData($key)
130
-    {
131
-        return isset($this->jsdata[$key])
132
-            ? $this->jsdata[$key]
133
-            : false;
134
-    }
135
-
136
-
137
-
138
-
139
-    /**
140
-     * Verifies whether the given data exists already on the jsdata array.
141
-     *
142
-     * Overriding data is not allowed.
143
-     *
144
-     * @param string       $key          Index for data.
145
-     * @return bool        If valid then return true.
146
-     * @throws InvalidArgumentException if data already exists.
147
-     */
148
-    protected function verifyDataNotExisting($key)
149
-    {
150
-        if (isset($this->jsdata[$key])) {
151
-            if (is_array($this->jsdata[$key])) {
152
-                throw new InvalidArgumentException(
153
-                    sprintf(
154
-                        __(
155
-                            'The value for %1$s already exists in the Registry::eejs object.
111
+						'event_espresso'
112
+					),
113
+					$key,
114
+					__METHOD__
115
+				)
116
+			);
117
+		}
118
+
119
+		$this->jsdata[$key][] = $value;
120
+	}
121
+
122
+
123
+	/**
124
+	 * Retrieve registered data.
125
+	 *
126
+	 * @param string $key           Name of key to attach data to.
127
+	 * @return mixed                If there is no for the given key, then false is returned.
128
+	 */
129
+	public function getData($key)
130
+	{
131
+		return isset($this->jsdata[$key])
132
+			? $this->jsdata[$key]
133
+			: false;
134
+	}
135
+
136
+
137
+
138
+
139
+	/**
140
+	 * Verifies whether the given data exists already on the jsdata array.
141
+	 *
142
+	 * Overriding data is not allowed.
143
+	 *
144
+	 * @param string       $key          Index for data.
145
+	 * @return bool        If valid then return true.
146
+	 * @throws InvalidArgumentException if data already exists.
147
+	 */
148
+	protected function verifyDataNotExisting($key)
149
+	{
150
+		if (isset($this->jsdata[$key])) {
151
+			if (is_array($this->jsdata[$key])) {
152
+				throw new InvalidArgumentException(
153
+					sprintf(
154
+						__(
155
+							'The value for %1$s already exists in the Registry::eejs object.
156 156
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
157 157
                             %2$s method to push your value to the array.',
158
-                            'event_espresso'
159
-                        ),
160
-                        $key,
161
-                        'pushData()'
162
-                    )
163
-                );
164
-            } else {
165
-                throw new InvalidArgumentException(
166
-                    sprintf(
167
-                        __(
168
-                            'The value for %1$s already exists in the Registry::eejs object. Overrides are not
158
+							'event_espresso'
159
+						),
160
+						$key,
161
+						'pushData()'
162
+					)
163
+				);
164
+			} else {
165
+				throw new InvalidArgumentException(
166
+					sprintf(
167
+						__(
168
+							'The value for %1$s already exists in the Registry::eejs object. Overrides are not
169 169
                             allowed.  Consider attaching your value to a different key',
170
-                            'event_espresso'
171
-                        ),
172
-                        $key
173
-                    )
174
-                );
175
-            }
176
-        }
177
-        return true;
178
-    }
170
+							'event_espresso'
171
+						),
172
+						$key
173
+					)
174
+				);
175
+			}
176
+		}
177
+		return true;
178
+	}
179 179
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@
 block discarded – undo
43 43
     {
44 44
         wp_register_script(
45 45
             'eejs-core',
46
-            EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js',
46
+            EE_PLUGIN_DIR_URL.'core/services/assets/core_assets/eejs-core.js',
47 47
             array(),
48 48
             espresso_version(),
49 49
             true
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,239 +40,239 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                ); ?>
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+				); ?>
56 56
             </p>
57 57
         </div>
58 58
         <?php
59
-        espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.24.rc.015');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.24.rc.015');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        /**
197
-         *    espresso_plugin_activation
198
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
199
-         */
200
-        function espresso_plugin_activation()
201
-        {
202
-            update_option('ee_espresso_activation', true);
203
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		/**
197
+		 *    espresso_plugin_activation
198
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
199
+		 */
200
+		function espresso_plugin_activation()
201
+		{
202
+			update_option('ee_espresso_activation', true);
203
+		}
204 204
 
205
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
206
-        /**
207
-         *    espresso_load_error_handling
208
-         *    this function loads EE's class for handling exceptions and errors
209
-         */
210
-        function espresso_load_error_handling()
211
-        {
212
-            // load debugging tools
213
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
214
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
215
-                EEH_Debug_Tools::instance();
216
-            }
217
-            // load error handling
218
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
219
-                require_once(EE_CORE . 'EE_Error.core.php');
220
-            } else {
221
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
222
-            }
223
-        }
205
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
206
+		/**
207
+		 *    espresso_load_error_handling
208
+		 *    this function loads EE's class for handling exceptions and errors
209
+		 */
210
+		function espresso_load_error_handling()
211
+		{
212
+			// load debugging tools
213
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
214
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
215
+				EEH_Debug_Tools::instance();
216
+			}
217
+			// load error handling
218
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
219
+				require_once(EE_CORE . 'EE_Error.core.php');
220
+			} else {
221
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
222
+			}
223
+		}
224 224
 
225
-        /**
226
-         *    espresso_load_required
227
-         *    given a class name and path, this function will load that file or throw an exception
228
-         *
229
-         * @param    string $classname
230
-         * @param    string $full_path_to_file
231
-         * @throws    EE_Error
232
-         */
233
-        function espresso_load_required($classname, $full_path_to_file)
234
-        {
235
-            static $error_handling_loaded = false;
236
-            if ( ! $error_handling_loaded) {
237
-                espresso_load_error_handling();
238
-                $error_handling_loaded = true;
239
-            }
240
-            if (is_readable($full_path_to_file)) {
241
-                require_once($full_path_to_file);
242
-            } else {
243
-                throw new EE_Error (
244
-                        sprintf(
245
-                                esc_html__(
246
-                                        'The %s class file could not be located or is not readable due to file permissions.',
247
-                                        'event_espresso'
248
-                                ),
249
-                                $classname
250
-                        )
251
-                );
252
-            }
253
-        }
225
+		/**
226
+		 *    espresso_load_required
227
+		 *    given a class name and path, this function will load that file or throw an exception
228
+		 *
229
+		 * @param    string $classname
230
+		 * @param    string $full_path_to_file
231
+		 * @throws    EE_Error
232
+		 */
233
+		function espresso_load_required($classname, $full_path_to_file)
234
+		{
235
+			static $error_handling_loaded = false;
236
+			if ( ! $error_handling_loaded) {
237
+				espresso_load_error_handling();
238
+				$error_handling_loaded = true;
239
+			}
240
+			if (is_readable($full_path_to_file)) {
241
+				require_once($full_path_to_file);
242
+			} else {
243
+				throw new EE_Error (
244
+						sprintf(
245
+								esc_html__(
246
+										'The %s class file could not be located or is not readable due to file permissions.',
247
+										'event_espresso'
248
+								),
249
+								$classname
250
+						)
251
+				);
252
+			}
253
+		}
254 254
 
255
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
256
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
257
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
258
-        new EE_Bootstrap();
259
-    }
255
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
256
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
257
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
258
+		new EE_Bootstrap();
259
+	}
260 260
 }
261 261
 if ( ! function_exists('espresso_deactivate_plugin')) {
262
-    /**
263
-     *    deactivate_plugin
264
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
265
-     *
266
-     * @access public
267
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
268
-     * @return    void
269
-     */
270
-    function espresso_deactivate_plugin($plugin_basename = '')
271
-    {
272
-        if ( ! function_exists('deactivate_plugins')) {
273
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
274
-        }
275
-        unset($_GET['activate'], $_REQUEST['activate']);
276
-        deactivate_plugins($plugin_basename);
277
-    }
262
+	/**
263
+	 *    deactivate_plugin
264
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
265
+	 *
266
+	 * @access public
267
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
268
+	 * @return    void
269
+	 */
270
+	function espresso_deactivate_plugin($plugin_basename = '')
271
+	{
272
+		if ( ! function_exists('deactivate_plugins')) {
273
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
274
+		}
275
+		unset($_GET['activate'], $_REQUEST['activate']);
276
+		deactivate_plugins($plugin_basename);
277
+	}
278 278
 }
Please login to merge, or discard this patch.