Completed
Branch BUG-10666-add-check-for-iconv (39eca5)
by
unknown
47:19 queued 36:07
created
core/data_migration_scripts/EE_DMS_Core_4_9_0.dms.php 1 patch
Indentation   +278 added lines, -278 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@  discard block
 block discarded – undo
12 12
 $stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*');
13 13
 $class_to_filepath = array();
14 14
 foreach ($stages as $filepath) {
15
-    $matches = array();
16
-    preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches);
17
-    $class_to_filepath[$matches[1]] = $filepath;
15
+	$matches = array();
16
+	preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches);
17
+	$class_to_filepath[$matches[1]] = $filepath;
18 18
 }
19 19
 //give addons a chance to autoload their stages too
20 20
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages', $class_to_filepath);
@@ -33,68 +33,68 @@  discard block
 block discarded – undo
33 33
 class EE_DMS_Core_4_9_0 extends EE_Data_Migration_Script_Base
34 34
 {
35 35
 
36
-    /**
37
-     * return EE_DMS_Core_4_9_0
38
-     *
39
-     * @param TableManager  $table_manager
40
-     * @param TableAnalysis $table_analysis
41
-     */
42
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
43
-    {
44
-        $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso");
45
-        $this->_priority = 10;
46
-        $this->_migration_stages = array(
47
-            new EE_DMS_4_9_0_Email_System_Question(),
48
-            new EE_DMS_4_9_0_Answers_With_No_Registration(),
49
-        );
50
-        parent::__construct($table_manager, $table_analysis);
51
-    }
36
+	/**
37
+	 * return EE_DMS_Core_4_9_0
38
+	 *
39
+	 * @param TableManager  $table_manager
40
+	 * @param TableAnalysis $table_analysis
41
+	 */
42
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
43
+	{
44
+		$this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso");
45
+		$this->_priority = 10;
46
+		$this->_migration_stages = array(
47
+			new EE_DMS_4_9_0_Email_System_Question(),
48
+			new EE_DMS_4_9_0_Answers_With_No_Registration(),
49
+		);
50
+		parent::__construct($table_manager, $table_analysis);
51
+	}
52 52
 
53 53
 
54 54
 
55
-    /**
56
-     * Whether to migrate or not.
57
-     *
58
-     * @param array $version_array
59
-     * @return bool
60
-     */
61
-    public function can_migrate_from_version($version_array)
62
-    {
63
-        $version_string = $version_array['Core'];
64
-        if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) {
65
-            //			echo "$version_string can be migrated from";
66
-            return true;
67
-        } elseif ( ! $version_string) {
68
-            //			echo "no version string provided: $version_string";
69
-            //no version string provided... this must be pre 4.3
70
-            return false;//changed mind. dont want people thinking they should migrate yet because they cant
71
-        } else {
72
-            //			echo "$version_string doesnt apply";
73
-            return false;
74
-        }
75
-    }
55
+	/**
56
+	 * Whether to migrate or not.
57
+	 *
58
+	 * @param array $version_array
59
+	 * @return bool
60
+	 */
61
+	public function can_migrate_from_version($version_array)
62
+	{
63
+		$version_string = $version_array['Core'];
64
+		if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) {
65
+			//			echo "$version_string can be migrated from";
66
+			return true;
67
+		} elseif ( ! $version_string) {
68
+			//			echo "no version string provided: $version_string";
69
+			//no version string provided... this must be pre 4.3
70
+			return false;//changed mind. dont want people thinking they should migrate yet because they cant
71
+		} else {
72
+			//			echo "$version_string doesnt apply";
73
+			return false;
74
+		}
75
+	}
76 76
 
77 77
 
78 78
 
79
-    /**
80
-     * @return bool
81
-     */
82
-    public function schema_changes_before_migration()
83
-    {
84
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
85
-        $now_in_mysql = current_time('mysql', true);
86
-        $table_name = 'esp_answer';
87
-        $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
79
+	/**
80
+	 * @return bool
81
+	 */
82
+	public function schema_changes_before_migration()
83
+	{
84
+		require_once(EE_HELPERS . 'EEH_Activation.helper.php');
85
+		$now_in_mysql = current_time('mysql', true);
86
+		$table_name = 'esp_answer';
87
+		$sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
88 88
 					REG_ID int(10) unsigned NOT NULL,
89 89
 					QST_ID int(10) unsigned NOT NULL,
90 90
 					ANS_value text NOT NULL,
91 91
 					PRIMARY KEY  (ANS_ID),
92 92
 					KEY REG_ID (REG_ID),
93 93
 					KEY QST_ID (QST_ID)";
94
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
95
-        $table_name = 'esp_attendee_meta';
96
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email');
97
-        $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
94
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
95
+		$table_name = 'esp_attendee_meta';
96
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email');
97
+		$sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
98 98
 				ATT_ID bigint(20) unsigned NOT NULL,
99 99
 				ATT_fname varchar(45) NOT NULL,
100 100
 				ATT_lname varchar(45) NOT NULL,
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 				KEY ATT_email (ATT_email(191)),
112 112
 				KEY ATT_lname (ATT_lname),
113 113
 				KEY ATT_fname (ATT_fname)";
114
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
115
-        $table_name = 'esp_checkin';
116
-        $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
114
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
115
+		$table_name = 'esp_checkin';
116
+		$sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
117 117
 				REG_ID int(10) unsigned NOT NULL,
118 118
 				DTT_ID int(10) unsigned NOT NULL,
119 119
 				CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 				PRIMARY KEY  (CHK_ID),
122 122
 				KEY REG_ID (REG_ID),
123 123
 				KEY DTT_ID (DTT_ID)";
124
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
125
-        $table_name = 'esp_country';
126
-        $sql = "CNT_ISO varchar(2) NOT NULL,
124
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
125
+		$table_name = 'esp_country';
126
+		$sql = "CNT_ISO varchar(2) NOT NULL,
127 127
 				CNT_ISO3 varchar(3) NOT NULL,
128 128
 				RGN_ID tinyint(3) unsigned DEFAULT NULL,
129 129
 				CNT_name varchar(45) NOT NULL,
@@ -139,25 +139,25 @@  discard block
 block discarded – undo
139 139
 				CNT_is_EU tinyint(1) DEFAULT '0',
140 140
 				CNT_active tinyint(1) DEFAULT '0',
141 141
 				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) NOT NULL,
142
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
143
+		$table_name = 'esp_currency';
144
+		$sql = "CUR_code varchar(6) NOT NULL,
145 145
 				CUR_single varchar(45) DEFAULT 'dollar',
146 146
 				CUR_plural varchar(45) DEFAULT 'dollars',
147 147
 				CUR_sign varchar(45) DEFAULT '$',
148 148
 				CUR_dec_plc varchar(1) NOT NULL DEFAULT '2',
149 149
 				CUR_active tinyint(1) DEFAULT '0',
150 150
 				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,
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,
154 154
 				CUR_code varchar(6) NOT NULL,
155 155
 				PMD_ID int(11) NOT NULL,
156 156
 				PRIMARY KEY  (CPM_ID),
157 157
 				KEY PMD_ID (PMD_ID)";
158
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
159
-        $table_name = 'esp_datetime';
160
-        $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
158
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
159
+		$table_name = 'esp_datetime';
160
+		$sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
161 161
 				EVT_ID bigint(20) unsigned NOT NULL,
162 162
 				DTT_name varchar(255) NOT NULL DEFAULT '',
163 163
 				DTT_description text NOT NULL,
@@ -174,25 +174,25 @@  discard block
 block discarded – undo
174 174
 				KEY DTT_EVT_start (DTT_EVT_start),
175 175
 				KEY EVT_ID (EVT_ID),
176 176
 				KEY DTT_is_primary (DTT_is_primary)";
177
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
178
-        $table_name = "esp_datetime_ticket";
179
-        $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
177
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
178
+		$table_name = "esp_datetime_ticket";
179
+		$sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
180 180
 				DTT_ID int(10) unsigned NOT NULL,
181 181
 				TKT_ID int(10) unsigned NOT NULL,
182 182
 				PRIMARY KEY  (DTK_ID),
183 183
 				KEY DTT_ID (DTT_ID),
184 184
 				KEY TKT_ID (TKT_ID)";
185
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
186
-        $table_name = 'esp_event_message_template';
187
-        $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
185
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
186
+		$table_name = 'esp_event_message_template';
187
+		$sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
188 188
 				EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0,
189 189
 				GRP_ID int(10) unsigned NOT NULL DEFAULT 0,
190 190
 				PRIMARY KEY  (EMT_ID),
191 191
 				KEY EVT_ID (EVT_ID),
192 192
 				KEY GRP_ID (GRP_ID)";
193
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
194
-        $table_name = 'esp_event_meta';
195
-        $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
193
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
194
+		$table_name = 'esp_event_meta';
195
+		$sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
196 196
 				EVT_ID bigint(20) unsigned NOT NULL,
197 197
 				EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1,
198 198
 				EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -207,34 +207,34 @@  discard block
 block discarded – undo
207 207
 				EVT_donations tinyint(1) NULL,
208 208
 				PRIMARY KEY  (EVTM_ID),
209 209
 				KEY EVT_ID (EVT_ID)";
210
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
211
-        $table_name = 'esp_event_question_group';
212
-        $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
210
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
211
+		$table_name = 'esp_event_question_group';
212
+		$sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
213 213
 				EVT_ID bigint(20) unsigned NOT NULL,
214 214
 				QSG_ID int(10) unsigned NOT NULL,
215 215
 				EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
216 216
 				PRIMARY KEY  (EQG_ID),
217 217
 				KEY EVT_ID (EVT_ID),
218 218
 				KEY QSG_ID (QSG_ID)";
219
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
220
-        $table_name = 'esp_event_venue';
221
-        $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
219
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
220
+		$table_name = 'esp_event_venue';
221
+		$sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
222 222
 				EVT_ID bigint(20) unsigned NOT NULL,
223 223
 				VNU_ID bigint(20) unsigned NOT NULL,
224 224
 				EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
225 225
 				PRIMARY KEY  (EVV_ID)";
226
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
227
-        $table_name = 'esp_extra_meta';
228
-        $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
226
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
227
+		$table_name = 'esp_extra_meta';
228
+		$sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
229 229
 				OBJ_ID int(11) DEFAULT NULL,
230 230
 				EXM_type varchar(45) DEFAULT NULL,
231 231
 				EXM_key varchar(45) DEFAULT NULL,
232 232
 				EXM_value text,
233 233
 				PRIMARY KEY  (EXM_ID),
234 234
 				KEY EXM_type (EXM_type,OBJ_ID,EXM_key)";
235
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
236
-        $table_name = 'esp_extra_join';
237
-        $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT,
235
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
236
+		$table_name = 'esp_extra_join';
237
+		$sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT,
238 238
 				EXJ_first_model_id varchar(6) NOT NULL,
239 239
 				EXJ_first_model_name varchar(20) NOT NULL,
240 240
 				EXJ_second_model_id varchar(6) NOT NULL,
@@ -242,9 +242,9 @@  discard block
 block discarded – undo
242 242
 				PRIMARY KEY  (EXJ_ID),
243 243
 				KEY first_model (EXJ_first_model_name,EXJ_first_model_id),
244 244
 				KEY second_model (EXJ_second_model_name,EXJ_second_model_id)";
245
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
246
-        $table_name = 'esp_line_item';
247
-        $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
245
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
246
+		$table_name = 'esp_line_item';
247
+		$sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
248 248
 				LIN_code varchar(245) NOT NULL DEFAULT '',
249 249
 				TXN_ID int(11) DEFAULT NULL,
250 250
 				LIN_name varchar(245) NOT NULL DEFAULT '',
@@ -263,9 +263,9 @@  discard block
 block discarded – undo
263 263
 				PRIMARY KEY  (LIN_ID),
264 264
 				KEY LIN_code (LIN_code(191)),
265 265
 				KEY TXN_ID (TXN_ID)";
266
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
267
-        $table_name = 'esp_log';
268
-        $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
266
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
267
+		$table_name = 'esp_log';
268
+		$sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
269 269
 				LOG_time datetime DEFAULT NULL,
270 270
 				OBJ_ID varchar(45) DEFAULT NULL,
271 271
 				OBJ_type varchar(45) DEFAULT NULL,
@@ -276,12 +276,12 @@  discard block
 block discarded – undo
276 276
 				KEY LOG_time (LOG_time),
277 277
 				KEY OBJ (OBJ_type,OBJ_ID),
278 278
 				KEY LOG_type (LOG_type)";
279
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
280
-        $table_name = 'esp_message';
281
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to');
282
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from');
283
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject');
284
-        $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
279
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
280
+		$table_name = 'esp_message';
281
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to');
282
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from');
283
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject');
284
+		$sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
285 285
 				GRP_ID int(10) unsigned NULL,
286 286
 				MSG_token varchar(255) NULL,
287 287
 				TXN_ID int(10) unsigned NULL,
@@ -313,18 +313,18 @@  discard block
 block discarded – undo
313 313
 				KEY STS_ID (STS_ID),
314 314
 				KEY MSG_created (MSG_created),
315 315
 				KEY MSG_modified (MSG_modified)";
316
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
317
-        $table_name = 'esp_message_template';
318
-        $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
316
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
317
+		$table_name = 'esp_message_template';
318
+		$sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
319 319
 				GRP_ID int(10) unsigned NOT NULL,
320 320
 				MTP_context varchar(50) NOT NULL,
321 321
 				MTP_template_field varchar(30) NOT NULL,
322 322
 				MTP_content text NOT NULL,
323 323
 				PRIMARY KEY  (MTP_ID),
324 324
 				KEY GRP_ID (GRP_ID)";
325
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
326
-        $table_name = 'esp_message_template_group';
327
-        $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
325
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
326
+		$table_name = 'esp_message_template_group';
327
+		$sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
328 328
 				MTP_user_id int(10) NOT NULL DEFAULT '1',
329 329
 				MTP_name varchar(245) NOT NULL DEFAULT '',
330 330
 				MTP_description varchar(245) NOT NULL DEFAULT '',
@@ -336,9 +336,9 @@  discard block
 block discarded – undo
336 336
 				MTP_is_active tinyint(1) NOT NULL DEFAULT '1',
337 337
 				PRIMARY KEY  (GRP_ID),
338 338
 				KEY MTP_user_id (MTP_user_id)";
339
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
340
-        $table_name = 'esp_payment';
341
-        $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
339
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
340
+		$table_name = 'esp_payment';
341
+		$sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
342 342
 				TXN_ID int(10) unsigned DEFAULT NULL,
343 343
 				STS_ID varchar(3) DEFAULT NULL,
344 344
 				PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -355,9 +355,9 @@  discard block
 block discarded – undo
355 355
 				PRIMARY KEY  (PAY_ID),
356 356
 				KEY PAY_timestamp (PAY_timestamp),
357 357
 				KEY TXN_ID (TXN_ID)";
358
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
359
-        $table_name = 'esp_payment_method';
360
-        $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
358
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
359
+		$table_name = 'esp_payment_method';
360
+		$sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
361 361
 				PMD_type varchar(124) DEFAULT NULL,
362 362
 				PMD_name varchar(255) DEFAULT NULL,
363 363
 				PMD_desc text,
@@ -373,24 +373,24 @@  discard block
 block discarded – undo
373 373
 				PRIMARY KEY  (PMD_ID),
374 374
 				UNIQUE KEY PMD_slug_UNIQUE (PMD_slug),
375 375
 				KEY PMD_type (PMD_type)";
376
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
377
-        $table_name = "esp_ticket_price";
378
-        $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
376
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
377
+		$table_name = "esp_ticket_price";
378
+		$sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
379 379
 				TKT_ID int(10) unsigned NOT NULL,
380 380
 				PRC_ID int(10) unsigned NOT NULL,
381 381
 				PRIMARY KEY  (TKP_ID),
382 382
 				KEY TKT_ID (TKT_ID),
383 383
 				KEY PRC_ID (PRC_ID)";
384
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
385
-        $table_name = "esp_ticket_template";
386
-        $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
384
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
385
+		$table_name = "esp_ticket_template";
386
+		$sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
387 387
 				TTM_name varchar(45) NOT NULL,
388 388
 				TTM_description text,
389 389
 				TTM_file varchar(45),
390 390
 				PRIMARY KEY  (TTM_ID)";
391
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
392
-        $table_name = 'esp_question';
393
-        $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
391
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
392
+		$table_name = 'esp_question';
393
+		$sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
394 394
 				QST_display_text text NOT NULL,
395 395
 				QST_admin_label varchar(255) NOT NULL,
396 396
 				QST_system varchar(25) DEFAULT NULL,
@@ -404,18 +404,18 @@  discard block
 block discarded – undo
404 404
 				QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0,
405 405
 				PRIMARY KEY  (QST_ID),
406 406
 				KEY QST_order (QST_order)';
407
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
408
-        $table_name = 'esp_question_group_question';
409
-        $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
407
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
408
+		$table_name = 'esp_question_group_question';
409
+		$sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
410 410
 				QSG_ID int(10) unsigned NOT NULL,
411 411
 				QST_ID int(10) unsigned NOT NULL,
412 412
 				QGQ_order int(10) unsigned NOT NULL DEFAULT 0,
413 413
 				PRIMARY KEY  (QGQ_ID),
414 414
 				KEY QST_ID (QST_ID),
415 415
 				KEY QSG_ID_order (QSG_ID,QGQ_order)";
416
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
417
-        $table_name = 'esp_question_option';
418
-        $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
416
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
417
+		$table_name = 'esp_question_option';
418
+		$sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
419 419
 				QSO_value varchar(255) NOT NULL,
420 420
 				QSO_desc text NOT NULL,
421 421
 				QST_ID int(10) unsigned NOT NULL,
@@ -425,9 +425,9 @@  discard block
 block discarded – undo
425 425
 				PRIMARY KEY  (QSO_ID),
426 426
 				KEY QST_ID (QST_ID),
427 427
 				KEY QSO_order (QSO_order)";
428
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
429
-        $table_name = 'esp_registration';
430
-        $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
428
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
429
+		$table_name = 'esp_registration';
430
+		$sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
431 431
 				EVT_ID bigint(20) unsigned NOT NULL,
432 432
 				ATT_ID bigint(20) unsigned NOT NULL,
433 433
 				TXN_ID int(10) unsigned NOT NULL,
@@ -451,18 +451,18 @@  discard block
 block discarded – undo
451 451
 				KEY TKT_ID (TKT_ID),
452 452
 				KEY EVT_ID (EVT_ID),
453 453
 				KEY STS_ID (STS_ID)";
454
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
455
-        $table_name = 'esp_registration_payment';
456
-        $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
454
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
455
+		$table_name = 'esp_registration_payment';
456
+		$sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
457 457
 					  REG_ID int(10) unsigned NOT NULL,
458 458
 					  PAY_ID int(10) unsigned NULL,
459 459
 					  RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00',
460 460
 					  PRIMARY KEY  (RPY_ID),
461 461
 					  KEY REG_ID (REG_ID),
462 462
 					  KEY PAY_ID (PAY_ID)";
463
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
464
-        $table_name = 'esp_state';
465
-        $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
463
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
464
+		$table_name = 'esp_state';
465
+		$sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
466 466
 				CNT_ISO varchar(2) NOT NULL,
467 467
 				STA_abbrev varchar(24) NOT NULL,
468 468
 				STA_name varchar(100) NOT NULL,
@@ -470,9 +470,9 @@  discard block
 block discarded – undo
470 470
 				PRIMARY KEY  (STA_ID),
471 471
 				KEY STA_abbrev (STA_abbrev),
472 472
 				KEY CNT_ISO (CNT_ISO)";
473
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
474
-        $table_name = 'esp_status';
475
-        $sql = "STS_ID varchar(3) NOT NULL,
473
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
474
+		$table_name = 'esp_status';
475
+		$sql = "STS_ID varchar(3) NOT NULL,
476 476
 				STS_code varchar(45) NOT NULL,
477 477
 				STS_type varchar(45) NOT NULL,
478 478
 				STS_can_edit tinyint(1) NOT NULL DEFAULT 0,
@@ -480,9 +480,9 @@  discard block
 block discarded – undo
480 480
 				STS_open tinyint(1) NOT NULL DEFAULT 1,
481 481
 				UNIQUE KEY STS_ID_UNIQUE (STS_ID),
482 482
 				KEY STS_type (STS_type)";
483
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
484
-        $table_name = 'esp_transaction';
485
-        $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
483
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
484
+		$table_name = 'esp_transaction';
485
+		$sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
486 486
 				TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
487 487
 				TXN_total decimal(12,3) DEFAULT '0.00',
488 488
 				TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00',
@@ -494,9 +494,9 @@  discard block
 block discarded – undo
494 494
 				PRIMARY KEY  (TXN_ID),
495 495
 				KEY TXN_timestamp (TXN_timestamp),
496 496
 				KEY STS_ID (STS_ID)";
497
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
498
-        $table_name = 'esp_venue_meta';
499
-        $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
497
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
498
+		$table_name = 'esp_venue_meta';
499
+		$sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
500 500
 			VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0,
501 501
 			VNU_address varchar(255) DEFAULT NULL,
502 502
 			VNU_address2 varchar(255) DEFAULT NULL,
@@ -515,10 +515,10 @@  discard block
 block discarded – undo
515 515
 			KEY VNU_ID (VNU_ID),
516 516
 			KEY STA_ID (STA_ID),
517 517
 			KEY CNT_ISO (CNT_ISO)";
518
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
519
-        //modified tables
520
-        $table_name = "esp_price";
521
-        $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
518
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
519
+		//modified tables
520
+		$table_name = "esp_price";
521
+		$sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
522 522
 				PRT_ID tinyint(3) unsigned NOT NULL,
523 523
 				PRC_amount decimal(12,3) NOT NULL DEFAULT '0.00',
524 524
 				PRC_name varchar(245) NOT NULL,
@@ -531,9 +531,9 @@  discard block
 block discarded – undo
531 531
 				PRC_parent int(10) unsigned DEFAULT 0,
532 532
 				PRIMARY KEY  (PRC_ID),
533 533
 				KEY PRT_ID (PRT_ID)";
534
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
535
-        $table_name = "esp_price_type";
536
-        $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
534
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
535
+		$table_name = "esp_price_type";
536
+		$sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
537 537
 				PRT_name varchar(45) NOT NULL,
538 538
 				PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1',
539 539
 				PRT_is_percent tinyint(1) NOT NULL DEFAULT '0',
@@ -542,9 +542,9 @@  discard block
 block discarded – undo
542 542
 				PRT_deleted tinyint(1) NOT NULL DEFAULT '0',
543 543
 				UNIQUE KEY PRT_name_UNIQUE (PRT_name),
544 544
 				PRIMARY KEY  (PRT_ID)";
545
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
546
-        $table_name = "esp_ticket";
547
-        $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
545
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
546
+		$table_name = "esp_ticket";
547
+		$sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
548 548
 				TTM_ID int(10) unsigned NOT NULL,
549 549
 				TKT_name varchar(245) NOT NULL DEFAULT '',
550 550
 				TKT_description text NOT NULL,
@@ -567,9 +567,9 @@  discard block
 block discarded – undo
567 567
 				TKT_deleted tinyint(1) NOT NULL DEFAULT '0',
568 568
 				PRIMARY KEY  (TKT_ID),
569 569
 				KEY TKT_start_date (TKT_start_date)";
570
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
571
-        $table_name = 'esp_question_group';
572
-        $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
570
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
571
+		$table_name = 'esp_question_group';
572
+		$sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
573 573
 				QSG_name varchar(255) NOT NULL,
574 574
 				QSG_identifier varchar(100) NOT NULL,
575 575
 				QSG_desc text NULL,
@@ -582,138 +582,138 @@  discard block
 block discarded – undo
582 582
 				PRIMARY KEY  (QSG_ID),
583 583
 				UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier),
584 584
 				KEY QSG_order (QSG_order)';
585
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
586
-        /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
587
-        $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
588
-        //(because many need to convert old string states to foreign keys into the states table)
589
-        $script_4_1_defaults->insert_default_states();
590
-        $script_4_1_defaults->insert_default_countries();
591
-        /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
592
-        $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
593
-        $script_4_5_defaults->insert_default_price_types();
594
-        $script_4_5_defaults->insert_default_prices();
595
-        $script_4_5_defaults->insert_default_tickets();
596
-        /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */
597
-        $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0');
598
-        $script_4_6_defaults->add_default_admin_only_payments();
599
-        $script_4_6_defaults->insert_default_currencies();
600
-        /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */
601
-        $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0');
602
-        $script_4_8_defaults->verify_new_countries();
603
-        $script_4_8_defaults->verify_new_currencies();
604
-        $this->verify_db_collations();
605
-        $this->verify_db_collations_again();
606
-        return true;
607
-    }
585
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
586
+		/** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
587
+		$script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
588
+		//(because many need to convert old string states to foreign keys into the states table)
589
+		$script_4_1_defaults->insert_default_states();
590
+		$script_4_1_defaults->insert_default_countries();
591
+		/** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
592
+		$script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
593
+		$script_4_5_defaults->insert_default_price_types();
594
+		$script_4_5_defaults->insert_default_prices();
595
+		$script_4_5_defaults->insert_default_tickets();
596
+		/** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */
597
+		$script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0');
598
+		$script_4_6_defaults->add_default_admin_only_payments();
599
+		$script_4_6_defaults->insert_default_currencies();
600
+		/** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */
601
+		$script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0');
602
+		$script_4_8_defaults->verify_new_countries();
603
+		$script_4_8_defaults->verify_new_currencies();
604
+		$this->verify_db_collations();
605
+		$this->verify_db_collations_again();
606
+		return true;
607
+	}
608 608
 
609 609
 
610 610
 
611
-    /**
612
-     * @return boolean
613
-     */
614
-    public function schema_changes_after_migration()
615
-    {
616
-        return true;
617
-    }
611
+	/**
612
+	 * @return boolean
613
+	 */
614
+	public function schema_changes_after_migration()
615
+	{
616
+		return true;
617
+	}
618 618
 
619 619
 
620 620
 
621
-    public function migration_page_hooks()
622
-    {
623
-    }
621
+	public function migration_page_hooks()
622
+	{
623
+	}
624 624
 
625 625
 
626 626
 
627
-    /**
628
-     * Verify all EE4 models' tables use utf8mb4 collation
629
-     *
630
-     * @return void
631
-     */
632
-    public function verify_db_collations()
633
-    {
634
-        if (get_option('ee_verified_db_collations', false)) {
635
-            return;
636
-        }
637
-        // grab tables from each model
638
-        $tables_to_check = array();
639
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
640
-            if (method_exists($model_name, 'instance')) {
641
-                $model_obj = call_user_func(array($model_name, 'instance'));
642
-                if ($model_obj instanceof EEM_Base) {
643
-                    foreach ($model_obj->get_tables() as $table) {
644
-                        if (
645
-                            strpos($table->get_table_name(), 'esp_')
646
-                            && (is_main_site()//for main tables, verify global tables
647
-                                || ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up)
648
-                            )
649
-                            && function_exists('maybe_convert_table_to_utf8mb4')
650
-                        ) {
651
-                            $tables_to_check[] = $table->get_table_name();
652
-                        }
653
-                    }
654
-                }
655
-            }
656
-        }
657
-        //and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active
658
-        //when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead
659
-        //of hard-coding this
660
-        $addon_tables = array(
661
-            //mailchimp
662
-            'esp_event_mailchimp_list_group',
663
-            'esp_event_question_mailchimp_field',
664
-            //multisite
665
-            'esp_blog_meta',
666
-            //people
667
-            'esp_people_to_post',
668
-            //promotions
669
-            'esp_promotion',
670
-            'esp_promotion_object',
671
-        );
672
-        foreach ($addon_tables as $table_name) {
673
-                $tables_to_check[] = $table_name;
674
-        }
675
-        $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
676
-        //ok and now let's remember this was done (without needing to check the db schemas all over again)
677
-        add_option('ee_verified_db_collations', true, null, 'no');
678
-        //seeing how this ran with the fix from 10435, no need to check again
679
-        add_option('ee_verified_db_collations_again',true,null,'no');
680
-    }
627
+	/**
628
+	 * Verify all EE4 models' tables use utf8mb4 collation
629
+	 *
630
+	 * @return void
631
+	 */
632
+	public function verify_db_collations()
633
+	{
634
+		if (get_option('ee_verified_db_collations', false)) {
635
+			return;
636
+		}
637
+		// grab tables from each model
638
+		$tables_to_check = array();
639
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
640
+			if (method_exists($model_name, 'instance')) {
641
+				$model_obj = call_user_func(array($model_name, 'instance'));
642
+				if ($model_obj instanceof EEM_Base) {
643
+					foreach ($model_obj->get_tables() as $table) {
644
+						if (
645
+							strpos($table->get_table_name(), 'esp_')
646
+							&& (is_main_site()//for main tables, verify global tables
647
+								|| ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up)
648
+							)
649
+							&& function_exists('maybe_convert_table_to_utf8mb4')
650
+						) {
651
+							$tables_to_check[] = $table->get_table_name();
652
+						}
653
+					}
654
+				}
655
+			}
656
+		}
657
+		//and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active
658
+		//when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead
659
+		//of hard-coding this
660
+		$addon_tables = array(
661
+			//mailchimp
662
+			'esp_event_mailchimp_list_group',
663
+			'esp_event_question_mailchimp_field',
664
+			//multisite
665
+			'esp_blog_meta',
666
+			//people
667
+			'esp_people_to_post',
668
+			//promotions
669
+			'esp_promotion',
670
+			'esp_promotion_object',
671
+		);
672
+		foreach ($addon_tables as $table_name) {
673
+				$tables_to_check[] = $table_name;
674
+		}
675
+		$this->_verify_db_collations_for_tables(array_unique($tables_to_check));
676
+		//ok and now let's remember this was done (without needing to check the db schemas all over again)
677
+		add_option('ee_verified_db_collations', true, null, 'no');
678
+		//seeing how this ran with the fix from 10435, no need to check again
679
+		add_option('ee_verified_db_collations_again',true,null,'no');
680
+	}
681 681
 
682 682
 
683 683
 
684
-    /**
685
-     * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435
686
-     * which meant some DB collations might not have been updated
687
-     * @return void
688
-     */
689
-    public function verify_db_collations_again(){
690
-        if (get_option('ee_verified_db_collations_again', false)) {
691
-            return;
692
-        }
693
-        $tables_to_check = array(
694
-            'esp_attendee_meta',
695
-            'esp_message'
696
-        );
697
-        $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
698
-        add_option('ee_verified_db_collations_again',true,null,'no');
699
-    }
684
+	/**
685
+	 * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435
686
+	 * which meant some DB collations might not have been updated
687
+	 * @return void
688
+	 */
689
+	public function verify_db_collations_again(){
690
+		if (get_option('ee_verified_db_collations_again', false)) {
691
+			return;
692
+		}
693
+		$tables_to_check = array(
694
+			'esp_attendee_meta',
695
+			'esp_message'
696
+		);
697
+		$this->_verify_db_collations_for_tables(array_unique($tables_to_check));
698
+		add_option('ee_verified_db_collations_again',true,null,'no');
699
+	}
700 700
 
701 701
 
702 702
 
703
-    /**
704
-     * Runs maybe_convert_table_to_utf8mb4 on the specified tables
705
-     * @param $tables_to_check
706
-     * @return boolean true if logic ran, false if it didn't
707
-     */
708
-    protected function _verify_db_collations_for_tables($tables_to_check)
709
-    {
710
-        foreach ($tables_to_check as $table_name) {
711
-            $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
712
-            if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name )
713
-                && $this->_get_table_analysis()->tableExists($table_name)
714
-            ) {
715
-                maybe_convert_table_to_utf8mb4($table_name);
716
-            }
717
-        }
718
-    }
703
+	/**
704
+	 * Runs maybe_convert_table_to_utf8mb4 on the specified tables
705
+	 * @param $tables_to_check
706
+	 * @return boolean true if logic ran, false if it didn't
707
+	 */
708
+	protected function _verify_db_collations_for_tables($tables_to_check)
709
+	{
710
+		foreach ($tables_to_check as $table_name) {
711
+			$table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
712
+			if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name )
713
+				&& $this->_get_table_analysis()->tableExists($table_name)
714
+			) {
715
+				maybe_convert_table_to_utf8mb4($table_name);
716
+			}
717
+		}
718
+	}
719 719
 }
720 720
\ No newline at end of file
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Addon.lib.php 2 patches
Indentation   +989 added lines, -989 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -19,1048 +19,1048 @@  discard block
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * possibly truncated version of the EE core version string
24
-     *
25
-     * @var string
26
-     */
27
-    protected static $_core_version = '';
22
+	/**
23
+	 * possibly truncated version of the EE core version string
24
+	 *
25
+	 * @var string
26
+	 */
27
+	protected static $_core_version = '';
28 28
 
29
-    /**
30
-     * Holds values for registered addons
31
-     *
32
-     * @var array
33
-     */
34
-    protected static $_settings = array();
29
+	/**
30
+	 * Holds values for registered addons
31
+	 *
32
+	 * @var array
33
+	 */
34
+	protected static $_settings = array();
35 35
 
36
-    /**
37
-     * @var  array $_incompatible_addons keys are addon SLUGS
38
-     * (first argument passed to EE_Register_Addon::register()), keys are
39
-     * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
40
-     * Generally this should be used sparingly, as we don't want to muddle up
41
-     * EE core with knowledge of ALL the addons out there.
42
-     * If you want NO versions of an addon to run with a certain version of core,
43
-     * it's usually best to define the addon's "min_core_version" as part of its call
44
-     * to EE_Register_Addon::register(), rather than using this array with a super high value for its
45
-     * minimum plugin version.
46
-     * @access    protected
47
-     */
48
-    protected static $_incompatible_addons = array(
49
-        'Multi_Event_Registration' => '2.0.11.rc.002',
50
-        'Promotions'               => '1.0.0.rc.084',
51
-    );
36
+	/**
37
+	 * @var  array $_incompatible_addons keys are addon SLUGS
38
+	 * (first argument passed to EE_Register_Addon::register()), keys are
39
+	 * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
40
+	 * Generally this should be used sparingly, as we don't want to muddle up
41
+	 * EE core with knowledge of ALL the addons out there.
42
+	 * If you want NO versions of an addon to run with a certain version of core,
43
+	 * it's usually best to define the addon's "min_core_version" as part of its call
44
+	 * to EE_Register_Addon::register(), rather than using this array with a super high value for its
45
+	 * minimum plugin version.
46
+	 * @access    protected
47
+	 */
48
+	protected static $_incompatible_addons = array(
49
+		'Multi_Event_Registration' => '2.0.11.rc.002',
50
+		'Promotions'               => '1.0.0.rc.084',
51
+	);
52 52
 
53 53
 
54
-    /**
55
-     * We should always be comparing core to a version like '4.3.0.rc.000',
56
-     * not just '4.3.0'.
57
-     * So if the addon developer doesn't provide that full version string,
58
-     * fill in the blanks for them
59
-     *
60
-     * @param string $min_core_version
61
-     * @return string always like '4.3.0.rc.000'
62
-     */
63
-    protected static function _effective_version($min_core_version)
64
-    {
65
-        // versions: 4 . 3 . 1 . p . 123
66
-        // offsets:    0 . 1 . 2 . 3 . 4
67
-        $version_parts = explode('.', $min_core_version);
68
-        //check they specified the micro version (after 2nd period)
69
-        if (! isset($version_parts[2])) {
70
-            $version_parts[2] = '0';
71
-        }
72
-        //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
73
-        //soon we can assume that's 'rc', but this current version is 'alpha'
74
-        if (! isset($version_parts[3])) {
75
-            $version_parts[3] = 'dev';
76
-        }
77
-        if (! isset($version_parts[4])) {
78
-            $version_parts[4] = '000';
79
-        }
80
-        return implode('.', $version_parts);
81
-    }
54
+	/**
55
+	 * We should always be comparing core to a version like '4.3.0.rc.000',
56
+	 * not just '4.3.0'.
57
+	 * So if the addon developer doesn't provide that full version string,
58
+	 * fill in the blanks for them
59
+	 *
60
+	 * @param string $min_core_version
61
+	 * @return string always like '4.3.0.rc.000'
62
+	 */
63
+	protected static function _effective_version($min_core_version)
64
+	{
65
+		// versions: 4 . 3 . 1 . p . 123
66
+		// offsets:    0 . 1 . 2 . 3 . 4
67
+		$version_parts = explode('.', $min_core_version);
68
+		//check they specified the micro version (after 2nd period)
69
+		if (! isset($version_parts[2])) {
70
+			$version_parts[2] = '0';
71
+		}
72
+		//if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
73
+		//soon we can assume that's 'rc', but this current version is 'alpha'
74
+		if (! isset($version_parts[3])) {
75
+			$version_parts[3] = 'dev';
76
+		}
77
+		if (! isset($version_parts[4])) {
78
+			$version_parts[4] = '000';
79
+		}
80
+		return implode('.', $version_parts);
81
+	}
82 82
 
83 83
 
84
-    /**
85
-     * Returns whether or not the min core version requirement of the addon is met
86
-     *
87
-     * @param string $min_core_version    the minimum core version required by the addon
88
-     * @param string $actual_core_version the actual core version, optional
89
-     * @return boolean
90
-     */
91
-    public static function _meets_min_core_version_requirement(
92
-        $min_core_version,
93
-        $actual_core_version = EVENT_ESPRESSO_VERSION
94
-    ) {
95
-        return version_compare(
96
-            self::_effective_version($actual_core_version),
97
-            self::_effective_version($min_core_version),
98
-            '>='
99
-        );
100
-    }
84
+	/**
85
+	 * Returns whether or not the min core version requirement of the addon is met
86
+	 *
87
+	 * @param string $min_core_version    the minimum core version required by the addon
88
+	 * @param string $actual_core_version the actual core version, optional
89
+	 * @return boolean
90
+	 */
91
+	public static function _meets_min_core_version_requirement(
92
+		$min_core_version,
93
+		$actual_core_version = EVENT_ESPRESSO_VERSION
94
+	) {
95
+		return version_compare(
96
+			self::_effective_version($actual_core_version),
97
+			self::_effective_version($min_core_version),
98
+			'>='
99
+		);
100
+	}
101 101
 
102 102
 
103
-    /**
104
-     *    Method for registering new EE_Addons.
105
-     * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
106
-     * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
107
-     * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
108
-     * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
109
-     * 'activate_plugin', it registers the addon still, but its components are not registered
110
-     * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
111
-     * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
112
-     * (so that we can detect that the addon has activated on the subsequent request)
113
-     *
114
-     * @since    4.3.0
115
-     * @param string                  $addon_name                           the EE_Addon's name. Required.
116
-     * @param  array                  $setup_args                           {                                    An
117
-     *                                                                      array of arguments provided for registering
118
-     *                                                                      the message type.
119
-     * @type  string                  $class_name                           the addon's main file name.
120
-     *                                                                      If left blank, generated from the addon
121
-     *                                                                      name, changes something like "calendar" to
122
-     *                                                                      "EE_Calendar"
123
-     * @type string                   $min_core_version                     the minimum version of EE Core that the
124
-     *       addon will work with. eg "4.8.1.rc.084"
125
-     * @type string                   $version                              the "software" version for the addon. eg
126
-     *       "1.0.0.p" for a first stable release, or "1.0.0.rc.043" for a version in progress
127
-     * @type string                   $main_file_path                       the full server path to the main file
128
-     *       loaded
129
-     *                                                                      directly by WP
130
-     * @type string                   $admin_path                           full server path to the folder where the
131
-     *       addon\'s admin files reside
132
-     * @type string                   $admin_callback                       a method to be called when the EE Admin is
133
-     *       first invoked, can be used for hooking into any admin page
134
-     * @type string                   $config_section                       the section name for this addon's
135
-     *       configuration settings section (defaults to "addons")
136
-     * @type string                   $config_class                         the class name for this addon's
137
-     *       configuration settings object
138
-     * @type string                   $config_name                          the class name for this addon's
139
-     *       configuration settings object
140
-     * @type string                   $autoloader_paths                     an array of class names and the full server
141
-     *       paths to those files. Required.
142
-     * @type string                   $autoloader_folders                   an array of  "full server paths" for any
143
-     *       folders containing classes that might be invoked by the addon
144
-     * @type string                   $dms_paths                            an array of full server paths to folders
145
-     *       that contain data migration scripts. Required.
146
-     * @type string                   $module_paths                         an array of full server paths to any
147
-     *       EED_Modules used by the addon
148
-     * @type string                   $shortcode_paths                      an array of full server paths to folders
149
-     *       that contain EES_Shortcodes
150
-     * @type string                   $widget_paths                         an array of full server paths to folders
151
-     *       that contain WP_Widgets
152
-     * @type string                   $pue_options
153
-     * @type array                    $capabilities                         an array indexed by role name
154
-     *                                                                      (i.e administrator,author ) and the values
155
-     *                                                                      are an array of caps to add to the role.
156
-     *                                                                      'administrator' => array(
157
-     *                                                                      'read_addon', 'edit_addon', etc.
158
-     *                                                                      ).
159
-     * @type EE_Meta_Capability_Map[] $capability_maps                      an array of EE_Meta_Capability_Map object
160
-     *       for any addons that need to register any special meta mapped capabilities.  Should be indexed where the
161
-     *       key is the EE_Meta_Capability_Map class name and the values are the arguments sent to the class.
162
-     * @type array                    $model_paths                          array of folders containing DB models
163
-     * @see      EE_Register_Model
164
-     * @type array                    $class_paths                          array of folders containing DB classes
165
-     * @see      EE_Register_Model
166
-     * @type array                    $model_extension_paths                array of folders containing DB model
167
-     *       extensions
168
-     * @see      EE_Register_Model_Extension
169
-     * @type array                    $class_extension_paths                array of folders containing DB class
170
-     *       extensions
171
-     * @see      EE_Register_Model_Extension
172
-     * @type array message_types {
173
-     *                                                                      An array of message types with the key as
174
-     *                                                                      the message type name and the values as
175
-     *                                                                      below:
176
-     * @type string                   $mtfilename                           The filename of the message type being
177
-     *       registered. This will be the main EE_{Messagetype_Name}_message_type class.
178
-     *                                                                      (eg.
179
-     *                                                                      EE_Declined_Registration_message_type.class.php)
180
-     *                                                                      Required.
181
-     * @type array                    $autoloadpaths                        An array of paths to add to the messages
182
-     *                                                                      autoloader for the new message type.
183
-     *                                                                      Required.
184
-     * @type array                    $messengers_to_activate_with          An array of messengers that this message
185
-     *                                                                      type should activate with. Each value in
186
-     *                                                                      the
187
-     *                                                                      array
188
-     *                                                                      should match the name property of a
189
-     *                                                                      EE_messenger. Optional.
190
-     * @type array                    $messengers_to_validate_with          An array of messengers that this message
191
-     *                                                                      type should validate with. Each value in
192
-     *                                                                      the
193
-     *                                                                      array
194
-     *                                                                      should match the name property of an
195
-     *                                                                      EE_messenger.
196
-     *                                                                      Optional.
197
-     *                                                                      }
198
-     * @type array                    $custom_post_types
199
-     * @type array                    $custom_taxonomies
200
-     * @type array                    $payment_method_paths                 each element is the folder containing the
201
-     *                                                                      EE_PMT_Base child class
202
-     *                                                                      (eg,
203
-     *                                                                      '/wp-content/plugins/my_plugin/Payomatic/'
204
-     *                                                                      which contains the files
205
-     *                                                                      EE_PMT_Payomatic.pm.php)
206
-     * @type array                    $default_terms
207
-     * @type array                    $namespace                            {
208
-     *                                                                      An array with two items for registering the
209
-     *                                                                      addon's namespace. (If, for some reason,
210
-     *                                                                      you
211
-     *                                                                      require additional namespaces, use
212
-     *                                                                      EventEspresso\core\Psr4Autoloader::addNamespace()
213
-     *                                                                      directly)
214
-     * @see      EventEspresso\core\Psr4Autoloader::addNamespace()
215
-     * @type string                   $FQNS                                 the namespace prefix
216
-     * @type string                   $DIR                                  a base directory for class files in the
217
-     *       namespace.
218
-     *                                                                      }
219
-     *                                                                      }
220
-     * @throws EE_Error
221
-     * @return void
222
-     */
223
-    public static function register($addon_name = '', $setup_args = array())
224
-    {
225
-        // required fields MUST be present, so let's make sure they are.
226
-        \EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
227
-        // get class name for addon
228
-        $class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
229
-        //setup $_settings array from incoming values.
230
-        $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
231
-        // setup PUE
232
-        \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
233
-        // does this addon work with this version of core or WordPress ?
234
-        if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
235
-            return;
236
-        }
237
-        // register namespaces
238
-        \EE_Register_Addon::_setup_namespaces($addon_settings);
239
-        // check if this is an activation request
240
-        if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
241
-            // dont bother setting up the rest of the addon atm
242
-            return;
243
-        }
244
-        // we need cars
245
-        \EE_Register_Addon::_setup_autoloaders($addon_name);
246
-        // register new models and extensions
247
-        \EE_Register_Addon::_register_models_and_extensions($addon_name);
248
-        // setup DMS
249
-        \EE_Register_Addon::_register_data_migration_scripts($addon_name);
250
-        // if config_class is present let's register config.
251
-        \EE_Register_Addon::_register_config($addon_name);
252
-        // register admin pages
253
-        \EE_Register_Addon::_register_admin_pages($addon_name);
254
-        // add to list of modules to be registered
255
-        \EE_Register_Addon::_register_modules($addon_name);
256
-        // add to list of shortcodes to be registered
257
-        \EE_Register_Addon::_register_shortcodes($addon_name);
258
-        // add to list of widgets to be registered
259
-        \EE_Register_Addon::_register_widgets($addon_name);
260
-        // register capability related stuff.
261
-        \EE_Register_Addon::_register_capabilities($addon_name);
262
-        // any message type to register?
263
-        \EE_Register_Addon::_register_message_types($addon_name);
264
-        // any custom post type/ custom capabilities or default terms to register
265
-        \EE_Register_Addon::_register_custom_post_types($addon_name);
266
-        // and any payment methods
267
-        \EE_Register_Addon::_register_payment_methods($addon_name);
268
-        // load and instantiate main addon class
269
-        $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name);
270
-        $addon->after_registration();
271
-    }
103
+	/**
104
+	 *    Method for registering new EE_Addons.
105
+	 * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
106
+	 * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
107
+	 * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
108
+	 * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
109
+	 * 'activate_plugin', it registers the addon still, but its components are not registered
110
+	 * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
111
+	 * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
112
+	 * (so that we can detect that the addon has activated on the subsequent request)
113
+	 *
114
+	 * @since    4.3.0
115
+	 * @param string                  $addon_name                           the EE_Addon's name. Required.
116
+	 * @param  array                  $setup_args                           {                                    An
117
+	 *                                                                      array of arguments provided for registering
118
+	 *                                                                      the message type.
119
+	 * @type  string                  $class_name                           the addon's main file name.
120
+	 *                                                                      If left blank, generated from the addon
121
+	 *                                                                      name, changes something like "calendar" to
122
+	 *                                                                      "EE_Calendar"
123
+	 * @type string                   $min_core_version                     the minimum version of EE Core that the
124
+	 *       addon will work with. eg "4.8.1.rc.084"
125
+	 * @type string                   $version                              the "software" version for the addon. eg
126
+	 *       "1.0.0.p" for a first stable release, or "1.0.0.rc.043" for a version in progress
127
+	 * @type string                   $main_file_path                       the full server path to the main file
128
+	 *       loaded
129
+	 *                                                                      directly by WP
130
+	 * @type string                   $admin_path                           full server path to the folder where the
131
+	 *       addon\'s admin files reside
132
+	 * @type string                   $admin_callback                       a method to be called when the EE Admin is
133
+	 *       first invoked, can be used for hooking into any admin page
134
+	 * @type string                   $config_section                       the section name for this addon's
135
+	 *       configuration settings section (defaults to "addons")
136
+	 * @type string                   $config_class                         the class name for this addon's
137
+	 *       configuration settings object
138
+	 * @type string                   $config_name                          the class name for this addon's
139
+	 *       configuration settings object
140
+	 * @type string                   $autoloader_paths                     an array of class names and the full server
141
+	 *       paths to those files. Required.
142
+	 * @type string                   $autoloader_folders                   an array of  "full server paths" for any
143
+	 *       folders containing classes that might be invoked by the addon
144
+	 * @type string                   $dms_paths                            an array of full server paths to folders
145
+	 *       that contain data migration scripts. Required.
146
+	 * @type string                   $module_paths                         an array of full server paths to any
147
+	 *       EED_Modules used by the addon
148
+	 * @type string                   $shortcode_paths                      an array of full server paths to folders
149
+	 *       that contain EES_Shortcodes
150
+	 * @type string                   $widget_paths                         an array of full server paths to folders
151
+	 *       that contain WP_Widgets
152
+	 * @type string                   $pue_options
153
+	 * @type array                    $capabilities                         an array indexed by role name
154
+	 *                                                                      (i.e administrator,author ) and the values
155
+	 *                                                                      are an array of caps to add to the role.
156
+	 *                                                                      'administrator' => array(
157
+	 *                                                                      'read_addon', 'edit_addon', etc.
158
+	 *                                                                      ).
159
+	 * @type EE_Meta_Capability_Map[] $capability_maps                      an array of EE_Meta_Capability_Map object
160
+	 *       for any addons that need to register any special meta mapped capabilities.  Should be indexed where the
161
+	 *       key is the EE_Meta_Capability_Map class name and the values are the arguments sent to the class.
162
+	 * @type array                    $model_paths                          array of folders containing DB models
163
+	 * @see      EE_Register_Model
164
+	 * @type array                    $class_paths                          array of folders containing DB classes
165
+	 * @see      EE_Register_Model
166
+	 * @type array                    $model_extension_paths                array of folders containing DB model
167
+	 *       extensions
168
+	 * @see      EE_Register_Model_Extension
169
+	 * @type array                    $class_extension_paths                array of folders containing DB class
170
+	 *       extensions
171
+	 * @see      EE_Register_Model_Extension
172
+	 * @type array message_types {
173
+	 *                                                                      An array of message types with the key as
174
+	 *                                                                      the message type name and the values as
175
+	 *                                                                      below:
176
+	 * @type string                   $mtfilename                           The filename of the message type being
177
+	 *       registered. This will be the main EE_{Messagetype_Name}_message_type class.
178
+	 *                                                                      (eg.
179
+	 *                                                                      EE_Declined_Registration_message_type.class.php)
180
+	 *                                                                      Required.
181
+	 * @type array                    $autoloadpaths                        An array of paths to add to the messages
182
+	 *                                                                      autoloader for the new message type.
183
+	 *                                                                      Required.
184
+	 * @type array                    $messengers_to_activate_with          An array of messengers that this message
185
+	 *                                                                      type should activate with. Each value in
186
+	 *                                                                      the
187
+	 *                                                                      array
188
+	 *                                                                      should match the name property of a
189
+	 *                                                                      EE_messenger. Optional.
190
+	 * @type array                    $messengers_to_validate_with          An array of messengers that this message
191
+	 *                                                                      type should validate with. Each value in
192
+	 *                                                                      the
193
+	 *                                                                      array
194
+	 *                                                                      should match the name property of an
195
+	 *                                                                      EE_messenger.
196
+	 *                                                                      Optional.
197
+	 *                                                                      }
198
+	 * @type array                    $custom_post_types
199
+	 * @type array                    $custom_taxonomies
200
+	 * @type array                    $payment_method_paths                 each element is the folder containing the
201
+	 *                                                                      EE_PMT_Base child class
202
+	 *                                                                      (eg,
203
+	 *                                                                      '/wp-content/plugins/my_plugin/Payomatic/'
204
+	 *                                                                      which contains the files
205
+	 *                                                                      EE_PMT_Payomatic.pm.php)
206
+	 * @type array                    $default_terms
207
+	 * @type array                    $namespace                            {
208
+	 *                                                                      An array with two items for registering the
209
+	 *                                                                      addon's namespace. (If, for some reason,
210
+	 *                                                                      you
211
+	 *                                                                      require additional namespaces, use
212
+	 *                                                                      EventEspresso\core\Psr4Autoloader::addNamespace()
213
+	 *                                                                      directly)
214
+	 * @see      EventEspresso\core\Psr4Autoloader::addNamespace()
215
+	 * @type string                   $FQNS                                 the namespace prefix
216
+	 * @type string                   $DIR                                  a base directory for class files in the
217
+	 *       namespace.
218
+	 *                                                                      }
219
+	 *                                                                      }
220
+	 * @throws EE_Error
221
+	 * @return void
222
+	 */
223
+	public static function register($addon_name = '', $setup_args = array())
224
+	{
225
+		// required fields MUST be present, so let's make sure they are.
226
+		\EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
227
+		// get class name for addon
228
+		$class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
229
+		//setup $_settings array from incoming values.
230
+		$addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
231
+		// setup PUE
232
+		\EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
233
+		// does this addon work with this version of core or WordPress ?
234
+		if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
235
+			return;
236
+		}
237
+		// register namespaces
238
+		\EE_Register_Addon::_setup_namespaces($addon_settings);
239
+		// check if this is an activation request
240
+		if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
241
+			// dont bother setting up the rest of the addon atm
242
+			return;
243
+		}
244
+		// we need cars
245
+		\EE_Register_Addon::_setup_autoloaders($addon_name);
246
+		// register new models and extensions
247
+		\EE_Register_Addon::_register_models_and_extensions($addon_name);
248
+		// setup DMS
249
+		\EE_Register_Addon::_register_data_migration_scripts($addon_name);
250
+		// if config_class is present let's register config.
251
+		\EE_Register_Addon::_register_config($addon_name);
252
+		// register admin pages
253
+		\EE_Register_Addon::_register_admin_pages($addon_name);
254
+		// add to list of modules to be registered
255
+		\EE_Register_Addon::_register_modules($addon_name);
256
+		// add to list of shortcodes to be registered
257
+		\EE_Register_Addon::_register_shortcodes($addon_name);
258
+		// add to list of widgets to be registered
259
+		\EE_Register_Addon::_register_widgets($addon_name);
260
+		// register capability related stuff.
261
+		\EE_Register_Addon::_register_capabilities($addon_name);
262
+		// any message type to register?
263
+		\EE_Register_Addon::_register_message_types($addon_name);
264
+		// any custom post type/ custom capabilities or default terms to register
265
+		\EE_Register_Addon::_register_custom_post_types($addon_name);
266
+		// and any payment methods
267
+		\EE_Register_Addon::_register_payment_methods($addon_name);
268
+		// load and instantiate main addon class
269
+		$addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name);
270
+		$addon->after_registration();
271
+	}
272 272
 
273 273
 
274
-    /**
275
-     * @param string $addon_name
276
-     * @param array  $setup_args
277
-     * @return void
278
-     * @throws \EE_Error
279
-     */
280
-    private static function _verify_parameters($addon_name, array $setup_args)
281
-    {
282
-        // required fields MUST be present, so let's make sure they are.
283
-        if (empty($addon_name) || ! is_array($setup_args)) {
284
-            throw new EE_Error(
285
-                __(
286
-                    'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
287
-                    'event_espresso'
288
-                )
289
-            );
290
-        }
291
-        if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
292
-            throw new EE_Error(
293
-                sprintf(
294
-                    __(
295
-                        'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
296
-                        'event_espresso'
297
-                    ),
298
-                    implode(',', array_keys($setup_args))
299
-                )
300
-            );
301
-        }
302
-        // check that addon has not already been registered with that name
303
-        if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) {
304
-            throw new EE_Error(
305
-                sprintf(
306
-                    __(
307
-                        'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
308
-                        'event_espresso'
309
-                    ),
310
-                    $addon_name
311
-                )
312
-            );
313
-        }
314
-    }
274
+	/**
275
+	 * @param string $addon_name
276
+	 * @param array  $setup_args
277
+	 * @return void
278
+	 * @throws \EE_Error
279
+	 */
280
+	private static function _verify_parameters($addon_name, array $setup_args)
281
+	{
282
+		// required fields MUST be present, so let's make sure they are.
283
+		if (empty($addon_name) || ! is_array($setup_args)) {
284
+			throw new EE_Error(
285
+				__(
286
+					'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
287
+					'event_espresso'
288
+				)
289
+			);
290
+		}
291
+		if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
292
+			throw new EE_Error(
293
+				sprintf(
294
+					__(
295
+						'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
296
+						'event_espresso'
297
+					),
298
+					implode(',', array_keys($setup_args))
299
+				)
300
+			);
301
+		}
302
+		// check that addon has not already been registered with that name
303
+		if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) {
304
+			throw new EE_Error(
305
+				sprintf(
306
+					__(
307
+						'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
308
+						'event_espresso'
309
+					),
310
+					$addon_name
311
+				)
312
+			);
313
+		}
314
+	}
315 315
 
316 316
 
317
-    /**
318
-     * @param string $addon_name
319
-     * @param array  $setup_args
320
-     * @return string
321
-     */
322
-    private static function _parse_class_name($addon_name, array $setup_args)
323
-    {
324
-        if (empty($setup_args['class_name'])) {
325
-            // generate one by first separating name with spaces
326
-            $class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
327
-            //capitalize, then replace spaces with underscores
328
-            $class_name = str_replace(' ', '_', ucwords($class_name));
329
-        } else {
330
-            $class_name = $setup_args['class_name'];
331
-        }
332
-        return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name;
333
-    }
317
+	/**
318
+	 * @param string $addon_name
319
+	 * @param array  $setup_args
320
+	 * @return string
321
+	 */
322
+	private static function _parse_class_name($addon_name, array $setup_args)
323
+	{
324
+		if (empty($setup_args['class_name'])) {
325
+			// generate one by first separating name with spaces
326
+			$class_name = str_replace(array('-', '_'), ' ', trim($addon_name));
327
+			//capitalize, then replace spaces with underscores
328
+			$class_name = str_replace(' ', '_', ucwords($class_name));
329
+		} else {
330
+			$class_name = $setup_args['class_name'];
331
+		}
332
+		return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name;
333
+	}
334 334
 
335 335
 
336
-    /**
337
-     * @param string $class_name
338
-     * @param array  $setup_args
339
-     * @return array
340
-     */
341
-    private static function _get_addon_settings($class_name, array $setup_args)
342
-    {
343
-        //setup $_settings array from incoming values.
344
-        $addon_settings = array(
345
-            // generated from the addon name, changes something like "calendar" to "EE_Calendar"
346
-            'class_name'            => $class_name,
347
-            // the addon slug for use in URLs, etc
348
-            'plugin_slug'           => isset($setup_args['plugin_slug'])
349
-                ? (string)$setup_args['plugin_slug']
350
-                : '',
351
-            // page slug to be used when generating the "Settings" link on the WP plugin page
352
-            'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
353
-                ? (string)$setup_args['plugin_action_slug']
354
-                : '',
355
-            // the "software" version for the addon
356
-            'version'               => isset($setup_args['version'])
357
-                ? (string)$setup_args['version']
358
-                : '',
359
-            // the minimum version of EE Core that the addon will work with
360
-            'min_core_version'      => isset($setup_args['min_core_version'])
361
-                ? (string)$setup_args['min_core_version']
362
-                : '',
363
-            // the minimum version of WordPress that the addon will work with
364
-            'min_wp_version'        => isset($setup_args['min_wp_version'])
365
-                ? (string)$setup_args['min_wp_version']
366
-                : EE_MIN_WP_VER_REQUIRED,
367
-            // full server path to main file (file loaded directly by WP)
368
-            'main_file_path'        => isset($setup_args['main_file_path'])
369
-                ? (string)$setup_args['main_file_path']
370
-                : '',
371
-            // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
372
-            'admin_path'            => isset($setup_args['admin_path'])
373
-                ? (string)$setup_args['admin_path'] : '',
374
-            // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
375
-            'admin_callback'        => isset($setup_args['admin_callback'])
376
-                ? (string)$setup_args['admin_callback']
377
-                : '',
378
-            // the section name for this addon's configuration settings section (defaults to "addons")
379
-            'config_section'        => isset($setup_args['config_section'])
380
-                ? (string)$setup_args['config_section']
381
-                : 'addons',
382
-            // the class name for this addon's configuration settings object
383
-            'config_class'          => isset($setup_args['config_class'])
384
-                ? (string)$setup_args['config_class'] : '',
385
-            //the name given to the config for this addons' configuration settings object (optional)
386
-            'config_name'           => isset($setup_args['config_name'])
387
-                ? (string)$setup_args['config_name'] : '',
388
-            // an array of "class names" => "full server paths" for any classes that might be invoked by the addon
389
-            'autoloader_paths'      => isset($setup_args['autoloader_paths'])
390
-                ? (array)$setup_args['autoloader_paths']
391
-                : array(),
392
-            // an array of  "full server paths" for any folders containing classes that might be invoked by the addon
393
-            'autoloader_folders'    => isset($setup_args['autoloader_folders'])
394
-                ? (array)$setup_args['autoloader_folders']
395
-                : array(),
396
-            // array of full server paths to any EE_DMS data migration scripts used by the addon
397
-            'dms_paths'             => isset($setup_args['dms_paths'])
398
-                ? (array)$setup_args['dms_paths']
399
-                : array(),
400
-            // array of full server paths to any EED_Modules used by the addon
401
-            'module_paths'          => isset($setup_args['module_paths'])
402
-                ? (array)$setup_args['module_paths']
403
-                : array(),
404
-            // array of full server paths to any EES_Shortcodes used by the addon
405
-            'shortcode_paths'       => isset($setup_args['shortcode_paths'])
406
-                ? (array)$setup_args['shortcode_paths']
407
-                : array(),
408
-            // array of full server paths to any WP_Widgets used by the addon
409
-            'widget_paths'          => isset($setup_args['widget_paths'])
410
-                ? (array)$setup_args['widget_paths']
411
-                : array(),
412
-            // array of PUE options used by the addon
413
-            'pue_options'           => isset($setup_args['pue_options'])
414
-                ? (array)$setup_args['pue_options']
415
-                : array(),
416
-            'message_types'         => isset($setup_args['message_types'])
417
-                ? (array)$setup_args['message_types']
418
-                : array(),
419
-            'capabilities'          => isset($setup_args['capabilities'])
420
-                ? (array)$setup_args['capabilities']
421
-                : array(),
422
-            'capability_maps'       => isset($setup_args['capability_maps'])
423
-                ? (array)$setup_args['capability_maps']
424
-                : array(),
425
-            'model_paths'           => isset($setup_args['model_paths'])
426
-                ? (array)$setup_args['model_paths']
427
-                : array(),
428
-            'class_paths'           => isset($setup_args['class_paths'])
429
-                ? (array)$setup_args['class_paths']
430
-                : array(),
431
-            'model_extension_paths' => isset($setup_args['model_extension_paths'])
432
-                ? (array)$setup_args['model_extension_paths']
433
-                : array(),
434
-            'class_extension_paths' => isset($setup_args['class_extension_paths'])
435
-                ? (array)$setup_args['class_extension_paths']
436
-                : array(),
437
-            'custom_post_types'     => isset($setup_args['custom_post_types'])
438
-                ? (array)$setup_args['custom_post_types']
439
-                : array(),
440
-            'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
441
-                ? (array)$setup_args['custom_taxonomies']
442
-                : array(),
443
-            'payment_method_paths'  => isset($setup_args['payment_method_paths'])
444
-                ? (array)$setup_args['payment_method_paths']
445
-                : array(),
446
-            'default_terms'         => isset($setup_args['default_terms'])
447
-                ? (array)$setup_args['default_terms']
448
-                : array(),
449
-            // if not empty, inserts a new table row after this plugin's row on the WP Plugins page
450
-            // that can be used for adding upgrading/marketing info
451
-            'plugins_page_row'      => isset($setup_args['plugins_page_row'])
452
-                ? $setup_args['plugins_page_row']
453
-                : '',
454
-            'namespace'             => isset(
455
-                $setup_args['namespace'],
456
-                $setup_args['namespace']['FQNS'],
457
-                $setup_args['namespace']['DIR']
458
-            )
459
-                ? (array)$setup_args['namespace']
460
-                : array(),
461
-        );
462
-        // if plugin_action_slug is NOT set, but an admin page path IS set,
463
-        // then let's just use the plugin_slug since that will be used for linking to the admin page
464
-        $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
465
-                                                && ! empty($addon_settings['admin_path'])
466
-            ? $addon_settings['plugin_slug']
467
-            : $addon_settings['plugin_action_slug'];
468
-        // full server path to main file (file loaded directly by WP)
469
-        $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
470
-        return $addon_settings;
471
-    }
336
+	/**
337
+	 * @param string $class_name
338
+	 * @param array  $setup_args
339
+	 * @return array
340
+	 */
341
+	private static function _get_addon_settings($class_name, array $setup_args)
342
+	{
343
+		//setup $_settings array from incoming values.
344
+		$addon_settings = array(
345
+			// generated from the addon name, changes something like "calendar" to "EE_Calendar"
346
+			'class_name'            => $class_name,
347
+			// the addon slug for use in URLs, etc
348
+			'plugin_slug'           => isset($setup_args['plugin_slug'])
349
+				? (string)$setup_args['plugin_slug']
350
+				: '',
351
+			// page slug to be used when generating the "Settings" link on the WP plugin page
352
+			'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
353
+				? (string)$setup_args['plugin_action_slug']
354
+				: '',
355
+			// the "software" version for the addon
356
+			'version'               => isset($setup_args['version'])
357
+				? (string)$setup_args['version']
358
+				: '',
359
+			// the minimum version of EE Core that the addon will work with
360
+			'min_core_version'      => isset($setup_args['min_core_version'])
361
+				? (string)$setup_args['min_core_version']
362
+				: '',
363
+			// the minimum version of WordPress that the addon will work with
364
+			'min_wp_version'        => isset($setup_args['min_wp_version'])
365
+				? (string)$setup_args['min_wp_version']
366
+				: EE_MIN_WP_VER_REQUIRED,
367
+			// full server path to main file (file loaded directly by WP)
368
+			'main_file_path'        => isset($setup_args['main_file_path'])
369
+				? (string)$setup_args['main_file_path']
370
+				: '',
371
+			// path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
372
+			'admin_path'            => isset($setup_args['admin_path'])
373
+				? (string)$setup_args['admin_path'] : '',
374
+			// a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
375
+			'admin_callback'        => isset($setup_args['admin_callback'])
376
+				? (string)$setup_args['admin_callback']
377
+				: '',
378
+			// the section name for this addon's configuration settings section (defaults to "addons")
379
+			'config_section'        => isset($setup_args['config_section'])
380
+				? (string)$setup_args['config_section']
381
+				: 'addons',
382
+			// the class name for this addon's configuration settings object
383
+			'config_class'          => isset($setup_args['config_class'])
384
+				? (string)$setup_args['config_class'] : '',
385
+			//the name given to the config for this addons' configuration settings object (optional)
386
+			'config_name'           => isset($setup_args['config_name'])
387
+				? (string)$setup_args['config_name'] : '',
388
+			// an array of "class names" => "full server paths" for any classes that might be invoked by the addon
389
+			'autoloader_paths'      => isset($setup_args['autoloader_paths'])
390
+				? (array)$setup_args['autoloader_paths']
391
+				: array(),
392
+			// an array of  "full server paths" for any folders containing classes that might be invoked by the addon
393
+			'autoloader_folders'    => isset($setup_args['autoloader_folders'])
394
+				? (array)$setup_args['autoloader_folders']
395
+				: array(),
396
+			// array of full server paths to any EE_DMS data migration scripts used by the addon
397
+			'dms_paths'             => isset($setup_args['dms_paths'])
398
+				? (array)$setup_args['dms_paths']
399
+				: array(),
400
+			// array of full server paths to any EED_Modules used by the addon
401
+			'module_paths'          => isset($setup_args['module_paths'])
402
+				? (array)$setup_args['module_paths']
403
+				: array(),
404
+			// array of full server paths to any EES_Shortcodes used by the addon
405
+			'shortcode_paths'       => isset($setup_args['shortcode_paths'])
406
+				? (array)$setup_args['shortcode_paths']
407
+				: array(),
408
+			// array of full server paths to any WP_Widgets used by the addon
409
+			'widget_paths'          => isset($setup_args['widget_paths'])
410
+				? (array)$setup_args['widget_paths']
411
+				: array(),
412
+			// array of PUE options used by the addon
413
+			'pue_options'           => isset($setup_args['pue_options'])
414
+				? (array)$setup_args['pue_options']
415
+				: array(),
416
+			'message_types'         => isset($setup_args['message_types'])
417
+				? (array)$setup_args['message_types']
418
+				: array(),
419
+			'capabilities'          => isset($setup_args['capabilities'])
420
+				? (array)$setup_args['capabilities']
421
+				: array(),
422
+			'capability_maps'       => isset($setup_args['capability_maps'])
423
+				? (array)$setup_args['capability_maps']
424
+				: array(),
425
+			'model_paths'           => isset($setup_args['model_paths'])
426
+				? (array)$setup_args['model_paths']
427
+				: array(),
428
+			'class_paths'           => isset($setup_args['class_paths'])
429
+				? (array)$setup_args['class_paths']
430
+				: array(),
431
+			'model_extension_paths' => isset($setup_args['model_extension_paths'])
432
+				? (array)$setup_args['model_extension_paths']
433
+				: array(),
434
+			'class_extension_paths' => isset($setup_args['class_extension_paths'])
435
+				? (array)$setup_args['class_extension_paths']
436
+				: array(),
437
+			'custom_post_types'     => isset($setup_args['custom_post_types'])
438
+				? (array)$setup_args['custom_post_types']
439
+				: array(),
440
+			'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
441
+				? (array)$setup_args['custom_taxonomies']
442
+				: array(),
443
+			'payment_method_paths'  => isset($setup_args['payment_method_paths'])
444
+				? (array)$setup_args['payment_method_paths']
445
+				: array(),
446
+			'default_terms'         => isset($setup_args['default_terms'])
447
+				? (array)$setup_args['default_terms']
448
+				: array(),
449
+			// if not empty, inserts a new table row after this plugin's row on the WP Plugins page
450
+			// that can be used for adding upgrading/marketing info
451
+			'plugins_page_row'      => isset($setup_args['plugins_page_row'])
452
+				? $setup_args['plugins_page_row']
453
+				: '',
454
+			'namespace'             => isset(
455
+				$setup_args['namespace'],
456
+				$setup_args['namespace']['FQNS'],
457
+				$setup_args['namespace']['DIR']
458
+			)
459
+				? (array)$setup_args['namespace']
460
+				: array(),
461
+		);
462
+		// if plugin_action_slug is NOT set, but an admin page path IS set,
463
+		// then let's just use the plugin_slug since that will be used for linking to the admin page
464
+		$addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
465
+												&& ! empty($addon_settings['admin_path'])
466
+			? $addon_settings['plugin_slug']
467
+			: $addon_settings['plugin_action_slug'];
468
+		// full server path to main file (file loaded directly by WP)
469
+		$addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
470
+		return $addon_settings;
471
+	}
472 472
 
473 473
 
474
-    /**
475
-     * @param string $addon_name
476
-     * @param array  $addon_settings
477
-     * @return boolean
478
-     */
479
-    private static function _addon_is_compatible($addon_name, array $addon_settings)
480
-    {
481
-        global $wp_version;
482
-        $incompatibility_message = '';
483
-        //check whether this addon version is compatible with EE core
484
-        if (
485
-            isset(EE_Register_Addon::$_incompatible_addons[$addon_name])
486
-            && ! self::_meets_min_core_version_requirement(
487
-                EE_Register_Addon::$_incompatible_addons[$addon_name],
488
-                $addon_settings['version']
489
-            )
490
-        ) {
491
-            $incompatibility_message = sprintf(
492
-                __(
493
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.'
494
-                ),
495
-                $addon_name,
496
-                '<br />',
497
-                EE_Register_Addon::$_incompatible_addons[$addon_name],
498
-                '<span style="font-weight: bold; color: #D54E21;">',
499
-                '</span><br />'
500
-            );
501
-        } else if (
502
-        ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
503
-        ) {
504
-            $incompatibility_message = sprintf(
505
-                __(
506
-                    '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
507
-                    'event_espresso'
508
-                ),
509
-                $addon_name,
510
-                self::_effective_version($addon_settings['min_core_version']),
511
-                self::_effective_version(espresso_version()),
512
-                '<br />',
513
-                '<span style="font-weight: bold; color: #D54E21;">',
514
-                '</span><br />'
515
-            );
516
-        } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
517
-            $incompatibility_message = sprintf(
518
-                __(
519
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
520
-                    'event_espresso'
521
-                ),
522
-                $addon_name,
523
-                $addon_settings['min_wp_version'],
524
-                '<br />',
525
-                '<span style="font-weight: bold; color: #D54E21;">',
526
-                '</span><br />'
527
-            );
528
-        }
529
-        if (! empty($incompatibility_message)) {
530
-            // remove 'activate' from the REQUEST
531
-            // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
532
-            unset($_GET['activate'], $_REQUEST['activate']);
533
-            if (current_user_can('activate_plugins')) {
534
-                // show an error message indicating the plugin didn't activate properly
535
-                EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
536
-            }
537
-            // BAIL FROM THE ADDON REGISTRATION PROCESS
538
-            return false;
539
-        }
540
-        // addon IS compatible
541
-        return true;
542
-    }
474
+	/**
475
+	 * @param string $addon_name
476
+	 * @param array  $addon_settings
477
+	 * @return boolean
478
+	 */
479
+	private static function _addon_is_compatible($addon_name, array $addon_settings)
480
+	{
481
+		global $wp_version;
482
+		$incompatibility_message = '';
483
+		//check whether this addon version is compatible with EE core
484
+		if (
485
+			isset(EE_Register_Addon::$_incompatible_addons[$addon_name])
486
+			&& ! self::_meets_min_core_version_requirement(
487
+				EE_Register_Addon::$_incompatible_addons[$addon_name],
488
+				$addon_settings['version']
489
+			)
490
+		) {
491
+			$incompatibility_message = sprintf(
492
+				__(
493
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.'
494
+				),
495
+				$addon_name,
496
+				'<br />',
497
+				EE_Register_Addon::$_incompatible_addons[$addon_name],
498
+				'<span style="font-weight: bold; color: #D54E21;">',
499
+				'</span><br />'
500
+			);
501
+		} else if (
502
+		! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
503
+		) {
504
+			$incompatibility_message = sprintf(
505
+				__(
506
+					'%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
507
+					'event_espresso'
508
+				),
509
+				$addon_name,
510
+				self::_effective_version($addon_settings['min_core_version']),
511
+				self::_effective_version(espresso_version()),
512
+				'<br />',
513
+				'<span style="font-weight: bold; color: #D54E21;">',
514
+				'</span><br />'
515
+			);
516
+		} else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
517
+			$incompatibility_message = sprintf(
518
+				__(
519
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
520
+					'event_espresso'
521
+				),
522
+				$addon_name,
523
+				$addon_settings['min_wp_version'],
524
+				'<br />',
525
+				'<span style="font-weight: bold; color: #D54E21;">',
526
+				'</span><br />'
527
+			);
528
+		}
529
+		if (! empty($incompatibility_message)) {
530
+			// remove 'activate' from the REQUEST
531
+			// so WP doesn't erroneously tell the user the plugin activated fine when it didn't
532
+			unset($_GET['activate'], $_REQUEST['activate']);
533
+			if (current_user_can('activate_plugins')) {
534
+				// show an error message indicating the plugin didn't activate properly
535
+				EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
536
+			}
537
+			// BAIL FROM THE ADDON REGISTRATION PROCESS
538
+			return false;
539
+		}
540
+		// addon IS compatible
541
+		return true;
542
+	}
543 543
 
544 544
 
545
-    /**
546
-     * if plugin update engine is being used for auto-updates,
547
-     * then let's set that up now before going any further so that ALL addons can be updated
548
-     * (not needed if PUE is not being used)
549
-     *
550
-     * @param string $addon_name
551
-     * @param string $class_name
552
-     * @param array  $setup_args
553
-     * @return void
554
-     */
555
-    private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
556
-    {
557
-        if (! empty($setup_args['pue_options'])) {
558
-            self::$_settings[$addon_name]['pue_options'] = array(
559
-                'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
560
-                    ? (string)$setup_args['pue_options']['pue_plugin_slug']
561
-                    : 'espresso_' . strtolower($class_name),
562
-                'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
563
-                    ? (string)$setup_args['pue_options']['plugin_basename']
564
-                    : plugin_basename($setup_args['main_file_path']),
565
-                'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
566
-                    ? (string)$setup_args['pue_options']['checkPeriod']
567
-                    : '24',
568
-                'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
569
-                    ? (string)$setup_args['pue_options']['use_wp_update']
570
-                    : false,
571
-            );
572
-            add_action(
573
-                'AHEE__EE_System__brew_espresso__after_pue_init',
574
-                array('EE_Register_Addon', 'load_pue_update')
575
-            );
576
-        }
577
-    }
545
+	/**
546
+	 * if plugin update engine is being used for auto-updates,
547
+	 * then let's set that up now before going any further so that ALL addons can be updated
548
+	 * (not needed if PUE is not being used)
549
+	 *
550
+	 * @param string $addon_name
551
+	 * @param string $class_name
552
+	 * @param array  $setup_args
553
+	 * @return void
554
+	 */
555
+	private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
556
+	{
557
+		if (! empty($setup_args['pue_options'])) {
558
+			self::$_settings[$addon_name]['pue_options'] = array(
559
+				'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
560
+					? (string)$setup_args['pue_options']['pue_plugin_slug']
561
+					: 'espresso_' . strtolower($class_name),
562
+				'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
563
+					? (string)$setup_args['pue_options']['plugin_basename']
564
+					: plugin_basename($setup_args['main_file_path']),
565
+				'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
566
+					? (string)$setup_args['pue_options']['checkPeriod']
567
+					: '24',
568
+				'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
569
+					? (string)$setup_args['pue_options']['use_wp_update']
570
+					: false,
571
+			);
572
+			add_action(
573
+				'AHEE__EE_System__brew_espresso__after_pue_init',
574
+				array('EE_Register_Addon', 'load_pue_update')
575
+			);
576
+		}
577
+	}
578 578
 
579 579
 
580
-    /**
581
-     * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
582
-     *
583
-     * @param array $addon_settings
584
-     * @return void
585
-     */
586
-    private static function _setup_namespaces(array $addon_settings)
587
-    {
588
-        //
589
-        if (
590
-        isset(
591
-            $addon_settings['namespace'],
592
-            $addon_settings['namespace']['FQNS'],
593
-            $addon_settings['namespace']['DIR']
594
-        )
595
-        ) {
596
-            EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
597
-                $addon_settings['namespace']['FQNS'],
598
-                $addon_settings['namespace']['DIR']
599
-            );
600
-        }
601
-    }
580
+	/**
581
+	 * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
582
+	 *
583
+	 * @param array $addon_settings
584
+	 * @return void
585
+	 */
586
+	private static function _setup_namespaces(array $addon_settings)
587
+	{
588
+		//
589
+		if (
590
+		isset(
591
+			$addon_settings['namespace'],
592
+			$addon_settings['namespace']['FQNS'],
593
+			$addon_settings['namespace']['DIR']
594
+		)
595
+		) {
596
+			EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
597
+				$addon_settings['namespace']['FQNS'],
598
+				$addon_settings['namespace']['DIR']
599
+			);
600
+		}
601
+	}
602 602
 
603 603
 
604
-    /**
605
-     * @param string $addon_name
606
-     * @param array  $addon_settings
607
-     * @return bool
608
-     */
609
-    private static function _addon_activation($addon_name, array $addon_settings)
610
-    {
611
-        // this is an activation request
612
-        if (did_action('activate_plugin')) {
613
-            //to find if THIS is the addon that was activated, just check if we have already registered it or not
614
-            //(as the newly-activated addon wasn't around the first time addons were registered).
615
-            //Note: the presence of pue_options in the addon registration options will initialize the $_settings
616
-            //property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
617
-            if (! isset(self::$_settings[$addon_name])
618
-                || (isset(self::$_settings[$addon_name])
619
-                    && ! isset(self::$_settings[$addon_name]['class_name'])
620
-                )
621
-            ) {
622
-                self::$_settings[$addon_name] = $addon_settings;
623
-                $addon                        = self::_load_and_init_addon_class($addon_name);
624
-                $addon->set_activation_indicator_option();
625
-                // dont bother setting up the rest of the addon.
626
-                // we know it was just activated and the request will end soon
627
-            }
628
-            return true;
629
-        } else {
630
-            // make sure this was called in the right place!
631
-            if (
632
-                ! did_action('AHEE__EE_System__load_espresso_addons')
633
-                || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
634
-            ) {
635
-                EE_Error::doing_it_wrong(
636
-                    __METHOD__,
637
-                    sprintf(
638
-                        __(
639
-                            'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
640
-                            'event_espresso'
641
-                        ),
642
-                        $addon_name
643
-                    ),
644
-                    '4.3.0'
645
-                );
646
-            }
647
-            // make sure addon settings are set correctly without overwriting anything existing
648
-            if (isset(self::$_settings[$addon_name])) {
649
-                self::$_settings[$addon_name] += $addon_settings;
650
-            } else {
651
-                self::$_settings[$addon_name] = $addon_settings;
652
-            }
653
-        }
654
-        return false;
655
-    }
604
+	/**
605
+	 * @param string $addon_name
606
+	 * @param array  $addon_settings
607
+	 * @return bool
608
+	 */
609
+	private static function _addon_activation($addon_name, array $addon_settings)
610
+	{
611
+		// this is an activation request
612
+		if (did_action('activate_plugin')) {
613
+			//to find if THIS is the addon that was activated, just check if we have already registered it or not
614
+			//(as the newly-activated addon wasn't around the first time addons were registered).
615
+			//Note: the presence of pue_options in the addon registration options will initialize the $_settings
616
+			//property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
617
+			if (! isset(self::$_settings[$addon_name])
618
+				|| (isset(self::$_settings[$addon_name])
619
+					&& ! isset(self::$_settings[$addon_name]['class_name'])
620
+				)
621
+			) {
622
+				self::$_settings[$addon_name] = $addon_settings;
623
+				$addon                        = self::_load_and_init_addon_class($addon_name);
624
+				$addon->set_activation_indicator_option();
625
+				// dont bother setting up the rest of the addon.
626
+				// we know it was just activated and the request will end soon
627
+			}
628
+			return true;
629
+		} else {
630
+			// make sure this was called in the right place!
631
+			if (
632
+				! did_action('AHEE__EE_System__load_espresso_addons')
633
+				|| did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
634
+			) {
635
+				EE_Error::doing_it_wrong(
636
+					__METHOD__,
637
+					sprintf(
638
+						__(
639
+							'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
640
+							'event_espresso'
641
+						),
642
+						$addon_name
643
+					),
644
+					'4.3.0'
645
+				);
646
+			}
647
+			// make sure addon settings are set correctly without overwriting anything existing
648
+			if (isset(self::$_settings[$addon_name])) {
649
+				self::$_settings[$addon_name] += $addon_settings;
650
+			} else {
651
+				self::$_settings[$addon_name] = $addon_settings;
652
+			}
653
+		}
654
+		return false;
655
+	}
656 656
 
657 657
 
658
-    /**
659
-     * @param string $addon_name
660
-     * @return void
661
-     * @throws \EE_Error
662
-     */
663
-    private static function _setup_autoloaders($addon_name)
664
-    {
665
-        if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
666
-            // setup autoloader for single file
667
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
668
-        }
669
-        // setup autoloaders for folders
670
-        if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
671
-            foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
672
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
673
-            }
674
-        }
675
-    }
658
+	/**
659
+	 * @param string $addon_name
660
+	 * @return void
661
+	 * @throws \EE_Error
662
+	 */
663
+	private static function _setup_autoloaders($addon_name)
664
+	{
665
+		if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
666
+			// setup autoloader for single file
667
+			EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
668
+		}
669
+		// setup autoloaders for folders
670
+		if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
671
+			foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
672
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
673
+			}
674
+		}
675
+	}
676 676
 
677 677
 
678
-    /**
679
-     * register new models and extensions
680
-     *
681
-     * @param string $addon_name
682
-     * @return void
683
-     * @throws \EE_Error
684
-     */
685
-    private static function _register_models_and_extensions($addon_name)
686
-    {
687
-        // register new models
688
-        if (
689
-            ! empty(self::$_settings[$addon_name]['model_paths'])
690
-            || ! empty(self::$_settings[$addon_name]['class_paths'])
691
-        ) {
692
-            EE_Register_Model::register(
693
-                $addon_name,
694
-                array(
695
-                    'model_paths' => self::$_settings[$addon_name]['model_paths'],
696
-                    'class_paths' => self::$_settings[$addon_name]['class_paths'],
697
-                )
698
-            );
699
-        }
700
-        // register model extensions
701
-        if (
702
-            ! empty(self::$_settings[$addon_name]['model_extension_paths'])
703
-            || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
704
-        ) {
705
-            EE_Register_Model_Extensions::register(
706
-                $addon_name,
707
-                array(
708
-                    'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'],
709
-                    'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'],
710
-                )
711
-            );
712
-        }
713
-    }
678
+	/**
679
+	 * register new models and extensions
680
+	 *
681
+	 * @param string $addon_name
682
+	 * @return void
683
+	 * @throws \EE_Error
684
+	 */
685
+	private static function _register_models_and_extensions($addon_name)
686
+	{
687
+		// register new models
688
+		if (
689
+			! empty(self::$_settings[$addon_name]['model_paths'])
690
+			|| ! empty(self::$_settings[$addon_name]['class_paths'])
691
+		) {
692
+			EE_Register_Model::register(
693
+				$addon_name,
694
+				array(
695
+					'model_paths' => self::$_settings[$addon_name]['model_paths'],
696
+					'class_paths' => self::$_settings[$addon_name]['class_paths'],
697
+				)
698
+			);
699
+		}
700
+		// register model extensions
701
+		if (
702
+			! empty(self::$_settings[$addon_name]['model_extension_paths'])
703
+			|| ! empty(self::$_settings[$addon_name]['class_extension_paths'])
704
+		) {
705
+			EE_Register_Model_Extensions::register(
706
+				$addon_name,
707
+				array(
708
+					'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'],
709
+					'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'],
710
+				)
711
+			);
712
+		}
713
+	}
714 714
 
715 715
 
716
-    /**
717
-     * @param string $addon_name
718
-     * @return void
719
-     * @throws \EE_Error
720
-     */
721
-    private static function _register_data_migration_scripts($addon_name)
722
-    {
723
-        // setup DMS
724
-        if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
725
-            EE_Register_Data_Migration_Scripts::register(
726
-                $addon_name,
727
-                array('dms_paths' => self::$_settings[$addon_name]['dms_paths'])
728
-            );
729
-        }
730
-    }
716
+	/**
717
+	 * @param string $addon_name
718
+	 * @return void
719
+	 * @throws \EE_Error
720
+	 */
721
+	private static function _register_data_migration_scripts($addon_name)
722
+	{
723
+		// setup DMS
724
+		if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
725
+			EE_Register_Data_Migration_Scripts::register(
726
+				$addon_name,
727
+				array('dms_paths' => self::$_settings[$addon_name]['dms_paths'])
728
+			);
729
+		}
730
+	}
731 731
 
732 732
 
733
-    /**
734
-     * @param string $addon_name
735
-     * @return void
736
-     * @throws \EE_Error
737
-     */
738
-    private static function _register_config($addon_name)
739
-    {
740
-        // if config_class is present let's register config.
741
-        if (! empty(self::$_settings[$addon_name]['config_class'])) {
742
-            EE_Register_Config::register(
743
-                self::$_settings[$addon_name]['config_class'],
744
-                array(
745
-                    'config_section' => self::$_settings[$addon_name]['config_section'],
746
-                    'config_name'    => self::$_settings[$addon_name]['config_name'],
747
-                )
748
-            );
749
-        }
750
-    }
733
+	/**
734
+	 * @param string $addon_name
735
+	 * @return void
736
+	 * @throws \EE_Error
737
+	 */
738
+	private static function _register_config($addon_name)
739
+	{
740
+		// if config_class is present let's register config.
741
+		if (! empty(self::$_settings[$addon_name]['config_class'])) {
742
+			EE_Register_Config::register(
743
+				self::$_settings[$addon_name]['config_class'],
744
+				array(
745
+					'config_section' => self::$_settings[$addon_name]['config_section'],
746
+					'config_name'    => self::$_settings[$addon_name]['config_name'],
747
+				)
748
+			);
749
+		}
750
+	}
751 751
 
752 752
 
753
-    /**
754
-     * @param string $addon_name
755
-     * @return void
756
-     * @throws \EE_Error
757
-     */
758
-    private static function _register_admin_pages($addon_name)
759
-    {
760
-        if (! empty(self::$_settings[$addon_name]['admin_path'])) {
761
-            EE_Register_Admin_Page::register(
762
-                $addon_name,
763
-                array('page_path' => self::$_settings[$addon_name]['admin_path'])
764
-            );
765
-        }
766
-    }
753
+	/**
754
+	 * @param string $addon_name
755
+	 * @return void
756
+	 * @throws \EE_Error
757
+	 */
758
+	private static function _register_admin_pages($addon_name)
759
+	{
760
+		if (! empty(self::$_settings[$addon_name]['admin_path'])) {
761
+			EE_Register_Admin_Page::register(
762
+				$addon_name,
763
+				array('page_path' => self::$_settings[$addon_name]['admin_path'])
764
+			);
765
+		}
766
+	}
767 767
 
768 768
 
769
-    /**
770
-     * @param string $addon_name
771
-     * @return void
772
-     * @throws \EE_Error
773
-     */
774
-    private static function _register_modules($addon_name)
775
-    {
776
-        if (! empty(self::$_settings[$addon_name]['module_paths'])) {
777
-            EE_Register_Module::register(
778
-                $addon_name,
779
-                array('module_paths' => self::$_settings[$addon_name]['module_paths'])
780
-            );
781
-        }
782
-    }
769
+	/**
770
+	 * @param string $addon_name
771
+	 * @return void
772
+	 * @throws \EE_Error
773
+	 */
774
+	private static function _register_modules($addon_name)
775
+	{
776
+		if (! empty(self::$_settings[$addon_name]['module_paths'])) {
777
+			EE_Register_Module::register(
778
+				$addon_name,
779
+				array('module_paths' => self::$_settings[$addon_name]['module_paths'])
780
+			);
781
+		}
782
+	}
783 783
 
784 784
 
785
-    /**
786
-     * @param string $addon_name
787
-     * @return void
788
-     * @throws \EE_Error
789
-     */
790
-    private static function _register_shortcodes($addon_name)
791
-    {
792
-        if (! empty(self::$_settings[$addon_name]['shortcode_paths'])) {
793
-            EE_Register_Shortcode::register(
794
-                $addon_name,
795
-                array('shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths'])
796
-            );
797
-        }
798
-    }
785
+	/**
786
+	 * @param string $addon_name
787
+	 * @return void
788
+	 * @throws \EE_Error
789
+	 */
790
+	private static function _register_shortcodes($addon_name)
791
+	{
792
+		if (! empty(self::$_settings[$addon_name]['shortcode_paths'])) {
793
+			EE_Register_Shortcode::register(
794
+				$addon_name,
795
+				array('shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths'])
796
+			);
797
+		}
798
+	}
799 799
 
800 800
 
801
-    /**
802
-     * @param string $addon_name
803
-     * @return void
804
-     * @throws \EE_Error
805
-     */
806
-    private static function _register_widgets($addon_name)
807
-    {
808
-        if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
809
-            EE_Register_Widget::register(
810
-                $addon_name,
811
-                array('widget_paths' => self::$_settings[$addon_name]['widget_paths'])
812
-            );
813
-        }
814
-    }
801
+	/**
802
+	 * @param string $addon_name
803
+	 * @return void
804
+	 * @throws \EE_Error
805
+	 */
806
+	private static function _register_widgets($addon_name)
807
+	{
808
+		if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
809
+			EE_Register_Widget::register(
810
+				$addon_name,
811
+				array('widget_paths' => self::$_settings[$addon_name]['widget_paths'])
812
+			);
813
+		}
814
+	}
815 815
 
816 816
 
817
-    /**
818
-     * @param string $addon_name
819
-     * @return void
820
-     * @throws \EE_Error
821
-     */
822
-    private static function _register_capabilities($addon_name)
823
-    {
824
-        if (! empty(self::$_settings[$addon_name]['capabilities'])) {
825
-            EE_Register_Capabilities::register(
826
-                $addon_name,
827
-                array(
828
-                    'capabilities'    => self::$_settings[$addon_name]['capabilities'],
829
-                    'capability_maps' => self::$_settings[$addon_name]['capability_maps'],
830
-                )
831
-            );
832
-        }
833
-    }
817
+	/**
818
+	 * @param string $addon_name
819
+	 * @return void
820
+	 * @throws \EE_Error
821
+	 */
822
+	private static function _register_capabilities($addon_name)
823
+	{
824
+		if (! empty(self::$_settings[$addon_name]['capabilities'])) {
825
+			EE_Register_Capabilities::register(
826
+				$addon_name,
827
+				array(
828
+					'capabilities'    => self::$_settings[$addon_name]['capabilities'],
829
+					'capability_maps' => self::$_settings[$addon_name]['capability_maps'],
830
+				)
831
+			);
832
+		}
833
+	}
834 834
 
835 835
 
836
-    /**
837
-     * @param string $addon_name
838
-     * @return void
839
-     * @throws \EE_Error
840
-     */
841
-    private static function _register_message_types($addon_name)
842
-    {
843
-        if (! empty(self::$_settings[$addon_name]['message_types'])) {
844
-            add_action(
845
-                'EE_Brewing_Regular___messages_caf',
846
-                array('EE_Register_Addon', 'register_message_types')
847
-            );
848
-        }
849
-    }
836
+	/**
837
+	 * @param string $addon_name
838
+	 * @return void
839
+	 * @throws \EE_Error
840
+	 */
841
+	private static function _register_message_types($addon_name)
842
+	{
843
+		if (! empty(self::$_settings[$addon_name]['message_types'])) {
844
+			add_action(
845
+				'EE_Brewing_Regular___messages_caf',
846
+				array('EE_Register_Addon', 'register_message_types')
847
+			);
848
+		}
849
+	}
850 850
 
851 851
 
852
-    /**
853
-     * @param string $addon_name
854
-     * @return void
855
-     * @throws \EE_Error
856
-     */
857
-    private static function _register_custom_post_types($addon_name)
858
-    {
859
-        if (
860
-            ! empty(self::$_settings[$addon_name]['custom_post_types'])
861
-            || ! empty(self::$_settings[$addon_name]['custom_taxonomies'])
862
-        ) {
863
-            EE_Register_CPT::register(
864
-                $addon_name,
865
-                array(
866
-                    'cpts'          => self::$_settings[$addon_name]['custom_post_types'],
867
-                    'cts'           => self::$_settings[$addon_name]['custom_taxonomies'],
868
-                    'default_terms' => self::$_settings[$addon_name]['default_terms'],
869
-                )
870
-            );
871
-        }
872
-    }
852
+	/**
853
+	 * @param string $addon_name
854
+	 * @return void
855
+	 * @throws \EE_Error
856
+	 */
857
+	private static function _register_custom_post_types($addon_name)
858
+	{
859
+		if (
860
+			! empty(self::$_settings[$addon_name]['custom_post_types'])
861
+			|| ! empty(self::$_settings[$addon_name]['custom_taxonomies'])
862
+		) {
863
+			EE_Register_CPT::register(
864
+				$addon_name,
865
+				array(
866
+					'cpts'          => self::$_settings[$addon_name]['custom_post_types'],
867
+					'cts'           => self::$_settings[$addon_name]['custom_taxonomies'],
868
+					'default_terms' => self::$_settings[$addon_name]['default_terms'],
869
+				)
870
+			);
871
+		}
872
+	}
873 873
 
874 874
 
875
-    /**
876
-     * @param string $addon_name
877
-     * @return void
878
-     * @throws \EE_Error
879
-     */
880
-    private static function _register_payment_methods($addon_name)
881
-    {
882
-        if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
883
-            EE_Register_Payment_Method::register(
884
-                $addon_name,
885
-                array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths'])
886
-            );
887
-        }
888
-    }
875
+	/**
876
+	 * @param string $addon_name
877
+	 * @return void
878
+	 * @throws \EE_Error
879
+	 */
880
+	private static function _register_payment_methods($addon_name)
881
+	{
882
+		if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
883
+			EE_Register_Payment_Method::register(
884
+				$addon_name,
885
+				array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths'])
886
+			);
887
+		}
888
+	}
889 889
 
890 890
 
891
-    /**
892
-     * Loads and instantiates the EE_Addon class and adds it onto the registry
893
-     *
894
-     * @param string $addon_name
895
-     * @return EE_Addon
896
-     */
897
-    private static function _load_and_init_addon_class($addon_name)
898
-    {
899
-        $addon = EE_Registry::instance()->load_addon(
900
-            dirname(self::$_settings[$addon_name]['main_file_path']),
901
-            self::$_settings[$addon_name]['class_name']
902
-        );
903
-        $addon->set_name($addon_name);
904
-        $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']);
905
-        $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']);
906
-        $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']);
907
-        $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']);
908
-        $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']);
909
-        $addon->set_version(self::$_settings[$addon_name]['version']);
910
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version']));
911
-        $addon->set_config_section(self::$_settings[$addon_name]['config_section']);
912
-        $addon->set_config_class(self::$_settings[$addon_name]['config_class']);
913
-        $addon->set_config_name(self::$_settings[$addon_name]['config_name']);
914
-        //unfortunately this can't be hooked in upon construction, because we don't have
915
-        //the plugin mainfile's path upon construction.
916
-        register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
917
-        // call any additional admin_callback functions during load_admin_controller hook
918
-        if (! empty(self::$_settings[$addon_name]['admin_callback'])) {
919
-            add_action(
920
-                'AHEE__EE_System__load_controllers__load_admin_controllers',
921
-                array($addon, self::$_settings[$addon_name]['admin_callback'])
922
-            );
923
-        }
924
-        return $addon;
925
-    }
891
+	/**
892
+	 * Loads and instantiates the EE_Addon class and adds it onto the registry
893
+	 *
894
+	 * @param string $addon_name
895
+	 * @return EE_Addon
896
+	 */
897
+	private static function _load_and_init_addon_class($addon_name)
898
+	{
899
+		$addon = EE_Registry::instance()->load_addon(
900
+			dirname(self::$_settings[$addon_name]['main_file_path']),
901
+			self::$_settings[$addon_name]['class_name']
902
+		);
903
+		$addon->set_name($addon_name);
904
+		$addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']);
905
+		$addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']);
906
+		$addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']);
907
+		$addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']);
908
+		$addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']);
909
+		$addon->set_version(self::$_settings[$addon_name]['version']);
910
+		$addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version']));
911
+		$addon->set_config_section(self::$_settings[$addon_name]['config_section']);
912
+		$addon->set_config_class(self::$_settings[$addon_name]['config_class']);
913
+		$addon->set_config_name(self::$_settings[$addon_name]['config_name']);
914
+		//unfortunately this can't be hooked in upon construction, because we don't have
915
+		//the plugin mainfile's path upon construction.
916
+		register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
917
+		// call any additional admin_callback functions during load_admin_controller hook
918
+		if (! empty(self::$_settings[$addon_name]['admin_callback'])) {
919
+			add_action(
920
+				'AHEE__EE_System__load_controllers__load_admin_controllers',
921
+				array($addon, self::$_settings[$addon_name]['admin_callback'])
922
+			);
923
+		}
924
+		return $addon;
925
+	}
926 926
 
927 927
 
928
-    /**
929
-     *    load_pue_update - Update notifications
930
-     *
931
-     * @return    void
932
-     */
933
-    public static function load_pue_update()
934
-    {
935
-        // load PUE client
936
-        require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php';
937
-        // cycle thru settings
938
-        foreach (self::$_settings as $settings) {
939
-            if (! empty($settings['pue_options'])) {
940
-                // initiate the class and start the plugin update engine!
941
-                new PluginUpdateEngineChecker(
942
-                // host file URL
943
-                    'https://eventespresso.com',
944
-                    // plugin slug(s)
945
-                    array(
946
-                        'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
947
-                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
948
-                    ),
949
-                    // options
950
-                    array(
951
-                        'apikey'            => EE_Registry::instance()->NET_CFG->core->site_license_key,
952
-                        'lang_domain'       => 'event_espresso',
953
-                        'checkPeriod'       => $settings['pue_options']['checkPeriod'],
954
-                        'option_key'        => 'site_license_key',
955
-                        'options_page_slug' => 'event_espresso',
956
-                        'plugin_basename'   => $settings['pue_options']['plugin_basename'],
957
-                        // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
958
-                        'use_wp_update'     => $settings['pue_options']['use_wp_update'],
959
-                    )
960
-                );
961
-            }
962
-        }
963
-    }
928
+	/**
929
+	 *    load_pue_update - Update notifications
930
+	 *
931
+	 * @return    void
932
+	 */
933
+	public static function load_pue_update()
934
+	{
935
+		// load PUE client
936
+		require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php';
937
+		// cycle thru settings
938
+		foreach (self::$_settings as $settings) {
939
+			if (! empty($settings['pue_options'])) {
940
+				// initiate the class and start the plugin update engine!
941
+				new PluginUpdateEngineChecker(
942
+				// host file URL
943
+					'https://eventespresso.com',
944
+					// plugin slug(s)
945
+					array(
946
+						'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
947
+						'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
948
+					),
949
+					// options
950
+					array(
951
+						'apikey'            => EE_Registry::instance()->NET_CFG->core->site_license_key,
952
+						'lang_domain'       => 'event_espresso',
953
+						'checkPeriod'       => $settings['pue_options']['checkPeriod'],
954
+						'option_key'        => 'site_license_key',
955
+						'options_page_slug' => 'event_espresso',
956
+						'plugin_basename'   => $settings['pue_options']['plugin_basename'],
957
+						// if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
958
+						'use_wp_update'     => $settings['pue_options']['use_wp_update'],
959
+					)
960
+				);
961
+			}
962
+		}
963
+	}
964 964
 
965 965
 
966
-    /**
967
-     * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
968
-     *
969
-     * @since 4.4.0
970
-     * @return void
971
-     * @throws \EE_Error
972
-     */
973
-    public static function register_message_types()
974
-    {
975
-        foreach (self::$_settings as $addon_name => $settings) {
976
-            if (! empty($settings['message_types'])) {
977
-                foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) {
978
-                    EE_Register_Message_Type::register($message_type, $message_type_settings);
979
-                }
980
-            }
981
-        }
982
-    }
966
+	/**
967
+	 * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
968
+	 *
969
+	 * @since 4.4.0
970
+	 * @return void
971
+	 * @throws \EE_Error
972
+	 */
973
+	public static function register_message_types()
974
+	{
975
+		foreach (self::$_settings as $addon_name => $settings) {
976
+			if (! empty($settings['message_types'])) {
977
+				foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) {
978
+					EE_Register_Message_Type::register($message_type, $message_type_settings);
979
+				}
980
+			}
981
+		}
982
+	}
983 983
 
984 984
 
985
-    /**
986
-     * This deregisters an addon that was previously registered with a specific addon_name.
987
-     *
988
-     * @since    4.3.0
989
-     * @param string $addon_name the name for the addon that was previously registered
990
-     * @throws EE_Error
991
-     * @return void
992
-     */
993
-    public static function deregister($addon_name = null)
994
-    {
995
-        if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) {
996
-            do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
997
-            $class_name = self::$_settings[$addon_name]['class_name'];
998
-            if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
999
-                // setup DMS
1000
-                EE_Register_Data_Migration_Scripts::deregister($addon_name);
1001
-            }
1002
-            if (! empty(self::$_settings[$addon_name]['admin_path'])) {
1003
-                // register admin page
1004
-                EE_Register_Admin_Page::deregister($addon_name);
1005
-            }
1006
-            if (! empty(self::$_settings[$addon_name]['module_paths'])) {
1007
-                // add to list of modules to be registered
1008
-                EE_Register_Module::deregister($addon_name);
1009
-            }
1010
-            if (! empty(self::$_settings[$addon_name]['shortcode_paths'])) {
1011
-                // add to list of shortcodes to be registered
1012
-                EE_Register_Shortcode::deregister($addon_name);
1013
-            }
1014
-            if (! empty(self::$_settings[$addon_name]['config_class'])) {
1015
-                // if config_class present let's register config.
1016
-                EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']);
1017
-            }
1018
-            if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
1019
-                // add to list of widgets to be registered
1020
-                EE_Register_Widget::deregister($addon_name);
1021
-            }
1022
-            if (! empty(self::$_settings[$addon_name]['model_paths'])
1023
-                ||
1024
-                ! empty(self::$_settings[$addon_name]['class_paths'])
1025
-            ) {
1026
-                // add to list of shortcodes to be registered
1027
-                EE_Register_Model::deregister($addon_name);
1028
-            }
1029
-            if (! empty(self::$_settings[$addon_name]['model_extension_paths'])
1030
-                ||
1031
-                ! empty(self::$_settings[$addon_name]['class_extension_paths'])
1032
-            ) {
1033
-                // add to list of shortcodes to be registered
1034
-                EE_Register_Model_Extensions::deregister($addon_name);
1035
-            }
1036
-            if (! empty(self::$_settings[$addon_name]['message_types'])) {
1037
-                foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1038
-                    EE_Register_Message_Type::deregister($message_type);
1039
-                }
1040
-            }
1041
-            //deregister capabilities for addon
1042
-            if (
1043
-                ! empty(self::$_settings[$addon_name]['capabilities'])
1044
-                || ! empty(self::$_settings[$addon_name]['capability_maps'])
1045
-            ) {
1046
-                EE_Register_Capabilities::deregister($addon_name);
1047
-            }
1048
-            //deregister custom_post_types for addon
1049
-            if (! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1050
-                EE_Register_CPT::deregister($addon_name);
1051
-            }
1052
-            remove_action(
1053
-                'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(),
1054
-                array(EE_Registry::instance()->addons->{$class_name}, 'deactivation')
1055
-            );
1056
-            remove_action(
1057
-                'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1058
-                array(EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required')
1059
-            );
1060
-            unset(EE_Registry::instance()->addons->{$class_name}, self::$_settings[$addon_name]);
1061
-            do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1062
-        }
1063
-    }
985
+	/**
986
+	 * This deregisters an addon that was previously registered with a specific addon_name.
987
+	 *
988
+	 * @since    4.3.0
989
+	 * @param string $addon_name the name for the addon that was previously registered
990
+	 * @throws EE_Error
991
+	 * @return void
992
+	 */
993
+	public static function deregister($addon_name = null)
994
+	{
995
+		if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) {
996
+			do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
997
+			$class_name = self::$_settings[$addon_name]['class_name'];
998
+			if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
999
+				// setup DMS
1000
+				EE_Register_Data_Migration_Scripts::deregister($addon_name);
1001
+			}
1002
+			if (! empty(self::$_settings[$addon_name]['admin_path'])) {
1003
+				// register admin page
1004
+				EE_Register_Admin_Page::deregister($addon_name);
1005
+			}
1006
+			if (! empty(self::$_settings[$addon_name]['module_paths'])) {
1007
+				// add to list of modules to be registered
1008
+				EE_Register_Module::deregister($addon_name);
1009
+			}
1010
+			if (! empty(self::$_settings[$addon_name]['shortcode_paths'])) {
1011
+				// add to list of shortcodes to be registered
1012
+				EE_Register_Shortcode::deregister($addon_name);
1013
+			}
1014
+			if (! empty(self::$_settings[$addon_name]['config_class'])) {
1015
+				// if config_class present let's register config.
1016
+				EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']);
1017
+			}
1018
+			if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
1019
+				// add to list of widgets to be registered
1020
+				EE_Register_Widget::deregister($addon_name);
1021
+			}
1022
+			if (! empty(self::$_settings[$addon_name]['model_paths'])
1023
+				||
1024
+				! empty(self::$_settings[$addon_name]['class_paths'])
1025
+			) {
1026
+				// add to list of shortcodes to be registered
1027
+				EE_Register_Model::deregister($addon_name);
1028
+			}
1029
+			if (! empty(self::$_settings[$addon_name]['model_extension_paths'])
1030
+				||
1031
+				! empty(self::$_settings[$addon_name]['class_extension_paths'])
1032
+			) {
1033
+				// add to list of shortcodes to be registered
1034
+				EE_Register_Model_Extensions::deregister($addon_name);
1035
+			}
1036
+			if (! empty(self::$_settings[$addon_name]['message_types'])) {
1037
+				foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1038
+					EE_Register_Message_Type::deregister($message_type);
1039
+				}
1040
+			}
1041
+			//deregister capabilities for addon
1042
+			if (
1043
+				! empty(self::$_settings[$addon_name]['capabilities'])
1044
+				|| ! empty(self::$_settings[$addon_name]['capability_maps'])
1045
+			) {
1046
+				EE_Register_Capabilities::deregister($addon_name);
1047
+			}
1048
+			//deregister custom_post_types for addon
1049
+			if (! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1050
+				EE_Register_CPT::deregister($addon_name);
1051
+			}
1052
+			remove_action(
1053
+				'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(),
1054
+				array(EE_Registry::instance()->addons->{$class_name}, 'deactivation')
1055
+			);
1056
+			remove_action(
1057
+				'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1058
+				array(EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required')
1059
+			);
1060
+			unset(EE_Registry::instance()->addons->{$class_name}, self::$_settings[$addon_name]);
1061
+			do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1062
+		}
1063
+	}
1064 1064
 
1065 1065
 
1066 1066
 }
Please login to merge, or discard this patch.
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
@@ -66,15 +66,15 @@  discard block
 block discarded – undo
66 66
         // offsets:    0 . 1 . 2 . 3 . 4
67 67
         $version_parts = explode('.', $min_core_version);
68 68
         //check they specified the micro version (after 2nd period)
69
-        if (! isset($version_parts[2])) {
69
+        if ( ! isset($version_parts[2])) {
70 70
             $version_parts[2] = '0';
71 71
         }
72 72
         //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
73 73
         //soon we can assume that's 'rc', but this current version is 'alpha'
74
-        if (! isset($version_parts[3])) {
74
+        if ( ! isset($version_parts[3])) {
75 75
             $version_parts[3] = 'dev';
76 76
         }
77
-        if (! isset($version_parts[4])) {
77
+        if ( ! isset($version_parts[4])) {
78 78
             $version_parts[4] = '000';
79 79
         }
80 80
         return implode('.', $version_parts);
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
         // setup PUE
232 232
         \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args);
233 233
         // does this addon work with this version of core or WordPress ?
234
-        if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
234
+        if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
235 235
             return;
236 236
         }
237 237
         // register namespaces
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
                 )
289 289
             );
290 290
         }
291
-        if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
291
+        if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) {
292 292
             throw new EE_Error(
293 293
                 sprintf(
294 294
                     __(
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
         } else {
330 330
             $class_name = $setup_args['class_name'];
331 331
         }
332
-        return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name;
332
+        return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_'.$class_name;
333 333
     }
334 334
 
335 335
 
@@ -346,105 +346,105 @@  discard block
 block discarded – undo
346 346
             'class_name'            => $class_name,
347 347
             // the addon slug for use in URLs, etc
348 348
             'plugin_slug'           => isset($setup_args['plugin_slug'])
349
-                ? (string)$setup_args['plugin_slug']
349
+                ? (string) $setup_args['plugin_slug']
350 350
                 : '',
351 351
             // page slug to be used when generating the "Settings" link on the WP plugin page
352 352
             'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
353
-                ? (string)$setup_args['plugin_action_slug']
353
+                ? (string) $setup_args['plugin_action_slug']
354 354
                 : '',
355 355
             // the "software" version for the addon
356 356
             'version'               => isset($setup_args['version'])
357
-                ? (string)$setup_args['version']
357
+                ? (string) $setup_args['version']
358 358
                 : '',
359 359
             // the minimum version of EE Core that the addon will work with
360 360
             'min_core_version'      => isset($setup_args['min_core_version'])
361
-                ? (string)$setup_args['min_core_version']
361
+                ? (string) $setup_args['min_core_version']
362 362
                 : '',
363 363
             // the minimum version of WordPress that the addon will work with
364 364
             'min_wp_version'        => isset($setup_args['min_wp_version'])
365
-                ? (string)$setup_args['min_wp_version']
365
+                ? (string) $setup_args['min_wp_version']
366 366
                 : EE_MIN_WP_VER_REQUIRED,
367 367
             // full server path to main file (file loaded directly by WP)
368 368
             'main_file_path'        => isset($setup_args['main_file_path'])
369
-                ? (string)$setup_args['main_file_path']
369
+                ? (string) $setup_args['main_file_path']
370 370
                 : '',
371 371
             // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
372 372
             'admin_path'            => isset($setup_args['admin_path'])
373
-                ? (string)$setup_args['admin_path'] : '',
373
+                ? (string) $setup_args['admin_path'] : '',
374 374
             // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
375 375
             'admin_callback'        => isset($setup_args['admin_callback'])
376
-                ? (string)$setup_args['admin_callback']
376
+                ? (string) $setup_args['admin_callback']
377 377
                 : '',
378 378
             // the section name for this addon's configuration settings section (defaults to "addons")
379 379
             'config_section'        => isset($setup_args['config_section'])
380
-                ? (string)$setup_args['config_section']
380
+                ? (string) $setup_args['config_section']
381 381
                 : 'addons',
382 382
             // the class name for this addon's configuration settings object
383 383
             'config_class'          => isset($setup_args['config_class'])
384
-                ? (string)$setup_args['config_class'] : '',
384
+                ? (string) $setup_args['config_class'] : '',
385 385
             //the name given to the config for this addons' configuration settings object (optional)
386 386
             'config_name'           => isset($setup_args['config_name'])
387
-                ? (string)$setup_args['config_name'] : '',
387
+                ? (string) $setup_args['config_name'] : '',
388 388
             // an array of "class names" => "full server paths" for any classes that might be invoked by the addon
389 389
             'autoloader_paths'      => isset($setup_args['autoloader_paths'])
390
-                ? (array)$setup_args['autoloader_paths']
390
+                ? (array) $setup_args['autoloader_paths']
391 391
                 : array(),
392 392
             // an array of  "full server paths" for any folders containing classes that might be invoked by the addon
393 393
             'autoloader_folders'    => isset($setup_args['autoloader_folders'])
394
-                ? (array)$setup_args['autoloader_folders']
394
+                ? (array) $setup_args['autoloader_folders']
395 395
                 : array(),
396 396
             // array of full server paths to any EE_DMS data migration scripts used by the addon
397 397
             'dms_paths'             => isset($setup_args['dms_paths'])
398
-                ? (array)$setup_args['dms_paths']
398
+                ? (array) $setup_args['dms_paths']
399 399
                 : array(),
400 400
             // array of full server paths to any EED_Modules used by the addon
401 401
             'module_paths'          => isset($setup_args['module_paths'])
402
-                ? (array)$setup_args['module_paths']
402
+                ? (array) $setup_args['module_paths']
403 403
                 : array(),
404 404
             // array of full server paths to any EES_Shortcodes used by the addon
405 405
             'shortcode_paths'       => isset($setup_args['shortcode_paths'])
406
-                ? (array)$setup_args['shortcode_paths']
406
+                ? (array) $setup_args['shortcode_paths']
407 407
                 : array(),
408 408
             // array of full server paths to any WP_Widgets used by the addon
409 409
             'widget_paths'          => isset($setup_args['widget_paths'])
410
-                ? (array)$setup_args['widget_paths']
410
+                ? (array) $setup_args['widget_paths']
411 411
                 : array(),
412 412
             // array of PUE options used by the addon
413 413
             'pue_options'           => isset($setup_args['pue_options'])
414
-                ? (array)$setup_args['pue_options']
414
+                ? (array) $setup_args['pue_options']
415 415
                 : array(),
416 416
             'message_types'         => isset($setup_args['message_types'])
417
-                ? (array)$setup_args['message_types']
417
+                ? (array) $setup_args['message_types']
418 418
                 : array(),
419 419
             'capabilities'          => isset($setup_args['capabilities'])
420
-                ? (array)$setup_args['capabilities']
420
+                ? (array) $setup_args['capabilities']
421 421
                 : array(),
422 422
             'capability_maps'       => isset($setup_args['capability_maps'])
423
-                ? (array)$setup_args['capability_maps']
423
+                ? (array) $setup_args['capability_maps']
424 424
                 : array(),
425 425
             'model_paths'           => isset($setup_args['model_paths'])
426
-                ? (array)$setup_args['model_paths']
426
+                ? (array) $setup_args['model_paths']
427 427
                 : array(),
428 428
             'class_paths'           => isset($setup_args['class_paths'])
429
-                ? (array)$setup_args['class_paths']
429
+                ? (array) $setup_args['class_paths']
430 430
                 : array(),
431 431
             'model_extension_paths' => isset($setup_args['model_extension_paths'])
432
-                ? (array)$setup_args['model_extension_paths']
432
+                ? (array) $setup_args['model_extension_paths']
433 433
                 : array(),
434 434
             'class_extension_paths' => isset($setup_args['class_extension_paths'])
435
-                ? (array)$setup_args['class_extension_paths']
435
+                ? (array) $setup_args['class_extension_paths']
436 436
                 : array(),
437 437
             'custom_post_types'     => isset($setup_args['custom_post_types'])
438
-                ? (array)$setup_args['custom_post_types']
438
+                ? (array) $setup_args['custom_post_types']
439 439
                 : array(),
440 440
             'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
441
-                ? (array)$setup_args['custom_taxonomies']
441
+                ? (array) $setup_args['custom_taxonomies']
442 442
                 : array(),
443 443
             'payment_method_paths'  => isset($setup_args['payment_method_paths'])
444
-                ? (array)$setup_args['payment_method_paths']
444
+                ? (array) $setup_args['payment_method_paths']
445 445
                 : array(),
446 446
             'default_terms'         => isset($setup_args['default_terms'])
447
-                ? (array)$setup_args['default_terms']
447
+                ? (array) $setup_args['default_terms']
448 448
                 : array(),
449 449
             // if not empty, inserts a new table row after this plugin's row on the WP Plugins page
450 450
             // that can be used for adding upgrading/marketing info
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
                 $setup_args['namespace']['FQNS'],
457 457
                 $setup_args['namespace']['DIR']
458 458
             )
459
-                ? (array)$setup_args['namespace']
459
+                ? (array) $setup_args['namespace']
460 460
                 : array(),
461 461
         );
462 462
         // if plugin_action_slug is NOT set, but an admin page path IS set,
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
                 '</span><br />'
527 527
             );
528 528
         }
529
-        if (! empty($incompatibility_message)) {
529
+        if ( ! empty($incompatibility_message)) {
530 530
             // remove 'activate' from the REQUEST
531 531
             // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
532 532
             unset($_GET['activate'], $_REQUEST['activate']);
@@ -554,19 +554,19 @@  discard block
 block discarded – undo
554 554
      */
555 555
     private static function _parse_pue_options($addon_name, $class_name, array $setup_args)
556 556
     {
557
-        if (! empty($setup_args['pue_options'])) {
557
+        if ( ! empty($setup_args['pue_options'])) {
558 558
             self::$_settings[$addon_name]['pue_options'] = array(
559 559
                 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug'])
560
-                    ? (string)$setup_args['pue_options']['pue_plugin_slug']
561
-                    : 'espresso_' . strtolower($class_name),
560
+                    ? (string) $setup_args['pue_options']['pue_plugin_slug']
561
+                    : 'espresso_'.strtolower($class_name),
562 562
                 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename'])
563
-                    ? (string)$setup_args['pue_options']['plugin_basename']
563
+                    ? (string) $setup_args['pue_options']['plugin_basename']
564 564
                     : plugin_basename($setup_args['main_file_path']),
565 565
                 'checkPeriod'     => isset($setup_args['pue_options']['checkPeriod'])
566
-                    ? (string)$setup_args['pue_options']['checkPeriod']
566
+                    ? (string) $setup_args['pue_options']['checkPeriod']
567 567
                     : '24',
568 568
                 'use_wp_update'   => isset($setup_args['pue_options']['use_wp_update'])
569
-                    ? (string)$setup_args['pue_options']['use_wp_update']
569
+                    ? (string) $setup_args['pue_options']['use_wp_update']
570 570
                     : false,
571 571
             );
572 572
             add_action(
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
             //(as the newly-activated addon wasn't around the first time addons were registered).
615 615
             //Note: the presence of pue_options in the addon registration options will initialize the $_settings
616 616
             //property for the add-on, but the add-on is only partially initialized.  Hence, the additional check.
617
-            if (! isset(self::$_settings[$addon_name])
617
+            if ( ! isset(self::$_settings[$addon_name])
618 618
                 || (isset(self::$_settings[$addon_name])
619 619
                     && ! isset(self::$_settings[$addon_name]['class_name'])
620 620
                 )
@@ -662,13 +662,13 @@  discard block
 block discarded – undo
662 662
      */
663 663
     private static function _setup_autoloaders($addon_name)
664 664
     {
665
-        if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
665
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
666 666
             // setup autoloader for single file
667 667
             EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
668 668
         }
669 669
         // setup autoloaders for folders
670
-        if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
671
-            foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
670
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
671
+            foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
672 672
                 EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
673 673
             }
674 674
         }
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
     private static function _register_data_migration_scripts($addon_name)
722 722
     {
723 723
         // setup DMS
724
-        if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
724
+        if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
725 725
             EE_Register_Data_Migration_Scripts::register(
726 726
                 $addon_name,
727 727
                 array('dms_paths' => self::$_settings[$addon_name]['dms_paths'])
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
     private static function _register_config($addon_name)
739 739
     {
740 740
         // if config_class is present let's register config.
741
-        if (! empty(self::$_settings[$addon_name]['config_class'])) {
741
+        if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
742 742
             EE_Register_Config::register(
743 743
                 self::$_settings[$addon_name]['config_class'],
744 744
                 array(
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
      */
758 758
     private static function _register_admin_pages($addon_name)
759 759
     {
760
-        if (! empty(self::$_settings[$addon_name]['admin_path'])) {
760
+        if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
761 761
             EE_Register_Admin_Page::register(
762 762
                 $addon_name,
763 763
                 array('page_path' => self::$_settings[$addon_name]['admin_path'])
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
      */
774 774
     private static function _register_modules($addon_name)
775 775
     {
776
-        if (! empty(self::$_settings[$addon_name]['module_paths'])) {
776
+        if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
777 777
             EE_Register_Module::register(
778 778
                 $addon_name,
779 779
                 array('module_paths' => self::$_settings[$addon_name]['module_paths'])
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
      */
790 790
     private static function _register_shortcodes($addon_name)
791 791
     {
792
-        if (! empty(self::$_settings[$addon_name]['shortcode_paths'])) {
792
+        if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) {
793 793
             EE_Register_Shortcode::register(
794 794
                 $addon_name,
795 795
                 array('shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths'])
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
      */
806 806
     private static function _register_widgets($addon_name)
807 807
     {
808
-        if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
808
+        if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
809 809
             EE_Register_Widget::register(
810 810
                 $addon_name,
811 811
                 array('widget_paths' => self::$_settings[$addon_name]['widget_paths'])
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
      */
822 822
     private static function _register_capabilities($addon_name)
823 823
     {
824
-        if (! empty(self::$_settings[$addon_name]['capabilities'])) {
824
+        if ( ! empty(self::$_settings[$addon_name]['capabilities'])) {
825 825
             EE_Register_Capabilities::register(
826 826
                 $addon_name,
827 827
                 array(
@@ -840,7 +840,7 @@  discard block
 block discarded – undo
840 840
      */
841 841
     private static function _register_message_types($addon_name)
842 842
     {
843
-        if (! empty(self::$_settings[$addon_name]['message_types'])) {
843
+        if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
844 844
             add_action(
845 845
                 'EE_Brewing_Regular___messages_caf',
846 846
                 array('EE_Register_Addon', 'register_message_types')
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
      */
880 880
     private static function _register_payment_methods($addon_name)
881 881
     {
882
-        if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
882
+        if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
883 883
             EE_Register_Payment_Method::register(
884 884
                 $addon_name,
885 885
                 array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths'])
@@ -915,7 +915,7 @@  discard block
 block discarded – undo
915 915
         //the plugin mainfile's path upon construction.
916 916
         register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation'));
917 917
         // call any additional admin_callback functions during load_admin_controller hook
918
-        if (! empty(self::$_settings[$addon_name]['admin_callback'])) {
918
+        if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) {
919 919
             add_action(
920 920
                 'AHEE__EE_System__load_controllers__load_admin_controllers',
921 921
                 array($addon, self::$_settings[$addon_name]['admin_callback'])
@@ -933,10 +933,10 @@  discard block
 block discarded – undo
933 933
     public static function load_pue_update()
934 934
     {
935 935
         // load PUE client
936
-        require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php';
936
+        require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php';
937 937
         // cycle thru settings
938 938
         foreach (self::$_settings as $settings) {
939
-            if (! empty($settings['pue_options'])) {
939
+            if ( ! empty($settings['pue_options'])) {
940 940
                 // initiate the class and start the plugin update engine!
941 941
                 new PluginUpdateEngineChecker(
942 942
                 // host file URL
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
                     // plugin slug(s)
945 945
                     array(
946 946
                         'premium'    => array('p' => $settings['pue_options']['pue_plugin_slug']),
947
-                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'),
947
+                        'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'),
948 948
                     ),
949 949
                     // options
950 950
                     array(
@@ -973,8 +973,8 @@  discard block
 block discarded – undo
973 973
     public static function register_message_types()
974 974
     {
975 975
         foreach (self::$_settings as $addon_name => $settings) {
976
-            if (! empty($settings['message_types'])) {
977
-                foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) {
976
+            if ( ! empty($settings['message_types'])) {
977
+                foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
978 978
                     EE_Register_Message_Type::register($message_type, $message_type_settings);
979 979
                 }
980 980
             }
@@ -995,46 +995,46 @@  discard block
 block discarded – undo
995 995
         if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) {
996 996
             do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
997 997
             $class_name = self::$_settings[$addon_name]['class_name'];
998
-            if (! empty(self::$_settings[$addon_name]['dms_paths'])) {
998
+            if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
999 999
                 // setup DMS
1000 1000
                 EE_Register_Data_Migration_Scripts::deregister($addon_name);
1001 1001
             }
1002
-            if (! empty(self::$_settings[$addon_name]['admin_path'])) {
1002
+            if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
1003 1003
                 // register admin page
1004 1004
                 EE_Register_Admin_Page::deregister($addon_name);
1005 1005
             }
1006
-            if (! empty(self::$_settings[$addon_name]['module_paths'])) {
1006
+            if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
1007 1007
                 // add to list of modules to be registered
1008 1008
                 EE_Register_Module::deregister($addon_name);
1009 1009
             }
1010
-            if (! empty(self::$_settings[$addon_name]['shortcode_paths'])) {
1010
+            if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) {
1011 1011
                 // add to list of shortcodes to be registered
1012 1012
                 EE_Register_Shortcode::deregister($addon_name);
1013 1013
             }
1014
-            if (! empty(self::$_settings[$addon_name]['config_class'])) {
1014
+            if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
1015 1015
                 // if config_class present let's register config.
1016 1016
                 EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']);
1017 1017
             }
1018
-            if (! empty(self::$_settings[$addon_name]['widget_paths'])) {
1018
+            if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
1019 1019
                 // add to list of widgets to be registered
1020 1020
                 EE_Register_Widget::deregister($addon_name);
1021 1021
             }
1022
-            if (! empty(self::$_settings[$addon_name]['model_paths'])
1022
+            if ( ! empty(self::$_settings[$addon_name]['model_paths'])
1023 1023
                 ||
1024 1024
                 ! empty(self::$_settings[$addon_name]['class_paths'])
1025 1025
             ) {
1026 1026
                 // add to list of shortcodes to be registered
1027 1027
                 EE_Register_Model::deregister($addon_name);
1028 1028
             }
1029
-            if (! empty(self::$_settings[$addon_name]['model_extension_paths'])
1029
+            if ( ! empty(self::$_settings[$addon_name]['model_extension_paths'])
1030 1030
                 ||
1031 1031
                 ! empty(self::$_settings[$addon_name]['class_extension_paths'])
1032 1032
             ) {
1033 1033
                 // add to list of shortcodes to be registered
1034 1034
                 EE_Register_Model_Extensions::deregister($addon_name);
1035 1035
             }
1036
-            if (! empty(self::$_settings[$addon_name]['message_types'])) {
1037
-                foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1036
+            if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
1037
+                foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1038 1038
                     EE_Register_Message_Type::deregister($message_type);
1039 1039
                 }
1040 1040
             }
@@ -1046,11 +1046,11 @@  discard block
 block discarded – undo
1046 1046
                 EE_Register_Capabilities::deregister($addon_name);
1047 1047
             }
1048 1048
             //deregister custom_post_types for addon
1049
-            if (! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1049
+            if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1050 1050
                 EE_Register_CPT::deregister($addon_name);
1051 1051
             }
1052 1052
             remove_action(
1053
-                'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(),
1053
+                'deactivate_'.EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(),
1054 1054
                 array(EE_Registry::instance()->addons->{$class_name}, 'deactivation')
1055 1055
             );
1056 1056
             remove_action(
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Message_Type.lib.php 1 patch
Indentation   +432 added lines, -432 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @since           4.3.0
8 8
  */
9 9
 if (! defined('EVENT_ESPRESSO_VERSION')) {
10
-    exit('No direct script access allowed');
10
+	exit('No direct script access allowed');
11 11
 }
12 12
 
13 13
 /**
@@ -22,461 +22,461 @@  discard block
 block discarded – undo
22 22
 {
23 23
 
24 24
 
25
-    /**
26
-     * Holds values for registered message types
27
-     *
28
-     * @var array
29
-     */
30
-    protected static $_ee_message_type_registry = array();
25
+	/**
26
+	 * Holds values for registered message types
27
+	 *
28
+	 * @var array
29
+	 */
30
+	protected static $_ee_message_type_registry = array();
31 31
 
32 32
 
33
-    /**
34
-     * Method for registering new message types in the EE_messages system.
35
-     * Note:  All message types must have the following files in order to work:
36
-     * Template files for default templates getting setup.
37
-     * See /core/libraries/messages/defaults/default/ for examples
38
-     * (note that template files match a specific naming schema).
39
-     * These templates will need to be registered with the default template pack.
40
-     * - EE_Messages_Validator extended class(es).  See /core/libraries/messages/validators/email/
41
-     *      for examples.  Note for any new message types, there will need to be a validator for each
42
-     *      messenger combo this message type can activate with.
43
-     * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new
44
-     *      message type and its properties.
45
-     *
46
-     * @since    4.3.0
47
-     * @param string $mt_name       Whatever is defined for the $name property of
48
-     *                              the message type you are registering (eg.
49
-     *                              declined_registration). Required.
50
-     * @param  array $setup_args    An array of arguments provided for registering the message type.
51
-     *                              @see inline docs in the register method for what can be passed in as arguments.
52
-     * @throws \EE_Error
53
-     *                              }
54
-     */
55
-    public static function register($mt_name = null, $setup_args = array())
56
-    {
57
-        //required fields MUST be present, so let's make sure they are.
58
-        if (
59
-            ! isset($mt_name)
60
-            || ! is_array($setup_args)
61
-            || empty($setup_args['mtfilename']) || empty($setup_args['autoloadpaths'])
62
-        ) {
63
-            throw new EE_Error(
64
-                __('In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"',
65
-                    'event_espresso')
66
-            );
67
-        }
33
+	/**
34
+	 * Method for registering new message types in the EE_messages system.
35
+	 * Note:  All message types must have the following files in order to work:
36
+	 * Template files for default templates getting setup.
37
+	 * See /core/libraries/messages/defaults/default/ for examples
38
+	 * (note that template files match a specific naming schema).
39
+	 * These templates will need to be registered with the default template pack.
40
+	 * - EE_Messages_Validator extended class(es).  See /core/libraries/messages/validators/email/
41
+	 *      for examples.  Note for any new message types, there will need to be a validator for each
42
+	 *      messenger combo this message type can activate with.
43
+	 * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new
44
+	 *      message type and its properties.
45
+	 *
46
+	 * @since    4.3.0
47
+	 * @param string $mt_name       Whatever is defined for the $name property of
48
+	 *                              the message type you are registering (eg.
49
+	 *                              declined_registration). Required.
50
+	 * @param  array $setup_args    An array of arguments provided for registering the message type.
51
+	 *                              @see inline docs in the register method for what can be passed in as arguments.
52
+	 * @throws \EE_Error
53
+	 *                              }
54
+	 */
55
+	public static function register($mt_name = null, $setup_args = array())
56
+	{
57
+		//required fields MUST be present, so let's make sure they are.
58
+		if (
59
+			! isset($mt_name)
60
+			|| ! is_array($setup_args)
61
+			|| empty($setup_args['mtfilename']) || empty($setup_args['autoloadpaths'])
62
+		) {
63
+			throw new EE_Error(
64
+				__('In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"',
65
+					'event_espresso')
66
+			);
67
+		}
68 68
 
69
-        //make sure we don't register twice
70
-        if (isset(self::$_ee_message_type_registry[$mt_name])) {
71
-            return;
72
-        }
69
+		//make sure we don't register twice
70
+		if (isset(self::$_ee_message_type_registry[$mt_name])) {
71
+			return;
72
+		}
73 73
 
74
-        //make sure this was called in the right place!
75
-        if (
76
-            ! did_action('EE_Brewing_Regular___messages_caf')
77
-            || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
78
-        ) {
79
-            EE_Error::doing_it_wrong(
80
-                __METHOD__,
81
-                sprintf(
82
-                    __('A message type named "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular___messages_caf" hook.',
83
-                        'event_espresso'),
84
-                    $mt_name
85
-                ),
86
-                '4.3.0'
87
-            );
88
-        }
89
-        //setup $__ee_message_type_registry array from incoming values.
90
-        self::$_ee_message_type_registry[$mt_name] = array(
91
-            /**
92
-             * The file name for the message type being registered.
93
-             * Required.
94
-             * @type string
95
-             */
96
-            'mtfilename'                  => (string)$setup_args['mtfilename'],
97
-            /**
98
-             * Autoload paths for classes used by the message type.
99
-             * Required.
100
-             * @type array
101
-             */
102
-            'autoloadpaths'               => (array)$setup_args['autoloadpaths'],
103
-            /**
104
-             * Messengers that the message type should be able to activate with.
105
-             * Use messenger slugs.
106
-             * @type array
107
-             */
108
-            'messengers_to_activate_with' => ! empty($setup_args['messengers_to_activate_with'])
109
-                ? (array)$setup_args['messengers_to_activate_with']
110
-                : array(),
111
-            /**
112
-             * Messengers that the message type should validate with.
113
-             * Use messenger slugs.
114
-             * @type array
115
-             */
116
-            'messengers_to_validate_with' => ! empty($setup_args['messengers_to_validate_with'])
117
-                ? (array)$setup_args['messengers_to_validate_with']
118
-                : array(),
119
-            /**
120
-             * Whether to force activate this message type the first time it is registered.
121
-             * @type bool   False means its not activated by default and left up to the end user to activate.
122
-             */
123
-            'force_activation'            => ! empty($setup_args['force_activation'])
124
-                ? (bool)$setup_args['force_activation']
125
-                : false,
126
-            /**
127
-             * What messengers this message type supports the default template pack for.
128
-             * Note: If you do not set this (or any of the following template pack/variation related arguments) to true,
129
-             * then it is expected that the message type being registered is doing its own custom default template
130
-             * pack/variation registration.
131
-             *
132
-             * If this is set and has values, then it is expected that the following arguments are also set in the incoming options
133
-             * $setup_arguments array as well:
134
-             * - 'base_path_for_default_templates'
135
-             *
136
-             * @type array   Expect an array of messengers this supports default template packs for.
137
-             */
138
-            'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with'])
139
-                ? (array)$setup_args['messengers_supporting_default_template_pack_with']
140
-                : array(),
141
-            /**
142
-             * The base path where the default templates for this message type can be found.
143
-             * @type string
144
-             */
145
-            'base_path_for_default_templates' => isset($setup_args['base_path_for_default_templates'])
146
-                ? $setup_args['base_path_for_default_templates']
147
-                : '',
148
-            /**
149
-             * The base path where the default variations for this message type can be found.
150
-             * @type string
151
-             */
152
-            'base_path_for_default_variation' => isset($setup_args['base_path_for_default_variation'])
153
-                ? $setup_args['base_path_for_default_variation']
154
-                : '',
155
-            /**
156
-             * The base url for the default variations for this message type.
157
-             * @type string
158
-             */
159
-            'base_url_for_default_variation' => isset($setup_args['base_url_for_default_variation'])
160
-                ? $setup_args['base_url_for_default_variation']
161
-                : ''
162
-        );
163
-        //add filters but only if they haven't already been set (these filters only need to be registered ONCE because
164
-        //the callback handles all registered message types.
165
-        if ( false === has_filter(
166
-            'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
167
-            array('EE_Register_Message_Type', 'register_msgs_autoload_paths')
168
-        )) {
169
-            add_filter(
170
-                'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
171
-                array('EE_Register_Message_Type', 'register_msgs_autoload_paths'),
172
-                10
173
-            );
174
-            add_filter(
175
-                'FHEE__EE_messages__get_installed__messagetype_files',
176
-                array('EE_Register_Message_Type', 'register_messagetype_files'),
177
-                10,
178
-                1
179
-            );
180
-            add_filter(
181
-                'FHEE__EE_messenger__get_default_message_types__default_types',
182
-                array('EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'),
183
-                10,
184
-                2
185
-            );
186
-            add_filter(
187
-                'FHEE__EE_messenger__get_valid_message_types__valid_types',
188
-                array('EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'),
189
-                10,
190
-                2
191
-            );
192
-            //actions
193
-            add_action(
194
-                'AHEE__EE_Addon__initialize_default_data__begin',
195
-                array('EE_Register_Message_Type', 'set_defaults')
196
-            );
74
+		//make sure this was called in the right place!
75
+		if (
76
+			! did_action('EE_Brewing_Regular___messages_caf')
77
+			|| did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
78
+		) {
79
+			EE_Error::doing_it_wrong(
80
+				__METHOD__,
81
+				sprintf(
82
+					__('A message type named "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular___messages_caf" hook.',
83
+						'event_espresso'),
84
+					$mt_name
85
+				),
86
+				'4.3.0'
87
+			);
88
+		}
89
+		//setup $__ee_message_type_registry array from incoming values.
90
+		self::$_ee_message_type_registry[$mt_name] = array(
91
+			/**
92
+			 * The file name for the message type being registered.
93
+			 * Required.
94
+			 * @type string
95
+			 */
96
+			'mtfilename'                  => (string)$setup_args['mtfilename'],
97
+			/**
98
+			 * Autoload paths for classes used by the message type.
99
+			 * Required.
100
+			 * @type array
101
+			 */
102
+			'autoloadpaths'               => (array)$setup_args['autoloadpaths'],
103
+			/**
104
+			 * Messengers that the message type should be able to activate with.
105
+			 * Use messenger slugs.
106
+			 * @type array
107
+			 */
108
+			'messengers_to_activate_with' => ! empty($setup_args['messengers_to_activate_with'])
109
+				? (array)$setup_args['messengers_to_activate_with']
110
+				: array(),
111
+			/**
112
+			 * Messengers that the message type should validate with.
113
+			 * Use messenger slugs.
114
+			 * @type array
115
+			 */
116
+			'messengers_to_validate_with' => ! empty($setup_args['messengers_to_validate_with'])
117
+				? (array)$setup_args['messengers_to_validate_with']
118
+				: array(),
119
+			/**
120
+			 * Whether to force activate this message type the first time it is registered.
121
+			 * @type bool   False means its not activated by default and left up to the end user to activate.
122
+			 */
123
+			'force_activation'            => ! empty($setup_args['force_activation'])
124
+				? (bool)$setup_args['force_activation']
125
+				: false,
126
+			/**
127
+			 * What messengers this message type supports the default template pack for.
128
+			 * Note: If you do not set this (or any of the following template pack/variation related arguments) to true,
129
+			 * then it is expected that the message type being registered is doing its own custom default template
130
+			 * pack/variation registration.
131
+			 *
132
+			 * If this is set and has values, then it is expected that the following arguments are also set in the incoming options
133
+			 * $setup_arguments array as well:
134
+			 * - 'base_path_for_default_templates'
135
+			 *
136
+			 * @type array   Expect an array of messengers this supports default template packs for.
137
+			 */
138
+			'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with'])
139
+				? (array)$setup_args['messengers_supporting_default_template_pack_with']
140
+				: array(),
141
+			/**
142
+			 * The base path where the default templates for this message type can be found.
143
+			 * @type string
144
+			 */
145
+			'base_path_for_default_templates' => isset($setup_args['base_path_for_default_templates'])
146
+				? $setup_args['base_path_for_default_templates']
147
+				: '',
148
+			/**
149
+			 * The base path where the default variations for this message type can be found.
150
+			 * @type string
151
+			 */
152
+			'base_path_for_default_variation' => isset($setup_args['base_path_for_default_variation'])
153
+				? $setup_args['base_path_for_default_variation']
154
+				: '',
155
+			/**
156
+			 * The base url for the default variations for this message type.
157
+			 * @type string
158
+			 */
159
+			'base_url_for_default_variation' => isset($setup_args['base_url_for_default_variation'])
160
+				? $setup_args['base_url_for_default_variation']
161
+				: ''
162
+		);
163
+		//add filters but only if they haven't already been set (these filters only need to be registered ONCE because
164
+		//the callback handles all registered message types.
165
+		if ( false === has_filter(
166
+			'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
167
+			array('EE_Register_Message_Type', 'register_msgs_autoload_paths')
168
+		)) {
169
+			add_filter(
170
+				'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
171
+				array('EE_Register_Message_Type', 'register_msgs_autoload_paths'),
172
+				10
173
+			);
174
+			add_filter(
175
+				'FHEE__EE_messages__get_installed__messagetype_files',
176
+				array('EE_Register_Message_Type', 'register_messagetype_files'),
177
+				10,
178
+				1
179
+			);
180
+			add_filter(
181
+				'FHEE__EE_messenger__get_default_message_types__default_types',
182
+				array('EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'),
183
+				10,
184
+				2
185
+			);
186
+			add_filter(
187
+				'FHEE__EE_messenger__get_valid_message_types__valid_types',
188
+				array('EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'),
189
+				10,
190
+				2
191
+			);
192
+			//actions
193
+			add_action(
194
+				'AHEE__EE_Addon__initialize_default_data__begin',
195
+				array('EE_Register_Message_Type', 'set_defaults')
196
+			);
197 197
 
198
-            //default template packs and variations related
199
-            add_filter(
200
-                'FHEE__EE_Messages_Template_Pack_Default__get_supports',
201
-                array('EE_Register_Message_Type', 'register_default_template_pack_supports')
202
-            );
203
-            add_filter(
204
-                'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path',
205
-                array('EE_Register_Message_Type', 'register_base_template_path'),
206
-                10,
207
-                6
208
-            );
209
-            add_filter(
210
-                'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url',
211
-                array('EE_Register_Message_Type', 'register_variation_base_path_or_url'),
212
-                10,
213
-                8
214
-            );
215
-            add_filter(
216
-                'FHEE__EE_Messages_Template_Pack__get_variation__base_path',
217
-                array('EE_Register_Message_Type', 'register_variation_base_path_or_url'),
218
-                10,
219
-                8
220
-            );
221
-        }
222
-    }
198
+			//default template packs and variations related
199
+			add_filter(
200
+				'FHEE__EE_Messages_Template_Pack_Default__get_supports',
201
+				array('EE_Register_Message_Type', 'register_default_template_pack_supports')
202
+			);
203
+			add_filter(
204
+				'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path',
205
+				array('EE_Register_Message_Type', 'register_base_template_path'),
206
+				10,
207
+				6
208
+			);
209
+			add_filter(
210
+				'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url',
211
+				array('EE_Register_Message_Type', 'register_variation_base_path_or_url'),
212
+				10,
213
+				8
214
+			);
215
+			add_filter(
216
+				'FHEE__EE_Messages_Template_Pack__get_variation__base_path',
217
+				array('EE_Register_Message_Type', 'register_variation_base_path_or_url'),
218
+				10,
219
+				8
220
+			);
221
+		}
222
+	}
223 223
 
224 224
 
225
-    /**
226
-     * This just ensures that when an addon registers a message type that on initial activation/reactivation the
227
-     * defaults the addon sets are taken care of.
228
-     */
229
-    public static function set_defaults()
230
-    {
231
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
232
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
225
+	/**
226
+	 * This just ensures that when an addon registers a message type that on initial activation/reactivation the
227
+	 * defaults the addon sets are taken care of.
228
+	 */
229
+	public static function set_defaults()
230
+	{
231
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
232
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
233 233
 
234
-        //for any message types with force activation, let's ensure they are activated
235
-        foreach (self::$_ee_message_type_registry as $message_type_name => $settings) {
236
-            if ($settings['force_activation']) {
237
-                foreach ($settings['messengers_to_activate_with'] as $messenger) {
238
-                    //DO not force activation if this message type has already been activated in the system
239
-                    if (! $message_resource_manager->has_message_type_been_activated_for_messenger($message_type_name,
240
-                        $messenger)
241
-                    ) {
242
-                        $message_resource_manager->ensure_message_type_is_active($message_type_name, $messenger);
243
-                    }
244
-                }
245
-            }
246
-        }
247
-    }
234
+		//for any message types with force activation, let's ensure they are activated
235
+		foreach (self::$_ee_message_type_registry as $message_type_name => $settings) {
236
+			if ($settings['force_activation']) {
237
+				foreach ($settings['messengers_to_activate_with'] as $messenger) {
238
+					//DO not force activation if this message type has already been activated in the system
239
+					if (! $message_resource_manager->has_message_type_been_activated_for_messenger($message_type_name,
240
+						$messenger)
241
+					) {
242
+						$message_resource_manager->ensure_message_type_is_active($message_type_name, $messenger);
243
+					}
244
+				}
245
+			}
246
+		}
247
+	}
248 248
 
249 249
 
250
-    /**
251
-     * This deregisters a message type that was previously registered with a specific message_type_name.
252
-     *
253
-     * @since    4.3.0
254
-     * @param string $message_type_name the name for the message type that was previously registered
255
-     * @return void
256
-     */
257
-    public static function deregister($message_type_name = null)
258
-    {
259
-        if (! empty(self::$_ee_message_type_registry[$message_type_name])) {
260
-            //let's make sure that we remove any place this message type was made active
261
-            /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
262
-            $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
263
-            //ensures that if this message type is registered again that it retains its previous active state vs
264
-            //remaining inactive.
265
-            $Message_Resource_Manager->remove_message_type_has_been_activated_from_all_messengers(
266
-                $message_type_name,
267
-                true
268
-            );
269
-            $Message_Resource_Manager->deactivate_message_type($message_type_name, false);
270
-            unset(self::$_ee_message_type_registry[$message_type_name]);
271
-        }
272
-    }
250
+	/**
251
+	 * This deregisters a message type that was previously registered with a specific message_type_name.
252
+	 *
253
+	 * @since    4.3.0
254
+	 * @param string $message_type_name the name for the message type that was previously registered
255
+	 * @return void
256
+	 */
257
+	public static function deregister($message_type_name = null)
258
+	{
259
+		if (! empty(self::$_ee_message_type_registry[$message_type_name])) {
260
+			//let's make sure that we remove any place this message type was made active
261
+			/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
262
+			$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
263
+			//ensures that if this message type is registered again that it retains its previous active state vs
264
+			//remaining inactive.
265
+			$Message_Resource_Manager->remove_message_type_has_been_activated_from_all_messengers(
266
+				$message_type_name,
267
+				true
268
+			);
269
+			$Message_Resource_Manager->deactivate_message_type($message_type_name, false);
270
+			unset(self::$_ee_message_type_registry[$message_type_name]);
271
+		}
272
+	}
273 273
 
274 274
 
275
-    /**
276
-     * callback for FHEE__EE_messages__get_installed__messagetype_files filter.
277
-     *
278
-     * @since   4.3.0
279
-     * @param  array $messagetype_files The current array of message type file names
280
-     * @return  array                                 Array of message type file names
281
-     */
282
-    public static function register_messagetype_files($messagetype_files)
283
-    {
284
-        if (empty(self::$_ee_message_type_registry)) {
285
-            return $messagetype_files;
286
-        }
287
-        foreach (self::$_ee_message_type_registry as $mt_reg) {
288
-            if (empty($mt_reg['mtfilename'])) {
289
-                continue;
290
-            }
291
-            $messagetype_files[] = $mt_reg['mtfilename'];
292
-        }
293
-        return $messagetype_files;
294
-    }
275
+	/**
276
+	 * callback for FHEE__EE_messages__get_installed__messagetype_files filter.
277
+	 *
278
+	 * @since   4.3.0
279
+	 * @param  array $messagetype_files The current array of message type file names
280
+	 * @return  array                                 Array of message type file names
281
+	 */
282
+	public static function register_messagetype_files($messagetype_files)
283
+	{
284
+		if (empty(self::$_ee_message_type_registry)) {
285
+			return $messagetype_files;
286
+		}
287
+		foreach (self::$_ee_message_type_registry as $mt_reg) {
288
+			if (empty($mt_reg['mtfilename'])) {
289
+				continue;
290
+			}
291
+			$messagetype_files[] = $mt_reg['mtfilename'];
292
+		}
293
+		return $messagetype_files;
294
+	}
295 295
 
296 296
 
297
-    /**
298
-     * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.
299
-     *
300
-     * @since    4.3.0
301
-     * @param array $paths array of paths to be checked by EE_messages autoloader.
302
-     * @return array
303
-     */
304
-    public static function register_msgs_autoload_paths($paths)
305
-    {
306
-        if (! empty(self::$_ee_message_type_registry)) {
307
-            foreach (self::$_ee_message_type_registry as $mt_reg) {
308
-                if (empty($mt_reg['autoloadpaths'])) {
309
-                    continue;
310
-                }
311
-                $paths = array_merge($paths, $mt_reg['autoloadpaths']);
312
-            }
313
-        }
314
-        return $paths;
315
-    }
297
+	/**
298
+	 * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.
299
+	 *
300
+	 * @since    4.3.0
301
+	 * @param array $paths array of paths to be checked by EE_messages autoloader.
302
+	 * @return array
303
+	 */
304
+	public static function register_msgs_autoload_paths($paths)
305
+	{
306
+		if (! empty(self::$_ee_message_type_registry)) {
307
+			foreach (self::$_ee_message_type_registry as $mt_reg) {
308
+				if (empty($mt_reg['autoloadpaths'])) {
309
+					continue;
310
+				}
311
+				$paths = array_merge($paths, $mt_reg['autoloadpaths']);
312
+			}
313
+		}
314
+		return $paths;
315
+	}
316 316
 
317 317
 
318
-    /**
319
-     * callback for FHEE__EE_messenger__get_default_message_types__default_types filter.
320
-     *
321
-     * @since  4.3.0
322
-     * @param  array        $default_types  array of message types activated with messenger (
323
-     *                                      corresponds to the $name property of message type)
324
-     * @param  EE_messenger $messenger      The EE_messenger the filter is called from.
325
-     * @return array
326
-     */
327
-    public static function register_messengers_to_activate_mt_with($default_types, EE_messenger $messenger)
328
-    {
329
-        if (empty(self::$_ee_message_type_registry)) {
330
-            return $default_types;
331
-        }
332
-        foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) {
333
-            if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) {
334
-                continue;
335
-            }
336
-            // loop through each of the messengers and if it matches the loaded class
337
-            // then we add this message type to the
338
-            foreach ($mt_reg['messengers_to_activate_with'] as $msgr) {
339
-                if ($messenger->name == $msgr) {
340
-                    $default_types[] = $message_type_name;
341
-                }
342
-            }
343
-        }
318
+	/**
319
+	 * callback for FHEE__EE_messenger__get_default_message_types__default_types filter.
320
+	 *
321
+	 * @since  4.3.0
322
+	 * @param  array        $default_types  array of message types activated with messenger (
323
+	 *                                      corresponds to the $name property of message type)
324
+	 * @param  EE_messenger $messenger      The EE_messenger the filter is called from.
325
+	 * @return array
326
+	 */
327
+	public static function register_messengers_to_activate_mt_with($default_types, EE_messenger $messenger)
328
+	{
329
+		if (empty(self::$_ee_message_type_registry)) {
330
+			return $default_types;
331
+		}
332
+		foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) {
333
+			if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) {
334
+				continue;
335
+			}
336
+			// loop through each of the messengers and if it matches the loaded class
337
+			// then we add this message type to the
338
+			foreach ($mt_reg['messengers_to_activate_with'] as $msgr) {
339
+				if ($messenger->name == $msgr) {
340
+					$default_types[] = $message_type_name;
341
+				}
342
+			}
343
+		}
344 344
 
345
-        return $default_types;
346
-    }
345
+		return $default_types;
346
+	}
347 347
 
348 348
 
349
-    /**
350
-     * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter.
351
-     *
352
-     * @since   4.3.0
353
-     * @param  array        $valid_types    array of message types valid with messenger (
354
-     *                                      corresponds to the $name property of message type)
355
-     * @param  EE_messenger $messenger      The EE_messenger the filter is called from.
356
-     * @return  array
357
-     */
358
-    public static function register_messengers_to_validate_mt_with($valid_types, EE_messenger $messenger)
359
-    {
360
-        if (empty(self::$_ee_message_type_registry)) {
361
-            return $valid_types;
362
-        }
363
-        foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) {
364
-            if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) {
365
-                continue;
366
-            }
367
-            // loop through each of the messengers and if it matches the loaded class
368
-            // then we add this message type to the
369
-            foreach ($mt_reg['messengers_to_validate_with'] as $msgr) {
370
-                if ($messenger->name == $msgr) {
371
-                    $valid_types[] = $message_type_name;
372
-                }
373
-            }
374
-        }
349
+	/**
350
+	 * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter.
351
+	 *
352
+	 * @since   4.3.0
353
+	 * @param  array        $valid_types    array of message types valid with messenger (
354
+	 *                                      corresponds to the $name property of message type)
355
+	 * @param  EE_messenger $messenger      The EE_messenger the filter is called from.
356
+	 * @return  array
357
+	 */
358
+	public static function register_messengers_to_validate_mt_with($valid_types, EE_messenger $messenger)
359
+	{
360
+		if (empty(self::$_ee_message_type_registry)) {
361
+			return $valid_types;
362
+		}
363
+		foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) {
364
+			if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) {
365
+				continue;
366
+			}
367
+			// loop through each of the messengers and if it matches the loaded class
368
+			// then we add this message type to the
369
+			foreach ($mt_reg['messengers_to_validate_with'] as $msgr) {
370
+				if ($messenger->name == $msgr) {
371
+					$valid_types[] = $message_type_name;
372
+				}
373
+			}
374
+		}
375 375
 
376
-        return $valid_types;
377
-    }
376
+		return $valid_types;
377
+	}
378 378
 
379 379
 
380
-    /**
381
-     * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as
382
-     * supporting the default template pack
383
-     *
384
-     * @param array $supports
385
-     *
386
-     * @return array
387
-     */
388
-    public static function register_default_template_pack_supports($supports)
389
-    {
390
-        foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) {
391
-            if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) {
392
-                continue;
393
-            }
394
-            foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
395
-                $supports[$messenger_slug][] = $message_type_name;
396
-            }
397
-        }
398
-        return $supports;
399
-    }
380
+	/**
381
+	 * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as
382
+	 * supporting the default template pack
383
+	 *
384
+	 * @param array $supports
385
+	 *
386
+	 * @return array
387
+	 */
388
+	public static function register_default_template_pack_supports($supports)
389
+	{
390
+		foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) {
391
+			if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) {
392
+				continue;
393
+			}
394
+			foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
395
+				$supports[$messenger_slug][] = $message_type_name;
396
+			}
397
+		}
398
+		return $supports;
399
+	}
400 400
 
401 401
 
402
-    /**
403
-     * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path
404
-     *
405
-     * @param string $base_path The original base path for message templates
406
-     * @param EE_messenger $messenger
407
-     * @param EE_message_type $message_type
408
-     * @param string $field  The field requesting a template
409
-     * @param string $context  The context requesting a template
410
-     * @param EE_Messages_Template_Pack $template_pack
411
-     *
412
-     * @return string
413
-     */
414
-    public static function register_base_template_path(
415
-        $base_path,
416
-        $messenger,
417
-        $message_type,
418
-        $field,
419
-        $context,
420
-        $template_pack
421
-    ) {
422
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default
423
-            || ! $message_type instanceof EE_message_type
424
-        ) {
425
-            return $base_path;
426
-        }
427
-        foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) {
428
-            if ($message_type->name === $message_type_name
429
-                && ! empty($mt_reg['base_path_for_default_templates'])
430
-            ) {
431
-                return $mt_reg['base_path_for_default_templates'];
432
-            }
433
-        }
434
-        return $base_path;
435
-    }
402
+	/**
403
+	 * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path
404
+	 *
405
+	 * @param string $base_path The original base path for message templates
406
+	 * @param EE_messenger $messenger
407
+	 * @param EE_message_type $message_type
408
+	 * @param string $field  The field requesting a template
409
+	 * @param string $context  The context requesting a template
410
+	 * @param EE_Messages_Template_Pack $template_pack
411
+	 *
412
+	 * @return string
413
+	 */
414
+	public static function register_base_template_path(
415
+		$base_path,
416
+		$messenger,
417
+		$message_type,
418
+		$field,
419
+		$context,
420
+		$template_pack
421
+	) {
422
+		if (! $template_pack instanceof EE_Messages_Template_Pack_Default
423
+			|| ! $message_type instanceof EE_message_type
424
+		) {
425
+			return $base_path;
426
+		}
427
+		foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) {
428
+			if ($message_type->name === $message_type_name
429
+				&& ! empty($mt_reg['base_path_for_default_templates'])
430
+			) {
431
+				return $mt_reg['base_path_for_default_templates'];
432
+			}
433
+		}
434
+		return $base_path;
435
+	}
436 436
 
437 437
 
438
-    /**
439
-     * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and
440
-     * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks
441
-     *
442
-     * @param string $base_path_or_url       The original incoming base url or path
443
-     * @param string $messenger_slug      The slug of the messenger the template is being generated for.
444
-     * @param string $message_type_slug The slug of the message type the template is being generated for.
445
-     * @param string $type             The "type" of css being requested.
446
-     * @param string $variation      The variation being requested.
447
-     * @param string $file_extension What file extension is expected for the variation file.
448
-     * @param bool $url whether a url or path is being requested.
449
-     * @param EE_Messages_Template_Pack $template_pack
450
-     *
451
-     * @return string
452
-     */
453
-    public static function register_variation_base_path_or_url(
454
-        $base_path_or_url,
455
-        $messenger_slug,
456
-        $message_type_slug,
457
-        $type,
458
-        $variation,
459
-        $url,
460
-        $file_extension,
461
-        $template_pack
462
-    ) {
463
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
464
-            return $base_path_or_url;
465
-        }
466
-        foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) {
467
-            if ($message_type_name === $message_type_slug
468
-            ) {
469
-                if ($url
470
-                    && ! empty($mt_reg['base_url_for_default_variation'])
471
-                ) {
472
-                    return $mt_reg['base_url_for_default_variation'];
473
-                } elseif (! $url
474
-                    && ! empty($mt_reg['base_path_for_default_variation'])
475
-                ) {
476
-                    return $mt_reg['base_path_for_default_variation'];
477
-                }
478
-            }
479
-        }
480
-        return $base_path_or_url;
481
-    }
438
+	/**
439
+	 * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and
440
+	 * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks
441
+	 *
442
+	 * @param string $base_path_or_url       The original incoming base url or path
443
+	 * @param string $messenger_slug      The slug of the messenger the template is being generated for.
444
+	 * @param string $message_type_slug The slug of the message type the template is being generated for.
445
+	 * @param string $type             The "type" of css being requested.
446
+	 * @param string $variation      The variation being requested.
447
+	 * @param string $file_extension What file extension is expected for the variation file.
448
+	 * @param bool $url whether a url or path is being requested.
449
+	 * @param EE_Messages_Template_Pack $template_pack
450
+	 *
451
+	 * @return string
452
+	 */
453
+	public static function register_variation_base_path_or_url(
454
+		$base_path_or_url,
455
+		$messenger_slug,
456
+		$message_type_slug,
457
+		$type,
458
+		$variation,
459
+		$url,
460
+		$file_extension,
461
+		$template_pack
462
+	) {
463
+		if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
464
+			return $base_path_or_url;
465
+		}
466
+		foreach (self::$_ee_message_type_registry as $message_type_name => $mt_reg) {
467
+			if ($message_type_name === $message_type_slug
468
+			) {
469
+				if ($url
470
+					&& ! empty($mt_reg['base_url_for_default_variation'])
471
+				) {
472
+					return $mt_reg['base_url_for_default_variation'];
473
+				} elseif (! $url
474
+					&& ! empty($mt_reg['base_path_for_default_variation'])
475
+				) {
476
+					return $mt_reg['base_path_for_default_variation'];
477
+				}
478
+			}
479
+		}
480
+		return $base_path_or_url;
481
+	}
482 482
 }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Message_Resource_Manager.lib.php 2 patches
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if (! defined('EVENT_ESPRESSO_VERSION')) {
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
5 5
 }
6 6
 
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
     public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
277 277
     {
278 278
         $this->_initialize_collections();
279
-        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
279
+        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]);
280 280
     }
281 281
 
282 282
 
@@ -304,8 +304,8 @@  discard block
 block discarded – undo
304 304
     {
305 305
         $settings = array();
306 306
         if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
307
-            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
308
-                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
307
+            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'])
308
+                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings']
309 309
                 : array();
310 310
         }
311 311
         return $settings;
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
         $this->_initialize_collections();
325 325
         return
326 326
             ! empty($this->_active_message_types[$messenger_name])
327
-            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
327
+            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types']);
328 328
     }
329 329
 
330 330
 
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
     public function get_active_message_types_for_messenger($messenger_name)
340 340
     {
341 341
         $message_types = array();
342
-        if (! $this->messenger_has_active_message_types($messenger_name)) {
342
+        if ( ! $this->messenger_has_active_message_types($messenger_name)) {
343 343
             return $message_types;
344 344
         }
345 345
         $installed_message_types = $this->installed_message_types();
@@ -364,11 +364,11 @@  discard block
 block discarded – undo
364 364
         $active_message_type_names = array();
365 365
         $this->_initialize_collections();
366 366
         foreach ($this->_active_message_types as $messenger => $messenger_settings) {
367
-            if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
367
+            if ( ! isset($messenger_settings['settings'][$messenger.'-message_types'])) {
368 368
                 continue;
369 369
             }
370
-            foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
371
-                if (! in_array($message_type_name, $active_message_type_names)) {
370
+            foreach ($messenger_settings['settings'][$messenger.'-message_types'] as $message_type_name => $message_type_config) {
371
+                if ( ! in_array($message_type_name, $active_message_type_names)) {
372 372
                     $active_message_type_names[] = $message_type_name;
373 373
                 }
374 374
             }
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
     public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
445 445
     {
446 446
         $valid_message_types = $messenger->get_valid_message_types();
447
-        if (! in_array($message_type_name, $valid_message_types)) {
447
+        if ( ! in_array($message_type_name, $valid_message_types)) {
448 448
             throw new EE_Error(
449 449
                 sprintf(
450 450
                     __(
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
      */
568 568
     public function ensure_messenger_is_active($messenger_name, $update_option = true)
569 569
     {
570
-        if (! isset($this->_active_messengers[$messenger_name])) {
570
+        if ( ! isset($this->_active_messengers[$messenger_name])) {
571 571
             try {
572 572
                 $this->activate_messenger($messenger_name, array(), $update_option);
573 573
             } catch (EE_Error $e) {
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
             $this->ensure_messenger_is_active($messenger_name, $update_option);
613 613
         }
614 614
 
615
-        if (! empty($not_installed_messenger)) {
615
+        if ( ! empty($not_installed_messenger)) {
616 616
             EE_Error::add_error(
617 617
                 sprintf(
618 618
                     __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
             //ensure messenger is active (that's an inherent coupling between active message types and the
644 644
             //messenger they are being activated for.
645 645
             try {
646
-                if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
646
+                if ( ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
647 647
                     //all is good so let's just get it active
648 648
                     $this->activate_messenger($messenger_name, array($message_type_name), $update_option);
649 649
                 }
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
      */
672 672
     public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
673 673
     {
674
-        $message_type_names = (array)$message_type_names;
674
+        $message_type_names = (array) $message_type_names;
675 675
         foreach ($message_type_names as $message_type_name) {
676 676
             // note, intentionally not updating option here because we're in a loop.
677 677
             // We'll follow the instructions of the incoming $update_option argument after the loop.
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
             //generate new templates if necessary and ensure all related templates that are already in the database are
718 718
             //marked active.  Note, this will also deactivate a message type for a messenger if the template
719 719
             //cannot be successfully created during its attempt (only happens for global template attempts).
720
-            if (! empty($message_type_names)) {
720
+            if ( ! empty($message_type_names)) {
721 721
                 $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
722 722
                 EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
723 723
             }
@@ -743,10 +743,10 @@  discard block
 block discarded – undo
743 743
         //only override _active_message_types when an explicit array of $message_type_names has been provided.
744 744
         $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
745 745
             ? $messenger->get_default_message_types()
746
-            : (array)$message_type_names;
746
+            : (array) $message_type_names;
747 747
 
748 748
         //now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
749
-        if (! isset($this->_active_message_types[$messenger->name])) {
749
+        if ( ! isset($this->_active_message_types[$messenger->name])) {
750 750
             $this->_active_message_types[$messenger->name]['settings'] = array();
751 751
         }
752 752
 
@@ -792,12 +792,12 @@  discard block
 block discarded – undo
792 792
                     $existing_settings[$field] = $new_settings[$field];
793 793
                     continue;
794 794
                 }
795
-                if (! isset($existing_settings[$field])) {
795
+                if ( ! isset($existing_settings[$field])) {
796 796
                     $existing_settings[$field] = $values['default'];
797 797
                 }
798 798
             }
799 799
         }
800
-        $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
800
+        $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'] = $existing_settings;
801 801
     }
802 802
 
803 803
 
@@ -818,11 +818,11 @@  discard block
 block discarded – undo
818 818
         }
819 819
 
820 820
         // make sure this messenger has a record in the has_activated array
821
-        if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
821
+        if ( ! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
822 822
             $this->_has_activated_messengers_and_message_types[$messenger->name] = array();
823 823
         }
824 824
         // check if message type has already been added
825
-        if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
825
+        if ( ! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
826 826
             $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
827 827
         }
828 828
     }
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
         $messenger = $this->get_messenger($messenger_name);
842 842
         if ($messenger instanceof EE_messenger) {
843 843
             $msgr_settings = $messenger->get_admin_settings_fields();
844
-            if (! empty($msgr_settings)) {
844
+            if ( ! empty($msgr_settings)) {
845 845
                 foreach ($msgr_settings as $field => $value) {
846 846
                     //is there a new setting for this?
847 847
                     if (isset($new_settings[$field])) {
@@ -849,7 +849,7 @@  discard block
 block discarded – undo
849 849
                         continue;
850 850
                     }
851 851
                     //only set the default if it isn't already set.
852
-                    if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
852
+                    if ( ! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
853 853
                         $this->_active_message_types[$messenger->name]['settings'][$field] = $value;
854 854
                     }
855 855
                 }
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
         }
894 894
         foreach ($this->_active_message_types as $messenger_name => $settings) {
895 895
             unset(
896
-                $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
896
+                $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]
897 897
             );
898 898
 
899 899
             //we always record (even on deactivation) that a message type has been activated because there should at
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
     {
920 920
         $this->_initialize_collections();
921 921
         if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
922
-            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
922
+            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]);
923 923
         }
924 924
         $this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
925 925
             array($message_type_name));
@@ -1013,7 +1013,7 @@  discard block
 block discarded – undo
1013 1013
         $all_message_types_valid           = true;
1014 1014
         //loop through list of active message types and verify they are installed.
1015 1015
         foreach ($list_of_active_message_type_names as $message_type_name) {
1016
-            if (! isset($installed_message_types[$message_type_name])) {
1016
+            if ( ! isset($installed_message_types[$message_type_name])) {
1017 1017
                 $this->remove_message_type_has_been_activated_from_all_messengers(
1018 1018
                     $message_type_name,
1019 1019
                     true
@@ -1087,7 +1087,7 @@  discard block
 block discarded – undo
1087 1087
         $message_type_name,
1088 1088
         $consider_current_state = false
1089 1089
     ) {
1090
-        foreach(array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1090
+        foreach (array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1091 1091
             $this->remove_message_type_has_been_activated_for_messenger(
1092 1092
                 $message_type_name,
1093 1093
                 $messenger_name,
Please login to merge, or discard this patch.
Indentation   +1112 added lines, -1112 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 
@@ -17,1117 +17,1117 @@  discard block
 block discarded – undo
17 17
 class EE_Message_Resource_Manager
18 18
 {
19 19
 
20
-    /**
21
-     * This option in the database is used to keep a record of message types that have been activated for a messenger
22
-     * at some point in the history of the site.  It is utilized by the implementation of the 'force' flag in
23
-     * EE_Register_Message_Type.  The force flag is an indication of whether a message type should be activated by
24
-     * default when the message type is registered.  However, if a user has explicitly deactivated a message type, then
25
-     * the force flag is ignored.  The method by which the code knows whether to ignore this flag is via this option.
26
-     * Note, that this is NOT a historical record.  Its entirely possible for a message type to have been activated for
27
-     * a messenger and yet not have a record in this option.  This occurs when a message type is inactivated through an
28
-     * automated process (when an add-on registering the message type deactivates, or when some other code calls the
29
-     * EE_Registery_Message_Type::deregister method) and the related record(s) is(are) removed from this option to ensure
30
-     * the "force" flag is respected if that message type is later re-registered.
31
-     *
32
-     * This option should NOT be used to determine the current "active" state of a message type for a given messenger.
33
-     *
34
-     * The name of this option (and related methods/properties) is due to matching the original intended purpose for the
35
-     * option that got superseded by later behaviour requirements.
36
-     */
37
-    const HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME = 'ee_has_activated_messenger';
38
-
39
-    /**
40
-     * @type boolean $_initialized
41
-     */
42
-    protected $_initialized = false;
43
-
44
-    /**
45
-     * @type EE_Messenger_Collection $_messenger_collection_loader
46
-     */
47
-    protected $_messenger_collection_loader;
48
-
49
-    /**
50
-     * @type EE_Message_Type_Collection $_message_type_collection_loader
51
-     */
52
-    protected $_message_type_collection_loader;
53
-
54
-    /**
55
-     * @type EEM_Message_Template_Group $_message_template_group_model
56
-     */
57
-    protected $_message_template_group_model;
58
-
59
-    /**
60
-     * @type EE_messenger[]
61
-     */
62
-    protected $_installed_messengers = array();
63
-
64
-    /**
65
-     * @type EE_message_type[]
66
-     */
67
-    protected $_installed_message_types = array();
68
-
69
-    /**
70
-     * Array of active messengers.
71
-     * Format is this:
72
-     * array(
73
-     *      'messenger_name' => EE_messenger
74
-     * )
75
-     *
76
-     * @type EE_messenger[]
77
-     */
78
-    protected $_active_messengers = array();
79
-
80
-    /**
81
-     * Formatted array of active message types grouped per messenger.
82
-     * Format is this:
83
-     * array(
84
-     *      'messenger_name' => array(
85
-     *          'settings' => array(
86
-     *              '{messenger_name}-message_types' => array(
87
-     *                  'message_type_name' => array() //variable array of settings corresponding to message type.
88
-     *              )
89
-     *          )
90
-     *      )
91
-     * )
92
-     *
93
-     * @type array
94
-     */
95
-    protected $_active_message_types = array();
96
-
97
-
98
-    /**
99
-     * This holds the array of messengers and their corresponding message types that have
100
-     * been activated on a site at some point.  This is an important record that helps the messages system
101
-     * not accidentally reactivate something that was intentionally deactivated by a user.
102
-     *
103
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
104
-     *
105
-     * @type array
106
-     */
107
-    protected $_has_activated_messengers_and_message_types = array();
108
-
109
-    /**
110
-     * An array of unique message type contexts across all active message types.
111
-     * The array will be indexed by either 'slugs' or 'all'.
112
-     * The slugs index contains an array indexed by unique context slugs with the latest label representation for that
113
-     * slug. array(
114
-     *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
115
-     * );
116
-     * The all index returns an array in this format:
117
-     * array(
118
-     *      'message_type_name' => array(
119
-     *          'context_slug' => array(
120
-     *              'label' => 'localized label for context',
121
-     *              'description' => 'localized description for context'
122
-     *          )
123
-     *      )
124
-     * );
125
-     *
126
-     * @type array
127
-     */
128
-    protected $_contexts = array();
129
-
130
-
131
-    /**
132
-     * EE_Message_Resource_Manager constructor.
133
-     *
134
-     * @param \EE_Messenger_Collection_Loader    $Messenger_Collection_Loader
135
-     * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader
136
-     * @param \EEM_Message_Template_Group        $Message_Template_Group_Model
137
-     */
138
-    function __construct(
139
-        EE_Messenger_Collection_Loader $Messenger_Collection_Loader,
140
-        EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader,
141
-        EEM_Message_Template_Group $Message_Template_Group_Model
142
-    ) {
143
-        $this->_messenger_collection_loader    = $Messenger_Collection_Loader;
144
-        $this->_message_type_collection_loader = $Message_Type_Collection_Loader;
145
-        $this->_message_template_group_model   = $Message_Template_Group_Model;
146
-    }
147
-
148
-
149
-    /**
150
-     * @return void
151
-     */
152
-    protected function _initialize_collections()
153
-    {
154
-        if ($this->_initialized) {
155
-            return;
156
-        }
157
-        $this->_initialized = true;
158
-        $this->_messenger_collection_loader->load_messengers_from_folder();
159
-        $this->_message_type_collection_loader->load_message_types_from_folder();
160
-        $this->get_has_activated_messengers_option(true);
161
-        $this->_set_active_messengers_and_message_types();
162
-    }
163
-
164
-
165
-    /**
166
-     * @return EE_Messenger_Collection
167
-     */
168
-    public function messenger_collection()
169
-    {
170
-        $this->_initialize_collections();
171
-        return $this->_messenger_collection_loader->messenger_collection();
172
-    }
173
-
174
-
175
-    /**
176
-     * @return EE_messenger[]
177
-     */
178
-    public function active_messengers()
179
-    {
180
-        $this->_initialize_collections();
181
-        return $this->_active_messengers;
182
-    }
183
-
184
-
185
-    /**
186
-     * @param string $messenger_name
187
-     * @return \EE_messenger
188
-     */
189
-    public function get_messenger($messenger_name)
190
-    {
191
-        return $this->messenger_collection()->get_by_info($messenger_name);
192
-    }
193
-
194
-
195
-    /**
196
-     * This returns the corresponding EE_messenger object for the given string if it is active.
197
-     *
198
-     * @param string $messenger
199
-     * @return EE_messenger | null
200
-     */
201
-    public function get_active_messenger($messenger)
202
-    {
203
-        $this->_initialize_collections();
204
-        return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null;
205
-    }
206
-
207
-
208
-    /**
209
-     * @return \EE_messenger[]
210
-     */
211
-    public function installed_messengers()
212
-    {
213
-        if (empty($this->_installed_messengers)) {
214
-            $this->_installed_messengers = array();
215
-            $this->messenger_collection()->rewind();
216
-            while ($this->messenger_collection()->valid()) {
217
-                $this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current();
218
-                $this->messenger_collection()->next();
219
-            }
220
-        }
221
-        return $this->_installed_messengers;
222
-    }
223
-
224
-
225
-    /**
226
-     * @param string $messenger_name
227
-     * @return \EE_messenger
228
-     * @throws \EE_Error
229
-     */
230
-    public function valid_messenger($messenger_name)
231
-    {
232
-        $messenger = $this->get_messenger($messenger_name);
233
-        if ($messenger instanceof EE_messenger) {
234
-            return $messenger;
235
-        }
236
-        throw new EE_Error(
237
-            sprintf(
238
-                __('The "%1$s" messenger is either invalid or not installed', 'event_espresso'),
239
-                $messenger_name
240
-            )
241
-        );
242
-    }
243
-
244
-
245
-    /**
246
-     * @return EE_Message_Type_Collection
247
-     */
248
-    public function message_type_collection()
249
-    {
250
-        $this->_initialize_collections();
251
-        return $this->_message_type_collection_loader->message_type_collection();
252
-    }
253
-
254
-
255
-    /**
256
-     * @return array
257
-     */
258
-    public function active_message_types()
259
-    {
260
-        $this->_initialize_collections();
261
-        return $this->_active_message_types;
262
-    }
263
-
264
-
265
-    /**
266
-     * @param string $message_type_name
267
-     * @return \EE_message_type
268
-     */
269
-    public function get_message_type($message_type_name)
270
-    {
271
-        return $this->message_type_collection()->get_by_info($message_type_name);
272
-    }
273
-
274
-
275
-    /**
276
-     * This returns the EE_message_type from the active message types array ( if present );
277
-     *
278
-     * @param string $messenger_name
279
-     * @param string $message_type_name
280
-     * @return \EE_message_type|null
281
-     */
282
-    public function get_active_message_type_for_messenger($messenger_name, $message_type_name)
283
-    {
284
-        return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
285
-            ? $this->get_message_type($message_type_name)
286
-            : null;
287
-    }
288
-
289
-
290
-    /**
291
-     * Returns whether the given message type is active for the given messenger.
292
-     *
293
-     * @param string $messenger_name
294
-     * @param string $message_type_name
295
-     * @return bool
296
-     */
297
-    public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
298
-    {
299
-        $this->_initialize_collections();
300
-        return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
301
-    }
302
-
303
-
304
-    /**
305
-     * Returns whether the given messenger is active.
306
-     *
307
-     * @param string $messenger_name the name of the messenger to check if active.
308
-     * @return bool
309
-     */
310
-    public function is_messenger_active($messenger_name)
311
-    {
312
-        $this->_initialize_collections();
313
-        return ! empty($this->_active_message_types[$messenger_name]);
314
-    }
315
-
316
-
317
-    /**
318
-     * This returns any settings that might be on a message type for a messenger
319
-     *
320
-     * @param string $messenger_name    The slug of the messenger
321
-     * @param string $message_type_name The slug of the message type getting the settings for.
322
-     * @return array
323
-     */
324
-    public function get_message_type_settings_for_messenger($messenger_name, $message_type_name)
325
-    {
326
-        $settings = array();
327
-        if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
328
-            $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
329
-                ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
330
-                : array();
331
-        }
332
-        return $settings;
333
-    }
334
-
335
-
336
-    /**
337
-     * Returns whether the given messenger name has active message types on it.
338
-     * Infers whether the messenger is active or not as well.
339
-     *
340
-     * @param string $messenger_name
341
-     * @return bool
342
-     */
343
-    public function messenger_has_active_message_types($messenger_name)
344
-    {
345
-        $this->_initialize_collections();
346
-        return
347
-            ! empty($this->_active_message_types[$messenger_name])
348
-            && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
349
-    }
350
-
351
-
352
-    /**
353
-     * This checks the _active_message_types property for any active message types
354
-     * that are present for the given messenger and returns them.
355
-     *
356
-     * @since 4.9.0
357
-     * @param string $messenger_name The messenger being checked
358
-     * @return EE_message_type[]|array    (empty array if no active_message_types)
359
-     */
360
-    public function get_active_message_types_for_messenger($messenger_name)
361
-    {
362
-        $message_types = array();
363
-        if (! $this->messenger_has_active_message_types($messenger_name)) {
364
-            return $message_types;
365
-        }
366
-        $installed_message_types = $this->installed_message_types();
367
-        foreach ($installed_message_types as $message_type_name => $message_type) {
368
-            if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
369
-                $message_types[$message_type_name] = $message_type;
370
-            }
371
-        }
372
-        return $message_types;
373
-    }
374
-
375
-
376
-    /**
377
-     * This does NOT return the _active_message_types property but
378
-     * simply returns an array of active message type names from that property.
379
-     * (The _active_message_types property is indexed by messenger and active message_types per messenger).
380
-     *
381
-     * @return array message_type references (string)
382
-     */
383
-    public function list_of_active_message_types()
384
-    {
385
-        $active_message_type_names = array();
386
-        $this->_initialize_collections();
387
-        foreach ($this->_active_message_types as $messenger => $messenger_settings) {
388
-            if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
389
-                continue;
390
-            }
391
-            foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
392
-                if (! in_array($message_type_name, $active_message_type_names)) {
393
-                    $active_message_type_names[] = $message_type_name;
394
-                }
395
-            }
396
-        }
397
-        return $active_message_type_names;
398
-    }
399
-
400
-
401
-    /**
402
-     * Same as list_of_active_message_types() except this returns actual EE_message_type objects
403
-     *
404
-     * @since 4.9.0
405
-     * @return \EE_message_type[]
406
-     */
407
-    public function get_active_message_type_objects()
408
-    {
409
-        $active_message_types      = array();
410
-        $installed_message_types   = $this->installed_message_types();
411
-        $active_message_type_names = $this->list_of_active_message_types();
412
-        foreach ($active_message_type_names as $active_message_type_name) {
413
-            if (isset($installed_message_types[$active_message_type_name])) {
414
-                $active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name];
415
-            }
416
-        }
417
-        return $active_message_types;
418
-    }
419
-
420
-
421
-    /**
422
-     * @return \EE_message_type[]
423
-     */
424
-    public function installed_message_types()
425
-    {
426
-        if (empty($this->_installed_message_types)) {
427
-            $this->message_type_collection()->rewind();
428
-            while ($this->message_type_collection()->valid()) {
429
-                $this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current();
430
-                $this->message_type_collection()->next();
431
-            }
432
-        }
433
-        return $this->_installed_message_types;
434
-    }
435
-
436
-
437
-    /**
438
-     * @param string $message_type_name
439
-     * @return \EE_message_type
440
-     * @throws \EE_Error
441
-     */
442
-    public function valid_message_type($message_type_name)
443
-    {
444
-        $message_type = $this->get_message_type($message_type_name);
445
-        if ($message_type instanceof EE_message_type) {
446
-            return $message_type;
447
-        }
448
-        throw new EE_Error(
449
-            sprintf(
450
-                __('The "%1$s" message type is either invalid or not installed', 'event_espresso'),
451
-                $message_type_name
452
-            )
453
-        );
454
-    }
455
-
456
-
457
-    /**
458
-     * valid_message_type_for_messenger
459
-     *
460
-     * @param EE_messenger $messenger
461
-     * @param string       $message_type_name
462
-     * @return boolean
463
-     * @throws \EE_Error
464
-     */
465
-    public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
466
-    {
467
-        $valid_message_types = $messenger->get_valid_message_types();
468
-        if (! in_array($message_type_name, $valid_message_types)) {
469
-            throw new EE_Error(
470
-                sprintf(
471
-                    __(
472
-                        'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger.  Double-check the spelling and verify that message type has been registered as a valid type with the messenger.',
473
-                        'event_espresso'
474
-                    ),
475
-                    $message_type_name,
476
-                    __METHOD__,
477
-                    $messenger->name
478
-                )
479
-            );
480
-        }
481
-        return true;
482
-    }
483
-
484
-
485
-    /**
486
-     * Used to return active messengers array stored in the wp options table.
487
-     * If no value is present in the option then an empty array is returned.
488
-     *
489
-     * @param   bool $reset     If true then we ignore whether the option is cached on the _active_message_types
490
-     *                          property and pull directly from the db.  Otherwise whatever is currently on the
491
-     *                          $_active_message_types property is pulled.
492
-     * @return array
493
-     */
494
-    public function get_active_messengers_option($reset = false)
495
-    {
496
-        if ($reset) {
497
-            $this->_active_message_types = get_option('ee_active_messengers', array());
498
-        }
499
-        return $this->_active_message_types;
500
-    }
501
-
502
-
503
-    /**
504
-     * Used to update the active messengers array stored in the wp options table.
505
-     *
506
-     * @param array $active_messenger_settings Incoming data to save.  If empty, then the internal cached property
507
-     *                                         representing this data is used.
508
-     * @return bool FALSE if not updated, TRUE if updated.
509
-     */
510
-    public function update_active_messengers_option($active_messenger_settings = array())
511
-    {
512
-        $active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings;
513
-        //make sure _active_message_types is updated (this is the internal cache for the settings).
514
-        $this->_active_message_types = $active_messenger_settings;
515
-        return update_option('ee_active_messengers', $active_messenger_settings);
516
-    }
517
-
518
-
519
-    /**
520
-     * Used to return has activated message types for messengers array stored in the wp options table.
521
-     * If no value is present in the option then an empty array is returned.
522
-     * The value is cached on the $_has_activated_messengers_and_message_types property for future calls.
523
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
524
-     *
525
-     * @param   bool $reset Used to indicate that any cached value should be ignored.
526
-     * @return array
527
-     */
528
-    public function get_has_activated_messengers_option($reset = false)
529
-    {
530
-        if ($reset || empty($this->_has_activated_messengers_and_message_types)) {
531
-            $this->_has_activated_messengers_and_message_types = get_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, array());
532
-        }
533
-        return $this->_has_activated_messengers_and_message_types;
534
-    }
535
-
536
-
537
-    /**
538
-     * Used to update the has activated option in the db.
539
-     *
540
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
541
-     *
542
-     * @param array $has_activated_messengers Incoming data to save.  If empty, then the internal cached property
543
-     *                                        representing this data is used.
544
-     * @return bool FALSE if not updated, TRUE if updated.
545
-     */
546
-    public function update_has_activated_messengers_option($has_activated_messengers = array())
547
-    {
548
-        //make sure the option has been retrieved from first so we don't overwrite it accidentally.
549
-        if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) {
550
-            $this->get_has_activated_messengers_option();
551
-        }
552
-        $has_activated_messengers = empty($has_activated_messengers)
553
-            ? $this->_has_activated_messengers_and_message_types
554
-            : $has_activated_messengers;
555
-        return update_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, $has_activated_messengers);
556
-    }
557
-
558
-
559
-    /**
560
-     * wrapper for _set_active_messengers_and_message_types()
561
-     */
562
-    public function reset_active_messengers_and_message_types()
563
-    {
564
-        $this->_set_active_messengers_and_message_types();
565
-    }
566
-
567
-
568
-    /**
569
-     * Generate list of active messengers and message types from collection.
570
-     * This sets up the active messengers from what is present in the database.
571
-     */
572
-    protected function _set_active_messengers_and_message_types()
573
-    {
574
-        //echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n";
575
-        // list of activated messengers as set via the admin
576
-        // note calling `get_active_messengers_options` also initializes the _active_message_types property.
577
-        $this->get_active_messengers_option(true);
578
-        $this->ensure_messengers_are_active(array(), false, true);
579
-        $this->update_active_messengers_option();
580
-        $this->update_has_activated_messengers_option();
581
-    }
582
-
583
-
584
-    /**
585
-     * Ensures that the specified messenger is currently active.
586
-     * If not, activates it and its default message types.
587
-     *
588
-     * @param string $messenger_name
589
-     * @param bool   $update_option Whether to update the option in the db or not.
590
-     * @return boolean true if either already active or successfully activated.
591
-     */
592
-    public function ensure_messenger_is_active($messenger_name, $update_option = true)
593
-    {
594
-        if (! isset($this->_active_messengers[$messenger_name])) {
595
-            try {
596
-                $this->activate_messenger($messenger_name, array(), $update_option);
597
-            } catch (EE_Error $e) {
598
-                EE_Error::add_error(
599
-                    $e->getMessage(),
600
-                    __FILE__,
601
-                    __FUNCTION__,
602
-                    __LINE__
603
-                );
604
-                return false;
605
-            }
606
-        }
607
-        return true;
608
-    }
609
-
610
-
611
-    /**
612
-     * This ensures the given array of messenger names is active in the system.
613
-     * Note, this method will not activate any NEW message types for the messenger when it is called. Instead,
614
-     * it will automatically activate the default message types for the messenger if its not active.
615
-     *
616
-     * @param array $messenger_names  Array of messenger names for messengers to be activated.  If an empty array
617
-     *                                (default) then will attempt to set the active messengers from the
618
-     *                                activated_messengers option
619
-     *                                (stored in $_active_message_types property).
620
-     * @param bool  $update_option    Whether to update the related active messengers option.
621
-     * @param bool  $verify           Whether to verify the messengers are installed before activating. Note if this is
622
-     *                                set to true and a messenger is indicated as active, but is NOT installed, then it
623
-     *                                will automatically be deactivated.
624
-     */
625
-    public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false)
626
-    {
627
-        $messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names;
628
-
629
-        $not_installed = array();
630
-        foreach ($messenger_names as $messenger_name) {
631
-            if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) {
632
-                $not_installed[] = $messenger_name;
633
-                $this->deactivate_messenger($messenger_name);
634
-                continue;
635
-            }
636
-            $this->ensure_messenger_is_active($messenger_name, $update_option);
637
-        }
638
-
639
-        if (! empty($not_installed_messenger)) {
640
-            EE_Error::add_error(
641
-                sprintf(
642
-                    __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
643
-                    '<br />',
644
-                    implode(', ', $not_installed_messenger)
645
-                ),
646
-                __FILE__, __FUNCTION__, __LINE__
647
-            );
648
-        }
649
-    }
650
-
651
-
652
-    /**
653
-     * Ensures that the specified message type for the given messenger is currently active, if not activates it.
654
-     * This ALSO ensures that the given messenger is active as well!
655
-     *
656
-     * @param string $message_type_name message type name.
657
-     * @param        $messenger_name
658
-     * @param bool   $update_option     Whether to update the option in the db or not.
659
-     * @return bool  Returns true if already is active or if was activated successfully.
660
-     * @throws \EE_Error
661
-     */
662
-    public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true)
663
-    {
664
-        // grab the messenger to work with.
665
-        $messenger = $this->valid_messenger($messenger_name);
666
-        if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) {
667
-            //ensure messenger is active (that's an inherent coupling between active message types and the
668
-            //messenger they are being activated for.
669
-            try {
670
-                if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
671
-                    //all is good so let's just get it active
672
-                    $this->activate_messenger($messenger_name, array($message_type_name), $update_option);
673
-                }
674
-            } catch (EE_Error $e) {
675
-                EE_Error::add_error(
676
-                    $e->getMessage(),
677
-                    __FILE__,
678
-                    __FUNCTION__,
679
-                    __LINE__
680
-                );
681
-                return false;
682
-            }
683
-        }
684
-        return true;
685
-    }
686
-
687
-
688
-    /**
689
-     * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a
690
-     * messenger are active in one go.
691
-     *
692
-     * @param array  $message_type_names Array of message type names to ensure are active.
693
-     * @param string $messenger_name     The name of the messenger that the message types are to be activated on.
694
-     * @param bool   $update_option      Whether to persist the activation to the database or not (default true).
695
-     */
696
-    public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
697
-    {
698
-        $message_type_names = (array)$message_type_names;
699
-        foreach ($message_type_names as $message_type_name) {
700
-            // note, intentionally not updating option here because we're in a loop.
701
-            // We'll follow the instructions of the incoming $update_option argument after the loop.
702
-            $this->ensure_message_type_is_active($message_type_name, $messenger_name, false);
703
-        }
704
-        if ($update_option) {
705
-            $this->update_active_messengers_option();
706
-            $this->update_has_activated_messengers_option();
707
-        }
708
-    }
709
-
710
-
711
-    /**
712
-     * Activates the specified messenger.
713
-     *
714
-     * @param string $messenger_name
715
-     * @param array  $message_type_names        An array of message type names to activate with this messenger.
716
-     *                                          If included we do NOT setup the default message types
717
-     *                                          (assuming they are already setup.)
718
-     * @param bool   $update_active_messengers_option
719
-     * @return array of generated templates
720
-     * @throws \EE_Error
721
-     */
722
-    public function activate_messenger(
723
-        $messenger_name,
724
-        $message_type_names = array(),
725
-        $update_active_messengers_option = true
726
-    ) {
727
-        $templates = array();
728
-        // grab the messenger to work with.
729
-        $messenger = $this->messenger_collection()->get_by_info($messenger_name);
730
-        // it's inactive. Activate it.
731
-        if ($messenger instanceof EE_messenger) {
732
-            $this->_active_messengers[$messenger->name] = $messenger;
733
-            //activate incoming message types set to be activated with messenger.
734
-            $message_type_names = $this->_activate_message_types($messenger, $message_type_names);
735
-            // setup any initial settings for the messenger if necessary.
736
-            $this->add_settings_for_messenger($messenger->name);
737
-            if ($update_active_messengers_option) {
738
-                $this->update_active_messengers_option();
739
-                $this->update_has_activated_messengers_option();
740
-            }
741
-            //generate new templates if necessary and ensure all related templates that are already in the database are
742
-            //marked active.  Note, this will also deactivate a message type for a messenger if the template
743
-            //cannot be successfully created during its attempt (only happens for global template attempts).
744
-            if (! empty($message_type_names)) {
745
-                $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
746
-                EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
747
-            }
748
-        }
749
-        return $templates;
750
-    }
751
-
752
-
753
-    /**
754
-     * Activates given message types for the given EE_messenger object.
755
-     * Note: (very important) This method does not persist the activation to the database.
756
-     * See code implementing this method in this class for examples of how to persist.
757
-     *
758
-     * @param \EE_messenger $messenger
759
-     * @param  array        $message_type_names
760
-     * @return array
761
-     */
762
-    protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array())
763
-    {
764
-        //If $message_type_names is empty, AND $this->_active_message_types is empty, then that means
765
-        //things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
766
-        //So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
767
-        //only override _active_message_types when an explicit array of $message_type_names has been provided.
768
-        $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
769
-            ? $messenger->get_default_message_types()
770
-            : (array)$message_type_names;
771
-
772
-        //now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
773
-        if (! isset($this->_active_message_types[$messenger->name])) {
774
-            $this->_active_message_types[$messenger->name]['settings'] = array();
775
-        }
776
-
777
-        if ($message_type_names) {
778
-            // cycle thru message types
779
-            foreach ($message_type_names as $message_type_name) {
780
-                //only register the message type as active IF it isn't already active
781
-                //and if its actually installed.
782
-                if (
783
-                ! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
784
-                ) {
785
-                    $this->add_settings_for_message_type($messenger->name, $message_type_name);
786
-                    $this->_set_messenger_has_activated_message_type(
787
-                        $messenger,
788
-                        $message_type_name
789
-                    );
790
-                }
791
-            }
792
-        }
793
-        return $message_type_names;
794
-    }
795
-
796
-
797
-    /**
798
-     * add_settings_for_message_type
799
-     * NOTE This does NOT automatically persist any settings to the db.  Client code should call
800
-     * $this->update_active_messengers_option to persist.
801
-     *
802
-     * @param  string $messenger_name    The name of the messenger adding the settings for
803
-     * @param  string $message_type_name The name of the message type adding the settings for
804
-     * @param  array  $new_settings      Any new settings being set for the message type and messenger
805
-     */
806
-    public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array())
807
-    {
808
-        // get installed message type from collection
809
-        $message_type      = $this->message_type_collection()->get_by_info($message_type_name);
810
-        $existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name);
811
-        //we need to setup any initial settings for message types
812
-        if ($message_type instanceof EE_message_type) {
813
-            $default_settings = $message_type->get_admin_settings_fields();
814
-            foreach ($default_settings as $field => $values) {
815
-                if (isset($new_settings[$field])) {
816
-                    $existing_settings[$field] = $new_settings[$field];
817
-                    continue;
818
-                }
819
-                if (! isset($existing_settings[$field])) {
820
-                    $existing_settings[$field] = $values['default'];
821
-                }
822
-            }
823
-        }
824
-        $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
825
-    }
826
-
827
-
828
-    /**
829
-     * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger
830
-     * and message type.
831
-     *
832
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
833
-     *
834
-     * @access protected
835
-     * @param \EE_messenger $messenger
836
-     * @param string        $message_type_name
837
-     */
838
-    protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name)
839
-    {
840
-
841
-        //if _has_activated_messengers_and_message_types is empty then lets ensure its initialized
842
-        if (empty($this->_has_activated_messengers_and_message_types)) {
843
-            $this->get_has_activated_messengers_option();
844
-        }
845
-
846
-        // make sure this messenger has a record in the has_activated array
847
-        if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
848
-            $this->_has_activated_messengers_and_message_types[$messenger->name] = array();
849
-        }
850
-        // check if message type has already been added
851
-        if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
852
-            $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
853
-        }
854
-    }
855
-
856
-
857
-    /**
858
-     * add_settings_for_messenger
859
-     * NOTE This does NOT automatically persist any settings to the db.  Client code should call
860
-     * $this->update_active_messengers_option to persist.
861
-     *
862
-     * @param string $messenger_name The name of the messenger the settings is being added for.
863
-     * @param array  $new_settings   An array of settings to update the existing settings.
864
-     */
865
-    public function add_settings_for_messenger($messenger_name, $new_settings = array())
866
-    {
867
-        $messenger = $this->get_messenger($messenger_name);
868
-        if ($messenger instanceof EE_messenger) {
869
-            $msgr_settings = $messenger->get_admin_settings_fields();
870
-            if (! empty($msgr_settings)) {
871
-                foreach ($msgr_settings as $field => $value) {
872
-                    //is there a new setting for this?
873
-                    if (isset($new_settings[$field])) {
874
-                        $this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field];
875
-                        continue;
876
-                    }
877
-                    //only set the default if it isn't already set.
878
-                    if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
879
-                        $this->_active_message_types[$messenger->name]['settings'][$field] = $value;
880
-                    }
881
-                }
882
-            }
883
-        }
884
-    }
885
-
886
-
887
-    /**
888
-     * deactivate_messenger
889
-     *
890
-     * @param  string|EE_messenger $messenger_name name of messenger
891
-     * @return void
892
-     */
893
-    public function deactivate_messenger($messenger_name)
894
-    {
895
-        $this->_initialize_collections();
896
-        if ($messenger_name instanceof EE_messenger) {
897
-            $messenger_name = $messenger_name->name;
898
-        }
899
-        unset($this->_active_messengers[$messenger_name]);
900
-        unset($this->_active_message_types[$messenger_name]);
901
-        $this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
902
-        $this->update_active_messengers_option();
903
-    }
904
-
905
-
906
-    /**
907
-     * Deactivates a message type (note this will deactivate across all messenger's it is active on.
908
-     *
909
-     * @param  string $message_type_name     name of message type being deactivated
910
-     * @param bool    $set_has_active_record By default we always record the has_active record when deactivating a message
911
-     *                                       type.  However, this can be overridden if we don't want this set (usually when
912
-     *                                       this is called as a part of deregistration of a custom message type)
913
-     */
914
-    public function deactivate_message_type($message_type_name, $set_has_active_record = true)
915
-    {
916
-        $this->_initialize_collections();
917
-        if ($message_type_name instanceof EE_message_type) {
918
-            $message_type_name = $message_type_name->name;
919
-        }
920
-        foreach ($this->_active_message_types as $messenger_name => $settings) {
921
-            unset(
922
-                $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
923
-            );
924
-
925
-            //we always record (even on deactivation) that a message type has been activated because there should at
926
-            //least be a record in the "has_activated" option that it WAS active at one point.
927
-            if ($set_has_active_record) {
928
-                $messenger = $this->get_messenger($messenger_name);
929
-                $this->_set_messenger_has_activated_message_type($messenger, $message_type_name);
930
-            }
931
-        }
932
-        $this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name);
933
-        $this->update_active_messengers_option();
934
-        $this->update_has_activated_messengers_option();
935
-    }
936
-
937
-
938
-    /**
939
-     * Deactivates a message type for a specific messenger as opposed to all messengers.
940
-     *
941
-     * @param string $message_type_name Name of message type being deactivated.
942
-     * @param string $messenger_name    Name of messenger the message type is being deactivated for.
943
-     */
944
-    public function deactivate_message_type_for_messenger($message_type_name, $messenger_name)
945
-    {
946
-        $this->_initialize_collections();
947
-        if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
948
-            unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
949
-        }
950
-        $this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
951
-            array($message_type_name));
952
-        $this->update_active_messengers_option();
953
-    }
954
-
955
-
956
-    /**
957
-     * Used to verify if a message can be sent for the given messenger and message type
958
-     * and that it is a generating messenger (used for generating message templates).
959
-     *
960
-     * @param EE_messenger    $messenger    messenger used in trigger
961
-     * @param EE_message_type $message_type message type used in trigger
962
-     * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
963
-     */
964
-    public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
965
-    {
966
-        //get the $messengers the message type says it can be used with.
967
-        foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) {
968
-            if (
969
-                $messenger->name === $generating_messenger
970
-                && $this->is_message_type_active_for_messenger($messenger->name, $message_type->name)
971
-            ) {
972
-                return true;
973
-            }
974
-        }
975
-        return false;
976
-    }
977
-
978
-
979
-    /**
980
-     * This returns all the contexts that are registered by all message types.
981
-     * If $slugs_only is true,
982
-     * then just an array indexed by unique context slugs with the latest label representation for that slug.
983
-     * array(
984
-     *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
985
-     * );
986
-     * If $slugs_only is false, then the format is:
987
-     * array(
988
-     *      'message_type_name' => array(
989
-     *          'context_slug' => array(
990
-     *              'label' => 'localized label for context',
991
-     *              'description' => 'localized description for context'
992
-     *          )
993
-     *      )
994
-     * );
995
-     * Keep in mind that although different message types may share the same context slugs,
996
-     * it is possible that the context is described differently by the message type.
997
-     *
998
-     * @since 4.9.0
999
-     * @param   bool $slugs_only Whether to return an array of just slugs and labels (true)
1000
-     *                           or all contexts indexed by message type.
1001
-     * @return array
1002
-     */
1003
-    public function get_all_contexts($slugs_only = true)
1004
-    {
1005
-        $key = $slugs_only ? 'slugs' : 'all';
1006
-        // check if contexts has been setup yet.
1007
-        if (empty($this->_contexts[$key])) {
1008
-            // So let's get all active message type objects and loop through to get all unique contexts
1009
-            foreach ($this->get_active_message_type_objects() as $message_type) {
1010
-                if ($message_type instanceof EE_message_type) {
1011
-                    $message_type_contexts = $message_type->get_contexts();
1012
-                    if ($slugs_only) {
1013
-                        foreach ($message_type_contexts as $context => $context_details) {
1014
-                            $this->_contexts[$key][$context] = $context_details['label'];
1015
-                        }
1016
-                    } else {
1017
-                        $this->_contexts[$key][$message_type->name] = $message_type_contexts;
1018
-                    }
1019
-                }
1020
-            }
1021
-        }
1022
-        return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array();
1023
-    }
1024
-
1025
-
1026
-    /**
1027
-     * This checks the internal record of what message types are considered "active" and verifies that
1028
-     * there is an installed class definition for that message type.  If the active message type does not have a
1029
-     * corresponding accessible message type class then it will be deactivated from all messengers it is active on and
1030
-     * any related message templates will be inactivated as well.
1031
-     *
1032
-     * @return bool   true means all active message types are valid, false means at least one message type was
1033
-     *                deactivated.
1034
-     */
1035
-    public function validate_active_message_types_are_installed()
1036
-    {
1037
-        $list_of_active_message_type_names = $this->list_of_active_message_types();
1038
-        $installed_message_types           = $this->installed_message_types();
1039
-        $all_message_types_valid           = true;
1040
-        //loop through list of active message types and verify they are installed.
1041
-        foreach ($list_of_active_message_type_names as $message_type_name) {
1042
-            if (! isset($installed_message_types[$message_type_name])) {
1043
-                $this->remove_message_type_has_been_activated_from_all_messengers(
1044
-                    $message_type_name,
1045
-                    true
1046
-                );
1047
-                $this->deactivate_message_type($message_type_name, false);
1048
-                $all_message_types_valid = false;
1049
-            }
1050
-        }
1051
-        return $all_message_types_valid;
1052
-    }
1053
-
1054
-
1055
-    /**
1056
-     * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been
1057
-     * activated for the given messenger.  This can be called by client code on plugin updates etc to determine whether
1058
-     * to attempt automatically reactivating message types that should be activated by default or not.
1059
-     *
1060
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1061
-     *
1062
-     * @param $message_type_name
1063
-     * @param $messenger_name
1064
-     * @return bool
1065
-     */
1066
-    public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1067
-    {
1068
-        $has_activated = $this->get_has_activated_messengers_option();
1069
-        return isset($has_activated[$messenger_name])
1070
-               && in_array($message_type_name, $has_activated[$messenger_name]);
1071
-    }
1072
-
1073
-
1074
-    /**
1075
-     * This method unsets a message type from the given messenger has activated option.
1076
-     *
1077
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1078
-     *
1079
-     * @param string $message_type_name
1080
-     * @param string $messenger_name
1081
-     * @param bool   $consider_current_state  Whether to consider whether the  message type is currently active or not.
1082
-     *                                        If it is currently active, then remove.  Otherwise leave it alone.
1083
-     */
1084
-    public function remove_message_type_has_been_activated_for_messenger(
1085
-        $message_type_name,
1086
-        $messenger_name,
1087
-        $consider_current_state = false
1088
-    ) {
1089
-        if ($consider_current_state
1090
-            && ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
1091
-        ) {
1092
-            //when consider current state is true, this means we don't want to change anything on the "has_activated"
1093
-            //record if the message type is currently active for this messenger.  This is used when we want to retain
1094
-            //the record for user initiated inactivations of the message type.
1095
-            return;
1096
-        }
1097
-        $has_activated = $this->get_has_activated_messengers_option();
1098
-        $key_for_message_type = isset($has_activated[$messenger_name])
1099
-            ? array_search($message_type_name, $has_activated[$messenger_name], true)
1100
-            : false;
1101
-        if ($key_for_message_type !== false) {
1102
-            unset($has_activated[$messenger_name][$key_for_message_type]);
1103
-            $this->update_has_activated_messengers_option($has_activated);
1104
-            //reset the internal cached property
1105
-            $this->get_has_activated_messengers_option(true);
1106
-        }
1107
-    }
1108
-
1109
-
1110
-    /**
1111
-     * Removes a message type active record from all messengers it is attached to.
1112
-     *
1113
-     * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1114
-     *
1115
-     * @param      $message_type_name
1116
-     * @param bool $consider_current_state  Whether to consider whether the  message type is currently active or not.
1117
-     *                                      If it is currently active, then remove.  Otherwise leave it alone.
1118
-     */
1119
-    public function remove_message_type_has_been_activated_from_all_messengers(
1120
-        $message_type_name,
1121
-        $consider_current_state = false
1122
-    ) {
1123
-        foreach(array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1124
-            $this->remove_message_type_has_been_activated_for_messenger(
1125
-                $message_type_name,
1126
-                $messenger_name,
1127
-                $consider_current_state
1128
-            );
1129
-        }
1130
-    }
20
+	/**
21
+	 * This option in the database is used to keep a record of message types that have been activated for a messenger
22
+	 * at some point in the history of the site.  It is utilized by the implementation of the 'force' flag in
23
+	 * EE_Register_Message_Type.  The force flag is an indication of whether a message type should be activated by
24
+	 * default when the message type is registered.  However, if a user has explicitly deactivated a message type, then
25
+	 * the force flag is ignored.  The method by which the code knows whether to ignore this flag is via this option.
26
+	 * Note, that this is NOT a historical record.  Its entirely possible for a message type to have been activated for
27
+	 * a messenger and yet not have a record in this option.  This occurs when a message type is inactivated through an
28
+	 * automated process (when an add-on registering the message type deactivates, or when some other code calls the
29
+	 * EE_Registery_Message_Type::deregister method) and the related record(s) is(are) removed from this option to ensure
30
+	 * the "force" flag is respected if that message type is later re-registered.
31
+	 *
32
+	 * This option should NOT be used to determine the current "active" state of a message type for a given messenger.
33
+	 *
34
+	 * The name of this option (and related methods/properties) is due to matching the original intended purpose for the
35
+	 * option that got superseded by later behaviour requirements.
36
+	 */
37
+	const HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME = 'ee_has_activated_messenger';
38
+
39
+	/**
40
+	 * @type boolean $_initialized
41
+	 */
42
+	protected $_initialized = false;
43
+
44
+	/**
45
+	 * @type EE_Messenger_Collection $_messenger_collection_loader
46
+	 */
47
+	protected $_messenger_collection_loader;
48
+
49
+	/**
50
+	 * @type EE_Message_Type_Collection $_message_type_collection_loader
51
+	 */
52
+	protected $_message_type_collection_loader;
53
+
54
+	/**
55
+	 * @type EEM_Message_Template_Group $_message_template_group_model
56
+	 */
57
+	protected $_message_template_group_model;
58
+
59
+	/**
60
+	 * @type EE_messenger[]
61
+	 */
62
+	protected $_installed_messengers = array();
63
+
64
+	/**
65
+	 * @type EE_message_type[]
66
+	 */
67
+	protected $_installed_message_types = array();
68
+
69
+	/**
70
+	 * Array of active messengers.
71
+	 * Format is this:
72
+	 * array(
73
+	 *      'messenger_name' => EE_messenger
74
+	 * )
75
+	 *
76
+	 * @type EE_messenger[]
77
+	 */
78
+	protected $_active_messengers = array();
79
+
80
+	/**
81
+	 * Formatted array of active message types grouped per messenger.
82
+	 * Format is this:
83
+	 * array(
84
+	 *      'messenger_name' => array(
85
+	 *          'settings' => array(
86
+	 *              '{messenger_name}-message_types' => array(
87
+	 *                  'message_type_name' => array() //variable array of settings corresponding to message type.
88
+	 *              )
89
+	 *          )
90
+	 *      )
91
+	 * )
92
+	 *
93
+	 * @type array
94
+	 */
95
+	protected $_active_message_types = array();
96
+
97
+
98
+	/**
99
+	 * This holds the array of messengers and their corresponding message types that have
100
+	 * been activated on a site at some point.  This is an important record that helps the messages system
101
+	 * not accidentally reactivate something that was intentionally deactivated by a user.
102
+	 *
103
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
104
+	 *
105
+	 * @type array
106
+	 */
107
+	protected $_has_activated_messengers_and_message_types = array();
108
+
109
+	/**
110
+	 * An array of unique message type contexts across all active message types.
111
+	 * The array will be indexed by either 'slugs' or 'all'.
112
+	 * The slugs index contains an array indexed by unique context slugs with the latest label representation for that
113
+	 * slug. array(
114
+	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
115
+	 * );
116
+	 * The all index returns an array in this format:
117
+	 * array(
118
+	 *      'message_type_name' => array(
119
+	 *          'context_slug' => array(
120
+	 *              'label' => 'localized label for context',
121
+	 *              'description' => 'localized description for context'
122
+	 *          )
123
+	 *      )
124
+	 * );
125
+	 *
126
+	 * @type array
127
+	 */
128
+	protected $_contexts = array();
129
+
130
+
131
+	/**
132
+	 * EE_Message_Resource_Manager constructor.
133
+	 *
134
+	 * @param \EE_Messenger_Collection_Loader    $Messenger_Collection_Loader
135
+	 * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader
136
+	 * @param \EEM_Message_Template_Group        $Message_Template_Group_Model
137
+	 */
138
+	function __construct(
139
+		EE_Messenger_Collection_Loader $Messenger_Collection_Loader,
140
+		EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader,
141
+		EEM_Message_Template_Group $Message_Template_Group_Model
142
+	) {
143
+		$this->_messenger_collection_loader    = $Messenger_Collection_Loader;
144
+		$this->_message_type_collection_loader = $Message_Type_Collection_Loader;
145
+		$this->_message_template_group_model   = $Message_Template_Group_Model;
146
+	}
147
+
148
+
149
+	/**
150
+	 * @return void
151
+	 */
152
+	protected function _initialize_collections()
153
+	{
154
+		if ($this->_initialized) {
155
+			return;
156
+		}
157
+		$this->_initialized = true;
158
+		$this->_messenger_collection_loader->load_messengers_from_folder();
159
+		$this->_message_type_collection_loader->load_message_types_from_folder();
160
+		$this->get_has_activated_messengers_option(true);
161
+		$this->_set_active_messengers_and_message_types();
162
+	}
163
+
164
+
165
+	/**
166
+	 * @return EE_Messenger_Collection
167
+	 */
168
+	public function messenger_collection()
169
+	{
170
+		$this->_initialize_collections();
171
+		return $this->_messenger_collection_loader->messenger_collection();
172
+	}
173
+
174
+
175
+	/**
176
+	 * @return EE_messenger[]
177
+	 */
178
+	public function active_messengers()
179
+	{
180
+		$this->_initialize_collections();
181
+		return $this->_active_messengers;
182
+	}
183
+
184
+
185
+	/**
186
+	 * @param string $messenger_name
187
+	 * @return \EE_messenger
188
+	 */
189
+	public function get_messenger($messenger_name)
190
+	{
191
+		return $this->messenger_collection()->get_by_info($messenger_name);
192
+	}
193
+
194
+
195
+	/**
196
+	 * This returns the corresponding EE_messenger object for the given string if it is active.
197
+	 *
198
+	 * @param string $messenger
199
+	 * @return EE_messenger | null
200
+	 */
201
+	public function get_active_messenger($messenger)
202
+	{
203
+		$this->_initialize_collections();
204
+		return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null;
205
+	}
206
+
207
+
208
+	/**
209
+	 * @return \EE_messenger[]
210
+	 */
211
+	public function installed_messengers()
212
+	{
213
+		if (empty($this->_installed_messengers)) {
214
+			$this->_installed_messengers = array();
215
+			$this->messenger_collection()->rewind();
216
+			while ($this->messenger_collection()->valid()) {
217
+				$this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current();
218
+				$this->messenger_collection()->next();
219
+			}
220
+		}
221
+		return $this->_installed_messengers;
222
+	}
223
+
224
+
225
+	/**
226
+	 * @param string $messenger_name
227
+	 * @return \EE_messenger
228
+	 * @throws \EE_Error
229
+	 */
230
+	public function valid_messenger($messenger_name)
231
+	{
232
+		$messenger = $this->get_messenger($messenger_name);
233
+		if ($messenger instanceof EE_messenger) {
234
+			return $messenger;
235
+		}
236
+		throw new EE_Error(
237
+			sprintf(
238
+				__('The "%1$s" messenger is either invalid or not installed', 'event_espresso'),
239
+				$messenger_name
240
+			)
241
+		);
242
+	}
243
+
244
+
245
+	/**
246
+	 * @return EE_Message_Type_Collection
247
+	 */
248
+	public function message_type_collection()
249
+	{
250
+		$this->_initialize_collections();
251
+		return $this->_message_type_collection_loader->message_type_collection();
252
+	}
253
+
254
+
255
+	/**
256
+	 * @return array
257
+	 */
258
+	public function active_message_types()
259
+	{
260
+		$this->_initialize_collections();
261
+		return $this->_active_message_types;
262
+	}
263
+
264
+
265
+	/**
266
+	 * @param string $message_type_name
267
+	 * @return \EE_message_type
268
+	 */
269
+	public function get_message_type($message_type_name)
270
+	{
271
+		return $this->message_type_collection()->get_by_info($message_type_name);
272
+	}
273
+
274
+
275
+	/**
276
+	 * This returns the EE_message_type from the active message types array ( if present );
277
+	 *
278
+	 * @param string $messenger_name
279
+	 * @param string $message_type_name
280
+	 * @return \EE_message_type|null
281
+	 */
282
+	public function get_active_message_type_for_messenger($messenger_name, $message_type_name)
283
+	{
284
+		return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
285
+			? $this->get_message_type($message_type_name)
286
+			: null;
287
+	}
288
+
289
+
290
+	/**
291
+	 * Returns whether the given message type is active for the given messenger.
292
+	 *
293
+	 * @param string $messenger_name
294
+	 * @param string $message_type_name
295
+	 * @return bool
296
+	 */
297
+	public function is_message_type_active_for_messenger($messenger_name, $message_type_name)
298
+	{
299
+		$this->_initialize_collections();
300
+		return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
301
+	}
302
+
303
+
304
+	/**
305
+	 * Returns whether the given messenger is active.
306
+	 *
307
+	 * @param string $messenger_name the name of the messenger to check if active.
308
+	 * @return bool
309
+	 */
310
+	public function is_messenger_active($messenger_name)
311
+	{
312
+		$this->_initialize_collections();
313
+		return ! empty($this->_active_message_types[$messenger_name]);
314
+	}
315
+
316
+
317
+	/**
318
+	 * This returns any settings that might be on a message type for a messenger
319
+	 *
320
+	 * @param string $messenger_name    The slug of the messenger
321
+	 * @param string $message_type_name The slug of the message type getting the settings for.
322
+	 * @return array
323
+	 */
324
+	public function get_message_type_settings_for_messenger($messenger_name, $message_type_name)
325
+	{
326
+		$settings = array();
327
+		if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
328
+			$settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'])
329
+				? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']
330
+				: array();
331
+		}
332
+		return $settings;
333
+	}
334
+
335
+
336
+	/**
337
+	 * Returns whether the given messenger name has active message types on it.
338
+	 * Infers whether the messenger is active or not as well.
339
+	 *
340
+	 * @param string $messenger_name
341
+	 * @return bool
342
+	 */
343
+	public function messenger_has_active_message_types($messenger_name)
344
+	{
345
+		$this->_initialize_collections();
346
+		return
347
+			! empty($this->_active_message_types[$messenger_name])
348
+			&& ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']);
349
+	}
350
+
351
+
352
+	/**
353
+	 * This checks the _active_message_types property for any active message types
354
+	 * that are present for the given messenger and returns them.
355
+	 *
356
+	 * @since 4.9.0
357
+	 * @param string $messenger_name The messenger being checked
358
+	 * @return EE_message_type[]|array    (empty array if no active_message_types)
359
+	 */
360
+	public function get_active_message_types_for_messenger($messenger_name)
361
+	{
362
+		$message_types = array();
363
+		if (! $this->messenger_has_active_message_types($messenger_name)) {
364
+			return $message_types;
365
+		}
366
+		$installed_message_types = $this->installed_message_types();
367
+		foreach ($installed_message_types as $message_type_name => $message_type) {
368
+			if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
369
+				$message_types[$message_type_name] = $message_type;
370
+			}
371
+		}
372
+		return $message_types;
373
+	}
374
+
375
+
376
+	/**
377
+	 * This does NOT return the _active_message_types property but
378
+	 * simply returns an array of active message type names from that property.
379
+	 * (The _active_message_types property is indexed by messenger and active message_types per messenger).
380
+	 *
381
+	 * @return array message_type references (string)
382
+	 */
383
+	public function list_of_active_message_types()
384
+	{
385
+		$active_message_type_names = array();
386
+		$this->_initialize_collections();
387
+		foreach ($this->_active_message_types as $messenger => $messenger_settings) {
388
+			if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) {
389
+				continue;
390
+			}
391
+			foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) {
392
+				if (! in_array($message_type_name, $active_message_type_names)) {
393
+					$active_message_type_names[] = $message_type_name;
394
+				}
395
+			}
396
+		}
397
+		return $active_message_type_names;
398
+	}
399
+
400
+
401
+	/**
402
+	 * Same as list_of_active_message_types() except this returns actual EE_message_type objects
403
+	 *
404
+	 * @since 4.9.0
405
+	 * @return \EE_message_type[]
406
+	 */
407
+	public function get_active_message_type_objects()
408
+	{
409
+		$active_message_types      = array();
410
+		$installed_message_types   = $this->installed_message_types();
411
+		$active_message_type_names = $this->list_of_active_message_types();
412
+		foreach ($active_message_type_names as $active_message_type_name) {
413
+			if (isset($installed_message_types[$active_message_type_name])) {
414
+				$active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name];
415
+			}
416
+		}
417
+		return $active_message_types;
418
+	}
419
+
420
+
421
+	/**
422
+	 * @return \EE_message_type[]
423
+	 */
424
+	public function installed_message_types()
425
+	{
426
+		if (empty($this->_installed_message_types)) {
427
+			$this->message_type_collection()->rewind();
428
+			while ($this->message_type_collection()->valid()) {
429
+				$this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current();
430
+				$this->message_type_collection()->next();
431
+			}
432
+		}
433
+		return $this->_installed_message_types;
434
+	}
435
+
436
+
437
+	/**
438
+	 * @param string $message_type_name
439
+	 * @return \EE_message_type
440
+	 * @throws \EE_Error
441
+	 */
442
+	public function valid_message_type($message_type_name)
443
+	{
444
+		$message_type = $this->get_message_type($message_type_name);
445
+		if ($message_type instanceof EE_message_type) {
446
+			return $message_type;
447
+		}
448
+		throw new EE_Error(
449
+			sprintf(
450
+				__('The "%1$s" message type is either invalid or not installed', 'event_espresso'),
451
+				$message_type_name
452
+			)
453
+		);
454
+	}
455
+
456
+
457
+	/**
458
+	 * valid_message_type_for_messenger
459
+	 *
460
+	 * @param EE_messenger $messenger
461
+	 * @param string       $message_type_name
462
+	 * @return boolean
463
+	 * @throws \EE_Error
464
+	 */
465
+	public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name)
466
+	{
467
+		$valid_message_types = $messenger->get_valid_message_types();
468
+		if (! in_array($message_type_name, $valid_message_types)) {
469
+			throw new EE_Error(
470
+				sprintf(
471
+					__(
472
+						'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger.  Double-check the spelling and verify that message type has been registered as a valid type with the messenger.',
473
+						'event_espresso'
474
+					),
475
+					$message_type_name,
476
+					__METHOD__,
477
+					$messenger->name
478
+				)
479
+			);
480
+		}
481
+		return true;
482
+	}
483
+
484
+
485
+	/**
486
+	 * Used to return active messengers array stored in the wp options table.
487
+	 * If no value is present in the option then an empty array is returned.
488
+	 *
489
+	 * @param   bool $reset     If true then we ignore whether the option is cached on the _active_message_types
490
+	 *                          property and pull directly from the db.  Otherwise whatever is currently on the
491
+	 *                          $_active_message_types property is pulled.
492
+	 * @return array
493
+	 */
494
+	public function get_active_messengers_option($reset = false)
495
+	{
496
+		if ($reset) {
497
+			$this->_active_message_types = get_option('ee_active_messengers', array());
498
+		}
499
+		return $this->_active_message_types;
500
+	}
501
+
502
+
503
+	/**
504
+	 * Used to update the active messengers array stored in the wp options table.
505
+	 *
506
+	 * @param array $active_messenger_settings Incoming data to save.  If empty, then the internal cached property
507
+	 *                                         representing this data is used.
508
+	 * @return bool FALSE if not updated, TRUE if updated.
509
+	 */
510
+	public function update_active_messengers_option($active_messenger_settings = array())
511
+	{
512
+		$active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings;
513
+		//make sure _active_message_types is updated (this is the internal cache for the settings).
514
+		$this->_active_message_types = $active_messenger_settings;
515
+		return update_option('ee_active_messengers', $active_messenger_settings);
516
+	}
517
+
518
+
519
+	/**
520
+	 * Used to return has activated message types for messengers array stored in the wp options table.
521
+	 * If no value is present in the option then an empty array is returned.
522
+	 * The value is cached on the $_has_activated_messengers_and_message_types property for future calls.
523
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
524
+	 *
525
+	 * @param   bool $reset Used to indicate that any cached value should be ignored.
526
+	 * @return array
527
+	 */
528
+	public function get_has_activated_messengers_option($reset = false)
529
+	{
530
+		if ($reset || empty($this->_has_activated_messengers_and_message_types)) {
531
+			$this->_has_activated_messengers_and_message_types = get_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, array());
532
+		}
533
+		return $this->_has_activated_messengers_and_message_types;
534
+	}
535
+
536
+
537
+	/**
538
+	 * Used to update the has activated option in the db.
539
+	 *
540
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
541
+	 *
542
+	 * @param array $has_activated_messengers Incoming data to save.  If empty, then the internal cached property
543
+	 *                                        representing this data is used.
544
+	 * @return bool FALSE if not updated, TRUE if updated.
545
+	 */
546
+	public function update_has_activated_messengers_option($has_activated_messengers = array())
547
+	{
548
+		//make sure the option has been retrieved from first so we don't overwrite it accidentally.
549
+		if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) {
550
+			$this->get_has_activated_messengers_option();
551
+		}
552
+		$has_activated_messengers = empty($has_activated_messengers)
553
+			? $this->_has_activated_messengers_and_message_types
554
+			: $has_activated_messengers;
555
+		return update_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, $has_activated_messengers);
556
+	}
557
+
558
+
559
+	/**
560
+	 * wrapper for _set_active_messengers_and_message_types()
561
+	 */
562
+	public function reset_active_messengers_and_message_types()
563
+	{
564
+		$this->_set_active_messengers_and_message_types();
565
+	}
566
+
567
+
568
+	/**
569
+	 * Generate list of active messengers and message types from collection.
570
+	 * This sets up the active messengers from what is present in the database.
571
+	 */
572
+	protected function _set_active_messengers_and_message_types()
573
+	{
574
+		//echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n";
575
+		// list of activated messengers as set via the admin
576
+		// note calling `get_active_messengers_options` also initializes the _active_message_types property.
577
+		$this->get_active_messengers_option(true);
578
+		$this->ensure_messengers_are_active(array(), false, true);
579
+		$this->update_active_messengers_option();
580
+		$this->update_has_activated_messengers_option();
581
+	}
582
+
583
+
584
+	/**
585
+	 * Ensures that the specified messenger is currently active.
586
+	 * If not, activates it and its default message types.
587
+	 *
588
+	 * @param string $messenger_name
589
+	 * @param bool   $update_option Whether to update the option in the db or not.
590
+	 * @return boolean true if either already active or successfully activated.
591
+	 */
592
+	public function ensure_messenger_is_active($messenger_name, $update_option = true)
593
+	{
594
+		if (! isset($this->_active_messengers[$messenger_name])) {
595
+			try {
596
+				$this->activate_messenger($messenger_name, array(), $update_option);
597
+			} catch (EE_Error $e) {
598
+				EE_Error::add_error(
599
+					$e->getMessage(),
600
+					__FILE__,
601
+					__FUNCTION__,
602
+					__LINE__
603
+				);
604
+				return false;
605
+			}
606
+		}
607
+		return true;
608
+	}
609
+
610
+
611
+	/**
612
+	 * This ensures the given array of messenger names is active in the system.
613
+	 * Note, this method will not activate any NEW message types for the messenger when it is called. Instead,
614
+	 * it will automatically activate the default message types for the messenger if its not active.
615
+	 *
616
+	 * @param array $messenger_names  Array of messenger names for messengers to be activated.  If an empty array
617
+	 *                                (default) then will attempt to set the active messengers from the
618
+	 *                                activated_messengers option
619
+	 *                                (stored in $_active_message_types property).
620
+	 * @param bool  $update_option    Whether to update the related active messengers option.
621
+	 * @param bool  $verify           Whether to verify the messengers are installed before activating. Note if this is
622
+	 *                                set to true and a messenger is indicated as active, but is NOT installed, then it
623
+	 *                                will automatically be deactivated.
624
+	 */
625
+	public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false)
626
+	{
627
+		$messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names;
628
+
629
+		$not_installed = array();
630
+		foreach ($messenger_names as $messenger_name) {
631
+			if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) {
632
+				$not_installed[] = $messenger_name;
633
+				$this->deactivate_messenger($messenger_name);
634
+				continue;
635
+			}
636
+			$this->ensure_messenger_is_active($messenger_name, $update_option);
637
+		}
638
+
639
+		if (! empty($not_installed_messenger)) {
640
+			EE_Error::add_error(
641
+				sprintf(
642
+					__('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'),
643
+					'<br />',
644
+					implode(', ', $not_installed_messenger)
645
+				),
646
+				__FILE__, __FUNCTION__, __LINE__
647
+			);
648
+		}
649
+	}
650
+
651
+
652
+	/**
653
+	 * Ensures that the specified message type for the given messenger is currently active, if not activates it.
654
+	 * This ALSO ensures that the given messenger is active as well!
655
+	 *
656
+	 * @param string $message_type_name message type name.
657
+	 * @param        $messenger_name
658
+	 * @param bool   $update_option     Whether to update the option in the db or not.
659
+	 * @return bool  Returns true if already is active or if was activated successfully.
660
+	 * @throws \EE_Error
661
+	 */
662
+	public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true)
663
+	{
664
+		// grab the messenger to work with.
665
+		$messenger = $this->valid_messenger($messenger_name);
666
+		if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) {
667
+			//ensure messenger is active (that's an inherent coupling between active message types and the
668
+			//messenger they are being activated for.
669
+			try {
670
+				if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
671
+					//all is good so let's just get it active
672
+					$this->activate_messenger($messenger_name, array($message_type_name), $update_option);
673
+				}
674
+			} catch (EE_Error $e) {
675
+				EE_Error::add_error(
676
+					$e->getMessage(),
677
+					__FILE__,
678
+					__FUNCTION__,
679
+					__LINE__
680
+				);
681
+				return false;
682
+			}
683
+		}
684
+		return true;
685
+	}
686
+
687
+
688
+	/**
689
+	 * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a
690
+	 * messenger are active in one go.
691
+	 *
692
+	 * @param array  $message_type_names Array of message type names to ensure are active.
693
+	 * @param string $messenger_name     The name of the messenger that the message types are to be activated on.
694
+	 * @param bool   $update_option      Whether to persist the activation to the database or not (default true).
695
+	 */
696
+	public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true)
697
+	{
698
+		$message_type_names = (array)$message_type_names;
699
+		foreach ($message_type_names as $message_type_name) {
700
+			// note, intentionally not updating option here because we're in a loop.
701
+			// We'll follow the instructions of the incoming $update_option argument after the loop.
702
+			$this->ensure_message_type_is_active($message_type_name, $messenger_name, false);
703
+		}
704
+		if ($update_option) {
705
+			$this->update_active_messengers_option();
706
+			$this->update_has_activated_messengers_option();
707
+		}
708
+	}
709
+
710
+
711
+	/**
712
+	 * Activates the specified messenger.
713
+	 *
714
+	 * @param string $messenger_name
715
+	 * @param array  $message_type_names        An array of message type names to activate with this messenger.
716
+	 *                                          If included we do NOT setup the default message types
717
+	 *                                          (assuming they are already setup.)
718
+	 * @param bool   $update_active_messengers_option
719
+	 * @return array of generated templates
720
+	 * @throws \EE_Error
721
+	 */
722
+	public function activate_messenger(
723
+		$messenger_name,
724
+		$message_type_names = array(),
725
+		$update_active_messengers_option = true
726
+	) {
727
+		$templates = array();
728
+		// grab the messenger to work with.
729
+		$messenger = $this->messenger_collection()->get_by_info($messenger_name);
730
+		// it's inactive. Activate it.
731
+		if ($messenger instanceof EE_messenger) {
732
+			$this->_active_messengers[$messenger->name] = $messenger;
733
+			//activate incoming message types set to be activated with messenger.
734
+			$message_type_names = $this->_activate_message_types($messenger, $message_type_names);
735
+			// setup any initial settings for the messenger if necessary.
736
+			$this->add_settings_for_messenger($messenger->name);
737
+			if ($update_active_messengers_option) {
738
+				$this->update_active_messengers_option();
739
+				$this->update_has_activated_messengers_option();
740
+			}
741
+			//generate new templates if necessary and ensure all related templates that are already in the database are
742
+			//marked active.  Note, this will also deactivate a message type for a messenger if the template
743
+			//cannot be successfully created during its attempt (only happens for global template attempts).
744
+			if (! empty($message_type_names)) {
745
+				$templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true);
746
+				EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names);
747
+			}
748
+		}
749
+		return $templates;
750
+	}
751
+
752
+
753
+	/**
754
+	 * Activates given message types for the given EE_messenger object.
755
+	 * Note: (very important) This method does not persist the activation to the database.
756
+	 * See code implementing this method in this class for examples of how to persist.
757
+	 *
758
+	 * @param \EE_messenger $messenger
759
+	 * @param  array        $message_type_names
760
+	 * @return array
761
+	 */
762
+	protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array())
763
+	{
764
+		//If $message_type_names is empty, AND $this->_active_message_types is empty, then that means
765
+		//things have never been initialized (which should happen on EEH_Activation::generate_message_templates).
766
+		//So ONLY then do we need to actually grab defaults and cycle through them.  Otherwise we
767
+		//only override _active_message_types when an explicit array of $message_type_names has been provided.
768
+		$message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name])
769
+			? $messenger->get_default_message_types()
770
+			: (array)$message_type_names;
771
+
772
+		//now we ALWAYS need to make sure that the messenger is active for the message types we're activating!
773
+		if (! isset($this->_active_message_types[$messenger->name])) {
774
+			$this->_active_message_types[$messenger->name]['settings'] = array();
775
+		}
776
+
777
+		if ($message_type_names) {
778
+			// cycle thru message types
779
+			foreach ($message_type_names as $message_type_name) {
780
+				//only register the message type as active IF it isn't already active
781
+				//and if its actually installed.
782
+				if (
783
+				! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name)
784
+				) {
785
+					$this->add_settings_for_message_type($messenger->name, $message_type_name);
786
+					$this->_set_messenger_has_activated_message_type(
787
+						$messenger,
788
+						$message_type_name
789
+					);
790
+				}
791
+			}
792
+		}
793
+		return $message_type_names;
794
+	}
795
+
796
+
797
+	/**
798
+	 * add_settings_for_message_type
799
+	 * NOTE This does NOT automatically persist any settings to the db.  Client code should call
800
+	 * $this->update_active_messengers_option to persist.
801
+	 *
802
+	 * @param  string $messenger_name    The name of the messenger adding the settings for
803
+	 * @param  string $message_type_name The name of the message type adding the settings for
804
+	 * @param  array  $new_settings      Any new settings being set for the message type and messenger
805
+	 */
806
+	public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array())
807
+	{
808
+		// get installed message type from collection
809
+		$message_type      = $this->message_type_collection()->get_by_info($message_type_name);
810
+		$existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name);
811
+		//we need to setup any initial settings for message types
812
+		if ($message_type instanceof EE_message_type) {
813
+			$default_settings = $message_type->get_admin_settings_fields();
814
+			foreach ($default_settings as $field => $values) {
815
+				if (isset($new_settings[$field])) {
816
+					$existing_settings[$field] = $new_settings[$field];
817
+					continue;
818
+				}
819
+				if (! isset($existing_settings[$field])) {
820
+					$existing_settings[$field] = $values['default'];
821
+				}
822
+			}
823
+		}
824
+		$this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings;
825
+	}
826
+
827
+
828
+	/**
829
+	 * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger
830
+	 * and message type.
831
+	 *
832
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
833
+	 *
834
+	 * @access protected
835
+	 * @param \EE_messenger $messenger
836
+	 * @param string        $message_type_name
837
+	 */
838
+	protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name)
839
+	{
840
+
841
+		//if _has_activated_messengers_and_message_types is empty then lets ensure its initialized
842
+		if (empty($this->_has_activated_messengers_and_message_types)) {
843
+			$this->get_has_activated_messengers_option();
844
+		}
845
+
846
+		// make sure this messenger has a record in the has_activated array
847
+		if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) {
848
+			$this->_has_activated_messengers_and_message_types[$messenger->name] = array();
849
+		}
850
+		// check if message type has already been added
851
+		if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) {
852
+			$this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name;
853
+		}
854
+	}
855
+
856
+
857
+	/**
858
+	 * add_settings_for_messenger
859
+	 * NOTE This does NOT automatically persist any settings to the db.  Client code should call
860
+	 * $this->update_active_messengers_option to persist.
861
+	 *
862
+	 * @param string $messenger_name The name of the messenger the settings is being added for.
863
+	 * @param array  $new_settings   An array of settings to update the existing settings.
864
+	 */
865
+	public function add_settings_for_messenger($messenger_name, $new_settings = array())
866
+	{
867
+		$messenger = $this->get_messenger($messenger_name);
868
+		if ($messenger instanceof EE_messenger) {
869
+			$msgr_settings = $messenger->get_admin_settings_fields();
870
+			if (! empty($msgr_settings)) {
871
+				foreach ($msgr_settings as $field => $value) {
872
+					//is there a new setting for this?
873
+					if (isset($new_settings[$field])) {
874
+						$this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field];
875
+						continue;
876
+					}
877
+					//only set the default if it isn't already set.
878
+					if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) {
879
+						$this->_active_message_types[$messenger->name]['settings'][$field] = $value;
880
+					}
881
+				}
882
+			}
883
+		}
884
+	}
885
+
886
+
887
+	/**
888
+	 * deactivate_messenger
889
+	 *
890
+	 * @param  string|EE_messenger $messenger_name name of messenger
891
+	 * @return void
892
+	 */
893
+	public function deactivate_messenger($messenger_name)
894
+	{
895
+		$this->_initialize_collections();
896
+		if ($messenger_name instanceof EE_messenger) {
897
+			$messenger_name = $messenger_name->name;
898
+		}
899
+		unset($this->_active_messengers[$messenger_name]);
900
+		unset($this->_active_message_types[$messenger_name]);
901
+		$this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name);
902
+		$this->update_active_messengers_option();
903
+	}
904
+
905
+
906
+	/**
907
+	 * Deactivates a message type (note this will deactivate across all messenger's it is active on.
908
+	 *
909
+	 * @param  string $message_type_name     name of message type being deactivated
910
+	 * @param bool    $set_has_active_record By default we always record the has_active record when deactivating a message
911
+	 *                                       type.  However, this can be overridden if we don't want this set (usually when
912
+	 *                                       this is called as a part of deregistration of a custom message type)
913
+	 */
914
+	public function deactivate_message_type($message_type_name, $set_has_active_record = true)
915
+	{
916
+		$this->_initialize_collections();
917
+		if ($message_type_name instanceof EE_message_type) {
918
+			$message_type_name = $message_type_name->name;
919
+		}
920
+		foreach ($this->_active_message_types as $messenger_name => $settings) {
921
+			unset(
922
+				$this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]
923
+			);
924
+
925
+			//we always record (even on deactivation) that a message type has been activated because there should at
926
+			//least be a record in the "has_activated" option that it WAS active at one point.
927
+			if ($set_has_active_record) {
928
+				$messenger = $this->get_messenger($messenger_name);
929
+				$this->_set_messenger_has_activated_message_type($messenger, $message_type_name);
930
+			}
931
+		}
932
+		$this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name);
933
+		$this->update_active_messengers_option();
934
+		$this->update_has_activated_messengers_option();
935
+	}
936
+
937
+
938
+	/**
939
+	 * Deactivates a message type for a specific messenger as opposed to all messengers.
940
+	 *
941
+	 * @param string $message_type_name Name of message type being deactivated.
942
+	 * @param string $messenger_name    Name of messenger the message type is being deactivated for.
943
+	 */
944
+	public function deactivate_message_type_for_messenger($message_type_name, $messenger_name)
945
+	{
946
+		$this->_initialize_collections();
947
+		if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) {
948
+			unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]);
949
+		}
950
+		$this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name),
951
+			array($message_type_name));
952
+		$this->update_active_messengers_option();
953
+	}
954
+
955
+
956
+	/**
957
+	 * Used to verify if a message can be sent for the given messenger and message type
958
+	 * and that it is a generating messenger (used for generating message templates).
959
+	 *
960
+	 * @param EE_messenger    $messenger    messenger used in trigger
961
+	 * @param EE_message_type $message_type message type used in trigger
962
+	 * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
963
+	 */
964
+	public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
965
+	{
966
+		//get the $messengers the message type says it can be used with.
967
+		foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) {
968
+			if (
969
+				$messenger->name === $generating_messenger
970
+				&& $this->is_message_type_active_for_messenger($messenger->name, $message_type->name)
971
+			) {
972
+				return true;
973
+			}
974
+		}
975
+		return false;
976
+	}
977
+
978
+
979
+	/**
980
+	 * This returns all the contexts that are registered by all message types.
981
+	 * If $slugs_only is true,
982
+	 * then just an array indexed by unique context slugs with the latest label representation for that slug.
983
+	 * array(
984
+	 *      'context_slug' => 'localized label for context obtained from latest message type in the loop'.
985
+	 * );
986
+	 * If $slugs_only is false, then the format is:
987
+	 * array(
988
+	 *      'message_type_name' => array(
989
+	 *          'context_slug' => array(
990
+	 *              'label' => 'localized label for context',
991
+	 *              'description' => 'localized description for context'
992
+	 *          )
993
+	 *      )
994
+	 * );
995
+	 * Keep in mind that although different message types may share the same context slugs,
996
+	 * it is possible that the context is described differently by the message type.
997
+	 *
998
+	 * @since 4.9.0
999
+	 * @param   bool $slugs_only Whether to return an array of just slugs and labels (true)
1000
+	 *                           or all contexts indexed by message type.
1001
+	 * @return array
1002
+	 */
1003
+	public function get_all_contexts($slugs_only = true)
1004
+	{
1005
+		$key = $slugs_only ? 'slugs' : 'all';
1006
+		// check if contexts has been setup yet.
1007
+		if (empty($this->_contexts[$key])) {
1008
+			// So let's get all active message type objects and loop through to get all unique contexts
1009
+			foreach ($this->get_active_message_type_objects() as $message_type) {
1010
+				if ($message_type instanceof EE_message_type) {
1011
+					$message_type_contexts = $message_type->get_contexts();
1012
+					if ($slugs_only) {
1013
+						foreach ($message_type_contexts as $context => $context_details) {
1014
+							$this->_contexts[$key][$context] = $context_details['label'];
1015
+						}
1016
+					} else {
1017
+						$this->_contexts[$key][$message_type->name] = $message_type_contexts;
1018
+					}
1019
+				}
1020
+			}
1021
+		}
1022
+		return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array();
1023
+	}
1024
+
1025
+
1026
+	/**
1027
+	 * This checks the internal record of what message types are considered "active" and verifies that
1028
+	 * there is an installed class definition for that message type.  If the active message type does not have a
1029
+	 * corresponding accessible message type class then it will be deactivated from all messengers it is active on and
1030
+	 * any related message templates will be inactivated as well.
1031
+	 *
1032
+	 * @return bool   true means all active message types are valid, false means at least one message type was
1033
+	 *                deactivated.
1034
+	 */
1035
+	public function validate_active_message_types_are_installed()
1036
+	{
1037
+		$list_of_active_message_type_names = $this->list_of_active_message_types();
1038
+		$installed_message_types           = $this->installed_message_types();
1039
+		$all_message_types_valid           = true;
1040
+		//loop through list of active message types and verify they are installed.
1041
+		foreach ($list_of_active_message_type_names as $message_type_name) {
1042
+			if (! isset($installed_message_types[$message_type_name])) {
1043
+				$this->remove_message_type_has_been_activated_from_all_messengers(
1044
+					$message_type_name,
1045
+					true
1046
+				);
1047
+				$this->deactivate_message_type($message_type_name, false);
1048
+				$all_message_types_valid = false;
1049
+			}
1050
+		}
1051
+		return $all_message_types_valid;
1052
+	}
1053
+
1054
+
1055
+	/**
1056
+	 * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been
1057
+	 * activated for the given messenger.  This can be called by client code on plugin updates etc to determine whether
1058
+	 * to attempt automatically reactivating message types that should be activated by default or not.
1059
+	 *
1060
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1061
+	 *
1062
+	 * @param $message_type_name
1063
+	 * @param $messenger_name
1064
+	 * @return bool
1065
+	 */
1066
+	public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name)
1067
+	{
1068
+		$has_activated = $this->get_has_activated_messengers_option();
1069
+		return isset($has_activated[$messenger_name])
1070
+			   && in_array($message_type_name, $has_activated[$messenger_name]);
1071
+	}
1072
+
1073
+
1074
+	/**
1075
+	 * This method unsets a message type from the given messenger has activated option.
1076
+	 *
1077
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1078
+	 *
1079
+	 * @param string $message_type_name
1080
+	 * @param string $messenger_name
1081
+	 * @param bool   $consider_current_state  Whether to consider whether the  message type is currently active or not.
1082
+	 *                                        If it is currently active, then remove.  Otherwise leave it alone.
1083
+	 */
1084
+	public function remove_message_type_has_been_activated_for_messenger(
1085
+		$message_type_name,
1086
+		$messenger_name,
1087
+		$consider_current_state = false
1088
+	) {
1089
+		if ($consider_current_state
1090
+			&& ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)
1091
+		) {
1092
+			//when consider current state is true, this means we don't want to change anything on the "has_activated"
1093
+			//record if the message type is currently active for this messenger.  This is used when we want to retain
1094
+			//the record for user initiated inactivations of the message type.
1095
+			return;
1096
+		}
1097
+		$has_activated = $this->get_has_activated_messengers_option();
1098
+		$key_for_message_type = isset($has_activated[$messenger_name])
1099
+			? array_search($message_type_name, $has_activated[$messenger_name], true)
1100
+			: false;
1101
+		if ($key_for_message_type !== false) {
1102
+			unset($has_activated[$messenger_name][$key_for_message_type]);
1103
+			$this->update_has_activated_messengers_option($has_activated);
1104
+			//reset the internal cached property
1105
+			$this->get_has_activated_messengers_option(true);
1106
+		}
1107
+	}
1108
+
1109
+
1110
+	/**
1111
+	 * Removes a message type active record from all messengers it is attached to.
1112
+	 *
1113
+	 * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details.
1114
+	 *
1115
+	 * @param      $message_type_name
1116
+	 * @param bool $consider_current_state  Whether to consider whether the  message type is currently active or not.
1117
+	 *                                      If it is currently active, then remove.  Otherwise leave it alone.
1118
+	 */
1119
+	public function remove_message_type_has_been_activated_from_all_messengers(
1120
+		$message_type_name,
1121
+		$consider_current_state = false
1122
+	) {
1123
+		foreach(array_keys($this->get_has_activated_messengers_option()) as $messenger_name) {
1124
+			$this->remove_message_type_has_been_activated_for_messenger(
1125
+				$message_type_name,
1126
+				$messenger_name,
1127
+				$consider_current_state
1128
+			);
1129
+		}
1130
+	}
1131 1131
 }
1132 1132
 // End of file EE_Message_Resource_Manager.lib.php
1133 1133
 // Location: /EE_Message_Resource_Manager.lib.php
1134 1134
\ No newline at end of file
Please login to merge, or discard this patch.
core/services/database/TableManager.php 2 patches
Indentation   +245 added lines, -247 removed lines patch added patch discarded remove patch
@@ -17,254 +17,252 @@
 block discarded – undo
17 17
 class TableManager extends \EE_Base
18 18
 {
19 19
 
20
-    /**
21
-     * @var TableAnalysis $table_analysis
22
-     */
23
-    private $table_analysis;
24
-
25
-
26
-
27
-    /**
28
-     * TableManager constructor.
29
-     *
30
-     * @param TableAnalysis $TableAnalysis
31
-     */
32
-    public function __construct(TableAnalysis $TableAnalysis)
33
-    {
34
-        $this->table_analysis = $TableAnalysis;
35
-    }
36
-
37
-
38
-
39
-    /**
40
-     * Gets the injected table analyzer, or throws an exception
41
-     *
42
-     * @return TableAnalysis
43
-     * @throws \EE_Error
44
-     */
45
-    protected function getTableAnalysis()
46
-    {
47
-        if ($this->table_analysis instanceof TableAnalysis) {
48
-            return $this->table_analysis;
49
-        } else {
50
-            throw new \EE_Error(
51
-                sprintf(
52
-                    __('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
53
-                    get_class($this)
54
-                )
55
-            );
56
-        }
57
-    }
58
-
59
-
60
-
61
-    /**
62
-     * @param string $table_name which can optionally start with $wpdb->prefix or not
63
-     * @param string $column_name
64
-     * @param string $column_info
65
-     * @return bool|false|int
66
-     */
67
-    public function addColumn($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL')
68
-    {
69
-        if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) {
70
-            return false;
71
-        }
72
-        global $wpdb;
73
-        $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
74
-        $columns = $this->getTableColumns($table_name);
75
-        if ( ! in_array($column_name, $columns)) {
76
-            $alter_query = "ALTER TABLE {$full_table_name} ADD {$column_name} {$column_info}";
77
-            return $wpdb->query($alter_query);
78
-        }
79
-        return true;
80
-    }
81
-
82
-
83
-
84
-    /**
85
-     * Gets the name of all columns on the  table. $table_name can
86
-     * optionally start with $wpdb->prefix or not
87
-     *
88
-     * @global \wpdb $wpdb
89
-     * @param string $table_name
90
-     * @return array
91
-     */
92
-    public function getTableColumns($table_name)
93
-    {
94
-        global $wpdb;
95
-        $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
96
-        $field_array = array();
97
-        if ( ! empty($table_name)) {
98
-            $columns = $wpdb->get_results("SHOW COLUMNS FROM {$table_name} ");
99
-            if ($columns !== false) {
100
-                foreach ($columns as $column) {
101
-                    $field_array[] = $column->Field;
102
-                }
103
-            }
104
-        }
105
-        return $field_array;
106
-    }
107
-
108
-
109
-
110
-    /**
111
-     * Drops the specified table from the database. $table_name can
112
-     * optionally start with $wpdb->prefix or not
113
-     *
114
-     * @global \wpdb $wpdb
115
-     * @param string $table_name
116
-     * @return int
117
-     */
118
-    public function dropTable($table_name)
119
-    {
120
-        global $wpdb;
121
-        if ($this->getTableAnalysis()->tableExists($table_name)) {
122
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
123
-            return $wpdb->query("DROP TABLE IF EXISTS {$table_name}");
124
-        }
125
-        return 0;
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
132
-     * each table name provided has a wpdb prefix attached, and that it exists.
133
-     * Returns the list actually deleted
134
-     *
135
-     * @global WPDB $wpdb
136
-     * @param array $table_names
137
-     * @return array of table names which we deleted
138
-     */
139
-    public function dropTables($table_names)
140
-    {
141
-        $tables_to_delete = array();
142
-        foreach ($table_names as $table_name) {
143
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
144
-            if ($this->getTableAnalysis()->tableExists($table_name)) {
145
-                $tables_to_delete[] = $table_name;
146
-            }
147
-        }
148
-        if( ! empty( $tables_to_delete ) ) {
149
-            global $wpdb;
150
-            //make sure we only have a unique strings in the array.
151
-            $tables_to_delete = array_unique($tables_to_delete);
152
-            $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete));
153
-        }
154
-        return $tables_to_delete;
155
-    }
156
-
157
-
158
-
159
-    /**
160
-     * Drops the specified index from the specified table. $table_name can
161
-     * optionally start with $wpdb->prefix or not
162
-
163
-     *
20
+	/**
21
+	 * @var TableAnalysis $table_analysis
22
+	 */
23
+	private $table_analysis;
24
+
25
+
26
+
27
+	/**
28
+	 * TableManager constructor.
29
+	 *
30
+	 * @param TableAnalysis $TableAnalysis
31
+	 */
32
+	public function __construct(TableAnalysis $TableAnalysis)
33
+	{
34
+		$this->table_analysis = $TableAnalysis;
35
+	}
36
+
37
+
38
+
39
+	/**
40
+	 * Gets the injected table analyzer, or throws an exception
41
+	 *
42
+	 * @return TableAnalysis
43
+	 * @throws \EE_Error
44
+	 */
45
+	protected function getTableAnalysis()
46
+	{
47
+		if ($this->table_analysis instanceof TableAnalysis) {
48
+			return $this->table_analysis;
49
+		} else {
50
+			throw new \EE_Error(
51
+				sprintf(
52
+					__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
53
+					get_class($this)
54
+				)
55
+			);
56
+		}
57
+	}
58
+
59
+
60
+
61
+	/**
62
+	 * @param string $table_name which can optionally start with $wpdb->prefix or not
63
+	 * @param string $column_name
64
+	 * @param string $column_info
65
+	 * @return bool|false|int
66
+	 */
67
+	public function addColumn($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL')
68
+	{
69
+		if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) {
70
+			return false;
71
+		}
72
+		global $wpdb;
73
+		$full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
74
+		$columns = $this->getTableColumns($table_name);
75
+		if ( ! in_array($column_name, $columns)) {
76
+			$alter_query = "ALTER TABLE {$full_table_name} ADD {$column_name} {$column_info}";
77
+			return $wpdb->query($alter_query);
78
+		}
79
+		return true;
80
+	}
81
+
82
+
83
+
84
+	/**
85
+	 * Gets the name of all columns on the  table. $table_name can
86
+	 * optionally start with $wpdb->prefix or not
87
+	 *
88
+	 * @global \wpdb $wpdb
89
+	 * @param string $table_name
90
+	 * @return array
91
+	 */
92
+	public function getTableColumns($table_name)
93
+	{
94
+		global $wpdb;
95
+		$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
96
+		$field_array = array();
97
+		if ( ! empty($table_name)) {
98
+			$columns = $wpdb->get_results("SHOW COLUMNS FROM {$table_name} ");
99
+			if ($columns !== false) {
100
+				foreach ($columns as $column) {
101
+					$field_array[] = $column->Field;
102
+				}
103
+			}
104
+		}
105
+		return $field_array;
106
+	}
107
+
108
+
109
+
110
+	/**
111
+	 * Drops the specified table from the database. $table_name can
112
+	 * optionally start with $wpdb->prefix or not
113
+	 *
114
+	 * @global \wpdb $wpdb
115
+	 * @param string $table_name
116
+	 * @return int
117
+	 */
118
+	public function dropTable($table_name)
119
+	{
120
+		global $wpdb;
121
+		if ($this->getTableAnalysis()->tableExists($table_name)) {
122
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
123
+			return $wpdb->query("DROP TABLE IF EXISTS {$table_name}");
124
+		}
125
+		return 0;
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
132
+	 * each table name provided has a wpdb prefix attached, and that it exists.
133
+	 * Returns the list actually deleted
134
+	 *
135
+	 * @global WPDB $wpdb
136
+	 * @param array $table_names
137
+	 * @return array of table names which we deleted
138
+	 */
139
+	public function dropTables($table_names)
140
+	{
141
+		$tables_to_delete = array();
142
+		foreach ($table_names as $table_name) {
143
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
144
+			if ($this->getTableAnalysis()->tableExists($table_name)) {
145
+				$tables_to_delete[] = $table_name;
146
+			}
147
+		}
148
+		if( ! empty( $tables_to_delete ) ) {
149
+			global $wpdb;
150
+			//make sure we only have a unique strings in the array.
151
+			$tables_to_delete = array_unique($tables_to_delete);
152
+			$wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete));
153
+		}
154
+		return $tables_to_delete;
155
+	}
156
+
157
+
158
+
159
+	/**
160
+	 * Drops the specified index from the specified table. $table_name can
161
+	 * optionally start with $wpdb->prefix or not
162
+	 *
164 163
 *@global \wpdb       $wpdb
165
-     * @param string $table_name
166
-     * @param string $index_name
167
-     * @return int the number of indexes dropped. False if there was a datbase error
168
-     */
169
-    public function dropIndex($table_name, $index_name)
170
-    {
171
-        if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) {
172
-            return 0;
173
-        }
174
-        global $wpdb;
175
-        $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
176
-        $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE key_name = '{$index_name}'";
177
-        if (
178
-            $this->getTableAnalysis()->tableExists($table_name)
179
-            && $wpdb->get_var($index_exists_query)
180
-               === $table_name //using get_var with the $index_exists_query returns the table's name
181
-        ) {
182
-            return $wpdb->query("ALTER TABLE {$table_name} DROP INDEX {$index_name}");
183
-        }
184
-        return 0;
185
-    }
186
-
187
-
188
-
189
-    /**
190
-     * Just creates the requested table. $table_name can
191
-     * optionally start with $wpdb->prefix or not
192
-
193
-     *
164
+	 * @param string $table_name
165
+	 * @param string $index_name
166
+	 * @return int the number of indexes dropped. False if there was a datbase error
167
+	 */
168
+	public function dropIndex($table_name, $index_name)
169
+	{
170
+		if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) {
171
+			return 0;
172
+		}
173
+		global $wpdb;
174
+		$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
175
+		$index_exists_query = "SHOW INDEX FROM {$table_name} WHERE key_name = '{$index_name}'";
176
+		if (
177
+			$this->getTableAnalysis()->tableExists($table_name)
178
+			&& $wpdb->get_var($index_exists_query)
179
+			   === $table_name //using get_var with the $index_exists_query returns the table's name
180
+		) {
181
+			return $wpdb->query("ALTER TABLE {$table_name} DROP INDEX {$index_name}");
182
+		}
183
+		return 0;
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * Just creates the requested table. $table_name can
190
+	 * optionally start with $wpdb->prefix or not
191
+	 *
194 192
 *@param string       $table_name
195
-     * @param string $create_sql defining the table's columns and indexes
196
-     * @param string $engine     (no need to specify "ENGINE=", that's implied)
197
-     * @return void
198
-     * @throws \EE_Error
199
-     */
200
-    public function createTable($table_name, $create_sql, $engine = 'MyISAM')
201
-    {
202
-        // does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns )
203
-        if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) {
204
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
205
-            /** @var \wpdb $wpdb */
206
-            global $wpdb;
207
-            $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate();
208
-
209
-            //get $wpdb to echo errors, but buffer them. This way at least WE know an error
210
-            //happened. And then we can choose to tell the end user
211
-            $old_show_errors_policy = $wpdb->show_errors(true);
212
-            $old_error_suppression_policy = $wpdb->suppress_errors(false);
213
-            ob_start();
214
-            dbDelta($SQL);
215
-            $output = ob_get_contents();
216
-            ob_end_clean();
217
-            $wpdb->show_errors($old_show_errors_policy);
218
-            $wpdb->suppress_errors($old_error_suppression_policy);
219
-            if ( ! empty($output)) {
220
-                throw new \EE_Error($output);
221
-            }
222
-        } else {
223
-            throw new \EE_Error(
224
-                sprintf(
225
-                    __('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s',
226
-                        'event_espresso'),
227
-                    '<br />',
228
-                    $create_sql
229
-                )
230
-            );
231
-        }
232
-    }
233
-
234
-
235
-
236
-    /**
237
-     * Drops the specified index if it's size differs from $desired_index_size.
238
-     * WordPress' dbdelta method doesn't automatically change index sizes, so this
239
-     * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal.
240
-     * If the table doesn't exist, or it exists but the index does not, or returns false
241
-     *
242
-     * @param string $table_name
243
-     * @param string $index_name
244
-     * @param string $column_name if none is provided, we assume the column name matches the index (often true in EE)
245
-     * @param string|int $desired_index_size defaults to TableAnalysis::index_col_size, the max for utf8mb4.
246
-     * @return bool whether an index was dropped or not
247
-     * @throws /EE_Error if table analysis object isn't defined
248
-     */
249
-    public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = TableAnalysis::INDEX_COLUMN_SIZE)
250
-    {
251
-        if($column_name === null){
252
-            $column_name = $index_name;
253
-        }
254
-        if(!$this->getTableAnalysis()->tableExists($table_name)){
255
-            return false;
256
-        }
257
-        $index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name);
258
-        if(empty($index_entries)){
259
-            return false;
260
-        }
261
-        foreach($index_entries as $index_entry){
262
-            if( $column_name === $index_entry->Column_name
263
-                && (string)$desired_index_size !== $index_entry->Sub_part){
264
-                return $this->dropIndex($table_name,$index_name);
265
-            }
266
-        }
267
-        return false;
268
-    }
193
+	 * @param string $create_sql defining the table's columns and indexes
194
+	 * @param string $engine     (no need to specify "ENGINE=", that's implied)
195
+	 * @return void
196
+	 * @throws \EE_Error
197
+	 */
198
+	public function createTable($table_name, $create_sql, $engine = 'MyISAM')
199
+	{
200
+		// does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns )
201
+		if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) {
202
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
203
+			/** @var \wpdb $wpdb */
204
+			global $wpdb;
205
+			$SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate();
206
+
207
+			//get $wpdb to echo errors, but buffer them. This way at least WE know an error
208
+			//happened. And then we can choose to tell the end user
209
+			$old_show_errors_policy = $wpdb->show_errors(true);
210
+			$old_error_suppression_policy = $wpdb->suppress_errors(false);
211
+			ob_start();
212
+			dbDelta($SQL);
213
+			$output = ob_get_contents();
214
+			ob_end_clean();
215
+			$wpdb->show_errors($old_show_errors_policy);
216
+			$wpdb->suppress_errors($old_error_suppression_policy);
217
+			if ( ! empty($output)) {
218
+				throw new \EE_Error($output);
219
+			}
220
+		} else {
221
+			throw new \EE_Error(
222
+				sprintf(
223
+					__('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s',
224
+						'event_espresso'),
225
+					'<br />',
226
+					$create_sql
227
+				)
228
+			);
229
+		}
230
+	}
231
+
232
+
233
+
234
+	/**
235
+	 * Drops the specified index if it's size differs from $desired_index_size.
236
+	 * WordPress' dbdelta method doesn't automatically change index sizes, so this
237
+	 * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal.
238
+	 * If the table doesn't exist, or it exists but the index does not, or returns false
239
+	 *
240
+	 * @param string $table_name
241
+	 * @param string $index_name
242
+	 * @param string $column_name if none is provided, we assume the column name matches the index (often true in EE)
243
+	 * @param string|int $desired_index_size defaults to TableAnalysis::index_col_size, the max for utf8mb4.
244
+	 * @return bool whether an index was dropped or not
245
+	 * @throws /EE_Error if table analysis object isn't defined
246
+	 */
247
+	public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = TableAnalysis::INDEX_COLUMN_SIZE)
248
+	{
249
+		if($column_name === null){
250
+			$column_name = $index_name;
251
+		}
252
+		if(!$this->getTableAnalysis()->tableExists($table_name)){
253
+			return false;
254
+		}
255
+		$index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name);
256
+		if(empty($index_entries)){
257
+			return false;
258
+		}
259
+		foreach($index_entries as $index_entry){
260
+			if( $column_name === $index_entry->Column_name
261
+				&& (string)$desired_index_size !== $index_entry->Sub_part){
262
+				return $this->dropIndex($table_name,$index_name);
263
+			}
264
+		}
265
+		return false;
266
+	}
269 267
 
270 268
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -145,11 +145,11 @@  discard block
 block discarded – undo
145 145
                 $tables_to_delete[] = $table_name;
146 146
             }
147 147
         }
148
-        if( ! empty( $tables_to_delete ) ) {
148
+        if ( ! empty($tables_to_delete)) {
149 149
             global $wpdb;
150 150
             //make sure we only have a unique strings in the array.
151 151
             $tables_to_delete = array_unique($tables_to_delete);
152
-            $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete));
152
+            $wpdb->query('DROP TABLE '.implode(', ', $tables_to_delete));
153 153
         }
154 154
         return $tables_to_delete;
155 155
     }
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
             $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
205 205
             /** @var \wpdb $wpdb */
206 206
             global $wpdb;
207
-            $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate();
207
+            $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} ".$wpdb->get_charset_collate();
208 208
 
209 209
             //get $wpdb to echo errors, but buffer them. This way at least WE know an error
210 210
             //happened. And then we can choose to tell the end user
@@ -248,20 +248,20 @@  discard block
 block discarded – undo
248 248
      */
249 249
     public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = TableAnalysis::INDEX_COLUMN_SIZE)
250 250
     {
251
-        if($column_name === null){
251
+        if ($column_name === null) {
252 252
             $column_name = $index_name;
253 253
         }
254
-        if(!$this->getTableAnalysis()->tableExists($table_name)){
254
+        if ( ! $this->getTableAnalysis()->tableExists($table_name)) {
255 255
             return false;
256 256
         }
257
-        $index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name);
258
-        if(empty($index_entries)){
257
+        $index_entries = $this->getTableAnalysis()->showIndexes($table_name, $index_name);
258
+        if (empty($index_entries)) {
259 259
             return false;
260 260
         }
261
-        foreach($index_entries as $index_entry){
262
-            if( $column_name === $index_entry->Column_name
263
-                && (string)$desired_index_size !== $index_entry->Sub_part){
264
-                return $this->dropIndex($table_name,$index_name);
261
+        foreach ($index_entries as $index_entry) {
262
+            if ($column_name === $index_entry->Column_name
263
+                && (string) $desired_index_size !== $index_entry->Sub_part) {
264
+                return $this->dropIndex($table_name, $index_name);
265 265
             }
266 266
         }
267 267
         return false;
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Proper.form.php 1 patch
Indentation   +1380 added lines, -1380 removed lines patch added patch discarded remove patch
@@ -11,1386 +11,1386 @@
 block discarded – undo
11 11
 class EE_Form_Section_Proper extends EE_Form_Section_Validatable
12 12
 {
13 13
 
14
-    const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
15
-
16
-    /**
17
-     * Subsections
18
-     *
19
-     * @var EE_Form_Section_Validatable[]
20
-     */
21
-    protected $_subsections = array();
22
-
23
-    /**
24
-     * Strategy for laying out the form
25
-     *
26
-     * @var EE_Form_Section_Layout_Base
27
-     */
28
-    protected $_layout_strategy;
29
-
30
-    /**
31
-     * Whether or not this form has received and validated a form submission yet
32
-     *
33
-     * @var boolean
34
-     */
35
-    protected $_received_submission = false;
36
-
37
-    /**
38
-     * message displayed to users upon successful form submission
39
-     *
40
-     * @var string
41
-     */
42
-    protected $_form_submission_success_message = '';
43
-
44
-    /**
45
-     * message displayed to users upon unsuccessful form submission
46
-     *
47
-     * @var string
48
-     */
49
-    protected $_form_submission_error_message = '';
50
-
51
-    /**
52
-     * Stores all the data that will localized for form validation
53
-     *
54
-     * @var array
55
-     */
56
-    static protected $_js_localization = array();
57
-
58
-    /**
59
-     * whether or not the form's localized validation JS vars have been set
60
-     *
61
-     * @type boolean
62
-     */
63
-    static protected $_scripts_localized = false;
64
-
65
-
66
-
67
-    /**
68
-     * when constructing a proper form section, calls _construct_finalize on children
69
-     * so that they know who their parent is, and what name they've been given.
70
-     *
71
-     * @param array $options_array   {
72
-     * @type        $subsections     EE_Form_Section_Validatable[] where keys are the section's name
73
-     * @type        $include         string[] numerically-indexed where values are section names to be included,
74
-     *                               and in that order. This is handy if you want
75
-     *                               the subsections to be ordered differently than the default, and if you override
76
-     *                               which fields are shown
77
-     * @type        $exclude         string[] values are subsections to be excluded. This is handy if you want
78
-     *                               to remove certain default subsections (note: if you specify BOTH 'include' AND
79
-     *                               'exclude', the inclusions will be applied first, and the exclusions will exclude
80
-     *                               items from that list of inclusions)
81
-     * @type        $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
82
-     *                               } @see EE_Form_Section_Validatable::__construct()
83
-     * @throws \EE_Error
84
-     */
85
-    public function __construct($options_array = array())
86
-    {
87
-        $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
88
-            $this);
89
-        //call parent first, as it may be setting the name
90
-        parent::__construct($options_array);
91
-        //if they've included subsections in the constructor, add them now
92
-        if (isset($options_array['include'])) {
93
-            //we are going to make sure we ONLY have those subsections to include
94
-            //AND we are going to make sure they're in that specified order
95
-            $reordered_subsections = array();
96
-            foreach ($options_array['include'] as $input_name) {
97
-                if (isset($this->_subsections[$input_name])) {
98
-                    $reordered_subsections[$input_name] = $this->_subsections[$input_name];
99
-                }
100
-            }
101
-            $this->_subsections = $reordered_subsections;
102
-        }
103
-        if (isset($options_array['exclude'])) {
104
-            $exclude = $options_array['exclude'];
105
-            $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
106
-        }
107
-        if (isset($options_array['layout_strategy'])) {
108
-            $this->_layout_strategy = $options_array['layout_strategy'];
109
-        }
110
-        if (! $this->_layout_strategy) {
111
-            $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
112
-        }
113
-        $this->_layout_strategy->_construct_finalize($this);
114
-        //ok so we are definitely going to want the forms JS,
115
-        //so enqueue it or remember to enqueue it during wp_enqueue_scripts
116
-        if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
117
-            //ok so they've constructed this object after when they should have.
118
-            //just enqueue the generic form scripts and initialize the form immediately in the JS
119
-            \EE_Form_Section_Proper::wp_enqueue_scripts(true);
120
-        } else {
121
-            add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
122
-            add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
123
-        }
124
-        add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
125
-
126
-        /**
127
-         * Gives other plugins a chance to hook in before construct finalize is called. The form probably doesn't
128
-         * yet have a parent form section. Since 4.9.32, when this action was introduced, this is the best place to
129
-         * add a subsection onto a form, assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
130
-         * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
131
-         * @since 4.9.32
132
-         * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, except maybe calling
133
-         *                                      _construct_finalize has been done
134
-         * @param array $options_array options passed into the constructor
135
-         */
136
-        do_action('AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', $this, $options_array);
137
-
138
-        if (isset($options_array['name'])) {
139
-            $this->_construct_finalize(null, $options_array['name']);
140
-        }
141
-    }
142
-
143
-
144
-
145
-    /**
146
-     * Finishes construction given the parent form section and this form section's name
147
-     *
148
-     * @param EE_Form_Section_Proper $parent_form_section
149
-     * @param string                 $name
150
-     * @throws \EE_Error
151
-     */
152
-    public function _construct_finalize($parent_form_section, $name)
153
-    {
154
-        parent::_construct_finalize($parent_form_section, $name);
155
-        $this->_set_default_name_if_empty();
156
-        $this->_set_default_html_id_if_empty();
157
-        foreach ($this->_subsections as $subsection_name => $subsection) {
158
-            if ($subsection instanceof EE_Form_Section_Base) {
159
-                $subsection->_construct_finalize($this, $subsection_name);
160
-            } else {
161
-                throw new EE_Error(
162
-                    sprintf(
163
-                        __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
164
-                            'event_espresso'),
165
-                        $subsection_name,
166
-                        get_class($this),
167
-                        $subsection ? get_class($subsection) : __('NULL', 'event_espresso')
168
-                    )
169
-                );
170
-            }
171
-        }
172
-        /**
173
-         * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
174
-         * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID (or other attributes derived
175
-         * from the name like the HTML label id, etc), this is where it should be done.
176
-         * This might only happen just before displaying the form, or just before it receives form submission data.
177
-         * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
178
-         * ensured it has a name, HTML IDs, etc
179
-         * @param EE_Form_Section_Proper $this
180
-         * @param EE_Form_Section_Proper|null $parent_form_section
181
-         * @param string $name
182
-         */
183
-        do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name);
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * Gets the layout strategy for this form section
190
-     *
191
-     * @return EE_Form_Section_Layout_Base
192
-     */
193
-    public function get_layout_strategy()
194
-    {
195
-        return $this->_layout_strategy;
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * Gets the HTML for a single input for this form section according
202
-     * to the layout strategy
203
-     *
204
-     * @param EE_Form_Input_Base $input
205
-     * @return string
206
-     */
207
-    public function get_html_for_input($input)
208
-    {
209
-        return $this->_layout_strategy->layout_input($input);
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * was_submitted - checks if form inputs are present in request data
216
-     * Basically an alias for form_data_present_in() (which is used by both
217
-     * proper form sections and form inputs)
218
-     *
219
-     * @param null $form_data
220
-     * @return boolean
221
-     */
222
-    public function was_submitted($form_data = null)
223
-    {
224
-        return $this->form_data_present_in($form_data);
225
-    }
226
-
227
-
228
-
229
-    /**
230
-     * After the form section is initially created, call this to sanitize the data in the submission
231
-     * which relates to this form section, validate it, and set it as properties on the form.
232
-     *
233
-     * @param array|null $req_data should usually be $_POST (the default).
234
-     *                             However, you CAN supply a different array.
235
-     *                             Consider using set_defaults() instead however.
236
-     *                             (If you rendered the form in the page using echo $form_x->get_html()
237
-     *                             the inputs will have the correct name in the request data for this function
238
-     *                             to find them and populate the form with them.
239
-     *                             If you have a flat form (with only input subsections),
240
-     *                             you can supply a flat array where keys
241
-     *                             are the form input names and values are their values)
242
-     * @param boolean    $validate whether or not to perform validation on this data. Default is,
243
-     *                             of course, to validate that data, and set errors on the invalid values.
244
-     *                             But if the data has already been validated
245
-     *                             (eg you validated the data then stored it in the DB)
246
-     *                             you may want to skip this step.
247
-     */
248
-    public function receive_form_submission($req_data = null, $validate = true)
249
-    {
250
-        $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this,
251
-            $validate);
252
-        if ($req_data === null) {
253
-            $req_data = array_merge($_GET, $_POST);
254
-        }
255
-        $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data,
256
-            $this);
257
-        $this->_normalize($req_data);
258
-        if ($validate) {
259
-            $this->_validate();
260
-            //if it's invalid, we're going to want to re-display so remember what they submitted
261
-            if (! $this->is_valid()) {
262
-                $this->store_submitted_form_data_in_session();
263
-            }
264
-        }
265
-        do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate);
266
-    }
267
-
268
-
269
-
270
-    /**
271
-     * caches the originally submitted input values in the session
272
-     * so that they can be used to repopulate the form if it failed validation
273
-     *
274
-     * @return boolean whether or not the data was successfully stored in the session
275
-     */
276
-    protected function store_submitted_form_data_in_session()
277
-    {
278
-        return EE_Registry::instance()->SSN->set_session_data(
279
-            array(
280
-                \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
281
-            )
282
-        );
283
-    }
284
-
285
-
286
-
287
-    /**
288
-     * retrieves the originally submitted input values in the session
289
-     * so that they can be used to repopulate the form if it failed validation
290
-     *
291
-     * @return array
292
-     */
293
-    protected function get_submitted_form_data_from_session()
294
-    {
295
-        $session = EE_Registry::instance()->SSN;
296
-        if ($session instanceof EE_Session) {
297
-            return $session->get_session_data(
298
-                \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
299
-            );
300
-        } else {
301
-            return array();
302
-        }
303
-    }
304
-
305
-
306
-
307
-    /**
308
-     * flushed the originally submitted input values from the session
309
-     *
310
-     * @return boolean whether or not the data was successfully removed from the session
311
-     */
312
-    protected function flush_submitted_form_data_from_session()
313
-    {
314
-        return EE_Registry::instance()->SSN->reset_data(
315
-            array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
316
-        );
317
-    }
318
-
319
-
320
-
321
-    /**
322
-     * Populates this form and its subsections with data from the session.
323
-     * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
324
-     * validation errors when displaying too)
325
-     * Returns true if the form was populated from the session, false otherwise
326
-     *
327
-     * @return boolean
328
-     */
329
-    public function populate_from_session()
330
-    {
331
-        $form_data_in_session = $this->get_submitted_form_data_from_session();
332
-        if (empty($form_data_in_session)) {
333
-            return false;
334
-        }
335
-        $this->receive_form_submission($form_data_in_session);
336
-        $this->flush_submitted_form_data_from_session();
337
-        if ($this->form_data_present_in($form_data_in_session)) {
338
-            return true;
339
-        } else {
340
-            return false;
341
-        }
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     * Populates the default data for the form, given an array where keys are
348
-     * the input names, and values are their values (preferably normalized to be their
349
-     * proper PHP types, not all strings... although that should be ok too).
350
-     * Proper subsections are sub-arrays, the key being the subsection's name, and
351
-     * the value being an array formatted in teh same way
352
-     *
353
-     * @param array $default_data
354
-     */
355
-    public function populate_defaults($default_data)
356
-    {
357
-        foreach ($this->subsections(false) as $subsection_name => $subsection) {
358
-            if (isset($default_data[$subsection_name])) {
359
-                if ($subsection instanceof EE_Form_Input_Base) {
360
-                    $subsection->set_default($default_data[$subsection_name]);
361
-                } elseif ($subsection instanceof EE_Form_Section_Proper) {
362
-                    $subsection->populate_defaults($default_data[$subsection_name]);
363
-                }
364
-            }
365
-        }
366
-    }
367
-
368
-
369
-
370
-    /**
371
-     * returns true if subsection exists
372
-     *
373
-     * @param string $name
374
-     * @return boolean
375
-     */
376
-    public function subsection_exists($name)
377
-    {
378
-        return isset($this->_subsections[$name]) ? true : false;
379
-    }
380
-
381
-
382
-
383
-    /**
384
-     * Gets the subsection specified by its name
385
-     *
386
-     * @param string  $name
387
-     * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
388
-     *                                                      so that the inputs will be properly configured.
389
-     *                                                      However, some client code may be ok
390
-     *                                                      with construction finalize being called later
391
-     *                                                      (realizing that the subsections' html names
392
-     *                                                      might not be set yet, etc.)
393
-     * @return EE_Form_Section_Base
394
-     * @throws \EE_Error
395
-     */
396
-    public function get_subsection($name, $require_construction_to_be_finalized = true)
397
-    {
398
-        if ($require_construction_to_be_finalized) {
399
-            $this->ensure_construct_finalized_called();
400
-        }
401
-        return $this->subsection_exists($name) ? $this->_subsections[$name] : null;
402
-    }
403
-
404
-
405
-
406
-    /**
407
-     * Gets all the validatable subsections of this form section
408
-     *
409
-     * @return EE_Form_Section_Validatable[]
410
-     */
411
-    public function get_validatable_subsections()
412
-    {
413
-        $validatable_subsections = array();
414
-        foreach ($this->subsections() as $name => $obj) {
415
-            if ($obj instanceof EE_Form_Section_Validatable) {
416
-                $validatable_subsections[$name] = $obj;
417
-            }
418
-        }
419
-        return $validatable_subsections;
420
-    }
421
-
422
-
423
-
424
-    /**
425
-     * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
426
-     * throw an EE_Error.
427
-     *
428
-     * @param string  $name
429
-     * @param boolean $require_construction_to_be_finalized most client code should
430
-     *                                                      leave this as TRUE so that the inputs will be properly
431
-     *                                                      configured. However, some client code may be ok with
432
-     *                                                      construction finalize being called later
433
-     *                                                      (realizing that the subsections' html names might not be
434
-     *                                                      set yet, etc.)
435
-     * @return EE_Form_Input_Base
436
-     * @throws EE_Error
437
-     */
438
-    public function get_input($name, $require_construction_to_be_finalized = true)
439
-    {
440
-        $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
441
-        if (! $subsection instanceof EE_Form_Input_Base) {
442
-            throw new EE_Error(
443
-                sprintf(
444
-                    __(
445
-                        "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
446
-                        'event_espresso'
447
-                    ),
448
-                    $name,
449
-                    get_class($this),
450
-                    $subsection ? get_class($subsection) : __("NULL", 'event_espresso')
451
-                )
452
-            );
453
-        }
454
-        return $subsection;
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * Like get_input(), gets the proper subsection of the form given the name,
461
-     * otherwise throws an EE_Error
462
-     *
463
-     * @param string  $name
464
-     * @param boolean $require_construction_to_be_finalized most client code should
465
-     *                                                      leave this as TRUE so that the inputs will be properly
466
-     *                                                      configured. However, some client code may be ok with
467
-     *                                                      construction finalize being called later
468
-     *                                                      (realizing that the subsections' html names might not be
469
-     *                                                      set yet, etc.)
470
-     * @return EE_Form_Section_Proper
471
-     * @throws EE_Error
472
-     */
473
-    public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
474
-    {
475
-        $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
476
-        if (! $subsection instanceof EE_Form_Section_Proper) {
477
-            throw new EE_Error(
478
-                sprintf(
479
-                    __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),
480
-                    $name,
481
-                    get_class($this)
482
-                )
483
-            );
484
-        }
485
-        return $subsection;
486
-    }
487
-
488
-
489
-
490
-    /**
491
-     * Gets the value of the specified input. Should be called after receive_form_submission()
492
-     * or populate_defaults() on the form, where the normalized value on the input is set.
493
-     *
494
-     * @param string $name
495
-     * @return mixed depending on the input's type and its normalization strategy
496
-     * @throws \EE_Error
497
-     */
498
-    public function get_input_value($name)
499
-    {
500
-        $input = $this->get_input($name);
501
-        return $input->normalized_value();
502
-    }
503
-
504
-
505
-
506
-    /**
507
-     * Checks if this form section itself is valid, and then checks its subsections
508
-     *
509
-     * @throws EE_Error
510
-     * @return boolean
511
-     */
512
-    public function is_valid()
513
-    {
514
-        if (! $this->has_received_submission()) {
515
-            throw new EE_Error(
516
-                sprintf(
517
-                    __(
518
-                        "You cannot check if a form is valid before receiving the form submission using receive_form_submission",
519
-                        "event_espresso"
520
-                    )
521
-                )
522
-            );
523
-        }
524
-        if (! parent::is_valid()) {
525
-            return false;
526
-        }
527
-        // ok so no general errors to this entire form section.
528
-        // so let's check the subsections, but only set errors if that hasn't been done yet
529
-        $set_submission_errors = $this->submission_error_message() === '' ? true : false;
530
-        foreach ($this->get_validatable_subsections() as $subsection) {
531
-            if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
532
-                if ($set_submission_errors) {
533
-                    $this->set_submission_error_message($subsection->get_validation_error_string());
534
-                }
535
-                return false;
536
-            }
537
-        }
538
-        return true;
539
-    }
540
-
541
-
542
-
543
-    /**
544
-     * gets teh default name of this form section if none is specified
545
-     *
546
-     * @return string
547
-     */
548
-    protected function _set_default_name_if_empty()
549
-    {
550
-        if (! $this->_name) {
551
-            $classname = get_class($this);
552
-            $default_name = str_replace("EE_", "", $classname);
553
-            $this->_name = $default_name;
554
-        }
555
-    }
556
-
557
-
558
-
559
-    /**
560
-     * Returns the HTML for the form, except for the form opening and closing tags
561
-     * (as the form section doesn't know where you necessarily want to send the information to),
562
-     * and except for a submit button. Enqueus JS and CSS; if called early enough we will
563
-     * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
564
-     * Not doing_it_wrong because theoretically this CAN be used properly,
565
-     * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
566
-     * any CSS.
567
-     *
568
-     * @throws \EE_Error
569
-     */
570
-    public function get_html_and_js()
571
-    {
572
-        $this->enqueue_js();
573
-        return $this->get_html();
574
-    }
575
-
576
-
577
-
578
-    /**
579
-     * returns HTML for displaying this form section. recursively calls display_section() on all subsections
580
-     *
581
-     * @param bool $display_previously_submitted_data
582
-     * @return string
583
-     */
584
-    public function get_html($display_previously_submitted_data = true)
585
-    {
586
-        $this->ensure_construct_finalized_called();
587
-        if ($display_previously_submitted_data) {
588
-            $this->populate_from_session();
589
-        }
590
-        return $this->_form_html_filter
591
-            ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
592
-            : $this->_layout_strategy->layout_form();
593
-    }
594
-
595
-
596
-
597
-    /**
598
-     * enqueues JS and CSS for the form.
599
-     * It is preferred to call this before wp_enqueue_scripts so the
600
-     * scripts and styles can be put in the header, but if called later
601
-     * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
602
-     * only be in the header; but in HTML5 its ok in the body.
603
-     * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
604
-     * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
605
-     *
606
-     * @return string
607
-     * @throws \EE_Error
608
-     */
609
-    public function enqueue_js()
610
-    {
611
-        $this->_enqueue_and_localize_form_js();
612
-        foreach ($this->subsections() as $subsection) {
613
-            $subsection->enqueue_js();
614
-        }
615
-    }
616
-
617
-
618
-
619
-    /**
620
-     * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
621
-     * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
622
-     * the wp_enqueue_scripts hook.
623
-     * However, registering the form js and localizing it can happen when we
624
-     * actually output the form (which is preferred, seeing how teh form's fields
625
-     * could change until it's actually outputted)
626
-     *
627
-     * @param boolean $init_form_validation_automatically whether or not we want the form validation
628
-     *                                                    to be triggered automatically or not
629
-     * @return void
630
-     */
631
-    public static function wp_enqueue_scripts($init_form_validation_automatically = true)
632
-    {
633
-        add_filter('FHEE_load_jquery_validate', '__return_true');
634
-        wp_register_script(
635
-            'ee_form_section_validation',
636
-            EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
637
-            array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
638
-            EVENT_ESPRESSO_VERSION,
639
-            true
640
-        );
641
-        wp_localize_script(
642
-            'ee_form_section_validation',
643
-            'ee_form_section_validation_init',
644
-            array('init' => $init_form_validation_automatically ? '1' : '0')
645
-        );
646
-    }
647
-
648
-
649
-
650
-    /**
651
-     * gets the variables used by form_section_validation.js.
652
-     * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
653
-     * but before the wordpress hook wp_loaded
654
-     *
655
-     * @throws \EE_Error
656
-     */
657
-    public function _enqueue_and_localize_form_js()
658
-    {
659
-        $this->ensure_construct_finalized_called();
660
-        //actually, we don't want to localize just yet. There may be other forms on the page.
661
-        //so we need to add our form section data to a static variable accessible by all form sections
662
-        //and localize it just before the footer
663
-        $this->localize_validation_rules();
664
-        add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
665
-        add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
666
-    }
667
-
668
-
669
-
670
-    /**
671
-     * add our form section data to a static variable accessible by all form sections
672
-     *
673
-     * @param bool $return_for_subsection
674
-     * @return void
675
-     * @throws \EE_Error
676
-     */
677
-    public function localize_validation_rules($return_for_subsection = false)
678
-    {
679
-        // we only want to localize vars ONCE for the entire form,
680
-        // so if the form section doesn't have a parent, then it must be the top dog
681
-        if ($return_for_subsection || ! $this->parent_section()) {
682
-            EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array(
683
-                'form_section_id'  => $this->html_id(true),
684
-                'validation_rules' => $this->get_jquery_validation_rules(),
685
-                'other_data'       => $this->get_other_js_data(),
686
-                'errors'           => $this->subsection_validation_errors_by_html_name(),
687
-            );
688
-            EE_Form_Section_Proper::$_scripts_localized = true;
689
-        }
690
-    }
691
-
692
-
693
-
694
-    /**
695
-     * Gets an array of extra data that will be useful for client-side javascript.
696
-     * This is primarily data added by inputs and forms in addition to any
697
-     * scripts they might enqueue
698
-     *
699
-     * @param array $form_other_js_data
700
-     * @return array
701
-     */
702
-    public function get_other_js_data($form_other_js_data = array())
703
-    {
704
-        foreach ($this->subsections() as $subsection) {
705
-            $form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
706
-        }
707
-        return $form_other_js_data;
708
-    }
709
-
710
-
711
-
712
-    /**
713
-     * Gets a flat array of inputs for this form section and its subsections.
714
-     * Keys are their form names, and values are the inputs themselves
715
-     *
716
-     * @return EE_Form_Input_Base
717
-     */
718
-    public function inputs_in_subsections()
719
-    {
720
-        $inputs = array();
721
-        foreach ($this->subsections() as $subsection) {
722
-            if ($subsection instanceof EE_Form_Input_Base) {
723
-                $inputs[$subsection->html_name()] = $subsection;
724
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
725
-                $inputs += $subsection->inputs_in_subsections();
726
-            }
727
-        }
728
-        return $inputs;
729
-    }
730
-
731
-
732
-
733
-    /**
734
-     * Gets a flat array of all the validation errors.
735
-     * Keys are html names (because those should be unique)
736
-     * and values are a string of all their validation errors
737
-     *
738
-     * @return string[]
739
-     */
740
-    public function subsection_validation_errors_by_html_name()
741
-    {
742
-        $inputs = $this->inputs();
743
-        $errors = array();
744
-        foreach ($inputs as $form_input) {
745
-            if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
746
-                $errors[$form_input->html_name()] = $form_input->get_validation_error_string();
747
-            }
748
-        }
749
-        return $errors;
750
-    }
751
-
752
-
753
-
754
-    /**
755
-     * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
756
-     * Should be setup by each form during the _enqueues_and_localize_form_js
757
-     */
758
-    public static function localize_script_for_all_forms()
759
-    {
760
-        //allow inputs and stuff to hook in their JS and stuff here
761
-        do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
762
-        EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
763
-        $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
764
-            ? EE_Registry::instance()->CFG->registration->email_validation_level
765
-            : 'wp_default';
766
-        EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level;
767
-        wp_enqueue_script('ee_form_section_validation');
768
-        wp_localize_script(
769
-            'ee_form_section_validation',
770
-            'ee_form_section_vars',
771
-            EE_Form_Section_Proper::$_js_localization
772
-        );
773
-    }
774
-
775
-
776
-
777
-    /**
778
-     * ensure_scripts_localized
779
-     */
780
-    public function ensure_scripts_localized()
781
-    {
782
-        if (! EE_Form_Section_Proper::$_scripts_localized) {
783
-            $this->_enqueue_and_localize_form_js();
784
-        }
785
-    }
786
-
787
-
788
-
789
-    /**
790
-     * Gets the hard-coded validation error messages to be used in the JS. The convention
791
-     * is that the key here should be the same as the custom validation rule put in the JS file
792
-     *
793
-     * @return array keys are custom validation rules, and values are internationalized strings
794
-     */
795
-    private static function _get_localized_error_messages()
796
-    {
797
-        return array(
798
-            'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"),
799
-            'regex'    => __('Please check your input', 'event_espresso'),
800
-        );
801
-    }
802
-
803
-
804
-
805
-    /**
806
-     * @return array
807
-     */
808
-    public static function js_localization()
809
-    {
810
-        return self::$_js_localization;
811
-    }
812
-
813
-
814
-
815
-    /**
816
-     * @return array
817
-     */
818
-    public static function reset_js_localization()
819
-    {
820
-        self::$_js_localization = array();
821
-    }
822
-
823
-
824
-
825
-    /**
826
-     * Gets the JS to put inside the jquery validation rules for subsection of this form section.
827
-     * See parent function for more...
828
-     *
829
-     * @return array
830
-     */
831
-    public function get_jquery_validation_rules()
832
-    {
833
-        $jquery_validation_rules = array();
834
-        foreach ($this->get_validatable_subsections() as $subsection) {
835
-            $jquery_validation_rules = array_merge(
836
-                $jquery_validation_rules,
837
-                $subsection->get_jquery_validation_rules()
838
-            );
839
-        }
840
-        return $jquery_validation_rules;
841
-    }
842
-
843
-
844
-
845
-    /**
846
-     * Sanitizes all the data and sets the sanitized value of each field
847
-     *
848
-     * @param array $req_data like $_POST
849
-     * @return void
850
-     */
851
-    protected function _normalize($req_data)
852
-    {
853
-        $this->_received_submission = true;
854
-        $this->_validation_errors = array();
855
-        foreach ($this->get_validatable_subsections() as $subsection) {
856
-            try {
857
-                $subsection->_normalize($req_data);
858
-            } catch (EE_Validation_Error $e) {
859
-                $subsection->add_validation_error($e);
860
-            }
861
-        }
862
-    }
863
-
864
-
865
-
866
-    /**
867
-     * Performs validation on this form section and its subsections.
868
-     * For each subsection,
869
-     * calls _validate_{subsection_name} on THIS form (if the function exists)
870
-     * and passes it the subsection, then calls _validate on that subsection.
871
-     * If you need to perform validation on the form as a whole (considering multiple)
872
-     * you would be best to override this _validate method,
873
-     * calling parent::_validate() first.
874
-     */
875
-    protected function _validate()
876
-    {
877
-        foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
878
-            if (method_exists($this, '_validate_' . $subsection_name)) {
879
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
880
-            }
881
-            $subsection->_validate();
882
-        }
883
-    }
884
-
885
-
886
-
887
-    /**
888
-     * Gets all the validated inputs for the form section
889
-     *
890
-     * @return array
891
-     */
892
-    public function valid_data()
893
-    {
894
-        $inputs = array();
895
-        foreach ($this->subsections() as $subsection_name => $subsection) {
896
-            if ($subsection instanceof EE_Form_Section_Proper) {
897
-                $inputs[$subsection_name] = $subsection->valid_data();
898
-            } else if ($subsection instanceof EE_Form_Input_Base) {
899
-                $inputs[$subsection_name] = $subsection->normalized_value();
900
-            }
901
-        }
902
-        return $inputs;
903
-    }
904
-
905
-
906
-
907
-    /**
908
-     * Gets all the inputs on this form section
909
-     *
910
-     * @return EE_Form_Input_Base[]
911
-     */
912
-    public function inputs()
913
-    {
914
-        $inputs = array();
915
-        foreach ($this->subsections() as $subsection_name => $subsection) {
916
-            if ($subsection instanceof EE_Form_Input_Base) {
917
-                $inputs[$subsection_name] = $subsection;
918
-            }
919
-        }
920
-        return $inputs;
921
-    }
922
-
923
-
924
-
925
-    /**
926
-     * Gets all the subsections which are a proper form
927
-     *
928
-     * @return EE_Form_Section_Proper[]
929
-     */
930
-    public function subforms()
931
-    {
932
-        $form_sections = array();
933
-        foreach ($this->subsections() as $name => $obj) {
934
-            if ($obj instanceof EE_Form_Section_Proper) {
935
-                $form_sections[$name] = $obj;
936
-            }
937
-        }
938
-        return $form_sections;
939
-    }
940
-
941
-
942
-
943
-    /**
944
-     * Gets all the subsections (inputs, proper subsections, or html-only sections).
945
-     * Consider using inputs() or subforms()
946
-     * if you only want form inputs or proper form sections.
947
-     *
948
-     * @param boolean $require_construction_to_be_finalized most client code should
949
-     *                                                      leave this as TRUE so that the inputs will be properly
950
-     *                                                      configured. However, some client code may be ok with
951
-     *                                                      construction finalize being called later
952
-     *                                                      (realizing that the subsections' html names might not be
953
-     *                                                      set yet, etc.)
954
-     * @return EE_Form_Section_Proper[]
955
-     */
956
-    public function subsections($require_construction_to_be_finalized = true)
957
-    {
958
-        if ($require_construction_to_be_finalized) {
959
-            $this->ensure_construct_finalized_called();
960
-        }
961
-        return $this->_subsections;
962
-    }
963
-
964
-
965
-
966
-    /**
967
-     * Returns a simple array where keys are input names, and values are their normalized
968
-     * values. (Similar to calling get_input_value on inputs)
969
-     *
970
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
971
-     *                                        or just this forms' direct children inputs
972
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
973
-     *                                        or allow multidimensional array
974
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
975
-     *                                        with array keys being input names
976
-     *                                        (regardless of whether they are from a subsection or not),
977
-     *                                        and if $flatten is FALSE it can be a multidimensional array
978
-     *                                        where keys are always subsection names and values are either
979
-     *                                        the input's normalized value, or an array like the top-level array
980
-     */
981
-    public function input_values($include_subform_inputs = false, $flatten = false)
982
-    {
983
-        return $this->_input_values(false, $include_subform_inputs, $flatten);
984
-    }
985
-
986
-
987
-
988
-    /**
989
-     * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
990
-     * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
991
-     * is not necessarily the value we want to display to users. This creates an array
992
-     * where keys are the input names, and values are their display values
993
-     *
994
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
995
-     *                                        or just this forms' direct children inputs
996
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
997
-     *                                        or allow multidimensional array
998
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
999
-     *                                        with array keys being input names
1000
-     *                                        (regardless of whether they are from a subsection or not),
1001
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1002
-     *                                        where keys are always subsection names and values are either
1003
-     *                                        the input's normalized value, or an array like the top-level array
1004
-     */
1005
-    public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1006
-    {
1007
-        return $this->_input_values(true, $include_subform_inputs, $flatten);
1008
-    }
1009
-
1010
-
1011
-
1012
-    /**
1013
-     * Gets the input values from the form
1014
-     *
1015
-     * @param boolean $pretty                 Whether to retrieve the pretty value,
1016
-     *                                        or just the normalized value
1017
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1018
-     *                                        or just this forms' direct children inputs
1019
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1020
-     *                                        or allow multidimensional array
1021
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1022
-     *                                        input names (regardless of whether they are from a subsection or not),
1023
-     *                                        and if $flatten is FALSE it can be a multidimensional array
1024
-     *                                        where keys are always subsection names and values are either
1025
-     *                                        the input's normalized value, or an array like the top-level array
1026
-     */
1027
-    public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1028
-    {
1029
-        $input_values = array();
1030
-        foreach ($this->subsections() as $subsection_name => $subsection) {
1031
-            if ($subsection instanceof EE_Form_Input_Base) {
1032
-                $input_values[$subsection_name] = $pretty
1033
-                    ? $subsection->pretty_value()
1034
-                    : $subsection->normalized_value();
1035
-            } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1036
-                $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten);
1037
-                if ($flatten) {
1038
-                    $input_values = array_merge($input_values, $subform_input_values);
1039
-                } else {
1040
-                    $input_values[$subsection_name] = $subform_input_values;
1041
-                }
1042
-            }
1043
-        }
1044
-        return $input_values;
1045
-    }
1046
-
1047
-
1048
-
1049
-    /**
1050
-     * Gets the originally submitted input values from the form
1051
-     *
1052
-     * @param boolean $include_subforms  Whether to include inputs from subforms,
1053
-     *                                   or just this forms' direct children inputs
1054
-     * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1055
-     *                                   with array keys being input names
1056
-     *                                   (regardless of whether they are from a subsection or not),
1057
-     *                                   and if $flatten is FALSE it can be a multidimensional array
1058
-     *                                   where keys are always subsection names and values are either
1059
-     *                                   the input's normalized value, or an array like the top-level array
1060
-     */
1061
-    public function submitted_values($include_subforms = false)
1062
-    {
1063
-        $submitted_values = array();
1064
-        foreach ($this->subsections() as $subsection) {
1065
-            if ($subsection instanceof EE_Form_Input_Base) {
1066
-                // is this input part of an array of inputs?
1067
-                if (strpos($subsection->html_name(), '[') !== false) {
1068
-                    $full_input_name = \EEH_Array::convert_array_values_to_keys(
1069
-                        explode('[', str_replace(']', '', $subsection->html_name())),
1070
-                        $subsection->raw_value()
1071
-                    );
1072
-                    $submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1073
-                } else {
1074
-                    $submitted_values[$subsection->html_name()] = $subsection->raw_value();
1075
-                }
1076
-            } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1077
-                $subform_input_values = $subsection->submitted_values($include_subforms);
1078
-                $submitted_values = array_replace_recursive($submitted_values, $subform_input_values);
1079
-            }
1080
-        }
1081
-        return $submitted_values;
1082
-    }
1083
-
1084
-
1085
-
1086
-    /**
1087
-     * Indicates whether or not this form has received a submission yet
1088
-     * (ie, had receive_form_submission called on it yet)
1089
-     *
1090
-     * @return boolean
1091
-     * @throws \EE_Error
1092
-     */
1093
-    public function has_received_submission()
1094
-    {
1095
-        $this->ensure_construct_finalized_called();
1096
-        return $this->_received_submission;
1097
-    }
1098
-
1099
-
1100
-
1101
-    /**
1102
-     * Equivalent to passing 'exclude' in the constructor's options array.
1103
-     * Removes the listed inputs from the form
1104
-     *
1105
-     * @param array $inputs_to_exclude values are the input names
1106
-     * @return void
1107
-     */
1108
-    public function exclude(array $inputs_to_exclude = array())
1109
-    {
1110
-        foreach ($inputs_to_exclude as $input_to_exclude_name) {
1111
-            unset($this->_subsections[$input_to_exclude_name]);
1112
-        }
1113
-    }
1114
-
1115
-
1116
-
1117
-    /**
1118
-     * @param array $inputs_to_hide
1119
-     * @throws \EE_Error
1120
-     */
1121
-    public function hide(array $inputs_to_hide = array())
1122
-    {
1123
-        foreach ($inputs_to_hide as $input_to_hide) {
1124
-            $input = $this->get_input($input_to_hide);
1125
-            $input->set_display_strategy(new EE_Hidden_Display_Strategy());
1126
-        }
1127
-    }
1128
-
1129
-
1130
-
1131
-    /**
1132
-     * add_subsections
1133
-     * Adds the listed subsections to the form section.
1134
-     * If $subsection_name_to_target is provided,
1135
-     * then new subsections are added before or after that subsection,
1136
-     * otherwise to the start or end of the entire subsections array.
1137
-     *
1138
-     * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1139
-     *                                                          where keys are their names
1140
-     * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1141
-     *                                                          should be added before or after
1142
-     *                                                          IF $subsection_name_to_target is null,
1143
-     *                                                          then $new_subsections will be added to
1144
-     *                                                          the beginning or end of the entire subsections array
1145
-     * @param boolean                $add_before                whether to add $new_subsections, before or after
1146
-     *                                                          $subsection_name_to_target,
1147
-     *                                                          or if $subsection_name_to_target is null,
1148
-     *                                                          before or after entire subsections array
1149
-     * @return void
1150
-     * @throws \EE_Error
1151
-     */
1152
-    public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1153
-    {
1154
-        foreach ($new_subsections as $subsection_name => $subsection) {
1155
-            if (! $subsection instanceof EE_Form_Section_Base) {
1156
-                EE_Error::add_error(
1157
-                    sprintf(
1158
-                        __(
1159
-                            "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1160
-                            "event_espresso"
1161
-                        ),
1162
-                        get_class($subsection),
1163
-                        $subsection_name,
1164
-                        $this->name()
1165
-                    )
1166
-                );
1167
-                unset($new_subsections[$subsection_name]);
1168
-            }
1169
-        }
1170
-        $this->_subsections = EEH_Array::insert_into_array(
1171
-            $this->_subsections,
1172
-            $new_subsections,
1173
-            $subsection_name_to_target,
1174
-            $add_before
1175
-        );
1176
-        if ($this->_construction_finalized) {
1177
-            foreach ($this->_subsections as $name => $subsection) {
1178
-                $subsection->_construct_finalize($this, $name);
1179
-            }
1180
-        }
1181
-    }
1182
-
1183
-
1184
-
1185
-    /**
1186
-     * Just gets all validatable subsections to clean their sensitive data
1187
-     */
1188
-    public function clean_sensitive_data()
1189
-    {
1190
-        foreach ($this->get_validatable_subsections() as $subsection) {
1191
-            $subsection->clean_sensitive_data();
1192
-        }
1193
-    }
1194
-
1195
-
1196
-
1197
-    /**
1198
-     * @param string $form_submission_error_message
1199
-     */
1200
-    public function set_submission_error_message($form_submission_error_message = '')
1201
-    {
1202
-        $this->_form_submission_error_message .= ! empty($form_submission_error_message)
1203
-            ? $form_submission_error_message
1204
-            : __('Form submission failed due to errors', 'event_espresso');
1205
-    }
1206
-
1207
-
1208
-
1209
-    /**
1210
-     * @return string
1211
-     */
1212
-    public function submission_error_message()
1213
-    {
1214
-        return $this->_form_submission_error_message;
1215
-    }
1216
-
1217
-
1218
-
1219
-    /**
1220
-     * @param string $form_submission_success_message
1221
-     */
1222
-    public function set_submission_success_message($form_submission_success_message)
1223
-    {
1224
-        $this->_form_submission_success_message .= ! empty($form_submission_success_message)
1225
-            ? $form_submission_success_message
1226
-            : __('Form submitted successfully', 'event_espresso');
1227
-    }
1228
-
1229
-
1230
-
1231
-    /**
1232
-     * @return string
1233
-     */
1234
-    public function submission_success_message()
1235
-    {
1236
-        return $this->_form_submission_success_message;
1237
-    }
1238
-
1239
-
1240
-
1241
-    /**
1242
-     * Returns the prefix that should be used on child of this form section for
1243
-     * their html names. If this form section itself has a parent, prepends ITS
1244
-     * prefix onto this form section's prefix. Used primarily by
1245
-     * EE_Form_Input_Base::_set_default_html_name_if_empty
1246
-     *
1247
-     * @return string
1248
-     * @throws \EE_Error
1249
-     */
1250
-    public function html_name_prefix()
1251
-    {
1252
-        if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1253
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1254
-        } else {
1255
-            return $this->name();
1256
-        }
1257
-    }
1258
-
1259
-
1260
-
1261
-    /**
1262
-     * Gets the name, but first checks _construct_finalize has been called. If not,
1263
-     * calls it (assumes there is no parent and that we want the name to be whatever
1264
-     * was set, which is probably nothing, or the classname)
1265
-     *
1266
-     * @return string
1267
-     * @throws \EE_Error
1268
-     */
1269
-    public function name()
1270
-    {
1271
-        $this->ensure_construct_finalized_called();
1272
-        return parent::name();
1273
-    }
1274
-
1275
-
1276
-
1277
-    /**
1278
-     * @return EE_Form_Section_Proper
1279
-     * @throws \EE_Error
1280
-     */
1281
-    public function parent_section()
1282
-    {
1283
-        $this->ensure_construct_finalized_called();
1284
-        return parent::parent_section();
1285
-    }
1286
-
1287
-
1288
-
1289
-    /**
1290
-     * make sure construction finalized was called, otherwise children might not be ready
1291
-     *
1292
-     * @return void
1293
-     * @throws \EE_Error
1294
-     */
1295
-    public function ensure_construct_finalized_called()
1296
-    {
1297
-        if (! $this->_construction_finalized) {
1298
-            $this->_construct_finalize($this->_parent_section, $this->_name);
1299
-        }
1300
-    }
1301
-
1302
-
1303
-
1304
-    /**
1305
-     * Checks if any of this form section's inputs, or any of its children's inputs,
1306
-     * are in teh form data. If any are found, returns true. Else false
1307
-     *
1308
-     * @param array $req_data
1309
-     * @return boolean
1310
-     */
1311
-    public function form_data_present_in($req_data = null)
1312
-    {
1313
-        if ($req_data === null) {
1314
-            $req_data = $_POST;
1315
-        }
1316
-        foreach ($this->subsections() as $subsection) {
1317
-            if ($subsection instanceof EE_Form_Input_Base) {
1318
-                if ($subsection->form_data_present_in($req_data)) {
1319
-                    return true;
1320
-                }
1321
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
1322
-                if ($subsection->form_data_present_in($req_data)) {
1323
-                    return true;
1324
-                }
1325
-            }
1326
-        }
1327
-        return false;
1328
-    }
1329
-
1330
-
1331
-
1332
-    /**
1333
-     * Gets validation errors for this form section and subsections
1334
-     * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1335
-     * gets the validation errors for ALL subsection
1336
-     *
1337
-     * @return EE_Validation_Error[]
1338
-     */
1339
-    public function get_validation_errors_accumulated()
1340
-    {
1341
-        $validation_errors = $this->get_validation_errors();
1342
-        foreach ($this->get_validatable_subsections() as $subsection) {
1343
-            if ($subsection instanceof EE_Form_Section_Proper) {
1344
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1345
-            } else {
1346
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors();
1347
-            }
1348
-            if ($validation_errors_on_this_subsection) {
1349
-                $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1350
-            }
1351
-        }
1352
-        return $validation_errors;
1353
-    }
1354
-
1355
-
1356
-
1357
-    /**
1358
-     * This isn't just the name of an input, it's a path pointing to an input. The
1359
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
1360
-     * dot-dot-slash (../) means to ascend into the parent section.
1361
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1362
-     * which will be returned.
1363
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1364
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1365
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1366
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1367
-     * Etc
1368
-     *
1369
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1370
-     * @return EE_Form_Section_Base
1371
-     */
1372
-    public function find_section_from_path($form_section_path)
1373
-    {
1374
-        //check if we can find the input from purely going straight up the tree
1375
-        $input = parent::find_section_from_path($form_section_path);
1376
-        if ($input instanceof EE_Form_Section_Base) {
1377
-            return $input;
1378
-        }
1379
-        $next_slash_pos = strpos($form_section_path, '/');
1380
-        if ($next_slash_pos !== false) {
1381
-            $child_section_name = substr($form_section_path, 0, $next_slash_pos);
1382
-            $subpath = substr($form_section_path, $next_slash_pos + 1);
1383
-        } else {
1384
-            $child_section_name = $form_section_path;
1385
-            $subpath = '';
1386
-        }
1387
-        $child_section = $this->get_subsection($child_section_name);
1388
-        if ($child_section instanceof EE_Form_Section_Base) {
1389
-            return $child_section->find_section_from_path($subpath);
1390
-        } else {
1391
-            return null;
1392
-        }
1393
-    }
14
+	const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
15
+
16
+	/**
17
+	 * Subsections
18
+	 *
19
+	 * @var EE_Form_Section_Validatable[]
20
+	 */
21
+	protected $_subsections = array();
22
+
23
+	/**
24
+	 * Strategy for laying out the form
25
+	 *
26
+	 * @var EE_Form_Section_Layout_Base
27
+	 */
28
+	protected $_layout_strategy;
29
+
30
+	/**
31
+	 * Whether or not this form has received and validated a form submission yet
32
+	 *
33
+	 * @var boolean
34
+	 */
35
+	protected $_received_submission = false;
36
+
37
+	/**
38
+	 * message displayed to users upon successful form submission
39
+	 *
40
+	 * @var string
41
+	 */
42
+	protected $_form_submission_success_message = '';
43
+
44
+	/**
45
+	 * message displayed to users upon unsuccessful form submission
46
+	 *
47
+	 * @var string
48
+	 */
49
+	protected $_form_submission_error_message = '';
50
+
51
+	/**
52
+	 * Stores all the data that will localized for form validation
53
+	 *
54
+	 * @var array
55
+	 */
56
+	static protected $_js_localization = array();
57
+
58
+	/**
59
+	 * whether or not the form's localized validation JS vars have been set
60
+	 *
61
+	 * @type boolean
62
+	 */
63
+	static protected $_scripts_localized = false;
64
+
65
+
66
+
67
+	/**
68
+	 * when constructing a proper form section, calls _construct_finalize on children
69
+	 * so that they know who their parent is, and what name they've been given.
70
+	 *
71
+	 * @param array $options_array   {
72
+	 * @type        $subsections     EE_Form_Section_Validatable[] where keys are the section's name
73
+	 * @type        $include         string[] numerically-indexed where values are section names to be included,
74
+	 *                               and in that order. This is handy if you want
75
+	 *                               the subsections to be ordered differently than the default, and if you override
76
+	 *                               which fields are shown
77
+	 * @type        $exclude         string[] values are subsections to be excluded. This is handy if you want
78
+	 *                               to remove certain default subsections (note: if you specify BOTH 'include' AND
79
+	 *                               'exclude', the inclusions will be applied first, and the exclusions will exclude
80
+	 *                               items from that list of inclusions)
81
+	 * @type        $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
82
+	 *                               } @see EE_Form_Section_Validatable::__construct()
83
+	 * @throws \EE_Error
84
+	 */
85
+	public function __construct($options_array = array())
86
+	{
87
+		$options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
88
+			$this);
89
+		//call parent first, as it may be setting the name
90
+		parent::__construct($options_array);
91
+		//if they've included subsections in the constructor, add them now
92
+		if (isset($options_array['include'])) {
93
+			//we are going to make sure we ONLY have those subsections to include
94
+			//AND we are going to make sure they're in that specified order
95
+			$reordered_subsections = array();
96
+			foreach ($options_array['include'] as $input_name) {
97
+				if (isset($this->_subsections[$input_name])) {
98
+					$reordered_subsections[$input_name] = $this->_subsections[$input_name];
99
+				}
100
+			}
101
+			$this->_subsections = $reordered_subsections;
102
+		}
103
+		if (isset($options_array['exclude'])) {
104
+			$exclude = $options_array['exclude'];
105
+			$this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
106
+		}
107
+		if (isset($options_array['layout_strategy'])) {
108
+			$this->_layout_strategy = $options_array['layout_strategy'];
109
+		}
110
+		if (! $this->_layout_strategy) {
111
+			$this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
112
+		}
113
+		$this->_layout_strategy->_construct_finalize($this);
114
+		//ok so we are definitely going to want the forms JS,
115
+		//so enqueue it or remember to enqueue it during wp_enqueue_scripts
116
+		if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) {
117
+			//ok so they've constructed this object after when they should have.
118
+			//just enqueue the generic form scripts and initialize the form immediately in the JS
119
+			\EE_Form_Section_Proper::wp_enqueue_scripts(true);
120
+		} else {
121
+			add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
122
+			add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
123
+		}
124
+		add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
125
+
126
+		/**
127
+		 * Gives other plugins a chance to hook in before construct finalize is called. The form probably doesn't
128
+		 * yet have a parent form section. Since 4.9.32, when this action was introduced, this is the best place to
129
+		 * add a subsection onto a form, assuming you don't care what the form section's name, HTML ID, or HTML name etc are.
130
+		 * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end
131
+		 * @since 4.9.32
132
+		 * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, except maybe calling
133
+		 *                                      _construct_finalize has been done
134
+		 * @param array $options_array options passed into the constructor
135
+		 */
136
+		do_action('AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', $this, $options_array);
137
+
138
+		if (isset($options_array['name'])) {
139
+			$this->_construct_finalize(null, $options_array['name']);
140
+		}
141
+	}
142
+
143
+
144
+
145
+	/**
146
+	 * Finishes construction given the parent form section and this form section's name
147
+	 *
148
+	 * @param EE_Form_Section_Proper $parent_form_section
149
+	 * @param string                 $name
150
+	 * @throws \EE_Error
151
+	 */
152
+	public function _construct_finalize($parent_form_section, $name)
153
+	{
154
+		parent::_construct_finalize($parent_form_section, $name);
155
+		$this->_set_default_name_if_empty();
156
+		$this->_set_default_html_id_if_empty();
157
+		foreach ($this->_subsections as $subsection_name => $subsection) {
158
+			if ($subsection instanceof EE_Form_Section_Base) {
159
+				$subsection->_construct_finalize($this, $subsection_name);
160
+			} else {
161
+				throw new EE_Error(
162
+					sprintf(
163
+						__('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
164
+							'event_espresso'),
165
+						$subsection_name,
166
+						get_class($this),
167
+						$subsection ? get_class($subsection) : __('NULL', 'event_espresso')
168
+					)
169
+				);
170
+			}
171
+		}
172
+		/**
173
+		 * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed.
174
+		 * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID (or other attributes derived
175
+		 * from the name like the HTML label id, etc), this is where it should be done.
176
+		 * This might only happen just before displaying the form, or just before it receives form submission data.
177
+		 * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've
178
+		 * ensured it has a name, HTML IDs, etc
179
+		 * @param EE_Form_Section_Proper $this
180
+		 * @param EE_Form_Section_Proper|null $parent_form_section
181
+		 * @param string $name
182
+		 */
183
+		do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name);
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * Gets the layout strategy for this form section
190
+	 *
191
+	 * @return EE_Form_Section_Layout_Base
192
+	 */
193
+	public function get_layout_strategy()
194
+	{
195
+		return $this->_layout_strategy;
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * Gets the HTML for a single input for this form section according
202
+	 * to the layout strategy
203
+	 *
204
+	 * @param EE_Form_Input_Base $input
205
+	 * @return string
206
+	 */
207
+	public function get_html_for_input($input)
208
+	{
209
+		return $this->_layout_strategy->layout_input($input);
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * was_submitted - checks if form inputs are present in request data
216
+	 * Basically an alias for form_data_present_in() (which is used by both
217
+	 * proper form sections and form inputs)
218
+	 *
219
+	 * @param null $form_data
220
+	 * @return boolean
221
+	 */
222
+	public function was_submitted($form_data = null)
223
+	{
224
+		return $this->form_data_present_in($form_data);
225
+	}
226
+
227
+
228
+
229
+	/**
230
+	 * After the form section is initially created, call this to sanitize the data in the submission
231
+	 * which relates to this form section, validate it, and set it as properties on the form.
232
+	 *
233
+	 * @param array|null $req_data should usually be $_POST (the default).
234
+	 *                             However, you CAN supply a different array.
235
+	 *                             Consider using set_defaults() instead however.
236
+	 *                             (If you rendered the form in the page using echo $form_x->get_html()
237
+	 *                             the inputs will have the correct name in the request data for this function
238
+	 *                             to find them and populate the form with them.
239
+	 *                             If you have a flat form (with only input subsections),
240
+	 *                             you can supply a flat array where keys
241
+	 *                             are the form input names and values are their values)
242
+	 * @param boolean    $validate whether or not to perform validation on this data. Default is,
243
+	 *                             of course, to validate that data, and set errors on the invalid values.
244
+	 *                             But if the data has already been validated
245
+	 *                             (eg you validated the data then stored it in the DB)
246
+	 *                             you may want to skip this step.
247
+	 */
248
+	public function receive_form_submission($req_data = null, $validate = true)
249
+	{
250
+		$req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this,
251
+			$validate);
252
+		if ($req_data === null) {
253
+			$req_data = array_merge($_GET, $_POST);
254
+		}
255
+		$req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data,
256
+			$this);
257
+		$this->_normalize($req_data);
258
+		if ($validate) {
259
+			$this->_validate();
260
+			//if it's invalid, we're going to want to re-display so remember what they submitted
261
+			if (! $this->is_valid()) {
262
+				$this->store_submitted_form_data_in_session();
263
+			}
264
+		}
265
+		do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate);
266
+	}
267
+
268
+
269
+
270
+	/**
271
+	 * caches the originally submitted input values in the session
272
+	 * so that they can be used to repopulate the form if it failed validation
273
+	 *
274
+	 * @return boolean whether or not the data was successfully stored in the session
275
+	 */
276
+	protected function store_submitted_form_data_in_session()
277
+	{
278
+		return EE_Registry::instance()->SSN->set_session_data(
279
+			array(
280
+				\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
281
+			)
282
+		);
283
+	}
284
+
285
+
286
+
287
+	/**
288
+	 * retrieves the originally submitted input values in the session
289
+	 * so that they can be used to repopulate the form if it failed validation
290
+	 *
291
+	 * @return array
292
+	 */
293
+	protected function get_submitted_form_data_from_session()
294
+	{
295
+		$session = EE_Registry::instance()->SSN;
296
+		if ($session instanceof EE_Session) {
297
+			return $session->get_session_data(
298
+				\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
299
+			);
300
+		} else {
301
+			return array();
302
+		}
303
+	}
304
+
305
+
306
+
307
+	/**
308
+	 * flushed the originally submitted input values from the session
309
+	 *
310
+	 * @return boolean whether or not the data was successfully removed from the session
311
+	 */
312
+	protected function flush_submitted_form_data_from_session()
313
+	{
314
+		return EE_Registry::instance()->SSN->reset_data(
315
+			array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
316
+		);
317
+	}
318
+
319
+
320
+
321
+	/**
322
+	 * Populates this form and its subsections with data from the session.
323
+	 * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
324
+	 * validation errors when displaying too)
325
+	 * Returns true if the form was populated from the session, false otherwise
326
+	 *
327
+	 * @return boolean
328
+	 */
329
+	public function populate_from_session()
330
+	{
331
+		$form_data_in_session = $this->get_submitted_form_data_from_session();
332
+		if (empty($form_data_in_session)) {
333
+			return false;
334
+		}
335
+		$this->receive_form_submission($form_data_in_session);
336
+		$this->flush_submitted_form_data_from_session();
337
+		if ($this->form_data_present_in($form_data_in_session)) {
338
+			return true;
339
+		} else {
340
+			return false;
341
+		}
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 * Populates the default data for the form, given an array where keys are
348
+	 * the input names, and values are their values (preferably normalized to be their
349
+	 * proper PHP types, not all strings... although that should be ok too).
350
+	 * Proper subsections are sub-arrays, the key being the subsection's name, and
351
+	 * the value being an array formatted in teh same way
352
+	 *
353
+	 * @param array $default_data
354
+	 */
355
+	public function populate_defaults($default_data)
356
+	{
357
+		foreach ($this->subsections(false) as $subsection_name => $subsection) {
358
+			if (isset($default_data[$subsection_name])) {
359
+				if ($subsection instanceof EE_Form_Input_Base) {
360
+					$subsection->set_default($default_data[$subsection_name]);
361
+				} elseif ($subsection instanceof EE_Form_Section_Proper) {
362
+					$subsection->populate_defaults($default_data[$subsection_name]);
363
+				}
364
+			}
365
+		}
366
+	}
367
+
368
+
369
+
370
+	/**
371
+	 * returns true if subsection exists
372
+	 *
373
+	 * @param string $name
374
+	 * @return boolean
375
+	 */
376
+	public function subsection_exists($name)
377
+	{
378
+		return isset($this->_subsections[$name]) ? true : false;
379
+	}
380
+
381
+
382
+
383
+	/**
384
+	 * Gets the subsection specified by its name
385
+	 *
386
+	 * @param string  $name
387
+	 * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
388
+	 *                                                      so that the inputs will be properly configured.
389
+	 *                                                      However, some client code may be ok
390
+	 *                                                      with construction finalize being called later
391
+	 *                                                      (realizing that the subsections' html names
392
+	 *                                                      might not be set yet, etc.)
393
+	 * @return EE_Form_Section_Base
394
+	 * @throws \EE_Error
395
+	 */
396
+	public function get_subsection($name, $require_construction_to_be_finalized = true)
397
+	{
398
+		if ($require_construction_to_be_finalized) {
399
+			$this->ensure_construct_finalized_called();
400
+		}
401
+		return $this->subsection_exists($name) ? $this->_subsections[$name] : null;
402
+	}
403
+
404
+
405
+
406
+	/**
407
+	 * Gets all the validatable subsections of this form section
408
+	 *
409
+	 * @return EE_Form_Section_Validatable[]
410
+	 */
411
+	public function get_validatable_subsections()
412
+	{
413
+		$validatable_subsections = array();
414
+		foreach ($this->subsections() as $name => $obj) {
415
+			if ($obj instanceof EE_Form_Section_Validatable) {
416
+				$validatable_subsections[$name] = $obj;
417
+			}
418
+		}
419
+		return $validatable_subsections;
420
+	}
421
+
422
+
423
+
424
+	/**
425
+	 * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
426
+	 * throw an EE_Error.
427
+	 *
428
+	 * @param string  $name
429
+	 * @param boolean $require_construction_to_be_finalized most client code should
430
+	 *                                                      leave this as TRUE so that the inputs will be properly
431
+	 *                                                      configured. However, some client code may be ok with
432
+	 *                                                      construction finalize being called later
433
+	 *                                                      (realizing that the subsections' html names might not be
434
+	 *                                                      set yet, etc.)
435
+	 * @return EE_Form_Input_Base
436
+	 * @throws EE_Error
437
+	 */
438
+	public function get_input($name, $require_construction_to_be_finalized = true)
439
+	{
440
+		$subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
441
+		if (! $subsection instanceof EE_Form_Input_Base) {
442
+			throw new EE_Error(
443
+				sprintf(
444
+					__(
445
+						"Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
446
+						'event_espresso'
447
+					),
448
+					$name,
449
+					get_class($this),
450
+					$subsection ? get_class($subsection) : __("NULL", 'event_espresso')
451
+				)
452
+			);
453
+		}
454
+		return $subsection;
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * Like get_input(), gets the proper subsection of the form given the name,
461
+	 * otherwise throws an EE_Error
462
+	 *
463
+	 * @param string  $name
464
+	 * @param boolean $require_construction_to_be_finalized most client code should
465
+	 *                                                      leave this as TRUE so that the inputs will be properly
466
+	 *                                                      configured. However, some client code may be ok with
467
+	 *                                                      construction finalize being called later
468
+	 *                                                      (realizing that the subsections' html names might not be
469
+	 *                                                      set yet, etc.)
470
+	 * @return EE_Form_Section_Proper
471
+	 * @throws EE_Error
472
+	 */
473
+	public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
474
+	{
475
+		$subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
476
+		if (! $subsection instanceof EE_Form_Section_Proper) {
477
+			throw new EE_Error(
478
+				sprintf(
479
+					__("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),
480
+					$name,
481
+					get_class($this)
482
+				)
483
+			);
484
+		}
485
+		return $subsection;
486
+	}
487
+
488
+
489
+
490
+	/**
491
+	 * Gets the value of the specified input. Should be called after receive_form_submission()
492
+	 * or populate_defaults() on the form, where the normalized value on the input is set.
493
+	 *
494
+	 * @param string $name
495
+	 * @return mixed depending on the input's type and its normalization strategy
496
+	 * @throws \EE_Error
497
+	 */
498
+	public function get_input_value($name)
499
+	{
500
+		$input = $this->get_input($name);
501
+		return $input->normalized_value();
502
+	}
503
+
504
+
505
+
506
+	/**
507
+	 * Checks if this form section itself is valid, and then checks its subsections
508
+	 *
509
+	 * @throws EE_Error
510
+	 * @return boolean
511
+	 */
512
+	public function is_valid()
513
+	{
514
+		if (! $this->has_received_submission()) {
515
+			throw new EE_Error(
516
+				sprintf(
517
+					__(
518
+						"You cannot check if a form is valid before receiving the form submission using receive_form_submission",
519
+						"event_espresso"
520
+					)
521
+				)
522
+			);
523
+		}
524
+		if (! parent::is_valid()) {
525
+			return false;
526
+		}
527
+		// ok so no general errors to this entire form section.
528
+		// so let's check the subsections, but only set errors if that hasn't been done yet
529
+		$set_submission_errors = $this->submission_error_message() === '' ? true : false;
530
+		foreach ($this->get_validatable_subsections() as $subsection) {
531
+			if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
532
+				if ($set_submission_errors) {
533
+					$this->set_submission_error_message($subsection->get_validation_error_string());
534
+				}
535
+				return false;
536
+			}
537
+		}
538
+		return true;
539
+	}
540
+
541
+
542
+
543
+	/**
544
+	 * gets teh default name of this form section if none is specified
545
+	 *
546
+	 * @return string
547
+	 */
548
+	protected function _set_default_name_if_empty()
549
+	{
550
+		if (! $this->_name) {
551
+			$classname = get_class($this);
552
+			$default_name = str_replace("EE_", "", $classname);
553
+			$this->_name = $default_name;
554
+		}
555
+	}
556
+
557
+
558
+
559
+	/**
560
+	 * Returns the HTML for the form, except for the form opening and closing tags
561
+	 * (as the form section doesn't know where you necessarily want to send the information to),
562
+	 * and except for a submit button. Enqueus JS and CSS; if called early enough we will
563
+	 * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
564
+	 * Not doing_it_wrong because theoretically this CAN be used properly,
565
+	 * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
566
+	 * any CSS.
567
+	 *
568
+	 * @throws \EE_Error
569
+	 */
570
+	public function get_html_and_js()
571
+	{
572
+		$this->enqueue_js();
573
+		return $this->get_html();
574
+	}
575
+
576
+
577
+
578
+	/**
579
+	 * returns HTML for displaying this form section. recursively calls display_section() on all subsections
580
+	 *
581
+	 * @param bool $display_previously_submitted_data
582
+	 * @return string
583
+	 */
584
+	public function get_html($display_previously_submitted_data = true)
585
+	{
586
+		$this->ensure_construct_finalized_called();
587
+		if ($display_previously_submitted_data) {
588
+			$this->populate_from_session();
589
+		}
590
+		return $this->_form_html_filter
591
+			? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this)
592
+			: $this->_layout_strategy->layout_form();
593
+	}
594
+
595
+
596
+
597
+	/**
598
+	 * enqueues JS and CSS for the form.
599
+	 * It is preferred to call this before wp_enqueue_scripts so the
600
+	 * scripts and styles can be put in the header, but if called later
601
+	 * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
602
+	 * only be in the header; but in HTML5 its ok in the body.
603
+	 * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
604
+	 * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
605
+	 *
606
+	 * @return string
607
+	 * @throws \EE_Error
608
+	 */
609
+	public function enqueue_js()
610
+	{
611
+		$this->_enqueue_and_localize_form_js();
612
+		foreach ($this->subsections() as $subsection) {
613
+			$subsection->enqueue_js();
614
+		}
615
+	}
616
+
617
+
618
+
619
+	/**
620
+	 * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
621
+	 * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
622
+	 * the wp_enqueue_scripts hook.
623
+	 * However, registering the form js and localizing it can happen when we
624
+	 * actually output the form (which is preferred, seeing how teh form's fields
625
+	 * could change until it's actually outputted)
626
+	 *
627
+	 * @param boolean $init_form_validation_automatically whether or not we want the form validation
628
+	 *                                                    to be triggered automatically or not
629
+	 * @return void
630
+	 */
631
+	public static function wp_enqueue_scripts($init_form_validation_automatically = true)
632
+	{
633
+		add_filter('FHEE_load_jquery_validate', '__return_true');
634
+		wp_register_script(
635
+			'ee_form_section_validation',
636
+			EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
637
+			array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
638
+			EVENT_ESPRESSO_VERSION,
639
+			true
640
+		);
641
+		wp_localize_script(
642
+			'ee_form_section_validation',
643
+			'ee_form_section_validation_init',
644
+			array('init' => $init_form_validation_automatically ? '1' : '0')
645
+		);
646
+	}
647
+
648
+
649
+
650
+	/**
651
+	 * gets the variables used by form_section_validation.js.
652
+	 * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
653
+	 * but before the wordpress hook wp_loaded
654
+	 *
655
+	 * @throws \EE_Error
656
+	 */
657
+	public function _enqueue_and_localize_form_js()
658
+	{
659
+		$this->ensure_construct_finalized_called();
660
+		//actually, we don't want to localize just yet. There may be other forms on the page.
661
+		//so we need to add our form section data to a static variable accessible by all form sections
662
+		//and localize it just before the footer
663
+		$this->localize_validation_rules();
664
+		add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
665
+		add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
666
+	}
667
+
668
+
669
+
670
+	/**
671
+	 * add our form section data to a static variable accessible by all form sections
672
+	 *
673
+	 * @param bool $return_for_subsection
674
+	 * @return void
675
+	 * @throws \EE_Error
676
+	 */
677
+	public function localize_validation_rules($return_for_subsection = false)
678
+	{
679
+		// we only want to localize vars ONCE for the entire form,
680
+		// so if the form section doesn't have a parent, then it must be the top dog
681
+		if ($return_for_subsection || ! $this->parent_section()) {
682
+			EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array(
683
+				'form_section_id'  => $this->html_id(true),
684
+				'validation_rules' => $this->get_jquery_validation_rules(),
685
+				'other_data'       => $this->get_other_js_data(),
686
+				'errors'           => $this->subsection_validation_errors_by_html_name(),
687
+			);
688
+			EE_Form_Section_Proper::$_scripts_localized = true;
689
+		}
690
+	}
691
+
692
+
693
+
694
+	/**
695
+	 * Gets an array of extra data that will be useful for client-side javascript.
696
+	 * This is primarily data added by inputs and forms in addition to any
697
+	 * scripts they might enqueue
698
+	 *
699
+	 * @param array $form_other_js_data
700
+	 * @return array
701
+	 */
702
+	public function get_other_js_data($form_other_js_data = array())
703
+	{
704
+		foreach ($this->subsections() as $subsection) {
705
+			$form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
706
+		}
707
+		return $form_other_js_data;
708
+	}
709
+
710
+
711
+
712
+	/**
713
+	 * Gets a flat array of inputs for this form section and its subsections.
714
+	 * Keys are their form names, and values are the inputs themselves
715
+	 *
716
+	 * @return EE_Form_Input_Base
717
+	 */
718
+	public function inputs_in_subsections()
719
+	{
720
+		$inputs = array();
721
+		foreach ($this->subsections() as $subsection) {
722
+			if ($subsection instanceof EE_Form_Input_Base) {
723
+				$inputs[$subsection->html_name()] = $subsection;
724
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
725
+				$inputs += $subsection->inputs_in_subsections();
726
+			}
727
+		}
728
+		return $inputs;
729
+	}
730
+
731
+
732
+
733
+	/**
734
+	 * Gets a flat array of all the validation errors.
735
+	 * Keys are html names (because those should be unique)
736
+	 * and values are a string of all their validation errors
737
+	 *
738
+	 * @return string[]
739
+	 */
740
+	public function subsection_validation_errors_by_html_name()
741
+	{
742
+		$inputs = $this->inputs();
743
+		$errors = array();
744
+		foreach ($inputs as $form_input) {
745
+			if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
746
+				$errors[$form_input->html_name()] = $form_input->get_validation_error_string();
747
+			}
748
+		}
749
+		return $errors;
750
+	}
751
+
752
+
753
+
754
+	/**
755
+	 * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
756
+	 * Should be setup by each form during the _enqueues_and_localize_form_js
757
+	 */
758
+	public static function localize_script_for_all_forms()
759
+	{
760
+		//allow inputs and stuff to hook in their JS and stuff here
761
+		do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
762
+		EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
763
+		$email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
764
+			? EE_Registry::instance()->CFG->registration->email_validation_level
765
+			: 'wp_default';
766
+		EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level;
767
+		wp_enqueue_script('ee_form_section_validation');
768
+		wp_localize_script(
769
+			'ee_form_section_validation',
770
+			'ee_form_section_vars',
771
+			EE_Form_Section_Proper::$_js_localization
772
+		);
773
+	}
774
+
775
+
776
+
777
+	/**
778
+	 * ensure_scripts_localized
779
+	 */
780
+	public function ensure_scripts_localized()
781
+	{
782
+		if (! EE_Form_Section_Proper::$_scripts_localized) {
783
+			$this->_enqueue_and_localize_form_js();
784
+		}
785
+	}
786
+
787
+
788
+
789
+	/**
790
+	 * Gets the hard-coded validation error messages to be used in the JS. The convention
791
+	 * is that the key here should be the same as the custom validation rule put in the JS file
792
+	 *
793
+	 * @return array keys are custom validation rules, and values are internationalized strings
794
+	 */
795
+	private static function _get_localized_error_messages()
796
+	{
797
+		return array(
798
+			'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"),
799
+			'regex'    => __('Please check your input', 'event_espresso'),
800
+		);
801
+	}
802
+
803
+
804
+
805
+	/**
806
+	 * @return array
807
+	 */
808
+	public static function js_localization()
809
+	{
810
+		return self::$_js_localization;
811
+	}
812
+
813
+
814
+
815
+	/**
816
+	 * @return array
817
+	 */
818
+	public static function reset_js_localization()
819
+	{
820
+		self::$_js_localization = array();
821
+	}
822
+
823
+
824
+
825
+	/**
826
+	 * Gets the JS to put inside the jquery validation rules for subsection of this form section.
827
+	 * See parent function for more...
828
+	 *
829
+	 * @return array
830
+	 */
831
+	public function get_jquery_validation_rules()
832
+	{
833
+		$jquery_validation_rules = array();
834
+		foreach ($this->get_validatable_subsections() as $subsection) {
835
+			$jquery_validation_rules = array_merge(
836
+				$jquery_validation_rules,
837
+				$subsection->get_jquery_validation_rules()
838
+			);
839
+		}
840
+		return $jquery_validation_rules;
841
+	}
842
+
843
+
844
+
845
+	/**
846
+	 * Sanitizes all the data and sets the sanitized value of each field
847
+	 *
848
+	 * @param array $req_data like $_POST
849
+	 * @return void
850
+	 */
851
+	protected function _normalize($req_data)
852
+	{
853
+		$this->_received_submission = true;
854
+		$this->_validation_errors = array();
855
+		foreach ($this->get_validatable_subsections() as $subsection) {
856
+			try {
857
+				$subsection->_normalize($req_data);
858
+			} catch (EE_Validation_Error $e) {
859
+				$subsection->add_validation_error($e);
860
+			}
861
+		}
862
+	}
863
+
864
+
865
+
866
+	/**
867
+	 * Performs validation on this form section and its subsections.
868
+	 * For each subsection,
869
+	 * calls _validate_{subsection_name} on THIS form (if the function exists)
870
+	 * and passes it the subsection, then calls _validate on that subsection.
871
+	 * If you need to perform validation on the form as a whole (considering multiple)
872
+	 * you would be best to override this _validate method,
873
+	 * calling parent::_validate() first.
874
+	 */
875
+	protected function _validate()
876
+	{
877
+		foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
878
+			if (method_exists($this, '_validate_' . $subsection_name)) {
879
+				call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
880
+			}
881
+			$subsection->_validate();
882
+		}
883
+	}
884
+
885
+
886
+
887
+	/**
888
+	 * Gets all the validated inputs for the form section
889
+	 *
890
+	 * @return array
891
+	 */
892
+	public function valid_data()
893
+	{
894
+		$inputs = array();
895
+		foreach ($this->subsections() as $subsection_name => $subsection) {
896
+			if ($subsection instanceof EE_Form_Section_Proper) {
897
+				$inputs[$subsection_name] = $subsection->valid_data();
898
+			} else if ($subsection instanceof EE_Form_Input_Base) {
899
+				$inputs[$subsection_name] = $subsection->normalized_value();
900
+			}
901
+		}
902
+		return $inputs;
903
+	}
904
+
905
+
906
+
907
+	/**
908
+	 * Gets all the inputs on this form section
909
+	 *
910
+	 * @return EE_Form_Input_Base[]
911
+	 */
912
+	public function inputs()
913
+	{
914
+		$inputs = array();
915
+		foreach ($this->subsections() as $subsection_name => $subsection) {
916
+			if ($subsection instanceof EE_Form_Input_Base) {
917
+				$inputs[$subsection_name] = $subsection;
918
+			}
919
+		}
920
+		return $inputs;
921
+	}
922
+
923
+
924
+
925
+	/**
926
+	 * Gets all the subsections which are a proper form
927
+	 *
928
+	 * @return EE_Form_Section_Proper[]
929
+	 */
930
+	public function subforms()
931
+	{
932
+		$form_sections = array();
933
+		foreach ($this->subsections() as $name => $obj) {
934
+			if ($obj instanceof EE_Form_Section_Proper) {
935
+				$form_sections[$name] = $obj;
936
+			}
937
+		}
938
+		return $form_sections;
939
+	}
940
+
941
+
942
+
943
+	/**
944
+	 * Gets all the subsections (inputs, proper subsections, or html-only sections).
945
+	 * Consider using inputs() or subforms()
946
+	 * if you only want form inputs or proper form sections.
947
+	 *
948
+	 * @param boolean $require_construction_to_be_finalized most client code should
949
+	 *                                                      leave this as TRUE so that the inputs will be properly
950
+	 *                                                      configured. However, some client code may be ok with
951
+	 *                                                      construction finalize being called later
952
+	 *                                                      (realizing that the subsections' html names might not be
953
+	 *                                                      set yet, etc.)
954
+	 * @return EE_Form_Section_Proper[]
955
+	 */
956
+	public function subsections($require_construction_to_be_finalized = true)
957
+	{
958
+		if ($require_construction_to_be_finalized) {
959
+			$this->ensure_construct_finalized_called();
960
+		}
961
+		return $this->_subsections;
962
+	}
963
+
964
+
965
+
966
+	/**
967
+	 * Returns a simple array where keys are input names, and values are their normalized
968
+	 * values. (Similar to calling get_input_value on inputs)
969
+	 *
970
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
971
+	 *                                        or just this forms' direct children inputs
972
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
973
+	 *                                        or allow multidimensional array
974
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
975
+	 *                                        with array keys being input names
976
+	 *                                        (regardless of whether they are from a subsection or not),
977
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
978
+	 *                                        where keys are always subsection names and values are either
979
+	 *                                        the input's normalized value, or an array like the top-level array
980
+	 */
981
+	public function input_values($include_subform_inputs = false, $flatten = false)
982
+	{
983
+		return $this->_input_values(false, $include_subform_inputs, $flatten);
984
+	}
985
+
986
+
987
+
988
+	/**
989
+	 * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
990
+	 * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
991
+	 * is not necessarily the value we want to display to users. This creates an array
992
+	 * where keys are the input names, and values are their display values
993
+	 *
994
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
995
+	 *                                        or just this forms' direct children inputs
996
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
997
+	 *                                        or allow multidimensional array
998
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
999
+	 *                                        with array keys being input names
1000
+	 *                                        (regardless of whether they are from a subsection or not),
1001
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1002
+	 *                                        where keys are always subsection names and values are either
1003
+	 *                                        the input's normalized value, or an array like the top-level array
1004
+	 */
1005
+	public function input_pretty_values($include_subform_inputs = false, $flatten = false)
1006
+	{
1007
+		return $this->_input_values(true, $include_subform_inputs, $flatten);
1008
+	}
1009
+
1010
+
1011
+
1012
+	/**
1013
+	 * Gets the input values from the form
1014
+	 *
1015
+	 * @param boolean $pretty                 Whether to retrieve the pretty value,
1016
+	 *                                        or just the normalized value
1017
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
1018
+	 *                                        or just this forms' direct children inputs
1019
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
1020
+	 *                                        or allow multidimensional array
1021
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
1022
+	 *                                        input names (regardless of whether they are from a subsection or not),
1023
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
1024
+	 *                                        where keys are always subsection names and values are either
1025
+	 *                                        the input's normalized value, or an array like the top-level array
1026
+	 */
1027
+	public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
1028
+	{
1029
+		$input_values = array();
1030
+		foreach ($this->subsections() as $subsection_name => $subsection) {
1031
+			if ($subsection instanceof EE_Form_Input_Base) {
1032
+				$input_values[$subsection_name] = $pretty
1033
+					? $subsection->pretty_value()
1034
+					: $subsection->normalized_value();
1035
+			} else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1036
+				$subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten);
1037
+				if ($flatten) {
1038
+					$input_values = array_merge($input_values, $subform_input_values);
1039
+				} else {
1040
+					$input_values[$subsection_name] = $subform_input_values;
1041
+				}
1042
+			}
1043
+		}
1044
+		return $input_values;
1045
+	}
1046
+
1047
+
1048
+
1049
+	/**
1050
+	 * Gets the originally submitted input values from the form
1051
+	 *
1052
+	 * @param boolean $include_subforms  Whether to include inputs from subforms,
1053
+	 *                                   or just this forms' direct children inputs
1054
+	 * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1055
+	 *                                   with array keys being input names
1056
+	 *                                   (regardless of whether they are from a subsection or not),
1057
+	 *                                   and if $flatten is FALSE it can be a multidimensional array
1058
+	 *                                   where keys are always subsection names and values are either
1059
+	 *                                   the input's normalized value, or an array like the top-level array
1060
+	 */
1061
+	public function submitted_values($include_subforms = false)
1062
+	{
1063
+		$submitted_values = array();
1064
+		foreach ($this->subsections() as $subsection) {
1065
+			if ($subsection instanceof EE_Form_Input_Base) {
1066
+				// is this input part of an array of inputs?
1067
+				if (strpos($subsection->html_name(), '[') !== false) {
1068
+					$full_input_name = \EEH_Array::convert_array_values_to_keys(
1069
+						explode('[', str_replace(']', '', $subsection->html_name())),
1070
+						$subsection->raw_value()
1071
+					);
1072
+					$submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1073
+				} else {
1074
+					$submitted_values[$subsection->html_name()] = $subsection->raw_value();
1075
+				}
1076
+			} else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1077
+				$subform_input_values = $subsection->submitted_values($include_subforms);
1078
+				$submitted_values = array_replace_recursive($submitted_values, $subform_input_values);
1079
+			}
1080
+		}
1081
+		return $submitted_values;
1082
+	}
1083
+
1084
+
1085
+
1086
+	/**
1087
+	 * Indicates whether or not this form has received a submission yet
1088
+	 * (ie, had receive_form_submission called on it yet)
1089
+	 *
1090
+	 * @return boolean
1091
+	 * @throws \EE_Error
1092
+	 */
1093
+	public function has_received_submission()
1094
+	{
1095
+		$this->ensure_construct_finalized_called();
1096
+		return $this->_received_submission;
1097
+	}
1098
+
1099
+
1100
+
1101
+	/**
1102
+	 * Equivalent to passing 'exclude' in the constructor's options array.
1103
+	 * Removes the listed inputs from the form
1104
+	 *
1105
+	 * @param array $inputs_to_exclude values are the input names
1106
+	 * @return void
1107
+	 */
1108
+	public function exclude(array $inputs_to_exclude = array())
1109
+	{
1110
+		foreach ($inputs_to_exclude as $input_to_exclude_name) {
1111
+			unset($this->_subsections[$input_to_exclude_name]);
1112
+		}
1113
+	}
1114
+
1115
+
1116
+
1117
+	/**
1118
+	 * @param array $inputs_to_hide
1119
+	 * @throws \EE_Error
1120
+	 */
1121
+	public function hide(array $inputs_to_hide = array())
1122
+	{
1123
+		foreach ($inputs_to_hide as $input_to_hide) {
1124
+			$input = $this->get_input($input_to_hide);
1125
+			$input->set_display_strategy(new EE_Hidden_Display_Strategy());
1126
+		}
1127
+	}
1128
+
1129
+
1130
+
1131
+	/**
1132
+	 * add_subsections
1133
+	 * Adds the listed subsections to the form section.
1134
+	 * If $subsection_name_to_target is provided,
1135
+	 * then new subsections are added before or after that subsection,
1136
+	 * otherwise to the start or end of the entire subsections array.
1137
+	 *
1138
+	 * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1139
+	 *                                                          where keys are their names
1140
+	 * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1141
+	 *                                                          should be added before or after
1142
+	 *                                                          IF $subsection_name_to_target is null,
1143
+	 *                                                          then $new_subsections will be added to
1144
+	 *                                                          the beginning or end of the entire subsections array
1145
+	 * @param boolean                $add_before                whether to add $new_subsections, before or after
1146
+	 *                                                          $subsection_name_to_target,
1147
+	 *                                                          or if $subsection_name_to_target is null,
1148
+	 *                                                          before or after entire subsections array
1149
+	 * @return void
1150
+	 * @throws \EE_Error
1151
+	 */
1152
+	public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1153
+	{
1154
+		foreach ($new_subsections as $subsection_name => $subsection) {
1155
+			if (! $subsection instanceof EE_Form_Section_Base) {
1156
+				EE_Error::add_error(
1157
+					sprintf(
1158
+						__(
1159
+							"Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1160
+							"event_espresso"
1161
+						),
1162
+						get_class($subsection),
1163
+						$subsection_name,
1164
+						$this->name()
1165
+					)
1166
+				);
1167
+				unset($new_subsections[$subsection_name]);
1168
+			}
1169
+		}
1170
+		$this->_subsections = EEH_Array::insert_into_array(
1171
+			$this->_subsections,
1172
+			$new_subsections,
1173
+			$subsection_name_to_target,
1174
+			$add_before
1175
+		);
1176
+		if ($this->_construction_finalized) {
1177
+			foreach ($this->_subsections as $name => $subsection) {
1178
+				$subsection->_construct_finalize($this, $name);
1179
+			}
1180
+		}
1181
+	}
1182
+
1183
+
1184
+
1185
+	/**
1186
+	 * Just gets all validatable subsections to clean their sensitive data
1187
+	 */
1188
+	public function clean_sensitive_data()
1189
+	{
1190
+		foreach ($this->get_validatable_subsections() as $subsection) {
1191
+			$subsection->clean_sensitive_data();
1192
+		}
1193
+	}
1194
+
1195
+
1196
+
1197
+	/**
1198
+	 * @param string $form_submission_error_message
1199
+	 */
1200
+	public function set_submission_error_message($form_submission_error_message = '')
1201
+	{
1202
+		$this->_form_submission_error_message .= ! empty($form_submission_error_message)
1203
+			? $form_submission_error_message
1204
+			: __('Form submission failed due to errors', 'event_espresso');
1205
+	}
1206
+
1207
+
1208
+
1209
+	/**
1210
+	 * @return string
1211
+	 */
1212
+	public function submission_error_message()
1213
+	{
1214
+		return $this->_form_submission_error_message;
1215
+	}
1216
+
1217
+
1218
+
1219
+	/**
1220
+	 * @param string $form_submission_success_message
1221
+	 */
1222
+	public function set_submission_success_message($form_submission_success_message)
1223
+	{
1224
+		$this->_form_submission_success_message .= ! empty($form_submission_success_message)
1225
+			? $form_submission_success_message
1226
+			: __('Form submitted successfully', 'event_espresso');
1227
+	}
1228
+
1229
+
1230
+
1231
+	/**
1232
+	 * @return string
1233
+	 */
1234
+	public function submission_success_message()
1235
+	{
1236
+		return $this->_form_submission_success_message;
1237
+	}
1238
+
1239
+
1240
+
1241
+	/**
1242
+	 * Returns the prefix that should be used on child of this form section for
1243
+	 * their html names. If this form section itself has a parent, prepends ITS
1244
+	 * prefix onto this form section's prefix. Used primarily by
1245
+	 * EE_Form_Input_Base::_set_default_html_name_if_empty
1246
+	 *
1247
+	 * @return string
1248
+	 * @throws \EE_Error
1249
+	 */
1250
+	public function html_name_prefix()
1251
+	{
1252
+		if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1253
+			return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1254
+		} else {
1255
+			return $this->name();
1256
+		}
1257
+	}
1258
+
1259
+
1260
+
1261
+	/**
1262
+	 * Gets the name, but first checks _construct_finalize has been called. If not,
1263
+	 * calls it (assumes there is no parent and that we want the name to be whatever
1264
+	 * was set, which is probably nothing, or the classname)
1265
+	 *
1266
+	 * @return string
1267
+	 * @throws \EE_Error
1268
+	 */
1269
+	public function name()
1270
+	{
1271
+		$this->ensure_construct_finalized_called();
1272
+		return parent::name();
1273
+	}
1274
+
1275
+
1276
+
1277
+	/**
1278
+	 * @return EE_Form_Section_Proper
1279
+	 * @throws \EE_Error
1280
+	 */
1281
+	public function parent_section()
1282
+	{
1283
+		$this->ensure_construct_finalized_called();
1284
+		return parent::parent_section();
1285
+	}
1286
+
1287
+
1288
+
1289
+	/**
1290
+	 * make sure construction finalized was called, otherwise children might not be ready
1291
+	 *
1292
+	 * @return void
1293
+	 * @throws \EE_Error
1294
+	 */
1295
+	public function ensure_construct_finalized_called()
1296
+	{
1297
+		if (! $this->_construction_finalized) {
1298
+			$this->_construct_finalize($this->_parent_section, $this->_name);
1299
+		}
1300
+	}
1301
+
1302
+
1303
+
1304
+	/**
1305
+	 * Checks if any of this form section's inputs, or any of its children's inputs,
1306
+	 * are in teh form data. If any are found, returns true. Else false
1307
+	 *
1308
+	 * @param array $req_data
1309
+	 * @return boolean
1310
+	 */
1311
+	public function form_data_present_in($req_data = null)
1312
+	{
1313
+		if ($req_data === null) {
1314
+			$req_data = $_POST;
1315
+		}
1316
+		foreach ($this->subsections() as $subsection) {
1317
+			if ($subsection instanceof EE_Form_Input_Base) {
1318
+				if ($subsection->form_data_present_in($req_data)) {
1319
+					return true;
1320
+				}
1321
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
1322
+				if ($subsection->form_data_present_in($req_data)) {
1323
+					return true;
1324
+				}
1325
+			}
1326
+		}
1327
+		return false;
1328
+	}
1329
+
1330
+
1331
+
1332
+	/**
1333
+	 * Gets validation errors for this form section and subsections
1334
+	 * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1335
+	 * gets the validation errors for ALL subsection
1336
+	 *
1337
+	 * @return EE_Validation_Error[]
1338
+	 */
1339
+	public function get_validation_errors_accumulated()
1340
+	{
1341
+		$validation_errors = $this->get_validation_errors();
1342
+		foreach ($this->get_validatable_subsections() as $subsection) {
1343
+			if ($subsection instanceof EE_Form_Section_Proper) {
1344
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1345
+			} else {
1346
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors();
1347
+			}
1348
+			if ($validation_errors_on_this_subsection) {
1349
+				$validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1350
+			}
1351
+		}
1352
+		return $validation_errors;
1353
+	}
1354
+
1355
+
1356
+
1357
+	/**
1358
+	 * This isn't just the name of an input, it's a path pointing to an input. The
1359
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
1360
+	 * dot-dot-slash (../) means to ascend into the parent section.
1361
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1362
+	 * which will be returned.
1363
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1364
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1365
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1366
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1367
+	 * Etc
1368
+	 *
1369
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1370
+	 * @return EE_Form_Section_Base
1371
+	 */
1372
+	public function find_section_from_path($form_section_path)
1373
+	{
1374
+		//check if we can find the input from purely going straight up the tree
1375
+		$input = parent::find_section_from_path($form_section_path);
1376
+		if ($input instanceof EE_Form_Section_Base) {
1377
+			return $input;
1378
+		}
1379
+		$next_slash_pos = strpos($form_section_path, '/');
1380
+		if ($next_slash_pos !== false) {
1381
+			$child_section_name = substr($form_section_path, 0, $next_slash_pos);
1382
+			$subpath = substr($form_section_path, $next_slash_pos + 1);
1383
+		} else {
1384
+			$child_section_name = $form_section_path;
1385
+			$subpath = '';
1386
+		}
1387
+		$child_section = $this->get_subsection($child_section_name);
1388
+		if ($child_section instanceof EE_Form_Section_Base) {
1389
+			return $child_section->find_section_from_path($subpath);
1390
+		} else {
1391
+			return null;
1392
+		}
1393
+	}
1394 1394
 
1395 1395
 }
1396 1396
 
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Form_Input_Base.input.php 2 patches
Indentation   +1139 added lines, -1139 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -16,1142 +16,1142 @@  discard block
 block discarded – undo
16 16
 abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable
17 17
 {
18 18
 
19
-    /**
20
-     * the input's name attribute
21
-     *
22
-     * @var string
23
-     */
24
-    protected $_html_name;
25
-
26
-    /**
27
-     * id for the html label tag
28
-     *
29
-     * @var string
30
-     */
31
-    protected $_html_label_id;
32
-
33
-    /**
34
-     * class for teh html label tag
35
-     *
36
-     * @var string
37
-     */
38
-    protected $_html_label_class;
39
-
40
-    /**
41
-     * any additional html attributes that you may want to add
42
-     *
43
-     * @var string
44
-     */
45
-    protected $_html_other_attributes;
46
-
47
-    /**
48
-     * style for teh html label tag
49
-     *
50
-     * @var string
51
-     */
52
-    protected $_html_label_style;
53
-
54
-    /**
55
-     * text to be placed in the html label
56
-     *
57
-     * @var string
58
-     */
59
-    protected $_html_label_text;
60
-
61
-    /**
62
-     * the full html label. If used, all other html_label_* properties are invalid
63
-     *
64
-     * @var string
65
-     */
66
-    protected $_html_label;
67
-
68
-    /**
69
-     * HTML to use for help text (normally placed below form input), in a span which normally
70
-     * has a class of 'description'
71
-     *
72
-     * @var string
73
-     */
74
-    protected $_html_help_text;
75
-
76
-    /**
77
-     * CSS classes for displaying the help span
78
-     *
79
-     * @var string
80
-     */
81
-    protected $_html_help_class = 'description';
82
-
83
-    /**
84
-     * CSS to put in the style attribute on the help span
85
-     *
86
-     * @var string
87
-     */
88
-    protected $_html_help_style;
89
-
90
-    /**
91
-     * Stores whether or not this input's response is required.
92
-     * Because certain styling elements may also want to know that this
93
-     * input is required etc.
94
-     *
95
-     * @var boolean
96
-     */
97
-    protected $_required;
98
-
99
-    /**
100
-     * css class added to required inputs
101
-     *
102
-     * @var string
103
-     */
104
-    protected $_required_css_class = 'ee-required';
105
-
106
-    /**
107
-     * css styles applied to button type inputs
108
-     *
109
-     * @var string
110
-     */
111
-    protected $_button_css_attributes;
112
-
113
-    /**
114
-     * The raw data submitted for this, like in the $_POST super global.
115
-     * Generally unsafe for usage in client code
116
-     *
117
-     * @var mixed string or array
118
-     */
119
-    protected $_raw_value;
120
-
121
-    /**
122
-     * Value normalized according to the input's normalization strategy.
123
-     * The normalization strategy dictates whether this is a string, int, float,
124
-     * boolean, or array of any of those.
125
-     *
126
-     * @var mixed
127
-     */
128
-    protected $_normalized_value;
129
-
130
-    /**
131
-     * Strategy used for displaying this field.
132
-     * Child classes must use _get_display_strategy to access it.
133
-     *
134
-     * @var EE_Display_Strategy_Base
135
-     */
136
-    private $_display_strategy;
137
-
138
-    /**
139
-     * Gets all the validation strategies used on this field
140
-     *
141
-     * @var EE_Validation_Strategy_Base[]
142
-     */
143
-    private $_validation_strategies = array();
144
-
145
-    /**
146
-     * The normalization strategy for this field
147
-     *
148
-     * @var EE_Normalization_Strategy_Base
149
-     */
150
-    private $_normalization_strategy;
151
-
152
-    /**
153
-     * Strategy for removing sensitive data after we're done with the form input
154
-     *
155
-     * @var EE_Sensitive_Data_Removal_Base
156
-     */
157
-    protected $_sensitive_data_removal_strategy;
158
-
159
-
160
-
161
-    /**
162
-     * @param array                         $input_args       {
163
-     * @type string                         $html_name        the html name for the input
164
-     * @type string                         $html_label_id    the id attribute to give to the html label tag
165
-     * @type string                         $html_label_class the class attribute to give to the html label tag
166
-     * @type string                         $html_label_style the style attribute to give ot teh label tag
167
-     * @type string                         $html_label_text  the text to put in the label tag
168
-     * @type string                         $html_label       the full html label. If used,
169
-     *                                                        all other html_label_* args are invalid
170
-     * @type string                         $html_help_text   text to put in help element
171
-     * @type string                         $html_help_style  style attribute to give to teh help element
172
-     * @type string                         $html_help_class  class attribute to give to the help element
173
-     * @type string                         $default          default value NORMALIZED (eg, if providing the default
174
-     *       for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0')
175
-     * @type EE_Display_Strategy_Base       $display          strategy
176
-     * @type EE_Normalization_Strategy_Base $normalization_strategy
177
-     * @type EE_Validation_Strategy_Base[]  $validation_strategies
178
-     *                                                        }
179
-     */
180
-    public function __construct($input_args = array())
181
-    {
182
-        $input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this);
183
-        // the following properties must be cast as arrays
184
-        if (isset($input_args['validation_strategies'])) {
185
-            foreach ((array)$input_args['validation_strategies'] as $validation_strategy) {
186
-                if ($validation_strategy instanceof EE_Validation_Strategy_Base) {
187
-                    $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy;
188
-                }
189
-            }
190
-            unset($input_args['validation_strategies']);
191
-        }
192
-        // loop thru incoming options
193
-        foreach ($input_args as $key => $value) {
194
-            // add underscore to $key to match property names
195
-            $_key = '_' . $key;
196
-            if (property_exists($this, $_key)) {
197
-                $this->{$_key} = $value;
198
-            }
199
-        }
200
-        // ensure that "required" is set correctly
201
-        $this->set_required(
202
-            $this->_required, isset($input_args['required_validation_error_message'])
203
-            ? $input_args['required_validation_error_message']
204
-            : null
205
-        );
206
-        //$this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE;
207
-        $this->_display_strategy->_construct_finalize($this);
208
-        foreach ($this->_validation_strategies as $validation_strategy) {
209
-            $validation_strategy->_construct_finalize($this);
210
-        }
211
-        if (! $this->_normalization_strategy) {
212
-            $this->_normalization_strategy = new EE_Text_Normalization();
213
-        }
214
-        $this->_normalization_strategy->_construct_finalize($this);
215
-        //at least we can use the normalization strategy to populate the default
216
-        if (isset($input_args['default'])) {
217
-            $this->set_default($input_args['default']);
218
-        }
219
-        if (! $this->_sensitive_data_removal_strategy) {
220
-            $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
221
-        }
222
-        $this->_sensitive_data_removal_strategy->_construct_finalize($this);
223
-        parent::__construct($input_args);
224
-    }
225
-
226
-
227
-
228
-    /**
229
-     * Sets the html_name to its default value, if none was specified in teh constructor.
230
-     * Calculation involves using the name and the parent's html_name
231
-     *
232
-     * @throws \EE_Error
233
-     */
234
-    protected function _set_default_html_name_if_empty()
235
-    {
236
-        if (! $this->_html_name) {
237
-            $this->_html_name = $this->name();
238
-            if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
239
-                $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
240
-            }
241
-        }
242
-    }
243
-
244
-
245
-
246
-    /**
247
-     * @param $parent_form_section
248
-     * @param $name
249
-     * @throws \EE_Error
250
-     */
251
-    public function _construct_finalize($parent_form_section, $name)
252
-    {
253
-        parent::_construct_finalize($parent_form_section, $name);
254
-        if ($this->_html_label === null && $this->_html_label_text === null) {
255
-            $this->_html_label_text = ucwords(str_replace("_", " ", $name));
256
-        }
257
-        do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name);
258
-    }
259
-
260
-
261
-
262
-    /**
263
-     * Returns the strategy for displaying this form input. If none is set, throws an exception.
264
-     *
265
-     * @return EE_Display_Strategy_Base
266
-     * @throws EE_Error
267
-     */
268
-    protected function _get_display_strategy()
269
-    {
270
-        $this->ensure_construct_finalized_called();
271
-        if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
272
-            throw new EE_Error(
273
-                sprintf(
274
-                    __(
275
-                        "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor",
276
-                        "event_espresso"
277
-                    ),
278
-                    $this->html_name(),
279
-                    $this->html_id()
280
-                )
281
-            );
282
-        } else {
283
-            return $this->_display_strategy;
284
-        }
285
-    }
286
-
287
-
288
-
289
-    /**
290
-     * Sets the display strategy.
291
-     *
292
-     * @param EE_Display_Strategy_Base $strategy
293
-     */
294
-    protected function _set_display_strategy(EE_Display_Strategy_Base $strategy)
295
-    {
296
-        $this->_display_strategy = $strategy;
297
-    }
298
-
299
-
300
-
301
-    /**
302
-     * Sets the sanitization strategy
303
-     *
304
-     * @param EE_Normalization_Strategy_Base $strategy
305
-     */
306
-    protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy)
307
-    {
308
-        $this->_normalization_strategy = $strategy;
309
-    }
310
-
311
-
312
-
313
-    /**
314
-     * Gets sensitive_data_removal_strategy
315
-     *
316
-     * @return EE_Sensitive_Data_Removal_Base
317
-     */
318
-    public function get_sensitive_data_removal_strategy()
319
-    {
320
-        return $this->_sensitive_data_removal_strategy;
321
-    }
322
-
323
-
324
-
325
-    /**
326
-     * Sets sensitive_data_removal_strategy
327
-     *
328
-     * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy
329
-     * @return boolean
330
-     */
331
-    public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy)
332
-    {
333
-        $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy;
334
-    }
335
-
336
-
337
-
338
-    /**
339
-     * Gets the display strategy for this input
340
-     *
341
-     * @return EE_Display_Strategy_Base
342
-     */
343
-    public function get_display_strategy()
344
-    {
345
-        return $this->_display_strategy;
346
-    }
347
-
348
-
349
-
350
-    /**
351
-     * Overwrites the display strategy
352
-     *
353
-     * @param EE_Display_Strategy_Base $display_strategy
354
-     */
355
-    public function set_display_strategy($display_strategy)
356
-    {
357
-        $this->_display_strategy = $display_strategy;
358
-        $this->_display_strategy->_construct_finalize($this);
359
-    }
360
-
361
-
362
-
363
-    /**
364
-     * Gets the normalization strategy set on this input
365
-     *
366
-     * @return EE_Normalization_Strategy_Base
367
-     */
368
-    public function get_normalization_strategy()
369
-    {
370
-        return $this->_normalization_strategy;
371
-    }
372
-
373
-
374
-
375
-    /**
376
-     * Overwrites the normalization strategy
377
-     *
378
-     * @param EE_Normalization_Strategy_Base $normalization_strategy
379
-     */
380
-    public function set_normalization_strategy($normalization_strategy)
381
-    {
382
-        $this->_normalization_strategy = $normalization_strategy;
383
-        $this->_normalization_strategy->_construct_finalize($this);
384
-    }
385
-
386
-
387
-
388
-    /**
389
-     * Returns all teh validation strategies which apply to this field, numerically indexed
390
-     *
391
-     * @return EE_Validation_Strategy_Base[]
392
-     */
393
-    public function get_validation_strategies()
394
-    {
395
-        return $this->_validation_strategies;
396
-    }
397
-
398
-
399
-
400
-    /**
401
-     * Adds this strategy to the field so it will be used in both JS validation and server-side validation
402
-     *
403
-     * @param EE_Validation_Strategy_Base $validation_strategy
404
-     * @return void
405
-     */
406
-    protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
407
-    {
408
-        $validation_strategy->_construct_finalize($this);
409
-        $this->_validation_strategies[] = $validation_strategy;
410
-    }
411
-
412
-
413
-
414
-    /**
415
-     * Adds a new validation strategy onto the form input
416
-     *
417
-     * @param EE_Validation_Strategy_Base $validation_strategy
418
-     * @return void
419
-     */
420
-    public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
421
-    {
422
-        $this->_add_validation_strategy($validation_strategy);
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     * The classname of the validation strategy to remove
429
-     *
430
-     * @param string $validation_strategy_classname
431
-     */
432
-    public function remove_validation_strategy($validation_strategy_classname)
433
-    {
434
-        foreach ($this->_validation_strategies as $key => $validation_strategy) {
435
-            if (
436
-                $validation_strategy instanceof $validation_strategy_classname
437
-                || is_subclass_of($validation_strategy, $validation_strategy_classname)
438
-            ) {
439
-                unset($this->_validation_strategies[$key]);
440
-            }
441
-        }
442
-    }
443
-
444
-
445
-
446
-    /**
447
-     * returns true if input employs any of the validation strategy defined by the supplied array of classnames
448
-     *
449
-     * @param array $validation_strategy_classnames
450
-     * @return bool
451
-     */
452
-    public function has_validation_strategy($validation_strategy_classnames)
453
-    {
454
-        $validation_strategy_classnames = is_array($validation_strategy_classnames)
455
-            ? $validation_strategy_classnames
456
-            : array($validation_strategy_classnames);
457
-        foreach ($this->_validation_strategies as $key => $validation_strategy) {
458
-            if (in_array($key, $validation_strategy_classnames)) {
459
-                return true;
460
-            }
461
-        }
462
-        return false;
463
-    }
464
-
465
-
466
-
467
-    /**
468
-     * Gets the HTML
469
-     *
470
-     * @return string
471
-     */
472
-    public function get_html()
473
-    {
474
-        return $this->_parent_section->get_html_for_input($this);
475
-    }
476
-
477
-
478
-
479
-    /**
480
-     * Gets the HTML for the input itself (no label or errors) according to the
481
-     * input's display strategy
482
-     * Makes sure the JS and CSS are enqueued for it
483
-     *
484
-     * @return string
485
-     * @throws \EE_Error
486
-     */
487
-    public function get_html_for_input()
488
-    {
489
-        return $this->_form_html_filter
490
-            ? $this->_form_html_filter->filterHtml(
491
-                $this->_get_display_strategy()->display(),
492
-                $this
493
-            )
494
-            : $this->_get_display_strategy()->display();
495
-    }
496
-
497
-
498
-
499
-    /**
500
-     * @return string
501
-     */
502
-    public function html_other_attributes()
503
-    {
504
-        return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : '';
505
-    }
506
-
507
-
508
-
509
-    /**
510
-     * @param string $html_other_attributes
511
-     */
512
-    public function set_html_other_attributes($html_other_attributes)
513
-    {
514
-        $this->_html_other_attributes = $html_other_attributes;
515
-    }
516
-
517
-
518
-
519
-    /**
520
-     * Gets the HTML for displaying the label for this form input
521
-     * according to the form section's layout strategy
522
-     *
523
-     * @return string
524
-     */
525
-    public function get_html_for_label()
526
-    {
527
-        return $this->_parent_section->get_layout_strategy()->display_label($this);
528
-    }
529
-
530
-
531
-
532
-    /**
533
-     * Gets the HTML for displaying the errors section for this form input
534
-     * according to the form section's layout strategy
535
-     *
536
-     * @return string
537
-     */
538
-    public function get_html_for_errors()
539
-    {
540
-        return $this->_parent_section->get_layout_strategy()->display_errors($this);
541
-    }
542
-
543
-
544
-
545
-    /**
546
-     * Gets the HTML for displaying the help text for this form input
547
-     * according to the form section's layout strategy
548
-     *
549
-     * @return string
550
-     */
551
-    public function get_html_for_help()
552
-    {
553
-        return $this->_parent_section->get_layout_strategy()->display_help_text($this);
554
-    }
555
-
556
-
557
-
558
-    /**
559
-     * Validates the input's sanitized value (assumes _sanitize() has already been called)
560
-     * and returns whether or not the form input's submitted value is value
561
-     *
562
-     * @return boolean
563
-     */
564
-    protected function _validate()
565
-    {
566
-        foreach ($this->_validation_strategies as $validation_strategy) {
567
-            if ($validation_strategy instanceof EE_Validation_Strategy_Base) {
568
-                try {
569
-                    $validation_strategy->validate($this->normalized_value());
570
-                } catch (EE_Validation_Error $e) {
571
-                    $this->add_validation_error($e);
572
-                }
573
-            }
574
-        }
575
-        if ($this->get_validation_errors()) {
576
-            return false;
577
-        } else {
578
-            return true;
579
-        }
580
-    }
581
-
582
-
583
-
584
-    /**
585
-     * Performs basic sanitization on this value. But what sanitization can be performed anyways?
586
-     * This value MIGHT be allowed to have tags, so we can't really remove them.
587
-     *
588
-     * @param string $value
589
-     * @return null|string
590
-     */
591
-    private function _sanitize($value)
592
-    {
593
-        return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null;
594
-    }
595
-
596
-
597
-
598
-    /**
599
-     * Picks out the form value that relates to this form input,
600
-     * and stores it as the sanitized value on the form input, and sets the normalized value.
601
-     * Returns whether or not any validation errors occurred
602
-     *
603
-     * @param array $req_data like $_POST
604
-     * @return boolean whether or not there was an error
605
-     * @throws \EE_Error
606
-     */
607
-    protected function _normalize($req_data)
608
-    {
609
-        //any existing validation errors don't apply so clear them
610
-        $this->_validation_errors = array();
611
-        try {
612
-            $raw_input = $this->find_form_data_for_this_section($req_data);
613
-            //super simple sanitization for now
614
-            if (is_array($raw_input)) {
615
-                $raw_value = array();
616
-                foreach ($raw_input as $key => $value) {
617
-                    $raw_value[$key] = $this->_sanitize($value);
618
-                }
619
-                $this->_set_raw_value($raw_value);
620
-            } else {
621
-                $this->_set_raw_value($this->_sanitize($raw_input));
622
-            }
623
-            //we want to mostly leave the input alone in case we need to re-display it to the user
624
-            $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value()));
625
-        } catch (EE_Validation_Error $e) {
626
-            $this->add_validation_error($e);
627
-        }
628
-    }
629
-
630
-
631
-
632
-    /**
633
-     * @return string
634
-     */
635
-    public function html_name()
636
-    {
637
-        $this->_set_default_html_name_if_empty();
638
-        return $this->_html_name;
639
-    }
640
-
641
-
642
-
643
-    /**
644
-     * @return string
645
-     */
646
-    public function html_label_id()
647
-    {
648
-        return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl';
649
-    }
650
-
651
-
652
-
653
-    /**
654
-     * @return string
655
-     */
656
-    public function html_label_class()
657
-    {
658
-        return $this->_html_label_class;
659
-    }
660
-
661
-
662
-
663
-    /**
664
-     * @return string
665
-     */
666
-    public function html_label_style()
667
-    {
668
-        return $this->_html_label_style;
669
-    }
670
-
671
-
672
-
673
-    /**
674
-     * @return string
675
-     */
676
-    public function html_label_text()
677
-    {
678
-        return $this->_html_label_text;
679
-    }
680
-
681
-
682
-
683
-    /**
684
-     * @return string
685
-     */
686
-    public function html_help_text()
687
-    {
688
-        return $this->_html_help_text;
689
-    }
690
-
691
-
692
-
693
-    /**
694
-     * @return string
695
-     */
696
-    public function html_help_class()
697
-    {
698
-        return $this->_html_help_class;
699
-    }
700
-
701
-
702
-
703
-    /**
704
-     * @return string
705
-     */
706
-    public function html_help_style()
707
-    {
708
-        return $this->_html_style;
709
-    }
710
-
711
-
712
-
713
-    /**
714
-     * returns the raw, UNSAFE, input, almost exactly as the user submitted it.
715
-     * Please note that almost all client code should instead use the normalized_value;
716
-     * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag,
717
-     * mostly by escaping quotes)
718
-     * Note, we do not store the exact original value sent in the user's request because
719
-     * it may have malicious content, and we MIGHT want to store the form input in a transient or something...
720
-     * in which case, we would have stored the malicious content to our database.
721
-     *
722
-     * @return string
723
-     */
724
-    public function raw_value()
725
-    {
726
-        return $this->_raw_value;
727
-    }
728
-
729
-
730
-
731
-    /**
732
-     * Returns a string safe to usage in form inputs when displaying, because
733
-     * it escapes all html entities
734
-     *
735
-     * @return string
736
-     */
737
-    public function raw_value_in_form()
738
-    {
739
-        return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8');
740
-    }
741
-
742
-
743
-
744
-    /**
745
-     * returns the value after it's been sanitized, and then converted into it's proper type
746
-     * in PHP. Eg, a string, an int, an array,
747
-     *
748
-     * @return mixed
749
-     */
750
-    public function normalized_value()
751
-    {
752
-        return $this->_normalized_value;
753
-    }
754
-
755
-
756
-
757
-    /**
758
-     * Returns the normalized value is a presentable way. By default this is just
759
-     * the normalized value by itself, but it can be overridden for when that's not
760
-     * the best thing to display
761
-     *
762
-     * @return string
763
-     */
764
-    public function pretty_value()
765
-    {
766
-        return $this->_normalized_value;
767
-    }
768
-
769
-
770
-
771
-    /**
772
-     * When generating the JS for the jquery validation rules like<br>
773
-     * <code>$( "#myform" ).validate({
774
-     * rules: {
775
-     * password: "required",
776
-     * password_again: {
777
-     * equalTo: "#password"
778
-     * }
779
-     * }
780
-     * });</code>
781
-     * if this field had the name 'password_again', it should return
782
-     * <br><code>password_again: {
783
-     * equalTo: "#password"
784
-     * }</code>
785
-     *
786
-     * @return array
787
-     */
788
-    public function get_jquery_validation_rules()
789
-    {
790
-        $jquery_validation_js = array();
791
-        $jquery_validation_rules = array();
792
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
793
-            $jquery_validation_rules = array_replace_recursive(
794
-                $jquery_validation_rules,
795
-                $validation_strategy->get_jquery_validation_rule_array()
796
-            );
797
-        }
798
-        if (! empty($jquery_validation_rules)) {
799
-            foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
800
-                $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules;
801
-            }
802
-        }
803
-        return $jquery_validation_js;
804
-    }
805
-
806
-
807
-
808
-    /**
809
-     * Sets the input's default value for use in displaying in the form. Note: value should be
810
-     * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0')
811
-     *
812
-     * @param mixed $value
813
-     * @return void
814
-     */
815
-    public function set_default($value)
816
-    {
817
-        $this->_set_normalized_value($value);
818
-        $this->_set_raw_value($value);
819
-    }
820
-
821
-
822
-
823
-    /**
824
-     * Sets the normalized value on this input
825
-     *
826
-     * @param mixed $value
827
-     */
828
-    protected function _set_normalized_value($value)
829
-    {
830
-        $this->_normalized_value = $value;
831
-    }
832
-
833
-
834
-
835
-    /**
836
-     * Sets the raw value on this input (ie, exactly as the user submitted it)
837
-     *
838
-     * @param mixed $value
839
-     */
840
-    protected function _set_raw_value($value)
841
-    {
842
-        $this->_raw_value = $this->_normalization_strategy->unnormalize($value);
843
-    }
844
-
845
-
846
-
847
-    /**
848
-     * Sets the HTML label text after it has already been defined
849
-     *
850
-     * @param string $label
851
-     * @return void
852
-     */
853
-    public function set_html_label_text($label)
854
-    {
855
-        $this->_html_label_text = $label;
856
-    }
857
-
858
-
859
-
860
-    /**
861
-     * Sets whether or not this field is required, and adjusts the validation strategy.
862
-     * If you want to use the EE_Conditionally_Required_Validation_Strategy,
863
-     * please add it as a validation strategy using add_validation_strategy as normal
864
-     *
865
-     * @param boolean $required boolean
866
-     * @param null    $required_text
867
-     */
868
-    public function set_required($required = true, $required_text = null)
869
-    {
870
-        $required = filter_var($required, FILTER_VALIDATE_BOOLEAN);
871
-        //whether $required is a string or a boolean, we want to add a required validation strategy
872
-        if ($required) {
873
-            $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text));
874
-        } else {
875
-            $this->remove_validation_strategy('EE_Required_Validation_Strategy');
876
-        }
877
-        $this->_required = $required;
878
-    }
879
-
880
-
881
-
882
-    /**
883
-     * Returns whether or not this field is required
884
-     *
885
-     * @return boolean
886
-     */
887
-    public function required()
888
-    {
889
-        return $this->_required;
890
-    }
891
-
892
-
893
-
894
-    /**
895
-     * @param string $required_css_class
896
-     */
897
-    public function set_required_css_class($required_css_class)
898
-    {
899
-        $this->_required_css_class = $required_css_class;
900
-    }
901
-
902
-
903
-
904
-    /**
905
-     * @return string
906
-     */
907
-    public function required_css_class()
908
-    {
909
-        return $this->_required_css_class;
910
-    }
911
-
912
-
913
-
914
-    /**
915
-     * @param bool $add_required
916
-     * @return string
917
-     */
918
-    public function html_class($add_required = false)
919
-    {
920
-        return $add_required && $this->required()
921
-            ? $this->required_css_class() . ' ' . $this->_html_class
922
-            : $this->_html_class;
923
-    }
924
-
925
-
926
-    /**
927
-     * Sets the help text, in case
928
-     *
929
-     * @param string $text
930
-     */
931
-    public function set_html_help_text($text)
932
-    {
933
-        $this->_html_help_text = $text;
934
-    }
935
-
936
-
937
-
938
-    /**
939
-     * Uses the sensitive data removal strategy to remove the sensitive data from this
940
-     * input. If there is any kind of sensitive data removal on this input, we clear
941
-     * out the raw value completely
942
-     *
943
-     * @return void
944
-     */
945
-    public function clean_sensitive_data()
946
-    {
947
-        //if we do ANY kind of sensitive data removal on this, then just clear out the raw value
948
-        //if we need more logic than this we'll make a strategy for it
949
-        if ($this->_sensitive_data_removal_strategy
950
-            && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal
951
-        ) {
952
-            $this->_set_raw_value(null);
953
-        }
954
-        //and clean the normalized value according to the appropriate strategy
955
-        $this->_set_normalized_value(
956
-            $this->get_sensitive_data_removal_strategy()->remove_sensitive_data(
957
-                $this->_normalized_value
958
-            )
959
-        );
960
-    }
961
-
962
-
963
-
964
-    /**
965
-     * @param bool   $primary
966
-     * @param string $button_size
967
-     * @param string $other_attributes
968
-     */
969
-    public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '')
970
-    {
971
-        $button_css_attributes = 'button';
972
-        $button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary';
973
-        switch ($button_size) {
974
-            case 'xs' :
975
-            case 'extra-small' :
976
-                $button_css_attributes .= ' button-xs';
977
-                break;
978
-            case 'sm' :
979
-            case 'small' :
980
-                $button_css_attributes .= ' button-sm';
981
-                break;
982
-            case 'lg' :
983
-            case 'large' :
984
-                $button_css_attributes .= ' button-lg';
985
-                break;
986
-            case 'block' :
987
-                $button_css_attributes .= ' button-block';
988
-                break;
989
-            case 'md' :
990
-            case 'medium' :
991
-            default :
992
-                $button_css_attributes .= '';
993
-        }
994
-        $this->_button_css_attributes .= ! empty($other_attributes)
995
-            ? $button_css_attributes . ' ' . $other_attributes
996
-            : $button_css_attributes;
997
-    }
998
-
999
-
1000
-
1001
-    /**
1002
-     * @return string
1003
-     */
1004
-    public function button_css_attributes()
1005
-    {
1006
-        if (empty($this->_button_css_attributes)) {
1007
-            $this->set_button_css_attributes();
1008
-        }
1009
-        return $this->_button_css_attributes;
1010
-    }
1011
-
1012
-
1013
-
1014
-    /**
1015
-     * find_form_data_for_this_section
1016
-     * using this section's name and its parents, finds the value of the form data that corresponds to it.
1017
-     * For example, if this form section's HTML name is my_form[subform][form_input_1],
1018
-     * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1'].
1019
-     * (If that doesn't exist, we also check for this subsection's name
1020
-     * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].)
1021
-     * This function finds its value in the form.
1022
-     *
1023
-     * @param array $req_data
1024
-     * @return mixed whatever the raw value of this form section is in the request data
1025
-     * @throws \EE_Error
1026
-     */
1027
-    public function find_form_data_for_this_section($req_data)
1028
-    {
1029
-        // break up the html name by "[]"
1030
-        if (strpos($this->html_name(), '[') !== false) {
1031
-            $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '['));
1032
-        } else {
1033
-            $before_any_brackets = $this->html_name();
1034
-        }
1035
-        // grab all of the segments
1036
-        preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches);
1037
-        if (isset($matches[1]) && is_array($matches[1])) {
1038
-            $name_parts = $matches[1];
1039
-            array_unshift($name_parts, $before_any_brackets);
1040
-        } else {
1041
-            $name_parts = array($before_any_brackets);
1042
-        }
1043
-        // now get the value for the input
1044
-        $value = $this->_find_form_data_for_this_section_using_name_parts($name_parts, $req_data);
1045
-        // check if this thing's name is at the TOP level of the request data
1046
-        if ($value === null && isset($req_data[$this->name()])) {
1047
-            $value = $req_data[$this->name()];
1048
-        }
1049
-        return $value;
1050
-    }
1051
-
1052
-
1053
-
1054
-    /**
1055
-     * @param array $html_name_parts
1056
-     * @param array $req_data
1057
-     * @return array | NULL
1058
-     */
1059
-    public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data)
1060
-    {
1061
-        $first_part_to_consider = array_shift($html_name_parts);
1062
-        if (isset($req_data[$first_part_to_consider])) {
1063
-            if (empty($html_name_parts)) {
1064
-                return $req_data[$first_part_to_consider];
1065
-            } else {
1066
-                return $this->_find_form_data_for_this_section_using_name_parts(
1067
-                    $html_name_parts,
1068
-                    $req_data[$first_part_to_consider]
1069
-                );
1070
-            }
1071
-        } else {
1072
-            return null;
1073
-        }
1074
-    }
1075
-
1076
-
1077
-
1078
-    /**
1079
-     * Checks if this form input's data is in the request data
1080
-     *
1081
-     * @param array $req_data like $_POST
1082
-     * @return boolean
1083
-     * @throws \EE_Error
1084
-     */
1085
-    public function form_data_present_in($req_data = null)
1086
-    {
1087
-        if ($req_data === null) {
1088
-            $req_data = $_POST;
1089
-        }
1090
-        $checked_value = $this->find_form_data_for_this_section($req_data);
1091
-        if ($checked_value !== null) {
1092
-            return true;
1093
-        } else {
1094
-            return false;
1095
-        }
1096
-    }
1097
-
1098
-
1099
-
1100
-    /**
1101
-     * Overrides parent to add js data from validation and display strategies
1102
-     *
1103
-     * @param array $form_other_js_data
1104
-     * @return array
1105
-     */
1106
-    public function get_other_js_data($form_other_js_data = array())
1107
-    {
1108
-        $form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data);
1109
-        return $form_other_js_data;
1110
-    }
1111
-
1112
-
1113
-
1114
-    /**
1115
-     * Gets other JS data for localization from this input's strategies, like
1116
-     * the validation strategies and the display strategy
1117
-     *
1118
-     * @param array $form_other_js_data
1119
-     * @return array
1120
-     */
1121
-    public function get_other_js_data_from_strategies($form_other_js_data = array())
1122
-    {
1123
-        $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data);
1124
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
1125
-            $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data);
1126
-        }
1127
-        return $form_other_js_data;
1128
-    }
1129
-
1130
-
1131
-
1132
-    /**
1133
-     * Override parent because we want to give our strategies an opportunity to enqueue some js and css
1134
-     *
1135
-     * @return void
1136
-     */
1137
-    public function enqueue_js()
1138
-    {
1139
-        //ask our display strategy and validation strategies if they have js to enqueue
1140
-        $this->enqueue_js_from_strategies();
1141
-    }
1142
-
1143
-
1144
-
1145
-    /**
1146
-     * Tells strategies when its ok to enqueue their js and css
1147
-     *
1148
-     * @return void
1149
-     */
1150
-    public function enqueue_js_from_strategies()
1151
-    {
1152
-        $this->get_display_strategy()->enqueue_js();
1153
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
1154
-            $validation_strategy->enqueue_js();
1155
-        }
1156
-    }
19
+	/**
20
+	 * the input's name attribute
21
+	 *
22
+	 * @var string
23
+	 */
24
+	protected $_html_name;
25
+
26
+	/**
27
+	 * id for the html label tag
28
+	 *
29
+	 * @var string
30
+	 */
31
+	protected $_html_label_id;
32
+
33
+	/**
34
+	 * class for teh html label tag
35
+	 *
36
+	 * @var string
37
+	 */
38
+	protected $_html_label_class;
39
+
40
+	/**
41
+	 * any additional html attributes that you may want to add
42
+	 *
43
+	 * @var string
44
+	 */
45
+	protected $_html_other_attributes;
46
+
47
+	/**
48
+	 * style for teh html label tag
49
+	 *
50
+	 * @var string
51
+	 */
52
+	protected $_html_label_style;
53
+
54
+	/**
55
+	 * text to be placed in the html label
56
+	 *
57
+	 * @var string
58
+	 */
59
+	protected $_html_label_text;
60
+
61
+	/**
62
+	 * the full html label. If used, all other html_label_* properties are invalid
63
+	 *
64
+	 * @var string
65
+	 */
66
+	protected $_html_label;
67
+
68
+	/**
69
+	 * HTML to use for help text (normally placed below form input), in a span which normally
70
+	 * has a class of 'description'
71
+	 *
72
+	 * @var string
73
+	 */
74
+	protected $_html_help_text;
75
+
76
+	/**
77
+	 * CSS classes for displaying the help span
78
+	 *
79
+	 * @var string
80
+	 */
81
+	protected $_html_help_class = 'description';
82
+
83
+	/**
84
+	 * CSS to put in the style attribute on the help span
85
+	 *
86
+	 * @var string
87
+	 */
88
+	protected $_html_help_style;
89
+
90
+	/**
91
+	 * Stores whether or not this input's response is required.
92
+	 * Because certain styling elements may also want to know that this
93
+	 * input is required etc.
94
+	 *
95
+	 * @var boolean
96
+	 */
97
+	protected $_required;
98
+
99
+	/**
100
+	 * css class added to required inputs
101
+	 *
102
+	 * @var string
103
+	 */
104
+	protected $_required_css_class = 'ee-required';
105
+
106
+	/**
107
+	 * css styles applied to button type inputs
108
+	 *
109
+	 * @var string
110
+	 */
111
+	protected $_button_css_attributes;
112
+
113
+	/**
114
+	 * The raw data submitted for this, like in the $_POST super global.
115
+	 * Generally unsafe for usage in client code
116
+	 *
117
+	 * @var mixed string or array
118
+	 */
119
+	protected $_raw_value;
120
+
121
+	/**
122
+	 * Value normalized according to the input's normalization strategy.
123
+	 * The normalization strategy dictates whether this is a string, int, float,
124
+	 * boolean, or array of any of those.
125
+	 *
126
+	 * @var mixed
127
+	 */
128
+	protected $_normalized_value;
129
+
130
+	/**
131
+	 * Strategy used for displaying this field.
132
+	 * Child classes must use _get_display_strategy to access it.
133
+	 *
134
+	 * @var EE_Display_Strategy_Base
135
+	 */
136
+	private $_display_strategy;
137
+
138
+	/**
139
+	 * Gets all the validation strategies used on this field
140
+	 *
141
+	 * @var EE_Validation_Strategy_Base[]
142
+	 */
143
+	private $_validation_strategies = array();
144
+
145
+	/**
146
+	 * The normalization strategy for this field
147
+	 *
148
+	 * @var EE_Normalization_Strategy_Base
149
+	 */
150
+	private $_normalization_strategy;
151
+
152
+	/**
153
+	 * Strategy for removing sensitive data after we're done with the form input
154
+	 *
155
+	 * @var EE_Sensitive_Data_Removal_Base
156
+	 */
157
+	protected $_sensitive_data_removal_strategy;
158
+
159
+
160
+
161
+	/**
162
+	 * @param array                         $input_args       {
163
+	 * @type string                         $html_name        the html name for the input
164
+	 * @type string                         $html_label_id    the id attribute to give to the html label tag
165
+	 * @type string                         $html_label_class the class attribute to give to the html label tag
166
+	 * @type string                         $html_label_style the style attribute to give ot teh label tag
167
+	 * @type string                         $html_label_text  the text to put in the label tag
168
+	 * @type string                         $html_label       the full html label. If used,
169
+	 *                                                        all other html_label_* args are invalid
170
+	 * @type string                         $html_help_text   text to put in help element
171
+	 * @type string                         $html_help_style  style attribute to give to teh help element
172
+	 * @type string                         $html_help_class  class attribute to give to the help element
173
+	 * @type string                         $default          default value NORMALIZED (eg, if providing the default
174
+	 *       for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0')
175
+	 * @type EE_Display_Strategy_Base       $display          strategy
176
+	 * @type EE_Normalization_Strategy_Base $normalization_strategy
177
+	 * @type EE_Validation_Strategy_Base[]  $validation_strategies
178
+	 *                                                        }
179
+	 */
180
+	public function __construct($input_args = array())
181
+	{
182
+		$input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this);
183
+		// the following properties must be cast as arrays
184
+		if (isset($input_args['validation_strategies'])) {
185
+			foreach ((array)$input_args['validation_strategies'] as $validation_strategy) {
186
+				if ($validation_strategy instanceof EE_Validation_Strategy_Base) {
187
+					$this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy;
188
+				}
189
+			}
190
+			unset($input_args['validation_strategies']);
191
+		}
192
+		// loop thru incoming options
193
+		foreach ($input_args as $key => $value) {
194
+			// add underscore to $key to match property names
195
+			$_key = '_' . $key;
196
+			if (property_exists($this, $_key)) {
197
+				$this->{$_key} = $value;
198
+			}
199
+		}
200
+		// ensure that "required" is set correctly
201
+		$this->set_required(
202
+			$this->_required, isset($input_args['required_validation_error_message'])
203
+			? $input_args['required_validation_error_message']
204
+			: null
205
+		);
206
+		//$this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE;
207
+		$this->_display_strategy->_construct_finalize($this);
208
+		foreach ($this->_validation_strategies as $validation_strategy) {
209
+			$validation_strategy->_construct_finalize($this);
210
+		}
211
+		if (! $this->_normalization_strategy) {
212
+			$this->_normalization_strategy = new EE_Text_Normalization();
213
+		}
214
+		$this->_normalization_strategy->_construct_finalize($this);
215
+		//at least we can use the normalization strategy to populate the default
216
+		if (isset($input_args['default'])) {
217
+			$this->set_default($input_args['default']);
218
+		}
219
+		if (! $this->_sensitive_data_removal_strategy) {
220
+			$this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
221
+		}
222
+		$this->_sensitive_data_removal_strategy->_construct_finalize($this);
223
+		parent::__construct($input_args);
224
+	}
225
+
226
+
227
+
228
+	/**
229
+	 * Sets the html_name to its default value, if none was specified in teh constructor.
230
+	 * Calculation involves using the name and the parent's html_name
231
+	 *
232
+	 * @throws \EE_Error
233
+	 */
234
+	protected function _set_default_html_name_if_empty()
235
+	{
236
+		if (! $this->_html_name) {
237
+			$this->_html_name = $this->name();
238
+			if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
239
+				$this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
240
+			}
241
+		}
242
+	}
243
+
244
+
245
+
246
+	/**
247
+	 * @param $parent_form_section
248
+	 * @param $name
249
+	 * @throws \EE_Error
250
+	 */
251
+	public function _construct_finalize($parent_form_section, $name)
252
+	{
253
+		parent::_construct_finalize($parent_form_section, $name);
254
+		if ($this->_html_label === null && $this->_html_label_text === null) {
255
+			$this->_html_label_text = ucwords(str_replace("_", " ", $name));
256
+		}
257
+		do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name);
258
+	}
259
+
260
+
261
+
262
+	/**
263
+	 * Returns the strategy for displaying this form input. If none is set, throws an exception.
264
+	 *
265
+	 * @return EE_Display_Strategy_Base
266
+	 * @throws EE_Error
267
+	 */
268
+	protected function _get_display_strategy()
269
+	{
270
+		$this->ensure_construct_finalized_called();
271
+		if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
272
+			throw new EE_Error(
273
+				sprintf(
274
+					__(
275
+						"Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor",
276
+						"event_espresso"
277
+					),
278
+					$this->html_name(),
279
+					$this->html_id()
280
+				)
281
+			);
282
+		} else {
283
+			return $this->_display_strategy;
284
+		}
285
+	}
286
+
287
+
288
+
289
+	/**
290
+	 * Sets the display strategy.
291
+	 *
292
+	 * @param EE_Display_Strategy_Base $strategy
293
+	 */
294
+	protected function _set_display_strategy(EE_Display_Strategy_Base $strategy)
295
+	{
296
+		$this->_display_strategy = $strategy;
297
+	}
298
+
299
+
300
+
301
+	/**
302
+	 * Sets the sanitization strategy
303
+	 *
304
+	 * @param EE_Normalization_Strategy_Base $strategy
305
+	 */
306
+	protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy)
307
+	{
308
+		$this->_normalization_strategy = $strategy;
309
+	}
310
+
311
+
312
+
313
+	/**
314
+	 * Gets sensitive_data_removal_strategy
315
+	 *
316
+	 * @return EE_Sensitive_Data_Removal_Base
317
+	 */
318
+	public function get_sensitive_data_removal_strategy()
319
+	{
320
+		return $this->_sensitive_data_removal_strategy;
321
+	}
322
+
323
+
324
+
325
+	/**
326
+	 * Sets sensitive_data_removal_strategy
327
+	 *
328
+	 * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy
329
+	 * @return boolean
330
+	 */
331
+	public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy)
332
+	{
333
+		$this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy;
334
+	}
335
+
336
+
337
+
338
+	/**
339
+	 * Gets the display strategy for this input
340
+	 *
341
+	 * @return EE_Display_Strategy_Base
342
+	 */
343
+	public function get_display_strategy()
344
+	{
345
+		return $this->_display_strategy;
346
+	}
347
+
348
+
349
+
350
+	/**
351
+	 * Overwrites the display strategy
352
+	 *
353
+	 * @param EE_Display_Strategy_Base $display_strategy
354
+	 */
355
+	public function set_display_strategy($display_strategy)
356
+	{
357
+		$this->_display_strategy = $display_strategy;
358
+		$this->_display_strategy->_construct_finalize($this);
359
+	}
360
+
361
+
362
+
363
+	/**
364
+	 * Gets the normalization strategy set on this input
365
+	 *
366
+	 * @return EE_Normalization_Strategy_Base
367
+	 */
368
+	public function get_normalization_strategy()
369
+	{
370
+		return $this->_normalization_strategy;
371
+	}
372
+
373
+
374
+
375
+	/**
376
+	 * Overwrites the normalization strategy
377
+	 *
378
+	 * @param EE_Normalization_Strategy_Base $normalization_strategy
379
+	 */
380
+	public function set_normalization_strategy($normalization_strategy)
381
+	{
382
+		$this->_normalization_strategy = $normalization_strategy;
383
+		$this->_normalization_strategy->_construct_finalize($this);
384
+	}
385
+
386
+
387
+
388
+	/**
389
+	 * Returns all teh validation strategies which apply to this field, numerically indexed
390
+	 *
391
+	 * @return EE_Validation_Strategy_Base[]
392
+	 */
393
+	public function get_validation_strategies()
394
+	{
395
+		return $this->_validation_strategies;
396
+	}
397
+
398
+
399
+
400
+	/**
401
+	 * Adds this strategy to the field so it will be used in both JS validation and server-side validation
402
+	 *
403
+	 * @param EE_Validation_Strategy_Base $validation_strategy
404
+	 * @return void
405
+	 */
406
+	protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
407
+	{
408
+		$validation_strategy->_construct_finalize($this);
409
+		$this->_validation_strategies[] = $validation_strategy;
410
+	}
411
+
412
+
413
+
414
+	/**
415
+	 * Adds a new validation strategy onto the form input
416
+	 *
417
+	 * @param EE_Validation_Strategy_Base $validation_strategy
418
+	 * @return void
419
+	 */
420
+	public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
421
+	{
422
+		$this->_add_validation_strategy($validation_strategy);
423
+	}
424
+
425
+
426
+
427
+	/**
428
+	 * The classname of the validation strategy to remove
429
+	 *
430
+	 * @param string $validation_strategy_classname
431
+	 */
432
+	public function remove_validation_strategy($validation_strategy_classname)
433
+	{
434
+		foreach ($this->_validation_strategies as $key => $validation_strategy) {
435
+			if (
436
+				$validation_strategy instanceof $validation_strategy_classname
437
+				|| is_subclass_of($validation_strategy, $validation_strategy_classname)
438
+			) {
439
+				unset($this->_validation_strategies[$key]);
440
+			}
441
+		}
442
+	}
443
+
444
+
445
+
446
+	/**
447
+	 * returns true if input employs any of the validation strategy defined by the supplied array of classnames
448
+	 *
449
+	 * @param array $validation_strategy_classnames
450
+	 * @return bool
451
+	 */
452
+	public function has_validation_strategy($validation_strategy_classnames)
453
+	{
454
+		$validation_strategy_classnames = is_array($validation_strategy_classnames)
455
+			? $validation_strategy_classnames
456
+			: array($validation_strategy_classnames);
457
+		foreach ($this->_validation_strategies as $key => $validation_strategy) {
458
+			if (in_array($key, $validation_strategy_classnames)) {
459
+				return true;
460
+			}
461
+		}
462
+		return false;
463
+	}
464
+
465
+
466
+
467
+	/**
468
+	 * Gets the HTML
469
+	 *
470
+	 * @return string
471
+	 */
472
+	public function get_html()
473
+	{
474
+		return $this->_parent_section->get_html_for_input($this);
475
+	}
476
+
477
+
478
+
479
+	/**
480
+	 * Gets the HTML for the input itself (no label or errors) according to the
481
+	 * input's display strategy
482
+	 * Makes sure the JS and CSS are enqueued for it
483
+	 *
484
+	 * @return string
485
+	 * @throws \EE_Error
486
+	 */
487
+	public function get_html_for_input()
488
+	{
489
+		return $this->_form_html_filter
490
+			? $this->_form_html_filter->filterHtml(
491
+				$this->_get_display_strategy()->display(),
492
+				$this
493
+			)
494
+			: $this->_get_display_strategy()->display();
495
+	}
496
+
497
+
498
+
499
+	/**
500
+	 * @return string
501
+	 */
502
+	public function html_other_attributes()
503
+	{
504
+		return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : '';
505
+	}
506
+
507
+
508
+
509
+	/**
510
+	 * @param string $html_other_attributes
511
+	 */
512
+	public function set_html_other_attributes($html_other_attributes)
513
+	{
514
+		$this->_html_other_attributes = $html_other_attributes;
515
+	}
516
+
517
+
518
+
519
+	/**
520
+	 * Gets the HTML for displaying the label for this form input
521
+	 * according to the form section's layout strategy
522
+	 *
523
+	 * @return string
524
+	 */
525
+	public function get_html_for_label()
526
+	{
527
+		return $this->_parent_section->get_layout_strategy()->display_label($this);
528
+	}
529
+
530
+
531
+
532
+	/**
533
+	 * Gets the HTML for displaying the errors section for this form input
534
+	 * according to the form section's layout strategy
535
+	 *
536
+	 * @return string
537
+	 */
538
+	public function get_html_for_errors()
539
+	{
540
+		return $this->_parent_section->get_layout_strategy()->display_errors($this);
541
+	}
542
+
543
+
544
+
545
+	/**
546
+	 * Gets the HTML for displaying the help text for this form input
547
+	 * according to the form section's layout strategy
548
+	 *
549
+	 * @return string
550
+	 */
551
+	public function get_html_for_help()
552
+	{
553
+		return $this->_parent_section->get_layout_strategy()->display_help_text($this);
554
+	}
555
+
556
+
557
+
558
+	/**
559
+	 * Validates the input's sanitized value (assumes _sanitize() has already been called)
560
+	 * and returns whether or not the form input's submitted value is value
561
+	 *
562
+	 * @return boolean
563
+	 */
564
+	protected function _validate()
565
+	{
566
+		foreach ($this->_validation_strategies as $validation_strategy) {
567
+			if ($validation_strategy instanceof EE_Validation_Strategy_Base) {
568
+				try {
569
+					$validation_strategy->validate($this->normalized_value());
570
+				} catch (EE_Validation_Error $e) {
571
+					$this->add_validation_error($e);
572
+				}
573
+			}
574
+		}
575
+		if ($this->get_validation_errors()) {
576
+			return false;
577
+		} else {
578
+			return true;
579
+		}
580
+	}
581
+
582
+
583
+
584
+	/**
585
+	 * Performs basic sanitization on this value. But what sanitization can be performed anyways?
586
+	 * This value MIGHT be allowed to have tags, so we can't really remove them.
587
+	 *
588
+	 * @param string $value
589
+	 * @return null|string
590
+	 */
591
+	private function _sanitize($value)
592
+	{
593
+		return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null;
594
+	}
595
+
596
+
597
+
598
+	/**
599
+	 * Picks out the form value that relates to this form input,
600
+	 * and stores it as the sanitized value on the form input, and sets the normalized value.
601
+	 * Returns whether or not any validation errors occurred
602
+	 *
603
+	 * @param array $req_data like $_POST
604
+	 * @return boolean whether or not there was an error
605
+	 * @throws \EE_Error
606
+	 */
607
+	protected function _normalize($req_data)
608
+	{
609
+		//any existing validation errors don't apply so clear them
610
+		$this->_validation_errors = array();
611
+		try {
612
+			$raw_input = $this->find_form_data_for_this_section($req_data);
613
+			//super simple sanitization for now
614
+			if (is_array($raw_input)) {
615
+				$raw_value = array();
616
+				foreach ($raw_input as $key => $value) {
617
+					$raw_value[$key] = $this->_sanitize($value);
618
+				}
619
+				$this->_set_raw_value($raw_value);
620
+			} else {
621
+				$this->_set_raw_value($this->_sanitize($raw_input));
622
+			}
623
+			//we want to mostly leave the input alone in case we need to re-display it to the user
624
+			$this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value()));
625
+		} catch (EE_Validation_Error $e) {
626
+			$this->add_validation_error($e);
627
+		}
628
+	}
629
+
630
+
631
+
632
+	/**
633
+	 * @return string
634
+	 */
635
+	public function html_name()
636
+	{
637
+		$this->_set_default_html_name_if_empty();
638
+		return $this->_html_name;
639
+	}
640
+
641
+
642
+
643
+	/**
644
+	 * @return string
645
+	 */
646
+	public function html_label_id()
647
+	{
648
+		return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl';
649
+	}
650
+
651
+
652
+
653
+	/**
654
+	 * @return string
655
+	 */
656
+	public function html_label_class()
657
+	{
658
+		return $this->_html_label_class;
659
+	}
660
+
661
+
662
+
663
+	/**
664
+	 * @return string
665
+	 */
666
+	public function html_label_style()
667
+	{
668
+		return $this->_html_label_style;
669
+	}
670
+
671
+
672
+
673
+	/**
674
+	 * @return string
675
+	 */
676
+	public function html_label_text()
677
+	{
678
+		return $this->_html_label_text;
679
+	}
680
+
681
+
682
+
683
+	/**
684
+	 * @return string
685
+	 */
686
+	public function html_help_text()
687
+	{
688
+		return $this->_html_help_text;
689
+	}
690
+
691
+
692
+
693
+	/**
694
+	 * @return string
695
+	 */
696
+	public function html_help_class()
697
+	{
698
+		return $this->_html_help_class;
699
+	}
700
+
701
+
702
+
703
+	/**
704
+	 * @return string
705
+	 */
706
+	public function html_help_style()
707
+	{
708
+		return $this->_html_style;
709
+	}
710
+
711
+
712
+
713
+	/**
714
+	 * returns the raw, UNSAFE, input, almost exactly as the user submitted it.
715
+	 * Please note that almost all client code should instead use the normalized_value;
716
+	 * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag,
717
+	 * mostly by escaping quotes)
718
+	 * Note, we do not store the exact original value sent in the user's request because
719
+	 * it may have malicious content, and we MIGHT want to store the form input in a transient or something...
720
+	 * in which case, we would have stored the malicious content to our database.
721
+	 *
722
+	 * @return string
723
+	 */
724
+	public function raw_value()
725
+	{
726
+		return $this->_raw_value;
727
+	}
728
+
729
+
730
+
731
+	/**
732
+	 * Returns a string safe to usage in form inputs when displaying, because
733
+	 * it escapes all html entities
734
+	 *
735
+	 * @return string
736
+	 */
737
+	public function raw_value_in_form()
738
+	{
739
+		return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8');
740
+	}
741
+
742
+
743
+
744
+	/**
745
+	 * returns the value after it's been sanitized, and then converted into it's proper type
746
+	 * in PHP. Eg, a string, an int, an array,
747
+	 *
748
+	 * @return mixed
749
+	 */
750
+	public function normalized_value()
751
+	{
752
+		return $this->_normalized_value;
753
+	}
754
+
755
+
756
+
757
+	/**
758
+	 * Returns the normalized value is a presentable way. By default this is just
759
+	 * the normalized value by itself, but it can be overridden for when that's not
760
+	 * the best thing to display
761
+	 *
762
+	 * @return string
763
+	 */
764
+	public function pretty_value()
765
+	{
766
+		return $this->_normalized_value;
767
+	}
768
+
769
+
770
+
771
+	/**
772
+	 * When generating the JS for the jquery validation rules like<br>
773
+	 * <code>$( "#myform" ).validate({
774
+	 * rules: {
775
+	 * password: "required",
776
+	 * password_again: {
777
+	 * equalTo: "#password"
778
+	 * }
779
+	 * }
780
+	 * });</code>
781
+	 * if this field had the name 'password_again', it should return
782
+	 * <br><code>password_again: {
783
+	 * equalTo: "#password"
784
+	 * }</code>
785
+	 *
786
+	 * @return array
787
+	 */
788
+	public function get_jquery_validation_rules()
789
+	{
790
+		$jquery_validation_js = array();
791
+		$jquery_validation_rules = array();
792
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
793
+			$jquery_validation_rules = array_replace_recursive(
794
+				$jquery_validation_rules,
795
+				$validation_strategy->get_jquery_validation_rule_array()
796
+			);
797
+		}
798
+		if (! empty($jquery_validation_rules)) {
799
+			foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
800
+				$jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules;
801
+			}
802
+		}
803
+		return $jquery_validation_js;
804
+	}
805
+
806
+
807
+
808
+	/**
809
+	 * Sets the input's default value for use in displaying in the form. Note: value should be
810
+	 * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0')
811
+	 *
812
+	 * @param mixed $value
813
+	 * @return void
814
+	 */
815
+	public function set_default($value)
816
+	{
817
+		$this->_set_normalized_value($value);
818
+		$this->_set_raw_value($value);
819
+	}
820
+
821
+
822
+
823
+	/**
824
+	 * Sets the normalized value on this input
825
+	 *
826
+	 * @param mixed $value
827
+	 */
828
+	protected function _set_normalized_value($value)
829
+	{
830
+		$this->_normalized_value = $value;
831
+	}
832
+
833
+
834
+
835
+	/**
836
+	 * Sets the raw value on this input (ie, exactly as the user submitted it)
837
+	 *
838
+	 * @param mixed $value
839
+	 */
840
+	protected function _set_raw_value($value)
841
+	{
842
+		$this->_raw_value = $this->_normalization_strategy->unnormalize($value);
843
+	}
844
+
845
+
846
+
847
+	/**
848
+	 * Sets the HTML label text after it has already been defined
849
+	 *
850
+	 * @param string $label
851
+	 * @return void
852
+	 */
853
+	public function set_html_label_text($label)
854
+	{
855
+		$this->_html_label_text = $label;
856
+	}
857
+
858
+
859
+
860
+	/**
861
+	 * Sets whether or not this field is required, and adjusts the validation strategy.
862
+	 * If you want to use the EE_Conditionally_Required_Validation_Strategy,
863
+	 * please add it as a validation strategy using add_validation_strategy as normal
864
+	 *
865
+	 * @param boolean $required boolean
866
+	 * @param null    $required_text
867
+	 */
868
+	public function set_required($required = true, $required_text = null)
869
+	{
870
+		$required = filter_var($required, FILTER_VALIDATE_BOOLEAN);
871
+		//whether $required is a string or a boolean, we want to add a required validation strategy
872
+		if ($required) {
873
+			$this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text));
874
+		} else {
875
+			$this->remove_validation_strategy('EE_Required_Validation_Strategy');
876
+		}
877
+		$this->_required = $required;
878
+	}
879
+
880
+
881
+
882
+	/**
883
+	 * Returns whether or not this field is required
884
+	 *
885
+	 * @return boolean
886
+	 */
887
+	public function required()
888
+	{
889
+		return $this->_required;
890
+	}
891
+
892
+
893
+
894
+	/**
895
+	 * @param string $required_css_class
896
+	 */
897
+	public function set_required_css_class($required_css_class)
898
+	{
899
+		$this->_required_css_class = $required_css_class;
900
+	}
901
+
902
+
903
+
904
+	/**
905
+	 * @return string
906
+	 */
907
+	public function required_css_class()
908
+	{
909
+		return $this->_required_css_class;
910
+	}
911
+
912
+
913
+
914
+	/**
915
+	 * @param bool $add_required
916
+	 * @return string
917
+	 */
918
+	public function html_class($add_required = false)
919
+	{
920
+		return $add_required && $this->required()
921
+			? $this->required_css_class() . ' ' . $this->_html_class
922
+			: $this->_html_class;
923
+	}
924
+
925
+
926
+	/**
927
+	 * Sets the help text, in case
928
+	 *
929
+	 * @param string $text
930
+	 */
931
+	public function set_html_help_text($text)
932
+	{
933
+		$this->_html_help_text = $text;
934
+	}
935
+
936
+
937
+
938
+	/**
939
+	 * Uses the sensitive data removal strategy to remove the sensitive data from this
940
+	 * input. If there is any kind of sensitive data removal on this input, we clear
941
+	 * out the raw value completely
942
+	 *
943
+	 * @return void
944
+	 */
945
+	public function clean_sensitive_data()
946
+	{
947
+		//if we do ANY kind of sensitive data removal on this, then just clear out the raw value
948
+		//if we need more logic than this we'll make a strategy for it
949
+		if ($this->_sensitive_data_removal_strategy
950
+			&& ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal
951
+		) {
952
+			$this->_set_raw_value(null);
953
+		}
954
+		//and clean the normalized value according to the appropriate strategy
955
+		$this->_set_normalized_value(
956
+			$this->get_sensitive_data_removal_strategy()->remove_sensitive_data(
957
+				$this->_normalized_value
958
+			)
959
+		);
960
+	}
961
+
962
+
963
+
964
+	/**
965
+	 * @param bool   $primary
966
+	 * @param string $button_size
967
+	 * @param string $other_attributes
968
+	 */
969
+	public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '')
970
+	{
971
+		$button_css_attributes = 'button';
972
+		$button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary';
973
+		switch ($button_size) {
974
+			case 'xs' :
975
+			case 'extra-small' :
976
+				$button_css_attributes .= ' button-xs';
977
+				break;
978
+			case 'sm' :
979
+			case 'small' :
980
+				$button_css_attributes .= ' button-sm';
981
+				break;
982
+			case 'lg' :
983
+			case 'large' :
984
+				$button_css_attributes .= ' button-lg';
985
+				break;
986
+			case 'block' :
987
+				$button_css_attributes .= ' button-block';
988
+				break;
989
+			case 'md' :
990
+			case 'medium' :
991
+			default :
992
+				$button_css_attributes .= '';
993
+		}
994
+		$this->_button_css_attributes .= ! empty($other_attributes)
995
+			? $button_css_attributes . ' ' . $other_attributes
996
+			: $button_css_attributes;
997
+	}
998
+
999
+
1000
+
1001
+	/**
1002
+	 * @return string
1003
+	 */
1004
+	public function button_css_attributes()
1005
+	{
1006
+		if (empty($this->_button_css_attributes)) {
1007
+			$this->set_button_css_attributes();
1008
+		}
1009
+		return $this->_button_css_attributes;
1010
+	}
1011
+
1012
+
1013
+
1014
+	/**
1015
+	 * find_form_data_for_this_section
1016
+	 * using this section's name and its parents, finds the value of the form data that corresponds to it.
1017
+	 * For example, if this form section's HTML name is my_form[subform][form_input_1],
1018
+	 * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1'].
1019
+	 * (If that doesn't exist, we also check for this subsection's name
1020
+	 * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].)
1021
+	 * This function finds its value in the form.
1022
+	 *
1023
+	 * @param array $req_data
1024
+	 * @return mixed whatever the raw value of this form section is in the request data
1025
+	 * @throws \EE_Error
1026
+	 */
1027
+	public function find_form_data_for_this_section($req_data)
1028
+	{
1029
+		// break up the html name by "[]"
1030
+		if (strpos($this->html_name(), '[') !== false) {
1031
+			$before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '['));
1032
+		} else {
1033
+			$before_any_brackets = $this->html_name();
1034
+		}
1035
+		// grab all of the segments
1036
+		preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches);
1037
+		if (isset($matches[1]) && is_array($matches[1])) {
1038
+			$name_parts = $matches[1];
1039
+			array_unshift($name_parts, $before_any_brackets);
1040
+		} else {
1041
+			$name_parts = array($before_any_brackets);
1042
+		}
1043
+		// now get the value for the input
1044
+		$value = $this->_find_form_data_for_this_section_using_name_parts($name_parts, $req_data);
1045
+		// check if this thing's name is at the TOP level of the request data
1046
+		if ($value === null && isset($req_data[$this->name()])) {
1047
+			$value = $req_data[$this->name()];
1048
+		}
1049
+		return $value;
1050
+	}
1051
+
1052
+
1053
+
1054
+	/**
1055
+	 * @param array $html_name_parts
1056
+	 * @param array $req_data
1057
+	 * @return array | NULL
1058
+	 */
1059
+	public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data)
1060
+	{
1061
+		$first_part_to_consider = array_shift($html_name_parts);
1062
+		if (isset($req_data[$first_part_to_consider])) {
1063
+			if (empty($html_name_parts)) {
1064
+				return $req_data[$first_part_to_consider];
1065
+			} else {
1066
+				return $this->_find_form_data_for_this_section_using_name_parts(
1067
+					$html_name_parts,
1068
+					$req_data[$first_part_to_consider]
1069
+				);
1070
+			}
1071
+		} else {
1072
+			return null;
1073
+		}
1074
+	}
1075
+
1076
+
1077
+
1078
+	/**
1079
+	 * Checks if this form input's data is in the request data
1080
+	 *
1081
+	 * @param array $req_data like $_POST
1082
+	 * @return boolean
1083
+	 * @throws \EE_Error
1084
+	 */
1085
+	public function form_data_present_in($req_data = null)
1086
+	{
1087
+		if ($req_data === null) {
1088
+			$req_data = $_POST;
1089
+		}
1090
+		$checked_value = $this->find_form_data_for_this_section($req_data);
1091
+		if ($checked_value !== null) {
1092
+			return true;
1093
+		} else {
1094
+			return false;
1095
+		}
1096
+	}
1097
+
1098
+
1099
+
1100
+	/**
1101
+	 * Overrides parent to add js data from validation and display strategies
1102
+	 *
1103
+	 * @param array $form_other_js_data
1104
+	 * @return array
1105
+	 */
1106
+	public function get_other_js_data($form_other_js_data = array())
1107
+	{
1108
+		$form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data);
1109
+		return $form_other_js_data;
1110
+	}
1111
+
1112
+
1113
+
1114
+	/**
1115
+	 * Gets other JS data for localization from this input's strategies, like
1116
+	 * the validation strategies and the display strategy
1117
+	 *
1118
+	 * @param array $form_other_js_data
1119
+	 * @return array
1120
+	 */
1121
+	public function get_other_js_data_from_strategies($form_other_js_data = array())
1122
+	{
1123
+		$form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data);
1124
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
1125
+			$form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data);
1126
+		}
1127
+		return $form_other_js_data;
1128
+	}
1129
+
1130
+
1131
+
1132
+	/**
1133
+	 * Override parent because we want to give our strategies an opportunity to enqueue some js and css
1134
+	 *
1135
+	 * @return void
1136
+	 */
1137
+	public function enqueue_js()
1138
+	{
1139
+		//ask our display strategy and validation strategies if they have js to enqueue
1140
+		$this->enqueue_js_from_strategies();
1141
+	}
1142
+
1143
+
1144
+
1145
+	/**
1146
+	 * Tells strategies when its ok to enqueue their js and css
1147
+	 *
1148
+	 * @return void
1149
+	 */
1150
+	public function enqueue_js_from_strategies()
1151
+	{
1152
+		$this->get_display_strategy()->enqueue_js();
1153
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
1154
+			$validation_strategy->enqueue_js();
1155
+		}
1156
+	}
1157 1157
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
@@ -179,10 +179,10 @@  discard block
 block discarded – undo
179 179
      */
180 180
     public function __construct($input_args = array())
181 181
     {
182
-        $input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this);
182
+        $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this);
183 183
         // the following properties must be cast as arrays
184 184
         if (isset($input_args['validation_strategies'])) {
185
-            foreach ((array)$input_args['validation_strategies'] as $validation_strategy) {
185
+            foreach ((array) $input_args['validation_strategies'] as $validation_strategy) {
186 186
                 if ($validation_strategy instanceof EE_Validation_Strategy_Base) {
187 187
                     $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy;
188 188
                 }
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
         // loop thru incoming options
193 193
         foreach ($input_args as $key => $value) {
194 194
             // add underscore to $key to match property names
195
-            $_key = '_' . $key;
195
+            $_key = '_'.$key;
196 196
             if (property_exists($this, $_key)) {
197 197
                 $this->{$_key} = $value;
198 198
             }
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
         foreach ($this->_validation_strategies as $validation_strategy) {
209 209
             $validation_strategy->_construct_finalize($this);
210 210
         }
211
-        if (! $this->_normalization_strategy) {
211
+        if ( ! $this->_normalization_strategy) {
212 212
             $this->_normalization_strategy = new EE_Text_Normalization();
213 213
         }
214 214
         $this->_normalization_strategy->_construct_finalize($this);
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
         if (isset($input_args['default'])) {
217 217
             $this->set_default($input_args['default']);
218 218
         }
219
-        if (! $this->_sensitive_data_removal_strategy) {
219
+        if ( ! $this->_sensitive_data_removal_strategy) {
220 220
             $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
221 221
         }
222 222
         $this->_sensitive_data_removal_strategy->_construct_finalize($this);
@@ -233,10 +233,10 @@  discard block
 block discarded – undo
233 233
      */
234 234
     protected function _set_default_html_name_if_empty()
235 235
     {
236
-        if (! $this->_html_name) {
236
+        if ( ! $this->_html_name) {
237 237
             $this->_html_name = $this->name();
238 238
             if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
239
-                $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
239
+                $this->_html_name = $this->_parent_section->html_name_prefix()."[{$this->name()}]";
240 240
             }
241 241
         }
242 242
     }
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
     protected function _get_display_strategy()
269 269
     {
270 270
         $this->ensure_construct_finalized_called();
271
-        if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
271
+        if ( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
272 272
             throw new EE_Error(
273 273
                 sprintf(
274 274
                     __(
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
      */
502 502
     public function html_other_attributes()
503 503
     {
504
-        return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : '';
504
+        return ! empty($this->_html_other_attributes) ? ' '.$this->_html_other_attributes : '';
505 505
     }
506 506
 
507 507
 
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
      */
646 646
     public function html_label_id()
647 647
     {
648
-        return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl';
648
+        return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id().'-lbl';
649 649
     }
650 650
 
651 651
 
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
                 $validation_strategy->get_jquery_validation_rule_array()
796 796
             );
797 797
         }
798
-        if (! empty($jquery_validation_rules)) {
798
+        if ( ! empty($jquery_validation_rules)) {
799 799
             foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
800 800
                 $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules;
801 801
             }
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
     public function html_class($add_required = false)
919 919
     {
920 920
         return $add_required && $this->required()
921
-            ? $this->required_css_class() . ' ' . $this->_html_class
921
+            ? $this->required_css_class().' '.$this->_html_class
922 922
             : $this->_html_class;
923 923
     }
924 924
 
@@ -992,7 +992,7 @@  discard block
 block discarded – undo
992 992
                 $button_css_attributes .= '';
993 993
         }
994 994
         $this->_button_css_attributes .= ! empty($other_attributes)
995
-            ? $button_css_attributes . ' ' . $other_attributes
995
+            ? $button_css_attributes.' '.$other_attributes
996 996
             : $button_css_attributes;
997 997
     }
998 998
 
Please login to merge, or discard this patch.
core/libraries/rest_api/controllers/config/Read.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 namespace EventEspresso\core\libraries\rest_api\controllers\config;
3 3
 
4 4
 if (! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -18,74 +18,74 @@  discard block
 block discarded – undo
18 18
 class Read
19 19
 {
20 20
 
21
-    /**
22
-     * @param \WP_REST_Request $request
23
-     * @return \EE_Config|\WP_Error
24
-     */
25
-    public static function handle_request(\WP_REST_Request $request)
26
-    {
27
-        $cap = \EE_Restriction_Generator_Base::get_default_restrictions_cap();
28
-        if (\EE_Capabilities::instance()->current_user_can($cap, 'read_over_api')) {
29
-            return \EE_Config::instance();
30
-        } else {
31
-            return new \WP_Error(
32
-                'cannot_read_config',
33
-                sprintf(
34
-                    __(
35
-                        'You do not have the necessary capabilities (%s) to read Event Espresso Configuration data',
36
-                        'event_espresso'
37
-                    ),
38
-                    $cap
39
-                ),
40
-                array('status' => 403)
41
-            );
42
-        }
43
-    }
21
+	/**
22
+	 * @param \WP_REST_Request $request
23
+	 * @return \EE_Config|\WP_Error
24
+	 */
25
+	public static function handle_request(\WP_REST_Request $request)
26
+	{
27
+		$cap = \EE_Restriction_Generator_Base::get_default_restrictions_cap();
28
+		if (\EE_Capabilities::instance()->current_user_can($cap, 'read_over_api')) {
29
+			return \EE_Config::instance();
30
+		} else {
31
+			return new \WP_Error(
32
+				'cannot_read_config',
33
+				sprintf(
34
+					__(
35
+						'You do not have the necessary capabilities (%s) to read Event Espresso Configuration data',
36
+						'event_espresso'
37
+					),
38
+					$cap
39
+				),
40
+				array('status' => 403)
41
+			);
42
+		}
43
+	}
44 44
 
45 45
 
46 46
 
47
-    /**
48
-     * Handles the request for public site info
49
-     *
50
-     * @global                 $wp_json_basic_auth_success       boolean set by the basic auth plugin, indicates if the
51
-     *                         current user could be authenticated using basic auth data
52
-     * @global                 $wp_json_basic_auth_received_data boolean set by the basic auth plugin, indicates if
53
-     *                         basic auth data was somehow received
54
-     * @param \WP_REST_Request $request
55
-     * @return \EE_Config|\WP_Error
56
-     */
57
-    public static function handle_request_site_info(\WP_REST_Request $request)
58
-    {
59
-        global $wp_json_basic_auth_success, $wp_json_basic_auth_received_data;
60
-        $insecure_usage_of_basic_auth = apply_filters(
61
-            'EventEspresso__core__libraries__rest_api__controllers__config__handle_request_site_info__insecure_usage_of_basic_auth',
62
-            $wp_json_basic_auth_success && ! is_ssl(),
63
-            $request
64
-        );
65
-        if ($insecure_usage_of_basic_auth) {
66
-            $warning = sprintf(
67
-                esc_html__('Notice: We strongly recommend installing an SSL Certificate on your website to keep your data secure. %1$sPlease see our recommendations.%2$s',
68
-                    'event_espresso'),
69
-                '<a href="https://eventespresso.com/wiki/rest-api-security-recommendations/">',
70
-                '</a>'
71
-            );
72
-        } else {
73
-            $warning = '';
74
-        }
75
-        return array(
76
-            'default_timezone' => array(
77
-                'pretty' => \EEH_DTT_Helper::get_timezone_string_for_display(),
78
-                'string' => get_option('timezone_string'),
79
-                'offset' => \EEH_DTT_Helper::get_site_timezone_gmt_offset(),
80
-            ),
81
-            'default_currency' => \EE_Config::instance()->currency,
82
-            'authentication'   => array(
83
-                'received_basic_auth_data'     => (bool)$wp_json_basic_auth_received_data,
84
-                'insecure_usage_of_basic_auth' => (bool)$insecure_usage_of_basic_auth,
85
-                'warning'                      => $warning
86
-            )
87
-        );
88
-    }
47
+	/**
48
+	 * Handles the request for public site info
49
+	 *
50
+	 * @global                 $wp_json_basic_auth_success       boolean set by the basic auth plugin, indicates if the
51
+	 *                         current user could be authenticated using basic auth data
52
+	 * @global                 $wp_json_basic_auth_received_data boolean set by the basic auth plugin, indicates if
53
+	 *                         basic auth data was somehow received
54
+	 * @param \WP_REST_Request $request
55
+	 * @return \EE_Config|\WP_Error
56
+	 */
57
+	public static function handle_request_site_info(\WP_REST_Request $request)
58
+	{
59
+		global $wp_json_basic_auth_success, $wp_json_basic_auth_received_data;
60
+		$insecure_usage_of_basic_auth = apply_filters(
61
+			'EventEspresso__core__libraries__rest_api__controllers__config__handle_request_site_info__insecure_usage_of_basic_auth',
62
+			$wp_json_basic_auth_success && ! is_ssl(),
63
+			$request
64
+		);
65
+		if ($insecure_usage_of_basic_auth) {
66
+			$warning = sprintf(
67
+				esc_html__('Notice: We strongly recommend installing an SSL Certificate on your website to keep your data secure. %1$sPlease see our recommendations.%2$s',
68
+					'event_espresso'),
69
+				'<a href="https://eventespresso.com/wiki/rest-api-security-recommendations/">',
70
+				'</a>'
71
+			);
72
+		} else {
73
+			$warning = '';
74
+		}
75
+		return array(
76
+			'default_timezone' => array(
77
+				'pretty' => \EEH_DTT_Helper::get_timezone_string_for_display(),
78
+				'string' => get_option('timezone_string'),
79
+				'offset' => \EEH_DTT_Helper::get_site_timezone_gmt_offset(),
80
+			),
81
+			'default_currency' => \EE_Config::instance()->currency,
82
+			'authentication'   => array(
83
+				'received_basic_auth_data'     => (bool)$wp_json_basic_auth_received_data,
84
+				'insecure_usage_of_basic_auth' => (bool)$insecure_usage_of_basic_auth,
85
+				'warning'                      => $warning
86
+			)
87
+		);
88
+	}
89 89
 }
90 90
 
91 91
 // End of file Read.php
92 92
\ No newline at end of file
Please login to merge, or discard this patch.
admin_pages/events/qtips/EE_Event_Editor_Decaf_Tips.lib.php 1 patch
Indentation   +357 added lines, -357 removed lines patch added patch discarded remove patch
@@ -13,386 +13,386 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * Creates the array for the tips
18
-     */
19
-    protected function _set_tips_array()
20
-    {
21
-        $this->_qtipsa = array(
22
-            2   => array(
23
-                'content_id' => 'dtt-evt-name-label',
24
-                'target'     => '.DTT_name_label',
25
-                'content'    => $this->_get_event_name_label_info(),
26
-            ),
27
-            3   => array(
28
-                'content_id' => 'dtt-evt-start-label',
29
-                'target'     => '.DTT_EVT_start_label',
30
-                'content'    => $this->_get_event_start_label_info(),
31
-            ),
32
-            5   => array(
33
-                'content_id' => 'dtt-evt-end-label',
34
-                'target'     => '.DTT_EVT_end_label',
35
-                'content'    => $this->_get_event_end_label_info(),
36
-            ),
37
-            10  => array(
38
-                'content_id' => 'dtt-reg-limit-label',
39
-                'target'     => '.DTT_reg_limit_label',
40
-                'content'    => $this->_get_event_datetime_DTT_reg_limit_label_info(),
41
-            ),
42
-            15  => array(
43
-                'content_id' => 'dtt-sold-label',
44
-                'target'     => '.DTT_sold_label',
45
-                'content'    => $this->_get_event_datetime_DTT_sold_label_info(),
46
-            ),
47
-            17  => array(
48
-                'content_id' => 'dtt-reserved-label',
49
-                'target'     => '.DTT_reserved_label',
50
-                'content'    => $this->_get_event_datetime_DTT_reserved_label_info(),
51
-            ),
52
-            20  => array(
53
-                'content_id' => 'tkt-name-label',
54
-                'target'     => '.TKT_name_label',
55
-                'content'    => $this->_get_event_ticket_TKT_name_label_info(),
56
-            ),
57
-            25  => array(
58
-                'content_id' => 'tkt-goes-on-sale-label',
59
-                'target'     => '.TKT_goes_on_sale_label',
60
-                'content'    => $this->_get_event_ticket_TKT_goes_on_sale_label_info(),
61
-            ),
62
-            30  => array(
63
-                'content_id' => 'tkt-sell-until-label',
64
-                'target'     => '.TKT_sell_until_label',
65
-                'content'    => $this->_get_event_ticket_TKT_sell_until_label_info(),
66
-            ),
67
-            35  => array(
68
-                'content_id' => 'tkt-price-label',
69
-                'target'     => '.TKT_price_label',
70
-                'content'    => $this->_get_event_ticket_TKT_price_label_info(),
71
-            ),
72
-            40  => array(
73
-                'content_id' => 'tkt-qty-label',
74
-                'target'     => '.TKT_qty_label',
75
-                'content'    => $this->_get_event_ticket_TKT_qty_label_info(),
76
-            ),
77
-            45  => array(
78
-                'content_id' => 'tkt-sold-label',
79
-                'target'     => '.TKT_sold_label',
80
-                'content'    => $this->_get_event_ticket_TKT_sold_label_info(),
81
-            ),
82
-            47  => array(
83
-                'content_id' => 'tkt-reserved-label',
84
-                'target'     => '.TKT_reserved_label',
85
-                'content'    => $this->_get_event_ticket_TKT_reserved_label_info(),
86
-            ),
87
-            50  => array(
88
-                'content_id' => 'tkt-regs-label',
89
-                'target'     => '.TKT_regs_label',
90
-                'content'    => $this->_get_event_ticket_TKT_regs_label_info(),
91
-            ),
92
-            55  => array(
93
-                'content_id' => 'ant-tkt-name-label',
94
-                'target'     => '.ANT_TKT_name_label',
95
-                'content'    => $this->_get_event_ticket_ANT_TKT_name_label_info(),
96
-            ),
97
-            60  => array(
98
-                'content_id' => 'ant-tkt-goes-on-sale-label',
99
-                'target'     => '.ANT_TKT_goes_on_sale_label',
100
-                'content'    => $this->_get_event_ticket_ANT_TKT_goes_on_sale_label_info(),
101
-            ),
102
-            65  => array(
103
-                'content_id' => 'ant-tkt-sell-until-label',
104
-                'target'     => '.ANT_TKT_sell_until_label',
105
-                'content'    => $this->_get_event_ticket_ANT_TKT_sell_until_label_info(),
106
-            ),
107
-            70  => array(
108
-                'content_id' => 'ant-tkt-price-label',
109
-                'target'     => '.ANT_TKT_price_label',
110
-                'content'    => $this->_get_event_ticket_ANT_TKT_price_label_info(),
111
-            ),
112
-            75  => array(
113
-                'content_id' => 'ant-tkt-qty-label',
114
-                'target'     => '.ANT_TKT_qty_label',
115
-                'content'    => $this->_get_event_ticket_ANT_TKT_qty_label_info(),
116
-            ),
117
-            80  => array(
118
-                'content_id' => 'ane-dtt-evt-start-label',
119
-                'target'     => '.add-new-event-datetime-DTT_EVT_start_label',
120
-                'content'    => $this->_get_add_new_event_start_label_info(),
121
-            ),
122
-            85  => array(
123
-                'content_id' => 'ane-dtt-evt-end-label',
124
-                'target'     => '.add-new-event-datetime-DTT_EVT_end_label',
125
-                'content'    => $this->_get_add_new_event_end_label_info(),
126
-            ),
127
-            90  => array(
128
-                'content_id' => 'ane_dtt-reg-limit-label',
129
-                'target'     => '.add-new-event-datetime-DTT_reg_limit_label',
130
-                'content'    => $this->_get_add_new_event_datetime_DTT_reg_limit_label_info(),
131
-            ),
132
-            100 => array(
133
-                'content_id' => 'td-tkt-number-datetimes-label',
134
-                'target'     => '.TD_TKT_number_datetimes_label',
135
-                'content'    => $this->_get_event_ticket_TD_TKT_number_datetimes_label_info(),
136
-            ),
137
-            110 => array(
138
-                'content_id' => 'td-tkt-min-qty-label',
139
-                'target'     => '.TD_TKT_min_qty_label',
140
-                'content'    => $this->_get_event_ticket_TD_TKT_min_qty_label_info(),
141
-            ),
142
-            120 => array(
143
-                'content_id' => 'td-tkt-max-qty-label',
144
-                'target'     => '.TD_TKT_max_qty_label',
145
-                'content'    => $this->_get_event_ticket_TD_TKT_max_qty_label_info(),
146
-            ),
147
-            130 => array(
148
-                'content_id' => 'ticket-lock-icon',
149
-                'target'     => '.ticket-archived .ee-lock-icon',
150
-                'content'    => esc_html__(
151
-                    'This ticket was automatically locked and archived because it has a sold quantity and the price was modified. Existing ticket holders will still be verified using these ticket details. However, Event Espresso has automatically created a new active ticket with the modified price for new registrants. This lock is meant to prevent accidental trashing of this ticket. Certain details of this ticket can still be edited (non disabled inputs).',
152
-                    'event_espresso'
153
-                ),
154
-            ),
155
-            135 => array(
156
-                'content_id' => 'ticket-lock-icon-event-editor',
157
-                'target'     => '.ee-lock-icon',
158
-                'content'    => esc_html__(
159
-                    'This datetime can no longer be duplicated or deleted because tickets associated with this datetime have already been sold.',
160
-                    'event_espresso'
161
-                ),
162
-            ),
163
-        );
164
-    }
16
+	/**
17
+	 * Creates the array for the tips
18
+	 */
19
+	protected function _set_tips_array()
20
+	{
21
+		$this->_qtipsa = array(
22
+			2   => array(
23
+				'content_id' => 'dtt-evt-name-label',
24
+				'target'     => '.DTT_name_label',
25
+				'content'    => $this->_get_event_name_label_info(),
26
+			),
27
+			3   => array(
28
+				'content_id' => 'dtt-evt-start-label',
29
+				'target'     => '.DTT_EVT_start_label',
30
+				'content'    => $this->_get_event_start_label_info(),
31
+			),
32
+			5   => array(
33
+				'content_id' => 'dtt-evt-end-label',
34
+				'target'     => '.DTT_EVT_end_label',
35
+				'content'    => $this->_get_event_end_label_info(),
36
+			),
37
+			10  => array(
38
+				'content_id' => 'dtt-reg-limit-label',
39
+				'target'     => '.DTT_reg_limit_label',
40
+				'content'    => $this->_get_event_datetime_DTT_reg_limit_label_info(),
41
+			),
42
+			15  => array(
43
+				'content_id' => 'dtt-sold-label',
44
+				'target'     => '.DTT_sold_label',
45
+				'content'    => $this->_get_event_datetime_DTT_sold_label_info(),
46
+			),
47
+			17  => array(
48
+				'content_id' => 'dtt-reserved-label',
49
+				'target'     => '.DTT_reserved_label',
50
+				'content'    => $this->_get_event_datetime_DTT_reserved_label_info(),
51
+			),
52
+			20  => array(
53
+				'content_id' => 'tkt-name-label',
54
+				'target'     => '.TKT_name_label',
55
+				'content'    => $this->_get_event_ticket_TKT_name_label_info(),
56
+			),
57
+			25  => array(
58
+				'content_id' => 'tkt-goes-on-sale-label',
59
+				'target'     => '.TKT_goes_on_sale_label',
60
+				'content'    => $this->_get_event_ticket_TKT_goes_on_sale_label_info(),
61
+			),
62
+			30  => array(
63
+				'content_id' => 'tkt-sell-until-label',
64
+				'target'     => '.TKT_sell_until_label',
65
+				'content'    => $this->_get_event_ticket_TKT_sell_until_label_info(),
66
+			),
67
+			35  => array(
68
+				'content_id' => 'tkt-price-label',
69
+				'target'     => '.TKT_price_label',
70
+				'content'    => $this->_get_event_ticket_TKT_price_label_info(),
71
+			),
72
+			40  => array(
73
+				'content_id' => 'tkt-qty-label',
74
+				'target'     => '.TKT_qty_label',
75
+				'content'    => $this->_get_event_ticket_TKT_qty_label_info(),
76
+			),
77
+			45  => array(
78
+				'content_id' => 'tkt-sold-label',
79
+				'target'     => '.TKT_sold_label',
80
+				'content'    => $this->_get_event_ticket_TKT_sold_label_info(),
81
+			),
82
+			47  => array(
83
+				'content_id' => 'tkt-reserved-label',
84
+				'target'     => '.TKT_reserved_label',
85
+				'content'    => $this->_get_event_ticket_TKT_reserved_label_info(),
86
+			),
87
+			50  => array(
88
+				'content_id' => 'tkt-regs-label',
89
+				'target'     => '.TKT_regs_label',
90
+				'content'    => $this->_get_event_ticket_TKT_regs_label_info(),
91
+			),
92
+			55  => array(
93
+				'content_id' => 'ant-tkt-name-label',
94
+				'target'     => '.ANT_TKT_name_label',
95
+				'content'    => $this->_get_event_ticket_ANT_TKT_name_label_info(),
96
+			),
97
+			60  => array(
98
+				'content_id' => 'ant-tkt-goes-on-sale-label',
99
+				'target'     => '.ANT_TKT_goes_on_sale_label',
100
+				'content'    => $this->_get_event_ticket_ANT_TKT_goes_on_sale_label_info(),
101
+			),
102
+			65  => array(
103
+				'content_id' => 'ant-tkt-sell-until-label',
104
+				'target'     => '.ANT_TKT_sell_until_label',
105
+				'content'    => $this->_get_event_ticket_ANT_TKT_sell_until_label_info(),
106
+			),
107
+			70  => array(
108
+				'content_id' => 'ant-tkt-price-label',
109
+				'target'     => '.ANT_TKT_price_label',
110
+				'content'    => $this->_get_event_ticket_ANT_TKT_price_label_info(),
111
+			),
112
+			75  => array(
113
+				'content_id' => 'ant-tkt-qty-label',
114
+				'target'     => '.ANT_TKT_qty_label',
115
+				'content'    => $this->_get_event_ticket_ANT_TKT_qty_label_info(),
116
+			),
117
+			80  => array(
118
+				'content_id' => 'ane-dtt-evt-start-label',
119
+				'target'     => '.add-new-event-datetime-DTT_EVT_start_label',
120
+				'content'    => $this->_get_add_new_event_start_label_info(),
121
+			),
122
+			85  => array(
123
+				'content_id' => 'ane-dtt-evt-end-label',
124
+				'target'     => '.add-new-event-datetime-DTT_EVT_end_label',
125
+				'content'    => $this->_get_add_new_event_end_label_info(),
126
+			),
127
+			90  => array(
128
+				'content_id' => 'ane_dtt-reg-limit-label',
129
+				'target'     => '.add-new-event-datetime-DTT_reg_limit_label',
130
+				'content'    => $this->_get_add_new_event_datetime_DTT_reg_limit_label_info(),
131
+			),
132
+			100 => array(
133
+				'content_id' => 'td-tkt-number-datetimes-label',
134
+				'target'     => '.TD_TKT_number_datetimes_label',
135
+				'content'    => $this->_get_event_ticket_TD_TKT_number_datetimes_label_info(),
136
+			),
137
+			110 => array(
138
+				'content_id' => 'td-tkt-min-qty-label',
139
+				'target'     => '.TD_TKT_min_qty_label',
140
+				'content'    => $this->_get_event_ticket_TD_TKT_min_qty_label_info(),
141
+			),
142
+			120 => array(
143
+				'content_id' => 'td-tkt-max-qty-label',
144
+				'target'     => '.TD_TKT_max_qty_label',
145
+				'content'    => $this->_get_event_ticket_TD_TKT_max_qty_label_info(),
146
+			),
147
+			130 => array(
148
+				'content_id' => 'ticket-lock-icon',
149
+				'target'     => '.ticket-archived .ee-lock-icon',
150
+				'content'    => esc_html__(
151
+					'This ticket was automatically locked and archived because it has a sold quantity and the price was modified. Existing ticket holders will still be verified using these ticket details. However, Event Espresso has automatically created a new active ticket with the modified price for new registrants. This lock is meant to prevent accidental trashing of this ticket. Certain details of this ticket can still be edited (non disabled inputs).',
152
+					'event_espresso'
153
+				),
154
+			),
155
+			135 => array(
156
+				'content_id' => 'ticket-lock-icon-event-editor',
157
+				'target'     => '.ee-lock-icon',
158
+				'content'    => esc_html__(
159
+					'This datetime can no longer be duplicated or deleted because tickets associated with this datetime have already been sold.',
160
+					'event_espresso'
161
+				),
162
+			),
163
+		);
164
+	}
165 165
 
166
-    /**
167
-     * @return string
168
-     */
169
-    private function _get_event_name_label_info()
170
-    {
171
-        return esc_html__(
172
-            'This is the name or title for an event datetime.',
173
-            'event_espresso'
174
-        );
175
-    }
166
+	/**
167
+	 * @return string
168
+	 */
169
+	private function _get_event_name_label_info()
170
+	{
171
+		return esc_html__(
172
+			'This is the name or title for an event datetime.',
173
+			'event_espresso'
174
+		);
175
+	}
176 176
 
177
-    /**
178
-     * @return string
179
-     */
180
-    private function _get_event_start_label_info()
181
-    {
182
-        return esc_html__(
183
-            'This shows when this event datetime starts.',
184
-            'event_espresso'
185
-        );
186
-    }
177
+	/**
178
+	 * @return string
179
+	 */
180
+	private function _get_event_start_label_info()
181
+	{
182
+		return esc_html__(
183
+			'This shows when this event datetime starts.',
184
+			'event_espresso'
185
+		);
186
+	}
187 187
 
188
-    /**
189
-     * @return string
190
-     */
191
-    private function _get_event_end_label_info()
192
-    {
193
-        return esc_html__('This shows when this event datetime ends.', 'event_espresso');
194
-    }
188
+	/**
189
+	 * @return string
190
+	 */
191
+	private function _get_event_end_label_info()
192
+	{
193
+		return esc_html__('This shows when this event datetime ends.', 'event_espresso');
194
+	}
195 195
 
196
-    /**
197
-     * @return string
198
-     */
199
-    private function _get_event_datetime_DTT_reg_limit_label_info()
200
-    {
201
-        return esc_html__(
202
-            'This field allows you to set a maximum number of tickets that you want to make available for an event datetime.',
203
-            'event_espresso'
204
-        );
205
-    }
196
+	/**
197
+	 * @return string
198
+	 */
199
+	private function _get_event_datetime_DTT_reg_limit_label_info()
200
+	{
201
+		return esc_html__(
202
+			'This field allows you to set a maximum number of tickets that you want to make available for an event datetime.',
203
+			'event_espresso'
204
+		);
205
+	}
206 206
 
207
-    /**
208
-     * @return string
209
-     */
210
-    private function _get_event_datetime_DTT_sold_label_info()
211
-    {
212
-        return esc_html__(
213
-            'This shows the number of tickets that have been sold that have access to this event datetime.',
214
-            'event_espresso'
215
-        );
216
-    }
207
+	/**
208
+	 * @return string
209
+	 */
210
+	private function _get_event_datetime_DTT_sold_label_info()
211
+	{
212
+		return esc_html__(
213
+			'This shows the number of tickets that have been sold that have access to this event datetime.',
214
+			'event_espresso'
215
+		);
216
+	}
217 217
 
218
-    /**
219
-     * @return string
220
-     */
221
-    private function _get_event_datetime_DTT_reserved_label_info()
222
-    {
223
-        return esc_html__(
224
-            'This shows the number of reserved tickets that have access to this event datetime.',
225
-            'event_espresso'
226
-        );
227
-    }
218
+	/**
219
+	 * @return string
220
+	 */
221
+	private function _get_event_datetime_DTT_reserved_label_info()
222
+	{
223
+		return esc_html__(
224
+			'This shows the number of reserved tickets that have access to this event datetime.',
225
+			'event_espresso'
226
+		);
227
+	}
228 228
 
229
-    /**
230
-     * @return string
231
-     */
232
-    private function _get_event_ticket_TKT_name_label_info()
233
-    {
234
-        return esc_html__('This is the name of this ticket option.', 'event_espresso');
235
-    }
229
+	/**
230
+	 * @return string
231
+	 */
232
+	private function _get_event_ticket_TKT_name_label_info()
233
+	{
234
+		return esc_html__('This is the name of this ticket option.', 'event_espresso');
235
+	}
236 236
 
237
-    /**
238
-     * @return string
239
-     */
240
-    private function _get_event_ticket_TKT_goes_on_sale_label_info()
241
-    {
242
-        return esc_html__('This shows when the first ticket is available for sale.', 'event_espresso');
243
-    }
237
+	/**
238
+	 * @return string
239
+	 */
240
+	private function _get_event_ticket_TKT_goes_on_sale_label_info()
241
+	{
242
+		return esc_html__('This shows when the first ticket is available for sale.', 'event_espresso');
243
+	}
244 244
 
245
-    /**
246
-     * @return string
247
-     */
248
-    private function _get_event_ticket_TKT_sell_until_label_info()
249
-    {
250
-        return esc_html__('This shows the date that ticket sales end for this ticket.', 'event_espresso');
251
-    }
245
+	/**
246
+	 * @return string
247
+	 */
248
+	private function _get_event_ticket_TKT_sell_until_label_info()
249
+	{
250
+		return esc_html__('This shows the date that ticket sales end for this ticket.', 'event_espresso');
251
+	}
252 252
 
253
-    /**
254
-     * @return string
255
-     */
256
-    private function _get_event_ticket_TKT_price_label_info()
257
-    {
258
-        return esc_html__('This is the price for this ticket.', 'event_espresso');
259
-    }
253
+	/**
254
+	 * @return string
255
+	 */
256
+	private function _get_event_ticket_TKT_price_label_info()
257
+	{
258
+		return esc_html__('This is the price for this ticket.', 'event_espresso');
259
+	}
260 260
 
261
-    /**
262
-     * @return string
263
-     */
264
-    private function _get_event_ticket_TKT_qty_label_info()
265
-    {
266
-        return esc_html__(
267
-            'This field shows the quantity of tickets that are available for this type of ticket.',
268
-            'event_espresso'
269
-        );
270
-    }
261
+	/**
262
+	 * @return string
263
+	 */
264
+	private function _get_event_ticket_TKT_qty_label_info()
265
+	{
266
+		return esc_html__(
267
+			'This field shows the quantity of tickets that are available for this type of ticket.',
268
+			'event_espresso'
269
+		);
270
+	}
271 271
 
272
-    /**
273
-     * @return string
274
-     */
275
-    private function _get_event_ticket_TKT_sold_label_info()
276
-    {
277
-        return esc_html__('This shows the number of tickets that have been sold for this ticket.', 'event_espresso');
278
-    }
272
+	/**
273
+	 * @return string
274
+	 */
275
+	private function _get_event_ticket_TKT_sold_label_info()
276
+	{
277
+		return esc_html__('This shows the number of tickets that have been sold for this ticket.', 'event_espresso');
278
+	}
279 279
 
280
-    /**
281
-     * @return string
282
-     */
283
-    private function _get_event_ticket_TKT_reserved_label_info()
284
-    {
285
-        return esc_html__('This shows the number of tickets that are reserved for this ticket.', 'event_espresso');
286
-    }
280
+	/**
281
+	 * @return string
282
+	 */
283
+	private function _get_event_ticket_TKT_reserved_label_info()
284
+	{
285
+		return esc_html__('This shows the number of tickets that are reserved for this ticket.', 'event_espresso');
286
+	}
287 287
 
288
-    /**
289
-     * @return string
290
-     */
291
-    private function _get_event_ticket_TKT_regs_label_info()
292
-    {
293
-        return esc_html__(
294
-            'This shows the number of registrations that have occurred from ticket sales.',
295
-            'event_espresso'
296
-        );
297
-    }
288
+	/**
289
+	 * @return string
290
+	 */
291
+	private function _get_event_ticket_TKT_regs_label_info()
292
+	{
293
+		return esc_html__(
294
+			'This shows the number of registrations that have occurred from ticket sales.',
295
+			'event_espresso'
296
+		);
297
+	}
298 298
 
299
-    /**
300
-     * @return string
301
-     */
302
-    private function _get_event_ticket_ANT_TKT_name_label_info()
303
-    {
304
-        return esc_html__('This is the name of this ticket option.', 'event_espresso');
305
-    }
299
+	/**
300
+	 * @return string
301
+	 */
302
+	private function _get_event_ticket_ANT_TKT_name_label_info()
303
+	{
304
+		return esc_html__('This is the name of this ticket option.', 'event_espresso');
305
+	}
306 306
 
307
-    /**
308
-     * @return string
309
-     */
310
-    private function _get_event_ticket_ANT_TKT_goes_on_sale_label_info()
311
-    {
312
-        return esc_html__('This shows when the first ticket is available for sale.', 'event_espresso');
313
-    }
307
+	/**
308
+	 * @return string
309
+	 */
310
+	private function _get_event_ticket_ANT_TKT_goes_on_sale_label_info()
311
+	{
312
+		return esc_html__('This shows when the first ticket is available for sale.', 'event_espresso');
313
+	}
314 314
 
315
-    /**
316
-     * @return string
317
-     */
318
-    private function _get_event_ticket_ANT_TKT_sell_until_label_info()
319
-    {
320
-        return esc_html__('This shows the date that ticket sales end for this ticket.', 'event_espresso');
321
-    }
315
+	/**
316
+	 * @return string
317
+	 */
318
+	private function _get_event_ticket_ANT_TKT_sell_until_label_info()
319
+	{
320
+		return esc_html__('This shows the date that ticket sales end for this ticket.', 'event_espresso');
321
+	}
322 322
 
323
-    /**
324
-     * @return string
325
-     */
326
-    private function _get_event_ticket_ANT_TKT_price_label_info()
327
-    {
328
-        return esc_html__('This is the price for this ticket.', 'event_espresso');
329
-    }
323
+	/**
324
+	 * @return string
325
+	 */
326
+	private function _get_event_ticket_ANT_TKT_price_label_info()
327
+	{
328
+		return esc_html__('This is the price for this ticket.', 'event_espresso');
329
+	}
330 330
 
331
-    /**
332
-     * @return string
333
-     */
334
-    private function _get_event_ticket_ANT_TKT_qty_label_info()
335
-    {
336
-        return esc_html__(
337
-            'This field shows the quantity of tickets that are available for this type of ticket.',
338
-            'event_espresso'
339
-        );
340
-    }
331
+	/**
332
+	 * @return string
333
+	 */
334
+	private function _get_event_ticket_ANT_TKT_qty_label_info()
335
+	{
336
+		return esc_html__(
337
+			'This field shows the quantity of tickets that are available for this type of ticket.',
338
+			'event_espresso'
339
+		);
340
+	}
341 341
 
342
-    /**
343
-     * @return string
344
-     */
345
-    private function _get_add_new_event_start_label_info()
346
-    {
347
-        return esc_html__('This shows when this event datetime starts.', 'event_espresso');
348
-    }
342
+	/**
343
+	 * @return string
344
+	 */
345
+	private function _get_add_new_event_start_label_info()
346
+	{
347
+		return esc_html__('This shows when this event datetime starts.', 'event_espresso');
348
+	}
349 349
 
350
-    /**
351
-     * @return string
352
-     */
353
-    private function _get_add_new_event_end_label_info()
354
-    {
355
-        return esc_html__('This shows when this event datetime ends.', 'event_espresso');
356
-    }
350
+	/**
351
+	 * @return string
352
+	 */
353
+	private function _get_add_new_event_end_label_info()
354
+	{
355
+		return esc_html__('This shows when this event datetime ends.', 'event_espresso');
356
+	}
357 357
 
358
-    /**
359
-     * @return string
360
-     */
361
-    private function _get_add_new_event_datetime_DTT_reg_limit_label_info()
362
-    {
363
-        return esc_html__(
364
-            'This field allows you to set a maximum number of tickets that you want to make available for an event datetime.',
365
-            'event_espresso'
366
-        );
367
-    }
358
+	/**
359
+	 * @return string
360
+	 */
361
+	private function _get_add_new_event_datetime_DTT_reg_limit_label_info()
362
+	{
363
+		return esc_html__(
364
+			'This field allows you to set a maximum number of tickets that you want to make available for an event datetime.',
365
+			'event_espresso'
366
+		);
367
+	}
368 368
 
369
-    /**
370
-     * @return string
371
-     */
372
-    private function _get_event_ticket_TD_TKT_number_datetimes_label_info()
373
-    {
374
-        return esc_html__(
375
-            'This field allows you to set the number of datetimes that a ticket should have access to.',
376
-            'event_espresso'
377
-        );
378
-    }
369
+	/**
370
+	 * @return string
371
+	 */
372
+	private function _get_event_ticket_TD_TKT_number_datetimes_label_info()
373
+	{
374
+		return esc_html__(
375
+			'This field allows you to set the number of datetimes that a ticket should have access to.',
376
+			'event_espresso'
377
+		);
378
+	}
379 379
 
380
-    /**
381
-     * @return string
382
-     */
383
-    private function _get_event_ticket_TD_TKT_min_qty_label_info()
384
-    {
385
-        return esc_html__(
386
-            'This shows the minimum quantity that can be purchased for this ticket.',
387
-            'event_espresso'
388
-        );
389
-    }
380
+	/**
381
+	 * @return string
382
+	 */
383
+	private function _get_event_ticket_TD_TKT_min_qty_label_info()
384
+	{
385
+		return esc_html__(
386
+			'This shows the minimum quantity that can be purchased for this ticket.',
387
+			'event_espresso'
388
+		);
389
+	}
390 390
 
391
-    /**
392
-     * @return string
393
-     */
394
-    private function _get_event_ticket_TD_TKT_max_qty_label_info()
395
-    {
396
-        return esc_html__('This shows the maximum quantity that can be purchased for this ticket.', 'event_espresso');
397
-    }
391
+	/**
392
+	 * @return string
393
+	 */
394
+	private function _get_event_ticket_TD_TKT_max_qty_label_info()
395
+	{
396
+		return esc_html__('This shows the maximum quantity that can be purchased for this ticket.', 'event_espresso');
397
+	}
398 398
 }
399 399
\ No newline at end of file
Please login to merge, or discard this patch.