Completed
Branch GDPR/privacy-policy-content (f954f3)
by
unknown
60:17 queued 46:07
created
core/data_migration_scripts/EE_DMS_Core_4_7_0.dms.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 // unfortunately, this needs to be done upon INCLUSION of this file,
16 16
 // instead of construction, because it only gets constructed on first page load
17 17
 // (all other times it gets resurrected from a wordpress option)
18
-$stages = glob(EE_CORE . 'data_migration_scripts/4_7_0_stages/*');
18
+$stages = glob(EE_CORE.'data_migration_scripts/4_7_0_stages/*');
19 19
 $class_to_filepath = array();
20 20
 foreach ($stages as $filepath) {
21 21
     $matches = array();
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
             return true;
80 80
         } elseif ( ! $version_string) {
81 81
             //no version string provided... this must be pre 4.3
82
-            return false;//changed mind. dont want people thinking they should migrate yet because they cant
82
+            return false; //changed mind. dont want people thinking they should migrate yet because they cant
83 83
         } else {
84 84
             return false;
85 85
         }
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
     public function schema_changes_before_migration()
104 104
     {
105 105
         //relies on 4.1's EEH_Activation::create_table
106
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
106
+        require_once(EE_HELPERS.'EEH_Activation.helper.php');
107 107
         $table_name = 'esp_answer';
108 108
         $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
109 109
 					REG_ID INT UNSIGNED NOT NULL,
Please login to merge, or discard this patch.
Indentation   +181 added lines, -182 removed lines patch added patch discarded remove patch
@@ -9,7 +9,6 @@  discard block
 block discarded – undo
9 9
  * and recalculates esp_registration.REG_final_price to actually be the final price
10 10
  * for that registration (before this it was just the ticket's price, NOT including
11 11
  * taxes or other price modifiers)
12
-
13 12
  */
14 13
 // make sure we have all the stages loaded too
15 14
 // unfortunately, this needs to be done upon INCLUSION of this file,
@@ -18,9 +17,9 @@  discard block
 block discarded – undo
18 17
 $stages = glob(EE_CORE . 'data_migration_scripts/4_7_0_stages/*');
19 18
 $class_to_filepath = array();
20 19
 foreach ($stages as $filepath) {
21
-    $matches = array();
22
-    preg_match('~4_7_0_stages/(.*).dmsstage.php~', $filepath, $matches);
23
-    $class_to_filepath[$matches[1]] = $filepath;
20
+	$matches = array();
21
+	preg_match('~4_7_0_stages/(.*).dmsstage.php~', $filepath, $matches);
22
+	$class_to_filepath[$matches[1]] = $filepath;
24 23
 }
25 24
 //give addons a chance to autoload their stages too
26 25
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_7_0__autoloaded_stages', $class_to_filepath);
@@ -39,72 +38,72 @@  discard block
 block discarded – undo
39 38
 class EE_DMS_Core_4_7_0 extends EE_Data_Migration_Script_Base
40 39
 {
41 40
 
42
-    /**
43
-     * return EE_DMS_Core_4_7_0
44
-     *
45
-     * @param TableManager  $table_manager
46
-     * @param TableAnalysis $table_analysis
47
-     */
48
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
49
-    {
50
-        $this->_pretty_name = __("Data Update to Event Espresso 4.7.0", "event_espresso");
51
-        $this->_priority = 10;
52
-        $this->_migration_stages = array(
53
-            new EE_DMS_4_7_0_Add_Taxes_To_REG_Final_Price(),
54
-            new EE_DMS_4_7_0_Registration_Payments(),
55
-        );
56
-        parent::__construct($table_manager, $table_analysis);
57
-    }
41
+	/**
42
+	 * return EE_DMS_Core_4_7_0
43
+	 *
44
+	 * @param TableManager  $table_manager
45
+	 * @param TableAnalysis $table_analysis
46
+	 */
47
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
48
+	{
49
+		$this->_pretty_name = __("Data Update to Event Espresso 4.7.0", "event_espresso");
50
+		$this->_priority = 10;
51
+		$this->_migration_stages = array(
52
+			new EE_DMS_4_7_0_Add_Taxes_To_REG_Final_Price(),
53
+			new EE_DMS_4_7_0_Registration_Payments(),
54
+		);
55
+		parent::__construct($table_manager, $table_analysis);
56
+	}
58 57
 
59 58
 
60 59
 
61
-    /**
62
-     * @param array $version_array
63
-     * @return bool
64
-     */
65
-    public function can_migrate_from_version($version_array)
66
-    {
67
-        $version_string = $version_array['Core'];
68
-        if (
69
-            (
70
-                version_compare($version_string, '4.7.0', '<=')
71
-                && version_compare($version_string, '4.6.0', '>=')
72
-            )
73
-            || (
74
-                version_compare($version_string, '4.7.0', '>=')
75
-                && ! $this->_get_table_analysis()->tableExists('esp_registration_payment')
76
-                && $this->_get_table_analysis()->tableExists('esp_registration')
77
-            )
78
-        ) {
79
-            return true;
80
-        } elseif ( ! $version_string) {
81
-            //no version string provided... this must be pre 4.3
82
-            return false;//changed mind. dont want people thinking they should migrate yet because they cant
83
-        } else {
84
-            return false;
85
-        }
86
-    }
60
+	/**
61
+	 * @param array $version_array
62
+	 * @return bool
63
+	 */
64
+	public function can_migrate_from_version($version_array)
65
+	{
66
+		$version_string = $version_array['Core'];
67
+		if (
68
+			(
69
+				version_compare($version_string, '4.7.0', '<=')
70
+				&& version_compare($version_string, '4.6.0', '>=')
71
+			)
72
+			|| (
73
+				version_compare($version_string, '4.7.0', '>=')
74
+				&& ! $this->_get_table_analysis()->tableExists('esp_registration_payment')
75
+				&& $this->_get_table_analysis()->tableExists('esp_registration')
76
+			)
77
+		) {
78
+			return true;
79
+		} elseif ( ! $version_string) {
80
+			//no version string provided... this must be pre 4.3
81
+			return false;//changed mind. dont want people thinking they should migrate yet because they cant
82
+		} else {
83
+			return false;
84
+		}
85
+	}
87 86
 
88 87
 
89 88
 
90
-    /**
91
-     * @return bool
92
-     */
93
-    public function schema_changes_before_migration()
94
-    {
95
-        //relies on 4.1's EEH_Activation::create_table
96
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
97
-        $table_name = 'esp_answer';
98
-        $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
89
+	/**
90
+	 * @return bool
91
+	 */
92
+	public function schema_changes_before_migration()
93
+	{
94
+		//relies on 4.1's EEH_Activation::create_table
95
+		require_once(EE_HELPERS . 'EEH_Activation.helper.php');
96
+		$table_name = 'esp_answer';
97
+		$sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
99 98
 					REG_ID INT UNSIGNED NOT NULL,
100 99
 					QST_ID INT UNSIGNED NOT NULL,
101 100
 					ANS_value TEXT NOT NULL,
102 101
 					PRIMARY KEY  (ANS_ID),
103 102
 					KEY REG_ID (REG_ID),
104 103
 					KEY QST_ID (QST_ID)";
105
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
106
-        $table_name = 'esp_attendee_meta';
107
-        $sql = "ATTM_ID INT(10) UNSIGNED NOT	NULL AUTO_INCREMENT,
104
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
105
+		$table_name = 'esp_attendee_meta';
106
+		$sql = "ATTM_ID INT(10) UNSIGNED NOT	NULL AUTO_INCREMENT,
108 107
 						ATT_ID BIGINT(20) UNSIGNED NOT NULL,
109 108
 						ATT_fname VARCHAR(45) NOT NULL,
110 109
 						ATT_lname VARCHAR(45) NOT	NULL,
@@ -121,9 +120,9 @@  discard block
 block discarded – undo
121 120
 								KEY ATT_email (ATT_email),
122 121
 								KEY ATT_lname (ATT_lname),
123 122
 								KEY ATT_fname (ATT_fname)";
124
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
125
-        $table_name = 'esp_country';
126
-        $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL,
123
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
124
+		$table_name = 'esp_country';
125
+		$sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL,
127 126
 					  CNT_ISO3 VARCHAR(3) COLLATE utf8_bin NOT NULL,
128 127
 					  RGN_ID TINYINT(3) UNSIGNED DEFAULT NULL,
129 128
 					  CNT_name VARCHAR(45) COLLATE utf8_bin NOT NULL,
@@ -139,25 +138,25 @@  discard block
 block discarded – undo
139 138
 					  CNT_is_EU TINYINT(1) DEFAULT '0',
140 139
 					  CNT_active TINYINT(1) DEFAULT '0',
141 140
 					  PRIMARY KEY  (CNT_ISO)";
142
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
143
-        $table_name = 'esp_currency';
144
-        $sql = "CUR_code VARCHAR(6) COLLATE utf8_bin NOT NULL,
141
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
142
+		$table_name = 'esp_currency';
143
+		$sql = "CUR_code VARCHAR(6) COLLATE utf8_bin NOT NULL,
145 144
 				CUR_single VARCHAR(45) COLLATE utf8_bin DEFAULT 'dollar',
146 145
 				CUR_plural VARCHAR(45) COLLATE utf8_bin DEFAULT 'dollars',
147 146
 				CUR_sign VARCHAR(45) COLLATE utf8_bin DEFAULT '$',
148 147
 				CUR_dec_plc VARCHAR(1) COLLATE utf8_bin NOT NULL DEFAULT '2',
149 148
 				CUR_active TINYINT(1) DEFAULT '0',
150 149
 				PRIMARY KEY  (CUR_code)";
151
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
152
-        $table_name = 'esp_currency_payment_method';
153
-        $sql = "CPM_ID INT(11) NOT NULL AUTO_INCREMENT,
150
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
151
+		$table_name = 'esp_currency_payment_method';
152
+		$sql = "CPM_ID INT(11) NOT NULL AUTO_INCREMENT,
154 153
 				CUR_code  VARCHAR(6) COLLATE utf8_bin NOT NULL,
155 154
 				PMD_ID INT(11) NOT NULL,
156 155
 				PRIMARY KEY  (CPM_ID),
157 156
 				KEY PMD_ID (PMD_ID)";
158
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
159
-        $table_name = 'esp_datetime';
160
-        $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
157
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
158
+		$table_name = 'esp_datetime';
159
+		$sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
161 160
 				  EVT_ID BIGINT(20) UNSIGNED NOT NULL,
162 161
 				  DTT_name VARCHAR(255) NOT NULL DEFAULT '',
163 162
 				  DTT_description TEXT NOT NULL,
@@ -173,9 +172,9 @@  discard block
 block discarded – undo
173 172
 						KEY DTT_EVT_start (DTT_EVT_start),
174 173
 						KEY EVT_ID (EVT_ID),
175 174
 						KEY DTT_is_primary (DTT_is_primary)";
176
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
177
-        $table_name = 'esp_event_meta';
178
-        $sql = "
175
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
176
+		$table_name = 'esp_event_meta';
177
+		$sql = "
179 178
 			EVTM_ID INT NOT NULL AUTO_INCREMENT,
180 179
 			EVT_ID BIGINT(20) UNSIGNED NOT NULL,
181 180
 			EVT_display_desc TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,
@@ -191,34 +190,34 @@  discard block
 block discarded – undo
191 190
 			EVT_donations TINYINT(1) NULL,
192 191
 			PRIMARY KEY  (EVTM_ID),
193 192
 			KEY EVT_ID (EVT_ID)";
194
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
195
-        $table_name = 'esp_event_question_group';
196
-        $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
193
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
194
+		$table_name = 'esp_event_question_group';
195
+		$sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
197 196
 					EVT_ID BIGINT(20) UNSIGNED NOT NULL,
198 197
 					QSG_ID INT UNSIGNED NOT NULL,
199 198
 					EQG_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
200 199
 					PRIMARY KEY  (EQG_ID),
201 200
 					KEY EVT_ID (EVT_ID),
202 201
 					KEY QSG_ID (QSG_ID)";
203
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
204
-        $table_name = 'esp_event_venue';
205
-        $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT,
202
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
203
+		$table_name = 'esp_event_venue';
204
+		$sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT,
206 205
 				EVT_ID BIGINT(20) UNSIGNED NOT NULL,
207 206
 				VNU_ID BIGINT(20) UNSIGNED NOT NULL,
208 207
 				EVV_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
209 208
 				PRIMARY KEY  (EVV_ID)";
210
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
211
-        $table_name = 'esp_extra_meta';
212
-        $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT,
209
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
210
+		$table_name = 'esp_extra_meta';
211
+		$sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT,
213 212
 				OBJ_ID INT(11) DEFAULT NULL,
214 213
 				EXM_type VARCHAR(45) DEFAULT NULL,
215 214
 				EXM_key VARCHAR(45) DEFAULT NULL,
216 215
 				EXM_value TEXT,
217 216
 				PRIMARY KEY  (EXM_ID),
218 217
 				KEY EXM_type (EXM_type, OBJ_ID, EXM_key(45))";
219
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
220
-        $table_name = 'esp_line_item';
221
-        $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT,
218
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
219
+		$table_name = 'esp_line_item';
220
+		$sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT,
222 221
 				LIN_code VARCHAR(245) NOT NULL DEFAULT '',
223 222
 				TXN_ID INT(11) DEFAULT NULL,
224 223
 				LIN_name VARCHAR(245) NOT NULL DEFAULT '',
@@ -236,9 +235,9 @@  discard block
 block discarded – undo
236 235
 				PRIMARY KEY  (LIN_ID),
237 236
 				KEY LIN_code (LIN_code(191)),
238 237
 				KEY TXN_ID (TXN_ID)";
239
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
240
-        $table_name = 'esp_log';
241
-        $sql = "LOG_ID INT(11) NOT NULL AUTO_INCREMENT,
238
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
239
+		$table_name = 'esp_log';
240
+		$sql = "LOG_ID INT(11) NOT NULL AUTO_INCREMENT,
242 241
 				LOG_time DATETIME DEFAULT NULL,
243 242
 				OBJ_ID VARCHAR(45) DEFAULT NULL,
244 243
 				OBJ_type VARCHAR(45) DEFAULT NULL,
@@ -249,18 +248,18 @@  discard block
 block discarded – undo
249 248
 				KEY LOG_time (LOG_time),
250 249
 				KEY OBJ (OBJ_type,OBJ_ID),
251 250
 				KEY LOG_type (LOG_type)";
252
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
253
-        $table_name = 'esp_message_template';
254
-        $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
251
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
252
+		$table_name = 'esp_message_template';
253
+		$sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
255 254
 					GRP_ID INT(10) UNSIGNED NOT NULL,
256 255
 					MTP_context VARCHAR(50) NOT NULL,
257 256
 					MTP_template_field VARCHAR(30) NOT NULL,
258 257
 					MTP_content TEXT NOT NULL,
259 258
 					PRIMARY KEY  (MTP_ID),
260 259
 					KEY GRP_ID (GRP_ID)";
261
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
262
-        $table_name = 'esp_message_template_group';
263
-        $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
260
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
261
+		$table_name = 'esp_message_template_group';
262
+		$sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
264 263
 					MTP_user_id INT(10) NOT NULL DEFAULT '1',
265 264
 					MTP_name VARCHAR(245) NOT NULL DEFAULT '',
266 265
 					MTP_description VARCHAR(245) NOT NULL DEFAULT '',
@@ -272,17 +271,17 @@  discard block
 block discarded – undo
272 271
 					MTP_is_active TINYINT(1) NOT NULL DEFAULT '1',
273 272
 					PRIMARY KEY  (GRP_ID),
274 273
 					KEY MTP_user_id (MTP_user_id)";
275
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
276
-        $table_name = 'esp_event_message_template';
277
-        $sql = "EMT_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
274
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
275
+		$table_name = 'esp_event_message_template';
276
+		$sql = "EMT_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
278 277
 					EVT_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
279 278
 					GRP_ID INT(10) UNSIGNED NOT NULL DEFAULT 0,
280 279
 					PRIMARY KEY  (EMT_ID),
281 280
 					KEY EVT_ID (EVT_ID),
282 281
 					KEY GRP_ID (GRP_ID)";
283
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
284
-        $table_name = 'esp_payment';
285
-        $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
282
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
283
+		$table_name = 'esp_payment';
284
+		$sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
286 285
 					TXN_ID INT(10) UNSIGNED DEFAULT NULL,
287 286
 					STS_ID VARCHAR(3) COLLATE utf8_bin DEFAULT NULL,
288 287
 					PAY_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -299,9 +298,9 @@  discard block
 block discarded – undo
299 298
 					PRIMARY KEY  (PAY_ID),
300 299
 					KEY PAY_timestamp (PAY_timestamp),
301 300
 					KEY TXN_ID (TXN_ID)";
302
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
303
-        $table_name = 'esp_payment_method';
304
-        $sql = "PMD_ID INT(11) NOT NULL AUTO_INCREMENT,
301
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
302
+		$table_name = 'esp_payment_method';
303
+		$sql = "PMD_ID INT(11) NOT NULL AUTO_INCREMENT,
305 304
 				PMD_type VARCHAR(124) DEFAULT NULL,
306 305
 				PMD_name VARCHAR(255) DEFAULT NULL,
307 306
 				PMD_desc TEXT,
@@ -317,32 +316,32 @@  discard block
 block discarded – undo
317 316
 				PRIMARY KEY  (PMD_ID),
318 317
 				UNIQUE KEY PMD_slug_UNIQUE (PMD_slug),
319 318
 				KEY PMD_type (PMD_type)";
320
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
321
-        $table_name = "esp_ticket_price";
322
-        $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
319
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
320
+		$table_name = "esp_ticket_price";
321
+		$sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
323 322
 					  TKT_ID INT(10) UNSIGNED NOT NULL,
324 323
 					  PRC_ID INT(10) UNSIGNED NOT NULL,
325 324
 					  PRIMARY KEY  (TKP_ID),
326 325
 					  KEY TKT_ID (TKT_ID),
327 326
 					  KEY PRC_ID (PRC_ID)";
328
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
329
-        $table_name = "esp_datetime_ticket";
330
-        $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
327
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
328
+		$table_name = "esp_datetime_ticket";
329
+		$sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
331 330
 					  DTT_ID INT(10) UNSIGNED NOT NULL,
332 331
 					  TKT_ID INT(10) UNSIGNED NOT NULL,
333 332
 					  PRIMARY KEY  (DTK_ID),
334 333
 					  KEY DTT_ID (DTT_ID),
335 334
 					  KEY TKT_ID (TKT_ID)";
336
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
337
-        $table_name = "esp_ticket_template";
338
-        $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
335
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
336
+		$table_name = "esp_ticket_template";
337
+		$sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
339 338
 					  TTM_name VARCHAR(45) NOT NULL,
340 339
 					  TTM_description TEXT,
341 340
 					  TTM_file VARCHAR(45),
342 341
 					  PRIMARY KEY  (TTM_ID)";
343
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
344
-        $table_name = 'esp_question';
345
-        $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
342
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
343
+		$table_name = 'esp_question';
344
+		$sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
346 345
 					QST_display_text TEXT NOT NULL,
347 346
 					QST_admin_label VARCHAR(255) NOT NULL,
348 347
 					QST_system VARCHAR(25) DEFAULT NULL,
@@ -355,18 +354,18 @@  discard block
 block discarded – undo
355 354
 					QST_deleted TINYINT UNSIGNED NOT NULL DEFAULT 0,
356 355
 					PRIMARY KEY  (QST_ID),
357 356
 					KEY QST_order (QST_order)';
358
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
359
-        $table_name = 'esp_question_group_question';
360
-        $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
357
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
358
+		$table_name = 'esp_question_group_question';
359
+		$sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
361 360
 					QSG_ID INT UNSIGNED NOT NULL,
362 361
 					QST_ID INT UNSIGNED NOT NULL,
363 362
 					QGQ_order INT UNSIGNED NOT NULL DEFAULT 0,
364 363
 					PRIMARY KEY  (QGQ_ID),
365 364
 					KEY QST_ID (QST_ID),
366 365
 					KEY QSG_ID_order (QSG_ID, QGQ_order)";
367
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
368
-        $table_name = 'esp_question_option';
369
-        $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
366
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
367
+		$table_name = 'esp_question_option';
368
+		$sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
370 369
 					QSO_value VARCHAR(255) NOT NULL,
371 370
 					QSO_desc TEXT NOT NULL,
372 371
 					QST_ID INT UNSIGNED NOT NULL,
@@ -375,9 +374,9 @@  discard block
 block discarded – undo
375 374
 					PRIMARY KEY  (QSO_ID),
376 375
 					KEY QST_ID (QST_ID),
377 376
 					KEY QSO_order (QSO_order)";
378
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
379
-        $table_name = 'esp_registration';
380
-        $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
377
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
378
+		$table_name = 'esp_registration';
379
+		$sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
381 380
 					  EVT_ID BIGINT(20) UNSIGNED NOT NULL,
382 381
 					  ATT_ID BIGINT(20) UNSIGNED NOT NULL,
383 382
 					  TXN_ID INT(10) UNSIGNED NOT NULL,
@@ -401,18 +400,18 @@  discard block
 block discarded – undo
401 400
 					  KEY TKT_ID (TKT_ID),
402 401
 					  KEY EVT_ID (EVT_ID),
403 402
 					  KEY STS_ID (STS_ID)";
404
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
405
-        $table_name = 'esp_registration_payment';
406
-        $sql = "RPY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
403
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
404
+		$table_name = 'esp_registration_payment';
405
+		$sql = "RPY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
407 406
 					  REG_ID INT(10) UNSIGNED NOT NULL,
408 407
 					  PAY_ID INT(10) UNSIGNED NULL,
409 408
 					  RPY_amount DECIMAL(10,3) NOT NULL DEFAULT '0.00',
410 409
 					  PRIMARY KEY  (RPY_ID),
411 410
 					  KEY REG_ID (REG_ID),
412 411
 					  KEY PAY_ID (PAY_ID)";
413
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
414
-        $table_name = 'esp_checkin';
415
-        $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
412
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
413
+		$table_name = 'esp_checkin';
414
+		$sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
416 415
 					REG_ID INT(10) UNSIGNED NOT NULL,
417 416
 					DTT_ID INT(10) UNSIGNED NOT NULL,
418 417
 					CHK_in TINYINT(1) UNSIGNED NOT NULL DEFAULT 1,
@@ -420,9 +419,9 @@  discard block
 block discarded – undo
420 419
 					PRIMARY KEY  (CHK_ID),
421 420
 					KEY REG_ID (REG_ID),
422 421
 					KEY DTT_ID (DTT_ID)";
423
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
424
-        $table_name = 'esp_state';
425
-        $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT,
422
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
423
+		$table_name = 'esp_state';
424
+		$sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT,
426 425
 					  CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL,
427 426
 					  STA_abbrev VARCHAR(24) COLLATE utf8_bin NOT NULL,
428 427
 					  STA_name VARCHAR(100) COLLATE utf8_bin NOT NULL,
@@ -430,9 +429,9 @@  discard block
 block discarded – undo
430 429
 					  PRIMARY KEY  (STA_ID),
431 430
 					  KEY STA_abbrev (STA_abbrev),
432 431
 					  KEY CNT_ISO (CNT_ISO)";
433
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
434
-        $table_name = 'esp_status';
435
-        $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL,
432
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
433
+		$table_name = 'esp_status';
434
+		$sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL,
436 435
 					  STS_code VARCHAR(45) COLLATE utf8_bin NOT NULL,
437 436
 					  STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL,
438 437
 					  STS_can_edit TINYINT(1) NOT NULL DEFAULT 0,
@@ -440,9 +439,9 @@  discard block
 block discarded – undo
440 439
 					  STS_open TINYINT(1) NOT NULL DEFAULT 1,
441 440
 					  UNIQUE KEY STS_ID_UNIQUE (STS_ID),
442 441
 					  KEY STS_type (STS_type)";
443
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
444
-        $table_name = 'esp_transaction';
445
-        $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
442
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
443
+		$table_name = 'esp_transaction';
444
+		$sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
446 445
 					  TXN_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
447 446
 					  TXN_total DECIMAL(10,3) DEFAULT '0.00',
448 447
 					  TXN_paid DECIMAL(10,3) NOT NULL DEFAULT '0.00',
@@ -454,9 +453,9 @@  discard block
 block discarded – undo
454 453
 					  PRIMARY KEY  (TXN_ID),
455 454
 					  KEY TXN_timestamp (TXN_timestamp),
456 455
 					  KEY STS_ID (STS_ID)";
457
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
458
-        $table_name = 'esp_venue_meta';
459
-        $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT,
456
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
457
+		$table_name = 'esp_venue_meta';
458
+		$sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT,
460 459
 			VNU_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
461 460
 			VNU_address VARCHAR(255) DEFAULT NULL,
462 461
 			VNU_address2 VARCHAR(255) DEFAULT NULL,
@@ -475,10 +474,10 @@  discard block
 block discarded – undo
475 474
 			KEY VNU_ID (VNU_ID),
476 475
 			KEY STA_ID (STA_ID),
477 476
 			KEY CNT_ISO (CNT_ISO)";
478
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
479
-        //modified tables
480
-        $table_name = "esp_price";
481
-        $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
477
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
478
+		//modified tables
479
+		$table_name = "esp_price";
480
+		$sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
482 481
 					  PRT_ID TINYINT(3) UNSIGNED NOT NULL,
483 482
 					  PRC_amount DECIMAL(10,3) NOT NULL DEFAULT '0.00',
484 483
 					  PRC_name VARCHAR(245) NOT NULL,
@@ -491,9 +490,9 @@  discard block
 block discarded – undo
491 490
 					  PRC_parent INT(10) UNSIGNED DEFAULT 0,
492 491
 					  PRIMARY KEY  (PRC_ID),
493 492
 					  KEY PRT_ID (PRT_ID)";
494
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
495
-        $table_name = "esp_price_type";
496
-        $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
493
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
494
+		$table_name = "esp_price_type";
495
+		$sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT,
497 496
 				  PRT_name VARCHAR(45) NOT NULL,
498 497
 				  PBT_ID TINYINT(3) UNSIGNED NOT NULL DEFAULT '1',
499 498
 				  PRT_is_percent TINYINT(1) NOT NULL DEFAULT '0',
@@ -502,9 +501,9 @@  discard block
 block discarded – undo
502 501
 				  PRT_deleted TINYINT(1) NOT NULL DEFAULT '0',
503 502
 				  UNIQUE KEY PRT_name_UNIQUE (PRT_name),
504 503
 				  PRIMARY KEY  (PRT_ID)";
505
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
506
-        $table_name = "esp_ticket";
507
-        $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
504
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
505
+		$table_name = "esp_ticket";
506
+		$sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
508 507
 					  TTM_ID INT(10) UNSIGNED NOT NULL,
509 508
 					  TKT_name VARCHAR(245) NOT NULL DEFAULT '',
510 509
 					  TKT_description TEXT NOT NULL,
@@ -526,9 +525,9 @@  discard block
 block discarded – undo
526 525
 					  TKT_deleted TINYINT(1) NOT NULL DEFAULT '0',
527 526
 					  PRIMARY KEY  (TKT_ID),
528 527
 					  KEY TKT_start_date (TKT_start_date)";
529
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
530
-        $table_name = 'esp_question_group';
531
-        $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
528
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
529
+		$table_name = 'esp_question_group';
530
+		$sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
532 531
 					QSG_name VARCHAR(255) NOT NULL,
533 532
 					QSG_identifier VARCHAR(100) NOT NULL,
534 533
 					QSG_desc TEXT NULL,
@@ -541,38 +540,38 @@  discard block
 block discarded – undo
541 540
 					PRIMARY KEY  (QSG_ID),
542 541
 					UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier),
543 542
 					KEY QSG_order (QSG_order)';
544
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
545
-        /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
546
-        $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
547
-        //(because many need to convert old string states to foreign keys into the states table)
548
-        $script_4_1_defaults->insert_default_states();
549
-        $script_4_1_defaults->insert_default_countries();
550
-        /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
551
-        $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
552
-        $script_4_5_defaults->insert_default_price_types();
553
-        $script_4_5_defaults->insert_default_prices();
554
-        $script_4_5_defaults->insert_default_tickets();
555
-        /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */
556
-        $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0');
557
-        $script_4_6_defaults->add_default_admin_only_payments();
558
-        $script_4_6_defaults->insert_default_currencies();
559
-        return true;
560
-    }
543
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
544
+		/** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
545
+		$script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
546
+		//(because many need to convert old string states to foreign keys into the states table)
547
+		$script_4_1_defaults->insert_default_states();
548
+		$script_4_1_defaults->insert_default_countries();
549
+		/** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
550
+		$script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
551
+		$script_4_5_defaults->insert_default_price_types();
552
+		$script_4_5_defaults->insert_default_prices();
553
+		$script_4_5_defaults->insert_default_tickets();
554
+		/** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */
555
+		$script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0');
556
+		$script_4_6_defaults->add_default_admin_only_payments();
557
+		$script_4_6_defaults->insert_default_currencies();
558
+		return true;
559
+	}
561 560
 
562 561
 
563 562
 
564
-    /**
565
-     * @return boolean
566
-     */
567
-    public function schema_changes_after_migration()
568
-    {
569
-        return true;
570
-    }
563
+	/**
564
+	 * @return boolean
565
+	 */
566
+	public function schema_changes_after_migration()
567
+	{
568
+		return true;
569
+	}
571 570
 
572 571
 
573 572
 
574
-    public function migration_page_hooks()
575
-    {
576
-    }
573
+	public function migration_page_hooks()
574
+	{
575
+	}
577 576
 }
578 577
 // end of file: /core/data_migration_scripts/EE_DMS_Core_4_7_0.dms.php
579 578
\ No newline at end of file
Please login to merge, or discard this patch.
maintenance/templates/ee_confirm_migration_crash_report_sent.template.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -5,39 +5,39 @@  discard block
 block discarded – undo
5 5
 /** @type string $reset_db_action_url */
6 6
 /** @type EE_Data_Migration_Script_Base $most_recent_migration */
7 7
 ?>
