@@ -12,9 +12,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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,29 +139,29 @@ discard block |
||
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 | - //note: although this table is no longer in use, |
|
153 | - //it hasn't been removed because then queries to the model will have errors. |
|
154 | - //but you should expect this table and its corresponding model to be removed in |
|
155 | - //the next few months |
|
156 | - $table_name = 'esp_currency_payment_method'; |
|
157 | - $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
151 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
152 | + //note: although this table is no longer in use, |
|
153 | + //it hasn't been removed because then queries to the model will have errors. |
|
154 | + //but you should expect this table and its corresponding model to be removed in |
|
155 | + //the next few months |
|
156 | + $table_name = 'esp_currency_payment_method'; |
|
157 | + $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
158 | 158 | CUR_code varchar(6) NOT NULL, |
159 | 159 | PMD_ID int(11) NOT NULL, |
160 | 160 | PRIMARY KEY (CPM_ID), |
161 | 161 | KEY PMD_ID (PMD_ID)"; |
162 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
163 | - $table_name = 'esp_datetime'; |
|
164 | - $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
162 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
163 | + $table_name = 'esp_datetime'; |
|
164 | + $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
165 | 165 | EVT_ID bigint(20) unsigned NOT NULL, |
166 | 166 | DTT_name varchar(255) NOT NULL DEFAULT '', |
167 | 167 | DTT_description text NOT NULL, |
@@ -178,25 +178,25 @@ discard block |
||
178 | 178 | KEY DTT_EVT_start (DTT_EVT_start), |
179 | 179 | KEY EVT_ID (EVT_ID), |
180 | 180 | KEY DTT_is_primary (DTT_is_primary)"; |
181 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
182 | - $table_name = "esp_datetime_ticket"; |
|
183 | - $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
181 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
182 | + $table_name = "esp_datetime_ticket"; |
|
183 | + $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
184 | 184 | DTT_ID int(10) unsigned NOT NULL, |
185 | 185 | TKT_ID int(10) unsigned NOT NULL, |
186 | 186 | PRIMARY KEY (DTK_ID), |
187 | 187 | KEY DTT_ID (DTT_ID), |
188 | 188 | KEY TKT_ID (TKT_ID)"; |
189 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
190 | - $table_name = 'esp_event_message_template'; |
|
191 | - $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
189 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
190 | + $table_name = 'esp_event_message_template'; |
|
191 | + $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
192 | 192 | EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
193 | 193 | GRP_ID int(10) unsigned NOT NULL DEFAULT 0, |
194 | 194 | PRIMARY KEY (EMT_ID), |
195 | 195 | KEY EVT_ID (EVT_ID), |
196 | 196 | KEY GRP_ID (GRP_ID)"; |
197 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | - $table_name = 'esp_event_meta'; |
|
199 | - $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
197 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | + $table_name = 'esp_event_meta'; |
|
199 | + $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
200 | 200 | EVT_ID bigint(20) unsigned NOT NULL, |
201 | 201 | EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1, |
202 | 202 | EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -211,34 +211,34 @@ discard block |
||
211 | 211 | EVT_donations tinyint(1) NULL, |
212 | 212 | PRIMARY KEY (EVTM_ID), |
213 | 213 | KEY EVT_ID (EVT_ID)"; |
214 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
215 | - $table_name = 'esp_event_question_group'; |
|
216 | - $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
214 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
215 | + $table_name = 'esp_event_question_group'; |
|
216 | + $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
217 | 217 | EVT_ID bigint(20) unsigned NOT NULL, |
218 | 218 | QSG_ID int(10) unsigned NOT NULL, |
219 | 219 | EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
220 | 220 | PRIMARY KEY (EQG_ID), |
221 | 221 | KEY EVT_ID (EVT_ID), |
222 | 222 | KEY QSG_ID (QSG_ID)"; |
223 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
224 | - $table_name = 'esp_event_venue'; |
|
225 | - $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
223 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
224 | + $table_name = 'esp_event_venue'; |
|
225 | + $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
226 | 226 | EVT_ID bigint(20) unsigned NOT NULL, |
227 | 227 | VNU_ID bigint(20) unsigned NOT NULL, |
228 | 228 | EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
229 | 229 | PRIMARY KEY (EVV_ID)"; |
230 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
231 | - $table_name = 'esp_extra_meta'; |
|
232 | - $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
230 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
231 | + $table_name = 'esp_extra_meta'; |
|
232 | + $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
233 | 233 | OBJ_ID int(11) DEFAULT NULL, |
234 | 234 | EXM_type varchar(45) DEFAULT NULL, |
235 | 235 | EXM_key varchar(45) DEFAULT NULL, |
236 | 236 | EXM_value text, |
237 | 237 | PRIMARY KEY (EXM_ID), |
238 | 238 | KEY EXM_type (EXM_type,OBJ_ID,EXM_key)"; |
239 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
240 | - $table_name = 'esp_extra_join'; |
|
241 | - $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
239 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
240 | + $table_name = 'esp_extra_join'; |
|
241 | + $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
242 | 242 | EXJ_first_model_id varchar(6) NOT NULL, |
243 | 243 | EXJ_first_model_name varchar(20) NOT NULL, |
244 | 244 | EXJ_second_model_id varchar(6) NOT NULL, |
@@ -246,9 +246,9 @@ discard block |
||
246 | 246 | PRIMARY KEY (EXJ_ID), |
247 | 247 | KEY first_model (EXJ_first_model_name,EXJ_first_model_id), |
248 | 248 | KEY second_model (EXJ_second_model_name,EXJ_second_model_id)"; |
249 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
250 | - $table_name = 'esp_line_item'; |
|
251 | - $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
249 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
250 | + $table_name = 'esp_line_item'; |
|
251 | + $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
252 | 252 | LIN_code varchar(245) NOT NULL DEFAULT '', |
253 | 253 | TXN_ID int(11) DEFAULT NULL, |
254 | 254 | LIN_name varchar(245) NOT NULL DEFAULT '', |
@@ -269,11 +269,11 @@ discard block |
||
269 | 269 | KEY txn_type_timestamp (TXN_ID,LIN_type,LIN_timestamp), |
270 | 270 | KEY txn_obj_id_obj_type (TXN_ID,OBJ_ID,OBJ_type), |
271 | 271 | KEY obj_id_obj_type (OBJ_ID,OBJ_type)"; |
272 | - $this->_get_table_manager()->dropIndex('esp_line_item', 'TXN_ID'); |
|
273 | - $this->_get_table_manager()->dropIndex('esp_line_item', 'LIN_code'); |
|
274 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
275 | - $table_name = 'esp_log'; |
|
276 | - $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
272 | + $this->_get_table_manager()->dropIndex('esp_line_item', 'TXN_ID'); |
|
273 | + $this->_get_table_manager()->dropIndex('esp_line_item', 'LIN_code'); |
|
274 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
275 | + $table_name = 'esp_log'; |
|
276 | + $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
277 | 277 | LOG_time datetime DEFAULT NULL, |
278 | 278 | OBJ_ID varchar(45) DEFAULT NULL, |
279 | 279 | OBJ_type varchar(45) DEFAULT NULL, |
@@ -284,12 +284,12 @@ discard block |
||
284 | 284 | KEY LOG_time (LOG_time), |
285 | 285 | KEY OBJ (OBJ_type,OBJ_ID), |
286 | 286 | KEY LOG_type (LOG_type)"; |
287 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
288 | - $table_name = 'esp_message'; |
|
289 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to'); |
|
290 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from'); |
|
291 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject'); |
|
292 | - $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
287 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
288 | + $table_name = 'esp_message'; |
|
289 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to'); |
|
290 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from'); |
|
291 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject'); |
|
292 | + $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
293 | 293 | GRP_ID int(10) unsigned NULL, |
294 | 294 | MSG_token varchar(255) NULL, |
295 | 295 | TXN_ID int(10) unsigned NULL, |
@@ -321,18 +321,18 @@ discard block |
||
321 | 321 | KEY STS_ID (STS_ID), |
322 | 322 | KEY MSG_created (MSG_created), |
323 | 323 | KEY MSG_modified (MSG_modified)"; |
324 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
325 | - $table_name = 'esp_message_template'; |
|
326 | - $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
324 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
325 | + $table_name = 'esp_message_template'; |
|
326 | + $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
327 | 327 | GRP_ID int(10) unsigned NOT NULL, |
328 | 328 | MTP_context varchar(50) NOT NULL, |
329 | 329 | MTP_template_field varchar(30) NOT NULL, |
330 | 330 | MTP_content text NOT NULL, |
331 | 331 | PRIMARY KEY (MTP_ID), |
332 | 332 | KEY GRP_ID (GRP_ID)"; |
333 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
334 | - $table_name = 'esp_message_template_group'; |
|
335 | - $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
333 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
334 | + $table_name = 'esp_message_template_group'; |
|
335 | + $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
336 | 336 | MTP_user_id int(10) NOT NULL DEFAULT '1', |
337 | 337 | MTP_name varchar(245) NOT NULL DEFAULT '', |
338 | 338 | MTP_description varchar(245) NOT NULL DEFAULT '', |
@@ -344,9 +344,9 @@ discard block |
||
344 | 344 | MTP_is_active tinyint(1) NOT NULL DEFAULT '1', |
345 | 345 | PRIMARY KEY (GRP_ID), |
346 | 346 | KEY MTP_user_id (MTP_user_id)"; |
347 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
348 | - $table_name = 'esp_payment'; |
|
349 | - $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
347 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
348 | + $table_name = 'esp_payment'; |
|
349 | + $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
350 | 350 | TXN_ID int(10) unsigned DEFAULT NULL, |
351 | 351 | STS_ID varchar(3) DEFAULT NULL, |
352 | 352 | PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -363,9 +363,9 @@ discard block |
||
363 | 363 | PRIMARY KEY (PAY_ID), |
364 | 364 | KEY PAY_timestamp (PAY_timestamp), |
365 | 365 | KEY TXN_ID (TXN_ID)"; |
366 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
367 | - $table_name = 'esp_payment_method'; |
|
368 | - $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
366 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
367 | + $table_name = 'esp_payment_method'; |
|
368 | + $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
369 | 369 | PMD_type varchar(124) DEFAULT NULL, |
370 | 370 | PMD_name varchar(255) DEFAULT NULL, |
371 | 371 | PMD_desc text, |
@@ -381,24 +381,24 @@ discard block |
||
381 | 381 | PRIMARY KEY (PMD_ID), |
382 | 382 | UNIQUE KEY PMD_slug_UNIQUE (PMD_slug), |
383 | 383 | KEY PMD_type (PMD_type)"; |
384 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
385 | - $table_name = "esp_ticket_price"; |
|
386 | - $sql = "TKP_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_price"; |
|
386 | + $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
387 | 387 | TKT_ID int(10) unsigned NOT NULL, |
388 | 388 | PRC_ID int(10) unsigned NOT NULL, |
389 | 389 | PRIMARY KEY (TKP_ID), |
390 | 390 | KEY TKT_ID (TKT_ID), |
391 | 391 | KEY PRC_ID (PRC_ID)"; |
392 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
393 | - $table_name = "esp_ticket_template"; |
|
394 | - $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
392 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
393 | + $table_name = "esp_ticket_template"; |
|
394 | + $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
395 | 395 | TTM_name varchar(45) NOT NULL, |
396 | 396 | TTM_description text, |
397 | 397 | TTM_file varchar(45), |
398 | 398 | PRIMARY KEY (TTM_ID)"; |
399 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
400 | - $table_name = 'esp_question'; |
|
401 | - $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
399 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
400 | + $table_name = 'esp_question'; |
|
401 | + $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
402 | 402 | QST_display_text text NOT NULL, |
403 | 403 | QST_admin_label varchar(255) NOT NULL, |
404 | 404 | QST_system varchar(25) DEFAULT NULL, |
@@ -412,18 +412,18 @@ discard block |
||
412 | 412 | QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0, |
413 | 413 | PRIMARY KEY (QST_ID), |
414 | 414 | KEY QST_order (QST_order)'; |
415 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
416 | - $table_name = 'esp_question_group_question'; |
|
417 | - $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
415 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
416 | + $table_name = 'esp_question_group_question'; |
|
417 | + $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
418 | 418 | QSG_ID int(10) unsigned NOT NULL, |
419 | 419 | QST_ID int(10) unsigned NOT NULL, |
420 | 420 | QGQ_order int(10) unsigned NOT NULL DEFAULT 0, |
421 | 421 | PRIMARY KEY (QGQ_ID), |
422 | 422 | KEY QST_ID (QST_ID), |
423 | 423 | KEY QSG_ID_order (QSG_ID,QGQ_order)"; |
424 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
425 | - $table_name = 'esp_question_option'; |
|
426 | - $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
424 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
425 | + $table_name = 'esp_question_option'; |
|
426 | + $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
427 | 427 | QSO_value varchar(255) NOT NULL, |
428 | 428 | QSO_desc text NOT NULL, |
429 | 429 | QST_ID int(10) unsigned NOT NULL, |
@@ -433,9 +433,9 @@ discard block |
||
433 | 433 | PRIMARY KEY (QSO_ID), |
434 | 434 | KEY QST_ID (QST_ID), |
435 | 435 | KEY QSO_order (QSO_order)"; |
436 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
437 | - $table_name = 'esp_registration'; |
|
438 | - $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
436 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
437 | + $table_name = 'esp_registration'; |
|
438 | + $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
439 | 439 | EVT_ID bigint(20) unsigned NOT NULL, |
440 | 440 | ATT_ID bigint(20) unsigned NOT NULL, |
441 | 441 | TXN_ID int(10) unsigned NOT NULL, |
@@ -459,18 +459,18 @@ discard block |
||
459 | 459 | KEY TKT_ID (TKT_ID), |
460 | 460 | KEY EVT_ID (EVT_ID), |
461 | 461 | KEY STS_ID (STS_ID)"; |
462 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
463 | - $table_name = 'esp_registration_payment'; |
|
464 | - $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
462 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
463 | + $table_name = 'esp_registration_payment'; |
|
464 | + $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
465 | 465 | REG_ID int(10) unsigned NOT NULL, |
466 | 466 | PAY_ID int(10) unsigned NULL, |
467 | 467 | RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
468 | 468 | PRIMARY KEY (RPY_ID), |
469 | 469 | KEY REG_ID (REG_ID), |
470 | 470 | KEY PAY_ID (PAY_ID)"; |
471 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
472 | - $table_name = 'esp_state'; |
|
473 | - $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
471 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
472 | + $table_name = 'esp_state'; |
|
473 | + $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
474 | 474 | CNT_ISO varchar(2) NOT NULL, |
475 | 475 | STA_abbrev varchar(24) NOT NULL, |
476 | 476 | STA_name varchar(100) NOT NULL, |
@@ -478,9 +478,9 @@ discard block |
||
478 | 478 | PRIMARY KEY (STA_ID), |
479 | 479 | KEY STA_abbrev (STA_abbrev), |
480 | 480 | KEY CNT_ISO (CNT_ISO)"; |
481 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
482 | - $table_name = 'esp_status'; |
|
483 | - $sql = "STS_ID varchar(3) NOT NULL, |
|
481 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
482 | + $table_name = 'esp_status'; |
|
483 | + $sql = "STS_ID varchar(3) NOT NULL, |
|
484 | 484 | STS_code varchar(45) NOT NULL, |
485 | 485 | STS_type varchar(45) NOT NULL, |
486 | 486 | STS_can_edit tinyint(1) NOT NULL DEFAULT 0, |
@@ -488,9 +488,9 @@ discard block |
||
488 | 488 | STS_open tinyint(1) NOT NULL DEFAULT 1, |
489 | 489 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
490 | 490 | KEY STS_type (STS_type)"; |
491 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
492 | - $table_name = 'esp_transaction'; |
|
493 | - $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
491 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
492 | + $table_name = 'esp_transaction'; |
|
493 | + $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
494 | 494 | TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
495 | 495 | TXN_total decimal(12,3) DEFAULT '0.00', |
496 | 496 | TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00', |
@@ -502,9 +502,9 @@ discard block |
||
502 | 502 | PRIMARY KEY (TXN_ID), |
503 | 503 | KEY TXN_timestamp (TXN_timestamp), |
504 | 504 | KEY STS_ID (STS_ID)"; |
505 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
506 | - $table_name = 'esp_venue_meta'; |
|
507 | - $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
505 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
506 | + $table_name = 'esp_venue_meta'; |
|
507 | + $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
508 | 508 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
509 | 509 | VNU_address varchar(255) DEFAULT NULL, |
510 | 510 | VNU_address2 varchar(255) DEFAULT NULL, |
@@ -523,10 +523,10 @@ discard block |
||
523 | 523 | KEY VNU_ID (VNU_ID), |
524 | 524 | KEY STA_ID (STA_ID), |
525 | 525 | KEY CNT_ISO (CNT_ISO)"; |
526 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
527 | - //modified tables |
|
528 | - $table_name = "esp_price"; |
|
529 | - $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
526 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
527 | + //modified tables |
|
528 | + $table_name = "esp_price"; |
|
529 | + $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
530 | 530 | PRT_ID tinyint(3) unsigned NOT NULL, |
531 | 531 | PRC_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
532 | 532 | PRC_name varchar(245) NOT NULL, |
@@ -539,9 +539,9 @@ discard block |
||
539 | 539 | PRC_parent int(10) unsigned DEFAULT 0, |
540 | 540 | PRIMARY KEY (PRC_ID), |
541 | 541 | KEY PRT_ID (PRT_ID)"; |
542 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
543 | - $table_name = "esp_price_type"; |
|
544 | - $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
542 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
543 | + $table_name = "esp_price_type"; |
|
544 | + $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
545 | 545 | PRT_name varchar(45) NOT NULL, |
546 | 546 | PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1', |
547 | 547 | PRT_is_percent tinyint(1) NOT NULL DEFAULT '0', |
@@ -550,9 +550,9 @@ discard block |
||
550 | 550 | PRT_deleted tinyint(1) NOT NULL DEFAULT '0', |
551 | 551 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
552 | 552 | PRIMARY KEY (PRT_ID)"; |
553 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
554 | - $table_name = "esp_ticket"; |
|
555 | - $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
553 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
554 | + $table_name = "esp_ticket"; |
|
555 | + $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
556 | 556 | TTM_ID int(10) unsigned NOT NULL, |
557 | 557 | TKT_name varchar(245) NOT NULL DEFAULT '', |
558 | 558 | TKT_description text NOT NULL, |
@@ -575,9 +575,9 @@ discard block |
||
575 | 575 | TKT_deleted tinyint(1) NOT NULL DEFAULT '0', |
576 | 576 | PRIMARY KEY (TKT_ID), |
577 | 577 | KEY TKT_start_date (TKT_start_date)"; |
578 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
579 | - $table_name = 'esp_question_group'; |
|
580 | - $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
578 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
579 | + $table_name = 'esp_question_group'; |
|
580 | + $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
581 | 581 | QSG_name varchar(255) NOT NULL, |
582 | 582 | QSG_identifier varchar(100) NOT NULL, |
583 | 583 | QSG_desc text NULL, |
@@ -590,145 +590,145 @@ discard block |
||
590 | 590 | PRIMARY KEY (QSG_ID), |
591 | 591 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier), |
592 | 592 | KEY QSG_order (QSG_order)'; |
593 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
594 | - /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
595 | - $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
596 | - //(because many need to convert old string states to foreign keys into the states table) |
|
597 | - $script_4_1_defaults->insert_default_states(); |
|
598 | - $script_4_1_defaults->insert_default_countries(); |
|
599 | - /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
600 | - $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
601 | - $script_4_5_defaults->insert_default_price_types(); |
|
602 | - $script_4_5_defaults->insert_default_prices(); |
|
603 | - $script_4_5_defaults->insert_default_tickets(); |
|
604 | - /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */ |
|
605 | - $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0'); |
|
606 | - $script_4_6_defaults->add_default_admin_only_payments(); |
|
607 | - $script_4_6_defaults->insert_default_currencies(); |
|
608 | - /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */ |
|
609 | - $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0'); |
|
610 | - $script_4_8_defaults->verify_new_countries(); |
|
611 | - $script_4_8_defaults->verify_new_currencies(); |
|
612 | - $this->verify_db_collations(); |
|
613 | - $this->verify_db_collations_again(); |
|
614 | - return true; |
|
615 | - } |
|
593 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
594 | + /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
595 | + $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
596 | + //(because many need to convert old string states to foreign keys into the states table) |
|
597 | + $script_4_1_defaults->insert_default_states(); |
|
598 | + $script_4_1_defaults->insert_default_countries(); |
|
599 | + /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
600 | + $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
601 | + $script_4_5_defaults->insert_default_price_types(); |
|
602 | + $script_4_5_defaults->insert_default_prices(); |
|
603 | + $script_4_5_defaults->insert_default_tickets(); |
|
604 | + /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */ |
|
605 | + $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0'); |
|
606 | + $script_4_6_defaults->add_default_admin_only_payments(); |
|
607 | + $script_4_6_defaults->insert_default_currencies(); |
|
608 | + /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */ |
|
609 | + $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0'); |
|
610 | + $script_4_8_defaults->verify_new_countries(); |
|
611 | + $script_4_8_defaults->verify_new_currencies(); |
|
612 | + $this->verify_db_collations(); |
|
613 | + $this->verify_db_collations_again(); |
|
614 | + return true; |
|
615 | + } |
|
616 | 616 | |
617 | 617 | |
618 | 618 | |
619 | - /** |
|
620 | - * @return boolean |
|
621 | - */ |
|
622 | - public function schema_changes_after_migration() |
|
623 | - { |
|
624 | - return true; |
|
625 | - } |
|
619 | + /** |
|
620 | + * @return boolean |
|
621 | + */ |
|
622 | + public function schema_changes_after_migration() |
|
623 | + { |
|
624 | + return true; |
|
625 | + } |
|
626 | 626 | |
627 | 627 | |
628 | 628 | |
629 | - public function migration_page_hooks() |
|
630 | - { |
|
631 | - } |
|
629 | + public function migration_page_hooks() |
|
630 | + { |
|
631 | + } |
|
632 | 632 | |
633 | 633 | |
634 | 634 | |
635 | - /** |
|
636 | - * Verify all EE4 models' tables use utf8mb4 collation |
|
637 | - * |
|
638 | - * @return void |
|
639 | - */ |
|
640 | - public function verify_db_collations() |
|
641 | - { |
|
642 | - global $wpdb; |
|
643 | - //double-check we haven't already done it or that that the DB doesn't support utf8mb4 |
|
644 | - if ('utf8mb4' !== $wpdb->charset |
|
645 | - || get_option('ee_verified_db_collations', false)) { |
|
646 | - return; |
|
647 | - } |
|
648 | - // grab tables from each model |
|
649 | - $tables_to_check = array(); |
|
650 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
651 | - if (method_exists($model_name, 'instance')) { |
|
652 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
653 | - if ($model_obj instanceof EEM_Base) { |
|
654 | - foreach ($model_obj->get_tables() as $table) { |
|
655 | - if ( |
|
656 | - strpos($table->get_table_name(), 'esp_') |
|
657 | - && (is_main_site()//for main tables, verify global tables |
|
658 | - || ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up) |
|
659 | - ) |
|
660 | - && function_exists('maybe_convert_table_to_utf8mb4') |
|
661 | - ) { |
|
662 | - $tables_to_check[] = $table->get_table_name(); |
|
663 | - } |
|
664 | - } |
|
665 | - } |
|
666 | - } |
|
667 | - } |
|
668 | - //and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active |
|
669 | - //when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead |
|
670 | - //of hard-coding this |
|
671 | - $addon_tables = array( |
|
672 | - //mailchimp |
|
673 | - 'esp_event_mailchimp_list_group', |
|
674 | - 'esp_event_question_mailchimp_field', |
|
675 | - //multisite |
|
676 | - 'esp_blog_meta', |
|
677 | - //people |
|
678 | - 'esp_people_to_post', |
|
679 | - //promotions |
|
680 | - 'esp_promotion', |
|
681 | - 'esp_promotion_object', |
|
682 | - ); |
|
683 | - foreach ($addon_tables as $table_name) { |
|
684 | - $tables_to_check[] = $table_name; |
|
685 | - } |
|
686 | - $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
687 | - //ok and now let's remember this was done (without needing to check the db schemas all over again) |
|
688 | - add_option('ee_verified_db_collations', true, null, 'no'); |
|
689 | - //seeing how this ran with the fix from 10435, no need to check again |
|
690 | - add_option('ee_verified_db_collations_again',true,null,'no'); |
|
691 | - } |
|
635 | + /** |
|
636 | + * Verify all EE4 models' tables use utf8mb4 collation |
|
637 | + * |
|
638 | + * @return void |
|
639 | + */ |
|
640 | + public function verify_db_collations() |
|
641 | + { |
|
642 | + global $wpdb; |
|
643 | + //double-check we haven't already done it or that that the DB doesn't support utf8mb4 |
|
644 | + if ('utf8mb4' !== $wpdb->charset |
|
645 | + || get_option('ee_verified_db_collations', false)) { |
|
646 | + return; |
|
647 | + } |
|
648 | + // grab tables from each model |
|
649 | + $tables_to_check = array(); |
|
650 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
651 | + if (method_exists($model_name, 'instance')) { |
|
652 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
653 | + if ($model_obj instanceof EEM_Base) { |
|
654 | + foreach ($model_obj->get_tables() as $table) { |
|
655 | + if ( |
|
656 | + strpos($table->get_table_name(), 'esp_') |
|
657 | + && (is_main_site()//for main tables, verify global tables |
|
658 | + || ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up) |
|
659 | + ) |
|
660 | + && function_exists('maybe_convert_table_to_utf8mb4') |
|
661 | + ) { |
|
662 | + $tables_to_check[] = $table->get_table_name(); |
|
663 | + } |
|
664 | + } |
|
665 | + } |
|
666 | + } |
|
667 | + } |
|
668 | + //and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active |
|
669 | + //when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead |
|
670 | + //of hard-coding this |
|
671 | + $addon_tables = array( |
|
672 | + //mailchimp |
|
673 | + 'esp_event_mailchimp_list_group', |
|
674 | + 'esp_event_question_mailchimp_field', |
|
675 | + //multisite |
|
676 | + 'esp_blog_meta', |
|
677 | + //people |
|
678 | + 'esp_people_to_post', |
|
679 | + //promotions |
|
680 | + 'esp_promotion', |
|
681 | + 'esp_promotion_object', |
|
682 | + ); |
|
683 | + foreach ($addon_tables as $table_name) { |
|
684 | + $tables_to_check[] = $table_name; |
|
685 | + } |
|
686 | + $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
687 | + //ok and now let's remember this was done (without needing to check the db schemas all over again) |
|
688 | + add_option('ee_verified_db_collations', true, null, 'no'); |
|
689 | + //seeing how this ran with the fix from 10435, no need to check again |
|
690 | + add_option('ee_verified_db_collations_again',true,null,'no'); |
|
691 | + } |
|
692 | 692 | |
693 | 693 | |
694 | 694 | |
695 | - /** |
|
696 | - * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435 |
|
697 | - * which meant some DB collations might not have been updated |
|
698 | - * @return void |
|
699 | - */ |
|
700 | - public function verify_db_collations_again(){ |
|
701 | - global $wpdb; |
|
702 | - //double-check we haven't already done this or that the DB doesn't support it |
|
703 | - //compare to how WordPress' upgrade_430() function does this check |
|
704 | - if ('utf8mb4' !== $wpdb->charset |
|
705 | - || get_option('ee_verified_db_collations_again', false)) { |
|
706 | - return; |
|
707 | - } |
|
708 | - $tables_to_check = array( |
|
709 | - 'esp_attendee_meta', |
|
710 | - 'esp_message' |
|
711 | - ); |
|
712 | - $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
713 | - add_option('ee_verified_db_collations_again',true,null,'no'); |
|
714 | - } |
|
695 | + /** |
|
696 | + * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435 |
|
697 | + * which meant some DB collations might not have been updated |
|
698 | + * @return void |
|
699 | + */ |
|
700 | + public function verify_db_collations_again(){ |
|
701 | + global $wpdb; |
|
702 | + //double-check we haven't already done this or that the DB doesn't support it |
|
703 | + //compare to how WordPress' upgrade_430() function does this check |
|
704 | + if ('utf8mb4' !== $wpdb->charset |
|
705 | + || get_option('ee_verified_db_collations_again', false)) { |
|
706 | + return; |
|
707 | + } |
|
708 | + $tables_to_check = array( |
|
709 | + 'esp_attendee_meta', |
|
710 | + 'esp_message' |
|
711 | + ); |
|
712 | + $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
713 | + add_option('ee_verified_db_collations_again',true,null,'no'); |
|
714 | + } |
|
715 | 715 | |
716 | 716 | |
717 | 717 | |
718 | - /** |
|
719 | - * Runs maybe_convert_table_to_utf8mb4 on the specified tables |
|
720 | - * @param $tables_to_check |
|
721 | - * @return boolean true if logic ran, false if it didn't |
|
722 | - */ |
|
723 | - protected function _verify_db_collations_for_tables($tables_to_check) |
|
724 | - { |
|
725 | - foreach ($tables_to_check as $table_name) { |
|
726 | - $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name); |
|
727 | - if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name ) |
|
728 | - && $this->_get_table_analysis()->tableExists($table_name) |
|
729 | - ) { |
|
730 | - maybe_convert_table_to_utf8mb4($table_name); |
|
731 | - } |
|
732 | - } |
|
733 | - } |
|
718 | + /** |
|
719 | + * Runs maybe_convert_table_to_utf8mb4 on the specified tables |
|
720 | + * @param $tables_to_check |
|
721 | + * @return boolean true if logic ran, false if it didn't |
|
722 | + */ |
|
723 | + protected function _verify_db_collations_for_tables($tables_to_check) |
|
724 | + { |
|
725 | + foreach ($tables_to_check as $table_name) { |
|
726 | + $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name); |
|
727 | + if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name ) |
|
728 | + && $this->_get_table_analysis()->tableExists($table_name) |
|
729 | + ) { |
|
730 | + maybe_convert_table_to_utf8mb4($table_name); |
|
731 | + } |
|
732 | + } |
|
733 | + } |
|
734 | 734 | } |
735 | 735 | \ No newline at end of file |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\widgets\EspressoWidget; |
5 | 5 | |
6 | 6 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -27,380 +27,380 @@ discard block |
||
27 | 27 | final class EE_Front_Controller |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * @var string $_template_path |
|
32 | - */ |
|
33 | - private $_template_path; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string $_template |
|
37 | - */ |
|
38 | - private $_template; |
|
39 | - |
|
40 | - /** |
|
41 | - * @type EE_Registry $Registry |
|
42 | - */ |
|
43 | - protected $Registry; |
|
44 | - |
|
45 | - /** |
|
46 | - * @type EE_Request_Handler $Request_Handler |
|
47 | - */ |
|
48 | - protected $Request_Handler; |
|
49 | - |
|
50 | - /** |
|
51 | - * @type EE_Module_Request_Router $Module_Request_Router |
|
52 | - */ |
|
53 | - protected $Module_Request_Router; |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * class constructor |
|
58 | - * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
59 | - * |
|
60 | - * @access public |
|
61 | - * @param \EE_Registry $Registry |
|
62 | - * @param \EE_Request_Handler $Request_Handler |
|
63 | - * @param \EE_Module_Request_Router $Module_Request_Router |
|
64 | - */ |
|
65 | - public function __construct( |
|
66 | - EE_Registry $Registry, |
|
67 | - EE_Request_Handler $Request_Handler, |
|
68 | - EE_Module_Request_Router $Module_Request_Router |
|
69 | - ) { |
|
70 | - $this->Registry = $Registry; |
|
71 | - $this->Request_Handler = $Request_Handler; |
|
72 | - $this->Module_Request_Router = $Module_Request_Router; |
|
73 | - // determine how to integrate WP_Query with the EE models |
|
74 | - add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
75 | - // load other resources and begin to actually run shortcodes and modules |
|
76 | - add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
77 | - // analyse the incoming WP request |
|
78 | - add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
79 | - // process request with module factory |
|
80 | - add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
81 | - // before headers sent |
|
82 | - add_action('wp', array($this, 'wp'), 5); |
|
83 | - // primarily used to process any content shortcodes |
|
84 | - add_action('template_redirect', array($this, 'templateRedirect'), 999); |
|
85 | - // header |
|
86 | - add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
87 | - add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
88 | - add_filter('template_include', array($this, 'template_include'), 1); |
|
89 | - // display errors |
|
90 | - add_action('loop_start', array($this, 'display_errors'), 2); |
|
91 | - // the content |
|
92 | - // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
93 | - //exclude our private cpt comments |
|
94 | - add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
95 | - //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
96 | - add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
97 | - // action hook EE |
|
98 | - do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * @return EE_Request_Handler |
|
104 | - */ |
|
105 | - public function Request_Handler() |
|
106 | - { |
|
107 | - return $this->Request_Handler; |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @return EE_Module_Request_Router |
|
113 | - */ |
|
114 | - public function Module_Request_Router() |
|
115 | - { |
|
116 | - return $this->Module_Request_Router; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @return LegacyShortcodesManager |
|
123 | - */ |
|
124 | - public function getLegacyShortcodesManager() |
|
125 | - { |
|
126 | - return EE_Config::getLegacyShortcodesManager(); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * filter_wp_comments |
|
139 | - * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
140 | - * widgets/queries done on frontend |
|
141 | - * |
|
142 | - * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
143 | - * @return array array of comment clauses with modifications. |
|
144 | - */ |
|
145 | - public function filter_wp_comments($clauses) |
|
146 | - { |
|
147 | - global $wpdb; |
|
148 | - if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
149 | - $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
150 | - foreach ($cpts as $cpt => $details) { |
|
151 | - $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
152 | - } |
|
153 | - } |
|
154 | - return $clauses; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * @return void |
|
160 | - * @throws EE_Error |
|
161 | - * @throws ReflectionException |
|
162 | - */ |
|
163 | - public function employ_CPT_Strategy() |
|
164 | - { |
|
165 | - if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
166 | - $this->Registry->load_core('CPT_Strategy'); |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
173 | - * |
|
174 | - * @param string $url incoming url |
|
175 | - * @return string final assembled url |
|
176 | - */ |
|
177 | - public function maybe_force_admin_ajax_ssl($url) |
|
178 | - { |
|
179 | - if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
180 | - $url = str_replace('http://', 'https://', $url); |
|
181 | - } |
|
182 | - return $url; |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - |
|
189 | - |
|
190 | - /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
195 | - * default priority init phases have run |
|
196 | - * |
|
197 | - * @access public |
|
198 | - * @return void |
|
199 | - */ |
|
200 | - public function wp_loaded() |
|
201 | - { |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - |
|
206 | - |
|
207 | - |
|
208 | - /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
209 | - /** |
|
210 | - * _get_request |
|
211 | - * |
|
212 | - * @access public |
|
213 | - * @param WP $WP |
|
214 | - * @return void |
|
215 | - */ |
|
216 | - public function get_request(WP $WP) |
|
217 | - { |
|
218 | - do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
219 | - $this->Request_Handler->parse_request($WP); |
|
220 | - do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
227 | - * |
|
228 | - * @access public |
|
229 | - * @param WP_Query $WP_Query |
|
230 | - * @return void |
|
231 | - */ |
|
232 | - public function pre_get_posts($WP_Query) |
|
233 | - { |
|
234 | - // only load Module_Request_Router if this is the main query |
|
235 | - if ( |
|
236 | - $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
237 | - && $WP_Query->is_main_query() |
|
238 | - ) { |
|
239 | - // cycle thru module routes |
|
240 | - while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
241 | - // determine module and method for route |
|
242 | - $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
243 | - if ($module instanceof EED_Module) { |
|
244 | - // get registered view for route |
|
245 | - $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
246 | - // grab module name |
|
247 | - $module_name = $module->module_name(); |
|
248 | - // map the module to the module objects |
|
249 | - $this->Registry->modules->{$module_name} = $module; |
|
250 | - } |
|
251 | - } |
|
252 | - } |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - |
|
257 | - |
|
258 | - |
|
259 | - /*********************************************** WP HOOK ***********************************************/ |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * wp - basically last chance to do stuff before headers sent |
|
264 | - * |
|
265 | - * @access public |
|
266 | - * @return void |
|
267 | - */ |
|
268 | - public function wp() |
|
269 | - { |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - |
|
274 | - /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
275 | - |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * callback for the "template_redirect" hook point |
|
280 | - * checks sidebars for EE widgets |
|
281 | - * loads resources and assets accordingly |
|
282 | - * |
|
283 | - * @return void |
|
284 | - */ |
|
285 | - public function templateRedirect() |
|
286 | - { |
|
287 | - global $wp_query; |
|
288 | - if (empty($wp_query->posts)){ |
|
289 | - return; |
|
290 | - } |
|
291 | - // if we already know this is an espresso page, then load assets |
|
292 | - $load_assets = $this->Request_Handler->is_espresso_page(); |
|
293 | - // if we are already loading assets then just move along, otherwise check for widgets |
|
294 | - $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
295 | - if ( $load_assets){ |
|
296 | - add_action('wp_enqueue_scripts', array($this, 'enqueueStyle'), 10); |
|
297 | - add_action('wp_print_footer_scripts', array($this, 'enqueueScripts'), 10); |
|
298 | - } |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * builds list of active widgets then scans active sidebars looking for them |
|
305 | - * returns true is an EE widget is found in an active sidebar |
|
306 | - * Please Note: this does NOT mean that the sidebar or widget |
|
307 | - * is actually in use in a given template, as that is unfortunately not known |
|
308 | - * until a sidebar and it's widgets are actually loaded |
|
309 | - * |
|
310 | - * @return boolean |
|
311 | - */ |
|
312 | - private function espresso_widgets_in_active_sidebars() |
|
313 | - { |
|
314 | - $espresso_widgets = array(); |
|
315 | - foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
316 | - $id_base = EspressoWidget::getIdBase($widget_class); |
|
317 | - if (is_active_widget(false, false, $id_base)) { |
|
318 | - $espresso_widgets[] = $id_base; |
|
319 | - } |
|
320 | - } |
|
321 | - $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
322 | - foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
323 | - if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
324 | - foreach ($sidebar_widgets as $sidebar_widget) { |
|
325 | - foreach ($espresso_widgets as $espresso_widget) { |
|
326 | - if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
327 | - return true; |
|
328 | - } |
|
329 | - } |
|
330 | - } |
|
331 | - } |
|
332 | - } |
|
333 | - return false; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * header_meta_tag |
|
341 | - * |
|
342 | - * @access public |
|
343 | - * @return void |
|
344 | - */ |
|
345 | - public function header_meta_tag() |
|
346 | - { |
|
347 | - print( |
|
348 | - apply_filters( |
|
349 | - 'FHEE__EE_Front_Controller__header_meta_tag', |
|
350 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
351 | - ); |
|
352 | - |
|
353 | - //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
354 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
355 | - //also exclude all critical pages from indexing |
|
356 | - if ( |
|
357 | - ( |
|
358 | - is_tax('espresso_event_type') |
|
359 | - && get_option( 'blog_public' ) !== '0' |
|
360 | - ) |
|
361 | - || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
362 | - ) { |
|
363 | - print( |
|
364 | - apply_filters( |
|
365 | - 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
366 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
367 | - ) |
|
368 | - ); |
|
369 | - } |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * wp_print_scripts |
|
376 | - * |
|
377 | - * @return void |
|
378 | - */ |
|
379 | - public function wp_print_scripts() |
|
380 | - { |
|
381 | - global $post; |
|
382 | - if ( |
|
383 | - isset($post->EE_Event) |
|
384 | - && $post->EE_Event instanceof EE_Event |
|
385 | - && get_post_type() === 'espresso_events' |
|
386 | - && is_singular() |
|
387 | - ) { |
|
388 | - \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
389 | - } |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - |
|
394 | - public function enqueueStyle() |
|
395 | - { |
|
396 | - wp_enqueue_style('espresso_default'); |
|
397 | - wp_enqueue_style('espresso_custom_css'); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - |
|
402 | - |
|
403 | - /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
|
30 | + /** |
|
31 | + * @var string $_template_path |
|
32 | + */ |
|
33 | + private $_template_path; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string $_template |
|
37 | + */ |
|
38 | + private $_template; |
|
39 | + |
|
40 | + /** |
|
41 | + * @type EE_Registry $Registry |
|
42 | + */ |
|
43 | + protected $Registry; |
|
44 | + |
|
45 | + /** |
|
46 | + * @type EE_Request_Handler $Request_Handler |
|
47 | + */ |
|
48 | + protected $Request_Handler; |
|
49 | + |
|
50 | + /** |
|
51 | + * @type EE_Module_Request_Router $Module_Request_Router |
|
52 | + */ |
|
53 | + protected $Module_Request_Router; |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * class constructor |
|
58 | + * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
59 | + * |
|
60 | + * @access public |
|
61 | + * @param \EE_Registry $Registry |
|
62 | + * @param \EE_Request_Handler $Request_Handler |
|
63 | + * @param \EE_Module_Request_Router $Module_Request_Router |
|
64 | + */ |
|
65 | + public function __construct( |
|
66 | + EE_Registry $Registry, |
|
67 | + EE_Request_Handler $Request_Handler, |
|
68 | + EE_Module_Request_Router $Module_Request_Router |
|
69 | + ) { |
|
70 | + $this->Registry = $Registry; |
|
71 | + $this->Request_Handler = $Request_Handler; |
|
72 | + $this->Module_Request_Router = $Module_Request_Router; |
|
73 | + // determine how to integrate WP_Query with the EE models |
|
74 | + add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
75 | + // load other resources and begin to actually run shortcodes and modules |
|
76 | + add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
77 | + // analyse the incoming WP request |
|
78 | + add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
79 | + // process request with module factory |
|
80 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
81 | + // before headers sent |
|
82 | + add_action('wp', array($this, 'wp'), 5); |
|
83 | + // primarily used to process any content shortcodes |
|
84 | + add_action('template_redirect', array($this, 'templateRedirect'), 999); |
|
85 | + // header |
|
86 | + add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
87 | + add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
88 | + add_filter('template_include', array($this, 'template_include'), 1); |
|
89 | + // display errors |
|
90 | + add_action('loop_start', array($this, 'display_errors'), 2); |
|
91 | + // the content |
|
92 | + // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
93 | + //exclude our private cpt comments |
|
94 | + add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
95 | + //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
96 | + add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
97 | + // action hook EE |
|
98 | + do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * @return EE_Request_Handler |
|
104 | + */ |
|
105 | + public function Request_Handler() |
|
106 | + { |
|
107 | + return $this->Request_Handler; |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @return EE_Module_Request_Router |
|
113 | + */ |
|
114 | + public function Module_Request_Router() |
|
115 | + { |
|
116 | + return $this->Module_Request_Router; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @return LegacyShortcodesManager |
|
123 | + */ |
|
124 | + public function getLegacyShortcodesManager() |
|
125 | + { |
|
126 | + return EE_Config::getLegacyShortcodesManager(); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * filter_wp_comments |
|
139 | + * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
140 | + * widgets/queries done on frontend |
|
141 | + * |
|
142 | + * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
143 | + * @return array array of comment clauses with modifications. |
|
144 | + */ |
|
145 | + public function filter_wp_comments($clauses) |
|
146 | + { |
|
147 | + global $wpdb; |
|
148 | + if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
149 | + $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
150 | + foreach ($cpts as $cpt => $details) { |
|
151 | + $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
152 | + } |
|
153 | + } |
|
154 | + return $clauses; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * @return void |
|
160 | + * @throws EE_Error |
|
161 | + * @throws ReflectionException |
|
162 | + */ |
|
163 | + public function employ_CPT_Strategy() |
|
164 | + { |
|
165 | + if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
166 | + $this->Registry->load_core('CPT_Strategy'); |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
173 | + * |
|
174 | + * @param string $url incoming url |
|
175 | + * @return string final assembled url |
|
176 | + */ |
|
177 | + public function maybe_force_admin_ajax_ssl($url) |
|
178 | + { |
|
179 | + if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
180 | + $url = str_replace('http://', 'https://', $url); |
|
181 | + } |
|
182 | + return $url; |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + |
|
189 | + |
|
190 | + /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
195 | + * default priority init phases have run |
|
196 | + * |
|
197 | + * @access public |
|
198 | + * @return void |
|
199 | + */ |
|
200 | + public function wp_loaded() |
|
201 | + { |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + |
|
206 | + |
|
207 | + |
|
208 | + /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
209 | + /** |
|
210 | + * _get_request |
|
211 | + * |
|
212 | + * @access public |
|
213 | + * @param WP $WP |
|
214 | + * @return void |
|
215 | + */ |
|
216 | + public function get_request(WP $WP) |
|
217 | + { |
|
218 | + do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
219 | + $this->Request_Handler->parse_request($WP); |
|
220 | + do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
227 | + * |
|
228 | + * @access public |
|
229 | + * @param WP_Query $WP_Query |
|
230 | + * @return void |
|
231 | + */ |
|
232 | + public function pre_get_posts($WP_Query) |
|
233 | + { |
|
234 | + // only load Module_Request_Router if this is the main query |
|
235 | + if ( |
|
236 | + $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
237 | + && $WP_Query->is_main_query() |
|
238 | + ) { |
|
239 | + // cycle thru module routes |
|
240 | + while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
241 | + // determine module and method for route |
|
242 | + $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
243 | + if ($module instanceof EED_Module) { |
|
244 | + // get registered view for route |
|
245 | + $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
246 | + // grab module name |
|
247 | + $module_name = $module->module_name(); |
|
248 | + // map the module to the module objects |
|
249 | + $this->Registry->modules->{$module_name} = $module; |
|
250 | + } |
|
251 | + } |
|
252 | + } |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + |
|
257 | + |
|
258 | + |
|
259 | + /*********************************************** WP HOOK ***********************************************/ |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * wp - basically last chance to do stuff before headers sent |
|
264 | + * |
|
265 | + * @access public |
|
266 | + * @return void |
|
267 | + */ |
|
268 | + public function wp() |
|
269 | + { |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + |
|
274 | + /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
275 | + |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * callback for the "template_redirect" hook point |
|
280 | + * checks sidebars for EE widgets |
|
281 | + * loads resources and assets accordingly |
|
282 | + * |
|
283 | + * @return void |
|
284 | + */ |
|
285 | + public function templateRedirect() |
|
286 | + { |
|
287 | + global $wp_query; |
|
288 | + if (empty($wp_query->posts)){ |
|
289 | + return; |
|
290 | + } |
|
291 | + // if we already know this is an espresso page, then load assets |
|
292 | + $load_assets = $this->Request_Handler->is_espresso_page(); |
|
293 | + // if we are already loading assets then just move along, otherwise check for widgets |
|
294 | + $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
295 | + if ( $load_assets){ |
|
296 | + add_action('wp_enqueue_scripts', array($this, 'enqueueStyle'), 10); |
|
297 | + add_action('wp_print_footer_scripts', array($this, 'enqueueScripts'), 10); |
|
298 | + } |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * builds list of active widgets then scans active sidebars looking for them |
|
305 | + * returns true is an EE widget is found in an active sidebar |
|
306 | + * Please Note: this does NOT mean that the sidebar or widget |
|
307 | + * is actually in use in a given template, as that is unfortunately not known |
|
308 | + * until a sidebar and it's widgets are actually loaded |
|
309 | + * |
|
310 | + * @return boolean |
|
311 | + */ |
|
312 | + private function espresso_widgets_in_active_sidebars() |
|
313 | + { |
|
314 | + $espresso_widgets = array(); |
|
315 | + foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
316 | + $id_base = EspressoWidget::getIdBase($widget_class); |
|
317 | + if (is_active_widget(false, false, $id_base)) { |
|
318 | + $espresso_widgets[] = $id_base; |
|
319 | + } |
|
320 | + } |
|
321 | + $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
322 | + foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
323 | + if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
324 | + foreach ($sidebar_widgets as $sidebar_widget) { |
|
325 | + foreach ($espresso_widgets as $espresso_widget) { |
|
326 | + if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
327 | + return true; |
|
328 | + } |
|
329 | + } |
|
330 | + } |
|
331 | + } |
|
332 | + } |
|
333 | + return false; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * header_meta_tag |
|
341 | + * |
|
342 | + * @access public |
|
343 | + * @return void |
|
344 | + */ |
|
345 | + public function header_meta_tag() |
|
346 | + { |
|
347 | + print( |
|
348 | + apply_filters( |
|
349 | + 'FHEE__EE_Front_Controller__header_meta_tag', |
|
350 | + '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
351 | + ); |
|
352 | + |
|
353 | + //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
354 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
355 | + //also exclude all critical pages from indexing |
|
356 | + if ( |
|
357 | + ( |
|
358 | + is_tax('espresso_event_type') |
|
359 | + && get_option( 'blog_public' ) !== '0' |
|
360 | + ) |
|
361 | + || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
362 | + ) { |
|
363 | + print( |
|
364 | + apply_filters( |
|
365 | + 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
366 | + '<meta name="robots" content="noindex,follow" />' . "\n" |
|
367 | + ) |
|
368 | + ); |
|
369 | + } |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * wp_print_scripts |
|
376 | + * |
|
377 | + * @return void |
|
378 | + */ |
|
379 | + public function wp_print_scripts() |
|
380 | + { |
|
381 | + global $post; |
|
382 | + if ( |
|
383 | + isset($post->EE_Event) |
|
384 | + && $post->EE_Event instanceof EE_Event |
|
385 | + && get_post_type() === 'espresso_events' |
|
386 | + && is_singular() |
|
387 | + ) { |
|
388 | + \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
389 | + } |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + |
|
394 | + public function enqueueStyle() |
|
395 | + { |
|
396 | + wp_enqueue_style('espresso_default'); |
|
397 | + wp_enqueue_style('espresso_custom_css'); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + |
|
402 | + |
|
403 | + /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
|
404 | 404 | |
405 | 405 | |
406 | 406 | |
@@ -411,117 +411,117 @@ discard block |
||
411 | 411 | // * @param $the_content |
412 | 412 | // * @return string |
413 | 413 | // */ |
414 | - // public function the_content( $the_content ) { |
|
415 | - // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
416 | - // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
417 | - // } |
|
418 | - // return $the_content; |
|
419 | - // } |
|
420 | - |
|
421 | - |
|
422 | - |
|
423 | - /*********************************************** WP_FOOTER ***********************************************/ |
|
424 | - |
|
425 | - |
|
426 | - |
|
427 | - public function enqueueScripts() |
|
428 | - { |
|
429 | - wp_enqueue_script('espresso_core'); |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - |
|
434 | - /** |
|
435 | - * display_errors |
|
436 | - * |
|
437 | - * @access public |
|
438 | - * @return void |
|
439 | - * @throws DomainException |
|
440 | - */ |
|
441 | - public function display_errors() |
|
442 | - { |
|
443 | - static $shown_already = false; |
|
444 | - do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
445 | - if ( |
|
446 | - ! $shown_already |
|
447 | - && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
448 | - && is_main_query() |
|
449 | - && ! is_feed() |
|
450 | - && in_the_loop() |
|
451 | - && $this->Request_Handler->is_espresso_page() |
|
452 | - ) { |
|
453 | - echo EE_Error::get_notices(); |
|
454 | - $shown_already = true; |
|
455 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
456 | - } |
|
457 | - do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - |
|
462 | - |
|
463 | - |
|
464 | - /*********************************************** UTILITIES ***********************************************/ |
|
465 | - /** |
|
466 | - * template_include |
|
467 | - * |
|
468 | - * @access public |
|
469 | - * @param string $template_include_path |
|
470 | - * @return string |
|
471 | - */ |
|
472 | - public function template_include($template_include_path = null) |
|
473 | - { |
|
474 | - if ($this->Request_Handler->is_espresso_page()) { |
|
475 | - $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
476 | - $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
477 | - $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
478 | - $this->_template = basename($this->_template_path); |
|
479 | - return $this->_template_path; |
|
480 | - } |
|
481 | - return $template_include_path; |
|
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - /** |
|
486 | - * get_selected_template |
|
487 | - * |
|
488 | - * @access public |
|
489 | - * @param bool $with_path |
|
490 | - * @return string |
|
491 | - */ |
|
492 | - public function get_selected_template($with_path = false) |
|
493 | - { |
|
494 | - return $with_path ? $this->_template_path : $this->_template; |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - |
|
499 | - /** |
|
500 | - * @deprecated 4.9.26 |
|
501 | - * @param string $shortcode_class |
|
502 | - * @param \WP $wp |
|
503 | - */ |
|
504 | - public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
505 | - { |
|
506 | - \EE_Error::doing_it_wrong( |
|
507 | - __METHOD__, |
|
508 | - __( |
|
509 | - 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
510 | - 'event_espresso' |
|
511 | - ), |
|
512 | - '4.9.26' |
|
513 | - ); |
|
514 | - $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /** |
|
519 | - * @return void |
|
520 | - * @deprecated 4.9.57.p |
|
521 | - */ |
|
522 | - public function loadPersistentAdminNoticeManager() |
|
523 | - { |
|
524 | - } |
|
414 | + // public function the_content( $the_content ) { |
|
415 | + // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
416 | + // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
417 | + // } |
|
418 | + // return $the_content; |
|
419 | + // } |
|
420 | + |
|
421 | + |
|
422 | + |
|
423 | + /*********************************************** WP_FOOTER ***********************************************/ |
|
424 | + |
|
425 | + |
|
426 | + |
|
427 | + public function enqueueScripts() |
|
428 | + { |
|
429 | + wp_enqueue_script('espresso_core'); |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + |
|
434 | + /** |
|
435 | + * display_errors |
|
436 | + * |
|
437 | + * @access public |
|
438 | + * @return void |
|
439 | + * @throws DomainException |
|
440 | + */ |
|
441 | + public function display_errors() |
|
442 | + { |
|
443 | + static $shown_already = false; |
|
444 | + do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
445 | + if ( |
|
446 | + ! $shown_already |
|
447 | + && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
448 | + && is_main_query() |
|
449 | + && ! is_feed() |
|
450 | + && in_the_loop() |
|
451 | + && $this->Request_Handler->is_espresso_page() |
|
452 | + ) { |
|
453 | + echo EE_Error::get_notices(); |
|
454 | + $shown_already = true; |
|
455 | + EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
456 | + } |
|
457 | + do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + |
|
462 | + |
|
463 | + |
|
464 | + /*********************************************** UTILITIES ***********************************************/ |
|
465 | + /** |
|
466 | + * template_include |
|
467 | + * |
|
468 | + * @access public |
|
469 | + * @param string $template_include_path |
|
470 | + * @return string |
|
471 | + */ |
|
472 | + public function template_include($template_include_path = null) |
|
473 | + { |
|
474 | + if ($this->Request_Handler->is_espresso_page()) { |
|
475 | + $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
476 | + $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
477 | + $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
478 | + $this->_template = basename($this->_template_path); |
|
479 | + return $this->_template_path; |
|
480 | + } |
|
481 | + return $template_include_path; |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + /** |
|
486 | + * get_selected_template |
|
487 | + * |
|
488 | + * @access public |
|
489 | + * @param bool $with_path |
|
490 | + * @return string |
|
491 | + */ |
|
492 | + public function get_selected_template($with_path = false) |
|
493 | + { |
|
494 | + return $with_path ? $this->_template_path : $this->_template; |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + |
|
499 | + /** |
|
500 | + * @deprecated 4.9.26 |
|
501 | + * @param string $shortcode_class |
|
502 | + * @param \WP $wp |
|
503 | + */ |
|
504 | + public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
505 | + { |
|
506 | + \EE_Error::doing_it_wrong( |
|
507 | + __METHOD__, |
|
508 | + __( |
|
509 | + 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
510 | + 'event_espresso' |
|
511 | + ), |
|
512 | + '4.9.26' |
|
513 | + ); |
|
514 | + $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /** |
|
519 | + * @return void |
|
520 | + * @deprecated 4.9.57.p |
|
521 | + */ |
|
522 | + public function loadPersistentAdminNoticeManager() |
|
523 | + { |
|
524 | + } |
|
525 | 525 | } |
526 | 526 | // End of file EE_Front_Controller.core.php |
527 | 527 | // Location: /core/EE_Front_Controller.core.php |
@@ -1,66 +1,66 @@ |
||
1 | 1 | <?php |
2 | 2 | //echo '<br/><h6 style="color:#2EA2CC;">'. __FILE__ . ' <span style="font-weight:normal;color:#E76700"> Line #: ' . __LINE__ . '</span></h6>'; |
3 | 3 | if ( |
4 | - ( is_single() && espresso_display_venue_in_event_details() ) |
|
5 | - || ( is_archive() && espresso_display_venue_in_event_list() ) |
|
4 | + (is_single() && espresso_display_venue_in_event_details()) |
|
5 | + || (is_archive() && espresso_display_venue_in_event_list()) |
|
6 | 6 | ) : |
7 | 7 | global $post; |
8 | - do_action( 'AHEE_event_details_before_venue_details', $post ); |
|
9 | - $venue_name = espresso_venue_name( 0, 'details', FALSE ); |
|
10 | - if ( empty( $venue_name ) && espresso_is_venue_private() ) { |
|
11 | - do_action( 'AHEE_event_details_after_venue_details', $post ); |
|
8 | + do_action('AHEE_event_details_before_venue_details', $post); |
|
9 | + $venue_name = espresso_venue_name(0, 'details', FALSE); |
|
10 | + if (empty($venue_name) && espresso_is_venue_private()) { |
|
11 | + do_action('AHEE_event_details_after_venue_details', $post); |
|
12 | 12 | return ''; |
13 | 13 | } |
14 | 14 | ?> |
15 | 15 | |
16 | 16 | <div class="espresso-venue-dv<?php echo espresso_is_venue_private() ? ' espresso-private-venue-dv' : ''; ?>"> |
17 | - <h4><strong><?php _e( 'Venue:', 'event_espresso' ); ?></strong> <strong> <?php echo $venue_name; ?></strong></h4> |
|
17 | + <h4><strong><?php _e('Venue:', 'event_espresso'); ?></strong> <strong> <?php echo $venue_name; ?></strong></h4> |
|
18 | 18 | <p><span class="smaller-text tags-links"><?php echo espresso_venue_categories(); ?></span></p> |
19 | -<?php if ( $venue_phone = espresso_venue_phone( $post->ID, FALSE )) : ?> |
|
19 | +<?php if ($venue_phone = espresso_venue_phone($post->ID, FALSE)) : ?> |
|
20 | 20 | <p> |
21 | - <span class="small-text"><strong><?php _e( 'Venue Phone:', 'event_espresso' ); ?></strong></span> <?php echo $venue_phone; ?> |
|
21 | + <span class="small-text"><strong><?php _e('Venue Phone:', 'event_espresso'); ?></strong></span> <?php echo $venue_phone; ?> |
|
22 | 22 | </p> |
23 | -<?php endif; ?> |
|
24 | -<?php if ( $venue_website = espresso_venue_website( $post->ID, FALSE )) : ?> |
|
23 | +<?php endif; ?> |
|
24 | +<?php if ($venue_website = espresso_venue_website($post->ID, FALSE)) : ?> |
|
25 | 25 | <p> |
26 | - <span class="small-text"><strong><?php _e( 'Venue Website:', 'event_espresso' ); ?></strong></span> <?php echo $venue_website; ?> |
|
26 | + <span class="small-text"><strong><?php _e('Venue Website:', 'event_espresso'); ?></strong></span> <?php echo $venue_website; ?> |
|
27 | 27 | </p> |
28 | 28 | <?php endif; ?> |
29 | -<?php if ( espresso_venue_has_address( $post->ID )) : ?> |
|
30 | - <strong><span class="dashicons dashicons-location-alt"></span><?php _e( 'Address:', 'event_espresso' ); ?></strong> |
|
31 | - <?php espresso_venue_address( 'inline' ); ?> |
|
32 | - <?php espresso_venue_gmap( $post->ID ); ?> |
|
29 | +<?php if (espresso_venue_has_address($post->ID)) : ?> |
|
30 | + <strong><span class="dashicons dashicons-location-alt"></span><?php _e('Address:', 'event_espresso'); ?></strong> |
|
31 | + <?php espresso_venue_address('inline'); ?> |
|
32 | + <?php espresso_venue_gmap($post->ID); ?> |
|
33 | 33 | <div class="clear"><br/></div> |
34 | -<?php endif; ?> |
|
34 | +<?php endif; ?> |
|
35 | 35 | |
36 | - <?php $VNU_ID = espresso_venue_id( $post->ID ); ?> |
|
37 | - <?php if ( is_single() ) : ?> |
|
38 | - <?php $venue_description = espresso_venue_description( $VNU_ID, FALSE ); ?> |
|
39 | - <?php if ( $venue_description ) : ?> |
|
36 | + <?php $VNU_ID = espresso_venue_id($post->ID); ?> |
|
37 | + <?php if (is_single()) : ?> |
|
38 | + <?php $venue_description = espresso_venue_description($VNU_ID, FALSE); ?> |
|
39 | + <?php if ($venue_description) : ?> |
|
40 | 40 | <p> |
41 | - <strong><?php _e( 'Description:', 'event_espresso' ); ?></strong><br/> |
|
42 | - <?php echo do_shortcode( $venue_description ); ?> |
|
41 | + <strong><?php _e('Description:', 'event_espresso'); ?></strong><br/> |
|
42 | + <?php echo do_shortcode($venue_description); ?> |
|
43 | 43 | </p> |
44 | - <?php endif; ?> |
|
44 | + <?php endif; ?> |
|
45 | 45 | <?php else : ?> |
46 | - <?php $venue_excerpt = espresso_venue_excerpt( $VNU_ID, FALSE ); ?> |
|
47 | - <?php if ( $venue_excerpt ) : ?> |
|
46 | + <?php $venue_excerpt = espresso_venue_excerpt($VNU_ID, FALSE); ?> |
|
47 | + <?php if ($venue_excerpt) : ?> |
|
48 | 48 | <p> |
49 | - <strong><?php _e( 'Description:', 'event_espresso' ); ?></strong><br/> |
|
49 | + <strong><?php _e('Description:', 'event_espresso'); ?></strong><br/> |
|
50 | 50 | <?php echo $venue_excerpt; ?> |
51 | 51 | </p> |
52 | - <?php endif; ?> |
|
53 | - <?php endif; ?> |
|
52 | + <?php endif; ?> |
|
53 | + <?php endif; ?> |
|
54 | 54 | </div> |
55 | 55 | <!-- .espresso-venue-dv --> |
56 | 56 | <?php |
57 | -do_action( 'AHEE_event_details_after_venue_details', $post ); |
|
57 | +do_action('AHEE_event_details_after_venue_details', $post); |
|
58 | 58 | else : |
59 | - if ( espresso_venue_is_password_protected() ) : |
|
59 | + if (espresso_venue_is_password_protected()) : |
|
60 | 60 | ?> |
61 | 61 | <div class="espresso-venue-dv espresso-password-protected-venue-dv" > |
62 | 62 | <h3 class="event-venues-h3 ee-event-h3"> |
63 | - <?php _e( 'Location', 'event_espresso' );?> |
|
63 | + <?php _e('Location', 'event_espresso'); ?> |
|
64 | 64 | </h3> |
65 | 65 | <?php echo espresso_password_protected_venue_form(); ?> |
66 | 66 | </div> |
@@ -14,133 +14,133 @@ |
||
14 | 14 | trait EventsAdmin |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @param string $additional_params |
|
19 | - */ |
|
20 | - public function amOnDefaultEventsListTablePage($additional_params = '') |
|
21 | - { |
|
22 | - $this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params)); |
|
23 | - } |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * Triggers the publishing of the Event. |
|
28 | - */ |
|
29 | - public function publishEvent() |
|
30 | - { |
|
31 | - $this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR); |
|
32 | - $this->actor()->wait(3); |
|
33 | - $this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR); |
|
34 | - $this->actor()->waitForText('Event published.', 30); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * Triggers saving the Event. |
|
40 | - */ |
|
41 | - public function saveEvent() |
|
42 | - { |
|
43 | - $this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR); |
|
44 | - $this->actor()->wait(2); |
|
45 | - $this->actor()->click(EventsPage::EVENT_EDITOR_SAVE_BUTTON_SELECTOR); |
|
46 | - } |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * Navigates the actor to the event list table page and will attempt to edit the event for the given title. |
|
51 | - * First this will search using the given title and then attempt to edit from the results of the search. |
|
52 | - * |
|
53 | - * Assumes actor is already logged in. |
|
54 | - * @param $event_title |
|
55 | - */ |
|
56 | - public function amEditingTheEventWithTitle($event_title) |
|
57 | - { |
|
58 | - $this->amOnDefaultEventsListTablePage(); |
|
59 | - $this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title); |
|
60 | - $this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR); |
|
61 | - $this->actor()->waitForText($event_title, 15); |
|
62 | - $this->actor()->click(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title)); |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View" |
|
68 | - * link for the event in the event list table. |
|
69 | - * Assumes the actor is already logged in and on the Event list table page. |
|
70 | - * |
|
71 | - * @param string $event_title |
|
72 | - */ |
|
73 | - public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title) |
|
74 | - { |
|
75 | - $this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title)); |
|
76 | - $this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title)); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Used to retrieve the event id for the event via the list table and for the given event. |
|
82 | - * @param string $event_title |
|
83 | - */ |
|
84 | - public function observeEventIdInListTableForEvent($event_title) |
|
85 | - { |
|
86 | - return $this->actor()->observeValueFromInputAt(EventsPage::eventListTableEventIdSelectorForTitle($event_title)); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * This performs the click action on the gear icon that triggers the advanced settings view state. |
|
92 | - * Assumes the actor is already logged in and editing an event. |
|
93 | - * |
|
94 | - * @param int $row_number What ticket row to toggle open/close. |
|
95 | - */ |
|
96 | - public function toggleAdvancedSettingsViewForTicketRow($row_number = 1) |
|
97 | - { |
|
98 | - $this->actor()->click(EventsPage::eventEditorTicketAdvancedDetailsSelector($row_number)); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * Toggles the TKT_is_taxable checkbox for the ticket in the given row. |
|
104 | - * Assumes the actor is already logged in and editing an event and that the advanced settings view state for that |
|
105 | - * ticket is "open". |
|
106 | - * |
|
107 | - * @param int $row_number What ticket row to toggle the checkbox for. |
|
108 | - */ |
|
109 | - public function toggleTicketIsTaxableForTicketRow($row_number = 1) |
|
110 | - { |
|
111 | - $this->actor()->click(EventsPage::eventEditorTicketTaxableCheckboxSelector($row_number)); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * Use to change the default registration status for the event. |
|
117 | - * Assumes the view is already on the event editor. |
|
118 | - * @param $registration_status |
|
119 | - */ |
|
120 | - public function changeDefaultRegistrationStatusTo($registration_status) |
|
121 | - { |
|
122 | - $this->actor()->selectOption( |
|
123 | - EventsPage::EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR, |
|
124 | - $registration_status |
|
125 | - ); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * Use this from the context of the event editor to select the given custom template for a given message type and |
|
131 | - * messenger. |
|
132 | - * |
|
133 | - * @param string $message_type_label The visible label for the message type (eg Registration Approved) |
|
134 | - * @param string $messenger_slug The slug for the messenger (eg 'email') |
|
135 | - * @param string $custom_template_label The visible label in the select input for the custom template you want |
|
136 | - * selected. |
|
137 | - */ |
|
138 | - public function selectCustomTemplateFor($message_type_label, $messenger_slug, $custom_template_label) |
|
139 | - { |
|
140 | - $this->actor()->click(EventsPage::eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug)); |
|
141 | - $this->actor()->selectOption( |
|
142 | - EventsPage::eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label), |
|
143 | - $custom_template_label |
|
144 | - ); |
|
145 | - } |
|
17 | + /** |
|
18 | + * @param string $additional_params |
|
19 | + */ |
|
20 | + public function amOnDefaultEventsListTablePage($additional_params = '') |
|
21 | + { |
|
22 | + $this->actor()->amOnAdminPage(EventsPage::defaultEventsListTableUrl($additional_params)); |
|
23 | + } |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * Triggers the publishing of the Event. |
|
28 | + */ |
|
29 | + public function publishEvent() |
|
30 | + { |
|
31 | + $this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR); |
|
32 | + $this->actor()->wait(3); |
|
33 | + $this->actor()->click(EventsPage::EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR); |
|
34 | + $this->actor()->waitForText('Event published.', 30); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * Triggers saving the Event. |
|
40 | + */ |
|
41 | + public function saveEvent() |
|
42 | + { |
|
43 | + $this->actor()->scrollTo(EventsPage::EVENT_EDITOR_TITLE_FIELD_SELECTOR); |
|
44 | + $this->actor()->wait(2); |
|
45 | + $this->actor()->click(EventsPage::EVENT_EDITOR_SAVE_BUTTON_SELECTOR); |
|
46 | + } |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * Navigates the actor to the event list table page and will attempt to edit the event for the given title. |
|
51 | + * First this will search using the given title and then attempt to edit from the results of the search. |
|
52 | + * |
|
53 | + * Assumes actor is already logged in. |
|
54 | + * @param $event_title |
|
55 | + */ |
|
56 | + public function amEditingTheEventWithTitle($event_title) |
|
57 | + { |
|
58 | + $this->amOnDefaultEventsListTablePage(); |
|
59 | + $this->actor()->fillField(EventsPage::EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR, $event_title); |
|
60 | + $this->actor()->click(CoreAdmin::LIST_TABLE_SEARCH_SUBMIT_SELECTOR); |
|
61 | + $this->actor()->waitForText($event_title, 15); |
|
62 | + $this->actor()->click(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title)); |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * Navigates the user to the single event page (frontend view) for the given event title via clicking the "View" |
|
68 | + * link for the event in the event list table. |
|
69 | + * Assumes the actor is already logged in and on the Event list table page. |
|
70 | + * |
|
71 | + * @param string $event_title |
|
72 | + */ |
|
73 | + public function amOnEventPageAfterClickingViewLinkInListTableForEvent($event_title) |
|
74 | + { |
|
75 | + $this->actor()->moveMouseOver(EventsPage::eventListTableEventTitleEditLinkSelectorForTitle($event_title)); |
|
76 | + $this->actor()->click(EventsPage::eventListTableEventTitleViewLinkSelectorForTitle($event_title)); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Used to retrieve the event id for the event via the list table and for the given event. |
|
82 | + * @param string $event_title |
|
83 | + */ |
|
84 | + public function observeEventIdInListTableForEvent($event_title) |
|
85 | + { |
|
86 | + return $this->actor()->observeValueFromInputAt(EventsPage::eventListTableEventIdSelectorForTitle($event_title)); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * This performs the click action on the gear icon that triggers the advanced settings view state. |
|
92 | + * Assumes the actor is already logged in and editing an event. |
|
93 | + * |
|
94 | + * @param int $row_number What ticket row to toggle open/close. |
|
95 | + */ |
|
96 | + public function toggleAdvancedSettingsViewForTicketRow($row_number = 1) |
|
97 | + { |
|
98 | + $this->actor()->click(EventsPage::eventEditorTicketAdvancedDetailsSelector($row_number)); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * Toggles the TKT_is_taxable checkbox for the ticket in the given row. |
|
104 | + * Assumes the actor is already logged in and editing an event and that the advanced settings view state for that |
|
105 | + * ticket is "open". |
|
106 | + * |
|
107 | + * @param int $row_number What ticket row to toggle the checkbox for. |
|
108 | + */ |
|
109 | + public function toggleTicketIsTaxableForTicketRow($row_number = 1) |
|
110 | + { |
|
111 | + $this->actor()->click(EventsPage::eventEditorTicketTaxableCheckboxSelector($row_number)); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * Use to change the default registration status for the event. |
|
117 | + * Assumes the view is already on the event editor. |
|
118 | + * @param $registration_status |
|
119 | + */ |
|
120 | + public function changeDefaultRegistrationStatusTo($registration_status) |
|
121 | + { |
|
122 | + $this->actor()->selectOption( |
|
123 | + EventsPage::EVENT_EDITOR_DEFAULT_REGISTRATION_STATUS_FIELD_SELECTOR, |
|
124 | + $registration_status |
|
125 | + ); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * Use this from the context of the event editor to select the given custom template for a given message type and |
|
131 | + * messenger. |
|
132 | + * |
|
133 | + * @param string $message_type_label The visible label for the message type (eg Registration Approved) |
|
134 | + * @param string $messenger_slug The slug for the messenger (eg 'email') |
|
135 | + * @param string $custom_template_label The visible label in the select input for the custom template you want |
|
136 | + * selected. |
|
137 | + */ |
|
138 | + public function selectCustomTemplateFor($message_type_label, $messenger_slug, $custom_template_label) |
|
139 | + { |
|
140 | + $this->actor()->click(EventsPage::eventEditorNotificationsMetaBoxMessengerTabSelector($messenger_slug)); |
|
141 | + $this->actor()->selectOption( |
|
142 | + EventsPage::eventEditorNotificationsMetaBoxSelectSelectorForMessageType($message_type_label), |
|
143 | + $custom_template_label |
|
144 | + ); |
|
145 | + } |
|
146 | 146 | } |
147 | 147 | \ No newline at end of file |
@@ -10,293 +10,293 @@ |
||
10 | 10 | */ |
11 | 11 | trait MessagesAdmin |
12 | 12 | { |
13 | - /** |
|
14 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
15 | - * a string. |
|
16 | - */ |
|
17 | - public function amOnMessagesActivityListTablePage($additional_params = '') |
|
18 | - { |
|
19 | - $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
20 | - } |
|
21 | - |
|
22 | - /** |
|
23 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
24 | - * a string. |
|
25 | - */ |
|
26 | - public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
27 | - { |
|
28 | - $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
34 | - * a string. |
|
35 | - */ |
|
36 | - public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
37 | - { |
|
38 | - $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * Directs to message settings page |
|
44 | - */ |
|
45 | - public function amOnMessageSettingsPage() |
|
46 | - { |
|
47 | - $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
52 | - { |
|
53 | - $this->actor()->dragAndDrop( |
|
54 | - MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
55 | - MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * Assumes you are already on the list table page that has the ui for editing the template. |
|
62 | - * @param string $message_type_slug |
|
63 | - * @param string $context [optional] if you want to click directly to the given context in the editor |
|
64 | - */ |
|
65 | - public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
66 | - { |
|
67 | - $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
73 | - * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
74 | - * |
|
75 | - * @param int $expected_occurence_count |
|
76 | - * @param string $text_to_check_for |
|
77 | - * @param string $field |
|
78 | - * @param string $message_type_label |
|
79 | - * @param string $message_status |
|
80 | - * @param string $messenger |
|
81 | - * @param string $context |
|
82 | - */ |
|
83 | - public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
84 | - $expected_occurence_count, |
|
85 | - $text_to_check_for, |
|
86 | - $field, |
|
87 | - $message_type_label, |
|
88 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
89 | - $messenger = 'Email', |
|
90 | - $context = 'Event Admin' |
|
91 | - ) { |
|
92 | - $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
93 | - $field, |
|
94 | - $message_type_label, |
|
95 | - $message_status, |
|
96 | - $messenger, |
|
97 | - $context, |
|
98 | - $text_to_check_for, |
|
99 | - 0 |
|
100 | - )); |
|
101 | - $actual_count = count($elements); |
|
102 | - $this->actor()->assertEquals( |
|
103 | - $expected_occurence_count, |
|
104 | - $actual_count, |
|
105 | - sprintf( |
|
106 | - 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
107 | - $expected_occurence_count, |
|
108 | - $text_to_check_for, |
|
109 | - $field, |
|
110 | - $actual_count |
|
111 | - ) |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * This will create a custom message template for the given messenger and message type from the context of the |
|
118 | - * default (global) message template list table. |
|
119 | - * Also takes care of verifying the template was created. |
|
120 | - * @param string $message_type_label |
|
121 | - * @param string $messenger_label |
|
122 | - */ |
|
123 | - public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
124 | - { |
|
125 | - $this->amOnDefaultMessageTemplateListTablePage(); |
|
126 | - $this->actor()->click( |
|
127 | - MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
128 | - $message_type_label, |
|
129 | - $messenger_label |
|
130 | - ) |
|
131 | - ); |
|
132 | - $this->actor()->seeInField('#title', 'New Custom Template'); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * This switches the context of the current messages template to the given reference. |
|
138 | - * @param string $context_reference This should be the visible label for the option. |
|
139 | - */ |
|
140 | - public function switchContextTo($context_reference) |
|
141 | - { |
|
142 | - $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
143 | - $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
144 | - $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after |
|
150 | - * toggling. |
|
151 | - * |
|
152 | - * @param string $context_string What context is being switched (used for the expected state text) |
|
153 | - * @param bool $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive |
|
154 | - * (false) |
|
155 | - */ |
|
156 | - public function toggleContextState($context_string, $expected_state_is_active = true) |
|
157 | - { |
|
158 | - $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE); |
|
159 | - if ($expected_state_is_active) { |
|
160 | - $this->actor()->waitForText("The template for $context_string is currently active."); |
|
161 | - } else { |
|
162 | - $this->actor()->waitForText("The template for $context_string is currently inactive"); |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * Triggers saving the message template. |
|
169 | - * @param bool $and_close Use to indicate to click the Save and Close button. |
|
170 | - */ |
|
171 | - public function saveMessageTemplate($and_close = false) |
|
172 | - { |
|
173 | - $this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR); |
|
174 | - if ($and_close) { |
|
175 | - $this->actor()->click('Save and Close'); |
|
176 | - } else { |
|
177 | - $this->actor()->click('Save'); |
|
178 | - } |
|
179 | - $this->actor()->waitForText('successfully updated'); |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * This takes care of clicking the View Message icon for the given parameters. |
|
185 | - * Assumes you are already viewing the messages activity list table. |
|
186 | - * @param $message_type_label |
|
187 | - * @param $message_status |
|
188 | - * @param string $messenger |
|
189 | - * @param string $context |
|
190 | - * @param int $number_in_set |
|
191 | - */ |
|
192 | - public function viewMessageInMessagesListTableFor( |
|
193 | - $message_type_label, |
|
194 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
195 | - $messenger = 'Email', |
|
196 | - $context = 'Event Admin', |
|
197 | - $number_in_set = 1 |
|
198 | - ) { |
|
199 | - $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
200 | - $message_type_label, |
|
201 | - $message_status, |
|
202 | - $messenger, |
|
203 | - $context, |
|
204 | - $number_in_set |
|
205 | - )); |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
211 | - * Assumes you are already viewing the messages activity list table. |
|
212 | - * @param $message_type_label |
|
213 | - * @param $message_status |
|
214 | - * @param string $messenger |
|
215 | - * @param string $context |
|
216 | - * @param int $number_in_set |
|
217 | - */ |
|
218 | - public function deleteMessageInMessagesListTableFor( |
|
219 | - $message_type_label, |
|
220 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
221 | - $messenger = 'Email', |
|
222 | - $context = 'Event Admin', |
|
223 | - $number_in_set = 1 |
|
224 | - ) { |
|
225 | - $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
226 | - $message_type_label, |
|
227 | - $message_status, |
|
228 | - $messenger, |
|
229 | - $context, |
|
230 | - $number_in_set |
|
231 | - ); |
|
232 | - $cell_selector = MessagesPage::messagesActivityListTableCellSelectorFor( |
|
233 | - 'to', |
|
234 | - $message_type_label, |
|
235 | - $message_status, |
|
236 | - $messenger, |
|
237 | - $context, |
|
238 | - '', |
|
239 | - $number_in_set |
|
240 | - ); |
|
241 | - $this->actor()->scrollTo($cell_selector, 0, -30); |
|
242 | - $this->actor()->moveMouseOver( |
|
243 | - $cell_selector, |
|
244 | - 5, |
|
245 | - 5 |
|
246 | - ); |
|
247 | - $this->actor()->waitForElementVisible( |
|
248 | - $delete_action_selector |
|
249 | - ); |
|
250 | - $this->actor()->click( |
|
251 | - $delete_action_selector |
|
252 | - ); |
|
253 | - $this->actor()->waitForText('successfully deleted', 20); |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
259 | - * list table, this will take care of validating the given text is in that window. |
|
260 | - * @param string $text_to_view |
|
261 | - */ |
|
262 | - public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
263 | - { |
|
264 | - $this->actor()->wait(2); |
|
265 | - $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
266 | - $this->actor()->switchToIframe('message-view-window'); |
|
267 | - $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
268 | - $this->actor()->switchToIframe(); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * This returns the value for the link at the given selector in the message modal. |
|
274 | - * @param string $selector (any selector string accepted by WebDriver) |
|
275 | - */ |
|
276 | - public function observeLinkAtSelectorInMessageModal($selector) |
|
277 | - { |
|
278 | - $this->actor()->wait(2); |
|
279 | - $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
280 | - $this->actor()->switchToIframe('message-view-window'); |
|
281 | - $link = $this->actor()->observeLinkUrlAt($selector); |
|
282 | - $this->actor()->switchToIframe(); |
|
283 | - return $link; |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
289 | - * list table, this will take care of validating the given text is NOT that window. |
|
290 | - * @param string $text_to_view |
|
291 | - */ |
|
292 | - public function dontSeeTextInViewMessageModal($text_to_view) |
|
293 | - { |
|
294 | - $this->seeTextInViewMessageModal($text_to_view, true); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - public function dismissMessageModal() |
|
299 | - { |
|
300 | - $this->actor()->executeJs('window.dialogHelper.closeModal()'); |
|
301 | - } |
|
13 | + /** |
|
14 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
15 | + * a string. |
|
16 | + */ |
|
17 | + public function amOnMessagesActivityListTablePage($additional_params = '') |
|
18 | + { |
|
19 | + $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
20 | + } |
|
21 | + |
|
22 | + /** |
|
23 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
24 | + * a string. |
|
25 | + */ |
|
26 | + public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
27 | + { |
|
28 | + $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
34 | + * a string. |
|
35 | + */ |
|
36 | + public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
37 | + { |
|
38 | + $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * Directs to message settings page |
|
44 | + */ |
|
45 | + public function amOnMessageSettingsPage() |
|
46 | + { |
|
47 | + $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
52 | + { |
|
53 | + $this->actor()->dragAndDrop( |
|
54 | + MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
55 | + MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * Assumes you are already on the list table page that has the ui for editing the template. |
|
62 | + * @param string $message_type_slug |
|
63 | + * @param string $context [optional] if you want to click directly to the given context in the editor |
|
64 | + */ |
|
65 | + public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
66 | + { |
|
67 | + $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
73 | + * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
74 | + * |
|
75 | + * @param int $expected_occurence_count |
|
76 | + * @param string $text_to_check_for |
|
77 | + * @param string $field |
|
78 | + * @param string $message_type_label |
|
79 | + * @param string $message_status |
|
80 | + * @param string $messenger |
|
81 | + * @param string $context |
|
82 | + */ |
|
83 | + public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
84 | + $expected_occurence_count, |
|
85 | + $text_to_check_for, |
|
86 | + $field, |
|
87 | + $message_type_label, |
|
88 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
89 | + $messenger = 'Email', |
|
90 | + $context = 'Event Admin' |
|
91 | + ) { |
|
92 | + $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
93 | + $field, |
|
94 | + $message_type_label, |
|
95 | + $message_status, |
|
96 | + $messenger, |
|
97 | + $context, |
|
98 | + $text_to_check_for, |
|
99 | + 0 |
|
100 | + )); |
|
101 | + $actual_count = count($elements); |
|
102 | + $this->actor()->assertEquals( |
|
103 | + $expected_occurence_count, |
|
104 | + $actual_count, |
|
105 | + sprintf( |
|
106 | + 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
107 | + $expected_occurence_count, |
|
108 | + $text_to_check_for, |
|
109 | + $field, |
|
110 | + $actual_count |
|
111 | + ) |
|
112 | + ); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * This will create a custom message template for the given messenger and message type from the context of the |
|
118 | + * default (global) message template list table. |
|
119 | + * Also takes care of verifying the template was created. |
|
120 | + * @param string $message_type_label |
|
121 | + * @param string $messenger_label |
|
122 | + */ |
|
123 | + public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
124 | + { |
|
125 | + $this->amOnDefaultMessageTemplateListTablePage(); |
|
126 | + $this->actor()->click( |
|
127 | + MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
128 | + $message_type_label, |
|
129 | + $messenger_label |
|
130 | + ) |
|
131 | + ); |
|
132 | + $this->actor()->seeInField('#title', 'New Custom Template'); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * This switches the context of the current messages template to the given reference. |
|
138 | + * @param string $context_reference This should be the visible label for the option. |
|
139 | + */ |
|
140 | + public function switchContextTo($context_reference) |
|
141 | + { |
|
142 | + $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
143 | + $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
144 | + $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * Toggles Context so its turned off or on (depending on where it started) and verifies the expected state after |
|
150 | + * toggling. |
|
151 | + * |
|
152 | + * @param string $context_string What context is being switched (used for the expected state text) |
|
153 | + * @param bool $expected_state_is_active Used to indicate whether the expected state is active (true) or inactive |
|
154 | + * (false) |
|
155 | + */ |
|
156 | + public function toggleContextState($context_string, $expected_state_is_active = true) |
|
157 | + { |
|
158 | + $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_ACTIVE_STATE_TOGGLE); |
|
159 | + if ($expected_state_is_active) { |
|
160 | + $this->actor()->waitForText("The template for $context_string is currently active."); |
|
161 | + } else { |
|
162 | + $this->actor()->waitForText("The template for $context_string is currently inactive"); |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * Triggers saving the message template. |
|
169 | + * @param bool $and_close Use to indicate to click the Save and Close button. |
|
170 | + */ |
|
171 | + public function saveMessageTemplate($and_close = false) |
|
172 | + { |
|
173 | + $this->actor()->scrollTo(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR); |
|
174 | + if ($and_close) { |
|
175 | + $this->actor()->click('Save and Close'); |
|
176 | + } else { |
|
177 | + $this->actor()->click('Save'); |
|
178 | + } |
|
179 | + $this->actor()->waitForText('successfully updated'); |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * This takes care of clicking the View Message icon for the given parameters. |
|
185 | + * Assumes you are already viewing the messages activity list table. |
|
186 | + * @param $message_type_label |
|
187 | + * @param $message_status |
|
188 | + * @param string $messenger |
|
189 | + * @param string $context |
|
190 | + * @param int $number_in_set |
|
191 | + */ |
|
192 | + public function viewMessageInMessagesListTableFor( |
|
193 | + $message_type_label, |
|
194 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
195 | + $messenger = 'Email', |
|
196 | + $context = 'Event Admin', |
|
197 | + $number_in_set = 1 |
|
198 | + ) { |
|
199 | + $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
200 | + $message_type_label, |
|
201 | + $message_status, |
|
202 | + $messenger, |
|
203 | + $context, |
|
204 | + $number_in_set |
|
205 | + )); |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
211 | + * Assumes you are already viewing the messages activity list table. |
|
212 | + * @param $message_type_label |
|
213 | + * @param $message_status |
|
214 | + * @param string $messenger |
|
215 | + * @param string $context |
|
216 | + * @param int $number_in_set |
|
217 | + */ |
|
218 | + public function deleteMessageInMessagesListTableFor( |
|
219 | + $message_type_label, |
|
220 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
221 | + $messenger = 'Email', |
|
222 | + $context = 'Event Admin', |
|
223 | + $number_in_set = 1 |
|
224 | + ) { |
|
225 | + $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
226 | + $message_type_label, |
|
227 | + $message_status, |
|
228 | + $messenger, |
|
229 | + $context, |
|
230 | + $number_in_set |
|
231 | + ); |
|
232 | + $cell_selector = MessagesPage::messagesActivityListTableCellSelectorFor( |
|
233 | + 'to', |
|
234 | + $message_type_label, |
|
235 | + $message_status, |
|
236 | + $messenger, |
|
237 | + $context, |
|
238 | + '', |
|
239 | + $number_in_set |
|
240 | + ); |
|
241 | + $this->actor()->scrollTo($cell_selector, 0, -30); |
|
242 | + $this->actor()->moveMouseOver( |
|
243 | + $cell_selector, |
|
244 | + 5, |
|
245 | + 5 |
|
246 | + ); |
|
247 | + $this->actor()->waitForElementVisible( |
|
248 | + $delete_action_selector |
|
249 | + ); |
|
250 | + $this->actor()->click( |
|
251 | + $delete_action_selector |
|
252 | + ); |
|
253 | + $this->actor()->waitForText('successfully deleted', 20); |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
259 | + * list table, this will take care of validating the given text is in that window. |
|
260 | + * @param string $text_to_view |
|
261 | + */ |
|
262 | + public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
263 | + { |
|
264 | + $this->actor()->wait(2); |
|
265 | + $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
266 | + $this->actor()->switchToIframe('message-view-window'); |
|
267 | + $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
268 | + $this->actor()->switchToIframe(); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * This returns the value for the link at the given selector in the message modal. |
|
274 | + * @param string $selector (any selector string accepted by WebDriver) |
|
275 | + */ |
|
276 | + public function observeLinkAtSelectorInMessageModal($selector) |
|
277 | + { |
|
278 | + $this->actor()->wait(2); |
|
279 | + $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
280 | + $this->actor()->switchToIframe('message-view-window'); |
|
281 | + $link = $this->actor()->observeLinkUrlAt($selector); |
|
282 | + $this->actor()->switchToIframe(); |
|
283 | + return $link; |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
289 | + * list table, this will take care of validating the given text is NOT that window. |
|
290 | + * @param string $text_to_view |
|
291 | + */ |
|
292 | + public function dontSeeTextInViewMessageModal($text_to_view) |
|
293 | + { |
|
294 | + $this->seeTextInViewMessageModal($text_to_view, true); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + public function dismissMessageModal() |
|
299 | + { |
|
300 | + $this->actor()->executeJs('window.dialogHelper.closeModal()'); |
|
301 | + } |
|
302 | 302 | } |
@@ -25,1144 +25,1144 @@ |
||
25 | 25 | { |
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * possibly truncated version of the EE core version string |
|
30 | - * |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected static $_core_version = ''; |
|
28 | + /** |
|
29 | + * possibly truncated version of the EE core version string |
|
30 | + * |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected static $_core_version = ''; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Holds values for registered addons |
|
37 | - * |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - protected static $_settings = array(); |
|
35 | + /** |
|
36 | + * Holds values for registered addons |
|
37 | + * |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + protected static $_settings = array(); |
|
41 | 41 | |
42 | - /** |
|
43 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
44 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
45 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
46 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
47 | - * EE core with knowledge of ALL the addons out there. |
|
48 | - * If you want NO versions of an addon to run with a certain version of core, |
|
49 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
50 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
51 | - * minimum plugin version. |
|
52 | - * @access protected |
|
53 | - */ |
|
54 | - protected static $_incompatible_addons = array( |
|
55 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
56 | - 'Promotions' => '1.0.0.rc.084', |
|
57 | - ); |
|
42 | + /** |
|
43 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
44 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
45 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
46 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
47 | + * EE core with knowledge of ALL the addons out there. |
|
48 | + * If you want NO versions of an addon to run with a certain version of core, |
|
49 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
50 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
51 | + * minimum plugin version. |
|
52 | + * @access protected |
|
53 | + */ |
|
54 | + protected static $_incompatible_addons = array( |
|
55 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
56 | + 'Promotions' => '1.0.0.rc.084', |
|
57 | + ); |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
62 | - * not just '4.3.0'. |
|
63 | - * So if the addon developer doesn't provide that full version string, |
|
64 | - * fill in the blanks for them |
|
65 | - * |
|
66 | - * @param string $min_core_version |
|
67 | - * @return string always like '4.3.0.rc.000' |
|
68 | - */ |
|
69 | - protected static function _effective_version($min_core_version) |
|
70 | - { |
|
71 | - // versions: 4 . 3 . 1 . p . 123 |
|
72 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
73 | - $version_parts = explode('.', $min_core_version); |
|
74 | - //check they specified the micro version (after 2nd period) |
|
75 | - if (! isset($version_parts[2])) { |
|
76 | - $version_parts[2] = '0'; |
|
77 | - } |
|
78 | - //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
79 | - //soon we can assume that's 'rc', but this current version is 'alpha' |
|
80 | - if (! isset($version_parts[3])) { |
|
81 | - $version_parts[3] = 'dev'; |
|
82 | - } |
|
83 | - if (! isset($version_parts[4])) { |
|
84 | - $version_parts[4] = '000'; |
|
85 | - } |
|
86 | - return implode('.', $version_parts); |
|
87 | - } |
|
60 | + /** |
|
61 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
62 | + * not just '4.3.0'. |
|
63 | + * So if the addon developer doesn't provide that full version string, |
|
64 | + * fill in the blanks for them |
|
65 | + * |
|
66 | + * @param string $min_core_version |
|
67 | + * @return string always like '4.3.0.rc.000' |
|
68 | + */ |
|
69 | + protected static function _effective_version($min_core_version) |
|
70 | + { |
|
71 | + // versions: 4 . 3 . 1 . p . 123 |
|
72 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
73 | + $version_parts = explode('.', $min_core_version); |
|
74 | + //check they specified the micro version (after 2nd period) |
|
75 | + if (! isset($version_parts[2])) { |
|
76 | + $version_parts[2] = '0'; |
|
77 | + } |
|
78 | + //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
79 | + //soon we can assume that's 'rc', but this current version is 'alpha' |
|
80 | + if (! isset($version_parts[3])) { |
|
81 | + $version_parts[3] = 'dev'; |
|
82 | + } |
|
83 | + if (! isset($version_parts[4])) { |
|
84 | + $version_parts[4] = '000'; |
|
85 | + } |
|
86 | + return implode('.', $version_parts); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * Returns whether or not the min core version requirement of the addon is met |
|
92 | - * |
|
93 | - * @param string $min_core_version the minimum core version required by the addon |
|
94 | - * @param string $actual_core_version the actual core version, optional |
|
95 | - * @return boolean |
|
96 | - */ |
|
97 | - public static function _meets_min_core_version_requirement( |
|
98 | - $min_core_version, |
|
99 | - $actual_core_version = EVENT_ESPRESSO_VERSION |
|
100 | - ) { |
|
101 | - return version_compare( |
|
102 | - self::_effective_version($actual_core_version), |
|
103 | - self::_effective_version($min_core_version), |
|
104 | - '>=' |
|
105 | - ); |
|
106 | - } |
|
90 | + /** |
|
91 | + * Returns whether or not the min core version requirement of the addon is met |
|
92 | + * |
|
93 | + * @param string $min_core_version the minimum core version required by the addon |
|
94 | + * @param string $actual_core_version the actual core version, optional |
|
95 | + * @return boolean |
|
96 | + */ |
|
97 | + public static function _meets_min_core_version_requirement( |
|
98 | + $min_core_version, |
|
99 | + $actual_core_version = EVENT_ESPRESSO_VERSION |
|
100 | + ) { |
|
101 | + return version_compare( |
|
102 | + self::_effective_version($actual_core_version), |
|
103 | + self::_effective_version($min_core_version), |
|
104 | + '>=' |
|
105 | + ); |
|
106 | + } |
|
107 | 107 | |
108 | 108 | |
109 | - /** |
|
110 | - * Method for registering new EE_Addons. |
|
111 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
112 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
113 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
114 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
115 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
116 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
117 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
118 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
119 | - * |
|
120 | - * @since 4.3.0 |
|
121 | - * @param string $addon_name the EE_Addon's name. Required. |
|
122 | - * @param array $setup_args { |
|
123 | - * An array of arguments provided for registering the |
|
124 | - * message type. |
|
125 | - * @type string $class_name the addon's main file name. |
|
126 | - * If left blank, generated from the addon name, |
|
127 | - * changes something like "calendar" to "EE_Calendar" |
|
128 | - * @type string $min_core_version the minimum version of EE Core that the |
|
129 | - * addon will work with. eg "4.8.1.rc.084" |
|
130 | - * @type string $version the "software" version for the addon. eg |
|
131 | - * "1.0.0.p" for a first stable release, or |
|
132 | - * "1.0.0.rc.043" for a version in progress |
|
133 | - * @type string $main_file_path the full server path to the main file |
|
134 | - * loaded directly by WP |
|
135 | - * @type string $domain_fqcn Fully Qualified Class Name |
|
136 | - * for the addon's Domain class |
|
137 | - * (see EventEspresso\core\domain\Domain) |
|
138 | - * @type string $admin_path full server path to the folder where the |
|
139 | - * addon\'s admin files reside |
|
140 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
141 | - * first invoked, can be used for hooking into |
|
142 | - * any admin page |
|
143 | - * @type string $config_section the section name for this addon's |
|
144 | - * configuration settings section |
|
145 | - * (defaults to "addons") |
|
146 | - * @type string $config_class the class name for this addon's |
|
147 | - * configuration settings object |
|
148 | - * @type string $config_name the class name for this addon's |
|
149 | - * configuration settings object |
|
150 | - * @type string $autoloader_paths an array of class names and the full server |
|
151 | - * paths to those files. Required. |
|
152 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
153 | - * folders containing classes that might be |
|
154 | - * invoked by the addon |
|
155 | - * @type string $dms_paths an array of full server paths to folders that |
|
156 | - * contain data migration scripts. Required. |
|
157 | - * @type string $module_paths an array of full server paths to any |
|
158 | - * EED_Modules used by the addon |
|
159 | - * @type string $shortcode_paths an array of full server paths to folders |
|
160 | - * that contain EES_Shortcodes |
|
161 | - * @type string $widget_paths an array of full server paths to folders |
|
162 | - * that contain WP_Widgets |
|
163 | - * @type string $pue_options |
|
164 | - * @type array $capabilities an array indexed by role name |
|
165 | - * (i.e administrator,author ) and the values |
|
166 | - * are an array of caps to add to the role. |
|
167 | - * 'administrator' => array( |
|
168 | - * 'read_addon', |
|
169 | - * 'edit_addon', |
|
170 | - * etc. |
|
171 | - * ). |
|
172 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
173 | - * for any addons that need to register any |
|
174 | - * special meta mapped capabilities. Should |
|
175 | - * be indexed where the key is the |
|
176 | - * EE_Meta_Capability_Map class name and the |
|
177 | - * values are the arguments sent to the class. |
|
178 | - * @type array $model_paths array of folders containing DB models |
|
179 | - * @see EE_Register_Model |
|
180 | - * @type array $class_paths array of folders containing DB classes |
|
181 | - * @see EE_Register_Model |
|
182 | - * @type array $model_extension_paths array of folders containing DB model |
|
183 | - * extensions |
|
184 | - * @see EE_Register_Model_Extension |
|
185 | - * @type array $class_extension_paths array of folders containing DB class |
|
186 | - * extensions |
|
187 | - * @see EE_Register_Model_Extension |
|
188 | - * @type array message_types { |
|
189 | - * An array of message types with the key as |
|
190 | - * the message type name and the values as |
|
191 | - * below: |
|
192 | - * @type string $mtfilename The filename of the message type being |
|
193 | - * registered. This will be the main |
|
194 | - * EE_{Message Type Name}_message_type class. |
|
195 | - * (eg. EE_Declined_Registration_message_type.class.php) |
|
196 | - * Required. |
|
197 | - * @type array $autoloadpaths An array of paths to add to the messages |
|
198 | - * autoloader for the new message type. |
|
199 | - * Required. |
|
200 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
201 | - * type should activate with. Each value in |
|
202 | - * the |
|
203 | - * array |
|
204 | - * should match the name property of a |
|
205 | - * EE_messenger. Optional. |
|
206 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
207 | - * type should validate with. Each value in |
|
208 | - * the |
|
209 | - * array |
|
210 | - * should match the name property of an |
|
211 | - * EE_messenger. |
|
212 | - * Optional. |
|
213 | - * } |
|
214 | - * @type array $custom_post_types |
|
215 | - * @type array $custom_taxonomies |
|
216 | - * @type array $payment_method_paths each element is the folder containing the |
|
217 | - * EE_PMT_Base child class |
|
218 | - * (eg, |
|
219 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
220 | - * which contains the files |
|
221 | - * EE_PMT_Payomatic.pm.php) |
|
222 | - * @type array $default_terms |
|
223 | - * @type array $namespace { |
|
224 | - * An array with two items for registering the |
|
225 | - * addon's namespace. (If, for some reason, you |
|
226 | - * require additional namespaces, |
|
227 | - * use EventEspresso\core\Psr4Autoloader::addNamespace() |
|
228 | - * directly) |
|
229 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
230 | - * @type string $FQNS the namespace prefix |
|
231 | - * @type string $DIR a base directory for class files in the |
|
232 | - * namespace. |
|
233 | - * } |
|
234 | - * } |
|
235 | - * @return void |
|
236 | - * @throws DomainException |
|
237 | - * @throws EE_Error |
|
238 | - * @throws InvalidArgumentException |
|
239 | - * @throws ReflectionException |
|
240 | - * @throws InvalidDataTypeException |
|
241 | - * @throws InvalidInterfaceException |
|
242 | - */ |
|
243 | - public static function register($addon_name = '', $setup_args = array()) |
|
244 | - { |
|
245 | - // required fields MUST be present, so let's make sure they are. |
|
246 | - EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
247 | - // get class name for addon |
|
248 | - $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
249 | - //setup $_settings array from incoming values. |
|
250 | - $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
251 | - // setup PUE |
|
252 | - EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
253 | - // does this addon work with this version of core or WordPress ? |
|
254 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
255 | - return; |
|
256 | - } |
|
257 | - // register namespaces |
|
258 | - EE_Register_Addon::_setup_namespaces($addon_settings); |
|
259 | - // check if this is an activation request |
|
260 | - if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
261 | - // dont bother setting up the rest of the addon atm |
|
262 | - return; |
|
263 | - } |
|
264 | - // we need cars |
|
265 | - EE_Register_Addon::_setup_autoloaders($addon_name); |
|
266 | - // register new models and extensions |
|
267 | - EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
268 | - // setup DMS |
|
269 | - EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
270 | - // if config_class is present let's register config. |
|
271 | - EE_Register_Addon::_register_config($addon_name); |
|
272 | - // register admin pages |
|
273 | - EE_Register_Addon::_register_admin_pages($addon_name); |
|
274 | - // add to list of modules to be registered |
|
275 | - EE_Register_Addon::_register_modules($addon_name); |
|
276 | - // add to list of shortcodes to be registered |
|
277 | - EE_Register_Addon::_register_shortcodes($addon_name); |
|
278 | - // add to list of widgets to be registered |
|
279 | - EE_Register_Addon::_register_widgets($addon_name); |
|
280 | - // register capability related stuff. |
|
281 | - EE_Register_Addon::_register_capabilities($addon_name); |
|
282 | - // any message type to register? |
|
283 | - EE_Register_Addon::_register_message_types($addon_name); |
|
284 | - // any custom post type/ custom capabilities or default terms to register |
|
285 | - EE_Register_Addon::_register_custom_post_types($addon_name); |
|
286 | - // and any payment methods |
|
287 | - EE_Register_Addon::_register_payment_methods($addon_name); |
|
288 | - // load and instantiate main addon class |
|
289 | - $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
290 | - //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
291 | - add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
292 | - } |
|
109 | + /** |
|
110 | + * Method for registering new EE_Addons. |
|
111 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
112 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
113 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
114 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
115 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
116 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
117 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
118 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
119 | + * |
|
120 | + * @since 4.3.0 |
|
121 | + * @param string $addon_name the EE_Addon's name. Required. |
|
122 | + * @param array $setup_args { |
|
123 | + * An array of arguments provided for registering the |
|
124 | + * message type. |
|
125 | + * @type string $class_name the addon's main file name. |
|
126 | + * If left blank, generated from the addon name, |
|
127 | + * changes something like "calendar" to "EE_Calendar" |
|
128 | + * @type string $min_core_version the minimum version of EE Core that the |
|
129 | + * addon will work with. eg "4.8.1.rc.084" |
|
130 | + * @type string $version the "software" version for the addon. eg |
|
131 | + * "1.0.0.p" for a first stable release, or |
|
132 | + * "1.0.0.rc.043" for a version in progress |
|
133 | + * @type string $main_file_path the full server path to the main file |
|
134 | + * loaded directly by WP |
|
135 | + * @type string $domain_fqcn Fully Qualified Class Name |
|
136 | + * for the addon's Domain class |
|
137 | + * (see EventEspresso\core\domain\Domain) |
|
138 | + * @type string $admin_path full server path to the folder where the |
|
139 | + * addon\'s admin files reside |
|
140 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
141 | + * first invoked, can be used for hooking into |
|
142 | + * any admin page |
|
143 | + * @type string $config_section the section name for this addon's |
|
144 | + * configuration settings section |
|
145 | + * (defaults to "addons") |
|
146 | + * @type string $config_class the class name for this addon's |
|
147 | + * configuration settings object |
|
148 | + * @type string $config_name the class name for this addon's |
|
149 | + * configuration settings object |
|
150 | + * @type string $autoloader_paths an array of class names and the full server |
|
151 | + * paths to those files. Required. |
|
152 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
153 | + * folders containing classes that might be |
|
154 | + * invoked by the addon |
|
155 | + * @type string $dms_paths an array of full server paths to folders that |
|
156 | + * contain data migration scripts. Required. |
|
157 | + * @type string $module_paths an array of full server paths to any |
|
158 | + * EED_Modules used by the addon |
|
159 | + * @type string $shortcode_paths an array of full server paths to folders |
|
160 | + * that contain EES_Shortcodes |
|
161 | + * @type string $widget_paths an array of full server paths to folders |
|
162 | + * that contain WP_Widgets |
|
163 | + * @type string $pue_options |
|
164 | + * @type array $capabilities an array indexed by role name |
|
165 | + * (i.e administrator,author ) and the values |
|
166 | + * are an array of caps to add to the role. |
|
167 | + * 'administrator' => array( |
|
168 | + * 'read_addon', |
|
169 | + * 'edit_addon', |
|
170 | + * etc. |
|
171 | + * ). |
|
172 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
173 | + * for any addons that need to register any |
|
174 | + * special meta mapped capabilities. Should |
|
175 | + * be indexed where the key is the |
|
176 | + * EE_Meta_Capability_Map class name and the |
|
177 | + * values are the arguments sent to the class. |
|
178 | + * @type array $model_paths array of folders containing DB models |
|
179 | + * @see EE_Register_Model |
|
180 | + * @type array $class_paths array of folders containing DB classes |
|
181 | + * @see EE_Register_Model |
|
182 | + * @type array $model_extension_paths array of folders containing DB model |
|
183 | + * extensions |
|
184 | + * @see EE_Register_Model_Extension |
|
185 | + * @type array $class_extension_paths array of folders containing DB class |
|
186 | + * extensions |
|
187 | + * @see EE_Register_Model_Extension |
|
188 | + * @type array message_types { |
|
189 | + * An array of message types with the key as |
|
190 | + * the message type name and the values as |
|
191 | + * below: |
|
192 | + * @type string $mtfilename The filename of the message type being |
|
193 | + * registered. This will be the main |
|
194 | + * EE_{Message Type Name}_message_type class. |
|
195 | + * (eg. EE_Declined_Registration_message_type.class.php) |
|
196 | + * Required. |
|
197 | + * @type array $autoloadpaths An array of paths to add to the messages |
|
198 | + * autoloader for the new message type. |
|
199 | + * Required. |
|
200 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
201 | + * type should activate with. Each value in |
|
202 | + * the |
|
203 | + * array |
|
204 | + * should match the name property of a |
|
205 | + * EE_messenger. Optional. |
|
206 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
207 | + * type should validate with. Each value in |
|
208 | + * the |
|
209 | + * array |
|
210 | + * should match the name property of an |
|
211 | + * EE_messenger. |
|
212 | + * Optional. |
|
213 | + * } |
|
214 | + * @type array $custom_post_types |
|
215 | + * @type array $custom_taxonomies |
|
216 | + * @type array $payment_method_paths each element is the folder containing the |
|
217 | + * EE_PMT_Base child class |
|
218 | + * (eg, |
|
219 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
220 | + * which contains the files |
|
221 | + * EE_PMT_Payomatic.pm.php) |
|
222 | + * @type array $default_terms |
|
223 | + * @type array $namespace { |
|
224 | + * An array with two items for registering the |
|
225 | + * addon's namespace. (If, for some reason, you |
|
226 | + * require additional namespaces, |
|
227 | + * use EventEspresso\core\Psr4Autoloader::addNamespace() |
|
228 | + * directly) |
|
229 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
230 | + * @type string $FQNS the namespace prefix |
|
231 | + * @type string $DIR a base directory for class files in the |
|
232 | + * namespace. |
|
233 | + * } |
|
234 | + * } |
|
235 | + * @return void |
|
236 | + * @throws DomainException |
|
237 | + * @throws EE_Error |
|
238 | + * @throws InvalidArgumentException |
|
239 | + * @throws ReflectionException |
|
240 | + * @throws InvalidDataTypeException |
|
241 | + * @throws InvalidInterfaceException |
|
242 | + */ |
|
243 | + public static function register($addon_name = '', $setup_args = array()) |
|
244 | + { |
|
245 | + // required fields MUST be present, so let's make sure they are. |
|
246 | + EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
247 | + // get class name for addon |
|
248 | + $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
249 | + //setup $_settings array from incoming values. |
|
250 | + $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
251 | + // setup PUE |
|
252 | + EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
253 | + // does this addon work with this version of core or WordPress ? |
|
254 | + if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
255 | + return; |
|
256 | + } |
|
257 | + // register namespaces |
|
258 | + EE_Register_Addon::_setup_namespaces($addon_settings); |
|
259 | + // check if this is an activation request |
|
260 | + if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
261 | + // dont bother setting up the rest of the addon atm |
|
262 | + return; |
|
263 | + } |
|
264 | + // we need cars |
|
265 | + EE_Register_Addon::_setup_autoloaders($addon_name); |
|
266 | + // register new models and extensions |
|
267 | + EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
268 | + // setup DMS |
|
269 | + EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
270 | + // if config_class is present let's register config. |
|
271 | + EE_Register_Addon::_register_config($addon_name); |
|
272 | + // register admin pages |
|
273 | + EE_Register_Addon::_register_admin_pages($addon_name); |
|
274 | + // add to list of modules to be registered |
|
275 | + EE_Register_Addon::_register_modules($addon_name); |
|
276 | + // add to list of shortcodes to be registered |
|
277 | + EE_Register_Addon::_register_shortcodes($addon_name); |
|
278 | + // add to list of widgets to be registered |
|
279 | + EE_Register_Addon::_register_widgets($addon_name); |
|
280 | + // register capability related stuff. |
|
281 | + EE_Register_Addon::_register_capabilities($addon_name); |
|
282 | + // any message type to register? |
|
283 | + EE_Register_Addon::_register_message_types($addon_name); |
|
284 | + // any custom post type/ custom capabilities or default terms to register |
|
285 | + EE_Register_Addon::_register_custom_post_types($addon_name); |
|
286 | + // and any payment methods |
|
287 | + EE_Register_Addon::_register_payment_methods($addon_name); |
|
288 | + // load and instantiate main addon class |
|
289 | + $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
290 | + //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
291 | + add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
292 | + } |
|
293 | 293 | |
294 | 294 | |
295 | - /** |
|
296 | - * @param string $addon_name |
|
297 | - * @param array $setup_args |
|
298 | - * @return void |
|
299 | - * @throws EE_Error |
|
300 | - */ |
|
301 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
302 | - { |
|
303 | - // required fields MUST be present, so let's make sure they are. |
|
304 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
305 | - throw new EE_Error( |
|
306 | - __( |
|
307 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
308 | - 'event_espresso' |
|
309 | - ) |
|
310 | - ); |
|
311 | - } |
|
312 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
313 | - throw new EE_Error( |
|
314 | - sprintf( |
|
315 | - __( |
|
316 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
317 | - 'event_espresso' |
|
318 | - ), |
|
319 | - implode(',', array_keys($setup_args)) |
|
320 | - ) |
|
321 | - ); |
|
322 | - } |
|
323 | - // check that addon has not already been registered with that name |
|
324 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
325 | - throw new EE_Error( |
|
326 | - sprintf( |
|
327 | - __( |
|
328 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
329 | - 'event_espresso' |
|
330 | - ), |
|
331 | - $addon_name |
|
332 | - ) |
|
333 | - ); |
|
334 | - } |
|
335 | - } |
|
295 | + /** |
|
296 | + * @param string $addon_name |
|
297 | + * @param array $setup_args |
|
298 | + * @return void |
|
299 | + * @throws EE_Error |
|
300 | + */ |
|
301 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
302 | + { |
|
303 | + // required fields MUST be present, so let's make sure they are. |
|
304 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
305 | + throw new EE_Error( |
|
306 | + __( |
|
307 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
308 | + 'event_espresso' |
|
309 | + ) |
|
310 | + ); |
|
311 | + } |
|
312 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
313 | + throw new EE_Error( |
|
314 | + sprintf( |
|
315 | + __( |
|
316 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
317 | + 'event_espresso' |
|
318 | + ), |
|
319 | + implode(',', array_keys($setup_args)) |
|
320 | + ) |
|
321 | + ); |
|
322 | + } |
|
323 | + // check that addon has not already been registered with that name |
|
324 | + if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
325 | + throw new EE_Error( |
|
326 | + sprintf( |
|
327 | + __( |
|
328 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
329 | + 'event_espresso' |
|
330 | + ), |
|
331 | + $addon_name |
|
332 | + ) |
|
333 | + ); |
|
334 | + } |
|
335 | + } |
|
336 | 336 | |
337 | 337 | |
338 | - /** |
|
339 | - * @param string $addon_name |
|
340 | - * @param array $setup_args |
|
341 | - * @return string |
|
342 | - */ |
|
343 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
344 | - { |
|
345 | - if (empty($setup_args['class_name'])) { |
|
346 | - // generate one by first separating name with spaces |
|
347 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
348 | - //capitalize, then replace spaces with underscores |
|
349 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
350 | - } else { |
|
351 | - $class_name = $setup_args['class_name']; |
|
352 | - } |
|
353 | - // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
354 | - return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
355 | - ? $class_name |
|
356 | - : 'EE_' . $class_name; |
|
357 | - } |
|
338 | + /** |
|
339 | + * @param string $addon_name |
|
340 | + * @param array $setup_args |
|
341 | + * @return string |
|
342 | + */ |
|
343 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
344 | + { |
|
345 | + if (empty($setup_args['class_name'])) { |
|
346 | + // generate one by first separating name with spaces |
|
347 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
348 | + //capitalize, then replace spaces with underscores |
|
349 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
350 | + } else { |
|
351 | + $class_name = $setup_args['class_name']; |
|
352 | + } |
|
353 | + // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
354 | + return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
355 | + ? $class_name |
|
356 | + : 'EE_' . $class_name; |
|
357 | + } |
|
358 | 358 | |
359 | 359 | |
360 | - /** |
|
361 | - * @param string $class_name |
|
362 | - * @param array $setup_args |
|
363 | - * @return array |
|
364 | - */ |
|
365 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
366 | - { |
|
367 | - //setup $_settings array from incoming values. |
|
368 | - $addon_settings = array( |
|
369 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
370 | - 'class_name' => $class_name, |
|
371 | - // the addon slug for use in URLs, etc |
|
372 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
373 | - ? (string) $setup_args['plugin_slug'] |
|
374 | - : '', |
|
375 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
376 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
377 | - ? (string) $setup_args['plugin_action_slug'] |
|
378 | - : '', |
|
379 | - // the "software" version for the addon |
|
380 | - 'version' => isset($setup_args['version']) |
|
381 | - ? (string) $setup_args['version'] |
|
382 | - : '', |
|
383 | - // the minimum version of EE Core that the addon will work with |
|
384 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
385 | - ? (string) $setup_args['min_core_version'] |
|
386 | - : '', |
|
387 | - // the minimum version of WordPress that the addon will work with |
|
388 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
389 | - ? (string) $setup_args['min_wp_version'] |
|
390 | - : EE_MIN_WP_VER_REQUIRED, |
|
391 | - // full server path to main file (file loaded directly by WP) |
|
392 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
393 | - ? (string) $setup_args['main_file_path'] |
|
394 | - : '', |
|
395 | - // Fully Qualified Class Name for the addon's Domain class |
|
396 | - 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
397 | - ? (string) $setup_args['domain_fqcn'] |
|
398 | - : '', |
|
399 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
400 | - 'admin_path' => isset($setup_args['admin_path']) |
|
401 | - ? (string) $setup_args['admin_path'] : '', |
|
402 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
403 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
404 | - ? (string) $setup_args['admin_callback'] |
|
405 | - : '', |
|
406 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
407 | - 'config_section' => isset($setup_args['config_section']) |
|
408 | - ? (string) $setup_args['config_section'] |
|
409 | - : 'addons', |
|
410 | - // the class name for this addon's configuration settings object |
|
411 | - 'config_class' => isset($setup_args['config_class']) |
|
412 | - ? (string) $setup_args['config_class'] : '', |
|
413 | - //the name given to the config for this addons' configuration settings object (optional) |
|
414 | - 'config_name' => isset($setup_args['config_name']) |
|
415 | - ? (string) $setup_args['config_name'] : '', |
|
416 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
417 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
418 | - ? (array) $setup_args['autoloader_paths'] |
|
419 | - : array(), |
|
420 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
421 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
422 | - ? (array) $setup_args['autoloader_folders'] |
|
423 | - : array(), |
|
424 | - // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
425 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
426 | - ? (array) $setup_args['dms_paths'] |
|
427 | - : array(), |
|
428 | - // array of full server paths to any EED_Modules used by the addon |
|
429 | - 'module_paths' => isset($setup_args['module_paths']) |
|
430 | - ? (array) $setup_args['module_paths'] |
|
431 | - : array(), |
|
432 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
433 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
434 | - ? (array) $setup_args['shortcode_paths'] |
|
435 | - : array(), |
|
436 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
437 | - ? (array) $setup_args['shortcode_fqcns'] |
|
438 | - : array(), |
|
439 | - // array of full server paths to any WP_Widgets used by the addon |
|
440 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
441 | - ? (array) $setup_args['widget_paths'] |
|
442 | - : array(), |
|
443 | - // array of PUE options used by the addon |
|
444 | - 'pue_options' => isset($setup_args['pue_options']) |
|
445 | - ? (array) $setup_args['pue_options'] |
|
446 | - : array(), |
|
447 | - 'message_types' => isset($setup_args['message_types']) |
|
448 | - ? (array) $setup_args['message_types'] |
|
449 | - : array(), |
|
450 | - 'capabilities' => isset($setup_args['capabilities']) |
|
451 | - ? (array) $setup_args['capabilities'] |
|
452 | - : array(), |
|
453 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
454 | - ? (array) $setup_args['capability_maps'] |
|
455 | - : array(), |
|
456 | - 'model_paths' => isset($setup_args['model_paths']) |
|
457 | - ? (array) $setup_args['model_paths'] |
|
458 | - : array(), |
|
459 | - 'class_paths' => isset($setup_args['class_paths']) |
|
460 | - ? (array) $setup_args['class_paths'] |
|
461 | - : array(), |
|
462 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
463 | - ? (array) $setup_args['model_extension_paths'] |
|
464 | - : array(), |
|
465 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
466 | - ? (array) $setup_args['class_extension_paths'] |
|
467 | - : array(), |
|
468 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
469 | - ? (array) $setup_args['custom_post_types'] |
|
470 | - : array(), |
|
471 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
472 | - ? (array) $setup_args['custom_taxonomies'] |
|
473 | - : array(), |
|
474 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
475 | - ? (array) $setup_args['payment_method_paths'] |
|
476 | - : array(), |
|
477 | - 'default_terms' => isset($setup_args['default_terms']) |
|
478 | - ? (array) $setup_args['default_terms'] |
|
479 | - : array(), |
|
480 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
481 | - // that can be used for adding upgrading/marketing info |
|
482 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
483 | - ? $setup_args['plugins_page_row'] |
|
484 | - : '', |
|
485 | - 'namespace' => isset( |
|
486 | - $setup_args['namespace']['FQNS'], |
|
487 | - $setup_args['namespace']['DIR'] |
|
488 | - ) |
|
489 | - ? (array) $setup_args['namespace'] |
|
490 | - : array(), |
|
491 | - ); |
|
492 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
493 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
494 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
495 | - && ! empty($addon_settings['admin_path']) |
|
496 | - ? $addon_settings['plugin_slug'] |
|
497 | - : $addon_settings['plugin_action_slug']; |
|
498 | - // full server path to main file (file loaded directly by WP) |
|
499 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
500 | - return $addon_settings; |
|
501 | - } |
|
360 | + /** |
|
361 | + * @param string $class_name |
|
362 | + * @param array $setup_args |
|
363 | + * @return array |
|
364 | + */ |
|
365 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
366 | + { |
|
367 | + //setup $_settings array from incoming values. |
|
368 | + $addon_settings = array( |
|
369 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
370 | + 'class_name' => $class_name, |
|
371 | + // the addon slug for use in URLs, etc |
|
372 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
373 | + ? (string) $setup_args['plugin_slug'] |
|
374 | + : '', |
|
375 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
376 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
377 | + ? (string) $setup_args['plugin_action_slug'] |
|
378 | + : '', |
|
379 | + // the "software" version for the addon |
|
380 | + 'version' => isset($setup_args['version']) |
|
381 | + ? (string) $setup_args['version'] |
|
382 | + : '', |
|
383 | + // the minimum version of EE Core that the addon will work with |
|
384 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
385 | + ? (string) $setup_args['min_core_version'] |
|
386 | + : '', |
|
387 | + // the minimum version of WordPress that the addon will work with |
|
388 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
389 | + ? (string) $setup_args['min_wp_version'] |
|
390 | + : EE_MIN_WP_VER_REQUIRED, |
|
391 | + // full server path to main file (file loaded directly by WP) |
|
392 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
393 | + ? (string) $setup_args['main_file_path'] |
|
394 | + : '', |
|
395 | + // Fully Qualified Class Name for the addon's Domain class |
|
396 | + 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
397 | + ? (string) $setup_args['domain_fqcn'] |
|
398 | + : '', |
|
399 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
400 | + 'admin_path' => isset($setup_args['admin_path']) |
|
401 | + ? (string) $setup_args['admin_path'] : '', |
|
402 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
403 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
404 | + ? (string) $setup_args['admin_callback'] |
|
405 | + : '', |
|
406 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
407 | + 'config_section' => isset($setup_args['config_section']) |
|
408 | + ? (string) $setup_args['config_section'] |
|
409 | + : 'addons', |
|
410 | + // the class name for this addon's configuration settings object |
|
411 | + 'config_class' => isset($setup_args['config_class']) |
|
412 | + ? (string) $setup_args['config_class'] : '', |
|
413 | + //the name given to the config for this addons' configuration settings object (optional) |
|
414 | + 'config_name' => isset($setup_args['config_name']) |
|
415 | + ? (string) $setup_args['config_name'] : '', |
|
416 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
417 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
418 | + ? (array) $setup_args['autoloader_paths'] |
|
419 | + : array(), |
|
420 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
421 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
422 | + ? (array) $setup_args['autoloader_folders'] |
|
423 | + : array(), |
|
424 | + // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
425 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
426 | + ? (array) $setup_args['dms_paths'] |
|
427 | + : array(), |
|
428 | + // array of full server paths to any EED_Modules used by the addon |
|
429 | + 'module_paths' => isset($setup_args['module_paths']) |
|
430 | + ? (array) $setup_args['module_paths'] |
|
431 | + : array(), |
|
432 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
433 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
434 | + ? (array) $setup_args['shortcode_paths'] |
|
435 | + : array(), |
|
436 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
437 | + ? (array) $setup_args['shortcode_fqcns'] |
|
438 | + : array(), |
|
439 | + // array of full server paths to any WP_Widgets used by the addon |
|
440 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
441 | + ? (array) $setup_args['widget_paths'] |
|
442 | + : array(), |
|
443 | + // array of PUE options used by the addon |
|
444 | + 'pue_options' => isset($setup_args['pue_options']) |
|
445 | + ? (array) $setup_args['pue_options'] |
|
446 | + : array(), |
|
447 | + 'message_types' => isset($setup_args['message_types']) |
|
448 | + ? (array) $setup_args['message_types'] |
|
449 | + : array(), |
|
450 | + 'capabilities' => isset($setup_args['capabilities']) |
|
451 | + ? (array) $setup_args['capabilities'] |
|
452 | + : array(), |
|
453 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
454 | + ? (array) $setup_args['capability_maps'] |
|
455 | + : array(), |
|
456 | + 'model_paths' => isset($setup_args['model_paths']) |
|
457 | + ? (array) $setup_args['model_paths'] |
|
458 | + : array(), |
|
459 | + 'class_paths' => isset($setup_args['class_paths']) |
|
460 | + ? (array) $setup_args['class_paths'] |
|
461 | + : array(), |
|
462 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
463 | + ? (array) $setup_args['model_extension_paths'] |
|
464 | + : array(), |
|
465 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
466 | + ? (array) $setup_args['class_extension_paths'] |
|
467 | + : array(), |
|
468 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
469 | + ? (array) $setup_args['custom_post_types'] |
|
470 | + : array(), |
|
471 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
472 | + ? (array) $setup_args['custom_taxonomies'] |
|
473 | + : array(), |
|
474 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
475 | + ? (array) $setup_args['payment_method_paths'] |
|
476 | + : array(), |
|
477 | + 'default_terms' => isset($setup_args['default_terms']) |
|
478 | + ? (array) $setup_args['default_terms'] |
|
479 | + : array(), |
|
480 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
481 | + // that can be used for adding upgrading/marketing info |
|
482 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
483 | + ? $setup_args['plugins_page_row'] |
|
484 | + : '', |
|
485 | + 'namespace' => isset( |
|
486 | + $setup_args['namespace']['FQNS'], |
|
487 | + $setup_args['namespace']['DIR'] |
|
488 | + ) |
|
489 | + ? (array) $setup_args['namespace'] |
|
490 | + : array(), |
|
491 | + ); |
|
492 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
493 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
494 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
495 | + && ! empty($addon_settings['admin_path']) |
|
496 | + ? $addon_settings['plugin_slug'] |
|
497 | + : $addon_settings['plugin_action_slug']; |
|
498 | + // full server path to main file (file loaded directly by WP) |
|
499 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
500 | + return $addon_settings; |
|
501 | + } |
|
502 | 502 | |
503 | 503 | |
504 | - /** |
|
505 | - * @param string $addon_name |
|
506 | - * @param array $addon_settings |
|
507 | - * @return boolean |
|
508 | - */ |
|
509 | - private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
510 | - { |
|
511 | - global $wp_version; |
|
512 | - $incompatibility_message = ''; |
|
513 | - //check whether this addon version is compatible with EE core |
|
514 | - if ( |
|
515 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
516 | - && ! self::_meets_min_core_version_requirement( |
|
517 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
518 | - $addon_settings['version'] |
|
519 | - ) |
|
520 | - ) { |
|
521 | - $incompatibility_message = sprintf( |
|
522 | - __( |
|
523 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
524 | - ), |
|
525 | - $addon_name, |
|
526 | - '<br />', |
|
527 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
528 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
529 | - '</span><br />' |
|
530 | - ); |
|
531 | - } elseif ( |
|
532 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
533 | - ) { |
|
534 | - $incompatibility_message = sprintf( |
|
535 | - __( |
|
536 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
537 | - 'event_espresso' |
|
538 | - ), |
|
539 | - $addon_name, |
|
540 | - self::_effective_version($addon_settings['min_core_version']), |
|
541 | - self::_effective_version(espresso_version()), |
|
542 | - '<br />', |
|
543 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
544 | - '</span><br />' |
|
545 | - ); |
|
546 | - } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
547 | - $incompatibility_message = sprintf( |
|
548 | - __( |
|
549 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
550 | - 'event_espresso' |
|
551 | - ), |
|
552 | - $addon_name, |
|
553 | - $addon_settings['min_wp_version'], |
|
554 | - '<br />', |
|
555 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
556 | - '</span><br />' |
|
557 | - ); |
|
558 | - } |
|
559 | - if (! empty($incompatibility_message)) { |
|
560 | - // remove 'activate' from the REQUEST |
|
561 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
562 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
563 | - if (current_user_can('activate_plugins')) { |
|
564 | - // show an error message indicating the plugin didn't activate properly |
|
565 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
566 | - } |
|
567 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
568 | - return false; |
|
569 | - } |
|
570 | - // addon IS compatible |
|
571 | - return true; |
|
572 | - } |
|
504 | + /** |
|
505 | + * @param string $addon_name |
|
506 | + * @param array $addon_settings |
|
507 | + * @return boolean |
|
508 | + */ |
|
509 | + private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
510 | + { |
|
511 | + global $wp_version; |
|
512 | + $incompatibility_message = ''; |
|
513 | + //check whether this addon version is compatible with EE core |
|
514 | + if ( |
|
515 | + isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
516 | + && ! self::_meets_min_core_version_requirement( |
|
517 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
518 | + $addon_settings['version'] |
|
519 | + ) |
|
520 | + ) { |
|
521 | + $incompatibility_message = sprintf( |
|
522 | + __( |
|
523 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
524 | + ), |
|
525 | + $addon_name, |
|
526 | + '<br />', |
|
527 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
528 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
529 | + '</span><br />' |
|
530 | + ); |
|
531 | + } elseif ( |
|
532 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
533 | + ) { |
|
534 | + $incompatibility_message = sprintf( |
|
535 | + __( |
|
536 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
537 | + 'event_espresso' |
|
538 | + ), |
|
539 | + $addon_name, |
|
540 | + self::_effective_version($addon_settings['min_core_version']), |
|
541 | + self::_effective_version(espresso_version()), |
|
542 | + '<br />', |
|
543 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
544 | + '</span><br />' |
|
545 | + ); |
|
546 | + } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
547 | + $incompatibility_message = sprintf( |
|
548 | + __( |
|
549 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
550 | + 'event_espresso' |
|
551 | + ), |
|
552 | + $addon_name, |
|
553 | + $addon_settings['min_wp_version'], |
|
554 | + '<br />', |
|
555 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
556 | + '</span><br />' |
|
557 | + ); |
|
558 | + } |
|
559 | + if (! empty($incompatibility_message)) { |
|
560 | + // remove 'activate' from the REQUEST |
|
561 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
562 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
563 | + if (current_user_can('activate_plugins')) { |
|
564 | + // show an error message indicating the plugin didn't activate properly |
|
565 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
566 | + } |
|
567 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
568 | + return false; |
|
569 | + } |
|
570 | + // addon IS compatible |
|
571 | + return true; |
|
572 | + } |
|
573 | 573 | |
574 | 574 | |
575 | - /** |
|
576 | - * if plugin update engine is being used for auto-updates, |
|
577 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
578 | - * (not needed if PUE is not being used) |
|
579 | - * |
|
580 | - * @param string $addon_name |
|
581 | - * @param string $class_name |
|
582 | - * @param array $setup_args |
|
583 | - * @return void |
|
584 | - */ |
|
585 | - private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
586 | - { |
|
587 | - if (! empty($setup_args['pue_options'])) { |
|
588 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
589 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
590 | - ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
591 | - : 'espresso_' . strtolower($class_name), |
|
592 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
593 | - ? (string) $setup_args['pue_options']['plugin_basename'] |
|
594 | - : plugin_basename($setup_args['main_file_path']), |
|
595 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
596 | - ? (string) $setup_args['pue_options']['checkPeriod'] |
|
597 | - : '24', |
|
598 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
599 | - ? (string) $setup_args['pue_options']['use_wp_update'] |
|
600 | - : false, |
|
601 | - ); |
|
602 | - add_action( |
|
603 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
604 | - array('EE_Register_Addon', 'load_pue_update') |
|
605 | - ); |
|
606 | - } |
|
607 | - } |
|
575 | + /** |
|
576 | + * if plugin update engine is being used for auto-updates, |
|
577 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
578 | + * (not needed if PUE is not being used) |
|
579 | + * |
|
580 | + * @param string $addon_name |
|
581 | + * @param string $class_name |
|
582 | + * @param array $setup_args |
|
583 | + * @return void |
|
584 | + */ |
|
585 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
586 | + { |
|
587 | + if (! empty($setup_args['pue_options'])) { |
|
588 | + self::$_settings[ $addon_name ]['pue_options'] = array( |
|
589 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
590 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
591 | + : 'espresso_' . strtolower($class_name), |
|
592 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
593 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
594 | + : plugin_basename($setup_args['main_file_path']), |
|
595 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
596 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
597 | + : '24', |
|
598 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
599 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
600 | + : false, |
|
601 | + ); |
|
602 | + add_action( |
|
603 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
604 | + array('EE_Register_Addon', 'load_pue_update') |
|
605 | + ); |
|
606 | + } |
|
607 | + } |
|
608 | 608 | |
609 | 609 | |
610 | - /** |
|
611 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
612 | - * |
|
613 | - * @param array $addon_settings |
|
614 | - * @return void |
|
615 | - */ |
|
616 | - private static function _setup_namespaces(array $addon_settings) |
|
617 | - { |
|
618 | - // |
|
619 | - if ( |
|
620 | - isset( |
|
621 | - $addon_settings['namespace']['FQNS'], |
|
622 | - $addon_settings['namespace']['DIR'] |
|
623 | - ) |
|
624 | - ) { |
|
625 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
626 | - $addon_settings['namespace']['FQNS'], |
|
627 | - $addon_settings['namespace']['DIR'] |
|
628 | - ); |
|
629 | - } |
|
630 | - } |
|
610 | + /** |
|
611 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
612 | + * |
|
613 | + * @param array $addon_settings |
|
614 | + * @return void |
|
615 | + */ |
|
616 | + private static function _setup_namespaces(array $addon_settings) |
|
617 | + { |
|
618 | + // |
|
619 | + if ( |
|
620 | + isset( |
|
621 | + $addon_settings['namespace']['FQNS'], |
|
622 | + $addon_settings['namespace']['DIR'] |
|
623 | + ) |
|
624 | + ) { |
|
625 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
626 | + $addon_settings['namespace']['FQNS'], |
|
627 | + $addon_settings['namespace']['DIR'] |
|
628 | + ); |
|
629 | + } |
|
630 | + } |
|
631 | 631 | |
632 | 632 | |
633 | - /** |
|
634 | - * @param string $addon_name |
|
635 | - * @param array $addon_settings |
|
636 | - * @return bool |
|
637 | - * @throws EE_Error |
|
638 | - * @throws InvalidArgumentException |
|
639 | - * @throws ReflectionException |
|
640 | - * @throws InvalidDataTypeException |
|
641 | - * @throws InvalidInterfaceException |
|
642 | - */ |
|
643 | - private static function _addon_activation($addon_name, array $addon_settings) |
|
644 | - { |
|
645 | - // this is an activation request |
|
646 | - if (did_action('activate_plugin')) { |
|
647 | - //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
648 | - //(as the newly-activated addon wasn't around the first time addons were registered). |
|
649 | - //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
650 | - //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
651 | - if (! isset(self::$_settings[ $addon_name ]) |
|
652 | - || (isset(self::$_settings[ $addon_name ]) |
|
653 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
654 | - ) |
|
655 | - ) { |
|
656 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
657 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
658 | - $addon->set_activation_indicator_option(); |
|
659 | - // dont bother setting up the rest of the addon. |
|
660 | - // we know it was just activated and the request will end soon |
|
661 | - } |
|
662 | - return true; |
|
663 | - } |
|
664 | - // make sure this was called in the right place! |
|
665 | - if ( |
|
666 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
667 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
668 | - ) { |
|
669 | - EE_Error::doing_it_wrong( |
|
670 | - __METHOD__, |
|
671 | - sprintf( |
|
672 | - __( |
|
673 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
674 | - 'event_espresso' |
|
675 | - ), |
|
676 | - $addon_name |
|
677 | - ), |
|
678 | - '4.3.0' |
|
679 | - ); |
|
680 | - } |
|
681 | - // make sure addon settings are set correctly without overwriting anything existing |
|
682 | - if (isset(self::$_settings[ $addon_name ])) { |
|
683 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
684 | - } else { |
|
685 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
686 | - } |
|
687 | - return false; |
|
688 | - } |
|
633 | + /** |
|
634 | + * @param string $addon_name |
|
635 | + * @param array $addon_settings |
|
636 | + * @return bool |
|
637 | + * @throws EE_Error |
|
638 | + * @throws InvalidArgumentException |
|
639 | + * @throws ReflectionException |
|
640 | + * @throws InvalidDataTypeException |
|
641 | + * @throws InvalidInterfaceException |
|
642 | + */ |
|
643 | + private static function _addon_activation($addon_name, array $addon_settings) |
|
644 | + { |
|
645 | + // this is an activation request |
|
646 | + if (did_action('activate_plugin')) { |
|
647 | + //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
648 | + //(as the newly-activated addon wasn't around the first time addons were registered). |
|
649 | + //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
650 | + //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
651 | + if (! isset(self::$_settings[ $addon_name ]) |
|
652 | + || (isset(self::$_settings[ $addon_name ]) |
|
653 | + && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
654 | + ) |
|
655 | + ) { |
|
656 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
657 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
658 | + $addon->set_activation_indicator_option(); |
|
659 | + // dont bother setting up the rest of the addon. |
|
660 | + // we know it was just activated and the request will end soon |
|
661 | + } |
|
662 | + return true; |
|
663 | + } |
|
664 | + // make sure this was called in the right place! |
|
665 | + if ( |
|
666 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
667 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
668 | + ) { |
|
669 | + EE_Error::doing_it_wrong( |
|
670 | + __METHOD__, |
|
671 | + sprintf( |
|
672 | + __( |
|
673 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
674 | + 'event_espresso' |
|
675 | + ), |
|
676 | + $addon_name |
|
677 | + ), |
|
678 | + '4.3.0' |
|
679 | + ); |
|
680 | + } |
|
681 | + // make sure addon settings are set correctly without overwriting anything existing |
|
682 | + if (isset(self::$_settings[ $addon_name ])) { |
|
683 | + self::$_settings[ $addon_name ] += $addon_settings; |
|
684 | + } else { |
|
685 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
686 | + } |
|
687 | + return false; |
|
688 | + } |
|
689 | 689 | |
690 | 690 | |
691 | - /** |
|
692 | - * @param string $addon_name |
|
693 | - * @return void |
|
694 | - * @throws EE_Error |
|
695 | - */ |
|
696 | - private static function _setup_autoloaders($addon_name) |
|
697 | - { |
|
698 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
699 | - // setup autoloader for single file |
|
700 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
701 | - } |
|
702 | - // setup autoloaders for folders |
|
703 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
704 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
705 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
706 | - } |
|
707 | - } |
|
708 | - } |
|
691 | + /** |
|
692 | + * @param string $addon_name |
|
693 | + * @return void |
|
694 | + * @throws EE_Error |
|
695 | + */ |
|
696 | + private static function _setup_autoloaders($addon_name) |
|
697 | + { |
|
698 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
699 | + // setup autoloader for single file |
|
700 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
701 | + } |
|
702 | + // setup autoloaders for folders |
|
703 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
704 | + foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
705 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
706 | + } |
|
707 | + } |
|
708 | + } |
|
709 | 709 | |
710 | 710 | |
711 | - /** |
|
712 | - * register new models and extensions |
|
713 | - * |
|
714 | - * @param string $addon_name |
|
715 | - * @return void |
|
716 | - * @throws EE_Error |
|
717 | - */ |
|
718 | - private static function _register_models_and_extensions($addon_name) |
|
719 | - { |
|
720 | - // register new models |
|
721 | - if ( |
|
722 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
723 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
724 | - ) { |
|
725 | - EE_Register_Model::register( |
|
726 | - $addon_name, |
|
727 | - array( |
|
728 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
729 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
730 | - ) |
|
731 | - ); |
|
732 | - } |
|
733 | - // register model extensions |
|
734 | - if ( |
|
735 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
736 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
737 | - ) { |
|
738 | - EE_Register_Model_Extensions::register( |
|
739 | - $addon_name, |
|
740 | - array( |
|
741 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
742 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
743 | - ) |
|
744 | - ); |
|
745 | - } |
|
746 | - } |
|
711 | + /** |
|
712 | + * register new models and extensions |
|
713 | + * |
|
714 | + * @param string $addon_name |
|
715 | + * @return void |
|
716 | + * @throws EE_Error |
|
717 | + */ |
|
718 | + private static function _register_models_and_extensions($addon_name) |
|
719 | + { |
|
720 | + // register new models |
|
721 | + if ( |
|
722 | + ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
723 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
724 | + ) { |
|
725 | + EE_Register_Model::register( |
|
726 | + $addon_name, |
|
727 | + array( |
|
728 | + 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
729 | + 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
730 | + ) |
|
731 | + ); |
|
732 | + } |
|
733 | + // register model extensions |
|
734 | + if ( |
|
735 | + ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
736 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
737 | + ) { |
|
738 | + EE_Register_Model_Extensions::register( |
|
739 | + $addon_name, |
|
740 | + array( |
|
741 | + 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
742 | + 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
743 | + ) |
|
744 | + ); |
|
745 | + } |
|
746 | + } |
|
747 | 747 | |
748 | 748 | |
749 | - /** |
|
750 | - * @param string $addon_name |
|
751 | - * @return void |
|
752 | - * @throws EE_Error |
|
753 | - */ |
|
754 | - private static function _register_data_migration_scripts($addon_name) |
|
755 | - { |
|
756 | - // setup DMS |
|
757 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
758 | - EE_Register_Data_Migration_Scripts::register( |
|
759 | - $addon_name, |
|
760 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
761 | - ); |
|
762 | - } |
|
763 | - } |
|
749 | + /** |
|
750 | + * @param string $addon_name |
|
751 | + * @return void |
|
752 | + * @throws EE_Error |
|
753 | + */ |
|
754 | + private static function _register_data_migration_scripts($addon_name) |
|
755 | + { |
|
756 | + // setup DMS |
|
757 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
758 | + EE_Register_Data_Migration_Scripts::register( |
|
759 | + $addon_name, |
|
760 | + array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
761 | + ); |
|
762 | + } |
|
763 | + } |
|
764 | 764 | |
765 | 765 | |
766 | - /** |
|
767 | - * @param string $addon_name |
|
768 | - * @return void |
|
769 | - * @throws EE_Error |
|
770 | - */ |
|
771 | - private static function _register_config($addon_name) |
|
772 | - { |
|
773 | - // if config_class is present let's register config. |
|
774 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
775 | - EE_Register_Config::register( |
|
776 | - self::$_settings[ $addon_name ]['config_class'], |
|
777 | - array( |
|
778 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
779 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
780 | - ) |
|
781 | - ); |
|
782 | - } |
|
783 | - } |
|
766 | + /** |
|
767 | + * @param string $addon_name |
|
768 | + * @return void |
|
769 | + * @throws EE_Error |
|
770 | + */ |
|
771 | + private static function _register_config($addon_name) |
|
772 | + { |
|
773 | + // if config_class is present let's register config. |
|
774 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
775 | + EE_Register_Config::register( |
|
776 | + self::$_settings[ $addon_name ]['config_class'], |
|
777 | + array( |
|
778 | + 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
779 | + 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
780 | + ) |
|
781 | + ); |
|
782 | + } |
|
783 | + } |
|
784 | 784 | |
785 | 785 | |
786 | - /** |
|
787 | - * @param string $addon_name |
|
788 | - * @return void |
|
789 | - * @throws EE_Error |
|
790 | - */ |
|
791 | - private static function _register_admin_pages($addon_name) |
|
792 | - { |
|
793 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
794 | - EE_Register_Admin_Page::register( |
|
795 | - $addon_name, |
|
796 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
797 | - ); |
|
798 | - } |
|
799 | - } |
|
786 | + /** |
|
787 | + * @param string $addon_name |
|
788 | + * @return void |
|
789 | + * @throws EE_Error |
|
790 | + */ |
|
791 | + private static function _register_admin_pages($addon_name) |
|
792 | + { |
|
793 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
794 | + EE_Register_Admin_Page::register( |
|
795 | + $addon_name, |
|
796 | + array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
797 | + ); |
|
798 | + } |
|
799 | + } |
|
800 | 800 | |
801 | 801 | |
802 | - /** |
|
803 | - * @param string $addon_name |
|
804 | - * @return void |
|
805 | - * @throws EE_Error |
|
806 | - */ |
|
807 | - private static function _register_modules($addon_name) |
|
808 | - { |
|
809 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
810 | - EE_Register_Module::register( |
|
811 | - $addon_name, |
|
812 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
813 | - ); |
|
814 | - } |
|
815 | - } |
|
802 | + /** |
|
803 | + * @param string $addon_name |
|
804 | + * @return void |
|
805 | + * @throws EE_Error |
|
806 | + */ |
|
807 | + private static function _register_modules($addon_name) |
|
808 | + { |
|
809 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
810 | + EE_Register_Module::register( |
|
811 | + $addon_name, |
|
812 | + array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
813 | + ); |
|
814 | + } |
|
815 | + } |
|
816 | 816 | |
817 | 817 | |
818 | - /** |
|
819 | - * @param string $addon_name |
|
820 | - * @return void |
|
821 | - * @throws EE_Error |
|
822 | - */ |
|
823 | - private static function _register_shortcodes($addon_name) |
|
824 | - { |
|
825 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
826 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
827 | - ) { |
|
828 | - EE_Register_Shortcode::register( |
|
829 | - $addon_name, |
|
830 | - array( |
|
831 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
832 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
833 | - : array(), |
|
834 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
835 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
836 | - : array(), |
|
837 | - ) |
|
838 | - ); |
|
839 | - } |
|
840 | - } |
|
818 | + /** |
|
819 | + * @param string $addon_name |
|
820 | + * @return void |
|
821 | + * @throws EE_Error |
|
822 | + */ |
|
823 | + private static function _register_shortcodes($addon_name) |
|
824 | + { |
|
825 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
826 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
827 | + ) { |
|
828 | + EE_Register_Shortcode::register( |
|
829 | + $addon_name, |
|
830 | + array( |
|
831 | + 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
832 | + ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
833 | + : array(), |
|
834 | + 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
835 | + ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
836 | + : array(), |
|
837 | + ) |
|
838 | + ); |
|
839 | + } |
|
840 | + } |
|
841 | 841 | |
842 | 842 | |
843 | - /** |
|
844 | - * @param string $addon_name |
|
845 | - * @return void |
|
846 | - * @throws EE_Error |
|
847 | - */ |
|
848 | - private static function _register_widgets($addon_name) |
|
849 | - { |
|
850 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
851 | - EE_Register_Widget::register( |
|
852 | - $addon_name, |
|
853 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
854 | - ); |
|
855 | - } |
|
856 | - } |
|
843 | + /** |
|
844 | + * @param string $addon_name |
|
845 | + * @return void |
|
846 | + * @throws EE_Error |
|
847 | + */ |
|
848 | + private static function _register_widgets($addon_name) |
|
849 | + { |
|
850 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
851 | + EE_Register_Widget::register( |
|
852 | + $addon_name, |
|
853 | + array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
854 | + ); |
|
855 | + } |
|
856 | + } |
|
857 | 857 | |
858 | 858 | |
859 | - /** |
|
860 | - * @param string $addon_name |
|
861 | - * @return void |
|
862 | - * @throws EE_Error |
|
863 | - */ |
|
864 | - private static function _register_capabilities($addon_name) |
|
865 | - { |
|
866 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
867 | - EE_Register_Capabilities::register( |
|
868 | - $addon_name, |
|
869 | - array( |
|
870 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
871 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
872 | - ) |
|
873 | - ); |
|
874 | - } |
|
875 | - } |
|
859 | + /** |
|
860 | + * @param string $addon_name |
|
861 | + * @return void |
|
862 | + * @throws EE_Error |
|
863 | + */ |
|
864 | + private static function _register_capabilities($addon_name) |
|
865 | + { |
|
866 | + if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
867 | + EE_Register_Capabilities::register( |
|
868 | + $addon_name, |
|
869 | + array( |
|
870 | + 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
871 | + 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
872 | + ) |
|
873 | + ); |
|
874 | + } |
|
875 | + } |
|
876 | 876 | |
877 | 877 | |
878 | - /** |
|
879 | - * @param string $addon_name |
|
880 | - * @return void |
|
881 | - * @throws EE_Error |
|
882 | - */ |
|
883 | - private static function _register_message_types($addon_name) |
|
884 | - { |
|
885 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
886 | - add_action( |
|
887 | - 'EE_Brewing_Regular___messages_caf', |
|
888 | - array('EE_Register_Addon', 'register_message_types') |
|
889 | - ); |
|
890 | - } |
|
891 | - } |
|
878 | + /** |
|
879 | + * @param string $addon_name |
|
880 | + * @return void |
|
881 | + * @throws EE_Error |
|
882 | + */ |
|
883 | + private static function _register_message_types($addon_name) |
|
884 | + { |
|
885 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
886 | + add_action( |
|
887 | + 'EE_Brewing_Regular___messages_caf', |
|
888 | + array('EE_Register_Addon', 'register_message_types') |
|
889 | + ); |
|
890 | + } |
|
891 | + } |
|
892 | 892 | |
893 | 893 | |
894 | - /** |
|
895 | - * @param string $addon_name |
|
896 | - * @return void |
|
897 | - * @throws EE_Error |
|
898 | - */ |
|
899 | - private static function _register_custom_post_types($addon_name) |
|
900 | - { |
|
901 | - if ( |
|
902 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
903 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
904 | - ) { |
|
905 | - EE_Register_CPT::register( |
|
906 | - $addon_name, |
|
907 | - array( |
|
908 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
909 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
910 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
911 | - ) |
|
912 | - ); |
|
913 | - } |
|
914 | - } |
|
894 | + /** |
|
895 | + * @param string $addon_name |
|
896 | + * @return void |
|
897 | + * @throws EE_Error |
|
898 | + */ |
|
899 | + private static function _register_custom_post_types($addon_name) |
|
900 | + { |
|
901 | + if ( |
|
902 | + ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
903 | + || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
904 | + ) { |
|
905 | + EE_Register_CPT::register( |
|
906 | + $addon_name, |
|
907 | + array( |
|
908 | + 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
909 | + 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
910 | + 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
911 | + ) |
|
912 | + ); |
|
913 | + } |
|
914 | + } |
|
915 | 915 | |
916 | 916 | |
917 | - /** |
|
918 | - * @param string $addon_name |
|
919 | - * @return void |
|
920 | - * @throws InvalidArgumentException |
|
921 | - * @throws InvalidInterfaceException |
|
922 | - * @throws InvalidDataTypeException |
|
923 | - * @throws DomainException |
|
924 | - * @throws EE_Error |
|
925 | - */ |
|
926 | - private static function _register_payment_methods($addon_name) |
|
927 | - { |
|
928 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
929 | - EE_Register_Payment_Method::register( |
|
930 | - $addon_name, |
|
931 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
932 | - ); |
|
933 | - } |
|
934 | - } |
|
917 | + /** |
|
918 | + * @param string $addon_name |
|
919 | + * @return void |
|
920 | + * @throws InvalidArgumentException |
|
921 | + * @throws InvalidInterfaceException |
|
922 | + * @throws InvalidDataTypeException |
|
923 | + * @throws DomainException |
|
924 | + * @throws EE_Error |
|
925 | + */ |
|
926 | + private static function _register_payment_methods($addon_name) |
|
927 | + { |
|
928 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
929 | + EE_Register_Payment_Method::register( |
|
930 | + $addon_name, |
|
931 | + array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
932 | + ); |
|
933 | + } |
|
934 | + } |
|
935 | 935 | |
936 | 936 | |
937 | - /** |
|
938 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
939 | - * |
|
940 | - * @param string $addon_name |
|
941 | - * @return EE_Addon |
|
942 | - * @throws InvalidArgumentException |
|
943 | - * @throws InvalidInterfaceException |
|
944 | - * @throws InvalidDataTypeException |
|
945 | - * @throws ReflectionException |
|
946 | - * @throws EE_Error |
|
947 | - */ |
|
948 | - private static function _load_and_init_addon_class($addon_name) |
|
949 | - { |
|
950 | - $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
951 | - $addon = $loader->getShared( |
|
952 | - self::$_settings[ $addon_name ]['class_name'], |
|
953 | - array('EE_Registry::create(addon)' => true) |
|
954 | - ); |
|
955 | - // setter inject dep map if required |
|
956 | - if($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null){ |
|
957 | - $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
|
958 | - } |
|
959 | - // setter inject domain if required |
|
960 | - if( |
|
961 | - $addon instanceof RequiresDomainInterface |
|
962 | - && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
963 | - && $addon->domain() === null |
|
964 | - ){ |
|
965 | - $addon->setDomain( |
|
966 | - $loader->getShared( |
|
967 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
968 | - array( |
|
969 | - self::$_settings[ $addon_name ]['main_file_path'], |
|
970 | - self::$_settings[ $addon_name ]['version'] |
|
971 | - ) |
|
972 | - ) |
|
973 | - ); |
|
974 | - } |
|
937 | + /** |
|
938 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
939 | + * |
|
940 | + * @param string $addon_name |
|
941 | + * @return EE_Addon |
|
942 | + * @throws InvalidArgumentException |
|
943 | + * @throws InvalidInterfaceException |
|
944 | + * @throws InvalidDataTypeException |
|
945 | + * @throws ReflectionException |
|
946 | + * @throws EE_Error |
|
947 | + */ |
|
948 | + private static function _load_and_init_addon_class($addon_name) |
|
949 | + { |
|
950 | + $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
951 | + $addon = $loader->getShared( |
|
952 | + self::$_settings[ $addon_name ]['class_name'], |
|
953 | + array('EE_Registry::create(addon)' => true) |
|
954 | + ); |
|
955 | + // setter inject dep map if required |
|
956 | + if($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null){ |
|
957 | + $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
|
958 | + } |
|
959 | + // setter inject domain if required |
|
960 | + if( |
|
961 | + $addon instanceof RequiresDomainInterface |
|
962 | + && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
963 | + && $addon->domain() === null |
|
964 | + ){ |
|
965 | + $addon->setDomain( |
|
966 | + $loader->getShared( |
|
967 | + self::$_settings[ $addon_name ]['domain_fqcn'], |
|
968 | + array( |
|
969 | + self::$_settings[ $addon_name ]['main_file_path'], |
|
970 | + self::$_settings[ $addon_name ]['version'] |
|
971 | + ) |
|
972 | + ) |
|
973 | + ); |
|
974 | + } |
|
975 | 975 | |
976 | - $addon->set_name($addon_name); |
|
977 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
978 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
979 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
980 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
981 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
982 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
983 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
984 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
985 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
986 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
987 | - //unfortunately this can't be hooked in upon construction, because we don't have |
|
988 | - //the plugin mainfile's path upon construction. |
|
989 | - register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
990 | - // call any additional admin_callback functions during load_admin_controller hook |
|
991 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
992 | - add_action( |
|
993 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
994 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
995 | - ); |
|
996 | - } |
|
997 | - return $addon; |
|
998 | - } |
|
976 | + $addon->set_name($addon_name); |
|
977 | + $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
978 | + $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
979 | + $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
980 | + $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
981 | + $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
982 | + $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
983 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
984 | + $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
985 | + $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
986 | + $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
987 | + //unfortunately this can't be hooked in upon construction, because we don't have |
|
988 | + //the plugin mainfile's path upon construction. |
|
989 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
990 | + // call any additional admin_callback functions during load_admin_controller hook |
|
991 | + if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
992 | + add_action( |
|
993 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
994 | + array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
995 | + ); |
|
996 | + } |
|
997 | + return $addon; |
|
998 | + } |
|
999 | 999 | |
1000 | 1000 | |
1001 | - /** |
|
1002 | - * load_pue_update - Update notifications |
|
1003 | - * |
|
1004 | - * @return void |
|
1005 | - * @throws InvalidArgumentException |
|
1006 | - * @throws InvalidDataTypeException |
|
1007 | - * @throws InvalidInterfaceException |
|
1008 | - */ |
|
1009 | - public static function load_pue_update() |
|
1010 | - { |
|
1011 | - // load PUE client |
|
1012 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
1013 | - // cycle thru settings |
|
1014 | - foreach (self::$_settings as $settings) { |
|
1015 | - if (! empty($settings['pue_options'])) { |
|
1016 | - // initiate the class and start the plugin update engine! |
|
1017 | - new PluginUpdateEngineChecker( |
|
1018 | - // host file URL |
|
1019 | - 'https://eventespresso.com', |
|
1020 | - // plugin slug(s) |
|
1021 | - array( |
|
1022 | - 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
1023 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
1024 | - ), |
|
1025 | - // options |
|
1026 | - array( |
|
1027 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
1028 | - 'lang_domain' => 'event_espresso', |
|
1029 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
1030 | - 'option_key' => 'site_license_key', |
|
1031 | - 'options_page_slug' => 'event_espresso', |
|
1032 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
1033 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
1034 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
1035 | - ) |
|
1036 | - ); |
|
1037 | - } |
|
1038 | - } |
|
1039 | - } |
|
1001 | + /** |
|
1002 | + * load_pue_update - Update notifications |
|
1003 | + * |
|
1004 | + * @return void |
|
1005 | + * @throws InvalidArgumentException |
|
1006 | + * @throws InvalidDataTypeException |
|
1007 | + * @throws InvalidInterfaceException |
|
1008 | + */ |
|
1009 | + public static function load_pue_update() |
|
1010 | + { |
|
1011 | + // load PUE client |
|
1012 | + require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
1013 | + // cycle thru settings |
|
1014 | + foreach (self::$_settings as $settings) { |
|
1015 | + if (! empty($settings['pue_options'])) { |
|
1016 | + // initiate the class and start the plugin update engine! |
|
1017 | + new PluginUpdateEngineChecker( |
|
1018 | + // host file URL |
|
1019 | + 'https://eventespresso.com', |
|
1020 | + // plugin slug(s) |
|
1021 | + array( |
|
1022 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
1023 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
1024 | + ), |
|
1025 | + // options |
|
1026 | + array( |
|
1027 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
1028 | + 'lang_domain' => 'event_espresso', |
|
1029 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
1030 | + 'option_key' => 'site_license_key', |
|
1031 | + 'options_page_slug' => 'event_espresso', |
|
1032 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
1033 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
1034 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
1035 | + ) |
|
1036 | + ); |
|
1037 | + } |
|
1038 | + } |
|
1039 | + } |
|
1040 | 1040 | |
1041 | 1041 | |
1042 | - /** |
|
1043 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1044 | - * |
|
1045 | - * @since 4.4.0 |
|
1046 | - * @return void |
|
1047 | - * @throws EE_Error |
|
1048 | - */ |
|
1049 | - public static function register_message_types() |
|
1050 | - { |
|
1051 | - foreach (self::$_settings as $addon_name => $settings) { |
|
1052 | - if (! empty($settings['message_types'])) { |
|
1053 | - foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1054 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1055 | - } |
|
1056 | - } |
|
1057 | - } |
|
1058 | - } |
|
1042 | + /** |
|
1043 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1044 | + * |
|
1045 | + * @since 4.4.0 |
|
1046 | + * @return void |
|
1047 | + * @throws EE_Error |
|
1048 | + */ |
|
1049 | + public static function register_message_types() |
|
1050 | + { |
|
1051 | + foreach (self::$_settings as $addon_name => $settings) { |
|
1052 | + if (! empty($settings['message_types'])) { |
|
1053 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1054 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1055 | + } |
|
1056 | + } |
|
1057 | + } |
|
1058 | + } |
|
1059 | 1059 | |
1060 | 1060 | |
1061 | - /** |
|
1062 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
1063 | - * |
|
1064 | - * @since 4.3.0 |
|
1065 | - * @param string $addon_name the name for the addon that was previously registered |
|
1066 | - * @throws DomainException |
|
1067 | - * @throws EE_Error |
|
1068 | - * @throws InvalidArgumentException |
|
1069 | - * @throws InvalidDataTypeException |
|
1070 | - * @throws InvalidInterfaceException |
|
1071 | - */ |
|
1072 | - public static function deregister($addon_name = null) |
|
1073 | - { |
|
1074 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1075 | - try { |
|
1076 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1077 | - $class_name = self::$_settings[$addon_name]['class_name']; |
|
1078 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
1079 | - // setup DMS |
|
1080 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1081 | - } |
|
1082 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
1083 | - // register admin page |
|
1084 | - EE_Register_Admin_Page::deregister($addon_name); |
|
1085 | - } |
|
1086 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
1087 | - // add to list of modules to be registered |
|
1088 | - EE_Register_Module::deregister($addon_name); |
|
1089 | - } |
|
1090 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
1091 | - || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
1092 | - ) { |
|
1093 | - // add to list of shortcodes to be registered |
|
1094 | - EE_Register_Shortcode::deregister($addon_name); |
|
1095 | - } |
|
1096 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
1097 | - // if config_class present let's register config. |
|
1098 | - EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
1099 | - } |
|
1100 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
1101 | - // add to list of widgets to be registered |
|
1102 | - EE_Register_Widget::deregister($addon_name); |
|
1103 | - } |
|
1104 | - if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
1105 | - || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
1106 | - ) { |
|
1107 | - // add to list of shortcodes to be registered |
|
1108 | - EE_Register_Model::deregister($addon_name); |
|
1109 | - } |
|
1110 | - if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
1111 | - || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
1112 | - ) { |
|
1113 | - // add to list of shortcodes to be registered |
|
1114 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
1115 | - } |
|
1116 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
1117 | - foreach ( |
|
1118 | - (array)self::$_settings[$addon_name]['message_types'] as $message_type => |
|
1119 | - $message_type_settings |
|
1120 | - ) { |
|
1121 | - EE_Register_Message_Type::deregister($message_type); |
|
1122 | - } |
|
1123 | - } |
|
1124 | - //deregister capabilities for addon |
|
1125 | - if ( |
|
1126 | - ! empty(self::$_settings[$addon_name]['capabilities']) |
|
1127 | - || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
1128 | - ) { |
|
1129 | - EE_Register_Capabilities::deregister($addon_name); |
|
1130 | - } |
|
1131 | - //deregister custom_post_types for addon |
|
1132 | - if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
1133 | - EE_Register_CPT::deregister($addon_name); |
|
1134 | - } |
|
1135 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
1136 | - EE_Register_Payment_Method::deregister($addon_name); |
|
1137 | - } |
|
1138 | - $addon = EE_Registry::instance()->getAddon($class_name); |
|
1139 | - if ($addon instanceof EE_Addon) { |
|
1140 | - remove_action( |
|
1141 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1142 | - array($addon, 'deactivation') |
|
1143 | - ); |
|
1144 | - remove_action( |
|
1145 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1146 | - array($addon, 'initialize_db_if_no_migrations_required') |
|
1147 | - ); |
|
1148 | - //remove `after_registration` call |
|
1149 | - remove_action( |
|
1150 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
1151 | - array($addon, 'after_registration'), |
|
1152 | - 999 |
|
1153 | - ); |
|
1154 | - } |
|
1155 | - EE_Registry::instance()->removeAddon($class_name); |
|
1156 | - } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1157 | - //the add-on was not yet registered in the registry, so RegistryContainer::__get() throws this exception. |
|
1158 | - //also no need to worry about this or log it, it's ok to deregister an add-on before its registered in the registry |
|
1159 | - } catch (Exception $e) { |
|
1160 | - new ExceptionLogger($e); |
|
1161 | - } |
|
1162 | - unset(self::$_settings[ $addon_name ]); |
|
1163 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1164 | - } |
|
1165 | - } |
|
1061 | + /** |
|
1062 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
1063 | + * |
|
1064 | + * @since 4.3.0 |
|
1065 | + * @param string $addon_name the name for the addon that was previously registered |
|
1066 | + * @throws DomainException |
|
1067 | + * @throws EE_Error |
|
1068 | + * @throws InvalidArgumentException |
|
1069 | + * @throws InvalidDataTypeException |
|
1070 | + * @throws InvalidInterfaceException |
|
1071 | + */ |
|
1072 | + public static function deregister($addon_name = null) |
|
1073 | + { |
|
1074 | + if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1075 | + try { |
|
1076 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1077 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
1078 | + if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
1079 | + // setup DMS |
|
1080 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1081 | + } |
|
1082 | + if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
1083 | + // register admin page |
|
1084 | + EE_Register_Admin_Page::deregister($addon_name); |
|
1085 | + } |
|
1086 | + if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
1087 | + // add to list of modules to be registered |
|
1088 | + EE_Register_Module::deregister($addon_name); |
|
1089 | + } |
|
1090 | + if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
1091 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
1092 | + ) { |
|
1093 | + // add to list of shortcodes to be registered |
|
1094 | + EE_Register_Shortcode::deregister($addon_name); |
|
1095 | + } |
|
1096 | + if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
1097 | + // if config_class present let's register config. |
|
1098 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
1099 | + } |
|
1100 | + if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
1101 | + // add to list of widgets to be registered |
|
1102 | + EE_Register_Widget::deregister($addon_name); |
|
1103 | + } |
|
1104 | + if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
1105 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
1106 | + ) { |
|
1107 | + // add to list of shortcodes to be registered |
|
1108 | + EE_Register_Model::deregister($addon_name); |
|
1109 | + } |
|
1110 | + if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
1111 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
1112 | + ) { |
|
1113 | + // add to list of shortcodes to be registered |
|
1114 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
1115 | + } |
|
1116 | + if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
1117 | + foreach ( |
|
1118 | + (array)self::$_settings[$addon_name]['message_types'] as $message_type => |
|
1119 | + $message_type_settings |
|
1120 | + ) { |
|
1121 | + EE_Register_Message_Type::deregister($message_type); |
|
1122 | + } |
|
1123 | + } |
|
1124 | + //deregister capabilities for addon |
|
1125 | + if ( |
|
1126 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
1127 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
1128 | + ) { |
|
1129 | + EE_Register_Capabilities::deregister($addon_name); |
|
1130 | + } |
|
1131 | + //deregister custom_post_types for addon |
|
1132 | + if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
1133 | + EE_Register_CPT::deregister($addon_name); |
|
1134 | + } |
|
1135 | + if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
1136 | + EE_Register_Payment_Method::deregister($addon_name); |
|
1137 | + } |
|
1138 | + $addon = EE_Registry::instance()->getAddon($class_name); |
|
1139 | + if ($addon instanceof EE_Addon) { |
|
1140 | + remove_action( |
|
1141 | + 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1142 | + array($addon, 'deactivation') |
|
1143 | + ); |
|
1144 | + remove_action( |
|
1145 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1146 | + array($addon, 'initialize_db_if_no_migrations_required') |
|
1147 | + ); |
|
1148 | + //remove `after_registration` call |
|
1149 | + remove_action( |
|
1150 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
1151 | + array($addon, 'after_registration'), |
|
1152 | + 999 |
|
1153 | + ); |
|
1154 | + } |
|
1155 | + EE_Registry::instance()->removeAddon($class_name); |
|
1156 | + } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1157 | + //the add-on was not yet registered in the registry, so RegistryContainer::__get() throws this exception. |
|
1158 | + //also no need to worry about this or log it, it's ok to deregister an add-on before its registered in the registry |
|
1159 | + } catch (Exception $e) { |
|
1160 | + new ExceptionLogger($e); |
|
1161 | + } |
|
1162 | + unset(self::$_settings[ $addon_name ]); |
|
1163 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1164 | + } |
|
1165 | + } |
|
1166 | 1166 | |
1167 | 1167 | |
1168 | 1168 | } |
@@ -72,15 +72,15 @@ discard block |
||
72 | 72 | // offsets: 0 . 1 . 2 . 3 . 4 |
73 | 73 | $version_parts = explode('.', $min_core_version); |
74 | 74 | //check they specified the micro version (after 2nd period) |
75 | - if (! isset($version_parts[2])) { |
|
75 | + if ( ! isset($version_parts[2])) { |
|
76 | 76 | $version_parts[2] = '0'; |
77 | 77 | } |
78 | 78 | //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
79 | 79 | //soon we can assume that's 'rc', but this current version is 'alpha' |
80 | - if (! isset($version_parts[3])) { |
|
80 | + if ( ! isset($version_parts[3])) { |
|
81 | 81 | $version_parts[3] = 'dev'; |
82 | 82 | } |
83 | - if (! isset($version_parts[4])) { |
|
83 | + if ( ! isset($version_parts[4])) { |
|
84 | 84 | $version_parts[4] = '000'; |
85 | 85 | } |
86 | 86 | return implode('.', $version_parts); |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | // setup PUE |
252 | 252 | EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
253 | 253 | // does this addon work with this version of core or WordPress ? |
254 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
254 | + if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
255 | 255 | return; |
256 | 256 | } |
257 | 257 | // register namespaces |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | ) |
310 | 310 | ); |
311 | 311 | } |
312 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
312 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
313 | 313 | throw new EE_Error( |
314 | 314 | sprintf( |
315 | 315 | __( |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | ); |
322 | 322 | } |
323 | 323 | // check that addon has not already been registered with that name |
324 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
324 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
325 | 325 | throw new EE_Error( |
326 | 326 | sprintf( |
327 | 327 | __( |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
354 | 354 | return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
355 | 355 | ? $class_name |
356 | - : 'EE_' . $class_name; |
|
356 | + : 'EE_'.$class_name; |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | |
@@ -512,9 +512,9 @@ discard block |
||
512 | 512 | $incompatibility_message = ''; |
513 | 513 | //check whether this addon version is compatible with EE core |
514 | 514 | if ( |
515 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
515 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
516 | 516 | && ! self::_meets_min_core_version_requirement( |
517 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
517 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
518 | 518 | $addon_settings['version'] |
519 | 519 | ) |
520 | 520 | ) { |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | ), |
525 | 525 | $addon_name, |
526 | 526 | '<br />', |
527 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
527 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
528 | 528 | '<span style="font-weight: bold; color: #D54E21;">', |
529 | 529 | '</span><br />' |
530 | 530 | ); |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | '</span><br />' |
557 | 557 | ); |
558 | 558 | } |
559 | - if (! empty($incompatibility_message)) { |
|
559 | + if ( ! empty($incompatibility_message)) { |
|
560 | 560 | // remove 'activate' from the REQUEST |
561 | 561 | // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
562 | 562 | unset($_GET['activate'], $_REQUEST['activate']); |
@@ -584,11 +584,11 @@ discard block |
||
584 | 584 | */ |
585 | 585 | private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
586 | 586 | { |
587 | - if (! empty($setup_args['pue_options'])) { |
|
588 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
587 | + if ( ! empty($setup_args['pue_options'])) { |
|
588 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
589 | 589 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
590 | 590 | ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
591 | - : 'espresso_' . strtolower($class_name), |
|
591 | + : 'espresso_'.strtolower($class_name), |
|
592 | 592 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
593 | 593 | ? (string) $setup_args['pue_options']['plugin_basename'] |
594 | 594 | : plugin_basename($setup_args['main_file_path']), |
@@ -648,12 +648,12 @@ discard block |
||
648 | 648 | //(as the newly-activated addon wasn't around the first time addons were registered). |
649 | 649 | //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
650 | 650 | //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
651 | - if (! isset(self::$_settings[ $addon_name ]) |
|
652 | - || (isset(self::$_settings[ $addon_name ]) |
|
653 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
651 | + if ( ! isset(self::$_settings[$addon_name]) |
|
652 | + || (isset(self::$_settings[$addon_name]) |
|
653 | + && ! isset(self::$_settings[$addon_name]['class_name']) |
|
654 | 654 | ) |
655 | 655 | ) { |
656 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
656 | + self::$_settings[$addon_name] = $addon_settings; |
|
657 | 657 | $addon = self::_load_and_init_addon_class($addon_name); |
658 | 658 | $addon->set_activation_indicator_option(); |
659 | 659 | // dont bother setting up the rest of the addon. |
@@ -679,10 +679,10 @@ discard block |
||
679 | 679 | ); |
680 | 680 | } |
681 | 681 | // make sure addon settings are set correctly without overwriting anything existing |
682 | - if (isset(self::$_settings[ $addon_name ])) { |
|
683 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
682 | + if (isset(self::$_settings[$addon_name])) { |
|
683 | + self::$_settings[$addon_name] += $addon_settings; |
|
684 | 684 | } else { |
685 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
685 | + self::$_settings[$addon_name] = $addon_settings; |
|
686 | 686 | } |
687 | 687 | return false; |
688 | 688 | } |
@@ -695,13 +695,13 @@ discard block |
||
695 | 695 | */ |
696 | 696 | private static function _setup_autoloaders($addon_name) |
697 | 697 | { |
698 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
698 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
699 | 699 | // setup autoloader for single file |
700 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
700 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
701 | 701 | } |
702 | 702 | // setup autoloaders for folders |
703 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
704 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
703 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
704 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
705 | 705 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
706 | 706 | } |
707 | 707 | } |
@@ -719,27 +719,27 @@ discard block |
||
719 | 719 | { |
720 | 720 | // register new models |
721 | 721 | if ( |
722 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
723 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
722 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
723 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
724 | 724 | ) { |
725 | 725 | EE_Register_Model::register( |
726 | 726 | $addon_name, |
727 | 727 | array( |
728 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
729 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
728 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
729 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
730 | 730 | ) |
731 | 731 | ); |
732 | 732 | } |
733 | 733 | // register model extensions |
734 | 734 | if ( |
735 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
736 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
735 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
736 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
737 | 737 | ) { |
738 | 738 | EE_Register_Model_Extensions::register( |
739 | 739 | $addon_name, |
740 | 740 | array( |
741 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
742 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
741 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
742 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
743 | 743 | ) |
744 | 744 | ); |
745 | 745 | } |
@@ -754,10 +754,10 @@ discard block |
||
754 | 754 | private static function _register_data_migration_scripts($addon_name) |
755 | 755 | { |
756 | 756 | // setup DMS |
757 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
757 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
758 | 758 | EE_Register_Data_Migration_Scripts::register( |
759 | 759 | $addon_name, |
760 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
760 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
761 | 761 | ); |
762 | 762 | } |
763 | 763 | } |
@@ -771,12 +771,12 @@ discard block |
||
771 | 771 | private static function _register_config($addon_name) |
772 | 772 | { |
773 | 773 | // if config_class is present let's register config. |
774 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
774 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
775 | 775 | EE_Register_Config::register( |
776 | - self::$_settings[ $addon_name ]['config_class'], |
|
776 | + self::$_settings[$addon_name]['config_class'], |
|
777 | 777 | array( |
778 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
779 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
778 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
779 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
780 | 780 | ) |
781 | 781 | ); |
782 | 782 | } |
@@ -790,10 +790,10 @@ discard block |
||
790 | 790 | */ |
791 | 791 | private static function _register_admin_pages($addon_name) |
792 | 792 | { |
793 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
793 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
794 | 794 | EE_Register_Admin_Page::register( |
795 | 795 | $addon_name, |
796 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
796 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
797 | 797 | ); |
798 | 798 | } |
799 | 799 | } |
@@ -806,10 +806,10 @@ discard block |
||
806 | 806 | */ |
807 | 807 | private static function _register_modules($addon_name) |
808 | 808 | { |
809 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
809 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
810 | 810 | EE_Register_Module::register( |
811 | 811 | $addon_name, |
812 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
812 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
813 | 813 | ); |
814 | 814 | } |
815 | 815 | } |
@@ -822,17 +822,17 @@ discard block |
||
822 | 822 | */ |
823 | 823 | private static function _register_shortcodes($addon_name) |
824 | 824 | { |
825 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
826 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
825 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
826 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
827 | 827 | ) { |
828 | 828 | EE_Register_Shortcode::register( |
829 | 829 | $addon_name, |
830 | 830 | array( |
831 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
832 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
831 | + 'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths']) |
|
832 | + ? self::$_settings[$addon_name]['shortcode_paths'] |
|
833 | 833 | : array(), |
834 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
835 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
834 | + 'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
835 | + ? self::$_settings[$addon_name]['shortcode_fqcns'] |
|
836 | 836 | : array(), |
837 | 837 | ) |
838 | 838 | ); |
@@ -847,10 +847,10 @@ discard block |
||
847 | 847 | */ |
848 | 848 | private static function _register_widgets($addon_name) |
849 | 849 | { |
850 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
850 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
851 | 851 | EE_Register_Widget::register( |
852 | 852 | $addon_name, |
853 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
853 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
854 | 854 | ); |
855 | 855 | } |
856 | 856 | } |
@@ -863,12 +863,12 @@ discard block |
||
863 | 863 | */ |
864 | 864 | private static function _register_capabilities($addon_name) |
865 | 865 | { |
866 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
866 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
867 | 867 | EE_Register_Capabilities::register( |
868 | 868 | $addon_name, |
869 | 869 | array( |
870 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
871 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
870 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
871 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
872 | 872 | ) |
873 | 873 | ); |
874 | 874 | } |
@@ -882,7 +882,7 @@ discard block |
||
882 | 882 | */ |
883 | 883 | private static function _register_message_types($addon_name) |
884 | 884 | { |
885 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
885 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
886 | 886 | add_action( |
887 | 887 | 'EE_Brewing_Regular___messages_caf', |
888 | 888 | array('EE_Register_Addon', 'register_message_types') |
@@ -899,15 +899,15 @@ discard block |
||
899 | 899 | private static function _register_custom_post_types($addon_name) |
900 | 900 | { |
901 | 901 | if ( |
902 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
903 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
902 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
903 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
904 | 904 | ) { |
905 | 905 | EE_Register_CPT::register( |
906 | 906 | $addon_name, |
907 | 907 | array( |
908 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
909 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
910 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
908 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
909 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
910 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
911 | 911 | ) |
912 | 912 | ); |
913 | 913 | } |
@@ -925,10 +925,10 @@ discard block |
||
925 | 925 | */ |
926 | 926 | private static function _register_payment_methods($addon_name) |
927 | 927 | { |
928 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
928 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
929 | 929 | EE_Register_Payment_Method::register( |
930 | 930 | $addon_name, |
931 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
931 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
932 | 932 | ); |
933 | 933 | } |
934 | 934 | } |
@@ -949,49 +949,49 @@ discard block |
||
949 | 949 | { |
950 | 950 | $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
951 | 951 | $addon = $loader->getShared( |
952 | - self::$_settings[ $addon_name ]['class_name'], |
|
952 | + self::$_settings[$addon_name]['class_name'], |
|
953 | 953 | array('EE_Registry::create(addon)' => true) |
954 | 954 | ); |
955 | 955 | // setter inject dep map if required |
956 | - if($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null){ |
|
956 | + if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) { |
|
957 | 957 | $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
958 | 958 | } |
959 | 959 | // setter inject domain if required |
960 | - if( |
|
960 | + if ( |
|
961 | 961 | $addon instanceof RequiresDomainInterface |
962 | - && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
962 | + && self::$_settings[$addon_name]['domain_fqcn'] !== '' |
|
963 | 963 | && $addon->domain() === null |
964 | - ){ |
|
964 | + ) { |
|
965 | 965 | $addon->setDomain( |
966 | 966 | $loader->getShared( |
967 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
967 | + self::$_settings[$addon_name]['domain_fqcn'], |
|
968 | 968 | array( |
969 | - self::$_settings[ $addon_name ]['main_file_path'], |
|
970 | - self::$_settings[ $addon_name ]['version'] |
|
969 | + self::$_settings[$addon_name]['main_file_path'], |
|
970 | + self::$_settings[$addon_name]['version'] |
|
971 | 971 | ) |
972 | 972 | ) |
973 | 973 | ); |
974 | 974 | } |
975 | 975 | |
976 | 976 | $addon->set_name($addon_name); |
977 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
978 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
979 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
980 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
981 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
982 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
983 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
984 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
985 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
986 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
977 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
978 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
979 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
980 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
981 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
982 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
983 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
984 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
985 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
986 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
987 | 987 | //unfortunately this can't be hooked in upon construction, because we don't have |
988 | 988 | //the plugin mainfile's path upon construction. |
989 | 989 | register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
990 | 990 | // call any additional admin_callback functions during load_admin_controller hook |
991 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
991 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
992 | 992 | add_action( |
993 | 993 | 'AHEE__EE_System__load_controllers__load_admin_controllers', |
994 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
994 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
995 | 995 | ); |
996 | 996 | } |
997 | 997 | return $addon; |
@@ -1009,10 +1009,10 @@ discard block |
||
1009 | 1009 | public static function load_pue_update() |
1010 | 1010 | { |
1011 | 1011 | // load PUE client |
1012 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
1012 | + require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php'; |
|
1013 | 1013 | // cycle thru settings |
1014 | 1014 | foreach (self::$_settings as $settings) { |
1015 | - if (! empty($settings['pue_options'])) { |
|
1015 | + if ( ! empty($settings['pue_options'])) { |
|
1016 | 1016 | // initiate the class and start the plugin update engine! |
1017 | 1017 | new PluginUpdateEngineChecker( |
1018 | 1018 | // host file URL |
@@ -1020,7 +1020,7 @@ discard block |
||
1020 | 1020 | // plugin slug(s) |
1021 | 1021 | array( |
1022 | 1022 | 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
1023 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
1023 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'), |
|
1024 | 1024 | ), |
1025 | 1025 | // options |
1026 | 1026 | array( |
@@ -1049,7 +1049,7 @@ discard block |
||
1049 | 1049 | public static function register_message_types() |
1050 | 1050 | { |
1051 | 1051 | foreach (self::$_settings as $addon_name => $settings) { |
1052 | - if (! empty($settings['message_types'])) { |
|
1052 | + if ( ! empty($settings['message_types'])) { |
|
1053 | 1053 | foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
1054 | 1054 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
1055 | 1055 | } |
@@ -1071,51 +1071,51 @@ discard block |
||
1071 | 1071 | */ |
1072 | 1072 | public static function deregister($addon_name = null) |
1073 | 1073 | { |
1074 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1074 | + if (isset(self::$_settings[$addon_name]['class_name'])) { |
|
1075 | 1075 | try { |
1076 | 1076 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
1077 | 1077 | $class_name = self::$_settings[$addon_name]['class_name']; |
1078 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
1078 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
1079 | 1079 | // setup DMS |
1080 | 1080 | EE_Register_Data_Migration_Scripts::deregister($addon_name); |
1081 | 1081 | } |
1082 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
1082 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
1083 | 1083 | // register admin page |
1084 | 1084 | EE_Register_Admin_Page::deregister($addon_name); |
1085 | 1085 | } |
1086 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
1086 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
1087 | 1087 | // add to list of modules to be registered |
1088 | 1088 | EE_Register_Module::deregister($addon_name); |
1089 | 1089 | } |
1090 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
1090 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
1091 | 1091 | || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
1092 | 1092 | ) { |
1093 | 1093 | // add to list of shortcodes to be registered |
1094 | 1094 | EE_Register_Shortcode::deregister($addon_name); |
1095 | 1095 | } |
1096 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
1096 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
1097 | 1097 | // if config_class present let's register config. |
1098 | 1098 | EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
1099 | 1099 | } |
1100 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
1100 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
1101 | 1101 | // add to list of widgets to be registered |
1102 | 1102 | EE_Register_Widget::deregister($addon_name); |
1103 | 1103 | } |
1104 | - if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
1104 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
1105 | 1105 | || ! empty(self::$_settings[$addon_name]['class_paths']) |
1106 | 1106 | ) { |
1107 | 1107 | // add to list of shortcodes to be registered |
1108 | 1108 | EE_Register_Model::deregister($addon_name); |
1109 | 1109 | } |
1110 | - if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
1110 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
1111 | 1111 | || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
1112 | 1112 | ) { |
1113 | 1113 | // add to list of shortcodes to be registered |
1114 | 1114 | EE_Register_Model_Extensions::deregister($addon_name); |
1115 | 1115 | } |
1116 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
1116 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
1117 | 1117 | foreach ( |
1118 | - (array)self::$_settings[$addon_name]['message_types'] as $message_type => |
|
1118 | + (array) self::$_settings[$addon_name]['message_types'] as $message_type => |
|
1119 | 1119 | $message_type_settings |
1120 | 1120 | ) { |
1121 | 1121 | EE_Register_Message_Type::deregister($message_type); |
@@ -1129,16 +1129,16 @@ discard block |
||
1129 | 1129 | EE_Register_Capabilities::deregister($addon_name); |
1130 | 1130 | } |
1131 | 1131 | //deregister custom_post_types for addon |
1132 | - if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
1132 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
1133 | 1133 | EE_Register_CPT::deregister($addon_name); |
1134 | 1134 | } |
1135 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
1135 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
1136 | 1136 | EE_Register_Payment_Method::deregister($addon_name); |
1137 | 1137 | } |
1138 | 1138 | $addon = EE_Registry::instance()->getAddon($class_name); |
1139 | 1139 | if ($addon instanceof EE_Addon) { |
1140 | 1140 | remove_action( |
1141 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1141 | + 'deactivate_'.$addon->get_main_plugin_file_basename(), |
|
1142 | 1142 | array($addon, 'deactivation') |
1143 | 1143 | ); |
1144 | 1144 | remove_action( |
@@ -1159,7 +1159,7 @@ discard block |
||
1159 | 1159 | } catch (Exception $e) { |
1160 | 1160 | new ExceptionLogger($e); |
1161 | 1161 | } |
1162 | - unset(self::$_settings[ $addon_name ]); |
|
1162 | + unset(self::$_settings[$addon_name]); |
|
1163 | 1163 | do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
1164 | 1164 | } |
1165 | 1165 | } |
@@ -45,25 +45,25 @@ discard block |
||
45 | 45 | * @param bool $password_check |
46 | 46 | * @return \EE_Venue|null |
47 | 47 | */ |
48 | - public static function get_venue( $VNU_ID = 0, $look_in_event = TRUE, $privacy_check = true, $password_check = true ) { |
|
49 | - $VNU_ID = absint( $VNU_ID ); |
|
48 | + public static function get_venue($VNU_ID = 0, $look_in_event = TRUE, $privacy_check = true, $password_check = true) { |
|
49 | + $VNU_ID = absint($VNU_ID); |
|
50 | 50 | // do we already have the Venue you are looking for? |
51 | - if ( EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID ) { |
|
51 | + if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
52 | 52 | //If the Venue ID matches $VNU_ID, return the venue. |
53 | - if( EEH_Venue_View::$_venue->ID() === $VNU_ID ) { |
|
54 | - return EEH_Venue_View::_get_venue( $privacy_check ); |
|
53 | + if (EEH_Venue_View::$_venue->ID() === $VNU_ID) { |
|
54 | + return EEH_Venue_View::_get_venue($privacy_check); |
|
55 | 55 | } |
56 | 56 | //If the Venue ID does not match, try pulling a venue using $VNU_ID. |
57 | - $venue = EEM_Venue::instance()->get_one_by_ID( $VNU_ID ); |
|
58 | - if( $venue instanceof EE_Venue ) { |
|
57 | + $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
58 | + if ($venue instanceof EE_Venue) { |
|
59 | 59 | EEH_Venue_View::$_venue = $venue; |
60 | - return EEH_Venue_View::_get_venue( $privacy_check ); |
|
60 | + return EEH_Venue_View::_get_venue($privacy_check); |
|
61 | 61 | } |
62 | 62 | } |
63 | 63 | // international newspaper? |
64 | 64 | global $post; |
65 | - if ( $post instanceof WP_Post ) { |
|
66 | - switch ( $post->post_type ) { |
|
65 | + if ($post instanceof WP_Post) { |
|
66 | + switch ($post->post_type) { |
|
67 | 67 | // if this is being called from an EE_Venue post, |
68 | 68 | // and the EE_Venue post corresponds to the EE_Venue that is being asked for, |
69 | 69 | // then we can try to just grab the attached EE_Venue object |
@@ -71,31 +71,31 @@ discard block |
||
71 | 71 | // the post already contains the related EE_Venue object AND one of the following is TRUE: |
72 | 72 | // the requested Venue ID matches the post ID OR... |
73 | 73 | // there was no specific Venue ID requested |
74 | - if ( isset( $post->EE_Venue ) && ( $VNU_ID == $post->ID || ! $VNU_ID )) { |
|
74 | + if (isset($post->EE_Venue) && ($VNU_ID == $post->ID || ! $VNU_ID)) { |
|
75 | 75 | // use existing related EE_Venue object |
76 | - EEH_Venue_View::$_venue = $post->EE_Venue; |
|
77 | - } else if ( $VNU_ID ) { |
|
76 | + EEH_Venue_View::$_venue = $post->EE_Venue; |
|
77 | + } else if ($VNU_ID) { |
|
78 | 78 | // there WAS a specific Venue ID requested, but it's NOT the current post object |
79 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID( $VNU_ID ); |
|
79 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
80 | 80 | } else { |
81 | 81 | // no specific Venue ID requested, so use post ID to generate EE_Venue object |
82 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID( $post->ID ); |
|
82 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID); |
|
83 | 83 | } |
84 | 84 | break; |
85 | 85 | |
86 | 86 | case 'espresso_events': |
87 | - if ( $look_in_event ) { |
|
87 | + if ($look_in_event) { |
|
88 | 88 | // grab the events related venues |
89 | 89 | $venues = EEH_Venue_View::get_event_venues(); |
90 | 90 | // make sure the result is an array |
91 | - $venues = is_array( $venues ) ? $venues : array(); |
|
91 | + $venues = is_array($venues) ? $venues : array(); |
|
92 | 92 | // do we have an ID for a specific venue? |
93 | - if ( $VNU_ID ) { |
|
93 | + if ($VNU_ID) { |
|
94 | 94 | // loop thru the related venues |
95 | - foreach( $venues as $venue ) { |
|
96 | - if ( $venue instanceof EE_Venue ) { |
|
95 | + foreach ($venues as $venue) { |
|
96 | + if ($venue instanceof EE_Venue) { |
|
97 | 97 | // until we find the venue we're looking for |
98 | - if ( $venue->ID() == $VNU_ID ) { |
|
98 | + if ($venue->ID() == $VNU_ID) { |
|
99 | 99 | EEH_Venue_View::$_venue = $venue; |
100 | 100 | break; |
101 | 101 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | // then the global post is an events post and this function was called with no argument |
106 | 106 | } else { |
107 | 107 | // just grab the first related event venue |
108 | - EEH_Venue_View::$_venue = reset( $venues ); |
|
108 | + EEH_Venue_View::$_venue = reset($venues); |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 | break; |
@@ -113,11 +113,11 @@ discard block |
||
113 | 113 | } |
114 | 114 | } |
115 | 115 | // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID... |
116 | - if ( ! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID ) { |
|
116 | + if ( ! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
117 | 117 | // sigh... pull it from the db |
118 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID( $VNU_ID ); |
|
118 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
119 | 119 | } |
120 | - return EEH_Venue_View::_get_venue( $privacy_check, $password_check ); |
|
120 | + return EEH_Venue_View::_get_venue($privacy_check, $password_check); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | |
@@ -130,13 +130,13 @@ discard block |
||
130 | 130 | * @param bool $password_check |
131 | 131 | * @return EE_Venue |
132 | 132 | */ |
133 | - protected static function _get_venue( $privacy_check = true, $password_check = true ) { |
|
133 | + protected static function _get_venue($privacy_check = true, $password_check = true) { |
|
134 | 134 | // check for private venues. |
135 | 135 | if ( |
136 | 136 | EEH_Venue_View::$_venue instanceof EE_Venue |
137 | 137 | && EEH_Venue_View::$_venue->status() == 'private' |
138 | 138 | && $privacy_check |
139 | - && ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_private_venues', 'get_venues' ) |
|
139 | + && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues') |
|
140 | 140 | ) { |
141 | 141 | return null; |
142 | 142 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | if ( |
145 | 145 | EEH_Venue_View::$_venue instanceof EE_Venue |
146 | 146 | && $password_check |
147 | - && post_password_required( EEH_Venue_View::$_venue->ID() ) |
|
147 | + && post_password_required(EEH_Venue_View::$_venue->ID()) |
|
148 | 148 | ) { |
149 | 149 | return null; |
150 | 150 | } |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public static function get_event_venues() { |
163 | 163 | global $post; |
164 | - if ( $post->post_type == 'espresso_events' ) { |
|
165 | - if ( isset( $post->EE_Event ) && $post->EE_Event instanceof EE_Event ) { |
|
164 | + if ($post->post_type == 'espresso_events') { |
|
165 | + if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) { |
|
166 | 166 | return $post->EE_Event->venues(); |
167 | 167 | } |
168 | 168 | } |
@@ -182,9 +182,9 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @return bool|null |
184 | 184 | */ |
185 | - public static function is_venue_private( $VNU_ID = false ) { |
|
186 | - $venue = EEH_Venue_View::get_venue( $VNU_ID, true, true ); |
|
187 | - if ( ! $venue instanceof EE_Venue ) { |
|
185 | + public static function is_venue_private($VNU_ID = false) { |
|
186 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true); |
|
187 | + if ( ! $venue instanceof EE_Venue) { |
|
188 | 188 | return null; |
189 | 189 | } |
190 | 190 | |
@@ -199,11 +199,11 @@ discard block |
||
199 | 199 | * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
200 | 200 | * @return bool |
201 | 201 | */ |
202 | - public static function is_venue_password_protected( $VNU_ID = false ) { |
|
203 | - $venue = EEH_Venue_View::get_venue( $VNU_ID, true, true, false ); |
|
202 | + public static function is_venue_password_protected($VNU_ID = false) { |
|
203 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
204 | 204 | if ( |
205 | 205 | $venue instanceof EE_Venue |
206 | - && post_password_required( $venue->ID() ) |
|
206 | + && post_password_required($venue->ID()) |
|
207 | 207 | ) { |
208 | 208 | return true; |
209 | 209 | } |
@@ -220,13 +220,13 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @return string |
222 | 222 | */ |
223 | - public static function password_protected_venue_form( $VNU_ID = false ) { |
|
224 | - $venue = EEH_Venue_View::get_venue( $VNU_ID, true, true, false ); |
|
223 | + public static function password_protected_venue_form($VNU_ID = false) { |
|
224 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
225 | 225 | if ( |
226 | 226 | $venue instanceof EE_Venue |
227 | - && post_password_required( $venue->ID() ) |
|
227 | + && post_password_required($venue->ID()) |
|
228 | 228 | ) { |
229 | - return get_the_password_form( $venue->ID() ); |
|
229 | + return get_the_password_form($venue->ID()); |
|
230 | 230 | } |
231 | 231 | return ''; |
232 | 232 | } |
@@ -240,9 +240,9 @@ discard block |
||
240 | 240 | * @param int $VNU_ID |
241 | 241 | * @return string |
242 | 242 | */ |
243 | - public static function venue_description( $VNU_ID = 0 ) { |
|
244 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
245 | - if ( $venue instanceof EE_Venue ) { |
|
243 | + public static function venue_description($VNU_ID = 0) { |
|
244 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
245 | + if ($venue instanceof EE_Venue) { |
|
246 | 246 | return$venue->description(); |
247 | 247 | } |
248 | 248 | return ''; |
@@ -257,12 +257,12 @@ discard block |
||
257 | 257 | * @param int $VNU_ID |
258 | 258 | * @return string |
259 | 259 | */ |
260 | - public static function venue_excerpt( $VNU_ID = 0 ) { |
|
261 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
262 | - if ( $venue instanceof EE_Venue ) { |
|
260 | + public static function venue_excerpt($VNU_ID = 0) { |
|
261 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
262 | + if ($venue instanceof EE_Venue) { |
|
263 | 263 | $excerpt = $venue->excerpt() != NULL && $venue->excerpt() ? $venue->excerpt() : $venue->description(); |
264 | - $venue_link = ' ' . EEH_Venue_View::venue_details_link( $venue->ID(), __( 'more', 'event_espresso' ) . '…' ); |
|
265 | - return ! empty( $excerpt ) ? wp_trim_words( $excerpt, 25, '' ) . $venue_link : ''; |
|
264 | + $venue_link = ' '.EEH_Venue_View::venue_details_link($venue->ID(), __('more', 'event_espresso').'…'); |
|
265 | + return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '').$venue_link : ''; |
|
266 | 266 | } |
267 | 267 | return ''; |
268 | 268 | } |
@@ -277,22 +277,22 @@ discard block |
||
277 | 277 | * @param bool $hide_uncategorized |
278 | 278 | * @return string |
279 | 279 | */ |
280 | - public static function venue_categories( $VNU_ID = 0, $hide_uncategorized = TRUE ) { |
|
280 | + public static function venue_categories($VNU_ID = 0, $hide_uncategorized = TRUE) { |
|
281 | 281 | $category_links = array(); |
282 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
283 | - if ( $venue instanceof EE_Venue ) { |
|
282 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
283 | + if ($venue instanceof EE_Venue) { |
|
284 | 284 | // get category terms |
285 | - if ( $venue_categories = get_the_terms( $venue->ID(), 'espresso_venue_categories' )) { |
|
285 | + if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) { |
|
286 | 286 | // loop thru terms and create links |
287 | - foreach ( $venue_categories as $term ) { |
|
288 | - $url = get_term_link( $term, 'espresso_venue_categories' ); |
|
289 | - if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) { |
|
290 | - $category_links[] = '<a href="' . esc_url( $url ) . '" rel="tag">' . $term->name . '</a> '; |
|
287 | + foreach ($venue_categories as $term) { |
|
288 | + $url = get_term_link($term, 'espresso_venue_categories'); |
|
289 | + if ( ! is_wp_error($url) && (($hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized)) { |
|
290 | + $category_links[] = '<a href="'.esc_url($url).'" rel="tag">'.$term->name.'</a> '; |
|
291 | 291 | } |
292 | 292 | } |
293 | 293 | } |
294 | 294 | } |
295 | - return implode( ', ', $category_links ); |
|
295 | + return implode(', ', $category_links); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | |
@@ -307,10 +307,10 @@ discard block |
||
307 | 307 | * @param bool $add_wrapper |
308 | 308 | * @return string |
309 | 309 | */ |
310 | - public static function venue_address( $type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true ) { |
|
311 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
312 | - if ( $venue instanceof EE_Venue ) { |
|
313 | - return EEH_Address::format( $venue, $type, $use_schema, $add_wrapper ); |
|
310 | + public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true) { |
|
311 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
312 | + if ($venue instanceof EE_Venue) { |
|
313 | + return EEH_Address::format($venue, $type, $use_schema, $add_wrapper); |
|
314 | 314 | } |
315 | 315 | return ''; |
316 | 316 | } |
@@ -324,10 +324,10 @@ discard block |
||
324 | 324 | * @param int $VNU_ID |
325 | 325 | * @return bool|string |
326 | 326 | */ |
327 | - public static function venue_has_address( $VNU_ID = 0 ) { |
|
328 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
329 | - if ( $venue instanceof EE_Venue ) { |
|
330 | - return EEH_Address::format( $venue, 'inline', FALSE, FALSE ); |
|
327 | + public static function venue_has_address($VNU_ID = 0) { |
|
328 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
329 | + if ($venue instanceof EE_Venue) { |
|
330 | + return EEH_Address::format($venue, 'inline', FALSE, FALSE); |
|
331 | 331 | } |
332 | 332 | return false; |
333 | 333 | } |
@@ -342,30 +342,30 @@ discard block |
||
342 | 342 | * @param int $VNU_ID |
343 | 343 | * @return string |
344 | 344 | */ |
345 | - public static function venue_name( $link_to = 'details', $VNU_ID = 0 ) { |
|
346 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
347 | - if ( $venue instanceof EE_Venue ) { |
|
345 | + public static function venue_name($link_to = 'details', $VNU_ID = 0) { |
|
346 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
347 | + if ($venue instanceof EE_Venue) { |
|
348 | 348 | $venue_name = apply_filters( |
349 | 349 | 'FHEE__EEH_Venue__venue_name__append_private_venue_name', |
350 | 350 | EEH_Venue_View::is_venue_private() |
351 | - ? EEH_Venue_View::$_venue->name() . " " . __( '(Private)', 'event_espresso' ) |
|
351 | + ? EEH_Venue_View::$_venue->name()." ".__('(Private)', 'event_espresso') |
|
352 | 352 | : EEH_Venue_View::$_venue->name(), |
353 | 353 | EEH_Venue_View::$_venue |
354 | 354 | ); |
355 | - $venue_name = EEH_Schema::name( $venue_name ); |
|
355 | + $venue_name = EEH_Schema::name($venue_name); |
|
356 | 356 | |
357 | 357 | //if venue is trashed then ignore the "link to" setting because the venue is trashed. |
358 | - if ( $venue->get('status') == 'trash' ) { |
|
358 | + if ($venue->get('status') == 'trash') { |
|
359 | 359 | $link_to = ''; |
360 | 360 | } |
361 | - switch( $link_to ) { |
|
361 | + switch ($link_to) { |
|
362 | 362 | |
363 | 363 | case 'details' : |
364 | - return EEH_Venue_View::venue_details_link( $venue->ID(), $venue_name ); |
|
364 | + return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name); |
|
365 | 365 | break; |
366 | 366 | |
367 | 367 | case 'website' : |
368 | - return EEH_Venue_View::venue_website_link( $venue->ID(), $venue_name ); |
|
368 | + return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name); |
|
369 | 369 | break; |
370 | 370 | |
371 | 371 | default : |
@@ -385,10 +385,10 @@ discard block |
||
385 | 385 | * @param string $text |
386 | 386 | * @return string |
387 | 387 | */ |
388 | - public static function venue_details_link( $VNU_ID = 0, $text = '' ) { |
|
389 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
390 | - if ( $venue instanceof EE_Venue ) { |
|
391 | - return EEH_Schema::url( get_permalink( $venue->ID() ), $text ); |
|
388 | + public static function venue_details_link($VNU_ID = 0, $text = '') { |
|
389 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
390 | + if ($venue instanceof EE_Venue) { |
|
391 | + return EEH_Schema::url(get_permalink($venue->ID()), $text); |
|
392 | 392 | } |
393 | 393 | return ''; |
394 | 394 | } |
@@ -403,12 +403,12 @@ discard block |
||
403 | 403 | * @param string $text |
404 | 404 | * @return string |
405 | 405 | */ |
406 | - public static function venue_website_link( $VNU_ID = 0, $text = '' ) { |
|
407 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
408 | - if ( $venue instanceof EE_Venue ) { |
|
406 | + public static function venue_website_link($VNU_ID = 0, $text = '') { |
|
407 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
408 | + if ($venue instanceof EE_Venue) { |
|
409 | 409 | $url = $venue->venue_url(); |
410 | - $text = ! empty( $text ) ? $text : $url; |
|
411 | - return ! empty( $url ) ? EEH_Schema::url( $url, $text ) : ''; |
|
410 | + $text = ! empty($text) ? $text : $url; |
|
411 | + return ! empty($url) ? EEH_Schema::url($url, $text) : ''; |
|
412 | 412 | } |
413 | 413 | return ''; |
414 | 414 | } |
@@ -422,10 +422,10 @@ discard block |
||
422 | 422 | * @param int $VNU_ID |
423 | 423 | * @return string |
424 | 424 | */ |
425 | - public static function venue_phone( $VNU_ID = 0) { |
|
426 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
427 | - if ( $venue instanceof EE_Venue ) { |
|
428 | - return EEH_Schema::telephone( $venue->phone() ); |
|
425 | + public static function venue_phone($VNU_ID = 0) { |
|
426 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
427 | + if ($venue instanceof EE_Venue) { |
|
428 | + return EEH_Schema::telephone($venue->phone()); |
|
429 | 429 | } |
430 | 430 | return ''; |
431 | 431 | } |
@@ -441,48 +441,48 @@ discard block |
||
441 | 441 | * @param array $gmap map options |
442 | 442 | * @return string |
443 | 443 | */ |
444 | - public static function venue_gmap( $VNU_ID = 0, $map_ID = FALSE, $gmap = array() ) { |
|
444 | + public static function venue_gmap($VNU_ID = 0, $map_ID = FALSE, $gmap = array()) { |
|
445 | 445 | |
446 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
447 | - if ( $venue instanceof EE_Venue ) { |
|
446 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
447 | + if ($venue instanceof EE_Venue) { |
|
448 | 448 | // check for global espresso_events post and use it's ID if no map_ID is set |
449 | 449 | global $post; |
450 | - $map_ID = empty( $map_ID ) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID; |
|
450 | + $map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID; |
|
451 | 451 | // grab map settings |
452 | 452 | $map_cfg = EE_Registry::instance()->CFG->map_settings; |
453 | 453 | // are maps enabled ? |
454 | - if ( $map_cfg->use_google_maps && $venue->enable_for_gmap() ) { |
|
454 | + if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) { |
|
455 | 455 | |
456 | 456 | $details_page = is_single(); |
457 | 457 | $options = array(); |
458 | - $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID . '-' . $venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/; |
|
458 | + $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID.'-'.$venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/; |
|
459 | 459 | |
460 | - $options['location'] = EEH_Address::format( $venue, 'inline', FALSE, FALSE ); |
|
460 | + $options['location'] = EEH_Address::format($venue, 'inline', FALSE, FALSE); |
|
461 | 461 | |
462 | 462 | $options['ee_map_width'] = $details_page ? $map_cfg->event_details_map_width : $map_cfg->event_list_map_width; |
463 | - $options['ee_map_width'] = isset( $gmap['ee_map_width'] ) && ! empty( $gmap['ee_map_width'] ) ? $gmap['ee_map_width'] : $options['ee_map_width']; |
|
463 | + $options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width']) ? $gmap['ee_map_width'] : $options['ee_map_width']; |
|
464 | 464 | |
465 | 465 | $options['ee_map_height'] = $details_page ? $map_cfg->event_details_map_height : $map_cfg->event_list_map_height; |
466 | - $options['ee_map_height'] = isset( $gmap['ee_map_height'] ) && ! empty( $gmap['ee_map_height'] ) ? $gmap['ee_map_height'] : $options['ee_map_height']; |
|
466 | + $options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height']) ? $gmap['ee_map_height'] : $options['ee_map_height']; |
|
467 | 467 | |
468 | 468 | $options['ee_map_zoom'] = $details_page ? $map_cfg->event_details_map_zoom : $map_cfg->event_list_map_zoom; |
469 | - $options['ee_map_zoom'] = isset( $gmap['ee_map_zoom'] ) && ! empty( $gmap['ee_map_zoom'] ) ? $gmap['ee_map_zoom'] : $options['ee_map_zoom']; |
|
469 | + $options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom']) ? $gmap['ee_map_zoom'] : $options['ee_map_zoom']; |
|
470 | 470 | |
471 | 471 | $options['ee_map_nav_display'] = $details_page ? $map_cfg->event_details_display_nav : $map_cfg->event_list_display_nav; |
472 | - $options['ee_map_nav_display'] = isset( $gmap['ee_map_nav_display'] ) && ! empty( $gmap['ee_map_nav_display'] ) ? 'true' : $options['ee_map_nav_display'];; |
|
472 | + $options['ee_map_nav_display'] = isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display']) ? 'true' : $options['ee_map_nav_display']; ; |
|
473 | 473 | |
474 | 474 | $options['ee_map_nav_size'] = $details_page ? $map_cfg->event_details_nav_size : $map_cfg->event_list_nav_size; |
475 | - $options['ee_map_nav_size'] = isset( $gmap['ee_map_nav_size'] ) && ! empty( $gmap['ee_map_nav_size'] )? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size']; |
|
475 | + $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size']) ? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size']; |
|
476 | 476 | |
477 | 477 | $options['ee_map_type_control'] = $details_page ? $map_cfg->event_details_control_type : $map_cfg->event_list_control_type; |
478 | - $options['ee_map_type_control'] = isset( $gmap['ee_map_type_control'] ) && ! empty( $gmap['ee_map_type_control'] )? $gmap['ee_map_type_control'] : $options['ee_map_type_control']; |
|
478 | + $options['ee_map_type_control'] = isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control']) ? $gmap['ee_map_type_control'] : $options['ee_map_type_control']; |
|
479 | 479 | |
480 | 480 | $options['ee_map_align'] = $details_page ? $map_cfg->event_details_map_align : $map_cfg->event_list_map_align; |
481 | - $options['ee_map_align'] = isset( $gmap['ee_map_align'] ) && ! empty( $gmap['ee_map_align'] )? $gmap['ee_map_align'] : $options['ee_map_align']; |
|
481 | + $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align']) ? $gmap['ee_map_align'] : $options['ee_map_align']; |
|
482 | 482 | |
483 | - $options['ee_static_url'] = isset( $gmap['ee_static_url'] ) && ! empty( $gmap['ee_static_url'] ) ? (bool)absint( $gmap['ee_static_url'] ) : $venue->google_map_link(); |
|
483 | + $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) ? (bool) absint($gmap['ee_static_url']) : $venue->google_map_link(); |
|
484 | 484 | |
485 | - return EEH_Maps::google_map( $options ); |
|
485 | + return EEH_Maps::google_map($options); |
|
486 | 486 | |
487 | 487 | } |
488 | 488 | } |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | * @param array $atts like EEH_Maps::google_map_link |
498 | 498 | * @return string |
499 | 499 | */ |
500 | - public static function espresso_google_static_map( EE_Venue $venue, $atts = array() ){ |
|
500 | + public static function espresso_google_static_map(EE_Venue $venue, $atts = array()) { |
|
501 | 501 | $state = $venue->state_obj(); |
502 | 502 | $country = $venue->country_obj(); |
503 | 503 | $atts = shortcode_atts( |
@@ -528,23 +528,23 @@ discard block |
||
528 | 528 | * @param string $after |
529 | 529 | * @return string |
530 | 530 | */ |
531 | - public static function edit_venue_link( $VNU_ID = 0, $link = '', $before = '<p class="edit-venue-lnk small-txt">', $after = '</p>' ) { |
|
532 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
533 | - if ( $venue instanceof EE_Venue ) { |
|
531 | + public static function edit_venue_link($VNU_ID = 0, $link = '', $before = '<p class="edit-venue-lnk small-txt">', $after = '</p>') { |
|
532 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
533 | + if ($venue instanceof EE_Venue) { |
|
534 | 534 | // can the user edit this post ? |
535 | - if ( current_user_can( 'edit_post', $venue->ID() )) { |
|
535 | + if (current_user_can('edit_post', $venue->ID())) { |
|
536 | 536 | // set link text |
537 | - $link = ! empty( $link ) ? $link : __('edit this venue'); |
|
537 | + $link = ! empty($link) ? $link : __('edit this venue'); |
|
538 | 538 | // generate nonce |
539 | - $nonce = wp_create_nonce( 'edit_nonce' ); |
|
539 | + $nonce = wp_create_nonce('edit_nonce'); |
|
540 | 540 | // generate url to venue editor for this venue |
541 | - $url = add_query_arg( array( 'page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce ), admin_url( 'admin.php' ) ); |
|
541 | + $url = add_query_arg(array('page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce), admin_url('admin.php')); |
|
542 | 542 | // get edit CPT text |
543 | - $post_type_obj = get_post_type_object( 'espresso_venues' ); |
|
543 | + $post_type_obj = get_post_type_object('espresso_venues'); |
|
544 | 544 | // build final link html |
545 | - $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( $post_type_obj->labels->edit_item ) . '">' . $link . '</a>'; |
|
545 | + $link = '<a class="post-edit-link" href="'.$url.'" title="'.esc_attr($post_type_obj->labels->edit_item).'">'.$link.'</a>'; |
|
546 | 546 | // put it all together |
547 | - return $before . apply_filters( 'edit_post_link', $link, $venue->ID() ) . $after; |
|
547 | + return $before.apply_filters('edit_post_link', $link, $venue->ID()).$after; |
|
548 | 548 | } |
549 | 549 | } |
550 | 550 | return ''; |
@@ -425,7 +425,7 @@ |
||
425 | 425 | * with construction finalize being called later |
426 | 426 | * (realizing that the subsections' html names |
427 | 427 | * might not be set yet, etc.) |
428 | - * @return EE_Form_Section_Base |
|
428 | + * @return EE_Form_Section_Validatable|null |
|
429 | 429 | * @throws EE_Error |
430 | 430 | */ |
431 | 431 | public function get_subsection($name, $require_construction_to_be_finalized = true) |
@@ -14,1421 +14,1421 @@ |
||
14 | 14 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable |
15 | 15 | { |
16 | 16 | |
17 | - const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
18 | - |
|
19 | - /** |
|
20 | - * Subsections |
|
21 | - * |
|
22 | - * @var EE_Form_Section_Validatable[] |
|
23 | - */ |
|
24 | - protected $_subsections = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * Strategy for laying out the form |
|
28 | - * |
|
29 | - * @var EE_Form_Section_Layout_Base |
|
30 | - */ |
|
31 | - protected $_layout_strategy; |
|
32 | - |
|
33 | - /** |
|
34 | - * Whether or not this form has received and validated a form submission yet |
|
35 | - * |
|
36 | - * @var boolean |
|
37 | - */ |
|
38 | - protected $_received_submission = false; |
|
39 | - |
|
40 | - /** |
|
41 | - * message displayed to users upon successful form submission |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - protected $_form_submission_success_message = ''; |
|
46 | - |
|
47 | - /** |
|
48 | - * message displayed to users upon unsuccessful form submission |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - protected $_form_submission_error_message = ''; |
|
53 | - |
|
54 | - /** |
|
55 | - * Stores all the data that will localized for form validation |
|
56 | - * |
|
57 | - * @var array |
|
58 | - */ |
|
59 | - static protected $_js_localization = array(); |
|
60 | - |
|
61 | - /** |
|
62 | - * whether or not the form's localized validation JS vars have been set |
|
63 | - * |
|
64 | - * @type boolean |
|
65 | - */ |
|
66 | - static protected $_scripts_localized = false; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * when constructing a proper form section, calls _construct_finalize on children |
|
71 | - * so that they know who their parent is, and what name they've been given. |
|
72 | - * |
|
73 | - * @param array[] $options_array { |
|
74 | - * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
75 | - * @type $include string[] numerically-indexed where values are section names to be included, |
|
76 | - * and in that order. This is handy if you want |
|
77 | - * the subsections to be ordered differently than the default, and if you override |
|
78 | - * which fields are shown |
|
79 | - * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
80 | - * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
81 | - * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
82 | - * items from that list of inclusions) |
|
83 | - * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
84 | - * } @see EE_Form_Section_Validatable::__construct() |
|
85 | - * @throws EE_Error |
|
86 | - */ |
|
87 | - public function __construct($options_array = array()) |
|
88 | - { |
|
89 | - $options_array = (array) apply_filters( |
|
90 | - 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
91 | - $options_array, |
|
92 | - $this |
|
93 | - ); |
|
94 | - //call parent first, as it may be setting the name |
|
95 | - parent::__construct($options_array); |
|
96 | - //if they've included subsections in the constructor, add them now |
|
97 | - if (isset($options_array['include'])) { |
|
98 | - //we are going to make sure we ONLY have those subsections to include |
|
99 | - //AND we are going to make sure they're in that specified order |
|
100 | - $reordered_subsections = array(); |
|
101 | - foreach ($options_array['include'] as $input_name) { |
|
102 | - if (isset($this->_subsections[ $input_name ])) { |
|
103 | - $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
104 | - } |
|
105 | - } |
|
106 | - $this->_subsections = $reordered_subsections; |
|
107 | - } |
|
108 | - if (isset($options_array['exclude'])) { |
|
109 | - $exclude = $options_array['exclude']; |
|
110 | - $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
111 | - } |
|
112 | - if (isset($options_array['layout_strategy'])) { |
|
113 | - $this->_layout_strategy = $options_array['layout_strategy']; |
|
114 | - } |
|
115 | - if (! $this->_layout_strategy) { |
|
116 | - $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
117 | - } |
|
118 | - $this->_layout_strategy->_construct_finalize($this); |
|
119 | - //ok so we are definitely going to want the forms JS, |
|
120 | - //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
121 | - if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
122 | - //ok so they've constructed this object after when they should have. |
|
123 | - //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
124 | - EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
125 | - } else { |
|
126 | - add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
127 | - add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
128 | - } |
|
129 | - add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
130 | - /** |
|
131 | - * Gives other plugins a chance to hook in before construct finalize is called. |
|
132 | - * The form probably doesn't yet have a parent form section. |
|
133 | - * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
134 | - * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
135 | - * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
136 | - * |
|
137 | - * @since 4.9.32 |
|
138 | - * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
139 | - * except maybe calling _construct_finalize has been done |
|
140 | - * @param array $options_array options passed into the constructor |
|
141 | - */ |
|
142 | - do_action( |
|
143 | - 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
144 | - $this, |
|
145 | - $options_array |
|
146 | - ); |
|
147 | - if (isset($options_array['name'])) { |
|
148 | - $this->_construct_finalize(null, $options_array['name']); |
|
149 | - } |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * Finishes construction given the parent form section and this form section's name |
|
155 | - * |
|
156 | - * @param EE_Form_Section_Proper $parent_form_section |
|
157 | - * @param string $name |
|
158 | - * @throws EE_Error |
|
159 | - */ |
|
160 | - public function _construct_finalize($parent_form_section, $name) |
|
161 | - { |
|
162 | - parent::_construct_finalize($parent_form_section, $name); |
|
163 | - $this->_set_default_name_if_empty(); |
|
164 | - $this->_set_default_html_id_if_empty(); |
|
165 | - foreach ($this->_subsections as $subsection_name => $subsection) { |
|
166 | - if ($subsection instanceof EE_Form_Section_Base) { |
|
167 | - $subsection->_construct_finalize($this, $subsection_name); |
|
168 | - } else { |
|
169 | - throw new EE_Error( |
|
170 | - sprintf( |
|
171 | - esc_html__( |
|
172 | - 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
173 | - 'event_espresso' |
|
174 | - ), |
|
175 | - $subsection_name, |
|
176 | - get_class($this), |
|
177 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
178 | - ) |
|
179 | - ); |
|
180 | - } |
|
181 | - } |
|
182 | - /** |
|
183 | - * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
184 | - * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
185 | - * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
186 | - * This might only happen just before displaying the form, or just before it receives form submission data. |
|
187 | - * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
188 | - * ensured it has a name, HTML IDs, etc |
|
189 | - * |
|
190 | - * @param EE_Form_Section_Proper $this |
|
191 | - * @param EE_Form_Section_Proper|null $parent_form_section |
|
192 | - * @param string $name |
|
193 | - */ |
|
194 | - do_action( |
|
195 | - 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
196 | - $this, |
|
197 | - $parent_form_section, |
|
198 | - $name |
|
199 | - ); |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * Gets the layout strategy for this form section |
|
205 | - * |
|
206 | - * @return EE_Form_Section_Layout_Base |
|
207 | - */ |
|
208 | - public function get_layout_strategy() |
|
209 | - { |
|
210 | - return $this->_layout_strategy; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * Gets the HTML for a single input for this form section according |
|
216 | - * to the layout strategy |
|
217 | - * |
|
218 | - * @param EE_Form_Input_Base $input |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - public function get_html_for_input($input) |
|
222 | - { |
|
223 | - return $this->_layout_strategy->layout_input($input); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * was_submitted - checks if form inputs are present in request data |
|
229 | - * Basically an alias for form_data_present_in() (which is used by both |
|
230 | - * proper form sections and form inputs) |
|
231 | - * |
|
232 | - * @param null $form_data |
|
233 | - * @return boolean |
|
234 | - * @throws EE_Error |
|
235 | - */ |
|
236 | - public function was_submitted($form_data = null) |
|
237 | - { |
|
238 | - return $this->form_data_present_in($form_data); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
244 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
245 | - * |
|
246 | - * @param array|null $req_data should usually be $_POST (the default). |
|
247 | - * However, you CAN supply a different array. |
|
248 | - * Consider using set_defaults() instead however. |
|
249 | - * (If you rendered the form in the page using echo $form_x->get_html() |
|
250 | - * the inputs will have the correct name in the request data for this function |
|
251 | - * to find them and populate the form with them. |
|
252 | - * If you have a flat form (with only input subsections), |
|
253 | - * you can supply a flat array where keys |
|
254 | - * are the form input names and values are their values) |
|
255 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
256 | - * of course, to validate that data, and set errors on the invalid values. |
|
257 | - * But if the data has already been validated |
|
258 | - * (eg you validated the data then stored it in the DB) |
|
259 | - * you may want to skip this step. |
|
260 | - * @throws InvalidArgumentException |
|
261 | - * @throws InvalidInterfaceException |
|
262 | - * @throws InvalidDataTypeException |
|
263 | - * @throws EE_Error |
|
264 | - */ |
|
265 | - public function receive_form_submission($req_data = null, $validate = true) |
|
266 | - { |
|
267 | - $req_data = apply_filters( |
|
268 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
269 | - $req_data, |
|
270 | - $this, |
|
271 | - $validate |
|
272 | - ); |
|
273 | - if ($req_data === null) { |
|
274 | - $req_data = array_merge($_GET, $_POST); |
|
275 | - } |
|
276 | - $req_data = apply_filters( |
|
277 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
278 | - $req_data, |
|
279 | - $this |
|
280 | - ); |
|
281 | - $this->_normalize($req_data); |
|
282 | - if ($validate) { |
|
283 | - $this->_validate(); |
|
284 | - //if it's invalid, we're going to want to re-display so remember what they submitted |
|
285 | - if (! $this->is_valid()) { |
|
286 | - $this->store_submitted_form_data_in_session(); |
|
287 | - } |
|
288 | - } |
|
289 | - do_action( |
|
290 | - 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
291 | - $req_data, |
|
292 | - $this, |
|
293 | - $validate |
|
294 | - ); |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * caches the originally submitted input values in the session |
|
300 | - * so that they can be used to repopulate the form if it failed validation |
|
301 | - * |
|
302 | - * @return boolean whether or not the data was successfully stored in the session |
|
303 | - * @throws InvalidArgumentException |
|
304 | - * @throws InvalidInterfaceException |
|
305 | - * @throws InvalidDataTypeException |
|
306 | - * @throws EE_Error |
|
307 | - */ |
|
308 | - protected function store_submitted_form_data_in_session() |
|
309 | - { |
|
310 | - return EE_Registry::instance()->SSN->set_session_data( |
|
311 | - array( |
|
312 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
313 | - ) |
|
314 | - ); |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * retrieves the originally submitted input values in the session |
|
320 | - * so that they can be used to repopulate the form if it failed validation |
|
321 | - * |
|
322 | - * @return array |
|
323 | - * @throws InvalidArgumentException |
|
324 | - * @throws InvalidInterfaceException |
|
325 | - * @throws InvalidDataTypeException |
|
326 | - */ |
|
327 | - protected function get_submitted_form_data_from_session() |
|
328 | - { |
|
329 | - $session = EE_Registry::instance()->SSN; |
|
330 | - if ($session instanceof EE_Session) { |
|
331 | - return $session->get_session_data( |
|
332 | - EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
333 | - ); |
|
334 | - } |
|
335 | - return array(); |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * flushed the originally submitted input values from the session |
|
341 | - * |
|
342 | - * @return boolean whether or not the data was successfully removed from the session |
|
343 | - * @throws InvalidArgumentException |
|
344 | - * @throws InvalidInterfaceException |
|
345 | - * @throws InvalidDataTypeException |
|
346 | - */ |
|
347 | - protected function flush_submitted_form_data_from_session() |
|
348 | - { |
|
349 | - return EE_Registry::instance()->SSN->reset_data( |
|
350 | - array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
351 | - ); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * Populates this form and its subsections with data from the session. |
|
357 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
358 | - * validation errors when displaying too) |
|
359 | - * Returns true if the form was populated from the session, false otherwise |
|
360 | - * |
|
361 | - * @return boolean |
|
362 | - * @throws InvalidArgumentException |
|
363 | - * @throws InvalidInterfaceException |
|
364 | - * @throws InvalidDataTypeException |
|
365 | - * @throws EE_Error |
|
366 | - */ |
|
367 | - public function populate_from_session() |
|
368 | - { |
|
369 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
370 | - if (empty($form_data_in_session)) { |
|
371 | - return false; |
|
372 | - } |
|
373 | - $this->receive_form_submission($form_data_in_session); |
|
374 | - $this->flush_submitted_form_data_from_session(); |
|
375 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
376 | - return true; |
|
377 | - } |
|
378 | - return false; |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * Populates the default data for the form, given an array where keys are |
|
384 | - * the input names, and values are their values (preferably normalized to be their |
|
385 | - * proper PHP types, not all strings... although that should be ok too). |
|
386 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
387 | - * the value being an array formatted in teh same way |
|
388 | - * |
|
389 | - * @param array $default_data |
|
390 | - * @throws EE_Error |
|
391 | - */ |
|
392 | - public function populate_defaults($default_data) |
|
393 | - { |
|
394 | - foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
395 | - if (isset($default_data[ $subsection_name ])) { |
|
396 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
397 | - $subsection->set_default($default_data[ $subsection_name ]); |
|
398 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
399 | - $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
400 | - } |
|
401 | - } |
|
402 | - } |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * returns true if subsection exists |
|
408 | - * |
|
409 | - * @param string $name |
|
410 | - * @return boolean |
|
411 | - */ |
|
412 | - public function subsection_exists($name) |
|
413 | - { |
|
414 | - return isset($this->_subsections[ $name ]) ? true : false; |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - * Gets the subsection specified by its name |
|
420 | - * |
|
421 | - * @param string $name |
|
422 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
423 | - * so that the inputs will be properly configured. |
|
424 | - * However, some client code may be ok |
|
425 | - * with construction finalize being called later |
|
426 | - * (realizing that the subsections' html names |
|
427 | - * might not be set yet, etc.) |
|
428 | - * @return EE_Form_Section_Base |
|
429 | - * @throws EE_Error |
|
430 | - */ |
|
431 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
432 | - { |
|
433 | - if ($require_construction_to_be_finalized) { |
|
434 | - $this->ensure_construct_finalized_called(); |
|
435 | - } |
|
436 | - return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * Gets all the validatable subsections of this form section |
|
442 | - * |
|
443 | - * @return EE_Form_Section_Validatable[] |
|
444 | - * @throws EE_Error |
|
445 | - */ |
|
446 | - public function get_validatable_subsections() |
|
447 | - { |
|
448 | - $validatable_subsections = array(); |
|
449 | - foreach ($this->subsections() as $name => $obj) { |
|
450 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
451 | - $validatable_subsections[ $name ] = $obj; |
|
452 | - } |
|
453 | - } |
|
454 | - return $validatable_subsections; |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
460 | - * throw an EE_Error. |
|
461 | - * |
|
462 | - * @param string $name |
|
463 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
464 | - * leave this as TRUE so that the inputs will be properly |
|
465 | - * configured. However, some client code may be ok with |
|
466 | - * construction finalize being called later |
|
467 | - * (realizing that the subsections' html names might not be |
|
468 | - * set yet, etc.) |
|
469 | - * @return EE_Form_Input_Base |
|
470 | - * @throws EE_Error |
|
471 | - */ |
|
472 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
473 | - { |
|
474 | - $subsection = $this->get_subsection( |
|
475 | - $name, |
|
476 | - $require_construction_to_be_finalized |
|
477 | - ); |
|
478 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
479 | - throw new EE_Error( |
|
480 | - sprintf( |
|
481 | - esc_html__( |
|
482 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
483 | - 'event_espresso' |
|
484 | - ), |
|
485 | - $name, |
|
486 | - get_class($this), |
|
487 | - $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
488 | - ) |
|
489 | - ); |
|
490 | - } |
|
491 | - return $subsection; |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
497 | - * otherwise throws an EE_Error |
|
498 | - * |
|
499 | - * @param string $name |
|
500 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
501 | - * leave this as TRUE so that the inputs will be properly |
|
502 | - * configured. However, some client code may be ok with |
|
503 | - * construction finalize being called later |
|
504 | - * (realizing that the subsections' html names might not be |
|
505 | - * set yet, etc.) |
|
506 | - * @return EE_Form_Section_Proper |
|
507 | - * @throws EE_Error |
|
508 | - */ |
|
509 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
510 | - { |
|
511 | - $subsection = $this->get_subsection( |
|
512 | - $name, |
|
513 | - $require_construction_to_be_finalized |
|
514 | - ); |
|
515 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
516 | - throw new EE_Error( |
|
517 | - sprintf( |
|
518 | - esc_html__( |
|
519 | - "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
520 | - 'event_espresso' |
|
521 | - ), |
|
522 | - $name, |
|
523 | - get_class($this) |
|
524 | - ) |
|
525 | - ); |
|
526 | - } |
|
527 | - return $subsection; |
|
528 | - } |
|
529 | - |
|
530 | - |
|
531 | - /** |
|
532 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
533 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
534 | - * |
|
535 | - * @param string $name |
|
536 | - * @return mixed depending on the input's type and its normalization strategy |
|
537 | - * @throws EE_Error |
|
538 | - */ |
|
539 | - public function get_input_value($name) |
|
540 | - { |
|
541 | - $input = $this->get_input($name); |
|
542 | - return $input->normalized_value(); |
|
543 | - } |
|
544 | - |
|
545 | - |
|
546 | - /** |
|
547 | - * Checks if this form section itself is valid, and then checks its subsections |
|
548 | - * |
|
549 | - * @throws EE_Error |
|
550 | - * @return boolean |
|
551 | - */ |
|
552 | - public function is_valid() |
|
553 | - { |
|
554 | - if (! $this->has_received_submission()) { |
|
555 | - throw new EE_Error( |
|
556 | - sprintf( |
|
557 | - esc_html__( |
|
558 | - 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
559 | - 'event_espresso' |
|
560 | - ) |
|
561 | - ) |
|
562 | - ); |
|
563 | - } |
|
564 | - if (! parent::is_valid()) { |
|
565 | - return false; |
|
566 | - } |
|
567 | - // ok so no general errors to this entire form section. |
|
568 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
569 | - $set_submission_errors = $this->submission_error_message() === ''; |
|
570 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
571 | - if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
572 | - if ($set_submission_errors) { |
|
573 | - $this->set_submission_error_message( |
|
574 | - $subsection->get_validation_error_string() |
|
575 | - ); |
|
576 | - } |
|
577 | - return false; |
|
578 | - } |
|
579 | - } |
|
580 | - return true; |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * gets the default name of this form section if none is specified |
|
586 | - * |
|
587 | - * @return void |
|
588 | - */ |
|
589 | - protected function _set_default_name_if_empty() |
|
590 | - { |
|
591 | - if (! $this->_name) { |
|
592 | - $classname = get_class($this); |
|
593 | - $default_name = str_replace('EE_', '', $classname); |
|
594 | - $this->_name = $default_name; |
|
595 | - } |
|
596 | - } |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * Returns the HTML for the form, except for the form opening and closing tags |
|
601 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
602 | - * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
603 | - * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
604 | - * Not doing_it_wrong because theoretically this CAN be used properly, |
|
605 | - * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
606 | - * any CSS. |
|
607 | - * |
|
608 | - * @throws InvalidArgumentException |
|
609 | - * @throws InvalidInterfaceException |
|
610 | - * @throws InvalidDataTypeException |
|
611 | - * @throws EE_Error |
|
612 | - */ |
|
613 | - public function get_html_and_js() |
|
614 | - { |
|
615 | - $this->enqueue_js(); |
|
616 | - return $this->get_html(); |
|
617 | - } |
|
618 | - |
|
619 | - |
|
620 | - /** |
|
621 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
622 | - * |
|
623 | - * @param bool $display_previously_submitted_data |
|
624 | - * @return string |
|
625 | - * @throws InvalidArgumentException |
|
626 | - * @throws InvalidInterfaceException |
|
627 | - * @throws InvalidDataTypeException |
|
628 | - * @throws EE_Error |
|
629 | - * @throws EE_Error |
|
630 | - * @throws EE_Error |
|
631 | - */ |
|
632 | - public function get_html($display_previously_submitted_data = true) |
|
633 | - { |
|
634 | - $this->ensure_construct_finalized_called(); |
|
635 | - if ($display_previously_submitted_data) { |
|
636 | - $this->populate_from_session(); |
|
637 | - } |
|
638 | - return $this->_form_html_filter |
|
639 | - ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
640 | - : $this->_layout_strategy->layout_form(); |
|
641 | - } |
|
642 | - |
|
643 | - |
|
644 | - /** |
|
645 | - * enqueues JS and CSS for the form. |
|
646 | - * It is preferred to call this before wp_enqueue_scripts so the |
|
647 | - * scripts and styles can be put in the header, but if called later |
|
648 | - * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
649 | - * only be in the header; but in HTML5 its ok in the body. |
|
650 | - * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
651 | - * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
652 | - * |
|
653 | - * @return void |
|
654 | - * @throws EE_Error |
|
655 | - */ |
|
656 | - public function enqueue_js() |
|
657 | - { |
|
658 | - $this->_enqueue_and_localize_form_js(); |
|
659 | - foreach ($this->subsections() as $subsection) { |
|
660 | - $subsection->enqueue_js(); |
|
661 | - } |
|
662 | - } |
|
663 | - |
|
664 | - |
|
665 | - /** |
|
666 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
667 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
668 | - * the wp_enqueue_scripts hook. |
|
669 | - * However, registering the form js and localizing it can happen when we |
|
670 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
671 | - * could change until it's actually outputted) |
|
672 | - * |
|
673 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
674 | - * to be triggered automatically or not |
|
675 | - * @return void |
|
676 | - */ |
|
677 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
678 | - { |
|
679 | - wp_register_script( |
|
680 | - 'ee_form_section_validation', |
|
681 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
682 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
683 | - EVENT_ESPRESSO_VERSION, |
|
684 | - true |
|
685 | - ); |
|
686 | - wp_localize_script( |
|
687 | - 'ee_form_section_validation', |
|
688 | - 'ee_form_section_validation_init', |
|
689 | - array('init' => $init_form_validation_automatically ? '1' : '0') |
|
690 | - ); |
|
691 | - } |
|
692 | - |
|
693 | - |
|
694 | - /** |
|
695 | - * gets the variables used by form_section_validation.js. |
|
696 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
697 | - * but before the wordpress hook wp_loaded |
|
698 | - * |
|
699 | - * @throws EE_Error |
|
700 | - */ |
|
701 | - public function _enqueue_and_localize_form_js() |
|
702 | - { |
|
703 | - $this->ensure_construct_finalized_called(); |
|
704 | - //actually, we don't want to localize just yet. There may be other forms on the page. |
|
705 | - //so we need to add our form section data to a static variable accessible by all form sections |
|
706 | - //and localize it just before the footer |
|
707 | - $this->localize_validation_rules(); |
|
708 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
709 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
710 | - } |
|
711 | - |
|
712 | - |
|
713 | - /** |
|
714 | - * add our form section data to a static variable accessible by all form sections |
|
715 | - * |
|
716 | - * @param bool $return_for_subsection |
|
717 | - * @return void |
|
718 | - * @throws EE_Error |
|
719 | - */ |
|
720 | - public function localize_validation_rules($return_for_subsection = false) |
|
721 | - { |
|
722 | - // we only want to localize vars ONCE for the entire form, |
|
723 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
724 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
725 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
726 | - 'form_section_id' => $this->html_id(true), |
|
727 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
728 | - 'other_data' => $this->get_other_js_data(), |
|
729 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
730 | - ); |
|
731 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
732 | - } |
|
733 | - } |
|
734 | - |
|
735 | - |
|
736 | - /** |
|
737 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
738 | - * This is primarily data added by inputs and forms in addition to any |
|
739 | - * scripts they might enqueue |
|
740 | - * |
|
741 | - * @param array $form_other_js_data |
|
742 | - * @return array |
|
743 | - * @throws EE_Error |
|
744 | - */ |
|
745 | - public function get_other_js_data($form_other_js_data = array()) |
|
746 | - { |
|
747 | - foreach ($this->subsections() as $subsection) { |
|
748 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
749 | - } |
|
750 | - return $form_other_js_data; |
|
751 | - } |
|
752 | - |
|
753 | - |
|
754 | - /** |
|
755 | - * Gets a flat array of inputs for this form section and its subsections. |
|
756 | - * Keys are their form names, and values are the inputs themselves |
|
757 | - * |
|
758 | - * @return EE_Form_Input_Base |
|
759 | - * @throws EE_Error |
|
760 | - */ |
|
761 | - public function inputs_in_subsections() |
|
762 | - { |
|
763 | - $inputs = array(); |
|
764 | - foreach ($this->subsections() as $subsection) { |
|
765 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
766 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
767 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
768 | - $inputs += $subsection->inputs_in_subsections(); |
|
769 | - } |
|
770 | - } |
|
771 | - return $inputs; |
|
772 | - } |
|
773 | - |
|
774 | - |
|
775 | - /** |
|
776 | - * Gets a flat array of all the validation errors. |
|
777 | - * Keys are html names (because those should be unique) |
|
778 | - * and values are a string of all their validation errors |
|
779 | - * |
|
780 | - * @return string[] |
|
781 | - * @throws EE_Error |
|
782 | - */ |
|
783 | - public function subsection_validation_errors_by_html_name() |
|
784 | - { |
|
785 | - $inputs = $this->inputs(); |
|
786 | - $errors = array(); |
|
787 | - foreach ($inputs as $form_input) { |
|
788 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
789 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
790 | - } |
|
791 | - } |
|
792 | - return $errors; |
|
793 | - } |
|
794 | - |
|
795 | - |
|
796 | - /** |
|
797 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
798 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
799 | - * |
|
800 | - * @throws InvalidArgumentException |
|
801 | - * @throws InvalidInterfaceException |
|
802 | - * @throws InvalidDataTypeException |
|
803 | - */ |
|
804 | - public static function localize_script_for_all_forms() |
|
805 | - { |
|
806 | - //allow inputs and stuff to hook in their JS and stuff here |
|
807 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
808 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
809 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
810 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
811 | - : 'wp_default'; |
|
812 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
813 | - wp_enqueue_script('ee_form_section_validation'); |
|
814 | - wp_localize_script( |
|
815 | - 'ee_form_section_validation', |
|
816 | - 'ee_form_section_vars', |
|
817 | - EE_Form_Section_Proper::$_js_localization |
|
818 | - ); |
|
819 | - } |
|
820 | - |
|
821 | - |
|
822 | - /** |
|
823 | - * ensure_scripts_localized |
|
824 | - * |
|
825 | - * @throws EE_Error |
|
826 | - */ |
|
827 | - public function ensure_scripts_localized() |
|
828 | - { |
|
829 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
830 | - $this->_enqueue_and_localize_form_js(); |
|
831 | - } |
|
832 | - } |
|
833 | - |
|
834 | - |
|
835 | - /** |
|
836 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
837 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
838 | - * |
|
839 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
840 | - */ |
|
841 | - private static function _get_localized_error_messages() |
|
842 | - { |
|
843 | - return array( |
|
844 | - 'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'), |
|
845 | - 'regex' => esc_html__('Please check your input', 'event_espresso'), |
|
846 | - ); |
|
847 | - } |
|
848 | - |
|
849 | - |
|
850 | - /** |
|
851 | - * @return array |
|
852 | - */ |
|
853 | - public static function js_localization() |
|
854 | - { |
|
855 | - return self::$_js_localization; |
|
856 | - } |
|
857 | - |
|
858 | - |
|
859 | - /** |
|
860 | - * @return void |
|
861 | - */ |
|
862 | - public static function reset_js_localization() |
|
863 | - { |
|
864 | - self::$_js_localization = array(); |
|
865 | - } |
|
866 | - |
|
867 | - |
|
868 | - /** |
|
869 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
870 | - * See parent function for more... |
|
871 | - * |
|
872 | - * @return array |
|
873 | - * @throws EE_Error |
|
874 | - */ |
|
875 | - public function get_jquery_validation_rules() |
|
876 | - { |
|
877 | - $jquery_validation_rules = array(); |
|
878 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
879 | - $jquery_validation_rules = array_merge( |
|
880 | - $jquery_validation_rules, |
|
881 | - $subsection->get_jquery_validation_rules() |
|
882 | - ); |
|
883 | - } |
|
884 | - return $jquery_validation_rules; |
|
885 | - } |
|
886 | - |
|
887 | - |
|
888 | - /** |
|
889 | - * Sanitizes all the data and sets the sanitized value of each field |
|
890 | - * |
|
891 | - * @param array $req_data like $_POST |
|
892 | - * @return void |
|
893 | - * @throws EE_Error |
|
894 | - */ |
|
895 | - protected function _normalize($req_data) |
|
896 | - { |
|
897 | - $this->_received_submission = true; |
|
898 | - $this->_validation_errors = array(); |
|
899 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
900 | - try { |
|
901 | - $subsection->_normalize($req_data); |
|
902 | - } catch (EE_Validation_Error $e) { |
|
903 | - $subsection->add_validation_error($e); |
|
904 | - } |
|
905 | - } |
|
906 | - } |
|
907 | - |
|
908 | - |
|
909 | - /** |
|
910 | - * Performs validation on this form section and its subsections. |
|
911 | - * For each subsection, |
|
912 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
913 | - * and passes it the subsection, then calls _validate on that subsection. |
|
914 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
915 | - * you would be best to override this _validate method, |
|
916 | - * calling parent::_validate() first. |
|
917 | - * |
|
918 | - * @throws EE_Error |
|
919 | - */ |
|
920 | - protected function _validate() |
|
921 | - { |
|
922 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
923 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
924 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
925 | - } |
|
926 | - $subsection->_validate(); |
|
927 | - } |
|
928 | - } |
|
929 | - |
|
930 | - |
|
931 | - /** |
|
932 | - * Gets all the validated inputs for the form section |
|
933 | - * |
|
934 | - * @return array |
|
935 | - * @throws EE_Error |
|
936 | - */ |
|
937 | - public function valid_data() |
|
938 | - { |
|
939 | - $inputs = array(); |
|
940 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
941 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
942 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
943 | - } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
944 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
945 | - } |
|
946 | - } |
|
947 | - return $inputs; |
|
948 | - } |
|
949 | - |
|
950 | - |
|
951 | - /** |
|
952 | - * Gets all the inputs on this form section |
|
953 | - * |
|
954 | - * @return EE_Form_Input_Base[] |
|
955 | - * @throws EE_Error |
|
956 | - */ |
|
957 | - public function inputs() |
|
958 | - { |
|
959 | - $inputs = array(); |
|
960 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
961 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
962 | - $inputs[ $subsection_name ] = $subsection; |
|
963 | - } |
|
964 | - } |
|
965 | - return $inputs; |
|
966 | - } |
|
967 | - |
|
968 | - |
|
969 | - /** |
|
970 | - * Gets all the subsections which are a proper form |
|
971 | - * |
|
972 | - * @return EE_Form_Section_Proper[] |
|
973 | - * @throws EE_Error |
|
974 | - */ |
|
975 | - public function subforms() |
|
976 | - { |
|
977 | - $form_sections = array(); |
|
978 | - foreach ($this->subsections() as $name => $obj) { |
|
979 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
980 | - $form_sections[ $name ] = $obj; |
|
981 | - } |
|
982 | - } |
|
983 | - return $form_sections; |
|
984 | - } |
|
985 | - |
|
986 | - |
|
987 | - /** |
|
988 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
989 | - * Consider using inputs() or subforms() |
|
990 | - * if you only want form inputs or proper form sections. |
|
991 | - * |
|
992 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
993 | - * leave this as TRUE so that the inputs will be properly |
|
994 | - * configured. However, some client code may be ok with |
|
995 | - * construction finalize being called later |
|
996 | - * (realizing that the subsections' html names might not be |
|
997 | - * set yet, etc.) |
|
998 | - * @return EE_Form_Section_Proper[] |
|
999 | - * @throws EE_Error |
|
1000 | - */ |
|
1001 | - public function subsections($require_construction_to_be_finalized = true) |
|
1002 | - { |
|
1003 | - if ($require_construction_to_be_finalized) { |
|
1004 | - $this->ensure_construct_finalized_called(); |
|
1005 | - } |
|
1006 | - return $this->_subsections; |
|
1007 | - } |
|
1008 | - |
|
1009 | - |
|
1010 | - /** |
|
1011 | - * Returns a simple array where keys are input names, and values are their normalized |
|
1012 | - * values. (Similar to calling get_input_value on inputs) |
|
1013 | - * |
|
1014 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1015 | - * or just this forms' direct children inputs |
|
1016 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1017 | - * or allow multidimensional array |
|
1018 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1019 | - * with array keys being input names |
|
1020 | - * (regardless of whether they are from a subsection or not), |
|
1021 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1022 | - * where keys are always subsection names and values are either |
|
1023 | - * the input's normalized value, or an array like the top-level array |
|
1024 | - * @throws EE_Error |
|
1025 | - */ |
|
1026 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
1027 | - { |
|
1028 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
1029 | - } |
|
1030 | - |
|
1031 | - |
|
1032 | - /** |
|
1033 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
1034 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
1035 | - * is not necessarily the value we want to display to users. This creates an array |
|
1036 | - * where keys are the input names, and values are their display values |
|
1037 | - * |
|
1038 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1039 | - * or just this forms' direct children inputs |
|
1040 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1041 | - * or allow multidimensional array |
|
1042 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1043 | - * with array keys being input names |
|
1044 | - * (regardless of whether they are from a subsection or not), |
|
1045 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1046 | - * where keys are always subsection names and values are either |
|
1047 | - * the input's normalized value, or an array like the top-level array |
|
1048 | - * @throws EE_Error |
|
1049 | - */ |
|
1050 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1051 | - { |
|
1052 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1053 | - } |
|
1054 | - |
|
1055 | - |
|
1056 | - /** |
|
1057 | - * Gets the input values from the form |
|
1058 | - * |
|
1059 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
1060 | - * or just the normalized value |
|
1061 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1062 | - * or just this forms' direct children inputs |
|
1063 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1064 | - * or allow multidimensional array |
|
1065 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1066 | - * input names (regardless of whether they are from a subsection or not), |
|
1067 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1068 | - * where keys are always subsection names and values are either |
|
1069 | - * the input's normalized value, or an array like the top-level array |
|
1070 | - * @throws EE_Error |
|
1071 | - */ |
|
1072 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1073 | - { |
|
1074 | - $input_values = array(); |
|
1075 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1076 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1077 | - $input_values[ $subsection_name ] = $pretty |
|
1078 | - ? $subsection->pretty_value() |
|
1079 | - : $subsection->normalized_value(); |
|
1080 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1081 | - $subform_input_values = $subsection->_input_values( |
|
1082 | - $pretty, |
|
1083 | - $include_subform_inputs, |
|
1084 | - $flatten |
|
1085 | - ); |
|
1086 | - if ($flatten) { |
|
1087 | - $input_values = array_merge($input_values, $subform_input_values); |
|
1088 | - } else { |
|
1089 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
1090 | - } |
|
1091 | - } |
|
1092 | - } |
|
1093 | - return $input_values; |
|
1094 | - } |
|
1095 | - |
|
1096 | - |
|
1097 | - /** |
|
1098 | - * Gets the originally submitted input values from the form |
|
1099 | - * |
|
1100 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1101 | - * or just this forms' direct children inputs |
|
1102 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1103 | - * with array keys being input names |
|
1104 | - * (regardless of whether they are from a subsection or not), |
|
1105 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1106 | - * where keys are always subsection names and values are either |
|
1107 | - * the input's normalized value, or an array like the top-level array |
|
1108 | - * @throws EE_Error |
|
1109 | - */ |
|
1110 | - public function submitted_values($include_subforms = false) |
|
1111 | - { |
|
1112 | - $submitted_values = array(); |
|
1113 | - foreach ($this->subsections() as $subsection) { |
|
1114 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1115 | - // is this input part of an array of inputs? |
|
1116 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
1117 | - $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
1118 | - explode( |
|
1119 | - '[', |
|
1120 | - str_replace(']', '', $subsection->html_name()) |
|
1121 | - ), |
|
1122 | - $subsection->raw_value() |
|
1123 | - ); |
|
1124 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1125 | - } else { |
|
1126 | - $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
1127 | - } |
|
1128 | - } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1129 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1130 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1131 | - } |
|
1132 | - } |
|
1133 | - return $submitted_values; |
|
1134 | - } |
|
1135 | - |
|
1136 | - |
|
1137 | - /** |
|
1138 | - * Indicates whether or not this form has received a submission yet |
|
1139 | - * (ie, had receive_form_submission called on it yet) |
|
1140 | - * |
|
1141 | - * @return boolean |
|
1142 | - * @throws EE_Error |
|
1143 | - */ |
|
1144 | - public function has_received_submission() |
|
1145 | - { |
|
1146 | - $this->ensure_construct_finalized_called(); |
|
1147 | - return $this->_received_submission; |
|
1148 | - } |
|
1149 | - |
|
1150 | - |
|
1151 | - /** |
|
1152 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
1153 | - * Removes the listed inputs from the form |
|
1154 | - * |
|
1155 | - * @param array $inputs_to_exclude values are the input names |
|
1156 | - * @return void |
|
1157 | - */ |
|
1158 | - public function exclude(array $inputs_to_exclude = array()) |
|
1159 | - { |
|
1160 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1161 | - unset($this->_subsections[ $input_to_exclude_name ]); |
|
1162 | - } |
|
1163 | - } |
|
1164 | - |
|
1165 | - |
|
1166 | - /** |
|
1167 | - * @param array $inputs_to_hide |
|
1168 | - * @throws EE_Error |
|
1169 | - */ |
|
1170 | - public function hide(array $inputs_to_hide = array()) |
|
1171 | - { |
|
1172 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
1173 | - $input = $this->get_input($input_to_hide); |
|
1174 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1175 | - } |
|
1176 | - } |
|
1177 | - |
|
1178 | - |
|
1179 | - /** |
|
1180 | - * add_subsections |
|
1181 | - * Adds the listed subsections to the form section. |
|
1182 | - * If $subsection_name_to_target is provided, |
|
1183 | - * then new subsections are added before or after that subsection, |
|
1184 | - * otherwise to the start or end of the entire subsections array. |
|
1185 | - * |
|
1186 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1187 | - * where keys are their names |
|
1188 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1189 | - * should be added before or after |
|
1190 | - * IF $subsection_name_to_target is null, |
|
1191 | - * then $new_subsections will be added to |
|
1192 | - * the beginning or end of the entire subsections array |
|
1193 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
1194 | - * $subsection_name_to_target, |
|
1195 | - * or if $subsection_name_to_target is null, |
|
1196 | - * before or after entire subsections array |
|
1197 | - * @return void |
|
1198 | - * @throws EE_Error |
|
1199 | - */ |
|
1200 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1201 | - { |
|
1202 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
1203 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
1204 | - EE_Error::add_error( |
|
1205 | - sprintf( |
|
1206 | - esc_html__( |
|
1207 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1208 | - 'event_espresso' |
|
1209 | - ), |
|
1210 | - get_class($subsection), |
|
1211 | - $subsection_name, |
|
1212 | - $this->name() |
|
1213 | - ) |
|
1214 | - ); |
|
1215 | - unset($new_subsections[ $subsection_name ]); |
|
1216 | - } |
|
1217 | - } |
|
1218 | - $this->_subsections = EEH_Array::insert_into_array( |
|
1219 | - $this->_subsections, |
|
1220 | - $new_subsections, |
|
1221 | - $subsection_name_to_target, |
|
1222 | - $add_before |
|
1223 | - ); |
|
1224 | - if ($this->_construction_finalized) { |
|
1225 | - foreach ($this->_subsections as $name => $subsection) { |
|
1226 | - $subsection->_construct_finalize($this, $name); |
|
1227 | - } |
|
1228 | - } |
|
1229 | - } |
|
1230 | - |
|
1231 | - |
|
1232 | - /** |
|
1233 | - * Just gets all validatable subsections to clean their sensitive data |
|
1234 | - * |
|
1235 | - * @throws EE_Error |
|
1236 | - */ |
|
1237 | - public function clean_sensitive_data() |
|
1238 | - { |
|
1239 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1240 | - $subsection->clean_sensitive_data(); |
|
1241 | - } |
|
1242 | - } |
|
1243 | - |
|
1244 | - |
|
1245 | - /** |
|
1246 | - * @param string $form_submission_error_message |
|
1247 | - */ |
|
1248 | - public function set_submission_error_message($form_submission_error_message = '') |
|
1249 | - { |
|
1250 | - $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
1251 | - ? $form_submission_error_message |
|
1252 | - : esc_html__('Form submission failed due to errors', 'event_espresso'); |
|
1253 | - } |
|
1254 | - |
|
1255 | - |
|
1256 | - /** |
|
1257 | - * @return string |
|
1258 | - */ |
|
1259 | - public function submission_error_message() |
|
1260 | - { |
|
1261 | - return $this->_form_submission_error_message; |
|
1262 | - } |
|
1263 | - |
|
1264 | - |
|
1265 | - /** |
|
1266 | - * @param string $form_submission_success_message |
|
1267 | - */ |
|
1268 | - public function set_submission_success_message($form_submission_success_message) |
|
1269 | - { |
|
1270 | - $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
1271 | - ? $form_submission_success_message |
|
1272 | - : esc_html__('Form submitted successfully', 'event_espresso'); |
|
1273 | - } |
|
1274 | - |
|
1275 | - |
|
1276 | - /** |
|
1277 | - * @return string |
|
1278 | - */ |
|
1279 | - public function submission_success_message() |
|
1280 | - { |
|
1281 | - return $this->_form_submission_success_message; |
|
1282 | - } |
|
1283 | - |
|
1284 | - |
|
1285 | - /** |
|
1286 | - * Returns the prefix that should be used on child of this form section for |
|
1287 | - * their html names. If this form section itself has a parent, prepends ITS |
|
1288 | - * prefix onto this form section's prefix. Used primarily by |
|
1289 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1290 | - * |
|
1291 | - * @return string |
|
1292 | - * @throws EE_Error |
|
1293 | - */ |
|
1294 | - public function html_name_prefix() |
|
1295 | - { |
|
1296 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1297 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1298 | - } |
|
1299 | - return $this->name(); |
|
1300 | - } |
|
1301 | - |
|
1302 | - |
|
1303 | - /** |
|
1304 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1305 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
1306 | - * was set, which is probably nothing, or the classname) |
|
1307 | - * |
|
1308 | - * @return string |
|
1309 | - * @throws EE_Error |
|
1310 | - */ |
|
1311 | - public function name() |
|
1312 | - { |
|
1313 | - $this->ensure_construct_finalized_called(); |
|
1314 | - return parent::name(); |
|
1315 | - } |
|
1316 | - |
|
1317 | - |
|
1318 | - /** |
|
1319 | - * @return EE_Form_Section_Proper |
|
1320 | - * @throws EE_Error |
|
1321 | - */ |
|
1322 | - public function parent_section() |
|
1323 | - { |
|
1324 | - $this->ensure_construct_finalized_called(); |
|
1325 | - return parent::parent_section(); |
|
1326 | - } |
|
1327 | - |
|
1328 | - |
|
1329 | - /** |
|
1330 | - * make sure construction finalized was called, otherwise children might not be ready |
|
1331 | - * |
|
1332 | - * @return void |
|
1333 | - * @throws EE_Error |
|
1334 | - */ |
|
1335 | - public function ensure_construct_finalized_called() |
|
1336 | - { |
|
1337 | - if (! $this->_construction_finalized) { |
|
1338 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1339 | - } |
|
1340 | - } |
|
1341 | - |
|
1342 | - |
|
1343 | - /** |
|
1344 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1345 | - * are in teh form data. If any are found, returns true. Else false |
|
1346 | - * |
|
1347 | - * @param array $req_data |
|
1348 | - * @return boolean |
|
1349 | - * @throws EE_Error |
|
1350 | - */ |
|
1351 | - public function form_data_present_in($req_data = null) |
|
1352 | - { |
|
1353 | - if ($req_data === null) { |
|
1354 | - $req_data = $_POST; |
|
1355 | - } |
|
1356 | - foreach ($this->subsections() as $subsection) { |
|
1357 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1358 | - if ($subsection->form_data_present_in($req_data)) { |
|
1359 | - return true; |
|
1360 | - } |
|
1361 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1362 | - if ($subsection->form_data_present_in($req_data)) { |
|
1363 | - return true; |
|
1364 | - } |
|
1365 | - } |
|
1366 | - } |
|
1367 | - return false; |
|
1368 | - } |
|
1369 | - |
|
1370 | - |
|
1371 | - /** |
|
1372 | - * Gets validation errors for this form section and subsections |
|
1373 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1374 | - * gets the validation errors for ALL subsection |
|
1375 | - * |
|
1376 | - * @return EE_Validation_Error[] |
|
1377 | - * @throws EE_Error |
|
1378 | - */ |
|
1379 | - public function get_validation_errors_accumulated() |
|
1380 | - { |
|
1381 | - $validation_errors = $this->get_validation_errors(); |
|
1382 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1383 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
1384 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1385 | - } else { |
|
1386 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1387 | - } |
|
1388 | - if ($validation_errors_on_this_subsection) { |
|
1389 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1390 | - } |
|
1391 | - } |
|
1392 | - return $validation_errors; |
|
1393 | - } |
|
1394 | - |
|
1395 | - |
|
1396 | - /** |
|
1397 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
1398 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1399 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
1400 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1401 | - * which will be returned. |
|
1402 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1403 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1404 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1405 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1406 | - * Etc |
|
1407 | - * |
|
1408 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1409 | - * @return EE_Form_Section_Base |
|
1410 | - * @throws EE_Error |
|
1411 | - */ |
|
1412 | - public function find_section_from_path($form_section_path) |
|
1413 | - { |
|
1414 | - //check if we can find the input from purely going straight up the tree |
|
1415 | - $input = parent::find_section_from_path($form_section_path); |
|
1416 | - if ($input instanceof EE_Form_Section_Base) { |
|
1417 | - return $input; |
|
1418 | - } |
|
1419 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
1420 | - if ($next_slash_pos !== false) { |
|
1421 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1422 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1423 | - } else { |
|
1424 | - $child_section_name = $form_section_path; |
|
1425 | - $subpath = ''; |
|
1426 | - } |
|
1427 | - $child_section = $this->get_subsection($child_section_name); |
|
1428 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
1429 | - return $child_section->find_section_from_path($subpath); |
|
1430 | - } |
|
1431 | - return null; |
|
1432 | - } |
|
17 | + const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
18 | + |
|
19 | + /** |
|
20 | + * Subsections |
|
21 | + * |
|
22 | + * @var EE_Form_Section_Validatable[] |
|
23 | + */ |
|
24 | + protected $_subsections = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * Strategy for laying out the form |
|
28 | + * |
|
29 | + * @var EE_Form_Section_Layout_Base |
|
30 | + */ |
|
31 | + protected $_layout_strategy; |
|
32 | + |
|
33 | + /** |
|
34 | + * Whether or not this form has received and validated a form submission yet |
|
35 | + * |
|
36 | + * @var boolean |
|
37 | + */ |
|
38 | + protected $_received_submission = false; |
|
39 | + |
|
40 | + /** |
|
41 | + * message displayed to users upon successful form submission |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + protected $_form_submission_success_message = ''; |
|
46 | + |
|
47 | + /** |
|
48 | + * message displayed to users upon unsuccessful form submission |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + protected $_form_submission_error_message = ''; |
|
53 | + |
|
54 | + /** |
|
55 | + * Stores all the data that will localized for form validation |
|
56 | + * |
|
57 | + * @var array |
|
58 | + */ |
|
59 | + static protected $_js_localization = array(); |
|
60 | + |
|
61 | + /** |
|
62 | + * whether or not the form's localized validation JS vars have been set |
|
63 | + * |
|
64 | + * @type boolean |
|
65 | + */ |
|
66 | + static protected $_scripts_localized = false; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * when constructing a proper form section, calls _construct_finalize on children |
|
71 | + * so that they know who their parent is, and what name they've been given. |
|
72 | + * |
|
73 | + * @param array[] $options_array { |
|
74 | + * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
75 | + * @type $include string[] numerically-indexed where values are section names to be included, |
|
76 | + * and in that order. This is handy if you want |
|
77 | + * the subsections to be ordered differently than the default, and if you override |
|
78 | + * which fields are shown |
|
79 | + * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
80 | + * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
81 | + * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
82 | + * items from that list of inclusions) |
|
83 | + * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
84 | + * } @see EE_Form_Section_Validatable::__construct() |
|
85 | + * @throws EE_Error |
|
86 | + */ |
|
87 | + public function __construct($options_array = array()) |
|
88 | + { |
|
89 | + $options_array = (array) apply_filters( |
|
90 | + 'FHEE__EE_Form_Section_Proper___construct__options_array', |
|
91 | + $options_array, |
|
92 | + $this |
|
93 | + ); |
|
94 | + //call parent first, as it may be setting the name |
|
95 | + parent::__construct($options_array); |
|
96 | + //if they've included subsections in the constructor, add them now |
|
97 | + if (isset($options_array['include'])) { |
|
98 | + //we are going to make sure we ONLY have those subsections to include |
|
99 | + //AND we are going to make sure they're in that specified order |
|
100 | + $reordered_subsections = array(); |
|
101 | + foreach ($options_array['include'] as $input_name) { |
|
102 | + if (isset($this->_subsections[ $input_name ])) { |
|
103 | + $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
104 | + } |
|
105 | + } |
|
106 | + $this->_subsections = $reordered_subsections; |
|
107 | + } |
|
108 | + if (isset($options_array['exclude'])) { |
|
109 | + $exclude = $options_array['exclude']; |
|
110 | + $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
111 | + } |
|
112 | + if (isset($options_array['layout_strategy'])) { |
|
113 | + $this->_layout_strategy = $options_array['layout_strategy']; |
|
114 | + } |
|
115 | + if (! $this->_layout_strategy) { |
|
116 | + $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
117 | + } |
|
118 | + $this->_layout_strategy->_construct_finalize($this); |
|
119 | + //ok so we are definitely going to want the forms JS, |
|
120 | + //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
121 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
122 | + //ok so they've constructed this object after when they should have. |
|
123 | + //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
124 | + EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
125 | + } else { |
|
126 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
127 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
128 | + } |
|
129 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
130 | + /** |
|
131 | + * Gives other plugins a chance to hook in before construct finalize is called. |
|
132 | + * The form probably doesn't yet have a parent form section. |
|
133 | + * Since 4.9.32, when this action was introduced, this is the best place to add a subsection onto a form, |
|
134 | + * assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
135 | + * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
136 | + * |
|
137 | + * @since 4.9.32 |
|
138 | + * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, |
|
139 | + * except maybe calling _construct_finalize has been done |
|
140 | + * @param array $options_array options passed into the constructor |
|
141 | + */ |
|
142 | + do_action( |
|
143 | + 'AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', |
|
144 | + $this, |
|
145 | + $options_array |
|
146 | + ); |
|
147 | + if (isset($options_array['name'])) { |
|
148 | + $this->_construct_finalize(null, $options_array['name']); |
|
149 | + } |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * Finishes construction given the parent form section and this form section's name |
|
155 | + * |
|
156 | + * @param EE_Form_Section_Proper $parent_form_section |
|
157 | + * @param string $name |
|
158 | + * @throws EE_Error |
|
159 | + */ |
|
160 | + public function _construct_finalize($parent_form_section, $name) |
|
161 | + { |
|
162 | + parent::_construct_finalize($parent_form_section, $name); |
|
163 | + $this->_set_default_name_if_empty(); |
|
164 | + $this->_set_default_html_id_if_empty(); |
|
165 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
166 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
167 | + $subsection->_construct_finalize($this, $subsection_name); |
|
168 | + } else { |
|
169 | + throw new EE_Error( |
|
170 | + sprintf( |
|
171 | + esc_html__( |
|
172 | + 'Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
173 | + 'event_espresso' |
|
174 | + ), |
|
175 | + $subsection_name, |
|
176 | + get_class($this), |
|
177 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
178 | + ) |
|
179 | + ); |
|
180 | + } |
|
181 | + } |
|
182 | + /** |
|
183 | + * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
184 | + * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID |
|
185 | + * (or other attributes derived from the name like the HTML label id, etc), this is where it should be done. |
|
186 | + * This might only happen just before displaying the form, or just before it receives form submission data. |
|
187 | + * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
188 | + * ensured it has a name, HTML IDs, etc |
|
189 | + * |
|
190 | + * @param EE_Form_Section_Proper $this |
|
191 | + * @param EE_Form_Section_Proper|null $parent_form_section |
|
192 | + * @param string $name |
|
193 | + */ |
|
194 | + do_action( |
|
195 | + 'AHEE__EE_Form_Section_Proper___construct_finalize__end', |
|
196 | + $this, |
|
197 | + $parent_form_section, |
|
198 | + $name |
|
199 | + ); |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * Gets the layout strategy for this form section |
|
205 | + * |
|
206 | + * @return EE_Form_Section_Layout_Base |
|
207 | + */ |
|
208 | + public function get_layout_strategy() |
|
209 | + { |
|
210 | + return $this->_layout_strategy; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * Gets the HTML for a single input for this form section according |
|
216 | + * to the layout strategy |
|
217 | + * |
|
218 | + * @param EE_Form_Input_Base $input |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + public function get_html_for_input($input) |
|
222 | + { |
|
223 | + return $this->_layout_strategy->layout_input($input); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * was_submitted - checks if form inputs are present in request data |
|
229 | + * Basically an alias for form_data_present_in() (which is used by both |
|
230 | + * proper form sections and form inputs) |
|
231 | + * |
|
232 | + * @param null $form_data |
|
233 | + * @return boolean |
|
234 | + * @throws EE_Error |
|
235 | + */ |
|
236 | + public function was_submitted($form_data = null) |
|
237 | + { |
|
238 | + return $this->form_data_present_in($form_data); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
244 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
245 | + * |
|
246 | + * @param array|null $req_data should usually be $_POST (the default). |
|
247 | + * However, you CAN supply a different array. |
|
248 | + * Consider using set_defaults() instead however. |
|
249 | + * (If you rendered the form in the page using echo $form_x->get_html() |
|
250 | + * the inputs will have the correct name in the request data for this function |
|
251 | + * to find them and populate the form with them. |
|
252 | + * If you have a flat form (with only input subsections), |
|
253 | + * you can supply a flat array where keys |
|
254 | + * are the form input names and values are their values) |
|
255 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
256 | + * of course, to validate that data, and set errors on the invalid values. |
|
257 | + * But if the data has already been validated |
|
258 | + * (eg you validated the data then stored it in the DB) |
|
259 | + * you may want to skip this step. |
|
260 | + * @throws InvalidArgumentException |
|
261 | + * @throws InvalidInterfaceException |
|
262 | + * @throws InvalidDataTypeException |
|
263 | + * @throws EE_Error |
|
264 | + */ |
|
265 | + public function receive_form_submission($req_data = null, $validate = true) |
|
266 | + { |
|
267 | + $req_data = apply_filters( |
|
268 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
269 | + $req_data, |
|
270 | + $this, |
|
271 | + $validate |
|
272 | + ); |
|
273 | + if ($req_data === null) { |
|
274 | + $req_data = array_merge($_GET, $_POST); |
|
275 | + } |
|
276 | + $req_data = apply_filters( |
|
277 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
278 | + $req_data, |
|
279 | + $this |
|
280 | + ); |
|
281 | + $this->_normalize($req_data); |
|
282 | + if ($validate) { |
|
283 | + $this->_validate(); |
|
284 | + //if it's invalid, we're going to want to re-display so remember what they submitted |
|
285 | + if (! $this->is_valid()) { |
|
286 | + $this->store_submitted_form_data_in_session(); |
|
287 | + } |
|
288 | + } |
|
289 | + do_action( |
|
290 | + 'AHEE__EE_Form_Section_Proper__receive_form_submission__end', |
|
291 | + $req_data, |
|
292 | + $this, |
|
293 | + $validate |
|
294 | + ); |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * caches the originally submitted input values in the session |
|
300 | + * so that they can be used to repopulate the form if it failed validation |
|
301 | + * |
|
302 | + * @return boolean whether or not the data was successfully stored in the session |
|
303 | + * @throws InvalidArgumentException |
|
304 | + * @throws InvalidInterfaceException |
|
305 | + * @throws InvalidDataTypeException |
|
306 | + * @throws EE_Error |
|
307 | + */ |
|
308 | + protected function store_submitted_form_data_in_session() |
|
309 | + { |
|
310 | + return EE_Registry::instance()->SSN->set_session_data( |
|
311 | + array( |
|
312 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
313 | + ) |
|
314 | + ); |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * retrieves the originally submitted input values in the session |
|
320 | + * so that they can be used to repopulate the form if it failed validation |
|
321 | + * |
|
322 | + * @return array |
|
323 | + * @throws InvalidArgumentException |
|
324 | + * @throws InvalidInterfaceException |
|
325 | + * @throws InvalidDataTypeException |
|
326 | + */ |
|
327 | + protected function get_submitted_form_data_from_session() |
|
328 | + { |
|
329 | + $session = EE_Registry::instance()->SSN; |
|
330 | + if ($session instanceof EE_Session) { |
|
331 | + return $session->get_session_data( |
|
332 | + EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
333 | + ); |
|
334 | + } |
|
335 | + return array(); |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * flushed the originally submitted input values from the session |
|
341 | + * |
|
342 | + * @return boolean whether or not the data was successfully removed from the session |
|
343 | + * @throws InvalidArgumentException |
|
344 | + * @throws InvalidInterfaceException |
|
345 | + * @throws InvalidDataTypeException |
|
346 | + */ |
|
347 | + protected function flush_submitted_form_data_from_session() |
|
348 | + { |
|
349 | + return EE_Registry::instance()->SSN->reset_data( |
|
350 | + array(EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
351 | + ); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * Populates this form and its subsections with data from the session. |
|
357 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
358 | + * validation errors when displaying too) |
|
359 | + * Returns true if the form was populated from the session, false otherwise |
|
360 | + * |
|
361 | + * @return boolean |
|
362 | + * @throws InvalidArgumentException |
|
363 | + * @throws InvalidInterfaceException |
|
364 | + * @throws InvalidDataTypeException |
|
365 | + * @throws EE_Error |
|
366 | + */ |
|
367 | + public function populate_from_session() |
|
368 | + { |
|
369 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
370 | + if (empty($form_data_in_session)) { |
|
371 | + return false; |
|
372 | + } |
|
373 | + $this->receive_form_submission($form_data_in_session); |
|
374 | + $this->flush_submitted_form_data_from_session(); |
|
375 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
376 | + return true; |
|
377 | + } |
|
378 | + return false; |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * Populates the default data for the form, given an array where keys are |
|
384 | + * the input names, and values are their values (preferably normalized to be their |
|
385 | + * proper PHP types, not all strings... although that should be ok too). |
|
386 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
387 | + * the value being an array formatted in teh same way |
|
388 | + * |
|
389 | + * @param array $default_data |
|
390 | + * @throws EE_Error |
|
391 | + */ |
|
392 | + public function populate_defaults($default_data) |
|
393 | + { |
|
394 | + foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
395 | + if (isset($default_data[ $subsection_name ])) { |
|
396 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
397 | + $subsection->set_default($default_data[ $subsection_name ]); |
|
398 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
399 | + $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
400 | + } |
|
401 | + } |
|
402 | + } |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * returns true if subsection exists |
|
408 | + * |
|
409 | + * @param string $name |
|
410 | + * @return boolean |
|
411 | + */ |
|
412 | + public function subsection_exists($name) |
|
413 | + { |
|
414 | + return isset($this->_subsections[ $name ]) ? true : false; |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + * Gets the subsection specified by its name |
|
420 | + * |
|
421 | + * @param string $name |
|
422 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
423 | + * so that the inputs will be properly configured. |
|
424 | + * However, some client code may be ok |
|
425 | + * with construction finalize being called later |
|
426 | + * (realizing that the subsections' html names |
|
427 | + * might not be set yet, etc.) |
|
428 | + * @return EE_Form_Section_Base |
|
429 | + * @throws EE_Error |
|
430 | + */ |
|
431 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
432 | + { |
|
433 | + if ($require_construction_to_be_finalized) { |
|
434 | + $this->ensure_construct_finalized_called(); |
|
435 | + } |
|
436 | + return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * Gets all the validatable subsections of this form section |
|
442 | + * |
|
443 | + * @return EE_Form_Section_Validatable[] |
|
444 | + * @throws EE_Error |
|
445 | + */ |
|
446 | + public function get_validatable_subsections() |
|
447 | + { |
|
448 | + $validatable_subsections = array(); |
|
449 | + foreach ($this->subsections() as $name => $obj) { |
|
450 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
451 | + $validatable_subsections[ $name ] = $obj; |
|
452 | + } |
|
453 | + } |
|
454 | + return $validatable_subsections; |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
460 | + * throw an EE_Error. |
|
461 | + * |
|
462 | + * @param string $name |
|
463 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
464 | + * leave this as TRUE so that the inputs will be properly |
|
465 | + * configured. However, some client code may be ok with |
|
466 | + * construction finalize being called later |
|
467 | + * (realizing that the subsections' html names might not be |
|
468 | + * set yet, etc.) |
|
469 | + * @return EE_Form_Input_Base |
|
470 | + * @throws EE_Error |
|
471 | + */ |
|
472 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
473 | + { |
|
474 | + $subsection = $this->get_subsection( |
|
475 | + $name, |
|
476 | + $require_construction_to_be_finalized |
|
477 | + ); |
|
478 | + if (! $subsection instanceof EE_Form_Input_Base) { |
|
479 | + throw new EE_Error( |
|
480 | + sprintf( |
|
481 | + esc_html__( |
|
482 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
483 | + 'event_espresso' |
|
484 | + ), |
|
485 | + $name, |
|
486 | + get_class($this), |
|
487 | + $subsection ? get_class($subsection) : esc_html__('NULL', 'event_espresso') |
|
488 | + ) |
|
489 | + ); |
|
490 | + } |
|
491 | + return $subsection; |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
497 | + * otherwise throws an EE_Error |
|
498 | + * |
|
499 | + * @param string $name |
|
500 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
501 | + * leave this as TRUE so that the inputs will be properly |
|
502 | + * configured. However, some client code may be ok with |
|
503 | + * construction finalize being called later |
|
504 | + * (realizing that the subsections' html names might not be |
|
505 | + * set yet, etc.) |
|
506 | + * @return EE_Form_Section_Proper |
|
507 | + * @throws EE_Error |
|
508 | + */ |
|
509 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
510 | + { |
|
511 | + $subsection = $this->get_subsection( |
|
512 | + $name, |
|
513 | + $require_construction_to_be_finalized |
|
514 | + ); |
|
515 | + if (! $subsection instanceof EE_Form_Section_Proper) { |
|
516 | + throw new EE_Error( |
|
517 | + sprintf( |
|
518 | + esc_html__( |
|
519 | + "Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", |
|
520 | + 'event_espresso' |
|
521 | + ), |
|
522 | + $name, |
|
523 | + get_class($this) |
|
524 | + ) |
|
525 | + ); |
|
526 | + } |
|
527 | + return $subsection; |
|
528 | + } |
|
529 | + |
|
530 | + |
|
531 | + /** |
|
532 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
533 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
534 | + * |
|
535 | + * @param string $name |
|
536 | + * @return mixed depending on the input's type and its normalization strategy |
|
537 | + * @throws EE_Error |
|
538 | + */ |
|
539 | + public function get_input_value($name) |
|
540 | + { |
|
541 | + $input = $this->get_input($name); |
|
542 | + return $input->normalized_value(); |
|
543 | + } |
|
544 | + |
|
545 | + |
|
546 | + /** |
|
547 | + * Checks if this form section itself is valid, and then checks its subsections |
|
548 | + * |
|
549 | + * @throws EE_Error |
|
550 | + * @return boolean |
|
551 | + */ |
|
552 | + public function is_valid() |
|
553 | + { |
|
554 | + if (! $this->has_received_submission()) { |
|
555 | + throw new EE_Error( |
|
556 | + sprintf( |
|
557 | + esc_html__( |
|
558 | + 'You cannot check if a form is valid before receiving the form submission using receive_form_submission', |
|
559 | + 'event_espresso' |
|
560 | + ) |
|
561 | + ) |
|
562 | + ); |
|
563 | + } |
|
564 | + if (! parent::is_valid()) { |
|
565 | + return false; |
|
566 | + } |
|
567 | + // ok so no general errors to this entire form section. |
|
568 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
569 | + $set_submission_errors = $this->submission_error_message() === ''; |
|
570 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
571 | + if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
572 | + if ($set_submission_errors) { |
|
573 | + $this->set_submission_error_message( |
|
574 | + $subsection->get_validation_error_string() |
|
575 | + ); |
|
576 | + } |
|
577 | + return false; |
|
578 | + } |
|
579 | + } |
|
580 | + return true; |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * gets the default name of this form section if none is specified |
|
586 | + * |
|
587 | + * @return void |
|
588 | + */ |
|
589 | + protected function _set_default_name_if_empty() |
|
590 | + { |
|
591 | + if (! $this->_name) { |
|
592 | + $classname = get_class($this); |
|
593 | + $default_name = str_replace('EE_', '', $classname); |
|
594 | + $this->_name = $default_name; |
|
595 | + } |
|
596 | + } |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * Returns the HTML for the form, except for the form opening and closing tags |
|
601 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
602 | + * and except for a submit button. Enqueues JS and CSS; if called early enough we will |
|
603 | + * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
604 | + * Not doing_it_wrong because theoretically this CAN be used properly, |
|
605 | + * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
606 | + * any CSS. |
|
607 | + * |
|
608 | + * @throws InvalidArgumentException |
|
609 | + * @throws InvalidInterfaceException |
|
610 | + * @throws InvalidDataTypeException |
|
611 | + * @throws EE_Error |
|
612 | + */ |
|
613 | + public function get_html_and_js() |
|
614 | + { |
|
615 | + $this->enqueue_js(); |
|
616 | + return $this->get_html(); |
|
617 | + } |
|
618 | + |
|
619 | + |
|
620 | + /** |
|
621 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
622 | + * |
|
623 | + * @param bool $display_previously_submitted_data |
|
624 | + * @return string |
|
625 | + * @throws InvalidArgumentException |
|
626 | + * @throws InvalidInterfaceException |
|
627 | + * @throws InvalidDataTypeException |
|
628 | + * @throws EE_Error |
|
629 | + * @throws EE_Error |
|
630 | + * @throws EE_Error |
|
631 | + */ |
|
632 | + public function get_html($display_previously_submitted_data = true) |
|
633 | + { |
|
634 | + $this->ensure_construct_finalized_called(); |
|
635 | + if ($display_previously_submitted_data) { |
|
636 | + $this->populate_from_session(); |
|
637 | + } |
|
638 | + return $this->_form_html_filter |
|
639 | + ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
640 | + : $this->_layout_strategy->layout_form(); |
|
641 | + } |
|
642 | + |
|
643 | + |
|
644 | + /** |
|
645 | + * enqueues JS and CSS for the form. |
|
646 | + * It is preferred to call this before wp_enqueue_scripts so the |
|
647 | + * scripts and styles can be put in the header, but if called later |
|
648 | + * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
649 | + * only be in the header; but in HTML5 its ok in the body. |
|
650 | + * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
651 | + * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
652 | + * |
|
653 | + * @return void |
|
654 | + * @throws EE_Error |
|
655 | + */ |
|
656 | + public function enqueue_js() |
|
657 | + { |
|
658 | + $this->_enqueue_and_localize_form_js(); |
|
659 | + foreach ($this->subsections() as $subsection) { |
|
660 | + $subsection->enqueue_js(); |
|
661 | + } |
|
662 | + } |
|
663 | + |
|
664 | + |
|
665 | + /** |
|
666 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
667 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
668 | + * the wp_enqueue_scripts hook. |
|
669 | + * However, registering the form js and localizing it can happen when we |
|
670 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
671 | + * could change until it's actually outputted) |
|
672 | + * |
|
673 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
674 | + * to be triggered automatically or not |
|
675 | + * @return void |
|
676 | + */ |
|
677 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
678 | + { |
|
679 | + wp_register_script( |
|
680 | + 'ee_form_section_validation', |
|
681 | + EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
682 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
683 | + EVENT_ESPRESSO_VERSION, |
|
684 | + true |
|
685 | + ); |
|
686 | + wp_localize_script( |
|
687 | + 'ee_form_section_validation', |
|
688 | + 'ee_form_section_validation_init', |
|
689 | + array('init' => $init_form_validation_automatically ? '1' : '0') |
|
690 | + ); |
|
691 | + } |
|
692 | + |
|
693 | + |
|
694 | + /** |
|
695 | + * gets the variables used by form_section_validation.js. |
|
696 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
697 | + * but before the wordpress hook wp_loaded |
|
698 | + * |
|
699 | + * @throws EE_Error |
|
700 | + */ |
|
701 | + public function _enqueue_and_localize_form_js() |
|
702 | + { |
|
703 | + $this->ensure_construct_finalized_called(); |
|
704 | + //actually, we don't want to localize just yet. There may be other forms on the page. |
|
705 | + //so we need to add our form section data to a static variable accessible by all form sections |
|
706 | + //and localize it just before the footer |
|
707 | + $this->localize_validation_rules(); |
|
708 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
709 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
710 | + } |
|
711 | + |
|
712 | + |
|
713 | + /** |
|
714 | + * add our form section data to a static variable accessible by all form sections |
|
715 | + * |
|
716 | + * @param bool $return_for_subsection |
|
717 | + * @return void |
|
718 | + * @throws EE_Error |
|
719 | + */ |
|
720 | + public function localize_validation_rules($return_for_subsection = false) |
|
721 | + { |
|
722 | + // we only want to localize vars ONCE for the entire form, |
|
723 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
724 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
725 | + EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
726 | + 'form_section_id' => $this->html_id(true), |
|
727 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
728 | + 'other_data' => $this->get_other_js_data(), |
|
729 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
730 | + ); |
|
731 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
732 | + } |
|
733 | + } |
|
734 | + |
|
735 | + |
|
736 | + /** |
|
737 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
738 | + * This is primarily data added by inputs and forms in addition to any |
|
739 | + * scripts they might enqueue |
|
740 | + * |
|
741 | + * @param array $form_other_js_data |
|
742 | + * @return array |
|
743 | + * @throws EE_Error |
|
744 | + */ |
|
745 | + public function get_other_js_data($form_other_js_data = array()) |
|
746 | + { |
|
747 | + foreach ($this->subsections() as $subsection) { |
|
748 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
749 | + } |
|
750 | + return $form_other_js_data; |
|
751 | + } |
|
752 | + |
|
753 | + |
|
754 | + /** |
|
755 | + * Gets a flat array of inputs for this form section and its subsections. |
|
756 | + * Keys are their form names, and values are the inputs themselves |
|
757 | + * |
|
758 | + * @return EE_Form_Input_Base |
|
759 | + * @throws EE_Error |
|
760 | + */ |
|
761 | + public function inputs_in_subsections() |
|
762 | + { |
|
763 | + $inputs = array(); |
|
764 | + foreach ($this->subsections() as $subsection) { |
|
765 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
766 | + $inputs[ $subsection->html_name() ] = $subsection; |
|
767 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
768 | + $inputs += $subsection->inputs_in_subsections(); |
|
769 | + } |
|
770 | + } |
|
771 | + return $inputs; |
|
772 | + } |
|
773 | + |
|
774 | + |
|
775 | + /** |
|
776 | + * Gets a flat array of all the validation errors. |
|
777 | + * Keys are html names (because those should be unique) |
|
778 | + * and values are a string of all their validation errors |
|
779 | + * |
|
780 | + * @return string[] |
|
781 | + * @throws EE_Error |
|
782 | + */ |
|
783 | + public function subsection_validation_errors_by_html_name() |
|
784 | + { |
|
785 | + $inputs = $this->inputs(); |
|
786 | + $errors = array(); |
|
787 | + foreach ($inputs as $form_input) { |
|
788 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
789 | + $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
790 | + } |
|
791 | + } |
|
792 | + return $errors; |
|
793 | + } |
|
794 | + |
|
795 | + |
|
796 | + /** |
|
797 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
798 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
799 | + * |
|
800 | + * @throws InvalidArgumentException |
|
801 | + * @throws InvalidInterfaceException |
|
802 | + * @throws InvalidDataTypeException |
|
803 | + */ |
|
804 | + public static function localize_script_for_all_forms() |
|
805 | + { |
|
806 | + //allow inputs and stuff to hook in their JS and stuff here |
|
807 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
808 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
809 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
810 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
811 | + : 'wp_default'; |
|
812 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
813 | + wp_enqueue_script('ee_form_section_validation'); |
|
814 | + wp_localize_script( |
|
815 | + 'ee_form_section_validation', |
|
816 | + 'ee_form_section_vars', |
|
817 | + EE_Form_Section_Proper::$_js_localization |
|
818 | + ); |
|
819 | + } |
|
820 | + |
|
821 | + |
|
822 | + /** |
|
823 | + * ensure_scripts_localized |
|
824 | + * |
|
825 | + * @throws EE_Error |
|
826 | + */ |
|
827 | + public function ensure_scripts_localized() |
|
828 | + { |
|
829 | + if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
830 | + $this->_enqueue_and_localize_form_js(); |
|
831 | + } |
|
832 | + } |
|
833 | + |
|
834 | + |
|
835 | + /** |
|
836 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
837 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
838 | + * |
|
839 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
840 | + */ |
|
841 | + private static function _get_localized_error_messages() |
|
842 | + { |
|
843 | + return array( |
|
844 | + 'validUrl' => esc_html__('This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg', 'event_espresso'), |
|
845 | + 'regex' => esc_html__('Please check your input', 'event_espresso'), |
|
846 | + ); |
|
847 | + } |
|
848 | + |
|
849 | + |
|
850 | + /** |
|
851 | + * @return array |
|
852 | + */ |
|
853 | + public static function js_localization() |
|
854 | + { |
|
855 | + return self::$_js_localization; |
|
856 | + } |
|
857 | + |
|
858 | + |
|
859 | + /** |
|
860 | + * @return void |
|
861 | + */ |
|
862 | + public static function reset_js_localization() |
|
863 | + { |
|
864 | + self::$_js_localization = array(); |
|
865 | + } |
|
866 | + |
|
867 | + |
|
868 | + /** |
|
869 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
870 | + * See parent function for more... |
|
871 | + * |
|
872 | + * @return array |
|
873 | + * @throws EE_Error |
|
874 | + */ |
|
875 | + public function get_jquery_validation_rules() |
|
876 | + { |
|
877 | + $jquery_validation_rules = array(); |
|
878 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
879 | + $jquery_validation_rules = array_merge( |
|
880 | + $jquery_validation_rules, |
|
881 | + $subsection->get_jquery_validation_rules() |
|
882 | + ); |
|
883 | + } |
|
884 | + return $jquery_validation_rules; |
|
885 | + } |
|
886 | + |
|
887 | + |
|
888 | + /** |
|
889 | + * Sanitizes all the data and sets the sanitized value of each field |
|
890 | + * |
|
891 | + * @param array $req_data like $_POST |
|
892 | + * @return void |
|
893 | + * @throws EE_Error |
|
894 | + */ |
|
895 | + protected function _normalize($req_data) |
|
896 | + { |
|
897 | + $this->_received_submission = true; |
|
898 | + $this->_validation_errors = array(); |
|
899 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
900 | + try { |
|
901 | + $subsection->_normalize($req_data); |
|
902 | + } catch (EE_Validation_Error $e) { |
|
903 | + $subsection->add_validation_error($e); |
|
904 | + } |
|
905 | + } |
|
906 | + } |
|
907 | + |
|
908 | + |
|
909 | + /** |
|
910 | + * Performs validation on this form section and its subsections. |
|
911 | + * For each subsection, |
|
912 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
913 | + * and passes it the subsection, then calls _validate on that subsection. |
|
914 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
915 | + * you would be best to override this _validate method, |
|
916 | + * calling parent::_validate() first. |
|
917 | + * |
|
918 | + * @throws EE_Error |
|
919 | + */ |
|
920 | + protected function _validate() |
|
921 | + { |
|
922 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
923 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
924 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
925 | + } |
|
926 | + $subsection->_validate(); |
|
927 | + } |
|
928 | + } |
|
929 | + |
|
930 | + |
|
931 | + /** |
|
932 | + * Gets all the validated inputs for the form section |
|
933 | + * |
|
934 | + * @return array |
|
935 | + * @throws EE_Error |
|
936 | + */ |
|
937 | + public function valid_data() |
|
938 | + { |
|
939 | + $inputs = array(); |
|
940 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
941 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
942 | + $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
943 | + } elseif ($subsection instanceof EE_Form_Input_Base) { |
|
944 | + $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
945 | + } |
|
946 | + } |
|
947 | + return $inputs; |
|
948 | + } |
|
949 | + |
|
950 | + |
|
951 | + /** |
|
952 | + * Gets all the inputs on this form section |
|
953 | + * |
|
954 | + * @return EE_Form_Input_Base[] |
|
955 | + * @throws EE_Error |
|
956 | + */ |
|
957 | + public function inputs() |
|
958 | + { |
|
959 | + $inputs = array(); |
|
960 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
961 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
962 | + $inputs[ $subsection_name ] = $subsection; |
|
963 | + } |
|
964 | + } |
|
965 | + return $inputs; |
|
966 | + } |
|
967 | + |
|
968 | + |
|
969 | + /** |
|
970 | + * Gets all the subsections which are a proper form |
|
971 | + * |
|
972 | + * @return EE_Form_Section_Proper[] |
|
973 | + * @throws EE_Error |
|
974 | + */ |
|
975 | + public function subforms() |
|
976 | + { |
|
977 | + $form_sections = array(); |
|
978 | + foreach ($this->subsections() as $name => $obj) { |
|
979 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
980 | + $form_sections[ $name ] = $obj; |
|
981 | + } |
|
982 | + } |
|
983 | + return $form_sections; |
|
984 | + } |
|
985 | + |
|
986 | + |
|
987 | + /** |
|
988 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
989 | + * Consider using inputs() or subforms() |
|
990 | + * if you only want form inputs or proper form sections. |
|
991 | + * |
|
992 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
993 | + * leave this as TRUE so that the inputs will be properly |
|
994 | + * configured. However, some client code may be ok with |
|
995 | + * construction finalize being called later |
|
996 | + * (realizing that the subsections' html names might not be |
|
997 | + * set yet, etc.) |
|
998 | + * @return EE_Form_Section_Proper[] |
|
999 | + * @throws EE_Error |
|
1000 | + */ |
|
1001 | + public function subsections($require_construction_to_be_finalized = true) |
|
1002 | + { |
|
1003 | + if ($require_construction_to_be_finalized) { |
|
1004 | + $this->ensure_construct_finalized_called(); |
|
1005 | + } |
|
1006 | + return $this->_subsections; |
|
1007 | + } |
|
1008 | + |
|
1009 | + |
|
1010 | + /** |
|
1011 | + * Returns a simple array where keys are input names, and values are their normalized |
|
1012 | + * values. (Similar to calling get_input_value on inputs) |
|
1013 | + * |
|
1014 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1015 | + * or just this forms' direct children inputs |
|
1016 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1017 | + * or allow multidimensional array |
|
1018 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1019 | + * with array keys being input names |
|
1020 | + * (regardless of whether they are from a subsection or not), |
|
1021 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1022 | + * where keys are always subsection names and values are either |
|
1023 | + * the input's normalized value, or an array like the top-level array |
|
1024 | + * @throws EE_Error |
|
1025 | + */ |
|
1026 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
1027 | + { |
|
1028 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
1029 | + } |
|
1030 | + |
|
1031 | + |
|
1032 | + /** |
|
1033 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
1034 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
1035 | + * is not necessarily the value we want to display to users. This creates an array |
|
1036 | + * where keys are the input names, and values are their display values |
|
1037 | + * |
|
1038 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1039 | + * or just this forms' direct children inputs |
|
1040 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1041 | + * or allow multidimensional array |
|
1042 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1043 | + * with array keys being input names |
|
1044 | + * (regardless of whether they are from a subsection or not), |
|
1045 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1046 | + * where keys are always subsection names and values are either |
|
1047 | + * the input's normalized value, or an array like the top-level array |
|
1048 | + * @throws EE_Error |
|
1049 | + */ |
|
1050 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1051 | + { |
|
1052 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1053 | + } |
|
1054 | + |
|
1055 | + |
|
1056 | + /** |
|
1057 | + * Gets the input values from the form |
|
1058 | + * |
|
1059 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
1060 | + * or just the normalized value |
|
1061 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1062 | + * or just this forms' direct children inputs |
|
1063 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1064 | + * or allow multidimensional array |
|
1065 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1066 | + * input names (regardless of whether they are from a subsection or not), |
|
1067 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1068 | + * where keys are always subsection names and values are either |
|
1069 | + * the input's normalized value, or an array like the top-level array |
|
1070 | + * @throws EE_Error |
|
1071 | + */ |
|
1072 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1073 | + { |
|
1074 | + $input_values = array(); |
|
1075 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1076 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1077 | + $input_values[ $subsection_name ] = $pretty |
|
1078 | + ? $subsection->pretty_value() |
|
1079 | + : $subsection->normalized_value(); |
|
1080 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1081 | + $subform_input_values = $subsection->_input_values( |
|
1082 | + $pretty, |
|
1083 | + $include_subform_inputs, |
|
1084 | + $flatten |
|
1085 | + ); |
|
1086 | + if ($flatten) { |
|
1087 | + $input_values = array_merge($input_values, $subform_input_values); |
|
1088 | + } else { |
|
1089 | + $input_values[ $subsection_name ] = $subform_input_values; |
|
1090 | + } |
|
1091 | + } |
|
1092 | + } |
|
1093 | + return $input_values; |
|
1094 | + } |
|
1095 | + |
|
1096 | + |
|
1097 | + /** |
|
1098 | + * Gets the originally submitted input values from the form |
|
1099 | + * |
|
1100 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1101 | + * or just this forms' direct children inputs |
|
1102 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1103 | + * with array keys being input names |
|
1104 | + * (regardless of whether they are from a subsection or not), |
|
1105 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1106 | + * where keys are always subsection names and values are either |
|
1107 | + * the input's normalized value, or an array like the top-level array |
|
1108 | + * @throws EE_Error |
|
1109 | + */ |
|
1110 | + public function submitted_values($include_subforms = false) |
|
1111 | + { |
|
1112 | + $submitted_values = array(); |
|
1113 | + foreach ($this->subsections() as $subsection) { |
|
1114 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1115 | + // is this input part of an array of inputs? |
|
1116 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
1117 | + $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
1118 | + explode( |
|
1119 | + '[', |
|
1120 | + str_replace(']', '', $subsection->html_name()) |
|
1121 | + ), |
|
1122 | + $subsection->raw_value() |
|
1123 | + ); |
|
1124 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1125 | + } else { |
|
1126 | + $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
1127 | + } |
|
1128 | + } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1129 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1130 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1131 | + } |
|
1132 | + } |
|
1133 | + return $submitted_values; |
|
1134 | + } |
|
1135 | + |
|
1136 | + |
|
1137 | + /** |
|
1138 | + * Indicates whether or not this form has received a submission yet |
|
1139 | + * (ie, had receive_form_submission called on it yet) |
|
1140 | + * |
|
1141 | + * @return boolean |
|
1142 | + * @throws EE_Error |
|
1143 | + */ |
|
1144 | + public function has_received_submission() |
|
1145 | + { |
|
1146 | + $this->ensure_construct_finalized_called(); |
|
1147 | + return $this->_received_submission; |
|
1148 | + } |
|
1149 | + |
|
1150 | + |
|
1151 | + /** |
|
1152 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
1153 | + * Removes the listed inputs from the form |
|
1154 | + * |
|
1155 | + * @param array $inputs_to_exclude values are the input names |
|
1156 | + * @return void |
|
1157 | + */ |
|
1158 | + public function exclude(array $inputs_to_exclude = array()) |
|
1159 | + { |
|
1160 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1161 | + unset($this->_subsections[ $input_to_exclude_name ]); |
|
1162 | + } |
|
1163 | + } |
|
1164 | + |
|
1165 | + |
|
1166 | + /** |
|
1167 | + * @param array $inputs_to_hide |
|
1168 | + * @throws EE_Error |
|
1169 | + */ |
|
1170 | + public function hide(array $inputs_to_hide = array()) |
|
1171 | + { |
|
1172 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
1173 | + $input = $this->get_input($input_to_hide); |
|
1174 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1175 | + } |
|
1176 | + } |
|
1177 | + |
|
1178 | + |
|
1179 | + /** |
|
1180 | + * add_subsections |
|
1181 | + * Adds the listed subsections to the form section. |
|
1182 | + * If $subsection_name_to_target is provided, |
|
1183 | + * then new subsections are added before or after that subsection, |
|
1184 | + * otherwise to the start or end of the entire subsections array. |
|
1185 | + * |
|
1186 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1187 | + * where keys are their names |
|
1188 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1189 | + * should be added before or after |
|
1190 | + * IF $subsection_name_to_target is null, |
|
1191 | + * then $new_subsections will be added to |
|
1192 | + * the beginning or end of the entire subsections array |
|
1193 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
1194 | + * $subsection_name_to_target, |
|
1195 | + * or if $subsection_name_to_target is null, |
|
1196 | + * before or after entire subsections array |
|
1197 | + * @return void |
|
1198 | + * @throws EE_Error |
|
1199 | + */ |
|
1200 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1201 | + { |
|
1202 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
1203 | + if (! $subsection instanceof EE_Form_Section_Base) { |
|
1204 | + EE_Error::add_error( |
|
1205 | + sprintf( |
|
1206 | + esc_html__( |
|
1207 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1208 | + 'event_espresso' |
|
1209 | + ), |
|
1210 | + get_class($subsection), |
|
1211 | + $subsection_name, |
|
1212 | + $this->name() |
|
1213 | + ) |
|
1214 | + ); |
|
1215 | + unset($new_subsections[ $subsection_name ]); |
|
1216 | + } |
|
1217 | + } |
|
1218 | + $this->_subsections = EEH_Array::insert_into_array( |
|
1219 | + $this->_subsections, |
|
1220 | + $new_subsections, |
|
1221 | + $subsection_name_to_target, |
|
1222 | + $add_before |
|
1223 | + ); |
|
1224 | + if ($this->_construction_finalized) { |
|
1225 | + foreach ($this->_subsections as $name => $subsection) { |
|
1226 | + $subsection->_construct_finalize($this, $name); |
|
1227 | + } |
|
1228 | + } |
|
1229 | + } |
|
1230 | + |
|
1231 | + |
|
1232 | + /** |
|
1233 | + * Just gets all validatable subsections to clean their sensitive data |
|
1234 | + * |
|
1235 | + * @throws EE_Error |
|
1236 | + */ |
|
1237 | + public function clean_sensitive_data() |
|
1238 | + { |
|
1239 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1240 | + $subsection->clean_sensitive_data(); |
|
1241 | + } |
|
1242 | + } |
|
1243 | + |
|
1244 | + |
|
1245 | + /** |
|
1246 | + * @param string $form_submission_error_message |
|
1247 | + */ |
|
1248 | + public function set_submission_error_message($form_submission_error_message = '') |
|
1249 | + { |
|
1250 | + $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
1251 | + ? $form_submission_error_message |
|
1252 | + : esc_html__('Form submission failed due to errors', 'event_espresso'); |
|
1253 | + } |
|
1254 | + |
|
1255 | + |
|
1256 | + /** |
|
1257 | + * @return string |
|
1258 | + */ |
|
1259 | + public function submission_error_message() |
|
1260 | + { |
|
1261 | + return $this->_form_submission_error_message; |
|
1262 | + } |
|
1263 | + |
|
1264 | + |
|
1265 | + /** |
|
1266 | + * @param string $form_submission_success_message |
|
1267 | + */ |
|
1268 | + public function set_submission_success_message($form_submission_success_message) |
|
1269 | + { |
|
1270 | + $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
1271 | + ? $form_submission_success_message |
|
1272 | + : esc_html__('Form submitted successfully', 'event_espresso'); |
|
1273 | + } |
|
1274 | + |
|
1275 | + |
|
1276 | + /** |
|
1277 | + * @return string |
|
1278 | + */ |
|
1279 | + public function submission_success_message() |
|
1280 | + { |
|
1281 | + return $this->_form_submission_success_message; |
|
1282 | + } |
|
1283 | + |
|
1284 | + |
|
1285 | + /** |
|
1286 | + * Returns the prefix that should be used on child of this form section for |
|
1287 | + * their html names. If this form section itself has a parent, prepends ITS |
|
1288 | + * prefix onto this form section's prefix. Used primarily by |
|
1289 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1290 | + * |
|
1291 | + * @return string |
|
1292 | + * @throws EE_Error |
|
1293 | + */ |
|
1294 | + public function html_name_prefix() |
|
1295 | + { |
|
1296 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1297 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1298 | + } |
|
1299 | + return $this->name(); |
|
1300 | + } |
|
1301 | + |
|
1302 | + |
|
1303 | + /** |
|
1304 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1305 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
1306 | + * was set, which is probably nothing, or the classname) |
|
1307 | + * |
|
1308 | + * @return string |
|
1309 | + * @throws EE_Error |
|
1310 | + */ |
|
1311 | + public function name() |
|
1312 | + { |
|
1313 | + $this->ensure_construct_finalized_called(); |
|
1314 | + return parent::name(); |
|
1315 | + } |
|
1316 | + |
|
1317 | + |
|
1318 | + /** |
|
1319 | + * @return EE_Form_Section_Proper |
|
1320 | + * @throws EE_Error |
|
1321 | + */ |
|
1322 | + public function parent_section() |
|
1323 | + { |
|
1324 | + $this->ensure_construct_finalized_called(); |
|
1325 | + return parent::parent_section(); |
|
1326 | + } |
|
1327 | + |
|
1328 | + |
|
1329 | + /** |
|
1330 | + * make sure construction finalized was called, otherwise children might not be ready |
|
1331 | + * |
|
1332 | + * @return void |
|
1333 | + * @throws EE_Error |
|
1334 | + */ |
|
1335 | + public function ensure_construct_finalized_called() |
|
1336 | + { |
|
1337 | + if (! $this->_construction_finalized) { |
|
1338 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1339 | + } |
|
1340 | + } |
|
1341 | + |
|
1342 | + |
|
1343 | + /** |
|
1344 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1345 | + * are in teh form data. If any are found, returns true. Else false |
|
1346 | + * |
|
1347 | + * @param array $req_data |
|
1348 | + * @return boolean |
|
1349 | + * @throws EE_Error |
|
1350 | + */ |
|
1351 | + public function form_data_present_in($req_data = null) |
|
1352 | + { |
|
1353 | + if ($req_data === null) { |
|
1354 | + $req_data = $_POST; |
|
1355 | + } |
|
1356 | + foreach ($this->subsections() as $subsection) { |
|
1357 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1358 | + if ($subsection->form_data_present_in($req_data)) { |
|
1359 | + return true; |
|
1360 | + } |
|
1361 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1362 | + if ($subsection->form_data_present_in($req_data)) { |
|
1363 | + return true; |
|
1364 | + } |
|
1365 | + } |
|
1366 | + } |
|
1367 | + return false; |
|
1368 | + } |
|
1369 | + |
|
1370 | + |
|
1371 | + /** |
|
1372 | + * Gets validation errors for this form section and subsections |
|
1373 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1374 | + * gets the validation errors for ALL subsection |
|
1375 | + * |
|
1376 | + * @return EE_Validation_Error[] |
|
1377 | + * @throws EE_Error |
|
1378 | + */ |
|
1379 | + public function get_validation_errors_accumulated() |
|
1380 | + { |
|
1381 | + $validation_errors = $this->get_validation_errors(); |
|
1382 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1383 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
1384 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1385 | + } else { |
|
1386 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1387 | + } |
|
1388 | + if ($validation_errors_on_this_subsection) { |
|
1389 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1390 | + } |
|
1391 | + } |
|
1392 | + return $validation_errors; |
|
1393 | + } |
|
1394 | + |
|
1395 | + |
|
1396 | + /** |
|
1397 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
1398 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1399 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
1400 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1401 | + * which will be returned. |
|
1402 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1403 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1404 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1405 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1406 | + * Etc |
|
1407 | + * |
|
1408 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1409 | + * @return EE_Form_Section_Base |
|
1410 | + * @throws EE_Error |
|
1411 | + */ |
|
1412 | + public function find_section_from_path($form_section_path) |
|
1413 | + { |
|
1414 | + //check if we can find the input from purely going straight up the tree |
|
1415 | + $input = parent::find_section_from_path($form_section_path); |
|
1416 | + if ($input instanceof EE_Form_Section_Base) { |
|
1417 | + return $input; |
|
1418 | + } |
|
1419 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
1420 | + if ($next_slash_pos !== false) { |
|
1421 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1422 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1423 | + } else { |
|
1424 | + $child_section_name = $form_section_path; |
|
1425 | + $subpath = ''; |
|
1426 | + } |
|
1427 | + $child_section = $this->get_subsection($child_section_name); |
|
1428 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
1429 | + return $child_section->find_section_from_path($subpath); |
|
1430 | + } |
|
1431 | + return null; |
|
1432 | + } |
|
1433 | 1433 | } |
1434 | 1434 |
@@ -99,8 +99,8 @@ discard block |
||
99 | 99 | //AND we are going to make sure they're in that specified order |
100 | 100 | $reordered_subsections = array(); |
101 | 101 | foreach ($options_array['include'] as $input_name) { |
102 | - if (isset($this->_subsections[ $input_name ])) { |
|
103 | - $reordered_subsections[ $input_name ] = $this->_subsections[ $input_name ]; |
|
102 | + if (isset($this->_subsections[$input_name])) { |
|
103 | + $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | $this->_subsections = $reordered_subsections; |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | if (isset($options_array['layout_strategy'])) { |
113 | 113 | $this->_layout_strategy = $options_array['layout_strategy']; |
114 | 114 | } |
115 | - if (! $this->_layout_strategy) { |
|
115 | + if ( ! $this->_layout_strategy) { |
|
116 | 116 | $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
117 | 117 | } |
118 | 118 | $this->_layout_strategy->_construct_finalize($this); |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | if ($validate) { |
283 | 283 | $this->_validate(); |
284 | 284 | //if it's invalid, we're going to want to re-display so remember what they submitted |
285 | - if (! $this->is_valid()) { |
|
285 | + if ( ! $this->is_valid()) { |
|
286 | 286 | $this->store_submitted_form_data_in_session(); |
287 | 287 | } |
288 | 288 | } |
@@ -392,11 +392,11 @@ discard block |
||
392 | 392 | public function populate_defaults($default_data) |
393 | 393 | { |
394 | 394 | foreach ($this->subsections(false) as $subsection_name => $subsection) { |
395 | - if (isset($default_data[ $subsection_name ])) { |
|
395 | + if (isset($default_data[$subsection_name])) { |
|
396 | 396 | if ($subsection instanceof EE_Form_Input_Base) { |
397 | - $subsection->set_default($default_data[ $subsection_name ]); |
|
397 | + $subsection->set_default($default_data[$subsection_name]); |
|
398 | 398 | } elseif ($subsection instanceof EE_Form_Section_Proper) { |
399 | - $subsection->populate_defaults($default_data[ $subsection_name ]); |
|
399 | + $subsection->populate_defaults($default_data[$subsection_name]); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | } |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | */ |
412 | 412 | public function subsection_exists($name) |
413 | 413 | { |
414 | - return isset($this->_subsections[ $name ]) ? true : false; |
|
414 | + return isset($this->_subsections[$name]) ? true : false; |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | if ($require_construction_to_be_finalized) { |
434 | 434 | $this->ensure_construct_finalized_called(); |
435 | 435 | } |
436 | - return $this->subsection_exists($name) ? $this->_subsections[ $name ] : null; |
|
436 | + return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | $validatable_subsections = array(); |
449 | 449 | foreach ($this->subsections() as $name => $obj) { |
450 | 450 | if ($obj instanceof EE_Form_Section_Validatable) { |
451 | - $validatable_subsections[ $name ] = $obj; |
|
451 | + $validatable_subsections[$name] = $obj; |
|
452 | 452 | } |
453 | 453 | } |
454 | 454 | return $validatable_subsections; |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | $name, |
476 | 476 | $require_construction_to_be_finalized |
477 | 477 | ); |
478 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
478 | + if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
479 | 479 | throw new EE_Error( |
480 | 480 | sprintf( |
481 | 481 | esc_html__( |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | $name, |
513 | 513 | $require_construction_to_be_finalized |
514 | 514 | ); |
515 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
515 | + if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
516 | 516 | throw new EE_Error( |
517 | 517 | sprintf( |
518 | 518 | esc_html__( |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | */ |
552 | 552 | public function is_valid() |
553 | 553 | { |
554 | - if (! $this->has_received_submission()) { |
|
554 | + if ( ! $this->has_received_submission()) { |
|
555 | 555 | throw new EE_Error( |
556 | 556 | sprintf( |
557 | 557 | esc_html__( |
@@ -561,14 +561,14 @@ discard block |
||
561 | 561 | ) |
562 | 562 | ); |
563 | 563 | } |
564 | - if (! parent::is_valid()) { |
|
564 | + if ( ! parent::is_valid()) { |
|
565 | 565 | return false; |
566 | 566 | } |
567 | 567 | // ok so no general errors to this entire form section. |
568 | 568 | // so let's check the subsections, but only set errors if that hasn't been done yet |
569 | 569 | $set_submission_errors = $this->submission_error_message() === ''; |
570 | 570 | foreach ($this->get_validatable_subsections() as $subsection) { |
571 | - if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
571 | + if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
572 | 572 | if ($set_submission_errors) { |
573 | 573 | $this->set_submission_error_message( |
574 | 574 | $subsection->get_validation_error_string() |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | */ |
589 | 589 | protected function _set_default_name_if_empty() |
590 | 590 | { |
591 | - if (! $this->_name) { |
|
591 | + if ( ! $this->_name) { |
|
592 | 592 | $classname = get_class($this); |
593 | 593 | $default_name = str_replace('EE_', '', $classname); |
594 | 594 | $this->_name = $default_name; |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | { |
679 | 679 | wp_register_script( |
680 | 680 | 'ee_form_section_validation', |
681 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
681 | + EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js', |
|
682 | 682 | array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
683 | 683 | EVENT_ESPRESSO_VERSION, |
684 | 684 | true |
@@ -722,13 +722,13 @@ discard block |
||
722 | 722 | // we only want to localize vars ONCE for the entire form, |
723 | 723 | // so if the form section doesn't have a parent, then it must be the top dog |
724 | 724 | if ($return_for_subsection || ! $this->parent_section()) { |
725 | - EE_Form_Section_Proper::$_js_localization['form_data'][ $this->html_id() ] = array( |
|
725 | + EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
726 | 726 | 'form_section_id' => $this->html_id(true), |
727 | 727 | 'validation_rules' => $this->get_jquery_validation_rules(), |
728 | 728 | 'other_data' => $this->get_other_js_data(), |
729 | 729 | 'errors' => $this->subsection_validation_errors_by_html_name(), |
730 | 730 | ); |
731 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
731 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
732 | 732 | } |
733 | 733 | } |
734 | 734 | |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | $inputs = array(); |
764 | 764 | foreach ($this->subsections() as $subsection) { |
765 | 765 | if ($subsection instanceof EE_Form_Input_Base) { |
766 | - $inputs[ $subsection->html_name() ] = $subsection; |
|
766 | + $inputs[$subsection->html_name()] = $subsection; |
|
767 | 767 | } elseif ($subsection instanceof EE_Form_Section_Proper) { |
768 | 768 | $inputs += $subsection->inputs_in_subsections(); |
769 | 769 | } |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | $errors = array(); |
787 | 787 | foreach ($inputs as $form_input) { |
788 | 788 | if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
789 | - $errors[ $form_input->html_name() ] = $form_input->get_validation_error_string(); |
|
789 | + $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
790 | 790 | } |
791 | 791 | } |
792 | 792 | return $errors; |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
810 | 810 | ? EE_Registry::instance()->CFG->registration->email_validation_level |
811 | 811 | : 'wp_default'; |
812 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
812 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
813 | 813 | wp_enqueue_script('ee_form_section_validation'); |
814 | 814 | wp_localize_script( |
815 | 815 | 'ee_form_section_validation', |
@@ -826,7 +826,7 @@ discard block |
||
826 | 826 | */ |
827 | 827 | public function ensure_scripts_localized() |
828 | 828 | { |
829 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
829 | + if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
830 | 830 | $this->_enqueue_and_localize_form_js(); |
831 | 831 | } |
832 | 832 | } |
@@ -920,8 +920,8 @@ discard block |
||
920 | 920 | protected function _validate() |
921 | 921 | { |
922 | 922 | foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
923 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
924 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
923 | + if (method_exists($this, '_validate_'.$subsection_name)) { |
|
924 | + call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection)); |
|
925 | 925 | } |
926 | 926 | $subsection->_validate(); |
927 | 927 | } |
@@ -939,9 +939,9 @@ discard block |
||
939 | 939 | $inputs = array(); |
940 | 940 | foreach ($this->subsections() as $subsection_name => $subsection) { |
941 | 941 | if ($subsection instanceof EE_Form_Section_Proper) { |
942 | - $inputs[ $subsection_name ] = $subsection->valid_data(); |
|
942 | + $inputs[$subsection_name] = $subsection->valid_data(); |
|
943 | 943 | } elseif ($subsection instanceof EE_Form_Input_Base) { |
944 | - $inputs[ $subsection_name ] = $subsection->normalized_value(); |
|
944 | + $inputs[$subsection_name] = $subsection->normalized_value(); |
|
945 | 945 | } |
946 | 946 | } |
947 | 947 | return $inputs; |
@@ -959,7 +959,7 @@ discard block |
||
959 | 959 | $inputs = array(); |
960 | 960 | foreach ($this->subsections() as $subsection_name => $subsection) { |
961 | 961 | if ($subsection instanceof EE_Form_Input_Base) { |
962 | - $inputs[ $subsection_name ] = $subsection; |
|
962 | + $inputs[$subsection_name] = $subsection; |
|
963 | 963 | } |
964 | 964 | } |
965 | 965 | return $inputs; |
@@ -977,7 +977,7 @@ discard block |
||
977 | 977 | $form_sections = array(); |
978 | 978 | foreach ($this->subsections() as $name => $obj) { |
979 | 979 | if ($obj instanceof EE_Form_Section_Proper) { |
980 | - $form_sections[ $name ] = $obj; |
|
980 | + $form_sections[$name] = $obj; |
|
981 | 981 | } |
982 | 982 | } |
983 | 983 | return $form_sections; |
@@ -1074,7 +1074,7 @@ discard block |
||
1074 | 1074 | $input_values = array(); |
1075 | 1075 | foreach ($this->subsections() as $subsection_name => $subsection) { |
1076 | 1076 | if ($subsection instanceof EE_Form_Input_Base) { |
1077 | - $input_values[ $subsection_name ] = $pretty |
|
1077 | + $input_values[$subsection_name] = $pretty |
|
1078 | 1078 | ? $subsection->pretty_value() |
1079 | 1079 | : $subsection->normalized_value(); |
1080 | 1080 | } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
@@ -1086,7 +1086,7 @@ discard block |
||
1086 | 1086 | if ($flatten) { |
1087 | 1087 | $input_values = array_merge($input_values, $subform_input_values); |
1088 | 1088 | } else { |
1089 | - $input_values[ $subsection_name ] = $subform_input_values; |
|
1089 | + $input_values[$subsection_name] = $subform_input_values; |
|
1090 | 1090 | } |
1091 | 1091 | } |
1092 | 1092 | } |
@@ -1114,7 +1114,7 @@ discard block |
||
1114 | 1114 | if ($subsection instanceof EE_Form_Input_Base) { |
1115 | 1115 | // is this input part of an array of inputs? |
1116 | 1116 | if (strpos($subsection->html_name(), '[') !== false) { |
1117 | - $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
1117 | + $full_input_name = EEH_Array::convert_array_values_to_keys( |
|
1118 | 1118 | explode( |
1119 | 1119 | '[', |
1120 | 1120 | str_replace(']', '', $subsection->html_name()) |
@@ -1123,7 +1123,7 @@ discard block |
||
1123 | 1123 | ); |
1124 | 1124 | $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
1125 | 1125 | } else { |
1126 | - $submitted_values[ $subsection->html_name() ] = $subsection->raw_value(); |
|
1126 | + $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
1127 | 1127 | } |
1128 | 1128 | } elseif ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
1129 | 1129 | $subform_input_values = $subsection->submitted_values($include_subforms); |
@@ -1158,7 +1158,7 @@ discard block |
||
1158 | 1158 | public function exclude(array $inputs_to_exclude = array()) |
1159 | 1159 | { |
1160 | 1160 | foreach ($inputs_to_exclude as $input_to_exclude_name) { |
1161 | - unset($this->_subsections[ $input_to_exclude_name ]); |
|
1161 | + unset($this->_subsections[$input_to_exclude_name]); |
|
1162 | 1162 | } |
1163 | 1163 | } |
1164 | 1164 | |
@@ -1200,7 +1200,7 @@ discard block |
||
1200 | 1200 | public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
1201 | 1201 | { |
1202 | 1202 | foreach ($new_subsections as $subsection_name => $subsection) { |
1203 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
1203 | + if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
1204 | 1204 | EE_Error::add_error( |
1205 | 1205 | sprintf( |
1206 | 1206 | esc_html__( |
@@ -1212,7 +1212,7 @@ discard block |
||
1212 | 1212 | $this->name() |
1213 | 1213 | ) |
1214 | 1214 | ); |
1215 | - unset($new_subsections[ $subsection_name ]); |
|
1215 | + unset($new_subsections[$subsection_name]); |
|
1216 | 1216 | } |
1217 | 1217 | } |
1218 | 1218 | $this->_subsections = EEH_Array::insert_into_array( |
@@ -1294,7 +1294,7 @@ discard block |
||
1294 | 1294 | public function html_name_prefix() |
1295 | 1295 | { |
1296 | 1296 | if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
1297 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1297 | + return $this->parent_section()->html_name_prefix().'['.$this->name().']'; |
|
1298 | 1298 | } |
1299 | 1299 | return $this->name(); |
1300 | 1300 | } |
@@ -1334,7 +1334,7 @@ discard block |
||
1334 | 1334 | */ |
1335 | 1335 | public function ensure_construct_finalized_called() |
1336 | 1336 | { |
1337 | - if (! $this->_construction_finalized) { |
|
1337 | + if ( ! $this->_construction_finalized) { |
|
1338 | 1338 | $this->_construct_finalize($this->_parent_section, $this->_name); |
1339 | 1339 | } |
1340 | 1340 | } |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use \EventEspresso\core\exceptions\SendMessageException; |
3 | 3 | |
4 | 4 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | /** |
@@ -18,693 +18,693 @@ discard block |
||
18 | 18 | { |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * @type string reference for sending action |
|
23 | - */ |
|
24 | - const action_sending = 'sending'; |
|
25 | - |
|
26 | - /** |
|
27 | - * @type string reference for generation action |
|
28 | - */ |
|
29 | - const action_generating = 'generation'; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @type EE_Message_Repository $_message_repository |
|
34 | - */ |
|
35 | - protected $_message_repository; |
|
36 | - |
|
37 | - /** |
|
38 | - * Sets the limit of how many messages are generated per process. |
|
39 | - * |
|
40 | - * @type int |
|
41 | - */ |
|
42 | - protected $_batch_count; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * This is an array of cached queue items being stored in this object. |
|
47 | - * The array keys will be the ID of the EE_Message in the db if saved. If the EE_Message |
|
48 | - * is not saved to the db then its key will be an increment of "UNS" (i.e. UNS1, UNS2 etc.) |
|
49 | - * |
|
50 | - * @type EE_Message[] |
|
51 | - */ |
|
52 | - protected $_cached_queue_items; |
|
53 | - |
|
54 | - /** |
|
55 | - * Tracks the number of unsaved queue items. |
|
56 | - * |
|
57 | - * @type int |
|
58 | - */ |
|
59 | - protected $_unsaved_count = 0; |
|
60 | - |
|
61 | - /** |
|
62 | - * used to record if a do_messenger_hooks has already been called for a message type. This prevents multiple |
|
63 | - * hooks getting fired if users have setup their action/filter hooks to prevent duplicate calls. |
|
64 | - * |
|
65 | - * @type array |
|
66 | - */ |
|
67 | - protected $_did_hook = array(); |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * Constructor. |
|
72 | - * Setup all the initial properties and load a EE_Message_Repository. |
|
73 | - * |
|
74 | - * @param \EE_Message_Repository $message_repository |
|
75 | - */ |
|
76 | - public function __construct(EE_Message_Repository $message_repository) |
|
77 | - { |
|
78 | - $this->_batch_count = apply_filters('FHEE__EE_Messages_Queue___batch_count', 50); |
|
79 | - $this->_message_repository = $message_repository; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * Add a EE_Message object to the queue |
|
85 | - * |
|
86 | - * @param EE_Message $message |
|
87 | - * @param array $data This will be an array of data to attach to the object in the repository. If the |
|
88 | - * object is persisted, this data will be saved on an extra_meta object related to |
|
89 | - * EE_Message. |
|
90 | - * @param bool $preview Whether this EE_Message represents a preview or not. |
|
91 | - * @param bool $test_send This indicates whether to do a test send instead of actual send. A test send will |
|
92 | - * use the messenger send method but typically is based on preview data. |
|
93 | - * @return bool Whether the message was successfully added to the repository or not. |
|
94 | - */ |
|
95 | - public function add(EE_Message $message, $data = array(), $preview = false, $test_send = false) |
|
96 | - { |
|
97 | - $data['preview'] = $preview; |
|
98 | - $data['test_send'] = $test_send; |
|
99 | - return $this->_message_repository->add($message, $data); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Removes EE_Message from _queue that matches the given EE_Message if the pointer is on a matching EE_Message |
|
105 | - * |
|
106 | - * @param EE_Message $message The message to detach from the queue |
|
107 | - * @param bool $persist This flag indicates whether to attempt to delete the object from the db as well. |
|
108 | - * @return bool |
|
109 | - */ |
|
110 | - public function remove(EE_Message $message, $persist = false) |
|
111 | - { |
|
112 | - if ($persist && $this->_message_repository->current() !== $message) { |
|
113 | - //get pointer on right message |
|
114 | - if ($this->_message_repository->has($message)) { |
|
115 | - $this->_message_repository->rewind(); |
|
116 | - while ($this->_message_repository->valid()) { |
|
117 | - if ($this->_message_repository->current() === $message) { |
|
118 | - break; |
|
119 | - } |
|
120 | - $this->_message_repository->next(); |
|
121 | - } |
|
122 | - } else { |
|
123 | - return false; |
|
124 | - } |
|
125 | - } |
|
126 | - return $persist ? $this->_message_repository->delete() : $this->_message_repository->remove($message); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Persists all queued EE_Message objects to the db. |
|
132 | - * |
|
133 | - * @param bool $do_hooks_only @see EE_Message_Repository::saveAll |
|
134 | - * @return array @see EE_Messages_Repository::saveAll() for return values. |
|
135 | - */ |
|
136 | - public function save($do_hooks_only = false) |
|
137 | - { |
|
138 | - return $this->_message_repository->saveAll($do_hooks_only); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @return EE_Message_Repository |
|
144 | - */ |
|
145 | - public function get_message_repository() |
|
146 | - { |
|
147 | - return $this->_message_repository; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * This does the following things: |
|
153 | - * 1. Checks if there is a lock on generation (prevents race conditions). If there is a lock then exits (return |
|
154 | - * false). |
|
155 | - * 2. If no lock, sets lock, then retrieves a batch of non-generated EE_Message objects and adds to queue |
|
156 | - * 3. Returns bool. True = batch ready. False = no batch ready (or nothing available for generation). |
|
157 | - * Note: Callers should make sure they release the lock otherwise batch generation will be prevented from |
|
158 | - * continuing. The lock is on a transient that is set to expire after one hour as a fallback in case locks are not |
|
159 | - * removed. |
|
160 | - * |
|
161 | - * @return bool true if successfully retrieved batch, false no batch ready. |
|
162 | - */ |
|
163 | - public function get_batch_to_generate() |
|
164 | - { |
|
165 | - if ($this->is_locked(EE_Messages_Queue::action_generating)) { |
|
166 | - return false; |
|
167 | - } |
|
168 | - |
|
169 | - //lock batch generation to prevent race conditions. |
|
170 | - $this->lock_queue(EE_Messages_Queue::action_generating); |
|
171 | - |
|
172 | - $query_args = array( |
|
173 | - // key 0 = where conditions |
|
174 | - 0 => array('STS_ID' => EEM_Message::status_incomplete), |
|
175 | - 'order_by' => $this->_get_priority_orderby(), |
|
176 | - 'limit' => $this->_batch_count, |
|
177 | - ); |
|
178 | - $messages = EEM_Message::instance()->get_all($query_args); |
|
179 | - |
|
180 | - if ( ! $messages) { |
|
181 | - return false; //nothing to generate |
|
182 | - } |
|
183 | - |
|
184 | - foreach ($messages as $message) { |
|
185 | - if ($message instanceof EE_Message) { |
|
186 | - $data = $message->all_extra_meta_array(); |
|
187 | - $this->add($message, $data); |
|
188 | - } |
|
189 | - } |
|
190 | - return true; |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * This does the following things: |
|
196 | - * 1. Checks if there is a lock on sending (prevents race conditions). If there is a lock then exits (return |
|
197 | - * false). |
|
198 | - * 2. Grabs the allowed number of messages to send for the rate_limit. If cannot send any more messages, then |
|
199 | - * return false. |
|
200 | - * 2. If no lock, sets lock, then retrieves a batch of EE_Message objects, adds to queue and triggers execution. |
|
201 | - * 3. On success or unsuccessful send, sets status appropriately. |
|
202 | - * 4. Saves messages via the queue |
|
203 | - * 5. Releases lock. |
|
204 | - * |
|
205 | - * @return bool true on success, false if something preventing sending (i.e. lock set). Note: true does not |
|
206 | - * necessarily mean that all messages were successfully sent. It just means that this method |
|
207 | - * successfully completed. On true, client may want to call $this->count_STS_in_queue( |
|
208 | - * EEM_Message::status_failed ) to see if any failed EE_Message objects. Each failed message object |
|
209 | - * will also have a saved error message on it to assist with notifying user. |
|
210 | - */ |
|
211 | - public function get_to_send_batch_and_send() |
|
212 | - { |
|
213 | - $rate_limit = $this->get_rate_limit(); |
|
214 | - if ($rate_limit < 1 || $this->is_locked(EE_Messages_Queue::action_sending)) { |
|
215 | - return false; |
|
216 | - } |
|
217 | - |
|
218 | - $this->lock_queue(EE_Messages_Queue::action_sending); |
|
219 | - |
|
220 | - $batch = $this->_batch_count < $rate_limit ? $this->_batch_count : $rate_limit; |
|
221 | - |
|
222 | - $query_args = array( |
|
223 | - // key 0 = where conditions |
|
224 | - 0 => array('STS_ID' => array('IN', EEM_Message::instance()->stati_indicating_to_send())), |
|
225 | - 'order_by' => $this->_get_priority_orderby(), |
|
226 | - 'limit' => $batch, |
|
227 | - ); |
|
228 | - |
|
229 | - $messages_to_send = EEM_Message::instance()->get_all($query_args); |
|
230 | - |
|
231 | - |
|
232 | - //any to send? |
|
233 | - if ( ! $messages_to_send) { |
|
234 | - $this->unlock_queue(EE_Messages_Queue::action_sending); |
|
235 | - return false; |
|
236 | - } |
|
237 | - |
|
238 | - $queue_count = 0; |
|
239 | - |
|
240 | - //add to queue. |
|
241 | - foreach ($messages_to_send as $message) { |
|
242 | - if ($message instanceof EE_Message) { |
|
243 | - $queue_count++; |
|
244 | - $this->add($message); |
|
245 | - } |
|
246 | - } |
|
247 | - |
|
248 | - //send messages (this also updates the rate limit) |
|
249 | - $this->execute(); |
|
250 | - |
|
251 | - //release lock |
|
252 | - $this->unlock_queue(EE_Messages_Queue::action_sending); |
|
253 | - //update rate limit |
|
254 | - $this->set_rate_limit($queue_count); |
|
255 | - return true; |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * Locks the queue so that no other queues can call the "batch" methods. |
|
261 | - * |
|
262 | - * @param string $type The type of queue being locked. |
|
263 | - */ |
|
264 | - public function lock_queue($type = EE_Messages_Queue::action_generating) |
|
265 | - { |
|
266 | - update_option($this->_get_lock_key($type), $this->_get_lock_expiry($type)); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * Unlocks the queue so that batch methods can be used. |
|
272 | - * |
|
273 | - * @param string $type The type of queue being unlocked. |
|
274 | - */ |
|
275 | - public function unlock_queue($type = EE_Messages_Queue::action_generating) |
|
276 | - { |
|
277 | - delete_option($this->_get_lock_key($type)); |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * Retrieve the key used for the lock transient. |
|
283 | - * |
|
284 | - * @param string $type The type of lock. |
|
285 | - * @return string |
|
286 | - */ |
|
287 | - protected function _get_lock_key($type = EE_Messages_Queue::action_generating) |
|
288 | - { |
|
289 | - return '_ee_lock_' . $type; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * Retrieve the expiry time for the lock transient. |
|
295 | - * |
|
296 | - * @param string $type The type of lock |
|
297 | - * @return int time to expiry in seconds. |
|
298 | - */ |
|
299 | - protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating) |
|
300 | - { |
|
301 | - return time() + (int) apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * Returns the key used for rate limit transient. |
|
307 | - * |
|
308 | - * @return string |
|
309 | - */ |
|
310 | - protected function _get_rate_limit_key() |
|
311 | - { |
|
312 | - return '_ee_rate_limit'; |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * Returns the rate limit expiry time. |
|
318 | - * |
|
319 | - * @return int |
|
320 | - */ |
|
321 | - protected function _get_rate_limit_expiry() |
|
322 | - { |
|
323 | - return time() + (int) apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS); |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * Returns the default rate limit for sending messages. |
|
329 | - * |
|
330 | - * @return int |
|
331 | - */ |
|
332 | - protected function _default_rate_limit() |
|
333 | - { |
|
334 | - return (int) apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * Return the orderby array for priority. |
|
340 | - * |
|
341 | - * @return array |
|
342 | - */ |
|
343 | - protected function _get_priority_orderby() |
|
344 | - { |
|
345 | - return array( |
|
346 | - 'MSG_priority' => 'ASC', |
|
347 | - 'MSG_modified' => 'DESC', |
|
348 | - ); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * Returns whether batch methods are "locked" or not. |
|
354 | - * |
|
355 | - * @param string $type The type of lock being checked for. |
|
356 | - * @return bool |
|
357 | - */ |
|
358 | - public function is_locked($type = EE_Messages_Queue::action_generating) |
|
359 | - { |
|
360 | - $lock = (int) get_option($this->_get_lock_key($type), 0); |
|
361 | - /** |
|
362 | - * This filters the default is_locked behaviour. |
|
363 | - */ |
|
364 | - $is_locked = filter_var( |
|
365 | - apply_filters( |
|
366 | - 'FHEE__EE_Messages_Queue__is_locked', |
|
367 | - $lock > time(), |
|
368 | - $this |
|
369 | - ), |
|
370 | - FILTER_VALIDATE_BOOLEAN |
|
371 | - ); |
|
372 | - |
|
373 | - /** |
|
374 | - * @see usage of this filter in EE_Messages_Queue::initiate_request_by_priority() method. |
|
375 | - * Also implemented here because messages processed on the same request should not have any locks applied. |
|
376 | - */ |
|
377 | - if ( |
|
378 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
379 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
380 | - ) { |
|
381 | - $is_locked = false; |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - return $is_locked; |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * Retrieves the rate limit that may be cached as a transient. |
|
391 | - * If the rate limit is not set, then this sets the default rate limit and expiry and returns it. |
|
392 | - * |
|
393 | - * @param bool $return_expiry If true then return the expiry time not the rate_limit. |
|
394 | - * @return int |
|
395 | - */ |
|
396 | - protected function get_rate_limit($return_expiry = false) |
|
397 | - { |
|
398 | - $stored_rate_info = get_option($this->_get_rate_limit_key(), array()); |
|
399 | - $rate_limit = isset($stored_rate_info[0]) |
|
400 | - ? (int) $stored_rate_info[0] |
|
401 | - : 0; |
|
402 | - $expiry = isset($stored_rate_info[1]) |
|
403 | - ? (int) $stored_rate_info[1] |
|
404 | - : 0; |
|
405 | - //set the default for tracking? |
|
406 | - if (empty($stored_rate_info) || time() > $expiry) { |
|
407 | - $expiry = $this->_get_rate_limit_expiry(); |
|
408 | - $rate_limit = $this->_default_rate_limit(); |
|
409 | - update_option($this->_get_rate_limit_key(), array($rate_limit, $expiry)); |
|
410 | - } |
|
411 | - return $return_expiry ? $expiry : $rate_limit; |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * This updates existing rate limit with the new limit which is the old minus the batch. |
|
417 | - * |
|
418 | - * @param int $batch_completed This sets the new rate limit based on the given batch that was completed. |
|
419 | - */ |
|
420 | - protected function set_rate_limit($batch_completed) |
|
421 | - { |
|
422 | - //first get the most up to date rate limit (in case its expired and reset) |
|
423 | - $rate_limit = $this->get_rate_limit(); |
|
424 | - $expiry = $this->get_rate_limit(true); |
|
425 | - $new_limit = $rate_limit - $batch_completed; |
|
426 | - //updating the transient option directly to avoid resetting the expiry. |
|
427 | - |
|
428 | - update_option($this->_get_rate_limit_key(), array($new_limit, $expiry)); |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * This method checks the queue for ANY EE_Message objects with a priority matching the given priority passed in. |
|
434 | - * If that exists, then we immediately initiate a non-blocking request to do the requested action type. |
|
435 | - * Note: Keep in mind that there is the possibility that the request will not execute if there is already another |
|
436 | - * request running on a queue for the given task. |
|
437 | - * |
|
438 | - * @param string $task This indicates what type of request is going to be initiated. |
|
439 | - * @param int $priority This indicates the priority that triggers initiating the request. |
|
440 | - */ |
|
441 | - public function initiate_request_by_priority($task = 'generate', $priority = EEM_Message::priority_high) |
|
442 | - { |
|
443 | - //determine what status is matched with the priority as part of the trigger conditions. |
|
444 | - $status = $task == 'generate' |
|
445 | - ? EEM_Message::status_incomplete |
|
446 | - : EEM_Message::instance()->stati_indicating_to_send(); |
|
447 | - // always make sure we save because either this will get executed immediately on a separate request |
|
448 | - // or remains in the queue for the regularly scheduled queue batch. |
|
449 | - $this->save(); |
|
450 | - /** |
|
451 | - * This filter/option allows users to override processing of messages on separate requests and instead have everything |
|
452 | - * happen on the same request. If this is utilized remember: |
|
453 | - * - message priorities don't matter |
|
454 | - * - existing unprocessed messages in the queue will not get processed unless manually triggered. |
|
455 | - * - things will be perceived to take longer to happen for end users (i.e. registrations) because of the additional |
|
456 | - * processing happening on the same request. |
|
457 | - * - any race condition protection (locks) are removed because they don't apply when things are processed on |
|
458 | - * the same request. |
|
459 | - */ |
|
460 | - if ( |
|
461 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
462 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
463 | - ) { |
|
464 | - $messages_processor = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
465 | - if ($messages_processor instanceof EE_Messages_Processor) { |
|
466 | - return $messages_processor->process_immediately_from_queue($this); |
|
467 | - } |
|
468 | - //if we get here then that means the messages processor couldn't be loaded so messages will just remain |
|
469 | - //queued for manual triggering by end user. |
|
470 | - } |
|
471 | - |
|
472 | - if ($this->_message_repository->count_by_priority_and_status($priority, $status)) { |
|
473 | - EE_Messages_Scheduler::initiate_scheduled_non_blocking_request($task); |
|
474 | - } |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * Loops through the EE_Message objects in the _queue and calls the messenger send methods for each message. |
|
480 | - * |
|
481 | - * @param bool $save Used to indicate whether to save the message queue after sending |
|
482 | - * (default will save). |
|
483 | - * @param mixed $sending_messenger (optional) When the sending messenger is different than |
|
484 | - * what is on the EE_Message object in the queue. |
|
485 | - * For instance, showing the browser view of an email message, |
|
486 | - * or giving a pdf generated view of an html document. |
|
487 | - * This should be an instance of EE_messenger but if you call this |
|
488 | - * method |
|
489 | - * intending it to be a sending messenger but a valid one could not be |
|
490 | - * retrieved then send in an instance of EE_Error that contains the |
|
491 | - * related error message. |
|
492 | - * @param bool|int $by_priority When set, this indicates that only messages |
|
493 | - * matching the given priority should be executed. |
|
494 | - * @return int Number of messages sent. Note, 0 does not mean that no messages were processed. |
|
495 | - * Also, if the messenger is an request type messenger (or a preview), |
|
496 | - * its entirely possible that the messenger will exit before |
|
497 | - */ |
|
498 | - public function execute($save = true, $sending_messenger = null, $by_priority = false) |
|
499 | - { |
|
500 | - $messages_sent = 0; |
|
501 | - $this->_did_hook = array(); |
|
502 | - $this->_message_repository->rewind(); |
|
503 | - |
|
504 | - while ($this->_message_repository->valid()) { |
|
505 | - $error_messages = array(); |
|
506 | - /** @type EE_Message $message */ |
|
507 | - $message = $this->_message_repository->current(); |
|
508 | - //only process things that are queued for sending |
|
509 | - if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
510 | - $this->_message_repository->next(); |
|
511 | - continue; |
|
512 | - } |
|
513 | - //if $by_priority is set and does not match then continue; |
|
514 | - if ($by_priority && $by_priority != $message->priority()) { |
|
515 | - $this->_message_repository->next(); |
|
516 | - continue; |
|
517 | - } |
|
518 | - //error checking |
|
519 | - if (! $message->valid_messenger()) { |
|
520 | - $error_messages[] = sprintf( |
|
521 | - __('The %s messenger is not active at time of sending.', 'event_espresso'), |
|
522 | - $message->messenger() |
|
523 | - ); |
|
524 | - } |
|
525 | - if (! $message->valid_message_type()) { |
|
526 | - $error_messages[] = sprintf( |
|
527 | - __('The %s message type is not active at the time of sending.', 'event_espresso'), |
|
528 | - $message->message_type() |
|
529 | - ); |
|
530 | - } |
|
531 | - // if there was supposed to be a sending messenger for this message, but it was invalid/inactive, |
|
532 | - // then it will instead be an EE_Error object, so let's check for that |
|
533 | - if ($sending_messenger instanceof EE_Error) { |
|
534 | - $error_messages[] = $sending_messenger->getMessage(); |
|
535 | - } |
|
536 | - // if there are no errors, then let's process the message |
|
537 | - if (empty($error_messages)) { |
|
538 | - if ($save) { |
|
539 | - $message->set_messenger_is_executing(); |
|
540 | - } |
|
541 | - if ($this->_process_message($message, $sending_messenger)) { |
|
542 | - $messages_sent++; |
|
543 | - } |
|
544 | - } |
|
545 | - $this->_set_error_message($message, $error_messages); |
|
546 | - //add modified time |
|
547 | - $message->set_modified(time()); |
|
548 | - //we save each message after its processed to make sure its status persists in case PHP times-out or runs |
|
549 | - //out of memory. @see https://events.codebasehq.com/projects/event-espresso/tickets/10281 |
|
550 | - if ($save) { |
|
551 | - $message->save(); |
|
552 | - } |
|
553 | - |
|
554 | - $this->_message_repository->next(); |
|
555 | - } |
|
556 | - if ($save) { |
|
557 | - $this->save(true); |
|
558 | - } |
|
559 | - return $messages_sent; |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * _process_message |
|
565 | - * |
|
566 | - * @param EE_Message $message |
|
567 | - * @param mixed $sending_messenger (optional) |
|
568 | - * @return bool |
|
569 | - */ |
|
570 | - protected function _process_message(EE_Message $message, $sending_messenger = null) |
|
571 | - { |
|
572 | - // these *should* have been validated in the execute() method above |
|
573 | - $messenger = $message->messenger_object(); |
|
574 | - $message_type = $message->message_type_object(); |
|
575 | - //do actions for sending messenger if it differs from generating messenger and swap values. |
|
576 | - if ( |
|
577 | - $sending_messenger instanceof EE_messenger |
|
578 | - && $messenger instanceof EE_messenger |
|
579 | - && $sending_messenger->name != $messenger->name |
|
580 | - ) { |
|
581 | - $messenger->do_secondary_messenger_hooks($sending_messenger->name); |
|
582 | - $messenger = $sending_messenger; |
|
583 | - } |
|
584 | - // send using messenger, but double check objects |
|
585 | - if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) { |
|
586 | - //set hook for message type (but only if not using another messenger to send). |
|
587 | - if ( ! isset($this->_did_hook[$message_type->name])) { |
|
588 | - $message_type->do_messenger_hooks($messenger); |
|
589 | - $this->_did_hook[$message_type->name] = 1; |
|
590 | - } |
|
591 | - //if preview then use preview method |
|
592 | - return $this->_message_repository->is_preview() |
|
593 | - ? $this->_do_preview($message, $messenger, $message_type, $this->_message_repository->is_test_send()) |
|
594 | - : $this->_do_send($message, $messenger, $message_type); |
|
595 | - } |
|
596 | - return false; |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * The intention of this method is to count how many EE_Message objects |
|
602 | - * are in the queue with a given status. |
|
603 | - * Example usage: |
|
604 | - * After a caller calls the "EE_Message_Queue::execute()" method, the caller can check if there were any failed |
|
605 | - * sends by calling $queue->count_STS_in_queue( EEM_Message_Queue::status_failed ). |
|
606 | - * |
|
607 | - * @param array|string $status Stati to check for in queue |
|
608 | - * @return int Count of EE_Message's matching the given status. |
|
609 | - */ |
|
610 | - public function count_STS_in_queue($status) |
|
611 | - { |
|
612 | - $count = 0; |
|
613 | - $status = is_array($status) ? $status : array($status); |
|
614 | - $this->_message_repository->rewind(); |
|
615 | - foreach ($this->_message_repository as $message) { |
|
616 | - if (in_array($message->STS_ID(), $status)) { |
|
617 | - $count++; |
|
618 | - } |
|
619 | - } |
|
620 | - return $count; |
|
621 | - } |
|
622 | - |
|
623 | - |
|
624 | - /** |
|
625 | - * Executes the get_preview method on the provided messenger. |
|
626 | - * |
|
627 | - * @param EE_Message $message |
|
628 | - * @param EE_messenger $messenger |
|
629 | - * @param EE_message_type $message_type |
|
630 | - * @param $test_send |
|
631 | - * @return bool true means all went well, false means, not so much. |
|
632 | - */ |
|
633 | - protected function _do_preview( |
|
634 | - EE_Message $message, |
|
635 | - EE_messenger $messenger, |
|
636 | - EE_message_type $message_type, |
|
637 | - $test_send |
|
638 | - ) { |
|
639 | - if ($preview = $messenger->get_preview($message, $message_type, $test_send)) { |
|
640 | - if ( ! $test_send) { |
|
641 | - $message->set_content($preview); |
|
642 | - } |
|
643 | - $message->set_STS_ID(EEM_Message::status_sent); |
|
644 | - return true; |
|
645 | - } else { |
|
646 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
647 | - return false; |
|
648 | - } |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - /** |
|
653 | - * Executes the send method on the provided messenger |
|
654 | - * EE_Messengers are expected to: |
|
655 | - * - return true if the send was successful. |
|
656 | - * - return false if the send was unsuccessful but can be tried again. |
|
657 | - * - throw an Exception if the send was unsuccessful and cannot be tried again. |
|
658 | - * |
|
659 | - * @param EE_Message $message |
|
660 | - * @param EE_messenger $messenger |
|
661 | - * @param EE_message_type $message_type |
|
662 | - * @return bool true means all went well, false means, not so much. |
|
663 | - */ |
|
664 | - protected function _do_send(EE_Message $message, EE_messenger $messenger, EE_message_type $message_type) |
|
665 | - { |
|
666 | - try { |
|
667 | - if ($messenger->send_message($message, $message_type)) { |
|
668 | - $message->set_STS_ID(EEM_Message::status_sent); |
|
669 | - return true; |
|
670 | - } else { |
|
671 | - $message->set_STS_ID(EEM_Message::status_retry); |
|
672 | - return false; |
|
673 | - } |
|
674 | - } catch (SendMessageException $e) { |
|
675 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
676 | - $message->set_error_message($e->getMessage()); |
|
677 | - return false; |
|
678 | - } |
|
679 | - } |
|
680 | - |
|
681 | - |
|
682 | - /** |
|
683 | - * This sets any necessary error messages on the message object and its status to failed. |
|
684 | - * |
|
685 | - * @param EE_Message $message |
|
686 | - * @param array $error_messages the response from the messenger. |
|
687 | - */ |
|
688 | - protected function _set_error_message(EE_Message $message, $error_messages) |
|
689 | - { |
|
690 | - $error_messages = (array)$error_messages; |
|
691 | - if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) { |
|
692 | - $notices = EE_Error::has_notices(); |
|
693 | - $error_messages[] = __( |
|
694 | - 'Messenger and Message Type were valid and active, but the messenger send method failed.', |
|
695 | - 'event_espresso' |
|
696 | - ); |
|
697 | - if ($notices === 1) { |
|
698 | - $notices = EE_Error::get_vanilla_notices(); |
|
699 | - $notices['errors'] = isset($notices['errors']) ? $notices['errors'] : array(); |
|
700 | - $error_messages[] = implode("\n", $notices['errors']); |
|
701 | - } |
|
702 | - } |
|
703 | - if (count($error_messages) > 0) { |
|
704 | - $msg = __('Message was not executed successfully.', 'event_espresso'); |
|
705 | - $msg = $msg . "\n" . implode("\n", $error_messages); |
|
706 | - $message->set_error_message($msg); |
|
707 | - } |
|
708 | - } |
|
21 | + /** |
|
22 | + * @type string reference for sending action |
|
23 | + */ |
|
24 | + const action_sending = 'sending'; |
|
25 | + |
|
26 | + /** |
|
27 | + * @type string reference for generation action |
|
28 | + */ |
|
29 | + const action_generating = 'generation'; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @type EE_Message_Repository $_message_repository |
|
34 | + */ |
|
35 | + protected $_message_repository; |
|
36 | + |
|
37 | + /** |
|
38 | + * Sets the limit of how many messages are generated per process. |
|
39 | + * |
|
40 | + * @type int |
|
41 | + */ |
|
42 | + protected $_batch_count; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * This is an array of cached queue items being stored in this object. |
|
47 | + * The array keys will be the ID of the EE_Message in the db if saved. If the EE_Message |
|
48 | + * is not saved to the db then its key will be an increment of "UNS" (i.e. UNS1, UNS2 etc.) |
|
49 | + * |
|
50 | + * @type EE_Message[] |
|
51 | + */ |
|
52 | + protected $_cached_queue_items; |
|
53 | + |
|
54 | + /** |
|
55 | + * Tracks the number of unsaved queue items. |
|
56 | + * |
|
57 | + * @type int |
|
58 | + */ |
|
59 | + protected $_unsaved_count = 0; |
|
60 | + |
|
61 | + /** |
|
62 | + * used to record if a do_messenger_hooks has already been called for a message type. This prevents multiple |
|
63 | + * hooks getting fired if users have setup their action/filter hooks to prevent duplicate calls. |
|
64 | + * |
|
65 | + * @type array |
|
66 | + */ |
|
67 | + protected $_did_hook = array(); |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * Constructor. |
|
72 | + * Setup all the initial properties and load a EE_Message_Repository. |
|
73 | + * |
|
74 | + * @param \EE_Message_Repository $message_repository |
|
75 | + */ |
|
76 | + public function __construct(EE_Message_Repository $message_repository) |
|
77 | + { |
|
78 | + $this->_batch_count = apply_filters('FHEE__EE_Messages_Queue___batch_count', 50); |
|
79 | + $this->_message_repository = $message_repository; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * Add a EE_Message object to the queue |
|
85 | + * |
|
86 | + * @param EE_Message $message |
|
87 | + * @param array $data This will be an array of data to attach to the object in the repository. If the |
|
88 | + * object is persisted, this data will be saved on an extra_meta object related to |
|
89 | + * EE_Message. |
|
90 | + * @param bool $preview Whether this EE_Message represents a preview or not. |
|
91 | + * @param bool $test_send This indicates whether to do a test send instead of actual send. A test send will |
|
92 | + * use the messenger send method but typically is based on preview data. |
|
93 | + * @return bool Whether the message was successfully added to the repository or not. |
|
94 | + */ |
|
95 | + public function add(EE_Message $message, $data = array(), $preview = false, $test_send = false) |
|
96 | + { |
|
97 | + $data['preview'] = $preview; |
|
98 | + $data['test_send'] = $test_send; |
|
99 | + return $this->_message_repository->add($message, $data); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Removes EE_Message from _queue that matches the given EE_Message if the pointer is on a matching EE_Message |
|
105 | + * |
|
106 | + * @param EE_Message $message The message to detach from the queue |
|
107 | + * @param bool $persist This flag indicates whether to attempt to delete the object from the db as well. |
|
108 | + * @return bool |
|
109 | + */ |
|
110 | + public function remove(EE_Message $message, $persist = false) |
|
111 | + { |
|
112 | + if ($persist && $this->_message_repository->current() !== $message) { |
|
113 | + //get pointer on right message |
|
114 | + if ($this->_message_repository->has($message)) { |
|
115 | + $this->_message_repository->rewind(); |
|
116 | + while ($this->_message_repository->valid()) { |
|
117 | + if ($this->_message_repository->current() === $message) { |
|
118 | + break; |
|
119 | + } |
|
120 | + $this->_message_repository->next(); |
|
121 | + } |
|
122 | + } else { |
|
123 | + return false; |
|
124 | + } |
|
125 | + } |
|
126 | + return $persist ? $this->_message_repository->delete() : $this->_message_repository->remove($message); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Persists all queued EE_Message objects to the db. |
|
132 | + * |
|
133 | + * @param bool $do_hooks_only @see EE_Message_Repository::saveAll |
|
134 | + * @return array @see EE_Messages_Repository::saveAll() for return values. |
|
135 | + */ |
|
136 | + public function save($do_hooks_only = false) |
|
137 | + { |
|
138 | + return $this->_message_repository->saveAll($do_hooks_only); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @return EE_Message_Repository |
|
144 | + */ |
|
145 | + public function get_message_repository() |
|
146 | + { |
|
147 | + return $this->_message_repository; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * This does the following things: |
|
153 | + * 1. Checks if there is a lock on generation (prevents race conditions). If there is a lock then exits (return |
|
154 | + * false). |
|
155 | + * 2. If no lock, sets lock, then retrieves a batch of non-generated EE_Message objects and adds to queue |
|
156 | + * 3. Returns bool. True = batch ready. False = no batch ready (or nothing available for generation). |
|
157 | + * Note: Callers should make sure they release the lock otherwise batch generation will be prevented from |
|
158 | + * continuing. The lock is on a transient that is set to expire after one hour as a fallback in case locks are not |
|
159 | + * removed. |
|
160 | + * |
|
161 | + * @return bool true if successfully retrieved batch, false no batch ready. |
|
162 | + */ |
|
163 | + public function get_batch_to_generate() |
|
164 | + { |
|
165 | + if ($this->is_locked(EE_Messages_Queue::action_generating)) { |
|
166 | + return false; |
|
167 | + } |
|
168 | + |
|
169 | + //lock batch generation to prevent race conditions. |
|
170 | + $this->lock_queue(EE_Messages_Queue::action_generating); |
|
171 | + |
|
172 | + $query_args = array( |
|
173 | + // key 0 = where conditions |
|
174 | + 0 => array('STS_ID' => EEM_Message::status_incomplete), |
|
175 | + 'order_by' => $this->_get_priority_orderby(), |
|
176 | + 'limit' => $this->_batch_count, |
|
177 | + ); |
|
178 | + $messages = EEM_Message::instance()->get_all($query_args); |
|
179 | + |
|
180 | + if ( ! $messages) { |
|
181 | + return false; //nothing to generate |
|
182 | + } |
|
183 | + |
|
184 | + foreach ($messages as $message) { |
|
185 | + if ($message instanceof EE_Message) { |
|
186 | + $data = $message->all_extra_meta_array(); |
|
187 | + $this->add($message, $data); |
|
188 | + } |
|
189 | + } |
|
190 | + return true; |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * This does the following things: |
|
196 | + * 1. Checks if there is a lock on sending (prevents race conditions). If there is a lock then exits (return |
|
197 | + * false). |
|
198 | + * 2. Grabs the allowed number of messages to send for the rate_limit. If cannot send any more messages, then |
|
199 | + * return false. |
|
200 | + * 2. If no lock, sets lock, then retrieves a batch of EE_Message objects, adds to queue and triggers execution. |
|
201 | + * 3. On success or unsuccessful send, sets status appropriately. |
|
202 | + * 4. Saves messages via the queue |
|
203 | + * 5. Releases lock. |
|
204 | + * |
|
205 | + * @return bool true on success, false if something preventing sending (i.e. lock set). Note: true does not |
|
206 | + * necessarily mean that all messages were successfully sent. It just means that this method |
|
207 | + * successfully completed. On true, client may want to call $this->count_STS_in_queue( |
|
208 | + * EEM_Message::status_failed ) to see if any failed EE_Message objects. Each failed message object |
|
209 | + * will also have a saved error message on it to assist with notifying user. |
|
210 | + */ |
|
211 | + public function get_to_send_batch_and_send() |
|
212 | + { |
|
213 | + $rate_limit = $this->get_rate_limit(); |
|
214 | + if ($rate_limit < 1 || $this->is_locked(EE_Messages_Queue::action_sending)) { |
|
215 | + return false; |
|
216 | + } |
|
217 | + |
|
218 | + $this->lock_queue(EE_Messages_Queue::action_sending); |
|
219 | + |
|
220 | + $batch = $this->_batch_count < $rate_limit ? $this->_batch_count : $rate_limit; |
|
221 | + |
|
222 | + $query_args = array( |
|
223 | + // key 0 = where conditions |
|
224 | + 0 => array('STS_ID' => array('IN', EEM_Message::instance()->stati_indicating_to_send())), |
|
225 | + 'order_by' => $this->_get_priority_orderby(), |
|
226 | + 'limit' => $batch, |
|
227 | + ); |
|
228 | + |
|
229 | + $messages_to_send = EEM_Message::instance()->get_all($query_args); |
|
230 | + |
|
231 | + |
|
232 | + //any to send? |
|
233 | + if ( ! $messages_to_send) { |
|
234 | + $this->unlock_queue(EE_Messages_Queue::action_sending); |
|
235 | + return false; |
|
236 | + } |
|
237 | + |
|
238 | + $queue_count = 0; |
|
239 | + |
|
240 | + //add to queue. |
|
241 | + foreach ($messages_to_send as $message) { |
|
242 | + if ($message instanceof EE_Message) { |
|
243 | + $queue_count++; |
|
244 | + $this->add($message); |
|
245 | + } |
|
246 | + } |
|
247 | + |
|
248 | + //send messages (this also updates the rate limit) |
|
249 | + $this->execute(); |
|
250 | + |
|
251 | + //release lock |
|
252 | + $this->unlock_queue(EE_Messages_Queue::action_sending); |
|
253 | + //update rate limit |
|
254 | + $this->set_rate_limit($queue_count); |
|
255 | + return true; |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * Locks the queue so that no other queues can call the "batch" methods. |
|
261 | + * |
|
262 | + * @param string $type The type of queue being locked. |
|
263 | + */ |
|
264 | + public function lock_queue($type = EE_Messages_Queue::action_generating) |
|
265 | + { |
|
266 | + update_option($this->_get_lock_key($type), $this->_get_lock_expiry($type)); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * Unlocks the queue so that batch methods can be used. |
|
272 | + * |
|
273 | + * @param string $type The type of queue being unlocked. |
|
274 | + */ |
|
275 | + public function unlock_queue($type = EE_Messages_Queue::action_generating) |
|
276 | + { |
|
277 | + delete_option($this->_get_lock_key($type)); |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * Retrieve the key used for the lock transient. |
|
283 | + * |
|
284 | + * @param string $type The type of lock. |
|
285 | + * @return string |
|
286 | + */ |
|
287 | + protected function _get_lock_key($type = EE_Messages_Queue::action_generating) |
|
288 | + { |
|
289 | + return '_ee_lock_' . $type; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * Retrieve the expiry time for the lock transient. |
|
295 | + * |
|
296 | + * @param string $type The type of lock |
|
297 | + * @return int time to expiry in seconds. |
|
298 | + */ |
|
299 | + protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating) |
|
300 | + { |
|
301 | + return time() + (int) apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * Returns the key used for rate limit transient. |
|
307 | + * |
|
308 | + * @return string |
|
309 | + */ |
|
310 | + protected function _get_rate_limit_key() |
|
311 | + { |
|
312 | + return '_ee_rate_limit'; |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * Returns the rate limit expiry time. |
|
318 | + * |
|
319 | + * @return int |
|
320 | + */ |
|
321 | + protected function _get_rate_limit_expiry() |
|
322 | + { |
|
323 | + return time() + (int) apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS); |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * Returns the default rate limit for sending messages. |
|
329 | + * |
|
330 | + * @return int |
|
331 | + */ |
|
332 | + protected function _default_rate_limit() |
|
333 | + { |
|
334 | + return (int) apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * Return the orderby array for priority. |
|
340 | + * |
|
341 | + * @return array |
|
342 | + */ |
|
343 | + protected function _get_priority_orderby() |
|
344 | + { |
|
345 | + return array( |
|
346 | + 'MSG_priority' => 'ASC', |
|
347 | + 'MSG_modified' => 'DESC', |
|
348 | + ); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * Returns whether batch methods are "locked" or not. |
|
354 | + * |
|
355 | + * @param string $type The type of lock being checked for. |
|
356 | + * @return bool |
|
357 | + */ |
|
358 | + public function is_locked($type = EE_Messages_Queue::action_generating) |
|
359 | + { |
|
360 | + $lock = (int) get_option($this->_get_lock_key($type), 0); |
|
361 | + /** |
|
362 | + * This filters the default is_locked behaviour. |
|
363 | + */ |
|
364 | + $is_locked = filter_var( |
|
365 | + apply_filters( |
|
366 | + 'FHEE__EE_Messages_Queue__is_locked', |
|
367 | + $lock > time(), |
|
368 | + $this |
|
369 | + ), |
|
370 | + FILTER_VALIDATE_BOOLEAN |
|
371 | + ); |
|
372 | + |
|
373 | + /** |
|
374 | + * @see usage of this filter in EE_Messages_Queue::initiate_request_by_priority() method. |
|
375 | + * Also implemented here because messages processed on the same request should not have any locks applied. |
|
376 | + */ |
|
377 | + if ( |
|
378 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
379 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
380 | + ) { |
|
381 | + $is_locked = false; |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + return $is_locked; |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * Retrieves the rate limit that may be cached as a transient. |
|
391 | + * If the rate limit is not set, then this sets the default rate limit and expiry and returns it. |
|
392 | + * |
|
393 | + * @param bool $return_expiry If true then return the expiry time not the rate_limit. |
|
394 | + * @return int |
|
395 | + */ |
|
396 | + protected function get_rate_limit($return_expiry = false) |
|
397 | + { |
|
398 | + $stored_rate_info = get_option($this->_get_rate_limit_key(), array()); |
|
399 | + $rate_limit = isset($stored_rate_info[0]) |
|
400 | + ? (int) $stored_rate_info[0] |
|
401 | + : 0; |
|
402 | + $expiry = isset($stored_rate_info[1]) |
|
403 | + ? (int) $stored_rate_info[1] |
|
404 | + : 0; |
|
405 | + //set the default for tracking? |
|
406 | + if (empty($stored_rate_info) || time() > $expiry) { |
|
407 | + $expiry = $this->_get_rate_limit_expiry(); |
|
408 | + $rate_limit = $this->_default_rate_limit(); |
|
409 | + update_option($this->_get_rate_limit_key(), array($rate_limit, $expiry)); |
|
410 | + } |
|
411 | + return $return_expiry ? $expiry : $rate_limit; |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * This updates existing rate limit with the new limit which is the old minus the batch. |
|
417 | + * |
|
418 | + * @param int $batch_completed This sets the new rate limit based on the given batch that was completed. |
|
419 | + */ |
|
420 | + protected function set_rate_limit($batch_completed) |
|
421 | + { |
|
422 | + //first get the most up to date rate limit (in case its expired and reset) |
|
423 | + $rate_limit = $this->get_rate_limit(); |
|
424 | + $expiry = $this->get_rate_limit(true); |
|
425 | + $new_limit = $rate_limit - $batch_completed; |
|
426 | + //updating the transient option directly to avoid resetting the expiry. |
|
427 | + |
|
428 | + update_option($this->_get_rate_limit_key(), array($new_limit, $expiry)); |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * This method checks the queue for ANY EE_Message objects with a priority matching the given priority passed in. |
|
434 | + * If that exists, then we immediately initiate a non-blocking request to do the requested action type. |
|
435 | + * Note: Keep in mind that there is the possibility that the request will not execute if there is already another |
|
436 | + * request running on a queue for the given task. |
|
437 | + * |
|
438 | + * @param string $task This indicates what type of request is going to be initiated. |
|
439 | + * @param int $priority This indicates the priority that triggers initiating the request. |
|
440 | + */ |
|
441 | + public function initiate_request_by_priority($task = 'generate', $priority = EEM_Message::priority_high) |
|
442 | + { |
|
443 | + //determine what status is matched with the priority as part of the trigger conditions. |
|
444 | + $status = $task == 'generate' |
|
445 | + ? EEM_Message::status_incomplete |
|
446 | + : EEM_Message::instance()->stati_indicating_to_send(); |
|
447 | + // always make sure we save because either this will get executed immediately on a separate request |
|
448 | + // or remains in the queue for the regularly scheduled queue batch. |
|
449 | + $this->save(); |
|
450 | + /** |
|
451 | + * This filter/option allows users to override processing of messages on separate requests and instead have everything |
|
452 | + * happen on the same request. If this is utilized remember: |
|
453 | + * - message priorities don't matter |
|
454 | + * - existing unprocessed messages in the queue will not get processed unless manually triggered. |
|
455 | + * - things will be perceived to take longer to happen for end users (i.e. registrations) because of the additional |
|
456 | + * processing happening on the same request. |
|
457 | + * - any race condition protection (locks) are removed because they don't apply when things are processed on |
|
458 | + * the same request. |
|
459 | + */ |
|
460 | + if ( |
|
461 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
462 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
463 | + ) { |
|
464 | + $messages_processor = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
465 | + if ($messages_processor instanceof EE_Messages_Processor) { |
|
466 | + return $messages_processor->process_immediately_from_queue($this); |
|
467 | + } |
|
468 | + //if we get here then that means the messages processor couldn't be loaded so messages will just remain |
|
469 | + //queued for manual triggering by end user. |
|
470 | + } |
|
471 | + |
|
472 | + if ($this->_message_repository->count_by_priority_and_status($priority, $status)) { |
|
473 | + EE_Messages_Scheduler::initiate_scheduled_non_blocking_request($task); |
|
474 | + } |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * Loops through the EE_Message objects in the _queue and calls the messenger send methods for each message. |
|
480 | + * |
|
481 | + * @param bool $save Used to indicate whether to save the message queue after sending |
|
482 | + * (default will save). |
|
483 | + * @param mixed $sending_messenger (optional) When the sending messenger is different than |
|
484 | + * what is on the EE_Message object in the queue. |
|
485 | + * For instance, showing the browser view of an email message, |
|
486 | + * or giving a pdf generated view of an html document. |
|
487 | + * This should be an instance of EE_messenger but if you call this |
|
488 | + * method |
|
489 | + * intending it to be a sending messenger but a valid one could not be |
|
490 | + * retrieved then send in an instance of EE_Error that contains the |
|
491 | + * related error message. |
|
492 | + * @param bool|int $by_priority When set, this indicates that only messages |
|
493 | + * matching the given priority should be executed. |
|
494 | + * @return int Number of messages sent. Note, 0 does not mean that no messages were processed. |
|
495 | + * Also, if the messenger is an request type messenger (or a preview), |
|
496 | + * its entirely possible that the messenger will exit before |
|
497 | + */ |
|
498 | + public function execute($save = true, $sending_messenger = null, $by_priority = false) |
|
499 | + { |
|
500 | + $messages_sent = 0; |
|
501 | + $this->_did_hook = array(); |
|
502 | + $this->_message_repository->rewind(); |
|
503 | + |
|
504 | + while ($this->_message_repository->valid()) { |
|
505 | + $error_messages = array(); |
|
506 | + /** @type EE_Message $message */ |
|
507 | + $message = $this->_message_repository->current(); |
|
508 | + //only process things that are queued for sending |
|
509 | + if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
510 | + $this->_message_repository->next(); |
|
511 | + continue; |
|
512 | + } |
|
513 | + //if $by_priority is set and does not match then continue; |
|
514 | + if ($by_priority && $by_priority != $message->priority()) { |
|
515 | + $this->_message_repository->next(); |
|
516 | + continue; |
|
517 | + } |
|
518 | + //error checking |
|
519 | + if (! $message->valid_messenger()) { |
|
520 | + $error_messages[] = sprintf( |
|
521 | + __('The %s messenger is not active at time of sending.', 'event_espresso'), |
|
522 | + $message->messenger() |
|
523 | + ); |
|
524 | + } |
|
525 | + if (! $message->valid_message_type()) { |
|
526 | + $error_messages[] = sprintf( |
|
527 | + __('The %s message type is not active at the time of sending.', 'event_espresso'), |
|
528 | + $message->message_type() |
|
529 | + ); |
|
530 | + } |
|
531 | + // if there was supposed to be a sending messenger for this message, but it was invalid/inactive, |
|
532 | + // then it will instead be an EE_Error object, so let's check for that |
|
533 | + if ($sending_messenger instanceof EE_Error) { |
|
534 | + $error_messages[] = $sending_messenger->getMessage(); |
|
535 | + } |
|
536 | + // if there are no errors, then let's process the message |
|
537 | + if (empty($error_messages)) { |
|
538 | + if ($save) { |
|
539 | + $message->set_messenger_is_executing(); |
|
540 | + } |
|
541 | + if ($this->_process_message($message, $sending_messenger)) { |
|
542 | + $messages_sent++; |
|
543 | + } |
|
544 | + } |
|
545 | + $this->_set_error_message($message, $error_messages); |
|
546 | + //add modified time |
|
547 | + $message->set_modified(time()); |
|
548 | + //we save each message after its processed to make sure its status persists in case PHP times-out or runs |
|
549 | + //out of memory. @see https://events.codebasehq.com/projects/event-espresso/tickets/10281 |
|
550 | + if ($save) { |
|
551 | + $message->save(); |
|
552 | + } |
|
553 | + |
|
554 | + $this->_message_repository->next(); |
|
555 | + } |
|
556 | + if ($save) { |
|
557 | + $this->save(true); |
|
558 | + } |
|
559 | + return $messages_sent; |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * _process_message |
|
565 | + * |
|
566 | + * @param EE_Message $message |
|
567 | + * @param mixed $sending_messenger (optional) |
|
568 | + * @return bool |
|
569 | + */ |
|
570 | + protected function _process_message(EE_Message $message, $sending_messenger = null) |
|
571 | + { |
|
572 | + // these *should* have been validated in the execute() method above |
|
573 | + $messenger = $message->messenger_object(); |
|
574 | + $message_type = $message->message_type_object(); |
|
575 | + //do actions for sending messenger if it differs from generating messenger and swap values. |
|
576 | + if ( |
|
577 | + $sending_messenger instanceof EE_messenger |
|
578 | + && $messenger instanceof EE_messenger |
|
579 | + && $sending_messenger->name != $messenger->name |
|
580 | + ) { |
|
581 | + $messenger->do_secondary_messenger_hooks($sending_messenger->name); |
|
582 | + $messenger = $sending_messenger; |
|
583 | + } |
|
584 | + // send using messenger, but double check objects |
|
585 | + if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) { |
|
586 | + //set hook for message type (but only if not using another messenger to send). |
|
587 | + if ( ! isset($this->_did_hook[$message_type->name])) { |
|
588 | + $message_type->do_messenger_hooks($messenger); |
|
589 | + $this->_did_hook[$message_type->name] = 1; |
|
590 | + } |
|
591 | + //if preview then use preview method |
|
592 | + return $this->_message_repository->is_preview() |
|
593 | + ? $this->_do_preview($message, $messenger, $message_type, $this->_message_repository->is_test_send()) |
|
594 | + : $this->_do_send($message, $messenger, $message_type); |
|
595 | + } |
|
596 | + return false; |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * The intention of this method is to count how many EE_Message objects |
|
602 | + * are in the queue with a given status. |
|
603 | + * Example usage: |
|
604 | + * After a caller calls the "EE_Message_Queue::execute()" method, the caller can check if there were any failed |
|
605 | + * sends by calling $queue->count_STS_in_queue( EEM_Message_Queue::status_failed ). |
|
606 | + * |
|
607 | + * @param array|string $status Stati to check for in queue |
|
608 | + * @return int Count of EE_Message's matching the given status. |
|
609 | + */ |
|
610 | + public function count_STS_in_queue($status) |
|
611 | + { |
|
612 | + $count = 0; |
|
613 | + $status = is_array($status) ? $status : array($status); |
|
614 | + $this->_message_repository->rewind(); |
|
615 | + foreach ($this->_message_repository as $message) { |
|
616 | + if (in_array($message->STS_ID(), $status)) { |
|
617 | + $count++; |
|
618 | + } |
|
619 | + } |
|
620 | + return $count; |
|
621 | + } |
|
622 | + |
|
623 | + |
|
624 | + /** |
|
625 | + * Executes the get_preview method on the provided messenger. |
|
626 | + * |
|
627 | + * @param EE_Message $message |
|
628 | + * @param EE_messenger $messenger |
|
629 | + * @param EE_message_type $message_type |
|
630 | + * @param $test_send |
|
631 | + * @return bool true means all went well, false means, not so much. |
|
632 | + */ |
|
633 | + protected function _do_preview( |
|
634 | + EE_Message $message, |
|
635 | + EE_messenger $messenger, |
|
636 | + EE_message_type $message_type, |
|
637 | + $test_send |
|
638 | + ) { |
|
639 | + if ($preview = $messenger->get_preview($message, $message_type, $test_send)) { |
|
640 | + if ( ! $test_send) { |
|
641 | + $message->set_content($preview); |
|
642 | + } |
|
643 | + $message->set_STS_ID(EEM_Message::status_sent); |
|
644 | + return true; |
|
645 | + } else { |
|
646 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
647 | + return false; |
|
648 | + } |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + /** |
|
653 | + * Executes the send method on the provided messenger |
|
654 | + * EE_Messengers are expected to: |
|
655 | + * - return true if the send was successful. |
|
656 | + * - return false if the send was unsuccessful but can be tried again. |
|
657 | + * - throw an Exception if the send was unsuccessful and cannot be tried again. |
|
658 | + * |
|
659 | + * @param EE_Message $message |
|
660 | + * @param EE_messenger $messenger |
|
661 | + * @param EE_message_type $message_type |
|
662 | + * @return bool true means all went well, false means, not so much. |
|
663 | + */ |
|
664 | + protected function _do_send(EE_Message $message, EE_messenger $messenger, EE_message_type $message_type) |
|
665 | + { |
|
666 | + try { |
|
667 | + if ($messenger->send_message($message, $message_type)) { |
|
668 | + $message->set_STS_ID(EEM_Message::status_sent); |
|
669 | + return true; |
|
670 | + } else { |
|
671 | + $message->set_STS_ID(EEM_Message::status_retry); |
|
672 | + return false; |
|
673 | + } |
|
674 | + } catch (SendMessageException $e) { |
|
675 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
676 | + $message->set_error_message($e->getMessage()); |
|
677 | + return false; |
|
678 | + } |
|
679 | + } |
|
680 | + |
|
681 | + |
|
682 | + /** |
|
683 | + * This sets any necessary error messages on the message object and its status to failed. |
|
684 | + * |
|
685 | + * @param EE_Message $message |
|
686 | + * @param array $error_messages the response from the messenger. |
|
687 | + */ |
|
688 | + protected function _set_error_message(EE_Message $message, $error_messages) |
|
689 | + { |
|
690 | + $error_messages = (array)$error_messages; |
|
691 | + if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) { |
|
692 | + $notices = EE_Error::has_notices(); |
|
693 | + $error_messages[] = __( |
|
694 | + 'Messenger and Message Type were valid and active, but the messenger send method failed.', |
|
695 | + 'event_espresso' |
|
696 | + ); |
|
697 | + if ($notices === 1) { |
|
698 | + $notices = EE_Error::get_vanilla_notices(); |
|
699 | + $notices['errors'] = isset($notices['errors']) ? $notices['errors'] : array(); |
|
700 | + $error_messages[] = implode("\n", $notices['errors']); |
|
701 | + } |
|
702 | + } |
|
703 | + if (count($error_messages) > 0) { |
|
704 | + $msg = __('Message was not executed successfully.', 'event_espresso'); |
|
705 | + $msg = $msg . "\n" . implode("\n", $error_messages); |
|
706 | + $message->set_error_message($msg); |
|
707 | + } |
|
708 | + } |
|
709 | 709 | |
710 | 710 | } //end EE_Messages_Queue class |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | use \EventEspresso\core\exceptions\SendMessageException; |
3 | 3 | |
4 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | 5 | exit('No direct script access allowed'); |
6 | 6 | } |
7 | 7 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | 'order_by' => $this->_get_priority_orderby(), |
176 | 176 | 'limit' => $this->_batch_count, |
177 | 177 | ); |
178 | - $messages = EEM_Message::instance()->get_all($query_args); |
|
178 | + $messages = EEM_Message::instance()->get_all($query_args); |
|
179 | 179 | |
180 | 180 | if ( ! $messages) { |
181 | 181 | return false; //nothing to generate |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | */ |
287 | 287 | protected function _get_lock_key($type = EE_Messages_Queue::action_generating) |
288 | 288 | { |
289 | - return '_ee_lock_' . $type; |
|
289 | + return '_ee_lock_'.$type; |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | /** @type EE_Message $message */ |
507 | 507 | $message = $this->_message_repository->current(); |
508 | 508 | //only process things that are queued for sending |
509 | - if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
509 | + if ( ! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
510 | 510 | $this->_message_repository->next(); |
511 | 511 | continue; |
512 | 512 | } |
@@ -516,13 +516,13 @@ discard block |
||
516 | 516 | continue; |
517 | 517 | } |
518 | 518 | //error checking |
519 | - if (! $message->valid_messenger()) { |
|
519 | + if ( ! $message->valid_messenger()) { |
|
520 | 520 | $error_messages[] = sprintf( |
521 | 521 | __('The %s messenger is not active at time of sending.', 'event_espresso'), |
522 | 522 | $message->messenger() |
523 | 523 | ); |
524 | 524 | } |
525 | - if (! $message->valid_message_type()) { |
|
525 | + if ( ! $message->valid_message_type()) { |
|
526 | 526 | $error_messages[] = sprintf( |
527 | 527 | __('The %s message type is not active at the time of sending.', 'event_espresso'), |
528 | 528 | $message->message_type() |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | */ |
688 | 688 | protected function _set_error_message(EE_Message $message, $error_messages) |
689 | 689 | { |
690 | - $error_messages = (array)$error_messages; |
|
690 | + $error_messages = (array) $error_messages; |
|
691 | 691 | if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) { |
692 | 692 | $notices = EE_Error::has_notices(); |
693 | 693 | $error_messages[] = __( |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | } |
703 | 703 | if (count($error_messages) > 0) { |
704 | 704 | $msg = __('Message was not executed successfully.', 'event_espresso'); |
705 | - $msg = $msg . "\n" . implode("\n", $error_messages); |
|
705 | + $msg = $msg."\n".implode("\n", $error_messages); |
|
706 | 706 | $message->set_error_message($msg); |
707 | 707 | } |
708 | 708 | } |