@@ -16,237 +16,237 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class EEH_Activation implements ResettableInterface |
18 | 18 | { |
19 | - /** |
|
20 | - * constant used to indicate a cron task is no longer in use |
|
21 | - */ |
|
22 | - const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
23 | - |
|
24 | - /** |
|
25 | - * WP_User->ID |
|
26 | - * |
|
27 | - * @var int |
|
28 | - */ |
|
29 | - private static $_default_creator_id; |
|
30 | - |
|
31 | - /** |
|
32 | - * indicates whether or not we've already verified core's default data during this request, |
|
33 | - * because after migrations are done, any addons activated while in maintenance mode |
|
34 | - * will want to setup their own default data, and they might hook into core's default data |
|
35 | - * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
36 | - * This prevents doing that for EVERY single addon. |
|
37 | - * |
|
38 | - * @var boolean |
|
39 | - */ |
|
40 | - protected static $_initialized_db_content_already_in_this_request = false; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var TableAnalysis $table_analysis |
|
44 | - */ |
|
45 | - private static $table_analysis; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var TableManager $table_manager |
|
49 | - */ |
|
50 | - private static $table_manager; |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @return TableAnalysis |
|
55 | - * @throws EE_Error |
|
56 | - * @throws ReflectionException |
|
57 | - */ |
|
58 | - public static function getTableAnalysis() |
|
59 | - { |
|
60 | - if (! self::$table_analysis instanceof TableAnalysis) { |
|
61 | - self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true); |
|
62 | - } |
|
63 | - return self::$table_analysis; |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @return TableManager |
|
69 | - * @throws EE_Error |
|
70 | - * @throws ReflectionException |
|
71 | - */ |
|
72 | - public static function getTableManager() |
|
73 | - { |
|
74 | - if (! self::$table_manager instanceof TableManager) { |
|
75 | - self::$table_manager = EE_Registry::instance()->create('TableManager', [], true); |
|
76 | - } |
|
77 | - return self::$table_manager; |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * @param $table_name |
|
83 | - * @return string |
|
84 | - * @throws EE_Error |
|
85 | - * @throws ReflectionException |
|
86 | - * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
87 | - */ |
|
88 | - public static function ensure_table_name_has_prefix($table_name) |
|
89 | - { |
|
90 | - return EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * ensures the EE configuration settings are loaded with at least default options set |
|
96 | - * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
97 | - * |
|
98 | - * @return void |
|
99 | - */ |
|
100 | - public static function system_initialization() |
|
101 | - { |
|
102 | - EEH_Activation::reset_and_update_config(); |
|
103 | - // which is fired BEFORE activation of plugin anyways |
|
104 | - EEH_Activation::verify_default_pages_exist(); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Sets the database schema and creates folders. This should |
|
110 | - * be called on plugin activation and reactivation |
|
111 | - * |
|
112 | - * @return boolean success, whether the database and folders are setup properly |
|
113 | - * @throws EE_Error |
|
114 | - * @throws ReflectionException |
|
115 | - */ |
|
116 | - public static function initialize_db_and_folders() |
|
117 | - { |
|
118 | - return EEH_Activation::create_database_tables(); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * assuming we have an up-to-date database schema, this will populate it |
|
124 | - * with default and initial data. This should be called |
|
125 | - * upon activation of a new plugin, reactivation, and at the end |
|
126 | - * of running migration scripts |
|
127 | - * |
|
128 | - * @throws EE_Error |
|
129 | - * @throws ReflectionException |
|
130 | - */ |
|
131 | - public static function initialize_db_content() |
|
132 | - { |
|
133 | - // let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
134 | - if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
135 | - return; |
|
136 | - } |
|
137 | - EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
138 | - |
|
139 | - EEH_Activation::initialize_system_questions(); |
|
140 | - EEH_Activation::insert_default_status_codes(); |
|
141 | - EEH_Activation::generate_default_message_templates(); |
|
142 | - EEH_Activation::create_no_ticket_prices_array(); |
|
143 | - EEH_Activation::removeEmailConfirmFromAddressGroup(); |
|
144 | - |
|
145 | - EEH_Activation::validate_messages_system(); |
|
146 | - EEH_Activation::insert_default_payment_methods(); |
|
147 | - // in case we've |
|
148 | - EEH_Activation::remove_cron_tasks(); |
|
149 | - EEH_Activation::create_cron_tasks(); |
|
150 | - // remove all TXN locks since that is being done via extra meta now |
|
151 | - delete_option('ee_locked_transactions'); |
|
152 | - // also, check for CAF default db content |
|
153 | - do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
154 | - // also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
155 | - // which users really won't care about on initial activation |
|
156 | - EE_Error::overwrite_success(); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
162 | - * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
163 | - * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
164 | - * (null) |
|
165 | - * |
|
166 | - * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
167 | - * 'old' (only returns ones that should no longer be used),or 'all', |
|
168 | - * @return array |
|
169 | - * @throws EE_Error |
|
170 | - */ |
|
171 | - public static function get_cron_tasks($which_to_include) |
|
172 | - { |
|
173 | - $cron_tasks = apply_filters( |
|
174 | - 'FHEE__EEH_Activation__get_cron_tasks', |
|
175 | - [ |
|
176 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
177 | - // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => |
|
178 | - // EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
|
179 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
180 | - // there may have been a bug which prevented from these cron tasks from getting unscheduled, |
|
181 | - // so we might want to remove these for a few updates |
|
182 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
183 | - ] |
|
184 | - ); |
|
185 | - if ($which_to_include === 'old') { |
|
186 | - $cron_tasks = array_filter( |
|
187 | - $cron_tasks, |
|
188 | - function ($value) { |
|
189 | - return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
190 | - } |
|
191 | - ); |
|
192 | - } elseif ($which_to_include === 'current') { |
|
193 | - $cron_tasks = array_filter($cron_tasks); |
|
194 | - } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
195 | - throw new EE_Error( |
|
196 | - sprintf( |
|
197 | - esc_html__( |
|
198 | - 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
199 | - 'event_espresso' |
|
200 | - ), |
|
201 | - $which_to_include |
|
202 | - ) |
|
203 | - ); |
|
204 | - } |
|
205 | - return $cron_tasks; |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
211 | - * |
|
212 | - * @throws EE_Error |
|
213 | - */ |
|
214 | - public static function create_cron_tasks() |
|
215 | - { |
|
216 | - |
|
217 | - foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
218 | - if (! wp_next_scheduled($hook_name)) { |
|
219 | - /** |
|
220 | - * This allows client code to define the initial start timestamp for this schedule. |
|
221 | - */ |
|
222 | - if ( |
|
223 | - is_array($frequency) |
|
224 | - && count($frequency) === 2 |
|
225 | - && isset($frequency[0], $frequency[1]) |
|
226 | - ) { |
|
227 | - $start_timestamp = $frequency[0]; |
|
228 | - $frequency = $frequency[1]; |
|
229 | - } else { |
|
230 | - $start_timestamp = time(); |
|
231 | - } |
|
232 | - wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
233 | - } |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * Remove the currently-existing and now-removed cron tasks. |
|
240 | - * |
|
241 | - * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
242 | - * @throws EE_Error |
|
243 | - */ |
|
244 | - public static function remove_cron_tasks($remove_all = true) |
|
245 | - { |
|
246 | - $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
247 | - $crons = _get_cron_array(); |
|
248 | - $crons = is_array($crons) ? $crons : []; |
|
249 | - /* reminder of what $crons look like: |
|
19 | + /** |
|
20 | + * constant used to indicate a cron task is no longer in use |
|
21 | + */ |
|
22 | + const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
23 | + |
|
24 | + /** |
|
25 | + * WP_User->ID |
|
26 | + * |
|
27 | + * @var int |
|
28 | + */ |
|
29 | + private static $_default_creator_id; |
|
30 | + |
|
31 | + /** |
|
32 | + * indicates whether or not we've already verified core's default data during this request, |
|
33 | + * because after migrations are done, any addons activated while in maintenance mode |
|
34 | + * will want to setup their own default data, and they might hook into core's default data |
|
35 | + * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
36 | + * This prevents doing that for EVERY single addon. |
|
37 | + * |
|
38 | + * @var boolean |
|
39 | + */ |
|
40 | + protected static $_initialized_db_content_already_in_this_request = false; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var TableAnalysis $table_analysis |
|
44 | + */ |
|
45 | + private static $table_analysis; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var TableManager $table_manager |
|
49 | + */ |
|
50 | + private static $table_manager; |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @return TableAnalysis |
|
55 | + * @throws EE_Error |
|
56 | + * @throws ReflectionException |
|
57 | + */ |
|
58 | + public static function getTableAnalysis() |
|
59 | + { |
|
60 | + if (! self::$table_analysis instanceof TableAnalysis) { |
|
61 | + self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', [], true); |
|
62 | + } |
|
63 | + return self::$table_analysis; |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @return TableManager |
|
69 | + * @throws EE_Error |
|
70 | + * @throws ReflectionException |
|
71 | + */ |
|
72 | + public static function getTableManager() |
|
73 | + { |
|
74 | + if (! self::$table_manager instanceof TableManager) { |
|
75 | + self::$table_manager = EE_Registry::instance()->create('TableManager', [], true); |
|
76 | + } |
|
77 | + return self::$table_manager; |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * @param $table_name |
|
83 | + * @return string |
|
84 | + * @throws EE_Error |
|
85 | + * @throws ReflectionException |
|
86 | + * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
87 | + */ |
|
88 | + public static function ensure_table_name_has_prefix($table_name) |
|
89 | + { |
|
90 | + return EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * ensures the EE configuration settings are loaded with at least default options set |
|
96 | + * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
97 | + * |
|
98 | + * @return void |
|
99 | + */ |
|
100 | + public static function system_initialization() |
|
101 | + { |
|
102 | + EEH_Activation::reset_and_update_config(); |
|
103 | + // which is fired BEFORE activation of plugin anyways |
|
104 | + EEH_Activation::verify_default_pages_exist(); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Sets the database schema and creates folders. This should |
|
110 | + * be called on plugin activation and reactivation |
|
111 | + * |
|
112 | + * @return boolean success, whether the database and folders are setup properly |
|
113 | + * @throws EE_Error |
|
114 | + * @throws ReflectionException |
|
115 | + */ |
|
116 | + public static function initialize_db_and_folders() |
|
117 | + { |
|
118 | + return EEH_Activation::create_database_tables(); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * assuming we have an up-to-date database schema, this will populate it |
|
124 | + * with default and initial data. This should be called |
|
125 | + * upon activation of a new plugin, reactivation, and at the end |
|
126 | + * of running migration scripts |
|
127 | + * |
|
128 | + * @throws EE_Error |
|
129 | + * @throws ReflectionException |
|
130 | + */ |
|
131 | + public static function initialize_db_content() |
|
132 | + { |
|
133 | + // let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
134 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
135 | + return; |
|
136 | + } |
|
137 | + EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
138 | + |
|
139 | + EEH_Activation::initialize_system_questions(); |
|
140 | + EEH_Activation::insert_default_status_codes(); |
|
141 | + EEH_Activation::generate_default_message_templates(); |
|
142 | + EEH_Activation::create_no_ticket_prices_array(); |
|
143 | + EEH_Activation::removeEmailConfirmFromAddressGroup(); |
|
144 | + |
|
145 | + EEH_Activation::validate_messages_system(); |
|
146 | + EEH_Activation::insert_default_payment_methods(); |
|
147 | + // in case we've |
|
148 | + EEH_Activation::remove_cron_tasks(); |
|
149 | + EEH_Activation::create_cron_tasks(); |
|
150 | + // remove all TXN locks since that is being done via extra meta now |
|
151 | + delete_option('ee_locked_transactions'); |
|
152 | + // also, check for CAF default db content |
|
153 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
154 | + // also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
155 | + // which users really won't care about on initial activation |
|
156 | + EE_Error::overwrite_success(); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
162 | + * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
163 | + * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
164 | + * (null) |
|
165 | + * |
|
166 | + * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
167 | + * 'old' (only returns ones that should no longer be used),or 'all', |
|
168 | + * @return array |
|
169 | + * @throws EE_Error |
|
170 | + */ |
|
171 | + public static function get_cron_tasks($which_to_include) |
|
172 | + { |
|
173 | + $cron_tasks = apply_filters( |
|
174 | + 'FHEE__EEH_Activation__get_cron_tasks', |
|
175 | + [ |
|
176 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
177 | + // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => |
|
178 | + // EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
|
179 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
180 | + // there may have been a bug which prevented from these cron tasks from getting unscheduled, |
|
181 | + // so we might want to remove these for a few updates |
|
182 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
183 | + ] |
|
184 | + ); |
|
185 | + if ($which_to_include === 'old') { |
|
186 | + $cron_tasks = array_filter( |
|
187 | + $cron_tasks, |
|
188 | + function ($value) { |
|
189 | + return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
190 | + } |
|
191 | + ); |
|
192 | + } elseif ($which_to_include === 'current') { |
|
193 | + $cron_tasks = array_filter($cron_tasks); |
|
194 | + } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
195 | + throw new EE_Error( |
|
196 | + sprintf( |
|
197 | + esc_html__( |
|
198 | + 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
199 | + 'event_espresso' |
|
200 | + ), |
|
201 | + $which_to_include |
|
202 | + ) |
|
203 | + ); |
|
204 | + } |
|
205 | + return $cron_tasks; |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
211 | + * |
|
212 | + * @throws EE_Error |
|
213 | + */ |
|
214 | + public static function create_cron_tasks() |
|
215 | + { |
|
216 | + |
|
217 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
218 | + if (! wp_next_scheduled($hook_name)) { |
|
219 | + /** |
|
220 | + * This allows client code to define the initial start timestamp for this schedule. |
|
221 | + */ |
|
222 | + if ( |
|
223 | + is_array($frequency) |
|
224 | + && count($frequency) === 2 |
|
225 | + && isset($frequency[0], $frequency[1]) |
|
226 | + ) { |
|
227 | + $start_timestamp = $frequency[0]; |
|
228 | + $frequency = $frequency[1]; |
|
229 | + } else { |
|
230 | + $start_timestamp = time(); |
|
231 | + } |
|
232 | + wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
233 | + } |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * Remove the currently-existing and now-removed cron tasks. |
|
240 | + * |
|
241 | + * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
242 | + * @throws EE_Error |
|
243 | + */ |
|
244 | + public static function remove_cron_tasks($remove_all = true) |
|
245 | + { |
|
246 | + $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
247 | + $crons = _get_cron_array(); |
|
248 | + $crons = is_array($crons) ? $crons : []; |
|
249 | + /* reminder of what $crons look like: |
|
250 | 250 | * Top-level keys are timestamps, and their values are arrays. |
251 | 251 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
252 | 252 | * and their values are arrays. |
@@ -263,893 +263,893 @@ discard block |
||
263 | 263 | * ... |
264 | 264 | * ... |
265 | 265 | */ |
266 | - $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
267 | - foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
268 | - if (is_array($hooks_to_fire_at_time)) { |
|
269 | - foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
270 | - if ( |
|
271 | - isset($ee_cron_tasks_to_remove[ $hook_name ]) |
|
272 | - && is_array($ee_cron_tasks_to_remove[ $hook_name ]) |
|
273 | - ) { |
|
274 | - unset($crons[ $timestamp ][ $hook_name ]); |
|
275 | - } |
|
276 | - } |
|
277 | - // also take care of any empty cron timestamps. |
|
278 | - if (empty($hooks_to_fire_at_time)) { |
|
279 | - unset($crons[ $timestamp ]); |
|
280 | - } |
|
281 | - } |
|
282 | - } |
|
283 | - _set_cron_array($crons); |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
289 | - * |
|
290 | - * @return void |
|
291 | - * @throws EE_Error |
|
292 | - * @throws ReflectionException |
|
293 | - */ |
|
294 | - public static function CPT_initialization() |
|
295 | - { |
|
296 | - // register Custom Post Types |
|
297 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
298 | - flush_rewrite_rules(); |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
304 | - * If there is old calendar config data saved, then it will get converted on activation. |
|
305 | - * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
306 | - * |
|
307 | - * @return void |
|
308 | - */ |
|
309 | - public static function reset_and_update_config() |
|
310 | - { |
|
311 | - do_action('AHEE__EE_Config___load_core_config__start', ['EEH_Activation', 'load_calendar_config']); |
|
312 | - add_filter( |
|
313 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
314 | - ['EEH_Activation', 'migrate_old_config_data'], |
|
315 | - 10, |
|
316 | - 3 |
|
317 | - ); |
|
318 | - if (! EE_Config::logging_enabled()) { |
|
319 | - delete_option(EE_Config::LOG_NAME); |
|
320 | - } |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * @return void |
|
326 | - */ |
|
327 | - public static function load_calendar_config() |
|
328 | - { |
|
329 | - // grab array of all plugin folders and loop thru it |
|
330 | - $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR); |
|
331 | - if (empty($plugins)) { |
|
332 | - return; |
|
333 | - } |
|
334 | - foreach ($plugins as $plugin_path) { |
|
335 | - // grab plugin folder name from path |
|
336 | - $plugin = basename($plugin_path); |
|
337 | - // drill down to Espresso plugins |
|
338 | - // then to calendar related plugins |
|
339 | - if ( |
|
340 | - strpos($plugin, 'espresso') !== false |
|
341 | - || strpos($plugin, 'Espresso') !== false |
|
342 | - || strpos($plugin, 'ee4') !== false |
|
343 | - || strpos($plugin, 'EE4') !== false |
|
344 | - || strpos($plugin, 'calendar') !== false |
|
345 | - ) { |
|
346 | - // this is what we are looking for |
|
347 | - $calendar_config = $plugin_path . '/EE_Calendar_Config.php'; |
|
348 | - // does it exist in this folder ? |
|
349 | - if (is_readable($calendar_config)) { |
|
350 | - // YEAH! let's load it |
|
351 | - require_once($calendar_config); |
|
352 | - } |
|
353 | - } |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * @param array|stdClass $settings |
|
360 | - * @param string $config |
|
361 | - * @param EE_Config $EE_Config |
|
362 | - * @return stdClass |
|
363 | - */ |
|
364 | - public static function migrate_old_config_data($settings, $config, EE_Config $EE_Config) |
|
365 | - { |
|
366 | - $convert_from_array = ['addons']; |
|
367 | - // in case old settings were saved as an array |
|
368 | - if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
369 | - // convert existing settings to an object |
|
370 | - $config_array = $settings; |
|
371 | - $settings = new stdClass(); |
|
372 | - foreach ($config_array as $key => $value) { |
|
373 | - if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
374 | - $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
375 | - } else { |
|
376 | - $settings->{$key} = $value; |
|
377 | - } |
|
378 | - } |
|
379 | - add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
380 | - } |
|
381 | - return $settings; |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * @return void |
|
387 | - */ |
|
388 | - public static function deactivate_event_espresso() |
|
389 | - { |
|
390 | - // check permissions |
|
391 | - if (current_user_can('activate_plugins')) { |
|
392 | - deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
393 | - } |
|
394 | - } |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * @return void |
|
399 | - * @throws InvalidDataTypeException |
|
400 | - */ |
|
401 | - public static function verify_default_pages_exist() |
|
402 | - { |
|
403 | - $critical_page_problem = false; |
|
404 | - $critical_pages = [ |
|
405 | - [ |
|
406 | - 'id' => 'reg_page_id', |
|
407 | - 'name' => esc_html__('Registration Checkout', 'event_espresso'), |
|
408 | - 'post' => null, |
|
409 | - 'code' => 'ESPRESSO_CHECKOUT', |
|
410 | - ], |
|
411 | - [ |
|
412 | - 'id' => 'txn_page_id', |
|
413 | - 'name' => esc_html__('Transactions', 'event_espresso'), |
|
414 | - 'post' => null, |
|
415 | - 'code' => 'ESPRESSO_TXN_PAGE', |
|
416 | - ], |
|
417 | - [ |
|
418 | - 'id' => 'thank_you_page_id', |
|
419 | - 'name' => esc_html__('Thank You', 'event_espresso'), |
|
420 | - 'post' => null, |
|
421 | - 'code' => 'ESPRESSO_THANK_YOU', |
|
422 | - ], |
|
423 | - [ |
|
424 | - 'id' => 'cancel_page_id', |
|
425 | - 'name' => esc_html__('Registration Cancelled', 'event_espresso'), |
|
426 | - 'post' => null, |
|
427 | - 'code' => 'ESPRESSO_CANCELLED', |
|
428 | - ], |
|
429 | - ]; |
|
430 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
431 | - foreach ($critical_pages as $critical_page) { |
|
432 | - // is critical page ID set in config ? |
|
433 | - if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
434 | - // attempt to find post by ID |
|
435 | - $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
436 | - } |
|
437 | - // no dice? |
|
438 | - if ($critical_page['post'] === null) { |
|
439 | - // attempt to find post by title |
|
440 | - $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
441 | - // still nothing? |
|
442 | - if ($critical_page['post'] === null) { |
|
443 | - $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
444 | - // REALLY? Still nothing ??!?!? |
|
445 | - if ($critical_page['post'] === null) { |
|
446 | - $msg = esc_html__( |
|
447 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
448 | - 'event_espresso' |
|
449 | - ); |
|
450 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
451 | - break; |
|
452 | - } |
|
453 | - } |
|
454 | - } |
|
455 | - // check that Post ID matches critical page ID in config |
|
456 | - if ( |
|
457 | - isset($critical_page['post']->ID) |
|
458 | - && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
459 | - ) { |
|
460 | - // update Config with post ID |
|
461 | - $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
462 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
463 | - $msg = esc_html__( |
|
464 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
465 | - 'event_espresso' |
|
466 | - ); |
|
467 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
468 | - } |
|
469 | - } |
|
470 | - $critical_page_problem = |
|
471 | - ! isset($critical_page['post']->post_status) |
|
472 | - || $critical_page['post']->post_status !== 'publish' |
|
473 | - || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
474 | - ? true |
|
475 | - : $critical_page_problem; |
|
476 | - } |
|
477 | - if ($critical_page_problem) { |
|
478 | - new PersistentAdminNotice( |
|
479 | - 'critical_page_problem', |
|
480 | - sprintf( |
|
481 | - esc_html__( |
|
482 | - 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
483 | - 'event_espresso' |
|
484 | - ), |
|
485 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
486 | - . esc_html__('Event Espresso Critical Pages Settings', 'event_espresso') |
|
487 | - . '</a>' |
|
488 | - ) |
|
489 | - ); |
|
490 | - } |
|
491 | - if (EE_Error::has_notices()) { |
|
492 | - EE_Error::get_notices(false, true); |
|
493 | - } |
|
494 | - } |
|
495 | - |
|
496 | - |
|
497 | - /** |
|
498 | - * Returns the first post which uses the specified shortcode |
|
499 | - * |
|
500 | - * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
501 | - * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
502 | - * "[ESPRESSO_THANK_YOU" |
|
503 | - * (we don't search for the closing shortcode bracket because they might have added |
|
504 | - * parameter to the shortcode |
|
505 | - * @return WP_Post or NULl |
|
506 | - */ |
|
507 | - public static function get_page_by_ee_shortcode($ee_shortcode) |
|
508 | - { |
|
509 | - global $wpdb; |
|
510 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
511 | - $post_id = |
|
512 | - $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
513 | - if ($post_id) { |
|
514 | - return get_post($post_id); |
|
515 | - } else { |
|
516 | - return null; |
|
517 | - } |
|
518 | - } |
|
519 | - |
|
520 | - |
|
521 | - /** |
|
522 | - * This function generates a post for critical espresso pages |
|
523 | - * |
|
524 | - * @param array $critical_page |
|
525 | - * @return array |
|
526 | - */ |
|
527 | - public static function create_critical_page($critical_page) |
|
528 | - { |
|
529 | - |
|
530 | - $post_args = [ |
|
531 | - 'post_title' => $critical_page['name'], |
|
532 | - 'post_status' => 'publish', |
|
533 | - 'post_type' => 'page', |
|
534 | - 'comment_status' => 'closed', |
|
535 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
536 | - ]; |
|
537 | - |
|
538 | - $post_id = wp_insert_post($post_args); |
|
539 | - if (! $post_id) { |
|
540 | - $msg = sprintf( |
|
541 | - esc_html__('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
542 | - $critical_page['name'] |
|
543 | - ); |
|
544 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
545 | - return $critical_page; |
|
546 | - } |
|
547 | - // get newly created post's details |
|
548 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
549 | - $msg = sprintf( |
|
550 | - esc_html__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
551 | - $critical_page['name'] |
|
552 | - ); |
|
553 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
554 | - } |
|
555 | - |
|
556 | - return $critical_page; |
|
557 | - } |
|
558 | - |
|
559 | - |
|
560 | - /** |
|
561 | - * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
562 | - * The role being used to check is filterable. |
|
563 | - * |
|
564 | - * @return int|null WP_user ID or NULL |
|
565 | - * @throws EE_Error |
|
566 | - * @throws ReflectionException |
|
567 | - * @since 4.6.0 |
|
568 | - * @global WPDB $wpdb |
|
569 | - */ |
|
570 | - public static function get_default_creator_id() |
|
571 | - { |
|
572 | - global $wpdb; |
|
573 | - if (! empty(self::$_default_creator_id)) { |
|
574 | - return self::$_default_creator_id; |
|
575 | - }/**/ |
|
576 | - $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
577 | - // let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
578 | - $pre_filtered_id = apply_filters( |
|
579 | - 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
580 | - false, |
|
581 | - $role_to_check |
|
582 | - ); |
|
583 | - if ($pre_filtered_id !== false) { |
|
584 | - return (int) $pre_filtered_id; |
|
585 | - } |
|
586 | - $capabilities_key = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
587 | - $query = $wpdb->prepare( |
|
588 | - "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
589 | - '%' . $role_to_check . '%' |
|
590 | - ); |
|
591 | - $user_id = $wpdb->get_var($query); |
|
592 | - $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
593 | - if ($user_id && (int) $user_id) { |
|
594 | - self::$_default_creator_id = (int) $user_id; |
|
595 | - return self::$_default_creator_id; |
|
596 | - } else { |
|
597 | - return null; |
|
598 | - } |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * used by EE and EE addons during plugin activation to create tables. |
|
604 | - * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
605 | - * but includes extra logic regarding activations. |
|
606 | - * |
|
607 | - * @param string $table_name without the $wpdb->prefix |
|
608 | - * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
609 | - * table query) |
|
610 | - * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
611 | - * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
612 | - * and new once this function is done (ie, you really do want to CREATE a |
|
613 | - * table, and expect it to be empty once you're done) leave as FALSE when |
|
614 | - * you just want to verify the table exists and matches this definition |
|
615 | - * (and if it HAS data in it you want to leave it be) |
|
616 | - * @return void |
|
617 | - * @throws EE_Error if there are database errors |
|
618 | - * @throws ReflectionException |
|
619 | - */ |
|
620 | - public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
621 | - { |
|
622 | - if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
623 | - return; |
|
624 | - } |
|
625 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
626 | - if (! function_exists('dbDelta')) { |
|
627 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
628 | - } |
|
629 | - $tableAnalysis = EEH_Activation::getTableAnalysis(); |
|
630 | - $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
631 | - // do we need to first delete an existing version of this table ? |
|
632 | - if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
633 | - // ok, delete the table... but ONLY if it's empty |
|
634 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
635 | - // table is NOT empty, are you SURE you want to delete this table ??? |
|
636 | - if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
637 | - EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
638 | - } elseif (! $deleted_safely) { |
|
639 | - // so we should be more cautious rather than just dropping tables so easily |
|
640 | - error_log( |
|
641 | - sprintf( |
|
642 | - esc_html__( |
|
643 | - 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
644 | - 'event_espresso' |
|
645 | - ), |
|
646 | - $wp_table_name, |
|
647 | - '<br/>', |
|
648 | - 'espresso_db_update' |
|
649 | - ) |
|
650 | - ); |
|
651 | - } |
|
652 | - } |
|
653 | - $engine = str_replace('ENGINE=', '', $engine); |
|
654 | - EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
655 | - } |
|
656 | - |
|
657 | - |
|
658 | - /** |
|
659 | - * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
660 | - * |
|
661 | - * @param string $table_name (without "wp_", eg "esp_attendee" |
|
662 | - * @param string $column_name |
|
663 | - * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
664 | - * 'VARCHAR(10)' |
|
665 | - * @return bool|int |
|
666 | - * @throws EE_Error |
|
667 | - * @throws ReflectionException |
|
668 | - * @deprecated instead use TableManager::addColumn() |
|
669 | - */ |
|
670 | - public static function add_column_if_it_doesnt_exist( |
|
671 | - $table_name, |
|
672 | - $column_name, |
|
673 | - $column_info = 'INT UNSIGNED NOT NULL' |
|
674 | - ) { |
|
675 | - return EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
676 | - } |
|
677 | - |
|
678 | - |
|
679 | - /** |
|
680 | - * Gets all the fields on the database table. |
|
681 | - * |
|
682 | - * @param string $table_name , without prefixed $wpdb->prefix |
|
683 | - * @return array of database column names |
|
684 | - * @throws EE_Error |
|
685 | - * @throws ReflectionException |
|
686 | - * @deprecated instead use TableManager::getTableColumns() |
|
687 | - */ |
|
688 | - public static function get_fields_on_table($table_name = null) |
|
689 | - { |
|
690 | - return EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
691 | - } |
|
692 | - |
|
693 | - |
|
694 | - /** |
|
695 | - * @param string $table_name |
|
696 | - * @return bool |
|
697 | - * @throws EE_Error |
|
698 | - * @throws ReflectionException |
|
699 | - * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
700 | - */ |
|
701 | - public static function db_table_is_empty($table_name) |
|
702 | - { |
|
703 | - return EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
704 | - } |
|
705 | - |
|
706 | - |
|
707 | - /** |
|
708 | - * @param string $table_name |
|
709 | - * @return bool | int |
|
710 | - * @throws EE_Error |
|
711 | - * @throws ReflectionException |
|
712 | - */ |
|
713 | - public static function delete_db_table_if_empty($table_name) |
|
714 | - { |
|
715 | - if (EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
716 | - return EEH_Activation::getTableManager()->dropTable($table_name); |
|
717 | - } |
|
718 | - return false; |
|
719 | - } |
|
720 | - |
|
721 | - |
|
722 | - /** |
|
723 | - * @param string $table_name |
|
724 | - * @return int |
|
725 | - * @throws EE_Error |
|
726 | - * @throws ReflectionException |
|
727 | - * @deprecated instead use TableManager::dropTable() |
|
728 | - */ |
|
729 | - public static function delete_unused_db_table($table_name) |
|
730 | - { |
|
731 | - return EEH_Activation::getTableManager()->dropTable($table_name); |
|
732 | - } |
|
733 | - |
|
734 | - |
|
735 | - /** |
|
736 | - * @param string $table_name |
|
737 | - * @param string $index_name |
|
738 | - * @return int |
|
739 | - * @throws EE_Error |
|
740 | - * @throws ReflectionException |
|
741 | - * @deprecated instead use TableManager::dropIndex() |
|
742 | - */ |
|
743 | - public static function drop_index($table_name, $index_name) |
|
744 | - { |
|
745 | - return EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
746 | - } |
|
747 | - |
|
748 | - |
|
749 | - /** |
|
750 | - * @return boolean success (whether database is setup properly or not) |
|
751 | - * @throws EE_Error |
|
752 | - * @throws ReflectionException |
|
753 | - */ |
|
754 | - public static function create_database_tables() |
|
755 | - { |
|
756 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
757 | - // find the migration script that sets the database to be compatible with the code |
|
758 | - $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
759 | - if (! $dms_name) { |
|
760 | - EE_Error::add_error( |
|
761 | - esc_html__( |
|
762 | - 'Could not determine most up-to-date data migration script from which to pull database schema |
|
266 | + $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
267 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
268 | + if (is_array($hooks_to_fire_at_time)) { |
|
269 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
270 | + if ( |
|
271 | + isset($ee_cron_tasks_to_remove[ $hook_name ]) |
|
272 | + && is_array($ee_cron_tasks_to_remove[ $hook_name ]) |
|
273 | + ) { |
|
274 | + unset($crons[ $timestamp ][ $hook_name ]); |
|
275 | + } |
|
276 | + } |
|
277 | + // also take care of any empty cron timestamps. |
|
278 | + if (empty($hooks_to_fire_at_time)) { |
|
279 | + unset($crons[ $timestamp ]); |
|
280 | + } |
|
281 | + } |
|
282 | + } |
|
283 | + _set_cron_array($crons); |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
289 | + * |
|
290 | + * @return void |
|
291 | + * @throws EE_Error |
|
292 | + * @throws ReflectionException |
|
293 | + */ |
|
294 | + public static function CPT_initialization() |
|
295 | + { |
|
296 | + // register Custom Post Types |
|
297 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
298 | + flush_rewrite_rules(); |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
304 | + * If there is old calendar config data saved, then it will get converted on activation. |
|
305 | + * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
306 | + * |
|
307 | + * @return void |
|
308 | + */ |
|
309 | + public static function reset_and_update_config() |
|
310 | + { |
|
311 | + do_action('AHEE__EE_Config___load_core_config__start', ['EEH_Activation', 'load_calendar_config']); |
|
312 | + add_filter( |
|
313 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
314 | + ['EEH_Activation', 'migrate_old_config_data'], |
|
315 | + 10, |
|
316 | + 3 |
|
317 | + ); |
|
318 | + if (! EE_Config::logging_enabled()) { |
|
319 | + delete_option(EE_Config::LOG_NAME); |
|
320 | + } |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * @return void |
|
326 | + */ |
|
327 | + public static function load_calendar_config() |
|
328 | + { |
|
329 | + // grab array of all plugin folders and loop thru it |
|
330 | + $plugins = glob(WP_PLUGIN_DIR . '/*', GLOB_ONLYDIR); |
|
331 | + if (empty($plugins)) { |
|
332 | + return; |
|
333 | + } |
|
334 | + foreach ($plugins as $plugin_path) { |
|
335 | + // grab plugin folder name from path |
|
336 | + $plugin = basename($plugin_path); |
|
337 | + // drill down to Espresso plugins |
|
338 | + // then to calendar related plugins |
|
339 | + if ( |
|
340 | + strpos($plugin, 'espresso') !== false |
|
341 | + || strpos($plugin, 'Espresso') !== false |
|
342 | + || strpos($plugin, 'ee4') !== false |
|
343 | + || strpos($plugin, 'EE4') !== false |
|
344 | + || strpos($plugin, 'calendar') !== false |
|
345 | + ) { |
|
346 | + // this is what we are looking for |
|
347 | + $calendar_config = $plugin_path . '/EE_Calendar_Config.php'; |
|
348 | + // does it exist in this folder ? |
|
349 | + if (is_readable($calendar_config)) { |
|
350 | + // YEAH! let's load it |
|
351 | + require_once($calendar_config); |
|
352 | + } |
|
353 | + } |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * @param array|stdClass $settings |
|
360 | + * @param string $config |
|
361 | + * @param EE_Config $EE_Config |
|
362 | + * @return stdClass |
|
363 | + */ |
|
364 | + public static function migrate_old_config_data($settings, $config, EE_Config $EE_Config) |
|
365 | + { |
|
366 | + $convert_from_array = ['addons']; |
|
367 | + // in case old settings were saved as an array |
|
368 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
369 | + // convert existing settings to an object |
|
370 | + $config_array = $settings; |
|
371 | + $settings = new stdClass(); |
|
372 | + foreach ($config_array as $key => $value) { |
|
373 | + if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
374 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
375 | + } else { |
|
376 | + $settings->{$key} = $value; |
|
377 | + } |
|
378 | + } |
|
379 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
380 | + } |
|
381 | + return $settings; |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * @return void |
|
387 | + */ |
|
388 | + public static function deactivate_event_espresso() |
|
389 | + { |
|
390 | + // check permissions |
|
391 | + if (current_user_can('activate_plugins')) { |
|
392 | + deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
393 | + } |
|
394 | + } |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * @return void |
|
399 | + * @throws InvalidDataTypeException |
|
400 | + */ |
|
401 | + public static function verify_default_pages_exist() |
|
402 | + { |
|
403 | + $critical_page_problem = false; |
|
404 | + $critical_pages = [ |
|
405 | + [ |
|
406 | + 'id' => 'reg_page_id', |
|
407 | + 'name' => esc_html__('Registration Checkout', 'event_espresso'), |
|
408 | + 'post' => null, |
|
409 | + 'code' => 'ESPRESSO_CHECKOUT', |
|
410 | + ], |
|
411 | + [ |
|
412 | + 'id' => 'txn_page_id', |
|
413 | + 'name' => esc_html__('Transactions', 'event_espresso'), |
|
414 | + 'post' => null, |
|
415 | + 'code' => 'ESPRESSO_TXN_PAGE', |
|
416 | + ], |
|
417 | + [ |
|
418 | + 'id' => 'thank_you_page_id', |
|
419 | + 'name' => esc_html__('Thank You', 'event_espresso'), |
|
420 | + 'post' => null, |
|
421 | + 'code' => 'ESPRESSO_THANK_YOU', |
|
422 | + ], |
|
423 | + [ |
|
424 | + 'id' => 'cancel_page_id', |
|
425 | + 'name' => esc_html__('Registration Cancelled', 'event_espresso'), |
|
426 | + 'post' => null, |
|
427 | + 'code' => 'ESPRESSO_CANCELLED', |
|
428 | + ], |
|
429 | + ]; |
|
430 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
431 | + foreach ($critical_pages as $critical_page) { |
|
432 | + // is critical page ID set in config ? |
|
433 | + if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
434 | + // attempt to find post by ID |
|
435 | + $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
436 | + } |
|
437 | + // no dice? |
|
438 | + if ($critical_page['post'] === null) { |
|
439 | + // attempt to find post by title |
|
440 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
441 | + // still nothing? |
|
442 | + if ($critical_page['post'] === null) { |
|
443 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
444 | + // REALLY? Still nothing ??!?!? |
|
445 | + if ($critical_page['post'] === null) { |
|
446 | + $msg = esc_html__( |
|
447 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
448 | + 'event_espresso' |
|
449 | + ); |
|
450 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
451 | + break; |
|
452 | + } |
|
453 | + } |
|
454 | + } |
|
455 | + // check that Post ID matches critical page ID in config |
|
456 | + if ( |
|
457 | + isset($critical_page['post']->ID) |
|
458 | + && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
459 | + ) { |
|
460 | + // update Config with post ID |
|
461 | + $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
462 | + if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
463 | + $msg = esc_html__( |
|
464 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
465 | + 'event_espresso' |
|
466 | + ); |
|
467 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
468 | + } |
|
469 | + } |
|
470 | + $critical_page_problem = |
|
471 | + ! isset($critical_page['post']->post_status) |
|
472 | + || $critical_page['post']->post_status !== 'publish' |
|
473 | + || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
474 | + ? true |
|
475 | + : $critical_page_problem; |
|
476 | + } |
|
477 | + if ($critical_page_problem) { |
|
478 | + new PersistentAdminNotice( |
|
479 | + 'critical_page_problem', |
|
480 | + sprintf( |
|
481 | + esc_html__( |
|
482 | + 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
483 | + 'event_espresso' |
|
484 | + ), |
|
485 | + '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
486 | + . esc_html__('Event Espresso Critical Pages Settings', 'event_espresso') |
|
487 | + . '</a>' |
|
488 | + ) |
|
489 | + ); |
|
490 | + } |
|
491 | + if (EE_Error::has_notices()) { |
|
492 | + EE_Error::get_notices(false, true); |
|
493 | + } |
|
494 | + } |
|
495 | + |
|
496 | + |
|
497 | + /** |
|
498 | + * Returns the first post which uses the specified shortcode |
|
499 | + * |
|
500 | + * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
501 | + * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
502 | + * "[ESPRESSO_THANK_YOU" |
|
503 | + * (we don't search for the closing shortcode bracket because they might have added |
|
504 | + * parameter to the shortcode |
|
505 | + * @return WP_Post or NULl |
|
506 | + */ |
|
507 | + public static function get_page_by_ee_shortcode($ee_shortcode) |
|
508 | + { |
|
509 | + global $wpdb; |
|
510 | + $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
511 | + $post_id = |
|
512 | + $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
513 | + if ($post_id) { |
|
514 | + return get_post($post_id); |
|
515 | + } else { |
|
516 | + return null; |
|
517 | + } |
|
518 | + } |
|
519 | + |
|
520 | + |
|
521 | + /** |
|
522 | + * This function generates a post for critical espresso pages |
|
523 | + * |
|
524 | + * @param array $critical_page |
|
525 | + * @return array |
|
526 | + */ |
|
527 | + public static function create_critical_page($critical_page) |
|
528 | + { |
|
529 | + |
|
530 | + $post_args = [ |
|
531 | + 'post_title' => $critical_page['name'], |
|
532 | + 'post_status' => 'publish', |
|
533 | + 'post_type' => 'page', |
|
534 | + 'comment_status' => 'closed', |
|
535 | + 'post_content' => '[' . $critical_page['code'] . ']', |
|
536 | + ]; |
|
537 | + |
|
538 | + $post_id = wp_insert_post($post_args); |
|
539 | + if (! $post_id) { |
|
540 | + $msg = sprintf( |
|
541 | + esc_html__('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
542 | + $critical_page['name'] |
|
543 | + ); |
|
544 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
545 | + return $critical_page; |
|
546 | + } |
|
547 | + // get newly created post's details |
|
548 | + if (! $critical_page['post'] = get_post($post_id)) { |
|
549 | + $msg = sprintf( |
|
550 | + esc_html__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
551 | + $critical_page['name'] |
|
552 | + ); |
|
553 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
554 | + } |
|
555 | + |
|
556 | + return $critical_page; |
|
557 | + } |
|
558 | + |
|
559 | + |
|
560 | + /** |
|
561 | + * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
562 | + * The role being used to check is filterable. |
|
563 | + * |
|
564 | + * @return int|null WP_user ID or NULL |
|
565 | + * @throws EE_Error |
|
566 | + * @throws ReflectionException |
|
567 | + * @since 4.6.0 |
|
568 | + * @global WPDB $wpdb |
|
569 | + */ |
|
570 | + public static function get_default_creator_id() |
|
571 | + { |
|
572 | + global $wpdb; |
|
573 | + if (! empty(self::$_default_creator_id)) { |
|
574 | + return self::$_default_creator_id; |
|
575 | + }/**/ |
|
576 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
577 | + // let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
578 | + $pre_filtered_id = apply_filters( |
|
579 | + 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
580 | + false, |
|
581 | + $role_to_check |
|
582 | + ); |
|
583 | + if ($pre_filtered_id !== false) { |
|
584 | + return (int) $pre_filtered_id; |
|
585 | + } |
|
586 | + $capabilities_key = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
587 | + $query = $wpdb->prepare( |
|
588 | + "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
589 | + '%' . $role_to_check . '%' |
|
590 | + ); |
|
591 | + $user_id = $wpdb->get_var($query); |
|
592 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
593 | + if ($user_id && (int) $user_id) { |
|
594 | + self::$_default_creator_id = (int) $user_id; |
|
595 | + return self::$_default_creator_id; |
|
596 | + } else { |
|
597 | + return null; |
|
598 | + } |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * used by EE and EE addons during plugin activation to create tables. |
|
604 | + * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
605 | + * but includes extra logic regarding activations. |
|
606 | + * |
|
607 | + * @param string $table_name without the $wpdb->prefix |
|
608 | + * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
609 | + * table query) |
|
610 | + * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
611 | + * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
612 | + * and new once this function is done (ie, you really do want to CREATE a |
|
613 | + * table, and expect it to be empty once you're done) leave as FALSE when |
|
614 | + * you just want to verify the table exists and matches this definition |
|
615 | + * (and if it HAS data in it you want to leave it be) |
|
616 | + * @return void |
|
617 | + * @throws EE_Error if there are database errors |
|
618 | + * @throws ReflectionException |
|
619 | + */ |
|
620 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
621 | + { |
|
622 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
623 | + return; |
|
624 | + } |
|
625 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
626 | + if (! function_exists('dbDelta')) { |
|
627 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
628 | + } |
|
629 | + $tableAnalysis = EEH_Activation::getTableAnalysis(); |
|
630 | + $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
631 | + // do we need to first delete an existing version of this table ? |
|
632 | + if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
633 | + // ok, delete the table... but ONLY if it's empty |
|
634 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
635 | + // table is NOT empty, are you SURE you want to delete this table ??? |
|
636 | + if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
637 | + EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
638 | + } elseif (! $deleted_safely) { |
|
639 | + // so we should be more cautious rather than just dropping tables so easily |
|
640 | + error_log( |
|
641 | + sprintf( |
|
642 | + esc_html__( |
|
643 | + 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
644 | + 'event_espresso' |
|
645 | + ), |
|
646 | + $wp_table_name, |
|
647 | + '<br/>', |
|
648 | + 'espresso_db_update' |
|
649 | + ) |
|
650 | + ); |
|
651 | + } |
|
652 | + } |
|
653 | + $engine = str_replace('ENGINE=', '', $engine); |
|
654 | + EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
655 | + } |
|
656 | + |
|
657 | + |
|
658 | + /** |
|
659 | + * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
660 | + * |
|
661 | + * @param string $table_name (without "wp_", eg "esp_attendee" |
|
662 | + * @param string $column_name |
|
663 | + * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
664 | + * 'VARCHAR(10)' |
|
665 | + * @return bool|int |
|
666 | + * @throws EE_Error |
|
667 | + * @throws ReflectionException |
|
668 | + * @deprecated instead use TableManager::addColumn() |
|
669 | + */ |
|
670 | + public static function add_column_if_it_doesnt_exist( |
|
671 | + $table_name, |
|
672 | + $column_name, |
|
673 | + $column_info = 'INT UNSIGNED NOT NULL' |
|
674 | + ) { |
|
675 | + return EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
676 | + } |
|
677 | + |
|
678 | + |
|
679 | + /** |
|
680 | + * Gets all the fields on the database table. |
|
681 | + * |
|
682 | + * @param string $table_name , without prefixed $wpdb->prefix |
|
683 | + * @return array of database column names |
|
684 | + * @throws EE_Error |
|
685 | + * @throws ReflectionException |
|
686 | + * @deprecated instead use TableManager::getTableColumns() |
|
687 | + */ |
|
688 | + public static function get_fields_on_table($table_name = null) |
|
689 | + { |
|
690 | + return EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
691 | + } |
|
692 | + |
|
693 | + |
|
694 | + /** |
|
695 | + * @param string $table_name |
|
696 | + * @return bool |
|
697 | + * @throws EE_Error |
|
698 | + * @throws ReflectionException |
|
699 | + * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
700 | + */ |
|
701 | + public static function db_table_is_empty($table_name) |
|
702 | + { |
|
703 | + return EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
704 | + } |
|
705 | + |
|
706 | + |
|
707 | + /** |
|
708 | + * @param string $table_name |
|
709 | + * @return bool | int |
|
710 | + * @throws EE_Error |
|
711 | + * @throws ReflectionException |
|
712 | + */ |
|
713 | + public static function delete_db_table_if_empty($table_name) |
|
714 | + { |
|
715 | + if (EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
716 | + return EEH_Activation::getTableManager()->dropTable($table_name); |
|
717 | + } |
|
718 | + return false; |
|
719 | + } |
|
720 | + |
|
721 | + |
|
722 | + /** |
|
723 | + * @param string $table_name |
|
724 | + * @return int |
|
725 | + * @throws EE_Error |
|
726 | + * @throws ReflectionException |
|
727 | + * @deprecated instead use TableManager::dropTable() |
|
728 | + */ |
|
729 | + public static function delete_unused_db_table($table_name) |
|
730 | + { |
|
731 | + return EEH_Activation::getTableManager()->dropTable($table_name); |
|
732 | + } |
|
733 | + |
|
734 | + |
|
735 | + /** |
|
736 | + * @param string $table_name |
|
737 | + * @param string $index_name |
|
738 | + * @return int |
|
739 | + * @throws EE_Error |
|
740 | + * @throws ReflectionException |
|
741 | + * @deprecated instead use TableManager::dropIndex() |
|
742 | + */ |
|
743 | + public static function drop_index($table_name, $index_name) |
|
744 | + { |
|
745 | + return EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
746 | + } |
|
747 | + |
|
748 | + |
|
749 | + /** |
|
750 | + * @return boolean success (whether database is setup properly or not) |
|
751 | + * @throws EE_Error |
|
752 | + * @throws ReflectionException |
|
753 | + */ |
|
754 | + public static function create_database_tables() |
|
755 | + { |
|
756 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
757 | + // find the migration script that sets the database to be compatible with the code |
|
758 | + $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
759 | + if (! $dms_name) { |
|
760 | + EE_Error::add_error( |
|
761 | + esc_html__( |
|
762 | + 'Could not determine most up-to-date data migration script from which to pull database schema |
|
763 | 763 | structure. So database is probably not setup properly', |
764 | - 'event_espresso' |
|
765 | - ), |
|
766 | - __FILE__, |
|
767 | - __FUNCTION__, |
|
768 | - __LINE__ |
|
769 | - ); |
|
770 | - return false; |
|
771 | - } |
|
772 | - $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
773 | - $current_data_migration_script->set_migrating(false); |
|
774 | - $current_data_migration_script->schema_changes_before_migration(); |
|
775 | - $current_data_migration_script->schema_changes_after_migration(); |
|
776 | - if ($current_data_migration_script->get_errors()) { |
|
777 | - if (WP_DEBUG) { |
|
778 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
779 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
780 | - } |
|
781 | - } else { |
|
782 | - EE_Error::add_error( |
|
783 | - esc_html__( |
|
784 | - 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
764 | + 'event_espresso' |
|
765 | + ), |
|
766 | + __FILE__, |
|
767 | + __FUNCTION__, |
|
768 | + __LINE__ |
|
769 | + ); |
|
770 | + return false; |
|
771 | + } |
|
772 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
773 | + $current_data_migration_script->set_migrating(false); |
|
774 | + $current_data_migration_script->schema_changes_before_migration(); |
|
775 | + $current_data_migration_script->schema_changes_after_migration(); |
|
776 | + if ($current_data_migration_script->get_errors()) { |
|
777 | + if (WP_DEBUG) { |
|
778 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
779 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
780 | + } |
|
781 | + } else { |
|
782 | + EE_Error::add_error( |
|
783 | + esc_html__( |
|
784 | + 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
785 | 785 | deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', |
786 | - 'event_espresso' |
|
787 | - ) |
|
788 | - ); |
|
789 | - } |
|
790 | - return false; |
|
791 | - } |
|
792 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
793 | - return true; |
|
794 | - } |
|
795 | - |
|
796 | - |
|
797 | - /** |
|
798 | - * @return void |
|
799 | - * @throws EE_Error |
|
800 | - * @throws ReflectionException |
|
801 | - */ |
|
802 | - public static function initialize_system_questions() |
|
803 | - { |
|
804 | - // QUESTION GROUPS |
|
805 | - global $wpdb; |
|
806 | - $table_name = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
807 | - $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
808 | - // what we have |
|
809 | - $question_groups = $wpdb->get_col($SQL); |
|
810 | - // check the response |
|
811 | - $question_groups = is_array($question_groups) ? $question_groups : []; |
|
812 | - // what we should have |
|
813 | - $QSG_systems = [1, 2]; |
|
814 | - // loop thru what we should have and compare to what we have |
|
815 | - foreach ($QSG_systems as $QSG_system) { |
|
816 | - // reset values array |
|
817 | - $QSG_values = []; |
|
818 | - // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
819 | - if (! in_array("$QSG_system", $question_groups)) { |
|
820 | - // add it |
|
821 | - switch ($QSG_system) { |
|
822 | - case 1: |
|
823 | - $QSG_values = [ |
|
824 | - 'QSG_name' => esc_html__('Personal Information', 'event_espresso'), |
|
825 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
826 | - 'QSG_desc' => '', |
|
827 | - 'QSG_order' => 1, |
|
828 | - 'QSG_show_group_name' => 1, |
|
829 | - 'QSG_show_group_desc' => 1, |
|
830 | - 'QSG_system' => EEM_Question_Group::system_personal, |
|
831 | - 'QSG_deleted' => 0, |
|
832 | - ]; |
|
833 | - break; |
|
834 | - case 2: |
|
835 | - $QSG_values = [ |
|
836 | - 'QSG_name' => esc_html__('Address Information', 'event_espresso'), |
|
837 | - 'QSG_identifier' => 'address-information-' . time(), |
|
838 | - 'QSG_desc' => '', |
|
839 | - 'QSG_order' => 2, |
|
840 | - 'QSG_show_group_name' => 1, |
|
841 | - 'QSG_show_group_desc' => 1, |
|
842 | - 'QSG_system' => EEM_Question_Group::system_address, |
|
843 | - 'QSG_deleted' => 0, |
|
844 | - ]; |
|
845 | - break; |
|
846 | - } |
|
847 | - // make sure we have some values before inserting them |
|
848 | - if (! empty($QSG_values)) { |
|
849 | - // insert system question |
|
850 | - $wpdb->insert( |
|
851 | - $table_name, |
|
852 | - $QSG_values, |
|
853 | - ['%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d'] |
|
854 | - ); |
|
855 | - $QSG_IDs[ $QSG_system ] = $wpdb->insert_id; |
|
856 | - } |
|
857 | - } |
|
858 | - } |
|
859 | - // QUESTIONS |
|
860 | - global $wpdb; |
|
861 | - $table_name = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
862 | - $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
863 | - // what we have |
|
864 | - $questions = $wpdb->get_col($SQL); |
|
865 | - // all system questions |
|
866 | - $personal_system_group_questions = ['fname', 'lname', 'email']; |
|
867 | - $address_system_group_questions = ['address', 'address2', 'city', 'country', 'state', 'zip', 'phone']; |
|
868 | - $system_questions_not_in_group = ['email_confirm']; |
|
869 | - // merge all of the system questions we should have |
|
870 | - $QST_systems = array_merge( |
|
871 | - $personal_system_group_questions, |
|
872 | - $address_system_group_questions, |
|
873 | - $system_questions_not_in_group |
|
874 | - ); |
|
875 | - $order_for_group_1 = 1; |
|
876 | - $order_for_group_2 = 1; |
|
877 | - // loop thru what we should have and compare to what we have |
|
878 | - foreach ($QST_systems as $QST_system) { |
|
879 | - // reset values array |
|
880 | - $QST_values = []; |
|
881 | - // if we don't have what we should have |
|
882 | - if (! in_array($QST_system, $questions)) { |
|
883 | - // add it |
|
884 | - switch ($QST_system) { |
|
885 | - case 'fname': |
|
886 | - $QST_values = [ |
|
887 | - 'QST_display_text' => esc_html__('First Name', 'event_espresso'), |
|
888 | - 'QST_admin_label' => esc_html__('First Name - System Question', 'event_espresso'), |
|
889 | - 'QST_system' => 'fname', |
|
890 | - 'QST_type' => 'TEXT', |
|
891 | - 'QST_required' => 1, |
|
892 | - 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
893 | - 'QST_order' => 1, |
|
894 | - 'QST_admin_only' => 0, |
|
895 | - 'QST_max' => EEM_Question::instance() |
|
896 | - ->absolute_max_for_system_question($QST_system), |
|
897 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
898 | - 'QST_deleted' => 0, |
|
899 | - ]; |
|
900 | - break; |
|
901 | - case 'lname': |
|
902 | - $QST_values = [ |
|
903 | - 'QST_display_text' => esc_html__('Last Name', 'event_espresso'), |
|
904 | - 'QST_admin_label' => esc_html__('Last Name - System Question', 'event_espresso'), |
|
905 | - 'QST_system' => 'lname', |
|
906 | - 'QST_type' => 'TEXT', |
|
907 | - 'QST_required' => 1, |
|
908 | - 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
909 | - 'QST_order' => 2, |
|
910 | - 'QST_admin_only' => 0, |
|
911 | - 'QST_max' => EEM_Question::instance() |
|
912 | - ->absolute_max_for_system_question($QST_system), |
|
913 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
914 | - 'QST_deleted' => 0, |
|
915 | - ]; |
|
916 | - break; |
|
917 | - case 'email': |
|
918 | - $QST_values = [ |
|
919 | - 'QST_display_text' => esc_html__('Email Address', 'event_espresso'), |
|
920 | - 'QST_admin_label' => esc_html__('Email Address - System Question', 'event_espresso'), |
|
921 | - 'QST_system' => 'email', |
|
922 | - 'QST_type' => 'EMAIL', |
|
923 | - 'QST_required' => 1, |
|
924 | - 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
925 | - 'QST_order' => 3, |
|
926 | - 'QST_admin_only' => 0, |
|
927 | - 'QST_max' => EEM_Question::instance() |
|
928 | - ->absolute_max_for_system_question($QST_system), |
|
929 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
930 | - 'QST_deleted' => 0, |
|
931 | - ]; |
|
932 | - break; |
|
933 | - case 'email_confirm': |
|
934 | - $QST_values = [ |
|
935 | - 'QST_display_text' => esc_html__('Confirm Email Address', 'event_espresso'), |
|
936 | - 'QST_admin_label' => esc_html__('Confirm Email Address - System Question', 'event_espresso'), |
|
937 | - 'QST_system' => 'email_confirm', |
|
938 | - 'QST_type' => 'EMAIL_CONFIRM', |
|
939 | - 'QST_required' => 1, |
|
940 | - 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
941 | - 'QST_order' => 4, |
|
942 | - 'QST_admin_only' => 0, |
|
943 | - 'QST_max' => EEM_Question::instance() |
|
944 | - ->absolute_max_for_system_question($QST_system), |
|
945 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
946 | - 'QST_deleted' => 0, |
|
947 | - ]; |
|
948 | - break; |
|
949 | - case 'address': |
|
950 | - $QST_values = [ |
|
951 | - 'QST_display_text' => esc_html__('Address', 'event_espresso'), |
|
952 | - 'QST_admin_label' => esc_html__('Address - System Question', 'event_espresso'), |
|
953 | - 'QST_system' => 'address', |
|
954 | - 'QST_type' => 'TEXT', |
|
955 | - 'QST_required' => 0, |
|
956 | - 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
957 | - 'QST_order' => 5, |
|
958 | - 'QST_admin_only' => 0, |
|
959 | - 'QST_max' => EEM_Question::instance() |
|
960 | - ->absolute_max_for_system_question($QST_system), |
|
961 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
962 | - 'QST_deleted' => 0, |
|
963 | - ]; |
|
964 | - break; |
|
965 | - case 'address2': |
|
966 | - $QST_values = [ |
|
967 | - 'QST_display_text' => esc_html__('Address2', 'event_espresso'), |
|
968 | - 'QST_admin_label' => esc_html__('Address2 - System Question', 'event_espresso'), |
|
969 | - 'QST_system' => 'address2', |
|
970 | - 'QST_type' => 'TEXT', |
|
971 | - 'QST_required' => 0, |
|
972 | - 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
973 | - 'QST_order' => 6, |
|
974 | - 'QST_admin_only' => 0, |
|
975 | - 'QST_max' => EEM_Question::instance() |
|
976 | - ->absolute_max_for_system_question($QST_system), |
|
977 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
978 | - 'QST_deleted' => 0, |
|
979 | - ]; |
|
980 | - break; |
|
981 | - case 'city': |
|
982 | - $QST_values = [ |
|
983 | - 'QST_display_text' => esc_html__('City', 'event_espresso'), |
|
984 | - 'QST_admin_label' => esc_html__('City - System Question', 'event_espresso'), |
|
985 | - 'QST_system' => 'city', |
|
986 | - 'QST_type' => 'TEXT', |
|
987 | - 'QST_required' => 0, |
|
988 | - 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
989 | - 'QST_order' => 7, |
|
990 | - 'QST_admin_only' => 0, |
|
991 | - 'QST_max' => EEM_Question::instance() |
|
992 | - ->absolute_max_for_system_question($QST_system), |
|
993 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
994 | - 'QST_deleted' => 0, |
|
995 | - ]; |
|
996 | - break; |
|
997 | - case 'country': |
|
998 | - $QST_values = [ |
|
999 | - 'QST_display_text' => esc_html__('Country', 'event_espresso'), |
|
1000 | - 'QST_admin_label' => esc_html__('Country - System Question', 'event_espresso'), |
|
1001 | - 'QST_system' => 'country', |
|
1002 | - 'QST_type' => 'COUNTRY', |
|
1003 | - 'QST_required' => 0, |
|
1004 | - 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
1005 | - 'QST_order' => 8, |
|
1006 | - 'QST_admin_only' => 0, |
|
1007 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1008 | - 'QST_deleted' => 0, |
|
1009 | - ]; |
|
1010 | - break; |
|
1011 | - case 'state': |
|
1012 | - $QST_values = [ |
|
1013 | - 'QST_display_text' => esc_html__('State/Province', 'event_espresso'), |
|
1014 | - 'QST_admin_label' => esc_html__('State/Province - System Question', 'event_espresso'), |
|
1015 | - 'QST_system' => 'state', |
|
1016 | - 'QST_type' => 'STATE', |
|
1017 | - 'QST_required' => 0, |
|
1018 | - 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
1019 | - 'QST_order' => 9, |
|
1020 | - 'QST_admin_only' => 0, |
|
1021 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1022 | - 'QST_deleted' => 0, |
|
1023 | - ]; |
|
1024 | - break; |
|
1025 | - case 'zip': |
|
1026 | - $QST_values = [ |
|
1027 | - 'QST_display_text' => esc_html__('Zip/Postal Code', 'event_espresso'), |
|
1028 | - 'QST_admin_label' => esc_html__('Zip/Postal Code - System Question', 'event_espresso'), |
|
1029 | - 'QST_system' => 'zip', |
|
1030 | - 'QST_type' => 'TEXT', |
|
1031 | - 'QST_required' => 0, |
|
1032 | - 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
1033 | - 'QST_order' => 10, |
|
1034 | - 'QST_admin_only' => 0, |
|
1035 | - 'QST_max' => EEM_Question::instance() |
|
1036 | - ->absolute_max_for_system_question($QST_system), |
|
1037 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1038 | - 'QST_deleted' => 0, |
|
1039 | - ]; |
|
1040 | - break; |
|
1041 | - case 'phone': |
|
1042 | - $QST_values = [ |
|
1043 | - 'QST_display_text' => esc_html__('Phone Number', 'event_espresso'), |
|
1044 | - 'QST_admin_label' => esc_html__('Phone Number - System Question', 'event_espresso'), |
|
1045 | - 'QST_system' => 'phone', |
|
1046 | - 'QST_type' => 'TEXT', |
|
1047 | - 'QST_required' => 0, |
|
1048 | - 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
1049 | - 'QST_order' => 11, |
|
1050 | - 'QST_admin_only' => 0, |
|
1051 | - 'QST_max' => EEM_Question::instance() |
|
1052 | - ->absolute_max_for_system_question($QST_system), |
|
1053 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1054 | - 'QST_deleted' => 0, |
|
1055 | - ]; |
|
1056 | - break; |
|
1057 | - } |
|
1058 | - if (! empty($QST_values)) { |
|
1059 | - // insert system question |
|
1060 | - $wpdb->insert( |
|
1061 | - $table_name, |
|
1062 | - $QST_values, |
|
1063 | - ['%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d'] |
|
1064 | - ); |
|
1065 | - $QST_ID = $wpdb->insert_id; |
|
1066 | - |
|
1067 | - // QUESTION GROUP QUESTIONS |
|
1068 | - if (in_array($QST_system, $personal_system_group_questions)) { |
|
1069 | - $system_question_we_want = EEM_Question_Group::system_personal; |
|
1070 | - } elseif (in_array($QST_system, $address_system_group_questions)) { |
|
1071 | - $system_question_we_want = EEM_Question_Group::system_address; |
|
1072 | - } else { |
|
1073 | - // QST_system should not be assigned to any group |
|
1074 | - continue; |
|
1075 | - } |
|
1076 | - if (isset($QSG_IDs[ $system_question_we_want ])) { |
|
1077 | - $QSG_ID = $QSG_IDs[ $system_question_we_want ]; |
|
1078 | - } else { |
|
1079 | - $id_col = EEM_Question_Group::instance() |
|
1080 | - ->get_col([['QSG_system' => $system_question_we_want]]); |
|
1081 | - if (is_array($id_col)) { |
|
1082 | - $QSG_ID = reset($id_col); |
|
1083 | - } else { |
|
1084 | - // ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
1085 | - EE_Log::instance()->log( |
|
1086 | - __FILE__, |
|
1087 | - __FUNCTION__, |
|
1088 | - sprintf( |
|
1089 | - esc_html__( |
|
1090 | - 'Could not associate question %1$s to a question group because no system question |
|
786 | + 'event_espresso' |
|
787 | + ) |
|
788 | + ); |
|
789 | + } |
|
790 | + return false; |
|
791 | + } |
|
792 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
793 | + return true; |
|
794 | + } |
|
795 | + |
|
796 | + |
|
797 | + /** |
|
798 | + * @return void |
|
799 | + * @throws EE_Error |
|
800 | + * @throws ReflectionException |
|
801 | + */ |
|
802 | + public static function initialize_system_questions() |
|
803 | + { |
|
804 | + // QUESTION GROUPS |
|
805 | + global $wpdb; |
|
806 | + $table_name = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
807 | + $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
808 | + // what we have |
|
809 | + $question_groups = $wpdb->get_col($SQL); |
|
810 | + // check the response |
|
811 | + $question_groups = is_array($question_groups) ? $question_groups : []; |
|
812 | + // what we should have |
|
813 | + $QSG_systems = [1, 2]; |
|
814 | + // loop thru what we should have and compare to what we have |
|
815 | + foreach ($QSG_systems as $QSG_system) { |
|
816 | + // reset values array |
|
817 | + $QSG_values = []; |
|
818 | + // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
819 | + if (! in_array("$QSG_system", $question_groups)) { |
|
820 | + // add it |
|
821 | + switch ($QSG_system) { |
|
822 | + case 1: |
|
823 | + $QSG_values = [ |
|
824 | + 'QSG_name' => esc_html__('Personal Information', 'event_espresso'), |
|
825 | + 'QSG_identifier' => 'personal-information-' . time(), |
|
826 | + 'QSG_desc' => '', |
|
827 | + 'QSG_order' => 1, |
|
828 | + 'QSG_show_group_name' => 1, |
|
829 | + 'QSG_show_group_desc' => 1, |
|
830 | + 'QSG_system' => EEM_Question_Group::system_personal, |
|
831 | + 'QSG_deleted' => 0, |
|
832 | + ]; |
|
833 | + break; |
|
834 | + case 2: |
|
835 | + $QSG_values = [ |
|
836 | + 'QSG_name' => esc_html__('Address Information', 'event_espresso'), |
|
837 | + 'QSG_identifier' => 'address-information-' . time(), |
|
838 | + 'QSG_desc' => '', |
|
839 | + 'QSG_order' => 2, |
|
840 | + 'QSG_show_group_name' => 1, |
|
841 | + 'QSG_show_group_desc' => 1, |
|
842 | + 'QSG_system' => EEM_Question_Group::system_address, |
|
843 | + 'QSG_deleted' => 0, |
|
844 | + ]; |
|
845 | + break; |
|
846 | + } |
|
847 | + // make sure we have some values before inserting them |
|
848 | + if (! empty($QSG_values)) { |
|
849 | + // insert system question |
|
850 | + $wpdb->insert( |
|
851 | + $table_name, |
|
852 | + $QSG_values, |
|
853 | + ['%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d'] |
|
854 | + ); |
|
855 | + $QSG_IDs[ $QSG_system ] = $wpdb->insert_id; |
|
856 | + } |
|
857 | + } |
|
858 | + } |
|
859 | + // QUESTIONS |
|
860 | + global $wpdb; |
|
861 | + $table_name = EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
862 | + $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
863 | + // what we have |
|
864 | + $questions = $wpdb->get_col($SQL); |
|
865 | + // all system questions |
|
866 | + $personal_system_group_questions = ['fname', 'lname', 'email']; |
|
867 | + $address_system_group_questions = ['address', 'address2', 'city', 'country', 'state', 'zip', 'phone']; |
|
868 | + $system_questions_not_in_group = ['email_confirm']; |
|
869 | + // merge all of the system questions we should have |
|
870 | + $QST_systems = array_merge( |
|
871 | + $personal_system_group_questions, |
|
872 | + $address_system_group_questions, |
|
873 | + $system_questions_not_in_group |
|
874 | + ); |
|
875 | + $order_for_group_1 = 1; |
|
876 | + $order_for_group_2 = 1; |
|
877 | + // loop thru what we should have and compare to what we have |
|
878 | + foreach ($QST_systems as $QST_system) { |
|
879 | + // reset values array |
|
880 | + $QST_values = []; |
|
881 | + // if we don't have what we should have |
|
882 | + if (! in_array($QST_system, $questions)) { |
|
883 | + // add it |
|
884 | + switch ($QST_system) { |
|
885 | + case 'fname': |
|
886 | + $QST_values = [ |
|
887 | + 'QST_display_text' => esc_html__('First Name', 'event_espresso'), |
|
888 | + 'QST_admin_label' => esc_html__('First Name - System Question', 'event_espresso'), |
|
889 | + 'QST_system' => 'fname', |
|
890 | + 'QST_type' => 'TEXT', |
|
891 | + 'QST_required' => 1, |
|
892 | + 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
893 | + 'QST_order' => 1, |
|
894 | + 'QST_admin_only' => 0, |
|
895 | + 'QST_max' => EEM_Question::instance() |
|
896 | + ->absolute_max_for_system_question($QST_system), |
|
897 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
898 | + 'QST_deleted' => 0, |
|
899 | + ]; |
|
900 | + break; |
|
901 | + case 'lname': |
|
902 | + $QST_values = [ |
|
903 | + 'QST_display_text' => esc_html__('Last Name', 'event_espresso'), |
|
904 | + 'QST_admin_label' => esc_html__('Last Name - System Question', 'event_espresso'), |
|
905 | + 'QST_system' => 'lname', |
|
906 | + 'QST_type' => 'TEXT', |
|
907 | + 'QST_required' => 1, |
|
908 | + 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
909 | + 'QST_order' => 2, |
|
910 | + 'QST_admin_only' => 0, |
|
911 | + 'QST_max' => EEM_Question::instance() |
|
912 | + ->absolute_max_for_system_question($QST_system), |
|
913 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
914 | + 'QST_deleted' => 0, |
|
915 | + ]; |
|
916 | + break; |
|
917 | + case 'email': |
|
918 | + $QST_values = [ |
|
919 | + 'QST_display_text' => esc_html__('Email Address', 'event_espresso'), |
|
920 | + 'QST_admin_label' => esc_html__('Email Address - System Question', 'event_espresso'), |
|
921 | + 'QST_system' => 'email', |
|
922 | + 'QST_type' => 'EMAIL', |
|
923 | + 'QST_required' => 1, |
|
924 | + 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
925 | + 'QST_order' => 3, |
|
926 | + 'QST_admin_only' => 0, |
|
927 | + 'QST_max' => EEM_Question::instance() |
|
928 | + ->absolute_max_for_system_question($QST_system), |
|
929 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
930 | + 'QST_deleted' => 0, |
|
931 | + ]; |
|
932 | + break; |
|
933 | + case 'email_confirm': |
|
934 | + $QST_values = [ |
|
935 | + 'QST_display_text' => esc_html__('Confirm Email Address', 'event_espresso'), |
|
936 | + 'QST_admin_label' => esc_html__('Confirm Email Address - System Question', 'event_espresso'), |
|
937 | + 'QST_system' => 'email_confirm', |
|
938 | + 'QST_type' => 'EMAIL_CONFIRM', |
|
939 | + 'QST_required' => 1, |
|
940 | + 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
941 | + 'QST_order' => 4, |
|
942 | + 'QST_admin_only' => 0, |
|
943 | + 'QST_max' => EEM_Question::instance() |
|
944 | + ->absolute_max_for_system_question($QST_system), |
|
945 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
946 | + 'QST_deleted' => 0, |
|
947 | + ]; |
|
948 | + break; |
|
949 | + case 'address': |
|
950 | + $QST_values = [ |
|
951 | + 'QST_display_text' => esc_html__('Address', 'event_espresso'), |
|
952 | + 'QST_admin_label' => esc_html__('Address - System Question', 'event_espresso'), |
|
953 | + 'QST_system' => 'address', |
|
954 | + 'QST_type' => 'TEXT', |
|
955 | + 'QST_required' => 0, |
|
956 | + 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
957 | + 'QST_order' => 5, |
|
958 | + 'QST_admin_only' => 0, |
|
959 | + 'QST_max' => EEM_Question::instance() |
|
960 | + ->absolute_max_for_system_question($QST_system), |
|
961 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
962 | + 'QST_deleted' => 0, |
|
963 | + ]; |
|
964 | + break; |
|
965 | + case 'address2': |
|
966 | + $QST_values = [ |
|
967 | + 'QST_display_text' => esc_html__('Address2', 'event_espresso'), |
|
968 | + 'QST_admin_label' => esc_html__('Address2 - System Question', 'event_espresso'), |
|
969 | + 'QST_system' => 'address2', |
|
970 | + 'QST_type' => 'TEXT', |
|
971 | + 'QST_required' => 0, |
|
972 | + 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
973 | + 'QST_order' => 6, |
|
974 | + 'QST_admin_only' => 0, |
|
975 | + 'QST_max' => EEM_Question::instance() |
|
976 | + ->absolute_max_for_system_question($QST_system), |
|
977 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
978 | + 'QST_deleted' => 0, |
|
979 | + ]; |
|
980 | + break; |
|
981 | + case 'city': |
|
982 | + $QST_values = [ |
|
983 | + 'QST_display_text' => esc_html__('City', 'event_espresso'), |
|
984 | + 'QST_admin_label' => esc_html__('City - System Question', 'event_espresso'), |
|
985 | + 'QST_system' => 'city', |
|
986 | + 'QST_type' => 'TEXT', |
|
987 | + 'QST_required' => 0, |
|
988 | + 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
989 | + 'QST_order' => 7, |
|
990 | + 'QST_admin_only' => 0, |
|
991 | + 'QST_max' => EEM_Question::instance() |
|
992 | + ->absolute_max_for_system_question($QST_system), |
|
993 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
994 | + 'QST_deleted' => 0, |
|
995 | + ]; |
|
996 | + break; |
|
997 | + case 'country': |
|
998 | + $QST_values = [ |
|
999 | + 'QST_display_text' => esc_html__('Country', 'event_espresso'), |
|
1000 | + 'QST_admin_label' => esc_html__('Country - System Question', 'event_espresso'), |
|
1001 | + 'QST_system' => 'country', |
|
1002 | + 'QST_type' => 'COUNTRY', |
|
1003 | + 'QST_required' => 0, |
|
1004 | + 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
1005 | + 'QST_order' => 8, |
|
1006 | + 'QST_admin_only' => 0, |
|
1007 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1008 | + 'QST_deleted' => 0, |
|
1009 | + ]; |
|
1010 | + break; |
|
1011 | + case 'state': |
|
1012 | + $QST_values = [ |
|
1013 | + 'QST_display_text' => esc_html__('State/Province', 'event_espresso'), |
|
1014 | + 'QST_admin_label' => esc_html__('State/Province - System Question', 'event_espresso'), |
|
1015 | + 'QST_system' => 'state', |
|
1016 | + 'QST_type' => 'STATE', |
|
1017 | + 'QST_required' => 0, |
|
1018 | + 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
1019 | + 'QST_order' => 9, |
|
1020 | + 'QST_admin_only' => 0, |
|
1021 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1022 | + 'QST_deleted' => 0, |
|
1023 | + ]; |
|
1024 | + break; |
|
1025 | + case 'zip': |
|
1026 | + $QST_values = [ |
|
1027 | + 'QST_display_text' => esc_html__('Zip/Postal Code', 'event_espresso'), |
|
1028 | + 'QST_admin_label' => esc_html__('Zip/Postal Code - System Question', 'event_espresso'), |
|
1029 | + 'QST_system' => 'zip', |
|
1030 | + 'QST_type' => 'TEXT', |
|
1031 | + 'QST_required' => 0, |
|
1032 | + 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
1033 | + 'QST_order' => 10, |
|
1034 | + 'QST_admin_only' => 0, |
|
1035 | + 'QST_max' => EEM_Question::instance() |
|
1036 | + ->absolute_max_for_system_question($QST_system), |
|
1037 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1038 | + 'QST_deleted' => 0, |
|
1039 | + ]; |
|
1040 | + break; |
|
1041 | + case 'phone': |
|
1042 | + $QST_values = [ |
|
1043 | + 'QST_display_text' => esc_html__('Phone Number', 'event_espresso'), |
|
1044 | + 'QST_admin_label' => esc_html__('Phone Number - System Question', 'event_espresso'), |
|
1045 | + 'QST_system' => 'phone', |
|
1046 | + 'QST_type' => 'TEXT', |
|
1047 | + 'QST_required' => 0, |
|
1048 | + 'QST_required_text' => esc_html__('This field is required', 'event_espresso'), |
|
1049 | + 'QST_order' => 11, |
|
1050 | + 'QST_admin_only' => 0, |
|
1051 | + 'QST_max' => EEM_Question::instance() |
|
1052 | + ->absolute_max_for_system_question($QST_system), |
|
1053 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1054 | + 'QST_deleted' => 0, |
|
1055 | + ]; |
|
1056 | + break; |
|
1057 | + } |
|
1058 | + if (! empty($QST_values)) { |
|
1059 | + // insert system question |
|
1060 | + $wpdb->insert( |
|
1061 | + $table_name, |
|
1062 | + $QST_values, |
|
1063 | + ['%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d'] |
|
1064 | + ); |
|
1065 | + $QST_ID = $wpdb->insert_id; |
|
1066 | + |
|
1067 | + // QUESTION GROUP QUESTIONS |
|
1068 | + if (in_array($QST_system, $personal_system_group_questions)) { |
|
1069 | + $system_question_we_want = EEM_Question_Group::system_personal; |
|
1070 | + } elseif (in_array($QST_system, $address_system_group_questions)) { |
|
1071 | + $system_question_we_want = EEM_Question_Group::system_address; |
|
1072 | + } else { |
|
1073 | + // QST_system should not be assigned to any group |
|
1074 | + continue; |
|
1075 | + } |
|
1076 | + if (isset($QSG_IDs[ $system_question_we_want ])) { |
|
1077 | + $QSG_ID = $QSG_IDs[ $system_question_we_want ]; |
|
1078 | + } else { |
|
1079 | + $id_col = EEM_Question_Group::instance() |
|
1080 | + ->get_col([['QSG_system' => $system_question_we_want]]); |
|
1081 | + if (is_array($id_col)) { |
|
1082 | + $QSG_ID = reset($id_col); |
|
1083 | + } else { |
|
1084 | + // ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
1085 | + EE_Log::instance()->log( |
|
1086 | + __FILE__, |
|
1087 | + __FUNCTION__, |
|
1088 | + sprintf( |
|
1089 | + esc_html__( |
|
1090 | + 'Could not associate question %1$s to a question group because no system question |
|
1091 | 1091 | group existed', |
1092 | - 'event_espresso' |
|
1093 | - ), |
|
1094 | - $QST_ID |
|
1095 | - ), |
|
1096 | - 'error' |
|
1097 | - ); |
|
1098 | - continue; |
|
1099 | - } |
|
1100 | - } |
|
1101 | - // add system questions to groups |
|
1102 | - $wpdb->insert( |
|
1103 | - EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
1104 | - [ |
|
1105 | - 'QSG_ID' => $QSG_ID, |
|
1106 | - 'QST_ID' => $QST_ID, |
|
1107 | - 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
1108 | - ], |
|
1109 | - ['%d', '%d', '%d'] |
|
1110 | - ); |
|
1111 | - } |
|
1112 | - } |
|
1113 | - } |
|
1114 | - } |
|
1115 | - |
|
1116 | - |
|
1117 | - /** |
|
1118 | - * Makes sure the default payment method (Invoice) is active. |
|
1119 | - * This used to be done automatically as part of constructing the old gateways config |
|
1120 | - * |
|
1121 | - * @throws EE_Error |
|
1122 | - * @throws ReflectionException |
|
1123 | - */ |
|
1124 | - public static function insert_default_payment_methods() |
|
1125 | - { |
|
1126 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1127 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1128 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1129 | - } else { |
|
1130 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
1131 | - } |
|
1132 | - } |
|
1133 | - |
|
1134 | - |
|
1135 | - /** |
|
1136 | - * @return void |
|
1137 | - * @throws EE_Error |
|
1138 | - * @throws ReflectionException |
|
1139 | - */ |
|
1140 | - public static function insert_default_status_codes() |
|
1141 | - { |
|
1142 | - |
|
1143 | - global $wpdb; |
|
1144 | - |
|
1145 | - if (EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
1146 | - $table_name = EEM_Status::instance()->table(); |
|
1147 | - |
|
1148 | - $SQL = |
|
1149 | - "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
1150 | - $wpdb->query($SQL); |
|
1151 | - |
|
1152 | - $SQL = "INSERT INTO $table_name |
|
1092 | + 'event_espresso' |
|
1093 | + ), |
|
1094 | + $QST_ID |
|
1095 | + ), |
|
1096 | + 'error' |
|
1097 | + ); |
|
1098 | + continue; |
|
1099 | + } |
|
1100 | + } |
|
1101 | + // add system questions to groups |
|
1102 | + $wpdb->insert( |
|
1103 | + EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
1104 | + [ |
|
1105 | + 'QSG_ID' => $QSG_ID, |
|
1106 | + 'QST_ID' => $QST_ID, |
|
1107 | + 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
1108 | + ], |
|
1109 | + ['%d', '%d', '%d'] |
|
1110 | + ); |
|
1111 | + } |
|
1112 | + } |
|
1113 | + } |
|
1114 | + } |
|
1115 | + |
|
1116 | + |
|
1117 | + /** |
|
1118 | + * Makes sure the default payment method (Invoice) is active. |
|
1119 | + * This used to be done automatically as part of constructing the old gateways config |
|
1120 | + * |
|
1121 | + * @throws EE_Error |
|
1122 | + * @throws ReflectionException |
|
1123 | + */ |
|
1124 | + public static function insert_default_payment_methods() |
|
1125 | + { |
|
1126 | + if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1127 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1128 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1129 | + } else { |
|
1130 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
1131 | + } |
|
1132 | + } |
|
1133 | + |
|
1134 | + |
|
1135 | + /** |
|
1136 | + * @return void |
|
1137 | + * @throws EE_Error |
|
1138 | + * @throws ReflectionException |
|
1139 | + */ |
|
1140 | + public static function insert_default_status_codes() |
|
1141 | + { |
|
1142 | + |
|
1143 | + global $wpdb; |
|
1144 | + |
|
1145 | + if (EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
1146 | + $table_name = EEM_Status::instance()->table(); |
|
1147 | + |
|
1148 | + $SQL = |
|
1149 | + "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
1150 | + $wpdb->query($SQL); |
|
1151 | + |
|
1152 | + $SQL = "INSERT INTO $table_name |
|
1153 | 1153 | (STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES |
1154 | 1154 | ('ACT', 'ACTIVE', 'event', 0, NULL, 1), |
1155 | 1155 | ('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0), |
@@ -1189,480 +1189,480 @@ discard block |
||
1189 | 1189 | ('MID', 'IDLE', 'message', 0, NULL, 1), |
1190 | 1190 | ('MRS', 'RESEND', 'message', 0, NULL, 1), |
1191 | 1191 | ('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);"; |
1192 | - $wpdb->query($SQL); |
|
1193 | - } |
|
1194 | - } |
|
1195 | - |
|
1196 | - |
|
1197 | - /** |
|
1198 | - * @return bool true means new templates were created. |
|
1199 | - * false means no templates were created. |
|
1200 | - * This is NOT an error flag. To check for errors you will want |
|
1201 | - * to use either EE_Error or a try catch for an EE_Error exception. |
|
1202 | - * @throws EE_Error |
|
1203 | - * @throws ReflectionException |
|
1204 | - */ |
|
1205 | - public static function generate_default_message_templates() |
|
1206 | - { |
|
1207 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1208 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1209 | - /* |
|
1192 | + $wpdb->query($SQL); |
|
1193 | + } |
|
1194 | + } |
|
1195 | + |
|
1196 | + |
|
1197 | + /** |
|
1198 | + * @return bool true means new templates were created. |
|
1199 | + * false means no templates were created. |
|
1200 | + * This is NOT an error flag. To check for errors you will want |
|
1201 | + * to use either EE_Error or a try catch for an EE_Error exception. |
|
1202 | + * @throws EE_Error |
|
1203 | + * @throws ReflectionException |
|
1204 | + */ |
|
1205 | + public static function generate_default_message_templates() |
|
1206 | + { |
|
1207 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1208 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1209 | + /* |
|
1210 | 1210 | * This first method is taking care of ensuring any default messengers |
1211 | 1211 | * that should be made active and have templates generated are done. |
1212 | 1212 | */ |
1213 | - $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
1214 | - $message_resource_manager |
|
1215 | - ); |
|
1216 | - /** |
|
1217 | - * This method is verifying there are no NEW default message types |
|
1218 | - * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
1219 | - */ |
|
1220 | - $new_templates_created_for_message_type = |
|
1221 | - self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1222 | - $message_resource_manager |
|
1223 | - ); |
|
1224 | - // after all is done, let's persist these changes to the db. |
|
1225 | - $message_resource_manager->update_has_activated_messengers_option(); |
|
1226 | - $message_resource_manager->update_active_messengers_option(); |
|
1227 | - // will return true if either of these are true. Otherwise will return false. |
|
1228 | - return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
1229 | - } |
|
1230 | - |
|
1231 | - |
|
1232 | - /** |
|
1233 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
1234 | - * @return array|bool |
|
1235 | - * @throws EE_Error |
|
1236 | - * @throws ReflectionException |
|
1237 | - */ |
|
1238 | - protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1239 | - EE_Message_Resource_Manager $message_resource_manager |
|
1240 | - ) { |
|
1241 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
1242 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1243 | - $templates_created = false; |
|
1244 | - foreach ($active_messengers as $active_messenger) { |
|
1245 | - $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
1246 | - $default_message_type_names_to_activate = []; |
|
1247 | - // looping through each default message type reported by the messenger |
|
1248 | - // and setup the actual message types to activate. |
|
1249 | - foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
1250 | - // if already active or has already been activated before we skip |
|
1251 | - // (otherwise we might reactivate something user's intentionally deactivated.) |
|
1252 | - // we also skip if the message type is not installed. |
|
1253 | - if ( |
|
1254 | - $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1255 | - $default_message_type_name_for_messenger, |
|
1256 | - $active_messenger->name |
|
1257 | - ) |
|
1258 | - || $message_resource_manager->is_message_type_active_for_messenger( |
|
1259 | - $active_messenger->name, |
|
1260 | - $default_message_type_name_for_messenger |
|
1261 | - ) |
|
1262 | - || ! isset($installed_message_types[ $default_message_type_name_for_messenger ]) |
|
1263 | - ) { |
|
1264 | - continue; |
|
1265 | - } |
|
1266 | - $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
1267 | - } |
|
1268 | - // let's activate! |
|
1269 | - $message_resource_manager->ensure_message_types_are_active( |
|
1270 | - $default_message_type_names_to_activate, |
|
1271 | - $active_messenger->name, |
|
1272 | - false |
|
1273 | - ); |
|
1274 | - // activate the templates for these message types |
|
1275 | - if (! empty($default_message_type_names_to_activate)) { |
|
1276 | - $templates_created = EEH_MSG_Template::generate_new_templates( |
|
1277 | - $active_messenger->name, |
|
1278 | - $default_message_type_names_for_messenger, |
|
1279 | - '', |
|
1280 | - true |
|
1281 | - ); |
|
1282 | - } |
|
1283 | - } |
|
1284 | - return $templates_created; |
|
1285 | - } |
|
1286 | - |
|
1287 | - |
|
1288 | - /** |
|
1289 | - * This will activate and generate default messengers and default message types for those messengers. |
|
1290 | - * |
|
1291 | - * @param EE_message_Resource_Manager $message_resource_manager |
|
1292 | - * @return array|bool True means there were default messengers and message type templates generated. |
|
1293 | - * False means that there were no templates generated |
|
1294 | - * (which could simply mean there are no default message types for a messenger). |
|
1295 | - * @throws EE_Error |
|
1296 | - * @throws ReflectionException |
|
1297 | - */ |
|
1298 | - protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
1299 | - EE_Message_Resource_Manager $message_resource_manager |
|
1300 | - ) { |
|
1301 | - $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
1302 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1303 | - $templates_generated = false; |
|
1304 | - foreach ($messengers_to_generate as $messenger_to_generate) { |
|
1305 | - $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
1306 | - // verify the default message types match an installed message type. |
|
1307 | - foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
1308 | - if ( |
|
1309 | - ! isset($installed_message_types[ $name ]) |
|
1310 | - || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1311 | - $name, |
|
1312 | - $messenger_to_generate->name |
|
1313 | - ) |
|
1314 | - ) { |
|
1315 | - unset($default_message_type_names_for_messenger[ $key ]); |
|
1316 | - } |
|
1317 | - } |
|
1318 | - // in previous iterations, the active_messengers option in the db |
|
1319 | - // needed updated before calling create templates. however with the changes this may not be necessary. |
|
1320 | - // This comment is left here just in case we discover that we _do_ need to update before |
|
1321 | - // passing off to create templates (after the refactor is done). |
|
1322 | - // @todo remove this comment when determined not necessary. |
|
1323 | - $message_resource_manager->activate_messenger( |
|
1324 | - $messenger_to_generate, |
|
1325 | - $default_message_type_names_for_messenger, |
|
1326 | - false |
|
1327 | - ); |
|
1328 | - // create any templates needing created (or will reactivate templates already generated as necessary). |
|
1329 | - if (! empty($default_message_type_names_for_messenger)) { |
|
1330 | - $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
1331 | - $messenger_to_generate->name, |
|
1332 | - $default_message_type_names_for_messenger, |
|
1333 | - '', |
|
1334 | - true |
|
1335 | - ); |
|
1336 | - } |
|
1337 | - } |
|
1338 | - return $templates_generated; |
|
1339 | - } |
|
1340 | - |
|
1341 | - |
|
1342 | - /** |
|
1343 | - * This returns the default messengers to generate templates for on activation of EE. |
|
1344 | - * It considers: |
|
1345 | - * - whether a messenger is already active in the db. |
|
1346 | - * - whether a messenger has been made active at any time in the past. |
|
1347 | - * |
|
1348 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
1349 | - * @return EE_messenger[] |
|
1350 | - */ |
|
1351 | - protected static function _get_default_messengers_to_generate_on_activation( |
|
1352 | - EE_Message_Resource_Manager $message_resource_manager |
|
1353 | - ) { |
|
1354 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
1355 | - $installed_messengers = $message_resource_manager->installed_messengers(); |
|
1356 | - $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
1357 | - |
|
1358 | - $messengers_to_generate = []; |
|
1359 | - foreach ($installed_messengers as $installed_messenger) { |
|
1360 | - // if installed messenger is a messenger that should be activated on install |
|
1361 | - // and is not already active |
|
1362 | - // and has never been activated |
|
1363 | - if ( |
|
1364 | - ! $installed_messenger->activate_on_install |
|
1365 | - || isset($active_messengers[ $installed_messenger->name ]) |
|
1366 | - || isset($has_activated[ $installed_messenger->name ]) |
|
1367 | - ) { |
|
1368 | - continue; |
|
1369 | - } |
|
1370 | - $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger; |
|
1371 | - } |
|
1372 | - return $messengers_to_generate; |
|
1373 | - } |
|
1374 | - |
|
1375 | - |
|
1376 | - /** |
|
1377 | - * This simply validates active message types to ensure they actually match installed |
|
1378 | - * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
1379 | - * rows are set inactive. |
|
1380 | - * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
1381 | - * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
1382 | - * are still handled in here. |
|
1383 | - * |
|
1384 | - * @return void |
|
1385 | - * @throws EE_Error |
|
1386 | - * @throws ReflectionException |
|
1387 | - * @since 4.3.1 |
|
1388 | - */ |
|
1389 | - public static function validate_messages_system() |
|
1390 | - { |
|
1391 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1392 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1393 | - $message_resource_manager->validate_active_message_types_are_installed(); |
|
1394 | - do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1395 | - } |
|
1396 | - |
|
1397 | - |
|
1398 | - /** |
|
1399 | - * @return void |
|
1400 | - */ |
|
1401 | - public static function create_no_ticket_prices_array() |
|
1402 | - { |
|
1403 | - // this creates an array for tracking events that have no active ticket prices created |
|
1404 | - // this allows us to warn admins of the situation so that it can be corrected |
|
1405 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
1406 | - if (! $espresso_no_ticket_prices) { |
|
1407 | - add_option('ee_no_ticket_prices', [], '', false); |
|
1408 | - } |
|
1409 | - } |
|
1410 | - |
|
1411 | - |
|
1412 | - /** |
|
1413 | - * @return void |
|
1414 | - */ |
|
1415 | - public static function plugin_deactivation() |
|
1416 | - { |
|
1417 | - } |
|
1418 | - |
|
1419 | - |
|
1420 | - /** |
|
1421 | - * Finds all our EE4 custom post types, and deletes them and their associated data |
|
1422 | - * (like post meta or term relations) |
|
1423 | - * |
|
1424 | - * @throws EE_Error |
|
1425 | - * @global wpdb $wpdb |
|
1426 | - */ |
|
1427 | - public static function delete_all_espresso_cpt_data() |
|
1428 | - { |
|
1429 | - global $wpdb; |
|
1430 | - // get all the CPT post_types |
|
1431 | - $ee_post_types = []; |
|
1432 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1433 | - if (method_exists($model_name, 'instance')) { |
|
1434 | - $model_obj = call_user_func([$model_name, 'instance']); |
|
1435 | - if ($model_obj instanceof EEM_CPT_Base) { |
|
1436 | - $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1437 | - } |
|
1438 | - } |
|
1439 | - } |
|
1440 | - // get all our CPTs |
|
1441 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1442 | - $cpt_ids = $wpdb->get_col($query); |
|
1443 | - // delete each post meta and term relations too |
|
1444 | - foreach ($cpt_ids as $post_id) { |
|
1445 | - wp_delete_post($post_id, true); |
|
1446 | - } |
|
1447 | - } |
|
1448 | - |
|
1449 | - |
|
1450 | - /** |
|
1451 | - * Deletes all EE custom tables |
|
1452 | - * |
|
1453 | - * @return array |
|
1454 | - * @throws EE_Error |
|
1455 | - * @throws ReflectionException |
|
1456 | - */ |
|
1457 | - public static function drop_espresso_tables() |
|
1458 | - { |
|
1459 | - $tables = []; |
|
1460 | - // load registry |
|
1461 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1462 | - if (method_exists($model_name, 'instance')) { |
|
1463 | - $model_obj = call_user_func([$model_name, 'instance']); |
|
1464 | - if ($model_obj instanceof EEM_Base) { |
|
1465 | - foreach ($model_obj->get_tables() as $table) { |
|
1466 | - if ( |
|
1467 | - strpos($table->get_table_name(), 'esp_') |
|
1468 | - && ( |
|
1469 | - is_main_site()// main site? nuke them all |
|
1470 | - || ! $table->is_global()// not main site,but not global either. nuke it |
|
1471 | - ) |
|
1472 | - ) { |
|
1473 | - $tables[ $table->get_table_name() ] = $table->get_table_name(); |
|
1474 | - } |
|
1475 | - } |
|
1476 | - } |
|
1477 | - } |
|
1478 | - } |
|
1479 | - |
|
1480 | - // there are some tables whose models were removed. |
|
1481 | - // they should be removed when removing all EE core's data |
|
1482 | - $tables_without_models = [ |
|
1483 | - 'esp_promotion', |
|
1484 | - 'esp_promotion_applied', |
|
1485 | - 'esp_promotion_object', |
|
1486 | - 'esp_promotion_rule', |
|
1487 | - 'esp_rule', |
|
1488 | - ]; |
|
1489 | - foreach ($tables_without_models as $table) { |
|
1490 | - $tables[ $table ] = $table; |
|
1491 | - } |
|
1492 | - return EEH_Activation::getTableManager()->dropTables($tables); |
|
1493 | - } |
|
1494 | - |
|
1495 | - |
|
1496 | - /** |
|
1497 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
1498 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
1499 | - * Returns the list actually deleted |
|
1500 | - * |
|
1501 | - * @param array $table_names |
|
1502 | - * @return array of table names which we deleted |
|
1503 | - * @throws EE_Error |
|
1504 | - * @throws ReflectionException |
|
1505 | - * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
1506 | - * @global WPDB $wpdb |
|
1507 | - */ |
|
1508 | - public static function drop_tables($table_names) |
|
1509 | - { |
|
1510 | - return EEH_Activation::getTableManager()->dropTables($table_names); |
|
1511 | - } |
|
1512 | - |
|
1513 | - |
|
1514 | - /** |
|
1515 | - * plugin_uninstall |
|
1516 | - * |
|
1517 | - * @param bool $remove_all |
|
1518 | - * @return void |
|
1519 | - * @throws EE_Error |
|
1520 | - * @throws ReflectionException |
|
1521 | - */ |
|
1522 | - public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
1523 | - { |
|
1524 | - global $wpdb; |
|
1525 | - self::drop_espresso_tables(); |
|
1526 | - $wp_options_to_delete = [ |
|
1527 | - 'ee_no_ticket_prices' => true, |
|
1528 | - 'ee_active_messengers' => true, |
|
1529 | - 'ee_has_activated_messenger' => true, |
|
1530 | - RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true, |
|
1531 | - 'ee_config' => false, |
|
1532 | - 'ee_data_migration_current_db_state' => true, |
|
1533 | - 'ee_data_migration_mapping_' => false, |
|
1534 | - 'ee_data_migration_script_' => false, |
|
1535 | - 'ee_data_migrations' => true, |
|
1536 | - 'ee_dms_map' => false, |
|
1537 | - 'ee_notices' => true, |
|
1538 | - 'lang_file_check_' => false, |
|
1539 | - 'ee_maintenance_mode' => true, |
|
1540 | - 'ee_ueip_optin' => true, |
|
1541 | - 'ee_ueip_has_notified' => true, |
|
1542 | - 'ee_plugin_activation_errors' => true, |
|
1543 | - 'ee_id_mapping_from' => false, |
|
1544 | - 'espresso_persistent_admin_notices' => true, |
|
1545 | - 'ee_encryption_key' => true, |
|
1546 | - 'pue_force_upgrade_' => false, |
|
1547 | - 'pue_json_error_' => false, |
|
1548 | - 'pue_install_key_' => false, |
|
1549 | - 'pue_verification_error_' => false, |
|
1550 | - 'pu_dismissed_upgrade_' => false, |
|
1551 | - 'external_updates-' => false, |
|
1552 | - 'ee_extra_data' => true, |
|
1553 | - 'ee_ssn_' => false, |
|
1554 | - 'ee_rss_' => false, |
|
1555 | - 'ee_rte_n_tx_' => false, |
|
1556 | - 'ee_pers_admin_notices' => true, |
|
1557 | - 'ee_job_parameters_' => false, |
|
1558 | - 'ee_upload_directories_incomplete' => true, |
|
1559 | - 'ee_verified_db_collations' => true, |
|
1560 | - ]; |
|
1561 | - if (is_main_site()) { |
|
1562 | - $wp_options_to_delete['ee_network_config'] = true; |
|
1563 | - } |
|
1564 | - $undeleted_options = []; |
|
1565 | - foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1566 | - if ($no_wildcard) { |
|
1567 | - if (! delete_option($option_name)) { |
|
1568 | - $undeleted_options[] = $option_name; |
|
1569 | - } |
|
1570 | - } else { |
|
1571 | - $option_names_to_delete_from_wildcard = |
|
1572 | - $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1573 | - foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1574 | - if (! delete_option($option_name_from_wildcard)) { |
|
1575 | - $undeleted_options[] = $option_name_from_wildcard; |
|
1576 | - } |
|
1577 | - } |
|
1578 | - } |
|
1579 | - } |
|
1580 | - // also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1581 | - remove_action('shutdown', [EE_Config::instance(), 'shutdown']); |
|
1582 | - if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1583 | - $db_update_sans_ee4 = []; |
|
1584 | - foreach ($espresso_db_update as $version => $times_activated) { |
|
1585 | - if ((string) $version[0] === '3') {// if its NON EE4 |
|
1586 | - $db_update_sans_ee4[ $version ] = $times_activated; |
|
1587 | - } |
|
1588 | - } |
|
1589 | - update_option('espresso_db_update', $db_update_sans_ee4); |
|
1590 | - } |
|
1591 | - $errors = ''; |
|
1592 | - if (! empty($undeleted_options)) { |
|
1593 | - $errors .= sprintf( |
|
1594 | - esc_html__('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1595 | - '<br/>', |
|
1596 | - implode(',<br/>', $undeleted_options) |
|
1597 | - ); |
|
1598 | - } |
|
1599 | - if (! empty($errors)) { |
|
1600 | - EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1601 | - } |
|
1602 | - } |
|
1603 | - |
|
1604 | - |
|
1605 | - /** |
|
1606 | - * Gets the mysql error code from the last used query by wpdb |
|
1607 | - * |
|
1608 | - * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
1609 | - */ |
|
1610 | - public static function last_wpdb_error_code() |
|
1611 | - { |
|
1612 | - // phpcs:disable PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved |
|
1613 | - global $wpdb; |
|
1614 | - return $wpdb->use_mysqli ? mysqli_errno($wpdb->dbh) : mysql_errno($wpdb->dbh); |
|
1615 | - // phpcs:enable |
|
1616 | - } |
|
1617 | - |
|
1618 | - |
|
1619 | - /** |
|
1620 | - * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
1621 | - * |
|
1622 | - * @param string $table_name with or without $wpdb->prefix |
|
1623 | - * @return boolean |
|
1624 | - * @throws EE_Error |
|
1625 | - * @throws ReflectionException |
|
1626 | - * @global wpdb $wpdb |
|
1627 | - * @deprecated instead use TableAnalysis::tableExists() |
|
1628 | - */ |
|
1629 | - public static function table_exists($table_name) |
|
1630 | - { |
|
1631 | - return EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
1632 | - } |
|
1633 | - |
|
1634 | - |
|
1635 | - /** |
|
1636 | - * Resets the cache on EEH_Activation |
|
1637 | - */ |
|
1638 | - public static function reset() |
|
1639 | - { |
|
1640 | - self::$_default_creator_id = null; |
|
1641 | - self::$_initialized_db_content_already_in_this_request = false; |
|
1642 | - } |
|
1643 | - |
|
1644 | - |
|
1645 | - /** |
|
1646 | - * Removes 'email_confirm' from the Address info question group on activation |
|
1647 | - * |
|
1648 | - * @return void |
|
1649 | - * @throws EE_Error |
|
1650 | - */ |
|
1651 | - public static function removeEmailConfirmFromAddressGroup() |
|
1652 | - { |
|
1653 | - |
|
1654 | - // Pull the email_confirm question ID. |
|
1655 | - $email_confirm_question_id = EEM_Question::instance()->get_Question_ID_from_system_string( |
|
1656 | - EEM_Attendee::system_question_email_confirm |
|
1657 | - ); |
|
1658 | - // Remove the email_confirm question group from the address group questions. |
|
1659 | - EEM_Question_Group_Question::instance()->delete( |
|
1660 | - [ |
|
1661 | - [ |
|
1662 | - 'QST_ID' => $email_confirm_question_id, |
|
1663 | - 'Question_Group.QSG_system' => EEM_Question_Group::system_address, |
|
1664 | - ], |
|
1665 | - ] |
|
1666 | - ); |
|
1667 | - } |
|
1213 | + $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
1214 | + $message_resource_manager |
|
1215 | + ); |
|
1216 | + /** |
|
1217 | + * This method is verifying there are no NEW default message types |
|
1218 | + * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
1219 | + */ |
|
1220 | + $new_templates_created_for_message_type = |
|
1221 | + self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1222 | + $message_resource_manager |
|
1223 | + ); |
|
1224 | + // after all is done, let's persist these changes to the db. |
|
1225 | + $message_resource_manager->update_has_activated_messengers_option(); |
|
1226 | + $message_resource_manager->update_active_messengers_option(); |
|
1227 | + // will return true if either of these are true. Otherwise will return false. |
|
1228 | + return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
1229 | + } |
|
1230 | + |
|
1231 | + |
|
1232 | + /** |
|
1233 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
1234 | + * @return array|bool |
|
1235 | + * @throws EE_Error |
|
1236 | + * @throws ReflectionException |
|
1237 | + */ |
|
1238 | + protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1239 | + EE_Message_Resource_Manager $message_resource_manager |
|
1240 | + ) { |
|
1241 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
1242 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1243 | + $templates_created = false; |
|
1244 | + foreach ($active_messengers as $active_messenger) { |
|
1245 | + $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
1246 | + $default_message_type_names_to_activate = []; |
|
1247 | + // looping through each default message type reported by the messenger |
|
1248 | + // and setup the actual message types to activate. |
|
1249 | + foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
1250 | + // if already active or has already been activated before we skip |
|
1251 | + // (otherwise we might reactivate something user's intentionally deactivated.) |
|
1252 | + // we also skip if the message type is not installed. |
|
1253 | + if ( |
|
1254 | + $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1255 | + $default_message_type_name_for_messenger, |
|
1256 | + $active_messenger->name |
|
1257 | + ) |
|
1258 | + || $message_resource_manager->is_message_type_active_for_messenger( |
|
1259 | + $active_messenger->name, |
|
1260 | + $default_message_type_name_for_messenger |
|
1261 | + ) |
|
1262 | + || ! isset($installed_message_types[ $default_message_type_name_for_messenger ]) |
|
1263 | + ) { |
|
1264 | + continue; |
|
1265 | + } |
|
1266 | + $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
1267 | + } |
|
1268 | + // let's activate! |
|
1269 | + $message_resource_manager->ensure_message_types_are_active( |
|
1270 | + $default_message_type_names_to_activate, |
|
1271 | + $active_messenger->name, |
|
1272 | + false |
|
1273 | + ); |
|
1274 | + // activate the templates for these message types |
|
1275 | + if (! empty($default_message_type_names_to_activate)) { |
|
1276 | + $templates_created = EEH_MSG_Template::generate_new_templates( |
|
1277 | + $active_messenger->name, |
|
1278 | + $default_message_type_names_for_messenger, |
|
1279 | + '', |
|
1280 | + true |
|
1281 | + ); |
|
1282 | + } |
|
1283 | + } |
|
1284 | + return $templates_created; |
|
1285 | + } |
|
1286 | + |
|
1287 | + |
|
1288 | + /** |
|
1289 | + * This will activate and generate default messengers and default message types for those messengers. |
|
1290 | + * |
|
1291 | + * @param EE_message_Resource_Manager $message_resource_manager |
|
1292 | + * @return array|bool True means there were default messengers and message type templates generated. |
|
1293 | + * False means that there were no templates generated |
|
1294 | + * (which could simply mean there are no default message types for a messenger). |
|
1295 | + * @throws EE_Error |
|
1296 | + * @throws ReflectionException |
|
1297 | + */ |
|
1298 | + protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
1299 | + EE_Message_Resource_Manager $message_resource_manager |
|
1300 | + ) { |
|
1301 | + $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
1302 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1303 | + $templates_generated = false; |
|
1304 | + foreach ($messengers_to_generate as $messenger_to_generate) { |
|
1305 | + $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
1306 | + // verify the default message types match an installed message type. |
|
1307 | + foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
1308 | + if ( |
|
1309 | + ! isset($installed_message_types[ $name ]) |
|
1310 | + || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1311 | + $name, |
|
1312 | + $messenger_to_generate->name |
|
1313 | + ) |
|
1314 | + ) { |
|
1315 | + unset($default_message_type_names_for_messenger[ $key ]); |
|
1316 | + } |
|
1317 | + } |
|
1318 | + // in previous iterations, the active_messengers option in the db |
|
1319 | + // needed updated before calling create templates. however with the changes this may not be necessary. |
|
1320 | + // This comment is left here just in case we discover that we _do_ need to update before |
|
1321 | + // passing off to create templates (after the refactor is done). |
|
1322 | + // @todo remove this comment when determined not necessary. |
|
1323 | + $message_resource_manager->activate_messenger( |
|
1324 | + $messenger_to_generate, |
|
1325 | + $default_message_type_names_for_messenger, |
|
1326 | + false |
|
1327 | + ); |
|
1328 | + // create any templates needing created (or will reactivate templates already generated as necessary). |
|
1329 | + if (! empty($default_message_type_names_for_messenger)) { |
|
1330 | + $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
1331 | + $messenger_to_generate->name, |
|
1332 | + $default_message_type_names_for_messenger, |
|
1333 | + '', |
|
1334 | + true |
|
1335 | + ); |
|
1336 | + } |
|
1337 | + } |
|
1338 | + return $templates_generated; |
|
1339 | + } |
|
1340 | + |
|
1341 | + |
|
1342 | + /** |
|
1343 | + * This returns the default messengers to generate templates for on activation of EE. |
|
1344 | + * It considers: |
|
1345 | + * - whether a messenger is already active in the db. |
|
1346 | + * - whether a messenger has been made active at any time in the past. |
|
1347 | + * |
|
1348 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
1349 | + * @return EE_messenger[] |
|
1350 | + */ |
|
1351 | + protected static function _get_default_messengers_to_generate_on_activation( |
|
1352 | + EE_Message_Resource_Manager $message_resource_manager |
|
1353 | + ) { |
|
1354 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
1355 | + $installed_messengers = $message_resource_manager->installed_messengers(); |
|
1356 | + $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
1357 | + |
|
1358 | + $messengers_to_generate = []; |
|
1359 | + foreach ($installed_messengers as $installed_messenger) { |
|
1360 | + // if installed messenger is a messenger that should be activated on install |
|
1361 | + // and is not already active |
|
1362 | + // and has never been activated |
|
1363 | + if ( |
|
1364 | + ! $installed_messenger->activate_on_install |
|
1365 | + || isset($active_messengers[ $installed_messenger->name ]) |
|
1366 | + || isset($has_activated[ $installed_messenger->name ]) |
|
1367 | + ) { |
|
1368 | + continue; |
|
1369 | + } |
|
1370 | + $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger; |
|
1371 | + } |
|
1372 | + return $messengers_to_generate; |
|
1373 | + } |
|
1374 | + |
|
1375 | + |
|
1376 | + /** |
|
1377 | + * This simply validates active message types to ensure they actually match installed |
|
1378 | + * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
1379 | + * rows are set inactive. |
|
1380 | + * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
1381 | + * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
1382 | + * are still handled in here. |
|
1383 | + * |
|
1384 | + * @return void |
|
1385 | + * @throws EE_Error |
|
1386 | + * @throws ReflectionException |
|
1387 | + * @since 4.3.1 |
|
1388 | + */ |
|
1389 | + public static function validate_messages_system() |
|
1390 | + { |
|
1391 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1392 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1393 | + $message_resource_manager->validate_active_message_types_are_installed(); |
|
1394 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1395 | + } |
|
1396 | + |
|
1397 | + |
|
1398 | + /** |
|
1399 | + * @return void |
|
1400 | + */ |
|
1401 | + public static function create_no_ticket_prices_array() |
|
1402 | + { |
|
1403 | + // this creates an array for tracking events that have no active ticket prices created |
|
1404 | + // this allows us to warn admins of the situation so that it can be corrected |
|
1405 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
1406 | + if (! $espresso_no_ticket_prices) { |
|
1407 | + add_option('ee_no_ticket_prices', [], '', false); |
|
1408 | + } |
|
1409 | + } |
|
1410 | + |
|
1411 | + |
|
1412 | + /** |
|
1413 | + * @return void |
|
1414 | + */ |
|
1415 | + public static function plugin_deactivation() |
|
1416 | + { |
|
1417 | + } |
|
1418 | + |
|
1419 | + |
|
1420 | + /** |
|
1421 | + * Finds all our EE4 custom post types, and deletes them and their associated data |
|
1422 | + * (like post meta or term relations) |
|
1423 | + * |
|
1424 | + * @throws EE_Error |
|
1425 | + * @global wpdb $wpdb |
|
1426 | + */ |
|
1427 | + public static function delete_all_espresso_cpt_data() |
|
1428 | + { |
|
1429 | + global $wpdb; |
|
1430 | + // get all the CPT post_types |
|
1431 | + $ee_post_types = []; |
|
1432 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1433 | + if (method_exists($model_name, 'instance')) { |
|
1434 | + $model_obj = call_user_func([$model_name, 'instance']); |
|
1435 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
1436 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1437 | + } |
|
1438 | + } |
|
1439 | + } |
|
1440 | + // get all our CPTs |
|
1441 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1442 | + $cpt_ids = $wpdb->get_col($query); |
|
1443 | + // delete each post meta and term relations too |
|
1444 | + foreach ($cpt_ids as $post_id) { |
|
1445 | + wp_delete_post($post_id, true); |
|
1446 | + } |
|
1447 | + } |
|
1448 | + |
|
1449 | + |
|
1450 | + /** |
|
1451 | + * Deletes all EE custom tables |
|
1452 | + * |
|
1453 | + * @return array |
|
1454 | + * @throws EE_Error |
|
1455 | + * @throws ReflectionException |
|
1456 | + */ |
|
1457 | + public static function drop_espresso_tables() |
|
1458 | + { |
|
1459 | + $tables = []; |
|
1460 | + // load registry |
|
1461 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1462 | + if (method_exists($model_name, 'instance')) { |
|
1463 | + $model_obj = call_user_func([$model_name, 'instance']); |
|
1464 | + if ($model_obj instanceof EEM_Base) { |
|
1465 | + foreach ($model_obj->get_tables() as $table) { |
|
1466 | + if ( |
|
1467 | + strpos($table->get_table_name(), 'esp_') |
|
1468 | + && ( |
|
1469 | + is_main_site()// main site? nuke them all |
|
1470 | + || ! $table->is_global()// not main site,but not global either. nuke it |
|
1471 | + ) |
|
1472 | + ) { |
|
1473 | + $tables[ $table->get_table_name() ] = $table->get_table_name(); |
|
1474 | + } |
|
1475 | + } |
|
1476 | + } |
|
1477 | + } |
|
1478 | + } |
|
1479 | + |
|
1480 | + // there are some tables whose models were removed. |
|
1481 | + // they should be removed when removing all EE core's data |
|
1482 | + $tables_without_models = [ |
|
1483 | + 'esp_promotion', |
|
1484 | + 'esp_promotion_applied', |
|
1485 | + 'esp_promotion_object', |
|
1486 | + 'esp_promotion_rule', |
|
1487 | + 'esp_rule', |
|
1488 | + ]; |
|
1489 | + foreach ($tables_without_models as $table) { |
|
1490 | + $tables[ $table ] = $table; |
|
1491 | + } |
|
1492 | + return EEH_Activation::getTableManager()->dropTables($tables); |
|
1493 | + } |
|
1494 | + |
|
1495 | + |
|
1496 | + /** |
|
1497 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
1498 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
1499 | + * Returns the list actually deleted |
|
1500 | + * |
|
1501 | + * @param array $table_names |
|
1502 | + * @return array of table names which we deleted |
|
1503 | + * @throws EE_Error |
|
1504 | + * @throws ReflectionException |
|
1505 | + * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
1506 | + * @global WPDB $wpdb |
|
1507 | + */ |
|
1508 | + public static function drop_tables($table_names) |
|
1509 | + { |
|
1510 | + return EEH_Activation::getTableManager()->dropTables($table_names); |
|
1511 | + } |
|
1512 | + |
|
1513 | + |
|
1514 | + /** |
|
1515 | + * plugin_uninstall |
|
1516 | + * |
|
1517 | + * @param bool $remove_all |
|
1518 | + * @return void |
|
1519 | + * @throws EE_Error |
|
1520 | + * @throws ReflectionException |
|
1521 | + */ |
|
1522 | + public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
1523 | + { |
|
1524 | + global $wpdb; |
|
1525 | + self::drop_espresso_tables(); |
|
1526 | + $wp_options_to_delete = [ |
|
1527 | + 'ee_no_ticket_prices' => true, |
|
1528 | + 'ee_active_messengers' => true, |
|
1529 | + 'ee_has_activated_messenger' => true, |
|
1530 | + RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true, |
|
1531 | + 'ee_config' => false, |
|
1532 | + 'ee_data_migration_current_db_state' => true, |
|
1533 | + 'ee_data_migration_mapping_' => false, |
|
1534 | + 'ee_data_migration_script_' => false, |
|
1535 | + 'ee_data_migrations' => true, |
|
1536 | + 'ee_dms_map' => false, |
|
1537 | + 'ee_notices' => true, |
|
1538 | + 'lang_file_check_' => false, |
|
1539 | + 'ee_maintenance_mode' => true, |
|
1540 | + 'ee_ueip_optin' => true, |
|
1541 | + 'ee_ueip_has_notified' => true, |
|
1542 | + 'ee_plugin_activation_errors' => true, |
|
1543 | + 'ee_id_mapping_from' => false, |
|
1544 | + 'espresso_persistent_admin_notices' => true, |
|
1545 | + 'ee_encryption_key' => true, |
|
1546 | + 'pue_force_upgrade_' => false, |
|
1547 | + 'pue_json_error_' => false, |
|
1548 | + 'pue_install_key_' => false, |
|
1549 | + 'pue_verification_error_' => false, |
|
1550 | + 'pu_dismissed_upgrade_' => false, |
|
1551 | + 'external_updates-' => false, |
|
1552 | + 'ee_extra_data' => true, |
|
1553 | + 'ee_ssn_' => false, |
|
1554 | + 'ee_rss_' => false, |
|
1555 | + 'ee_rte_n_tx_' => false, |
|
1556 | + 'ee_pers_admin_notices' => true, |
|
1557 | + 'ee_job_parameters_' => false, |
|
1558 | + 'ee_upload_directories_incomplete' => true, |
|
1559 | + 'ee_verified_db_collations' => true, |
|
1560 | + ]; |
|
1561 | + if (is_main_site()) { |
|
1562 | + $wp_options_to_delete['ee_network_config'] = true; |
|
1563 | + } |
|
1564 | + $undeleted_options = []; |
|
1565 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1566 | + if ($no_wildcard) { |
|
1567 | + if (! delete_option($option_name)) { |
|
1568 | + $undeleted_options[] = $option_name; |
|
1569 | + } |
|
1570 | + } else { |
|
1571 | + $option_names_to_delete_from_wildcard = |
|
1572 | + $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1573 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1574 | + if (! delete_option($option_name_from_wildcard)) { |
|
1575 | + $undeleted_options[] = $option_name_from_wildcard; |
|
1576 | + } |
|
1577 | + } |
|
1578 | + } |
|
1579 | + } |
|
1580 | + // also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1581 | + remove_action('shutdown', [EE_Config::instance(), 'shutdown']); |
|
1582 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1583 | + $db_update_sans_ee4 = []; |
|
1584 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
1585 | + if ((string) $version[0] === '3') {// if its NON EE4 |
|
1586 | + $db_update_sans_ee4[ $version ] = $times_activated; |
|
1587 | + } |
|
1588 | + } |
|
1589 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
1590 | + } |
|
1591 | + $errors = ''; |
|
1592 | + if (! empty($undeleted_options)) { |
|
1593 | + $errors .= sprintf( |
|
1594 | + esc_html__('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1595 | + '<br/>', |
|
1596 | + implode(',<br/>', $undeleted_options) |
|
1597 | + ); |
|
1598 | + } |
|
1599 | + if (! empty($errors)) { |
|
1600 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1601 | + } |
|
1602 | + } |
|
1603 | + |
|
1604 | + |
|
1605 | + /** |
|
1606 | + * Gets the mysql error code from the last used query by wpdb |
|
1607 | + * |
|
1608 | + * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
1609 | + */ |
|
1610 | + public static function last_wpdb_error_code() |
|
1611 | + { |
|
1612 | + // phpcs:disable PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved |
|
1613 | + global $wpdb; |
|
1614 | + return $wpdb->use_mysqli ? mysqli_errno($wpdb->dbh) : mysql_errno($wpdb->dbh); |
|
1615 | + // phpcs:enable |
|
1616 | + } |
|
1617 | + |
|
1618 | + |
|
1619 | + /** |
|
1620 | + * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
1621 | + * |
|
1622 | + * @param string $table_name with or without $wpdb->prefix |
|
1623 | + * @return boolean |
|
1624 | + * @throws EE_Error |
|
1625 | + * @throws ReflectionException |
|
1626 | + * @global wpdb $wpdb |
|
1627 | + * @deprecated instead use TableAnalysis::tableExists() |
|
1628 | + */ |
|
1629 | + public static function table_exists($table_name) |
|
1630 | + { |
|
1631 | + return EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
1632 | + } |
|
1633 | + |
|
1634 | + |
|
1635 | + /** |
|
1636 | + * Resets the cache on EEH_Activation |
|
1637 | + */ |
|
1638 | + public static function reset() |
|
1639 | + { |
|
1640 | + self::$_default_creator_id = null; |
|
1641 | + self::$_initialized_db_content_already_in_this_request = false; |
|
1642 | + } |
|
1643 | + |
|
1644 | + |
|
1645 | + /** |
|
1646 | + * Removes 'email_confirm' from the Address info question group on activation |
|
1647 | + * |
|
1648 | + * @return void |
|
1649 | + * @throws EE_Error |
|
1650 | + */ |
|
1651 | + public static function removeEmailConfirmFromAddressGroup() |
|
1652 | + { |
|
1653 | + |
|
1654 | + // Pull the email_confirm question ID. |
|
1655 | + $email_confirm_question_id = EEM_Question::instance()->get_Question_ID_from_system_string( |
|
1656 | + EEM_Attendee::system_question_email_confirm |
|
1657 | + ); |
|
1658 | + // Remove the email_confirm question group from the address group questions. |
|
1659 | + EEM_Question_Group_Question::instance()->delete( |
|
1660 | + [ |
|
1661 | + [ |
|
1662 | + 'QST_ID' => $email_confirm_question_id, |
|
1663 | + 'Question_Group.QSG_system' => EEM_Question_Group::system_address, |
|
1664 | + ], |
|
1665 | + ] |
|
1666 | + ); |
|
1667 | + } |
|
1668 | 1668 | } |
@@ -11,230 +11,230 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Messages_Template_Defaults extends EE_Base |
13 | 13 | { |
14 | - /** |
|
15 | - * Used for holding the EE_Message_Template GRP_ID field value. |
|
16 | - * |
|
17 | - * @var [type] |
|
18 | - */ |
|
19 | - protected $_GRP_ID; |
|
20 | - |
|
21 | - /** |
|
22 | - * holds the messenger object |
|
23 | - * |
|
24 | - * @var EE_messenger |
|
25 | - */ |
|
26 | - protected $_messenger; |
|
27 | - |
|
28 | - /** |
|
29 | - * holds the message type object |
|
30 | - * |
|
31 | - * @var EE_message_type |
|
32 | - */ |
|
33 | - protected $_message_type; |
|
34 | - |
|
35 | - /** |
|
36 | - * holds the fields used (this is retrieved from the messenger) |
|
37 | - * |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - protected $_fields; |
|
41 | - |
|
42 | - /** |
|
43 | - * holds the assembled template (with defaults) for creation in the database |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - protected $_templates; |
|
48 | - |
|
49 | - /** |
|
50 | - * holds the contexts used (this is retrieved from the message type) |
|
51 | - * |
|
52 | - * @var array |
|
53 | - */ |
|
54 | - protected $_contexts; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @var EEM_Message_Template_Group |
|
59 | - */ |
|
60 | - protected $_message_template_group_model; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @var EEM_Message_Template |
|
65 | - */ |
|
66 | - protected $_message_template_model; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * EE_Messages_Template_Defaults constructor. |
|
71 | - * |
|
72 | - * @param EE_messenger $messenger |
|
73 | - * @param EE_message_type $message_type |
|
74 | - * @param int $GRP_ID Optional. If included then we're just |
|
75 | - * regenerating the template fields for the given |
|
76 | - * group not the message template group itself |
|
77 | - * @param EEM_Message_Template_Group $message_template_group_model |
|
78 | - * @param EEM_Message_Template $message_template_model |
|
79 | - */ |
|
80 | - public function __construct( |
|
81 | - EE_messenger $messenger, |
|
82 | - EE_message_type $message_type, |
|
83 | - int $GRP_ID, |
|
84 | - EEM_Message_Template_Group $message_template_group_model, |
|
85 | - EEM_Message_Template $message_template_model |
|
86 | - ) { |
|
87 | - $this->_messenger = $messenger; |
|
88 | - $this->_message_type = $message_type; |
|
89 | - $this->_GRP_ID = $GRP_ID ?? 0; |
|
90 | - // set the model object |
|
91 | - $this->_message_template_group_model = $message_template_group_model; |
|
92 | - $this->_message_template_model = $message_template_model; |
|
93 | - $this->_fields = $this->_messenger->get_template_fields(); |
|
94 | - $this->_contexts = $this->_message_type->get_contexts(); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * Setup the _template_data property. |
|
100 | - * This method sets the _templates property array before templates are created. |
|
101 | - * |
|
102 | - * @param string $template_pack This corresponds to a template pack class reference which will contain information |
|
103 | - * about where to obtain the templates. |
|
104 | - * |
|
105 | - */ |
|
106 | - private function _set_templates(string $template_pack) |
|
107 | - { |
|
108 | - // get the corresponding template pack object (if present. If not then we just load the default and add a |
|
109 | - // notice). The class name should be something like 'EE_Messages_Template_Pack_Default' where "default' would be |
|
110 | - // the incoming template pack reference. |
|
111 | - $class_name = |
|
112 | - 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $template_pack))); |
|
113 | - |
|
114 | - if (! class_exists($class_name)) { |
|
115 | - EE_Error::add_error( |
|
116 | - sprintf( |
|
117 | - esc_html__( |
|
118 | - 'The template pack represented by a class corresponding to "%1$s" does not exist. Likely the autoloader for this class has the wrong path or the incoming reference is misspelled. The default template pack has been used to generate the templates instead.', |
|
119 | - 'event_espresso' |
|
120 | - ), |
|
121 | - $class_name |
|
122 | - ), |
|
123 | - __FILE__, |
|
124 | - __FUNCTION__, |
|
125 | - __LINE__ |
|
126 | - ); |
|
127 | - $class_name = 'EE_Messages_Template_Pack_Default'; |
|
128 | - } |
|
129 | - /** @type EE_Messages_Template_Pack $template_pack */ |
|
130 | - $template_pack = new $class_name(); |
|
131 | - |
|
132 | - // get all the templates from the template pack. |
|
133 | - $this->_templates = $template_pack->get_templates($this->_messenger, $this->_message_type); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * Return the contexts for the message type as cached on this instance. |
|
139 | - * |
|
140 | - * @return array |
|
141 | - */ |
|
142 | - public function get_contexts(): array |
|
143 | - { |
|
144 | - return $this->_contexts; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * public facing create new templates method |
|
150 | - * |
|
151 | - * @return array|false|int|string success array or false. |
|
152 | - * @throws EE_Error |
|
153 | - * @throws ReflectionException |
|
154 | - */ |
|
155 | - public function create_new_templates() |
|
156 | - { |
|
157 | - $template_pack = 'default'; |
|
158 | - // if we have the GRP_ID then let's use that to see if there is a set template pack and use that for the new templates. |
|
159 | - if (! empty($this->_GRP_ID)) { |
|
160 | - $message_template_group = $this->_message_template_group_model->get_one_by_ID($this->_GRP_ID); |
|
161 | - $template_pack = $message_template_group instanceof EE_Message_Template_Group |
|
162 | - ? $message_template_group->get_template_pack_name() |
|
163 | - : 'default'; |
|
164 | - // we also need to reset the template variation to default |
|
165 | - $message_template_group->set_template_pack_variation('default'); |
|
166 | - } |
|
167 | - return $this->_create_new_templates($template_pack); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * Handles creating new default templates. |
|
173 | - * |
|
174 | - * @param string $template_pack This corresponds to a template pack class reference |
|
175 | - * which will contain information about where to obtain the templates. |
|
176 | - * @returnarray|bool success array or false. |
|
177 | - * @throws EE_Error |
|
178 | - * @throws ReflectionException |
|
179 | - */ |
|
180 | - protected function _create_new_templates(string $template_pack) |
|
181 | - { |
|
182 | - $this->_set_templates($template_pack); |
|
183 | - |
|
184 | - // necessary properties are set, let's save the default templates |
|
185 | - if (empty($this->_GRP_ID)) { |
|
186 | - $main_template_data = [ |
|
187 | - 'MTP_messenger' => $this->_messenger->name, |
|
188 | - 'MTP_message_type' => $this->_message_type->name, |
|
189 | - 'MTP_is_override' => 0, |
|
190 | - 'MTP_deleted' => 0, |
|
191 | - 'MTP_is_global' => 1, |
|
192 | - 'MTP_user_id' => EEH_Activation::get_default_creator_id(), |
|
193 | - 'MTP_is_active' => 1, |
|
194 | - ]; |
|
195 | - // let's insert the above and get our GRP_ID, then reset the template data array to just include the GRP_ID |
|
196 | - $grp_id = $this->_message_template_group_model->insert($main_template_data); |
|
197 | - if (empty($grp_id)) { |
|
198 | - return $grp_id; |
|
199 | - } |
|
200 | - $this->_GRP_ID = $grp_id; |
|
201 | - } |
|
202 | - |
|
203 | - $template_data = ['GRP_ID' => $this->_GRP_ID]; |
|
204 | - |
|
205 | - foreach ($this->_contexts as $context => $details) { |
|
206 | - foreach ($this->_fields as $field => $field_type) { |
|
207 | - if ($field != 'extra') { |
|
208 | - $template_data['MTP_context'] = $context; |
|
209 | - $template_data['MTP_template_field'] = $field; |
|
210 | - $template_data['MTP_content'] = $this->_templates[ $context ][ $field ]; |
|
211 | - |
|
212 | - $MTP = $this->_message_template_model->insert($template_data); |
|
213 | - if (! $MTP) { |
|
214 | - EE_Error::add_error( |
|
215 | - sprintf( |
|
216 | - esc_html__( |
|
217 | - 'There was an error in saving new template data for %1$s messenger, %2$s message type, %3$s context and %4$s template field.', |
|
218 | - 'event_espresso' |
|
219 | - ), |
|
220 | - $this->_messenger->name, |
|
221 | - $this->_message_type->name, |
|
222 | - $context, |
|
223 | - $field |
|
224 | - ), |
|
225 | - __FILE__, |
|
226 | - __FUNCTION__, |
|
227 | - __LINE__ |
|
228 | - ); |
|
229 | - return false; |
|
230 | - } |
|
231 | - } |
|
232 | - } |
|
233 | - } |
|
234 | - |
|
235 | - return [ |
|
236 | - 'GRP_ID' => $this->_GRP_ID, |
|
237 | - 'MTP_context' => key($this->_contexts), |
|
238 | - ]; |
|
239 | - } |
|
14 | + /** |
|
15 | + * Used for holding the EE_Message_Template GRP_ID field value. |
|
16 | + * |
|
17 | + * @var [type] |
|
18 | + */ |
|
19 | + protected $_GRP_ID; |
|
20 | + |
|
21 | + /** |
|
22 | + * holds the messenger object |
|
23 | + * |
|
24 | + * @var EE_messenger |
|
25 | + */ |
|
26 | + protected $_messenger; |
|
27 | + |
|
28 | + /** |
|
29 | + * holds the message type object |
|
30 | + * |
|
31 | + * @var EE_message_type |
|
32 | + */ |
|
33 | + protected $_message_type; |
|
34 | + |
|
35 | + /** |
|
36 | + * holds the fields used (this is retrieved from the messenger) |
|
37 | + * |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + protected $_fields; |
|
41 | + |
|
42 | + /** |
|
43 | + * holds the assembled template (with defaults) for creation in the database |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + protected $_templates; |
|
48 | + |
|
49 | + /** |
|
50 | + * holds the contexts used (this is retrieved from the message type) |
|
51 | + * |
|
52 | + * @var array |
|
53 | + */ |
|
54 | + protected $_contexts; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @var EEM_Message_Template_Group |
|
59 | + */ |
|
60 | + protected $_message_template_group_model; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @var EEM_Message_Template |
|
65 | + */ |
|
66 | + protected $_message_template_model; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * EE_Messages_Template_Defaults constructor. |
|
71 | + * |
|
72 | + * @param EE_messenger $messenger |
|
73 | + * @param EE_message_type $message_type |
|
74 | + * @param int $GRP_ID Optional. If included then we're just |
|
75 | + * regenerating the template fields for the given |
|
76 | + * group not the message template group itself |
|
77 | + * @param EEM_Message_Template_Group $message_template_group_model |
|
78 | + * @param EEM_Message_Template $message_template_model |
|
79 | + */ |
|
80 | + public function __construct( |
|
81 | + EE_messenger $messenger, |
|
82 | + EE_message_type $message_type, |
|
83 | + int $GRP_ID, |
|
84 | + EEM_Message_Template_Group $message_template_group_model, |
|
85 | + EEM_Message_Template $message_template_model |
|
86 | + ) { |
|
87 | + $this->_messenger = $messenger; |
|
88 | + $this->_message_type = $message_type; |
|
89 | + $this->_GRP_ID = $GRP_ID ?? 0; |
|
90 | + // set the model object |
|
91 | + $this->_message_template_group_model = $message_template_group_model; |
|
92 | + $this->_message_template_model = $message_template_model; |
|
93 | + $this->_fields = $this->_messenger->get_template_fields(); |
|
94 | + $this->_contexts = $this->_message_type->get_contexts(); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * Setup the _template_data property. |
|
100 | + * This method sets the _templates property array before templates are created. |
|
101 | + * |
|
102 | + * @param string $template_pack This corresponds to a template pack class reference which will contain information |
|
103 | + * about where to obtain the templates. |
|
104 | + * |
|
105 | + */ |
|
106 | + private function _set_templates(string $template_pack) |
|
107 | + { |
|
108 | + // get the corresponding template pack object (if present. If not then we just load the default and add a |
|
109 | + // notice). The class name should be something like 'EE_Messages_Template_Pack_Default' where "default' would be |
|
110 | + // the incoming template pack reference. |
|
111 | + $class_name = |
|
112 | + 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $template_pack))); |
|
113 | + |
|
114 | + if (! class_exists($class_name)) { |
|
115 | + EE_Error::add_error( |
|
116 | + sprintf( |
|
117 | + esc_html__( |
|
118 | + 'The template pack represented by a class corresponding to "%1$s" does not exist. Likely the autoloader for this class has the wrong path or the incoming reference is misspelled. The default template pack has been used to generate the templates instead.', |
|
119 | + 'event_espresso' |
|
120 | + ), |
|
121 | + $class_name |
|
122 | + ), |
|
123 | + __FILE__, |
|
124 | + __FUNCTION__, |
|
125 | + __LINE__ |
|
126 | + ); |
|
127 | + $class_name = 'EE_Messages_Template_Pack_Default'; |
|
128 | + } |
|
129 | + /** @type EE_Messages_Template_Pack $template_pack */ |
|
130 | + $template_pack = new $class_name(); |
|
131 | + |
|
132 | + // get all the templates from the template pack. |
|
133 | + $this->_templates = $template_pack->get_templates($this->_messenger, $this->_message_type); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * Return the contexts for the message type as cached on this instance. |
|
139 | + * |
|
140 | + * @return array |
|
141 | + */ |
|
142 | + public function get_contexts(): array |
|
143 | + { |
|
144 | + return $this->_contexts; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * public facing create new templates method |
|
150 | + * |
|
151 | + * @return array|false|int|string success array or false. |
|
152 | + * @throws EE_Error |
|
153 | + * @throws ReflectionException |
|
154 | + */ |
|
155 | + public function create_new_templates() |
|
156 | + { |
|
157 | + $template_pack = 'default'; |
|
158 | + // if we have the GRP_ID then let's use that to see if there is a set template pack and use that for the new templates. |
|
159 | + if (! empty($this->_GRP_ID)) { |
|
160 | + $message_template_group = $this->_message_template_group_model->get_one_by_ID($this->_GRP_ID); |
|
161 | + $template_pack = $message_template_group instanceof EE_Message_Template_Group |
|
162 | + ? $message_template_group->get_template_pack_name() |
|
163 | + : 'default'; |
|
164 | + // we also need to reset the template variation to default |
|
165 | + $message_template_group->set_template_pack_variation('default'); |
|
166 | + } |
|
167 | + return $this->_create_new_templates($template_pack); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * Handles creating new default templates. |
|
173 | + * |
|
174 | + * @param string $template_pack This corresponds to a template pack class reference |
|
175 | + * which will contain information about where to obtain the templates. |
|
176 | + * @returnarray|bool success array or false. |
|
177 | + * @throws EE_Error |
|
178 | + * @throws ReflectionException |
|
179 | + */ |
|
180 | + protected function _create_new_templates(string $template_pack) |
|
181 | + { |
|
182 | + $this->_set_templates($template_pack); |
|
183 | + |
|
184 | + // necessary properties are set, let's save the default templates |
|
185 | + if (empty($this->_GRP_ID)) { |
|
186 | + $main_template_data = [ |
|
187 | + 'MTP_messenger' => $this->_messenger->name, |
|
188 | + 'MTP_message_type' => $this->_message_type->name, |
|
189 | + 'MTP_is_override' => 0, |
|
190 | + 'MTP_deleted' => 0, |
|
191 | + 'MTP_is_global' => 1, |
|
192 | + 'MTP_user_id' => EEH_Activation::get_default_creator_id(), |
|
193 | + 'MTP_is_active' => 1, |
|
194 | + ]; |
|
195 | + // let's insert the above and get our GRP_ID, then reset the template data array to just include the GRP_ID |
|
196 | + $grp_id = $this->_message_template_group_model->insert($main_template_data); |
|
197 | + if (empty($grp_id)) { |
|
198 | + return $grp_id; |
|
199 | + } |
|
200 | + $this->_GRP_ID = $grp_id; |
|
201 | + } |
|
202 | + |
|
203 | + $template_data = ['GRP_ID' => $this->_GRP_ID]; |
|
204 | + |
|
205 | + foreach ($this->_contexts as $context => $details) { |
|
206 | + foreach ($this->_fields as $field => $field_type) { |
|
207 | + if ($field != 'extra') { |
|
208 | + $template_data['MTP_context'] = $context; |
|
209 | + $template_data['MTP_template_field'] = $field; |
|
210 | + $template_data['MTP_content'] = $this->_templates[ $context ][ $field ]; |
|
211 | + |
|
212 | + $MTP = $this->_message_template_model->insert($template_data); |
|
213 | + if (! $MTP) { |
|
214 | + EE_Error::add_error( |
|
215 | + sprintf( |
|
216 | + esc_html__( |
|
217 | + 'There was an error in saving new template data for %1$s messenger, %2$s message type, %3$s context and %4$s template field.', |
|
218 | + 'event_espresso' |
|
219 | + ), |
|
220 | + $this->_messenger->name, |
|
221 | + $this->_message_type->name, |
|
222 | + $context, |
|
223 | + $field |
|
224 | + ), |
|
225 | + __FILE__, |
|
226 | + __FUNCTION__, |
|
227 | + __LINE__ |
|
228 | + ); |
|
229 | + return false; |
|
230 | + } |
|
231 | + } |
|
232 | + } |
|
233 | + } |
|
234 | + |
|
235 | + return [ |
|
236 | + 'GRP_ID' => $this->_GRP_ID, |
|
237 | + 'MTP_context' => key($this->_contexts), |
|
238 | + ]; |
|
239 | + } |
|
240 | 240 | } |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | // notice). The class name should be something like 'EE_Messages_Template_Pack_Default' where "default' would be |
110 | 110 | // the incoming template pack reference. |
111 | 111 | $class_name = |
112 | - 'EE_Messages_Template_Pack_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $template_pack))); |
|
112 | + 'EE_Messages_Template_Pack_'.str_replace(' ', '_', ucwords(str_replace('_', ' ', $template_pack))); |
|
113 | 113 | |
114 | - if (! class_exists($class_name)) { |
|
114 | + if ( ! class_exists($class_name)) { |
|
115 | 115 | EE_Error::add_error( |
116 | 116 | sprintf( |
117 | 117 | esc_html__( |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | { |
157 | 157 | $template_pack = 'default'; |
158 | 158 | // if we have the GRP_ID then let's use that to see if there is a set template pack and use that for the new templates. |
159 | - if (! empty($this->_GRP_ID)) { |
|
159 | + if ( ! empty($this->_GRP_ID)) { |
|
160 | 160 | $message_template_group = $this->_message_template_group_model->get_one_by_ID($this->_GRP_ID); |
161 | 161 | $template_pack = $message_template_group instanceof EE_Message_Template_Group |
162 | 162 | ? $message_template_group->get_template_pack_name() |
@@ -207,10 +207,10 @@ discard block |
||
207 | 207 | if ($field != 'extra') { |
208 | 208 | $template_data['MTP_context'] = $context; |
209 | 209 | $template_data['MTP_template_field'] = $field; |
210 | - $template_data['MTP_content'] = $this->_templates[ $context ][ $field ]; |
|
210 | + $template_data['MTP_content'] = $this->_templates[$context][$field]; |
|
211 | 211 | |
212 | 212 | $MTP = $this->_message_template_model->insert($template_data); |
213 | - if (! $MTP) { |
|
213 | + if ( ! $MTP) { |
|
214 | 214 | EE_Error::add_error( |
215 | 215 | sprintf( |
216 | 216 | esc_html__( |
@@ -10,549 +10,549 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_Html_messenger extends EE_messenger |
12 | 12 | { |
13 | - /** |
|
14 | - * The following are the properties that this messenger requires for displaying the html |
|
15 | - */ |
|
16 | - /** |
|
17 | - * This is the html body generated by the template via the message type. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - protected $_content = ''; |
|
22 | - |
|
23 | - /** |
|
24 | - * This is for the page title that gets displayed. (Why use "subject"? Because the "title" tag in html is |
|
25 | - * equivalent to the "subject" of the page. |
|
26 | - * |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $_subject = ''; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * EE_Html_messenger constructor. |
|
34 | - */ |
|
35 | - public function __construct() |
|
36 | - { |
|
37 | - // set properties |
|
38 | - $this->name = 'html'; |
|
39 | - $this->description = esc_html__( |
|
40 | - 'This messenger outputs a message to a browser for display.', |
|
41 | - 'event_espresso' |
|
42 | - ); |
|
43 | - $this->label = [ |
|
44 | - 'singular' => esc_html__('html', 'event_espresso'), |
|
45 | - 'plural' => esc_html__('html', 'event_espresso'), |
|
46 | - ]; |
|
47 | - $this->activate_on_install = true; |
|
48 | - // add the "powered by EE" credit link to the HTML receipt and invoice |
|
49 | - add_filter( |
|
50 | - 'FHEE__EE_Html_messenger___send_message__main_body', |
|
51 | - [$this, 'add_powered_by_credit_link_to_receipt_and_invoice'], |
|
52 | - 10, |
|
53 | - 3 |
|
54 | - ); |
|
55 | - parent::__construct(); |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * HTML Messenger desires execution immediately. |
|
61 | - * |
|
62 | - * @return bool |
|
63 | - * @since 4.9.0 |
|
64 | - * @see parent::send_now() for documentation. |
|
65 | - */ |
|
66 | - public function send_now(): bool |
|
67 | - { |
|
68 | - return true; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * HTML Messenger allows an empty to field. |
|
74 | - * |
|
75 | - * @return bool |
|
76 | - * @since 4.9.0 |
|
77 | - * @see parent::allow_empty_to_field() for documentation |
|
78 | - */ |
|
79 | - public function allow_empty_to_field(): bool |
|
80 | - { |
|
81 | - return true; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @see abstract declaration in EE_messenger for details. |
|
87 | - */ |
|
88 | - protected function _set_admin_pages() |
|
89 | - { |
|
90 | - $this->admin_registered_pages = ['events_edit' => true]; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * @see abstract declaration in EE_messenger for details. |
|
96 | - */ |
|
97 | - protected function _set_valid_shortcodes() |
|
98 | - { |
|
99 | - $this->_valid_shortcodes = []; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @see abstract declaration in EE_messenger for details. |
|
105 | - */ |
|
106 | - protected function _set_validator_config() |
|
107 | - { |
|
108 | - $this->_validator_config = [ |
|
109 | - 'subject' => [ |
|
110 | - 'shortcodes' => ['organization', 'primary_registration_details', 'email', 'transaction'], |
|
111 | - ], |
|
112 | - 'content' => [ |
|
113 | - 'shortcodes' => [ |
|
114 | - 'organization', |
|
115 | - 'primary_registration_list', |
|
116 | - 'primary_registration_details', |
|
117 | - 'email', |
|
118 | - 'transaction', |
|
119 | - 'event_list', |
|
120 | - 'payment_list', |
|
121 | - 'venue', |
|
122 | - 'line_item_list', |
|
123 | - 'messenger', |
|
124 | - 'ticket_list', |
|
125 | - ], |
|
126 | - ], |
|
127 | - 'event_list' => [ |
|
128 | - 'shortcodes' => [ |
|
129 | - 'event', |
|
130 | - 'ticket_list', |
|
131 | - 'venue', |
|
132 | - 'primary_registration_details', |
|
133 | - 'primary_registration_list', |
|
134 | - 'event_author', |
|
135 | - ], |
|
136 | - 'required' => ['[EVENT_LIST]'], |
|
137 | - ], |
|
138 | - 'ticket_list' => [ |
|
139 | - 'shortcodes' => [ |
|
140 | - 'attendee_list', |
|
141 | - 'ticket', |
|
142 | - 'datetime_list', |
|
143 | - 'primary_registration_details', |
|
144 | - 'line_item_list', |
|
145 | - 'venue', |
|
146 | - ], |
|
147 | - 'required' => ['[TICKET_LIST]'], |
|
148 | - ], |
|
149 | - 'ticket_line_item_no_pms' => [ |
|
150 | - 'shortcodes' => ['line_item', 'ticket'], |
|
151 | - 'required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
152 | - ], |
|
153 | - 'ticket_line_item_pms' => [ |
|
154 | - 'shortcodes' => ['line_item', 'ticket', 'line_item_list'], |
|
155 | - 'required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
156 | - ], |
|
157 | - 'price_modifier_line_item_list' => [ |
|
158 | - 'shortcodes' => ['line_item'], |
|
159 | - 'required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'], |
|
160 | - ], |
|
161 | - 'datetime_list' => [ |
|
162 | - 'shortcodes' => ['datetime'], |
|
163 | - 'required' => ['[DATETIME_LIST]'], |
|
164 | - ], |
|
165 | - 'attendee_list' => [ |
|
166 | - 'shortcodes' => ['attendee'], |
|
167 | - 'required' => ['[ATTENDEE_LIST]'], |
|
168 | - ], |
|
169 | - 'tax_line_item_list' => [ |
|
170 | - 'shortcodes' => ['line_item'], |
|
171 | - 'required' => ['[TAX_LINE_ITEM_LIST]'], |
|
172 | - ], |
|
173 | - 'additional_line_item_list' => [ |
|
174 | - 'shortcodes' => ['line_item'], |
|
175 | - 'required' => ['[ADDITIONAL_LINE_ITEM_LIST]'], |
|
176 | - ], |
|
177 | - 'payment_list' => [ |
|
178 | - 'shortcodes' => ['payment'], |
|
179 | - 'required' => ['[PAYMENT_LIST_*]'], |
|
180 | - ], |
|
181 | - ]; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger |
|
187 | - * is a different messenger. Child messengers can set hooks for the sending messenger to callback on if necessary |
|
188 | - * (i.e. swap out css files or something else). |
|
189 | - * |
|
190 | - * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed. |
|
191 | - * @return void |
|
192 | - * @since 4.5.0 |
|
193 | - */ |
|
194 | - public function do_secondary_messenger_hooks($sending_messenger_name) |
|
195 | - { |
|
196 | - if ($sending_messenger_name === 'pdf') { |
|
197 | - add_filter('EE_messenger__get_variation__variation', [$this, 'add_html_css'], 10, 8); |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @param $variation_path |
|
204 | - * @param EE_Messages_Template_Pack $template_pack |
|
205 | - * @param $messenger_name |
|
206 | - * @param $message_type_name |
|
207 | - * @param $url |
|
208 | - * @param $type |
|
209 | - * @param $variation |
|
210 | - * @param $skip_filters |
|
211 | - * @return string |
|
212 | - */ |
|
213 | - public function add_html_css( |
|
214 | - $variation_path, |
|
215 | - EE_Messages_Template_Pack $template_pack, |
|
216 | - $messenger_name, |
|
217 | - $message_type_name, |
|
218 | - $url, |
|
219 | - $type, |
|
220 | - $variation, |
|
221 | - $skip_filters |
|
222 | - ): string { |
|
223 | - return $template_pack->get_variation( |
|
224 | - $this->name, |
|
225 | - $message_type_name, |
|
226 | - $type, |
|
227 | - $variation, |
|
228 | - $url, |
|
229 | - '.css', |
|
230 | - $skip_filters |
|
231 | - ); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * Takes care of enqueuing any necessary scripts or styles for the page. A do_action() so message types using this |
|
237 | - * messenger can add their own js. |
|
238 | - * |
|
239 | - * @return void. |
|
240 | - */ |
|
241 | - public function enqueue_scripts_styles() |
|
242 | - { |
|
243 | - parent::enqueue_scripts_styles(); |
|
244 | - do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles'); |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * _set_template_fields |
|
250 | - * This sets up the fields that a messenger requires for the message to go out. |
|
251 | - * |
|
252 | - * @access protected |
|
253 | - * @return void |
|
254 | - */ |
|
255 | - protected function _set_template_fields() |
|
256 | - { |
|
257 | - // any extra template fields that are NOT used by the messenger |
|
258 | - // but will get used by a messenger field for shortcode replacement |
|
259 | - // get added to the 'extra' key in an associated array |
|
260 | - // indexed by the messenger field they relate to. |
|
261 | - // This is important for the Messages_admin to know what fields to display to the user. |
|
262 | - // Also, notice that the "values" are equal to the field type |
|
263 | - // that messages admin will use to know what kind of field to display. |
|
264 | - // The values ALSO have one index labeled "shortcode". |
|
265 | - // The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) |
|
266 | - // is required in order for this extra field to be displayed. |
|
267 | - // If the required shortcode isn't part of the shortcodes array |
|
268 | - // then the field is not needed and will not be displayed/parsed. |
|
269 | - $this->_template_fields = [ |
|
270 | - 'subject' => [ |
|
271 | - 'input' => 'text', |
|
272 | - 'label' => esc_html__('Page Title', 'event_espresso'), |
|
273 | - 'type' => 'string', |
|
274 | - 'required' => true, |
|
275 | - 'validation' => true, |
|
276 | - 'css_class' => 'large-text', |
|
277 | - 'format' => '%s', |
|
278 | - ], |
|
279 | - 'content' => '', |
|
280 | - // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
281 | - 'extra' => [ |
|
282 | - 'content' => [ |
|
283 | - 'main' => [ |
|
284 | - 'input' => 'wp_editor', |
|
285 | - 'label' => esc_html__('Main Content', 'event_espresso'), |
|
286 | - 'type' => 'string', |
|
287 | - 'required' => true, |
|
288 | - 'validation' => true, |
|
289 | - 'format' => '%s', |
|
290 | - 'rows' => '15', |
|
291 | - ], |
|
292 | - 'event_list' => [ |
|
293 | - 'input' => 'wp_editor', |
|
294 | - 'label' => '[EVENT_LIST]', |
|
295 | - 'type' => 'string', |
|
296 | - 'required' => true, |
|
297 | - 'validation' => true, |
|
298 | - 'format' => '%s', |
|
299 | - 'rows' => '15', |
|
300 | - 'shortcodes_required' => ['[EVENT_LIST]'], |
|
301 | - ], |
|
302 | - 'ticket_list' => [ |
|
303 | - 'input' => 'textarea', |
|
304 | - 'label' => '[TICKET_LIST]', |
|
305 | - 'type' => 'string', |
|
306 | - 'required' => true, |
|
307 | - 'validation' => true, |
|
308 | - 'format' => '%s', |
|
309 | - 'css_class' => 'large-text', |
|
310 | - 'rows' => '10', |
|
311 | - 'shortcodes_required' => ['[TICKET_LIST]'], |
|
312 | - ], |
|
313 | - 'ticket_line_item_no_pms' => [ |
|
314 | - 'input' => 'textarea', |
|
315 | - 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
316 | - 'Ticket Line Item List with no Price Modifiers', |
|
317 | - 'event_espresso' |
|
318 | - ), |
|
319 | - 'type' => 'string', |
|
320 | - 'required' => false, |
|
321 | - 'validation' => true, |
|
322 | - 'format' => '%s', |
|
323 | - 'css_class' => 'large-text', |
|
324 | - 'rows' => '5', |
|
325 | - 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
326 | - ], |
|
327 | - 'ticket_line_item_pms' => [ |
|
328 | - 'input' => 'textarea', |
|
329 | - 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
330 | - 'Ticket Line Item List with Price Modifiers', |
|
331 | - 'event_espresso' |
|
332 | - ), |
|
333 | - 'type' => 'string', |
|
334 | - 'required' => false, |
|
335 | - 'validation' => true, |
|
336 | - 'format' => '%s', |
|
337 | - 'css_class' => 'large-text', |
|
338 | - 'rows' => '5', |
|
339 | - 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
340 | - ], |
|
341 | - 'price_modifier_line_item_list' => [ |
|
342 | - 'input' => 'textarea', |
|
343 | - 'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
344 | - 'type' => 'string', |
|
345 | - 'required' => false, |
|
346 | - 'validation' => true, |
|
347 | - 'format' => '%s', |
|
348 | - 'css_class' => 'large-text', |
|
349 | - 'rows' => '5', |
|
350 | - 'shortcodes_required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'], |
|
351 | - ], |
|
352 | - 'datetime_list' => [ |
|
353 | - 'input' => 'textarea', |
|
354 | - 'label' => '[DATETIME_LIST]', |
|
355 | - 'type' => 'string', |
|
356 | - 'required' => true, |
|
357 | - 'validation' => true, |
|
358 | - 'format' => '%s', |
|
359 | - 'css_class' => 'large-text', |
|
360 | - 'rows' => '5', |
|
361 | - 'shortcodes_required' => ['[DATETIME_LIST]'], |
|
362 | - ], |
|
363 | - 'attendee_list' => [ |
|
364 | - 'input' => 'textarea', |
|
365 | - 'label' => '[ATTENDEE_LIST]', |
|
366 | - 'type' => 'string', |
|
367 | - 'required' => true, |
|
368 | - 'validation' => true, |
|
369 | - 'format' => '%s', |
|
370 | - 'css_class' => 'large-text', |
|
371 | - 'rows' => '5', |
|
372 | - 'shortcodes_required' => ['[ATTENDEE_LIST]'], |
|
373 | - ], |
|
374 | - 'tax_line_item_list' => [ |
|
375 | - 'input' => 'textarea', |
|
376 | - 'label' => '[TAX_LINE_ITEM_LIST]', |
|
377 | - 'type' => 'string', |
|
378 | - 'required' => false, |
|
379 | - 'validation' => true, |
|
380 | - 'format' => '%s', |
|
381 | - 'css_class' => 'large-text', |
|
382 | - 'rows' => '5', |
|
383 | - 'shortcodes_required' => ['[TAX_LINE_ITEM_LIST]'], |
|
384 | - ], |
|
385 | - 'additional_line_item_list' => [ |
|
386 | - 'input' => 'textarea', |
|
387 | - 'label' => '[ADDITIONAL_LINE_ITEM_LIST]', |
|
388 | - 'type' => 'string', |
|
389 | - 'required' => false, |
|
390 | - 'validation' => true, |
|
391 | - 'format' => '%s', |
|
392 | - 'css_class' => 'large-text', |
|
393 | - 'rows' => '5', |
|
394 | - 'shortcodes_required' => ['[ADDITIONAL_LINE_ITEM_LIST]'], |
|
395 | - ], |
|
396 | - 'payment_list' => [ |
|
397 | - 'input' => 'textarea', |
|
398 | - 'label' => '[PAYMENT_LIST]', |
|
399 | - 'type' => 'string', |
|
400 | - 'required' => true, |
|
401 | - 'validation' => true, |
|
402 | - 'format' => '%s', |
|
403 | - 'css_class' => 'large-text', |
|
404 | - 'rows' => '5', |
|
405 | - 'shortcodes_required' => ['[PAYMENT_LIST_*]'], |
|
406 | - ], |
|
407 | - ], |
|
408 | - ], |
|
409 | - ]; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * @see definition of this method in parent |
|
415 | - * @since 4.5.0 |
|
416 | - */ |
|
417 | - protected function _set_default_message_types() |
|
418 | - { |
|
419 | - $this->_default_message_types = ['receipt', 'invoice']; |
|
420 | - } |
|
421 | - |
|
422 | - |
|
423 | - /** |
|
424 | - * @see definition of this method in parent |
|
425 | - * @since 4.5.0 |
|
426 | - */ |
|
427 | - protected function _set_valid_message_types() |
|
428 | - { |
|
429 | - $this->_valid_message_types = ['receipt', 'invoice']; |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * Displays the message in the browser. |
|
435 | - * |
|
436 | - * @return void. |
|
437 | - * @since 4.5.0 |
|
438 | - */ |
|
439 | - protected function _send_message() |
|
440 | - { |
|
441 | - $this->_template_args = [ |
|
442 | - 'page_title' => $this->_subject, |
|
443 | - 'base_css' => $this->get_variation( |
|
444 | - $this->_tmp_pack, |
|
445 | - $this->_incoming_message_type->name, |
|
446 | - true, |
|
447 | - 'base', |
|
448 | - $this->_variation |
|
449 | - ), |
|
450 | - 'print_css' => $this->get_variation( |
|
451 | - $this->_tmp_pack, |
|
452 | - $this->_incoming_message_type->name, |
|
453 | - true, |
|
454 | - 'print', |
|
455 | - $this->_variation |
|
456 | - ), |
|
457 | - 'main_css' => $this->get_variation( |
|
458 | - $this->_tmp_pack, |
|
459 | - $this->_incoming_message_type->name, |
|
460 | - true, |
|
461 | - 'main', |
|
462 | - $this->_variation |
|
463 | - ), |
|
464 | - 'main_body' => wpautop( |
|
465 | - apply_filters( |
|
466 | - 'FHEE__EE_Html_messenger___send_message__main_body', |
|
467 | - $this->_content, |
|
468 | - $this->_content, |
|
469 | - $this->_incoming_message_type |
|
470 | - ) |
|
471 | - ), |
|
472 | - ]; |
|
473 | - $this->_deregister_wp_hooks(); |
|
474 | - add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_styles']); |
|
475 | - echo $this->_get_main_template(); // already escaped |
|
476 | - exit(); |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - /** |
|
481 | - * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't |
|
482 | - * interfere with our templates. If users want to add any custom styles or scripts they must use the |
|
483 | - * AHEE__EE_Html_messenger__enqueue_scripts_styles hook. |
|
484 | - * |
|
485 | - * @return void |
|
486 | - * @since 4.5.0 |
|
487 | - */ |
|
488 | - protected function _deregister_wp_hooks() |
|
489 | - { |
|
490 | - remove_all_actions('wp_head'); |
|
491 | - remove_all_actions('wp_footer'); |
|
492 | - remove_all_actions('wp_print_footer_scripts'); |
|
493 | - remove_all_actions('wp_enqueue_scripts'); |
|
494 | - global $wp_scripts, $wp_styles; |
|
495 | - $wp_scripts = $wp_styles = []; |
|
496 | - // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load. |
|
497 | - add_action('wp_footer', 'wp_print_footer_scripts'); |
|
498 | - add_action('wp_print_footer_scripts', '_wp_footer_scripts'); |
|
499 | - add_action('wp_head', 'wp_enqueue_scripts'); |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - /** |
|
504 | - * Overwrite parent _get_main_template for display_html purposes. |
|
505 | - * |
|
506 | - * @param bool $preview |
|
507 | - * @return string |
|
508 | - * @since 4.5.0 |
|
509 | - */ |
|
510 | - protected function _get_main_template($preview = false): string |
|
511 | - { |
|
512 | - $wrapper_template = $this->_tmp_pack->get_wrapper($this->name); |
|
513 | - // include message type as a template arg |
|
514 | - $this->_template_args['message_type'] = $this->_incoming_message_type; |
|
515 | - return EEH_Template::display_template($wrapper_template, $this->_template_args, true); |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * @return void |
|
521 | - */ |
|
522 | - protected function _preview() |
|
523 | - { |
|
524 | - $this->_send_message(); |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - protected function _set_admin_settings_fields() |
|
529 | - { |
|
530 | - } |
|
531 | - |
|
532 | - |
|
533 | - /** |
|
534 | - * add the "powered by EE" credit link to the HTML receipt and invoice |
|
535 | - * |
|
536 | - * @param string $content |
|
537 | - * @param string $content_again |
|
538 | - * @param EE_message_type $incoming_message_type |
|
539 | - * @return string |
|
540 | - */ |
|
541 | - public function add_powered_by_credit_link_to_receipt_and_invoice( |
|
542 | - string $content, |
|
543 | - string $content_again, |
|
544 | - EE_message_type $incoming_message_type |
|
545 | - ): string { |
|
546 | - if ( |
|
547 | - ($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt') |
|
548 | - && apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true) |
|
549 | - ) { |
|
550 | - $content .= EEH_Template::powered_by_event_espresso( |
|
551 | - 'aln-cntr', |
|
552 | - '', |
|
553 | - ['utm_content' => 'messages_system'] |
|
554 | - ) . EEH_HTML::div(EEH_HTML::p(' ')); |
|
555 | - } |
|
556 | - return $content; |
|
557 | - } |
|
13 | + /** |
|
14 | + * The following are the properties that this messenger requires for displaying the html |
|
15 | + */ |
|
16 | + /** |
|
17 | + * This is the html body generated by the template via the message type. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + protected $_content = ''; |
|
22 | + |
|
23 | + /** |
|
24 | + * This is for the page title that gets displayed. (Why use "subject"? Because the "title" tag in html is |
|
25 | + * equivalent to the "subject" of the page. |
|
26 | + * |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $_subject = ''; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * EE_Html_messenger constructor. |
|
34 | + */ |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + // set properties |
|
38 | + $this->name = 'html'; |
|
39 | + $this->description = esc_html__( |
|
40 | + 'This messenger outputs a message to a browser for display.', |
|
41 | + 'event_espresso' |
|
42 | + ); |
|
43 | + $this->label = [ |
|
44 | + 'singular' => esc_html__('html', 'event_espresso'), |
|
45 | + 'plural' => esc_html__('html', 'event_espresso'), |
|
46 | + ]; |
|
47 | + $this->activate_on_install = true; |
|
48 | + // add the "powered by EE" credit link to the HTML receipt and invoice |
|
49 | + add_filter( |
|
50 | + 'FHEE__EE_Html_messenger___send_message__main_body', |
|
51 | + [$this, 'add_powered_by_credit_link_to_receipt_and_invoice'], |
|
52 | + 10, |
|
53 | + 3 |
|
54 | + ); |
|
55 | + parent::__construct(); |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * HTML Messenger desires execution immediately. |
|
61 | + * |
|
62 | + * @return bool |
|
63 | + * @since 4.9.0 |
|
64 | + * @see parent::send_now() for documentation. |
|
65 | + */ |
|
66 | + public function send_now(): bool |
|
67 | + { |
|
68 | + return true; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * HTML Messenger allows an empty to field. |
|
74 | + * |
|
75 | + * @return bool |
|
76 | + * @since 4.9.0 |
|
77 | + * @see parent::allow_empty_to_field() for documentation |
|
78 | + */ |
|
79 | + public function allow_empty_to_field(): bool |
|
80 | + { |
|
81 | + return true; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @see abstract declaration in EE_messenger for details. |
|
87 | + */ |
|
88 | + protected function _set_admin_pages() |
|
89 | + { |
|
90 | + $this->admin_registered_pages = ['events_edit' => true]; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * @see abstract declaration in EE_messenger for details. |
|
96 | + */ |
|
97 | + protected function _set_valid_shortcodes() |
|
98 | + { |
|
99 | + $this->_valid_shortcodes = []; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @see abstract declaration in EE_messenger for details. |
|
105 | + */ |
|
106 | + protected function _set_validator_config() |
|
107 | + { |
|
108 | + $this->_validator_config = [ |
|
109 | + 'subject' => [ |
|
110 | + 'shortcodes' => ['organization', 'primary_registration_details', 'email', 'transaction'], |
|
111 | + ], |
|
112 | + 'content' => [ |
|
113 | + 'shortcodes' => [ |
|
114 | + 'organization', |
|
115 | + 'primary_registration_list', |
|
116 | + 'primary_registration_details', |
|
117 | + 'email', |
|
118 | + 'transaction', |
|
119 | + 'event_list', |
|
120 | + 'payment_list', |
|
121 | + 'venue', |
|
122 | + 'line_item_list', |
|
123 | + 'messenger', |
|
124 | + 'ticket_list', |
|
125 | + ], |
|
126 | + ], |
|
127 | + 'event_list' => [ |
|
128 | + 'shortcodes' => [ |
|
129 | + 'event', |
|
130 | + 'ticket_list', |
|
131 | + 'venue', |
|
132 | + 'primary_registration_details', |
|
133 | + 'primary_registration_list', |
|
134 | + 'event_author', |
|
135 | + ], |
|
136 | + 'required' => ['[EVENT_LIST]'], |
|
137 | + ], |
|
138 | + 'ticket_list' => [ |
|
139 | + 'shortcodes' => [ |
|
140 | + 'attendee_list', |
|
141 | + 'ticket', |
|
142 | + 'datetime_list', |
|
143 | + 'primary_registration_details', |
|
144 | + 'line_item_list', |
|
145 | + 'venue', |
|
146 | + ], |
|
147 | + 'required' => ['[TICKET_LIST]'], |
|
148 | + ], |
|
149 | + 'ticket_line_item_no_pms' => [ |
|
150 | + 'shortcodes' => ['line_item', 'ticket'], |
|
151 | + 'required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
152 | + ], |
|
153 | + 'ticket_line_item_pms' => [ |
|
154 | + 'shortcodes' => ['line_item', 'ticket', 'line_item_list'], |
|
155 | + 'required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
156 | + ], |
|
157 | + 'price_modifier_line_item_list' => [ |
|
158 | + 'shortcodes' => ['line_item'], |
|
159 | + 'required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'], |
|
160 | + ], |
|
161 | + 'datetime_list' => [ |
|
162 | + 'shortcodes' => ['datetime'], |
|
163 | + 'required' => ['[DATETIME_LIST]'], |
|
164 | + ], |
|
165 | + 'attendee_list' => [ |
|
166 | + 'shortcodes' => ['attendee'], |
|
167 | + 'required' => ['[ATTENDEE_LIST]'], |
|
168 | + ], |
|
169 | + 'tax_line_item_list' => [ |
|
170 | + 'shortcodes' => ['line_item'], |
|
171 | + 'required' => ['[TAX_LINE_ITEM_LIST]'], |
|
172 | + ], |
|
173 | + 'additional_line_item_list' => [ |
|
174 | + 'shortcodes' => ['line_item'], |
|
175 | + 'required' => ['[ADDITIONAL_LINE_ITEM_LIST]'], |
|
176 | + ], |
|
177 | + 'payment_list' => [ |
|
178 | + 'shortcodes' => ['payment'], |
|
179 | + 'required' => ['[PAYMENT_LIST_*]'], |
|
180 | + ], |
|
181 | + ]; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger |
|
187 | + * is a different messenger. Child messengers can set hooks for the sending messenger to callback on if necessary |
|
188 | + * (i.e. swap out css files or something else). |
|
189 | + * |
|
190 | + * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed. |
|
191 | + * @return void |
|
192 | + * @since 4.5.0 |
|
193 | + */ |
|
194 | + public function do_secondary_messenger_hooks($sending_messenger_name) |
|
195 | + { |
|
196 | + if ($sending_messenger_name === 'pdf') { |
|
197 | + add_filter('EE_messenger__get_variation__variation', [$this, 'add_html_css'], 10, 8); |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @param $variation_path |
|
204 | + * @param EE_Messages_Template_Pack $template_pack |
|
205 | + * @param $messenger_name |
|
206 | + * @param $message_type_name |
|
207 | + * @param $url |
|
208 | + * @param $type |
|
209 | + * @param $variation |
|
210 | + * @param $skip_filters |
|
211 | + * @return string |
|
212 | + */ |
|
213 | + public function add_html_css( |
|
214 | + $variation_path, |
|
215 | + EE_Messages_Template_Pack $template_pack, |
|
216 | + $messenger_name, |
|
217 | + $message_type_name, |
|
218 | + $url, |
|
219 | + $type, |
|
220 | + $variation, |
|
221 | + $skip_filters |
|
222 | + ): string { |
|
223 | + return $template_pack->get_variation( |
|
224 | + $this->name, |
|
225 | + $message_type_name, |
|
226 | + $type, |
|
227 | + $variation, |
|
228 | + $url, |
|
229 | + '.css', |
|
230 | + $skip_filters |
|
231 | + ); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * Takes care of enqueuing any necessary scripts or styles for the page. A do_action() so message types using this |
|
237 | + * messenger can add their own js. |
|
238 | + * |
|
239 | + * @return void. |
|
240 | + */ |
|
241 | + public function enqueue_scripts_styles() |
|
242 | + { |
|
243 | + parent::enqueue_scripts_styles(); |
|
244 | + do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles'); |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * _set_template_fields |
|
250 | + * This sets up the fields that a messenger requires for the message to go out. |
|
251 | + * |
|
252 | + * @access protected |
|
253 | + * @return void |
|
254 | + */ |
|
255 | + protected function _set_template_fields() |
|
256 | + { |
|
257 | + // any extra template fields that are NOT used by the messenger |
|
258 | + // but will get used by a messenger field for shortcode replacement |
|
259 | + // get added to the 'extra' key in an associated array |
|
260 | + // indexed by the messenger field they relate to. |
|
261 | + // This is important for the Messages_admin to know what fields to display to the user. |
|
262 | + // Also, notice that the "values" are equal to the field type |
|
263 | + // that messages admin will use to know what kind of field to display. |
|
264 | + // The values ALSO have one index labeled "shortcode". |
|
265 | + // The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) |
|
266 | + // is required in order for this extra field to be displayed. |
|
267 | + // If the required shortcode isn't part of the shortcodes array |
|
268 | + // then the field is not needed and will not be displayed/parsed. |
|
269 | + $this->_template_fields = [ |
|
270 | + 'subject' => [ |
|
271 | + 'input' => 'text', |
|
272 | + 'label' => esc_html__('Page Title', 'event_espresso'), |
|
273 | + 'type' => 'string', |
|
274 | + 'required' => true, |
|
275 | + 'validation' => true, |
|
276 | + 'css_class' => 'large-text', |
|
277 | + 'format' => '%s', |
|
278 | + ], |
|
279 | + 'content' => '', |
|
280 | + // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
281 | + 'extra' => [ |
|
282 | + 'content' => [ |
|
283 | + 'main' => [ |
|
284 | + 'input' => 'wp_editor', |
|
285 | + 'label' => esc_html__('Main Content', 'event_espresso'), |
|
286 | + 'type' => 'string', |
|
287 | + 'required' => true, |
|
288 | + 'validation' => true, |
|
289 | + 'format' => '%s', |
|
290 | + 'rows' => '15', |
|
291 | + ], |
|
292 | + 'event_list' => [ |
|
293 | + 'input' => 'wp_editor', |
|
294 | + 'label' => '[EVENT_LIST]', |
|
295 | + 'type' => 'string', |
|
296 | + 'required' => true, |
|
297 | + 'validation' => true, |
|
298 | + 'format' => '%s', |
|
299 | + 'rows' => '15', |
|
300 | + 'shortcodes_required' => ['[EVENT_LIST]'], |
|
301 | + ], |
|
302 | + 'ticket_list' => [ |
|
303 | + 'input' => 'textarea', |
|
304 | + 'label' => '[TICKET_LIST]', |
|
305 | + 'type' => 'string', |
|
306 | + 'required' => true, |
|
307 | + 'validation' => true, |
|
308 | + 'format' => '%s', |
|
309 | + 'css_class' => 'large-text', |
|
310 | + 'rows' => '10', |
|
311 | + 'shortcodes_required' => ['[TICKET_LIST]'], |
|
312 | + ], |
|
313 | + 'ticket_line_item_no_pms' => [ |
|
314 | + 'input' => 'textarea', |
|
315 | + 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
316 | + 'Ticket Line Item List with no Price Modifiers', |
|
317 | + 'event_espresso' |
|
318 | + ), |
|
319 | + 'type' => 'string', |
|
320 | + 'required' => false, |
|
321 | + 'validation' => true, |
|
322 | + 'format' => '%s', |
|
323 | + 'css_class' => 'large-text', |
|
324 | + 'rows' => '5', |
|
325 | + 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
326 | + ], |
|
327 | + 'ticket_line_item_pms' => [ |
|
328 | + 'input' => 'textarea', |
|
329 | + 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
330 | + 'Ticket Line Item List with Price Modifiers', |
|
331 | + 'event_espresso' |
|
332 | + ), |
|
333 | + 'type' => 'string', |
|
334 | + 'required' => false, |
|
335 | + 'validation' => true, |
|
336 | + 'format' => '%s', |
|
337 | + 'css_class' => 'large-text', |
|
338 | + 'rows' => '5', |
|
339 | + 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
340 | + ], |
|
341 | + 'price_modifier_line_item_list' => [ |
|
342 | + 'input' => 'textarea', |
|
343 | + 'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
344 | + 'type' => 'string', |
|
345 | + 'required' => false, |
|
346 | + 'validation' => true, |
|
347 | + 'format' => '%s', |
|
348 | + 'css_class' => 'large-text', |
|
349 | + 'rows' => '5', |
|
350 | + 'shortcodes_required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'], |
|
351 | + ], |
|
352 | + 'datetime_list' => [ |
|
353 | + 'input' => 'textarea', |
|
354 | + 'label' => '[DATETIME_LIST]', |
|
355 | + 'type' => 'string', |
|
356 | + 'required' => true, |
|
357 | + 'validation' => true, |
|
358 | + 'format' => '%s', |
|
359 | + 'css_class' => 'large-text', |
|
360 | + 'rows' => '5', |
|
361 | + 'shortcodes_required' => ['[DATETIME_LIST]'], |
|
362 | + ], |
|
363 | + 'attendee_list' => [ |
|
364 | + 'input' => 'textarea', |
|
365 | + 'label' => '[ATTENDEE_LIST]', |
|
366 | + 'type' => 'string', |
|
367 | + 'required' => true, |
|
368 | + 'validation' => true, |
|
369 | + 'format' => '%s', |
|
370 | + 'css_class' => 'large-text', |
|
371 | + 'rows' => '5', |
|
372 | + 'shortcodes_required' => ['[ATTENDEE_LIST]'], |
|
373 | + ], |
|
374 | + 'tax_line_item_list' => [ |
|
375 | + 'input' => 'textarea', |
|
376 | + 'label' => '[TAX_LINE_ITEM_LIST]', |
|
377 | + 'type' => 'string', |
|
378 | + 'required' => false, |
|
379 | + 'validation' => true, |
|
380 | + 'format' => '%s', |
|
381 | + 'css_class' => 'large-text', |
|
382 | + 'rows' => '5', |
|
383 | + 'shortcodes_required' => ['[TAX_LINE_ITEM_LIST]'], |
|
384 | + ], |
|
385 | + 'additional_line_item_list' => [ |
|
386 | + 'input' => 'textarea', |
|
387 | + 'label' => '[ADDITIONAL_LINE_ITEM_LIST]', |
|
388 | + 'type' => 'string', |
|
389 | + 'required' => false, |
|
390 | + 'validation' => true, |
|
391 | + 'format' => '%s', |
|
392 | + 'css_class' => 'large-text', |
|
393 | + 'rows' => '5', |
|
394 | + 'shortcodes_required' => ['[ADDITIONAL_LINE_ITEM_LIST]'], |
|
395 | + ], |
|
396 | + 'payment_list' => [ |
|
397 | + 'input' => 'textarea', |
|
398 | + 'label' => '[PAYMENT_LIST]', |
|
399 | + 'type' => 'string', |
|
400 | + 'required' => true, |
|
401 | + 'validation' => true, |
|
402 | + 'format' => '%s', |
|
403 | + 'css_class' => 'large-text', |
|
404 | + 'rows' => '5', |
|
405 | + 'shortcodes_required' => ['[PAYMENT_LIST_*]'], |
|
406 | + ], |
|
407 | + ], |
|
408 | + ], |
|
409 | + ]; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * @see definition of this method in parent |
|
415 | + * @since 4.5.0 |
|
416 | + */ |
|
417 | + protected function _set_default_message_types() |
|
418 | + { |
|
419 | + $this->_default_message_types = ['receipt', 'invoice']; |
|
420 | + } |
|
421 | + |
|
422 | + |
|
423 | + /** |
|
424 | + * @see definition of this method in parent |
|
425 | + * @since 4.5.0 |
|
426 | + */ |
|
427 | + protected function _set_valid_message_types() |
|
428 | + { |
|
429 | + $this->_valid_message_types = ['receipt', 'invoice']; |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * Displays the message in the browser. |
|
435 | + * |
|
436 | + * @return void. |
|
437 | + * @since 4.5.0 |
|
438 | + */ |
|
439 | + protected function _send_message() |
|
440 | + { |
|
441 | + $this->_template_args = [ |
|
442 | + 'page_title' => $this->_subject, |
|
443 | + 'base_css' => $this->get_variation( |
|
444 | + $this->_tmp_pack, |
|
445 | + $this->_incoming_message_type->name, |
|
446 | + true, |
|
447 | + 'base', |
|
448 | + $this->_variation |
|
449 | + ), |
|
450 | + 'print_css' => $this->get_variation( |
|
451 | + $this->_tmp_pack, |
|
452 | + $this->_incoming_message_type->name, |
|
453 | + true, |
|
454 | + 'print', |
|
455 | + $this->_variation |
|
456 | + ), |
|
457 | + 'main_css' => $this->get_variation( |
|
458 | + $this->_tmp_pack, |
|
459 | + $this->_incoming_message_type->name, |
|
460 | + true, |
|
461 | + 'main', |
|
462 | + $this->_variation |
|
463 | + ), |
|
464 | + 'main_body' => wpautop( |
|
465 | + apply_filters( |
|
466 | + 'FHEE__EE_Html_messenger___send_message__main_body', |
|
467 | + $this->_content, |
|
468 | + $this->_content, |
|
469 | + $this->_incoming_message_type |
|
470 | + ) |
|
471 | + ), |
|
472 | + ]; |
|
473 | + $this->_deregister_wp_hooks(); |
|
474 | + add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_styles']); |
|
475 | + echo $this->_get_main_template(); // already escaped |
|
476 | + exit(); |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + /** |
|
481 | + * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't |
|
482 | + * interfere with our templates. If users want to add any custom styles or scripts they must use the |
|
483 | + * AHEE__EE_Html_messenger__enqueue_scripts_styles hook. |
|
484 | + * |
|
485 | + * @return void |
|
486 | + * @since 4.5.0 |
|
487 | + */ |
|
488 | + protected function _deregister_wp_hooks() |
|
489 | + { |
|
490 | + remove_all_actions('wp_head'); |
|
491 | + remove_all_actions('wp_footer'); |
|
492 | + remove_all_actions('wp_print_footer_scripts'); |
|
493 | + remove_all_actions('wp_enqueue_scripts'); |
|
494 | + global $wp_scripts, $wp_styles; |
|
495 | + $wp_scripts = $wp_styles = []; |
|
496 | + // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load. |
|
497 | + add_action('wp_footer', 'wp_print_footer_scripts'); |
|
498 | + add_action('wp_print_footer_scripts', '_wp_footer_scripts'); |
|
499 | + add_action('wp_head', 'wp_enqueue_scripts'); |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + /** |
|
504 | + * Overwrite parent _get_main_template for display_html purposes. |
|
505 | + * |
|
506 | + * @param bool $preview |
|
507 | + * @return string |
|
508 | + * @since 4.5.0 |
|
509 | + */ |
|
510 | + protected function _get_main_template($preview = false): string |
|
511 | + { |
|
512 | + $wrapper_template = $this->_tmp_pack->get_wrapper($this->name); |
|
513 | + // include message type as a template arg |
|
514 | + $this->_template_args['message_type'] = $this->_incoming_message_type; |
|
515 | + return EEH_Template::display_template($wrapper_template, $this->_template_args, true); |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * @return void |
|
521 | + */ |
|
522 | + protected function _preview() |
|
523 | + { |
|
524 | + $this->_send_message(); |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + protected function _set_admin_settings_fields() |
|
529 | + { |
|
530 | + } |
|
531 | + |
|
532 | + |
|
533 | + /** |
|
534 | + * add the "powered by EE" credit link to the HTML receipt and invoice |
|
535 | + * |
|
536 | + * @param string $content |
|
537 | + * @param string $content_again |
|
538 | + * @param EE_message_type $incoming_message_type |
|
539 | + * @return string |
|
540 | + */ |
|
541 | + public function add_powered_by_credit_link_to_receipt_and_invoice( |
|
542 | + string $content, |
|
543 | + string $content_again, |
|
544 | + EE_message_type $incoming_message_type |
|
545 | + ): string { |
|
546 | + if ( |
|
547 | + ($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt') |
|
548 | + && apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true) |
|
549 | + ) { |
|
550 | + $content .= EEH_Template::powered_by_event_espresso( |
|
551 | + 'aln-cntr', |
|
552 | + '', |
|
553 | + ['utm_content' => 'messages_system'] |
|
554 | + ) . EEH_HTML::div(EEH_HTML::p(' ')); |
|
555 | + } |
|
556 | + return $content; |
|
557 | + } |
|
558 | 558 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | 'This messenger outputs a message to a browser for display.', |
41 | 41 | 'event_espresso' |
42 | 42 | ); |
43 | - $this->label = [ |
|
43 | + $this->label = [ |
|
44 | 44 | 'singular' => esc_html__('html', 'event_espresso'), |
45 | 45 | 'plural' => esc_html__('html', 'event_espresso'), |
46 | 46 | ]; |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | ], |
313 | 313 | 'ticket_line_item_no_pms' => [ |
314 | 314 | 'input' => 'textarea', |
315 | - 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
315 | + 'label' => '[TICKET_LINE_ITEM_LIST] <br>'.esc_html__( |
|
316 | 316 | 'Ticket Line Item List with no Price Modifiers', |
317 | 317 | 'event_espresso' |
318 | 318 | ), |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | ], |
327 | 327 | 'ticket_line_item_pms' => [ |
328 | 328 | 'input' => 'textarea', |
329 | - 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
329 | + 'label' => '[TICKET_LINE_ITEM_LIST] <br>'.esc_html__( |
|
330 | 330 | 'Ticket Line Item List with Price Modifiers', |
331 | 331 | 'event_espresso' |
332 | 332 | ), |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | 'aln-cntr', |
552 | 552 | '', |
553 | 553 | ['utm_content' => 'messages_system'] |
554 | - ) . EEH_HTML::div(EEH_HTML::p(' ')); |
|
554 | + ).EEH_HTML::div(EEH_HTML::p(' ')); |
|
555 | 555 | } |
556 | 556 | return $content; |
557 | 557 | } |