8
-<?php if ( $success ) { ?>
9
-	<h1><?php _e( "Database Update Crash Report Sent", "event_espresso" ); ?></h1>
10
-	<p><?php _e( "A crash report email was sent to Event Espresso. You should hear back from us soon.", "event_espresso" ); ?></p>
8
+<?php if ($success) { ?>
9
+	<h1><?php _e("Database Update Crash Report Sent", "event_espresso"); ?></h1>
10
+	<p><?php _e("A crash report email was sent to Event Espresso. You should hear back from us soon.", "event_espresso"); ?></p>
11 11
 <?php } else {//didn't send email properly ?>
12
-	<h1><?php _e( "Migration Report not sent", "event_espresso" ); ?></h1>
13
-	<p><?php _e( "An error occurred and we were not able to automatically send a report to Event Espresso support.", "event_espresso" ); ?></p>
14
-	<p><?php printf( esc_html__( "Please copy-and-paste the system information below to %s", "event_espresso" ), '<a href="mailto:' . EE_SUPPORT_EMAIL . '">' .EE_SUPPORT_EMAIL . "</a>" ); ?></p>
12
+	<h1><?php _e("Migration Report not sent", "event_espresso"); ?></h1>
13
+	<p><?php _e("An error occurred and we were not able to automatically send a report to Event Espresso support.", "event_espresso"); ?></p>
14
+	<p><?php printf(esc_html__("Please copy-and-paste the system information below to %s", "event_espresso"), '<a href="mailto:'.EE_SUPPORT_EMAIL.'">'.EE_SUPPORT_EMAIL."</a>"); ?></p>
15 15
 	<label>
16
-		<?php _e( "system status info", "event_espresso" ); ?>
17
-		<textarea name="system_status_info" class="system_status_info"><?php print_r( EEM_System_Status::instance()->get_system_stati() ); ?></textarea>
16
+		<?php _e("system status info", "event_espresso"); ?>
17
+		<textarea name="system_status_info" class="system_status_info"><?php print_r(EEM_System_Status::instance()->get_system_stati()); ?></textarea>
18 18
 	</label>
19 19
 <?php } ?>
20 20
 
21 21
 
22
-<h1><?php _e( "What's next?", 'event_espresso' ); ?></h1>
23
-<p><?php _e( "Well, it depends on your situation:", 'event_espresso' ); ?></p>
22
+<h1><?php _e("What's next?", 'event_espresso'); ?></h1>
23
+<p><?php _e("Well, it depends on your situation:", 'event_espresso'); ?></p>
24 24
 <div class='ee-table-wrap'>
25 25
 	<table>
26 26
 		<thead>
27 27
 			<tr>
28
-				<th><?php _e( "Your Situation", 'event_espresso' ); ?></th>
29
-				<th><?php _e( "Suggested Action", 'event_espresso' ); ?></th>
28
+				<th><?php _e("Your Situation", 'event_espresso'); ?></th>
29
+				<th><?php _e("Suggested Action", 'event_espresso'); ?></th>
30 30
 			</tr>
31 31
 		</thead>
32 32
 		<tbody>
33 33
 			<tr>
34
-				<td><p class='big-text'><?php _e( "I want to retry migrating my data", 'event_espresso' ); ?></p></td>
34
+				<td><p class='big-text'><?php _e("I want to retry migrating my data", 'event_espresso'); ?></p></td>
35 35
 				<td>
36 36
 					<p>
37 37
 						<?php
38 38
 						printf(
39
-							esc_html__( 'First, %1$s check the forums %2$s to see if there is a solution before re-attempting the Database Update. Often it helps to deactivate other plugins which may have conflicts; or it may help to add %3$s to your %4$s wp-config.php%5$s (which will make the update run slower, but may resolve any memory exhaustion errors.', 'event_espresso' ),
40
-							"<a href='" . EE_SUPPORT_EMAIL . "' target='_blank'>",
39
+							esc_html__('First, %1$s check the forums %2$s to see if there is a solution before re-attempting the Database Update. Often it helps to deactivate other plugins which may have conflicts; or it may help to add %3$s to your %4$s wp-config.php%5$s (which will make the update run slower, but may resolve any memory exhaustion errors.', 'event_espresso'),
40
+							"<a href='".EE_SUPPORT_EMAIL."' target='_blank'>",
41 41
 							'</a>',
42 42
 							'<pre lang="php">define( EE_MIGRATION_STEP_SIZE, 10 );</pre>',
43 43
 							'<b>',
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 					<p>
50 50
 						<?php
51 51
 						printf(
52
-							esc_html__( 'To retry updating your data: restore to the backup you made before the update and reactivate EE (and any addons you are using) and re-run the Database Update. If you did not make a database backup and are migrating from EE3: delete your EE4 data (use the %1$s Reset/Delete Data tab above%2$s), and then reactivate EE4, and then re-run the migration and updates. If you did not make a database backup, are only updating from a previous install of EE4, have found a solution to the fatal error you received, and are willing to possibly have some data lost, %3$sattempt to continue migrating%2$s.', 'event_espresso' ),
52
+							esc_html__('To retry updating your data: restore to the backup you made before the update and reactivate EE (and any addons you are using) and re-run the Database Update. If you did not make a database backup and are migrating from EE3: delete your EE4 data (use the %1$s Reset/Delete Data tab above%2$s), and then reactivate EE4, and then re-run the migration and updates. If you did not make a database backup, are only updating from a previous install of EE4, have found a solution to the fatal error you received, and are willing to possibly have some data lost, %3$sattempt to continue migrating%2$s.', 'event_espresso'),
53 53
 							"<a href='$reset_db_page_url'>",
54 54
 							"</a>",
55 55
 							"<a class='button-primary' href='$reattempt_action_url'>"
@@ -60,13 +60,13 @@  discard block
 block discarded – undo
60 60
 			</tr>
61 61
 			<tr>
62 62
 				<td>
63
-					<p class='big-text'><?php _e( "I want to hear from Support before proceeding", 'event_espresso' ); ?></p>
63
+					<p class='big-text'><?php _e("I want to hear from Support before proceeding", 'event_espresso'); ?></p>
64 64
 				</td>
65 65
 				<td>
66 66
 					<?php
67 67
 					printf(
68
-						esc_html__( 'Just make sure you\'ve %1$s checked for a solution in the forums,%2$s and properly contacted Support. We will get back to you as soon as possible', 'event_espresso' ),
69
-						"<a href='" . EE_SUPPORT_EMAIL . "'>",
68
+						esc_html__('Just make sure you\'ve %1$s checked for a solution in the forums,%2$s and properly contacted Support. We will get back to you as soon as possible', 'event_espresso'),
69
+						"<a href='".EE_SUPPORT_EMAIL."'>",
70 70
 						"</a>"
71 71
 					);
72 72
 					?>
@@ -74,12 +74,12 @@  discard block
 block discarded – undo
74 74
 			</tr>
75 75
 			<tr>
76 76
 				<td>
77
-					<p class='big-text'><?php printf( esc_html__( 'I don\'t need my old EE %s data', 'event_espresso' ), $most_recent_migration->slug() ); ?></p>
77
+					<p class='big-text'><?php printf(esc_html__('I don\'t need my old EE %s data', 'event_espresso'), $most_recent_migration->slug()); ?></p>
78 78
 				</td>
79 79
 				<td>
80 80
 					<?php
81 81
 					printf(
82
-						esc_html__( 'If you are ok with losing all the EE %1$s data, you can skip the Database Updates and %2$s use EE4 with only default Data%3$s', 'event_espresso' ),
82
+						esc_html__('If you are ok with losing all the EE %1$s data, you can skip the Database Updates and %2$s use EE4 with only default Data%3$s', 'event_espresso'),
83 83
 						$most_recent_migration->slug(),
84 84
 						"<a id='do-not-migrate' class='do-not-migrate button-primary' href='$reset_db_action_url'>",
85 85
 						"</a>"
@@ -89,20 +89,20 @@  discard block
 block discarded – undo
89 89
 			</tr>
90 90
 			<tr>
91 91
 				<td>
92
-					<p class='big-text'><?php printf( esc_html__( 'I want to go back to my old version of EE %1$s', 'event_espresso' ), $most_recent_migration->slug() ); ?>
92
+					<p class='big-text'><?php printf(esc_html__('I want to go back to my old version of EE %1$s', 'event_espresso'), $most_recent_migration->slug()); ?>
93 93
 				</td>
94 94
 				<td>
95 95
 					<p>
96 96
 					<?php
97 97
 					printf(
98
-						esc_html__( 'Then we suggest you re-activate the old version of EE %3$s and restore your database to the backup you made just before the Database Update . If you didn\'t backup your database and are migrating from EE3, you can also delete your EE4 data (use on the %1$s"Reset/Delete Data" tab above%2$s), and then reactivate EE3 from the plugins page. Note: some of your EE3 shortcodes may have been changed to their EE4 equivalents, so you will need to change them back.', 'event_espresso' ),
98
+						esc_html__('Then we suggest you re-activate the old version of EE %3$s and restore your database to the backup you made just before the Database Update . If you didn\'t backup your database and are migrating from EE3, you can also delete your EE4 data (use on the %1$s"Reset/Delete Data" tab above%2$s), and then reactivate EE3 from the plugins page. Note: some of your EE3 shortcodes may have been changed to their EE4 equivalents, so you will need to change them back.', 'event_espresso'),
99 99
 						"<a href='$reset_db_page_url'>",
100 100
 						"</a>",
101 101
 						$most_recent_migration->slug()
102 102
 					);
103 103
 					?>
104 104
 					</p>
105
-					<p><?php _e( "If you ever decide to re-attempt using EE4, you will again be given the option to migrate your EE3 data or not.", 'event_espresso' ); ?></p>
105
+					<p><?php _e("If you ever decide to re-attempt using EE4, you will again be given the option to migrate your EE3 data or not.", 'event_espresso'); ?></p>
106 106
 				</td>
107 107
 			</tr>
108 108
 
Please login to merge, or discard this patch.
maintenance/templates/ee_upgrade_addons_before_migrating.template.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 ?>
4
-<h1><?php esc_html_e("You must upgrade your Event Espresso Add-ons before Migrating", "event_espresso");?></h1>
5
-<p><?php printf(esc_html__("Please %s visit the plugins page%s and update all Event Espresso addon plugins before updating your database.", "event_espresso"), "<a href='".admin_url('/plugins.php')."'>","</a>");?></p>
6
-<p><?php esc_html_e("You can also deactivate the addons, but all of their data will be lost when your database is migrated", "event_espresso");?></p>
7 4
\ No newline at end of file
5
+<h1><?php esc_html_e("You must upgrade your Event Espresso Add-ons before Migrating", "event_espresso"); ?></h1>
6
+<p><?php printf(esc_html__("Please %s visit the plugins page%s and update all Event Espresso addon plugins before updating your database.", "event_espresso"), "<a href='".admin_url('/plugins.php')."'>", "</a>"); ?></p>
7
+<p><?php esc_html_e("You can also deactivate the addons, but all of their data will be lost when your database is migrated", "event_espresso"); ?></p>
8 8
\ No newline at end of file
Please login to merge, or discard this patch.
admin_pages/maintenance/templates/ee_migration_page.template.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -28,29 +28,29 @@  discard block
 block discarded – undo
28 28
             <h3 class="espresso-header">
29 29
                 <span class="dashicons dashicons-flag ee-icon-size-22"></span>
30 30
                 <?php
31
-                echo apply_filters(
32
-                        'FHEE__ee_migration_page__header',
33
-                        sprintf(
34
-                                esc_html__("Your Event Espresso data needs to be updated.", "event_espresso"),
35
-                                $current_db_state,
36
-                                $next_db_state
37
-                        ),
38
-                        $current_db_state,
39
-                        $next_db_state
40
-                );
41
-                ?>
31
+				echo apply_filters(
32
+						'FHEE__ee_migration_page__header',
33
+						sprintf(
34
+								esc_html__("Your Event Espresso data needs to be updated.", "event_espresso"),
35
+								$current_db_state,
36
+								$next_db_state
37
+						),
38
+						$current_db_state,
39
+						$next_db_state
40
+				);
41
+				?>
42 42
             </h3>
43 43
         <?php } elseif ($show_most_recent_migration) { ?>
44 44
             <h3 class="espresso-header">
45 45
                 <span class="dashicons dashicons-awards ee-icon-size-22"></span>
46 46
                 <?php echo apply_filters('FHEE__ee_migration_page__done_migration_header',
47
-                        sprintf(esc_html__('Congratulations! Your database is "up-to-date" and you are ready to begin using %s',
48
-                                "event_espresso"), $ultimate_db_state)); ?>
47
+						sprintf(esc_html__('Congratulations! Your database is "up-to-date" and you are ready to begin using %s',
48
+								"event_espresso"), $ultimate_db_state)); ?>
49 49
             </h3>
50 50
             <p>
51 51
                 <?php echo apply_filters('FHEE__ee_migration_page__p_after_done_migration_header',
52
-                        sprintf(esc_html__("Time to find out about all the great new features %s has to offer.",
53
-                                "event_espresso"), $ultimate_db_state)); ?> &nbsp;
52
+						sprintf(esc_html__("Time to find out about all the great new features %s has to offer.",
53
+								"event_espresso"), $ultimate_db_state)); ?> &nbsp;
54 54
                 <b><a id="get-started-after-migrate" class="button-primary"
55 55
                       href="<?php echo add_query_arg(array('page' => 'espresso_about'), admin_url('admin.php')); ?>">
56 56
                         <?php esc_html_e("Let's Get Started", "event_espresso"); ?>&nbsp;<span
@@ -61,34 +61,34 @@  discard block
 block discarded – undo
61 61
 
62 62
 
63 63
         <?php if ($show_backup_db_text) {
64
-            echo $migration_options_html;
65
-        } ?>
64
+			echo $migration_options_html;
65
+		} ?>
66 66
 
67 67
         <?php
68
-        if ($show_most_recent_migration) {
69
-            if ($most_recent_migration && $most_recent_migration instanceof EE_Data_Migration_Script_Base) {
70
-                if ($most_recent_migration->can_continue()) {
71
-                    //tell the user they should continue their migration because it appears to be unfinished... well, assuming there were no errors ?>
68
+		if ($show_most_recent_migration) {
69
+			if ($most_recent_migration && $most_recent_migration instanceof EE_Data_Migration_Script_Base) {
70
+				if ($most_recent_migration->can_continue()) {
71
+					//tell the user they should continue their migration because it appears to be unfinished... well, assuming there were no errors ?>
72 72
                     <h3 class="espresso-header">
73 73
                         <span class="dashicons dashicons-star-half ee-icon-size-22"></span>
74 74
                         <?php printf(esc_html__("It appears that your previous Database Update (%s) is incomplete, and should be resumed",
75
-                                "event_espresso"), $most_recent_migration->pretty_name()); ?>
75
+								"event_espresso"), $most_recent_migration->pretty_name()); ?>
76 76
                     </h3>
77 77
                 <?php } elseif ($most_recent_migration->is_broken()) {
78
-                    //tell the user the migration failed and they should notify EE?>
78
+					//tell the user the migration failed and they should notify EE?>
79 79
                     <h3 class="espresso-header">
80 80
                         <span class="dashicons dashicons-no ee-icon-size-22"></span>
81 81
                         <?php echo $most_recent_migration->get_feedback_message() ?>
82 82
                     </h3>
83 83
                 <?php }
84
-                //display errors or not of the most recent migration ran
85
-                if ($most_recent_migration->get_errors()) { ?>
84
+				//display errors or not of the most recent migration ran
85
+				if ($most_recent_migration->get_errors()) { ?>
86 86
                     <div class="ee-attention">
87 87
                         <strong><?php printf(esc_html__("Warnings occurred during your last Database Update (%s):",
88
-                                    'event_espresso'),
89
-                                    $most_recent_migration->pretty_name()) ?></strong>
88
+									'event_espresso'),
89
+									$most_recent_migration->pretty_name()) ?></strong>
90 90
                         <a id="show-hide-migration-warnings" class="display-the-hidden"><?php esc_html_e("Show Warnings",
91
-                                    'event_espresso'); ?></a>
91
+									'event_espresso'); ?></a>
92 92
                         <ul class="migration-warnings" style="display:none">
93 93
                             <?php foreach ($most_recent_migration->get_errors() as $error) { ?>
94 94
                                 <li><?php echo htmlentities($error) ?></li>
@@ -96,15 +96,15 @@  discard block
 block discarded – undo
96 96
                         </ul>
97 97
                     </div>
98 98
                 <?php } else {
99
-                    //there were no errors during the last migration, just say so?>
99
+					//there were no errors during the last migration, just say so?>
100 100
                     <h2><?php printf(esc_html__("The last Database Update (%s) ran successfully without errors.",
101
-                                "event_espresso"), $most_recent_migration->pretty_name()) ?></h2>
101
+								"event_espresso"), $most_recent_migration->pretty_name()) ?></h2>
102 102
                 <?php }
103
-            } else {
104
-            }
105
-        }
106
-        // end of: if ( $show_most_recent_migration )
107
-        ?>
103
+			} else {
104
+			}
105
+		}
106
+		// end of: if ( $show_most_recent_migration )
107
+		?>
108 108
 
109 109
     </div>
110 110
     <!--end of #migration-prep-->
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
             <div id='progress-area'>
125 125
                 <h3 class="espresso-header">
126 126
                     <?php
127
-                    echo sprintf(_n(
128
-                            "The following task needs to be performed:",
129
-                            "The following %s tasks need to be performed:",
130
-                            count($script_names),
131
-                            "event_espresso"
132
-                    ), count($script_names)); ?>
127
+					echo sprintf(_n(
128
+							"The following task needs to be performed:",
129
+							"The following %s tasks need to be performed:",
130
+							count($script_names),
131
+							"event_espresso"
132
+					), count($script_names)); ?>
133 133
                 </h3>
134 134
                 <ul style="list-style: inside;">
135 135
                     <?php foreach ($script_names as $script_name) { ?>
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
                 <br/>
140 140
                 <?php if (count($script_names) > 1) { ?>
141 141
                     <p><?php esc_html_e("Please note: after each task is completed you will need to continue the Database Update, or report an error to Event Espresso.",
142
-                                "event_espresso"); ?></p>
142
+								"event_espresso"); ?></p>
143 143
                 <?php } ?>
144 144
 
145 145
                 <div class="ee-attention">
@@ -149,11 +149,11 @@  discard block
 block discarded – undo
149 149
 					</span>
150 150
                         <br/>
151 151
                         <?php esc_html_e("Depending on the number of events and the complexity of the information in your database, this could take a few minutes.",
152
-                                "event_espresso"); ?>
152
+								"event_espresso"); ?>
153 153
                     </p>
154 154
                     <p>
155 155
                         <?php printf(esc_html__("%sPlease be patient and do NOT navigate away from this page once the migration has begun%s. If any issues arise due to existing malformed data, an itemized report will be made available to you after the migration has completed.",
156
-                                "event_espresso"), '<strong>', '</strong>'); ?>
156
+								"event_espresso"), '<strong>', '</strong>'); ?>
157 157
                     </p>
158 158
                     <p>
159 159
                         <?php esc_html_e("Click the button below to begin the migration process.", "event_espresso") ?>
@@ -169,8 +169,8 @@  discard block
 block discarded – undo
169 169
 
170 170
                 <button id='start-migration' class='button-primary'>
171 171
                     <?php echo $show_continue_current_migration_script ? esc_html__("Continue Database Update",
172
-                            "event_espresso")
173
-                            : esc_html__("Begin Database Update", "event_espresso"); ?>
172
+							"event_espresso")
173
+							: esc_html__("Begin Database Update", "event_espresso"); ?>
174 174
                 </button>
175 175
                 <br class="clear"/>
176 176
 
@@ -186,10 +186,10 @@  discard block
 block discarded – undo
186 186
         </div>
187 187
 
188 188
     <?php }
189
-    if ($show_maintenance_switch) {
190
-        ?>
189
+	if ($show_maintenance_switch) {
190
+		?>
191 191
         <h2><span class="dashicons dashicons-admin-tools"></span><?php esc_html_e('Set Event Espresso Maintenance Mode',
192
-                    'event_espresso'); ?></h2>
192
+					'event_espresso'); ?></h2>
193 193
         <form method='post' action='<?php echo $update_migration_script_page_link ?>'>
194 194
             <div class="ee-table-wrap">
195 195
                 <table>
@@ -197,15 +197,15 @@  discard block
 block discarded – undo
197 197
                         <td width="40px" align="center">
198 198
                             <input type="radio" id="maintenance_mode_level_off" name="maintenance_mode_level"
199 199
                                    value="0" <?php echo EE_Maintenance_Mode::instance()->level()
200
-                                                        == EE_Maintenance_Mode::level_0_not_in_maintenance
201
-                                    ? 'checked="checked"' : '' ?>>
200
+														== EE_Maintenance_Mode::level_0_not_in_maintenance
201
+									? 'checked="checked"' : '' ?>>
202 202
                         </td>
203 203
                         <th align="left">
204 204
                             <label for="maintenance_mode_level_off"><?php esc_html_e('Maintenance Mode OFF',
205
-                                        'event_espresso'); ?></label>
205
+										'event_espresso'); ?></label>
206 206
                             <p class='description' style="font-weight: normal;">
207 207
                                 <?php esc_html_e("This is the normal operating mode for Event Espresso and allows all functionality to be viewed by all site visitors.",
208
-                                        "event_espresso"); ?>
208
+										"event_espresso"); ?>
209 209
                             </p>
210 210
                         </th>
211 211
                     </tr>
@@ -213,8 +213,8 @@  discard block
 block discarded – undo
213 213
                         <td width="40px" align="center">
214 214
                             <input type="radio" id="maintenance_mode_level_on" name="maintenance_mode_level"
215 215
                                    value="1" <?php echo EE_Maintenance_Mode::instance()->level()
216
-                                                        == EE_Maintenance_Mode::level_1_frontend_only_maintenance
217
-                                    ? 'checked="checked"' : '' ?>>
216
+														== EE_Maintenance_Mode::level_1_frontend_only_maintenance
217
+									? 'checked="checked"' : '' ?>>
218 218
                         </td>
219 219
                         <th align="left">
220 220
                             <label for="maintenance_mode_level_on">
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
                             </label>
223 223
                             <p class='description' style="font-weight: normal;">
224 224
                                 <?php esc_html_e("This disables Event Espresso frontend functionality for all site visitors that are not administrators, and allows you to configure and/or test things on the frontend of your website before others can see.",
225
-                                        "event_espresso"); ?>
225
+										"event_espresso"); ?>
226 226
                             </p>
227 227
                         </th>
228 228
                     </tr>
@@ -234,6 +234,6 @@  discard block
 block discarded – undo
234 234
             </p>
235 235
         </form>
236 236
         <?php
237
-    } ?>
237
+	} ?>
238 238
 
239 239
 </div>
Please login to merge, or discard this patch.
admin_pages/maintenance/templates/ee_migration_was_borked_page.template.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,26 +1,26 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 ?>
4
-<h1><?php esc_html_e("Data Migration Error", "event_espresso");?></h1>
5
-<p class='error'><?php printf(esc_html__("Your last Database Update had a %s FATAL ERROR, and CANNOT be continued%s.", "event_espresso"),"<b>","</b>");?></p>
6
-<a id="show-hide-migration-warnings" class="display-the-hidden"><?php esc_html_e("Show Errors", 'event_espresso');?></a>
4
+<h1><?php esc_html_e("Data Migration Error", "event_espresso"); ?></h1>
5
+<p class='error'><?php printf(esc_html__("Your last Database Update had a %s FATAL ERROR, and CANNOT be continued%s.", "event_espresso"), "<b>", "</b>"); ?></p>
6
+<a id="show-hide-migration-warnings" class="display-the-hidden"><?php esc_html_e("Show Errors", 'event_espresso'); ?></a>
7 7
 <ul class="migration-warnings" style="display:none">
