Completed
Branch BUG-10381-asset-loading (189bf4)
by
unknown
13:54
created
core/data_migration_scripts/EE_DMS_Core_4_9_0.dms.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 //unfortunately, this needs to be done upon INCLUSION of this file,
10 10
 //instead of construction, because it only gets constructed on first page load
11 11
 //(all other times it gets resurrected from a wordpress option)
12
-$stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*');
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 15
     $matches = array();
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         } elseif ( ! $version_string) {
68 68
             //			echo "no version string provided: $version_string";
69 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
70
+            return false; //changed mind. dont want people thinking they should migrate yet because they cant
71 71
         } else {
72 72
             //			echo "$version_string doesnt apply";
73 73
             return false;
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      */
82 82
     public function schema_changes_before_migration()
83 83
     {
84
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
84
+        require_once(EE_HELPERS.'EEH_Activation.helper.php');
85 85
         $now_in_mysql = current_time('mysql', true);
86 86
         $table_name = 'esp_answer';
87 87
         $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
             'esp_promotion_object',
671 671
         );
672 672
         foreach ($addon_tables as $table_name) {
673
-            if($this->_table_analysis->tableExists( $table_name )){
673
+            if ($this->_table_analysis->tableExists($table_name)) {
674 674
                 $tables_to_check[] = $table_name;
675 675
             }
676 676
         }
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
         //ok and now let's remember this was done (without needing to check the db schemas all over again)
679 679
         add_option('ee_verified_db_collations', true, null, 'no');
680 680
         //seeing how this ran with the fix from 10435, no need to check again
681
-        add_option('ee_verified_db_collations_again',true,null,'no');
681
+        add_option('ee_verified_db_collations_again', true, null, 'no');
682 682
     }
683 683
 
684 684
 
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
      * which meant some DB collations might not have been updated
689 689
      * @return void
690 690
      */
691
-    public function verify_db_collations_again(){
691
+    public function verify_db_collations_again() {
692 692
         if (get_option('ee_verified_db_collations_again', false)) {
693 693
             return;
694 694
         }
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
             'esp_message'
698 698
         );
699 699
         $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
700
-        add_option('ee_verified_db_collations_again',true,null,'no');
700
+        add_option('ee_verified_db_collations_again', true, null, 'no');
701 701
     }
702 702
 
703 703
 
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
     {
713 713
         foreach ($tables_to_check as $table_name) {
714 714
             $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
715
-            if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name ) ) {
715
+            if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name)) {
716 716
                 maybe_convert_table_to_utf8mb4($table_name);
717 717
             }
718 718
         }
Please login to merge, or discard this 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_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
267
-        $table_name = 'esp_log';
268
-        $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
266
+		$this->_table_has_not_changed_since_previous($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_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
359
-        $table_name = 'esp_payment_method';
360
-        $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
358
+		$this->_table_has_not_changed_since_previous($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_has_not_changed_since_previous($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_has_not_changed_since_previous($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(10,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_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
464
-        $table_name = 'esp_state';
465
-        $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
463
+		$this->_table_has_not_changed_since_previous($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(10,3) DEFAULT '0.00',
488 488
 				TXN_paid decimal(10,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_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
498
-        $table_name = 'esp_venue_meta';
499
-        $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
497
+		$this->_table_has_not_changed_since_previous($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(10,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_has_not_changed_since_previous($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_has_not_changed_since_previous($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
-            if($this->_table_analysis->tableExists( $table_name )){
674
-                $tables_to_check[] = $table_name;
675
-            }
676
-        }
677
-        $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
678
-        //ok and now let's remember this was done (without needing to check the db schemas all over again)
679
-        add_option('ee_verified_db_collations', true, null, 'no');
680
-        //seeing how this ran with the fix from 10435, no need to check again
681
-        add_option('ee_verified_db_collations_again',true,null,'no');
682
-    }
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
+			if($this->_table_analysis->tableExists( $table_name )){
674
+				$tables_to_check[] = $table_name;
675
+			}
676
+		}
677
+		$this->_verify_db_collations_for_tables(array_unique($tables_to_check));
678
+		//ok and now let's remember this was done (without needing to check the db schemas all over again)
679
+		add_option('ee_verified_db_collations', true, null, 'no');
680
+		//seeing how this ran with the fix from 10435, no need to check again
681
+		add_option('ee_verified_db_collations_again',true,null,'no');
682
+	}
683 683
 
684 684
 
685 685
 
686
-    /**
687
-     * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435
688
-     * which meant some DB collations might not have been updated
689
-     * @return void
690
-     */
691
-    public function verify_db_collations_again(){
692
-        if (get_option('ee_verified_db_collations_again', false)) {
693
-            return;
694
-        }
695
-        $tables_to_check = array(
696
-            'esp_attendee_meta',
697
-            'esp_message'
698
-        );
699
-        $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
700
-        add_option('ee_verified_db_collations_again',true,null,'no');
701
-    }
686
+	/**
687
+	 * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435
688
+	 * which meant some DB collations might not have been updated
689
+	 * @return void
690
+	 */
691
+	public function verify_db_collations_again(){
692
+		if (get_option('ee_verified_db_collations_again', false)) {
693
+			return;
694
+		}
695
+		$tables_to_check = array(
696
+			'esp_attendee_meta',
697
+			'esp_message'
698
+		);
699
+		$this->_verify_db_collations_for_tables(array_unique($tables_to_check));
700
+		add_option('ee_verified_db_collations_again',true,null,'no');
701
+	}
702 702
 
703 703
 
704 704
 
705
-    /**
706
-     * Runs maybe_convert_table_to_utf8mb4 on the specified tables
707
-     * @param $tables_to_check
708
-     * @return boolean true if logic ran, false if it didn't
709
-     */
710
-    protected function _verify_db_collations_for_tables($tables_to_check)
711
-    {
712
-        foreach ($tables_to_check as $table_name) {
713
-            $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
714
-            if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name ) ) {
715
-                maybe_convert_table_to_utf8mb4($table_name);
716
-            }
717
-        }
718
-    }
705
+	/**
706
+	 * Runs maybe_convert_table_to_utf8mb4 on the specified tables
707
+	 * @param $tables_to_check
708
+	 * @return boolean true if logic ran, false if it didn't
709
+	 */
710
+	protected function _verify_db_collations_for_tables($tables_to_check)
711
+	{
712
+		foreach ($tables_to_check as $table_name) {
713
+			$table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
714
+			if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name ) ) {
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/services/database/TableAnalysis.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -105,29 +105,29 @@
 block discarded – undo
105 105
 
106 106
 
107 107
 
108
-    /**
109
-     * @param $table_name
110
-     * @param $index_name
111
-     * @return array of columns used on that index, Each entry is an object with the following properties {
112
-     *  @type string Table
113
-     *  @type string Non_unique "0" or "1"
114
-     *  @type string Key_name
115
-     *  @type string Seq_in_index
116
-     *  @type string Column_name
117
-     *  @type string Collation
118
-     *  @type string Cardinality
119
-     *  @type string Sub_part on a column, usually this is just the number of characters from this column to use in indexing
120
-     *  @type string|null Packed
121
-     *  @type string Null
122
-     *  @type string Index_type
123
-     *  @type string Comment
124
-     *  @type string Index_comment
125
-     * }
126
-     */
108
+	/**
109
+	 * @param $table_name
110
+	 * @param $index_name
111
+	 * @return array of columns used on that index, Each entry is an object with the following properties {
112
+	 *  @type string Table
113
+	 *  @type string Non_unique "0" or "1"
114
+	 *  @type string Key_name
115
+	 *  @type string Seq_in_index
116
+	 *  @type string Column_name
117
+	 *  @type string Collation
118
+	 *  @type string Cardinality
119
+	 *  @type string Sub_part on a column, usually this is just the number of characters from this column to use in indexing
120
+	 *  @type string|null Packed
121
+	 *  @type string Null
122
+	 *  @type string Index_type
123
+	 *  @type string Comment
124
+	 *  @type string Index_comment
125
+	 * }
126
+	 */
127 127
 	public function showIndexes($table_name, $index_name){
128
-	    global $wpdb;
129
-        $table_name = $this->ensureTableNameHasPrefix($table_name);
130
-        $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE Key_name = '{$index_name}'";
131
-        return $wpdb->get_results($index_exists_query);
132
-    }
128
+		global $wpdb;
129
+		$table_name = $this->ensureTableNameHasPrefix($table_name);
130
+		$index_exists_query = "SHOW INDEX FROM {$table_name} WHERE Key_name = '{$index_name}'";
131
+		return $wpdb->get_results($index_exists_query);
132
+	}
133 133
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -24,10 +24,10 @@  discard block
 block discarded – undo
24 24
 	 * @param string $table_name
25 25
 	 * @return string $tableName, having ensured it has the wpdb prefix on the front
26 26
 	 */
27
-	public function ensureTableNameHasPrefix( $table_name )
27
+	public function ensureTableNameHasPrefix($table_name)
28 28
 	{
29 29
 		global $wpdb;
30
-		return strpos( $table_name, $wpdb->base_prefix ) === 0 ? $table_name : $wpdb->prefix . $table_name;
30
+		return strpos($table_name, $wpdb->base_prefix) === 0 ? $table_name : $wpdb->prefix.$table_name;
31 31
 	}
32 32
 
33 33
 
@@ -39,13 +39,13 @@  discard block
 block discarded – undo
39 39
 	 * @param string $table_name
40 40
 	 * @return bool
41 41
 	 */
42
-	public function tableIsEmpty( $table_name )
42
+	public function tableIsEmpty($table_name)
43 43
 	{
44 44
 		global $wpdb;
45
-		$table_name = $this->ensureTableNameHasPrefix( $table_name );
46
-		if ( $this->tableExists( $table_name ) ) {
47
-			$count = $wpdb->get_var( "SELECT COUNT(*) FROM $table_name" );
48
-			return absint( $count ) === 0 ? true : false;
45
+		$table_name = $this->ensureTableNameHasPrefix($table_name);
46
+		if ($this->tableExists($table_name)) {
47
+			$count = $wpdb->get_var("SELECT COUNT(*) FROM $table_name");
48
+			return absint($count) === 0 ? true : false;
49 49
 		}
50 50
 		return false;
51 51
 	}
@@ -60,24 +60,24 @@  discard block
 block discarded – undo
60 60
 	 * @param $table_name
61 61
 	 * @return bool
62 62
 	 */
63
-	public function tableExists( $table_name )
63
+	public function tableExists($table_name)
64 64
 	{
65 65
 		global $wpdb, $EZSQL_ERROR;
66
-		$table_name = $this->ensureTableNameHasPrefix( $table_name );
66
+		$table_name = $this->ensureTableNameHasPrefix($table_name);
67 67
 		//ignore if this causes an sql error
68 68
 		$old_error = $wpdb->last_error;
69 69
 		$old_suppress_errors = $wpdb->suppress_errors();
70
-		$old_show_errors_value = $wpdb->show_errors( FALSE );
70
+		$old_show_errors_value = $wpdb->show_errors(FALSE);
71 71
 		$ezsql_error_cache = $EZSQL_ERROR;
72
-		$wpdb->get_results( "SELECT * from $table_name LIMIT 1");
73
-		$wpdb->show_errors( $old_show_errors_value );
74
-		$wpdb->suppress_errors( $old_suppress_errors );
72
+		$wpdb->get_results("SELECT * from $table_name LIMIT 1");
73
+		$wpdb->show_errors($old_show_errors_value);
74
+		$wpdb->suppress_errors($old_suppress_errors);
75 75
 		$new_error = $wpdb->last_error;
76 76
 		$wpdb->last_error = $old_error;
77 77
 		$EZSQL_ERROR = $ezsql_error_cache;
78 78
 		//if there was a table doesn't exist error
79
-		if( ! empty( $new_error ) ) {
80
-			if(
79
+		if ( ! empty($new_error)) {
80
+			if (
81 81
 				in_array(
82 82
 					\EEH_Activation::last_wpdb_error_code(),
83 83
 					array(
@@ -87,14 +87,14 @@  discard block
 block discarded – undo
87 87
 					)
88 88
 				)
89 89
 				||
90
-				preg_match( '~^Table .* doesn\'t exist~', $new_error ) //in case not using mysql and error codes aren't reliable, just check for this error string
90
+				preg_match('~^Table .* doesn\'t exist~', $new_error) //in case not using mysql and error codes aren't reliable, just check for this error string
91 91
 			) {
92 92
 				return false;
93 93
 			} else {
94 94
 				//log this because that's weird. Just use the normal PHP error log
95 95
 				error_log(
96 96
 					sprintf(
97
-						__( 'Event Espresso error detected when checking if table existed: %1$s (it wasn\'t just that the table didn\'t exist either)', 'event_espresso' ),
97
+						__('Event Espresso error detected when checking if table existed: %1$s (it wasn\'t just that the table didn\'t exist either)', 'event_espresso'),
98 98
 					$new_error
99 99
 					)
100 100
 				);
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      *  @type string Index_comment
125 125
      * }
126 126
      */
127
-	public function showIndexes($table_name, $index_name){
127
+	public function showIndexes($table_name, $index_name) {
128 128
 	    global $wpdb;
129 129
         $table_name = $this->ensureTableNameHasPrefix($table_name);
130 130
         $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE Key_name = '{$index_name}'";
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -390,43 +390,43 @@
 block discarded – undo
390 390
 			),
391 391
 			'EE_Data_Migration_Class_Base' => array(
392 392
 				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
393
-                'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
393
+				'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
394 394
 			),
395 395
 			'EE_DMS_Core_4_1_0' => array(
396 396
 				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
397
-                'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
397
+				'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
398 398
 			),
399 399
 			'EE_DMS_Core_4_2_0' => array(
400 400
 				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
401
-                'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
401
+				'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
402 402
 			),
403 403
 			'EE_DMS_Core_4_3_0' => array(
404 404
 				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
405
-                'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
405
+				'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
406 406
 			),
407 407
 			'EE_DMS_Core_4_4_0' => array(
408 408
 				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
409
-                'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
409
+				'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
410 410
 			),
411 411
 			'EE_DMS_Core_4_5_0' => array(
412 412
 				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
413
-                'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
413
+				'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
414 414
 			),
415 415
 			'EE_DMS_Core_4_6_0' => array(
416 416
 				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
417
-                'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
417
+				'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
418 418
 			),
419 419
 			'EE_DMS_Core_4_7_0' => array(
420 420
 				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
421
-                'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
421
+				'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
422 422
 			),
423 423
 			'EE_DMS_Core_4_8_0' => array(
424 424
 				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
425
-                'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
425
+				'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
426 426
 			),
427 427
 			'EE_DMS_Core_4_9_0' => array(
428 428
 				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
429
-                'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
429
+				'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache,
430 430
 			),
431 431
 		);
432 432
 	}
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 2 patches
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      */
62 62
     public static function getTableAnalysis()
63 63
     {
64
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
64
+        if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
65 65
             self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
66 66
         }
67 67
         return self::$table_analysis;
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
      */
74 74
     public static function getTableManager()
75 75
     {
76
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
76
+        if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
77 77
             self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
78 78
         }
79 79
         return self::$table_manager;
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
         if ($which_to_include === 'old') {
190 190
             $cron_tasks = array_filter(
191 191
                 $cron_tasks,
192
-                function ($value) {
192
+                function($value) {
193 193
                     return $value === EEH_Activation::cron_task_no_longer_in_use;
194 194
                 }
195 195
             );
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
     {
220 220
 
221 221
         foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
222
-            if (! wp_next_scheduled($hook_name)) {
222
+            if ( ! wp_next_scheduled($hook_name)) {
223 223
                 /**
224 224
                  * This allows client code to define the initial start timestamp for this schedule.
225 225
                  */
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
             3
325 325
         );
326 326
         //EE_Config::reset();
327
-        if (! EE_Config::logging_enabled()) {
327
+        if ( ! EE_Config::logging_enabled()) {
328 328
             delete_option(EE_Config::LOG_NAME);
329 329
         }
330 330
     }
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
     public static function load_calendar_config()
340 340
     {
341 341
         // grab array of all plugin folders and loop thru it
342
-        $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
342
+        $plugins = glob(WP_PLUGIN_DIR.DS.'*', GLOB_ONLYDIR);
343 343
         if (empty($plugins)) {
344 344
             return;
345 345
         }
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
                 || strpos($plugin, 'calendar') !== false
357 357
             ) {
358 358
                 // this is what we are looking for
359
-                $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
359
+                $calendar_config = $plugin_path.DS.'EE_Calendar_Config.php';
360 360
                 // does it exist in this folder ?
361 361
                 if (is_readable($calendar_config)) {
362 362
                     // YEAH! let's load it
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
             ) {
490 490
                 //update Config with post ID
491 491
                 $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
492
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
492
+                if ( ! EE_Config::instance()->update_espresso_config(false, false)) {
493 493
                     $msg = __(
494 494
                         'The Event Espresso critical page configuration settings could not be updated.',
495 495
                         'event_espresso'
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
     public static function get_page_by_ee_shortcode($ee_shortcode)
539 539
     {
540 540
         global $wpdb;
541
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
541
+        $shortcode_and_opening_bracket = '['.$ee_shortcode;
542 542
         $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
543 543
         if ($post_id) {
544 544
             return get_post($post_id);
@@ -564,11 +564,11 @@  discard block
 block discarded – undo
564 564
             'post_status'    => 'publish',
565 565
             'post_type'      => 'page',
566 566
             'comment_status' => 'closed',
567
-            'post_content'   => '[' . $critical_page['code'] . ']',
567
+            'post_content'   => '['.$critical_page['code'].']',
568 568
         );
569 569
 
570 570
         $post_id = wp_insert_post($post_args);
571
-        if (! $post_id) {
571
+        if ( ! $post_id) {
572 572
             $msg = sprintf(
573 573
                 __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
574 574
                 $critical_page['name']
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
             return $critical_page;
578 578
         }
579 579
         // get newly created post's details
580
-        if (! $critical_page['post'] = get_post($post_id)) {
580
+        if ( ! $critical_page['post'] = get_post($post_id)) {
581 581
             $msg = sprintf(
582 582
                 __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
583 583
                 $critical_page['name']
@@ -664,17 +664,17 @@  discard block
 block discarded – undo
664 664
             $role_to_check
665 665
         );
666 666
         if ($pre_filtered_id !== false) {
667
-            return (int)$pre_filtered_id;
667
+            return (int) $pre_filtered_id;
668 668
         }
669 669
         $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
670 670
         $query = $wpdb->prepare(
671 671
             "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
672
-            '%' . $role_to_check . '%'
672
+            '%'.$role_to_check.'%'
673 673
         );
674 674
         $user_id = $wpdb->get_var($query);
675 675
         $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
676
-        if ($user_id && (int)$user_id) {
677
-            self::$_default_creator_id = (int)$user_id;
676
+        if ($user_id && (int) $user_id) {
677
+            self::$_default_creator_id = (int) $user_id;
678 678
             return self::$_default_creator_id;
679 679
         } else {
680 680
             return null;
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
         }
710 710
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
711 711
         if ( ! function_exists('dbDelta')) {
712
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
712
+            require_once(ABSPATH.'wp-admin/includes/upgrade.php');
713 713
         }
714 714
         $tableAnalysis = \EEH_Activation::getTableAnalysis();
715 715
         $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
@@ -920,13 +920,13 @@  discard block
 block discarded – undo
920 920
             // reset values array
921 921
             $QSG_values = array();
922 922
             // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
923
-            if (! in_array("$QSG_system", $question_groups)) {
923
+            if ( ! in_array("$QSG_system", $question_groups)) {
924 924
                 // add it
925 925
                 switch ($QSG_system) {
926 926
                     case 1:
927 927
                         $QSG_values = array(
928 928
                             'QSG_name'            => __('Personal Information', 'event_espresso'),
929
-                            'QSG_identifier'      => 'personal-information-' . time(),
929
+                            'QSG_identifier'      => 'personal-information-'.time(),
930 930
                             'QSG_desc'            => '',
931 931
                             'QSG_order'           => 1,
932 932
                             'QSG_show_group_name' => 1,
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
                     case 2:
939 939
                         $QSG_values = array(
940 940
                             'QSG_name'            => __('Address Information', 'event_espresso'),
941
-                            'QSG_identifier'      => 'address-information-' . time(),
941
+                            'QSG_identifier'      => 'address-information-'.time(),
942 942
                             'QSG_desc'            => '',
943 943
                             'QSG_order'           => 2,
944 944
                             'QSG_show_group_name' => 1,
@@ -949,7 +949,7 @@  discard block
 block discarded – undo
949 949
                         break;
950 950
                 }
951 951
                 // make sure we have some values before inserting them
952
-                if (! empty($QSG_values)) {
952
+                if ( ! empty($QSG_values)) {
953 953
                     // insert system question
954 954
                     $wpdb->insert(
955 955
                         $table_name,
@@ -986,7 +986,7 @@  discard block
 block discarded – undo
986 986
             // reset values array
987 987
             $QST_values = array();
988 988
             // if we don't have what we should have
989
-            if (! in_array($QST_system, $questions)) {
989
+            if ( ! in_array($QST_system, $questions)) {
990 990
                 // add it
991 991
                 switch ($QST_system) {
992 992
                     case 'fname':
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
                         );
1139 1139
                         break;
1140 1140
                 }
1141
-                if (! empty($QST_values)) {
1141
+                if ( ! empty($QST_values)) {
1142 1142
                     // insert system question
1143 1143
                     $wpdb->insert(
1144 1144
                         $table_name,
@@ -1199,7 +1199,7 @@  discard block
 block discarded – undo
1199 1199
      */
1200 1200
     public static function insert_default_payment_methods()
1201 1201
     {
1202
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1202
+        if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1203 1203
             EE_Registry::instance()->load_lib('Payment_Method_Manager');
1204 1204
             EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1205 1205
         } else {
@@ -1287,9 +1287,9 @@  discard block
 block discarded – undo
1287 1287
         $folders = array(
1288 1288
             EVENT_ESPRESSO_TEMPLATE_DIR,
1289 1289
             EVENT_ESPRESSO_GATEWAY_DIR,
1290
-            EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1291
-            EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1292
-            EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1290
+            EVENT_ESPRESSO_UPLOAD_DIR.'logs/',
1291
+            EVENT_ESPRESSO_UPLOAD_DIR.'css/',
1292
+            EVENT_ESPRESSO_UPLOAD_DIR.'tickets/',
1293 1293
         );
1294 1294
         foreach ($folders as $folder) {
1295 1295
             try {
@@ -1300,7 +1300,7 @@  discard block
 block discarded – undo
1300 1300
                     sprintf(
1301 1301
                         __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1302 1302
                         $folder,
1303
-                        '<br />' . $e->getMessage()
1303
+                        '<br />'.$e->getMessage()
1304 1304
                     ),
1305 1305
                     __FILE__, __FUNCTION__, __LINE__
1306 1306
                 );
@@ -1311,7 +1311,7 @@  discard block
 block discarded – undo
1311 1311
         }
1312 1312
         //just add the .htaccess file to the logs directory to begin with. Even if logging
1313 1313
         //is disabled, there might be activation errors recorded in there
1314
-        EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1314
+        EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs/');
1315 1315
         //remember EE's folders are all good
1316 1316
         delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1317 1317
         return true;
@@ -1547,7 +1547,7 @@  discard block
 block discarded – undo
1547 1547
         // this creates an array for tracking events that have no active ticket prices created
1548 1548
         // this allows us to warn admins of the situation so that it can be corrected
1549 1549
         $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1550
-        if (! $espresso_no_ticket_prices) {
1550
+        if ( ! $espresso_no_ticket_prices) {
1551 1551
             add_option('ee_no_ticket_prices', array(), '', false);
1552 1552
         }
1553 1553
     }
@@ -1586,7 +1586,7 @@  discard block
 block discarded – undo
1586 1586
             }
1587 1587
         }
1588 1588
         //get all our CPTs
1589
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1589
+        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")";
1590 1590
         $cpt_ids = $wpdb->get_col($query);
1591 1591
         //delete each post meta and term relations too
1592 1592
         foreach ($cpt_ids as $post_id) {
@@ -1726,7 +1726,7 @@  discard block
 block discarded – undo
1726 1726
         if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1727 1727
             $db_update_sans_ee4 = array();
1728 1728
             foreach ($espresso_db_update as $version => $times_activated) {
1729
-                if ((string)$version[0] === '3') {//if its NON EE4
1729
+                if ((string) $version[0] === '3') {//if its NON EE4
1730 1730
                     $db_update_sans_ee4[$version] = $times_activated;
1731 1731
                 }
1732 1732
             }
Please login to merge, or discard this patch.
Indentation   +1653 added lines, -1653 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -14,244 +14,244 @@  discard block
 block discarded – undo
14 14
 class EEH_Activation
15 15
 {
16 16
 
17
-    /**
18
-     * constant used to indicate a cron task is no longer in use
19
-     */
20
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
21
-
22
-    /**
23
-     * option name that will indicate whether or not we still
24
-     * need to create EE's folders in the uploads directory
25
-     * (because if EE was installed without file system access,
26
-     * we need to request credentials before we can create them)
27
-     */
28
-    const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
29
-
30
-    /**
31
-     * WP_User->ID
32
-     *
33
-     * @var int
34
-     */
35
-    private static $_default_creator_id;
36
-
37
-    /**
38
-     * indicates whether or not we've already verified core's default data during this request,
39
-     * because after migrations are done, any addons activated while in maintenance mode
40
-     * will want to setup their own default data, and they might hook into core's default data
41
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
42
-     * This prevents doing that for EVERY single addon.
43
-     *
44
-     * @var boolean
45
-     */
46
-    protected static $_initialized_db_content_already_in_this_request = false;
47
-
48
-    /**
49
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
50
-     */
51
-    private static $table_analysis;
52
-
53
-    /**
54
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
55
-     */
56
-    private static $table_manager;
57
-
58
-
59
-    /**
60
-     * @return \EventEspresso\core\services\database\TableAnalysis
61
-     */
62
-    public static function getTableAnalysis()
63
-    {
64
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
65
-            self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
66
-        }
67
-        return self::$table_analysis;
68
-    }
69
-
70
-
71
-    /**
72
-     * @return \EventEspresso\core\services\database\TableManager
73
-     */
74
-    public static function getTableManager()
75
-    {
76
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
77
-            self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
78
-        }
79
-        return self::$table_manager;
80
-    }
81
-
82
-
83
-    /**
84
-     *    _ensure_table_name_has_prefix
85
-     *
86
-     * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
87
-     * @access     public
88
-     * @static
89
-     * @param $table_name
90
-     * @return string
91
-     */
92
-    public static function ensure_table_name_has_prefix($table_name)
93
-    {
94
-        return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
95
-    }
96
-
97
-
98
-    /**
99
-     *    system_initialization
100
-     *    ensures the EE configuration settings are loaded with at least default options set
101
-     *    and that all critical EE pages have been generated with the appropriate shortcodes in place
102
-     *
103
-     * @access public
104
-     * @static
105
-     * @return void
106
-     */
107
-    public static function system_initialization()
108
-    {
109
-        EEH_Activation::reset_and_update_config();
110
-        //which is fired BEFORE activation of plugin anyways
111
-        EEH_Activation::verify_default_pages_exist();
112
-    }
113
-
114
-
115
-    /**
116
-     * Sets the database schema and creates folders. This should
117
-     * be called on plugin activation and reactivation
118
-     *
119
-     * @return boolean success, whether the database and folders are setup properly
120
-     * @throws \EE_Error
121
-     */
122
-    public static function initialize_db_and_folders()
123
-    {
124
-        $good_filesystem = EEH_Activation::create_upload_directories();
125
-        $good_db         = EEH_Activation::create_database_tables();
126
-        return $good_filesystem && $good_db;
127
-    }
128
-
129
-
130
-    /**
131
-     * assuming we have an up-to-date database schema, this will populate it
132
-     * with default and initial data. This should be called
133
-     * upon activation of a new plugin, reactivation, and at the end
134
-     * of running migration scripts
135
-     *
136
-     * @throws \EE_Error
137
-     */
138
-    public static function initialize_db_content()
139
-    {
140
-        //let's avoid doing all this logic repeatedly, especially when addons are requesting it
141
-        if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
142
-            return;
143
-        }
144
-        EEH_Activation::$_initialized_db_content_already_in_this_request = true;
145
-
146
-        EEH_Activation::initialize_system_questions();
147
-        EEH_Activation::insert_default_status_codes();
148
-        EEH_Activation::generate_default_message_templates();
149
-        EEH_Activation::create_no_ticket_prices_array();
150
-        EE_Registry::instance()->CAP->init_caps();
151
-
152
-        EEH_Activation::validate_messages_system();
153
-        EEH_Activation::insert_default_payment_methods();
154
-        //in case we've
155
-        EEH_Activation::remove_cron_tasks();
156
-        EEH_Activation::create_cron_tasks();
157
-        // remove all TXN locks since that is being done via extra meta now
158
-        delete_option('ee_locked_transactions');
159
-        //also, check for CAF default db content
160
-        do_action('AHEE__EEH_Activation__initialize_db_content');
161
-        //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
162
-        //which users really won't care about on initial activation
163
-        EE_Error::overwrite_success();
164
-    }
165
-
166
-
167
-    /**
168
-     * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
169
-     * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
170
-     * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
171
-     * (null)
172
-     *
173
-     * @param string $which_to_include can be 'current' (ones that are currently in use),
174
-     *                                 'old' (only returns ones that should no longer be used),or 'all',
175
-     * @return array
176
-     * @throws \EE_Error
177
-     */
178
-    public static function get_cron_tasks($which_to_include)
179
-    {
180
-        $cron_tasks = apply_filters(
181
-            'FHEE__EEH_Activation__get_cron_tasks',
182
-            array(
183
-                'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
17
+	/**
18
+	 * constant used to indicate a cron task is no longer in use
19
+	 */
20
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
21
+
22
+	/**
23
+	 * option name that will indicate whether or not we still
24
+	 * need to create EE's folders in the uploads directory
25
+	 * (because if EE was installed without file system access,
26
+	 * we need to request credentials before we can create them)
27
+	 */
28
+	const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
29
+
30
+	/**
31
+	 * WP_User->ID
32
+	 *
33
+	 * @var int
34
+	 */
35
+	private static $_default_creator_id;
36
+
37
+	/**
38
+	 * indicates whether or not we've already verified core's default data during this request,
39
+	 * because after migrations are done, any addons activated while in maintenance mode
40
+	 * will want to setup their own default data, and they might hook into core's default data
41
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
42
+	 * This prevents doing that for EVERY single addon.
43
+	 *
44
+	 * @var boolean
45
+	 */
46
+	protected static $_initialized_db_content_already_in_this_request = false;
47
+
48
+	/**
49
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
50
+	 */
51
+	private static $table_analysis;
52
+
53
+	/**
54
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
55
+	 */
56
+	private static $table_manager;
57
+
58
+
59
+	/**
60
+	 * @return \EventEspresso\core\services\database\TableAnalysis
61
+	 */
62
+	public static function getTableAnalysis()
63
+	{
64
+		if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
65
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
66
+		}
67
+		return self::$table_analysis;
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return \EventEspresso\core\services\database\TableManager
73
+	 */
74
+	public static function getTableManager()
75
+	{
76
+		if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
77
+			self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
78
+		}
79
+		return self::$table_manager;
80
+	}
81
+
82
+
83
+	/**
84
+	 *    _ensure_table_name_has_prefix
85
+	 *
86
+	 * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
87
+	 * @access     public
88
+	 * @static
89
+	 * @param $table_name
90
+	 * @return string
91
+	 */
92
+	public static function ensure_table_name_has_prefix($table_name)
93
+	{
94
+		return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
95
+	}
96
+
97
+
98
+	/**
99
+	 *    system_initialization
100
+	 *    ensures the EE configuration settings are loaded with at least default options set
101
+	 *    and that all critical EE pages have been generated with the appropriate shortcodes in place
102
+	 *
103
+	 * @access public
104
+	 * @static
105
+	 * @return void
106
+	 */
107
+	public static function system_initialization()
108
+	{
109
+		EEH_Activation::reset_and_update_config();
110
+		//which is fired BEFORE activation of plugin anyways
111
+		EEH_Activation::verify_default_pages_exist();
112
+	}
113
+
114
+
115
+	/**
116
+	 * Sets the database schema and creates folders. This should
117
+	 * be called on plugin activation and reactivation
118
+	 *
119
+	 * @return boolean success, whether the database and folders are setup properly
120
+	 * @throws \EE_Error
121
+	 */
122
+	public static function initialize_db_and_folders()
123
+	{
124
+		$good_filesystem = EEH_Activation::create_upload_directories();
125
+		$good_db         = EEH_Activation::create_database_tables();
126
+		return $good_filesystem && $good_db;
127
+	}
128
+
129
+
130
+	/**
131
+	 * assuming we have an up-to-date database schema, this will populate it
132
+	 * with default and initial data. This should be called
133
+	 * upon activation of a new plugin, reactivation, and at the end
134
+	 * of running migration scripts
135
+	 *
136
+	 * @throws \EE_Error
137
+	 */
138
+	public static function initialize_db_content()
139
+	{
140
+		//let's avoid doing all this logic repeatedly, especially when addons are requesting it
141
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
142
+			return;
143
+		}
144
+		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
145
+
146
+		EEH_Activation::initialize_system_questions();
147
+		EEH_Activation::insert_default_status_codes();
148
+		EEH_Activation::generate_default_message_templates();
149
+		EEH_Activation::create_no_ticket_prices_array();
150
+		EE_Registry::instance()->CAP->init_caps();
151
+
152
+		EEH_Activation::validate_messages_system();
153
+		EEH_Activation::insert_default_payment_methods();
154
+		//in case we've
155
+		EEH_Activation::remove_cron_tasks();
156
+		EEH_Activation::create_cron_tasks();
157
+		// remove all TXN locks since that is being done via extra meta now
158
+		delete_option('ee_locked_transactions');
159
+		//also, check for CAF default db content
160
+		do_action('AHEE__EEH_Activation__initialize_db_content');
161
+		//also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
162
+		//which users really won't care about on initial activation
163
+		EE_Error::overwrite_success();
164
+	}
165
+
166
+
167
+	/**
168
+	 * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
169
+	 * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
170
+	 * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
171
+	 * (null)
172
+	 *
173
+	 * @param string $which_to_include can be 'current' (ones that are currently in use),
174
+	 *                                 'old' (only returns ones that should no longer be used),or 'all',
175
+	 * @return array
176
+	 * @throws \EE_Error
177
+	 */
178
+	public static function get_cron_tasks($which_to_include)
179
+	{
180
+		$cron_tasks = apply_filters(
181
+			'FHEE__EEH_Activation__get_cron_tasks',
182
+			array(
183
+				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
184 184
 //				'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
185
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
186
-                //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
187
-                'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
188
-            )
189
-        );
190
-        if ($which_to_include === 'old') {
191
-            $cron_tasks = array_filter(
192
-                $cron_tasks,
193
-                function ($value) {
194
-                    return $value === EEH_Activation::cron_task_no_longer_in_use;
195
-                }
196
-            );
197
-        } elseif ($which_to_include === 'current') {
198
-            $cron_tasks = array_filter($cron_tasks);
199
-        } elseif (WP_DEBUG && $which_to_include !== 'all') {
200
-            throw new EE_Error(
201
-                sprintf(
202
-                    __(
203
-                        'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
204
-                        'event_espresso'
205
-                    ),
206
-                    $which_to_include
207
-                )
208
-            );
209
-        }
210
-        return $cron_tasks;
211
-    }
212
-
213
-
214
-    /**
215
-     * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
216
-     *
217
-     * @throws \EE_Error
218
-     */
219
-    public static function create_cron_tasks()
220
-    {
221
-
222
-        foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
223
-            if (! wp_next_scheduled($hook_name)) {
224
-                /**
225
-                 * This allows client code to define the initial start timestamp for this schedule.
226
-                 */
227
-                if (is_array($frequency)
228
-                    && count($frequency) === 2
229
-                    && isset($frequency[0], $frequency[1])
230
-                ) {
231
-                    $start_timestamp = $frequency[0];
232
-                    $frequency = $frequency[1];
233
-                } else {
234
-                    $start_timestamp = time();
235
-                }
236
-                wp_schedule_event($start_timestamp, $frequency, $hook_name);
237
-            }
238
-        }
239
-
240
-    }
241
-
242
-
243
-    /**
244
-     * Remove the currently-existing and now-removed cron tasks.
245
-     *
246
-     * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
247
-     * @throws \EE_Error
248
-     */
249
-    public static function remove_cron_tasks($remove_all = true)
250
-    {
251
-        $cron_tasks_to_remove = $remove_all ? 'all' : 'old';
252
-        $crons                = _get_cron_array();
253
-        $crons                = is_array($crons) ? $crons : array();
254
-        /* reminder of what $crons look like:
185
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
186
+				//there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
187
+				'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
188
+			)
189
+		);
190
+		if ($which_to_include === 'old') {
191
+			$cron_tasks = array_filter(
192
+				$cron_tasks,
193
+				function ($value) {
194
+					return $value === EEH_Activation::cron_task_no_longer_in_use;
195
+				}
196
+			);
197
+		} elseif ($which_to_include === 'current') {
198
+			$cron_tasks = array_filter($cron_tasks);
199
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
200
+			throw new EE_Error(
201
+				sprintf(
202
+					__(
203
+						'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
204
+						'event_espresso'
205
+					),
206
+					$which_to_include
207
+				)
208
+			);
209
+		}
210
+		return $cron_tasks;
211
+	}
212
+
213
+
214
+	/**
215
+	 * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
216
+	 *
217
+	 * @throws \EE_Error
218
+	 */
219
+	public static function create_cron_tasks()
220
+	{
221
+
222
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
223
+			if (! wp_next_scheduled($hook_name)) {
224
+				/**
225
+				 * This allows client code to define the initial start timestamp for this schedule.
226
+				 */
227
+				if (is_array($frequency)
228
+					&& count($frequency) === 2
229
+					&& isset($frequency[0], $frequency[1])
230
+				) {
231
+					$start_timestamp = $frequency[0];
232
+					$frequency = $frequency[1];
233
+				} else {
234
+					$start_timestamp = time();
235
+				}
236
+				wp_schedule_event($start_timestamp, $frequency, $hook_name);
237
+			}
238
+		}
239
+
240
+	}
241
+
242
+
243
+	/**
244
+	 * Remove the currently-existing and now-removed cron tasks.
245
+	 *
246
+	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
247
+	 * @throws \EE_Error
248
+	 */
249
+	public static function remove_cron_tasks($remove_all = true)
250
+	{
251
+		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
252
+		$crons                = _get_cron_array();
253
+		$crons                = is_array($crons) ? $crons : array();
254
+		/* reminder of what $crons look like:
255 255
          * Top-level keys are timestamps, and their values are arrays.
256 256
          * The 2nd level arrays have keys with each of the cron task hook names to run at that time
257 257
          * and their values are arrays.
@@ -268,912 +268,912 @@  discard block
 block discarded – undo
268 268
          *					...
269 269
          *      ...
270 270
          */
271
-        $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
272
-        foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
273
-            if (is_array($hooks_to_fire_at_time)) {
274
-                foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
275
-                    if (isset($ee_cron_tasks_to_remove[$hook_name])
276
-                        && is_array($ee_cron_tasks_to_remove[$hook_name])
277
-                    ) {
278
-                        unset($crons[$timestamp][$hook_name]);
279
-                    }
280
-                }
281
-                //also take care of any empty cron timestamps.
282
-                if (empty($hooks_to_fire_at_time)) {
283
-                    unset($crons[$timestamp]);
284
-                }
285
-            }
286
-        }
287
-        _set_cron_array($crons);
288
-    }
289
-
290
-
291
-    /**
292
-     *    CPT_initialization
293
-     *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
294
-     *
295
-     * @access public
296
-     * @static
297
-     * @return void
298
-     */
299
-    public static function CPT_initialization()
300
-    {
301
-        // register Custom Post Types
302
-        EE_Registry::instance()->load_core('Register_CPTs');
303
-        flush_rewrite_rules();
304
-    }
305
-
306
-
307
-
308
-    /**
309
-     *    reset_and_update_config
310
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
311
-     * If there is old calendar config data saved, then it will get converted on activation.
312
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
313
-     *
314
-     * @access public
315
-     * @static
316
-     * @return void
317
-     */
318
-    public static function reset_and_update_config()
319
-    {
320
-        do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
321
-        add_filter(
322
-            'FHEE__EE_Config___load_core_config__config_settings',
323
-            array('EEH_Activation', 'migrate_old_config_data'),
324
-            10,
325
-            3
326
-        );
327
-        //EE_Config::reset();
328
-        if (! EE_Config::logging_enabled()) {
329
-            delete_option(EE_Config::LOG_NAME);
330
-        }
331
-    }
332
-
333
-
334
-    /**
335
-     *    load_calendar_config
336
-     *
337
-     * @access    public
338
-     * @return    void
339
-     */
340
-    public static function load_calendar_config()
341
-    {
342
-        // grab array of all plugin folders and loop thru it
343
-        $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
344
-        if (empty($plugins)) {
345
-            return;
346
-        }
347
-        foreach ($plugins as $plugin_path) {
348
-            // grab plugin folder name from path
349
-            $plugin = basename($plugin_path);
350
-            // drill down to Espresso plugins
351
-            // then to calendar related plugins
352
-            if (
353
-                strpos($plugin, 'espresso') !== false
354
-                || strpos($plugin, 'Espresso') !== false
355
-                || strpos($plugin, 'ee4') !== false
356
-                || strpos($plugin, 'EE4') !== false
357
-                || strpos($plugin, 'calendar') !== false
358
-            ) {
359
-                // this is what we are looking for
360
-                $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
361
-                // does it exist in this folder ?
362
-                if (is_readable($calendar_config)) {
363
-                    // YEAH! let's load it
364
-                    require_once($calendar_config);
365
-                }
366
-            }
367
-        }
368
-    }
369
-
370
-
371
-
372
-    /**
373
-     *    _migrate_old_config_data
374
-     *
375
-     * @access    public
376
-     * @param array|stdClass $settings
377
-     * @param string         $config
378
-     * @param \EE_Config     $EE_Config
379
-     * @return \stdClass
380
-     */
381
-    public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
382
-    {
383
-        $convert_from_array = array('addons');
384
-        // in case old settings were saved as an array
385
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
386
-            // convert existing settings to an object
387
-            $config_array = $settings;
388
-            $settings = new stdClass();
389
-            foreach ($config_array as $key => $value) {
390
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
391
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
392
-                } else {
393
-                    $settings->{$key} = $value;
394
-                }
395
-            }
396
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
397
-        }
398
-        return $settings;
399
-    }
400
-
401
-
402
-    /**
403
-     * deactivate_event_espresso
404
-     *
405
-     * @access public
406
-     * @static
407
-     * @return void
408
-     */
409
-    public static function deactivate_event_espresso()
410
-    {
411
-        // check permissions
412
-        if (current_user_can('activate_plugins')) {
413
-            deactivate_plugins(EE_PLUGIN_BASENAME, true);
414
-        }
415
-    }
416
-
417
-
418
-
419
-
420
-
421
-    /**
422
-     * verify_default_pages_exist
423
-     *
424
-     * @access public
425
-     * @static
426
-     * @return void
427
-     */
428
-    public static function verify_default_pages_exist()
429
-    {
430
-        $critical_page_problem = false;
431
-        $critical_pages = array(
432
-            array(
433
-                'id'   => 'reg_page_id',
434
-                'name' => __('Registration Checkout', 'event_espresso'),
435
-                'post' => null,
436
-                'code' => 'ESPRESSO_CHECKOUT',
437
-            ),
438
-            array(
439
-                'id'   => 'txn_page_id',
440
-                'name' => __('Transactions', 'event_espresso'),
441
-                'post' => null,
442
-                'code' => 'ESPRESSO_TXN_PAGE',
443
-            ),
444
-            array(
445
-                'id'   => 'thank_you_page_id',
446
-                'name' => __('Thank You', 'event_espresso'),
447
-                'post' => null,
448
-                'code' => 'ESPRESSO_THANK_YOU',
449
-            ),
450
-            array(
451
-                'id'   => 'cancel_page_id',
452
-                'name' => __('Registration Cancelled', 'event_espresso'),
453
-                'post' => null,
454
-                'code' => 'ESPRESSO_CANCELLED',
455
-            ),
456
-        );
457
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
458
-        foreach ($critical_pages as $critical_page) {
459
-            // is critical page ID set in config ?
460
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
461
-                // attempt to find post by ID
462
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
463
-            }
464
-            // no dice?
465
-            if ($critical_page['post'] === null) {
466
-                // attempt to find post by title
467
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
468
-                // still nothing?
469
-                if ($critical_page['post'] === null) {
470
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
471
-                    // REALLY? Still nothing ??!?!?
472
-                    if ($critical_page['post'] === null) {
473
-                        $msg = __(
474
-                            'The Event Espresso critical page configuration settings could not be updated.',
475
-                            'event_espresso'
476
-                        );
477
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
478
-                        break;
479
-                    }
480
-                }
481
-            }
482
-            // check that Post ID matches critical page ID in config
483
-            if (
484
-                isset($critical_page['post']->ID)
485
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
486
-            ) {
487
-                //update Config with post ID
488
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
489
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
490
-                    $msg = __(
491
-                        'The Event Espresso critical page configuration settings could not be updated.',
492
-                        'event_espresso'
493
-                    );
494
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
495
-                }
496
-            }
497
-            $critical_page_problem =
498
-                ! isset($critical_page['post']->post_status)
499
-                || $critical_page['post']->post_status !== 'publish'
500
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
501
-                    ? true
502
-                    : $critical_page_problem;
503
-        }
504
-        if ($critical_page_problem) {
505
-            $msg = sprintf(
506
-                __(
507
-                    'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
508
-                    'event_espresso'
509
-                ),
510
-                '<a href="'
511
-                . admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
512
-                . '">'
513
-                . __('Event Espresso Critical Pages Settings', 'event_espresso')
514
-                . '</a>'
515
-            );
516
-            EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
517
-        }
518
-        if (EE_Error::has_notices()) {
519
-            EE_Error::get_notices(false, true, true);
520
-        }
521
-    }
522
-
523
-
524
-
525
-    /**
526
-     * Returns the first post which uses the specified shortcode
527
-     *
528
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
529
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
530
-     *                             "[ESPRESSO_THANK_YOU"
531
-     *                             (we don't search for the closing shortcode bracket because they might have added
532
-     *                             parameter to the shortcode
533
-     * @return WP_Post or NULl
534
-     */
535
-    public static function get_page_by_ee_shortcode($ee_shortcode)
536
-    {
537
-        global $wpdb;
538
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
539
-        $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
540
-        if ($post_id) {
541
-            return get_post($post_id);
542
-        } else {
543
-            return null;
544
-        }
545
-    }
546
-
547
-
548
-    /**
549
-     *    This function generates a post for critical espresso pages
550
-     *
551
-     * @access public
552
-     * @static
553
-     * @param array $critical_page
554
-     * @return array
555
-     */
556
-    public static function create_critical_page($critical_page)
557
-    {
558
-
559
-        $post_args = array(
560
-            'post_title'     => $critical_page['name'],
561
-            'post_status'    => 'publish',
562
-            'post_type'      => 'page',
563
-            'comment_status' => 'closed',
564
-            'post_content'   => '[' . $critical_page['code'] . ']',
565
-        );
566
-
567
-        $post_id = wp_insert_post($post_args);
568
-        if (! $post_id) {
569
-            $msg = sprintf(
570
-                __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
571
-                $critical_page['name']
572
-            );
573
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
574
-            return $critical_page;
575
-        }
576
-        // get newly created post's details
577
-        if (! $critical_page['post'] = get_post($post_id)) {
578
-            $msg = sprintf(
579
-                __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
580
-                $critical_page['name']
581
-            );
582
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
583
-        }
584
-
585
-        return $critical_page;
586
-
587
-    }
588
-
589
-
590
-
591
-
592
-    /**
593
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
594
-     * The role being used to check is filterable.
595
-     *
596
-     * @since  4.6.0
597
-     * @global WPDB $wpdb
598
-     * @return mixed null|int WP_user ID or NULL
599
-     */
600
-    public static function get_default_creator_id()
601
-    {
602
-        global $wpdb;
603
-        if ( ! empty(self::$_default_creator_id)) {
604
-            return self::$_default_creator_id;
605
-        }/**/
606
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
607
-        //let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
608
-        $pre_filtered_id = apply_filters(
609
-            'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
610
-            false,
611
-            $role_to_check
612
-        );
613
-        if ($pre_filtered_id !== false) {
614
-            return (int)$pre_filtered_id;
615
-        }
616
-        $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
617
-        $query = $wpdb->prepare(
618
-            "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
619
-            '%' . $role_to_check . '%'
620
-        );
621
-        $user_id = $wpdb->get_var($query);
622
-        $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
623
-        if ($user_id && (int)$user_id) {
624
-            self::$_default_creator_id = (int)$user_id;
625
-            return self::$_default_creator_id;
626
-        } else {
627
-            return null;
628
-        }
629
-    }
630
-
631
-
632
-
633
-    /**
634
-     * used by EE and EE addons during plugin activation to create tables.
635
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
636
-     * but includes extra logic regarding activations.
637
-     *
638
-     * @access public
639
-     * @static
640
-     * @param string  $table_name              without the $wpdb->prefix
641
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
642
-     *                                         table query)
643
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
644
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
645
-     *                                         and new once this function is done (ie, you really do want to CREATE a
646
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
647
-     *                                         you just want to verify the table exists and matches this definition
648
-     *                                         (and if it HAS data in it you want to leave it be)
649
-     * @return void
650
-     * @throws EE_Error if there are database errors
651
-     */
652
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
653
-    {
654
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
655
-            return;
656
-        }
657
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
658
-        if ( ! function_exists('dbDelta')) {
659
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
660
-        }
661
-        $tableAnalysis = \EEH_Activation::getTableAnalysis();
662
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
663
-        // do we need to first delete an existing version of this table ?
664
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
665
-            // ok, delete the table... but ONLY if it's empty
666
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
667
-            // table is NOT empty, are you SURE you want to delete this table ???
668
-            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
669
-                \EEH_Activation::getTableManager()->dropTable($wp_table_name);
670
-            } else if ( ! $deleted_safely) {
671
-                // so we should be more cautious rather than just dropping tables so easily
672
-                error_log(
673
-                    sprintf(
674
-                        __(
675
-                            'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
676
-                            'event_espresso'
677
-                        ),
678
-                        $wp_table_name,
679
-                        '<br/>',
680
-                        'espresso_db_update'
681
-                    )
682
-                );
683
-            }
684
-        }
685
-        $engine = str_replace('ENGINE=', '', $engine);
686
-        \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
687
-    }
688
-
689
-
690
-
691
-    /**
692
-     *    add_column_if_it_doesn't_exist
693
-     *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
694
-     *
695
-     * @access     public
696
-     * @static
697
-     * @deprecated instead use TableManager::addColumn()
698
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
699
-     * @param string $column_name
700
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
701
-     *                            'VARCHAR(10)'
702
-     * @return bool|int
703
-     */
704
-    public static function add_column_if_it_doesnt_exist(
705
-        $table_name,
706
-        $column_name,
707
-        $column_info = 'INT UNSIGNED NOT NULL'
708
-    ) {
709
-        return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
710
-    }
711
-
712
-
713
-    /**
714
-     * get_fields_on_table
715
-     * Gets all the fields on the database table.
716
-     *
717
-     * @access     public
718
-     * @deprecated instead use TableManager::getTableColumns()
719
-     * @static
720
-     * @param string $table_name , without prefixed $wpdb->prefix
721
-     * @return array of database column names
722
-     */
723
-    public static function get_fields_on_table($table_name = null)
724
-    {
725
-        return \EEH_Activation::getTableManager()->getTableColumns($table_name);
726
-    }
727
-
728
-
729
-    /**
730
-     * db_table_is_empty
731
-     *
732
-     * @access     public\
733
-     * @deprecated instead use TableAnalysis::tableIsEmpty()
734
-     * @static
735
-     * @param string $table_name
736
-     * @return bool
737
-     */
738
-    public static function db_table_is_empty($table_name)
739
-    {
740
-        return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
741
-    }
742
-
743
-
744
-    /**
745
-     * delete_db_table_if_empty
746
-     *
747
-     * @access public
748
-     * @static
749
-     * @param string $table_name
750
-     * @return bool | int
751
-     */
752
-    public static function delete_db_table_if_empty($table_name)
753
-    {
754
-        if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
755
-            return \EEH_Activation::getTableManager()->dropTable($table_name);
756
-        }
757
-        return false;
758
-    }
759
-
760
-
761
-    /**
762
-     * delete_unused_db_table
763
-     *
764
-     * @access     public
765
-     * @static
766
-     * @deprecated instead use TableManager::dropTable()
767
-     * @param string $table_name
768
-     * @return bool | int
769
-     */
770
-    public static function delete_unused_db_table($table_name)
771
-    {
772
-        return \EEH_Activation::getTableManager()->dropTable($table_name);
773
-    }
774
-
775
-
776
-    /**
777
-     * drop_index
778
-     *
779
-     * @access     public
780
-     * @static
781
-     * @deprecated instead use TableManager::dropIndex()
782
-     * @param string $table_name
783
-     * @param string $index_name
784
-     * @return bool | int
785
-     */
786
-    public static function drop_index($table_name, $index_name)
787
-    {
788
-        return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
789
-    }
790
-
791
-
792
-
793
-    /**
794
-     * create_database_tables
795
-     *
796
-     * @access public
797
-     * @static
798
-     * @throws EE_Error
799
-     * @return boolean success (whether database is setup properly or not)
800
-     */
801
-    public static function create_database_tables()
802
-    {
803
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
804
-        //find the migration script that sets the database to be compatible with the code
805
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
806
-        if ($dms_name) {
807
-            $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
808
-            $current_data_migration_script->set_migrating(false);
809
-            $current_data_migration_script->schema_changes_before_migration();
810
-            $current_data_migration_script->schema_changes_after_migration();
811
-            if ($current_data_migration_script->get_errors()) {
812
-                if (WP_DEBUG) {
813
-                    foreach ($current_data_migration_script->get_errors() as $error) {
814
-                        EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
815
-                    }
816
-                } else {
817
-                    EE_Error::add_error(
818
-                        __(
819
-                            'There were errors creating the Event Espresso database tables and Event Espresso has been 
271
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
272
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
273
+			if (is_array($hooks_to_fire_at_time)) {
274
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
275
+					if (isset($ee_cron_tasks_to_remove[$hook_name])
276
+						&& is_array($ee_cron_tasks_to_remove[$hook_name])
277
+					) {
278
+						unset($crons[$timestamp][$hook_name]);
279
+					}
280
+				}
281
+				//also take care of any empty cron timestamps.
282
+				if (empty($hooks_to_fire_at_time)) {
283
+					unset($crons[$timestamp]);
284
+				}
285
+			}
286
+		}
287
+		_set_cron_array($crons);
288
+	}
289
+
290
+
291
+	/**
292
+	 *    CPT_initialization
293
+	 *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
294
+	 *
295
+	 * @access public
296
+	 * @static
297
+	 * @return void
298
+	 */
299
+	public static function CPT_initialization()
300
+	{
301
+		// register Custom Post Types
302
+		EE_Registry::instance()->load_core('Register_CPTs');
303
+		flush_rewrite_rules();
304
+	}
305
+
306
+
307
+
308
+	/**
309
+	 *    reset_and_update_config
310
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
311
+	 * If there is old calendar config data saved, then it will get converted on activation.
312
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
313
+	 *
314
+	 * @access public
315
+	 * @static
316
+	 * @return void
317
+	 */
318
+	public static function reset_and_update_config()
319
+	{
320
+		do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
321
+		add_filter(
322
+			'FHEE__EE_Config___load_core_config__config_settings',
323
+			array('EEH_Activation', 'migrate_old_config_data'),
324
+			10,
325
+			3
326
+		);
327
+		//EE_Config::reset();
328
+		if (! EE_Config::logging_enabled()) {
329
+			delete_option(EE_Config::LOG_NAME);
330
+		}
331
+	}
332
+
333
+
334
+	/**
335
+	 *    load_calendar_config
336
+	 *
337
+	 * @access    public
338
+	 * @return    void
339
+	 */
340
+	public static function load_calendar_config()
341
+	{
342
+		// grab array of all plugin folders and loop thru it
343
+		$plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
344
+		if (empty($plugins)) {
345
+			return;
346
+		}
347
+		foreach ($plugins as $plugin_path) {
348
+			// grab plugin folder name from path
349
+			$plugin = basename($plugin_path);
350
+			// drill down to Espresso plugins
351
+			// then to calendar related plugins
352
+			if (
353
+				strpos($plugin, 'espresso') !== false
354
+				|| strpos($plugin, 'Espresso') !== false
355
+				|| strpos($plugin, 'ee4') !== false
356
+				|| strpos($plugin, 'EE4') !== false
357
+				|| strpos($plugin, 'calendar') !== false
358
+			) {
359
+				// this is what we are looking for
360
+				$calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
361
+				// does it exist in this folder ?
362
+				if (is_readable($calendar_config)) {
363
+					// YEAH! let's load it
364
+					require_once($calendar_config);
365
+				}
366
+			}
367
+		}
368
+	}
369
+
370
+
371
+
372
+	/**
373
+	 *    _migrate_old_config_data
374
+	 *
375
+	 * @access    public
376
+	 * @param array|stdClass $settings
377
+	 * @param string         $config
378
+	 * @param \EE_Config     $EE_Config
379
+	 * @return \stdClass
380
+	 */
381
+	public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
382
+	{
383
+		$convert_from_array = array('addons');
384
+		// in case old settings were saved as an array
385
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
386
+			// convert existing settings to an object
387
+			$config_array = $settings;
388
+			$settings = new stdClass();
389
+			foreach ($config_array as $key => $value) {
390
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
391
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
392
+				} else {
393
+					$settings->{$key} = $value;
394
+				}
395
+			}
396
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
397
+		}
398
+		return $settings;
399
+	}
400
+
401
+
402
+	/**
403
+	 * deactivate_event_espresso
404
+	 *
405
+	 * @access public
406
+	 * @static
407
+	 * @return void
408
+	 */
409
+	public static function deactivate_event_espresso()
410
+	{
411
+		// check permissions
412
+		if (current_user_can('activate_plugins')) {
413
+			deactivate_plugins(EE_PLUGIN_BASENAME, true);
414
+		}
415
+	}
416
+
417
+
418
+
419
+
420
+
421
+	/**
422
+	 * verify_default_pages_exist
423
+	 *
424
+	 * @access public
425
+	 * @static
426
+	 * @return void
427
+	 */
428
+	public static function verify_default_pages_exist()
429
+	{
430
+		$critical_page_problem = false;
431
+		$critical_pages = array(
432
+			array(
433
+				'id'   => 'reg_page_id',
434
+				'name' => __('Registration Checkout', 'event_espresso'),
435
+				'post' => null,
436
+				'code' => 'ESPRESSO_CHECKOUT',
437
+			),
438
+			array(
439
+				'id'   => 'txn_page_id',
440
+				'name' => __('Transactions', 'event_espresso'),
441
+				'post' => null,
442
+				'code' => 'ESPRESSO_TXN_PAGE',
443
+			),
444
+			array(
445
+				'id'   => 'thank_you_page_id',
446
+				'name' => __('Thank You', 'event_espresso'),
447
+				'post' => null,
448
+				'code' => 'ESPRESSO_THANK_YOU',
449
+			),
450
+			array(
451
+				'id'   => 'cancel_page_id',
452
+				'name' => __('Registration Cancelled', 'event_espresso'),
453
+				'post' => null,
454
+				'code' => 'ESPRESSO_CANCELLED',
455
+			),
456
+		);
457
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
458
+		foreach ($critical_pages as $critical_page) {
459
+			// is critical page ID set in config ?
460
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
461
+				// attempt to find post by ID
462
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
463
+			}
464
+			// no dice?
465
+			if ($critical_page['post'] === null) {
466
+				// attempt to find post by title
467
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
468
+				// still nothing?
469
+				if ($critical_page['post'] === null) {
470
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
471
+					// REALLY? Still nothing ??!?!?
472
+					if ($critical_page['post'] === null) {
473
+						$msg = __(
474
+							'The Event Espresso critical page configuration settings could not be updated.',
475
+							'event_espresso'
476
+						);
477
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
478
+						break;
479
+					}
480
+				}
481
+			}
482
+			// check that Post ID matches critical page ID in config
483
+			if (
484
+				isset($critical_page['post']->ID)
485
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
486
+			) {
487
+				//update Config with post ID
488
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
489
+				if (! EE_Config::instance()->update_espresso_config(false, false)) {
490
+					$msg = __(
491
+						'The Event Espresso critical page configuration settings could not be updated.',
492
+						'event_espresso'
493
+					);
494
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
495
+				}
496
+			}
497
+			$critical_page_problem =
498
+				! isset($critical_page['post']->post_status)
499
+				|| $critical_page['post']->post_status !== 'publish'
500
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
501
+					? true
502
+					: $critical_page_problem;
503
+		}
504
+		if ($critical_page_problem) {
505
+			$msg = sprintf(
506
+				__(
507
+					'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
508
+					'event_espresso'
509
+				),
510
+				'<a href="'
511
+				. admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
512
+				. '">'
513
+				. __('Event Espresso Critical Pages Settings', 'event_espresso')
514
+				. '</a>'
515
+			);
516
+			EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
517
+		}
518
+		if (EE_Error::has_notices()) {
519
+			EE_Error::get_notices(false, true, true);
520
+		}
521
+	}
522
+
523
+
524
+
525
+	/**
526
+	 * Returns the first post which uses the specified shortcode
527
+	 *
528
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
529
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
530
+	 *                             "[ESPRESSO_THANK_YOU"
531
+	 *                             (we don't search for the closing shortcode bracket because they might have added
532
+	 *                             parameter to the shortcode
533
+	 * @return WP_Post or NULl
534
+	 */
535
+	public static function get_page_by_ee_shortcode($ee_shortcode)
536
+	{
537
+		global $wpdb;
538
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
539
+		$post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
540
+		if ($post_id) {
541
+			return get_post($post_id);
542
+		} else {
543
+			return null;
544
+		}
545
+	}
546
+
547
+
548
+	/**
549
+	 *    This function generates a post for critical espresso pages
550
+	 *
551
+	 * @access public
552
+	 * @static
553
+	 * @param array $critical_page
554
+	 * @return array
555
+	 */
556
+	public static function create_critical_page($critical_page)
557
+	{
558
+
559
+		$post_args = array(
560
+			'post_title'     => $critical_page['name'],
561
+			'post_status'    => 'publish',
562
+			'post_type'      => 'page',
563
+			'comment_status' => 'closed',
564
+			'post_content'   => '[' . $critical_page['code'] . ']',
565
+		);
566
+
567
+		$post_id = wp_insert_post($post_args);
568
+		if (! $post_id) {
569
+			$msg = sprintf(
570
+				__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
571
+				$critical_page['name']
572
+			);
573
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
574
+			return $critical_page;
575
+		}
576
+		// get newly created post's details
577
+		if (! $critical_page['post'] = get_post($post_id)) {
578
+			$msg = sprintf(
579
+				__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
580
+				$critical_page['name']
581
+			);
582
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
583
+		}
584
+
585
+		return $critical_page;
586
+
587
+	}
588
+
589
+
590
+
591
+
592
+	/**
593
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
594
+	 * The role being used to check is filterable.
595
+	 *
596
+	 * @since  4.6.0
597
+	 * @global WPDB $wpdb
598
+	 * @return mixed null|int WP_user ID or NULL
599
+	 */
600
+	public static function get_default_creator_id()
601
+	{
602
+		global $wpdb;
603
+		if ( ! empty(self::$_default_creator_id)) {
604
+			return self::$_default_creator_id;
605
+		}/**/
606
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
607
+		//let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
608
+		$pre_filtered_id = apply_filters(
609
+			'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
610
+			false,
611
+			$role_to_check
612
+		);
613
+		if ($pre_filtered_id !== false) {
614
+			return (int)$pre_filtered_id;
615
+		}
616
+		$capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
617
+		$query = $wpdb->prepare(
618
+			"SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
619
+			'%' . $role_to_check . '%'
620
+		);
621
+		$user_id = $wpdb->get_var($query);
622
+		$user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
623
+		if ($user_id && (int)$user_id) {
624
+			self::$_default_creator_id = (int)$user_id;
625
+			return self::$_default_creator_id;
626
+		} else {
627
+			return null;
628
+		}
629
+	}
630
+
631
+
632
+
633
+	/**
634
+	 * used by EE and EE addons during plugin activation to create tables.
635
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
636
+	 * but includes extra logic regarding activations.
637
+	 *
638
+	 * @access public
639
+	 * @static
640
+	 * @param string  $table_name              without the $wpdb->prefix
641
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
642
+	 *                                         table query)
643
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
644
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
645
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
646
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
647
+	 *                                         you just want to verify the table exists and matches this definition
648
+	 *                                         (and if it HAS data in it you want to leave it be)
649
+	 * @return void
650
+	 * @throws EE_Error if there are database errors
651
+	 */
652
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
653
+	{
654
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
655
+			return;
656
+		}
657
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
658
+		if ( ! function_exists('dbDelta')) {
659
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
660
+		}
661
+		$tableAnalysis = \EEH_Activation::getTableAnalysis();
662
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
663
+		// do we need to first delete an existing version of this table ?
664
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
665
+			// ok, delete the table... but ONLY if it's empty
666
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
667
+			// table is NOT empty, are you SURE you want to delete this table ???
668
+			if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
669
+				\EEH_Activation::getTableManager()->dropTable($wp_table_name);
670
+			} else if ( ! $deleted_safely) {
671
+				// so we should be more cautious rather than just dropping tables so easily
672
+				error_log(
673
+					sprintf(
674
+						__(
675
+							'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
676
+							'event_espresso'
677
+						),
678
+						$wp_table_name,
679
+						'<br/>',
680
+						'espresso_db_update'
681
+					)
682
+				);
683
+			}
684
+		}
685
+		$engine = str_replace('ENGINE=', '', $engine);
686
+		\EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
687
+	}
688
+
689
+
690
+
691
+	/**
692
+	 *    add_column_if_it_doesn't_exist
693
+	 *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
694
+	 *
695
+	 * @access     public
696
+	 * @static
697
+	 * @deprecated instead use TableManager::addColumn()
698
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
699
+	 * @param string $column_name
700
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
701
+	 *                            'VARCHAR(10)'
702
+	 * @return bool|int
703
+	 */
704
+	public static function add_column_if_it_doesnt_exist(
705
+		$table_name,
706
+		$column_name,
707
+		$column_info = 'INT UNSIGNED NOT NULL'
708
+	) {
709
+		return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
710
+	}
711
+
712
+
713
+	/**
714
+	 * get_fields_on_table
715
+	 * Gets all the fields on the database table.
716
+	 *
717
+	 * @access     public
718
+	 * @deprecated instead use TableManager::getTableColumns()
719
+	 * @static
720
+	 * @param string $table_name , without prefixed $wpdb->prefix
721
+	 * @return array of database column names
722
+	 */
723
+	public static function get_fields_on_table($table_name = null)
724
+	{
725
+		return \EEH_Activation::getTableManager()->getTableColumns($table_name);
726
+	}
727
+
728
+
729
+	/**
730
+	 * db_table_is_empty
731
+	 *
732
+	 * @access     public\
733
+	 * @deprecated instead use TableAnalysis::tableIsEmpty()
734
+	 * @static
735
+	 * @param string $table_name
736
+	 * @return bool
737
+	 */
738
+	public static function db_table_is_empty($table_name)
739
+	{
740
+		return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
741
+	}
742
+
743
+
744
+	/**
745
+	 * delete_db_table_if_empty
746
+	 *
747
+	 * @access public
748
+	 * @static
749
+	 * @param string $table_name
750
+	 * @return bool | int
751
+	 */
752
+	public static function delete_db_table_if_empty($table_name)
753
+	{
754
+		if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
755
+			return \EEH_Activation::getTableManager()->dropTable($table_name);
756
+		}
757
+		return false;
758
+	}
759
+
760
+
761
+	/**
762
+	 * delete_unused_db_table
763
+	 *
764
+	 * @access     public
765
+	 * @static
766
+	 * @deprecated instead use TableManager::dropTable()
767
+	 * @param string $table_name
768
+	 * @return bool | int
769
+	 */
770
+	public static function delete_unused_db_table($table_name)
771
+	{
772
+		return \EEH_Activation::getTableManager()->dropTable($table_name);
773
+	}
774
+
775
+
776
+	/**
777
+	 * drop_index
778
+	 *
779
+	 * @access     public
780
+	 * @static
781
+	 * @deprecated instead use TableManager::dropIndex()
782
+	 * @param string $table_name
783
+	 * @param string $index_name
784
+	 * @return bool | int
785
+	 */
786
+	public static function drop_index($table_name, $index_name)
787
+	{
788
+		return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
789
+	}
790
+
791
+
792
+
793
+	/**
794
+	 * create_database_tables
795
+	 *
796
+	 * @access public
797
+	 * @static
798
+	 * @throws EE_Error
799
+	 * @return boolean success (whether database is setup properly or not)
800
+	 */
801
+	public static function create_database_tables()
802
+	{
803
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
804
+		//find the migration script that sets the database to be compatible with the code
805
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
806
+		if ($dms_name) {
807
+			$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
808
+			$current_data_migration_script->set_migrating(false);
809
+			$current_data_migration_script->schema_changes_before_migration();
810
+			$current_data_migration_script->schema_changes_after_migration();
811
+			if ($current_data_migration_script->get_errors()) {
812
+				if (WP_DEBUG) {
813
+					foreach ($current_data_migration_script->get_errors() as $error) {
814
+						EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
815
+					}
816
+				} else {
817
+					EE_Error::add_error(
818
+						__(
819
+							'There were errors creating the Event Espresso database tables and Event Espresso has been 
820 820
                             deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
821
-                            'event_espresso'
822
-                        )
823
-                    );
824
-                }
825
-                return false;
826
-            }
827
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to();
828
-        } else {
829
-            EE_Error::add_error(
830
-                __(
831
-                    'Could not determine most up-to-date data migration script from which to pull database schema
821
+							'event_espresso'
822
+						)
823
+					);
824
+				}
825
+				return false;
826
+			}
827
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to();
828
+		} else {
829
+			EE_Error::add_error(
830
+				__(
831
+					'Could not determine most up-to-date data migration script from which to pull database schema
832 832
                      structure. So database is probably not setup properly',
833
-                    'event_espresso'
834
-                ),
835
-                __FILE__,
836
-                __FUNCTION__,
837
-                __LINE__
838
-            );
839
-            return false;
840
-        }
841
-        return true;
842
-    }
843
-
844
-
845
-
846
-    /**
847
-     * initialize_system_questions
848
-     *
849
-     * @access public
850
-     * @static
851
-     * @return void
852
-     */
853
-    public static function initialize_system_questions()
854
-    {
855
-        // QUESTION GROUPS
856
-        global $wpdb;
857
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
858
-        $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
859
-        // what we have
860
-        $question_groups = $wpdb->get_col($SQL);
861
-        // check the response
862
-        $question_groups = is_array($question_groups) ? $question_groups : array();
863
-        // what we should have
864
-        $QSG_systems = array(1, 2);
865
-        // loop thru what we should have and compare to what we have
866
-        foreach ($QSG_systems as $QSG_system) {
867
-            // reset values array
868
-            $QSG_values = array();
869
-            // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
870
-            if (! in_array("$QSG_system", $question_groups)) {
871
-                // add it
872
-                switch ($QSG_system) {
873
-                    case 1:
874
-                        $QSG_values = array(
875
-                            'QSG_name'            => __('Personal Information', 'event_espresso'),
876
-                            'QSG_identifier'      => 'personal-information-' . time(),
877
-                            'QSG_desc'            => '',
878
-                            'QSG_order'           => 1,
879
-                            'QSG_show_group_name' => 1,
880
-                            'QSG_show_group_desc' => 1,
881
-                            'QSG_system'          => EEM_Question_Group::system_personal,
882
-                            'QSG_deleted'         => 0,
883
-                        );
884
-                        break;
885
-                    case 2:
886
-                        $QSG_values = array(
887
-                            'QSG_name'            => __('Address Information', 'event_espresso'),
888
-                            'QSG_identifier'      => 'address-information-' . time(),
889
-                            'QSG_desc'            => '',
890
-                            'QSG_order'           => 2,
891
-                            'QSG_show_group_name' => 1,
892
-                            'QSG_show_group_desc' => 1,
893
-                            'QSG_system'          => EEM_Question_Group::system_address,
894
-                            'QSG_deleted'         => 0,
895
-                        );
896
-                        break;
897
-                }
898
-                // make sure we have some values before inserting them
899
-                if (! empty($QSG_values)) {
900
-                    // insert system question
901
-                    $wpdb->insert(
902
-                        $table_name,
903
-                        $QSG_values,
904
-                        array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
905
-                    );
906
-                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
907
-                }
908
-            }
909
-        }
910
-        // QUESTIONS
911
-        global $wpdb;
912
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
913
-        $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
914
-        // what we have
915
-        $questions = $wpdb->get_col($SQL);
916
-        // what we should have
917
-        $QST_systems = array(
918
-            'fname',
919
-            'lname',
920
-            'email',
921
-            'address',
922
-            'address2',
923
-            'city',
924
-            'country',
925
-            'state',
926
-            'zip',
927
-            'phone',
928
-        );
929
-        $order_for_group_1 = 1;
930
-        $order_for_group_2 = 1;
931
-        // loop thru what we should have and compare to what we have
932
-        foreach ($QST_systems as $QST_system) {
933
-            // reset values array
934
-            $QST_values = array();
935
-            // if we don't have what we should have
936
-            if (! in_array($QST_system, $questions)) {
937
-                // add it
938
-                switch ($QST_system) {
939
-                    case 'fname':
940
-                        $QST_values = array(
941
-                            'QST_display_text'  => __('First Name', 'event_espresso'),
942
-                            'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
943
-                            'QST_system'        => 'fname',
944
-                            'QST_type'          => 'TEXT',
945
-                            'QST_required'      => 1,
946
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
947
-                            'QST_order'         => 1,
948
-                            'QST_admin_only'    => 0,
949
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
950
-                            'QST_wp_user'       => self::get_default_creator_id(),
951
-                            'QST_deleted'       => 0,
952
-                        );
953
-                        break;
954
-                    case 'lname':
955
-                        $QST_values = array(
956
-                            'QST_display_text'  => __('Last Name', 'event_espresso'),
957
-                            'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
958
-                            'QST_system'        => 'lname',
959
-                            'QST_type'          => 'TEXT',
960
-                            'QST_required'      => 1,
961
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
962
-                            'QST_order'         => 2,
963
-                            'QST_admin_only'    => 0,
964
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
965
-                            'QST_wp_user'       => self::get_default_creator_id(),
966
-                            'QST_deleted'       => 0,
967
-                        );
968
-                        break;
969
-                    case 'email':
970
-                        $QST_values = array(
971
-                            'QST_display_text'  => __('Email Address', 'event_espresso'),
972
-                            'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
973
-                            'QST_system'        => 'email',
974
-                            'QST_type'          => 'EMAIL',
975
-                            'QST_required'      => 1,
976
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
977
-                            'QST_order'         => 3,
978
-                            'QST_admin_only'    => 0,
979
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
980
-                            'QST_wp_user'       => self::get_default_creator_id(),
981
-                            'QST_deleted'       => 0,
982
-                        );
983
-                        break;
984
-                    case 'address':
985
-                        $QST_values = array(
986
-                            'QST_display_text'  => __('Address', 'event_espresso'),
987
-                            'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
988
-                            'QST_system'        => 'address',
989
-                            'QST_type'          => 'TEXT',
990
-                            'QST_required'      => 0,
991
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
992
-                            'QST_order'         => 4,
993
-                            'QST_admin_only'    => 0,
994
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
995
-                            'QST_wp_user'       => self::get_default_creator_id(),
996
-                            'QST_deleted'       => 0,
997
-                        );
998
-                        break;
999
-                    case 'address2':
1000
-                        $QST_values = array(
1001
-                            'QST_display_text'  => __('Address2', 'event_espresso'),
1002
-                            'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1003
-                            'QST_system'        => 'address2',
1004
-                            'QST_type'          => 'TEXT',
1005
-                            'QST_required'      => 0,
1006
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1007
-                            'QST_order'         => 5,
1008
-                            'QST_admin_only'    => 0,
1009
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1010
-                            'QST_wp_user'       => self::get_default_creator_id(),
1011
-                            'QST_deleted'       => 0,
1012
-                        );
1013
-                        break;
1014
-                    case 'city':
1015
-                        $QST_values = array(
1016
-                            'QST_display_text'  => __('City', 'event_espresso'),
1017
-                            'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1018
-                            'QST_system'        => 'city',
1019
-                            'QST_type'          => 'TEXT',
1020
-                            'QST_required'      => 0,
1021
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1022
-                            'QST_order'         => 6,
1023
-                            'QST_admin_only'    => 0,
1024
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1025
-                            'QST_wp_user'       => self::get_default_creator_id(),
1026
-                            'QST_deleted'       => 0,
1027
-                        );
1028
-                        break;
1029
-                    case 'country':
1030
-                        $QST_values = array(
1031
-                            'QST_display_text'  => __('Country', 'event_espresso'),
1032
-                            'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1033
-                            'QST_system'        => 'country',
1034
-                            'QST_type'          => 'COUNTRY',
1035
-                            'QST_required'      => 0,
1036
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1037
-                            'QST_order'         => 7,
1038
-                            'QST_admin_only'    => 0,
1039
-                            'QST_wp_user'       => self::get_default_creator_id(),
1040
-                            'QST_deleted'       => 0,
1041
-                        );
1042
-                        break;
1043
-                    case 'state':
1044
-                        $QST_values = array(
1045
-                            'QST_display_text'  => __('State/Province', 'event_espresso'),
1046
-                            'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1047
-                            'QST_system'        => 'state',
1048
-                            'QST_type'          => 'STATE',
1049
-                            'QST_required'      => 0,
1050
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1051
-                            'QST_order'         => 8,
1052
-                            'QST_admin_only'    => 0,
1053
-                            'QST_wp_user'       => self::get_default_creator_id(),
1054
-                            'QST_deleted'       => 0,
1055
-                        );
1056
-                        break;
1057
-                    case 'zip':
1058
-                        $QST_values = array(
1059
-                            'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1060
-                            'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1061
-                            'QST_system'        => 'zip',
1062
-                            'QST_type'          => 'TEXT',
1063
-                            'QST_required'      => 0,
1064
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1065
-                            'QST_order'         => 9,
1066
-                            'QST_admin_only'    => 0,
1067
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1068
-                            'QST_wp_user'       => self::get_default_creator_id(),
1069
-                            'QST_deleted'       => 0,
1070
-                        );
1071
-                        break;
1072
-                    case 'phone':
1073
-                        $QST_values = array(
1074
-                            'QST_display_text'  => __('Phone Number', 'event_espresso'),
1075
-                            'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1076
-                            'QST_system'        => 'phone',
1077
-                            'QST_type'          => 'TEXT',
1078
-                            'QST_required'      => 0,
1079
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1080
-                            'QST_order'         => 10,
1081
-                            'QST_admin_only'    => 0,
1082
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1083
-                            'QST_wp_user'       => self::get_default_creator_id(),
1084
-                            'QST_deleted'       => 0,
1085
-                        );
1086
-                        break;
1087
-                }
1088
-                if (! empty($QST_values)) {
1089
-                    // insert system question
1090
-                    $wpdb->insert(
1091
-                        $table_name,
1092
-                        $QST_values,
1093
-                        array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1094
-                    );
1095
-                    $QST_ID = $wpdb->insert_id;
1096
-                    // QUESTION GROUP QUESTIONS
1097
-                    if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1098
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1099
-                    } else {
1100
-                        $system_question_we_want = EEM_Question_Group::system_address;
1101
-                    }
1102
-                    if (isset($QSG_IDs[$system_question_we_want])) {
1103
-                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1104
-                    } else {
1105
-                        $id_col = EEM_Question_Group::instance()
1106
-                                                    ->get_col(array(array('QSG_system' => $system_question_we_want)));
1107
-                        if (is_array($id_col)) {
1108
-                            $QSG_ID = reset($id_col);
1109
-                        } else {
1110
-                            //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1111
-                            EE_Log::instance()->log(
1112
-                                __FILE__,
1113
-                                __FUNCTION__,
1114
-                                sprintf(
1115
-                                    __(
1116
-                                        'Could not associate question %1$s to a question group because no system question
833
+					'event_espresso'
834
+				),
835
+				__FILE__,
836
+				__FUNCTION__,
837
+				__LINE__
838
+			);
839
+			return false;
840
+		}
841
+		return true;
842
+	}
843
+
844
+
845
+
846
+	/**
847
+	 * initialize_system_questions
848
+	 *
849
+	 * @access public
850
+	 * @static
851
+	 * @return void
852
+	 */
853
+	public static function initialize_system_questions()
854
+	{
855
+		// QUESTION GROUPS
856
+		global $wpdb;
857
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
858
+		$SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
859
+		// what we have
860
+		$question_groups = $wpdb->get_col($SQL);
861
+		// check the response
862
+		$question_groups = is_array($question_groups) ? $question_groups : array();
863
+		// what we should have
864
+		$QSG_systems = array(1, 2);
865
+		// loop thru what we should have and compare to what we have
866
+		foreach ($QSG_systems as $QSG_system) {
867
+			// reset values array
868
+			$QSG_values = array();
869
+			// if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
870
+			if (! in_array("$QSG_system", $question_groups)) {
871
+				// add it
872
+				switch ($QSG_system) {
873
+					case 1:
874
+						$QSG_values = array(
875
+							'QSG_name'            => __('Personal Information', 'event_espresso'),
876
+							'QSG_identifier'      => 'personal-information-' . time(),
877
+							'QSG_desc'            => '',
878
+							'QSG_order'           => 1,
879
+							'QSG_show_group_name' => 1,
880
+							'QSG_show_group_desc' => 1,
881
+							'QSG_system'          => EEM_Question_Group::system_personal,
882
+							'QSG_deleted'         => 0,
883
+						);
884
+						break;
885
+					case 2:
886
+						$QSG_values = array(
887
+							'QSG_name'            => __('Address Information', 'event_espresso'),
888
+							'QSG_identifier'      => 'address-information-' . time(),
889
+							'QSG_desc'            => '',
890
+							'QSG_order'           => 2,
891
+							'QSG_show_group_name' => 1,
892
+							'QSG_show_group_desc' => 1,
893
+							'QSG_system'          => EEM_Question_Group::system_address,
894
+							'QSG_deleted'         => 0,
895
+						);
896
+						break;
897
+				}
898
+				// make sure we have some values before inserting them
899
+				if (! empty($QSG_values)) {
900
+					// insert system question
901
+					$wpdb->insert(
902
+						$table_name,
903
+						$QSG_values,
904
+						array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
905
+					);
906
+					$QSG_IDs[$QSG_system] = $wpdb->insert_id;
907
+				}
908
+			}
909
+		}
910
+		// QUESTIONS
911
+		global $wpdb;
912
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
913
+		$SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
914
+		// what we have
915
+		$questions = $wpdb->get_col($SQL);
916
+		// what we should have
917
+		$QST_systems = array(
918
+			'fname',
919
+			'lname',
920
+			'email',
921
+			'address',
922
+			'address2',
923
+			'city',
924
+			'country',
925
+			'state',
926
+			'zip',
927
+			'phone',
928
+		);
929
+		$order_for_group_1 = 1;
930
+		$order_for_group_2 = 1;
931
+		// loop thru what we should have and compare to what we have
932
+		foreach ($QST_systems as $QST_system) {
933
+			// reset values array
934
+			$QST_values = array();
935
+			// if we don't have what we should have
936
+			if (! in_array($QST_system, $questions)) {
937
+				// add it
938
+				switch ($QST_system) {
939
+					case 'fname':
940
+						$QST_values = array(
941
+							'QST_display_text'  => __('First Name', 'event_espresso'),
942
+							'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
943
+							'QST_system'        => 'fname',
944
+							'QST_type'          => 'TEXT',
945
+							'QST_required'      => 1,
946
+							'QST_required_text' => __('This field is required', 'event_espresso'),
947
+							'QST_order'         => 1,
948
+							'QST_admin_only'    => 0,
949
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
950
+							'QST_wp_user'       => self::get_default_creator_id(),
951
+							'QST_deleted'       => 0,
952
+						);
953
+						break;
954
+					case 'lname':
955
+						$QST_values = array(
956
+							'QST_display_text'  => __('Last Name', 'event_espresso'),
957
+							'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
958
+							'QST_system'        => 'lname',
959
+							'QST_type'          => 'TEXT',
960
+							'QST_required'      => 1,
961
+							'QST_required_text' => __('This field is required', 'event_espresso'),
962
+							'QST_order'         => 2,
963
+							'QST_admin_only'    => 0,
964
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
965
+							'QST_wp_user'       => self::get_default_creator_id(),
966
+							'QST_deleted'       => 0,
967
+						);
968
+						break;
969
+					case 'email':
970
+						$QST_values = array(
971
+							'QST_display_text'  => __('Email Address', 'event_espresso'),
972
+							'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
973
+							'QST_system'        => 'email',
974
+							'QST_type'          => 'EMAIL',
975
+							'QST_required'      => 1,
976
+							'QST_required_text' => __('This field is required', 'event_espresso'),
977
+							'QST_order'         => 3,
978
+							'QST_admin_only'    => 0,
979
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
980
+							'QST_wp_user'       => self::get_default_creator_id(),
981
+							'QST_deleted'       => 0,
982
+						);
983
+						break;
984
+					case 'address':
985
+						$QST_values = array(
986
+							'QST_display_text'  => __('Address', 'event_espresso'),
987
+							'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
988
+							'QST_system'        => 'address',
989
+							'QST_type'          => 'TEXT',
990
+							'QST_required'      => 0,
991
+							'QST_required_text' => __('This field is required', 'event_espresso'),
992
+							'QST_order'         => 4,
993
+							'QST_admin_only'    => 0,
994
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
995
+							'QST_wp_user'       => self::get_default_creator_id(),
996
+							'QST_deleted'       => 0,
997
+						);
998
+						break;
999
+					case 'address2':
1000
+						$QST_values = array(
1001
+							'QST_display_text'  => __('Address2', 'event_espresso'),
1002
+							'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1003
+							'QST_system'        => 'address2',
1004
+							'QST_type'          => 'TEXT',
1005
+							'QST_required'      => 0,
1006
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1007
+							'QST_order'         => 5,
1008
+							'QST_admin_only'    => 0,
1009
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1010
+							'QST_wp_user'       => self::get_default_creator_id(),
1011
+							'QST_deleted'       => 0,
1012
+						);
1013
+						break;
1014
+					case 'city':
1015
+						$QST_values = array(
1016
+							'QST_display_text'  => __('City', 'event_espresso'),
1017
+							'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1018
+							'QST_system'        => 'city',
1019
+							'QST_type'          => 'TEXT',
1020
+							'QST_required'      => 0,
1021
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1022
+							'QST_order'         => 6,
1023
+							'QST_admin_only'    => 0,
1024
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1025
+							'QST_wp_user'       => self::get_default_creator_id(),
1026
+							'QST_deleted'       => 0,
1027
+						);
1028
+						break;
1029
+					case 'country':
1030
+						$QST_values = array(
1031
+							'QST_display_text'  => __('Country', 'event_espresso'),
1032
+							'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1033
+							'QST_system'        => 'country',
1034
+							'QST_type'          => 'COUNTRY',
1035
+							'QST_required'      => 0,
1036
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1037
+							'QST_order'         => 7,
1038
+							'QST_admin_only'    => 0,
1039
+							'QST_wp_user'       => self::get_default_creator_id(),
1040
+							'QST_deleted'       => 0,
1041
+						);
1042
+						break;
1043
+					case 'state':
1044
+						$QST_values = array(
1045
+							'QST_display_text'  => __('State/Province', 'event_espresso'),
1046
+							'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1047
+							'QST_system'        => 'state',
1048
+							'QST_type'          => 'STATE',
1049
+							'QST_required'      => 0,
1050
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1051
+							'QST_order'         => 8,
1052
+							'QST_admin_only'    => 0,
1053
+							'QST_wp_user'       => self::get_default_creator_id(),
1054
+							'QST_deleted'       => 0,
1055
+						);
1056
+						break;
1057
+					case 'zip':
1058
+						$QST_values = array(
1059
+							'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1060
+							'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1061
+							'QST_system'        => 'zip',
1062
+							'QST_type'          => 'TEXT',
1063
+							'QST_required'      => 0,
1064
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1065
+							'QST_order'         => 9,
1066
+							'QST_admin_only'    => 0,
1067
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1068
+							'QST_wp_user'       => self::get_default_creator_id(),
1069
+							'QST_deleted'       => 0,
1070
+						);
1071
+						break;
1072
+					case 'phone':
1073
+						$QST_values = array(
1074
+							'QST_display_text'  => __('Phone Number', 'event_espresso'),
1075
+							'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1076
+							'QST_system'        => 'phone',
1077
+							'QST_type'          => 'TEXT',
1078
+							'QST_required'      => 0,
1079
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1080
+							'QST_order'         => 10,
1081
+							'QST_admin_only'    => 0,
1082
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1083
+							'QST_wp_user'       => self::get_default_creator_id(),
1084
+							'QST_deleted'       => 0,
1085
+						);
1086
+						break;
1087
+				}
1088
+				if (! empty($QST_values)) {
1089
+					// insert system question
1090
+					$wpdb->insert(
1091
+						$table_name,
1092
+						$QST_values,
1093
+						array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1094
+					);
1095
+					$QST_ID = $wpdb->insert_id;
1096
+					// QUESTION GROUP QUESTIONS
1097
+					if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1098
+						$system_question_we_want = EEM_Question_Group::system_personal;
1099
+					} else {
1100
+						$system_question_we_want = EEM_Question_Group::system_address;
1101
+					}
1102
+					if (isset($QSG_IDs[$system_question_we_want])) {
1103
+						$QSG_ID = $QSG_IDs[$system_question_we_want];
1104
+					} else {
1105
+						$id_col = EEM_Question_Group::instance()
1106
+													->get_col(array(array('QSG_system' => $system_question_we_want)));
1107
+						if (is_array($id_col)) {
1108
+							$QSG_ID = reset($id_col);
1109
+						} else {
1110
+							//ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1111
+							EE_Log::instance()->log(
1112
+								__FILE__,
1113
+								__FUNCTION__,
1114
+								sprintf(
1115
+									__(
1116
+										'Could not associate question %1$s to a question group because no system question
1117 1117
                                          group existed',
1118
-                                        'event_espresso'
1119
-                                    ),
1120
-                                    $QST_ID),
1121
-                                'error');
1122
-                            continue;
1123
-                        }
1124
-                    }
1125
-                    // add system questions to groups
1126
-                    $wpdb->insert(
1127
-                        \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1128
-                        array(
1129
-                            'QSG_ID'    => $QSG_ID,
1130
-                            'QST_ID'    => $QST_ID,
1131
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1132
-                        ),
1133
-                        array('%d', '%d', '%d')
1134
-                    );
1135
-                }
1136
-            }
1137
-        }
1138
-    }
1139
-
1140
-
1141
-    /**
1142
-     * Makes sure the default payment method (Invoice) is active.
1143
-     * This used to be done automatically as part of constructing the old gateways config
1144
-     *
1145
-     * @throws \EE_Error
1146
-     */
1147
-    public static function insert_default_payment_methods()
1148
-    {
1149
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1150
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
1151
-            EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1152
-        } else {
1153
-            EEM_Payment_Method::instance()->verify_button_urls();
1154
-        }
1155
-    }
1156
-
1157
-    /**
1158
-     * insert_default_status_codes
1159
-     *
1160
-     * @access public
1161
-     * @static
1162
-     * @return void
1163
-     */
1164
-    public static function insert_default_status_codes()
1165
-    {
1166
-
1167
-        global $wpdb;
1168
-
1169
-        if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1170
-
1171
-            $table_name = EEM_Status::instance()->table();
1172
-
1173
-            $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1174
-            $wpdb->query($SQL);
1175
-
1176
-            $SQL = "INSERT INTO $table_name
1118
+										'event_espresso'
1119
+									),
1120
+									$QST_ID),
1121
+								'error');
1122
+							continue;
1123
+						}
1124
+					}
1125
+					// add system questions to groups
1126
+					$wpdb->insert(
1127
+						\EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1128
+						array(
1129
+							'QSG_ID'    => $QSG_ID,
1130
+							'QST_ID'    => $QST_ID,
1131
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1132
+						),
1133
+						array('%d', '%d', '%d')
1134
+					);
1135
+				}
1136
+			}
1137
+		}
1138
+	}
1139
+
1140
+
1141
+	/**
1142
+	 * Makes sure the default payment method (Invoice) is active.
1143
+	 * This used to be done automatically as part of constructing the old gateways config
1144
+	 *
1145
+	 * @throws \EE_Error
1146
+	 */
1147
+	public static function insert_default_payment_methods()
1148
+	{
1149
+		if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1150
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1151
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1152
+		} else {
1153
+			EEM_Payment_Method::instance()->verify_button_urls();
1154
+		}
1155
+	}
1156
+
1157
+	/**
1158
+	 * insert_default_status_codes
1159
+	 *
1160
+	 * @access public
1161
+	 * @static
1162
+	 * @return void
1163
+	 */
1164
+	public static function insert_default_status_codes()
1165
+	{
1166
+
1167
+		global $wpdb;
1168
+
1169
+		if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1170
+
1171
+			$table_name = EEM_Status::instance()->table();
1172
+
1173
+			$SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1174
+			$wpdb->query($SQL);
1175
+
1176
+			$SQL = "INSERT INTO $table_name
1177 1177
 					(STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES
1178 1178
 					('ACT', 'ACTIVE', 'event', 0, NULL, 1),
1179 1179
 					('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0),
@@ -1213,521 +1213,521 @@  discard block
 block discarded – undo
1213 1213
 					('MID', 'IDLE', 'message', 0, NULL, 1),
1214 1214
 					('MRS', 'RESEND', 'message', 0, NULL, 1),
1215 1215
 					('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);";
1216
-            $wpdb->query($SQL);
1217
-
1218
-        }
1219
-
1220
-    }
1221
-
1222
-
1223
-    /**
1224
-     * create_upload_directories
1225
-     * Creates folders in the uploads directory to facilitate addons and templates
1226
-     *
1227
-     * @access public
1228
-     * @static
1229
-     * @return boolean success of verifying upload directories exist
1230
-     */
1231
-    public static function create_upload_directories()
1232
-    {
1233
-        // Create the required folders
1234
-        $folders = array(
1235
-            EVENT_ESPRESSO_TEMPLATE_DIR,
1236
-            EVENT_ESPRESSO_GATEWAY_DIR,
1237
-            EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1238
-            EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1239
-            EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1240
-        );
1241
-        foreach ($folders as $folder) {
1242
-            try {
1243
-                EEH_File::ensure_folder_exists_and_is_writable($folder);
1244
-                @ chmod($folder, 0755);
1245
-            } catch (EE_Error $e) {
1246
-                EE_Error::add_error(
1247
-                    sprintf(
1248
-                        __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1249
-                        $folder,
1250
-                        '<br />' . $e->getMessage()
1251
-                    ),
1252
-                    __FILE__, __FUNCTION__, __LINE__
1253
-                );
1254
-                //indicate we'll need to fix this later
1255
-                update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1256
-                return false;
1257
-            }
1258
-        }
1259
-        //just add the .htaccess file to the logs directory to begin with. Even if logging
1260
-        //is disabled, there might be activation errors recorded in there
1261
-        EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1262
-        //remember EE's folders are all good
1263
-        delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1264
-        return true;
1265
-    }
1266
-
1267
-    /**
1268
-     * Whether the upload directories need to be fixed or not.
1269
-     * If EE is installed but filesystem access isn't initially available,
1270
-     * we need to get the user's filesystem credentials and THEN create them,
1271
-     * so there might be period of time when EE is installed but its
1272
-     * upload directories aren't available. This indicates such a state
1273
-     *
1274
-     * @return boolean
1275
-     */
1276
-    public static function upload_directories_incomplete()
1277
-    {
1278
-        return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1279
-    }
1280
-
1281
-
1282
-    /**
1283
-     * generate_default_message_templates
1284
-     *
1285
-     * @static
1286
-     * @throws EE_Error
1287
-     * @return bool     true means new templates were created.
1288
-     *                  false means no templates were created.
1289
-     *                  This is NOT an error flag. To check for errors you will want
1290
-     *                  to use either EE_Error or a try catch for an EE_Error exception.
1291
-     */
1292
-    public static function generate_default_message_templates()
1293
-    {
1294
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1295
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1296
-        /*
1216
+			$wpdb->query($SQL);
1217
+
1218
+		}
1219
+
1220
+	}
1221
+
1222
+
1223
+	/**
1224
+	 * create_upload_directories
1225
+	 * Creates folders in the uploads directory to facilitate addons and templates
1226
+	 *
1227
+	 * @access public
1228
+	 * @static
1229
+	 * @return boolean success of verifying upload directories exist
1230
+	 */
1231
+	public static function create_upload_directories()
1232
+	{
1233
+		// Create the required folders
1234
+		$folders = array(
1235
+			EVENT_ESPRESSO_TEMPLATE_DIR,
1236
+			EVENT_ESPRESSO_GATEWAY_DIR,
1237
+			EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1238
+			EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1239
+			EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1240
+		);
1241
+		foreach ($folders as $folder) {
1242
+			try {
1243
+				EEH_File::ensure_folder_exists_and_is_writable($folder);
1244
+				@ chmod($folder, 0755);
1245
+			} catch (EE_Error $e) {
1246
+				EE_Error::add_error(
1247
+					sprintf(
1248
+						__('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1249
+						$folder,
1250
+						'<br />' . $e->getMessage()
1251
+					),
1252
+					__FILE__, __FUNCTION__, __LINE__
1253
+				);
1254
+				//indicate we'll need to fix this later
1255
+				update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1256
+				return false;
1257
+			}
1258
+		}
1259
+		//just add the .htaccess file to the logs directory to begin with. Even if logging
1260
+		//is disabled, there might be activation errors recorded in there
1261
+		EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1262
+		//remember EE's folders are all good
1263
+		delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1264
+		return true;
1265
+	}
1266
+
1267
+	/**
1268
+	 * Whether the upload directories need to be fixed or not.
1269
+	 * If EE is installed but filesystem access isn't initially available,
1270
+	 * we need to get the user's filesystem credentials and THEN create them,
1271
+	 * so there might be period of time when EE is installed but its
1272
+	 * upload directories aren't available. This indicates such a state
1273
+	 *
1274
+	 * @return boolean
1275
+	 */
1276
+	public static function upload_directories_incomplete()
1277
+	{
1278
+		return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1279
+	}
1280
+
1281
+
1282
+	/**
1283
+	 * generate_default_message_templates
1284
+	 *
1285
+	 * @static
1286
+	 * @throws EE_Error
1287
+	 * @return bool     true means new templates were created.
1288
+	 *                  false means no templates were created.
1289
+	 *                  This is NOT an error flag. To check for errors you will want
1290
+	 *                  to use either EE_Error or a try catch for an EE_Error exception.
1291
+	 */
1292
+	public static function generate_default_message_templates()
1293
+	{
1294
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1295
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1296
+		/*
1297 1297
          * This first method is taking care of ensuring any default messengers
1298 1298
          * that should be made active and have templates generated are done.
1299 1299
          */
1300
-        $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1301
-            $message_resource_manager
1302
-        );
1303
-        /**
1304
-         * This method is verifying there are no NEW default message types
1305
-         * for ACTIVE messengers that need activated (and corresponding templates setup).
1306
-         */
1307
-        $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1308
-            $message_resource_manager
1309
-        );
1310
-        //after all is done, let's persist these changes to the db.
1311
-        $message_resource_manager->update_has_activated_messengers_option();
1312
-        $message_resource_manager->update_active_messengers_option();
1313
-        // will return true if either of these are true.  Otherwise will return false.
1314
-        return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1315
-    }
1316
-
1317
-
1318
-
1319
-    /**
1320
-     * @param \EE_Message_Resource_Manager $message_resource_manager
1321
-     * @return array|bool
1322
-     * @throws \EE_Error
1323
-     */
1324
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1325
-        EE_Message_Resource_Manager $message_resource_manager
1326
-    ) {
1327
-        /** @type EE_messenger[] $active_messengers */
1328
-        $active_messengers = $message_resource_manager->active_messengers();
1329
-        $installed_message_types = $message_resource_manager->installed_message_types();
1330
-        $templates_created = false;
1331
-        foreach ($active_messengers as $active_messenger) {
1332
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1333
-            $default_message_type_names_to_activate = array();
1334
-            // looping through each default message type reported by the messenger
1335
-            // and setup the actual message types to activate.
1336
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1337
-                // if already active or has already been activated before we skip
1338
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1339
-                // we also skip if the message type is not installed.
1340
-                if (
1341
-                    $message_resource_manager->has_message_type_been_activated_for_messenger(
1342
-                        $default_message_type_name_for_messenger,
1343
-                        $active_messenger->name
1344
-                    )
1345
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1346
-                        $active_messenger->name,
1347
-                        $default_message_type_name_for_messenger
1348
-                    )
1349
-                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1350
-                ) {
1351
-                    continue;
1352
-                }
1353
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1354
-            }
1355
-            //let's activate!
1356
-            $message_resource_manager->ensure_message_types_are_active(
1357
-                $default_message_type_names_to_activate,
1358
-                $active_messenger->name,
1359
-                false
1360
-            );
1361
-            //activate the templates for these message types
1362
-            if ( ! empty($default_message_type_names_to_activate)) {
1363
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1364
-                    $active_messenger->name,
1365
-                    $default_message_type_names_for_messenger,
1366
-                    '',
1367
-                    true
1368
-                );
1369
-            }
1370
-        }
1371
-        return $templates_created;
1372
-    }
1373
-
1374
-
1375
-
1376
-    /**
1377
-     * This will activate and generate default messengers and default message types for those messengers.
1378
-     *
1379
-     * @param EE_message_Resource_Manager $message_resource_manager
1380
-     * @return array|bool  True means there were default messengers and message type templates generated.
1381
-     *                     False means that there were no templates generated
1382
-     *                     (which could simply mean there are no default message types for a messenger).
1383
-     * @throws EE_Error
1384
-     */
1385
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1386
-        EE_Message_Resource_Manager $message_resource_manager
1387
-    ) {
1388
-        /** @type EE_messenger[] $messengers_to_generate */
1389
-        $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1390
-        $installed_message_types = $message_resource_manager->installed_message_types();
1391
-        $templates_generated = false;
1392
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1393
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1394
-            //verify the default message types match an installed message type.
1395
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1396
-                if (
1397
-                    ! isset($installed_message_types[$name])
1398
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger(
1399
-                        $name,
1400
-                        $messenger_to_generate->name
1401
-                    )
1402
-                ) {
1403
-                    unset($default_message_type_names_for_messenger[$key]);
1404
-                }
1405
-            }
1406
-            // in previous iterations, the active_messengers option in the db
1407
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1408
-            // This comment is left here just in case we discover that we _do_ need to update before
1409
-            // passing off to create templates (after the refactor is done).
1410
-            // @todo remove this comment when determined not necessary.
1411
-            $message_resource_manager->activate_messenger(
1412
-                $messenger_to_generate->name,
1413
-                $default_message_type_names_for_messenger,
1414
-                false
1415
-            );
1416
-            //create any templates needing created (or will reactivate templates already generated as necessary).
1417
-            if ( ! empty($default_message_type_names_for_messenger)) {
1418
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1419
-                    $messenger_to_generate->name,
1420
-                    $default_message_type_names_for_messenger,
1421
-                    '',
1422
-                    true
1423
-                );
1424
-            }
1425
-        }
1426
-        return $templates_generated;
1427
-    }
1428
-
1429
-
1430
-    /**
1431
-     * This returns the default messengers to generate templates for on activation of EE.
1432
-     * It considers:
1433
-     * - whether a messenger is already active in the db.
1434
-     * - whether a messenger has been made active at any time in the past.
1435
-     *
1436
-     * @static
1437
-     * @param  EE_Message_Resource_Manager $message_resource_manager
1438
-     * @return EE_messenger[]
1439
-     */
1440
-    protected static function _get_default_messengers_to_generate_on_activation(
1441
-        EE_Message_Resource_Manager $message_resource_manager
1442
-    ) {
1443
-        $active_messengers    = $message_resource_manager->active_messengers();
1444
-        $installed_messengers = $message_resource_manager->installed_messengers();
1445
-        $has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1446
-
1447
-        $messengers_to_generate = array();
1448
-        foreach ($installed_messengers as $installed_messenger) {
1449
-            //if installed messenger is a messenger that should be activated on install
1450
-            //and is not already active
1451
-            //and has never been activated
1452
-            if (
1453
-                ! $installed_messenger->activate_on_install
1454
-                || isset($active_messengers[$installed_messenger->name])
1455
-                || isset($has_activated[$installed_messenger->name])
1456
-            ) {
1457
-                continue;
1458
-            }
1459
-            $messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1460
-        }
1461
-        return $messengers_to_generate;
1462
-    }
1463
-
1464
-
1465
-    /**
1466
-     * This simply validates active message types to ensure they actually match installed
1467
-     * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1468
-     * rows are set inactive.
1469
-     * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1470
-     * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1471
-     * are still handled in here.
1472
-     *
1473
-     * @since 4.3.1
1474
-     * @return void
1475
-     */
1476
-    public static function validate_messages_system()
1477
-    {
1478
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1479
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1480
-        $message_resource_manager->validate_active_message_types_are_installed();
1481
-        do_action('AHEE__EEH_Activation__validate_messages_system');
1482
-    }
1483
-
1484
-
1485
-    /**
1486
-     * create_no_ticket_prices_array
1487
-     *
1488
-     * @access public
1489
-     * @static
1490
-     * @return void
1491
-     */
1492
-    public static function create_no_ticket_prices_array()
1493
-    {
1494
-        // this creates an array for tracking events that have no active ticket prices created
1495
-        // this allows us to warn admins of the situation so that it can be corrected
1496
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1497
-        if (! $espresso_no_ticket_prices) {
1498
-            add_option('ee_no_ticket_prices', array(), '', false);
1499
-        }
1500
-    }
1501
-
1502
-
1503
-    /**
1504
-     * plugin_deactivation
1505
-     *
1506
-     * @access public
1507
-     * @static
1508
-     * @return void
1509
-     */
1510
-    public static function plugin_deactivation()
1511
-    {
1512
-    }
1513
-
1514
-
1515
-    /**
1516
-     * Finds all our EE4 custom post types, and deletes them and their associated data
1517
-     * (like post meta or term relations)
1518
-     *
1519
-     * @global wpdb $wpdb
1520
-     * @throws \EE_Error
1521
-     */
1522
-    public static function delete_all_espresso_cpt_data()
1523
-    {
1524
-        global $wpdb;
1525
-        //get all the CPT post_types
1526
-        $ee_post_types = array();
1527
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1528
-            if (method_exists($model_name, 'instance')) {
1529
-                $model_obj = call_user_func(array($model_name, 'instance'));
1530
-                if ($model_obj instanceof EEM_CPT_Base) {
1531
-                    $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1532
-                }
1533
-            }
1534
-        }
1535
-        //get all our CPTs
1536
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1537
-        $cpt_ids = $wpdb->get_col($query);
1538
-        //delete each post meta and term relations too
1539
-        foreach ($cpt_ids as $post_id) {
1540
-            wp_delete_post($post_id, true);
1541
-        }
1542
-    }
1543
-
1544
-    /**
1545
-     * Deletes all EE custom tables
1546
-     *
1547
-     * @return array
1548
-     */
1549
-    public static function drop_espresso_tables()
1550
-    {
1551
-        $tables = array();
1552
-        // load registry
1553
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1554
-            if (method_exists($model_name, 'instance')) {
1555
-                $model_obj = call_user_func(array($model_name, 'instance'));
1556
-                if ($model_obj instanceof EEM_Base) {
1557
-                    foreach ($model_obj->get_tables() as $table) {
1558
-                        if (strpos($table->get_table_name(), 'esp_')
1559
-                            &&
1560
-                            (
1561
-                                is_main_site()//main site? nuke them all
1562
-                                || ! $table->is_global()//not main site,but not global either. nuke it
1563
-                            )
1564
-                        ) {
1565
-                            $tables[] = $table->get_table_name();
1566
-                        }
1567
-                    }
1568
-                }
1569
-            }
1570
-        }
1571
-
1572
-        //there are some tables whose models were removed.
1573
-        //they should be removed when removing all EE core's data
1574
-        $tables_without_models = array(
1575
-            'esp_promotion',
1576
-            'esp_promotion_applied',
1577
-            'esp_promotion_object',
1578
-            'esp_promotion_rule',
1579
-            'esp_rule',
1580
-        );
1581
-        foreach ($tables_without_models as $table) {
1582
-            $tables[] = $table;
1583
-        }
1584
-        return \EEH_Activation::getTableManager()->dropTables($tables);
1585
-    }
1586
-
1587
-
1588
-
1589
-    /**
1590
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1591
-     * each table name provided has a wpdb prefix attached, and that it exists.
1592
-     * Returns the list actually deleted
1593
-     *
1594
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1595
-     * @global WPDB $wpdb
1596
-     * @param array $table_names
1597
-     * @return array of table names which we deleted
1598
-     */
1599
-    public static function drop_tables($table_names)
1600
-    {
1601
-        return \EEH_Activation::getTableManager()->dropTables($table_names);
1602
-    }
1603
-
1604
-
1605
-
1606
-    /**
1607
-     * plugin_uninstall
1608
-     *
1609
-     * @access public
1610
-     * @static
1611
-     * @param bool $remove_all
1612
-     * @return void
1613
-     */
1614
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1615
-    {
1616
-        global $wpdb;
1617
-        self::drop_espresso_tables();
1618
-        $wp_options_to_delete = array(
1619
-            'ee_no_ticket_prices'                => true,
1620
-            'ee_active_messengers'               => true,
1621
-            'ee_has_activated_messenger'         => true,
1622
-            'ee_flush_rewrite_rules'             => true,
1623
-            'ee_config'                          => false,
1624
-            'ee_data_migration_current_db_state' => true,
1625
-            'ee_data_migration_mapping_'         => false,
1626
-            'ee_data_migration_script_'          => false,
1627
-            'ee_data_migrations'                 => true,
1628
-            'ee_dms_map'                         => false,
1629
-            'ee_notices'                         => true,
1630
-            'lang_file_check_'                   => false,
1631
-            'ee_maintenance_mode'                => true,
1632
-            'ee_ueip_optin'                      => true,
1633
-            'ee_ueip_has_notified'               => true,
1634
-            'ee_plugin_activation_errors'        => true,
1635
-            'ee_id_mapping_from'                 => false,
1636
-            'espresso_persistent_admin_notices'  => true,
1637
-            'ee_encryption_key'                  => true,
1638
-            'pue_force_upgrade_'                 => false,
1639
-            'pue_json_error_'                    => false,
1640
-            'pue_install_key_'                   => false,
1641
-            'pue_verification_error_'            => false,
1642
-            'pu_dismissed_upgrade_'              => false,
1643
-            'external_updates-'                  => false,
1644
-            'ee_extra_data'                      => true,
1645
-            'ee_ssn_'                            => false,
1646
-            'ee_rss_'                            => false,
1647
-            'ee_rte_n_tx_'                       => false,
1648
-            'ee_pers_admin_notices'              => true,
1649
-            'ee_job_parameters_'                 => false,
1650
-            'ee_upload_directories_incomplete'   => true,
1651
-            'ee_verified_db_collations'          => true,
1652
-        );
1653
-        if (is_main_site()) {
1654
-            $wp_options_to_delete['ee_network_config'] = true;
1655
-        }
1656
-        $undeleted_options = array();
1657
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1658
-            if ($no_wildcard) {
1659
-                if ( ! delete_option($option_name)) {
1660
-                    $undeleted_options[] = $option_name;
1661
-                }
1662
-            } else {
1663
-                $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1664
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1665
-                    if ( ! delete_option($option_name_from_wildcard)) {
1666
-                        $undeleted_options[] = $option_name_from_wildcard;
1667
-                    }
1668
-                }
1669
-            }
1670
-        }
1671
-        //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1672
-        remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1673
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1674
-            $db_update_sans_ee4 = array();
1675
-            foreach ($espresso_db_update as $version => $times_activated) {
1676
-                if ((string)$version[0] === '3') {//if its NON EE4
1677
-                    $db_update_sans_ee4[$version] = $times_activated;
1678
-                }
1679
-            }
1680
-            update_option('espresso_db_update', $db_update_sans_ee4);
1681
-        }
1682
-        $errors = '';
1683
-        if ( ! empty($undeleted_options)) {
1684
-            $errors .= sprintf(
1685
-                __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1686
-                '<br/>',
1687
-                implode(',<br/>', $undeleted_options)
1688
-            );
1689
-        }
1690
-        if ( ! empty($errors)) {
1691
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1692
-        }
1693
-    }
1694
-
1695
-    /**
1696
-     * Gets the mysql error code from the last used query by wpdb
1697
-     *
1698
-     * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1699
-     */
1700
-    public static function last_wpdb_error_code()
1701
-    {
1702
-        global $wpdb;
1703
-        if ($wpdb->use_mysqli) {
1704
-            return mysqli_errno($wpdb->dbh);
1705
-        } else {
1706
-            return mysql_errno($wpdb->dbh);
1707
-        }
1708
-    }
1709
-
1710
-    /**
1711
-     * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1712
-     *
1713
-     * @global wpdb  $wpdb
1714
-     * @deprecated instead use TableAnalysis::tableExists()
1715
-     * @param string $table_name with or without $wpdb->prefix
1716
-     * @return boolean
1717
-     */
1718
-    public static function table_exists($table_name)
1719
-    {
1720
-        return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1721
-    }
1722
-
1723
-    /**
1724
-     * Resets the cache on EEH_Activation
1725
-     */
1726
-    public static function reset()
1727
-    {
1728
-        self::$_default_creator_id                             = null;
1729
-        self::$_initialized_db_content_already_in_this_request = false;
1730
-    }
1300
+		$new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1301
+			$message_resource_manager
1302
+		);
1303
+		/**
1304
+		 * This method is verifying there are no NEW default message types
1305
+		 * for ACTIVE messengers that need activated (and corresponding templates setup).
1306
+		 */
1307
+		$new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1308
+			$message_resource_manager
1309
+		);
1310
+		//after all is done, let's persist these changes to the db.
1311
+		$message_resource_manager->update_has_activated_messengers_option();
1312
+		$message_resource_manager->update_active_messengers_option();
1313
+		// will return true if either of these are true.  Otherwise will return false.
1314
+		return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1315
+	}
1316
+
1317
+
1318
+
1319
+	/**
1320
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
1321
+	 * @return array|bool
1322
+	 * @throws \EE_Error
1323
+	 */
1324
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1325
+		EE_Message_Resource_Manager $message_resource_manager
1326
+	) {
1327
+		/** @type EE_messenger[] $active_messengers */
1328
+		$active_messengers = $message_resource_manager->active_messengers();
1329
+		$installed_message_types = $message_resource_manager->installed_message_types();
1330
+		$templates_created = false;
1331
+		foreach ($active_messengers as $active_messenger) {
1332
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1333
+			$default_message_type_names_to_activate = array();
1334
+			// looping through each default message type reported by the messenger
1335
+			// and setup the actual message types to activate.
1336
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1337
+				// if already active or has already been activated before we skip
1338
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1339
+				// we also skip if the message type is not installed.
1340
+				if (
1341
+					$message_resource_manager->has_message_type_been_activated_for_messenger(
1342
+						$default_message_type_name_for_messenger,
1343
+						$active_messenger->name
1344
+					)
1345
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1346
+						$active_messenger->name,
1347
+						$default_message_type_name_for_messenger
1348
+					)
1349
+					|| ! isset($installed_message_types[$default_message_type_name_for_messenger])
1350
+				) {
1351
+					continue;
1352
+				}
1353
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1354
+			}
1355
+			//let's activate!
1356
+			$message_resource_manager->ensure_message_types_are_active(
1357
+				$default_message_type_names_to_activate,
1358
+				$active_messenger->name,
1359
+				false
1360
+			);
1361
+			//activate the templates for these message types
1362
+			if ( ! empty($default_message_type_names_to_activate)) {
1363
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1364
+					$active_messenger->name,
1365
+					$default_message_type_names_for_messenger,
1366
+					'',
1367
+					true
1368
+				);
1369
+			}
1370
+		}
1371
+		return $templates_created;
1372
+	}
1373
+
1374
+
1375
+
1376
+	/**
1377
+	 * This will activate and generate default messengers and default message types for those messengers.
1378
+	 *
1379
+	 * @param EE_message_Resource_Manager $message_resource_manager
1380
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1381
+	 *                     False means that there were no templates generated
1382
+	 *                     (which could simply mean there are no default message types for a messenger).
1383
+	 * @throws EE_Error
1384
+	 */
1385
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1386
+		EE_Message_Resource_Manager $message_resource_manager
1387
+	) {
1388
+		/** @type EE_messenger[] $messengers_to_generate */
1389
+		$messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1390
+		$installed_message_types = $message_resource_manager->installed_message_types();
1391
+		$templates_generated = false;
1392
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1393
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1394
+			//verify the default message types match an installed message type.
1395
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1396
+				if (
1397
+					! isset($installed_message_types[$name])
1398
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger(
1399
+						$name,
1400
+						$messenger_to_generate->name
1401
+					)
1402
+				) {
1403
+					unset($default_message_type_names_for_messenger[$key]);
1404
+				}
1405
+			}
1406
+			// in previous iterations, the active_messengers option in the db
1407
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1408
+			// This comment is left here just in case we discover that we _do_ need to update before
1409
+			// passing off to create templates (after the refactor is done).
1410
+			// @todo remove this comment when determined not necessary.
1411
+			$message_resource_manager->activate_messenger(
1412
+				$messenger_to_generate->name,
1413
+				$default_message_type_names_for_messenger,
1414
+				false
1415
+			);
1416
+			//create any templates needing created (or will reactivate templates already generated as necessary).
1417
+			if ( ! empty($default_message_type_names_for_messenger)) {
1418
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1419
+					$messenger_to_generate->name,
1420
+					$default_message_type_names_for_messenger,
1421
+					'',
1422
+					true
1423
+				);
1424
+			}
1425
+		}
1426
+		return $templates_generated;
1427
+	}
1428
+
1429
+
1430
+	/**
1431
+	 * This returns the default messengers to generate templates for on activation of EE.
1432
+	 * It considers:
1433
+	 * - whether a messenger is already active in the db.
1434
+	 * - whether a messenger has been made active at any time in the past.
1435
+	 *
1436
+	 * @static
1437
+	 * @param  EE_Message_Resource_Manager $message_resource_manager
1438
+	 * @return EE_messenger[]
1439
+	 */
1440
+	protected static function _get_default_messengers_to_generate_on_activation(
1441
+		EE_Message_Resource_Manager $message_resource_manager
1442
+	) {
1443
+		$active_messengers    = $message_resource_manager->active_messengers();
1444
+		$installed_messengers = $message_resource_manager->installed_messengers();
1445
+		$has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1446
+
1447
+		$messengers_to_generate = array();
1448
+		foreach ($installed_messengers as $installed_messenger) {
1449
+			//if installed messenger is a messenger that should be activated on install
1450
+			//and is not already active
1451
+			//and has never been activated
1452
+			if (
1453
+				! $installed_messenger->activate_on_install
1454
+				|| isset($active_messengers[$installed_messenger->name])
1455
+				|| isset($has_activated[$installed_messenger->name])
1456
+			) {
1457
+				continue;
1458
+			}
1459
+			$messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1460
+		}
1461
+		return $messengers_to_generate;
1462
+	}
1463
+
1464
+
1465
+	/**
1466
+	 * This simply validates active message types to ensure they actually match installed
1467
+	 * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1468
+	 * rows are set inactive.
1469
+	 * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1470
+	 * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1471
+	 * are still handled in here.
1472
+	 *
1473
+	 * @since 4.3.1
1474
+	 * @return void
1475
+	 */
1476
+	public static function validate_messages_system()
1477
+	{
1478
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1479
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1480
+		$message_resource_manager->validate_active_message_types_are_installed();
1481
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1482
+	}
1483
+
1484
+
1485
+	/**
1486
+	 * create_no_ticket_prices_array
1487
+	 *
1488
+	 * @access public
1489
+	 * @static
1490
+	 * @return void
1491
+	 */
1492
+	public static function create_no_ticket_prices_array()
1493
+	{
1494
+		// this creates an array for tracking events that have no active ticket prices created
1495
+		// this allows us to warn admins of the situation so that it can be corrected
1496
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1497
+		if (! $espresso_no_ticket_prices) {
1498
+			add_option('ee_no_ticket_prices', array(), '', false);
1499
+		}
1500
+	}
1501
+
1502
+
1503
+	/**
1504
+	 * plugin_deactivation
1505
+	 *
1506
+	 * @access public
1507
+	 * @static
1508
+	 * @return void
1509
+	 */
1510
+	public static function plugin_deactivation()
1511
+	{
1512
+	}
1513
+
1514
+
1515
+	/**
1516
+	 * Finds all our EE4 custom post types, and deletes them and their associated data
1517
+	 * (like post meta or term relations)
1518
+	 *
1519
+	 * @global wpdb $wpdb
1520
+	 * @throws \EE_Error
1521
+	 */
1522
+	public static function delete_all_espresso_cpt_data()
1523
+	{
1524
+		global $wpdb;
1525
+		//get all the CPT post_types
1526
+		$ee_post_types = array();
1527
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1528
+			if (method_exists($model_name, 'instance')) {
1529
+				$model_obj = call_user_func(array($model_name, 'instance'));
1530
+				if ($model_obj instanceof EEM_CPT_Base) {
1531
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1532
+				}
1533
+			}
1534
+		}
1535
+		//get all our CPTs
1536
+		$query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1537
+		$cpt_ids = $wpdb->get_col($query);
1538
+		//delete each post meta and term relations too
1539
+		foreach ($cpt_ids as $post_id) {
1540
+			wp_delete_post($post_id, true);
1541
+		}
1542
+	}
1543
+
1544
+	/**
1545
+	 * Deletes all EE custom tables
1546
+	 *
1547
+	 * @return array
1548
+	 */
1549
+	public static function drop_espresso_tables()
1550
+	{
1551
+		$tables = array();
1552
+		// load registry
1553
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1554
+			if (method_exists($model_name, 'instance')) {
1555
+				$model_obj = call_user_func(array($model_name, 'instance'));
1556
+				if ($model_obj instanceof EEM_Base) {
1557
+					foreach ($model_obj->get_tables() as $table) {
1558
+						if (strpos($table->get_table_name(), 'esp_')
1559
+							&&
1560
+							(
1561
+								is_main_site()//main site? nuke them all
1562
+								|| ! $table->is_global()//not main site,but not global either. nuke it
1563
+							)
1564
+						) {
1565
+							$tables[] = $table->get_table_name();
1566
+						}
1567
+					}
1568
+				}
1569
+			}
1570
+		}
1571
+
1572
+		//there are some tables whose models were removed.
1573
+		//they should be removed when removing all EE core's data
1574
+		$tables_without_models = array(
1575
+			'esp_promotion',
1576
+			'esp_promotion_applied',
1577
+			'esp_promotion_object',
1578
+			'esp_promotion_rule',
1579
+			'esp_rule',
1580
+		);
1581
+		foreach ($tables_without_models as $table) {
1582
+			$tables[] = $table;
1583
+		}
1584
+		return \EEH_Activation::getTableManager()->dropTables($tables);
1585
+	}
1586
+
1587
+
1588
+
1589
+	/**
1590
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1591
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1592
+	 * Returns the list actually deleted
1593
+	 *
1594
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1595
+	 * @global WPDB $wpdb
1596
+	 * @param array $table_names
1597
+	 * @return array of table names which we deleted
1598
+	 */
1599
+	public static function drop_tables($table_names)
1600
+	{
1601
+		return \EEH_Activation::getTableManager()->dropTables($table_names);
1602
+	}
1603
+
1604
+
1605
+
1606
+	/**
1607
+	 * plugin_uninstall
1608
+	 *
1609
+	 * @access public
1610
+	 * @static
1611
+	 * @param bool $remove_all
1612
+	 * @return void
1613
+	 */
1614
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1615
+	{
1616
+		global $wpdb;
1617
+		self::drop_espresso_tables();
1618
+		$wp_options_to_delete = array(
1619
+			'ee_no_ticket_prices'                => true,
1620
+			'ee_active_messengers'               => true,
1621
+			'ee_has_activated_messenger'         => true,
1622
+			'ee_flush_rewrite_rules'             => true,
1623
+			'ee_config'                          => false,
1624
+			'ee_data_migration_current_db_state' => true,
1625
+			'ee_data_migration_mapping_'         => false,
1626
+			'ee_data_migration_script_'          => false,
1627
+			'ee_data_migrations'                 => true,
1628
+			'ee_dms_map'                         => false,
1629
+			'ee_notices'                         => true,
1630
+			'lang_file_check_'                   => false,
1631
+			'ee_maintenance_mode'                => true,
1632
+			'ee_ueip_optin'                      => true,
1633
+			'ee_ueip_has_notified'               => true,
1634
+			'ee_plugin_activation_errors'        => true,
1635
+			'ee_id_mapping_from'                 => false,
1636
+			'espresso_persistent_admin_notices'  => true,
1637
+			'ee_encryption_key'                  => true,
1638
+			'pue_force_upgrade_'                 => false,
1639
+			'pue_json_error_'                    => false,
1640
+			'pue_install_key_'                   => false,
1641
+			'pue_verification_error_'            => false,
1642
+			'pu_dismissed_upgrade_'              => false,
1643
+			'external_updates-'                  => false,
1644
+			'ee_extra_data'                      => true,
1645
+			'ee_ssn_'                            => false,
1646
+			'ee_rss_'                            => false,
1647
+			'ee_rte_n_tx_'                       => false,
1648
+			'ee_pers_admin_notices'              => true,
1649
+			'ee_job_parameters_'                 => false,
1650
+			'ee_upload_directories_incomplete'   => true,
1651
+			'ee_verified_db_collations'          => true,
1652
+		);
1653
+		if (is_main_site()) {
1654
+			$wp_options_to_delete['ee_network_config'] = true;
1655
+		}
1656
+		$undeleted_options = array();
1657
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1658
+			if ($no_wildcard) {
1659
+				if ( ! delete_option($option_name)) {
1660
+					$undeleted_options[] = $option_name;
1661
+				}
1662
+			} else {
1663
+				$option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1664
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1665
+					if ( ! delete_option($option_name_from_wildcard)) {
1666
+						$undeleted_options[] = $option_name_from_wildcard;
1667
+					}
1668
+				}
1669
+			}
1670
+		}
1671
+		//also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1672
+		remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1673
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1674
+			$db_update_sans_ee4 = array();
1675
+			foreach ($espresso_db_update as $version => $times_activated) {
1676
+				if ((string)$version[0] === '3') {//if its NON EE4
1677
+					$db_update_sans_ee4[$version] = $times_activated;
1678
+				}
1679
+			}
1680
+			update_option('espresso_db_update', $db_update_sans_ee4);
1681
+		}
1682
+		$errors = '';
1683
+		if ( ! empty($undeleted_options)) {
1684
+			$errors .= sprintf(
1685
+				__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1686
+				'<br/>',
1687
+				implode(',<br/>', $undeleted_options)
1688
+			);
1689
+		}
1690
+		if ( ! empty($errors)) {
1691
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1692
+		}
1693
+	}
1694
+
1695
+	/**
1696
+	 * Gets the mysql error code from the last used query by wpdb
1697
+	 *
1698
+	 * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1699
+	 */
1700
+	public static function last_wpdb_error_code()
1701
+	{
1702
+		global $wpdb;
1703
+		if ($wpdb->use_mysqli) {
1704
+			return mysqli_errno($wpdb->dbh);
1705
+		} else {
1706
+			return mysql_errno($wpdb->dbh);
1707
+		}
1708
+	}
1709
+
1710
+	/**
1711
+	 * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1712
+	 *
1713
+	 * @global wpdb  $wpdb
1714
+	 * @deprecated instead use TableAnalysis::tableExists()
1715
+	 * @param string $table_name with or without $wpdb->prefix
1716
+	 * @return boolean
1717
+	 */
1718
+	public static function table_exists($table_name)
1719
+	{
1720
+		return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1721
+	}
1722
+
1723
+	/**
1724
+	 * Resets the cache on EEH_Activation
1725
+	 */
1726
+	public static function reset()
1727
+	{
1728
+		self::$_default_creator_id                             = null;
1729
+		self::$_initialized_db_content_already_in_this_request = false;
1730
+	}
1731 1731
 }
1732 1732
 // End of file EEH_Activation.helper.php
1733 1733
 // Location: /helpers/EEH_Activation.core.php
Please login to merge, or discard this patch.
core/EE_Error.core.php 1 patch
Spacing   +247 added lines, -247 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2 2
 // if you're a dev and want to receive all errors via email add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
3
-if ( defined( 'WP_DEBUG' ) && WP_DEBUG === TRUE && defined( 'EE_ERROR_EMAILS' ) && EE_ERROR_EMAILS === TRUE ) {
4
-	set_error_handler( array( 'EE_Error', 'error_handler' ));
5
-	register_shutdown_function( array( 'EE_Error', 'fatal_error_handler' ));
3
+if (defined('WP_DEBUG') && WP_DEBUG === TRUE && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === TRUE) {
4
+	set_error_handler(array('EE_Error', 'error_handler'));
5
+	register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
6 6
 }
7 7
 /**
8 8
  *
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	* 	@access	private
65 65
     *	@var boolean
66 66
 	*/
67
-	private static $_espresso_notices = array( 'success' => FALSE, 'errors' => FALSE, 'attention' => FALSE );
67
+	private static $_espresso_notices = array('success' => FALSE, 'errors' => FALSE, 'attention' => FALSE);
68 68
 
69 69
 
70 70
 
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
 	*	@access public
76 76
 	*	@echo string
77 77
 	*/
78
-	function __construct( $message, $code = 0, Exception $previous = NULL ) {
79
-		if ( version_compare( phpversion(), '5.3.0', '<' )) {
80
-			parent::__construct( $message, $code );
78
+	function __construct($message, $code = 0, Exception $previous = NULL) {
79
+		if (version_compare(phpversion(), '5.3.0', '<')) {
80
+			parent::__construct($message, $code);
81 81
 		} else {
82
-			parent::__construct( $message, $code, $previous );
82
+			parent::__construct($message, $code, $previous);
83 83
 		}
84 84
 	}
85 85
 
@@ -94,10 +94,10 @@  discard block
 block discarded – undo
94 94
 	 * @param $line
95 95
 	 * @return void
96 96
 	 */
97
-	public static function error_handler( $code, $message, $file, $line ) {
98
-		$type = EE_Error::error_type( $code );
97
+	public static function error_handler($code, $message, $file, $line) {
98
+		$type = EE_Error::error_type($code);
99 99
 		$site = site_url();
100
-		switch ( $site ) {
100
+		switch ($site) {
101 101
 			case 'http://ee4.eventespresso.com/' :
102 102
 			case 'http://ee4decaf.eventespresso.com/' :
103 103
 			case 'http://ee4hf.eventespresso.com/' :
@@ -110,16 +110,16 @@  discard block
 block discarded – undo
110 110
 				$to = '[email protected]';
111 111
 				break;
112 112
 			default :
113
-				$to = get_option( 'admin_email' );
113
+				$to = get_option('admin_email');
114 114
 		}
115
-		$subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
116
-		$msg = EE_Error::_format_error( $type, $message, $file, $line );
117
-		if ( function_exists( 'wp_mail' )) {
118
-			add_filter( 'wp_mail_content_type', array( 'EE_Error', 'set_content_type' ));
119
-			wp_mail( $to, $subject, $msg );
115
+		$subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url();
116
+		$msg = EE_Error::_format_error($type, $message, $file, $line);
117
+		if (function_exists('wp_mail')) {
118
+			add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
119
+			wp_mail($to, $subject, $msg);
120 120
 		}
121 121
 		echo '<div id="message" class="espresso-notices error"><p>';
122
-		echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
122
+		echo $type.': '.$message.'<br />'.$file.' line '.$line;
123 123
 		echo '<br /></p></div>';
124 124
 	}
125 125
 
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
 	 * @param $code
133 133
 	 * @return string
134 134
 	 */
135
-	public static function error_type( $code ) {
136
-		switch( $code ) {
135
+	public static function error_type($code) {
136
+		switch ($code) {
137 137
 			case E_ERROR: // 1 //
138 138
 			return 'E_ERROR';
139 139
 			case E_WARNING: // 2 //
@@ -179,8 +179,8 @@  discard block
 block discarded – undo
179 179
 	*/
180 180
 	public static function fatal_error_handler() {
181 181
 		$last_error = error_get_last();
182
-		if ( $last_error['type'] === E_ERROR ) {
183
-			EE_Error::error_handler( E_ERROR, $last_error['message'], $last_error['file'], $last_error['line'] );
182
+		if ($last_error['type'] === E_ERROR) {
183
+			EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
184 184
 		}
185 185
 	}
186 186
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	 * @param $line
196 196
 	 * @return string
197 197
 	 */
198
-	private static function _format_error( $code, $message, $file, $line ) {
198
+	private static function _format_error($code, $message, $file, $line) {
199 199
 		$html  = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
200 200
 		$html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
201 201
 		$html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 	 * @param $content_type
214 214
 	 * @return string
215 215
 	 */
216
-	public static function set_content_type( $content_type ) {
216
+	public static function set_content_type($content_type) {
217 217
 		return 'text/html';
218 218
 	}
219 219
 
@@ -227,24 +227,24 @@  discard block
 block discarded – undo
227 227
 	*/
228 228
     public function get_error() {
229 229
 
230
-		if( apply_filters( 'FHEE__EE_Error__get_error__show_normal_exceptions', FALSE ) ){
230
+		if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', FALSE)) {
231 231
 			throw $this;
232 232
 		}
233 233
 		// get separate user and developer messages if they exist
234
-		$msg = explode( '||', $this->getMessage() );
234
+		$msg = explode('||', $this->getMessage());
235 235
 		$user_msg = $msg[0];
236
-		$dev_msg = isset( $msg[1] ) ? $msg[1] : $msg[0];
236
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
237 237
 		$msg = WP_DEBUG ? $dev_msg : $user_msg;
238 238
 
239 239
 		// add details to _all_exceptions array
240 240
 		$x_time = time();
241
-		self::$_all_exceptions[ $x_time ]['name'] 	= get_class( $this );
242
-		self::$_all_exceptions[ $x_time ]['file'] 		= $this->getFile();
243
-		self::$_all_exceptions[ $x_time ]['line'] 		= $this->getLine();
244
-		self::$_all_exceptions[ $x_time ]['msg'] 	= $msg;
245
-		self::$_all_exceptions[ $x_time ]['code'] 	= $this->getCode();
246
-		self::$_all_exceptions[ $x_time ]['trace'] 	= $this->getTrace();
247
-		self::$_all_exceptions[ $x_time ]['string'] 	= $this->getTraceAsString();
241
+		self::$_all_exceptions[$x_time]['name'] = get_class($this);
242
+		self::$_all_exceptions[$x_time]['file'] 		= $this->getFile();
243
+		self::$_all_exceptions[$x_time]['line'] 		= $this->getLine();
244
+		self::$_all_exceptions[$x_time]['msg'] = $msg;
245
+		self::$_all_exceptions[$x_time]['code'] = $this->getCode();
246
+		self::$_all_exceptions[$x_time]['trace'] 	= $this->getTrace();
247
+		self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
248 248
 		self::$_error_count++;
249 249
 
250 250
 		//add_action( 'shutdown', array( $this, 'display_errors' ));
@@ -262,14 +262,14 @@  discard block
 block discarded – undo
262 262
      * @param string $type_to_check
263 263
      * @return bool
264 264
      */
265
-    public static function has_error( $check_stored = false, $type_to_check = 'errors' ){
265
+    public static function has_error($check_stored = false, $type_to_check = 'errors') {
266 266
 	    $has_error = isset(self::$_espresso_notices[$type_to_check]) && ! empty(self::$_espresso_notices[$type_to_check])
267 267
             ? true
268 268
             : false;
269
-	    if ( $check_stored && ! $has_error ) {
270
-		    $notices = (array) get_option( 'ee_notices', array() );
271
-		    foreach ( $notices as $type => $notice ) {
272
-			    if ( $type === $type_to_check && $notice ) {
269
+	    if ($check_stored && ! $has_error) {
270
+		    $notices = (array) get_option('ee_notices', array());
271
+		    foreach ($notices as $type => $notice) {
272
+			    if ($type === $type_to_check && $notice) {
273 273
 				    return true;
274 274
 			    }
275 275
 		    }
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 	*	@access public
285 285
 	*	@echo string
286 286
 	*/
287
-    public function display_errors(){
287
+    public function display_errors() {
288 288
 
289 289
 		$trace_details = '';
290 290
 
@@ -345,18 +345,18 @@  discard block
 block discarded – undo
345 345
 </style>
346 346
 <div id="ee-error-message" class="error">';
347 347
 
348
-		if ( ! WP_DEBUG ) {
348
+		if ( ! WP_DEBUG) {
349 349
 			$output .= '
350 350
 	<p>';
351 351
 		}
352 352
 
353 353
 		// cycle thru errors
354
-		foreach ( self::$_all_exceptions as $time => $ex ) {
354
+		foreach (self::$_all_exceptions as $time => $ex) {
355 355
 
356 356
 			// process trace info
357
-			if ( empty( $ex['trace'] )) {
357
+			if (empty($ex['trace'])) {
358 358
 
359
-	            $trace_details .= __( 'Sorry, but no trace information was available for this exception.', 'event_espresso' );
359
+	            $trace_details .= __('Sorry, but no trace information was available for this exception.', 'event_espresso');
360 360
 
361 361
 			} else {
362 362
 
@@ -371,50 +371,50 @@  discard block
 block discarded – undo
371 371
 					<th scope="col" align="left">Method( arguments )</th>
372 372
 				</tr>';
373 373
 
374
-				$last_on_stack = count( $ex['trace'] ) - 1;
374
+				$last_on_stack = count($ex['trace']) - 1;
375 375
 				// reverse array so that stack is in proper chronological order
376
-				$sorted_trace = array_reverse( $ex['trace'] );
376
+				$sorted_trace = array_reverse($ex['trace']);
377 377
 
378
-				foreach ( $sorted_trace as $nmbr => $trace ) {
378
+				foreach ($sorted_trace as $nmbr => $trace) {
379 379
 
380
-					$file = isset( $trace['file'] ) ? $trace['file'] : '' ;
381
-					$class = isset( $trace['class'] ) ? $trace['class'] : '';
382
-					$type = isset( $trace['type'] ) ? $trace['type'] : '';
383
-					$function = isset( $trace['function'] ) ? $trace['function'] : '';
384
-					$args = isset( $trace['args'] ) ? $this->_convert_args_to_string( $trace['args'] ) : '';
385
-					$line = isset( $trace['line'] ) ? $trace['line'] : '';
380
+					$file = isset($trace['file']) ? $trace['file'] : '';
381
+					$class = isset($trace['class']) ? $trace['class'] : '';
382
+					$type = isset($trace['type']) ? $trace['type'] : '';
383
+					$function = isset($trace['function']) ? $trace['function'] : '';
384
+					$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
385
+					$line = isset($trace['line']) ? $trace['line'] : '';
386 386
 					$zebra = $nmbr % 2 ? ' odd' : '';
387 387
 
388
-					if ( empty( $file ) && ! empty( $class )) {
389
-						$a = new ReflectionClass( $class );
388
+					if (empty($file) && ! empty($class)) {
389
+						$a = new ReflectionClass($class);
390 390
 						$file = $a->getFileName();
391
-						if ( empty( $line ) && ! empty( $function )) {
392
-							$b = new ReflectionMethod( $class, $function );
391
+						if (empty($line) && ! empty($function)) {
392
+							$b = new ReflectionMethod($class, $function);
393 393
 							$line = $b->getStartLine();
394 394
 						}
395 395
 					}
396 396
 
397
-					if ( $nmbr == $last_on_stack ) {
397
+					if ($nmbr == $last_on_stack) {
398 398
 						$file = $ex['file'] != '' ? $ex['file'] : $file;
399 399
 						$line = $ex['line'] != '' ? $ex['line'] : $line;
400
-						$error_code = self::generate_error_code ( $file, $trace['function'], $line );
400
+						$error_code = self::generate_error_code($file, $trace['function'], $line);
401 401
 					}
402 402
 
403
-					$nmbr_dsply = ! empty( $nmbr ) ? $nmbr : '&nbsp;';
404
-					$line_dsply = ! empty( $line ) ? $line : '&nbsp;';
405
-					$file_dsply = ! empty( $file ) ? $file : '&nbsp;';
406
-					$class_dsply = ! empty( $class ) ? $class : '&nbsp;';
407
-					$type_dsply = ! empty( $type ) ? $type : '&nbsp;';
408
-					$function_dsply = ! empty( $function ) ? $function : '&nbsp;';
409
-					$args_dsply = ! empty( $args ) ? '( ' . $args . ' )' : '';
403
+					$nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
404
+					$line_dsply = ! empty($line) ? $line : '&nbsp;';
405
+					$file_dsply = ! empty($file) ? $file : '&nbsp;';
406
+					$class_dsply = ! empty($class) ? $class : '&nbsp;';
407
+					$type_dsply = ! empty($type) ? $type : '&nbsp;';
408
+					$function_dsply = ! empty($function) ? $function : '&nbsp;';
409
+					$args_dsply = ! empty($args) ? '( '.$args.' )' : '';
410 410
 
411 411
 		              $trace_details .= '
412 412
 					<tr>
413
-						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
414
-						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
415
-						<td align="left" class="' . $zebra . '">' . $file_dsply . '</td>
416
-						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
417
-						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
413
+						<td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td>
414
+						<td align="right" class="' . $zebra.'">'.$line_dsply.'</td>
415
+						<td align="left" class="' . $zebra.'">'.$file_dsply.'</td>
416
+						<td align="left" class="' . $zebra.'">'.$class_dsply.'</td>
417
+						<td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td>
418 418
 					</tr>';
419 419
 
420 420
 
@@ -429,9 +429,9 @@  discard block
 block discarded – undo
429 429
 			$ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
430 430
 
431 431
 			// add generic non-identifying messages for non-privileged uesrs
432
-			if ( ! WP_DEBUG ) {
432
+			if ( ! WP_DEBUG) {
433 433
 
434
-				$output .= '<span class="ee-error-user-msg-spn">' . trim( $ex['msg'] )  . '</span> &nbsp; <sup>' . $ex['code'] . '</sup><br />';
434
+				$output .= '<span class="ee-error-user-msg-spn">'.trim($ex['msg']).'</span> &nbsp; <sup>'.$ex['code'].'</sup><br />';
435 435
 
436 436
 			} else {
437 437
 
@@ -439,24 +439,24 @@  discard block
 block discarded – undo
439 439
 				$output .= '
440 440
 		<div class="ee-error-dev-msg-dv">
441 441
 			<p class="ee-error-dev-msg-pg">
442
-				<strong class="ee-error-dev-msg-str">An ' . $ex['name'] . ' exception was thrown!</strong>  &nbsp; <span>code: ' . $ex['code'] . '</span><br />
443
-				<span class="big-text">"' . trim( $ex['msg'] ) . '"</span><br/>
444
-				<a id="display-ee-error-trace-' . self::$_error_count . $time . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' . self::$_error_count . $time . '">
445
-					' . __( 'click to view backtrace and class/method details', 'event_espresso' ) . '
442
+				<strong class="ee-error-dev-msg-str">An ' . $ex['name'].' exception was thrown!</strong>  &nbsp; <span>code: '.$ex['code'].'</span><br />
443
+				<span class="big-text">"' . trim($ex['msg']).'"</span><br/>
444
+				<a id="display-ee-error-trace-' . self::$_error_count.$time.'" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'.self::$_error_count.$time.'">
445
+					' . __('click to view backtrace and class/method details', 'event_espresso').'
446 446
 				</a><br />
447 447
 				<span class="small-text lt-grey-text">'.$ex['file'].' &nbsp; ( line no: '.$ex['line'].' )</span>
448 448
 			</p>
449
-			<div id="ee-error-trace-' . self::$_error_count . $time . '-dv" class="ee-error-trace-dv" style="display: none;">
449
+			<div id="ee-error-trace-' . self::$_error_count.$time.'-dv" class="ee-error-trace-dv" style="display: none;">
450 450
 				' . $trace_details;
451 451
 
452
-				if ( ! empty( $class )) {
452
+				if ( ! empty($class)) {
453 453
 					$output .= '
454 454
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
455 455
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
456 456
 						<h3>Class Details</h3>';
457
-						$a = new ReflectionClass( $class );
457
+						$a = new ReflectionClass($class);
458 458
 						$output .= '
459
-						<pre>' . $a . '</pre>
459
+						<pre>' . $a.'</pre>
460 460
 					</div>
461 461
 				</div>';
462 462
 				}
@@ -468,14 +468,14 @@  discard block
 block discarded – undo
468 468
 
469 469
 			}
470 470
 
471
-			$this->write_to_error_log( $time, $ex );
471
+			$this->write_to_error_log($time, $ex);
472 472
 
473 473
 		}
474 474
 
475 475
 		// remove last linebreak
476
-		$output = substr( $output, 0, ( count( $output ) - 7 ));
476
+		$output = substr($output, 0, (count($output) - 7));
477 477
 
478
-		if ( ! WP_DEBUG ) {
478
+		if ( ! WP_DEBUG) {
479 479
 			$output .= '
480 480
 	</p>';
481 481
 		}
@@ -483,10 +483,10 @@  discard block
 block discarded – undo
483 483
 		$output .= '
484 484
 </div>';
485 485
 
486
-		$output .= self::_print_scripts( TRUE );
486
+		$output .= self::_print_scripts(TRUE);
487 487
 
488
-		if ( defined( 'DOING_AJAX' )) {
489
-			echo wp_json_encode( array( 'error' => $output ));
488
+		if (defined('DOING_AJAX')) {
489
+			echo wp_json_encode(array('error' => $output));
490 490
 			exit();
491 491
 		}
492 492
 
@@ -506,29 +506,29 @@  discard block
 block discarded – undo
506 506
 	*	@ param array $arguments
507 507
 	*	@ return string
508 508
 	*/
509
-	private function _convert_args_to_string ( $arguments = array(), $array = FALSE ) {
509
+	private function _convert_args_to_string($arguments = array(), $array = FALSE) {
510 510
 
511 511
 		$arg_string = '';
512
-		if ( ! empty( $arguments )) {
512
+		if ( ! empty($arguments)) {
513 513
 
514 514
 			$args = array();
515 515
 
516
-			foreach ( $arguments as $arg ) {
516
+			foreach ($arguments as $arg) {
517 517
 
518
-				if ( ! empty( $arg )) {
518
+				if ( ! empty($arg)) {
519 519
 
520
-					if ( is_string( $arg )) {
521
-						$args[] = " '" . $arg . "'";
522
-					} elseif ( is_array( $arg )) {
523
-						$args[] = 'ARRAY(' . $this->_convert_args_to_string( $arg, TRUE );
524
-					} elseif ( is_null( $arg )) {
520
+					if (is_string($arg)) {
521
+						$args[] = " '".$arg."'";
522
+					} elseif (is_array($arg)) {
523
+						$args[] = 'ARRAY('.$this->_convert_args_to_string($arg, TRUE);
524
+					} elseif (is_null($arg)) {
525 525
 						$args[] = ' NULL';
526
-					} elseif ( is_bool( $arg )) {
527
-						$args[] = ( $arg ) ? ' TRUE' : ' FALSE';
528
-					} elseif ( is_object( $arg )) {
529
-						$args[] = ' OBJECT ' . get_class( $arg );
530
-					} elseif ( is_resource( $arg )) {
531
-						$args[] = get_resource_type( $arg );
526
+					} elseif (is_bool($arg)) {
527
+						$args[] = ($arg) ? ' TRUE' : ' FALSE';
528
+					} elseif (is_object($arg)) {
529
+						$args[] = ' OBJECT '.get_class($arg);
530
+					} elseif (is_resource($arg)) {
531
+						$args[] = get_resource_type($arg);
532 532
 					} else {
533 533
 						$args[] = $arg;
534 534
 					}
@@ -536,9 +536,9 @@  discard block
 block discarded – undo
536 536
 				}
537 537
 
538 538
 			}
539
-			$arg_string = implode( ', ', $args );
539
+			$arg_string = implode(', ', $args);
540 540
 		}
541
-		if ( $array ) {
541
+		if ($array) {
542 542
 			$arg_string .= ' )';
543 543
 		}
544 544
 		return $arg_string;
@@ -558,8 +558,8 @@  discard block
 block discarded – undo
558 558
 	* 	@param		string		$line	the line number where the error occurred - just use __LINE__
559 559
 	* 	@return 		void
560 560
 	*/
561
-	public static function add_error( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) {
562
-		self::_add_notice ( 'errors', $msg, $file, $func, $line );
561
+	public static function add_error($msg = NULL, $file = NULL, $func = NULL, $line = NULL) {
562
+		self::_add_notice('errors', $msg, $file, $func, $line);
563 563
 		self::$_error_count++;
564 564
 	}
565 565
 
@@ -572,11 +572,11 @@  discard block
 block discarded – undo
572 572
 	 * @param string $line
573 573
 	 * @throws EE_Error
574 574
 	 */
575
-	public static function throw_exception_if_debugging( $msg = null, $file = null, $func = null, $line = null ) {
576
-		if( WP_DEBUG ) {
577
-			throw new EE_Error( $msg );
578
-		} else  {
579
-			EE_Error::add_error( $msg, $file, $func, $line );
575
+	public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) {
576
+		if (WP_DEBUG) {
577
+			throw new EE_Error($msg);
578
+		} else {
579
+			EE_Error::add_error($msg, $file, $func, $line);
580 580
 		}
581 581
 	}
582 582
 
@@ -594,8 +594,8 @@  discard block
 block discarded – undo
594 594
 	* 	@param		string		$line	the line number where the error occurred - just use __LINE__
595 595
 	* 	@return 		void
596 596
 	*/
597
-	public static function add_success( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) {
598
-		self::_add_notice ( 'success', $msg, $file, $func, $line );
597
+	public static function add_success($msg = NULL, $file = NULL, $func = NULL, $line = NULL) {
598
+		self::_add_notice('success', $msg, $file, $func, $line);
599 599
 	}
600 600
 
601 601
 
@@ -612,8 +612,8 @@  discard block
 block discarded – undo
612 612
 	* 	@param		string		$line	the line number where the error occurred - just use __LINE__
613 613
 	* 	@return 		void
614 614
 	*/
615
-	public static function add_attention( $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) {
616
-		self::_add_notice ( 'attention', $msg, $file, $func, $line );
615
+	public static function add_attention($msg = NULL, $file = NULL, $func = NULL, $line = NULL) {
616
+		self::_add_notice('attention', $msg, $file, $func, $line);
617 617
 	}
618 618
 
619 619
 
@@ -631,12 +631,12 @@  discard block
 block discarded – undo
631 631
 	* 	@param		string		$line	the line number where the error occurred - just use __LINE__
632 632
 	* 	@return 		void
633 633
 	*/
634
-	private static function _add_notice( $type = 'success', $msg = NULL, $file = NULL, $func = NULL, $line = NULL ) {
635
-		if ( empty( $msg )) {
634
+	private static function _add_notice($type = 'success', $msg = NULL, $file = NULL, $func = NULL, $line = NULL) {
635
+		if (empty($msg)) {
636 636
 			EE_Error::doing_it_wrong(
637
-				'EE_Error::add_' . $type . '()',
637
+				'EE_Error::add_'.$type.'()',
638 638
 				sprintf(
639
-					__( 'Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', 'event_espresso' ),
639
+					__('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', 'event_espresso'),
640 640
 					$type,
641 641
 					$file,
642 642
 					$line
@@ -644,17 +644,17 @@  discard block
 block discarded – undo
644 644
 				EVENT_ESPRESSO_VERSION
645 645
 			);
646 646
 		}
647
-		if ( $type == 'errors' && ( empty( $file ) || empty( $func ) || empty( $line ))) {
647
+		if ($type == 'errors' && (empty($file) || empty($func) || empty($line))) {
648 648
 			EE_Error::doing_it_wrong(
649 649
 				'EE_Error::add_error()',
650
-				__('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', 'event_espresso' ),
650
+				__('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', 'event_espresso'),
651 651
 				EVENT_ESPRESSO_VERSION
652 652
 			);
653 653
 		}
654 654
 		// get separate user and developer messages if they exist
655
-		$msg = explode( '||', $msg );
655
+		$msg = explode('||', $msg);
656 656
 		$user_msg = $msg[0];
657
-		$dev_msg = isset( $msg[1] ) ? $msg[1] : $msg[0];
657
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
658 658
 		/**
659 659
 		 * Do an action so other code can be triggered when a notice is created
660 660
 		 * @param string $type can be 'errors', 'attention', or 'success'
@@ -664,22 +664,22 @@  discard block
 block discarded – undo
664 664
 		 * @param string $func function where error was generated
665 665
 		 * @param string $line line where error was generated
666 666
 		 */
667
-		do_action( 'AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line );
667
+		do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
668 668
 		$msg = WP_DEBUG ? $dev_msg : $user_msg;
669 669
 		// add notice if message exists
670
-		if ( ! empty( $msg )) {
670
+		if ( ! empty($msg)) {
671 671
 			// get error code
672
-			$notice_code = EE_Error::generate_error_code( $file, $func, $line );
673
-			if ( WP_DEBUG && $type == 'errors' ) {
674
-				$msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
672
+			$notice_code = EE_Error::generate_error_code($file, $func, $line);
673
+			if (WP_DEBUG && $type == 'errors') {
674
+				$msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>';
675 675
 			}
676 676
 			// add notice. Index by code if it's not blank
677
-			if( $notice_code ) {
678
-				self::$_espresso_notices[ $type ][ $notice_code ] = $msg;
677
+			if ($notice_code) {
678
+				self::$_espresso_notices[$type][$notice_code] = $msg;
679 679
 			} else {
680
-				self::$_espresso_notices[ $type ][] = $msg;
680
+				self::$_espresso_notices[$type][] = $msg;
681 681
 			}
682
-			add_action( 'wp_footer', array( 'EE_Error', 'enqueue_error_scripts' ), 1 );
682
+			add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
683 683
 		}
684 684
 
685 685
 	}
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
 	*	@access private
734 734
 	*	@return void
735 735
 	*/
736
-	public static function reset_notices(){
736
+	public static function reset_notices() {
737 737
     	self::$_espresso_notices['success'] = FALSE;
738 738
     	self::$_espresso_notices['attention'] = FALSE;
739 739
     	self::$_espresso_notices['errors'] = FALSE;
@@ -746,14 +746,14 @@  discard block
 block discarded – undo
746 746
 	*	@access public
747 747
 	*	@return int
748 748
 	*/
749
-    public static function has_notices(){
749
+    public static function has_notices() {
750 750
 		$has_notices = 0;
751 751
 		// check for success messages
752
-		$has_notices = self::$_espresso_notices['success'] && ! empty(  self::$_espresso_notices['success'] ) ? 3 : $has_notices;
752
+		$has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3 : $has_notices;
753 753
 		// check for attention messages
754
-		$has_notices = self::$_espresso_notices['attention'] && ! empty(  self::$_espresso_notices['attention'] ) ? 2 : $has_notices;
754
+		$has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2 : $has_notices;
755 755
 		// check for error messages
756
-		$has_notices = self::$_espresso_notices['errors'] && ! empty(  self::$_espresso_notices['errors'] ) ? 1 : $has_notices;
756
+		$has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1 : $has_notices;
757 757
 		return $has_notices;
758 758
 	}
759 759
 
@@ -768,9 +768,9 @@  discard block
 block discarded – undo
768 768
 	 */
769 769
 	public static function get_vanilla_notices() {
770 770
 		return array(
771
-			'success' => isset( self::$_espresso_notices['success'] ) ? self::$_espresso_notices['success'] : array(),
772
-			'attention' => isset( self::$_espresso_notices['attention'] )  ? self::$_espresso_notices['attention'] : array(),
773
-			'errors' => isset( self::$_espresso_notices['errors'] ) ? self::$_espresso_notices['errors'] : array(),
771
+			'success' => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(),
772
+			'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention'] : array(),
773
+			'errors' => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(),
774 774
 		);
775 775
 	}
776 776
 
@@ -786,8 +786,8 @@  discard block
 block discarded – undo
786 786
 	* 	@param		boolean		$remove_empty		whether or not to unset empty messages
787 787
 	* 	@return 		array
788 788
 	*/
789
-	public static function get_notices( $format_output = TRUE, $save_to_transient = FALSE, $remove_empty = TRUE ) {
790
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
789
+	public static function get_notices($format_output = TRUE, $save_to_transient = FALSE, $remove_empty = TRUE) {
790
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
791 791
 
792 792
 		$success_messages = '';
793 793
 		$attention_messages = '';
@@ -797,44 +797,44 @@  discard block
 block discarded – undo
797 797
 		// EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
798 798
 
799 799
 		// either save notices to the db
800
-		if ( $save_to_transient ) {
801
-			update_option( 'ee_notices', self::$_espresso_notices );
800
+		if ($save_to_transient) {
801
+			update_option('ee_notices', self::$_espresso_notices);
802 802
 			return;
803 803
 		}
804 804
 		// grab any notices that have been previously saved
805
-		if ( $notices = get_option( 'ee_notices', FALSE )) {
806
-			foreach ( $notices as $type => $notice ) {
807
-				if ( is_array( $notice ) && ! empty( $notice )) {
805
+		if ($notices = get_option('ee_notices', FALSE)) {
806
+			foreach ($notices as $type => $notice) {
807
+				if (is_array($notice) && ! empty($notice)) {
808 808
 					// make sure that existing notice type is an array
809
-					self::$_espresso_notices[ $type ] =  is_array( self::$_espresso_notices[ $type ] ) && ! empty( self::$_espresso_notices[ $type ] ) ? self::$_espresso_notices[ $type ] : array();
809
+					self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) && ! empty(self::$_espresso_notices[$type]) ? self::$_espresso_notices[$type] : array();
810 810
 					// merge stored notices with any newly created ones
811
-					self::$_espresso_notices[ $type ] = array_merge( self::$_espresso_notices[ $type ], $notice );
811
+					self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
812 812
 					$print_scripts = TRUE;
813 813
 				}
814 814
 			}
815 815
 			// now clear any stored notices
816
-			update_option( 'ee_notices', FALSE );
816
+			update_option('ee_notices', FALSE);
817 817
 		}
818 818
 
819 819
 		// check for success messages
820
-		if ( self::$_espresso_notices['success'] && ! empty(  self::$_espresso_notices['success'] )) {
820
+		if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
821 821
 			// combine messages
822
-			$success_messages .= implode( self::$_espresso_notices['success'], '<br />' );
822
+			$success_messages .= implode(self::$_espresso_notices['success'], '<br />');
823 823
 			$print_scripts = TRUE;
824 824
 		}
825 825
 
826 826
 		// check for attention messages
827
-		if ( self::$_espresso_notices['attention'] && ! empty(  self::$_espresso_notices['attention'] ) ) {
827
+		if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
828 828
 			// combine messages
829
-			$attention_messages .= implode( self::$_espresso_notices['attention'], '<br />' );
829
+			$attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
830 830
 			$print_scripts = TRUE;
831 831
 		}
832 832
 
833 833
 		// check for error messages
834
-		if ( self::$_espresso_notices['errors'] && ! empty(  self::$_espresso_notices['errors'] ) ) {
835
-			$error_messages .= count( self::$_espresso_notices['errors'] ) > 1 ? __( 'The following errors have occurred:<br />', 'event_espresso' ) : __( 'An error has occurred:<br />', 'event_espresso' );
834
+		if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
835
+			$error_messages .= count(self::$_espresso_notices['errors']) > 1 ? __('The following errors have occurred:<br />', 'event_espresso') : __('An error has occurred:<br />', 'event_espresso');
836 836
 			// combine messages
837
-			$error_messages .= implode( self::$_espresso_notices['errors'], '<br />' );
837
+			$error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
838 838
 			$print_scripts = TRUE;
839 839
 		}
840 840
 
@@ -848,21 +848,21 @@  discard block
 block discarded – undo
848 848
 				$css_id = is_admin() ? 'message' : 'espresso-notices-success';
849 849
 				$css_class = is_admin() ? 'updated fade' : 'success fade-away';
850 850
 				//showMessage( $success_messages );
851
-				$notices .= '<div id="' . $css_id . '" class="espresso-notices ' . $css_class . '" style="display:none;"><p>' . $success_messages . '</p>' . $close . '</div>';
851
+				$notices .= '<div id="'.$css_id.'" class="espresso-notices '.$css_class.'" style="display:none;"><p>'.$success_messages.'</p>'.$close.'</div>';
852 852
 			}
853 853
 
854 854
 			if ($attention_messages !== '') {
855 855
 				$css_id = is_admin() ? 'message' : 'espresso-notices-attention';
856 856
 				$css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
857 857
 				//showMessage( $error_messages, TRUE );
858
-				$notices .= '<div id="' . $css_id . '" class="espresso-notices ' . $css_class . '" style="display:none;"><p>' . $attention_messages . '</p>' . $close . '</div>';
858
+				$notices .= '<div id="'.$css_id.'" class="espresso-notices '.$css_class.'" style="display:none;"><p>'.$attention_messages.'</p>'.$close.'</div>';
859 859
 			}
860 860
 
861 861
 			if ($error_messages !== '') {
862 862
 				$css_id = is_admin() ? 'message' : 'espresso-notices-error';
863 863
 				$css_class = is_admin() ? 'error' : 'error fade-away';
864 864
 				//showMessage( $error_messages, TRUE );
865
-				$notices .= '<div id="' . $css_id . '" class="espresso-notices ' . $css_class . '" style="display:none;"><p>' . $error_messages . '</p>' . $close . '</div>';
865
+				$notices .= '<div id="'.$css_id.'" class="espresso-notices '.$css_class.'" style="display:none;"><p>'.$error_messages.'</p>'.$close.'</div>';
866 866
 			}
867 867
 
868 868
 			$notices .= '</div>';
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
 					'errors' => $error_messages
876 876
 			);
877 877
 
878
-			if ( $remove_empty ) {
878
+			if ($remove_empty) {
879 879
 				// remove empty notices
880 880
 				foreach ($notices as $type => $notice) {
881 881
 					if (empty($notice)) {
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
 			}
886 886
 		}
887 887
 
888
-		if ( $print_scripts ) {
888
+		if ($print_scripts) {
889 889
 			self::_print_scripts();
890 890
 		}
891 891
 
@@ -905,17 +905,17 @@  discard block
 block discarded – undo
905 905
 	* 	@param bool $force_update allows one to enforce the reappearance of a persistent message.
906 906
 	* 	@return 		void
907 907
 	*/
908
-	public static function add_persistent_admin_notice( $pan_name = '', $pan_message, $force_update = FALSE ) {
909
-		if ( ! empty( $pan_name ) && ! empty( $pan_message )) {
910
-			$persistent_admin_notices = get_option( 'ee_pers_admin_notices', array() );
908
+	public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = FALSE) {
909
+		if ( ! empty($pan_name) && ! empty($pan_message)) {
910
+			$persistent_admin_notices = get_option('ee_pers_admin_notices', array());
911 911
 			//maybe initialize persistent_admin_notices
912
-			if ( empty( $persistent_admin_notices )) {
913
-				add_option( 'ee_pers_admin_notices', array(), '', 'no' );
912
+			if (empty($persistent_admin_notices)) {
913
+				add_option('ee_pers_admin_notices', array(), '', 'no');
914 914
 			}
915
-			$pan_name = sanitize_key( $pan_name );
916
-			if ( ! array_key_exists( $pan_name, $persistent_admin_notices ) || $force_update ) {
917
-				$persistent_admin_notices[ $pan_name ] = $pan_message;
918
-				update_option( 'ee_pers_admin_notices', $persistent_admin_notices );
915
+			$pan_name = sanitize_key($pan_name);
916
+			if ( ! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
917
+				$persistent_admin_notices[$pan_name] = $pan_message;
918
+				update_option('ee_pers_admin_notices', $persistent_admin_notices);
919 919
 			}
920 920
 		}
921 921
 	}
@@ -931,34 +931,34 @@  discard block
 block discarded – undo
931 931
 	 * @param bool          $return_immediately
932 932
 	 * @return        void
933 933
 	 */
934
-	public static function dismiss_persistent_admin_notice( $pan_name = '', $purge = FALSE, $return_immediately = FALSE ) {
935
-		$pan_name = EE_Registry::instance()->REQ->is_set( 'ee_nag_notice' ) ? EE_Registry::instance()->REQ->get( 'ee_nag_notice' ) : $pan_name;
936
-		if ( ! empty( $pan_name )) {
937
-			$persistent_admin_notices = get_option( 'ee_pers_admin_notices', array() );
934
+	public static function dismiss_persistent_admin_notice($pan_name = '', $purge = FALSE, $return_immediately = FALSE) {
935
+		$pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice') ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name;
936
+		if ( ! empty($pan_name)) {
937
+			$persistent_admin_notices = get_option('ee_pers_admin_notices', array());
938 938
 			// check if notice we wish to dismiss is actually in the $persistent_admin_notices array
939
-			if ( is_array( $persistent_admin_notices ) && isset( $persistent_admin_notices[ $pan_name ] )) {
939
+			if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) {
940 940
 				// completely delete nag notice, or just NULL message so that it can NOT be added again ?
941
-				if ( $purge ) {
942
-					unset( $persistent_admin_notices[ $pan_name ] );
941
+				if ($purge) {
942
+					unset($persistent_admin_notices[$pan_name]);
943 943
 				} else {
944
-					$persistent_admin_notices[ $pan_name ] = NULL;
944
+					$persistent_admin_notices[$pan_name] = NULL;
945 945
 				}
946
-				if ( update_option( 'ee_pers_admin_notices', $persistent_admin_notices ) === FALSE ) {
947
-					EE_Error::add_error( sprintf( __( 'The persistent admin notice for "%s" could not be deleted.', 'event_espresso' ), $pan_name ), __FILE__, __FUNCTION__, __LINE__ );
946
+				if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === FALSE) {
947
+					EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.', 'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__);
948 948
 				}
949 949
 			}
950 950
 		}
951
-		if ( $return_immediately ) {
951
+		if ($return_immediately) {
952 952
 			return;
953
-		} else if ( EE_Registry::instance()->REQ->ajax ) {
953
+		} else if (EE_Registry::instance()->REQ->ajax) {
954 954
 			// grab any notices and concatenate into string
955
-			echo wp_json_encode( array( 'errors' => implode( '<br />', EE_Error::get_notices( FALSE ))));
955
+			echo wp_json_encode(array('errors' => implode('<br />', EE_Error::get_notices(FALSE))));
956 956
 			exit();
957 957
 		} else {
958 958
 			// save errors to a transient to be displayed on next request (after redirect)
959
-			EE_Error::get_notices( FALSE, TRUE );
960
-			$return_url = EE_Registry::instance()->REQ->is_set( 'return_url' ) ? EE_Registry::instance()->REQ->get( 'return_url' ) : '';
961
-			wp_safe_redirect( urldecode( $return_url ));
959
+			EE_Error::get_notices(FALSE, TRUE);
960
+			$return_url = EE_Registry::instance()->REQ->is_set('return_url') ? EE_Registry::instance()->REQ->get('return_url') : '';
961
+			wp_safe_redirect(urldecode($return_url));
962 962
 		}
963 963
 	}
964 964
 
@@ -973,20 +973,20 @@  discard block
 block discarded – undo
973 973
 	 * @param  string $return_url  URL to go back to after nag notice is dismissed
974 974
 	 * @return string
975 975
 	 */
976
-	public static function display_persistent_admin_notices( $pan_name = '', $pan_message = '', $return_url = '' ) {
977
-		if ( ! empty( $pan_name ) && ! empty( $pan_message )) {
976
+	public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') {
977
+		if ( ! empty($pan_name) && ! empty($pan_message)) {
978 978
 			$args = array(
979 979
 				'nag_notice' => $pan_name,
980
-				'return_url' => urlencode( $return_url ),
980
+				'return_url' => urlencode($return_url),
981 981
 				'ajax_url' => WP_AJAX_URL,
982
-				'unknown_error' => __( 'An unknown error has occurred on the server while attempting to dismiss this notice.', 'event_espresso' )
982
+				'unknown_error' => __('An unknown error has occurred on the server while attempting to dismiss this notice.', 'event_espresso')
983 983
 			);
984
-			wp_localize_script( 'espresso_core', 'ee_dismiss', $args );
984
+			wp_localize_script('espresso_core', 'ee_dismiss', $args);
985 985
 			return '
986
-			<div id="' . $pan_name . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;">
987
-				<p>' . $pan_message . '</p>
988
-				<a class="dismiss-ee-nag-notice hide-if-no-js" style="float: right; cursor: pointer; text-decoration:none;" rel="' . $pan_name . '">
989
-					<span class="dashicons dashicons-dismiss" style="position:relative; top:-1px; margin-right:.25em;"></span>'.__( 'Dismiss', 'event_espresso' ) .'
986
+			<div id="' . $pan_name.'" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;">
987
+				<p>' . $pan_message.'</p>
988
+				<a class="dismiss-ee-nag-notice hide-if-no-js" style="float: right; cursor: pointer; text-decoration:none;" rel="' . $pan_name.'">
989
+					<span class="dashicons dashicons-dismiss" style="position:relative; top:-1px; margin-right:.25em;"></span>'.__('Dismiss', 'event_espresso').'
990 990
 				</a>
991 991
 				<div style="clear:both;"></div>
992 992
 			</div>';
@@ -1003,24 +1003,24 @@  discard block
 block discarded – undo
1003 1003
 	 * @param string $return_url
1004 1004
 	 * @return    array
1005 1005
 	 */
1006
-	public static function get_persistent_admin_notices( $return_url = '' ) {
1006
+	public static function get_persistent_admin_notices($return_url = '') {
1007 1007
 		$notices = '';
1008 1008
 		// check for persistent admin notices
1009 1009
 		//filter the list though so plugins can notify the admin in a different way if they want
1010 1010
 		$persistent_admin_notices = apply_filters(
1011 1011
 			'FHEE__EE_Error__get_persistent_admin_notices',
1012
-			get_option( 'ee_pers_admin_notices', FALSE ),
1012
+			get_option('ee_pers_admin_notices', FALSE),
1013 1013
 			'ee_pers_admin_notices',
1014 1014
 			$return_url
1015 1015
 		);
1016
-		if ( $persistent_admin_notices ) {
1016
+		if ($persistent_admin_notices) {
1017 1017
 			// load scripts
1018
-			wp_register_script( 'espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE );
1019
-			wp_register_script( 'ee_error_js', EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, TRUE );
1020
-			wp_enqueue_script( 'ee_error_js' );
1018
+			wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE);
1019
+			wp_register_script('ee_error_js', EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, TRUE);
1020
+			wp_enqueue_script('ee_error_js');
1021 1021
 			// and display notices
1022
-			foreach( $persistent_admin_notices as $pan_name => $pan_message ) {
1023
-				$notices .= self::display_persistent_admin_notices( $pan_name, $pan_message, $return_url );
1022
+			foreach ($persistent_admin_notices as $pan_name => $pan_message) {
1023
+				$notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url);
1024 1024
 			}
1025 1025
 		}
1026 1026
 		return $notices;
@@ -1035,26 +1035,26 @@  discard block
 block discarded – undo
1035 1035
 	 * @param 	bool $force_print
1036 1036
 	 * @return 	void
1037 1037
 	 */
1038
-	private static function _print_scripts( $force_print = FALSE ) {
1039
-		if (( did_action( 'admin_enqueue_scripts' ) || did_action( 'wp_enqueue_scripts' )) && ! $force_print ) {
1040
-			if ( wp_script_is( 'ee_error_js', 'enqueued' )) {
1038
+	private static function _print_scripts($force_print = FALSE) {
1039
+		if ((did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts')) && ! $force_print) {
1040
+			if (wp_script_is('ee_error_js', 'enqueued')) {
1041 1041
 				return;
1042
-			} else if ( wp_script_is( 'ee_error_js', 'registered' )) {
1043
-				add_filter( 'FHEE_load_css', '__return_true' );
1044
-				add_filter( 'FHEE_load_js', '__return_true' );
1045
-				wp_enqueue_script( 'ee_error_js' );
1046
-				wp_localize_script( 'ee_error_js','ee_settings', array( 'wp_debug'=>WP_DEBUG ));
1042
+			} else if (wp_script_is('ee_error_js', 'registered')) {
1043
+				add_filter('FHEE_load_css', '__return_true');
1044
+				add_filter('FHEE_load_js', '__return_true');
1045
+				wp_enqueue_script('ee_error_js');
1046
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug'=>WP_DEBUG));
1047 1047
 			}
1048 1048
 		} else {
1049 1049
 			return '
1050 1050
 <script>
1051 1051
 /* <![CDATA[ */
1052
-var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
1052
+var ee_settings = {"wp_debug":"' . WP_DEBUG.'"};
1053 1053
 /* ]]> */
1054 1054
 </script>
1055
-<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script>
1056
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1057
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1055
+<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script>
1056
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1057
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1058 1058
 ';
1059 1059
 
1060 1060
 		}
@@ -1088,11 +1088,11 @@  discard block
 block discarded – undo
1088 1088
 	*	@param string $line
1089 1089
 	*	@return string
1090 1090
 	*/
1091
-	public static function generate_error_code ( $file = '', $func = '', $line = '' ) {
1092
-		$file = explode( '.', basename( $file ));
1093
-		$error_code = ! empty( $file[0] ) ? $file[0] : '';
1094
-		$error_code .= ! empty( $func ) ? ' - ' . $func : '';
1095
-		$error_code .= ! empty( $line ) ? ' - ' . $line : '';
1091
+	public static function generate_error_code($file = '', $func = '', $line = '') {
1092
+		$file = explode('.', basename($file));
1093
+		$error_code = ! empty($file[0]) ? $file[0] : '';
1094
+		$error_code .= ! empty($func) ? ' - '.$func : '';
1095
+		$error_code .= ! empty($line) ? ' - '.$line : '';
1096 1096
 		return $error_code;
1097 1097
 	}
1098 1098
 
@@ -1108,36 +1108,36 @@  discard block
 block discarded – undo
1108 1108
 	*	@ param object $ex
1109 1109
 	*	@ return void
1110 1110
 	*/
1111
-	public function write_to_error_log ( $time = FALSE, $ex = FALSE, $clear = FALSE ) {
1111
+	public function write_to_error_log($time = FALSE, $ex = FALSE, $clear = FALSE) {
1112 1112
 
1113
-		if ( ! $ex ) {
1113
+		if ( ! $ex) {
1114 1114
 			return;
1115 1115
 		}
1116 1116
 
1117
-		if ( ! $time ) {
1117
+		if ( ! $time) {
1118 1118
 			$time = time();
1119 1119
 		}
1120 1120
 
1121
-		$exception_log = '----------------------------------------------------------------------------------------' . PHP_EOL;
1122
-		$exception_log .= '[' . date( 'Y-m-d H:i:s', $time ) . ']  Exception Details' . PHP_EOL;
1123
-		$exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1124
-		$exception_log .= 'Code: '. $ex['code'] . PHP_EOL;
1125
-		$exception_log .= 'File: '. $ex['file'] . PHP_EOL;
1126
-		$exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1127
-		$exception_log .= 'Stack trace: ' . PHP_EOL;
1128
-		$exception_log .= $ex['string'] . PHP_EOL;
1129
-		$exception_log .= '----------------------------------------------------------------------------------------' . PHP_EOL;
1121
+		$exception_log = '----------------------------------------------------------------------------------------'.PHP_EOL;
1122
+		$exception_log .= '['.date('Y-m-d H:i:s', $time).']  Exception Details'.PHP_EOL;
1123
+		$exception_log .= 'Message: '.$ex['msg'].PHP_EOL;
1124
+		$exception_log .= 'Code: '.$ex['code'].PHP_EOL;
1125
+		$exception_log .= 'File: '.$ex['file'].PHP_EOL;
1126
+		$exception_log .= 'Line No: '.$ex['line'].PHP_EOL;
1127
+		$exception_log .= 'Stack trace: '.PHP_EOL;
1128
+		$exception_log .= $ex['string'].PHP_EOL;
1129
+		$exception_log .= '----------------------------------------------------------------------------------------'.PHP_EOL;
1130 1130
 
1131 1131
 		try {
1132
-			EEH_File::ensure_file_exists_and_is_writable( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file );
1133
-			EEH_File::add_htaccess_deny_from_all( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' );
1134
-			if ( ! $clear ) {
1132
+			EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file);
1133
+			EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs');
1134
+			if ( ! $clear) {
1135 1135
 				//get existing log file and append new log info
1136
-				$exception_log = EEH_File::get_file_contents( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file ) . $exception_log;
1136
+				$exception_log = EEH_File::get_file_contents(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file).$exception_log;
1137 1137
 			}
1138
-			EEH_File::write_to_file( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file, $exception_log );
1139
-		} catch( EE_Error $e ){
1140
-			EE_Error::add_error( sprintf( __(  'Event Espresso error logging could not be setup because: %s', 'event_espresso' ), $e->getMessage() ));
1138
+			EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file, $exception_log);
1139
+		} catch (EE_Error $e) {
1140
+			EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', 'event_espresso'), $e->getMessage()));
1141 1141
 			return;
1142 1142
 		}
1143 1143
 
@@ -1173,8 +1173,8 @@  discard block
 block discarded – undo
1173 1173
 		$applies_when = '',
1174 1174
 		$error_type = null
1175 1175
 	) {
1176
-		if ( defined('WP_DEBUG') && WP_DEBUG ) {
1177
-			EEH_Debug_Tools::instance()->doing_it_wrong( $function, $message, $version, $applies_when, $error_type );
1176
+		if (defined('WP_DEBUG') && WP_DEBUG) {
1177
+			EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1178 1178
 		}
1179 1179
 	}
1180 1180
 
@@ -1208,13 +1208,13 @@  discard block
 block discarded – undo
1208 1208
  */
1209 1209
 function espresso_error_enqueue_scripts() {
1210 1210
 	// js for error handling
1211
-	wp_register_script( 'espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, FALSE );
1212
-	wp_register_script( 'ee_error_js', EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, FALSE );
1211
+	wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, FALSE);
1212
+	wp_register_script('ee_error_js', EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', array('espresso_core'), EVENT_ESPRESSO_VERSION, FALSE);
1213 1213
 }
1214
-if ( is_admin() ) {
1215
-	add_action( 'admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2 );
1214
+if (is_admin()) {
1215
+	add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1216 1216
 } else {
1217
-	add_action( 'wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2 );
1217
+	add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1218 1218
 }
1219 1219
 
1220 1220
 
Please login to merge, or discard this patch.
core/templates/json_linked_data_for_event.template.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@
 block discarded – undo
32 32
       "price": "<?php echo $ticket['price']; ?>",
33 33
       "priceCurrency": "<?php echo $currency; ?>"
34 34
     }<?php if (is_array($event_tickets) && end($event_tickets) !== $ticket) { echo ','; }
35
-    }
36
-    ?>
35
+	}
36
+	?>
37 37
     ]<?php if ($venue_name) { ?>,
38 38
   "location": {
39 39
     "@type": "Place",
Please login to merge, or discard this patch.
espresso.php 2 patches
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -129,54 +129,54 @@  discard block
 block discarded – undo
129 129
         define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130 130
         define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131 131
         // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
132
+        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH.'admin_pages'.DS);
133
+        define('EE_CORE', EE_PLUGIN_DIR_PATH.'core'.DS);
134
+        define('EE_MODULES', EE_PLUGIN_DIR_PATH.'modules'.DS);
135
+        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH.'public'.DS);
136
+        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH.'shortcodes'.DS);
137
+        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH.'widgets'.DS);
138
+        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH.'payment_methods'.DS);
139
+        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH.'caffeinated'.DS);
140 140
         // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
141
+        define('EE_ADMIN', EE_CORE.'admin'.DS);
142
+        define('EE_CPTS', EE_CORE.'CPTs'.DS);
143
+        define('EE_CLASSES', EE_CORE.'db_classes'.DS);
144
+        define('EE_INTERFACES', EE_CORE.'interfaces'.DS);
145
+        define('EE_BUSINESS', EE_CORE.'business'.DS);
146
+        define('EE_MODELS', EE_CORE.'db_models'.DS);
147
+        define('EE_HELPERS', EE_CORE.'helpers'.DS);
148
+        define('EE_LIBRARIES', EE_CORE.'libraries'.DS);
149
+        define('EE_TEMPLATES', EE_CORE.'templates'.DS);
150
+        define('EE_THIRD_PARTY', EE_CORE.'third_party_libs'.DS);
151
+        define('EE_GLOBAL_ASSETS', EE_TEMPLATES.'global_assets'.DS);
152
+        define('EE_FORM_SECTIONS', EE_LIBRARIES.'form_sections'.DS);
153 153
         // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
154
+        define('EE_GATEWAYS', EE_MODULES.'gateways'.DS);
155
+        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL.'modules'.DS.'gateways'.DS);
156 156
         // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
157
+        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL.'core'.DS.'templates'.DS);
158
+        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL.'global_assets'.DS);
159
+        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL.'images'.DS);
160
+        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL.'core'.DS.'third_party_libs'.DS);
161
+        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL.'core/helpers/assets/');
162
+        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL.'core/libraries/');
163 163
         // define upload paths
164 164
         $uploads = wp_upload_dir();
165 165
         // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
166
+        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'].DS.'espresso'.DS);
167
+        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'].DS.'espresso'.DS);
168 168
         // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
169
+        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'].DS.'espresso'.DS.'templates'.DS);
170
+        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'].DS.'espresso'.DS.'templates'.DS);
171 171
         // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
172
+        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'].DS.'espresso'.DS.'gateways'.DS);
173
+        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'].DS.'espresso'.DS.'gateways'.DS);
174 174
         // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
175
+        define('EE_LANGUAGES_SAFE_LOC', '..'.DS.'uploads'.DS.'espresso'.DS.'languages'.DS);
176
+        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'languages'.DS);
177 177
         //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
178
+        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS)) {
179
+            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS);
180 180
         }
181 181
         //ajax constants
182 182
         define(
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
         //you're better to use this than its straight value (currently -1) in case you ever
192 192
         //want to change its default value! or find when -1 means infinity
193 193
         define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
194
+        define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX);
195 195
         define('EE_DEBUG', false);
196 196
         // for older WP versions
197 197
         if ( ! defined('MONTH_IN_SECONDS')) {
@@ -214,13 +214,13 @@  discard block
 block discarded – undo
214 214
         function espresso_load_error_handling()
215 215
         {
216 216
             // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
217
+            if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) {
218
+                require_once(EE_HELPERS.'EEH_Debug_Tools.helper.php');
219 219
                 EEH_Debug_Tools::instance();
220 220
             }
221 221
             // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
222
+            if (is_readable(EE_CORE.'EE_Error.core.php')) {
223
+                require_once(EE_CORE.'EE_Error.core.php');
224 224
             } else {
225 225
                 wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226 226
             }
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
             if (is_readable($full_path_to_file)) {
245 245
                 require_once($full_path_to_file);
246 246
             } else {
247
-                throw new EE_Error (
247
+                throw new EE_Error(
248 248
                         sprintf(
249 249
                                 esc_html__(
250 250
                                         'The %s class file could not be located or is not readable due to file permissions.',
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
             }
257 257
         }
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
259
+        espresso_load_required('EEH_Base', EE_CORE.'helpers'.DS.'EEH_Base.helper.php');
260
+        espresso_load_required('EEH_File', EE_CORE.'helpers'.DS.'EEH_File.helper.php');
261
+        espresso_load_required('EE_Bootstrap', EE_CORE.'EE_Bootstrap.core.php');
262 262
         new EE_Bootstrap();
263 263
     }
264 264
 }
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
     function espresso_deactivate_plugin($plugin_basename = '')
275 275
     {
276 276
         if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
277
+            require_once(ABSPATH.'wp-admin/includes/plugin.php');
278 278
         }
279 279
         unset($_GET['activate'], $_REQUEST['activate']);
280 280
         deactivate_plugins($plugin_basename);
Please login to merge, or discard this patch.
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,243 +40,243 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                ); ?>
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+				); ?>
56 56
             </p>
57 57
         </div>
58 58
         <?php
59
-        espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.30.rc.012');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.30.rc.012');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
-        new EE_Bootstrap();
263
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
+		new EE_Bootstrap();
263
+	}
264 264
 }
265 265
 if ( ! function_exists('espresso_deactivate_plugin')) {
266
-    /**
267
-     *    deactivate_plugin
268
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
-     *
270
-     * @access public
271
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
-     * @return    void
273
-     */
274
-    function espresso_deactivate_plugin($plugin_basename = '')
275
-    {
276
-        if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
-        }
279
-        unset($_GET['activate'], $_REQUEST['activate']);
280
-        deactivate_plugins($plugin_basename);
281
-    }
266
+	/**
267
+	 *    deactivate_plugin
268
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
+	 *
270
+	 * @access public
271
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
+	 * @return    void
273
+	 */
274
+	function espresso_deactivate_plugin($plugin_basename = '')
275
+	{
276
+		if ( ! function_exists('deactivate_plugins')) {
277
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
+		}
279
+		unset($_GET['activate'], $_REQUEST['activate']);
280
+		deactivate_plugins($plugin_basename);
281
+	}
282 282
 }
Please login to merge, or discard this patch.
public/template_tags.php 1 patch
Spacing   +276 added lines, -276 removed lines patch added patch discarded remove patch
@@ -27,12 +27,12 @@  discard block
 block discarded – undo
27 27
  * @param int | \EE_Event $event
28 28
  * @return bool
29 29
  */
30
-function is_espresso_event( $event = NULL ) {
31
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
30
+function is_espresso_event($event = NULL) {
31
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
32 32
 		// extract EE_Event object from passed param regardless of what it is (within reason of course)
33
-		$event = EEH_Event_View::get_event( $event );
33
+		$event = EEH_Event_View::get_event($event);
34 34
 		// do we have a valid event ?
35
-		return $event instanceof EE_Event  ? TRUE : FALSE;
35
+		return $event instanceof EE_Event ? TRUE : FALSE;
36 36
 	}
37 37
 	return FALSE;
38 38
 }
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
  * @return bool
45 45
  */
46 46
 function is_espresso_event_single() {
47
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
47
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
48 48
 		global $wp_query;
49 49
 		// return conditionals set by CPTs
50 50
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_single : FALSE;
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
  * @return bool
60 60
  */
61 61
 function is_espresso_event_archive() {
62
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
62
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
63 63
 		global $wp_query;
64 64
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_archive : FALSE;
65 65
 	}
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
  * @return bool
74 74
  */
75 75
 function is_espresso_event_taxonomy() {
76
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
76
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
77 77
 		global $wp_query;
78 78
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_taxonomy : FALSE;
79 79
 	}
@@ -87,10 +87,10 @@  discard block
 block discarded – undo
87 87
  * @param int | \EE_Venue $venue
88 88
  * @return bool
89 89
  */
90
-function is_espresso_venue( $venue = NULL ) {
91
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
90
+function is_espresso_venue($venue = NULL) {
91
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
92 92
 		// extract EE_Venue object from passed param regardless of what it is (within reason of course)
93
-		$venue = EEH_Venue_View::get_venue( $venue, FALSE );
93
+		$venue = EEH_Venue_View::get_venue($venue, FALSE);
94 94
 		// do we have a valid event ?
95 95
 		return $venue instanceof EE_Venue ? TRUE : FALSE;
96 96
 	}
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
  * @return bool
105 105
  */
106 106
 function is_espresso_venue_single() {
107
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
107
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
108 108
 		global $wp_query;
109 109
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_single : FALSE;
110 110
 	}
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
  * @return bool
119 119
  */
120 120
 function is_espresso_venue_archive() {
121
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
121
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
122 122
 		global $wp_query;
123 123
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_archive : FALSE;
124 124
 	}
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
  * @return bool
133 133
  */
134 134
 function is_espresso_venue_taxonomy() {
135
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
135
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
136 136
 		global $wp_query;
137 137
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_taxonomy : FALSE;
138 138
 	}
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
  * @param $conditional_tag
147 147
  * @return bool
148 148
  */
149
-function can_use_espresso_conditionals( $conditional_tag ) {
150
-	if ( ! did_action( 'AHEE__EE_System__initialize' )) {
149
+function can_use_espresso_conditionals($conditional_tag) {
150
+	if ( ! did_action('AHEE__EE_System__initialize')) {
151 151
 		EE_Error::doing_it_wrong(
152 152
 			__FUNCTION__,
153 153
 			sprintf(
154
-				__( 'The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.','event_espresso'),
154
+				__('The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.', 'event_espresso'),
155 155
 				$conditional_tag
156 156
 			),
157 157
 			'4.4.0'
@@ -166,13 +166,13 @@  discard block
 block discarded – undo
166 166
 
167 167
 /*************************** Event Queries ***************************/
168 168
 
169
-if ( ! function_exists( 'espresso_get_events' )) {
169
+if ( ! function_exists('espresso_get_events')) {
170 170
 	/**
171 171
 	 * 	espresso_get_events
172 172
 	 * @param array $params
173 173
 	 * @return array
174 174
 	 */
175
-	function espresso_get_events( $params = array() ) {
175
+	function espresso_get_events($params = array()) {
176 176
 		//set default params
177 177
 		$default_espresso_events_params = array(
178 178
 			'limit' => 10,
@@ -183,18 +183,18 @@  discard block
 block discarded – undo
183 183
 			'sort' => 'ASC'
184 184
 		);
185 185
 		// allow the defaults to be filtered
186
-		$default_espresso_events_params = apply_filters( 'espresso_get_events__default_espresso_events_params', $default_espresso_events_params );
186
+		$default_espresso_events_params = apply_filters('espresso_get_events__default_espresso_events_params', $default_espresso_events_params);
187 187
 		// grab params and merge with defaults, then extract
188
-		$params = array_merge( $default_espresso_events_params, $params );
188
+		$params = array_merge($default_espresso_events_params, $params);
189 189
 		// run the query
190
-		$events_query = new EE_Event_List_Query( $params );
190
+		$events_query = new EE_Event_List_Query($params);
191 191
 		// assign results to a variable so we can return it
192 192
 		$events = $events_query->have_posts() ? $events_query->posts : array();
193 193
 		// but first reset the query and postdata
194 194
 		wp_reset_query();
195 195
 		wp_reset_postdata();
196 196
 		EED_Events_Archive::remove_all_events_archive_filters();
197
-		unset( $events_query );
197
+		unset($events_query);
198 198
 		return $events;
199 199
 	}
200 200
 }
@@ -208,32 +208,32 @@  discard block
 block discarded – undo
208 208
  * espresso_load_ticket_selector
209 209
  */
210 210
 function espresso_load_ticket_selector() {
211
-	EE_Registry::instance()->load_file( EE_MODULES . 'ticket_selector', 'EED_Ticket_Selector', 'module' );
211
+	EE_Registry::instance()->load_file(EE_MODULES.'ticket_selector', 'EED_Ticket_Selector', 'module');
212 212
 }
213 213
 
214
-if ( ! function_exists( 'espresso_ticket_selector' )) {
214
+if ( ! function_exists('espresso_ticket_selector')) {
215 215
 	/**
216 216
 	 * espresso_ticket_selector
217 217
 	 * @param null $event
218 218
 	 */
219
-	function espresso_ticket_selector( $event = NULL ) {
220
-		if (  ! apply_filters( 'FHEE_disable_espresso_ticket_selector', FALSE ) ) {
219
+	function espresso_ticket_selector($event = NULL) {
220
+		if ( ! apply_filters('FHEE_disable_espresso_ticket_selector', FALSE)) {
221 221
 			espresso_load_ticket_selector();
222
-			echo EED_Ticket_Selector::display_ticket_selector( $event );
222
+			echo EED_Ticket_Selector::display_ticket_selector($event);
223 223
 		}
224 224
 	}
225 225
 }
226 226
 
227 227
 
228
-	if ( ! function_exists( 'espresso_view_details_btn' )) {
228
+	if ( ! function_exists('espresso_view_details_btn')) {
229 229
 	/**
230 230
 	 * espresso_view_details_btn
231 231
 	 * @param null $event
232 232
 	 */
233
-	function espresso_view_details_btn( $event = NULL ) {
234
-		if (  ! apply_filters( 'FHEE_disable_espresso_view_details_btn', FALSE ) ) {
233
+	function espresso_view_details_btn($event = NULL) {
234
+		if ( ! apply_filters('FHEE_disable_espresso_view_details_btn', FALSE)) {
235 235
 			espresso_load_ticket_selector();
236
-			echo EED_Ticket_Selector::display_ticket_selector( $event, TRUE );
236
+			echo EED_Ticket_Selector::display_ticket_selector($event, TRUE);
237 237
 		}
238 238
 	}
239 239
 }
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 
244 244
 /*************************** EEH_Event_View ***************************/
245 245
 
246
-if ( ! function_exists( 'espresso_load_event_list_assets' )) {
246
+if ( ! function_exists('espresso_load_event_list_assets')) {
247 247
 	/**
248 248
 	 * espresso_load_event_list_assets
249 249
 	 * ensures that event list styles and scripts are loaded
@@ -252,13 +252,13 @@  discard block
 block discarded – undo
252 252
 	 */
253 253
 	function espresso_load_event_list_assets() {
254 254
 		$event_list = EED_Events_Archive::instance();
255
-		add_action( 'AHEE__EE_System__initialize_last', array( $event_list, 'load_event_list_assets' ), 10 );
256
-		add_filter( 'FHEE_enable_default_espresso_css', '__return_true' );
255
+		add_action('AHEE__EE_System__initialize_last', array($event_list, 'load_event_list_assets'), 10);
256
+		add_filter('FHEE_enable_default_espresso_css', '__return_true');
257 257
 	}
258 258
 }
259 259
 
260 260
 
261
-if ( ! function_exists( 'espresso_event_reg_button' )) {
261
+if ( ! function_exists('espresso_event_reg_button')) {
262 262
 	/**
263 263
 	 * espresso_event_reg_button
264 264
 	 * returns the "Register Now" button if event is active,
@@ -270,9 +270,9 @@  discard block
 block discarded – undo
270 270
 	 * @param bool $EVT_ID
271 271
 	 * @return string
272 272
 	 */
273
-	function espresso_event_reg_button( $btn_text_if_active = NULL, $btn_text_if_inactive = FALSE, $EVT_ID = FALSE ) {
274
-		$event_status = EEH_Event_View::event_active_status( $EVT_ID );
275
-		switch ( $event_status ) {
273
+	function espresso_event_reg_button($btn_text_if_active = NULL, $btn_text_if_inactive = FALSE, $EVT_ID = FALSE) {
274
+		$event_status = EEH_Event_View::event_active_status($EVT_ID);
275
+		switch ($event_status) {
276 276
 			case EE_Datetime::sold_out :
277 277
 				$btn_text = __('Sold Out', 'event_espresso');
278 278
 				$class = 'ee-pink';
@@ -288,10 +288,10 @@  discard block
 block discarded – undo
288 288
 			case EE_Datetime::upcoming :
289 289
 			case EE_Datetime::active :
290 290
 			default :
291
-				$btn_text =! empty( $btn_text_if_active ) ? $btn_text_if_active : __( 'Register Now', 'event_espresso' );
291
+				$btn_text = ! empty($btn_text_if_active) ? $btn_text_if_active : __('Register Now', 'event_espresso');
292 292
 				$class = 'ee-green';
293 293
 		}
294
-		if ( $event_status < 1 && ! empty( $btn_text_if_inactive )) {
294
+		if ($event_status < 1 && ! empty($btn_text_if_inactive)) {
295 295
 			$btn_text = $btn_text_if_inactive;
296 296
 			$class = 'ee-grey';
297 297
 		}
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 
306 306
 
307 307
 
308
-if ( ! function_exists( 'espresso_display_ticket_selector' )) {
308
+if ( ! function_exists('espresso_display_ticket_selector')) {
309 309
 	/**
310 310
 	 * espresso_display_ticket_selector
311 311
 	 * whether or not to display the Ticket Selector for an event
@@ -313,14 +313,14 @@  discard block
 block discarded – undo
313 313
 	 * @param bool $EVT_ID
314 314
 	 * @return boolean
315 315
 	 */
316
-	function espresso_display_ticket_selector( $EVT_ID = FALSE ) {
317
-		return EEH_Event_View::display_ticket_selector( $EVT_ID );
316
+	function espresso_display_ticket_selector($EVT_ID = FALSE) {
317
+		return EEH_Event_View::display_ticket_selector($EVT_ID);
318 318
 	}
319 319
 }
320 320
 
321 321
 
322 322
 
323
-if ( ! function_exists( 'espresso_event_status_banner' )) {
323
+if ( ! function_exists('espresso_event_status_banner')) {
324 324
 	/**
325 325
 	 * espresso_event_status
326 326
 	 * returns a banner showing the event status if it is sold out, expired, or inactive
@@ -328,13 +328,13 @@  discard block
 block discarded – undo
328 328
 	 * @param bool $EVT_ID
329 329
 	 * @return string
330 330
 	 */
331
-	function espresso_event_status_banner( $EVT_ID = FALSE ) {
332
-		return EEH_Event_View::event_status( $EVT_ID );
331
+	function espresso_event_status_banner($EVT_ID = FALSE) {
332
+		return EEH_Event_View::event_status($EVT_ID);
333 333
 	}
334 334
 }
335 335
 
336 336
 
337
-if ( ! function_exists( 'espresso_event_status' )) {
337
+if ( ! function_exists('espresso_event_status')) {
338 338
 	/**
339 339
 	 * espresso_event_status
340 340
 	 * returns the event status if it is sold out, expired, or inactive
@@ -343,17 +343,17 @@  discard block
 block discarded – undo
343 343
 	 * @param bool $echo
344 344
 	 * @return string
345 345
 	 */
346
-	function espresso_event_status( $EVT_ID = 0, $echo = TRUE ) {
347
-		if ( $echo ) {
348
-			echo EEH_Event_View::event_active_status( $EVT_ID );
346
+	function espresso_event_status($EVT_ID = 0, $echo = TRUE) {
347
+		if ($echo) {
348
+			echo EEH_Event_View::event_active_status($EVT_ID);
349 349
 			return '';
350 350
 		}
351
-		return EEH_Event_View::event_active_status( $EVT_ID );
351
+		return EEH_Event_View::event_active_status($EVT_ID);
352 352
 	}
353 353
 }
354 354
 
355 355
 
356
-if ( ! function_exists( 'espresso_event_categories' )) {
356
+if ( ! function_exists('espresso_event_categories')) {
357 357
 	/**
358 358
 	 * espresso_event_categories
359 359
 	 * returns the terms associated with an event
@@ -363,17 +363,17 @@  discard block
 block discarded – undo
363 363
 	 * @param bool $echo
364 364
 	 * @return string
365 365
 	 */
366
-	function espresso_event_categories( $EVT_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE ) {
367
-		if ( $echo ) {
368
-			echo EEH_Event_View::event_categories( $EVT_ID, $hide_uncategorized );
366
+	function espresso_event_categories($EVT_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE) {
367
+		if ($echo) {
368
+			echo EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized);
369 369
 			return '';
370 370
 		}
371
-		return EEH_Event_View::event_categories( $EVT_ID, $hide_uncategorized );
371
+		return EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized);
372 372
 	}
373 373
 }
374 374
 
375 375
 
376
-if ( ! function_exists( 'espresso_event_tickets_available' )) {
376
+if ( ! function_exists('espresso_event_tickets_available')) {
377 377
 	/**
378 378
 	 * espresso_event_tickets_available
379 379
 	 * returns the ticket types available for purchase for an event
@@ -383,26 +383,26 @@  discard block
 block discarded – undo
383 383
 	 * @param bool $format
384 384
 	 * @return string
385 385
 	 */
386
-	function espresso_event_tickets_available( $EVT_ID = 0, $echo = TRUE, $format = TRUE ) {
387
-		$tickets = EEH_Event_View::event_tickets_available( $EVT_ID );
388
-		if ( is_array( $tickets ) && ! empty( $tickets )) {
386
+	function espresso_event_tickets_available($EVT_ID = 0, $echo = TRUE, $format = TRUE) {
387
+		$tickets = EEH_Event_View::event_tickets_available($EVT_ID);
388
+		if (is_array($tickets) && ! empty($tickets)) {
389 389
 			// if formatting then $html will be a string, else it will be an array of ticket objects
390
-			$html = $format ? '<ul id="ee-event-tickets-ul-' . $EVT_ID . '" class="ee-event-tickets-ul">' : array();
391
-			foreach ( $tickets as $ticket ) {
392
-				if ( $ticket instanceof EE_Ticket ) {
393
-					if ( $format ) {
394
-						$html .= '<li id="ee-event-tickets-li-' . $ticket->ID() . '" class="ee-event-tickets-li">';
395
-						$html .= $ticket->name() . ' ' . EEH_Template::format_currency( $ticket->get_ticket_total_with_taxes() );
390
+			$html = $format ? '<ul id="ee-event-tickets-ul-'.$EVT_ID.'" class="ee-event-tickets-ul">' : array();
391
+			foreach ($tickets as $ticket) {
392
+				if ($ticket instanceof EE_Ticket) {
393
+					if ($format) {
394
+						$html .= '<li id="ee-event-tickets-li-'.$ticket->ID().'" class="ee-event-tickets-li">';
395
+						$html .= $ticket->name().' '.EEH_Template::format_currency($ticket->get_ticket_total_with_taxes());
396 396
 						$html .= '</li>';
397 397
 					} else {
398 398
 						$html[] = $ticket;
399 399
 					}
400 400
 				}
401 401
 			}
402
-			if ( $format ) {
402
+			if ($format) {
403 403
 				$html .= '</ul>';
404 404
 			}
405
-			if ( $echo && ! $format ) {
405
+			if ($echo && ! $format) {
406 406
 				echo $html;
407 407
 				return '';
408 408
 			}
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
 	}
413 413
 }
414 414
 
415
-if ( ! function_exists( 'espresso_event_date_obj' )) {
415
+if ( ! function_exists('espresso_event_date_obj')) {
416 416
 	/**
417 417
 	 * espresso_event_date_obj
418 418
 	 * returns the primary date object for an event
@@ -420,13 +420,13 @@  discard block
 block discarded – undo
420 420
 	 * @param bool $EVT_ID
421 421
 	 * @return object
422 422
 	 */
423
-	function espresso_event_date_obj( $EVT_ID = FALSE ) {
424
-		return EEH_Event_View::get_primary_date_obj( $EVT_ID );
423
+	function espresso_event_date_obj($EVT_ID = FALSE) {
424
+		return EEH_Event_View::get_primary_date_obj($EVT_ID);
425 425
 	}
426 426
 }
427 427
 
428 428
 
429
-if ( ! function_exists( 'espresso_event_date' )) {
429
+if ( ! function_exists('espresso_event_date')) {
430 430
 	/**
431 431
 	 * espresso_event_date
432 432
 	 * returns the primary date for an event
@@ -437,22 +437,22 @@  discard block
 block discarded – undo
437 437
 	 * @param bool $echo
438 438
 	 * @return string
439 439
 	 */
440
-	function espresso_event_date( $date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE ) {
441
-		$date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' );
442
-		$time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' );
443
-		$date_format = apply_filters( 'FHEE__espresso_event_date__date_format', $date_format );
444
-		$time_format = apply_filters( 'FHEE__espresso_event_date__time_format', $time_format );
445
-		if($echo){
446
-			echo EEH_Event_View::the_event_date( $date_format, $time_format, $EVT_ID );
440
+	function espresso_event_date($date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE) {
441
+		$date_format = ! empty($date_format) ? $date_format : get_option('date_format');
442
+		$time_format = ! empty($time_format) ? $time_format : get_option('time_format');
443
+		$date_format = apply_filters('FHEE__espresso_event_date__date_format', $date_format);
444
+		$time_format = apply_filters('FHEE__espresso_event_date__time_format', $time_format);
445
+		if ($echo) {
446
+			echo EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID);
447 447
 			return '';
448 448
 		}
449
-		return EEH_Event_View::the_event_date( $date_format, $time_format, $EVT_ID );
449
+		return EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID);
450 450
 
451 451
 	}
452 452
 }
453 453
 
454 454
 
455
-if ( ! function_exists( 'espresso_list_of_event_dates' )) {
455
+if ( ! function_exists('espresso_list_of_event_dates')) {
456 456
 	/**
457 457
 	 * espresso_list_of_event_dates
458 458
 	 * returns a unordered list of dates for an event
@@ -467,40 +467,40 @@  discard block
 block discarded – undo
467 467
 	 * @param null   $limit
468 468
 	 * @return string
469 469
 	 */
470
-	function espresso_list_of_event_dates( $EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL ) {
471
-		$date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' );
472
-		$time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' );
473
-		$date_format = apply_filters( 'FHEE__espresso_list_of_event_dates__date_format', $date_format );
474
-		$time_format = apply_filters( 'FHEE__espresso_list_of_event_dates__time_format', $time_format );
475
-		$datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, $show_expired, FALSE, $limit );
476
-		if ( ! $format ) {
477
-			return apply_filters( 'FHEE__espresso_list_of_event_dates__datetimes', $datetimes );
470
+	function espresso_list_of_event_dates($EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL) {
471
+		$date_format = ! empty($date_format) ? $date_format : get_option('date_format');
472
+		$time_format = ! empty($time_format) ? $time_format : get_option('time_format');
473
+		$date_format = apply_filters('FHEE__espresso_list_of_event_dates__date_format', $date_format);
474
+		$time_format = apply_filters('FHEE__espresso_list_of_event_dates__time_format', $time_format);
475
+		$datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, $show_expired, FALSE, $limit);
476
+		if ( ! $format) {
477
+			return apply_filters('FHEE__espresso_list_of_event_dates__datetimes', $datetimes);
478 478
 		}
479 479
 		//d( $datetimes );
480
-		if ( is_array( $datetimes ) && ! empty( $datetimes )) {
480
+		if (is_array($datetimes) && ! empty($datetimes)) {
481 481
 			global $post;
482
-			$html = $format ? '<ul id="ee-event-datetimes-ul-' . $post->ID . '" class="ee-event-datetimes-ul ee-clearfix">' : '';
483
-			foreach ( $datetimes as $datetime ) {
484
-				if ( $datetime instanceof EE_Datetime ) {
485
-					$html .= '<li id="ee-event-datetimes-li-' . $datetime->ID();
486
-					$html .= '" class="ee-event-datetimes-li ee-event-datetimes-li-' . $datetime->get_active_status() . '">';
482
+			$html = $format ? '<ul id="ee-event-datetimes-ul-'.$post->ID.'" class="ee-event-datetimes-ul ee-clearfix">' : '';
483
+			foreach ($datetimes as $datetime) {
484
+				if ($datetime instanceof EE_Datetime) {
485
+					$html .= '<li id="ee-event-datetimes-li-'.$datetime->ID();
486
+					$html .= '" class="ee-event-datetimes-li ee-event-datetimes-li-'.$datetime->get_active_status().'">';
487 487
 					$datetime_name = $datetime->name();
488
-					$html .= ! empty( $datetime_name ) ? '<strong>' . $datetime_name . '</strong>' : '';
489
-					$html .= ! empty( $datetime_name )  && $add_breaks ? '<br />' : '';
490
-					$html .= '<span class="dashicons dashicons-calendar"></span>' . $datetime->date_range( $date_format ) . '<br/>';
491
-					$html .= '<span class="dashicons dashicons-clock"></span>' . $datetime->time_range( $time_format );
488
+					$html .= ! empty($datetime_name) ? '<strong>'.$datetime_name.'</strong>' : '';
489
+					$html .= ! empty($datetime_name) && $add_breaks ? '<br />' : '';
490
+					$html .= '<span class="dashicons dashicons-calendar"></span>'.$datetime->date_range($date_format).'<br/>';
491
+					$html .= '<span class="dashicons dashicons-clock"></span>'.$datetime->time_range($time_format);
492 492
 					$datetime_description = $datetime->description();
493
-					$html .= ! empty( $datetime_description )  && $add_breaks ? '<br />' : '';
494
-					$html .= ! empty( $datetime_description ) ? ' - ' . $datetime_description : '';
495
-					$html = apply_filters( 'FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime );
493
+					$html .= ! empty($datetime_description) && $add_breaks ? '<br />' : '';
494
+					$html .= ! empty($datetime_description) ? ' - '.$datetime_description : '';
495
+					$html = apply_filters('FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime);
496 496
 					$html .= '</li>';
497 497
 				}
498 498
 			}
499 499
 			$html .= $format ? '</ul>' : '';
500 500
 		} else {
501
-			$html = $format ?  '<p><span class="dashicons dashicons-marker pink-text"></span>' . __( 'There are no upcoming dates for this event.', 'event_espresso' ) . '</p><br/>' : '';
501
+			$html = $format ? '<p><span class="dashicons dashicons-marker pink-text"></span>'.__('There are no upcoming dates for this event.', 'event_espresso').'</p><br/>' : '';
502 502
 		}
503
-		if ( $echo ) {
503
+		if ($echo) {
504 504
 			echo $html;
505 505
 			return '';
506 506
 		}
@@ -509,7 +509,7 @@  discard block
 block discarded – undo
509 509
 }
510 510
 
511 511
 
512
-if ( ! function_exists( 'espresso_event_end_date' )) {
512
+if ( ! function_exists('espresso_event_end_date')) {
513 513
 	/**
514 514
 	 * espresso_event_end_date
515 515
 	 * returns the last date for an event
@@ -520,20 +520,20 @@  discard block
 block discarded – undo
520 520
 	 * @param bool   $echo
521 521
 	 * @return string
522 522
 	 */
523
-	function espresso_event_end_date( $date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE ) {
524
-		$date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' );
525
-		$time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' );
526
-		$date_format = apply_filters( 'FHEE__espresso_event_end_date__date_format', $date_format );
527
-		$time_format = apply_filters( 'FHEE__espresso_event_end_date__time_format', $time_format );
528
-		if($echo){
529
-			echo EEH_Event_View::the_event_end_date( $date_format, $time_format, $EVT_ID );
523
+	function espresso_event_end_date($date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE) {
524
+		$date_format = ! empty($date_format) ? $date_format : get_option('date_format');
525
+		$time_format = ! empty($time_format) ? $time_format : get_option('time_format');
526
+		$date_format = apply_filters('FHEE__espresso_event_end_date__date_format', $date_format);
527
+		$time_format = apply_filters('FHEE__espresso_event_end_date__time_format', $time_format);
528
+		if ($echo) {
529
+			echo EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID);
530 530
 			return '';
531 531
 		}
532
-		return EEH_Event_View::the_event_end_date( $date_format, $time_format, $EVT_ID );
532
+		return EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID);
533 533
 	}
534 534
 }
535 535
 
536
-if ( ! function_exists( 'espresso_event_date_range' )) {
536
+if ( ! function_exists('espresso_event_date_range')) {
537 537
 	/**
538 538
 	 * espresso_event_date_range
539 539
 	 * returns the first and last chronologically ordered dates for an event (if different)
@@ -546,31 +546,31 @@  discard block
 block discarded – undo
546 546
 	 * @param bool   $echo
547 547
 	 * @return string
548 548
 	 */
549
-	function espresso_event_date_range( $date_format = '', $time_format = '', $single_date_format = '', $single_time_format = '', $EVT_ID = FALSE, $echo = TRUE ) {
549
+	function espresso_event_date_range($date_format = '', $time_format = '', $single_date_format = '', $single_time_format = '', $EVT_ID = FALSE, $echo = TRUE) {
550 550
 		// set and filter date and time formats when a range is returned
551
-		$date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' );
552
-		$date_format = apply_filters( 'FHEE__espresso_event_date_range__date_format', $date_format );
551
+		$date_format = ! empty($date_format) ? $date_format : get_option('date_format');
552
+		$date_format = apply_filters('FHEE__espresso_event_date_range__date_format', $date_format);
553 553
 		// get the start and end date with NO time portion
554
-		$the_event_date = EEH_Event_View::the_earliest_event_date( $date_format, '', $EVT_ID );
555
-		$the_event_end_date = EEH_Event_View::the_latest_event_date( $date_format, '', $EVT_ID );
554
+		$the_event_date = EEH_Event_View::the_earliest_event_date($date_format, '', $EVT_ID);
555
+		$the_event_end_date = EEH_Event_View::the_latest_event_date($date_format, '', $EVT_ID);
556 556
 		// now we can determine if date range spans more than one day
557
-		if ( $the_event_date != $the_event_end_date ) {
558
-			$time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' );
559
-			$time_format = apply_filters( 'FHEE__espresso_event_date_range__time_format', $time_format );
557
+		if ($the_event_date != $the_event_end_date) {
558
+			$time_format = ! empty($time_format) ? $time_format : get_option('time_format');
559
+			$time_format = apply_filters('FHEE__espresso_event_date_range__time_format', $time_format);
560 560
 			$html = sprintf(
561
-				__( '%1$s - %2$s', 'event_espresso' ),
562
-				EEH_Event_View::the_earliest_event_date( $date_format, $time_format, $EVT_ID ),
563
-				EEH_Event_View::the_latest_event_date( $date_format, $time_format, $EVT_ID )
561
+				__('%1$s - %2$s', 'event_espresso'),
562
+				EEH_Event_View::the_earliest_event_date($date_format, $time_format, $EVT_ID),
563
+				EEH_Event_View::the_latest_event_date($date_format, $time_format, $EVT_ID)
564 564
 			);
565 565
 		} else {
566 566
 			// set and filter date and time formats when only a single datetime is returned
567
-			$single_date_format = ! empty( $single_date_format ) ? $single_date_format : get_option( 'date_format' );
568
-			$single_time_format = ! empty( $single_time_format ) ? $single_time_format : get_option( 'time_format' );
569
-			$single_date_format = apply_filters( 'FHEE__espresso_event_date_range__single_date_format', $single_date_format );
570
-			$single_time_format = apply_filters( 'FHEE__espresso_event_date_range__single_time_format', $single_time_format );
571
-			$html = EEH_Event_View::the_earliest_event_date( $single_date_format, $single_time_format, $EVT_ID );
567
+			$single_date_format = ! empty($single_date_format) ? $single_date_format : get_option('date_format');
568
+			$single_time_format = ! empty($single_time_format) ? $single_time_format : get_option('time_format');
569
+			$single_date_format = apply_filters('FHEE__espresso_event_date_range__single_date_format', $single_date_format);
570
+			$single_time_format = apply_filters('FHEE__espresso_event_date_range__single_time_format', $single_time_format);
571
+			$html = EEH_Event_View::the_earliest_event_date($single_date_format, $single_time_format, $EVT_ID);
572 572
 		}
573
-		if ( $echo ) {
573
+		if ($echo) {
574 574
 			echo $html;
575 575
 			return '';
576 576
 		}
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
 }
580 580
 
581 581
 
582
-if ( ! function_exists( 'espresso_event_date_as_calendar_page' )) {
582
+if ( ! function_exists('espresso_event_date_as_calendar_page')) {
583 583
 	/**
584 584
 	 * espresso_event_date_as_calendar_page
585 585
 	 * returns the primary date for an event, stylized to appear as the page of a calendar
@@ -587,15 +587,15 @@  discard block
 block discarded – undo
587 587
 	 * @param bool $EVT_ID
588 588
 	 * @return string
589 589
 	 */
590
-	function espresso_event_date_as_calendar_page( $EVT_ID = FALSE ) {
591
-		EEH_Event_View::event_date_as_calendar_page( $EVT_ID );
590
+	function espresso_event_date_as_calendar_page($EVT_ID = FALSE) {
591
+		EEH_Event_View::event_date_as_calendar_page($EVT_ID);
592 592
 	}
593 593
 }
594 594
 
595 595
 
596 596
 
597 597
 
598
-if ( ! function_exists( 'espresso_event_link_url' )) {
598
+if ( ! function_exists('espresso_event_link_url')) {
599 599
 	/**
600 600
 	 * espresso_event_link_url
601 601
 	 *
@@ -603,18 +603,18 @@  discard block
 block discarded – undo
603 603
 	 * @param bool $echo
604 604
 	 * @return string
605 605
 	 */
606
-	function espresso_event_link_url( $EVT_ID = 0, $echo = TRUE ) {
607
-		if ( $echo ) {
608
-			echo EEH_Event_View::event_link_url( $EVT_ID );
606
+	function espresso_event_link_url($EVT_ID = 0, $echo = TRUE) {
607
+		if ($echo) {
608
+			echo EEH_Event_View::event_link_url($EVT_ID);
609 609
 			return '';
610 610
 		}
611
-		return EEH_Event_View::event_link_url( $EVT_ID );
611
+		return EEH_Event_View::event_link_url($EVT_ID);
612 612
 	}
613 613
 }
614 614
 
615 615
 
616 616
 
617
-if ( ! function_exists( 'espresso_event_has_content_or_excerpt' )) {
617
+if ( ! function_exists('espresso_event_has_content_or_excerpt')) {
618 618
 	/**
619 619
 	 *    espresso_event_has_content_or_excerpt
620 620
 	 *
@@ -622,15 +622,15 @@  discard block
 block discarded – undo
622 622
 	 * @param bool $EVT_ID
623 623
 	 * @return    boolean
624 624
 	 */
625
-	function espresso_event_has_content_or_excerpt( $EVT_ID = FALSE ) {
626
-		return EEH_Event_View::event_has_content_or_excerpt( $EVT_ID );
625
+	function espresso_event_has_content_or_excerpt($EVT_ID = FALSE) {
626
+		return EEH_Event_View::event_has_content_or_excerpt($EVT_ID);
627 627
 	}
628 628
 }
629 629
 
630 630
 
631 631
 
632 632
 
633
-if ( ! function_exists( 'espresso_event_content_or_excerpt' )) {
633
+if ( ! function_exists('espresso_event_content_or_excerpt')) {
634 634
 	/**
635 635
 	 * espresso_event_content_or_excerpt
636 636
 	 *
@@ -639,18 +639,18 @@  discard block
 block discarded – undo
639 639
 	 * @param bool $echo
640 640
 	 * @return string
641 641
 	 */
642
-	function espresso_event_content_or_excerpt( $num_words = 55, $more = NULL, $echo = TRUE ) {
643
-		if ( $echo ) {
644
-			echo EEH_Event_View::event_content_or_excerpt( $num_words, $more );
642
+	function espresso_event_content_or_excerpt($num_words = 55, $more = NULL, $echo = TRUE) {
643
+		if ($echo) {
644
+			echo EEH_Event_View::event_content_or_excerpt($num_words, $more);
645 645
 			return '';
646 646
 		}
647
-		return EEH_Event_View::event_content_or_excerpt( $num_words, $more );
647
+		return EEH_Event_View::event_content_or_excerpt($num_words, $more);
648 648
 	}
649 649
 }
650 650
 
651 651
 
652 652
 
653
-if ( ! function_exists( 'espresso_event_phone' )) {
653
+if ( ! function_exists('espresso_event_phone')) {
654 654
 	/**
655 655
 	 * espresso_event_phone
656 656
 	 *
@@ -658,18 +658,18 @@  discard block
 block discarded – undo
658 658
 	 * @param bool $echo
659 659
 	 * @return string
660 660
 	 */
661
-	function espresso_event_phone( $EVT_ID = 0, $echo = TRUE ) {
662
-		if ( $echo ) {
663
-			echo EEH_Event_View::event_phone( $EVT_ID );
661
+	function espresso_event_phone($EVT_ID = 0, $echo = TRUE) {
662
+		if ($echo) {
663
+			echo EEH_Event_View::event_phone($EVT_ID);
664 664
 			return '';
665 665
 		}
666
-		return EEH_Event_View::event_phone( $EVT_ID );
666
+		return EEH_Event_View::event_phone($EVT_ID);
667 667
 	}
668 668
 }
669 669
 
670 670
 
671 671
 
672
-if ( ! function_exists( 'espresso_edit_event_link' )) {
672
+if ( ! function_exists('espresso_edit_event_link')) {
673 673
 	/**
674 674
 	 * espresso_edit_event_link
675 675
 	 * returns a link to edit an event
@@ -678,39 +678,39 @@  discard block
 block discarded – undo
678 678
 	 * @param bool $echo
679 679
 	 * @return string
680 680
 	 */
681
-	function espresso_edit_event_link( $EVT_ID = 0, $echo = TRUE ) {
682
-		if ( $echo ) {
683
-			echo EEH_Event_View::edit_event_link( $EVT_ID );
681
+	function espresso_edit_event_link($EVT_ID = 0, $echo = TRUE) {
682
+		if ($echo) {
683
+			echo EEH_Event_View::edit_event_link($EVT_ID);
684 684
 			return '';
685 685
 		}
686
-		return EEH_Event_View::edit_event_link( $EVT_ID );
686
+		return EEH_Event_View::edit_event_link($EVT_ID);
687 687
 	}
688 688
 }
689 689
 
690 690
 
691
-if ( ! function_exists( 'espresso_organization_name' )) {
691
+if ( ! function_exists('espresso_organization_name')) {
692 692
 	/**
693 693
 	 * espresso_organization_name
694 694
 	 * @param bool $echo
695 695
 	 * @return string
696 696
 	 */
697 697
 	function espresso_organization_name($echo = TRUE) {
698
-		if($echo){
699
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'name' );
698
+		if ($echo) {
699
+			echo EE_Registry::instance()->CFG->organization->get_pretty('name');
700 700
 			return '';
701 701
 		}
702
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'name' );
702
+		return EE_Registry::instance()->CFG->organization->get_pretty('name');
703 703
 	}
704 704
 }
705 705
 
706
-if ( ! function_exists( 'espresso_organization_address' )) {
706
+if ( ! function_exists('espresso_organization_address')) {
707 707
 	/**
708 708
 	 * espresso_organization_address
709 709
 	 * @param string $type
710 710
 	 * @return string
711 711
 	 */
712
-	function espresso_organization_address( $type = 'inline' ) {
713
-		if ( EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config ) {
712
+	function espresso_organization_address($type = 'inline') {
713
+		if (EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config) {
714 714
 			$address = new EventEspresso\core\domain\entities\GenericAddress(
715 715
 				EE_Registry::instance()->CFG->organization->address_1,
716 716
 				EE_Registry::instance()->CFG->organization->address_2,
@@ -719,129 +719,129 @@  discard block
 block discarded – undo
719 719
 				EE_Registry::instance()->CFG->organization->zip,
720 720
 				EE_Registry::instance()->CFG->organization->CNT_ISO
721 721
 			);
722
-			return EEH_Address::format( $address, $type );
722
+			return EEH_Address::format($address, $type);
723 723
 		}
724 724
 		return '';
725 725
 	}
726 726
 }
727 727
 
728
-if ( ! function_exists( 'espresso_organization_email' )) {
728
+if ( ! function_exists('espresso_organization_email')) {
729 729
 	/**
730 730
 	 * espresso_organization_email
731 731
 	 * @param bool $echo
732 732
 	 * @return string
733 733
 	 */
734
-	function espresso_organization_email( $echo = TRUE ) {
735
-		if($echo){
736
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'email' );
734
+	function espresso_organization_email($echo = TRUE) {
735
+		if ($echo) {
736
+			echo EE_Registry::instance()->CFG->organization->get_pretty('email');
737 737
 			return '';
738 738
 		}
739
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'email' );
739
+		return EE_Registry::instance()->CFG->organization->get_pretty('email');
740 740
 	}
741 741
 }
742 742
 
743
-if ( ! function_exists( 'espresso_organization_logo_url' )) {
743
+if ( ! function_exists('espresso_organization_logo_url')) {
744 744
 	/**
745 745
 	 * espresso_organization_logo_url
746 746
 	 * @param bool $echo
747 747
 	 * @return string
748 748
 	 */
749
-	function espresso_organization_logo_url( $echo = TRUE ) {
750
-		if($echo){
751
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'logo_url' );
749
+	function espresso_organization_logo_url($echo = TRUE) {
750
+		if ($echo) {
751
+			echo EE_Registry::instance()->CFG->organization->get_pretty('logo_url');
752 752
 			return '';
753 753
 		}
754
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'logo_url' );
754
+		return EE_Registry::instance()->CFG->organization->get_pretty('logo_url');
755 755
 	}
756 756
 }
757 757
 
758
-if ( ! function_exists( 'espresso_organization_facebook' )) {
758
+if ( ! function_exists('espresso_organization_facebook')) {
759 759
 	/**
760 760
 	 * espresso_organization_facebook
761 761
 	 * @param bool $echo
762 762
 	 * @return string
763 763
 	 */
764
-	function espresso_organization_facebook( $echo = TRUE ) {
765
-		if($echo){
766
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'facebook' );
764
+	function espresso_organization_facebook($echo = TRUE) {
765
+		if ($echo) {
766
+			echo EE_Registry::instance()->CFG->organization->get_pretty('facebook');
767 767
 			return '';
768 768
 		}
769
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'facebook' );
769
+		return EE_Registry::instance()->CFG->organization->get_pretty('facebook');
770 770
 	}
771 771
 }
772 772
 
773
-if ( ! function_exists( 'espresso_organization_twitter' )) {
773
+if ( ! function_exists('espresso_organization_twitter')) {
774 774
 	/**
775 775
 	 * espresso_organization_twitter
776 776
 	 * @param bool $echo
777 777
 	 * @return string
778 778
 	 */
779
-	function espresso_organization_twitter( $echo = TRUE ) {
780
-		if($echo){
781
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'twitter' );
779
+	function espresso_organization_twitter($echo = TRUE) {
780
+		if ($echo) {
781
+			echo EE_Registry::instance()->CFG->organization->get_pretty('twitter');
782 782
 			return '';
783 783
 		}
784
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'twitter' );
784
+		return EE_Registry::instance()->CFG->organization->get_pretty('twitter');
785 785
 	}
786 786
 }
787 787
 
788
-if ( ! function_exists( 'espresso_organization_linkedin' )) {
788
+if ( ! function_exists('espresso_organization_linkedin')) {
789 789
 	/**
790 790
 	 * espresso_organization_linkedin
791 791
 	 * @param bool $echo
792 792
 	 * @return string
793 793
 	 */
794
-	function espresso_organization_linkedin( $echo = TRUE ) {
795
-		if($echo){
796
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'linkedin' );
794
+	function espresso_organization_linkedin($echo = TRUE) {
795
+		if ($echo) {
796
+			echo EE_Registry::instance()->CFG->organization->get_pretty('linkedin');
797 797
 			return '';
798 798
 		}
799
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'linkedin' );
799
+		return EE_Registry::instance()->CFG->organization->get_pretty('linkedin');
800 800
 	}
801 801
 }
802 802
 
803
-if ( ! function_exists( 'espresso_organization_pinterest' )) {
803
+if ( ! function_exists('espresso_organization_pinterest')) {
804 804
 	/**
805 805
 	 * espresso_organization_pinterest
806 806
 	 * @param bool $echo
807 807
 	 * @return string
808 808
 	 */
809
-	function espresso_organization_pinterest( $echo = TRUE ) {
810
-		if($echo){
811
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'pinterest' );
809
+	function espresso_organization_pinterest($echo = TRUE) {
810
+		if ($echo) {
811
+			echo EE_Registry::instance()->CFG->organization->get_pretty('pinterest');
812 812
 			return '';
813 813
 		}
814
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'pinterest' );
814
+		return EE_Registry::instance()->CFG->organization->get_pretty('pinterest');
815 815
 	}
816 816
 }
817 817
 
818
-if ( ! function_exists( 'espresso_organization_google' )) {
818
+if ( ! function_exists('espresso_organization_google')) {
819 819
 	/**
820 820
 	 * espresso_organization_google
821 821
 	 * @param bool $echo
822 822
 	 * @return string
823 823
 	 */
824
-	function espresso_organization_google( $echo = TRUE ) {
825
-		if($echo){
826
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'google' );
824
+	function espresso_organization_google($echo = TRUE) {
825
+		if ($echo) {
826
+			echo EE_Registry::instance()->CFG->organization->get_pretty('google');
827 827
 			return '';
828 828
 		}
829
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'google' );
829
+		return EE_Registry::instance()->CFG->organization->get_pretty('google');
830 830
 	}
831 831
 }
832 832
 
833
-if ( ! function_exists( 'espresso_organization_instagram' )) {
833
+if ( ! function_exists('espresso_organization_instagram')) {
834 834
 	/**
835 835
 	 * espresso_organization_instagram
836 836
 	 * @param bool $echo
837 837
 	 * @return string
838 838
 	 */
839
-	function espresso_organization_instagram( $echo = TRUE ) {
840
-		if($echo){
841
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'instagram' );
839
+	function espresso_organization_instagram($echo = TRUE) {
840
+		if ($echo) {
841
+			echo EE_Registry::instance()->CFG->organization->get_pretty('instagram');
842 842
 			return '';
843 843
 		}
844
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'instagram' );
844
+		return EE_Registry::instance()->CFG->organization->get_pretty('instagram');
845 845
 	}
846 846
 }
847 847
 
@@ -851,7 +851,7 @@  discard block
 block discarded – undo
851 851
 
852 852
 
853 853
 
854
-if ( ! function_exists( 'espresso_event_venues' )) {
854
+if ( ! function_exists('espresso_event_venues')) {
855 855
 	/**
856 856
 	 * espresso_event_venues
857 857
 	 *
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
 
866 866
 
867 867
 
868
-if ( ! function_exists( 'espresso_venue_id' )) {
868
+if ( ! function_exists('espresso_venue_id')) {
869 869
 	/**
870 870
 	 *    espresso_venue_name
871 871
 	 *
@@ -873,15 +873,15 @@  discard block
 block discarded – undo
873 873
 	 * @param     int $EVT_ID
874 874
 	 * @return    string
875 875
 	 */
876
-	function espresso_venue_id( $EVT_ID = 0 ) {
877
-		$venue = EEH_Venue_View::get_venue( $EVT_ID );
876
+	function espresso_venue_id($EVT_ID = 0) {
877
+		$venue = EEH_Venue_View::get_venue($EVT_ID);
878 878
 		return $venue instanceof EE_Venue ? $venue->ID() : 0;
879 879
 	}
880 880
 }
881 881
 
882 882
 
883 883
 
884
-if ( ! function_exists( 'espresso_is_venue_private' ) ) {
884
+if ( ! function_exists('espresso_is_venue_private')) {
885 885
 	/**
886 886
 	 * Return whether a venue is private or not.
887 887
 	 * @see EEH_Venue_View::get_venue() for more info on expected return results.
@@ -890,45 +890,45 @@  discard block
 block discarded – undo
890 890
 	 *
891 891
 	 * @return bool | null
892 892
 	 */
893
-	function espresso_is_venue_private( $VNU_ID = 0 ) {
894
-		return EEH_Venue_View::is_venue_private( $VNU_ID );
893
+	function espresso_is_venue_private($VNU_ID = 0) {
894
+		return EEH_Venue_View::is_venue_private($VNU_ID);
895 895
 	}
896 896
 }
897 897
 
898 898
 
899 899
 
900
-if ( ! function_exists( 'espresso_venue_is_password_protected' ) ) {
900
+if ( ! function_exists('espresso_venue_is_password_protected')) {
901 901
 	/**
902 902
 	 * returns true or false if a venue is password protected or not
903 903
 	 *
904 904
 	 * @param int     $VNU_ID optional, the venue id to check.
905 905
 	 * @return string
906 906
 	 */
907
-	function espresso_venue_is_password_protected( $VNU_ID = 0 ) {
908
-		EE_Registry::instance()->load_helper( 'Venue_View' );
909
-		return EEH_Venue_View::is_venue_password_protected( $VNU_ID );
907
+	function espresso_venue_is_password_protected($VNU_ID = 0) {
908
+		EE_Registry::instance()->load_helper('Venue_View');
909
+		return EEH_Venue_View::is_venue_password_protected($VNU_ID);
910 910
 	}
911 911
 }
912 912
 
913 913
 
914 914
 
915
-if ( ! function_exists( 'espresso_password_protected_venue_form' ) ) {
915
+if ( ! function_exists('espresso_password_protected_venue_form')) {
916 916
 	/**
917 917
 	 * Returns a password form if venue is password protected.
918 918
 	 *
919 919
 	 * @param int     $VNU_ID optional, the venue id to check.
920 920
 	 * @return string
921 921
 	 */
922
-	function espresso_password_protected_venue_form( $VNU_ID = 0 ) {
923
-		EE_Registry::instance()->load_helper( 'Venue_View' );
924
-		return EEH_Venue_View::password_protected_venue_form( $VNU_ID );
922
+	function espresso_password_protected_venue_form($VNU_ID = 0) {
923
+		EE_Registry::instance()->load_helper('Venue_View');
924
+		return EEH_Venue_View::password_protected_venue_form($VNU_ID);
925 925
 	}
926 926
 }
927 927
 
928 928
 
929 929
 
930 930
 
931
-if ( ! function_exists( 'espresso_venue_name' )) {
931
+if ( ! function_exists('espresso_venue_name')) {
932 932
 	/**
933 933
 	 *    espresso_venue_name
934 934
 	 *
@@ -938,19 +938,19 @@  discard block
 block discarded – undo
938 938
 	 * @param bool   $echo
939 939
 	 * @return    string
940 940
 	 */
941
-	function espresso_venue_name( $VNU_ID = 0, $link_to = 'details', $echo = TRUE ) {
942
-		if($echo){
943
-			echo EEH_Venue_View::venue_name( $link_to, $VNU_ID );
941
+	function espresso_venue_name($VNU_ID = 0, $link_to = 'details', $echo = TRUE) {
942
+		if ($echo) {
943
+			echo EEH_Venue_View::venue_name($link_to, $VNU_ID);
944 944
 			return '';
945 945
 		}
946
-		return EEH_Venue_View::venue_name( $link_to, $VNU_ID );
946
+		return EEH_Venue_View::venue_name($link_to, $VNU_ID);
947 947
 	}
948 948
 }
949 949
 
950 950
 
951 951
 
952 952
 
953
-if ( ! function_exists( 'espresso_venue_link' )) {
953
+if ( ! function_exists('espresso_venue_link')) {
954 954
 	/**
955 955
 	 * 	espresso_venue_link
956 956
 	 *
@@ -959,14 +959,14 @@  discard block
 block discarded – undo
959 959
 	 *  @param 	string 	$text
960 960
 	 *  @return 	string
961 961
 	 */
962
-	function espresso_venue_link( $VNU_ID = 0, $text = '' ) {
963
-		return EEH_Venue_View::venue_details_link( $VNU_ID, $text );
962
+	function espresso_venue_link($VNU_ID = 0, $text = '') {
963
+		return EEH_Venue_View::venue_details_link($VNU_ID, $text);
964 964
 	}
965 965
 }
966 966
 
967 967
 
968 968
 
969
-if ( ! function_exists( 'espresso_venue_description' )) {
969
+if ( ! function_exists('espresso_venue_description')) {
970 970
 	/**
971 971
 	 *    espresso_venue_description
972 972
 	 *
@@ -975,17 +975,17 @@  discard block
 block discarded – undo
975 975
 	 * @param bool $echo
976 976
 	 * @return    string
977 977
 	 */
978
-	function espresso_venue_description( $VNU_ID = FALSE, $echo = TRUE ) {
979
-		if($echo){
980
-			echo EEH_Venue_View::venue_description( $VNU_ID );
978
+	function espresso_venue_description($VNU_ID = FALSE, $echo = TRUE) {
979
+		if ($echo) {
980
+			echo EEH_Venue_View::venue_description($VNU_ID);
981 981
 			return '';
982 982
 		}
983
-		return EEH_Venue_View::venue_description( $VNU_ID );
983
+		return EEH_Venue_View::venue_description($VNU_ID);
984 984
 	}
985 985
 }
986 986
 
987 987
 
988
-if ( ! function_exists( 'espresso_venue_excerpt' )) {
988
+if ( ! function_exists('espresso_venue_excerpt')) {
989 989
 	/**
990 990
 	 *    espresso_venue_excerpt
991 991
 	 *
@@ -994,18 +994,18 @@  discard block
 block discarded – undo
994 994
 	 * @param bool $echo
995 995
 	 * @return    string
996 996
 	 */
997
-	function espresso_venue_excerpt( $VNU_ID = 0,  $echo = TRUE ) {
998
-		if ( $echo ) {
999
-			echo EEH_Venue_View::venue_excerpt( $VNU_ID );
997
+	function espresso_venue_excerpt($VNU_ID = 0, $echo = TRUE) {
998
+		if ($echo) {
999
+			echo EEH_Venue_View::venue_excerpt($VNU_ID);
1000 1000
 			return '';
1001 1001
 		}
1002
-		return EEH_Venue_View::venue_excerpt( $VNU_ID );
1002
+		return EEH_Venue_View::venue_excerpt($VNU_ID);
1003 1003
 	}
1004 1004
 }
1005 1005
 
1006 1006
 
1007 1007
 
1008
-if ( ! function_exists( 'espresso_venue_categories' )) {
1008
+if ( ! function_exists('espresso_venue_categories')) {
1009 1009
 	/**
1010 1010
 	 * espresso_venue_categories
1011 1011
 	 * returns the terms associated with a venue
@@ -1015,17 +1015,17 @@  discard block
 block discarded – undo
1015 1015
 	 * @param bool $echo
1016 1016
 	 * @return string
1017 1017
 	 */
1018
-	function espresso_venue_categories( $VNU_ID = 0, $hide_uncategorized = TRUE,  $echo = TRUE ) {
1019
-		if ( $echo ) {
1020
-			echo EEH_Venue_View::venue_categories( $VNU_ID, $hide_uncategorized );
1018
+	function espresso_venue_categories($VNU_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE) {
1019
+		if ($echo) {
1020
+			echo EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized);
1021 1021
 			return '';
1022 1022
 		}
1023
-		return EEH_Venue_View::venue_categories( $VNU_ID, $hide_uncategorized );
1023
+		return EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized);
1024 1024
 	}
1025 1025
 }
1026 1026
 
1027 1027
 
1028
-if ( ! function_exists( 'espresso_venue_address' )) {
1028
+if ( ! function_exists('espresso_venue_address')) {
1029 1029
 	/**
1030 1030
 	 * espresso_venue_address
1031 1031
 	 * returns a formatted block of html  for displaying a venue's address
@@ -1035,17 +1035,17 @@  discard block
 block discarded – undo
1035 1035
 	 * @param bool   $echo
1036 1036
 	 * @return string
1037 1037
 	 */
1038
-	function espresso_venue_address( $type = 'multiline', $VNU_ID = 0, $echo = TRUE ) {
1039
-		if ( $echo ) {
1040
-			echo EEH_Venue_View::venue_address( $type, $VNU_ID );
1038
+	function espresso_venue_address($type = 'multiline', $VNU_ID = 0, $echo = TRUE) {
1039
+		if ($echo) {
1040
+			echo EEH_Venue_View::venue_address($type, $VNU_ID);
1041 1041
 			return '';
1042 1042
 		}
1043
-		return EEH_Venue_View::venue_address( $type, $VNU_ID );
1043
+		return EEH_Venue_View::venue_address($type, $VNU_ID);
1044 1044
 	}
1045 1045
 }
1046 1046
 
1047 1047
 
1048
-if ( ! function_exists( 'espresso_venue_raw_address' )) {
1048
+if ( ! function_exists('espresso_venue_raw_address')) {
1049 1049
 	/**
1050 1050
 	 * espresso_venue_address
1051 1051
 	 * returns an UN-formatted string containing a venue's address
@@ -1055,17 +1055,17 @@  discard block
 block discarded – undo
1055 1055
 	 * @param bool     $echo
1056 1056
 	 * @return string
1057 1057
 	 */
1058
-	function espresso_venue_raw_address( $type = 'multiline', $VNU_ID = 0, $echo = TRUE ) {
1059
-		if ( $echo ) {
1060
-			echo EEH_Venue_View::venue_address( $type, $VNU_ID, FALSE, FALSE );
1058
+	function espresso_venue_raw_address($type = 'multiline', $VNU_ID = 0, $echo = TRUE) {
1059
+		if ($echo) {
1060
+			echo EEH_Venue_View::venue_address($type, $VNU_ID, FALSE, FALSE);
1061 1061
 			return '';
1062 1062
 		}
1063
-		return EEH_Venue_View::venue_address( $type, $VNU_ID, FALSE, FALSE );
1063
+		return EEH_Venue_View::venue_address($type, $VNU_ID, FALSE, FALSE);
1064 1064
 	}
1065 1065
 }
1066 1066
 
1067 1067
 
1068
-if ( ! function_exists( 'espresso_venue_has_address' )) {
1068
+if ( ! function_exists('espresso_venue_has_address')) {
1069 1069
 	/**
1070 1070
 	 * espresso_venue_has_address
1071 1071
 	 * returns TRUE or FALSE if a Venue has address information
@@ -1073,13 +1073,13 @@  discard block
 block discarded – undo
1073 1073
 	 * @param int $VNU_ID
1074 1074
 	 * @return bool
1075 1075
 	 */
1076
-	function espresso_venue_has_address( $VNU_ID = 0 ) {
1077
-		return EEH_Venue_View::venue_has_address( $VNU_ID );
1076
+	function espresso_venue_has_address($VNU_ID = 0) {
1077
+		return EEH_Venue_View::venue_has_address($VNU_ID);
1078 1078
 	}
1079 1079
 }
1080 1080
 
1081 1081
 
1082
-if ( ! function_exists( 'espresso_venue_gmap' )) {
1082
+if ( ! function_exists('espresso_venue_gmap')) {
1083 1083
 	/**
1084 1084
 	 * espresso_venue_gmap
1085 1085
 	 * returns a google map for the venue address
@@ -1090,17 +1090,17 @@  discard block
 block discarded – undo
1090 1090
 	 * @param bool     $echo
1091 1091
 	 * @return string
1092 1092
 	 */
1093
-	function espresso_venue_gmap( $VNU_ID = 0, $map_ID = FALSE, $gmap = array(), $echo = TRUE  ) {
1094
-		if ( $echo ) {
1095
-			echo EEH_Venue_View::venue_gmap( $VNU_ID, $map_ID, $gmap );
1093
+	function espresso_venue_gmap($VNU_ID = 0, $map_ID = FALSE, $gmap = array(), $echo = TRUE) {
1094
+		if ($echo) {
1095
+			echo EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap);
1096 1096
 			return '';
1097 1097
 		}
1098
-		return EEH_Venue_View::venue_gmap( $VNU_ID, $map_ID, $gmap );
1098
+		return EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap);
1099 1099
 	}
1100 1100
 }
1101 1101
 
1102 1102
 
1103
-if ( ! function_exists( 'espresso_venue_phone' )) {
1103
+if ( ! function_exists('espresso_venue_phone')) {
1104 1104
 	/**
1105 1105
 	 * espresso_venue_phone
1106 1106
 	 *
@@ -1108,18 +1108,18 @@  discard block
 block discarded – undo
1108 1108
 	 * @param bool $echo
1109 1109
 	 * @return string
1110 1110
 	 */
1111
-	function espresso_venue_phone( $VNU_ID = 0, $echo = TRUE ) {
1112
-		if ( $echo ) {
1113
-			echo EEH_Venue_View::venue_phone( $VNU_ID );
1111
+	function espresso_venue_phone($VNU_ID = 0, $echo = TRUE) {
1112
+		if ($echo) {
1113
+			echo EEH_Venue_View::venue_phone($VNU_ID);
1114 1114
 			return '';
1115 1115
 		}
1116
-		return EEH_Venue_View::venue_phone( $VNU_ID );
1116
+		return EEH_Venue_View::venue_phone($VNU_ID);
1117 1117
 	}
1118 1118
 }
1119 1119
 
1120 1120
 
1121 1121
 
1122
-if ( ! function_exists( 'espresso_venue_website' )) {
1122
+if ( ! function_exists('espresso_venue_website')) {
1123 1123
 	/**
1124 1124
 	 * espresso_venue_website
1125 1125
 	 *
@@ -1127,18 +1127,18 @@  discard block
 block discarded – undo
1127 1127
 	 * @param bool $echo
1128 1128
 	 * @return string
1129 1129
 	 */
1130
-	function espresso_venue_website( $VNU_ID = 0, $echo = TRUE ) {
1131
-		if ( $echo ) {
1132
-			echo EEH_Venue_View::venue_website_link( $VNU_ID );
1130
+	function espresso_venue_website($VNU_ID = 0, $echo = TRUE) {
1131
+		if ($echo) {
1132
+			echo EEH_Venue_View::venue_website_link($VNU_ID);
1133 1133
 			return '';
1134 1134
 		}
1135
-		return EEH_Venue_View::venue_website_link( $VNU_ID );
1135
+		return EEH_Venue_View::venue_website_link($VNU_ID);
1136 1136
 	}
1137 1137
 }
1138 1138
 
1139 1139
 
1140 1140
 
1141
-if ( ! function_exists( 'espresso_edit_venue_link' )) {
1141
+if ( ! function_exists('espresso_edit_venue_link')) {
1142 1142
 	/**
1143 1143
 	 * espresso_edit_venue_link
1144 1144
 	 *
@@ -1146,12 +1146,12 @@  discard block
 block discarded – undo
1146 1146
 	 * @param bool $echo
1147 1147
 	 * @return string
1148 1148
 	 */
1149
-	function espresso_edit_venue_link( $VNU_ID = 0, $echo = TRUE ) {
1150
-		if($echo){
1151
-			echo EEH_Venue_View::edit_venue_link( $VNU_ID );
1149
+	function espresso_edit_venue_link($VNU_ID = 0, $echo = TRUE) {
1150
+		if ($echo) {
1151
+			echo EEH_Venue_View::edit_venue_link($VNU_ID);
1152 1152
 			return '';
1153 1153
 		}
1154
-		return EEH_Venue_View::edit_venue_link( $VNU_ID );
1154
+		return EEH_Venue_View::edit_venue_link($VNU_ID);
1155 1155
 	}
1156 1156
 }
1157 1157
 
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 2 patches
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -532,11 +532,11 @@  discard block
 block discarded – undo
532 532
     {
533 533
         wp_register_style(
534 534
             'events-admin-css',
535
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
535
+            EVENTS_ASSETS_URL.'events-admin-page.css',
536 536
             array(),
537 537
             EVENT_ESPRESSO_VERSION
538 538
         );
539
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
539
+        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
540 540
         wp_enqueue_style('events-admin-css');
541 541
         wp_enqueue_style('ee-cat-admin');
542 542
         //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
         //scripts
545 545
         wp_register_script(
546 546
             'event_editor_js',
547
-            EVENTS_ASSETS_URL . 'event_editor.js',
547
+            EVENTS_ASSETS_URL.'event_editor.js',
548 548
             array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
549 549
             EVENT_ESPRESSO_VERSION,
550 550
             true
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
         wp_enqueue_style('espresso-ui-theme');
577 577
         wp_register_style(
578 578
             'event-editor-css',
579
-            EVENTS_ASSETS_URL . 'event-editor.css',
579
+            EVENTS_ASSETS_URL.'event-editor.css',
580 580
             array('ee-admin-css'),
581 581
             EVENT_ESPRESSO_VERSION
582 582
         );
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
         //scripts
585 585
         wp_register_script(
586 586
             'event-datetime-metabox',
587
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
587
+            EVENTS_ASSETS_URL.'event-datetime-metabox.js',
588 588
             array('event_editor_js', 'ee-datepicker'),
589 589
             EVENT_ESPRESSO_VERSION
590 590
         );
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
                         'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.',
751 751
                         'event_espresso'
752 752
                     ),
753
-                    '<a href="' . admin_url('options-general.php') . '">',
753
+                    '<a href="'.admin_url('options-general.php').'">',
754 754
                     '</a>'
755 755
                 ),
756 756
                 __FILE__,
@@ -820,31 +820,31 @@  discard block
 block discarded – undo
820 820
         $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
821 821
         $statuses = array(
822 822
             'sold_out_status'  => array(
823
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
823
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out,
824 824
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
825 825
             ),
826 826
             'active_status'    => array(
827
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
827
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active,
828 828
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
829 829
             ),
830 830
             'upcoming_status'  => array(
831
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
831
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming,
832 832
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
833 833
             ),
834 834
             'postponed_status' => array(
835
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
835
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed,
836 836
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
837 837
             ),
838 838
             'cancelled_status' => array(
839
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
839
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled,
840 840
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
841 841
             ),
842 842
             'expired_status'   => array(
843
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
843
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired,
844 844
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
845 845
             ),
846 846
             'inactive_status'  => array(
847
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
847
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive,
848 848
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
849 849
             ),
850 850
         );
@@ -908,7 +908,7 @@  discard block
 block discarded – undo
908 908
     {
909 909
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
910 910
         $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
911
-            ? (array)$this->_template_args['after_list_table']
911
+            ? (array) $this->_template_args['after_list_table']
912 912
             : array();
913 913
         $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
914 914
                                                                               . EEH_Template::get_button_or_link(
@@ -917,7 +917,7 @@  discard block
 block discarded – undo
917 917
                 'button'
918 918
             );
919 919
         $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
920
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
920
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
921 921
                 'create_new',
922 922
                 'add',
923 923
                 array(),
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
      */
1048 1048
     protected function _default_venue_update(\EE_Event $evtobj, $data)
1049 1049
     {
1050
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1050
+        require_once(EE_MODELS.'EEM_Venue.model.php');
1051 1051
         $venue_model = EE_Registry::instance()->load_model('Venue');
1052 1052
         $rows_affected = null;
1053 1053
         $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
@@ -1171,7 +1171,7 @@  discard block
 block discarded – undo
1171 1171
             if (empty($tkt['TKT_start_date'])) {
1172 1172
                 //let's use now in the set timezone.
1173 1173
                 $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1174
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1174
+                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]);
1175 1175
             }
1176 1176
             if (empty($tkt['TKT_end_date'])) {
1177 1177
                 //use the start date of the first datetime
@@ -1460,7 +1460,7 @@  discard block
 block discarded – undo
1460 1460
         $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1461 1461
         // load template
1462 1462
         EEH_Template::display_template(
1463
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1463
+            EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',
1464 1464
             $publish_box_extra_args
1465 1465
         );
1466 1466
     }
@@ -1587,7 +1587,7 @@  discard block
 block discarded – undo
1587 1587
         );
1588 1588
         $template = apply_filters(
1589 1589
             'FHEE__Events_Admin_Page__ticket_metabox__template',
1590
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1590
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'
1591 1591
         );
1592 1592
         EEH_Template::display_template($template, $template_args);
1593 1593
     }
@@ -1606,7 +1606,7 @@  discard block
 block discarded – undo
1606 1606
     private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1607 1607
     {
1608 1608
         $template_args = array(
1609
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1609
+            'tkt_status_class'    => ' tkt-status-'.$ticket->ticket_status(),
1610 1610
             'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1611 1611
                 : '',
1612 1612
             'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
@@ -1660,7 +1660,7 @@  discard block
 block discarded – undo
1660 1660
         $template_args = array_merge($template_args, $price_args);
1661 1661
         $template = apply_filters(
1662 1662
             'FHEE__Events_Admin_Page__get_ticket_row__template',
1663
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1663
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',
1664 1664
             $ticket
1665 1665
         );
1666 1666
         return EEH_Template::display_template($template, $template_args, true);
@@ -1712,7 +1712,7 @@  discard block
 block discarded – undo
1712 1712
             $default_reg_status_values
1713 1713
         );
1714 1714
         EEH_Template::display_template(
1715
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1715
+            EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',
1716 1716
             $template_args
1717 1717
         );
1718 1718
     }
@@ -1735,7 +1735,7 @@  discard block
 block discarded – undo
1735 1735
     {
1736 1736
         $EEME = $this->_event_model();
1737 1737
         $offset = ($current_page - 1) * $per_page;
1738
-        $limit = $count ? null : $offset . ',' . $per_page;
1738
+        $limit = $count ? null : $offset.','.$per_page;
1739 1739
         $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1740 1740
         $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1741 1741
         if (isset($this->_req_data['month_range'])) {
@@ -1769,7 +1769,7 @@  discard block
 block discarded – undo
1769 1769
         $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1770 1770
         if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1771 1771
             $DateTime = new DateTime(
1772
-                $year_r . '-' . $month_r . '-01 00:00:00',
1772
+                $year_r.'-'.$month_r.'-01 00:00:00',
1773 1773
                 new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1774 1774
             );
1775 1775
             $start = $DateTime->format(implode(' ', $start_formats));
@@ -1815,7 +1815,7 @@  discard block
 block discarded – undo
1815 1815
         }
1816 1816
         //search query handling
1817 1817
         if (isset($this->_req_data['s'])) {
1818
-            $search_string = '%' . $this->_req_data['s'] . '%';
1818
+            $search_string = '%'.$this->_req_data['s'].'%';
1819 1819
             $where['OR'] = array(
1820 1820
                 'EVT_name'       => array('LIKE', $search_string),
1821 1821
                 'EVT_desc'       => array('LIKE', $search_string),
@@ -1949,7 +1949,7 @@  discard block
 block discarded – undo
1949 1949
         if ( ! empty($event_status)) {
1950 1950
             $success = true;
1951 1951
             //determine the event id and set to array.
1952
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1952
+            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
1953 1953
             // loop thru events
1954 1954
             foreach ($EVT_IDs as $EVT_ID) {
1955 1955
                 if ($EVT_ID = absint($EVT_ID)) {
@@ -2097,7 +2097,7 @@  discard block
 block discarded – undo
2097 2097
         // get list of events with no prices
2098 2098
         $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2099 2099
         //determine the event id and set to array.
2100
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2100
+        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2101 2101
         // loop thru events
2102 2102
         foreach ($EVT_IDs as $EVT_ID) {
2103 2103
             $EVT_ID = absint($EVT_ID);
@@ -2280,7 +2280,7 @@  discard block
 block discarded – undo
2280 2280
         $this->_set_add_edit_form_tags('update_default_event_settings');
2281 2281
         $this->_set_publish_post_box_vars(null, false, false, null, false);
2282 2282
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2283
-            EVENTS_TEMPLATE_PATH . 'event_settings.template.php',
2283
+            EVENTS_TEMPLATE_PATH.'event_settings.template.php',
2284 2284
             $this->_template_args,
2285 2285
             true
2286 2286
         );
@@ -2325,10 +2325,10 @@  discard block
 block discarded – undo
2325 2325
                                                . 'caffeinated_template_features.jpg" alt="'
2326 2326
                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2327 2327
                                                . '" />';
2328
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__(
2328
+        $this->_template_args['preview_text'] = '<strong>'.esc_html__(
2329 2329
                 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2330 2330
                 'event_espresso'
2331
-            ) . '</strong>';
2331
+            ).'</strong>';
2332 2332
         $this->display_admin_caf_preview_page('template_settings_tab');
2333 2333
     }
2334 2334
 
@@ -2377,7 +2377,7 @@  discard block
 block discarded – undo
2377 2377
     {
2378 2378
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2379 2379
         $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2380
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2380
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
2381 2381
                 'add_category',
2382 2382
                 'add_category',
2383 2383
                 array(),
@@ -2453,7 +2453,7 @@  discard block
 block discarded – undo
2453 2453
             'disable'                  => '',
2454 2454
             'disabled_message'         => false,
2455 2455
         );
2456
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2456
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
2457 2457
         return EEH_Template::display_template($template, $template_args, true);
2458 2458
     }
2459 2459
 
@@ -2461,8 +2461,8 @@  discard block
 block discarded – undo
2461 2461
 
2462 2462
     protected function _delete_categories()
2463 2463
     {
2464
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2465
-            : (array)$this->_req_data['category_id'];
2464
+        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2465
+            : (array) $this->_req_data['category_id'];
2466 2466
         foreach ($cat_ids as $cat_id) {
2467 2467
             $this->_delete_category($cat_id);
2468 2468
         }
@@ -2563,7 +2563,7 @@  discard block
 block discarded – undo
2563 2563
         $limit = ($current_page - 1) * $per_page;
2564 2564
         $where = array('taxonomy' => 'espresso_event_categories');
2565 2565
         if (isset($this->_req_data['s'])) {
2566
-            $sstr = '%' . $this->_req_data['s'] . '%';
2566
+            $sstr = '%'.$this->_req_data['s'].'%';
2567 2567
             $where['OR'] = array(
2568 2568
                 'Term.name'   => array('LIKE', $sstr),
2569 2569
                 'description' => array('LIKE', $sstr),
@@ -2572,7 +2572,7 @@  discard block
 block discarded – undo
2572 2572
         $query_params = array(
2573 2573
             $where,
2574 2574
             'order_by'   => array($orderby => $order),
2575
-            'limit'      => $limit . ',' . $per_page,
2575
+            'limit'      => $limit.','.$per_page,
2576 2576
             'force_join' => array('Term'),
2577 2577
         );
2578 2578
         $categories = $count
Please login to merge, or discard this patch.
Indentation   +2570 added lines, -2570 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -17,2576 +17,2576 @@  discard block
 block discarded – undo
17 17
 class Events_Admin_Page extends EE_Admin_Page_CPT
18 18
 {
19 19
 
20
-    /**
21
-     * This will hold the event object for event_details screen.
22
-     *
23
-     * @access protected
24
-     * @var EE_Event $_event
25
-     */
26
-    protected $_event;
27
-
28
-
29
-    /**
30
-     * This will hold the category object for category_details screen.
31
-     *
32
-     * @var stdClass $_category
33
-     */
34
-    protected $_category;
35
-
36
-
37
-    /**
38
-     * This will hold the event model instance
39
-     *
40
-     * @var EEM_Event $_event_model
41
-     */
42
-    protected $_event_model;
43
-
44
-
45
-
46
-    /**
47
-     * @var EE_Event
48
-     */
49
-    protected $_cpt_model_obj = false;
50
-
51
-
52
-
53
-    protected function _init_page_props()
54
-    {
55
-        $this->page_slug = EVENTS_PG_SLUG;
56
-        $this->page_label = EVENTS_LABEL;
57
-        $this->_admin_base_url = EVENTS_ADMIN_URL;
58
-        $this->_admin_base_path = EVENTS_ADMIN;
59
-        $this->_cpt_model_names = array(
60
-            'create_new' => 'EEM_Event',
61
-            'edit'       => 'EEM_Event',
62
-        );
63
-        $this->_cpt_edit_routes = array(
64
-            'espresso_events' => 'edit',
65
-        );
66
-        add_action(
67
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
68
-            array($this, 'verify_event_edit')
69
-        );
70
-    }
71
-
72
-
73
-
74
-    protected function _ajax_hooks()
75
-    {
76
-        //todo: all hooks for events ajax goes in here.
77
-    }
78
-
79
-
80
-
81
-    protected function _define_page_props()
82
-    {
83
-        $this->_admin_page_title = EVENTS_LABEL;
84
-        $this->_labels = array(
85
-            'buttons'      => array(
86
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
87
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
88
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
89
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
90
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
91
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
92
-            ),
93
-            'editor_title' => array(
94
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
95
-            ),
96
-            'publishbox'   => array(
97
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
98
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
99
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
100
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
101
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
102
-            ),
103
-        );
104
-    }
105
-
106
-
107
-
108
-    protected function _set_page_routes()
109
-    {
110
-        //load formatter helper
111
-        //load field generator helper
112
-        //is there a evt_id in the request?
113
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
114
-            ? $this->_req_data['EVT_ID'] : 0;
115
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
116
-        $this->_page_routes = array(
117
-            'default'                       => array(
118
-                'func'       => '_events_overview_list_table',
119
-                'capability' => 'ee_read_events',
120
-            ),
121
-            'create_new'                    => array(
122
-                'func'       => '_create_new_cpt_item',
123
-                'capability' => 'ee_edit_events',
124
-            ),
125
-            'edit'                          => array(
126
-                'func'       => '_edit_cpt_item',
127
-                'capability' => 'ee_edit_event',
128
-                'obj_id'     => $evt_id,
129
-            ),
130
-            'copy_event'                    => array(
131
-                'func'       => '_copy_events',
132
-                'capability' => 'ee_edit_event',
133
-                'obj_id'     => $evt_id,
134
-                'noheader'   => true,
135
-            ),
136
-            'trash_event'                   => array(
137
-                'func'       => '_trash_or_restore_event',
138
-                'args'       => array('event_status' => 'trash'),
139
-                'capability' => 'ee_delete_event',
140
-                'obj_id'     => $evt_id,
141
-                'noheader'   => true,
142
-            ),
143
-            'trash_events'                  => array(
144
-                'func'       => '_trash_or_restore_events',
145
-                'args'       => array('event_status' => 'trash'),
146
-                'capability' => 'ee_delete_events',
147
-                'noheader'   => true,
148
-            ),
149
-            'restore_event'                 => array(
150
-                'func'       => '_trash_or_restore_event',
151
-                'args'       => array('event_status' => 'draft'),
152
-                'capability' => 'ee_delete_event',
153
-                'obj_id'     => $evt_id,
154
-                'noheader'   => true,
155
-            ),
156
-            'restore_events'                => array(
157
-                'func'       => '_trash_or_restore_events',
158
-                'args'       => array('event_status' => 'draft'),
159
-                'capability' => 'ee_delete_events',
160
-                'noheader'   => true,
161
-            ),
162
-            'delete_event'                  => array(
163
-                'func'       => '_delete_event',
164
-                'capability' => 'ee_delete_event',
165
-                'obj_id'     => $evt_id,
166
-                'noheader'   => true,
167
-            ),
168
-            'delete_events'                 => array(
169
-                'func'       => '_delete_events',
170
-                'capability' => 'ee_delete_events',
171
-                'noheader'   => true,
172
-            ),
173
-            'view_report'                   => array(
174
-                'func'      => '_view_report',
175
-                'capablity' => 'ee_edit_events',
176
-            ),
177
-            'default_event_settings'        => array(
178
-                'func'       => '_default_event_settings',
179
-                'capability' => 'manage_options',
180
-            ),
181
-            'update_default_event_settings' => array(
182
-                'func'       => '_update_default_event_settings',
183
-                'capability' => 'manage_options',
184
-                'noheader'   => true,
185
-            ),
186
-            'template_settings'             => array(
187
-                'func'       => '_template_settings',
188
-                'capability' => 'manage_options',
189
-            ),
190
-            //event category tab related
191
-            'add_category'                  => array(
192
-                'func'       => '_category_details',
193
-                'capability' => 'ee_edit_event_category',
194
-                'args'       => array('add'),
195
-            ),
196
-            'edit_category'                 => array(
197
-                'func'       => '_category_details',
198
-                'capability' => 'ee_edit_event_category',
199
-                'args'       => array('edit'),
200
-            ),
201
-            'delete_categories'             => array(
202
-                'func'       => '_delete_categories',
203
-                'capability' => 'ee_delete_event_category',
204
-                'noheader'   => true,
205
-            ),
206
-            'delete_category'               => array(
207
-                'func'       => '_delete_categories',
208
-                'capability' => 'ee_delete_event_category',
209
-                'noheader'   => true,
210
-            ),
211
-            'insert_category'               => array(
212
-                'func'       => '_insert_or_update_category',
213
-                'args'       => array('new_category' => true),
214
-                'capability' => 'ee_edit_event_category',
215
-                'noheader'   => true,
216
-            ),
217
-            'update_category'               => array(
218
-                'func'       => '_insert_or_update_category',
219
-                'args'       => array('new_category' => false),
220
-                'capability' => 'ee_edit_event_category',
221
-                'noheader'   => true,
222
-            ),
223
-            'category_list'                 => array(
224
-                'func'       => '_category_list_table',
225
-                'capability' => 'ee_manage_event_categories',
226
-            ),
227
-        );
228
-    }
229
-
230
-
231
-
232
-    protected function _set_page_config()
233
-    {
234
-        $this->_page_config = array(
235
-            'default'                => array(
236
-                'nav'           => array(
237
-                    'label' => esc_html__('Overview', 'event_espresso'),
238
-                    'order' => 10,
239
-                ),
240
-                'list_table'    => 'Events_Admin_List_Table',
241
-                'help_tabs'     => array(
242
-                    'events_overview_help_tab'                       => array(
243
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
244
-                        'filename' => 'events_overview',
245
-                    ),
246
-                    'events_overview_table_column_headings_help_tab' => array(
247
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
248
-                        'filename' => 'events_overview_table_column_headings',
249
-                    ),
250
-                    'events_overview_filters_help_tab'               => array(
251
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
252
-                        'filename' => 'events_overview_filters',
253
-                    ),
254
-                    'events_overview_view_help_tab'                  => array(
255
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
256
-                        'filename' => 'events_overview_views',
257
-                    ),
258
-                    'events_overview_other_help_tab'                 => array(
259
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
260
-                        'filename' => 'events_overview_other',
261
-                    ),
262
-                ),
263
-                'help_tour'     => array(
264
-                    'Event_Overview_Help_Tour',
265
-                    //'New_Features_Test_Help_Tour' for testing multiple help tour
266
-                ),
267
-                'qtips'         => array(
268
-                    'EE_Event_List_Table_Tips',
269
-                ),
270
-                'require_nonce' => false,
271
-            ),
272
-            'create_new'             => array(
273
-                'nav'           => array(
274
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
275
-                    'order'      => 5,
276
-                    'persistent' => false,
277
-                ),
278
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
279
-                'help_tabs'     => array(
280
-                    'event_editor_help_tab'                            => array(
281
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
282
-                        'filename' => 'event_editor',
283
-                    ),
284
-                    'event_editor_title_richtexteditor_help_tab'       => array(
285
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
286
-                        'filename' => 'event_editor_title_richtexteditor',
287
-                    ),
288
-                    'event_editor_venue_details_help_tab'              => array(
289
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
290
-                        'filename' => 'event_editor_venue_details',
291
-                    ),
292
-                    'event_editor_event_datetimes_help_tab'            => array(
293
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
294
-                        'filename' => 'event_editor_event_datetimes',
295
-                    ),
296
-                    'event_editor_event_tickets_help_tab'              => array(
297
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
298
-                        'filename' => 'event_editor_event_tickets',
299
-                    ),
300
-                    'event_editor_event_registration_options_help_tab' => array(
301
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
302
-                        'filename' => 'event_editor_event_registration_options',
303
-                    ),
304
-                    'event_editor_tags_categories_help_tab'            => array(
305
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
306
-                        'filename' => 'event_editor_tags_categories',
307
-                    ),
308
-                    'event_editor_questions_registrants_help_tab'      => array(
309
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
310
-                        'filename' => 'event_editor_questions_registrants',
311
-                    ),
312
-                    'event_editor_save_new_event_help_tab'             => array(
313
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
314
-                        'filename' => 'event_editor_save_new_event',
315
-                    ),
316
-                    'event_editor_other_help_tab'                      => array(
317
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
318
-                        'filename' => 'event_editor_other',
319
-                    ),
320
-                ),
321
-                'help_tour'     => array(
322
-                    'Event_Editor_Help_Tour',
323
-                ),
324
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
325
-                'require_nonce' => false,
326
-            ),
327
-            'edit'                   => array(
328
-                'nav'           => array(
329
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
330
-                    'order'      => 5,
331
-                    'persistent' => false,
332
-                    'url'        => isset($this->_req_data['post'])
333
-                        ? EE_Admin_Page::add_query_args_and_nonce(
334
-                            array('post' => $this->_req_data['post'], 'action' => 'edit'),
335
-                            $this->_current_page_view_url
336
-                        )
337
-                        : $this->_admin_base_url,
338
-                ),
339
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
340
-                'help_tabs'     => array(
341
-                    'event_editor_help_tab'                            => array(
342
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
343
-                        'filename' => 'event_editor',
344
-                    ),
345
-                    'event_editor_title_richtexteditor_help_tab'       => array(
346
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
347
-                        'filename' => 'event_editor_title_richtexteditor',
348
-                    ),
349
-                    'event_editor_venue_details_help_tab'              => array(
350
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
351
-                        'filename' => 'event_editor_venue_details',
352
-                    ),
353
-                    'event_editor_event_datetimes_help_tab'            => array(
354
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
355
-                        'filename' => 'event_editor_event_datetimes',
356
-                    ),
357
-                    'event_editor_event_tickets_help_tab'              => array(
358
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
359
-                        'filename' => 'event_editor_event_tickets',
360
-                    ),
361
-                    'event_editor_event_registration_options_help_tab' => array(
362
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
363
-                        'filename' => 'event_editor_event_registration_options',
364
-                    ),
365
-                    'event_editor_tags_categories_help_tab'            => array(
366
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
367
-                        'filename' => 'event_editor_tags_categories',
368
-                    ),
369
-                    'event_editor_questions_registrants_help_tab'      => array(
370
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
371
-                        'filename' => 'event_editor_questions_registrants',
372
-                    ),
373
-                    'event_editor_save_new_event_help_tab'             => array(
374
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
375
-                        'filename' => 'event_editor_save_new_event',
376
-                    ),
377
-                    'event_editor_other_help_tab'                      => array(
378
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
379
-                        'filename' => 'event_editor_other',
380
-                    ),
381
-                ),
382
-                /*'help_tour' => array(
20
+	/**
21
+	 * This will hold the event object for event_details screen.
22
+	 *
23
+	 * @access protected
24
+	 * @var EE_Event $_event
25
+	 */
26
+	protected $_event;
27
+
28
+
29
+	/**
30
+	 * This will hold the category object for category_details screen.
31
+	 *
32
+	 * @var stdClass $_category
33
+	 */
34
+	protected $_category;
35
+
36
+
37
+	/**
38
+	 * This will hold the event model instance
39
+	 *
40
+	 * @var EEM_Event $_event_model
41
+	 */
42
+	protected $_event_model;
43
+
44
+
45
+
46
+	/**
47
+	 * @var EE_Event
48
+	 */
49
+	protected $_cpt_model_obj = false;
50
+
51
+
52
+
53
+	protected function _init_page_props()
54
+	{
55
+		$this->page_slug = EVENTS_PG_SLUG;
56
+		$this->page_label = EVENTS_LABEL;
57
+		$this->_admin_base_url = EVENTS_ADMIN_URL;
58
+		$this->_admin_base_path = EVENTS_ADMIN;
59
+		$this->_cpt_model_names = array(
60
+			'create_new' => 'EEM_Event',
61
+			'edit'       => 'EEM_Event',
62
+		);
63
+		$this->_cpt_edit_routes = array(
64
+			'espresso_events' => 'edit',
65
+		);
66
+		add_action(
67
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
68
+			array($this, 'verify_event_edit')
69
+		);
70
+	}
71
+
72
+
73
+
74
+	protected function _ajax_hooks()
75
+	{
76
+		//todo: all hooks for events ajax goes in here.
77
+	}
78
+
79
+
80
+
81
+	protected function _define_page_props()
82
+	{
83
+		$this->_admin_page_title = EVENTS_LABEL;
84
+		$this->_labels = array(
85
+			'buttons'      => array(
86
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
87
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
88
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
89
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
90
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
91
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
92
+			),
93
+			'editor_title' => array(
94
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
95
+			),
96
+			'publishbox'   => array(
97
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
98
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
99
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
100
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
101
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
102
+			),
103
+		);
104
+	}
105
+
106
+
107
+
108
+	protected function _set_page_routes()
109
+	{
110
+		//load formatter helper
111
+		//load field generator helper
112
+		//is there a evt_id in the request?
113
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
114
+			? $this->_req_data['EVT_ID'] : 0;
115
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
116
+		$this->_page_routes = array(
117
+			'default'                       => array(
118
+				'func'       => '_events_overview_list_table',
119
+				'capability' => 'ee_read_events',
120
+			),
121
+			'create_new'                    => array(
122
+				'func'       => '_create_new_cpt_item',
123
+				'capability' => 'ee_edit_events',
124
+			),
125
+			'edit'                          => array(
126
+				'func'       => '_edit_cpt_item',
127
+				'capability' => 'ee_edit_event',
128
+				'obj_id'     => $evt_id,
129
+			),
130
+			'copy_event'                    => array(
131
+				'func'       => '_copy_events',
132
+				'capability' => 'ee_edit_event',
133
+				'obj_id'     => $evt_id,
134
+				'noheader'   => true,
135
+			),
136
+			'trash_event'                   => array(
137
+				'func'       => '_trash_or_restore_event',
138
+				'args'       => array('event_status' => 'trash'),
139
+				'capability' => 'ee_delete_event',
140
+				'obj_id'     => $evt_id,
141
+				'noheader'   => true,
142
+			),
143
+			'trash_events'                  => array(
144
+				'func'       => '_trash_or_restore_events',
145
+				'args'       => array('event_status' => 'trash'),
146
+				'capability' => 'ee_delete_events',
147
+				'noheader'   => true,
148
+			),
149
+			'restore_event'                 => array(
150
+				'func'       => '_trash_or_restore_event',
151
+				'args'       => array('event_status' => 'draft'),
152
+				'capability' => 'ee_delete_event',
153
+				'obj_id'     => $evt_id,
154
+				'noheader'   => true,
155
+			),
156
+			'restore_events'                => array(
157
+				'func'       => '_trash_or_restore_events',
158
+				'args'       => array('event_status' => 'draft'),
159
+				'capability' => 'ee_delete_events',
160
+				'noheader'   => true,
161
+			),
162
+			'delete_event'                  => array(
163
+				'func'       => '_delete_event',
164
+				'capability' => 'ee_delete_event',
165
+				'obj_id'     => $evt_id,
166
+				'noheader'   => true,
167
+			),
168
+			'delete_events'                 => array(
169
+				'func'       => '_delete_events',
170
+				'capability' => 'ee_delete_events',
171
+				'noheader'   => true,
172
+			),
173
+			'view_report'                   => array(
174
+				'func'      => '_view_report',
175
+				'capablity' => 'ee_edit_events',
176
+			),
177
+			'default_event_settings'        => array(
178
+				'func'       => '_default_event_settings',
179
+				'capability' => 'manage_options',
180
+			),
181
+			'update_default_event_settings' => array(
182
+				'func'       => '_update_default_event_settings',
183
+				'capability' => 'manage_options',
184
+				'noheader'   => true,
185
+			),
186
+			'template_settings'             => array(
187
+				'func'       => '_template_settings',
188
+				'capability' => 'manage_options',
189
+			),
190
+			//event category tab related
191
+			'add_category'                  => array(
192
+				'func'       => '_category_details',
193
+				'capability' => 'ee_edit_event_category',
194
+				'args'       => array('add'),
195
+			),
196
+			'edit_category'                 => array(
197
+				'func'       => '_category_details',
198
+				'capability' => 'ee_edit_event_category',
199
+				'args'       => array('edit'),
200
+			),
201
+			'delete_categories'             => array(
202
+				'func'       => '_delete_categories',
203
+				'capability' => 'ee_delete_event_category',
204
+				'noheader'   => true,
205
+			),
206
+			'delete_category'               => array(
207
+				'func'       => '_delete_categories',
208
+				'capability' => 'ee_delete_event_category',
209
+				'noheader'   => true,
210
+			),
211
+			'insert_category'               => array(
212
+				'func'       => '_insert_or_update_category',
213
+				'args'       => array('new_category' => true),
214
+				'capability' => 'ee_edit_event_category',
215
+				'noheader'   => true,
216
+			),
217
+			'update_category'               => array(
218
+				'func'       => '_insert_or_update_category',
219
+				'args'       => array('new_category' => false),
220
+				'capability' => 'ee_edit_event_category',
221
+				'noheader'   => true,
222
+			),
223
+			'category_list'                 => array(
224
+				'func'       => '_category_list_table',
225
+				'capability' => 'ee_manage_event_categories',
226
+			),
227
+		);
228
+	}
229
+
230
+
231
+
232
+	protected function _set_page_config()
233
+	{
234
+		$this->_page_config = array(
235
+			'default'                => array(
236
+				'nav'           => array(
237
+					'label' => esc_html__('Overview', 'event_espresso'),
238
+					'order' => 10,
239
+				),
240
+				'list_table'    => 'Events_Admin_List_Table',
241
+				'help_tabs'     => array(
242
+					'events_overview_help_tab'                       => array(
243
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
244
+						'filename' => 'events_overview',
245
+					),
246
+					'events_overview_table_column_headings_help_tab' => array(
247
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
248
+						'filename' => 'events_overview_table_column_headings',
249
+					),
250
+					'events_overview_filters_help_tab'               => array(
251
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
252
+						'filename' => 'events_overview_filters',
253
+					),
254
+					'events_overview_view_help_tab'                  => array(
255
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
256
+						'filename' => 'events_overview_views',
257
+					),
258
+					'events_overview_other_help_tab'                 => array(
259
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
260
+						'filename' => 'events_overview_other',
261
+					),
262
+				),
263
+				'help_tour'     => array(
264
+					'Event_Overview_Help_Tour',
265
+					//'New_Features_Test_Help_Tour' for testing multiple help tour
266
+				),
267
+				'qtips'         => array(
268
+					'EE_Event_List_Table_Tips',
269
+				),
270
+				'require_nonce' => false,
271
+			),
272
+			'create_new'             => array(
273
+				'nav'           => array(
274
+					'label'      => esc_html__('Add Event', 'event_espresso'),
275
+					'order'      => 5,
276
+					'persistent' => false,
277
+				),
278
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
279
+				'help_tabs'     => array(
280
+					'event_editor_help_tab'                            => array(
281
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
282
+						'filename' => 'event_editor',
283
+					),
284
+					'event_editor_title_richtexteditor_help_tab'       => array(
285
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
286
+						'filename' => 'event_editor_title_richtexteditor',
287
+					),
288
+					'event_editor_venue_details_help_tab'              => array(
289
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
290
+						'filename' => 'event_editor_venue_details',
291
+					),
292
+					'event_editor_event_datetimes_help_tab'            => array(
293
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
294
+						'filename' => 'event_editor_event_datetimes',
295
+					),
296
+					'event_editor_event_tickets_help_tab'              => array(
297
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
298
+						'filename' => 'event_editor_event_tickets',
299
+					),
300
+					'event_editor_event_registration_options_help_tab' => array(
301
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
302
+						'filename' => 'event_editor_event_registration_options',
303
+					),
304
+					'event_editor_tags_categories_help_tab'            => array(
305
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
306
+						'filename' => 'event_editor_tags_categories',
307
+					),
308
+					'event_editor_questions_registrants_help_tab'      => array(
309
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
310
+						'filename' => 'event_editor_questions_registrants',
311
+					),
312
+					'event_editor_save_new_event_help_tab'             => array(
313
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
314
+						'filename' => 'event_editor_save_new_event',
315
+					),
316
+					'event_editor_other_help_tab'                      => array(
317
+						'title'    => esc_html__('Event Other', 'event_espresso'),
318
+						'filename' => 'event_editor_other',
319
+					),
320
+				),
321
+				'help_tour'     => array(
322
+					'Event_Editor_Help_Tour',
323
+				),
324
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
325
+				'require_nonce' => false,
326
+			),
327
+			'edit'                   => array(
328
+				'nav'           => array(
329
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
330
+					'order'      => 5,
331
+					'persistent' => false,
332
+					'url'        => isset($this->_req_data['post'])
333
+						? EE_Admin_Page::add_query_args_and_nonce(
334
+							array('post' => $this->_req_data['post'], 'action' => 'edit'),
335
+							$this->_current_page_view_url
336
+						)
337
+						: $this->_admin_base_url,
338
+				),
339
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
340
+				'help_tabs'     => array(
341
+					'event_editor_help_tab'                            => array(
342
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
343
+						'filename' => 'event_editor',
344
+					),
345
+					'event_editor_title_richtexteditor_help_tab'       => array(
346
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
347
+						'filename' => 'event_editor_title_richtexteditor',
348
+					),
349
+					'event_editor_venue_details_help_tab'              => array(
350
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
351
+						'filename' => 'event_editor_venue_details',
352
+					),
353
+					'event_editor_event_datetimes_help_tab'            => array(
354
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
355
+						'filename' => 'event_editor_event_datetimes',
356
+					),
357
+					'event_editor_event_tickets_help_tab'              => array(
358
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
359
+						'filename' => 'event_editor_event_tickets',
360
+					),
361
+					'event_editor_event_registration_options_help_tab' => array(
362
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
363
+						'filename' => 'event_editor_event_registration_options',
364
+					),
365
+					'event_editor_tags_categories_help_tab'            => array(
366
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
367
+						'filename' => 'event_editor_tags_categories',
368
+					),
369
+					'event_editor_questions_registrants_help_tab'      => array(
370
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
371
+						'filename' => 'event_editor_questions_registrants',
372
+					),
373
+					'event_editor_save_new_event_help_tab'             => array(
374
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
375
+						'filename' => 'event_editor_save_new_event',
376
+					),
377
+					'event_editor_other_help_tab'                      => array(
378
+						'title'    => esc_html__('Event Other', 'event_espresso'),
379
+						'filename' => 'event_editor_other',
380
+					),
381
+				),
382
+				/*'help_tour' => array(
383 383
 					'Event_Edit_Help_Tour'
384 384
 				),*/
385
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
386
-                'require_nonce' => false,
387
-            ),
388
-            'default_event_settings' => array(
389
-                'nav'           => array(
390
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
391
-                    'order' => 40,
392
-                ),
393
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
394
-                'labels'        => array(
395
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
396
-                ),
397
-                'help_tabs'     => array(
398
-                    'default_settings_help_tab'        => array(
399
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
400
-                        'filename' => 'events_default_settings',
401
-                    ),
402
-                    'default_settings_status_help_tab' => array(
403
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
404
-                        'filename' => 'events_default_settings_status',
405
-                    ),
406
-                ),
407
-                'help_tour'     => array('Event_Default_Settings_Help_Tour'),
408
-                'require_nonce' => false,
409
-            ),
410
-            //template settings
411
-            'template_settings'      => array(
412
-                'nav'           => array(
413
-                    'label' => esc_html__('Templates', 'event_espresso'),
414
-                    'order' => 30,
415
-                ),
416
-                'metaboxes'     => $this->_default_espresso_metaboxes,
417
-                'help_tabs'     => array(
418
-                    'general_settings_templates_help_tab' => array(
419
-                        'title'    => esc_html__('Templates', 'event_espresso'),
420
-                        'filename' => 'general_settings_templates',
421
-                    ),
422
-                ),
423
-                'help_tour'     => array('Templates_Help_Tour'),
424
-                'require_nonce' => false,
425
-            ),
426
-            //event category stuff
427
-            'add_category'           => array(
428
-                'nav'           => array(
429
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
430
-                    'order'      => 15,
431
-                    'persistent' => false,
432
-                ),
433
-                'help_tabs'     => array(
434
-                    'add_category_help_tab' => array(
435
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
436
-                        'filename' => 'events_add_category',
437
-                    ),
438
-                ),
439
-                'help_tour'     => array('Event_Add_Category_Help_Tour'),
440
-                'metaboxes'     => array('_publish_post_box'),
441
-                'require_nonce' => false,
442
-            ),
443
-            'edit_category'          => array(
444
-                'nav'           => array(
445
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
446
-                    'order'      => 15,
447
-                    'persistent' => false,
448
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
449
-                        ? add_query_arg(
450
-                            array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
451
-                            $this->_current_page_view_url
452
-                        )
453
-                        : $this->_admin_base_url,
454
-                ),
455
-                'help_tabs'     => array(
456
-                    'edit_category_help_tab' => array(
457
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
458
-                        'filename' => 'events_edit_category',
459
-                    ),
460
-                ),
461
-                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
462
-                'metaboxes'     => array('_publish_post_box'),
463
-                'require_nonce' => false,
464
-            ),
465
-            'category_list'          => array(
466
-                'nav'           => array(
467
-                    'label' => esc_html__('Categories', 'event_espresso'),
468
-                    'order' => 20,
469
-                ),
470
-                'list_table'    => 'Event_Categories_Admin_List_Table',
471
-                'help_tabs'     => array(
472
-                    'events_categories_help_tab'                       => array(
473
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
474
-                        'filename' => 'events_categories',
475
-                    ),
476
-                    'events_categories_table_column_headings_help_tab' => array(
477
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
478
-                        'filename' => 'events_categories_table_column_headings',
479
-                    ),
480
-                    'events_categories_view_help_tab'                  => array(
481
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
482
-                        'filename' => 'events_categories_views',
483
-                    ),
484
-                    'events_categories_other_help_tab'                 => array(
485
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
486
-                        'filename' => 'events_categories_other',
487
-                    ),
488
-                ),
489
-                'help_tour'     => array(
490
-                    'Event_Categories_Help_Tour',
491
-                ),
492
-                'metaboxes'     => $this->_default_espresso_metaboxes,
493
-                'require_nonce' => false,
494
-            ),
495
-        );
496
-    }
497
-
498
-
499
-
500
-    protected function _add_screen_options()
501
-    {
502
-        //todo
503
-    }
504
-
505
-
506
-
507
-    protected function _add_screen_options_default()
508
-    {
509
-        $this->_per_page_screen_option();
510
-    }
511
-
512
-
513
-
514
-    protected function _add_screen_options_category_list()
515
-    {
516
-        $page_title = $this->_admin_page_title;
517
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
518
-        $this->_per_page_screen_option();
519
-        $this->_admin_page_title = $page_title;
520
-    }
521
-
522
-
523
-
524
-    protected function _add_feature_pointers()
525
-    {
526
-        //todo
527
-    }
528
-
529
-
530
-
531
-    public function load_scripts_styles()
532
-    {
533
-        wp_register_style(
534
-            'events-admin-css',
535
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
536
-            array(),
537
-            EVENT_ESPRESSO_VERSION
538
-        );
539
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
540
-        wp_enqueue_style('events-admin-css');
541
-        wp_enqueue_style('ee-cat-admin');
542
-        //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
543
-        //registers for all views
544
-        //scripts
545
-        wp_register_script(
546
-            'event_editor_js',
547
-            EVENTS_ASSETS_URL . 'event_editor.js',
548
-            array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
549
-            EVENT_ESPRESSO_VERSION,
550
-            true
551
-        );
552
-    }
553
-
554
-
555
-
556
-    /**
557
-     * enqueuing scripts and styles specific to this view
558
-     *
559
-     * @return void
560
-     */
561
-    public function load_scripts_styles_create_new()
562
-    {
563
-        $this->load_scripts_styles_edit();
564
-    }
565
-
566
-
567
-
568
-    /**
569
-     * enqueuing scripts and styles specific to this view
570
-     *
571
-     * @return void
572
-     */
573
-    public function load_scripts_styles_edit()
574
-    {
575
-        //styles
576
-        wp_enqueue_style('espresso-ui-theme');
577
-        wp_register_style(
578
-            'event-editor-css',
579
-            EVENTS_ASSETS_URL . 'event-editor.css',
580
-            array('ee-admin-css'),
581
-            EVENT_ESPRESSO_VERSION
582
-        );
583
-        wp_enqueue_style('event-editor-css');
584
-        //scripts
585
-        wp_register_script(
586
-            'event-datetime-metabox',
587
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
588
-            array('event_editor_js', 'ee-datepicker'),
589
-            EVENT_ESPRESSO_VERSION
590
-        );
591
-        wp_enqueue_script('event-datetime-metabox');
592
-    }
593
-
594
-
595
-
596
-    public function load_scripts_styles_add_category()
597
-    {
598
-        $this->load_scripts_styles_edit_category();
599
-    }
600
-
601
-
602
-
603
-    public function load_scripts_styles_edit_category()
604
-    {
605
-    }
606
-
607
-
608
-
609
-    protected function _set_list_table_views_category_list()
610
-    {
611
-        $this->_views = array(
612
-            'all' => array(
613
-                'slug'        => 'all',
614
-                'label'       => esc_html__('All', 'event_espresso'),
615
-                'count'       => 0,
616
-                'bulk_action' => array(
617
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
618
-                ),
619
-            ),
620
-        );
621
-    }
622
-
623
-
624
-
625
-    public function admin_init()
626
-    {
627
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
628
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
629
-            'event_espresso'
630
-        );
631
-    }
632
-
633
-
634
-
635
-    //nothing needed for events with these methods.
636
-    public function admin_notices()
637
-    {
638
-    }
639
-
640
-
641
-
642
-    public function admin_footer_scripts()
643
-    {
644
-    }
645
-
646
-
647
-
648
-    /**
649
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
650
-     * warning (via EE_Error::add_error());
651
-     *
652
-     * @param  EE_Event $event Event object
653
-     * @access public
654
-     * @return void
655
-     */
656
-    public function verify_event_edit($event = null)
657
-    {
658
-        // no event?
659
-        if (empty($event)) {
660
-            // set event
661
-            $event = $this->_cpt_model_obj;
662
-        }
663
-        // STILL no event?
664
-        if (empty ($event)) {
665
-            return;
666
-        }
667
-        $orig_status = $event->status();
668
-        // first check if event is active.
669
-        if (
670
-            $orig_status === EEM_Event::cancelled
671
-            || $orig_status === EEM_Event::postponed
672
-            || $event->is_expired()
673
-            || $event->is_inactive()
674
-        ) {
675
-            return;
676
-        }
677
-        //made it here so it IS active... next check that any of the tickets are sold.
678
-        if ($event->is_sold_out(true)) {
679
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
680
-                EE_Error::add_attention(
681
-                    sprintf(
682
-                        esc_html__(
683
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
684
-                            'event_espresso'
685
-                        ),
686
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
687
-                    )
688
-                );
689
-            }
690
-            return;
691
-        } else if ($orig_status === EEM_Event::sold_out) {
692
-            EE_Error::add_attention(
693
-                sprintf(
694
-                    esc_html__(
695
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
696
-                        'event_espresso'
697
-                    ),
698
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
699
-                )
700
-            );
701
-        }
702
-        //now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
703
-        if ( ! $event->tickets_on_sale()) {
704
-            return;
705
-        }
706
-        //made it here so show warning
707
-        $this->_edit_event_warning();
708
-    }
709
-
710
-
711
-
712
-    /**
713
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
714
-     * When needed, hook this into a EE_Error::add_error() notice.
715
-     *
716
-     * @access protected
717
-     * @return void
718
-     */
719
-    protected function _edit_event_warning()
720
-    {
721
-        // we don't want to add warnings during these requests
722
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
723
-            return;
724
-        }
725
-        EE_Error::add_attention(
726
-            esc_html__(
727
-                'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.',
728
-                'event_espresso'
729
-            )
730
-        );
731
-    }
732
-
733
-
734
-
735
-    /**
736
-     * When a user is creating a new event, notify them if they haven't set their timezone.
737
-     * Otherwise, do the normal logic
738
-     *
739
-     * @return string
740
-     * @throws \EE_Error
741
-     */
742
-    protected function _create_new_cpt_item()
743
-    {
744
-        $gmt_offset = get_option('gmt_offset');
745
-        //only nag them about setting their timezone if it's their first event, and they haven't already done it
746
-        if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) {
747
-            EE_Error::add_attention(
748
-                sprintf(
749
-                    __(
750
-                        'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.',
751
-                        'event_espresso'
752
-                    ),
753
-                    '<a href="' . admin_url('options-general.php') . '">',
754
-                    '</a>'
755
-                ),
756
-                __FILE__,
757
-                __FUNCTION__,
758
-                __LINE__
759
-            );
760
-        }
761
-        return parent::_create_new_cpt_item();
762
-    }
763
-
764
-
765
-
766
-    protected function _set_list_table_views_default()
767
-    {
768
-        $this->_views = array(
769
-            'all'   => array(
770
-                'slug'        => 'all',
771
-                'label'       => esc_html__('View All Events', 'event_espresso'),
772
-                'count'       => 0,
773
-                'bulk_action' => array(
774
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
775
-                ),
776
-            ),
777
-            'draft' => array(
778
-                'slug'        => 'draft',
779
-                'label'       => esc_html__('Draft', 'event_espresso'),
780
-                'count'       => 0,
781
-                'bulk_action' => array(
782
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
783
-                ),
784
-            ),
785
-        );
786
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
787
-            $this->_views['trash'] = array(
788
-                'slug'        => 'trash',
789
-                'label'       => esc_html__('Trash', 'event_espresso'),
790
-                'count'       => 0,
791
-                'bulk_action' => array(
792
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
793
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
794
-                ),
795
-            );
796
-        }
797
-    }
798
-
799
-
800
-
801
-    /**
802
-     * @return array
803
-     */
804
-    protected function _event_legend_items()
805
-    {
806
-        $items = array(
807
-            'view_details'   => array(
808
-                'class' => 'dashicons dashicons-search',
809
-                'desc'  => esc_html__('View Event', 'event_espresso'),
810
-            ),
811
-            'edit_event'     => array(
812
-                'class' => 'ee-icon ee-icon-calendar-edit',
813
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
814
-            ),
815
-            'view_attendees' => array(
816
-                'class' => 'dashicons dashicons-groups',
817
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
818
-            ),
819
-        );
820
-        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
821
-        $statuses = array(
822
-            'sold_out_status'  => array(
823
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
824
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
825
-            ),
826
-            'active_status'    => array(
827
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
828
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
829
-            ),
830
-            'upcoming_status'  => array(
831
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
832
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
833
-            ),
834
-            'postponed_status' => array(
835
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
836
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
837
-            ),
838
-            'cancelled_status' => array(
839
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
840
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
841
-            ),
842
-            'expired_status'   => array(
843
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
844
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
845
-            ),
846
-            'inactive_status'  => array(
847
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
848
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
849
-            ),
850
-        );
851
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
852
-        return array_merge($items, $statuses);
853
-    }
854
-
855
-
856
-
857
-    /**
858
-     * _event_model
859
-     *
860
-     * @return EEM_Event
861
-     */
862
-    private function _event_model()
863
-    {
864
-        if ( ! $this->_event_model instanceof EEM_Event) {
865
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
866
-        }
867
-        return $this->_event_model;
868
-    }
869
-
870
-
871
-
872
-    /**
873
-     * Adds extra buttons to the WP CPT permalink field row.
874
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
875
-     *
876
-     * @param  string $return    the current html
877
-     * @param  int    $id        the post id for the page
878
-     * @param  string $new_title What the title is
879
-     * @param  string $new_slug  what the slug is
880
-     * @return string            The new html string for the permalink area
881
-     */
882
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
883
-    {
884
-        //make sure this is only when editing
885
-        if ( ! empty($id)) {
886
-            $post = get_post($id);
887
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
888
-                       . esc_html__('Shortcode', 'event_espresso')
889
-                       . '</a> ';
890
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
891
-                       . $post->ID
892
-                       . ']">';
893
-        }
894
-        return $return;
895
-    }
896
-
897
-
898
-
899
-    /**
900
-     * _events_overview_list_table
901
-     * This contains the logic for showing the events_overview list
902
-     *
903
-     * @access protected
904
-     * @return void
905
-     * @throws \EE_Error
906
-     */
907
-    protected function _events_overview_list_table()
908
-    {
909
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
910
-        $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
911
-            ? (array)$this->_template_args['after_list_table']
912
-            : array();
913
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
914
-                                                                              . EEH_Template::get_button_or_link(
915
-                get_post_type_archive_link('espresso_events'),
916
-                esc_html__("View Event Archive Page", "event_espresso"),
917
-                'button'
918
-            );
919
-        $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
920
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
921
-                'create_new',
922
-                'add',
923
-                array(),
924
-                'add-new-h2'
925
-            );
926
-        $this->display_admin_list_table_page_with_no_sidebar();
927
-    }
928
-
929
-
930
-
931
-    /**
932
-     * this allows for extra misc actions in the default WP publish box
933
-     *
934
-     * @return void
935
-     */
936
-    public function extra_misc_actions_publish_box()
937
-    {
938
-        $this->_generate_publish_box_extra_content();
939
-    }
940
-
941
-
942
-
943
-    /**
944
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
945
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
946
-     * data.
947
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
948
-     * ALSO very important.  When a post transitions from scheduled to published, the save_post action is fired but you
949
-     * will NOT have any _POST data containing any extra info you may have from other meta saves.  So MAKE sure that
950
-     * you handle this accordingly.
951
-     *
952
-     * @access protected
953
-     * @abstract
954
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
955
-     * @param  object $post    The post object of the cpt that was saved.
956
-     * @return void
957
-     */
958
-    protected function _insert_update_cpt_item($post_id, $post)
959
-    {
960
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
961
-            //get out we're not processing an event save.
962
-            return;
963
-        }
964
-        $event_values = array(
965
-            'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
966
-            'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
967
-            'EVT_additional_limit'            => min(
968
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
969
-                ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
970
-            ),
971
-            'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
972
-                ? $this->_req_data['EVT_default_registration_status']
973
-                : EE_Registry::instance()->CFG->registration->default_STS_ID,
974
-            'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
975
-            'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
976
-            'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
977
-                ? $this->_req_data['timezone_string'] : null,
978
-            'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
979
-                ? $this->_req_data['externalURL'] : null,
980
-            'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
981
-                ? $this->_req_data['event_phone'] : null,
982
-        );
983
-        //update event
984
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
985
-        //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
986
-        $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status);
987
-        $event = $this->_event_model()->get_one(array($get_one_where));
988
-        //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
989
-        $event_update_callbacks = apply_filters(
990
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
991
-            array(array($this, '_default_venue_update'), array($this, '_default_tickets_update'))
992
-        );
993
-        $att_success = true;
994
-        foreach ($event_update_callbacks as $e_callback) {
995
-            $_succ = call_user_func_array($e_callback, array($event, $this->_req_data));
996
-            $att_success = ! $att_success ? $att_success
997
-                : $_succ; //if ANY of these updates fail then we want the appropriate global error message
998
-        }
999
-        //any errors?
1000
-        if ($success && false === $att_success) {
1001
-            EE_Error::add_error(
1002
-                esc_html__(
1003
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1004
-                    'event_espresso'
1005
-                ),
1006
-                __FILE__,
1007
-                __FUNCTION__,
1008
-                __LINE__
1009
-            );
1010
-        } else if ($success === false) {
1011
-            EE_Error::add_error(
1012
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1013
-                __FILE__,
1014
-                __FUNCTION__,
1015
-                __LINE__
1016
-            );
1017
-        }
1018
-    }
1019
-
1020
-
1021
-
1022
-    /**
1023
-     * @see parent::restore_item()
1024
-     * @param int $post_id
1025
-     * @param int $revision_id
1026
-     */
1027
-    protected function _restore_cpt_item($post_id, $revision_id)
1028
-    {
1029
-        //copy existing event meta to new post
1030
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1031
-        if ($post_evt instanceof EE_Event) {
1032
-            //meta revision restore
1033
-            $post_evt->restore_revision($revision_id);
1034
-            //related objs restore
1035
-            $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1036
-        }
1037
-    }
1038
-
1039
-
1040
-
1041
-    /**
1042
-     * Attach the venue to the Event
1043
-     *
1044
-     * @param  \EE_Event $evtobj Event Object to add the venue to
1045
-     * @param  array     $data   The request data from the form
1046
-     * @return bool           Success or fail.
1047
-     */
1048
-    protected function _default_venue_update(\EE_Event $evtobj, $data)
1049
-    {
1050
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1051
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1052
-        $rows_affected = null;
1053
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1054
-        // very important.  If we don't have a venue name...
1055
-        // then we'll get out because not necessary to create empty venue
1056
-        if (empty($data['venue_title'])) {
1057
-            return false;
1058
-        }
1059
-        $venue_array = array(
1060
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1061
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1062
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1063
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1064
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1065
-                : null,
1066
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1067
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1068
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1069
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1070
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1071
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1072
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1073
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1074
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1075
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1076
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1077
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1078
-            'status'              => 'publish',
1079
-        );
1080
-        //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1081
-        if ( ! empty($venue_id)) {
1082
-            $update_where = array($venue_model->primary_key_name() => $venue_id);
1083
-            $rows_affected = $venue_model->update($venue_array, array($update_where));
1084
-            //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1085
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1086
-            return $rows_affected > 0 ? true : false;
1087
-        } else {
1088
-            //we insert the venue
1089
-            $venue_id = $venue_model->insert($venue_array);
1090
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1091
-            return ! empty($venue_id) ? true : false;
1092
-        }
1093
-        //when we have the ancestor come in it's already been handled by the revision save.
1094
-    }
1095
-
1096
-
1097
-
1098
-    /**
1099
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1100
-     *
1101
-     * @param  EE_Event $evtobj The Event object we're attaching data to
1102
-     * @param  array    $data   The request data from the form
1103
-     * @return array
1104
-     */
1105
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1106
-    {
1107
-        $success = true;
1108
-        $saved_dtt = null;
1109
-        $saved_tickets = array();
1110
-        $incoming_date_formats = array('Y-m-d', 'h:i a');
1111
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1112
-            //trim all values to ensure any excess whitespace is removed.
1113
-            $dtt = array_map('trim', $dtt);
1114
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1115
-                : $dtt['DTT_EVT_start'];
1116
-            $datetime_values = array(
1117
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1118
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1119
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1120
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1121
-                'DTT_order'     => $row,
1122
-            );
1123
-            //if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1124
-            if ( ! empty($dtt['DTT_ID'])) {
1125
-                $DTM = EE_Registry::instance()
1126
-                                  ->load_model('Datetime', array($evtobj->get_timezone()))
1127
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1128
-                $DTM->set_date_format($incoming_date_formats[0]);
1129
-                $DTM->set_time_format($incoming_date_formats[1]);
1130
-                foreach ($datetime_values as $field => $value) {
1131
-                    $DTM->set($field, $value);
1132
-                }
1133
-                //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1134
-                $saved_dtts[$DTM->ID()] = $DTM;
1135
-            } else {
1136
-                $DTM = EE_Registry::instance()->load_class(
1137
-                    'Datetime',
1138
-                    array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1139
-                    false,
1140
-                    false
1141
-                );
1142
-                foreach ($datetime_values as $field => $value) {
1143
-                    $DTM->set($field, $value);
1144
-                }
1145
-            }
1146
-            $DTM->save();
1147
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1148
-            //load DTT helper
1149
-            //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1150
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1151
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1152
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1153
-                $DTT->save();
1154
-            }
1155
-            //now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1156
-            $saved_dtt = $DTT;
1157
-            $success = ! $success ? $success : $DTT;
1158
-            //if ANY of these updates fail then we want the appropriate global error message.
1159
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1160
-        }
1161
-        //no dtts get deleted so we don't do any of that logic here.
1162
-        //update tickets next
1163
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1164
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1165
-            $incoming_date_formats = array('Y-m-d', 'h:i a');
1166
-            $update_prices = false;
1167
-            $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1168
-                ? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1169
-            // trim inputs to ensure any excess whitespace is removed.
1170
-            $tkt = array_map('trim', $tkt);
1171
-            if (empty($tkt['TKT_start_date'])) {
1172
-                //let's use now in the set timezone.
1173
-                $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1174
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1175
-            }
1176
-            if (empty($tkt['TKT_end_date'])) {
1177
-                //use the start date of the first datetime
1178
-                $dtt = $evtobj->first_datetime();
1179
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1180
-                    $incoming_date_formats[0],
1181
-                    $incoming_date_formats[1]
1182
-                );
1183
-            }
1184
-            $TKT_values = array(
1185
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1186
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1187
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1188
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1189
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1190
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1191
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1192
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1193
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1194
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1195
-                'TKT_row'         => $row,
1196
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1197
-                'TKT_price'       => $ticket_price,
1198
-            );
1199
-            //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1200
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1201
-                $TKT_values['TKT_ID'] = 0;
1202
-                $TKT_values['TKT_is_default'] = 0;
1203
-                $TKT_values['TKT_price'] = $ticket_price;
1204
-                $update_prices = true;
1205
-            }
1206
-            //if we have a TKT_ID then we need to get that existing TKT_obj and update it
1207
-            //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1208
-            //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1209
-            if ( ! empty($tkt['TKT_ID'])) {
1210
-                $TKT = EE_Registry::instance()
1211
-                                  ->load_model('Ticket', array($evtobj->get_timezone()))
1212
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1213
-                if ($TKT instanceof EE_Ticket) {
1214
-                    $ticket_sold = $TKT->count_related(
1215
-                        'Registration',
1216
-                        array(
1217
-                            array(
1218
-                                'STS_ID' => array(
1219
-                                    'NOT IN',
1220
-                                    array(EEM_Registration::status_id_incomplete),
1221
-                                ),
1222
-                            ),
1223
-                        )
1224
-                    ) > 0 ? true : false;
1225
-                    //let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1226
-                    $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1227
-                                      && ! $TKT->get(
1228
-                        'TKT_deleted'
1229
-                    ) ? true : false;
1230
-                    $TKT->set_date_format($incoming_date_formats[0]);
1231
-                    $TKT->set_time_format($incoming_date_formats[1]);
1232
-                    //set new values
1233
-                    foreach ($TKT_values as $field => $value) {
1234
-                        if ($field == 'TKT_qty') {
1235
-                            $TKT->set_qty($value);
1236
-                        } else {
1237
-                            $TKT->set($field, $value);
1238
-                        }
1239
-                    }
1240
-                    //if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1241
-                    if ($create_new_TKT) {
1242
-                        //archive the old ticket first
1243
-                        $TKT->set('TKT_deleted', 1);
1244
-                        $TKT->save();
1245
-                        //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1246
-                        $saved_tickets[$TKT->ID()] = $TKT;
1247
-                        //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1248
-                        $TKT = clone $TKT;
1249
-                        $TKT->set('TKT_ID', 0);
1250
-                        $TKT->set('TKT_deleted', 0);
1251
-                        $TKT->set('TKT_price', $ticket_price);
1252
-                        $TKT->set('TKT_sold', 0);
1253
-                        //now we need to make sure that $new prices are created as well and attached to new ticket.
1254
-                        $update_prices = true;
1255
-                    }
1256
-                    //make sure price is set if it hasn't been already
1257
-                    $TKT->set('TKT_price', $ticket_price);
1258
-                }
1259
-            } else {
1260
-                //no TKT_id so a new TKT
1261
-                $TKT_values['TKT_price'] = $ticket_price;
1262
-                $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1263
-                if ($TKT instanceof EE_Ticket) {
1264
-                    //need to reset values to properly account for the date formats
1265
-                    $TKT->set_date_format($incoming_date_formats[0]);
1266
-                    $TKT->set_time_format($incoming_date_formats[1]);
1267
-                    $TKT->set_timezone($evtobj->get_timezone());
1268
-                    //set new values
1269
-                    foreach ($TKT_values as $field => $value) {
1270
-                        if ($field == 'TKT_qty') {
1271
-                            $TKT->set_qty($value);
1272
-                        } else {
1273
-                            $TKT->set($field, $value);
1274
-                        }
1275
-                    }
1276
-                    $update_prices = true;
1277
-                }
1278
-            }
1279
-            // cap ticket qty by datetime reg limits
1280
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1281
-            //update ticket.
1282
-            $TKT->save();
1283
-            //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1284
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1285
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1286
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1287
-                $TKT->save();
1288
-            }
1289
-            //initially let's add the ticket to the dtt
1290
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1291
-            $saved_tickets[$TKT->ID()] = $TKT;
1292
-            //add prices to ticket
1293
-            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1294
-        }
1295
-        //however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1296
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1297
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1298
-        foreach ($tickets_removed as $id) {
1299
-            $id = absint($id);
1300
-            //get the ticket for this id
1301
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1302
-            //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1303
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1304
-            foreach ($dtts as $dtt) {
1305
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1306
-            }
1307
-            //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1308
-            $tkt_to_remove->delete_related_permanently('Price');
1309
-            //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1310
-            $tkt_to_remove->delete_permanently();
1311
-        }
1312
-        return array($saved_dtt, $saved_tickets);
1313
-    }
1314
-
1315
-
1316
-
1317
-    /**
1318
-     * This attaches a list of given prices to a ticket.
1319
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1320
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1321
-     * price info and prices are automatically "archived" via the ticket.
1322
-     *
1323
-     * @access  private
1324
-     * @param array     $prices     Array of prices from the form.
1325
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1326
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1327
-     * @return  void
1328
-     */
1329
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1330
-    {
1331
-        foreach ($prices as $row => $prc) {
1332
-            $PRC_values = array(
1333
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1334
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1335
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1336
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1337
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1338
-                'PRC_is_default' => 0, //make sure prices are NOT set as default from this context
1339
-                'PRC_order'      => $row,
1340
-            );
1341
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1342
-                $PRC_values['PRC_ID'] = 0;
1343
-                $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1344
-            } else {
1345
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1346
-                //update this price with new values
1347
-                foreach ($PRC_values as $field => $newprc) {
1348
-                    $PRC->set($field, $newprc);
1349
-                }
1350
-                $PRC->save();
1351
-            }
1352
-            $ticket->_add_relation_to($PRC, 'Price');
1353
-        }
1354
-    }
1355
-
1356
-
1357
-
1358
-    /**
1359
-     * Add in our autosave ajax handlers
1360
-     *
1361
-     * @return void
1362
-     */
1363
-    protected function _ee_autosave_create_new()
1364
-    {
1365
-        // $this->_ee_autosave_edit();
1366
-    }
1367
-
1368
-
1369
-
1370
-    protected function _ee_autosave_edit()
1371
-    {
1372
-        return; //TEMPORARILY EXITING CAUSE THIS IS A TODO
1373
-    }
1374
-
1375
-
1376
-
1377
-    /**
1378
-     *    _generate_publish_box_extra_content
1379
-     *
1380
-     * @access private
1381
-     * @return void
1382
-     */
1383
-    private function _generate_publish_box_extra_content()
1384
-    {
1385
-        //load formatter helper
1386
-        //args for getting related registrations
1387
-        $approved_query_args = array(
1388
-            array(
1389
-                'REG_deleted' => 0,
1390
-                'STS_ID'      => EEM_Registration::status_id_approved,
1391
-            ),
1392
-        );
1393
-        $not_approved_query_args = array(
1394
-            array(
1395
-                'REG_deleted' => 0,
1396
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1397
-            ),
1398
-        );
1399
-        $pending_payment_query_args = array(
1400
-            array(
1401
-                'REG_deleted' => 0,
1402
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1403
-            ),
1404
-        );
1405
-        // publish box
1406
-        $publish_box_extra_args = array(
1407
-            'view_approved_reg_url'        => add_query_arg(
1408
-                array(
1409
-                    'action'      => 'default',
1410
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1411
-                    '_reg_status' => EEM_Registration::status_id_approved,
1412
-                ),
1413
-                REG_ADMIN_URL
1414
-            ),
1415
-            'view_not_approved_reg_url'    => add_query_arg(
1416
-                array(
1417
-                    'action'      => 'default',
1418
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1419
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1420
-                ),
1421
-                REG_ADMIN_URL
1422
-            ),
1423
-            'view_pending_payment_reg_url' => add_query_arg(
1424
-                array(
1425
-                    'action'      => 'default',
1426
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1427
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1428
-                ),
1429
-                REG_ADMIN_URL
1430
-            ),
1431
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1432
-                'Registration',
1433
-                $approved_query_args
1434
-            ),
1435
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1436
-                'Registration',
1437
-                $not_approved_query_args
1438
-            ),
1439
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1440
-                'Registration',
1441
-                $pending_payment_query_args
1442
-            ),
1443
-            'misc_pub_section_class'       => apply_filters(
1444
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1445
-                'misc-pub-section'
1446
-            ),
1447
-            //'email_attendees_url' => add_query_arg(
1448
-            //	array(
1449
-            //		'event_admin_reports' => 'event_newsletter',
1450
-            //		'event_id' => $this->_cpt_model_obj->id
1451
-            //	),
1452
-            //	'admin.php?page=espresso_registrations'
1453
-            //),
1454
-        );
1455
-        ob_start();
1456
-        do_action(
1457
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1458
-            $this->_cpt_model_obj
1459
-        );
1460
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1461
-        // load template
1462
-        EEH_Template::display_template(
1463
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1464
-            $publish_box_extra_args
1465
-        );
1466
-    }
1467
-
1468
-
1469
-
1470
-    /**
1471
-     * This just returns whatever is set as the _event object property
1472
-     * //todo this will become obsolete once the models are in place
1473
-     *
1474
-     * @return object
1475
-     */
1476
-    public function get_event_object()
1477
-    {
1478
-        return $this->_cpt_model_obj;
1479
-    }
1480
-
1481
-
1482
-
1483
-
1484
-    /** METABOXES * */
1485
-    /**
1486
-     * _register_event_editor_meta_boxes
1487
-     * add all metaboxes related to the event_editor
1488
-     *
1489
-     * @return void
1490
-     */
1491
-    protected function _register_event_editor_meta_boxes()
1492
-    {
1493
-        $this->verify_cpt_object();
1494
-        add_meta_box(
1495
-            'espresso_event_editor_tickets',
1496
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1497
-            array($this, 'ticket_metabox'),
1498
-            $this->page_slug,
1499
-            'normal',
1500
-            'high'
1501
-        );
1502
-        add_meta_box(
1503
-            'espresso_event_editor_event_options',
1504
-            esc_html__('Event Registration Options', 'event_espresso'),
1505
-            array($this, 'registration_options_meta_box'),
1506
-            $this->page_slug,
1507
-            'side',
1508
-            'default'
1509
-        );
1510
-        // NOTE: if you're looking for other metaboxes in here,
1511
-        // where a metabox has a related management page in the admin
1512
-        // you will find it setup in the related management page's "_Hooks" file.
1513
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1514
-    }
1515
-
1516
-
1517
-
1518
-    public function ticket_metabox()
1519
-    {
1520
-        $existing_datetime_ids = $existing_ticket_ids = array();
1521
-        //defaults for template args
1522
-        $template_args = array(
1523
-            'existing_datetime_ids'    => '',
1524
-            'event_datetime_help_link' => '',
1525
-            'ticket_options_help_link' => '',
1526
-            'time'                     => null,
1527
-            'ticket_rows'              => '',
1528
-            'existing_ticket_ids'      => '',
1529
-            'total_ticket_rows'        => 1,
1530
-            'ticket_js_structure'      => '',
1531
-            'trash_icon'               => 'ee-lock-icon',
1532
-            'disabled'                 => '',
1533
-        );
1534
-        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1535
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1536
-        /**
1537
-         * 1. Start with retrieving Datetimes
1538
-         * 2. Fore each datetime get related tickets
1539
-         * 3. For each ticket get related prices
1540
-         */
1541
-        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1542
-        /** @type EE_Datetime $first_datetime */
1543
-        $first_datetime = reset($times);
1544
-        //do we get related tickets?
1545
-        if ($first_datetime instanceof EE_Datetime
1546
-            && $first_datetime->ID() !== 0
1547
-        ) {
1548
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1549
-            $template_args['time'] = $first_datetime;
1550
-            $related_tickets = $first_datetime->tickets(
1551
-                array(
1552
-                    array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1553
-                    'default_where_conditions' => 'none',
1554
-                )
1555
-            );
1556
-            if ( ! empty($related_tickets)) {
1557
-                $template_args['total_ticket_rows'] = count($related_tickets);
1558
-                $row = 0;
1559
-                foreach ($related_tickets as $ticket) {
1560
-                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1561
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1562
-                    $row++;
1563
-                }
1564
-            } else {
1565
-                $template_args['total_ticket_rows'] = 1;
1566
-                /** @type EE_Ticket $ticket */
1567
-                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1568
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1569
-            }
1570
-        } else {
1571
-            $template_args['time'] = $times[0];
1572
-            /** @type EE_Ticket $ticket */
1573
-            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1574
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1575
-            // NOTE: we're just sending the first default row
1576
-            // (decaf can't manage default tickets so this should be sufficient);
1577
-        }
1578
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1579
-            'event_editor_event_datetimes_help_tab'
1580
-        );
1581
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1582
-        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1583
-        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1584
-        $template_args['ticket_js_structure'] = $this->_get_ticket_row(
1585
-            EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1586
-            true
1587
-        );
1588
-        $template = apply_filters(
1589
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1590
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1591
-        );
1592
-        EEH_Template::display_template($template, $template_args);
1593
-    }
1594
-
1595
-
1596
-
1597
-    /**
1598
-     * Setup an individual ticket form for the decaf event editor page
1599
-     *
1600
-     * @access private
1601
-     * @param  EE_Ticket $ticket   the ticket object
1602
-     * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1603
-     * @param int        $row
1604
-     * @return string generated html for the ticket row.
1605
-     */
1606
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1607
-    {
1608
-        $template_args = array(
1609
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1610
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1611
-                : '',
1612
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1613
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1614
-            'TKT_name'            => $ticket->get('TKT_name'),
1615
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1616
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1617
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1618
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1619
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1620
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1621
-            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1622
-                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1623
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1624
-            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1625
-                : ' disabled=disabled',
1626
-        );
1627
-        $price = $ticket->ID() !== 0
1628
-            ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1629
-            : EE_Registry::instance()->load_model('Price')->create_default_object();
1630
-        $price_args = array(
1631
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1632
-            'PRC_amount'            => $price->get('PRC_amount'),
1633
-            'PRT_ID'                => $price->get('PRT_ID'),
1634
-            'PRC_ID'                => $price->get('PRC_ID'),
1635
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1636
-        );
1637
-        //make sure we have default start and end dates if skeleton
1638
-        //handle rows that should NOT be empty
1639
-        if (empty($template_args['TKT_start_date'])) {
1640
-            //if empty then the start date will be now.
1641
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1642
-        }
1643
-        if (empty($template_args['TKT_end_date'])) {
1644
-            //get the earliest datetime (if present);
1645
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1646
-                ? $this->_cpt_model_obj->get_first_related(
1647
-                    'Datetime',
1648
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1649
-                )
1650
-                : null;
1651
-            if ( ! empty($earliest_dtt)) {
1652
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1653
-            } else {
1654
-                $template_args['TKT_end_date'] = date(
1655
-                    'Y-m-d h:i a',
1656
-                    mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1657
-                );
1658
-            }
1659
-        }
1660
-        $template_args = array_merge($template_args, $price_args);
1661
-        $template = apply_filters(
1662
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1663
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1664
-            $ticket
1665
-        );
1666
-        return EEH_Template::display_template($template, $template_args, true);
1667
-    }
1668
-
1669
-
1670
-
1671
-    public function registration_options_meta_box()
1672
-    {
1673
-        $yes_no_values = array(
1674
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1675
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1676
-        );
1677
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1678
-            array(
1679
-                EEM_Registration::status_id_cancelled,
1680
-                EEM_Registration::status_id_declined,
1681
-                EEM_Registration::status_id_incomplete,
1682
-            ),
1683
-            true
1684
-        );
1685
-        //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1686
-        $template_args['_event'] = $this->_cpt_model_obj;
1687
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1688
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1689
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1690
-            'default_reg_status',
1691
-            $default_reg_status_values,
1692
-            $this->_cpt_model_obj->default_registration_status()
1693
-        );
1694
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1695
-            'display_desc',
1696
-            $yes_no_values,
1697
-            $this->_cpt_model_obj->display_description()
1698
-        );
1699
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1700
-            'display_ticket_selector',
1701
-            $yes_no_values,
1702
-            $this->_cpt_model_obj->display_ticket_selector(),
1703
-            '',
1704
-            '',
1705
-            false
1706
-        );
1707
-        $template_args['additional_registration_options'] = apply_filters(
1708
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1709
-            '',
1710
-            $template_args,
1711
-            $yes_no_values,
1712
-            $default_reg_status_values
1713
-        );
1714
-        EEH_Template::display_template(
1715
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1716
-            $template_args
1717
-        );
1718
-    }
1719
-
1720
-
1721
-
1722
-    /**
1723
-     * _get_events()
1724
-     * This method simply returns all the events (for the given _view and paging)
1725
-     *
1726
-     * @access public
1727
-     * @param int  $per_page     count of items per page (20 default);
1728
-     * @param int  $current_page what is the current page being viewed.
1729
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1730
-     *                           If FALSE then we return an array of event objects
1731
-     *                           that match the given _view and paging parameters.
1732
-     * @return array an array of event objects.
1733
-     */
1734
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1735
-    {
1736
-        $EEME = $this->_event_model();
1737
-        $offset = ($current_page - 1) * $per_page;
1738
-        $limit = $count ? null : $offset . ',' . $per_page;
1739
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1740
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1741
-        if (isset($this->_req_data['month_range'])) {
1742
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1743
-            //simulate the FIRST day of the month, that fixes issues for months like February
1744
-            //where PHP doesn't know what to assume for date.
1745
-            //@see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1746
-            $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1747
-            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1748
-        }
1749
-        $where = array();
1750
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1751
-        //determine what post_status our condition will have for the query.
1752
-        switch ($status) {
1753
-            case 'month' :
1754
-            case 'today' :
1755
-            case null :
1756
-            case 'all' :
1757
-                break;
1758
-            case 'draft' :
1759
-                $where['status'] = array('IN', array('draft', 'auto-draft'));
1760
-                break;
1761
-            default :
1762
-                $where['status'] = $status;
1763
-        }
1764
-        //categories?
1765
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1766
-            ? $this->_req_data['EVT_CAT'] : null;
1767
-        if ( ! empty ($category)) {
1768
-            $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1769
-            $where['Term_Taxonomy.term_id'] = $category;
1770
-        }
1771
-        //date where conditions
1772
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1773
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1774
-            $DateTime = new DateTime(
1775
-                $year_r . '-' . $month_r . '-01 00:00:00',
1776
-                new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1777
-            );
1778
-            $start = $DateTime->format(implode(' ', $start_formats));
1779
-            $end = $DateTime->setDate($year_r, $month_r, $DateTime
1780
-                ->format('t'))->setTime(23, 59, 59)
1781
-                            ->format(implode(' ', $start_formats));
1782
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1783
-        } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1784
-            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1785
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1786
-            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1787
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1788
-        } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1789
-            $now = date('Y-m-01');
1790
-            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1791
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1792
-            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1793
-                            ->setTime(23, 59, 59)
1794
-                            ->format(implode(' ', $start_formats));
1795
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1796
-        }
1797
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1798
-            $where['EVT_wp_user'] = get_current_user_id();
1799
-        } else {
1800
-            if ( ! isset($where['status'])) {
1801
-                if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1802
-                    $where['OR'] = array(
1803
-                        'status*restrict_private' => array('!=', 'private'),
1804
-                        'AND'                     => array(
1805
-                            'status*inclusive' => array('=', 'private'),
1806
-                            'EVT_wp_user'      => get_current_user_id(),
1807
-                        ),
1808
-                    );
1809
-                }
1810
-            }
1811
-        }
1812
-        if (isset($this->_req_data['EVT_wp_user'])) {
1813
-            if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1814
-                && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1815
-            ) {
1816
-                $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1817
-            }
1818
-        }
1819
-        //search query handling
1820
-        if (isset($this->_req_data['s'])) {
1821
-            $search_string = '%' . $this->_req_data['s'] . '%';
1822
-            $where['OR'] = array(
1823
-                'EVT_name'       => array('LIKE', $search_string),
1824
-                'EVT_desc'       => array('LIKE', $search_string),
1825
-                'EVT_short_desc' => array('LIKE', $search_string),
1826
-            );
1827
-        }
1828
-        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1829
-        $query_params = apply_filters(
1830
-            'FHEE__Events_Admin_Page__get_events__query_params',
1831
-            array(
1832
-                $where,
1833
-                'limit'    => $limit,
1834
-                'order_by' => $orderby,
1835
-                'order'    => $order,
1836
-                'group_by' => 'EVT_ID',
1837
-            ),
1838
-            $this->_req_data
1839
-        );
1840
-        //let's first check if we have special requests coming in.
1841
-        if (isset($this->_req_data['active_status'])) {
1842
-            switch ($this->_req_data['active_status']) {
1843
-                case 'upcoming' :
1844
-                    return $EEME->get_upcoming_events($query_params, $count);
1845
-                    break;
1846
-                case 'expired' :
1847
-                    return $EEME->get_expired_events($query_params, $count);
1848
-                    break;
1849
-                case 'active' :
1850
-                    return $EEME->get_active_events($query_params, $count);
1851
-                    break;
1852
-                case 'inactive' :
1853
-                    return $EEME->get_inactive_events($query_params, $count);
1854
-                    break;
1855
-            }
1856
-        }
1857
-        $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1858
-        return $events;
1859
-    }
1860
-
1861
-
1862
-
1863
-    /**
1864
-     * handling for WordPress CPT actions (trash, restore, delete)
1865
-     *
1866
-     * @param string $post_id
1867
-     */
1868
-    public function trash_cpt_item($post_id)
1869
-    {
1870
-        $this->_req_data['EVT_ID'] = $post_id;
1871
-        $this->_trash_or_restore_event('trash', false);
1872
-    }
1873
-
1874
-
1875
-
1876
-    /**
1877
-     * @param string $post_id
1878
-     */
1879
-    public function restore_cpt_item($post_id)
1880
-    {
1881
-        $this->_req_data['EVT_ID'] = $post_id;
1882
-        $this->_trash_or_restore_event('draft', false);
1883
-    }
1884
-
1885
-
1886
-
1887
-    /**
1888
-     * @param string $post_id
1889
-     */
1890
-    public function delete_cpt_item($post_id)
1891
-    {
1892
-        $this->_req_data['EVT_ID'] = $post_id;
1893
-        $this->_delete_event(false);
1894
-    }
1895
-
1896
-
1897
-
1898
-    /**
1899
-     * _trash_or_restore_event
1900
-     *
1901
-     * @access protected
1902
-     * @param  string $event_status
1903
-     * @param bool    $redirect_after
1904
-     */
1905
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1906
-    {
1907
-        //determine the event id and set to array.
1908
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1909
-        // loop thru events
1910
-        if ($EVT_ID) {
1911
-            // clean status
1912
-            $event_status = sanitize_key($event_status);
1913
-            // grab status
1914
-            if ( ! empty($event_status)) {
1915
-                $success = $this->_change_event_status($EVT_ID, $event_status);
1916
-            } else {
1917
-                $success = false;
1918
-                $msg = esc_html__(
1919
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1920
-                    'event_espresso'
1921
-                );
1922
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1923
-            }
1924
-        } else {
1925
-            $success = false;
1926
-            $msg = esc_html__(
1927
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1928
-                'event_espresso'
1929
-            );
1930
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1931
-        }
1932
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1933
-        if ($redirect_after) {
1934
-            $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1935
-        }
1936
-    }
1937
-
1938
-
1939
-
1940
-    /**
1941
-     * _trash_or_restore_events
1942
-     *
1943
-     * @access protected
1944
-     * @param  string $event_status
1945
-     * @return void
1946
-     */
1947
-    protected function _trash_or_restore_events($event_status = 'trash')
1948
-    {
1949
-        // clean status
1950
-        $event_status = sanitize_key($event_status);
1951
-        // grab status
1952
-        if ( ! empty($event_status)) {
1953
-            $success = true;
1954
-            //determine the event id and set to array.
1955
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1956
-            // loop thru events
1957
-            foreach ($EVT_IDs as $EVT_ID) {
1958
-                if ($EVT_ID = absint($EVT_ID)) {
1959
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
1960
-                    $success = $results !== false ? $success : false;
1961
-                } else {
1962
-                    $msg = sprintf(
1963
-                        esc_html__(
1964
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1965
-                            'event_espresso'
1966
-                        ),
1967
-                        $EVT_ID
1968
-                    );
1969
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1970
-                    $success = false;
1971
-                }
1972
-            }
1973
-        } else {
1974
-            $success = false;
1975
-            $msg = esc_html__(
1976
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1977
-                'event_espresso'
1978
-            );
1979
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1980
-        }
1981
-        // in order to force a pluralized result message we need to send back a success status greater than 1
1982
-        $success = $success ? 2 : false;
1983
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1984
-        $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
1985
-    }
1986
-
1987
-
1988
-
1989
-    /**
1990
-     * _trash_or_restore_events
1991
-     *
1992
-     * @access  private
1993
-     * @param  int    $EVT_ID
1994
-     * @param  string $event_status
1995
-     * @return bool
1996
-     */
1997
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
1998
-    {
1999
-        // grab event id
2000
-        if ( ! $EVT_ID) {
2001
-            $msg = esc_html__(
2002
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2003
-                'event_espresso'
2004
-            );
2005
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2006
-            return false;
2007
-        }
2008
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2009
-        // clean status
2010
-        $event_status = sanitize_key($event_status);
2011
-        // grab status
2012
-        if (empty($event_status)) {
2013
-            $msg = esc_html__(
2014
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2015
-                'event_espresso'
2016
-            );
2017
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2018
-            return false;
2019
-        }
2020
-        // was event trashed or restored ?
2021
-        switch ($event_status) {
2022
-            case 'draft' :
2023
-                $action = 'restored from the trash';
2024
-                $hook = 'AHEE_event_restored_from_trash';
2025
-                break;
2026
-            case 'trash' :
2027
-                $action = 'moved to the trash';
2028
-                $hook = 'AHEE_event_moved_to_trash';
2029
-                break;
2030
-            default :
2031
-                $action = 'updated';
2032
-                $hook = false;
2033
-        }
2034
-        //use class to change status
2035
-        $this->_cpt_model_obj->set_status($event_status);
2036
-        $success = $this->_cpt_model_obj->save();
2037
-        if ($success === false) {
2038
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2039
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2040
-            return false;
2041
-        }
2042
-        if ($hook) {
2043
-            do_action($hook);
2044
-        }
2045
-        return true;
2046
-    }
2047
-
2048
-
2049
-
2050
-    /**
2051
-     * _delete_event
2052
-     *
2053
-     * @access protected
2054
-     * @param bool $redirect_after
2055
-     */
2056
-    protected function _delete_event($redirect_after = true)
2057
-    {
2058
-        //determine the event id and set to array.
2059
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2060
-        $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2061
-        // loop thru events
2062
-        if ($EVT_ID) {
2063
-            $success = $this->_permanently_delete_event($EVT_ID);
2064
-            // get list of events with no prices
2065
-            $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2066
-            // remove this event from the list of events with no prices
2067
-            if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2068
-                unset($espresso_no_ticket_prices[$EVT_ID]);
2069
-            }
2070
-            update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2071
-        } else {
2072
-            $success = false;
2073
-            $msg = esc_html__(
2074
-                'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2075
-                'event_espresso'
2076
-            );
2077
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2078
-        }
2079
-        if ($redirect_after) {
2080
-            $this->_redirect_after_action(
2081
-                $success,
2082
-                'Event',
2083
-                'deleted',
2084
-                array('action' => 'default', 'status' => 'trash')
2085
-            );
2086
-        }
2087
-    }
2088
-
2089
-
2090
-
2091
-    /**
2092
-     * _delete_events
2093
-     *
2094
-     * @access protected
2095
-     * @return void
2096
-     */
2097
-    protected function _delete_events()
2098
-    {
2099
-        $success = true;
2100
-        // get list of events with no prices
2101
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2102
-        //determine the event id and set to array.
2103
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2104
-        // loop thru events
2105
-        foreach ($EVT_IDs as $EVT_ID) {
2106
-            $EVT_ID = absint($EVT_ID);
2107
-            if ($EVT_ID) {
2108
-                $results = $this->_permanently_delete_event($EVT_ID);
2109
-                $success = $results !== false ? $success : false;
2110
-                // remove this event from the list of events with no prices
2111
-                unset($espresso_no_ticket_prices[$EVT_ID]);
2112
-            } else {
2113
-                $success = false;
2114
-                $msg = esc_html__(
2115
-                    'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2116
-                    'event_espresso'
2117
-                );
2118
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2119
-            }
2120
-        }
2121
-        update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2122
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2123
-        $success = $success ? 2 : false;
2124
-        $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2125
-    }
2126
-
2127
-
2128
-
2129
-    /**
2130
-     * _permanently_delete_event
2131
-     *
2132
-     * @access  private
2133
-     * @param  int $EVT_ID
2134
-     * @return bool
2135
-     */
2136
-    private function _permanently_delete_event($EVT_ID = 0)
2137
-    {
2138
-        // grab event id
2139
-        if ( ! $EVT_ID) {
2140
-            $msg = esc_html__(
2141
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2142
-                'event_espresso'
2143
-            );
2144
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2145
-            return false;
2146
-        }
2147
-        if (
2148
-            ! $this->_cpt_model_obj instanceof EE_Event
2149
-            || $this->_cpt_model_obj->ID() !== $EVT_ID
2150
-        ) {
2151
-            $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2152
-        }
2153
-        if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2154
-            return false;
2155
-        }
2156
-        //need to delete related tickets and prices first.
2157
-        $datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2158
-        foreach ($datetimes as $datetime) {
2159
-            $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2160
-            $tickets = $datetime->get_many_related('Ticket');
2161
-            foreach ($tickets as $ticket) {
2162
-                $ticket->_remove_relation_to($datetime, 'Datetime');
2163
-                $ticket->delete_related_permanently('Price');
2164
-                $ticket->delete_permanently();
2165
-            }
2166
-            $datetime->delete();
2167
-        }
2168
-        //what about related venues or terms?
2169
-        $venues = $this->_cpt_model_obj->get_many_related('Venue');
2170
-        foreach ($venues as $venue) {
2171
-            $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2172
-        }
2173
-        //any attached question groups?
2174
-        $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2175
-        if ( ! empty($question_groups)) {
2176
-            foreach ($question_groups as $question_group) {
2177
-                $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2178
-            }
2179
-        }
2180
-        //Message Template Groups
2181
-        $this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2182
-        /** @type EE_Term_Taxonomy[] $term_taxonomies */
2183
-        $term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2184
-        foreach ($term_taxonomies as $term_taxonomy) {
2185
-            $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2186
-        }
2187
-        $success = $this->_cpt_model_obj->delete_permanently();
2188
-        // did it all go as planned ?
2189
-        if ($success) {
2190
-            $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2191
-            EE_Error::add_success($msg);
2192
-        } else {
2193
-            $msg = sprintf(
2194
-                esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2195
-                $EVT_ID
2196
-            );
2197
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2198
-            return false;
2199
-        }
2200
-        do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2201
-        return true;
2202
-    }
2203
-
2204
-
2205
-
2206
-    /**
2207
-     * get total number of events
2208
-     *
2209
-     * @access public
2210
-     * @return int
2211
-     */
2212
-    public function total_events()
2213
-    {
2214
-        $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2215
-        return $count;
2216
-    }
2217
-
2218
-
2219
-
2220
-    /**
2221
-     * get total number of draft events
2222
-     *
2223
-     * @access public
2224
-     * @return int
2225
-     */
2226
-    public function total_events_draft()
2227
-    {
2228
-        $where = array(
2229
-            'status' => array('IN', array('draft', 'auto-draft')),
2230
-        );
2231
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2232
-        return $count;
2233
-    }
2234
-
2235
-
2236
-
2237
-    /**
2238
-     * get total number of trashed events
2239
-     *
2240
-     * @access public
2241
-     * @return int
2242
-     */
2243
-    public function total_trashed_events()
2244
-    {
2245
-        $where = array(
2246
-            'status' => 'trash',
2247
-        );
2248
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2249
-        return $count;
2250
-    }
2251
-
2252
-
2253
-
2254
-    /**
2255
-     *    _default_event_settings
2256
-     *    This generates the Default Settings Tab
2257
-     *
2258
-     * @return void
2259
-     */
2260
-    protected function _default_event_settings()
2261
-    {
2262
-        $this->_template_args['values'] = $this->_yes_no_values;
2263
-        $this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array(
2264
-        // exclude array
2265
-            array(
2266
-                EEM_Registration::status_id_cancelled,
2267
-                EEM_Registration::status_id_declined,
2268
-                EEM_Registration::status_id_incomplete,
2269
-                EEM_Registration::status_id_wait_list,
2270
-            ),
2271
-            // translated
2272
-            true
2273
-        );
2274
-        $this->_template_args['default_reg_status'] = isset(
2275
-                                                          EE_Registry::instance()->CFG->registration->default_STS_ID
2276
-                                                      )
2277
-                                                      && array_key_exists(
2278
-                                                          EE_Registry::instance()->CFG->registration->default_STS_ID,
2279
-                                                          $this->_template_args['reg_status_array']
2280
-                                                      )
2281
-            ? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID)
2282
-            : EEM_Registration::status_id_pending_payment;
2283
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2284
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2285
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2286
-            EVENTS_TEMPLATE_PATH . 'event_settings.template.php',
2287
-            $this->_template_args,
2288
-            true
2289
-        );
2290
-        $this->display_admin_page_with_sidebar();
2291
-    }
2292
-
2293
-
2294
-
2295
-    /**
2296
-     * _update_default_event_settings
2297
-     *
2298
-     * @access protected
2299
-     * @return void
2300
-     */
2301
-    protected function _update_default_event_settings()
2302
-    {
2303
-        EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status'])
2304
-            ? sanitize_text_field($this->_req_data['default_reg_status'])
2305
-            : EEM_Registration::status_id_pending_payment;
2306
-        $what = 'Default Event Settings';
2307
-        $success = $this->_update_espresso_configuration(
2308
-            $what,
2309
-            EE_Config::instance(),
2310
-            __FILE__,
2311
-            __FUNCTION__,
2312
-            __LINE__
2313
-        );
2314
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings'));
2315
-    }
2316
-
2317
-
2318
-
2319
-    /*************        Templates        *************/
2320
-    protected function _template_settings()
2321
-    {
2322
-        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2323
-        $this->_template_args['preview_img'] = '<img src="'
2324
-                                               . EVENTS_ASSETS_URL
2325
-                                               . DS
2326
-                                               . 'images'
2327
-                                               . DS
2328
-                                               . 'caffeinated_template_features.jpg" alt="'
2329
-                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2330
-                                               . '" />';
2331
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__(
2332
-                'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2333
-                'event_espresso'
2334
-            ) . '</strong>';
2335
-        $this->display_admin_caf_preview_page('template_settings_tab');
2336
-    }
2337
-
2338
-
2339
-    /** Event Category Stuff **/
2340
-    /**
2341
-     * set the _category property with the category object for the loaded page.
2342
-     *
2343
-     * @access private
2344
-     * @return void
2345
-     */
2346
-    private function _set_category_object()
2347
-    {
2348
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2349
-            return;
2350
-        } //already have the category object so get out.
2351
-        //set default category object
2352
-        $this->_set_empty_category_object();
2353
-        //only set if we've got an id
2354
-        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2355
-            return;
2356
-        }
2357
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2358
-        $term = get_term($category_id, 'espresso_event_categories');
2359
-        if ( ! empty($term)) {
2360
-            $this->_category->category_name = $term->name;
2361
-            $this->_category->category_identifier = $term->slug;
2362
-            $this->_category->category_desc = $term->description;
2363
-            $this->_category->id = $term->term_id;
2364
-            $this->_category->parent = $term->parent;
2365
-        }
2366
-    }
2367
-
2368
-
2369
-
2370
-    private function _set_empty_category_object()
2371
-    {
2372
-        $this->_category = new stdClass();
2373
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2374
-        $this->_category->id = $this->_category->parent = 0;
2375
-    }
2376
-
2377
-
2378
-
2379
-    protected function _category_list_table()
2380
-    {
2381
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2382
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2383
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2384
-                'add_category',
2385
-                'add_category',
2386
-                array(),
2387
-                'add-new-h2'
2388
-            );
2389
-        $this->display_admin_list_table_page_with_sidebar();
2390
-    }
2391
-
2392
-
2393
-
2394
-    /**
2395
-     * @param $view
2396
-     */
2397
-    protected function _category_details($view)
2398
-    {
2399
-        //load formatter helper
2400
-        //load field generator helper
2401
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2402
-        $this->_set_add_edit_form_tags($route);
2403
-        $this->_set_category_object();
2404
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2405
-        $delete_action = 'delete_category';
2406
-        //custom redirect
2407
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2408
-            array('action' => 'category_list'),
2409
-            $this->_admin_base_url
2410
-        );
2411
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2412
-        //take care of contents
2413
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2414
-        $this->display_admin_page_with_sidebar();
2415
-    }
2416
-
2417
-
2418
-
2419
-    /**
2420
-     * @return mixed
2421
-     */
2422
-    protected function _category_details_content()
2423
-    {
2424
-        $editor_args['category_desc'] = array(
2425
-            'type'          => 'wp_editor',
2426
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2427
-            'class'         => 'my_editor_custom',
2428
-            'wpeditor_args' => array('media_buttons' => false),
2429
-        );
2430
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2431
-        $all_terms = get_terms(
2432
-            array('espresso_event_categories'),
2433
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2434
-        );
2435
-        //setup category select for term parents.
2436
-        $category_select_values[] = array(
2437
-            'text' => esc_html__('No Parent', 'event_espresso'),
2438
-            'id'   => 0,
2439
-        );
2440
-        foreach ($all_terms as $term) {
2441
-            $category_select_values[] = array(
2442
-                'text' => $term->name,
2443
-                'id'   => $term->term_id,
2444
-            );
2445
-        }
2446
-        $category_select = EEH_Form_Fields::select_input(
2447
-            'category_parent',
2448
-            $category_select_values,
2449
-            $this->_category->parent
2450
-        );
2451
-        $template_args = array(
2452
-            'category'                 => $this->_category,
2453
-            'category_select'          => $category_select,
2454
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2455
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2456
-            'disable'                  => '',
2457
-            'disabled_message'         => false,
2458
-        );
2459
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2460
-        return EEH_Template::display_template($template, $template_args, true);
2461
-    }
2462
-
2463
-
2464
-
2465
-    protected function _delete_categories()
2466
-    {
2467
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2468
-            : (array)$this->_req_data['category_id'];
2469
-        foreach ($cat_ids as $cat_id) {
2470
-            $this->_delete_category($cat_id);
2471
-        }
2472
-        //doesn't matter what page we're coming from... we're going to the same place after delete.
2473
-        $query_args = array(
2474
-            'action' => 'category_list',
2475
-        );
2476
-        $this->_redirect_after_action(0, '', '', $query_args);
2477
-    }
2478
-
2479
-
2480
-
2481
-    /**
2482
-     * @param $cat_id
2483
-     */
2484
-    protected function _delete_category($cat_id)
2485
-    {
2486
-        $cat_id = absint($cat_id);
2487
-        wp_delete_term($cat_id, 'espresso_event_categories');
2488
-    }
2489
-
2490
-
2491
-
2492
-    /**
2493
-     * @param $new_category
2494
-     */
2495
-    protected function _insert_or_update_category($new_category)
2496
-    {
2497
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2498
-        $success = 0; //we already have a success message so lets not send another.
2499
-        if ($cat_id) {
2500
-            $query_args = array(
2501
-                'action'     => 'edit_category',
2502
-                'EVT_CAT_ID' => $cat_id,
2503
-            );
2504
-        } else {
2505
-            $query_args = array('action' => 'add_category');
2506
-        }
2507
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2508
-    }
2509
-
2510
-
2511
-
2512
-    /**
2513
-     * @param bool $update
2514
-     * @return bool|mixed|string
2515
-     */
2516
-    private function _insert_category($update = false)
2517
-    {
2518
-        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2519
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2520
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2521
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2522
-        if (empty($category_name)) {
2523
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2524
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2525
-            return false;
2526
-        }
2527
-        $term_args = array(
2528
-            'name'        => $category_name,
2529
-            'description' => $category_desc,
2530
-            'parent'      => $category_parent,
2531
-        );
2532
-        //was the category_identifier input disabled?
2533
-        if (isset($this->_req_data['category_identifier'])) {
2534
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2535
-        }
2536
-        $insert_ids = $update
2537
-            ? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2538
-            : wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2539
-        if ( ! is_array($insert_ids)) {
2540
-            $msg = esc_html__(
2541
-                'An error occurred and the category has not been saved to the database.',
2542
-                'event_espresso'
2543
-            );
2544
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2545
-        } else {
2546
-            $cat_id = $insert_ids['term_id'];
2547
-            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2548
-            EE_Error::add_success($msg);
2549
-        }
2550
-        return $cat_id;
2551
-    }
2552
-
2553
-
2554
-
2555
-    /**
2556
-     * @param int  $per_page
2557
-     * @param int  $current_page
2558
-     * @param bool $count
2559
-     * @return \EE_Base_Class[]|int
2560
-     */
2561
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2562
-    {
2563
-        //testing term stuff
2564
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2565
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2566
-        $limit = ($current_page - 1) * $per_page;
2567
-        $where = array('taxonomy' => 'espresso_event_categories');
2568
-        if (isset($this->_req_data['s'])) {
2569
-            $sstr = '%' . $this->_req_data['s'] . '%';
2570
-            $where['OR'] = array(
2571
-                'Term.name'   => array('LIKE', $sstr),
2572
-                'description' => array('LIKE', $sstr),
2573
-            );
2574
-        }
2575
-        $query_params = array(
2576
-            $where,
2577
-            'order_by'   => array($orderby => $order),
2578
-            'limit'      => $limit . ',' . $per_page,
2579
-            'force_join' => array('Term'),
2580
-        );
2581
-        $categories = $count
2582
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2583
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2584
-        return $categories;
2585
-    }
2586
-
2587
-
2588
-
2589
-    /* end category stuff */
2590
-    /**************/
385
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
386
+				'require_nonce' => false,
387
+			),
388
+			'default_event_settings' => array(
389
+				'nav'           => array(
390
+					'label' => esc_html__('Default Settings', 'event_espresso'),
391
+					'order' => 40,
392
+				),
393
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
394
+				'labels'        => array(
395
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
396
+				),
397
+				'help_tabs'     => array(
398
+					'default_settings_help_tab'        => array(
399
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
400
+						'filename' => 'events_default_settings',
401
+					),
402
+					'default_settings_status_help_tab' => array(
403
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
404
+						'filename' => 'events_default_settings_status',
405
+					),
406
+				),
407
+				'help_tour'     => array('Event_Default_Settings_Help_Tour'),
408
+				'require_nonce' => false,
409
+			),
410
+			//template settings
411
+			'template_settings'      => array(
412
+				'nav'           => array(
413
+					'label' => esc_html__('Templates', 'event_espresso'),
414
+					'order' => 30,
415
+				),
416
+				'metaboxes'     => $this->_default_espresso_metaboxes,
417
+				'help_tabs'     => array(
418
+					'general_settings_templates_help_tab' => array(
419
+						'title'    => esc_html__('Templates', 'event_espresso'),
420
+						'filename' => 'general_settings_templates',
421
+					),
422
+				),
423
+				'help_tour'     => array('Templates_Help_Tour'),
424
+				'require_nonce' => false,
425
+			),
426
+			//event category stuff
427
+			'add_category'           => array(
428
+				'nav'           => array(
429
+					'label'      => esc_html__('Add Category', 'event_espresso'),
430
+					'order'      => 15,
431
+					'persistent' => false,
432
+				),
433
+				'help_tabs'     => array(
434
+					'add_category_help_tab' => array(
435
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
436
+						'filename' => 'events_add_category',
437
+					),
438
+				),
439
+				'help_tour'     => array('Event_Add_Category_Help_Tour'),
440
+				'metaboxes'     => array('_publish_post_box'),
441
+				'require_nonce' => false,
442
+			),
443
+			'edit_category'          => array(
444
+				'nav'           => array(
445
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
446
+					'order'      => 15,
447
+					'persistent' => false,
448
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
449
+						? add_query_arg(
450
+							array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
451
+							$this->_current_page_view_url
452
+						)
453
+						: $this->_admin_base_url,
454
+				),
455
+				'help_tabs'     => array(
456
+					'edit_category_help_tab' => array(
457
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
458
+						'filename' => 'events_edit_category',
459
+					),
460
+				),
461
+				/*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
462
+				'metaboxes'     => array('_publish_post_box'),
463
+				'require_nonce' => false,
464
+			),
465
+			'category_list'          => array(
466
+				'nav'           => array(
467
+					'label' => esc_html__('Categories', 'event_espresso'),
468
+					'order' => 20,
469
+				),
470
+				'list_table'    => 'Event_Categories_Admin_List_Table',
471
+				'help_tabs'     => array(
472
+					'events_categories_help_tab'                       => array(
473
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
474
+						'filename' => 'events_categories',
475
+					),
476
+					'events_categories_table_column_headings_help_tab' => array(
477
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
478
+						'filename' => 'events_categories_table_column_headings',
479
+					),
480
+					'events_categories_view_help_tab'                  => array(
481
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
482
+						'filename' => 'events_categories_views',
483
+					),
484
+					'events_categories_other_help_tab'                 => array(
485
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
486
+						'filename' => 'events_categories_other',
487
+					),
488
+				),
489
+				'help_tour'     => array(
490
+					'Event_Categories_Help_Tour',
491
+				),
492
+				'metaboxes'     => $this->_default_espresso_metaboxes,
493
+				'require_nonce' => false,
494
+			),
495
+		);
496
+	}
497
+
498
+
499
+
500
+	protected function _add_screen_options()
501
+	{
502
+		//todo
503
+	}
504
+
505
+
506
+
507
+	protected function _add_screen_options_default()
508
+	{
509
+		$this->_per_page_screen_option();
510
+	}
511
+
512
+
513
+
514
+	protected function _add_screen_options_category_list()
515
+	{
516
+		$page_title = $this->_admin_page_title;
517
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
518
+		$this->_per_page_screen_option();
519
+		$this->_admin_page_title = $page_title;
520
+	}
521
+
522
+
523
+
524
+	protected function _add_feature_pointers()
525
+	{
526
+		//todo
527
+	}
528
+
529
+
530
+
531
+	public function load_scripts_styles()
532
+	{
533
+		wp_register_style(
534
+			'events-admin-css',
535
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
536
+			array(),
537
+			EVENT_ESPRESSO_VERSION
538
+		);
539
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
540
+		wp_enqueue_style('events-admin-css');
541
+		wp_enqueue_style('ee-cat-admin');
542
+		//todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
543
+		//registers for all views
544
+		//scripts
545
+		wp_register_script(
546
+			'event_editor_js',
547
+			EVENTS_ASSETS_URL . 'event_editor.js',
548
+			array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
549
+			EVENT_ESPRESSO_VERSION,
550
+			true
551
+		);
552
+	}
553
+
554
+
555
+
556
+	/**
557
+	 * enqueuing scripts and styles specific to this view
558
+	 *
559
+	 * @return void
560
+	 */
561
+	public function load_scripts_styles_create_new()
562
+	{
563
+		$this->load_scripts_styles_edit();
564
+	}
565
+
566
+
567
+
568
+	/**
569
+	 * enqueuing scripts and styles specific to this view
570
+	 *
571
+	 * @return void
572
+	 */
573
+	public function load_scripts_styles_edit()
574
+	{
575
+		//styles
576
+		wp_enqueue_style('espresso-ui-theme');
577
+		wp_register_style(
578
+			'event-editor-css',
579
+			EVENTS_ASSETS_URL . 'event-editor.css',
580
+			array('ee-admin-css'),
581
+			EVENT_ESPRESSO_VERSION
582
+		);
583
+		wp_enqueue_style('event-editor-css');
584
+		//scripts
585
+		wp_register_script(
586
+			'event-datetime-metabox',
587
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
588
+			array('event_editor_js', 'ee-datepicker'),
589
+			EVENT_ESPRESSO_VERSION
590
+		);
591
+		wp_enqueue_script('event-datetime-metabox');
592
+	}
593
+
594
+
595
+
596
+	public function load_scripts_styles_add_category()
597
+	{
598
+		$this->load_scripts_styles_edit_category();
599
+	}
600
+
601
+
602
+
603
+	public function load_scripts_styles_edit_category()
604
+	{
605
+	}
606
+
607
+
608
+
609
+	protected function _set_list_table_views_category_list()
610
+	{
611
+		$this->_views = array(
612
+			'all' => array(
613
+				'slug'        => 'all',
614
+				'label'       => esc_html__('All', 'event_espresso'),
615
+				'count'       => 0,
616
+				'bulk_action' => array(
617
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
618
+				),
619
+			),
620
+		);
621
+	}
622
+
623
+
624
+
625
+	public function admin_init()
626
+	{
627
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
628
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
629
+			'event_espresso'
630
+		);
631
+	}
632
+
633
+
634
+
635
+	//nothing needed for events with these methods.
636
+	public function admin_notices()
637
+	{
638
+	}
639
+
640
+
641
+
642
+	public function admin_footer_scripts()
643
+	{
644
+	}
645
+
646
+
647
+
648
+	/**
649
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
650
+	 * warning (via EE_Error::add_error());
651
+	 *
652
+	 * @param  EE_Event $event Event object
653
+	 * @access public
654
+	 * @return void
655
+	 */
656
+	public function verify_event_edit($event = null)
657
+	{
658
+		// no event?
659
+		if (empty($event)) {
660
+			// set event
661
+			$event = $this->_cpt_model_obj;
662
+		}
663
+		// STILL no event?
664
+		if (empty ($event)) {
665
+			return;
666
+		}
667
+		$orig_status = $event->status();
668
+		// first check if event is active.
669
+		if (
670
+			$orig_status === EEM_Event::cancelled
671
+			|| $orig_status === EEM_Event::postponed
672
+			|| $event->is_expired()
673
+			|| $event->is_inactive()
674
+		) {
675
+			return;
676
+		}
677
+		//made it here so it IS active... next check that any of the tickets are sold.
678
+		if ($event->is_sold_out(true)) {
679
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
680
+				EE_Error::add_attention(
681
+					sprintf(
682
+						esc_html__(
683
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
684
+							'event_espresso'
685
+						),
686
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
687
+					)
688
+				);
689
+			}
690
+			return;
691
+		} else if ($orig_status === EEM_Event::sold_out) {
692
+			EE_Error::add_attention(
693
+				sprintf(
694
+					esc_html__(
695
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
696
+						'event_espresso'
697
+					),
698
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
699
+				)
700
+			);
701
+		}
702
+		//now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
703
+		if ( ! $event->tickets_on_sale()) {
704
+			return;
705
+		}
706
+		//made it here so show warning
707
+		$this->_edit_event_warning();
708
+	}
709
+
710
+
711
+
712
+	/**
713
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
714
+	 * When needed, hook this into a EE_Error::add_error() notice.
715
+	 *
716
+	 * @access protected
717
+	 * @return void
718
+	 */
719
+	protected function _edit_event_warning()
720
+	{
721
+		// we don't want to add warnings during these requests
722
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
723
+			return;
724
+		}
725
+		EE_Error::add_attention(
726
+			esc_html__(
727
+				'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.',
728
+				'event_espresso'
729
+			)
730
+		);
731
+	}
732
+
733
+
734
+
735
+	/**
736
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
737
+	 * Otherwise, do the normal logic
738
+	 *
739
+	 * @return string
740
+	 * @throws \EE_Error
741
+	 */
742
+	protected function _create_new_cpt_item()
743
+	{
744
+		$gmt_offset = get_option('gmt_offset');
745
+		//only nag them about setting their timezone if it's their first event, and they haven't already done it
746
+		if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) {
747
+			EE_Error::add_attention(
748
+				sprintf(
749
+					__(
750
+						'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.',
751
+						'event_espresso'
752
+					),
753
+					'<a href="' . admin_url('options-general.php') . '">',
754
+					'</a>'
755
+				),
756
+				__FILE__,
757
+				__FUNCTION__,
758
+				__LINE__
759
+			);
760
+		}
761
+		return parent::_create_new_cpt_item();
762
+	}
763
+
764
+
765
+
766
+	protected function _set_list_table_views_default()
767
+	{
768
+		$this->_views = array(
769
+			'all'   => array(
770
+				'slug'        => 'all',
771
+				'label'       => esc_html__('View All Events', 'event_espresso'),
772
+				'count'       => 0,
773
+				'bulk_action' => array(
774
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
775
+				),
776
+			),
777
+			'draft' => array(
778
+				'slug'        => 'draft',
779
+				'label'       => esc_html__('Draft', 'event_espresso'),
780
+				'count'       => 0,
781
+				'bulk_action' => array(
782
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
783
+				),
784
+			),
785
+		);
786
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
787
+			$this->_views['trash'] = array(
788
+				'slug'        => 'trash',
789
+				'label'       => esc_html__('Trash', 'event_espresso'),
790
+				'count'       => 0,
791
+				'bulk_action' => array(
792
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
793
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
794
+				),
795
+			);
796
+		}
797
+	}
798
+
799
+
800
+
801
+	/**
802
+	 * @return array
803
+	 */
804
+	protected function _event_legend_items()
805
+	{
806
+		$items = array(
807
+			'view_details'   => array(
808
+				'class' => 'dashicons dashicons-search',
809
+				'desc'  => esc_html__('View Event', 'event_espresso'),
810
+			),
811
+			'edit_event'     => array(
812
+				'class' => 'ee-icon ee-icon-calendar-edit',
813
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
814
+			),
815
+			'view_attendees' => array(
816
+				'class' => 'dashicons dashicons-groups',
817
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
818
+			),
819
+		);
820
+		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
821
+		$statuses = array(
822
+			'sold_out_status'  => array(
823
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
824
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
825
+			),
826
+			'active_status'    => array(
827
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
828
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
829
+			),
830
+			'upcoming_status'  => array(
831
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
832
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
833
+			),
834
+			'postponed_status' => array(
835
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
836
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
837
+			),
838
+			'cancelled_status' => array(
839
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
840
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
841
+			),
842
+			'expired_status'   => array(
843
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
844
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
845
+			),
846
+			'inactive_status'  => array(
847
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
848
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
849
+			),
850
+		);
851
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
852
+		return array_merge($items, $statuses);
853
+	}
854
+
855
+
856
+
857
+	/**
858
+	 * _event_model
859
+	 *
860
+	 * @return EEM_Event
861
+	 */
862
+	private function _event_model()
863
+	{
864
+		if ( ! $this->_event_model instanceof EEM_Event) {
865
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
866
+		}
867
+		return $this->_event_model;
868
+	}
869
+
870
+
871
+
872
+	/**
873
+	 * Adds extra buttons to the WP CPT permalink field row.
874
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
875
+	 *
876
+	 * @param  string $return    the current html
877
+	 * @param  int    $id        the post id for the page
878
+	 * @param  string $new_title What the title is
879
+	 * @param  string $new_slug  what the slug is
880
+	 * @return string            The new html string for the permalink area
881
+	 */
882
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
883
+	{
884
+		//make sure this is only when editing
885
+		if ( ! empty($id)) {
886
+			$post = get_post($id);
887
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
888
+					   . esc_html__('Shortcode', 'event_espresso')
889
+					   . '</a> ';
890
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
891
+					   . $post->ID
892
+					   . ']">';
893
+		}
894
+		return $return;
895
+	}
896
+
897
+
898
+
899
+	/**
900
+	 * _events_overview_list_table
901
+	 * This contains the logic for showing the events_overview list
902
+	 *
903
+	 * @access protected
904
+	 * @return void
905
+	 * @throws \EE_Error
906
+	 */
907
+	protected function _events_overview_list_table()
908
+	{
909
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
910
+		$this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
911
+			? (array)$this->_template_args['after_list_table']
912
+			: array();
913
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
914
+																			  . EEH_Template::get_button_or_link(
915
+				get_post_type_archive_link('espresso_events'),
916
+				esc_html__("View Event Archive Page", "event_espresso"),
917
+				'button'
918
+			);
919
+		$this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
920
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
921
+				'create_new',
922
+				'add',
923
+				array(),
924
+				'add-new-h2'
925
+			);
926
+		$this->display_admin_list_table_page_with_no_sidebar();
927
+	}
928
+
929
+
930
+
931
+	/**
932
+	 * this allows for extra misc actions in the default WP publish box
933
+	 *
934
+	 * @return void
935
+	 */
936
+	public function extra_misc_actions_publish_box()
937
+	{
938
+		$this->_generate_publish_box_extra_content();
939
+	}
940
+
941
+
942
+
943
+	/**
944
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
945
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
946
+	 * data.
947
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
948
+	 * ALSO very important.  When a post transitions from scheduled to published, the save_post action is fired but you
949
+	 * will NOT have any _POST data containing any extra info you may have from other meta saves.  So MAKE sure that
950
+	 * you handle this accordingly.
951
+	 *
952
+	 * @access protected
953
+	 * @abstract
954
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
955
+	 * @param  object $post    The post object of the cpt that was saved.
956
+	 * @return void
957
+	 */
958
+	protected function _insert_update_cpt_item($post_id, $post)
959
+	{
960
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
961
+			//get out we're not processing an event save.
962
+			return;
963
+		}
964
+		$event_values = array(
965
+			'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
966
+			'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
967
+			'EVT_additional_limit'            => min(
968
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
969
+				! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
970
+			),
971
+			'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
972
+				? $this->_req_data['EVT_default_registration_status']
973
+				: EE_Registry::instance()->CFG->registration->default_STS_ID,
974
+			'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
975
+			'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
976
+			'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
977
+				? $this->_req_data['timezone_string'] : null,
978
+			'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
979
+				? $this->_req_data['externalURL'] : null,
980
+			'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
981
+				? $this->_req_data['event_phone'] : null,
982
+		);
983
+		//update event
984
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
985
+		//get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
986
+		$get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status);
987
+		$event = $this->_event_model()->get_one(array($get_one_where));
988
+		//the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
989
+		$event_update_callbacks = apply_filters(
990
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
991
+			array(array($this, '_default_venue_update'), array($this, '_default_tickets_update'))
992
+		);
993
+		$att_success = true;
994
+		foreach ($event_update_callbacks as $e_callback) {
995
+			$_succ = call_user_func_array($e_callback, array($event, $this->_req_data));
996
+			$att_success = ! $att_success ? $att_success
997
+				: $_succ; //if ANY of these updates fail then we want the appropriate global error message
998
+		}
999
+		//any errors?
1000
+		if ($success && false === $att_success) {
1001
+			EE_Error::add_error(
1002
+				esc_html__(
1003
+					'Event Details saved successfully but something went wrong with saving attachments.',
1004
+					'event_espresso'
1005
+				),
1006
+				__FILE__,
1007
+				__FUNCTION__,
1008
+				__LINE__
1009
+			);
1010
+		} else if ($success === false) {
1011
+			EE_Error::add_error(
1012
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1013
+				__FILE__,
1014
+				__FUNCTION__,
1015
+				__LINE__
1016
+			);
1017
+		}
1018
+	}
1019
+
1020
+
1021
+
1022
+	/**
1023
+	 * @see parent::restore_item()
1024
+	 * @param int $post_id
1025
+	 * @param int $revision_id
1026
+	 */
1027
+	protected function _restore_cpt_item($post_id, $revision_id)
1028
+	{
1029
+		//copy existing event meta to new post
1030
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1031
+		if ($post_evt instanceof EE_Event) {
1032
+			//meta revision restore
1033
+			$post_evt->restore_revision($revision_id);
1034
+			//related objs restore
1035
+			$post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1036
+		}
1037
+	}
1038
+
1039
+
1040
+
1041
+	/**
1042
+	 * Attach the venue to the Event
1043
+	 *
1044
+	 * @param  \EE_Event $evtobj Event Object to add the venue to
1045
+	 * @param  array     $data   The request data from the form
1046
+	 * @return bool           Success or fail.
1047
+	 */
1048
+	protected function _default_venue_update(\EE_Event $evtobj, $data)
1049
+	{
1050
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1051
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1052
+		$rows_affected = null;
1053
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1054
+		// very important.  If we don't have a venue name...
1055
+		// then we'll get out because not necessary to create empty venue
1056
+		if (empty($data['venue_title'])) {
1057
+			return false;
1058
+		}
1059
+		$venue_array = array(
1060
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1061
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1062
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1063
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1064
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1065
+				: null,
1066
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1067
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1068
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1069
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1070
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1071
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1072
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1073
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1074
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1075
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1076
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1077
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1078
+			'status'              => 'publish',
1079
+		);
1080
+		//if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1081
+		if ( ! empty($venue_id)) {
1082
+			$update_where = array($venue_model->primary_key_name() => $venue_id);
1083
+			$rows_affected = $venue_model->update($venue_array, array($update_where));
1084
+			//we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1085
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1086
+			return $rows_affected > 0 ? true : false;
1087
+		} else {
1088
+			//we insert the venue
1089
+			$venue_id = $venue_model->insert($venue_array);
1090
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1091
+			return ! empty($venue_id) ? true : false;
1092
+		}
1093
+		//when we have the ancestor come in it's already been handled by the revision save.
1094
+	}
1095
+
1096
+
1097
+
1098
+	/**
1099
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1100
+	 *
1101
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
1102
+	 * @param  array    $data   The request data from the form
1103
+	 * @return array
1104
+	 */
1105
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1106
+	{
1107
+		$success = true;
1108
+		$saved_dtt = null;
1109
+		$saved_tickets = array();
1110
+		$incoming_date_formats = array('Y-m-d', 'h:i a');
1111
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1112
+			//trim all values to ensure any excess whitespace is removed.
1113
+			$dtt = array_map('trim', $dtt);
1114
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1115
+				: $dtt['DTT_EVT_start'];
1116
+			$datetime_values = array(
1117
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1118
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1119
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1120
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1121
+				'DTT_order'     => $row,
1122
+			);
1123
+			//if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1124
+			if ( ! empty($dtt['DTT_ID'])) {
1125
+				$DTM = EE_Registry::instance()
1126
+								  ->load_model('Datetime', array($evtobj->get_timezone()))
1127
+								  ->get_one_by_ID($dtt['DTT_ID']);
1128
+				$DTM->set_date_format($incoming_date_formats[0]);
1129
+				$DTM->set_time_format($incoming_date_formats[1]);
1130
+				foreach ($datetime_values as $field => $value) {
1131
+					$DTM->set($field, $value);
1132
+				}
1133
+				//make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1134
+				$saved_dtts[$DTM->ID()] = $DTM;
1135
+			} else {
1136
+				$DTM = EE_Registry::instance()->load_class(
1137
+					'Datetime',
1138
+					array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1139
+					false,
1140
+					false
1141
+				);
1142
+				foreach ($datetime_values as $field => $value) {
1143
+					$DTM->set($field, $value);
1144
+				}
1145
+			}
1146
+			$DTM->save();
1147
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1148
+			//load DTT helper
1149
+			//before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1150
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1151
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1152
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1153
+				$DTT->save();
1154
+			}
1155
+			//now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1156
+			$saved_dtt = $DTT;
1157
+			$success = ! $success ? $success : $DTT;
1158
+			//if ANY of these updates fail then we want the appropriate global error message.
1159
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1160
+		}
1161
+		//no dtts get deleted so we don't do any of that logic here.
1162
+		//update tickets next
1163
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1164
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1165
+			$incoming_date_formats = array('Y-m-d', 'h:i a');
1166
+			$update_prices = false;
1167
+			$ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1168
+				? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1169
+			// trim inputs to ensure any excess whitespace is removed.
1170
+			$tkt = array_map('trim', $tkt);
1171
+			if (empty($tkt['TKT_start_date'])) {
1172
+				//let's use now in the set timezone.
1173
+				$now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1174
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1175
+			}
1176
+			if (empty($tkt['TKT_end_date'])) {
1177
+				//use the start date of the first datetime
1178
+				$dtt = $evtobj->first_datetime();
1179
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1180
+					$incoming_date_formats[0],
1181
+					$incoming_date_formats[1]
1182
+				);
1183
+			}
1184
+			$TKT_values = array(
1185
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1186
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1187
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1188
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1189
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1190
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1191
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1192
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1193
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1194
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1195
+				'TKT_row'         => $row,
1196
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1197
+				'TKT_price'       => $ticket_price,
1198
+			);
1199
+			//if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1200
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1201
+				$TKT_values['TKT_ID'] = 0;
1202
+				$TKT_values['TKT_is_default'] = 0;
1203
+				$TKT_values['TKT_price'] = $ticket_price;
1204
+				$update_prices = true;
1205
+			}
1206
+			//if we have a TKT_ID then we need to get that existing TKT_obj and update it
1207
+			//we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1208
+			//keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1209
+			if ( ! empty($tkt['TKT_ID'])) {
1210
+				$TKT = EE_Registry::instance()
1211
+								  ->load_model('Ticket', array($evtobj->get_timezone()))
1212
+								  ->get_one_by_ID($tkt['TKT_ID']);
1213
+				if ($TKT instanceof EE_Ticket) {
1214
+					$ticket_sold = $TKT->count_related(
1215
+						'Registration',
1216
+						array(
1217
+							array(
1218
+								'STS_ID' => array(
1219
+									'NOT IN',
1220
+									array(EEM_Registration::status_id_incomplete),
1221
+								),
1222
+							),
1223
+						)
1224
+					) > 0 ? true : false;
1225
+					//let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1226
+					$create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1227
+									  && ! $TKT->get(
1228
+						'TKT_deleted'
1229
+					) ? true : false;
1230
+					$TKT->set_date_format($incoming_date_formats[0]);
1231
+					$TKT->set_time_format($incoming_date_formats[1]);
1232
+					//set new values
1233
+					foreach ($TKT_values as $field => $value) {
1234
+						if ($field == 'TKT_qty') {
1235
+							$TKT->set_qty($value);
1236
+						} else {
1237
+							$TKT->set($field, $value);
1238
+						}
1239
+					}
1240
+					//if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1241
+					if ($create_new_TKT) {
1242
+						//archive the old ticket first
1243
+						$TKT->set('TKT_deleted', 1);
1244
+						$TKT->save();
1245
+						//make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1246
+						$saved_tickets[$TKT->ID()] = $TKT;
1247
+						//create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1248
+						$TKT = clone $TKT;
1249
+						$TKT->set('TKT_ID', 0);
1250
+						$TKT->set('TKT_deleted', 0);
1251
+						$TKT->set('TKT_price', $ticket_price);
1252
+						$TKT->set('TKT_sold', 0);
1253
+						//now we need to make sure that $new prices are created as well and attached to new ticket.
1254
+						$update_prices = true;
1255
+					}
1256
+					//make sure price is set if it hasn't been already
1257
+					$TKT->set('TKT_price', $ticket_price);
1258
+				}
1259
+			} else {
1260
+				//no TKT_id so a new TKT
1261
+				$TKT_values['TKT_price'] = $ticket_price;
1262
+				$TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1263
+				if ($TKT instanceof EE_Ticket) {
1264
+					//need to reset values to properly account for the date formats
1265
+					$TKT->set_date_format($incoming_date_formats[0]);
1266
+					$TKT->set_time_format($incoming_date_formats[1]);
1267
+					$TKT->set_timezone($evtobj->get_timezone());
1268
+					//set new values
1269
+					foreach ($TKT_values as $field => $value) {
1270
+						if ($field == 'TKT_qty') {
1271
+							$TKT->set_qty($value);
1272
+						} else {
1273
+							$TKT->set($field, $value);
1274
+						}
1275
+					}
1276
+					$update_prices = true;
1277
+				}
1278
+			}
1279
+			// cap ticket qty by datetime reg limits
1280
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1281
+			//update ticket.
1282
+			$TKT->save();
1283
+			//before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1284
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1285
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1286
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1287
+				$TKT->save();
1288
+			}
1289
+			//initially let's add the ticket to the dtt
1290
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1291
+			$saved_tickets[$TKT->ID()] = $TKT;
1292
+			//add prices to ticket
1293
+			$this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1294
+		}
1295
+		//however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1296
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1297
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1298
+		foreach ($tickets_removed as $id) {
1299
+			$id = absint($id);
1300
+			//get the ticket for this id
1301
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1302
+			//need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1303
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1304
+			foreach ($dtts as $dtt) {
1305
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1306
+			}
1307
+			//need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1308
+			$tkt_to_remove->delete_related_permanently('Price');
1309
+			//finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1310
+			$tkt_to_remove->delete_permanently();
1311
+		}
1312
+		return array($saved_dtt, $saved_tickets);
1313
+	}
1314
+
1315
+
1316
+
1317
+	/**
1318
+	 * This attaches a list of given prices to a ticket.
1319
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1320
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1321
+	 * price info and prices are automatically "archived" via the ticket.
1322
+	 *
1323
+	 * @access  private
1324
+	 * @param array     $prices     Array of prices from the form.
1325
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1326
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1327
+	 * @return  void
1328
+	 */
1329
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1330
+	{
1331
+		foreach ($prices as $row => $prc) {
1332
+			$PRC_values = array(
1333
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1334
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1335
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1336
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1337
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1338
+				'PRC_is_default' => 0, //make sure prices are NOT set as default from this context
1339
+				'PRC_order'      => $row,
1340
+			);
1341
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1342
+				$PRC_values['PRC_ID'] = 0;
1343
+				$PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1344
+			} else {
1345
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1346
+				//update this price with new values
1347
+				foreach ($PRC_values as $field => $newprc) {
1348
+					$PRC->set($field, $newprc);
1349
+				}
1350
+				$PRC->save();
1351
+			}
1352
+			$ticket->_add_relation_to($PRC, 'Price');
1353
+		}
1354
+	}
1355
+
1356
+
1357
+
1358
+	/**
1359
+	 * Add in our autosave ajax handlers
1360
+	 *
1361
+	 * @return void
1362
+	 */
1363
+	protected function _ee_autosave_create_new()
1364
+	{
1365
+		// $this->_ee_autosave_edit();
1366
+	}
1367
+
1368
+
1369
+
1370
+	protected function _ee_autosave_edit()
1371
+	{
1372
+		return; //TEMPORARILY EXITING CAUSE THIS IS A TODO
1373
+	}
1374
+
1375
+
1376
+
1377
+	/**
1378
+	 *    _generate_publish_box_extra_content
1379
+	 *
1380
+	 * @access private
1381
+	 * @return void
1382
+	 */
1383
+	private function _generate_publish_box_extra_content()
1384
+	{
1385
+		//load formatter helper
1386
+		//args for getting related registrations
1387
+		$approved_query_args = array(
1388
+			array(
1389
+				'REG_deleted' => 0,
1390
+				'STS_ID'      => EEM_Registration::status_id_approved,
1391
+			),
1392
+		);
1393
+		$not_approved_query_args = array(
1394
+			array(
1395
+				'REG_deleted' => 0,
1396
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1397
+			),
1398
+		);
1399
+		$pending_payment_query_args = array(
1400
+			array(
1401
+				'REG_deleted' => 0,
1402
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1403
+			),
1404
+		);
1405
+		// publish box
1406
+		$publish_box_extra_args = array(
1407
+			'view_approved_reg_url'        => add_query_arg(
1408
+				array(
1409
+					'action'      => 'default',
1410
+					'event_id'    => $this->_cpt_model_obj->ID(),
1411
+					'_reg_status' => EEM_Registration::status_id_approved,
1412
+				),
1413
+				REG_ADMIN_URL
1414
+			),
1415
+			'view_not_approved_reg_url'    => add_query_arg(
1416
+				array(
1417
+					'action'      => 'default',
1418
+					'event_id'    => $this->_cpt_model_obj->ID(),
1419
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1420
+				),
1421
+				REG_ADMIN_URL
1422
+			),
1423
+			'view_pending_payment_reg_url' => add_query_arg(
1424
+				array(
1425
+					'action'      => 'default',
1426
+					'event_id'    => $this->_cpt_model_obj->ID(),
1427
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1428
+				),
1429
+				REG_ADMIN_URL
1430
+			),
1431
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1432
+				'Registration',
1433
+				$approved_query_args
1434
+			),
1435
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1436
+				'Registration',
1437
+				$not_approved_query_args
1438
+			),
1439
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1440
+				'Registration',
1441
+				$pending_payment_query_args
1442
+			),
1443
+			'misc_pub_section_class'       => apply_filters(
1444
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1445
+				'misc-pub-section'
1446
+			),
1447
+			//'email_attendees_url' => add_query_arg(
1448
+			//	array(
1449
+			//		'event_admin_reports' => 'event_newsletter',
1450
+			//		'event_id' => $this->_cpt_model_obj->id
1451
+			//	),
1452
+			//	'admin.php?page=espresso_registrations'
1453
+			//),
1454
+		);
1455
+		ob_start();
1456
+		do_action(
1457
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1458
+			$this->_cpt_model_obj
1459
+		);
1460
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1461
+		// load template
1462
+		EEH_Template::display_template(
1463
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1464
+			$publish_box_extra_args
1465
+		);
1466
+	}
1467
+
1468
+
1469
+
1470
+	/**
1471
+	 * This just returns whatever is set as the _event object property
1472
+	 * //todo this will become obsolete once the models are in place
1473
+	 *
1474
+	 * @return object
1475
+	 */
1476
+	public function get_event_object()
1477
+	{
1478
+		return $this->_cpt_model_obj;
1479
+	}
1480
+
1481
+
1482
+
1483
+
1484
+	/** METABOXES * */
1485
+	/**
1486
+	 * _register_event_editor_meta_boxes
1487
+	 * add all metaboxes related to the event_editor
1488
+	 *
1489
+	 * @return void
1490
+	 */
1491
+	protected function _register_event_editor_meta_boxes()
1492
+	{
1493
+		$this->verify_cpt_object();
1494
+		add_meta_box(
1495
+			'espresso_event_editor_tickets',
1496
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1497
+			array($this, 'ticket_metabox'),
1498
+			$this->page_slug,
1499
+			'normal',
1500
+			'high'
1501
+		);
1502
+		add_meta_box(
1503
+			'espresso_event_editor_event_options',
1504
+			esc_html__('Event Registration Options', 'event_espresso'),
1505
+			array($this, 'registration_options_meta_box'),
1506
+			$this->page_slug,
1507
+			'side',
1508
+			'default'
1509
+		);
1510
+		// NOTE: if you're looking for other metaboxes in here,
1511
+		// where a metabox has a related management page in the admin
1512
+		// you will find it setup in the related management page's "_Hooks" file.
1513
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1514
+	}
1515
+
1516
+
1517
+
1518
+	public function ticket_metabox()
1519
+	{
1520
+		$existing_datetime_ids = $existing_ticket_ids = array();
1521
+		//defaults for template args
1522
+		$template_args = array(
1523
+			'existing_datetime_ids'    => '',
1524
+			'event_datetime_help_link' => '',
1525
+			'ticket_options_help_link' => '',
1526
+			'time'                     => null,
1527
+			'ticket_rows'              => '',
1528
+			'existing_ticket_ids'      => '',
1529
+			'total_ticket_rows'        => 1,
1530
+			'ticket_js_structure'      => '',
1531
+			'trash_icon'               => 'ee-lock-icon',
1532
+			'disabled'                 => '',
1533
+		);
1534
+		$event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1535
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1536
+		/**
1537
+		 * 1. Start with retrieving Datetimes
1538
+		 * 2. Fore each datetime get related tickets
1539
+		 * 3. For each ticket get related prices
1540
+		 */
1541
+		$times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1542
+		/** @type EE_Datetime $first_datetime */
1543
+		$first_datetime = reset($times);
1544
+		//do we get related tickets?
1545
+		if ($first_datetime instanceof EE_Datetime
1546
+			&& $first_datetime->ID() !== 0
1547
+		) {
1548
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1549
+			$template_args['time'] = $first_datetime;
1550
+			$related_tickets = $first_datetime->tickets(
1551
+				array(
1552
+					array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1553
+					'default_where_conditions' => 'none',
1554
+				)
1555
+			);
1556
+			if ( ! empty($related_tickets)) {
1557
+				$template_args['total_ticket_rows'] = count($related_tickets);
1558
+				$row = 0;
1559
+				foreach ($related_tickets as $ticket) {
1560
+					$existing_ticket_ids[] = $ticket->get('TKT_ID');
1561
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1562
+					$row++;
1563
+				}
1564
+			} else {
1565
+				$template_args['total_ticket_rows'] = 1;
1566
+				/** @type EE_Ticket $ticket */
1567
+				$ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1568
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1569
+			}
1570
+		} else {
1571
+			$template_args['time'] = $times[0];
1572
+			/** @type EE_Ticket $ticket */
1573
+			$ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1574
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1575
+			// NOTE: we're just sending the first default row
1576
+			// (decaf can't manage default tickets so this should be sufficient);
1577
+		}
1578
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1579
+			'event_editor_event_datetimes_help_tab'
1580
+		);
1581
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1582
+		$template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1583
+		$template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1584
+		$template_args['ticket_js_structure'] = $this->_get_ticket_row(
1585
+			EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1586
+			true
1587
+		);
1588
+		$template = apply_filters(
1589
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1590
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1591
+		);
1592
+		EEH_Template::display_template($template, $template_args);
1593
+	}
1594
+
1595
+
1596
+
1597
+	/**
1598
+	 * Setup an individual ticket form for the decaf event editor page
1599
+	 *
1600
+	 * @access private
1601
+	 * @param  EE_Ticket $ticket   the ticket object
1602
+	 * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1603
+	 * @param int        $row
1604
+	 * @return string generated html for the ticket row.
1605
+	 */
1606
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1607
+	{
1608
+		$template_args = array(
1609
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1610
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1611
+				: '',
1612
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1613
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1614
+			'TKT_name'            => $ticket->get('TKT_name'),
1615
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1616
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1617
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1618
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1619
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1620
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1621
+			'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1622
+									 && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1623
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1624
+			'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1625
+				: ' disabled=disabled',
1626
+		);
1627
+		$price = $ticket->ID() !== 0
1628
+			? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1629
+			: EE_Registry::instance()->load_model('Price')->create_default_object();
1630
+		$price_args = array(
1631
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1632
+			'PRC_amount'            => $price->get('PRC_amount'),
1633
+			'PRT_ID'                => $price->get('PRT_ID'),
1634
+			'PRC_ID'                => $price->get('PRC_ID'),
1635
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1636
+		);
1637
+		//make sure we have default start and end dates if skeleton
1638
+		//handle rows that should NOT be empty
1639
+		if (empty($template_args['TKT_start_date'])) {
1640
+			//if empty then the start date will be now.
1641
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1642
+		}
1643
+		if (empty($template_args['TKT_end_date'])) {
1644
+			//get the earliest datetime (if present);
1645
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1646
+				? $this->_cpt_model_obj->get_first_related(
1647
+					'Datetime',
1648
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1649
+				)
1650
+				: null;
1651
+			if ( ! empty($earliest_dtt)) {
1652
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1653
+			} else {
1654
+				$template_args['TKT_end_date'] = date(
1655
+					'Y-m-d h:i a',
1656
+					mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1657
+				);
1658
+			}
1659
+		}
1660
+		$template_args = array_merge($template_args, $price_args);
1661
+		$template = apply_filters(
1662
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1663
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1664
+			$ticket
1665
+		);
1666
+		return EEH_Template::display_template($template, $template_args, true);
1667
+	}
1668
+
1669
+
1670
+
1671
+	public function registration_options_meta_box()
1672
+	{
1673
+		$yes_no_values = array(
1674
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1675
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1676
+		);
1677
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1678
+			array(
1679
+				EEM_Registration::status_id_cancelled,
1680
+				EEM_Registration::status_id_declined,
1681
+				EEM_Registration::status_id_incomplete,
1682
+			),
1683
+			true
1684
+		);
1685
+		//$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1686
+		$template_args['_event'] = $this->_cpt_model_obj;
1687
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1688
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1689
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1690
+			'default_reg_status',
1691
+			$default_reg_status_values,
1692
+			$this->_cpt_model_obj->default_registration_status()
1693
+		);
1694
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1695
+			'display_desc',
1696
+			$yes_no_values,
1697
+			$this->_cpt_model_obj->display_description()
1698
+		);
1699
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1700
+			'display_ticket_selector',
1701
+			$yes_no_values,
1702
+			$this->_cpt_model_obj->display_ticket_selector(),
1703
+			'',
1704
+			'',
1705
+			false
1706
+		);
1707
+		$template_args['additional_registration_options'] = apply_filters(
1708
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1709
+			'',
1710
+			$template_args,
1711
+			$yes_no_values,
1712
+			$default_reg_status_values
1713
+		);
1714
+		EEH_Template::display_template(
1715
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1716
+			$template_args
1717
+		);
1718
+	}
1719
+
1720
+
1721
+
1722
+	/**
1723
+	 * _get_events()
1724
+	 * This method simply returns all the events (for the given _view and paging)
1725
+	 *
1726
+	 * @access public
1727
+	 * @param int  $per_page     count of items per page (20 default);
1728
+	 * @param int  $current_page what is the current page being viewed.
1729
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1730
+	 *                           If FALSE then we return an array of event objects
1731
+	 *                           that match the given _view and paging parameters.
1732
+	 * @return array an array of event objects.
1733
+	 */
1734
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1735
+	{
1736
+		$EEME = $this->_event_model();
1737
+		$offset = ($current_page - 1) * $per_page;
1738
+		$limit = $count ? null : $offset . ',' . $per_page;
1739
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1740
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1741
+		if (isset($this->_req_data['month_range'])) {
1742
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1743
+			//simulate the FIRST day of the month, that fixes issues for months like February
1744
+			//where PHP doesn't know what to assume for date.
1745
+			//@see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1746
+			$month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1747
+			$year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1748
+		}
1749
+		$where = array();
1750
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1751
+		//determine what post_status our condition will have for the query.
1752
+		switch ($status) {
1753
+			case 'month' :
1754
+			case 'today' :
1755
+			case null :
1756
+			case 'all' :
1757
+				break;
1758
+			case 'draft' :
1759
+				$where['status'] = array('IN', array('draft', 'auto-draft'));
1760
+				break;
1761
+			default :
1762
+				$where['status'] = $status;
1763
+		}
1764
+		//categories?
1765
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1766
+			? $this->_req_data['EVT_CAT'] : null;
1767
+		if ( ! empty ($category)) {
1768
+			$where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1769
+			$where['Term_Taxonomy.term_id'] = $category;
1770
+		}
1771
+		//date where conditions
1772
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1773
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1774
+			$DateTime = new DateTime(
1775
+				$year_r . '-' . $month_r . '-01 00:00:00',
1776
+				new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1777
+			);
1778
+			$start = $DateTime->format(implode(' ', $start_formats));
1779
+			$end = $DateTime->setDate($year_r, $month_r, $DateTime
1780
+				->format('t'))->setTime(23, 59, 59)
1781
+							->format(implode(' ', $start_formats));
1782
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1783
+		} else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1784
+			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1785
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1786
+			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1787
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1788
+		} else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1789
+			$now = date('Y-m-01');
1790
+			$DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1791
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1792
+			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1793
+							->setTime(23, 59, 59)
1794
+							->format(implode(' ', $start_formats));
1795
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1796
+		}
1797
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1798
+			$where['EVT_wp_user'] = get_current_user_id();
1799
+		} else {
1800
+			if ( ! isset($where['status'])) {
1801
+				if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1802
+					$where['OR'] = array(
1803
+						'status*restrict_private' => array('!=', 'private'),
1804
+						'AND'                     => array(
1805
+							'status*inclusive' => array('=', 'private'),
1806
+							'EVT_wp_user'      => get_current_user_id(),
1807
+						),
1808
+					);
1809
+				}
1810
+			}
1811
+		}
1812
+		if (isset($this->_req_data['EVT_wp_user'])) {
1813
+			if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1814
+				&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1815
+			) {
1816
+				$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1817
+			}
1818
+		}
1819
+		//search query handling
1820
+		if (isset($this->_req_data['s'])) {
1821
+			$search_string = '%' . $this->_req_data['s'] . '%';
1822
+			$where['OR'] = array(
1823
+				'EVT_name'       => array('LIKE', $search_string),
1824
+				'EVT_desc'       => array('LIKE', $search_string),
1825
+				'EVT_short_desc' => array('LIKE', $search_string),
1826
+			);
1827
+		}
1828
+		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1829
+		$query_params = apply_filters(
1830
+			'FHEE__Events_Admin_Page__get_events__query_params',
1831
+			array(
1832
+				$where,
1833
+				'limit'    => $limit,
1834
+				'order_by' => $orderby,
1835
+				'order'    => $order,
1836
+				'group_by' => 'EVT_ID',
1837
+			),
1838
+			$this->_req_data
1839
+		);
1840
+		//let's first check if we have special requests coming in.
1841
+		if (isset($this->_req_data['active_status'])) {
1842
+			switch ($this->_req_data['active_status']) {
1843
+				case 'upcoming' :
1844
+					return $EEME->get_upcoming_events($query_params, $count);
1845
+					break;
1846
+				case 'expired' :
1847
+					return $EEME->get_expired_events($query_params, $count);
1848
+					break;
1849
+				case 'active' :
1850
+					return $EEME->get_active_events($query_params, $count);
1851
+					break;
1852
+				case 'inactive' :
1853
+					return $EEME->get_inactive_events($query_params, $count);
1854
+					break;
1855
+			}
1856
+		}
1857
+		$events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1858
+		return $events;
1859
+	}
1860
+
1861
+
1862
+
1863
+	/**
1864
+	 * handling for WordPress CPT actions (trash, restore, delete)
1865
+	 *
1866
+	 * @param string $post_id
1867
+	 */
1868
+	public function trash_cpt_item($post_id)
1869
+	{
1870
+		$this->_req_data['EVT_ID'] = $post_id;
1871
+		$this->_trash_or_restore_event('trash', false);
1872
+	}
1873
+
1874
+
1875
+
1876
+	/**
1877
+	 * @param string $post_id
1878
+	 */
1879
+	public function restore_cpt_item($post_id)
1880
+	{
1881
+		$this->_req_data['EVT_ID'] = $post_id;
1882
+		$this->_trash_or_restore_event('draft', false);
1883
+	}
1884
+
1885
+
1886
+
1887
+	/**
1888
+	 * @param string $post_id
1889
+	 */
1890
+	public function delete_cpt_item($post_id)
1891
+	{
1892
+		$this->_req_data['EVT_ID'] = $post_id;
1893
+		$this->_delete_event(false);
1894
+	}
1895
+
1896
+
1897
+
1898
+	/**
1899
+	 * _trash_or_restore_event
1900
+	 *
1901
+	 * @access protected
1902
+	 * @param  string $event_status
1903
+	 * @param bool    $redirect_after
1904
+	 */
1905
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1906
+	{
1907
+		//determine the event id and set to array.
1908
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1909
+		// loop thru events
1910
+		if ($EVT_ID) {
1911
+			// clean status
1912
+			$event_status = sanitize_key($event_status);
1913
+			// grab status
1914
+			if ( ! empty($event_status)) {
1915
+				$success = $this->_change_event_status($EVT_ID, $event_status);
1916
+			} else {
1917
+				$success = false;
1918
+				$msg = esc_html__(
1919
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1920
+					'event_espresso'
1921
+				);
1922
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1923
+			}
1924
+		} else {
1925
+			$success = false;
1926
+			$msg = esc_html__(
1927
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1928
+				'event_espresso'
1929
+			);
1930
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1931
+		}
1932
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1933
+		if ($redirect_after) {
1934
+			$this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1935
+		}
1936
+	}
1937
+
1938
+
1939
+
1940
+	/**
1941
+	 * _trash_or_restore_events
1942
+	 *
1943
+	 * @access protected
1944
+	 * @param  string $event_status
1945
+	 * @return void
1946
+	 */
1947
+	protected function _trash_or_restore_events($event_status = 'trash')
1948
+	{
1949
+		// clean status
1950
+		$event_status = sanitize_key($event_status);
1951
+		// grab status
1952
+		if ( ! empty($event_status)) {
1953
+			$success = true;
1954
+			//determine the event id and set to array.
1955
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1956
+			// loop thru events
1957
+			foreach ($EVT_IDs as $EVT_ID) {
1958
+				if ($EVT_ID = absint($EVT_ID)) {
1959
+					$results = $this->_change_event_status($EVT_ID, $event_status);
1960
+					$success = $results !== false ? $success : false;
1961
+				} else {
1962
+					$msg = sprintf(
1963
+						esc_html__(
1964
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1965
+							'event_espresso'
1966
+						),
1967
+						$EVT_ID
1968
+					);
1969
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1970
+					$success = false;
1971
+				}
1972
+			}
1973
+		} else {
1974
+			$success = false;
1975
+			$msg = esc_html__(
1976
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1977
+				'event_espresso'
1978
+			);
1979
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1980
+		}
1981
+		// in order to force a pluralized result message we need to send back a success status greater than 1
1982
+		$success = $success ? 2 : false;
1983
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1984
+		$this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
1985
+	}
1986
+
1987
+
1988
+
1989
+	/**
1990
+	 * _trash_or_restore_events
1991
+	 *
1992
+	 * @access  private
1993
+	 * @param  int    $EVT_ID
1994
+	 * @param  string $event_status
1995
+	 * @return bool
1996
+	 */
1997
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
1998
+	{
1999
+		// grab event id
2000
+		if ( ! $EVT_ID) {
2001
+			$msg = esc_html__(
2002
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2003
+				'event_espresso'
2004
+			);
2005
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2006
+			return false;
2007
+		}
2008
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2009
+		// clean status
2010
+		$event_status = sanitize_key($event_status);
2011
+		// grab status
2012
+		if (empty($event_status)) {
2013
+			$msg = esc_html__(
2014
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2015
+				'event_espresso'
2016
+			);
2017
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2018
+			return false;
2019
+		}
2020
+		// was event trashed or restored ?
2021
+		switch ($event_status) {
2022
+			case 'draft' :
2023
+				$action = 'restored from the trash';
2024
+				$hook = 'AHEE_event_restored_from_trash';
2025
+				break;
2026
+			case 'trash' :
2027
+				$action = 'moved to the trash';
2028
+				$hook = 'AHEE_event_moved_to_trash';
2029
+				break;
2030
+			default :
2031
+				$action = 'updated';
2032
+				$hook = false;
2033
+		}
2034
+		//use class to change status
2035
+		$this->_cpt_model_obj->set_status($event_status);
2036
+		$success = $this->_cpt_model_obj->save();
2037
+		if ($success === false) {
2038
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2039
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2040
+			return false;
2041
+		}
2042
+		if ($hook) {
2043
+			do_action($hook);
2044
+		}
2045
+		return true;
2046
+	}
2047
+
2048
+
2049
+
2050
+	/**
2051
+	 * _delete_event
2052
+	 *
2053
+	 * @access protected
2054
+	 * @param bool $redirect_after
2055
+	 */
2056
+	protected function _delete_event($redirect_after = true)
2057
+	{
2058
+		//determine the event id and set to array.
2059
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2060
+		$EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2061
+		// loop thru events
2062
+		if ($EVT_ID) {
2063
+			$success = $this->_permanently_delete_event($EVT_ID);
2064
+			// get list of events with no prices
2065
+			$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2066
+			// remove this event from the list of events with no prices
2067
+			if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2068
+				unset($espresso_no_ticket_prices[$EVT_ID]);
2069
+			}
2070
+			update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2071
+		} else {
2072
+			$success = false;
2073
+			$msg = esc_html__(
2074
+				'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2075
+				'event_espresso'
2076
+			);
2077
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2078
+		}
2079
+		if ($redirect_after) {
2080
+			$this->_redirect_after_action(
2081
+				$success,
2082
+				'Event',
2083
+				'deleted',
2084
+				array('action' => 'default', 'status' => 'trash')
2085
+			);
2086
+		}
2087
+	}
2088
+
2089
+
2090
+
2091
+	/**
2092
+	 * _delete_events
2093
+	 *
2094
+	 * @access protected
2095
+	 * @return void
2096
+	 */
2097
+	protected function _delete_events()
2098
+	{
2099
+		$success = true;
2100
+		// get list of events with no prices
2101
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2102
+		//determine the event id and set to array.
2103
+		$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2104
+		// loop thru events
2105
+		foreach ($EVT_IDs as $EVT_ID) {
2106
+			$EVT_ID = absint($EVT_ID);
2107
+			if ($EVT_ID) {
2108
+				$results = $this->_permanently_delete_event($EVT_ID);
2109
+				$success = $results !== false ? $success : false;
2110
+				// remove this event from the list of events with no prices
2111
+				unset($espresso_no_ticket_prices[$EVT_ID]);
2112
+			} else {
2113
+				$success = false;
2114
+				$msg = esc_html__(
2115
+					'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2116
+					'event_espresso'
2117
+				);
2118
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2119
+			}
2120
+		}
2121
+		update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2122
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2123
+		$success = $success ? 2 : false;
2124
+		$this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2125
+	}
2126
+
2127
+
2128
+
2129
+	/**
2130
+	 * _permanently_delete_event
2131
+	 *
2132
+	 * @access  private
2133
+	 * @param  int $EVT_ID
2134
+	 * @return bool
2135
+	 */
2136
+	private function _permanently_delete_event($EVT_ID = 0)
2137
+	{
2138
+		// grab event id
2139
+		if ( ! $EVT_ID) {
2140
+			$msg = esc_html__(
2141
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2142
+				'event_espresso'
2143
+			);
2144
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2145
+			return false;
2146
+		}
2147
+		if (
2148
+			! $this->_cpt_model_obj instanceof EE_Event
2149
+			|| $this->_cpt_model_obj->ID() !== $EVT_ID
2150
+		) {
2151
+			$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2152
+		}
2153
+		if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2154
+			return false;
2155
+		}
2156
+		//need to delete related tickets and prices first.
2157
+		$datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2158
+		foreach ($datetimes as $datetime) {
2159
+			$this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2160
+			$tickets = $datetime->get_many_related('Ticket');
2161
+			foreach ($tickets as $ticket) {
2162
+				$ticket->_remove_relation_to($datetime, 'Datetime');
2163
+				$ticket->delete_related_permanently('Price');
2164
+				$ticket->delete_permanently();
2165
+			}
2166
+			$datetime->delete();
2167
+		}
2168
+		//what about related venues or terms?
2169
+		$venues = $this->_cpt_model_obj->get_many_related('Venue');
2170
+		foreach ($venues as $venue) {
2171
+			$this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2172
+		}
2173
+		//any attached question groups?
2174
+		$question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2175
+		if ( ! empty($question_groups)) {
2176
+			foreach ($question_groups as $question_group) {
2177
+				$this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2178
+			}
2179
+		}
2180
+		//Message Template Groups
2181
+		$this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2182
+		/** @type EE_Term_Taxonomy[] $term_taxonomies */
2183
+		$term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2184
+		foreach ($term_taxonomies as $term_taxonomy) {
2185
+			$this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2186
+		}
2187
+		$success = $this->_cpt_model_obj->delete_permanently();
2188
+		// did it all go as planned ?
2189
+		if ($success) {
2190
+			$msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2191
+			EE_Error::add_success($msg);
2192
+		} else {
2193
+			$msg = sprintf(
2194
+				esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2195
+				$EVT_ID
2196
+			);
2197
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2198
+			return false;
2199
+		}
2200
+		do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2201
+		return true;
2202
+	}
2203
+
2204
+
2205
+
2206
+	/**
2207
+	 * get total number of events
2208
+	 *
2209
+	 * @access public
2210
+	 * @return int
2211
+	 */
2212
+	public function total_events()
2213
+	{
2214
+		$count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2215
+		return $count;
2216
+	}
2217
+
2218
+
2219
+
2220
+	/**
2221
+	 * get total number of draft events
2222
+	 *
2223
+	 * @access public
2224
+	 * @return int
2225
+	 */
2226
+	public function total_events_draft()
2227
+	{
2228
+		$where = array(
2229
+			'status' => array('IN', array('draft', 'auto-draft')),
2230
+		);
2231
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2232
+		return $count;
2233
+	}
2234
+
2235
+
2236
+
2237
+	/**
2238
+	 * get total number of trashed events
2239
+	 *
2240
+	 * @access public
2241
+	 * @return int
2242
+	 */
2243
+	public function total_trashed_events()
2244
+	{
2245
+		$where = array(
2246
+			'status' => 'trash',
2247
+		);
2248
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2249
+		return $count;
2250
+	}
2251
+
2252
+
2253
+
2254
+	/**
2255
+	 *    _default_event_settings
2256
+	 *    This generates the Default Settings Tab
2257
+	 *
2258
+	 * @return void
2259
+	 */
2260
+	protected function _default_event_settings()
2261
+	{
2262
+		$this->_template_args['values'] = $this->_yes_no_values;
2263
+		$this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array(
2264
+		// exclude array
2265
+			array(
2266
+				EEM_Registration::status_id_cancelled,
2267
+				EEM_Registration::status_id_declined,
2268
+				EEM_Registration::status_id_incomplete,
2269
+				EEM_Registration::status_id_wait_list,
2270
+			),
2271
+			// translated
2272
+			true
2273
+		);
2274
+		$this->_template_args['default_reg_status'] = isset(
2275
+														  EE_Registry::instance()->CFG->registration->default_STS_ID
2276
+													  )
2277
+													  && array_key_exists(
2278
+														  EE_Registry::instance()->CFG->registration->default_STS_ID,
2279
+														  $this->_template_args['reg_status_array']
2280
+													  )
2281
+			? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID)
2282
+			: EEM_Registration::status_id_pending_payment;
2283
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2284
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2285
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2286
+			EVENTS_TEMPLATE_PATH . 'event_settings.template.php',
2287
+			$this->_template_args,
2288
+			true
2289
+		);
2290
+		$this->display_admin_page_with_sidebar();
2291
+	}
2292
+
2293
+
2294
+
2295
+	/**
2296
+	 * _update_default_event_settings
2297
+	 *
2298
+	 * @access protected
2299
+	 * @return void
2300
+	 */
2301
+	protected function _update_default_event_settings()
2302
+	{
2303
+		EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status'])
2304
+			? sanitize_text_field($this->_req_data['default_reg_status'])
2305
+			: EEM_Registration::status_id_pending_payment;
2306
+		$what = 'Default Event Settings';
2307
+		$success = $this->_update_espresso_configuration(
2308
+			$what,
2309
+			EE_Config::instance(),
2310
+			__FILE__,
2311
+			__FUNCTION__,
2312
+			__LINE__
2313
+		);
2314
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings'));
2315
+	}
2316
+
2317
+
2318
+
2319
+	/*************        Templates        *************/
2320
+	protected function _template_settings()
2321
+	{
2322
+		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2323
+		$this->_template_args['preview_img'] = '<img src="'
2324
+											   . EVENTS_ASSETS_URL
2325
+											   . DS
2326
+											   . 'images'
2327
+											   . DS
2328
+											   . 'caffeinated_template_features.jpg" alt="'
2329
+											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2330
+											   . '" />';
2331
+		$this->_template_args['preview_text'] = '<strong>' . esc_html__(
2332
+				'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2333
+				'event_espresso'
2334
+			) . '</strong>';
2335
+		$this->display_admin_caf_preview_page('template_settings_tab');
2336
+	}
2337
+
2338
+
2339
+	/** Event Category Stuff **/
2340
+	/**
2341
+	 * set the _category property with the category object for the loaded page.
2342
+	 *
2343
+	 * @access private
2344
+	 * @return void
2345
+	 */
2346
+	private function _set_category_object()
2347
+	{
2348
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2349
+			return;
2350
+		} //already have the category object so get out.
2351
+		//set default category object
2352
+		$this->_set_empty_category_object();
2353
+		//only set if we've got an id
2354
+		if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2355
+			return;
2356
+		}
2357
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2358
+		$term = get_term($category_id, 'espresso_event_categories');
2359
+		if ( ! empty($term)) {
2360
+			$this->_category->category_name = $term->name;
2361
+			$this->_category->category_identifier = $term->slug;
2362
+			$this->_category->category_desc = $term->description;
2363
+			$this->_category->id = $term->term_id;
2364
+			$this->_category->parent = $term->parent;
2365
+		}
2366
+	}
2367
+
2368
+
2369
+
2370
+	private function _set_empty_category_object()
2371
+	{
2372
+		$this->_category = new stdClass();
2373
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2374
+		$this->_category->id = $this->_category->parent = 0;
2375
+	}
2376
+
2377
+
2378
+
2379
+	protected function _category_list_table()
2380
+	{
2381
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2382
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2383
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2384
+				'add_category',
2385
+				'add_category',
2386
+				array(),
2387
+				'add-new-h2'
2388
+			);
2389
+		$this->display_admin_list_table_page_with_sidebar();
2390
+	}
2391
+
2392
+
2393
+
2394
+	/**
2395
+	 * @param $view
2396
+	 */
2397
+	protected function _category_details($view)
2398
+	{
2399
+		//load formatter helper
2400
+		//load field generator helper
2401
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2402
+		$this->_set_add_edit_form_tags($route);
2403
+		$this->_set_category_object();
2404
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
2405
+		$delete_action = 'delete_category';
2406
+		//custom redirect
2407
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2408
+			array('action' => 'category_list'),
2409
+			$this->_admin_base_url
2410
+		);
2411
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2412
+		//take care of contents
2413
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2414
+		$this->display_admin_page_with_sidebar();
2415
+	}
2416
+
2417
+
2418
+
2419
+	/**
2420
+	 * @return mixed
2421
+	 */
2422
+	protected function _category_details_content()
2423
+	{
2424
+		$editor_args['category_desc'] = array(
2425
+			'type'          => 'wp_editor',
2426
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2427
+			'class'         => 'my_editor_custom',
2428
+			'wpeditor_args' => array('media_buttons' => false),
2429
+		);
2430
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2431
+		$all_terms = get_terms(
2432
+			array('espresso_event_categories'),
2433
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2434
+		);
2435
+		//setup category select for term parents.
2436
+		$category_select_values[] = array(
2437
+			'text' => esc_html__('No Parent', 'event_espresso'),
2438
+			'id'   => 0,
2439
+		);
2440
+		foreach ($all_terms as $term) {
2441
+			$category_select_values[] = array(
2442
+				'text' => $term->name,
2443
+				'id'   => $term->term_id,
2444
+			);
2445
+		}
2446
+		$category_select = EEH_Form_Fields::select_input(
2447
+			'category_parent',
2448
+			$category_select_values,
2449
+			$this->_category->parent
2450
+		);
2451
+		$template_args = array(
2452
+			'category'                 => $this->_category,
2453
+			'category_select'          => $category_select,
2454
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2455
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2456
+			'disable'                  => '',
2457
+			'disabled_message'         => false,
2458
+		);
2459
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2460
+		return EEH_Template::display_template($template, $template_args, true);
2461
+	}
2462
+
2463
+
2464
+
2465
+	protected function _delete_categories()
2466
+	{
2467
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2468
+			: (array)$this->_req_data['category_id'];
2469
+		foreach ($cat_ids as $cat_id) {
2470
+			$this->_delete_category($cat_id);
2471
+		}
2472
+		//doesn't matter what page we're coming from... we're going to the same place after delete.
2473
+		$query_args = array(
2474
+			'action' => 'category_list',
2475
+		);
2476
+		$this->_redirect_after_action(0, '', '', $query_args);
2477
+	}
2478
+
2479
+
2480
+
2481
+	/**
2482
+	 * @param $cat_id
2483
+	 */
2484
+	protected function _delete_category($cat_id)
2485
+	{
2486
+		$cat_id = absint($cat_id);
2487
+		wp_delete_term($cat_id, 'espresso_event_categories');
2488
+	}
2489
+
2490
+
2491
+
2492
+	/**
2493
+	 * @param $new_category
2494
+	 */
2495
+	protected function _insert_or_update_category($new_category)
2496
+	{
2497
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2498
+		$success = 0; //we already have a success message so lets not send another.
2499
+		if ($cat_id) {
2500
+			$query_args = array(
2501
+				'action'     => 'edit_category',
2502
+				'EVT_CAT_ID' => $cat_id,
2503
+			);
2504
+		} else {
2505
+			$query_args = array('action' => 'add_category');
2506
+		}
2507
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2508
+	}
2509
+
2510
+
2511
+
2512
+	/**
2513
+	 * @param bool $update
2514
+	 * @return bool|mixed|string
2515
+	 */
2516
+	private function _insert_category($update = false)
2517
+	{
2518
+		$cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2519
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2520
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2521
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2522
+		if (empty($category_name)) {
2523
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2524
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2525
+			return false;
2526
+		}
2527
+		$term_args = array(
2528
+			'name'        => $category_name,
2529
+			'description' => $category_desc,
2530
+			'parent'      => $category_parent,
2531
+		);
2532
+		//was the category_identifier input disabled?
2533
+		if (isset($this->_req_data['category_identifier'])) {
2534
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2535
+		}
2536
+		$insert_ids = $update
2537
+			? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2538
+			: wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2539
+		if ( ! is_array($insert_ids)) {
2540
+			$msg = esc_html__(
2541
+				'An error occurred and the category has not been saved to the database.',
2542
+				'event_espresso'
2543
+			);
2544
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2545
+		} else {
2546
+			$cat_id = $insert_ids['term_id'];
2547
+			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2548
+			EE_Error::add_success($msg);
2549
+		}
2550
+		return $cat_id;
2551
+	}
2552
+
2553
+
2554
+
2555
+	/**
2556
+	 * @param int  $per_page
2557
+	 * @param int  $current_page
2558
+	 * @param bool $count
2559
+	 * @return \EE_Base_Class[]|int
2560
+	 */
2561
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2562
+	{
2563
+		//testing term stuff
2564
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2565
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2566
+		$limit = ($current_page - 1) * $per_page;
2567
+		$where = array('taxonomy' => 'espresso_event_categories');
2568
+		if (isset($this->_req_data['s'])) {
2569
+			$sstr = '%' . $this->_req_data['s'] . '%';
2570
+			$where['OR'] = array(
2571
+				'Term.name'   => array('LIKE', $sstr),
2572
+				'description' => array('LIKE', $sstr),
2573
+			);
2574
+		}
2575
+		$query_params = array(
2576
+			$where,
2577
+			'order_by'   => array($orderby => $order),
2578
+			'limit'      => $limit . ',' . $per_page,
2579
+			'force_join' => array('Term'),
2580
+		);
2581
+		$categories = $count
2582
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2583
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2584
+		return $categories;
2585
+	}
2586
+
2587
+
2588
+
2589
+	/* end category stuff */
2590
+	/**************/
2591 2591
 }
2592 2592
 //end class Events_Admin_Page
Please login to merge, or discard this patch.