8
-<?php foreach($most_recent_migration->get_errors() as $error){ ?>
8
+<?php foreach ($most_recent_migration->get_errors() as $error) { ?>
9 9
 	<li style="overflow-y:auto;max-height:100px"><?php echo esc_html($error)?></li>
10 10
 <?php }?>
11 11
 </ul>
12
-<h2><?php esc_html_e("Fill out the below form to automatically Send Event Espresso a Crash Report", "event_espresso");?></h2>
13
-<form action='<?php echo EE_Admin_Page::add_query_args_and_nonce(array('action'=>'send_migration_crash_report'), EE_MAINTENANCE_ADMIN_URL);?>' method='post'>
12
+<h2><?php esc_html_e("Fill out the below form to automatically Send Event Espresso a Crash Report", "event_espresso"); ?></h2>
13
+<form action='<?php echo EE_Admin_Page::add_query_args_and_nonce(array('action'=>'send_migration_crash_report'), EE_MAINTENANCE_ADMIN_URL); ?>' method='post'>
14 14
 	<table class='widefat'>
15
-		<tr><td><label for='from'><?php esc_html_e("From/Reply-To:", "event_espresso");?></label></td><td><input name='from' id='from' type='text' style="width:200px"value='<?php echo get_bloginfo('admin_email','display'); ?>'></td></tr>
16
-		<tr><td><label for='from_name'><?php esc_html_e("Your Name", "event_espresso");?></label></td><td><input name='from_name' id='from_name' type='text' style="width:200px"value='<?php printf(esc_html__("Admin of %s", "event_espresso"),get_bloginfo('name','display'));?>'></td></tr>
17
-		<tr><td><label for='body'><?php esc_html_e("Comments", "event_espresso");?></label></td><td><textarea name="body" id="body" class='system_status_info'><?php esc_html_e("Enter any comments about why you think the error may have occurred", "event_espresso");?></textarea>
18
-			<p class='description'><?php esc_html_e("Note: the System Information report will also be added to the email's body, which contains information about your Event Espresso, Wordpress, and PHP settings which can be helpful in debugging the problem.", "event_espresso");?></p></td></tr>
19
-		<tr><td colspan="2"><input type="submit" value="<?php esc_html_e("Mail Crash Report to Event Espresso", "event_espresso");?>"/></td></tr>
15
+		<tr><td><label for='from'><?php esc_html_e("From/Reply-To:", "event_espresso"); ?></label></td><td><input name='from' id='from' type='text' style="width:200px"value='<?php echo get_bloginfo('admin_email', 'display'); ?>'></td></tr>
16
+		<tr><td><label for='from_name'><?php esc_html_e("Your Name", "event_espresso"); ?></label></td><td><input name='from_name' id='from_name' type='text' style="width:200px"value='<?php printf(esc_html__("Admin of %s", "event_espresso"), get_bloginfo('name', 'display')); ?>'></td></tr>
17
+		<tr><td><label for='body'><?php esc_html_e("Comments", "event_espresso"); ?></label></td><td><textarea name="body" id="body" class='system_status_info'><?php esc_html_e("Enter any comments about why you think the error may have occurred", "event_espresso"); ?></textarea>
18
+			<p class='description'><?php esc_html_e("Note: the System Information report will also be added to the email's body, which contains information about your Event Espresso, Wordpress, and PHP settings which can be helpful in debugging the problem.", "event_espresso"); ?></p></td></tr>
19
+		<tr><td colspan="2"><input type="submit" value="<?php esc_html_e("Mail Crash Report to Event Espresso", "event_espresso"); ?>"/></td></tr>
20 20
 	</table>
21 21
 </form>
22 22
 <br>
23
-<p><?php printf(esc_html__('...or copy-and-paste the below information to %1$s %2$s %3$s', "event_espresso"),'<a href="mailto:'.EE_SUPPORT_EMAIL.'">',EE_SUPPORT_EMAIL,"</a>");?></p>
24
-<textarea class="system_status_info"><?php print_r( EEM_System_Status::instance()->get_system_stati())?></textarea>
25
-<p><?php printf( esc_html__( '%1$sNext Step%2$s', 'event_espresso' ), "<a href='$next_url'>","</a>");?></p>
26
-<p><?php printf( esc_html__( '...or %1$sDON\'T send crash report%2$s.', 'event_espresso' ), "<a href='$next_url'>","</a>");?></p>
23
+<p><?php printf(esc_html__('...or copy-and-paste the below information to %1$s %2$s %3$s', "event_espresso"), '<a href="mailto:'.EE_SUPPORT_EMAIL.'">', EE_SUPPORT_EMAIL, "</a>"); ?></p>
24
+<textarea class="system_status_info"><?php print_r(EEM_System_Status::instance()->get_system_stati())?></textarea>
25
+<p><?php printf(esc_html__('%1$sNext Step%2$s', 'event_espresso'), "<a href='$next_url'>", "</a>"); ?></p>
26
+<p><?php printf(esc_html__('...or %1$sDON\'T send crash report%2$s.', 'event_espresso'), "<a href='$next_url'>", "</a>"); ?></p>
Please login to merge, or discard this patch.
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
      * _get_transaction_and_cart_for_previous_visit
782 782
      *
783 783
      * @access private
784
-     * @return mixed EE_Transaction|NULL
784
+     * @return EE_Transaction|null EE_Transaction|NULL
785 785
      */
786 786
     private function _get_transaction_and_cart_for_previous_visit()
787 787
     {
@@ -863,7 +863,7 @@  discard block
 block discarded – undo
863 863
      *    generates a new EE_Transaction object and adds it to the $_transaction property.
864 864
      *
865 865
      * @access private
866
-     * @return mixed EE_Transaction|NULL
866
+     * @return EE_Transaction|null EE_Transaction|NULL
867 867
      */
868 868
     private function _initialize_transaction()
869 869
     {
Please login to merge, or discard this patch.
Indentation   +1836 added lines, -1836 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use EventEspresso\core\exceptions\InvalidInterfaceException;
7 7
 
8 8
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
9
-    exit('No direct script access allowed');
9
+	exit('No direct script access allowed');
10 10
 }
11 11
 
12 12
 
@@ -21,1841 +21,1841 @@  discard block
 block discarded – undo
21 21
 class EED_Single_Page_Checkout extends EED_Module
22 22
 {
23 23
 
24
-    /**
25
-     * $_initialized - has the SPCO controller already been initialized ?
26
-     *
27
-     * @access private
28
-     * @var bool $_initialized
29
-     */
30
-    private static $_initialized = false;
31
-
32
-
33
-    /**
34
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
35
-     *
36
-     * @access private
37
-     * @var bool $_valid_checkout
38
-     */
39
-    private static $_checkout_verified = true;
40
-
41
-    /**
42
-     *    $_reg_steps_array - holds initial array of reg steps
43
-     *
44
-     * @access private
45
-     * @var array $_reg_steps_array
46
-     */
47
-    private static $_reg_steps_array = array();
48
-
49
-    /**
50
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
51
-     *
52
-     * @access public
53
-     * @var EE_Checkout $checkout
54
-     */
55
-    public $checkout;
56
-
57
-
58
-
59
-    /**
60
-     * @return EED_Module|EED_Single_Page_Checkout
61
-     */
62
-    public static function instance()
63
-    {
64
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
65
-        return parent::get_instance(__CLASS__);
66
-    }
67
-
68
-
69
-
70
-    /**
71
-     * @return EE_CART
72
-     */
73
-    public function cart()
74
-    {
75
-        return $this->checkout->cart;
76
-    }
77
-
78
-
79
-
80
-    /**
81
-     * @return EE_Transaction
82
-     */
83
-    public function transaction()
84
-    {
85
-        return $this->checkout->transaction;
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     *    set_hooks - for hooking into EE Core, other modules, etc
92
-     *
93
-     * @access    public
94
-     * @return    void
95
-     * @throws EE_Error
96
-     */
97
-    public static function set_hooks()
98
-    {
99
-        EED_Single_Page_Checkout::set_definitions();
100
-    }
101
-
102
-
103
-
104
-    /**
105
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
106
-     *
107
-     * @access    public
108
-     * @return    void
109
-     * @throws EE_Error
110
-     */
111
-    public static function set_hooks_admin()
112
-    {
113
-        EED_Single_Page_Checkout::set_definitions();
114
-        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
115
-            return;
116
-        }
117
-        // going to start an output buffer in case anything gets accidentally output
118
-        // that might disrupt our JSON response
119
-        ob_start();
120
-        EED_Single_Page_Checkout::load_request_handler();
121
-        EED_Single_Page_Checkout::load_reg_steps();
122
-        // set ajax hooks
123
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
125
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
127
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     *    process ajax request
135
-     *
136
-     * @param string $ajax_action
137
-     * @throws EE_Error
138
-     */
139
-    public static function process_ajax_request($ajax_action)
140
-    {
141
-        EE_Registry::instance()->REQ->set('action', $ajax_action);
142
-        EED_Single_Page_Checkout::instance()->_initialize();
143
-    }
144
-
145
-
146
-
147
-    /**
148
-     *    ajax display registration step
149
-     *
150
-     * @throws EE_Error
151
-     */
152
-    public static function display_reg_step()
153
-    {
154
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     *    ajax process registration step
161
-     *
162
-     * @throws EE_Error
163
-     */
164
-    public static function process_reg_step()
165
-    {
166
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
167
-    }
168
-
169
-
170
-
171
-    /**
172
-     *    ajax process registration step
173
-     *
174
-     * @throws EE_Error
175
-     */
176
-    public static function update_reg_step()
177
-    {
178
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
179
-    }
180
-
181
-
182
-
183
-    /**
184
-     *   update_checkout
185
-     *
186
-     * @access public
187
-     * @return void
188
-     * @throws EE_Error
189
-     */
190
-    public static function update_checkout()
191
-    {
192
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
193
-    }
194
-
195
-
196
-
197
-    /**
198
-     *    load_request_handler
199
-     *
200
-     * @access    public
201
-     * @return    void
202
-     */
203
-    public static function load_request_handler()
204
-    {
205
-        // load core Request_Handler class
206
-        if (EE_Registry::instance()->REQ !== null) {
207
-            EE_Registry::instance()->load_core('Request_Handler');
208
-        }
209
-    }
210
-
211
-
212
-
213
-    /**
214
-     *    set_definitions
215
-     *
216
-     * @access    public
217
-     * @return    void
218
-     * @throws EE_Error
219
-     */
220
-    public static function set_definitions()
221
-    {
222
-        if(defined('SPCO_BASE_PATH')) {
223
-            return;
224
-        }
225
-        define(
226
-            'SPCO_BASE_PATH',
227
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
228
-        );
229
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
230
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
231
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
232
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
233
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
234
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
235
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
236
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
237
-    }
238
-
239
-
240
-
241
-    /**
242
-     * load_reg_steps
243
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
244
-     *
245
-     * @access    private
246
-     * @throws EE_Error
247
-     */
248
-    public static function load_reg_steps()
249
-    {
250
-        static $reg_steps_loaded = false;
251
-        if ($reg_steps_loaded) {
252
-            return;
253
-        }
254
-        // filter list of reg_steps
255
-        $reg_steps_to_load = (array)apply_filters(
256
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
257
-            EED_Single_Page_Checkout::get_reg_steps()
258
-        );
259
-        // sort by key (order)
260
-        ksort($reg_steps_to_load);
261
-        // loop through folders
262
-        foreach ($reg_steps_to_load as $order => $reg_step) {
263
-            // we need a
264
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
265
-                // copy over to the reg_steps_array
266
-                EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
267
-                // register custom key route for each reg step
268
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
269
-                EE_Config::register_route(
270
-                    $reg_step['slug'],
271
-                    'EED_Single_Page_Checkout',
272
-                    'run',
273
-                    'step'
274
-                );
275
-                // add AJAX or other hooks
276
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
277
-                    // setup autoloaders if necessary
278
-                    if ( ! class_exists($reg_step['class_name'])) {
279
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
280
-                            $reg_step['file_path'],
281
-                            true
282
-                        );
283
-                    }
284
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
285
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
286
-                    }
287
-                }
288
-            }
289
-        }
290
-        $reg_steps_loaded = true;
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     *    get_reg_steps
297
-     *
298
-     * @access    public
299
-     * @return    array
300
-     */
301
-    public static function get_reg_steps()
302
-    {
303
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
304
-        if (empty($reg_steps)) {
305
-            $reg_steps = array(
306
-                10  => array(
307
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
308
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
309
-                    'slug'       => 'attendee_information',
310
-                    'has_hooks'  => false,
311
-                ),
312
-                30  => array(
313
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
314
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
315
-                    'slug'       => 'payment_options',
316
-                    'has_hooks'  => true,
317
-                ),
318
-                999 => array(
319
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
320
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
321
-                    'slug'       => 'finalize_registration',
322
-                    'has_hooks'  => false,
323
-                ),
324
-            );
325
-        }
326
-        return $reg_steps;
327
-    }
328
-
329
-
330
-
331
-    /**
332
-     *    registration_checkout_for_admin
333
-     *
334
-     * @access    public
335
-     * @return    string
336
-     * @throws EE_Error
337
-     */
338
-    public static function registration_checkout_for_admin()
339
-    {
340
-        EED_Single_Page_Checkout::load_request_handler();
341
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
342
-        EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
343
-        EE_Registry::instance()->REQ->set('process_form_submission', false);
344
-        EED_Single_Page_Checkout::instance()->_initialize();
345
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
346
-        return EE_Registry::instance()->REQ->get_output();
347
-    }
348
-
349
-
350
-
351
-    /**
352
-     * process_registration_from_admin
353
-     *
354
-     * @access public
355
-     * @return \EE_Transaction
356
-     * @throws EE_Error
357
-     */
358
-    public static function process_registration_from_admin()
359
-    {
360
-        EED_Single_Page_Checkout::load_request_handler();
361
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
362
-        EE_Registry::instance()->REQ->set('action', 'process_reg_step');
363
-        EE_Registry::instance()->REQ->set('process_form_submission', true);
364
-        EED_Single_Page_Checkout::instance()->_initialize();
365
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
366
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
367
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
368
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
369
-                if ($final_reg_step->process_reg_step()) {
370
-                    $final_reg_step->set_completed();
371
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
372
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
373
-                }
374
-            }
375
-        }
376
-        return null;
377
-    }
378
-
379
-
380
-
381
-    /**
382
-     *    run
383
-     *
384
-     * @access    public
385
-     * @param WP_Query $WP_Query
386
-     * @return    void
387
-     * @throws EE_Error
388
-     */
389
-    public function run($WP_Query)
390
-    {
391
-        if (
392
-            $WP_Query instanceof WP_Query
393
-            && $WP_Query->is_main_query()
394
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
395
-            && $this->_is_reg_checkout()
396
-        ) {
397
-            $this->_initialize();
398
-        }
399
-    }
400
-
401
-
402
-
403
-    /**
404
-     * determines whether current url matches reg page url
405
-     *
406
-     * @return bool
407
-     */
408
-    protected function _is_reg_checkout()
409
-    {
410
-        // get current permalink for reg page without any extra query args
411
-        $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
412
-        // get request URI for current request, but without the scheme or host
413
-        $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
414
-        $current_request_uri = html_entity_decode($current_request_uri);
415
-        // get array of query args from the current request URI
416
-        $query_args = \EEH_URL::get_query_string($current_request_uri);
417
-        // grab page id if it is set
418
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
419
-        // and remove the page id from the query args (we will re-add it later)
420
-        unset($query_args['page_id']);
421
-        // now strip all query args from current request URI
422
-        $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
423
-        // and re-add the page id if it was set
424
-        if ($page_id) {
425
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
426
-        }
427
-        // remove slashes and ?
428
-        $current_request_uri = trim($current_request_uri, '?/');
429
-        // is current request URI part of the known full reg page URL ?
430
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * @param WP_Query $wp_query
437
-     * @return    void
438
-     * @throws EE_Error
439
-     */
440
-    public static function init($wp_query)
441
-    {
442
-        EED_Single_Page_Checkout::instance()->run($wp_query);
443
-    }
444
-
445
-
446
-
447
-    /**
448
-     *    _initialize - initial module setup
449
-     *
450
-     * @access    private
451
-     * @throws EE_Error
452
-     * @return    void
453
-     */
454
-    private function _initialize()
455
-    {
456
-        // ensure SPCO doesn't run twice
457
-        if (EED_Single_Page_Checkout::$_initialized) {
458
-            return;
459
-        }
460
-        try {
461
-            EED_Single_Page_Checkout::load_reg_steps();
462
-            $this->_verify_session();
463
-            // setup the EE_Checkout object
464
-            $this->checkout = $this->_initialize_checkout();
465
-            // filter checkout
466
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
467
-            // get the $_GET
468
-            $this->_get_request_vars();
469
-            if ($this->_block_bots()) {
470
-                return;
471
-            }
472
-            // filter continue_reg
473
-            $this->checkout->continue_reg = apply_filters(
474
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
475
-                true,
476
-                $this->checkout
477
-            );
478
-            // load the reg steps array
479
-            if ( ! $this->_load_and_instantiate_reg_steps()) {
480
-                EED_Single_Page_Checkout::$_initialized = true;
481
-                return;
482
-            }
483
-            // set the current step
484
-            $this->checkout->set_current_step($this->checkout->step);
485
-            // and the next step
486
-            $this->checkout->set_next_step();
487
-            // verify that everything has been setup correctly
488
-            if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
489
-                EED_Single_Page_Checkout::$_initialized = true;
490
-                return;
491
-            }
492
-            // lock the transaction
493
-            $this->checkout->transaction->lock();
494
-            // make sure all of our cached objects are added to their respective model entity mappers
495
-            $this->checkout->refresh_all_entities();
496
-            // set amount owing
497
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
498
-            // initialize each reg step, which gives them the chance to potentially alter the process
499
-            $this->_initialize_reg_steps();
500
-            // DEBUG LOG
501
-            //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
502
-            // get reg form
503
-            if( ! $this->_check_form_submission()) {
504
-                EED_Single_Page_Checkout::$_initialized = true;
505
-                return;
506
-            }
507
-            // checkout the action!!!
508
-            $this->_process_form_action();
509
-            // add some style and make it dance
510
-            $this->add_styles_and_scripts();
511
-            // kk... SPCO has successfully run
512
-            EED_Single_Page_Checkout::$_initialized = true;
513
-            // set no cache headers and constants
514
-            EE_System::do_not_cache();
515
-            // add anchor
516
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
517
-            // remove transaction lock
518
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
519
-        } catch (Exception $e) {
520
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
521
-        }
522
-    }
523
-
524
-
525
-
526
-    /**
527
-     *    _verify_session
528
-     * checks that the session is valid and not expired
529
-     *
530
-     * @access    private
531
-     * @throws EE_Error
532
-     */
533
-    private function _verify_session()
534
-    {
535
-        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
536
-            throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
537
-        }
538
-        $clear_session_requested = filter_var(
539
-            EE_Registry::instance()->REQ->get('clear_session', false),
540
-            FILTER_VALIDATE_BOOLEAN
541
-        );
542
-        // is session still valid ?
543
-        if ($clear_session_requested
544
-            || ( EE_Registry::instance()->SSN->expired()
545
-              && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
546
-            )
547
-        ) {
548
-            $this->checkout = new EE_Checkout();
549
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
550
-            // EE_Registry::instance()->SSN->reset_cart();
551
-            // EE_Registry::instance()->SSN->reset_checkout();
552
-            // EE_Registry::instance()->SSN->reset_transaction();
553
-            if (! $clear_session_requested) {
554
-                EE_Error::add_attention(
555
-                    EE_Registry::$i18n_js_strings['registration_expiration_notice'],
556
-                    __FILE__, __FUNCTION__, __LINE__
557
-                );
558
-            }
559
-            // EE_Registry::instance()->SSN->reset_expired();
560
-        }
561
-    }
562
-
563
-
564
-
565
-    /**
566
-     *    _initialize_checkout
567
-     * loads and instantiates EE_Checkout
568
-     *
569
-     * @access    private
570
-     * @throws EE_Error
571
-     * @return EE_Checkout
572
-     */
573
-    private function _initialize_checkout()
574
-    {
575
-        // look in session for existing checkout
576
-        /** @type EE_Checkout $checkout */
577
-        $checkout = EE_Registry::instance()->SSN->checkout();
578
-        // verify
579
-        if ( ! $checkout instanceof EE_Checkout) {
580
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
581
-            $checkout = EE_Registry::instance()->load_file(
582
-                SPCO_INC_PATH,
583
-                'EE_Checkout',
584
-                'class', array(),
585
-                false
586
-            );
587
-        } else {
588
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
589
-                $this->unlock_transaction();
590
-                wp_safe_redirect($checkout->redirect_url);
591
-                exit();
592
-            }
593
-        }
594
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
595
-        // verify again
596
-        if ( ! $checkout instanceof EE_Checkout) {
597
-            throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
598
-        }
599
-        // reset anything that needs a clean slate for each request
600
-        $checkout->reset_for_current_request();
601
-        return $checkout;
602
-    }
603
-
604
-
605
-
606
-    /**
607
-     *    _get_request_vars
608
-     *
609
-     * @access    private
610
-     * @return    void
611
-     * @throws EE_Error
612
-     */
613
-    private function _get_request_vars()
614
-    {
615
-        // load classes
616
-        EED_Single_Page_Checkout::load_request_handler();
617
-        //make sure this request is marked as belonging to EE
618
-        EE_Registry::instance()->REQ->set_espresso_page(true);
619
-        // which step is being requested ?
620
-        $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
621
-        // which step is being edited ?
622
-        $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
623
-        // and what we're doing on the current step
624
-        $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
625
-        // timestamp
626
-        $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
627
-        // returning to edit ?
628
-        $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
629
-        // add reg url link to registration query params
630
-        if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
631
-            $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
632
-        }
633
-        // or some other kind of revisit ?
634
-        $this->checkout->revisit = filter_var(
635
-            EE_Registry::instance()->REQ->get('revisit', false),
636
-            FILTER_VALIDATE_BOOLEAN
637
-        );
638
-        // and whether or not to generate a reg form for this request
639
-        $this->checkout->generate_reg_form = filter_var(
640
-            EE_Registry::instance()->REQ->get('generate_reg_form', true),
641
-            FILTER_VALIDATE_BOOLEAN
642
-        );
643
-        // and whether or not to process a reg form submission for this request
644
-        $this->checkout->process_form_submission = filter_var(
645
-            EE_Registry::instance()->REQ->get(
646
-                'process_form_submission',
647
-                $this->checkout->action === 'process_reg_step'
648
-            ),
649
-            FILTER_VALIDATE_BOOLEAN
650
-        );
651
-        $this->checkout->process_form_submission = filter_var(
652
-            $this->checkout->action !== 'display_spco_reg_step'
653
-                ? $this->checkout->process_form_submission
654
-                : false,
655
-            FILTER_VALIDATE_BOOLEAN
656
-        );
657
-        // $this->_display_request_vars();
658
-    }
659
-
660
-
661
-
662
-    /**
663
-     *  _display_request_vars
664
-     *
665
-     * @access    protected
666
-     * @return    void
667
-     */
668
-    protected function _display_request_vars()
669
-    {
670
-        if ( ! WP_DEBUG) {
671
-            return;
672
-        }
673
-        EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
674
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
675
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
676
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
677
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
678
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
679
-        EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
680
-        EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
681
-    }
682
-
683
-
684
-
685
-    /**
686
-     * _block_bots
687
-     * checks that the incoming request has either of the following set:
688
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
689
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
690
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
691
-     * then where you coming from man?
692
-     *
693
-     * @return boolean
694
-     */
695
-    private function _block_bots()
696
-    {
697
-        $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
698
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
699
-            return true;
700
-        }
701
-        return false;
702
-    }
703
-
704
-
705
-
706
-    /**
707
-     *    _get_first_step
708
-     *  gets slug for first step in $_reg_steps_array
709
-     *
710
-     * @access    private
711
-     * @throws EE_Error
712
-     * @return    string
713
-     */
714
-    private function _get_first_step()
715
-    {
716
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
717
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
718
-    }
719
-
720
-
721
-    /**
722
-     * instantiates each reg step based on the loaded reg_steps array
723
-     *
724
-     * @return    bool
725
-     * @throws EE_Error
726
-     * @throws InvalidArgumentException
727
-     * @throws InvalidDataTypeException
728
-     * @throws InvalidInterfaceException
729
-     */
730
-    private function _load_and_instantiate_reg_steps()
731
-    {
732
-        do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
733
-        // have reg_steps already been instantiated ?
734
-        if (
735
-            empty($this->checkout->reg_steps)
736
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
737
-        ) {
738
-            // if not, then loop through raw reg steps array
739
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
740
-                if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
741
-                    return false;
742
-                }
743
-            }
744
-            if(isset($this->checkout->reg_steps['registration_confirmation'])){
745
-                // skip the registration_confirmation page ?
746
-                if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
747
-                    // just remove it from the reg steps array
748
-                    $this->checkout->remove_reg_step('registration_confirmation', false);
749
-                } elseif (EE_Registry::instance()->CFG->registration->reg_confirmation_last
750
-                ) {
751
-                    // set the order to something big like 100
752
-                    $this->checkout->set_reg_step_order('registration_confirmation', 100);
753
-                }
754
-            }
755
-            // filter the array for good luck
756
-            $this->checkout->reg_steps = apply_filters(
757
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
758
-                $this->checkout->reg_steps
759
-            );
760
-            // finally re-sort based on the reg step class order properties
761
-            $this->checkout->sort_reg_steps();
762
-        } else {
763
-            foreach ($this->checkout->reg_steps as $reg_step) {
764
-                // set all current step stati to FALSE
765
-                $reg_step->set_is_current_step(false);
766
-            }
767
-        }
768
-        if (empty($this->checkout->reg_steps)) {
769
-            EE_Error::add_error(
770
-                __('No Reg Steps were loaded..', 'event_espresso'),
771
-                __FILE__, __FUNCTION__, __LINE__
772
-            );
773
-            return false;
774
-        }
775
-        // make reg step details available to JS
776
-        $this->checkout->set_reg_step_JSON_info();
777
-        return true;
778
-    }
779
-
780
-
781
-
782
-    /**
783
-     *     _load_and_instantiate_reg_step
784
-     *
785
-     * @access    private
786
-     * @param array $reg_step
787
-     * @param int   $order
788
-     * @return bool
789
-     */
790
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
791
-    {
792
-        // we need a file_path, class_name, and slug to add a reg step
793
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
794
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
795
-            if (
796
-                $this->checkout->reg_url_link
797
-                && $this->checkout->step !== $reg_step['slug']
798
-                && $reg_step['slug'] !== 'finalize_registration'
799
-                // normally at this point we would NOT load the reg step, but this filter can change that
800
-                && apply_filters(
801
-                    'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
802
-                    true,
803
-                    $reg_step,
804
-                    $this->checkout
805
-                )
806
-            ) {
807
-                return true;
808
-            }
809
-            // instantiate step class using file path and class name
810
-            $reg_step_obj = EE_Registry::instance()->load_file(
811
-                $reg_step['file_path'],
812
-                $reg_step['class_name'],
813
-                'class',
814
-                $this->checkout,
815
-                false
816
-            );
817
-            // did we gets the goods ?
818
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
819
-                // set reg step order based on config
820
-                $reg_step_obj->set_order($order);
821
-                // add instantiated reg step object to the master reg steps array
822
-                $this->checkout->add_reg_step($reg_step_obj);
823
-            } else {
824
-                EE_Error::add_error(
825
-                    __('The current step could not be set.', 'event_espresso'),
826
-                    __FILE__, __FUNCTION__, __LINE__
827
-                );
828
-                return false;
829
-            }
830
-        } else {
831
-            if (WP_DEBUG) {
832
-                EE_Error::add_error(
833
-                    sprintf(
834
-                        __(
835
-                            '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',
836
-                            'event_espresso'
837
-                        ),
838
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
839
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
840
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
841
-                        '<ul>',
842
-                        '<li>',
843
-                        '</li>',
844
-                        '</ul>'
845
-                    ),
846
-                    __FILE__, __FUNCTION__, __LINE__
847
-                );
848
-            }
849
-            return false;
850
-        }
851
-        return true;
852
-    }
853
-
854
-
855
-    /**
856
-     * _verify_transaction_and_get_registrations
857
-     *
858
-     * @access private
859
-     * @return bool
860
-     * @throws InvalidDataTypeException
861
-     * @throws InvalidEntityException
862
-     * @throws EE_Error
863
-     */
864
-    private function _verify_transaction_and_get_registrations()
865
-    {
866
-        // was there already a valid transaction in the checkout from the session ?
867
-        if ( ! $this->checkout->transaction instanceof EE_Transaction) {
868
-            // get transaction from db or session
869
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
870
-                ? $this->_get_transaction_and_cart_for_previous_visit()
871
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
872
-            if ( ! $this->checkout->transaction instanceof EE_Transaction) {
873
-                EE_Error::add_error(
874
-                    __('Your Registration and Transaction information could not be retrieved from the db.',
875
-                        'event_espresso'),
876
-                    __FILE__, __FUNCTION__, __LINE__
877
-                );
878
-                $this->checkout->transaction = EE_Transaction::new_instance();
879
-                // add some style and make it dance
880
-                $this->add_styles_and_scripts();
881
-                EED_Single_Page_Checkout::$_initialized = true;
882
-                return false;
883
-            }
884
-            // and the registrations for the transaction
885
-            $this->_get_registrations($this->checkout->transaction);
886
-        }
887
-        return true;
888
-    }
889
-
890
-
891
-
892
-    /**
893
-     * _get_transaction_and_cart_for_previous_visit
894
-     *
895
-     * @access private
896
-     * @return mixed EE_Transaction|NULL
897
-     */
898
-    private function _get_transaction_and_cart_for_previous_visit()
899
-    {
900
-        /** @var $TXN_model EEM_Transaction */
901
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
902
-        // because the reg_url_link is present in the request,
903
-        // this is a return visit to SPCO, so we'll get the transaction data from the db
904
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
905
-        // verify transaction
906
-        if ($transaction instanceof EE_Transaction) {
907
-            // and get the cart that was used for that transaction
908
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
909
-            return $transaction;
910
-        }
911
-        EE_Error::add_error(
912
-            __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
913
-            __FILE__, __FUNCTION__, __LINE__
914
-        );
915
-        return null;
916
-
917
-    }
918
-
919
-
920
-
921
-    /**
922
-     * _get_cart_for_transaction
923
-     *
924
-     * @access private
925
-     * @param EE_Transaction $transaction
926
-     * @return EE_Cart
927
-     */
928
-    private function _get_cart_for_transaction($transaction)
929
-    {
930
-        return $this->checkout->get_cart_for_transaction($transaction);
931
-    }
932
-
933
-
934
-
935
-    /**
936
-     * get_cart_for_transaction
937
-     *
938
-     * @access public
939
-     * @param EE_Transaction $transaction
940
-     * @return EE_Cart
941
-     */
942
-    public function get_cart_for_transaction(EE_Transaction $transaction)
943
-    {
944
-        return $this->checkout->get_cart_for_transaction($transaction);
945
-    }
946
-
947
-
948
-
949
-    /**
950
-     * _get_transaction_and_cart_for_current_session
951
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
952
-     *
953
-     * @access private
954
-     * @return EE_Transaction
955
-     * @throws EE_Error
956
-     */
957
-    private function _get_cart_for_current_session_and_setup_new_transaction()
958
-    {
959
-        //  if there's no transaction, then this is the FIRST visit to SPCO
960
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
961
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
962
-        // and then create a new transaction
963
-        $transaction = $this->_initialize_transaction();
964
-        // verify transaction
965
-        if ($transaction instanceof EE_Transaction) {
966
-            // save it so that we have an ID for other objects to use
967
-            $transaction->save();
968
-            // and save TXN data to the cart
969
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
970
-        } else {
971
-            EE_Error::add_error(
972
-                __('A Valid Transaction could not be initialized.', 'event_espresso'),
973
-                __FILE__, __FUNCTION__, __LINE__
974
-            );
975
-        }
976
-        return $transaction;
977
-    }
978
-
979
-
980
-
981
-    /**
982
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
983
-     *
984
-     * @access private
985
-     * @return mixed EE_Transaction|NULL
986
-     */
987
-    private function _initialize_transaction()
988
-    {
989
-        try {
990
-            // ensure cart totals have been calculated
991
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
992
-            // grab the cart grand total
993
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
994
-            // create new TXN
995
-            $transaction = EE_Transaction::new_instance(
996
-                array(
997
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
998
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
999
-                    'TXN_paid'      => 0,
1000
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
1001
-                )
1002
-            );
1003
-            // save it so that we have an ID for other objects to use
1004
-            $transaction->save();
1005
-            // set cron job for following up on TXNs after their session has expired
1006
-            EE_Cron_Tasks::schedule_expired_transaction_check(
1007
-                EE_Registry::instance()->SSN->expiration() + 1,
1008
-                $transaction->ID()
1009
-            );
1010
-            return $transaction;
1011
-        } catch (Exception $e) {
1012
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1013
-        }
1014
-        return null;
1015
-    }
1016
-
1017
-
1018
-    /**
1019
-     * _get_registrations
1020
-     *
1021
-     * @access private
1022
-     * @param EE_Transaction $transaction
1023
-     * @return void
1024
-     * @throws InvalidDataTypeException
1025
-     * @throws InvalidEntityException
1026
-     * @throws EE_Error
1027
-     */
1028
-    private function _get_registrations(EE_Transaction $transaction)
1029
-    {
1030
-        // first step: grab the registrants  { : o
1031
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1032
-        $this->checkout->total_ticket_count = count($registrations);
1033
-        // verify registrations have been set
1034
-        if (empty($registrations)) {
1035
-            // if no cached registrations, then check the db
1036
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1037
-            // still nothing ? well as long as this isn't a revisit
1038
-            if (empty($registrations) && ! $this->checkout->revisit) {
1039
-                // generate new registrations from scratch
1040
-                $registrations = $this->_initialize_registrations($transaction);
1041
-            }
1042
-        }
1043
-        // sort by their original registration order
1044
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1045
-        // then loop thru the array
1046
-        foreach ($registrations as $registration) {
1047
-            // verify each registration
1048
-            if ($registration instanceof EE_Registration) {
1049
-                // we display all attendee info for the primary registrant
1050
-                if ($this->checkout->reg_url_link === $registration->reg_url_link()
1051
-                    && $registration->is_primary_registrant()
1052
-                ) {
1053
-                    $this->checkout->primary_revisit = true;
1054
-                    break;
1055
-                }
1056
-                if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1057
-                    // but hide info if it doesn't belong to you
1058
-                    $transaction->clear_cache('Registration', $registration->ID());
1059
-                    $this->checkout->total_ticket_count--;
1060
-                }
1061
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1062
-            }
1063
-        }
1064
-    }
1065
-
1066
-
1067
-    /**
1068
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1069
-     *
1070
-     * @access private
1071
-     * @param EE_Transaction $transaction
1072
-     * @return    array
1073
-     * @throws InvalidDataTypeException
1074
-     * @throws InvalidEntityException
1075
-     * @throws EE_Error
1076
-     */
1077
-    private function _initialize_registrations(EE_Transaction $transaction)
1078
-    {
1079
-        $att_nmbr = 0;
1080
-        $registrations = array();
1081
-        if ($transaction instanceof EE_Transaction) {
1082
-            /** @type EE_Registration_Processor $registration_processor */
1083
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1084
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1085
-            // now let's add the cart items to the $transaction
1086
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1087
-                //do the following for each ticket of this type they selected
1088
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1089
-                    $att_nmbr++;
1090
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1091
-                    $CreateRegistrationCommand = EE_Registry::instance()->create(
1092
-                        'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1093
-                        array(
1094
-                            $transaction,
1095
-                            $line_item,
1096
-                            $att_nmbr,
1097
-                            $this->checkout->total_ticket_count,
1098
-                        )
1099
-                    );
1100
-                    // override capabilities for frontend registrations
1101
-                    if ( ! is_admin()) {
1102
-                        $CreateRegistrationCommand->setCapCheck(
1103
-                            new PublicCapabilities('', 'create_new_registration')
1104
-                        );
1105
-                    }
1106
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1107
-                    if ( ! $registration instanceof EE_Registration) {
1108
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1109
-                    }
1110
-                    $registrations[ $registration->ID() ] = $registration;
1111
-                }
1112
-            }
1113
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1114
-        }
1115
-        return $registrations;
1116
-    }
1117
-
1118
-
1119
-
1120
-    /**
1121
-     * sorts registrations by REG_count
1122
-     *
1123
-     * @access public
1124
-     * @param EE_Registration $reg_A
1125
-     * @param EE_Registration $reg_B
1126
-     * @return int
1127
-     */
1128
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1129
-    {
1130
-        // this shouldn't ever happen within the same TXN, but oh well
1131
-        if ($reg_A->count() === $reg_B->count()) {
1132
-            return 0;
1133
-        }
1134
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1135
-    }
1136
-
1137
-
1138
-
1139
-    /**
1140
-     *    _final_verifications
1141
-     * just makes sure that everything is set up correctly before proceeding
1142
-     *
1143
-     * @access    private
1144
-     * @return    bool
1145
-     * @throws EE_Error
1146
-     */
1147
-    private function _final_verifications()
1148
-    {
1149
-        // filter checkout
1150
-        $this->checkout = apply_filters(
1151
-            'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1152
-            $this->checkout
1153
-        );
1154
-        //verify that current step is still set correctly
1155
-        if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1156
-            EE_Error::add_error(
1157
-                __('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'),
1158
-                __FILE__,
1159
-                __FUNCTION__,
1160
-                __LINE__
1161
-            );
1162
-            return false;
1163
-        }
1164
-        // if returning to SPCO, then verify that primary registrant is set
1165
-        if ( ! empty($this->checkout->reg_url_link)) {
1166
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1167
-            if ( ! $valid_registrant instanceof EE_Registration) {
1168
-                EE_Error::add_error(
1169
-                    __('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'),
1170
-                    __FILE__,
1171
-                    __FUNCTION__,
1172
-                    __LINE__
1173
-                );
1174
-                return false;
1175
-            }
1176
-            $valid_registrant = null;
1177
-            foreach (
1178
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1179
-            ) {
1180
-                if (
1181
-                    $registration instanceof EE_Registration
1182
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1183
-                ) {
1184
-                    $valid_registrant = $registration;
1185
-                }
1186
-            }
1187
-            if ( ! $valid_registrant instanceof EE_Registration) {
1188
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1189
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1190
-                    // clear the session, mark the checkout as unverified, and try again
1191
-                    EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1192
-                    EED_Single_Page_Checkout::$_initialized = false;
1193
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1194
-                    $this->_initialize();
1195
-                    EE_Error::reset_notices();
1196
-                    return false;
1197
-                }
1198
-                EE_Error::add_error(
1199
-                    __(
1200
-                        '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.',
1201
-                        'event_espresso'
1202
-                    ),
1203
-                    __FILE__,
1204
-                    __FUNCTION__,
1205
-                    __LINE__
1206
-                );
1207
-                return false;
1208
-            }
1209
-        }
1210
-        // now that things have been kinda sufficiently verified,
1211
-        // let's add the checkout to the session so that it's available to other systems
1212
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1213
-        return true;
1214
-    }
1215
-
1216
-
1217
-
1218
-    /**
1219
-     *    _initialize_reg_steps
1220
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1221
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1222
-     *
1223
-     * @access    private
1224
-     * @param bool $reinitializing
1225
-     * @throws EE_Error
1226
-     */
1227
-    private function _initialize_reg_steps($reinitializing = false)
1228
-    {
1229
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1230
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1231
-        foreach ($this->checkout->reg_steps as $reg_step) {
1232
-            if ( ! $reg_step->initialize_reg_step()) {
1233
-                // if not initialized then maybe this step is being removed...
1234
-                if ( ! $reinitializing && $reg_step->is_current_step()) {
1235
-                    // if it was the current step, then we need to start over here
1236
-                    $this->_initialize_reg_steps(true);
1237
-                    return;
1238
-                }
1239
-                continue;
1240
-            }
1241
-            // add css and JS for current step
1242
-            $reg_step->enqueue_styles_and_scripts();
1243
-            // i18n
1244
-            $reg_step->translate_js_strings();
1245
-            if ($reg_step->is_current_step()) {
1246
-                // the text that appears on the reg step form submit button
1247
-                $reg_step->set_submit_button_text();
1248
-            }
1249
-        }
1250
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1251
-        do_action(
1252
-            "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1253
-            $this->checkout->current_step
1254
-        );
1255
-    }
1256
-
1257
-
1258
-
1259
-    /**
1260
-     * _check_form_submission
1261
-     *
1262
-     * @access private
1263
-     * @return boolean
1264
-     */
1265
-    private function _check_form_submission()
1266
-    {
1267
-        //does this request require the reg form to be generated ?
1268
-        if ($this->checkout->generate_reg_form) {
1269
-            // ever heard that song by Blue Rodeo ?
1270
-            try {
1271
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1272
-                // if not displaying a form, then check for form submission
1273
-                if (
1274
-                    $this->checkout->process_form_submission
1275
-                    && $this->checkout->current_step->reg_form->was_submitted()
1276
-                ) {
1277
-                    // clear out any old data in case this step is being run again
1278
-                    $this->checkout->current_step->set_valid_data(array());
1279
-                    // capture submitted form data
1280
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1281
-                        apply_filters(
1282
-                            'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1283
-                            EE_Registry::instance()->REQ->params(),
1284
-                            $this->checkout
1285
-                        )
1286
-                    );
1287
-                    // validate submitted form data
1288
-                    if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1289
-                        // thou shall not pass !!!
1290
-                        $this->checkout->continue_reg = false;
1291
-                        // any form validation errors?
1292
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1293
-                            EE_Error::add_error(
1294
-                                $this->checkout->current_step->reg_form->submission_error_message(),
1295
-                                __FILE__, __FUNCTION__, __LINE__
1296
-                            );
1297
-                        }
1298
-                        // well not really... what will happen is
1299
-                        // we'll just get redirected back to redo the current step
1300
-                        $this->go_to_next_step();
1301
-                        return false;
1302
-                    }
1303
-                }
1304
-            } catch (EE_Error $e) {
1305
-                $e->get_error();
1306
-            }
1307
-        }
1308
-        return true;
1309
-    }
1310
-
1311
-
1312
-
1313
-    /**
1314
-     * _process_action
1315
-     *
1316
-     * @access private
1317
-     * @return void
1318
-     * @throws EE_Error
1319
-     */
1320
-    private function _process_form_action()
1321
-    {
1322
-        // what cha wanna do?
1323
-        switch ($this->checkout->action) {
1324
-            // AJAX next step reg form
1325
-            case 'display_spco_reg_step' :
1326
-                $this->checkout->redirect = false;
1327
-                if (EE_Registry::instance()->REQ->ajax) {
1328
-                    $this->checkout->json_response->set_reg_step_html(
1329
-                        $this->checkout->current_step->display_reg_form()
1330
-                    );
1331
-                }
1332
-                break;
1333
-            default :
1334
-                // meh... do one of those other steps first
1335
-                if (
1336
-                    ! empty($this->checkout->action)
1337
-                    && is_callable(array($this->checkout->current_step, $this->checkout->action))
1338
-                ) {
1339
-                    // dynamically creates hook point like:
1340
-                    //   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1341
-                    do_action(
1342
-                        "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1343
-                        $this->checkout->current_step
1344
-                    );
1345
-                    // call action on current step
1346
-                    if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1347
-                        // good registrant, you get to proceed
1348
-                        if (
1349
-                            $this->checkout->current_step->success_message() !== ''
1350
-                            && apply_filters(
1351
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1352
-                                false
1353
-                            )
1354
-                        ) {
1355
-                            EE_Error::add_success(
1356
-                                $this->checkout->current_step->success_message()
1357
-                                . '<br />' . $this->checkout->next_step->_instructions()
1358
-                            );
1359
-                        }
1360
-                        // pack it up, pack it in...
1361
-                        $this->_setup_redirect();
1362
-                    }
1363
-                    // dynamically creates hook point like:
1364
-                    //  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1365
-                    do_action(
1366
-                        "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1367
-                        $this->checkout->current_step
1368
-                    );
1369
-                } else {
1370
-                    EE_Error::add_error(
1371
-                        sprintf(
1372
-                            __(
1373
-                                'The requested form action "%s" does not exist for the current "%s" registration step.',
1374
-                                'event_espresso'
1375
-                            ),
1376
-                            $this->checkout->action,
1377
-                            $this->checkout->current_step->name()
1378
-                        ),
1379
-                        __FILE__,
1380
-                        __FUNCTION__,
1381
-                        __LINE__
1382
-                    );
1383
-                }
1384
-            // end default
1385
-        }
1386
-        // store our progress so far
1387
-        $this->checkout->stash_transaction_and_checkout();
1388
-        // advance to the next step! If you pass GO, collect $200
1389
-        $this->go_to_next_step();
1390
-    }
1391
-
1392
-
1393
-
1394
-    /**
1395
-     *        add_styles_and_scripts
1396
-     *
1397
-     * @access        public
1398
-     * @return        void
1399
-     */
1400
-    public function add_styles_and_scripts()
1401
-    {
1402
-        // i18n
1403
-        $this->translate_js_strings();
1404
-        if ($this->checkout->admin_request) {
1405
-            add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1406
-        } else {
1407
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1408
-        }
1409
-    }
1410
-
1411
-
1412
-
1413
-    /**
1414
-     *        translate_js_strings
1415
-     *
1416
-     * @access        public
1417
-     * @return        void
1418
-     */
1419
-    public function translate_js_strings()
1420
-    {
1421
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1422
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1423
-        EE_Registry::$i18n_js_strings['server_error'] = __(
1424
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1425
-            'event_espresso'
1426
-        );
1427
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1428
-            'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1429
-            'event_espresso'
1430
-        );
1431
-        EE_Registry::$i18n_js_strings['validation_error'] = __(
1432
-            'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1433
-            'event_espresso'
1434
-        );
1435
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1436
-            'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1437
-            'event_espresso'
1438
-        );
1439
-        EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1440
-            'This registration step could not be completed. Please refresh the page and try again.',
1441
-            'event_espresso'
1442
-        );
1443
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1444
-            'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1445
-            'event_espresso'
1446
-        );
1447
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1448
-            __(
1449
-                'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1450
-                'event_espresso'
1451
-            ),
1452
-            '<br/>',
1453
-            '<br/>'
1454
-        );
1455
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1456
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1457
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1458
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1459
-        EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1460
-        EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1461
-        EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1462
-        EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1463
-        EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1464
-        EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1465
-        EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1466
-        EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1467
-        EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1468
-        EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1469
-        EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1470
-        EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1471
-        EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1472
-        EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1473
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
1474
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1475
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1476
-            true
1477
-        );
1478
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1479
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1480
-        );
1481
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1482
-            'M d, Y H:i:s',
1483
-            EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1484
-        );
1485
-    }
1486
-
1487
-
1488
-
1489
-    /**
1490
-     *    enqueue_styles_and_scripts
1491
-     *
1492
-     * @access        public
1493
-     * @return        void
1494
-     * @throws EE_Error
1495
-     */
1496
-    public function enqueue_styles_and_scripts()
1497
-    {
1498
-        // load css
1499
-        wp_register_style(
1500
-            'single_page_checkout',
1501
-            SPCO_CSS_URL . 'single_page_checkout.css',
1502
-            array('espresso_default'),
1503
-            EVENT_ESPRESSO_VERSION
1504
-        );
1505
-        wp_enqueue_style('single_page_checkout');
1506
-        // load JS
1507
-        wp_register_script(
1508
-            'jquery_plugin',
1509
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1510
-            array('jquery'),
1511
-            '1.0.1',
1512
-            true
1513
-        );
1514
-        wp_register_script(
1515
-            'jquery_countdown',
1516
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1517
-            array('jquery_plugin'),
1518
-            '2.0.2',
1519
-            true
1520
-        );
1521
-        wp_register_script(
1522
-            'single_page_checkout',
1523
-            SPCO_JS_URL . 'single_page_checkout.js',
1524
-            array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1525
-            EVENT_ESPRESSO_VERSION,
1526
-            true
1527
-        );
1528
-        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1529
-            $this->checkout->registration_form->enqueue_js();
1530
-        }
1531
-        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1532
-            $this->checkout->current_step->reg_form->enqueue_js();
1533
-        }
1534
-        wp_enqueue_script('single_page_checkout');
1535
-        /**
1536
-         * global action hook for enqueueing styles and scripts with
1537
-         * spco calls.
1538
-         */
1539
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1540
-        /**
1541
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1542
-         * The hook will end up being something like:
1543
-         *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1544
-         */
1545
-        do_action(
1546
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1547
-            $this
1548
-        );
1549
-    }
1550
-
1551
-
1552
-
1553
-    /**
1554
-     *    display the Registration Single Page Checkout Form
1555
-     *
1556
-     * @access    private
1557
-     * @return    void
1558
-     * @throws EE_Error
1559
-     */
1560
-    private function _display_spco_reg_form()
1561
-    {
1562
-        // if registering via the admin, just display the reg form for the current step
1563
-        if ($this->checkout->admin_request) {
1564
-            EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1565
-        } else {
1566
-            // add powered by EE msg
1567
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1568
-            $empty_cart = count(
1569
-                $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1570
-            ) < 1;
1571
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1572
-            $cookies_not_set_msg = '';
1573
-            if ($empty_cart) {
1574
-                $cookies_not_set_msg = apply_filters(
1575
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1576
-                    sprintf(
1577
-                        __(
1578
-                            '%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',
1579
-                            'event_espresso'
1580
-                        ),
1581
-                        '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1582
-                        '</div>',
1583
-                        '<h6 class="important-notice">',
1584
-                        '</h6>',
1585
-                        '<p>',
1586
-                        '</p>',
1587
-                        '<br />',
1588
-                        '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1589
-                        '</a>'
1590
-                    )
1591
-                );
1592
-            }
1593
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1594
-                array(
1595
-                    'name'            => 'single-page-checkout',
1596
-                    'html_id'         => 'ee-single-page-checkout-dv',
1597
-                    'layout_strategy' =>
1598
-                        new EE_Template_Layout(
1599
-                            array(
1600
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1601
-                                'template_args'        => array(
1602
-                                    'empty_cart'              => $empty_cart,
1603
-                                    'revisit'                 => $this->checkout->revisit,
1604
-                                    'reg_steps'               => $this->checkout->reg_steps,
1605
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1606
-                                        ? $this->checkout->next_step->slug()
1607
-                                        : '',
1608
-                                    'empty_msg'               => apply_filters(
1609
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1610
-                                        sprintf(
1611
-                                            __(
1612
-                                                'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1613
-                                                'event_espresso'
1614
-                                            ),
1615
-                                            '<a href="'
1616
-                                            . get_post_type_archive_link('espresso_events')
1617
-                                            . '" title="',
1618
-                                            '">',
1619
-                                            '</a>'
1620
-                                        )
1621
-                                    ),
1622
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1623
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1624
-                                    'session_expiration'      => gmdate(
1625
-                                        'M d, Y H:i:s',
1626
-                                        EE_Registry::instance()->SSN->expiration()
1627
-                                        + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1628
-                                    ),
1629
-                                ),
1630
-                            )
1631
-                        ),
1632
-                )
1633
-            );
1634
-            // load template and add to output sent that gets filtered into the_content()
1635
-            EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1636
-        }
1637
-    }
1638
-
1639
-
1640
-
1641
-    /**
1642
-     *    add_extra_finalize_registration_inputs
1643
-     *
1644
-     * @access    public
1645
-     * @param $next_step
1646
-     * @internal  param string $label
1647
-     * @return void
1648
-     */
1649
-    public function add_extra_finalize_registration_inputs($next_step)
1650
-    {
1651
-        if ($next_step === 'finalize_registration') {
1652
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1653
-        }
1654
-    }
1655
-
1656
-
1657
-
1658
-    /**
1659
-     *    display_registration_footer
1660
-     *
1661
-     * @access    public
1662
-     * @return    string
1663
-     */
1664
-    public static function display_registration_footer()
1665
-    {
1666
-        if (
1667
-        apply_filters(
1668
-            'FHEE__EE_Front__Controller__show_reg_footer',
1669
-            EE_Registry::instance()->CFG->admin->show_reg_footer
1670
-        )
1671
-        ) {
1672
-            add_filter(
1673
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1674
-                function ($url) {
1675
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1676
-                }
1677
-            );
1678
-            echo apply_filters(
1679
-                'FHEE__EE_Front_Controller__display_registration_footer',
1680
-                \EEH_Template::powered_by_event_espresso(
1681
-                    '',
1682
-                    'espresso-registration-footer-dv',
1683
-                    array('utm_content' => 'registration_checkout')
1684
-                )
1685
-            );
1686
-        }
1687
-        return '';
1688
-    }
1689
-
1690
-
1691
-
1692
-    /**
1693
-     *    unlock_transaction
1694
-     *
1695
-     * @access    public
1696
-     * @return    void
1697
-     * @throws EE_Error
1698
-     */
1699
-    public function unlock_transaction()
1700
-    {
1701
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1702
-            $this->checkout->transaction->unlock();
1703
-        }
1704
-    }
1705
-
1706
-
1707
-
1708
-    /**
1709
-     *        _setup_redirect
1710
-     *
1711
-     * @access    private
1712
-     * @return void
1713
-     */
1714
-    private function _setup_redirect()
1715
-    {
1716
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1717
-            $this->checkout->redirect = true;
1718
-            if (empty($this->checkout->redirect_url)) {
1719
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1720
-            }
1721
-            $this->checkout->redirect_url = apply_filters(
1722
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1723
-                $this->checkout->redirect_url,
1724
-                $this->checkout
1725
-            );
1726
-        }
1727
-    }
1728
-
1729
-
1730
-
1731
-    /**
1732
-     *   handle ajax message responses and redirects
1733
-     *
1734
-     * @access public
1735
-     * @return void
1736
-     * @throws EE_Error
1737
-     */
1738
-    public function go_to_next_step()
1739
-    {
1740
-        if (EE_Registry::instance()->REQ->ajax) {
1741
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1742
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1743
-        }
1744
-        $this->unlock_transaction();
1745
-        // just return for these conditions
1746
-        if (
1747
-            $this->checkout->admin_request
1748
-            || $this->checkout->action === 'redirect_form'
1749
-            || $this->checkout->action === 'update_checkout'
1750
-        ) {
1751
-            return;
1752
-        }
1753
-        // AJAX response
1754
-        $this->_handle_json_response();
1755
-        // redirect to next step or the Thank You page
1756
-        $this->_handle_html_redirects();
1757
-        // hmmm... must be something wrong, so let's just display the form again !
1758
-        $this->_display_spco_reg_form();
1759
-    }
1760
-
1761
-
1762
-
1763
-    /**
1764
-     *   _handle_json_response
1765
-     *
1766
-     * @access protected
1767
-     * @return void
1768
-     */
1769
-    protected function _handle_json_response()
1770
-    {
1771
-        // if this is an ajax request
1772
-        if (EE_Registry::instance()->REQ->ajax) {
1773
-            // DEBUG LOG
1774
-            //$this->checkout->log(
1775
-            //	__CLASS__, __FUNCTION__, __LINE__,
1776
-            //	array(
1777
-            //		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1778
-            //		'redirect'                   => $this->checkout->redirect,
1779
-            //		'continue_reg'               => $this->checkout->continue_reg,
1780
-            //	)
1781
-            //);
1782
-            $this->checkout->json_response->set_registration_time_limit(
1783
-                $this->checkout->get_registration_time_limit()
1784
-            );
1785
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1786
-            // just send the ajax (
1787
-            $json_response = apply_filters(
1788
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1789
-                $this->checkout->json_response
1790
-            );
1791
-            echo $json_response;
1792
-            exit();
1793
-        }
1794
-    }
1795
-
1796
-
1797
-
1798
-    /**
1799
-     *   _handle_redirects
1800
-     *
1801
-     * @access protected
1802
-     * @return void
1803
-     */
1804
-    protected function _handle_html_redirects()
1805
-    {
1806
-        // going somewhere ?
1807
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1808
-            // store notices in a transient
1809
-            EE_Error::get_notices(false, true, true);
1810
-            // DEBUG LOG
1811
-            //$this->checkout->log(
1812
-            //	__CLASS__, __FUNCTION__, __LINE__,
1813
-            //	array(
1814
-            //		'headers_sent' => headers_sent(),
1815
-            //		'redirect_url'     => $this->checkout->redirect_url,
1816
-            //		'headers_list'    => headers_list(),
1817
-            //	)
1818
-            //);
1819
-            wp_safe_redirect($this->checkout->redirect_url);
1820
-            exit();
1821
-        }
1822
-    }
1823
-
1824
-
1825
-
1826
-    /**
1827
-     *   set_checkout_anchor
1828
-     *
1829
-     * @access public
1830
-     * @return void
1831
-     */
1832
-    public function set_checkout_anchor()
1833
-    {
1834
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1835
-    }
1836
-
1837
-    /**
1838
-     *    getRegistrationExpirationNotice
1839
-     *
1840
-     * @since 4.9.59.p
1841
-     * @access    public
1842
-     * @return    string
1843
-     */
1844
-    public static function getRegistrationExpirationNotice()
1845
-    {
1846
-        return sprintf(
1847
-            __('%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 accept our apologies for any inconvenience this may have caused.%8$s',
1848
-                'event_espresso'),
1849
-            '<h4 class="important-notice">',
1850
-            '</h4>',
1851
-            '<br />',
1852
-            '<p>',
1853
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1854
-            '">',
1855
-            '</a>',
1856
-            '</p>'
1857
-        );
1858
-    }
24
+	/**
25
+	 * $_initialized - has the SPCO controller already been initialized ?
26
+	 *
27
+	 * @access private
28
+	 * @var bool $_initialized
29
+	 */
30
+	private static $_initialized = false;
31
+
32
+
33
+	/**
34
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
35
+	 *
36
+	 * @access private
37
+	 * @var bool $_valid_checkout
38
+	 */
39
+	private static $_checkout_verified = true;
40
+
41
+	/**
42
+	 *    $_reg_steps_array - holds initial array of reg steps
43
+	 *
44
+	 * @access private
45
+	 * @var array $_reg_steps_array
46
+	 */
47
+	private static $_reg_steps_array = array();
48
+
49
+	/**
50
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
51
+	 *
52
+	 * @access public
53
+	 * @var EE_Checkout $checkout
54
+	 */
55
+	public $checkout;
56
+
57
+
58
+
59
+	/**
60
+	 * @return EED_Module|EED_Single_Page_Checkout
61
+	 */
62
+	public static function instance()
63
+	{
64
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
65
+		return parent::get_instance(__CLASS__);
66
+	}
67
+
68
+
69
+
70
+	/**
71
+	 * @return EE_CART
72
+	 */
73
+	public function cart()
74
+	{
75
+		return $this->checkout->cart;
76
+	}
77
+
78
+
79
+
80
+	/**
81
+	 * @return EE_Transaction
82
+	 */
83
+	public function transaction()
84
+	{
85
+		return $this->checkout->transaction;
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 *    set_hooks - for hooking into EE Core, other modules, etc
92
+	 *
93
+	 * @access    public
94
+	 * @return    void
95
+	 * @throws EE_Error
96
+	 */
97
+	public static function set_hooks()
98
+	{
99
+		EED_Single_Page_Checkout::set_definitions();
100
+	}
101
+
102
+
103
+
104
+	/**
105
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
106
+	 *
107
+	 * @access    public
108
+	 * @return    void
109
+	 * @throws EE_Error
110
+	 */
111
+	public static function set_hooks_admin()
112
+	{
113
+		EED_Single_Page_Checkout::set_definitions();
114
+		if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
115
+			return;
116
+		}
117
+		// going to start an output buffer in case anything gets accidentally output
118
+		// that might disrupt our JSON response
119
+		ob_start();
120
+		EED_Single_Page_Checkout::load_request_handler();
121
+		EED_Single_Page_Checkout::load_reg_steps();
122
+		// set ajax hooks
123
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
124
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
125
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
126
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
127
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
128
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 *    process ajax request
135
+	 *
136
+	 * @param string $ajax_action
137
+	 * @throws EE_Error
138
+	 */
139
+	public static function process_ajax_request($ajax_action)
140
+	{
141
+		EE_Registry::instance()->REQ->set('action', $ajax_action);
142
+		EED_Single_Page_Checkout::instance()->_initialize();
143
+	}
144
+
145
+
146
+
147
+	/**
148
+	 *    ajax display registration step
149
+	 *
150
+	 * @throws EE_Error
151
+	 */
152
+	public static function display_reg_step()
153
+	{
154
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 *    ajax process registration step
161
+	 *
162
+	 * @throws EE_Error
163
+	 */
164
+	public static function process_reg_step()
165
+	{
166
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
167
+	}
168
+
169
+
170
+
171
+	/**
172
+	 *    ajax process registration step
173
+	 *
174
+	 * @throws EE_Error
175
+	 */
176
+	public static function update_reg_step()
177
+	{
178
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
179
+	}
180
+
181
+
182
+
183
+	/**
184
+	 *   update_checkout
185
+	 *
186
+	 * @access public
187
+	 * @return void
188
+	 * @throws EE_Error
189
+	 */
190
+	public static function update_checkout()
191
+	{
192
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
193
+	}
194
+
195
+
196
+
197
+	/**
198
+	 *    load_request_handler
199
+	 *
200
+	 * @access    public
201
+	 * @return    void
202
+	 */
203
+	public static function load_request_handler()
204
+	{
205
+		// load core Request_Handler class
206
+		if (EE_Registry::instance()->REQ !== null) {
207
+			EE_Registry::instance()->load_core('Request_Handler');
208
+		}
209
+	}
210
+
211
+
212
+
213
+	/**
214
+	 *    set_definitions
215
+	 *
216
+	 * @access    public
217
+	 * @return    void
218
+	 * @throws EE_Error
219
+	 */
220
+	public static function set_definitions()
221
+	{
222
+		if(defined('SPCO_BASE_PATH')) {
223
+			return;
224
+		}
225
+		define(
226
+			'SPCO_BASE_PATH',
227
+			rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
228
+		);
229
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
230
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
231
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
232
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
233
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
234
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
235
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
236
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
237
+	}
238
+
239
+
240
+
241
+	/**
242
+	 * load_reg_steps
243
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
244
+	 *
245
+	 * @access    private
246
+	 * @throws EE_Error
247
+	 */
248
+	public static function load_reg_steps()
249
+	{
250
+		static $reg_steps_loaded = false;
251
+		if ($reg_steps_loaded) {
252
+			return;
253
+		}
254
+		// filter list of reg_steps
255
+		$reg_steps_to_load = (array)apply_filters(
256
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
257
+			EED_Single_Page_Checkout::get_reg_steps()
258
+		);
259
+		// sort by key (order)
260
+		ksort($reg_steps_to_load);
261
+		// loop through folders
262
+		foreach ($reg_steps_to_load as $order => $reg_step) {
263
+			// we need a
264
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
265
+				// copy over to the reg_steps_array
266
+				EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
267
+				// register custom key route for each reg step
268
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
269
+				EE_Config::register_route(
270
+					$reg_step['slug'],
271
+					'EED_Single_Page_Checkout',
272
+					'run',
273
+					'step'
274
+				);
275
+				// add AJAX or other hooks
276
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
277
+					// setup autoloaders if necessary
278
+					if ( ! class_exists($reg_step['class_name'])) {
279
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
280
+							$reg_step['file_path'],
281
+							true
282
+						);
283
+					}
284
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
285
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
286
+					}
287
+				}
288
+			}
289
+		}
290
+		$reg_steps_loaded = true;
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 *    get_reg_steps
297
+	 *
298
+	 * @access    public
299
+	 * @return    array
300
+	 */
301
+	public static function get_reg_steps()
302
+	{
303
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
304
+		if (empty($reg_steps)) {
305
+			$reg_steps = array(
306
+				10  => array(
307
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
308
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
309
+					'slug'       => 'attendee_information',
310
+					'has_hooks'  => false,
311
+				),
312
+				30  => array(
313
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
314
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
315
+					'slug'       => 'payment_options',
316
+					'has_hooks'  => true,
317
+				),
318
+				999 => array(
319
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
320
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
321
+					'slug'       => 'finalize_registration',
322
+					'has_hooks'  => false,
323
+				),
324
+			);
325
+		}
326
+		return $reg_steps;
327
+	}
328
+
329
+
330
+
331
+	/**
332
+	 *    registration_checkout_for_admin
333
+	 *
334
+	 * @access    public
335
+	 * @return    string
336
+	 * @throws EE_Error
337
+	 */
338
+	public static function registration_checkout_for_admin()
339
+	{
340
+		EED_Single_Page_Checkout::load_request_handler();
341
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
342
+		EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
343
+		EE_Registry::instance()->REQ->set('process_form_submission', false);
344
+		EED_Single_Page_Checkout::instance()->_initialize();
345
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
346
+		return EE_Registry::instance()->REQ->get_output();
347
+	}
348
+
349
+
350
+
351
+	/**
352
+	 * process_registration_from_admin
353
+	 *
354
+	 * @access public
355
+	 * @return \EE_Transaction
356
+	 * @throws EE_Error
357
+	 */
358
+	public static function process_registration_from_admin()
359
+	{
360
+		EED_Single_Page_Checkout::load_request_handler();
361
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
362
+		EE_Registry::instance()->REQ->set('action', 'process_reg_step');
363
+		EE_Registry::instance()->REQ->set('process_form_submission', true);
364
+		EED_Single_Page_Checkout::instance()->_initialize();
365
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
366
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
367
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
368
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
369
+				if ($final_reg_step->process_reg_step()) {
370
+					$final_reg_step->set_completed();
371
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
372
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
373
+				}
374
+			}
375
+		}
376
+		return null;
377
+	}
378
+
379
+
380
+
381
+	/**
382
+	 *    run
383
+	 *
384
+	 * @access    public
385
+	 * @param WP_Query $WP_Query
386
+	 * @return    void
387
+	 * @throws EE_Error
388
+	 */
389
+	public function run($WP_Query)
390
+	{
391
+		if (
392
+			$WP_Query instanceof WP_Query
393
+			&& $WP_Query->is_main_query()
394
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
395
+			&& $this->_is_reg_checkout()
396
+		) {
397
+			$this->_initialize();
398
+		}
399
+	}
400
+
401
+
402
+
403
+	/**
404
+	 * determines whether current url matches reg page url
405
+	 *
406
+	 * @return bool
407
+	 */
408
+	protected function _is_reg_checkout()
409
+	{
410
+		// get current permalink for reg page without any extra query args
411
+		$reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
412
+		// get request URI for current request, but without the scheme or host
413
+		$current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
414
+		$current_request_uri = html_entity_decode($current_request_uri);
415
+		// get array of query args from the current request URI
416
+		$query_args = \EEH_URL::get_query_string($current_request_uri);
417
+		// grab page id if it is set
418
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
419
+		// and remove the page id from the query args (we will re-add it later)
420
+		unset($query_args['page_id']);
421
+		// now strip all query args from current request URI
422
+		$current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
423
+		// and re-add the page id if it was set
424
+		if ($page_id) {
425
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
426
+		}
427
+		// remove slashes and ?
428
+		$current_request_uri = trim($current_request_uri, '?/');
429
+		// is current request URI part of the known full reg page URL ?
430
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * @param WP_Query $wp_query
437
+	 * @return    void
438
+	 * @throws EE_Error
439
+	 */
440
+	public static function init($wp_query)
441
+	{
442
+		EED_Single_Page_Checkout::instance()->run($wp_query);
443
+	}
444
+
445
+
446
+
447
+	/**
448
+	 *    _initialize - initial module setup
449
+	 *
450
+	 * @access    private
451
+	 * @throws EE_Error
452
+	 * @return    void
453
+	 */
454
+	private function _initialize()
455
+	{
456
+		// ensure SPCO doesn't run twice
457
+		if (EED_Single_Page_Checkout::$_initialized) {
458
+			return;
459
+		}
460
+		try {
461
+			EED_Single_Page_Checkout::load_reg_steps();
462
+			$this->_verify_session();
463
+			// setup the EE_Checkout object
464
+			$this->checkout = $this->_initialize_checkout();
465
+			// filter checkout
466
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
467
+			// get the $_GET
468
+			$this->_get_request_vars();
469
+			if ($this->_block_bots()) {
470
+				return;
471
+			}
472
+			// filter continue_reg
473
+			$this->checkout->continue_reg = apply_filters(
474
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
475
+				true,
476
+				$this->checkout
477
+			);
478
+			// load the reg steps array
479
+			if ( ! $this->_load_and_instantiate_reg_steps()) {
480
+				EED_Single_Page_Checkout::$_initialized = true;
481
+				return;
482
+			}
483
+			// set the current step
484
+			$this->checkout->set_current_step($this->checkout->step);
485
+			// and the next step
486
+			$this->checkout->set_next_step();
487
+			// verify that everything has been setup correctly
488
+			if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
489
+				EED_Single_Page_Checkout::$_initialized = true;
490
+				return;
491
+			}
492
+			// lock the transaction
493
+			$this->checkout->transaction->lock();
494
+			// make sure all of our cached objects are added to their respective model entity mappers
495
+			$this->checkout->refresh_all_entities();
496
+			// set amount owing
497
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
498
+			// initialize each reg step, which gives them the chance to potentially alter the process
499
+			$this->_initialize_reg_steps();
500
+			// DEBUG LOG
501
+			//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
502
+			// get reg form
503
+			if( ! $this->_check_form_submission()) {
504
+				EED_Single_Page_Checkout::$_initialized = true;
505
+				return;
506
+			}
507
+			// checkout the action!!!
508
+			$this->_process_form_action();
509
+			// add some style and make it dance
510
+			$this->add_styles_and_scripts();
511
+			// kk... SPCO has successfully run
512
+			EED_Single_Page_Checkout::$_initialized = true;
513
+			// set no cache headers and constants
514
+			EE_System::do_not_cache();
515
+			// add anchor
516
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
517
+			// remove transaction lock
518
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
519
+		} catch (Exception $e) {
520
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
521
+		}
522
+	}
523
+
524
+
525
+
526
+	/**
527
+	 *    _verify_session
528
+	 * checks that the session is valid and not expired
529
+	 *
530
+	 * @access    private
531
+	 * @throws EE_Error
532
+	 */
533
+	private function _verify_session()
534
+	{
535
+		if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
536
+			throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso'));
537
+		}
538
+		$clear_session_requested = filter_var(
539
+			EE_Registry::instance()->REQ->get('clear_session', false),
540
+			FILTER_VALIDATE_BOOLEAN
541
+		);
542
+		// is session still valid ?
543
+		if ($clear_session_requested
544
+			|| ( EE_Registry::instance()->SSN->expired()
545
+			  && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
546
+			)
547
+		) {
548
+			$this->checkout = new EE_Checkout();
549
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
550
+			// EE_Registry::instance()->SSN->reset_cart();
551
+			// EE_Registry::instance()->SSN->reset_checkout();
552
+			// EE_Registry::instance()->SSN->reset_transaction();
553
+			if (! $clear_session_requested) {
554
+				EE_Error::add_attention(
555
+					EE_Registry::$i18n_js_strings['registration_expiration_notice'],
556
+					__FILE__, __FUNCTION__, __LINE__
557
+				);
558
+			}
559
+			// EE_Registry::instance()->SSN->reset_expired();
560
+		}
561
+	}
562
+
563
+
564
+
565
+	/**
566
+	 *    _initialize_checkout
567
+	 * loads and instantiates EE_Checkout
568
+	 *
569
+	 * @access    private
570
+	 * @throws EE_Error
571
+	 * @return EE_Checkout
572
+	 */
573
+	private function _initialize_checkout()
574
+	{
575
+		// look in session for existing checkout
576
+		/** @type EE_Checkout $checkout */
577
+		$checkout = EE_Registry::instance()->SSN->checkout();
578
+		// verify
579
+		if ( ! $checkout instanceof EE_Checkout) {
580
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
581
+			$checkout = EE_Registry::instance()->load_file(
582
+				SPCO_INC_PATH,
583
+				'EE_Checkout',
584
+				'class', array(),
585
+				false
586
+			);
587
+		} else {
588
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
589
+				$this->unlock_transaction();
590
+				wp_safe_redirect($checkout->redirect_url);
591
+				exit();
592
+			}
593
+		}
594
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
595
+		// verify again
596
+		if ( ! $checkout instanceof EE_Checkout) {
597
+			throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso'));
598
+		}
599
+		// reset anything that needs a clean slate for each request
600
+		$checkout->reset_for_current_request();
601
+		return $checkout;
602
+	}
603
+
604
+
605
+
606
+	/**
607
+	 *    _get_request_vars
608
+	 *
609
+	 * @access    private
610
+	 * @return    void
611
+	 * @throws EE_Error
612
+	 */
613
+	private function _get_request_vars()
614
+	{
615
+		// load classes
616
+		EED_Single_Page_Checkout::load_request_handler();
617
+		//make sure this request is marked as belonging to EE
618
+		EE_Registry::instance()->REQ->set_espresso_page(true);
619
+		// which step is being requested ?
620
+		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
621
+		// which step is being edited ?
622
+		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
623
+		// and what we're doing on the current step
624
+		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
625
+		// timestamp
626
+		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
627
+		// returning to edit ?
628
+		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
629
+		// add reg url link to registration query params
630
+		if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
631
+			$this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
632
+		}
633
+		// or some other kind of revisit ?
634
+		$this->checkout->revisit = filter_var(
635
+			EE_Registry::instance()->REQ->get('revisit', false),
636
+			FILTER_VALIDATE_BOOLEAN
637
+		);
638
+		// and whether or not to generate a reg form for this request
639
+		$this->checkout->generate_reg_form = filter_var(
640
+			EE_Registry::instance()->REQ->get('generate_reg_form', true),
641
+			FILTER_VALIDATE_BOOLEAN
642
+		);
643
+		// and whether or not to process a reg form submission for this request
644
+		$this->checkout->process_form_submission = filter_var(
645
+			EE_Registry::instance()->REQ->get(
646
+				'process_form_submission',
647
+				$this->checkout->action === 'process_reg_step'
648
+			),
649
+			FILTER_VALIDATE_BOOLEAN
650
+		);
651
+		$this->checkout->process_form_submission = filter_var(
652
+			$this->checkout->action !== 'display_spco_reg_step'
653
+				? $this->checkout->process_form_submission
654
+				: false,
655
+			FILTER_VALIDATE_BOOLEAN
656
+		);
657
+		// $this->_display_request_vars();
658
+	}
659
+
660
+
661
+
662
+	/**
663
+	 *  _display_request_vars
664
+	 *
665
+	 * @access    protected
666
+	 * @return    void
667
+	 */
668
+	protected function _display_request_vars()
669
+	{
670
+		if ( ! WP_DEBUG) {
671
+			return;
672
+		}
673
+		EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
674
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
675
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
676
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
677
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
678
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
679
+		EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__);
680
+		EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__);
681
+	}
682
+
683
+
684
+
685
+	/**
686
+	 * _block_bots
687
+	 * checks that the incoming request has either of the following set:
688
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
689
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
690
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
691
+	 * then where you coming from man?
692
+	 *
693
+	 * @return boolean
694
+	 */
695
+	private function _block_bots()
696
+	{
697
+		$invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
698
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
699
+			return true;
700
+		}
701
+		return false;
702
+	}
703
+
704
+
705
+
706
+	/**
707
+	 *    _get_first_step
708
+	 *  gets slug for first step in $_reg_steps_array
709
+	 *
710
+	 * @access    private
711
+	 * @throws EE_Error
712
+	 * @return    string
713
+	 */
714
+	private function _get_first_step()
715
+	{
716
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
717
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
718
+	}
719
+
720
+
721
+	/**
722
+	 * instantiates each reg step based on the loaded reg_steps array
723
+	 *
724
+	 * @return    bool
725
+	 * @throws EE_Error
726
+	 * @throws InvalidArgumentException
727
+	 * @throws InvalidDataTypeException
728
+	 * @throws InvalidInterfaceException
729
+	 */
730
+	private function _load_and_instantiate_reg_steps()
731
+	{
732
+		do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
733
+		// have reg_steps already been instantiated ?
734
+		if (
735
+			empty($this->checkout->reg_steps)
736
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
737
+		) {
738
+			// if not, then loop through raw reg steps array
739
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
740
+				if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
741
+					return false;
742
+				}
743
+			}
744
+			if(isset($this->checkout->reg_steps['registration_confirmation'])){
745
+				// skip the registration_confirmation page ?
746
+				if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
747
+					// just remove it from the reg steps array
748
+					$this->checkout->remove_reg_step('registration_confirmation', false);
749
+				} elseif (EE_Registry::instance()->CFG->registration->reg_confirmation_last
750
+				) {
751
+					// set the order to something big like 100
752
+					$this->checkout->set_reg_step_order('registration_confirmation', 100);
753
+				}
754
+			}
755
+			// filter the array for good luck
756
+			$this->checkout->reg_steps = apply_filters(
757
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
758
+				$this->checkout->reg_steps
759
+			);
760
+			// finally re-sort based on the reg step class order properties
761
+			$this->checkout->sort_reg_steps();
762
+		} else {
763
+			foreach ($this->checkout->reg_steps as $reg_step) {
764
+				// set all current step stati to FALSE
765
+				$reg_step->set_is_current_step(false);
766
+			}
767
+		}
768
+		if (empty($this->checkout->reg_steps)) {
769
+			EE_Error::add_error(
770
+				__('No Reg Steps were loaded..', 'event_espresso'),
771
+				__FILE__, __FUNCTION__, __LINE__
772
+			);
773
+			return false;
774
+		}
775
+		// make reg step details available to JS
776
+		$this->checkout->set_reg_step_JSON_info();
777
+		return true;
778
+	}
779
+
780
+
781
+
782
+	/**
783
+	 *     _load_and_instantiate_reg_step
784
+	 *
785
+	 * @access    private
786
+	 * @param array $reg_step
787
+	 * @param int   $order
788
+	 * @return bool
789
+	 */
790
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
791
+	{
792
+		// we need a file_path, class_name, and slug to add a reg step
793
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
794
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
795
+			if (
796
+				$this->checkout->reg_url_link
797
+				&& $this->checkout->step !== $reg_step['slug']
798
+				&& $reg_step['slug'] !== 'finalize_registration'
799
+				// normally at this point we would NOT load the reg step, but this filter can change that
800
+				&& apply_filters(
801
+					'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
802
+					true,
803
+					$reg_step,
804
+					$this->checkout
805
+				)
806
+			) {
807
+				return true;
808
+			}
809
+			// instantiate step class using file path and class name
810
+			$reg_step_obj = EE_Registry::instance()->load_file(
811
+				$reg_step['file_path'],
812
+				$reg_step['class_name'],
813
+				'class',
814
+				$this->checkout,
815
+				false
816
+			);
817
+			// did we gets the goods ?
818
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
819
+				// set reg step order based on config
820
+				$reg_step_obj->set_order($order);
821
+				// add instantiated reg step object to the master reg steps array
822
+				$this->checkout->add_reg_step($reg_step_obj);
823
+			} else {
824
+				EE_Error::add_error(
825
+					__('The current step could not be set.', 'event_espresso'),
826
+					__FILE__, __FUNCTION__, __LINE__
827
+				);
828
+				return false;
829
+			}
830
+		} else {
831
+			if (WP_DEBUG) {
832
+				EE_Error::add_error(
833
+					sprintf(
834
+						__(
835
+							'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',
836
+							'event_espresso'
837
+						),
838
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
839
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
840
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
841
+						'<ul>',
842
+						'<li>',
843
+						'</li>',
844
+						'</ul>'
845
+					),
846
+					__FILE__, __FUNCTION__, __LINE__
847
+				);
848
+			}
849
+			return false;
850
+		}
851
+		return true;
852
+	}
853
+
854
+
855
+	/**
856
+	 * _verify_transaction_and_get_registrations
857
+	 *
858
+	 * @access private
859
+	 * @return bool
860
+	 * @throws InvalidDataTypeException
861
+	 * @throws InvalidEntityException
862
+	 * @throws EE_Error
863
+	 */
864
+	private function _verify_transaction_and_get_registrations()
865
+	{
866
+		// was there already a valid transaction in the checkout from the session ?
867
+		if ( ! $this->checkout->transaction instanceof EE_Transaction) {
868
+			// get transaction from db or session
869
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
870
+				? $this->_get_transaction_and_cart_for_previous_visit()
871
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
872
+			if ( ! $this->checkout->transaction instanceof EE_Transaction) {
873
+				EE_Error::add_error(
874
+					__('Your Registration and Transaction information could not be retrieved from the db.',
875
+						'event_espresso'),
876
+					__FILE__, __FUNCTION__, __LINE__
877
+				);
878
+				$this->checkout->transaction = EE_Transaction::new_instance();
879
+				// add some style and make it dance
880
+				$this->add_styles_and_scripts();
881
+				EED_Single_Page_Checkout::$_initialized = true;
882
+				return false;
883
+			}
884
+			// and the registrations for the transaction
885
+			$this->_get_registrations($this->checkout->transaction);
886
+		}
887
+		return true;
888
+	}
889
+
890
+
891
+
892
+	/**
893
+	 * _get_transaction_and_cart_for_previous_visit
894
+	 *
895
+	 * @access private
896
+	 * @return mixed EE_Transaction|NULL
897
+	 */
898
+	private function _get_transaction_and_cart_for_previous_visit()
899
+	{
900
+		/** @var $TXN_model EEM_Transaction */
901
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
902
+		// because the reg_url_link is present in the request,
903
+		// this is a return visit to SPCO, so we'll get the transaction data from the db
904
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
905
+		// verify transaction
906
+		if ($transaction instanceof EE_Transaction) {
907
+			// and get the cart that was used for that transaction
908
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
909
+			return $transaction;
910
+		}
911
+		EE_Error::add_error(
912
+			__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
913
+			__FILE__, __FUNCTION__, __LINE__
914
+		);
915
+		return null;
916
+
917
+	}
918
+
919
+
920
+
921
+	/**
922
+	 * _get_cart_for_transaction
923
+	 *
924
+	 * @access private
925
+	 * @param EE_Transaction $transaction
926
+	 * @return EE_Cart
927
+	 */
928
+	private function _get_cart_for_transaction($transaction)
929
+	{
930
+		return $this->checkout->get_cart_for_transaction($transaction);
931
+	}
932
+
933
+
934
+
935
+	/**
936
+	 * get_cart_for_transaction
937
+	 *
938
+	 * @access public
939
+	 * @param EE_Transaction $transaction
940
+	 * @return EE_Cart
941
+	 */
942
+	public function get_cart_for_transaction(EE_Transaction $transaction)
943
+	{
944
+		return $this->checkout->get_cart_for_transaction($transaction);
945
+	}
946
+
947
+
948
+
949
+	/**
950
+	 * _get_transaction_and_cart_for_current_session
951
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
952
+	 *
953
+	 * @access private
954
+	 * @return EE_Transaction
955
+	 * @throws EE_Error
956
+	 */
957
+	private function _get_cart_for_current_session_and_setup_new_transaction()
958
+	{
959
+		//  if there's no transaction, then this is the FIRST visit to SPCO
960
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
961
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
962
+		// and then create a new transaction
963
+		$transaction = $this->_initialize_transaction();
964
+		// verify transaction
965
+		if ($transaction instanceof EE_Transaction) {
966
+			// save it so that we have an ID for other objects to use
967
+			$transaction->save();
968
+			// and save TXN data to the cart
969
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
970
+		} else {
971
+			EE_Error::add_error(
972
+				__('A Valid Transaction could not be initialized.', 'event_espresso'),
973
+				__FILE__, __FUNCTION__, __LINE__
974
+			);
975
+		}
976
+		return $transaction;
977
+	}
978
+
979
+
980
+
981
+	/**
982
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
983
+	 *
984
+	 * @access private
985
+	 * @return mixed EE_Transaction|NULL
986
+	 */
987
+	private function _initialize_transaction()
988
+	{
989
+		try {
990
+			// ensure cart totals have been calculated
991
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
992
+			// grab the cart grand total
993
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
994
+			// create new TXN
995
+			$transaction = EE_Transaction::new_instance(
996
+				array(
997
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
998
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
999
+					'TXN_paid'      => 0,
1000
+					'STS_ID'        => EEM_Transaction::failed_status_code,
1001
+				)
1002
+			);
1003
+			// save it so that we have an ID for other objects to use
1004
+			$transaction->save();
1005
+			// set cron job for following up on TXNs after their session has expired
1006
+			EE_Cron_Tasks::schedule_expired_transaction_check(
1007
+				EE_Registry::instance()->SSN->expiration() + 1,
1008
+				$transaction->ID()
1009
+			);
1010
+			return $transaction;
1011
+		} catch (Exception $e) {
1012
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1013
+		}
1014
+		return null;
1015
+	}
1016
+
1017
+
1018
+	/**
1019
+	 * _get_registrations
1020
+	 *
1021
+	 * @access private
1022
+	 * @param EE_Transaction $transaction
1023
+	 * @return void
1024
+	 * @throws InvalidDataTypeException
1025
+	 * @throws InvalidEntityException
1026
+	 * @throws EE_Error
1027
+	 */
1028
+	private function _get_registrations(EE_Transaction $transaction)
1029
+	{
1030
+		// first step: grab the registrants  { : o
1031
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1032
+		$this->checkout->total_ticket_count = count($registrations);
1033
+		// verify registrations have been set
1034
+		if (empty($registrations)) {
1035
+			// if no cached registrations, then check the db
1036
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1037
+			// still nothing ? well as long as this isn't a revisit
1038
+			if (empty($registrations) && ! $this->checkout->revisit) {
1039
+				// generate new registrations from scratch
1040
+				$registrations = $this->_initialize_registrations($transaction);
1041
+			}
1042
+		}
1043
+		// sort by their original registration order
1044
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1045
+		// then loop thru the array
1046
+		foreach ($registrations as $registration) {
1047
+			// verify each registration
1048
+			if ($registration instanceof EE_Registration) {
1049
+				// we display all attendee info for the primary registrant
1050
+				if ($this->checkout->reg_url_link === $registration->reg_url_link()
1051
+					&& $registration->is_primary_registrant()
1052
+				) {
1053
+					$this->checkout->primary_revisit = true;
1054
+					break;
1055
+				}
1056
+				if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1057
+					// but hide info if it doesn't belong to you
1058
+					$transaction->clear_cache('Registration', $registration->ID());
1059
+					$this->checkout->total_ticket_count--;
1060
+				}
1061
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1062
+			}
1063
+		}
1064
+	}
1065
+
1066
+
1067
+	/**
1068
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1069
+	 *
1070
+	 * @access private
1071
+	 * @param EE_Transaction $transaction
1072
+	 * @return    array
1073
+	 * @throws InvalidDataTypeException
1074
+	 * @throws InvalidEntityException
1075
+	 * @throws EE_Error
1076
+	 */
1077
+	private function _initialize_registrations(EE_Transaction $transaction)
1078
+	{
1079
+		$att_nmbr = 0;
1080
+		$registrations = array();
1081
+		if ($transaction instanceof EE_Transaction) {
1082
+			/** @type EE_Registration_Processor $registration_processor */
1083
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1084
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1085
+			// now let's add the cart items to the $transaction
1086
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1087
+				//do the following for each ticket of this type they selected
1088
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1089
+					$att_nmbr++;
1090
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1091
+					$CreateRegistrationCommand = EE_Registry::instance()->create(
1092
+						'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1093
+						array(
1094
+							$transaction,
1095
+							$line_item,
1096
+							$att_nmbr,
1097
+							$this->checkout->total_ticket_count,
1098
+						)
1099
+					);
1100
+					// override capabilities for frontend registrations
1101
+					if ( ! is_admin()) {
1102
+						$CreateRegistrationCommand->setCapCheck(
1103
+							new PublicCapabilities('', 'create_new_registration')
1104
+						);
1105
+					}
1106
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1107
+					if ( ! $registration instanceof EE_Registration) {
1108
+						throw new InvalidEntityException($registration, 'EE_Registration');
1109
+					}
1110
+					$registrations[ $registration->ID() ] = $registration;
1111
+				}
1112
+			}
1113
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1114
+		}
1115
+		return $registrations;
1116
+	}
1117
+
1118
+
1119
+
1120
+	/**
1121
+	 * sorts registrations by REG_count
1122
+	 *
1123
+	 * @access public
1124
+	 * @param EE_Registration $reg_A
1125
+	 * @param EE_Registration $reg_B
1126
+	 * @return int
1127
+	 */
1128
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1129
+	{
1130
+		// this shouldn't ever happen within the same TXN, but oh well
1131
+		if ($reg_A->count() === $reg_B->count()) {
1132
+			return 0;
1133
+		}
1134
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1135
+	}
1136
+
1137
+
1138
+
1139
+	/**
1140
+	 *    _final_verifications
1141
+	 * just makes sure that everything is set up correctly before proceeding
1142
+	 *
1143
+	 * @access    private
1144
+	 * @return    bool
1145
+	 * @throws EE_Error
1146
+	 */
1147
+	private function _final_verifications()
1148
+	{
1149
+		// filter checkout
1150
+		$this->checkout = apply_filters(
1151
+			'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1152
+			$this->checkout
1153
+		);
1154
+		//verify that current step is still set correctly
1155
+		if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1156
+			EE_Error::add_error(
1157
+				__('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'),
1158
+				__FILE__,
1159
+				__FUNCTION__,
1160
+				__LINE__
1161
+			);
1162
+			return false;
1163
+		}
1164
+		// if returning to SPCO, then verify that primary registrant is set
1165
+		if ( ! empty($this->checkout->reg_url_link)) {
1166
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1167
+			if ( ! $valid_registrant instanceof EE_Registration) {
1168
+				EE_Error::add_error(
1169
+					__('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'),
1170
+					__FILE__,
1171
+					__FUNCTION__,
1172
+					__LINE__
1173
+				);
1174
+				return false;
1175
+			}
1176
+			$valid_registrant = null;
1177
+			foreach (
1178
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration
1179
+			) {
1180
+				if (
1181
+					$registration instanceof EE_Registration
1182
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1183
+				) {
1184
+					$valid_registrant = $registration;
1185
+				}
1186
+			}
1187
+			if ( ! $valid_registrant instanceof EE_Registration) {
1188
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1189
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1190
+					// clear the session, mark the checkout as unverified, and try again
1191
+					EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1192
+					EED_Single_Page_Checkout::$_initialized = false;
1193
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1194
+					$this->_initialize();
1195
+					EE_Error::reset_notices();
1196
+					return false;
1197
+				}
1198
+				EE_Error::add_error(
1199
+					__(
1200
+						'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.',
1201
+						'event_espresso'
1202
+					),
1203
+					__FILE__,
1204
+					__FUNCTION__,
1205
+					__LINE__
1206
+				);
1207
+				return false;
1208
+			}
1209
+		}
1210
+		// now that things have been kinda sufficiently verified,
1211
+		// let's add the checkout to the session so that it's available to other systems
1212
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1213
+		return true;
1214
+	}
1215
+
1216
+
1217
+
1218
+	/**
1219
+	 *    _initialize_reg_steps
1220
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1221
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1222
+	 *
1223
+	 * @access    private
1224
+	 * @param bool $reinitializing
1225
+	 * @throws EE_Error
1226
+	 */
1227
+	private function _initialize_reg_steps($reinitializing = false)
1228
+	{
1229
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1230
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1231
+		foreach ($this->checkout->reg_steps as $reg_step) {
1232
+			if ( ! $reg_step->initialize_reg_step()) {
1233
+				// if not initialized then maybe this step is being removed...
1234
+				if ( ! $reinitializing && $reg_step->is_current_step()) {
1235
+					// if it was the current step, then we need to start over here
1236
+					$this->_initialize_reg_steps(true);
1237
+					return;
1238
+				}
1239
+				continue;
1240
+			}
1241
+			// add css and JS for current step
1242
+			$reg_step->enqueue_styles_and_scripts();
1243
+			// i18n
1244
+			$reg_step->translate_js_strings();
1245
+			if ($reg_step->is_current_step()) {
1246
+				// the text that appears on the reg step form submit button
1247
+				$reg_step->set_submit_button_text();
1248
+			}
1249
+		}
1250
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1251
+		do_action(
1252
+			"AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1253
+			$this->checkout->current_step
1254
+		);
1255
+	}
1256
+
1257
+
1258
+
1259
+	/**
1260
+	 * _check_form_submission
1261
+	 *
1262
+	 * @access private
1263
+	 * @return boolean
1264
+	 */
1265
+	private function _check_form_submission()
1266
+	{
1267
+		//does this request require the reg form to be generated ?
1268
+		if ($this->checkout->generate_reg_form) {
1269
+			// ever heard that song by Blue Rodeo ?
1270
+			try {
1271
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1272
+				// if not displaying a form, then check for form submission
1273
+				if (
1274
+					$this->checkout->process_form_submission
1275
+					&& $this->checkout->current_step->reg_form->was_submitted()
1276
+				) {
1277
+					// clear out any old data in case this step is being run again
1278
+					$this->checkout->current_step->set_valid_data(array());
1279
+					// capture submitted form data
1280
+					$this->checkout->current_step->reg_form->receive_form_submission(
1281
+						apply_filters(
1282
+							'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1283
+							EE_Registry::instance()->REQ->params(),
1284
+							$this->checkout
1285
+						)
1286
+					);
1287
+					// validate submitted form data
1288
+					if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1289
+						// thou shall not pass !!!
1290
+						$this->checkout->continue_reg = false;
1291
+						// any form validation errors?
1292
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1293
+							EE_Error::add_error(
1294
+								$this->checkout->current_step->reg_form->submission_error_message(),
1295
+								__FILE__, __FUNCTION__, __LINE__
1296
+							);
1297
+						}
1298
+						// well not really... what will happen is
1299
+						// we'll just get redirected back to redo the current step
1300
+						$this->go_to_next_step();
1301
+						return false;
1302
+					}
1303
+				}
1304
+			} catch (EE_Error $e) {
1305
+				$e->get_error();
1306
+			}
1307
+		}
1308
+		return true;
1309
+	}
1310
+
1311
+
1312
+
1313
+	/**
1314
+	 * _process_action
1315
+	 *
1316
+	 * @access private
1317
+	 * @return void
1318
+	 * @throws EE_Error
1319
+	 */
1320
+	private function _process_form_action()
1321
+	{
1322
+		// what cha wanna do?
1323
+		switch ($this->checkout->action) {
1324
+			// AJAX next step reg form
1325
+			case 'display_spco_reg_step' :
1326
+				$this->checkout->redirect = false;
1327
+				if (EE_Registry::instance()->REQ->ajax) {
1328
+					$this->checkout->json_response->set_reg_step_html(
1329
+						$this->checkout->current_step->display_reg_form()
1330
+					);
1331
+				}
1332
+				break;
1333
+			default :
1334
+				// meh... do one of those other steps first
1335
+				if (
1336
+					! empty($this->checkout->action)
1337
+					&& is_callable(array($this->checkout->current_step, $this->checkout->action))
1338
+				) {
1339
+					// dynamically creates hook point like:
1340
+					//   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1341
+					do_action(
1342
+						"AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1343
+						$this->checkout->current_step
1344
+					);
1345
+					// call action on current step
1346
+					if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1347
+						// good registrant, you get to proceed
1348
+						if (
1349
+							$this->checkout->current_step->success_message() !== ''
1350
+							&& apply_filters(
1351
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1352
+								false
1353
+							)
1354
+						) {
1355
+							EE_Error::add_success(
1356
+								$this->checkout->current_step->success_message()
1357
+								. '<br />' . $this->checkout->next_step->_instructions()
1358
+							);
1359
+						}
1360
+						// pack it up, pack it in...
1361
+						$this->_setup_redirect();
1362
+					}
1363
+					// dynamically creates hook point like:
1364
+					//  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1365
+					do_action(
1366
+						"AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1367
+						$this->checkout->current_step
1368
+					);
1369
+				} else {
1370
+					EE_Error::add_error(
1371
+						sprintf(
1372
+							__(
1373
+								'The requested form action "%s" does not exist for the current "%s" registration step.',
1374
+								'event_espresso'
1375
+							),
1376
+							$this->checkout->action,
1377
+							$this->checkout->current_step->name()
1378
+						),
1379
+						__FILE__,
1380
+						__FUNCTION__,
1381
+						__LINE__
1382
+					);
1383
+				}
1384
+			// end default
1385
+		}
1386
+		// store our progress so far
1387
+		$this->checkout->stash_transaction_and_checkout();
1388
+		// advance to the next step! If you pass GO, collect $200
1389
+		$this->go_to_next_step();
1390
+	}
1391
+
1392
+
1393
+
1394
+	/**
1395
+	 *        add_styles_and_scripts
1396
+	 *
1397
+	 * @access        public
1398
+	 * @return        void
1399
+	 */
1400
+	public function add_styles_and_scripts()
1401
+	{
1402
+		// i18n
1403
+		$this->translate_js_strings();
1404
+		if ($this->checkout->admin_request) {
1405
+			add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1406
+		} else {
1407
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1408
+		}
1409
+	}
1410
+
1411
+
1412
+
1413
+	/**
1414
+	 *        translate_js_strings
1415
+	 *
1416
+	 * @access        public
1417
+	 * @return        void
1418
+	 */
1419
+	public function translate_js_strings()
1420
+	{
1421
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1422
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1423
+		EE_Registry::$i18n_js_strings['server_error'] = __(
1424
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1425
+			'event_espresso'
1426
+		);
1427
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = __(
1428
+			'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1429
+			'event_espresso'
1430
+		);
1431
+		EE_Registry::$i18n_js_strings['validation_error'] = __(
1432
+			'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1433
+			'event_espresso'
1434
+		);
1435
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = __(
1436
+			'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1437
+			'event_espresso'
1438
+		);
1439
+		EE_Registry::$i18n_js_strings['reg_step_error'] = __(
1440
+			'This registration step could not be completed. Please refresh the page and try again.',
1441
+			'event_espresso'
1442
+		);
1443
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = __(
1444
+			'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1445
+			'event_espresso'
1446
+		);
1447
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1448
+			__(
1449
+				'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1450
+				'event_espresso'
1451
+			),
1452
+			'<br/>',
1453
+			'<br/>'
1454
+		);
1455
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1456
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1457
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1458
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1459
+		EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso');
1460
+		EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso');
1461
+		EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso');
1462
+		EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso');
1463
+		EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso');
1464
+		EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso');
1465
+		EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso');
1466
+		EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso');
1467
+		EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso');
1468
+		EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso');
1469
+		EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso');
1470
+		EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso');
1471
+		EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso');
1472
+		EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso');
1473
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
1474
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1475
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1476
+			true
1477
+		);
1478
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1479
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1480
+		);
1481
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1482
+			'M d, Y H:i:s',
1483
+			EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1484
+		);
1485
+	}
1486
+
1487
+
1488
+
1489
+	/**
1490
+	 *    enqueue_styles_and_scripts
1491
+	 *
1492
+	 * @access        public
1493
+	 * @return        void
1494
+	 * @throws EE_Error
1495
+	 */
1496
+	public function enqueue_styles_and_scripts()
1497
+	{
1498
+		// load css
1499
+		wp_register_style(
1500
+			'single_page_checkout',
1501
+			SPCO_CSS_URL . 'single_page_checkout.css',
1502
+			array('espresso_default'),
1503
+			EVENT_ESPRESSO_VERSION
1504
+		);
1505
+		wp_enqueue_style('single_page_checkout');
1506
+		// load JS
1507
+		wp_register_script(
1508
+			'jquery_plugin',
1509
+			EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1510
+			array('jquery'),
1511
+			'1.0.1',
1512
+			true
1513
+		);
1514
+		wp_register_script(
1515
+			'jquery_countdown',
1516
+			EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1517
+			array('jquery_plugin'),
1518
+			'2.0.2',
1519
+			true
1520
+		);
1521
+		wp_register_script(
1522
+			'single_page_checkout',
1523
+			SPCO_JS_URL . 'single_page_checkout.js',
1524
+			array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1525
+			EVENT_ESPRESSO_VERSION,
1526
+			true
1527
+		);
1528
+		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1529
+			$this->checkout->registration_form->enqueue_js();
1530
+		}
1531
+		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1532
+			$this->checkout->current_step->reg_form->enqueue_js();
1533
+		}
1534
+		wp_enqueue_script('single_page_checkout');
1535
+		/**
1536
+		 * global action hook for enqueueing styles and scripts with
1537
+		 * spco calls.
1538
+		 */
1539
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1540
+		/**
1541
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1542
+		 * The hook will end up being something like:
1543
+		 *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1544
+		 */
1545
+		do_action(
1546
+			'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1547
+			$this
1548
+		);
1549
+	}
1550
+
1551
+
1552
+
1553
+	/**
1554
+	 *    display the Registration Single Page Checkout Form
1555
+	 *
1556
+	 * @access    private
1557
+	 * @return    void
1558
+	 * @throws EE_Error
1559
+	 */
1560
+	private function _display_spco_reg_form()
1561
+	{
1562
+		// if registering via the admin, just display the reg form for the current step
1563
+		if ($this->checkout->admin_request) {
1564
+			EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1565
+		} else {
1566
+			// add powered by EE msg
1567
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1568
+			$empty_cart = count(
1569
+				$this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)
1570
+			) < 1;
1571
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1572
+			$cookies_not_set_msg = '';
1573
+			if ($empty_cart) {
1574
+				$cookies_not_set_msg = apply_filters(
1575
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1576
+					sprintf(
1577
+						__(
1578
+							'%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',
1579
+							'event_espresso'
1580
+						),
1581
+						'<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1582
+						'</div>',
1583
+						'<h6 class="important-notice">',
1584
+						'</h6>',
1585
+						'<p>',
1586
+						'</p>',
1587
+						'<br />',
1588
+						'<a href="http://www.whatarecookies.com/enable.asp" target="_blank">',
1589
+						'</a>'
1590
+					)
1591
+				);
1592
+			}
1593
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1594
+				array(
1595
+					'name'            => 'single-page-checkout',
1596
+					'html_id'         => 'ee-single-page-checkout-dv',
1597
+					'layout_strategy' =>
1598
+						new EE_Template_Layout(
1599
+							array(
1600
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1601
+								'template_args'        => array(
1602
+									'empty_cart'              => $empty_cart,
1603
+									'revisit'                 => $this->checkout->revisit,
1604
+									'reg_steps'               => $this->checkout->reg_steps,
1605
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1606
+										? $this->checkout->next_step->slug()
1607
+										: '',
1608
+									'empty_msg'               => apply_filters(
1609
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1610
+										sprintf(
1611
+											__(
1612
+												'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1613
+												'event_espresso'
1614
+											),
1615
+											'<a href="'
1616
+											. get_post_type_archive_link('espresso_events')
1617
+											. '" title="',
1618
+											'">',
1619
+											'</a>'
1620
+										)
1621
+									),
1622
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1623
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1624
+									'session_expiration'      => gmdate(
1625
+										'M d, Y H:i:s',
1626
+										EE_Registry::instance()->SSN->expiration()
1627
+										+ (get_option('gmt_offset') * HOUR_IN_SECONDS)
1628
+									),
1629
+								),
1630
+							)
1631
+						),
1632
+				)
1633
+			);
1634
+			// load template and add to output sent that gets filtered into the_content()
1635
+			EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1636
+		}
1637
+	}
1638
+
1639
+
1640
+
1641
+	/**
1642
+	 *    add_extra_finalize_registration_inputs
1643
+	 *
1644
+	 * @access    public
1645
+	 * @param $next_step
1646
+	 * @internal  param string $label
1647
+	 * @return void
1648
+	 */
1649
+	public function add_extra_finalize_registration_inputs($next_step)
1650
+	{
1651
+		if ($next_step === 'finalize_registration') {
1652
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1653
+		}
1654
+	}
1655
+
1656
+
1657
+
1658
+	/**
1659
+	 *    display_registration_footer
1660
+	 *
1661
+	 * @access    public
1662
+	 * @return    string
1663
+	 */
1664
+	public static function display_registration_footer()
1665
+	{
1666
+		if (
1667
+		apply_filters(
1668
+			'FHEE__EE_Front__Controller__show_reg_footer',
1669
+			EE_Registry::instance()->CFG->admin->show_reg_footer
1670
+		)
1671
+		) {
1672
+			add_filter(
1673
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1674
+				function ($url) {
1675
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1676
+				}
1677
+			);
1678
+			echo apply_filters(
1679
+				'FHEE__EE_Front_Controller__display_registration_footer',
1680
+				\EEH_Template::powered_by_event_espresso(
1681
+					'',
1682
+					'espresso-registration-footer-dv',
1683
+					array('utm_content' => 'registration_checkout')
1684
+				)
1685
+			);
1686
+		}
1687
+		return '';
1688
+	}
1689
+
1690
+
1691
+
1692
+	/**
1693
+	 *    unlock_transaction
1694
+	 *
1695
+	 * @access    public
1696
+	 * @return    void
1697
+	 * @throws EE_Error
1698
+	 */
1699
+	public function unlock_transaction()
1700
+	{
1701
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1702
+			$this->checkout->transaction->unlock();
1703
+		}
1704
+	}
1705
+
1706
+
1707
+
1708
+	/**
1709
+	 *        _setup_redirect
1710
+	 *
1711
+	 * @access    private
1712
+	 * @return void
1713
+	 */
1714
+	private function _setup_redirect()
1715
+	{
1716
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1717
+			$this->checkout->redirect = true;
1718
+			if (empty($this->checkout->redirect_url)) {
1719
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1720
+			}
1721
+			$this->checkout->redirect_url = apply_filters(
1722
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1723
+				$this->checkout->redirect_url,
1724
+				$this->checkout
1725
+			);
1726
+		}
1727
+	}
1728
+
1729
+
1730
+
1731
+	/**
1732
+	 *   handle ajax message responses and redirects
1733
+	 *
1734
+	 * @access public
1735
+	 * @return void
1736
+	 * @throws EE_Error
1737
+	 */
1738
+	public function go_to_next_step()
1739
+	{
1740
+		if (EE_Registry::instance()->REQ->ajax) {
1741
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1742
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1743
+		}
1744
+		$this->unlock_transaction();
1745
+		// just return for these conditions
1746
+		if (
1747
+			$this->checkout->admin_request
1748
+			|| $this->checkout->action === 'redirect_form'
1749
+			|| $this->checkout->action === 'update_checkout'
1750
+		) {
1751
+			return;
1752
+		}
1753
+		// AJAX response
1754
+		$this->_handle_json_response();
1755
+		// redirect to next step or the Thank You page
1756
+		$this->_handle_html_redirects();
1757
+		// hmmm... must be something wrong, so let's just display the form again !
1758
+		$this->_display_spco_reg_form();
1759
+	}
1760
+
1761
+
1762
+
1763
+	/**
1764
+	 *   _handle_json_response
1765
+	 *
1766
+	 * @access protected
1767
+	 * @return void
1768
+	 */
1769
+	protected function _handle_json_response()
1770
+	{
1771
+		// if this is an ajax request
1772
+		if (EE_Registry::instance()->REQ->ajax) {
1773
+			// DEBUG LOG
1774
+			//$this->checkout->log(
1775
+			//	__CLASS__, __FUNCTION__, __LINE__,
1776
+			//	array(
1777
+			//		'json_response_redirect_url' => $this->checkout->json_response->redirect_url(),
1778
+			//		'redirect'                   => $this->checkout->redirect,
1779
+			//		'continue_reg'               => $this->checkout->continue_reg,
1780
+			//	)
1781
+			//);
1782
+			$this->checkout->json_response->set_registration_time_limit(
1783
+				$this->checkout->get_registration_time_limit()
1784
+			);
1785
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1786
+			// just send the ajax (
1787
+			$json_response = apply_filters(
1788
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1789
+				$this->checkout->json_response
1790
+			);
1791
+			echo $json_response;
1792
+			exit();
1793
+		}
1794
+	}
1795
+
1796
+
1797
+
1798
+	/**
1799
+	 *   _handle_redirects
1800
+	 *
1801
+	 * @access protected
1802
+	 * @return void
1803
+	 */
1804
+	protected function _handle_html_redirects()
1805
+	{
1806
+		// going somewhere ?
1807
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1808
+			// store notices in a transient
1809
+			EE_Error::get_notices(false, true, true);
1810
+			// DEBUG LOG
1811
+			//$this->checkout->log(
1812
+			//	__CLASS__, __FUNCTION__, __LINE__,
1813
+			//	array(
1814
+			//		'headers_sent' => headers_sent(),
1815
+			//		'redirect_url'     => $this->checkout->redirect_url,
1816
+			//		'headers_list'    => headers_list(),
1817
+			//	)
1818
+			//);
1819
+			wp_safe_redirect($this->checkout->redirect_url);
1820
+			exit();
1821
+		}
1822
+	}
1823
+
1824
+
1825
+
1826
+	/**
1827
+	 *   set_checkout_anchor
1828
+	 *
1829
+	 * @access public
1830
+	 * @return void
1831
+	 */
1832
+	public function set_checkout_anchor()
1833
+	{
1834
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1835
+	}
1836
+
1837
+	/**
1838
+	 *    getRegistrationExpirationNotice
1839
+	 *
1840
+	 * @since 4.9.59.p
1841
+	 * @access    public
1842
+	 * @return    string
1843
+	 */
1844
+	public static function getRegistrationExpirationNotice()
1845
+	{
1846
+		return sprintf(
1847
+			__('%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 accept our apologies for any inconvenience this may have caused.%8$s',
1848
+				'event_espresso'),
1849
+			'<h4 class="important-notice">',
1850
+			'</h4>',
1851
+			'<br />',
1852
+			'<p>',
1853
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1854
+			'">',
1855
+			'</a>',
1856
+			'</p>'
1857
+		);
1858
+	}
1859 1859
 
1860 1860
 }
1861 1861
 // End of file EED_Single_Page_Checkout.module.php
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -219,19 +219,19 @@  discard block
 block discarded – undo
219 219
      */
220 220
     public static function set_definitions()
221 221
     {
222
-        if(defined('SPCO_BASE_PATH')) {
222
+        if (defined('SPCO_BASE_PATH')) {
223 223
             return;
224 224
         }
225 225
         define(
226 226
             'SPCO_BASE_PATH',
227
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
227
+            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS
228 228
         );
229
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
230
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
231
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
232
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
233
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
234
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
229
+        define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS);
230
+        define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS);
231
+        define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS);
232
+        define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS);
233
+        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS);
234
+        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS);
235 235
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
236 236
         EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice();
237 237
     }
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
             return;
253 253
         }
254 254
         // filter list of reg_steps
255
-        $reg_steps_to_load = (array)apply_filters(
255
+        $reg_steps_to_load = (array) apply_filters(
256 256
             'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
257 257
             EED_Single_Page_Checkout::get_reg_steps()
258 258
         );
@@ -304,19 +304,19 @@  discard block
 block discarded – undo
304 304
         if (empty($reg_steps)) {
305 305
             $reg_steps = array(
306 306
                 10  => array(
307
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
307
+                    'file_path'  => SPCO_REG_STEPS_PATH.'attendee_information',
308 308
                     'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
309 309
                     'slug'       => 'attendee_information',
310 310
                     'has_hooks'  => false,
311 311
                 ),
312 312
                 30  => array(
313
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
313
+                    'file_path'  => SPCO_REG_STEPS_PATH.'payment_options',
314 314
                     'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
315 315
                     'slug'       => 'payment_options',
316 316
                     'has_hooks'  => true,
317 317
                 ),
318 318
                 999 => array(
319
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
319
+                    'file_path'  => SPCO_REG_STEPS_PATH.'finalize_registration',
320 320
                     'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
321 321
                     'slug'       => 'finalize_registration',
322 322
                     'has_hooks'  => false,
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
             // DEBUG LOG
501 501
             //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
502 502
             // get reg form
503
-            if( ! $this->_check_form_submission()) {
503
+            if ( ! $this->_check_form_submission()) {
504 504
                 EED_Single_Page_Checkout::$_initialized = true;
505 505
                 return;
506 506
             }
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
         );
542 542
         // is session still valid ?
543 543
         if ($clear_session_requested
544
-            || ( EE_Registry::instance()->SSN->expired()
544
+            || (EE_Registry::instance()->SSN->expired()
545 545
               && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
546 546
             )
547 547
         ) {
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
             // EE_Registry::instance()->SSN->reset_cart();
551 551
             // EE_Registry::instance()->SSN->reset_checkout();
552 552
             // EE_Registry::instance()->SSN->reset_transaction();
553
-            if (! $clear_session_requested) {
553
+            if ( ! $clear_session_requested) {
554 554
                 EE_Error::add_attention(
555 555
                     EE_Registry::$i18n_js_strings['registration_expiration_notice'],
556 556
                     __FILE__, __FUNCTION__, __LINE__
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
                     return false;
742 742
                 }
743 743
             }
744
-            if(isset($this->checkout->reg_steps['registration_confirmation'])){
744
+            if (isset($this->checkout->reg_steps['registration_confirmation'])) {
745 745
                 // skip the registration_confirmation page ?
746 746
                 if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
747 747
                     // just remove it from the reg steps array
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
                     if ( ! $registration instanceof EE_Registration) {
1108 1108
                         throw new InvalidEntityException($registration, 'EE_Registration');
1109 1109
                     }
1110
-                    $registrations[ $registration->ID() ] = $registration;
1110
+                    $registrations[$registration->ID()] = $registration;
1111 1111
                 }
1112 1112
             }
1113 1113
             $registration_processor->fix_reg_final_price_rounding_issue($transaction);
@@ -1354,7 +1354,7 @@  discard block
 block discarded – undo
1354 1354
                         ) {
1355 1355
                             EE_Error::add_success(
1356 1356
                                 $this->checkout->current_step->success_message()
1357
-                                . '<br />' . $this->checkout->next_step->_instructions()
1357
+                                . '<br />'.$this->checkout->next_step->_instructions()
1358 1358
                             );
1359 1359
                         }
1360 1360
                         // pack it up, pack it in...
@@ -1498,7 +1498,7 @@  discard block
 block discarded – undo
1498 1498
         // load css
1499 1499
         wp_register_style(
1500 1500
             'single_page_checkout',
1501
-            SPCO_CSS_URL . 'single_page_checkout.css',
1501
+            SPCO_CSS_URL.'single_page_checkout.css',
1502 1502
             array('espresso_default'),
1503 1503
             EVENT_ESPRESSO_VERSION
1504 1504
         );
@@ -1506,21 +1506,21 @@  discard block
 block discarded – undo
1506 1506
         // load JS
1507 1507
         wp_register_script(
1508 1508
             'jquery_plugin',
1509
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1509
+            EE_THIRD_PARTY_URL.'jquery	.plugin.min.js',
1510 1510
             array('jquery'),
1511 1511
             '1.0.1',
1512 1512
             true
1513 1513
         );
1514 1514
         wp_register_script(
1515 1515
             'jquery_countdown',
1516
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1516
+            EE_THIRD_PARTY_URL.'jquery	.countdown.min.js',
1517 1517
             array('jquery_plugin'),
1518 1518
             '2.0.2',
1519 1519
             true
1520 1520
         );
1521 1521
         wp_register_script(
1522 1522
             'single_page_checkout',
1523
-            SPCO_JS_URL . 'single_page_checkout.js',
1523
+            SPCO_JS_URL.'single_page_checkout.js',
1524 1524
             array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'),
1525 1525
             EVENT_ESPRESSO_VERSION,
1526 1526
             true
@@ -1543,7 +1543,7 @@  discard block
 block discarded – undo
1543 1543
          *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1544 1544
          */
1545 1545
         do_action(
1546
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1546
+            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(),
1547 1547
             $this
1548 1548
         );
1549 1549
     }
@@ -1597,7 +1597,7 @@  discard block
 block discarded – undo
1597 1597
                     'layout_strategy' =>
1598 1598
                         new EE_Template_Layout(
1599 1599
                             array(
1600
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1600
+                                'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php',
1601 1601
                                 'template_args'        => array(
1602 1602
                                     'empty_cart'              => $empty_cart,
1603 1603
                                     'revisit'                 => $this->checkout->revisit,
@@ -1671,7 +1671,7 @@  discard block
 block discarded – undo
1671 1671
         ) {
1672 1672
             add_filter(
1673 1673
                 'FHEE__EEH_Template__powered_by_event_espresso__url',
1674
-                function ($url) {
1674
+                function($url) {
1675 1675
                     return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1676 1676
                 }
1677 1677
             );
@@ -1850,7 +1850,7 @@  discard block
 block discarded – undo
1850 1850
             '</h4>',
1851 1851
             '<br />',
1852 1852
             '<p>',
1853
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1853
+            '<a href="'.get_post_type_archive_link('espresso_events').'" title="',
1854 1854
             '">',
1855 1855
             '</a>',
1856 1856
             '</p>'
Please login to merge, or discard this patch.
admin_pages/maintenance/templates/migration_options_from_ee4.template.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@
 block discarded – undo
68 68
     </div>
69 69
     <p><?php esc_html_e('Don\'t want to keep your old Event Espresso data? Alternatively, you can delete it all and start fresh.',
70 70
                 'event_espresso'); ?> <a
71
-                href="<?php echo $data_reset_page;?>"><?php esc_html_e('Visit the Maintenance Page and Reset Your Event Espresso Data',
71
+                href="<?php echo $data_reset_page; ?>"><?php esc_html_e('Visit the Maintenance Page and Reset Your Event Espresso Data',
72 72
                     'event_espresso'); ?></a></p>
73 73
     <?php do_action('AHEE__ee_migration_page__after_migration_options_table'); ?>
74 74
 </div>
75 75
\ No newline at end of file
Please login to merge, or discard this patch.
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -25,14 +25,14 @@  discard block
 block discarded – undo
25 25
             <tr>
26 26
                 <td>
27 27
                     <?php
28
-                    echo apply_filters(
29
-                            'FHEE__ee_migration_page__option_1_main',
30
-                            esc_html__('Before updating your database, you should first create a database backup',
31
-                                    "event_espresso"),
32
-                            $current_db_state,
33
-                            $next_db_state
34
-                    );
35
-                    ?>
28
+					echo apply_filters(
29
+							'FHEE__ee_migration_page__option_1_main',
30
+							esc_html__('Before updating your database, you should first create a database backup',
31
+									"event_espresso"),
32
+							$current_db_state,
33
+							$next_db_state
34
+					);
35
+					?>
36 36
                     <a id="display-migration-details"
37 37
                        class="display-the-hidden lt-grey-text smaller-text hide-if-no-js"
38 38
                        rel="migration-details"><?php esc_html_e('How Do I Make a Database Backup?', "event_espresso"); ?>
@@ -41,8 +41,8 @@  discard block
 block discarded – undo
41 41
                 <td>
42 42
                     <a id="db-backed-up"
43 43
                        class="toggle-migration-monitor button-primary"><?php echo apply_filters('FHEE__ee_migration_page__option_1_button_text',
44
-                                sprintf(esc_html__("My Database Is Backed Up, Continue", "event_espresso"), $current_db_state,
45
-                                        $next_db_state), $current_db_state, $next_db_state); ?></a>
44
+								sprintf(esc_html__("My Database Is Backed Up, Continue", "event_espresso"), $current_db_state,
45
+										$next_db_state), $current_db_state, $next_db_state); ?></a>
46 46
                 </td>
47 47
             </tr>
48 48
             <tr>
@@ -50,14 +50,14 @@  discard block
 block discarded – undo
50 50
                     <div id="migration-details-dv" style="display: none; padding: 1em;">
51 51
                         <p>
52 52
                             <?php
53
-                            printf(
54
-                                    esc_html__('%1$sClick Here to Learn How To Backup your Database Yourself%2$s. Or have one of our dedicated support technicians help you by %3$spurchasing a Priority Support Token.%2$s',
55
-                                            "event_espresso"),
56
-                                    '<a target="_blank" href="http://eventespresso.com/wiki/how-to-back-up-your-site/">',
57
-                                    "</a>",
58
-                                    "<a target=\"_blank\" href='http://eventespresso.com/product/priority-support-tokens/'>"
59
-                            );
60
-                            ?>
53
+							printf(
54
+									esc_html__('%1$sClick Here to Learn How To Backup your Database Yourself%2$s. Or have one of our dedicated support technicians help you by %3$spurchasing a Priority Support Token.%2$s',
55
+											"event_espresso"),
56
+									'<a target="_blank" href="http://eventespresso.com/wiki/how-to-back-up-your-site/">',
57
+									"</a>",
58
+									"<a target=\"_blank\" href='http://eventespresso.com/product/priority-support-tokens/'>"
59
+							);
60
+							?>
61 61
                         </p>
62 62
                         <?php do_action('AHEE__ee_migration_page__option_1_extra_details'); ?>
63 63
                     </div>
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
         </table>
68 68
     </div>
69 69
     <p><?php esc_html_e('Don\'t want to keep your old Event Espresso data? Alternatively, you can delete it all and start fresh.',
70
-                'event_espresso'); ?> <a
70
+				'event_espresso'); ?> <a
71 71
                 href="<?php echo $data_reset_page;?>"><?php esc_html_e('Visit the Maintenance Page and Reset Your Event Espresso Data',
72
-                    'event_espresso'); ?></a></p>
72
+					'event_espresso'); ?></a></p>
73 73
     <?php do_action('AHEE__ee_migration_page__after_migration_options_table'); ?>
74 74
 </div>
75 75
\ No newline at end of file
Please login to merge, or discard this patch.
core/EE_Cart.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
      * @access  public
261 261
      * @param EE_Ticket $ticket
262 262
      * @param int       $qty
263
-     * @return TRUE on success, FALSE on fail
263
+     * @return boolean on success, FALSE on fail
264 264
      * @throws \EE_Error
265 265
      */
266 266
     public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
      * @save   cart to session
386 386
      * @access public
387 387
      * @param bool $apply_taxes
388
-     * @return TRUE on success, FALSE on fail
388
+     * @return boolean on success, FALSE on fail
389 389
      * @throws \EE_Error
390 390
      */
391 391
     public function save_cart($apply_taxes = true)
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 
420 420
 
421 421
     /**
422
-     * @return array
422
+     * @return string[]
423 423
      */
424 424
     public function __sleep()
425 425
     {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -203,7 +203,7 @@
 block discarded – undo
203 203
      */
204 204
     public function get_tickets()
205 205
     {
206
-        if ($this->_grand_total === null ) {
206
+        if ($this->_grand_total === null) {
207 207
             return array();
208 208
         }
209 209
         return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
Please login to merge, or discard this patch.
Indentation   +416 added lines, -416 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\interfaces\ResettableInterface;
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
 do_action('AHEE_log', __FILE__, __FUNCTION__, '');
8 8
 
@@ -23,421 +23,421 @@  discard block
 block discarded – undo
23 23
 class EE_Cart implements ResettableInterface
24 24
 {
25 25
 
26
-    /**
27
-     * instance of the EE_Cart object
28
-     *
29
-     * @access    private
30
-     * @var EE_Cart $_instance
31
-     */
32
-    private static $_instance;
33
-
34
-    /**
35
-     * instance of the EE_Session object
36
-     *
37
-     * @access    protected
38
-     * @var EE_Session $_session
39
-     */
40
-    protected $_session;
41
-
42
-    /**
43
-     * The total Line item which comprises all the children line-item subtotals,
44
-     * which in turn each have their line items.
45
-     * Typically, the line item structure will look like:
46
-     * grand total
47
-     * -tickets-sub-total
48
-     * --ticket1
49
-     * --ticket2
50
-     * --...
51
-     * -taxes-sub-total
52
-     * --tax1
53
-     * --tax2
54
-     *
55
-     * @var EE_Line_Item
56
-     */
57
-    private $_grand_total;
58
-
59
-
60
-
61
-    /**
62
-     * @singleton method used to instantiate class object
63
-     * @access    public
64
-     * @param EE_Line_Item $grand_total
65
-     * @param EE_Session   $session
66
-     * @return \EE_Cart
67
-     * @throws \EE_Error
68
-     */
69
-    public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
70
-    {
71
-        if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
72
-            self::$_instance = new self($grand_total, $session);
73
-        }
74
-        // or maybe retrieve an existing one ?
75
-        if ( ! self::$_instance instanceof EE_Cart) {
76
-            // try getting the cart out of the session
77
-            $saved_cart = $session instanceof EE_Session ? $session->cart() : null;
78
-            self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
79
-            unset($saved_cart);
80
-        }
81
-        // verify that cart is ok and grand total line item exists
82
-        if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
83
-            self::$_instance = new self($grand_total, $session);
84
-        }
85
-        self::$_instance->get_grand_total();
86
-        // once everything is all said and done, save the cart to the EE_Session
87
-        add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
88
-        return self::$_instance;
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * private constructor to prevent direct creation
95
-     *
96
-     * @Constructor
97
-     * @access private
98
-     * @param EE_Line_Item $grand_total
99
-     * @param EE_Session   $session
100
-     */
101
-    private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
102
-    {
103
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
104
-        $this->set_session($session);
105
-        if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
106
-            $this->set_grand_total_line_item($grand_total);
107
-        }
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * Resets the cart completely (whereas empty_cart
114
-     *
115
-     * @param EE_Line_Item $grand_total
116
-     * @param EE_Session   $session
117
-     * @return EE_Cart
118
-     * @throws \EE_Error
119
-     */
120
-    public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
121
-    {
122
-        remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
123
-        if ($session instanceof EE_Session) {
124
-            $session->reset_cart();
125
-        }
126
-        self::$_instance = null;
127
-        return self::instance($grand_total, $session);
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @return \EE_Session
134
-     */
135
-    public function session()
136
-    {
137
-        if ( ! $this->_session instanceof EE_Session) {
138
-            $this->set_session();
139
-        }
140
-        return $this->_session;
141
-    }
142
-
143
-
144
-
145
-    /**
146
-     * @param EE_Session $session
147
-     */
148
-    public function set_session(EE_Session $session = null)
149
-    {
150
-        $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * Sets the cart to match the line item. Especially handy for loading an old cart where you
157
-     *  know the grand total line item on it
158
-     *
159
-     * @param EE_Line_Item $line_item
160
-     */
161
-    public function set_grand_total_line_item(EE_Line_Item $line_item)
162
-    {
163
-        $this->_grand_total = $line_item;
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     * get_cart_from_reg_url_link
170
-     *
171
-     * @access public
172
-     * @param EE_Transaction $transaction
173
-     * @param EE_Session     $session
174
-     * @return \EE_Cart
175
-     * @throws \EE_Error
176
-     */
177
-    public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
178
-    {
179
-        $grand_total = $transaction->total_line_item();
180
-        $grand_total->get_items();
181
-        $grand_total->tax_descendants();
182
-        return EE_Cart::instance($grand_total, $session);
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
189
-     *
190
-     * @return EE_Line_Item
191
-     * @throws \EE_Error
192
-     */
193
-    private function _create_grand_total()
194
-    {
195
-        $this->_grand_total = EEH_Line_Item::create_total_line_item();
196
-        return $this->_grand_total;
197
-    }
198
-
199
-
200
-
201
-    /**
202
-     * Gets all the line items of object type Ticket
203
-     *
204
-     * @access public
205
-     * @return \EE_Line_Item[]
206
-     */
207
-    public function get_tickets()
208
-    {
209
-        if ($this->_grand_total === null ) {
210
-            return array();
211
-        }
212
-        return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     * returns the total quantity of tickets in the cart
219
-     *
220
-     * @access public
221
-     * @return int
222
-     * @throws \EE_Error
223
-     */
224
-    public function all_ticket_quantity_count()
225
-    {
226
-        $tickets = $this->get_tickets();
227
-        if (empty($tickets)) {
228
-            return 0;
229
-        }
230
-        $count = 0;
231
-        foreach ($tickets as $ticket) {
232
-            $count += $ticket->get('LIN_quantity');
233
-        }
234
-        return $count;
235
-    }
236
-
237
-
238
-
239
-    /**
240
-     * Gets all the tax line items
241
-     *
242
-     * @return \EE_Line_Item[]
243
-     * @throws \EE_Error
244
-     */
245
-    public function get_taxes()
246
-    {
247
-        return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
248
-    }
249
-
250
-
251
-
252
-    /**
253
-     * Gets the total line item (which is a parent of all other line items) on this cart
254
-     *
255
-     * @return EE_Line_Item
256
-     * @throws \EE_Error
257
-     */
258
-    public function get_grand_total()
259
-    {
260
-        return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     * @process items for adding to cart
267
-     * @access  public
268
-     * @param EE_Ticket $ticket
269
-     * @param int       $qty
270
-     * @return TRUE on success, FALSE on fail
271
-     * @throws \EE_Error
272
-     */
273
-    public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
274
-    {
275
-        EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
276
-        return $this->save_cart() ? true : false;
277
-    }
278
-
279
-
280
-
281
-    /**
282
-     * get_cart_total_before_tax
283
-     *
284
-     * @access public
285
-     * @return float
286
-     * @throws \EE_Error
287
-     */
288
-    public function get_cart_total_before_tax()
289
-    {
290
-        return $this->get_grand_total()->recalculate_pre_tax_total();
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     * gets the total amount of tax paid for items in this cart
297
-     *
298
-     * @access public
299
-     * @return float
300
-     * @throws \EE_Error
301
-     */
302
-    public function get_applied_taxes()
303
-    {
304
-        return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
305
-    }
306
-
307
-
308
-
309
-    /**
310
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
311
-     *
312
-     * @access public
313
-     * @return float
314
-     * @throws \EE_Error
315
-     */
316
-    public function get_cart_grand_total()
317
-    {
318
-        EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
319
-        return $this->get_grand_total()->total();
320
-    }
321
-
322
-
323
-
324
-    /**
325
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
326
-     *
327
-     * @access public
328
-     * @return float
329
-     * @throws \EE_Error
330
-     */
331
-    public function recalculate_all_cart_totals()
332
-    {
333
-        $pre_tax_total = $this->get_cart_total_before_tax();
334
-        $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
335
-        $this->_grand_total->set_total($pre_tax_total + $taxes_total);
336
-        $this->_grand_total->save_this_and_descendants_to_txn();
337
-        return $this->get_grand_total()->total();
338
-    }
339
-
340
-
341
-
342
-    /**
343
-     * deletes an item from the cart
344
-     *
345
-     * @access public
346
-     * @param array|bool|string $line_item_codes
347
-     * @return int on success, FALSE on fail
348
-     * @throws \EE_Error
349
-     */
350
-    public function delete_items($line_item_codes = false)
351
-    {
352
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
353
-        return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
354
-    }
355
-
356
-
357
-
358
-    /**
359
-     * @remove ALL items from cart and zero ALL totals
360
-     * @access public
361
-     * @return bool
362
-     * @throws \EE_Error
363
-     */
364
-    public function empty_cart()
365
-    {
366
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
367
-        $this->_grand_total = $this->_create_grand_total();
368
-        return $this->save_cart(true);
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * @remove ALL items from cart and delete total as well
375
-     * @access public
376
-     * @return bool
377
-     * @throws \EE_Error
378
-     */
379
-    public function delete_cart()
380
-    {
381
-        if ($this->_grand_total instanceof EE_Line_Item) {
382
-            $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
383
-            if ($deleted) {
384
-                $deleted += $this->_grand_total->delete();
385
-                $this->_grand_total = null;
386
-                return true;
387
-            }
388
-        }
389
-        return false;
390
-    }
391
-
392
-
393
-
394
-    /**
395
-     * @save   cart to session
396
-     * @access public
397
-     * @param bool $apply_taxes
398
-     * @return TRUE on success, FALSE on fail
399
-     * @throws \EE_Error
400
-     */
401
-    public function save_cart($apply_taxes = true)
402
-    {
403
-        if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
404
-            EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
405
-            //make sure we don't cache the transaction because it can get stale
406
-            if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
407
-                && $this->_grand_total->get_one_from_cache('Transaction')->ID()
408
-            ) {
409
-                $this->_grand_total->clear_cache('Transaction', null, true);
410
-            }
411
-        }
412
-        if ($this->session() instanceof EE_Session) {
413
-            return $this->session()->set_cart($this);
414
-        } else {
415
-            return false;
416
-        }
417
-    }
418
-
419
-
420
-
421
-    public function __wakeup()
422
-    {
423
-        if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
424
-            // $this->_grand_total is actually just an ID, so use it to get the object from the db
425
-            $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
426
-        }
427
-    }
428
-
429
-
430
-
431
-    /**
432
-     * @return array
433
-     */
434
-    public function __sleep()
435
-    {
436
-        if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
437
-            $this->_grand_total = $this->_grand_total->ID();
438
-        }
439
-        return array('_grand_total');
440
-    }
26
+	/**
27
+	 * instance of the EE_Cart object
28
+	 *
29
+	 * @access    private
30
+	 * @var EE_Cart $_instance
31
+	 */
32
+	private static $_instance;
33
+
34
+	/**
35
+	 * instance of the EE_Session object
36
+	 *
37
+	 * @access    protected
38
+	 * @var EE_Session $_session
39
+	 */
40
+	protected $_session;
41
+
42
+	/**
43
+	 * The total Line item which comprises all the children line-item subtotals,
44
+	 * which in turn each have their line items.
45
+	 * Typically, the line item structure will look like:
46
+	 * grand total
47
+	 * -tickets-sub-total
48
+	 * --ticket1
49
+	 * --ticket2
50
+	 * --...
51
+	 * -taxes-sub-total
52
+	 * --tax1
53
+	 * --tax2
54
+	 *
55
+	 * @var EE_Line_Item
56
+	 */
57
+	private $_grand_total;
58
+
59
+
60
+
61
+	/**
62
+	 * @singleton method used to instantiate class object
63
+	 * @access    public
64
+	 * @param EE_Line_Item $grand_total
65
+	 * @param EE_Session   $session
66
+	 * @return \EE_Cart
67
+	 * @throws \EE_Error
68
+	 */
69
+	public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
70
+	{
71
+		if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
72
+			self::$_instance = new self($grand_total, $session);
73
+		}
74
+		// or maybe retrieve an existing one ?
75
+		if ( ! self::$_instance instanceof EE_Cart) {
76
+			// try getting the cart out of the session
77
+			$saved_cart = $session instanceof EE_Session ? $session->cart() : null;
78
+			self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
79
+			unset($saved_cart);
80
+		}
81
+		// verify that cart is ok and grand total line item exists
82
+		if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
83
+			self::$_instance = new self($grand_total, $session);
84
+		}
85
+		self::$_instance->get_grand_total();
86
+		// once everything is all said and done, save the cart to the EE_Session
87
+		add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
88
+		return self::$_instance;
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * private constructor to prevent direct creation
95
+	 *
96
+	 * @Constructor
97
+	 * @access private
98
+	 * @param EE_Line_Item $grand_total
99
+	 * @param EE_Session   $session
100
+	 */
101
+	private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
102
+	{
103
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
104
+		$this->set_session($session);
105
+		if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
106
+			$this->set_grand_total_line_item($grand_total);
107
+		}
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * Resets the cart completely (whereas empty_cart
114
+	 *
115
+	 * @param EE_Line_Item $grand_total
116
+	 * @param EE_Session   $session
117
+	 * @return EE_Cart
118
+	 * @throws \EE_Error
119
+	 */
120
+	public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
121
+	{
122
+		remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
123
+		if ($session instanceof EE_Session) {
124
+			$session->reset_cart();
125
+		}
126
+		self::$_instance = null;
127
+		return self::instance($grand_total, $session);
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @return \EE_Session
134
+	 */
135
+	public function session()
136
+	{
137
+		if ( ! $this->_session instanceof EE_Session) {
138
+			$this->set_session();
139
+		}
140
+		return $this->_session;
141
+	}
142
+
143
+
144
+
145
+	/**
146
+	 * @param EE_Session $session
147
+	 */
148
+	public function set_session(EE_Session $session = null)
149
+	{
150
+		$this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * Sets the cart to match the line item. Especially handy for loading an old cart where you
157
+	 *  know the grand total line item on it
158
+	 *
159
+	 * @param EE_Line_Item $line_item
160
+	 */
161
+	public function set_grand_total_line_item(EE_Line_Item $line_item)
162
+	{
163
+		$this->_grand_total = $line_item;
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 * get_cart_from_reg_url_link
170
+	 *
171
+	 * @access public
172
+	 * @param EE_Transaction $transaction
173
+	 * @param EE_Session     $session
174
+	 * @return \EE_Cart
175
+	 * @throws \EE_Error
176
+	 */
177
+	public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
178
+	{
179
+		$grand_total = $transaction->total_line_item();
180
+		$grand_total->get_items();
181
+		$grand_total->tax_descendants();
182
+		return EE_Cart::instance($grand_total, $session);
183
+	}
184
+
185
+
186
+
187
+	/**
188
+	 * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
189
+	 *
190
+	 * @return EE_Line_Item
191
+	 * @throws \EE_Error
192
+	 */
193
+	private function _create_grand_total()
194
+	{
195
+		$this->_grand_total = EEH_Line_Item::create_total_line_item();
196
+		return $this->_grand_total;
197
+	}
198
+
199
+
200
+
201
+	/**
202
+	 * Gets all the line items of object type Ticket
203
+	 *
204
+	 * @access public
205
+	 * @return \EE_Line_Item[]
206
+	 */
207
+	public function get_tickets()
208
+	{
209
+		if ($this->_grand_total === null ) {
210
+			return array();
211
+		}
212
+		return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 * returns the total quantity of tickets in the cart
219
+	 *
220
+	 * @access public
221
+	 * @return int
222
+	 * @throws \EE_Error
223
+	 */
224
+	public function all_ticket_quantity_count()
225
+	{
226
+		$tickets = $this->get_tickets();
227
+		if (empty($tickets)) {
228
+			return 0;
229
+		}
230
+		$count = 0;
231
+		foreach ($tickets as $ticket) {
232
+			$count += $ticket->get('LIN_quantity');
233
+		}
234
+		return $count;
235
+	}
236
+
237
+
238
+
239
+	/**
240
+	 * Gets all the tax line items
241
+	 *
242
+	 * @return \EE_Line_Item[]
243
+	 * @throws \EE_Error
244
+	 */
245
+	public function get_taxes()
246
+	{
247
+		return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
248
+	}
249
+
250
+
251
+
252
+	/**
253
+	 * Gets the total line item (which is a parent of all other line items) on this cart
254
+	 *
255
+	 * @return EE_Line_Item
256
+	 * @throws \EE_Error
257
+	 */
258
+	public function get_grand_total()
259
+	{
260
+		return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 * @process items for adding to cart
267
+	 * @access  public
268
+	 * @param EE_Ticket $ticket
269
+	 * @param int       $qty
270
+	 * @return TRUE on success, FALSE on fail
271
+	 * @throws \EE_Error
272
+	 */
273
+	public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
274
+	{
275
+		EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
276
+		return $this->save_cart() ? true : false;
277
+	}
278
+
279
+
280
+
281
+	/**
282
+	 * get_cart_total_before_tax
283
+	 *
284
+	 * @access public
285
+	 * @return float
286
+	 * @throws \EE_Error
287
+	 */
288
+	public function get_cart_total_before_tax()
289
+	{
290
+		return $this->get_grand_total()->recalculate_pre_tax_total();
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 * gets the total amount of tax paid for items in this cart
297
+	 *
298
+	 * @access public
299
+	 * @return float
300
+	 * @throws \EE_Error
301
+	 */
302
+	public function get_applied_taxes()
303
+	{
304
+		return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
305
+	}
306
+
307
+
308
+
309
+	/**
310
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
311
+	 *
312
+	 * @access public
313
+	 * @return float
314
+	 * @throws \EE_Error
315
+	 */
316
+	public function get_cart_grand_total()
317
+	{
318
+		EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
319
+		return $this->get_grand_total()->total();
320
+	}
321
+
322
+
323
+
324
+	/**
325
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
326
+	 *
327
+	 * @access public
328
+	 * @return float
329
+	 * @throws \EE_Error
330
+	 */
331
+	public function recalculate_all_cart_totals()
332
+	{
333
+		$pre_tax_total = $this->get_cart_total_before_tax();
334
+		$taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
335
+		$this->_grand_total->set_total($pre_tax_total + $taxes_total);
336
+		$this->_grand_total->save_this_and_descendants_to_txn();
337
+		return $this->get_grand_total()->total();
338
+	}
339
+
340
+
341
+
342
+	/**
343
+	 * deletes an item from the cart
344
+	 *
345
+	 * @access public
346
+	 * @param array|bool|string $line_item_codes
347
+	 * @return int on success, FALSE on fail
348
+	 * @throws \EE_Error
349
+	 */
350
+	public function delete_items($line_item_codes = false)
351
+	{
352
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
353
+		return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
354
+	}
355
+
356
+
357
+
358
+	/**
359
+	 * @remove ALL items from cart and zero ALL totals
360
+	 * @access public
361
+	 * @return bool
362
+	 * @throws \EE_Error
363
+	 */
364
+	public function empty_cart()
365
+	{
366
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
367
+		$this->_grand_total = $this->_create_grand_total();
368
+		return $this->save_cart(true);
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * @remove ALL items from cart and delete total as well
375
+	 * @access public
376
+	 * @return bool
377
+	 * @throws \EE_Error
378
+	 */
379
+	public function delete_cart()
380
+	{
381
+		if ($this->_grand_total instanceof EE_Line_Item) {
382
+			$deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
383
+			if ($deleted) {
384
+				$deleted += $this->_grand_total->delete();
385
+				$this->_grand_total = null;
386
+				return true;
387
+			}
388
+		}
389
+		return false;
390
+	}
391
+
392
+
393
+
394
+	/**
395
+	 * @save   cart to session
396
+	 * @access public
397
+	 * @param bool $apply_taxes
398
+	 * @return TRUE on success, FALSE on fail
399
+	 * @throws \EE_Error
400
+	 */
401
+	public function save_cart($apply_taxes = true)
402
+	{
403
+		if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
404
+			EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
405
+			//make sure we don't cache the transaction because it can get stale
406
+			if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
407
+				&& $this->_grand_total->get_one_from_cache('Transaction')->ID()
408
+			) {
409
+				$this->_grand_total->clear_cache('Transaction', null, true);
410
+			}
411
+		}
412
+		if ($this->session() instanceof EE_Session) {
413
+			return $this->session()->set_cart($this);
414
+		} else {
415
+			return false;
416
+		}
417
+	}
418
+
419
+
420
+
421
+	public function __wakeup()
422
+	{
423
+		if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
424
+			// $this->_grand_total is actually just an ID, so use it to get the object from the db
425
+			$this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
426
+		}
427
+	}
428
+
429
+
430
+
431
+	/**
432
+	 * @return array
433
+	 */
434
+	public function __sleep()
435
+	{
436
+		if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
437
+			$this->_grand_total = $this->_grand_total->ID();
438
+		}
439
+		return array('_grand_total');
440
+	}
441 441
 
442 442
 
443 443
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
      *
614 614
      * @since  4.6.0
615 615
      * @global WPDB $wpdb
616
-     * @return mixed null|int WP_user ID or NULL
616
+     * @return integer|null null|int WP_user ID or NULL
617 617
      */
618 618
     public static function get_default_creator_id()
619 619
     {
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
      * @static
775 775
      * @deprecated instead use TableManager::dropTable()
776 776
      * @param string $table_name
777
-     * @return bool | int
777
+     * @return integer | int
778 778
      */
779 779
     public static function delete_unused_db_table($table_name)
780 780
     {
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
      * @deprecated instead use TableManager::dropIndex()
792 792
      * @param string $table_name
793 793
      * @param string $index_name
794
-     * @return bool | int
794
+     * @return integer | int
795 795
      */
796 796
     public static function drop_index($table_name, $index_name)
797 797
     {
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public static function getTableAnalysis()
59 59
     {
60
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
60
+        if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
61 61
             self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
62 62
         }
63 63
         return self::$table_analysis;
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public static function getTableManager()
71 71
     {
72
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
72
+        if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
73 73
             self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
74 74
         }
75 75
         return self::$table_manager;
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
         if ($which_to_include === 'old') {
184 184
             $cron_tasks = array_filter(
185 185
                 $cron_tasks,
186
-                function ($value) {
186
+                function($value) {
187 187
                     return $value === EEH_Activation::cron_task_no_longer_in_use;
188 188
                 }
189 189
             );
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
     {
214 214
 
215 215
         foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
216
-            if (! wp_next_scheduled($hook_name)) {
216
+            if ( ! wp_next_scheduled($hook_name)) {
217 217
                 /**
218 218
                  * This allows client code to define the initial start timestamp for this schedule.
219 219
                  */
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
             3
319 319
         );
320 320
         //EE_Config::reset();
321
-        if (! EE_Config::logging_enabled()) {
321
+        if ( ! EE_Config::logging_enabled()) {
322 322
             delete_option(EE_Config::LOG_NAME);
323 323
         }
324 324
     }
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
     public static function load_calendar_config()
334 334
     {
335 335
         // grab array of all plugin folders and loop thru it
336
-        $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
336
+        $plugins = glob(WP_PLUGIN_DIR.DS.'*', GLOB_ONLYDIR);
337 337
         if (empty($plugins)) {
338 338
             return;
339 339
         }
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
                 || strpos($plugin, 'calendar') !== false
351 351
             ) {
352 352
                 // this is what we are looking for
353
-                $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
353
+                $calendar_config = $plugin_path.DS.'EE_Calendar_Config.php';
354 354
                 // does it exist in this folder ?
355 355
                 if (is_readable($calendar_config)) {
356 356
                     // YEAH! let's load it
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
             ) {
479 479
                 //update Config with post ID
480 480
                 $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
481
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
481
+                if ( ! EE_Config::instance()->update_espresso_config(false, false)) {
482 482
                     $msg = __(
483 483
                         'The Event Espresso critical page configuration settings could not be updated.',
484 484
                         'event_espresso'
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
                         'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
502 502
                         'event_espresso'
503 503
                     ),
504
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
504
+                    '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">'
505 505
                     . __('Event Espresso Critical Pages Settings', 'event_espresso')
506 506
                     . '</a>'
507 507
                 )
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
     public static function get_page_by_ee_shortcode($ee_shortcode)
528 528
     {
529 529
         global $wpdb;
530
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
530
+        $shortcode_and_opening_bracket = '['.$ee_shortcode;
531 531
         $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
532 532
         if ($post_id) {
533 533
             return get_post($post_id);
@@ -553,11 +553,11 @@  discard block
 block discarded – undo
553 553
             'post_status'    => 'publish',
554 554
             'post_type'      => 'page',
555 555
             'comment_status' => 'closed',
556
-            'post_content'   => '[' . $critical_page['code'] . ']',
556
+            'post_content'   => '['.$critical_page['code'].']',
557 557
         );
558 558
 
559 559
         $post_id = wp_insert_post($post_args);
560
-        if (! $post_id) {
560
+        if ( ! $post_id) {
561 561
             $msg = sprintf(
562 562
                 __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
563 563
                 $critical_page['name']
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
             return $critical_page;
567 567
         }
568 568
         // get newly created post's details
569
-        if (! $critical_page['post'] = get_post($post_id)) {
569
+        if ( ! $critical_page['post'] = get_post($post_id)) {
570 570
             $msg = sprintf(
571 571
                 __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
572 572
                 $critical_page['name']
@@ -603,17 +603,17 @@  discard block
 block discarded – undo
603 603
             $role_to_check
604 604
         );
605 605
         if ($pre_filtered_id !== false) {
606
-            return (int)$pre_filtered_id;
606
+            return (int) $pre_filtered_id;
607 607
         }
608 608
         $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
609 609
         $query = $wpdb->prepare(
610 610
             "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
611
-            '%' . $role_to_check . '%'
611
+            '%'.$role_to_check.'%'
612 612
         );
613 613
         $user_id = $wpdb->get_var($query);
614 614
         $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
615
-        if ($user_id && (int)$user_id) {
616
-            self::$_default_creator_id = (int)$user_id;
615
+        if ($user_id && (int) $user_id) {
616
+            self::$_default_creator_id = (int) $user_id;
617 617
             return self::$_default_creator_id;
618 618
         } else {
619 619
             return null;
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
         }
649 649
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
650 650
         if ( ! function_exists('dbDelta')) {
651
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
651
+            require_once(ABSPATH.'wp-admin/includes/upgrade.php');
652 652
         }
653 653
         $tableAnalysis = \EEH_Activation::getTableAnalysis();
654 654
         $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
@@ -859,13 +859,13 @@  discard block
 block discarded – undo
859 859
             // reset values array
860 860
             $QSG_values = array();
861 861
             // 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)
862
-            if (! in_array("$QSG_system", $question_groups)) {
862
+            if ( ! in_array("$QSG_system", $question_groups)) {
863 863
                 // add it
864 864
                 switch ($QSG_system) {
865 865
                     case 1:
866 866
                         $QSG_values = array(
867 867
                             'QSG_name'            => __('Personal Information', 'event_espresso'),
868
-                            'QSG_identifier'      => 'personal-information-' . time(),
868
+                            'QSG_identifier'      => 'personal-information-'.time(),
869 869
                             'QSG_desc'            => '',
870 870
                             'QSG_order'           => 1,
871 871
                             'QSG_show_group_name' => 1,
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
                     case 2:
878 878
                         $QSG_values = array(
879 879
                             'QSG_name'            => __('Address Information', 'event_espresso'),
880
-                            'QSG_identifier'      => 'address-information-' . time(),
880
+                            'QSG_identifier'      => 'address-information-'.time(),
881 881
                             'QSG_desc'            => '',
882 882
                             'QSG_order'           => 2,
883 883
                             'QSG_show_group_name' => 1,
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
                         break;
889 889
                 }
890 890
                 // make sure we have some values before inserting them
891
-                if (! empty($QSG_values)) {
891
+                if ( ! empty($QSG_values)) {
892 892
                     // insert system question
893 893
                     $wpdb->insert(
894 894
                         $table_name,
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
             // reset values array
926 926
             $QST_values = array();
927 927
             // if we don't have what we should have
928
-            if (! in_array($QST_system, $questions)) {
928
+            if ( ! in_array($QST_system, $questions)) {
929 929
                 // add it
930 930
                 switch ($QST_system) {
931 931
                     case 'fname':
@@ -1077,7 +1077,7 @@  discard block
 block discarded – undo
1077 1077
                         );
1078 1078
                         break;
1079 1079
                 }
1080
-                if (! empty($QST_values)) {
1080
+                if ( ! empty($QST_values)) {
1081 1081
                     // insert system question
1082 1082
                     $wpdb->insert(
1083 1083
                         $table_name,
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
      */
1139 1139
     public static function insert_default_payment_methods()
1140 1140
     {
1141
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1141
+        if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1142 1142
             EE_Registry::instance()->load_lib('Payment_Method_Manager');
1143 1143
             EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1144 1144
         } else {
@@ -1427,7 +1427,7 @@  discard block
 block discarded – undo
1427 1427
         // this creates an array for tracking events that have no active ticket prices created
1428 1428
         // this allows us to warn admins of the situation so that it can be corrected
1429 1429
         $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1430
-        if (! $espresso_no_ticket_prices) {
1430
+        if ( ! $espresso_no_ticket_prices) {
1431 1431
             add_option('ee_no_ticket_prices', array(), '', false);
1432 1432
         }
1433 1433
     }
@@ -1466,7 +1466,7 @@  discard block
 block discarded – undo
1466 1466
             }
1467 1467
         }
1468 1468
         //get all our CPTs
1469
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1469
+        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")";
1470 1470
         $cpt_ids = $wpdb->get_col($query);
1471 1471
         //delete each post meta and term relations too
1472 1472
         foreach ($cpt_ids as $post_id) {
@@ -1606,7 +1606,7 @@  discard block
 block discarded – undo
1606 1606
         if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1607 1607
             $db_update_sans_ee4 = array();
1608 1608
             foreach ($espresso_db_update as $version => $times_activated) {
1609
-                if ((string)$version[0] === '3') {//if its NON EE4
1609
+                if ((string) $version[0] === '3') {//if its NON EE4
1610 1610
                     $db_update_sans_ee4[$version] = $times_activated;
1611 1611
                 }
1612 1612
             }
Please login to merge, or discard this patch.
Indentation   +1581 added lines, -1581 removed lines patch added patch discarded remove patch
@@ -19,233 +19,233 @@  discard block
 block discarded – undo
19 19
 class EEH_Activation implements ResettableInterface
20 20
 {
21 21
 
22
-    /**
23
-     * constant used to indicate a cron task is no longer in use
24
-     */
25
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
26
-
27
-    /**
28
-     * WP_User->ID
29
-     *
30
-     * @var int
31
-     */
32
-    private static $_default_creator_id;
33
-
34
-    /**
35
-     * indicates whether or not we've already verified core's default data during this request,
36
-     * because after migrations are done, any addons activated while in maintenance mode
37
-     * will want to setup their own default data, and they might hook into core's default data
38
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
39
-     * This prevents doing that for EVERY single addon.
40
-     *
41
-     * @var boolean
42
-     */
43
-    protected static $_initialized_db_content_already_in_this_request = false;
44
-
45
-    /**
46
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
47
-     */
48
-    private static $table_analysis;
49
-
50
-    /**
51
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
52
-     */
53
-    private static $table_manager;
54
-
55
-
56
-    /**
57
-     * @return \EventEspresso\core\services\database\TableAnalysis
58
-     */
59
-    public static function getTableAnalysis()
60
-    {
61
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
62
-            self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
63
-        }
64
-        return self::$table_analysis;
65
-    }
66
-
67
-
68
-    /**
69
-     * @return \EventEspresso\core\services\database\TableManager
70
-     */
71
-    public static function getTableManager()
72
-    {
73
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
74
-            self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
75
-        }
76
-        return self::$table_manager;
77
-    }
78
-
79
-
80
-    /**
81
-     *    _ensure_table_name_has_prefix
82
-     *
83
-     * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
84
-     * @access     public
85
-     * @static
86
-     * @param $table_name
87
-     * @return string
88
-     */
89
-    public static function ensure_table_name_has_prefix($table_name)
90
-    {
91
-        return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
92
-    }
93
-
94
-
95
-    /**
96
-     *    system_initialization
97
-     *    ensures the EE configuration settings are loaded with at least default options set
98
-     *    and that all critical EE pages have been generated with the appropriate shortcodes in place
99
-     *
100
-     * @access public
101
-     * @static
102
-     * @return void
103
-     */
104
-    public static function system_initialization()
105
-    {
106
-        EEH_Activation::reset_and_update_config();
107
-        //which is fired BEFORE activation of plugin anyways
108
-        EEH_Activation::verify_default_pages_exist();
109
-    }
110
-
111
-
112
-    /**
113
-     * Sets the database schema and creates folders. This should
114
-     * be called on plugin activation and reactivation
115
-     *
116
-     * @return boolean success, whether the database and folders are setup properly
117
-     * @throws \EE_Error
118
-     */
119
-    public static function initialize_db_and_folders()
120
-    {
121
-        return EEH_Activation::create_database_tables();
122
-    }
123
-
124
-
125
-    /**
126
-     * assuming we have an up-to-date database schema, this will populate it
127
-     * with default and initial data. This should be called
128
-     * upon activation of a new plugin, reactivation, and at the end
129
-     * of running migration scripts
130
-     *
131
-     * @throws \EE_Error
132
-     */
133
-    public static function initialize_db_content()
134
-    {
135
-        //let's avoid doing all this logic repeatedly, especially when addons are requesting it
136
-        if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
137
-            return;
138
-        }
139
-        EEH_Activation::$_initialized_db_content_already_in_this_request = true;
140
-
141
-        EEH_Activation::initialize_system_questions();
142
-        EEH_Activation::insert_default_status_codes();
143
-        EEH_Activation::generate_default_message_templates();
144
-        EEH_Activation::create_no_ticket_prices_array();
145
-
146
-        EEH_Activation::validate_messages_system();
147
-        EEH_Activation::insert_default_payment_methods();
148
-        //in case we've
149
-        EEH_Activation::remove_cron_tasks();
150
-        EEH_Activation::create_cron_tasks();
151
-        // remove all TXN locks since that is being done via extra meta now
152
-        delete_option('ee_locked_transactions');
153
-        //also, check for CAF default db content
154
-        do_action('AHEE__EEH_Activation__initialize_db_content');
155
-        //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
156
-        //which users really won't care about on initial activation
157
-        EE_Error::overwrite_success();
158
-    }
159
-
160
-
161
-    /**
162
-     * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
163
-     * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
164
-     * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
165
-     * (null)
166
-     *
167
-     * @param string $which_to_include can be 'current' (ones that are currently in use),
168
-     *                                 'old' (only returns ones that should no longer be used),or 'all',
169
-     * @return array
170
-     * @throws \EE_Error
171
-     */
172
-    public static function get_cron_tasks($which_to_include)
173
-    {
174
-        $cron_tasks = apply_filters(
175
-            'FHEE__EEH_Activation__get_cron_tasks',
176
-            array(
177
-                'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
22
+	/**
23
+	 * constant used to indicate a cron task is no longer in use
24
+	 */
25
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
26
+
27
+	/**
28
+	 * WP_User->ID
29
+	 *
30
+	 * @var int
31
+	 */
32
+	private static $_default_creator_id;
33
+
34
+	/**
35
+	 * indicates whether or not we've already verified core's default data during this request,
36
+	 * because after migrations are done, any addons activated while in maintenance mode
37
+	 * will want to setup their own default data, and they might hook into core's default data
38
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
39
+	 * This prevents doing that for EVERY single addon.
40
+	 *
41
+	 * @var boolean
42
+	 */
43
+	protected static $_initialized_db_content_already_in_this_request = false;
44
+
45
+	/**
46
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
47
+	 */
48
+	private static $table_analysis;
49
+
50
+	/**
51
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
52
+	 */
53
+	private static $table_manager;
54
+
55
+
56
+	/**
57
+	 * @return \EventEspresso\core\services\database\TableAnalysis
58
+	 */
59
+	public static function getTableAnalysis()
60
+	{
61
+		if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
62
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
63
+		}
64
+		return self::$table_analysis;
65
+	}
66
+
67
+
68
+	/**
69
+	 * @return \EventEspresso\core\services\database\TableManager
70
+	 */
71
+	public static function getTableManager()
72
+	{
73
+		if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
74
+			self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
75
+		}
76
+		return self::$table_manager;
77
+	}
78
+
79
+
80
+	/**
81
+	 *    _ensure_table_name_has_prefix
82
+	 *
83
+	 * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
84
+	 * @access     public
85
+	 * @static
86
+	 * @param $table_name
87
+	 * @return string
88
+	 */
89
+	public static function ensure_table_name_has_prefix($table_name)
90
+	{
91
+		return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
92
+	}
93
+
94
+
95
+	/**
96
+	 *    system_initialization
97
+	 *    ensures the EE configuration settings are loaded with at least default options set
98
+	 *    and that all critical EE pages have been generated with the appropriate shortcodes in place
99
+	 *
100
+	 * @access public
101
+	 * @static
102
+	 * @return void
103
+	 */
104
+	public static function system_initialization()
105
+	{
106
+		EEH_Activation::reset_and_update_config();
107
+		//which is fired BEFORE activation of plugin anyways
108
+		EEH_Activation::verify_default_pages_exist();
109
+	}
110
+
111
+
112
+	/**
113
+	 * Sets the database schema and creates folders. This should
114
+	 * be called on plugin activation and reactivation
115
+	 *
116
+	 * @return boolean success, whether the database and folders are setup properly
117
+	 * @throws \EE_Error
118
+	 */
119
+	public static function initialize_db_and_folders()
120
+	{
121
+		return EEH_Activation::create_database_tables();
122
+	}
123
+
124
+
125
+	/**
126
+	 * assuming we have an up-to-date database schema, this will populate it
127
+	 * with default and initial data. This should be called
128
+	 * upon activation of a new plugin, reactivation, and at the end
129
+	 * of running migration scripts
130
+	 *
131
+	 * @throws \EE_Error
132
+	 */
133
+	public static function initialize_db_content()
134
+	{
135
+		//let's avoid doing all this logic repeatedly, especially when addons are requesting it
136
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
137
+			return;
138
+		}
139
+		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
140
+
141
+		EEH_Activation::initialize_system_questions();
142
+		EEH_Activation::insert_default_status_codes();
143
+		EEH_Activation::generate_default_message_templates();
144
+		EEH_Activation::create_no_ticket_prices_array();
145
+
146
+		EEH_Activation::validate_messages_system();
147
+		EEH_Activation::insert_default_payment_methods();
148
+		//in case we've
149
+		EEH_Activation::remove_cron_tasks();
150
+		EEH_Activation::create_cron_tasks();
151
+		// remove all TXN locks since that is being done via extra meta now
152
+		delete_option('ee_locked_transactions');
153
+		//also, check for CAF default db content
154
+		do_action('AHEE__EEH_Activation__initialize_db_content');
155
+		//also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
156
+		//which users really won't care about on initial activation
157
+		EE_Error::overwrite_success();
158
+	}
159
+
160
+
161
+	/**
162
+	 * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
163
+	 * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
164
+	 * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
165
+	 * (null)
166
+	 *
167
+	 * @param string $which_to_include can be 'current' (ones that are currently in use),
168
+	 *                                 'old' (only returns ones that should no longer be used),or 'all',
169
+	 * @return array
170
+	 * @throws \EE_Error
171
+	 */
172
+	public static function get_cron_tasks($which_to_include)
173
+	{
174
+		$cron_tasks = apply_filters(
175
+			'FHEE__EEH_Activation__get_cron_tasks',
176
+			array(
177
+				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
178 178
 //				'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
179
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
180
-                //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
181
-                'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
182
-            )
183
-        );
184
-        if ($which_to_include === 'old') {
185
-            $cron_tasks = array_filter(
186
-                $cron_tasks,
187
-                function ($value) {
188
-                    return $value === EEH_Activation::cron_task_no_longer_in_use;
189
-                }
190
-            );
191
-        } elseif ($which_to_include === 'current') {
192
-            $cron_tasks = array_filter($cron_tasks);
193
-        } elseif (WP_DEBUG && $which_to_include !== 'all') {
194
-            throw new EE_Error(
195
-                sprintf(
196
-                    __(
197
-                        'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
198
-                        'event_espresso'
199
-                    ),
200
-                    $which_to_include
201
-                )
202
-            );
203
-        }
204
-        return $cron_tasks;
205
-    }
206
-
207
-
208
-    /**
209
-     * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
210
-     *
211
-     * @throws \EE_Error
212
-     */
213
-    public static function create_cron_tasks()
214
-    {
215
-
216
-        foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
217
-            if (! wp_next_scheduled($hook_name)) {
218
-                /**
219
-                 * This allows client code to define the initial start timestamp for this schedule.
220
-                 */
221
-                if (is_array($frequency)
222
-                    && count($frequency) === 2
223
-                    && isset($frequency[0], $frequency[1])
224
-                ) {
225
-                    $start_timestamp = $frequency[0];
226
-                    $frequency = $frequency[1];
227
-                } else {
228
-                    $start_timestamp = time();
229
-                }
230
-                wp_schedule_event($start_timestamp, $frequency, $hook_name);
231
-            }
232
-        }
233
-
234
-    }
235
-
236
-
237
-    /**
238
-     * Remove the currently-existing and now-removed cron tasks.
239
-     *
240
-     * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
241
-     * @throws \EE_Error
242
-     */
243
-    public static function remove_cron_tasks($remove_all = true)
244
-    {
245
-        $cron_tasks_to_remove = $remove_all ? 'all' : 'old';
246
-        $crons                = _get_cron_array();
247
-        $crons                = is_array($crons) ? $crons : array();
248
-        /* reminder of what $crons look like:
179
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
180
+				//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
181
+				'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
182
+			)
183
+		);
184
+		if ($which_to_include === 'old') {
185
+			$cron_tasks = array_filter(
186
+				$cron_tasks,
187
+				function ($value) {
188
+					return $value === EEH_Activation::cron_task_no_longer_in_use;
189
+				}
190
+			);
191
+		} elseif ($which_to_include === 'current') {
192
+			$cron_tasks = array_filter($cron_tasks);
193
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
194
+			throw new EE_Error(
195
+				sprintf(
196
+					__(
197
+						'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
198
+						'event_espresso'
199
+					),
200
+					$which_to_include
201
+				)
202
+			);
203
+		}
204
+		return $cron_tasks;
205
+	}
206
+
207
+
208
+	/**
209
+	 * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
210
+	 *
211
+	 * @throws \EE_Error
212
+	 */
213
+	public static function create_cron_tasks()
214
+	{
215
+
216
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
217
+			if (! wp_next_scheduled($hook_name)) {
218
+				/**
219
+				 * This allows client code to define the initial start timestamp for this schedule.
220
+				 */
221
+				if (is_array($frequency)
222
+					&& count($frequency) === 2
223
+					&& isset($frequency[0], $frequency[1])
224
+				) {
225
+					$start_timestamp = $frequency[0];
226
+					$frequency = $frequency[1];
227
+				} else {
228
+					$start_timestamp = time();
229
+				}
230
+				wp_schedule_event($start_timestamp, $frequency, $hook_name);
231
+			}
232
+		}
233
+
234
+	}
235
+
236
+
237
+	/**
238
+	 * Remove the currently-existing and now-removed cron tasks.
239
+	 *
240
+	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
241
+	 * @throws \EE_Error
242
+	 */
243
+	public static function remove_cron_tasks($remove_all = true)
244
+	{
245
+		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
246
+		$crons                = _get_cron_array();
247
+		$crons                = is_array($crons) ? $crons : array();
248
+		/* reminder of what $crons look like:
249 249
          * Top-level keys are timestamps, and their values are arrays.
250 250
          * The 2nd level arrays have keys with each of the cron task hook names to run at that time
251 251
          * and their values are arrays.
@@ -262,911 +262,911 @@  discard block
 block discarded – undo
262 262
          *					...
263 263
          *      ...
264 264
          */
265
-        $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
266
-        foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
267
-            if (is_array($hooks_to_fire_at_time)) {
268
-                foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
269
-                    if (isset($ee_cron_tasks_to_remove[$hook_name])
270
-                        && is_array($ee_cron_tasks_to_remove[$hook_name])
271
-                    ) {
272
-                        unset($crons[$timestamp][$hook_name]);
273
-                    }
274
-                }
275
-                //also take care of any empty cron timestamps.
276
-                if (empty($hooks_to_fire_at_time)) {
277
-                    unset($crons[$timestamp]);
278
-                }
279
-            }
280
-        }
281
-        _set_cron_array($crons);
282
-    }
283
-
284
-
285
-    /**
286
-     *    CPT_initialization
287
-     *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
288
-     *
289
-     * @access public
290
-     * @static
291
-     * @return void
292
-     */
293
-    public static function CPT_initialization()
294
-    {
295
-        // register Custom Post Types
296
-        EE_Registry::instance()->load_core('Register_CPTs');
297
-        flush_rewrite_rules();
298
-    }
299
-
300
-
301
-
302
-    /**
303
-     *    reset_and_update_config
304
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
305
-     * If there is old calendar config data saved, then it will get converted on activation.
306
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
307
-     *
308
-     * @access public
309
-     * @static
310
-     * @return void
311
-     */
312
-    public static function reset_and_update_config()
313
-    {
314
-        do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
315
-        add_filter(
316
-            'FHEE__EE_Config___load_core_config__config_settings',
317
-            array('EEH_Activation', 'migrate_old_config_data'),
318
-            10,
319
-            3
320
-        );
321
-        //EE_Config::reset();
322
-        if (! EE_Config::logging_enabled()) {
323
-            delete_option(EE_Config::LOG_NAME);
324
-        }
325
-    }
326
-
327
-
328
-    /**
329
-     *    load_calendar_config
330
-     *
331
-     * @access    public
332
-     * @return    void
333
-     */
334
-    public static function load_calendar_config()
335
-    {
336
-        // grab array of all plugin folders and loop thru it
337
-        $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
338
-        if (empty($plugins)) {
339
-            return;
340
-        }
341
-        foreach ($plugins as $plugin_path) {
342
-            // grab plugin folder name from path
343
-            $plugin = basename($plugin_path);
344
-            // drill down to Espresso plugins
345
-            // then to calendar related plugins
346
-            if (
347
-                strpos($plugin, 'espresso') !== false
348
-                || strpos($plugin, 'Espresso') !== false
349
-                || strpos($plugin, 'ee4') !== false
350
-                || strpos($plugin, 'EE4') !== false
351
-                || strpos($plugin, 'calendar') !== false
352
-            ) {
353
-                // this is what we are looking for
354
-                $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
355
-                // does it exist in this folder ?
356
-                if (is_readable($calendar_config)) {
357
-                    // YEAH! let's load it
358
-                    require_once($calendar_config);
359
-                }
360
-            }
361
-        }
362
-    }
363
-
364
-
365
-
366
-    /**
367
-     *    _migrate_old_config_data
368
-     *
369
-     * @access    public
370
-     * @param array|stdClass $settings
371
-     * @param string         $config
372
-     * @param \EE_Config     $EE_Config
373
-     * @return \stdClass
374
-     */
375
-    public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
376
-    {
377
-        $convert_from_array = array('addons');
378
-        // in case old settings were saved as an array
379
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
380
-            // convert existing settings to an object
381
-            $config_array = $settings;
382
-            $settings = new stdClass();
383
-            foreach ($config_array as $key => $value) {
384
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
385
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
386
-                } else {
387
-                    $settings->{$key} = $value;
388
-                }
389
-            }
390
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
391
-        }
392
-        return $settings;
393
-    }
394
-
395
-
396
-    /**
397
-     * deactivate_event_espresso
398
-     *
399
-     * @access public
400
-     * @static
401
-     * @return void
402
-     */
403
-    public static function deactivate_event_espresso()
404
-    {
405
-        // check permissions
406
-        if (current_user_can('activate_plugins')) {
407
-            deactivate_plugins(EE_PLUGIN_BASENAME, true);
408
-        }
409
-    }
410
-
411
-
412
-
413
-    /**
414
-     * verify_default_pages_exist
415
-     *
416
-     * @access public
417
-     * @static
418
-     * @return void
419
-     * @throws InvalidDataTypeException
420
-     */
421
-    public static function verify_default_pages_exist()
422
-    {
423
-        $critical_page_problem = false;
424
-        $critical_pages = array(
425
-            array(
426
-                'id'   => 'reg_page_id',
427
-                'name' => __('Registration Checkout', 'event_espresso'),
428
-                'post' => null,
429
-                'code' => 'ESPRESSO_CHECKOUT',
430
-            ),
431
-            array(
432
-                'id'   => 'txn_page_id',
433
-                'name' => __('Transactions', 'event_espresso'),
434
-                'post' => null,
435
-                'code' => 'ESPRESSO_TXN_PAGE',
436
-            ),
437
-            array(
438
-                'id'   => 'thank_you_page_id',
439
-                'name' => __('Thank You', 'event_espresso'),
440
-                'post' => null,
441
-                'code' => 'ESPRESSO_THANK_YOU',
442
-            ),
443
-            array(
444
-                'id'   => 'cancel_page_id',
445
-                'name' => __('Registration Cancelled', 'event_espresso'),
446
-                'post' => null,
447
-                'code' => 'ESPRESSO_CANCELLED',
448
-            ),
449
-        );
450
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
451
-        foreach ($critical_pages as $critical_page) {
452
-            // is critical page ID set in config ?
453
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
454
-                // attempt to find post by ID
455
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
456
-            }
457
-            // no dice?
458
-            if ($critical_page['post'] === null) {
459
-                // attempt to find post by title
460
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
461
-                // still nothing?
462
-                if ($critical_page['post'] === null) {
463
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
464
-                    // REALLY? Still nothing ??!?!?
465
-                    if ($critical_page['post'] === null) {
466
-                        $msg = __(
467
-                            'The Event Espresso critical page configuration settings could not be updated.',
468
-                            'event_espresso'
469
-                        );
470
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
471
-                        break;
472
-                    }
473
-                }
474
-            }
475
-            // check that Post ID matches critical page ID in config
476
-            if (
477
-                isset($critical_page['post']->ID)
478
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
479
-            ) {
480
-                //update Config with post ID
481
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
482
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
483
-                    $msg = __(
484
-                        'The Event Espresso critical page configuration settings could not be updated.',
485
-                        'event_espresso'
486
-                    );
487
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
488
-                }
489
-            }
490
-            $critical_page_problem =
491
-                ! isset($critical_page['post']->post_status)
492
-                || $critical_page['post']->post_status !== 'publish'
493
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
494
-                    ? true
495
-                    : $critical_page_problem;
496
-        }
497
-        if ($critical_page_problem) {
498
-            new PersistentAdminNotice(
499
-                'critical_page_problem',
500
-                sprintf(
501
-                    esc_html__(
502
-                        'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
503
-                        'event_espresso'
504
-                    ),
505
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
506
-                    . __('Event Espresso Critical Pages Settings', 'event_espresso')
507
-                    . '</a>'
508
-                )
509
-            );
510
-        }
511
-        if (EE_Error::has_notices()) {
512
-            EE_Error::get_notices(false, true, true);
513
-        }
514
-    }
515
-
516
-
517
-
518
-    /**
519
-     * Returns the first post which uses the specified shortcode
520
-     *
521
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
522
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
523
-     *                             "[ESPRESSO_THANK_YOU"
524
-     *                             (we don't search for the closing shortcode bracket because they might have added
525
-     *                             parameter to the shortcode
526
-     * @return WP_Post or NULl
527
-     */
528
-    public static function get_page_by_ee_shortcode($ee_shortcode)
529
-    {
530
-        global $wpdb;
531
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
532
-        $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
533
-        if ($post_id) {
534
-            return get_post($post_id);
535
-        } else {
536
-            return null;
537
-        }
538
-    }
539
-
540
-
541
-    /**
542
-     *    This function generates a post for critical espresso pages
543
-     *
544
-     * @access public
545
-     * @static
546
-     * @param array $critical_page
547
-     * @return array
548
-     */
549
-    public static function create_critical_page($critical_page)
550
-    {
551
-
552
-        $post_args = array(
553
-            'post_title'     => $critical_page['name'],
554
-            'post_status'    => 'publish',
555
-            'post_type'      => 'page',
556
-            'comment_status' => 'closed',
557
-            'post_content'   => '[' . $critical_page['code'] . ']',
558
-        );
559
-
560
-        $post_id = wp_insert_post($post_args);
561
-        if (! $post_id) {
562
-            $msg = sprintf(
563
-                __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
564
-                $critical_page['name']
565
-            );
566
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
567
-            return $critical_page;
568
-        }
569
-        // get newly created post's details
570
-        if (! $critical_page['post'] = get_post($post_id)) {
571
-            $msg = sprintf(
572
-                __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
573
-                $critical_page['name']
574
-            );
575
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
576
-        }
577
-
578
-        return $critical_page;
579
-
580
-    }
581
-
582
-
583
-
584
-
585
-    /**
586
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
587
-     * The role being used to check is filterable.
588
-     *
589
-     * @since  4.6.0
590
-     * @global WPDB $wpdb
591
-     * @return mixed null|int WP_user ID or NULL
592
-     */
593
-    public static function get_default_creator_id()
594
-    {
595
-        global $wpdb;
596
-        if ( ! empty(self::$_default_creator_id)) {
597
-            return self::$_default_creator_id;
598
-        }/**/
599
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
600
-        //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.
601
-        $pre_filtered_id = apply_filters(
602
-            'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
603
-            false,
604
-            $role_to_check
605
-        );
606
-        if ($pre_filtered_id !== false) {
607
-            return (int)$pre_filtered_id;
608
-        }
609
-        $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
610
-        $query = $wpdb->prepare(
611
-            "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
612
-            '%' . $role_to_check . '%'
613
-        );
614
-        $user_id = $wpdb->get_var($query);
615
-        $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
616
-        if ($user_id && (int)$user_id) {
617
-            self::$_default_creator_id = (int)$user_id;
618
-            return self::$_default_creator_id;
619
-        } else {
620
-            return null;
621
-        }
622
-    }
623
-
624
-
625
-
626
-    /**
627
-     * used by EE and EE addons during plugin activation to create tables.
628
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
629
-     * but includes extra logic regarding activations.
630
-     *
631
-     * @access public
632
-     * @static
633
-     * @param string  $table_name              without the $wpdb->prefix
634
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
635
-     *                                         table query)
636
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
637
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
638
-     *                                         and new once this function is done (ie, you really do want to CREATE a
639
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
640
-     *                                         you just want to verify the table exists and matches this definition
641
-     *                                         (and if it HAS data in it you want to leave it be)
642
-     * @return void
643
-     * @throws EE_Error if there are database errors
644
-     */
645
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
646
-    {
647
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
648
-            return;
649
-        }
650
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
651
-        if ( ! function_exists('dbDelta')) {
652
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
653
-        }
654
-        $tableAnalysis = \EEH_Activation::getTableAnalysis();
655
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
656
-        // do we need to first delete an existing version of this table ?
657
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
658
-            // ok, delete the table... but ONLY if it's empty
659
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
660
-            // table is NOT empty, are you SURE you want to delete this table ???
661
-            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
662
-                \EEH_Activation::getTableManager()->dropTable($wp_table_name);
663
-            } else if ( ! $deleted_safely) {
664
-                // so we should be more cautious rather than just dropping tables so easily
665
-                error_log(
666
-                    sprintf(
667
-                        __(
668
-                            '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.',
669
-                            'event_espresso'
670
-                        ),
671
-                        $wp_table_name,
672
-                        '<br/>',
673
-                        'espresso_db_update'
674
-                    )
675
-                );
676
-            }
677
-        }
678
-        $engine = str_replace('ENGINE=', '', $engine);
679
-        \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
680
-    }
681
-
682
-
683
-
684
-    /**
685
-     *    add_column_if_it_doesn't_exist
686
-     *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
687
-     *
688
-     * @access     public
689
-     * @static
690
-     * @deprecated instead use TableManager::addColumn()
691
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
692
-     * @param string $column_name
693
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
694
-     *                            'VARCHAR(10)'
695
-     * @return bool|int
696
-     */
697
-    public static function add_column_if_it_doesnt_exist(
698
-        $table_name,
699
-        $column_name,
700
-        $column_info = 'INT UNSIGNED NOT NULL'
701
-    ) {
702
-        return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
703
-    }
704
-
705
-
706
-    /**
707
-     * get_fields_on_table
708
-     * Gets all the fields on the database table.
709
-     *
710
-     * @access     public
711
-     * @deprecated instead use TableManager::getTableColumns()
712
-     * @static
713
-     * @param string $table_name , without prefixed $wpdb->prefix
714
-     * @return array of database column names
715
-     */
716
-    public static function get_fields_on_table($table_name = null)
717
-    {
718
-        return \EEH_Activation::getTableManager()->getTableColumns($table_name);
719
-    }
720
-
721
-
722
-    /**
723
-     * db_table_is_empty
724
-     *
725
-     * @access     public\
726
-     * @deprecated instead use TableAnalysis::tableIsEmpty()
727
-     * @static
728
-     * @param string $table_name
729
-     * @return bool
730
-     */
731
-    public static function db_table_is_empty($table_name)
732
-    {
733
-        return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
734
-    }
735
-
736
-
737
-    /**
738
-     * delete_db_table_if_empty
739
-     *
740
-     * @access public
741
-     * @static
742
-     * @param string $table_name
743
-     * @return bool | int
744
-     */
745
-    public static function delete_db_table_if_empty($table_name)
746
-    {
747
-        if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
748
-            return \EEH_Activation::getTableManager()->dropTable($table_name);
749
-        }
750
-        return false;
751
-    }
752
-
753
-
754
-    /**
755
-     * delete_unused_db_table
756
-     *
757
-     * @access     public
758
-     * @static
759
-     * @deprecated instead use TableManager::dropTable()
760
-     * @param string $table_name
761
-     * @return bool | int
762
-     */
763
-    public static function delete_unused_db_table($table_name)
764
-    {
765
-        return \EEH_Activation::getTableManager()->dropTable($table_name);
766
-    }
767
-
768
-
769
-    /**
770
-     * drop_index
771
-     *
772
-     * @access     public
773
-     * @static
774
-     * @deprecated instead use TableManager::dropIndex()
775
-     * @param string $table_name
776
-     * @param string $index_name
777
-     * @return bool | int
778
-     */
779
-    public static function drop_index($table_name, $index_name)
780
-    {
781
-        return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
782
-    }
783
-
784
-
785
-
786
-    /**
787
-     * create_database_tables
788
-     *
789
-     * @access public
790
-     * @static
791
-     * @throws EE_Error
792
-     * @return boolean success (whether database is setup properly or not)
793
-     */
794
-    public static function create_database_tables()
795
-    {
796
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
797
-        //find the migration script that sets the database to be compatible with the code
798
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
799
-        if ($dms_name) {
800
-            $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
801
-            $current_data_migration_script->set_migrating(false);
802
-            $current_data_migration_script->schema_changes_before_migration();
803
-            $current_data_migration_script->schema_changes_after_migration();
804
-            if ($current_data_migration_script->get_errors()) {
805
-                if (WP_DEBUG) {
806
-                    foreach ($current_data_migration_script->get_errors() as $error) {
807
-                        EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
808
-                    }
809
-                } else {
810
-                    EE_Error::add_error(
811
-                        __(
812
-                            'There were errors creating the Event Espresso database tables and Event Espresso has been 
265
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
266
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
267
+			if (is_array($hooks_to_fire_at_time)) {
268
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
269
+					if (isset($ee_cron_tasks_to_remove[$hook_name])
270
+						&& is_array($ee_cron_tasks_to_remove[$hook_name])
271
+					) {
272
+						unset($crons[$timestamp][$hook_name]);
273
+					}
274
+				}
275
+				//also take care of any empty cron timestamps.
276
+				if (empty($hooks_to_fire_at_time)) {
277
+					unset($crons[$timestamp]);
278
+				}
279
+			}
280
+		}
281
+		_set_cron_array($crons);
282
+	}
283
+
284
+
285
+	/**
286
+	 *    CPT_initialization
287
+	 *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
288
+	 *
289
+	 * @access public
290
+	 * @static
291
+	 * @return void
292
+	 */
293
+	public static function CPT_initialization()
294
+	{
295
+		// register Custom Post Types
296
+		EE_Registry::instance()->load_core('Register_CPTs');
297
+		flush_rewrite_rules();
298
+	}
299
+
300
+
301
+
302
+	/**
303
+	 *    reset_and_update_config
304
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
305
+	 * If there is old calendar config data saved, then it will get converted on activation.
306
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
307
+	 *
308
+	 * @access public
309
+	 * @static
310
+	 * @return void
311
+	 */
312
+	public static function reset_and_update_config()
313
+	{
314
+		do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
315
+		add_filter(
316
+			'FHEE__EE_Config___load_core_config__config_settings',
317
+			array('EEH_Activation', 'migrate_old_config_data'),
318
+			10,
319
+			3
320
+		);
321
+		//EE_Config::reset();
322
+		if (! EE_Config::logging_enabled()) {
323
+			delete_option(EE_Config::LOG_NAME);
324
+		}
325
+	}
326
+
327
+
328
+	/**
329
+	 *    load_calendar_config
330
+	 *
331
+	 * @access    public
332
+	 * @return    void
333
+	 */
334
+	public static function load_calendar_config()
335
+	{
336
+		// grab array of all plugin folders and loop thru it
337
+		$plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
338
+		if (empty($plugins)) {
339
+			return;
340
+		}
341
+		foreach ($plugins as $plugin_path) {
342
+			// grab plugin folder name from path
343
+			$plugin = basename($plugin_path);
344
+			// drill down to Espresso plugins
345
+			// then to calendar related plugins
346
+			if (
347
+				strpos($plugin, 'espresso') !== false
348
+				|| strpos($plugin, 'Espresso') !== false
349
+				|| strpos($plugin, 'ee4') !== false
350
+				|| strpos($plugin, 'EE4') !== false
351
+				|| strpos($plugin, 'calendar') !== false
352
+			) {
353
+				// this is what we are looking for
354
+				$calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
355
+				// does it exist in this folder ?
356
+				if (is_readable($calendar_config)) {
357
+					// YEAH! let's load it
358
+					require_once($calendar_config);
359
+				}
360
+			}
361
+		}
362
+	}
363
+
364
+
365
+
366
+	/**
367
+	 *    _migrate_old_config_data
368
+	 *
369
+	 * @access    public
370
+	 * @param array|stdClass $settings
371
+	 * @param string         $config
372
+	 * @param \EE_Config     $EE_Config
373
+	 * @return \stdClass
374
+	 */
375
+	public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
376
+	{
377
+		$convert_from_array = array('addons');
378
+		// in case old settings were saved as an array
379
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
380
+			// convert existing settings to an object
381
+			$config_array = $settings;
382
+			$settings = new stdClass();
383
+			foreach ($config_array as $key => $value) {
384
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
385
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
386
+				} else {
387
+					$settings->{$key} = $value;
388
+				}
389
+			}
390
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
391
+		}
392
+		return $settings;
393
+	}
394
+
395
+
396
+	/**
397
+	 * deactivate_event_espresso
398
+	 *
399
+	 * @access public
400
+	 * @static
401
+	 * @return void
402
+	 */
403
+	public static function deactivate_event_espresso()
404
+	{
405
+		// check permissions
406
+		if (current_user_can('activate_plugins')) {
407
+			deactivate_plugins(EE_PLUGIN_BASENAME, true);
408
+		}
409
+	}
410
+
411
+
412
+
413
+	/**
414
+	 * verify_default_pages_exist
415
+	 *
416
+	 * @access public
417
+	 * @static
418
+	 * @return void
419
+	 * @throws InvalidDataTypeException
420
+	 */
421
+	public static function verify_default_pages_exist()
422
+	{
423
+		$critical_page_problem = false;
424
+		$critical_pages = array(
425
+			array(
426
+				'id'   => 'reg_page_id',
427
+				'name' => __('Registration Checkout', 'event_espresso'),
428
+				'post' => null,
429
+				'code' => 'ESPRESSO_CHECKOUT',
430
+			),
431
+			array(
432
+				'id'   => 'txn_page_id',
433
+				'name' => __('Transactions', 'event_espresso'),
434
+				'post' => null,
435
+				'code' => 'ESPRESSO_TXN_PAGE',
436
+			),
437
+			array(
438
+				'id'   => 'thank_you_page_id',
439
+				'name' => __('Thank You', 'event_espresso'),
440
+				'post' => null,
441
+				'code' => 'ESPRESSO_THANK_YOU',
442
+			),
443
+			array(
444
+				'id'   => 'cancel_page_id',
445
+				'name' => __('Registration Cancelled', 'event_espresso'),
446
+				'post' => null,
447
+				'code' => 'ESPRESSO_CANCELLED',
448
+			),
449
+		);
450
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
451
+		foreach ($critical_pages as $critical_page) {
452
+			// is critical page ID set in config ?
453
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
454
+				// attempt to find post by ID
455
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
456
+			}
457
+			// no dice?
458
+			if ($critical_page['post'] === null) {
459
+				// attempt to find post by title
460
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
461
+				// still nothing?
462
+				if ($critical_page['post'] === null) {
463
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
464
+					// REALLY? Still nothing ??!?!?
465
+					if ($critical_page['post'] === null) {
466
+						$msg = __(
467
+							'The Event Espresso critical page configuration settings could not be updated.',
468
+							'event_espresso'
469
+						);
470
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
471
+						break;
472
+					}
473
+				}
474
+			}
475
+			// check that Post ID matches critical page ID in config
476
+			if (
477
+				isset($critical_page['post']->ID)
478
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
479
+			) {
480
+				//update Config with post ID
481
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
482
+				if (! EE_Config::instance()->update_espresso_config(false, false)) {
483
+					$msg = __(
484
+						'The Event Espresso critical page configuration settings could not be updated.',
485
+						'event_espresso'
486
+					);
487
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
488
+				}
489
+			}
490
+			$critical_page_problem =
491
+				! isset($critical_page['post']->post_status)
492
+				|| $critical_page['post']->post_status !== 'publish'
493
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
494
+					? true
495
+					: $critical_page_problem;
496
+		}
497
+		if ($critical_page_problem) {
498
+			new PersistentAdminNotice(
499
+				'critical_page_problem',
500
+				sprintf(
501
+					esc_html__(
502
+						'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
503
+						'event_espresso'
504
+					),
505
+					'<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
506
+					. __('Event Espresso Critical Pages Settings', 'event_espresso')
507
+					. '</a>'
508
+				)
509
+			);
510
+		}
511
+		if (EE_Error::has_notices()) {
512
+			EE_Error::get_notices(false, true, true);
513
+		}
514
+	}
515
+
516
+
517
+
518
+	/**
519
+	 * Returns the first post which uses the specified shortcode
520
+	 *
521
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
522
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
523
+	 *                             "[ESPRESSO_THANK_YOU"
524
+	 *                             (we don't search for the closing shortcode bracket because they might have added
525
+	 *                             parameter to the shortcode
526
+	 * @return WP_Post or NULl
527
+	 */
528
+	public static function get_page_by_ee_shortcode($ee_shortcode)
529
+	{
530
+		global $wpdb;
531
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
532
+		$post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
533
+		if ($post_id) {
534
+			return get_post($post_id);
535
+		} else {
536
+			return null;
537
+		}
538
+	}
539
+
540
+
541
+	/**
542
+	 *    This function generates a post for critical espresso pages
543
+	 *
544
+	 * @access public
545
+	 * @static
546
+	 * @param array $critical_page
547
+	 * @return array
548
+	 */
549
+	public static function create_critical_page($critical_page)
550
+	{
551
+
552
+		$post_args = array(
553
+			'post_title'     => $critical_page['name'],
554
+			'post_status'    => 'publish',
555
+			'post_type'      => 'page',
556
+			'comment_status' => 'closed',
557
+			'post_content'   => '[' . $critical_page['code'] . ']',
558
+		);
559
+
560
+		$post_id = wp_insert_post($post_args);
561
+		if (! $post_id) {
562
+			$msg = sprintf(
563
+				__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
564
+				$critical_page['name']
565
+			);
566
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
567
+			return $critical_page;
568
+		}
569
+		// get newly created post's details
570
+		if (! $critical_page['post'] = get_post($post_id)) {
571
+			$msg = sprintf(
572
+				__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
573
+				$critical_page['name']
574
+			);
575
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
576
+		}
577
+
578
+		return $critical_page;
579
+
580
+	}
581
+
582
+
583
+
584
+
585
+	/**
586
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
587
+	 * The role being used to check is filterable.
588
+	 *
589
+	 * @since  4.6.0
590
+	 * @global WPDB $wpdb
591
+	 * @return mixed null|int WP_user ID or NULL
592
+	 */
593
+	public static function get_default_creator_id()
594
+	{
595
+		global $wpdb;
596
+		if ( ! empty(self::$_default_creator_id)) {
597
+			return self::$_default_creator_id;
598
+		}/**/
599
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
600
+		//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.
601
+		$pre_filtered_id = apply_filters(
602
+			'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
603
+			false,
604
+			$role_to_check
605
+		);
606
+		if ($pre_filtered_id !== false) {
607
+			return (int)$pre_filtered_id;
608
+		}
609
+		$capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
610
+		$query = $wpdb->prepare(
611
+			"SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
612
+			'%' . $role_to_check . '%'
613
+		);
614
+		$user_id = $wpdb->get_var($query);
615
+		$user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
616
+		if ($user_id && (int)$user_id) {
617
+			self::$_default_creator_id = (int)$user_id;
618
+			return self::$_default_creator_id;
619
+		} else {
620
+			return null;
621
+		}
622
+	}
623
+
624
+
625
+
626
+	/**
627
+	 * used by EE and EE addons during plugin activation to create tables.
628
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
629
+	 * but includes extra logic regarding activations.
630
+	 *
631
+	 * @access public
632
+	 * @static
633
+	 * @param string  $table_name              without the $wpdb->prefix
634
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
635
+	 *                                         table query)
636
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
637
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
638
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
639
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
640
+	 *                                         you just want to verify the table exists and matches this definition
641
+	 *                                         (and if it HAS data in it you want to leave it be)
642
+	 * @return void
643
+	 * @throws EE_Error if there are database errors
644
+	 */
645
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
646
+	{
647
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
648
+			return;
649
+		}
650
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
651
+		if ( ! function_exists('dbDelta')) {
652
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
653
+		}
654
+		$tableAnalysis = \EEH_Activation::getTableAnalysis();
655
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
656
+		// do we need to first delete an existing version of this table ?
657
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
658
+			// ok, delete the table... but ONLY if it's empty
659
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
660
+			// table is NOT empty, are you SURE you want to delete this table ???
661
+			if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
662
+				\EEH_Activation::getTableManager()->dropTable($wp_table_name);
663
+			} else if ( ! $deleted_safely) {
664
+				// so we should be more cautious rather than just dropping tables so easily
665
+				error_log(
666
+					sprintf(
667
+						__(
668
+							'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.',
669
+							'event_espresso'
670
+						),
671
+						$wp_table_name,
672
+						'<br/>',
673
+						'espresso_db_update'
674
+					)
675
+				);
676
+			}
677
+		}
678
+		$engine = str_replace('ENGINE=', '', $engine);
679
+		\EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
680
+	}
681
+
682
+
683
+
684
+	/**
685
+	 *    add_column_if_it_doesn't_exist
686
+	 *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
687
+	 *
688
+	 * @access     public
689
+	 * @static
690
+	 * @deprecated instead use TableManager::addColumn()
691
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
692
+	 * @param string $column_name
693
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
694
+	 *                            'VARCHAR(10)'
695
+	 * @return bool|int
696
+	 */
697
+	public static function add_column_if_it_doesnt_exist(
698
+		$table_name,
699
+		$column_name,
700
+		$column_info = 'INT UNSIGNED NOT NULL'
701
+	) {
702
+		return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
703
+	}
704
+
705
+
706
+	/**
707
+	 * get_fields_on_table
708
+	 * Gets all the fields on the database table.
709
+	 *
710
+	 * @access     public
711
+	 * @deprecated instead use TableManager::getTableColumns()
712
+	 * @static
713
+	 * @param string $table_name , without prefixed $wpdb->prefix
714
+	 * @return array of database column names
715
+	 */
716
+	public static function get_fields_on_table($table_name = null)
717
+	{
718
+		return \EEH_Activation::getTableManager()->getTableColumns($table_name);
719
+	}
720
+
721
+
722
+	/**
723
+	 * db_table_is_empty
724
+	 *
725
+	 * @access     public\
726
+	 * @deprecated instead use TableAnalysis::tableIsEmpty()
727
+	 * @static
728
+	 * @param string $table_name
729
+	 * @return bool
730
+	 */
731
+	public static function db_table_is_empty($table_name)
732
+	{
733
+		return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
734
+	}
735
+
736
+
737
+	/**
738
+	 * delete_db_table_if_empty
739
+	 *
740
+	 * @access public
741
+	 * @static
742
+	 * @param string $table_name
743
+	 * @return bool | int
744
+	 */
745
+	public static function delete_db_table_if_empty($table_name)
746
+	{
747
+		if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
748
+			return \EEH_Activation::getTableManager()->dropTable($table_name);
749
+		}
750
+		return false;
751
+	}
752
+
753
+
754
+	/**
755
+	 * delete_unused_db_table
756
+	 *
757
+	 * @access     public
758
+	 * @static
759
+	 * @deprecated instead use TableManager::dropTable()
760
+	 * @param string $table_name
761
+	 * @return bool | int
762
+	 */
763
+	public static function delete_unused_db_table($table_name)
764
+	{
765
+		return \EEH_Activation::getTableManager()->dropTable($table_name);
766
+	}
767
+
768
+
769
+	/**
770
+	 * drop_index
771
+	 *
772
+	 * @access     public
773
+	 * @static
774
+	 * @deprecated instead use TableManager::dropIndex()
775
+	 * @param string $table_name
776
+	 * @param string $index_name
777
+	 * @return bool | int
778
+	 */
779
+	public static function drop_index($table_name, $index_name)
780
+	{
781
+		return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
782
+	}
783
+
784
+
785
+
786
+	/**
787
+	 * create_database_tables
788
+	 *
789
+	 * @access public
790
+	 * @static
791
+	 * @throws EE_Error
792
+	 * @return boolean success (whether database is setup properly or not)
793
+	 */
794
+	public static function create_database_tables()
795
+	{
796
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
797
+		//find the migration script that sets the database to be compatible with the code
798
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
799
+		if ($dms_name) {
800
+			$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
801
+			$current_data_migration_script->set_migrating(false);
802
+			$current_data_migration_script->schema_changes_before_migration();
803
+			$current_data_migration_script->schema_changes_after_migration();
804
+			if ($current_data_migration_script->get_errors()) {
805
+				if (WP_DEBUG) {
806
+					foreach ($current_data_migration_script->get_errors() as $error) {
807
+						EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
808
+					}
809
+				} else {
810
+					EE_Error::add_error(
811
+						__(
812
+							'There were errors creating the Event Espresso database tables and Event Espresso has been 
813 813
                             deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
814
-                            'event_espresso'
815
-                        )
816
-                    );
817
-                }
818
-                return false;
819
-            }
820
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to();
821
-        } else {
822
-            EE_Error::add_error(
823
-                __(
824
-                    'Could not determine most up-to-date data migration script from which to pull database schema
814
+							'event_espresso'
815
+						)
816
+					);
817
+				}
818
+				return false;
819
+			}
820
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to();
821
+		} else {
822
+			EE_Error::add_error(
823
+				__(
824
+					'Could not determine most up-to-date data migration script from which to pull database schema
825 825
                      structure. So database is probably not setup properly',
826
-                    'event_espresso'
827
-                ),
828
-                __FILE__,
829
-                __FUNCTION__,
830
-                __LINE__
831
-            );
832
-            return false;
833
-        }
834
-        return true;
835
-    }
836
-
837
-
838
-
839
-    /**
840
-     * initialize_system_questions
841
-     *
842
-     * @access public
843
-     * @static
844
-     * @return void
845
-     */
846
-    public static function initialize_system_questions()
847
-    {
848
-        // QUESTION GROUPS
849
-        global $wpdb;
850
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
851
-        $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
852
-        // what we have
853
-        $question_groups = $wpdb->get_col($SQL);
854
-        // check the response
855
-        $question_groups = is_array($question_groups) ? $question_groups : array();
856
-        // what we should have
857
-        $QSG_systems = array(1, 2);
858
-        // loop thru what we should have and compare to what we have
859
-        foreach ($QSG_systems as $QSG_system) {
860
-            // reset values array
861
-            $QSG_values = array();
862
-            // 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)
863
-            if (! in_array("$QSG_system", $question_groups)) {
864
-                // add it
865
-                switch ($QSG_system) {
866
-                    case 1:
867
-                        $QSG_values = array(
868
-                            'QSG_name'            => __('Personal Information', 'event_espresso'),
869
-                            'QSG_identifier'      => 'personal-information-' . time(),
870
-                            'QSG_desc'            => '',
871
-                            'QSG_order'           => 1,
872
-                            'QSG_show_group_name' => 1,
873
-                            'QSG_show_group_desc' => 1,
874
-                            'QSG_system'          => EEM_Question_Group::system_personal,
875
-                            'QSG_deleted'         => 0,
876
-                        );
877
-                        break;
878
-                    case 2:
879
-                        $QSG_values = array(
880
-                            'QSG_name'            => __('Address Information', 'event_espresso'),
881
-                            'QSG_identifier'      => 'address-information-' . time(),
882
-                            'QSG_desc'            => '',
883
-                            'QSG_order'           => 2,
884
-                            'QSG_show_group_name' => 1,
885
-                            'QSG_show_group_desc' => 1,
886
-                            'QSG_system'          => EEM_Question_Group::system_address,
887
-                            'QSG_deleted'         => 0,
888
-                        );
889
-                        break;
890
-                }
891
-                // make sure we have some values before inserting them
892
-                if (! empty($QSG_values)) {
893
-                    // insert system question
894
-                    $wpdb->insert(
895
-                        $table_name,
896
-                        $QSG_values,
897
-                        array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
898
-                    );
899
-                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
900
-                }
901
-            }
902
-        }
903
-        // QUESTIONS
904
-        global $wpdb;
905
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
906
-        $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
907
-        // what we have
908
-        $questions = $wpdb->get_col($SQL);
909
-        // what we should have
910
-        $QST_systems = array(
911
-            'fname',
912
-            'lname',
913
-            'email',
914
-            'address',
915
-            'address2',
916
-            'city',
917
-            'country',
918
-            'state',
919
-            'zip',
920
-            'phone',
921
-        );
922
-        $order_for_group_1 = 1;
923
-        $order_for_group_2 = 1;
924
-        // loop thru what we should have and compare to what we have
925
-        foreach ($QST_systems as $QST_system) {
926
-            // reset values array
927
-            $QST_values = array();
928
-            // if we don't have what we should have
929
-            if (! in_array($QST_system, $questions)) {
930
-                // add it
931
-                switch ($QST_system) {
932
-                    case 'fname':
933
-                        $QST_values = array(
934
-                            'QST_display_text'  => __('First Name', 'event_espresso'),
935
-                            'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
936
-                            'QST_system'        => 'fname',
937
-                            'QST_type'          => 'TEXT',
938
-                            'QST_required'      => 1,
939
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
940
-                            'QST_order'         => 1,
941
-                            'QST_admin_only'    => 0,
942
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
943
-                            'QST_wp_user'       => self::get_default_creator_id(),
944
-                            'QST_deleted'       => 0,
945
-                        );
946
-                        break;
947
-                    case 'lname':
948
-                        $QST_values = array(
949
-                            'QST_display_text'  => __('Last Name', 'event_espresso'),
950
-                            'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
951
-                            'QST_system'        => 'lname',
952
-                            'QST_type'          => 'TEXT',
953
-                            'QST_required'      => 1,
954
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
955
-                            'QST_order'         => 2,
956
-                            'QST_admin_only'    => 0,
957
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
958
-                            'QST_wp_user'       => self::get_default_creator_id(),
959
-                            'QST_deleted'       => 0,
960
-                        );
961
-                        break;
962
-                    case 'email':
963
-                        $QST_values = array(
964
-                            'QST_display_text'  => __('Email Address', 'event_espresso'),
965
-                            'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
966
-                            'QST_system'        => 'email',
967
-                            'QST_type'          => 'EMAIL',
968
-                            'QST_required'      => 1,
969
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
970
-                            'QST_order'         => 3,
971
-                            'QST_admin_only'    => 0,
972
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
973
-                            'QST_wp_user'       => self::get_default_creator_id(),
974
-                            'QST_deleted'       => 0,
975
-                        );
976
-                        break;
977
-                    case 'address':
978
-                        $QST_values = array(
979
-                            'QST_display_text'  => __('Address', 'event_espresso'),
980
-                            'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
981
-                            'QST_system'        => 'address',
982
-                            'QST_type'          => 'TEXT',
983
-                            'QST_required'      => 0,
984
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
985
-                            'QST_order'         => 4,
986
-                            'QST_admin_only'    => 0,
987
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
988
-                            'QST_wp_user'       => self::get_default_creator_id(),
989
-                            'QST_deleted'       => 0,
990
-                        );
991
-                        break;
992
-                    case 'address2':
993
-                        $QST_values = array(
994
-                            'QST_display_text'  => __('Address2', 'event_espresso'),
995
-                            'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
996
-                            'QST_system'        => 'address2',
997
-                            'QST_type'          => 'TEXT',
998
-                            'QST_required'      => 0,
999
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1000
-                            'QST_order'         => 5,
1001
-                            'QST_admin_only'    => 0,
1002
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1003
-                            'QST_wp_user'       => self::get_default_creator_id(),
1004
-                            'QST_deleted'       => 0,
1005
-                        );
1006
-                        break;
1007
-                    case 'city':
1008
-                        $QST_values = array(
1009
-                            'QST_display_text'  => __('City', 'event_espresso'),
1010
-                            'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1011
-                            'QST_system'        => 'city',
1012
-                            'QST_type'          => 'TEXT',
1013
-                            'QST_required'      => 0,
1014
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1015
-                            'QST_order'         => 6,
1016
-                            'QST_admin_only'    => 0,
1017
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1018
-                            'QST_wp_user'       => self::get_default_creator_id(),
1019
-                            'QST_deleted'       => 0,
1020
-                        );
1021
-                        break;
1022
-                    case 'country':
1023
-                        $QST_values = array(
1024
-                            'QST_display_text'  => __('Country', 'event_espresso'),
1025
-                            'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1026
-                            'QST_system'        => 'country',
1027
-                            'QST_type'          => 'COUNTRY',
1028
-                            'QST_required'      => 0,
1029
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1030
-                            'QST_order'         => 7,
1031
-                            'QST_admin_only'    => 0,
1032
-                            'QST_wp_user'       => self::get_default_creator_id(),
1033
-                            'QST_deleted'       => 0,
1034
-                        );
1035
-                        break;
1036
-                    case 'state':
1037
-                        $QST_values = array(
1038
-                            'QST_display_text'  => __('State/Province', 'event_espresso'),
1039
-                            'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1040
-                            'QST_system'        => 'state',
1041
-                            'QST_type'          => 'STATE',
1042
-                            'QST_required'      => 0,
1043
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1044
-                            'QST_order'         => 8,
1045
-                            'QST_admin_only'    => 0,
1046
-                            'QST_wp_user'       => self::get_default_creator_id(),
1047
-                            'QST_deleted'       => 0,
1048
-                        );
1049
-                        break;
1050
-                    case 'zip':
1051
-                        $QST_values = array(
1052
-                            'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1053
-                            'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1054
-                            'QST_system'        => 'zip',
1055
-                            'QST_type'          => 'TEXT',
1056
-                            'QST_required'      => 0,
1057
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1058
-                            'QST_order'         => 9,
1059
-                            'QST_admin_only'    => 0,
1060
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1061
-                            'QST_wp_user'       => self::get_default_creator_id(),
1062
-                            'QST_deleted'       => 0,
1063
-                        );
1064
-                        break;
1065
-                    case 'phone':
1066
-                        $QST_values = array(
1067
-                            'QST_display_text'  => __('Phone Number', 'event_espresso'),
1068
-                            'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1069
-                            'QST_system'        => 'phone',
1070
-                            'QST_type'          => 'TEXT',
1071
-                            'QST_required'      => 0,
1072
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1073
-                            'QST_order'         => 10,
1074
-                            'QST_admin_only'    => 0,
1075
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1076
-                            'QST_wp_user'       => self::get_default_creator_id(),
1077
-                            'QST_deleted'       => 0,
1078
-                        );
1079
-                        break;
1080
-                }
1081
-                if (! empty($QST_values)) {
1082
-                    // insert system question
1083
-                    $wpdb->insert(
1084
-                        $table_name,
1085
-                        $QST_values,
1086
-                        array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1087
-                    );
1088
-                    $QST_ID = $wpdb->insert_id;
1089
-                    // QUESTION GROUP QUESTIONS
1090
-                    if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1091
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1092
-                    } else {
1093
-                        $system_question_we_want = EEM_Question_Group::system_address;
1094
-                    }
1095
-                    if (isset($QSG_IDs[$system_question_we_want])) {
1096
-                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1097
-                    } else {
1098
-                        $id_col = EEM_Question_Group::instance()
1099
-                                                    ->get_col(array(array('QSG_system' => $system_question_we_want)));
1100
-                        if (is_array($id_col)) {
1101
-                            $QSG_ID = reset($id_col);
1102
-                        } else {
1103
-                            //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
1104
-                            EE_Log::instance()->log(
1105
-                                __FILE__,
1106
-                                __FUNCTION__,
1107
-                                sprintf(
1108
-                                    __(
1109
-                                        'Could not associate question %1$s to a question group because no system question
826
+					'event_espresso'
827
+				),
828
+				__FILE__,
829
+				__FUNCTION__,
830
+				__LINE__
831
+			);
832
+			return false;
833
+		}
834
+		return true;
835
+	}
836
+
837
+
838
+
839
+	/**
840
+	 * initialize_system_questions
841
+	 *
842
+	 * @access public
843
+	 * @static
844
+	 * @return void
845
+	 */
846
+	public static function initialize_system_questions()
847
+	{
848
+		// QUESTION GROUPS
849
+		global $wpdb;
850
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
851
+		$SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
852
+		// what we have
853
+		$question_groups = $wpdb->get_col($SQL);
854
+		// check the response
855
+		$question_groups = is_array($question_groups) ? $question_groups : array();
856
+		// what we should have
857
+		$QSG_systems = array(1, 2);
858
+		// loop thru what we should have and compare to what we have
859
+		foreach ($QSG_systems as $QSG_system) {
860
+			// reset values array
861
+			$QSG_values = array();
862
+			// 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)
863
+			if (! in_array("$QSG_system", $question_groups)) {
864
+				// add it
865
+				switch ($QSG_system) {
866
+					case 1:
867
+						$QSG_values = array(
868
+							'QSG_name'            => __('Personal Information', 'event_espresso'),
869
+							'QSG_identifier'      => 'personal-information-' . time(),
870
+							'QSG_desc'            => '',
871
+							'QSG_order'           => 1,
872
+							'QSG_show_group_name' => 1,
873
+							'QSG_show_group_desc' => 1,
874
+							'QSG_system'          => EEM_Question_Group::system_personal,
875
+							'QSG_deleted'         => 0,
876
+						);
877
+						break;
878
+					case 2:
879
+						$QSG_values = array(
880
+							'QSG_name'            => __('Address Information', 'event_espresso'),
881
+							'QSG_identifier'      => 'address-information-' . time(),
882
+							'QSG_desc'            => '',
883
+							'QSG_order'           => 2,
884
+							'QSG_show_group_name' => 1,
885
+							'QSG_show_group_desc' => 1,
886
+							'QSG_system'          => EEM_Question_Group::system_address,
887
+							'QSG_deleted'         => 0,
888
+						);
889
+						break;
890
+				}
891
+				// make sure we have some values before inserting them
892
+				if (! empty($QSG_values)) {
893
+					// insert system question
894
+					$wpdb->insert(
895
+						$table_name,
896
+						$QSG_values,
897
+						array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
898
+					);
899
+					$QSG_IDs[$QSG_system] = $wpdb->insert_id;
900
+				}
901
+			}
902
+		}
903
+		// QUESTIONS
904
+		global $wpdb;
905
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
906
+		$SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
907
+		// what we have
908
+		$questions = $wpdb->get_col($SQL);
909
+		// what we should have
910
+		$QST_systems = array(
911
+			'fname',
912
+			'lname',
913
+			'email',
914
+			'address',
915
+			'address2',
916
+			'city',
917
+			'country',
918
+			'state',
919
+			'zip',
920
+			'phone',
921
+		);
922
+		$order_for_group_1 = 1;
923
+		$order_for_group_2 = 1;
924
+		// loop thru what we should have and compare to what we have
925
+		foreach ($QST_systems as $QST_system) {
926
+			// reset values array
927
+			$QST_values = array();
928
+			// if we don't have what we should have
929
+			if (! in_array($QST_system, $questions)) {
930
+				// add it
931
+				switch ($QST_system) {
932
+					case 'fname':
933
+						$QST_values = array(
934
+							'QST_display_text'  => __('First Name', 'event_espresso'),
935
+							'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
936
+							'QST_system'        => 'fname',
937
+							'QST_type'          => 'TEXT',
938
+							'QST_required'      => 1,
939
+							'QST_required_text' => __('This field is required', 'event_espresso'),
940
+							'QST_order'         => 1,
941
+							'QST_admin_only'    => 0,
942
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
943
+							'QST_wp_user'       => self::get_default_creator_id(),
944
+							'QST_deleted'       => 0,
945
+						);
946
+						break;
947
+					case 'lname':
948
+						$QST_values = array(
949
+							'QST_display_text'  => __('Last Name', 'event_espresso'),
950
+							'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
951
+							'QST_system'        => 'lname',
952
+							'QST_type'          => 'TEXT',
953
+							'QST_required'      => 1,
954
+							'QST_required_text' => __('This field is required', 'event_espresso'),
955
+							'QST_order'         => 2,
956
+							'QST_admin_only'    => 0,
957
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
958
+							'QST_wp_user'       => self::get_default_creator_id(),
959
+							'QST_deleted'       => 0,
960
+						);
961
+						break;
962
+					case 'email':
963
+						$QST_values = array(
964
+							'QST_display_text'  => __('Email Address', 'event_espresso'),
965
+							'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
966
+							'QST_system'        => 'email',
967
+							'QST_type'          => 'EMAIL',
968
+							'QST_required'      => 1,
969
+							'QST_required_text' => __('This field is required', 'event_espresso'),
970
+							'QST_order'         => 3,
971
+							'QST_admin_only'    => 0,
972
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
973
+							'QST_wp_user'       => self::get_default_creator_id(),
974
+							'QST_deleted'       => 0,
975
+						);
976
+						break;
977
+					case 'address':
978
+						$QST_values = array(
979
+							'QST_display_text'  => __('Address', 'event_espresso'),
980
+							'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
981
+							'QST_system'        => 'address',
982
+							'QST_type'          => 'TEXT',
983
+							'QST_required'      => 0,
984
+							'QST_required_text' => __('This field is required', 'event_espresso'),
985
+							'QST_order'         => 4,
986
+							'QST_admin_only'    => 0,
987
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
988
+							'QST_wp_user'       => self::get_default_creator_id(),
989
+							'QST_deleted'       => 0,
990
+						);
991
+						break;
992
+					case 'address2':
993
+						$QST_values = array(
994
+							'QST_display_text'  => __('Address2', 'event_espresso'),
995
+							'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
996
+							'QST_system'        => 'address2',
997
+							'QST_type'          => 'TEXT',
998
+							'QST_required'      => 0,
999
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1000
+							'QST_order'         => 5,
1001
+							'QST_admin_only'    => 0,
1002
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1003
+							'QST_wp_user'       => self::get_default_creator_id(),
1004
+							'QST_deleted'       => 0,
1005
+						);
1006
+						break;
1007
+					case 'city':
1008
+						$QST_values = array(
1009
+							'QST_display_text'  => __('City', 'event_espresso'),
1010
+							'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1011
+							'QST_system'        => 'city',
1012
+							'QST_type'          => 'TEXT',
1013
+							'QST_required'      => 0,
1014
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1015
+							'QST_order'         => 6,
1016
+							'QST_admin_only'    => 0,
1017
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1018
+							'QST_wp_user'       => self::get_default_creator_id(),
1019
+							'QST_deleted'       => 0,
1020
+						);
1021
+						break;
1022
+					case 'country':
1023
+						$QST_values = array(
1024
+							'QST_display_text'  => __('Country', 'event_espresso'),
1025
+							'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1026
+							'QST_system'        => 'country',
1027
+							'QST_type'          => 'COUNTRY',
1028
+							'QST_required'      => 0,
1029
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1030
+							'QST_order'         => 7,
1031
+							'QST_admin_only'    => 0,
1032
+							'QST_wp_user'       => self::get_default_creator_id(),
1033
+							'QST_deleted'       => 0,
1034
+						);
1035
+						break;
1036
+					case 'state':
1037
+						$QST_values = array(
1038
+							'QST_display_text'  => __('State/Province', 'event_espresso'),
1039
+							'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1040
+							'QST_system'        => 'state',
1041
+							'QST_type'          => 'STATE',
1042
+							'QST_required'      => 0,
1043
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1044
+							'QST_order'         => 8,
1045
+							'QST_admin_only'    => 0,
1046
+							'QST_wp_user'       => self::get_default_creator_id(),
1047
+							'QST_deleted'       => 0,
1048
+						);
1049
+						break;
1050
+					case 'zip':
1051
+						$QST_values = array(
1052
+							'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1053
+							'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1054
+							'QST_system'        => 'zip',
1055
+							'QST_type'          => 'TEXT',
1056
+							'QST_required'      => 0,
1057
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1058
+							'QST_order'         => 9,
1059
+							'QST_admin_only'    => 0,
1060
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1061
+							'QST_wp_user'       => self::get_default_creator_id(),
1062
+							'QST_deleted'       => 0,
1063
+						);
1064
+						break;
1065
+					case 'phone':
1066
+						$QST_values = array(
1067
+							'QST_display_text'  => __('Phone Number', 'event_espresso'),
1068
+							'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1069
+							'QST_system'        => 'phone',
1070
+							'QST_type'          => 'TEXT',
1071
+							'QST_required'      => 0,
1072
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1073
+							'QST_order'         => 10,
1074
+							'QST_admin_only'    => 0,
1075
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1076
+							'QST_wp_user'       => self::get_default_creator_id(),
1077
+							'QST_deleted'       => 0,
1078
+						);
1079
+						break;
1080
+				}
1081
+				if (! empty($QST_values)) {
1082
+					// insert system question
1083
+					$wpdb->insert(
1084
+						$table_name,
1085
+						$QST_values,
1086
+						array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1087
+					);
1088
+					$QST_ID = $wpdb->insert_id;
1089
+					// QUESTION GROUP QUESTIONS
1090
+					if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1091
+						$system_question_we_want = EEM_Question_Group::system_personal;
1092
+					} else {
1093
+						$system_question_we_want = EEM_Question_Group::system_address;
1094
+					}
1095
+					if (isset($QSG_IDs[$system_question_we_want])) {
1096
+						$QSG_ID = $QSG_IDs[$system_question_we_want];
1097
+					} else {
1098
+						$id_col = EEM_Question_Group::instance()
1099
+													->get_col(array(array('QSG_system' => $system_question_we_want)));
1100
+						if (is_array($id_col)) {
1101
+							$QSG_ID = reset($id_col);
1102
+						} else {
1103
+							//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
1104
+							EE_Log::instance()->log(
1105
+								__FILE__,
1106
+								__FUNCTION__,
1107
+								sprintf(
1108
+									__(
1109
+										'Could not associate question %1$s to a question group because no system question
1110 1110
                                          group existed',
1111
-                                        'event_espresso'
1112
-                                    ),
1113
-                                    $QST_ID),
1114
-                                'error');
1115
-                            continue;
1116
-                        }
1117
-                    }
1118
-                    // add system questions to groups
1119
-                    $wpdb->insert(
1120
-                        \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1121
-                        array(
1122
-                            'QSG_ID'    => $QSG_ID,
1123
-                            'QST_ID'    => $QST_ID,
1124
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1125
-                        ),
1126
-                        array('%d', '%d', '%d')
1127
-                    );
1128
-                }
1129
-            }
1130
-        }
1131
-    }
1132
-
1133
-
1134
-    /**
1135
-     * Makes sure the default payment method (Invoice) is active.
1136
-     * This used to be done automatically as part of constructing the old gateways config
1137
-     *
1138
-     * @throws \EE_Error
1139
-     */
1140
-    public static function insert_default_payment_methods()
1141
-    {
1142
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1143
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
1144
-            EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1145
-        } else {
1146
-            EEM_Payment_Method::instance()->verify_button_urls();
1147
-        }
1148
-    }
1149
-
1150
-    /**
1151
-     * insert_default_status_codes
1152
-     *
1153
-     * @access public
1154
-     * @static
1155
-     * @return void
1156
-     */
1157
-    public static function insert_default_status_codes()
1158
-    {
1159
-
1160
-        global $wpdb;
1161
-
1162
-        if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1163
-
1164
-            $table_name = EEM_Status::instance()->table();
1165
-
1166
-            $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1167
-            $wpdb->query($SQL);
1168
-
1169
-            $SQL = "INSERT INTO $table_name
1111
+										'event_espresso'
1112
+									),
1113
+									$QST_ID),
1114
+								'error');
1115
+							continue;
1116
+						}
1117
+					}
1118
+					// add system questions to groups
1119
+					$wpdb->insert(
1120
+						\EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1121
+						array(
1122
+							'QSG_ID'    => $QSG_ID,
1123
+							'QST_ID'    => $QST_ID,
1124
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1125
+						),
1126
+						array('%d', '%d', '%d')
1127
+					);
1128
+				}
1129
+			}
1130
+		}
1131
+	}
1132
+
1133
+
1134
+	/**
1135
+	 * Makes sure the default payment method (Invoice) is active.
1136
+	 * This used to be done automatically as part of constructing the old gateways config
1137
+	 *
1138
+	 * @throws \EE_Error
1139
+	 */
1140
+	public static function insert_default_payment_methods()
1141
+	{
1142
+		if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1143
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1144
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1145
+		} else {
1146
+			EEM_Payment_Method::instance()->verify_button_urls();
1147
+		}
1148
+	}
1149
+
1150
+	/**
1151
+	 * insert_default_status_codes
1152
+	 *
1153
+	 * @access public
1154
+	 * @static
1155
+	 * @return void
1156
+	 */
1157
+	public static function insert_default_status_codes()
1158
+	{
1159
+
1160
+		global $wpdb;
1161
+
1162
+		if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1163
+
1164
+			$table_name = EEM_Status::instance()->table();
1165
+
1166
+			$SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1167
+			$wpdb->query($SQL);
1168
+
1169
+			$SQL = "INSERT INTO $table_name
1170 1170
 					(STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES
1171 1171
 					('ACT', 'ACTIVE', 'event', 0, NULL, 1),
1172 1172
 					('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0),
@@ -1206,462 +1206,462 @@  discard block
 block discarded – undo
1206 1206
 					('MID', 'IDLE', 'message', 0, NULL, 1),
1207 1207
 					('MRS', 'RESEND', 'message', 0, NULL, 1),
1208 1208
 					('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);";
1209
-            $wpdb->query($SQL);
1210
-
1211
-        }
1212
-
1213
-    }
1214
-
1215
-
1216
-    /**
1217
-     * generate_default_message_templates
1218
-     *
1219
-     * @static
1220
-     * @throws EE_Error
1221
-     * @return bool     true means new templates were created.
1222
-     *                  false means no templates were created.
1223
-     *                  This is NOT an error flag. To check for errors you will want
1224
-     *                  to use either EE_Error or a try catch for an EE_Error exception.
1225
-     */
1226
-    public static function generate_default_message_templates()
1227
-    {
1228
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1229
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1230
-        /*
1209
+			$wpdb->query($SQL);
1210
+
1211
+		}
1212
+
1213
+	}
1214
+
1215
+
1216
+	/**
1217
+	 * generate_default_message_templates
1218
+	 *
1219
+	 * @static
1220
+	 * @throws EE_Error
1221
+	 * @return bool     true means new templates were created.
1222
+	 *                  false means no templates were created.
1223
+	 *                  This is NOT an error flag. To check for errors you will want
1224
+	 *                  to use either EE_Error or a try catch for an EE_Error exception.
1225
+	 */
1226
+	public static function generate_default_message_templates()
1227
+	{
1228
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1229
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1230
+		/*
1231 1231
          * This first method is taking care of ensuring any default messengers
1232 1232
          * that should be made active and have templates generated are done.
1233 1233
          */
1234
-        $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1235
-            $message_resource_manager
1236
-        );
1237
-        /**
1238
-         * This method is verifying there are no NEW default message types
1239
-         * for ACTIVE messengers that need activated (and corresponding templates setup).
1240
-         */
1241
-        $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1242
-            $message_resource_manager
1243
-        );
1244
-        //after all is done, let's persist these changes to the db.
1245
-        $message_resource_manager->update_has_activated_messengers_option();
1246
-        $message_resource_manager->update_active_messengers_option();
1247
-        // will return true if either of these are true.  Otherwise will return false.
1248
-        return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1249
-    }
1250
-
1251
-
1252
-
1253
-    /**
1254
-     * @param \EE_Message_Resource_Manager $message_resource_manager
1255
-     * @return array|bool
1256
-     * @throws \EE_Error
1257
-     */
1258
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1259
-        EE_Message_Resource_Manager $message_resource_manager
1260
-    ) {
1261
-        /** @type EE_messenger[] $active_messengers */
1262
-        $active_messengers = $message_resource_manager->active_messengers();
1263
-        $installed_message_types = $message_resource_manager->installed_message_types();
1264
-        $templates_created = false;
1265
-        foreach ($active_messengers as $active_messenger) {
1266
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1267
-            $default_message_type_names_to_activate = array();
1268
-            // looping through each default message type reported by the messenger
1269
-            // and setup the actual message types to activate.
1270
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1271
-                // if already active or has already been activated before we skip
1272
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1273
-                // we also skip if the message type is not installed.
1274
-                if (
1275
-                    $message_resource_manager->has_message_type_been_activated_for_messenger(
1276
-                        $default_message_type_name_for_messenger,
1277
-                        $active_messenger->name
1278
-                    )
1279
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1280
-                        $active_messenger->name,
1281
-                        $default_message_type_name_for_messenger
1282
-                    )
1283
-                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1284
-                ) {
1285
-                    continue;
1286
-                }
1287
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1288
-            }
1289
-            //let's activate!
1290
-            $message_resource_manager->ensure_message_types_are_active(
1291
-                $default_message_type_names_to_activate,
1292
-                $active_messenger->name,
1293
-                false
1294
-            );
1295
-            //activate the templates for these message types
1296
-            if ( ! empty($default_message_type_names_to_activate)) {
1297
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1298
-                    $active_messenger->name,
1299
-                    $default_message_type_names_for_messenger,
1300
-                    '',
1301
-                    true
1302
-                );
1303
-            }
1304
-        }
1305
-        return $templates_created;
1306
-    }
1307
-
1308
-
1309
-
1310
-    /**
1311
-     * This will activate and generate default messengers and default message types for those messengers.
1312
-     *
1313
-     * @param EE_message_Resource_Manager $message_resource_manager
1314
-     * @return array|bool  True means there were default messengers and message type templates generated.
1315
-     *                     False means that there were no templates generated
1316
-     *                     (which could simply mean there are no default message types for a messenger).
1317
-     * @throws EE_Error
1318
-     */
1319
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1320
-        EE_Message_Resource_Manager $message_resource_manager
1321
-    ) {
1322
-        /** @type EE_messenger[] $messengers_to_generate */
1323
-        $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1324
-        $installed_message_types = $message_resource_manager->installed_message_types();
1325
-        $templates_generated = false;
1326
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1327
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1328
-            //verify the default message types match an installed message type.
1329
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1330
-                if (
1331
-                    ! isset($installed_message_types[$name])
1332
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger(
1333
-                        $name,
1334
-                        $messenger_to_generate->name
1335
-                    )
1336
-                ) {
1337
-                    unset($default_message_type_names_for_messenger[$key]);
1338
-                }
1339
-            }
1340
-            // in previous iterations, the active_messengers option in the db
1341
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1342
-            // This comment is left here just in case we discover that we _do_ need to update before
1343
-            // passing off to create templates (after the refactor is done).
1344
-            // @todo remove this comment when determined not necessary.
1345
-            $message_resource_manager->activate_messenger(
1346
-                $messenger_to_generate->name,
1347
-                $default_message_type_names_for_messenger,
1348
-                false
1349
-            );
1350
-            //create any templates needing created (or will reactivate templates already generated as necessary).
1351
-            if ( ! empty($default_message_type_names_for_messenger)) {
1352
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1353
-                    $messenger_to_generate->name,
1354
-                    $default_message_type_names_for_messenger,
1355
-                    '',
1356
-                    true
1357
-                );
1358
-            }
1359
-        }
1360
-        return $templates_generated;
1361
-    }
1362
-
1363
-
1364
-    /**
1365
-     * This returns the default messengers to generate templates for on activation of EE.
1366
-     * It considers:
1367
-     * - whether a messenger is already active in the db.
1368
-     * - whether a messenger has been made active at any time in the past.
1369
-     *
1370
-     * @static
1371
-     * @param  EE_Message_Resource_Manager $message_resource_manager
1372
-     * @return EE_messenger[]
1373
-     */
1374
-    protected static function _get_default_messengers_to_generate_on_activation(
1375
-        EE_Message_Resource_Manager $message_resource_manager
1376
-    ) {
1377
-        $active_messengers    = $message_resource_manager->active_messengers();
1378
-        $installed_messengers = $message_resource_manager->installed_messengers();
1379
-        $has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1380
-
1381
-        $messengers_to_generate = array();
1382
-        foreach ($installed_messengers as $installed_messenger) {
1383
-            //if installed messenger is a messenger that should be activated on install
1384
-            //and is not already active
1385
-            //and has never been activated
1386
-            if (
1387
-                ! $installed_messenger->activate_on_install
1388
-                || isset($active_messengers[$installed_messenger->name])
1389
-                || isset($has_activated[$installed_messenger->name])
1390
-            ) {
1391
-                continue;
1392
-            }
1393
-            $messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1394
-        }
1395
-        return $messengers_to_generate;
1396
-    }
1397
-
1398
-
1399
-    /**
1400
-     * This simply validates active message types to ensure they actually match installed
1401
-     * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1402
-     * rows are set inactive.
1403
-     * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1404
-     * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1405
-     * are still handled in here.
1406
-     *
1407
-     * @since 4.3.1
1408
-     * @return void
1409
-     */
1410
-    public static function validate_messages_system()
1411
-    {
1412
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1413
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1414
-        $message_resource_manager->validate_active_message_types_are_installed();
1415
-        do_action('AHEE__EEH_Activation__validate_messages_system');
1416
-    }
1417
-
1418
-
1419
-    /**
1420
-     * create_no_ticket_prices_array
1421
-     *
1422
-     * @access public
1423
-     * @static
1424
-     * @return void
1425
-     */
1426
-    public static function create_no_ticket_prices_array()
1427
-    {
1428
-        // this creates an array for tracking events that have no active ticket prices created
1429
-        // this allows us to warn admins of the situation so that it can be corrected
1430
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1431
-        if (! $espresso_no_ticket_prices) {
1432
-            add_option('ee_no_ticket_prices', array(), '', false);
1433
-        }
1434
-    }
1435
-
1436
-
1437
-    /**
1438
-     * plugin_deactivation
1439
-     *
1440
-     * @access public
1441
-     * @static
1442
-     * @return void
1443
-     */
1444
-    public static function plugin_deactivation()
1445
-    {
1446
-    }
1447
-
1448
-
1449
-    /**
1450
-     * Finds all our EE4 custom post types, and deletes them and their associated data
1451
-     * (like post meta or term relations)
1452
-     *
1453
-     * @global wpdb $wpdb
1454
-     * @throws \EE_Error
1455
-     */
1456
-    public static function delete_all_espresso_cpt_data()
1457
-    {
1458
-        global $wpdb;
1459
-        //get all the CPT post_types
1460
-        $ee_post_types = array();
1461
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1462
-            if (method_exists($model_name, 'instance')) {
1463
-                $model_obj = call_user_func(array($model_name, 'instance'));
1464
-                if ($model_obj instanceof EEM_CPT_Base) {
1465
-                    $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1466
-                }
1467
-            }
1468
-        }
1469
-        //get all our CPTs
1470
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1471
-        $cpt_ids = $wpdb->get_col($query);
1472
-        //delete each post meta and term relations too
1473
-        foreach ($cpt_ids as $post_id) {
1474
-            wp_delete_post($post_id, true);
1475
-        }
1476
-    }
1477
-
1478
-    /**
1479
-     * Deletes all EE custom tables
1480
-     *
1481
-     * @return array
1482
-     */
1483
-    public static function drop_espresso_tables()
1484
-    {
1485
-        $tables = array();
1486
-        // load registry
1487
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1488
-            if (method_exists($model_name, 'instance')) {
1489
-                $model_obj = call_user_func(array($model_name, 'instance'));
1490
-                if ($model_obj instanceof EEM_Base) {
1491
-                    foreach ($model_obj->get_tables() as $table) {
1492
-                        if (strpos($table->get_table_name(), 'esp_')
1493
-                            &&
1494
-                            (
1495
-                                is_main_site()//main site? nuke them all
1496
-                                || ! $table->is_global()//not main site,but not global either. nuke it
1497
-                            )
1498
-                        ) {
1499
-                            $tables[$table->get_table_name()] = $table->get_table_name();
1500
-                        }
1501
-                    }
1502
-                }
1503
-            }
1504
-        }
1505
-
1506
-        //there are some tables whose models were removed.
1507
-        //they should be removed when removing all EE core's data
1508
-        $tables_without_models = array(
1509
-            'esp_promotion',
1510
-            'esp_promotion_applied',
1511
-            'esp_promotion_object',
1512
-            'esp_promotion_rule',
1513
-            'esp_rule',
1514
-        );
1515
-        foreach ($tables_without_models as $table) {
1516
-            $tables[$table] = $table;
1517
-        }
1518
-        return \EEH_Activation::getTableManager()->dropTables($tables);
1519
-    }
1520
-
1521
-
1522
-
1523
-    /**
1524
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1525
-     * each table name provided has a wpdb prefix attached, and that it exists.
1526
-     * Returns the list actually deleted
1527
-     *
1528
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1529
-     * @global WPDB $wpdb
1530
-     * @param array $table_names
1531
-     * @return array of table names which we deleted
1532
-     */
1533
-    public static function drop_tables($table_names)
1534
-    {
1535
-        return \EEH_Activation::getTableManager()->dropTables($table_names);
1536
-    }
1537
-
1538
-
1539
-
1540
-    /**
1541
-     * plugin_uninstall
1542
-     *
1543
-     * @access public
1544
-     * @static
1545
-     * @param bool $remove_all
1546
-     * @return void
1547
-     */
1548
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1549
-    {
1550
-        global $wpdb;
1551
-        self::drop_espresso_tables();
1552
-        $wp_options_to_delete = array(
1553
-            'ee_no_ticket_prices'                => true,
1554
-            'ee_active_messengers'               => true,
1555
-            'ee_has_activated_messenger'         => true,
1556
-            RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true,
1557
-            'ee_config'                          => false,
1558
-            'ee_data_migration_current_db_state' => true,
1559
-            'ee_data_migration_mapping_'         => false,
1560
-            'ee_data_migration_script_'          => false,
1561
-            'ee_data_migrations'                 => true,
1562
-            'ee_dms_map'                         => false,
1563
-            'ee_notices'                         => true,
1564
-            'lang_file_check_'                   => false,
1565
-            'ee_maintenance_mode'                => true,
1566
-            'ee_ueip_optin'                      => true,
1567
-            'ee_ueip_has_notified'               => true,
1568
-            'ee_plugin_activation_errors'        => true,
1569
-            'ee_id_mapping_from'                 => false,
1570
-            'espresso_persistent_admin_notices'  => true,
1571
-            'ee_encryption_key'                  => true,
1572
-            'pue_force_upgrade_'                 => false,
1573
-            'pue_json_error_'                    => false,
1574
-            'pue_install_key_'                   => false,
1575
-            'pue_verification_error_'            => false,
1576
-            'pu_dismissed_upgrade_'              => false,
1577
-            'external_updates-'                  => false,
1578
-            'ee_extra_data'                      => true,
1579
-            'ee_ssn_'                            => false,
1580
-            'ee_rss_'                            => false,
1581
-            'ee_rte_n_tx_'                       => false,
1582
-            'ee_pers_admin_notices'              => true,
1583
-            'ee_job_parameters_'                 => false,
1584
-            'ee_upload_directories_incomplete'   => true,
1585
-            'ee_verified_db_collations'          => true,
1586
-        );
1587
-        if (is_main_site()) {
1588
-            $wp_options_to_delete['ee_network_config'] = true;
1589
-        }
1590
-        $undeleted_options = array();
1591
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1592
-            if ($no_wildcard) {
1593
-                if ( ! delete_option($option_name)) {
1594
-                    $undeleted_options[] = $option_name;
1595
-                }
1596
-            } else {
1597
-                $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1598
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1599
-                    if ( ! delete_option($option_name_from_wildcard)) {
1600
-                        $undeleted_options[] = $option_name_from_wildcard;
1601
-                    }
1602
-                }
1603
-            }
1604
-        }
1605
-        //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1606
-        remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1607
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1608
-            $db_update_sans_ee4 = array();
1609
-            foreach ($espresso_db_update as $version => $times_activated) {
1610
-                if ((string)$version[0] === '3') {//if its NON EE4
1611
-                    $db_update_sans_ee4[$version] = $times_activated;
1612
-                }
1613
-            }
1614
-            update_option('espresso_db_update', $db_update_sans_ee4);
1615
-        }
1616
-        $errors = '';
1617
-        if ( ! empty($undeleted_options)) {
1618
-            $errors .= sprintf(
1619
-                __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1620
-                '<br/>',
1621
-                implode(',<br/>', $undeleted_options)
1622
-            );
1623
-        }
1624
-        if ( ! empty($errors)) {
1625
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1626
-        }
1627
-    }
1628
-
1629
-    /**
1630
-     * Gets the mysql error code from the last used query by wpdb
1631
-     *
1632
-     * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1633
-     */
1634
-    public static function last_wpdb_error_code()
1635
-    {
1636
-        global $wpdb;
1637
-        if ($wpdb->use_mysqli) {
1638
-            return mysqli_errno($wpdb->dbh);
1639
-        } else {
1640
-            return mysql_errno($wpdb->dbh);
1641
-        }
1642
-    }
1643
-
1644
-    /**
1645
-     * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1646
-     *
1647
-     * @global wpdb  $wpdb
1648
-     * @deprecated instead use TableAnalysis::tableExists()
1649
-     * @param string $table_name with or without $wpdb->prefix
1650
-     * @return boolean
1651
-     */
1652
-    public static function table_exists($table_name)
1653
-    {
1654
-        return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1655
-    }
1656
-
1657
-    /**
1658
-     * Resets the cache on EEH_Activation
1659
-     */
1660
-    public static function reset()
1661
-    {
1662
-        self::$_default_creator_id                             = null;
1663
-        self::$_initialized_db_content_already_in_this_request = false;
1664
-    }
1234
+		$new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1235
+			$message_resource_manager
1236
+		);
1237
+		/**
1238
+		 * This method is verifying there are no NEW default message types
1239
+		 * for ACTIVE messengers that need activated (and corresponding templates setup).
1240
+		 */
1241
+		$new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1242
+			$message_resource_manager
1243
+		);
1244
+		//after all is done, let's persist these changes to the db.
1245
+		$message_resource_manager->update_has_activated_messengers_option();
1246
+		$message_resource_manager->update_active_messengers_option();
1247
+		// will return true if either of these are true.  Otherwise will return false.
1248
+		return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1249
+	}
1250
+
1251
+
1252
+
1253
+	/**
1254
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
1255
+	 * @return array|bool
1256
+	 * @throws \EE_Error
1257
+	 */
1258
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1259
+		EE_Message_Resource_Manager $message_resource_manager
1260
+	) {
1261
+		/** @type EE_messenger[] $active_messengers */
1262
+		$active_messengers = $message_resource_manager->active_messengers();
1263
+		$installed_message_types = $message_resource_manager->installed_message_types();
1264
+		$templates_created = false;
1265
+		foreach ($active_messengers as $active_messenger) {
1266
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1267
+			$default_message_type_names_to_activate = array();
1268
+			// looping through each default message type reported by the messenger
1269
+			// and setup the actual message types to activate.
1270
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1271
+				// if already active or has already been activated before we skip
1272
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1273
+				// we also skip if the message type is not installed.
1274
+				if (
1275
+					$message_resource_manager->has_message_type_been_activated_for_messenger(
1276
+						$default_message_type_name_for_messenger,
1277
+						$active_messenger->name
1278
+					)
1279
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1280
+						$active_messenger->name,
1281
+						$default_message_type_name_for_messenger
1282
+					)
1283
+					|| ! isset($installed_message_types[$default_message_type_name_for_messenger])
1284
+				) {
1285
+					continue;
1286
+				}
1287
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1288
+			}
1289
+			//let's activate!
1290
+			$message_resource_manager->ensure_message_types_are_active(
1291
+				$default_message_type_names_to_activate,
1292
+				$active_messenger->name,
1293
+				false
1294
+			);
1295
+			//activate the templates for these message types
1296
+			if ( ! empty($default_message_type_names_to_activate)) {
1297
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1298
+					$active_messenger->name,
1299
+					$default_message_type_names_for_messenger,
1300
+					'',
1301
+					true
1302
+				);
1303
+			}
1304
+		}
1305
+		return $templates_created;
1306
+	}
1307
+
1308
+
1309
+
1310
+	/**
1311
+	 * This will activate and generate default messengers and default message types for those messengers.
1312
+	 *
1313
+	 * @param EE_message_Resource_Manager $message_resource_manager
1314
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1315
+	 *                     False means that there were no templates generated
1316
+	 *                     (which could simply mean there are no default message types for a messenger).
1317
+	 * @throws EE_Error
1318
+	 */
1319
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1320
+		EE_Message_Resource_Manager $message_resource_manager
1321
+	) {
1322
+		/** @type EE_messenger[] $messengers_to_generate */
1323
+		$messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1324
+		$installed_message_types = $message_resource_manager->installed_message_types();
1325
+		$templates_generated = false;
1326
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1327
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1328
+			//verify the default message types match an installed message type.
1329
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1330
+				if (
1331
+					! isset($installed_message_types[$name])
1332
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger(
1333
+						$name,
1334
+						$messenger_to_generate->name
1335
+					)
1336
+				) {
1337
+					unset($default_message_type_names_for_messenger[$key]);
1338
+				}
1339
+			}
1340
+			// in previous iterations, the active_messengers option in the db
1341
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1342
+			// This comment is left here just in case we discover that we _do_ need to update before
1343
+			// passing off to create templates (after the refactor is done).
1344
+			// @todo remove this comment when determined not necessary.
1345
+			$message_resource_manager->activate_messenger(
1346
+				$messenger_to_generate->name,
1347
+				$default_message_type_names_for_messenger,
1348
+				false
1349
+			);
1350
+			//create any templates needing created (or will reactivate templates already generated as necessary).
1351
+			if ( ! empty($default_message_type_names_for_messenger)) {
1352
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1353
+					$messenger_to_generate->name,
1354
+					$default_message_type_names_for_messenger,
1355
+					'',
1356
+					true
1357
+				);
1358
+			}
1359
+		}
1360
+		return $templates_generated;
1361
+	}
1362
+
1363
+
1364
+	/**
1365
+	 * This returns the default messengers to generate templates for on activation of EE.
1366
+	 * It considers:
1367
+	 * - whether a messenger is already active in the db.
1368
+	 * - whether a messenger has been made active at any time in the past.
1369
+	 *
1370
+	 * @static
1371
+	 * @param  EE_Message_Resource_Manager $message_resource_manager
1372
+	 * @return EE_messenger[]
1373
+	 */
1374
+	protected static function _get_default_messengers_to_generate_on_activation(
1375
+		EE_Message_Resource_Manager $message_resource_manager
1376
+	) {
1377
+		$active_messengers    = $message_resource_manager->active_messengers();
1378
+		$installed_messengers = $message_resource_manager->installed_messengers();
1379
+		$has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1380
+
1381
+		$messengers_to_generate = array();
1382
+		foreach ($installed_messengers as $installed_messenger) {
1383
+			//if installed messenger is a messenger that should be activated on install
1384
+			//and is not already active
1385
+			//and has never been activated
1386
+			if (
1387
+				! $installed_messenger->activate_on_install
1388
+				|| isset($active_messengers[$installed_messenger->name])
1389
+				|| isset($has_activated[$installed_messenger->name])
1390
+			) {
1391
+				continue;
1392
+			}
1393
+			$messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1394
+		}
1395
+		return $messengers_to_generate;
1396
+	}
1397
+
1398
+
1399
+	/**
1400
+	 * This simply validates active message types to ensure they actually match installed
1401
+	 * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1402
+	 * rows are set inactive.
1403
+	 * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1404
+	 * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1405
+	 * are still handled in here.
1406
+	 *
1407
+	 * @since 4.3.1
1408
+	 * @return void
1409
+	 */
1410
+	public static function validate_messages_system()
1411
+	{
1412
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1413
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1414
+		$message_resource_manager->validate_active_message_types_are_installed();
1415
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1416
+	}
1417
+
1418
+
1419
+	/**
1420
+	 * create_no_ticket_prices_array
1421
+	 *
1422
+	 * @access public
1423
+	 * @static
1424
+	 * @return void
1425
+	 */
1426
+	public static function create_no_ticket_prices_array()
1427
+	{
1428
+		// this creates an array for tracking events that have no active ticket prices created
1429
+		// this allows us to warn admins of the situation so that it can be corrected
1430
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1431
+		if (! $espresso_no_ticket_prices) {
1432
+			add_option('ee_no_ticket_prices', array(), '', false);
1433
+		}
1434
+	}
1435
+
1436
+
1437
+	/**
1438
+	 * plugin_deactivation
1439
+	 *
1440
+	 * @access public
1441
+	 * @static
1442
+	 * @return void
1443
+	 */
1444
+	public static function plugin_deactivation()
1445
+	{
1446
+	}
1447
+
1448
+
1449
+	/**
1450
+	 * Finds all our EE4 custom post types, and deletes them and their associated data
1451
+	 * (like post meta or term relations)
1452
+	 *
1453
+	 * @global wpdb $wpdb
1454
+	 * @throws \EE_Error
1455
+	 */
1456
+	public static function delete_all_espresso_cpt_data()
1457
+	{
1458
+		global $wpdb;
1459
+		//get all the CPT post_types
1460
+		$ee_post_types = array();
1461
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1462
+			if (method_exists($model_name, 'instance')) {
1463
+				$model_obj = call_user_func(array($model_name, 'instance'));
1464
+				if ($model_obj instanceof EEM_CPT_Base) {
1465
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1466
+				}
1467
+			}
1468
+		}
1469
+		//get all our CPTs
1470
+		$query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1471
+		$cpt_ids = $wpdb->get_col($query);
1472
+		//delete each post meta and term relations too
1473
+		foreach ($cpt_ids as $post_id) {
1474
+			wp_delete_post($post_id, true);
1475
+		}
1476
+	}
1477
+
1478
+	/**
1479
+	 * Deletes all EE custom tables
1480
+	 *
1481
+	 * @return array
1482
+	 */
1483
+	public static function drop_espresso_tables()
1484
+	{
1485
+		$tables = array();
1486
+		// load registry
1487
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1488
+			if (method_exists($model_name, 'instance')) {
1489
+				$model_obj = call_user_func(array($model_name, 'instance'));
1490
+				if ($model_obj instanceof EEM_Base) {
1491
+					foreach ($model_obj->get_tables() as $table) {
1492
+						if (strpos($table->get_table_name(), 'esp_')
1493
+							&&
1494
+							(
1495
+								is_main_site()//main site? nuke them all
1496
+								|| ! $table->is_global()//not main site,but not global either. nuke it
1497
+							)
1498
+						) {
1499
+							$tables[$table->get_table_name()] = $table->get_table_name();
1500
+						}
1501
+					}
1502
+				}
1503
+			}
1504
+		}
1505
+
1506
+		//there are some tables whose models were removed.
1507
+		//they should be removed when removing all EE core's data
1508
+		$tables_without_models = array(
1509
+			'esp_promotion',
1510
+			'esp_promotion_applied',
1511
+			'esp_promotion_object',
1512
+			'esp_promotion_rule',
1513
+			'esp_rule',
1514
+		);
1515
+		foreach ($tables_without_models as $table) {
1516
+			$tables[$table] = $table;
1517
+		}
1518
+		return \EEH_Activation::getTableManager()->dropTables($tables);
1519
+	}
1520
+
1521
+
1522
+
1523
+	/**
1524
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1525
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1526
+	 * Returns the list actually deleted
1527
+	 *
1528
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1529
+	 * @global WPDB $wpdb
1530
+	 * @param array $table_names
1531
+	 * @return array of table names which we deleted
1532
+	 */
1533
+	public static function drop_tables($table_names)
1534
+	{
1535
+		return \EEH_Activation::getTableManager()->dropTables($table_names);
1536
+	}
1537
+
1538
+
1539
+
1540
+	/**
1541
+	 * plugin_uninstall
1542
+	 *
1543
+	 * @access public
1544
+	 * @static
1545
+	 * @param bool $remove_all
1546
+	 * @return void
1547
+	 */
1548
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1549
+	{
1550
+		global $wpdb;
1551
+		self::drop_espresso_tables();
1552
+		$wp_options_to_delete = array(
1553
+			'ee_no_ticket_prices'                => true,
1554
+			'ee_active_messengers'               => true,
1555
+			'ee_has_activated_messenger'         => true,
1556
+			RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true,
1557
+			'ee_config'                          => false,
1558
+			'ee_data_migration_current_db_state' => true,
1559
+			'ee_data_migration_mapping_'         => false,
1560
+			'ee_data_migration_script_'          => false,
1561
+			'ee_data_migrations'                 => true,
1562
+			'ee_dms_map'                         => false,
1563
+			'ee_notices'                         => true,
1564
+			'lang_file_check_'                   => false,
1565
+			'ee_maintenance_mode'                => true,
1566
+			'ee_ueip_optin'                      => true,
1567
+			'ee_ueip_has_notified'               => true,
1568
+			'ee_plugin_activation_errors'        => true,
1569
+			'ee_id_mapping_from'                 => false,
1570
+			'espresso_persistent_admin_notices'  => true,
1571
+			'ee_encryption_key'                  => true,
1572
+			'pue_force_upgrade_'                 => false,
1573
+			'pue_json_error_'                    => false,
1574
+			'pue_install_key_'                   => false,
1575
+			'pue_verification_error_'            => false,
1576
+			'pu_dismissed_upgrade_'              => false,
1577
+			'external_updates-'                  => false,
1578
+			'ee_extra_data'                      => true,
1579
+			'ee_ssn_'                            => false,
1580
+			'ee_rss_'                            => false,
1581
+			'ee_rte_n_tx_'                       => false,
1582
+			'ee_pers_admin_notices'              => true,
1583
+			'ee_job_parameters_'                 => false,
1584
+			'ee_upload_directories_incomplete'   => true,
1585
+			'ee_verified_db_collations'          => true,
1586
+		);
1587
+		if (is_main_site()) {
1588
+			$wp_options_to_delete['ee_network_config'] = true;
1589
+		}
1590
+		$undeleted_options = array();
1591
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1592
+			if ($no_wildcard) {
1593
+				if ( ! delete_option($option_name)) {
1594
+					$undeleted_options[] = $option_name;
1595
+				}
1596
+			} else {
1597
+				$option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1598
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1599
+					if ( ! delete_option($option_name_from_wildcard)) {
1600
+						$undeleted_options[] = $option_name_from_wildcard;
1601
+					}
1602
+				}
1603
+			}
1604
+		}
1605
+		//also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1606
+		remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1607
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1608
+			$db_update_sans_ee4 = array();
1609
+			foreach ($espresso_db_update as $version => $times_activated) {
1610
+				if ((string)$version[0] === '3') {//if its NON EE4
1611
+					$db_update_sans_ee4[$version] = $times_activated;
1612
+				}
1613
+			}
1614
+			update_option('espresso_db_update', $db_update_sans_ee4);
1615
+		}
1616
+		$errors = '';
1617
+		if ( ! empty($undeleted_options)) {
1618
+			$errors .= sprintf(
1619
+				__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1620
+				'<br/>',
1621
+				implode(',<br/>', $undeleted_options)
1622
+			);
1623
+		}
1624
+		if ( ! empty($errors)) {
1625
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1626
+		}
1627
+	}
1628
+
1629
+	/**
1630
+	 * Gets the mysql error code from the last used query by wpdb
1631
+	 *
1632
+	 * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1633
+	 */
1634
+	public static function last_wpdb_error_code()
1635
+	{
1636
+		global $wpdb;
1637
+		if ($wpdb->use_mysqli) {
1638
+			return mysqli_errno($wpdb->dbh);
1639
+		} else {
1640
+			return mysql_errno($wpdb->dbh);
1641
+		}
1642
+	}
1643
+
1644
+	/**
1645
+	 * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1646
+	 *
1647
+	 * @global wpdb  $wpdb
1648
+	 * @deprecated instead use TableAnalysis::tableExists()
1649
+	 * @param string $table_name with or without $wpdb->prefix
1650
+	 * @return boolean
1651
+	 */
1652
+	public static function table_exists($table_name)
1653
+	{
1654
+		return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1655
+	}
1656
+
1657
+	/**
1658
+	 * Resets the cache on EEH_Activation
1659
+	 */
1660
+	public static function reset()
1661
+	{
1662
+		self::$_default_creator_id                             = null;
1663
+		self::$_initialized_db_content_already_in_this_request = false;
1664
+	}
1665 1665
 }
1666 1666
 // End of file EEH_Activation.helper.php
1667 1667
 // Location: /helpers/EEH_Activation.core.php
Please login to merge, or discard this patch.