@@ -12,549 +12,549 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Html_messenger extends EE_messenger |
14 | 14 | { |
15 | - /** |
|
16 | - * The following are the properties that this messenger requires for displaying the html |
|
17 | - */ |
|
18 | - /** |
|
19 | - * This is the html body generated by the template via the message type. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $_content = ''; |
|
24 | - |
|
25 | - /** |
|
26 | - * This is for the page title that gets displayed. (Why use "subject"? Because the "title" tag in html is |
|
27 | - * equivalent to the "subject" of the page. |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $_subject = ''; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * EE_Html_messenger constructor. |
|
36 | - */ |
|
37 | - public function __construct() |
|
38 | - { |
|
39 | - // set properties |
|
40 | - $this->name = 'html'; |
|
41 | - $this->description = esc_html__( |
|
42 | - 'This messenger outputs a message to a browser for display.', |
|
43 | - 'event_espresso' |
|
44 | - ); |
|
45 | - $this->label = [ |
|
46 | - 'singular' => esc_html__('html', 'event_espresso'), |
|
47 | - 'plural' => esc_html__('html', 'event_espresso'), |
|
48 | - ]; |
|
49 | - $this->activate_on_install = true; |
|
50 | - // add the "powered by EE" credit link to the HTML receipt and invoice |
|
51 | - add_filter( |
|
52 | - 'FHEE__EE_Html_messenger___send_message__main_body', |
|
53 | - [$this, 'add_powered_by_credit_link_to_receipt_and_invoice'], |
|
54 | - 10, |
|
55 | - 3 |
|
56 | - ); |
|
57 | - parent::__construct(); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * HTML Messenger desires execution immediately. |
|
63 | - * |
|
64 | - * @return bool |
|
65 | - * @since 4.9.0 |
|
66 | - * @see parent::send_now() for documentation. |
|
67 | - */ |
|
68 | - public function send_now(): bool |
|
69 | - { |
|
70 | - return true; |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * HTML Messenger allows an empty to field. |
|
76 | - * |
|
77 | - * @return bool |
|
78 | - * @since 4.9.0 |
|
79 | - * @see parent::allow_empty_to_field() for documentation |
|
80 | - */ |
|
81 | - public function allow_empty_to_field(): bool |
|
82 | - { |
|
83 | - return true; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @see abstract declaration in EE_messenger for details. |
|
89 | - */ |
|
90 | - protected function _set_admin_pages() |
|
91 | - { |
|
92 | - $this->admin_registered_pages = ['events_edit' => true]; |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @see abstract declaration in EE_messenger for details. |
|
98 | - */ |
|
99 | - protected function _set_valid_shortcodes() |
|
100 | - { |
|
101 | - $this->_valid_shortcodes = []; |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @see abstract declaration in EE_messenger for details. |
|
107 | - */ |
|
108 | - protected function _set_validator_config() |
|
109 | - { |
|
110 | - $this->_validator_config = [ |
|
111 | - 'subject' => [ |
|
112 | - 'shortcodes' => ['organization', 'primary_registration_details', 'email', 'transaction'], |
|
113 | - ], |
|
114 | - 'content' => [ |
|
115 | - 'shortcodes' => [ |
|
116 | - 'organization', |
|
117 | - 'primary_registration_list', |
|
118 | - 'primary_registration_details', |
|
119 | - 'email', |
|
120 | - 'transaction', |
|
121 | - 'event_list', |
|
122 | - 'payment_list', |
|
123 | - 'venue', |
|
124 | - 'line_item_list', |
|
125 | - 'messenger', |
|
126 | - 'ticket_list', |
|
127 | - ], |
|
128 | - ], |
|
129 | - 'event_list' => [ |
|
130 | - 'shortcodes' => [ |
|
131 | - 'event', |
|
132 | - 'ticket_list', |
|
133 | - 'venue', |
|
134 | - 'primary_registration_details', |
|
135 | - 'primary_registration_list', |
|
136 | - 'event_author', |
|
137 | - ], |
|
138 | - 'required' => ['[EVENT_LIST]'], |
|
139 | - ], |
|
140 | - 'ticket_list' => [ |
|
141 | - 'shortcodes' => [ |
|
142 | - 'attendee_list', |
|
143 | - 'ticket', |
|
144 | - 'datetime_list', |
|
145 | - 'primary_registration_details', |
|
146 | - 'line_item_list', |
|
147 | - 'venue', |
|
148 | - ], |
|
149 | - 'required' => ['[TICKET_LIST]'], |
|
150 | - ], |
|
151 | - 'ticket_line_item_no_pms' => [ |
|
152 | - 'shortcodes' => ['line_item', 'ticket'], |
|
153 | - 'required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
154 | - ], |
|
155 | - 'ticket_line_item_pms' => [ |
|
156 | - 'shortcodes' => ['line_item', 'ticket', 'line_item_list'], |
|
157 | - 'required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
158 | - ], |
|
159 | - 'price_modifier_line_item_list' => [ |
|
160 | - 'shortcodes' => ['line_item'], |
|
161 | - 'required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'], |
|
162 | - ], |
|
163 | - 'datetime_list' => [ |
|
164 | - 'shortcodes' => ['datetime'], |
|
165 | - 'required' => ['[DATETIME_LIST]'], |
|
166 | - ], |
|
167 | - 'attendee_list' => [ |
|
168 | - 'shortcodes' => ['attendee'], |
|
169 | - 'required' => ['[ATTENDEE_LIST]'], |
|
170 | - ], |
|
171 | - 'tax_line_item_list' => [ |
|
172 | - 'shortcodes' => ['line_item'], |
|
173 | - 'required' => ['[TAX_LINE_ITEM_LIST]'], |
|
174 | - ], |
|
175 | - 'additional_line_item_list' => [ |
|
176 | - 'shortcodes' => ['line_item'], |
|
177 | - 'required' => ['[ADDITIONAL_LINE_ITEM_LIST]'], |
|
178 | - ], |
|
179 | - 'payment_list' => [ |
|
180 | - 'shortcodes' => ['payment'], |
|
181 | - 'required' => ['[PAYMENT_LIST_*]'], |
|
182 | - ], |
|
183 | - ]; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger |
|
189 | - * is a different messenger. Child messengers can set hooks for the sending messenger to callback on if necessary |
|
190 | - * (i.e. swap out css files or something else). |
|
191 | - * |
|
192 | - * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed. |
|
193 | - * @return void |
|
194 | - * @since 4.5.0 |
|
195 | - */ |
|
196 | - public function do_secondary_messenger_hooks($sending_messenger_name) |
|
197 | - { |
|
198 | - if ($sending_messenger_name === 'pdf') { |
|
199 | - add_filter('EE_messenger__get_variation__variation', [$this, 'add_html_css'], 10, 8); |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * @param $variation_path |
|
206 | - * @param EE_Messages_Template_Pack $template_pack |
|
207 | - * @param $messenger_name |
|
208 | - * @param $message_type_name |
|
209 | - * @param $url |
|
210 | - * @param $type |
|
211 | - * @param $variation |
|
212 | - * @param $skip_filters |
|
213 | - * @return string |
|
214 | - */ |
|
215 | - public function add_html_css( |
|
216 | - $variation_path, |
|
217 | - EE_Messages_Template_Pack $template_pack, |
|
218 | - $messenger_name, |
|
219 | - $message_type_name, |
|
220 | - $url, |
|
221 | - $type, |
|
222 | - $variation, |
|
223 | - $skip_filters |
|
224 | - ): string { |
|
225 | - return $template_pack->get_variation( |
|
226 | - $this->name, |
|
227 | - $message_type_name, |
|
228 | - $type, |
|
229 | - $variation, |
|
230 | - $url, |
|
231 | - '.css', |
|
232 | - $skip_filters |
|
233 | - ); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * Takes care of enqueuing any necessary scripts or styles for the page. A do_action() so message types using this |
|
239 | - * messenger can add their own js. |
|
240 | - * |
|
241 | - * @return void. |
|
242 | - */ |
|
243 | - public function enqueue_scripts_styles() |
|
244 | - { |
|
245 | - parent::enqueue_scripts_styles(); |
|
246 | - do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles'); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * _set_template_fields |
|
252 | - * This sets up the fields that a messenger requires for the message to go out. |
|
253 | - * |
|
254 | - * @access protected |
|
255 | - * @return void |
|
256 | - */ |
|
257 | - protected function _set_template_fields() |
|
258 | - { |
|
259 | - // any extra template fields that are NOT used by the messenger |
|
260 | - // but will get used by a messenger field for shortcode replacement |
|
261 | - // get added to the 'extra' key in an associated array |
|
262 | - // indexed by the messenger field they relate to. |
|
263 | - // This is important for the Messages_admin to know what fields to display to the user. |
|
264 | - // Also, notice that the "values" are equal to the field type |
|
265 | - // that messages admin will use to know what kind of field to display. |
|
266 | - // The values ALSO have one index labeled "shortcode". |
|
267 | - // The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) |
|
268 | - // is required in order for this extra field to be displayed. |
|
269 | - // If the required shortcode isn't part of the shortcodes array |
|
270 | - // then the field is not needed and will not be displayed/parsed. |
|
271 | - $this->_template_fields = [ |
|
272 | - 'subject' => [ |
|
273 | - 'input' => 'text', |
|
274 | - 'label' => esc_html__('Page Title', 'event_espresso'), |
|
275 | - 'type' => 'string', |
|
276 | - 'required' => true, |
|
277 | - 'validation' => true, |
|
278 | - 'css_class' => 'large-text', |
|
279 | - 'format' => '%s', |
|
280 | - ], |
|
281 | - 'content' => '', |
|
282 | - // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
283 | - 'extra' => [ |
|
284 | - 'content' => [ |
|
285 | - 'main' => [ |
|
286 | - 'input' => 'wp_editor', |
|
287 | - 'label' => esc_html__('Main Content', 'event_espresso'), |
|
288 | - 'type' => 'string', |
|
289 | - 'required' => true, |
|
290 | - 'validation' => true, |
|
291 | - 'format' => '%s', |
|
292 | - 'rows' => '15', |
|
293 | - ], |
|
294 | - 'event_list' => [ |
|
295 | - 'input' => 'wp_editor', |
|
296 | - 'label' => '[EVENT_LIST]', |
|
297 | - 'type' => 'string', |
|
298 | - 'required' => true, |
|
299 | - 'validation' => true, |
|
300 | - 'format' => '%s', |
|
301 | - 'rows' => '15', |
|
302 | - 'shortcodes_required' => ['[EVENT_LIST]'], |
|
303 | - ], |
|
304 | - 'ticket_list' => [ |
|
305 | - 'input' => 'textarea', |
|
306 | - 'label' => '[TICKET_LIST]', |
|
307 | - 'type' => 'string', |
|
308 | - 'required' => true, |
|
309 | - 'validation' => true, |
|
310 | - 'format' => '%s', |
|
311 | - 'css_class' => 'large-text', |
|
312 | - 'rows' => '10', |
|
313 | - 'shortcodes_required' => ['[TICKET_LIST]'], |
|
314 | - ], |
|
315 | - 'ticket_line_item_no_pms' => [ |
|
316 | - 'input' => 'textarea', |
|
317 | - 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
318 | - 'Ticket Line Item List with no Price Modifiers', |
|
319 | - 'event_espresso' |
|
320 | - ), |
|
321 | - 'type' => 'string', |
|
322 | - 'required' => false, |
|
323 | - 'validation' => true, |
|
324 | - 'format' => '%s', |
|
325 | - 'css_class' => 'large-text', |
|
326 | - 'rows' => '5', |
|
327 | - 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
328 | - ], |
|
329 | - 'ticket_line_item_pms' => [ |
|
330 | - 'input' => 'textarea', |
|
331 | - 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
332 | - 'Ticket Line Item List with Price Modifiers', |
|
333 | - 'event_espresso' |
|
334 | - ), |
|
335 | - 'type' => 'string', |
|
336 | - 'required' => false, |
|
337 | - 'validation' => true, |
|
338 | - 'format' => '%s', |
|
339 | - 'css_class' => 'large-text', |
|
340 | - 'rows' => '5', |
|
341 | - 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
342 | - ], |
|
343 | - 'price_modifier_line_item_list' => [ |
|
344 | - 'input' => 'textarea', |
|
345 | - 'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
346 | - 'type' => 'string', |
|
347 | - 'required' => false, |
|
348 | - 'validation' => true, |
|
349 | - 'format' => '%s', |
|
350 | - 'css_class' => 'large-text', |
|
351 | - 'rows' => '5', |
|
352 | - 'shortcodes_required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'], |
|
353 | - ], |
|
354 | - 'datetime_list' => [ |
|
355 | - 'input' => 'textarea', |
|
356 | - 'label' => '[DATETIME_LIST]', |
|
357 | - 'type' => 'string', |
|
358 | - 'required' => true, |
|
359 | - 'validation' => true, |
|
360 | - 'format' => '%s', |
|
361 | - 'css_class' => 'large-text', |
|
362 | - 'rows' => '5', |
|
363 | - 'shortcodes_required' => ['[DATETIME_LIST]'], |
|
364 | - ], |
|
365 | - 'attendee_list' => [ |
|
366 | - 'input' => 'textarea', |
|
367 | - 'label' => '[ATTENDEE_LIST]', |
|
368 | - 'type' => 'string', |
|
369 | - 'required' => true, |
|
370 | - 'validation' => true, |
|
371 | - 'format' => '%s', |
|
372 | - 'css_class' => 'large-text', |
|
373 | - 'rows' => '5', |
|
374 | - 'shortcodes_required' => ['[ATTENDEE_LIST]'], |
|
375 | - ], |
|
376 | - 'tax_line_item_list' => [ |
|
377 | - 'input' => 'textarea', |
|
378 | - 'label' => '[TAX_LINE_ITEM_LIST]', |
|
379 | - 'type' => 'string', |
|
380 | - 'required' => false, |
|
381 | - 'validation' => true, |
|
382 | - 'format' => '%s', |
|
383 | - 'css_class' => 'large-text', |
|
384 | - 'rows' => '5', |
|
385 | - 'shortcodes_required' => ['[TAX_LINE_ITEM_LIST]'], |
|
386 | - ], |
|
387 | - 'additional_line_item_list' => [ |
|
388 | - 'input' => 'textarea', |
|
389 | - 'label' => '[ADDITIONAL_LINE_ITEM_LIST]', |
|
390 | - 'type' => 'string', |
|
391 | - 'required' => false, |
|
392 | - 'validation' => true, |
|
393 | - 'format' => '%s', |
|
394 | - 'css_class' => 'large-text', |
|
395 | - 'rows' => '5', |
|
396 | - 'shortcodes_required' => ['[ADDITIONAL_LINE_ITEM_LIST]'], |
|
397 | - ], |
|
398 | - 'payment_list' => [ |
|
399 | - 'input' => 'textarea', |
|
400 | - 'label' => '[PAYMENT_LIST]', |
|
401 | - 'type' => 'string', |
|
402 | - 'required' => true, |
|
403 | - 'validation' => true, |
|
404 | - 'format' => '%s', |
|
405 | - 'css_class' => 'large-text', |
|
406 | - 'rows' => '5', |
|
407 | - 'shortcodes_required' => ['[PAYMENT_LIST_*]'], |
|
408 | - ], |
|
409 | - ], |
|
410 | - ], |
|
411 | - ]; |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * @see definition of this method in parent |
|
417 | - * @since 4.5.0 |
|
418 | - */ |
|
419 | - protected function _set_default_message_types() |
|
420 | - { |
|
421 | - $this->_default_message_types = ['receipt', 'invoice']; |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - /** |
|
426 | - * @see definition of this method in parent |
|
427 | - * @since 4.5.0 |
|
428 | - */ |
|
429 | - protected function _set_valid_message_types() |
|
430 | - { |
|
431 | - $this->_valid_message_types = ['receipt', 'invoice']; |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * Displays the message in the browser. |
|
437 | - * |
|
438 | - * @return void. |
|
439 | - * @since 4.5.0 |
|
440 | - */ |
|
441 | - protected function _send_message() |
|
442 | - { |
|
443 | - $this->_template_args = [ |
|
444 | - 'page_title' => $this->_subject, |
|
445 | - 'base_css' => $this->get_variation( |
|
446 | - $this->_tmp_pack, |
|
447 | - $this->_incoming_message_type->name, |
|
448 | - true, |
|
449 | - 'base', |
|
450 | - $this->_variation |
|
451 | - ), |
|
452 | - 'print_css' => $this->get_variation( |
|
453 | - $this->_tmp_pack, |
|
454 | - $this->_incoming_message_type->name, |
|
455 | - true, |
|
456 | - 'print', |
|
457 | - $this->_variation |
|
458 | - ), |
|
459 | - 'main_css' => $this->get_variation( |
|
460 | - $this->_tmp_pack, |
|
461 | - $this->_incoming_message_type->name, |
|
462 | - true, |
|
463 | - 'main', |
|
464 | - $this->_variation |
|
465 | - ), |
|
466 | - 'main_body' => wpautop( |
|
467 | - apply_filters( |
|
468 | - 'FHEE__EE_Html_messenger___send_message__main_body', |
|
469 | - $this->_content, |
|
470 | - $this->_content, |
|
471 | - $this->_incoming_message_type |
|
472 | - ) |
|
473 | - ), |
|
474 | - ]; |
|
475 | - $this->_deregister_wp_hooks(); |
|
476 | - add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_styles']); |
|
477 | - echo '<!doctype html>' . wp_kses($this->_get_main_template(), AllowedTags::getWithFullTags()); |
|
478 | - exit(); |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't |
|
484 | - * interfere with our templates. If users want to add any custom styles or scripts they must use the |
|
485 | - * AHEE__EE_Html_messenger__enqueue_scripts_styles hook. |
|
486 | - * |
|
487 | - * @return void |
|
488 | - * @since 4.5.0 |
|
489 | - */ |
|
490 | - protected function _deregister_wp_hooks() |
|
491 | - { |
|
492 | - remove_all_actions('wp_head'); |
|
493 | - remove_all_actions('wp_footer'); |
|
494 | - remove_all_actions('wp_print_footer_scripts'); |
|
495 | - remove_all_actions('wp_enqueue_scripts'); |
|
496 | - global $wp_scripts, $wp_styles; |
|
497 | - $wp_scripts = $wp_styles = []; |
|
498 | - // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load. |
|
499 | - add_action('wp_footer', 'wp_print_footer_scripts'); |
|
500 | - add_action('wp_print_footer_scripts', '_wp_footer_scripts'); |
|
501 | - add_action('wp_head', 'wp_enqueue_scripts'); |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - /** |
|
506 | - * Overwrite parent _get_main_template for display_html purposes. |
|
507 | - * |
|
508 | - * @param bool $preview |
|
509 | - * @return string |
|
510 | - * @since 4.5.0 |
|
511 | - */ |
|
512 | - protected function _get_main_template($preview = false): string |
|
513 | - { |
|
514 | - $wrapper_template = $this->_tmp_pack->get_wrapper($this->name); |
|
515 | - // include message type as a template arg |
|
516 | - $this->_template_args['message_type'] = $this->_incoming_message_type; |
|
517 | - return EEH_Template::display_template($wrapper_template, $this->_template_args, true); |
|
518 | - } |
|
519 | - |
|
520 | - |
|
521 | - /** |
|
522 | - * @return void |
|
523 | - */ |
|
524 | - protected function _preview() |
|
525 | - { |
|
526 | - $this->_send_message(); |
|
527 | - } |
|
528 | - |
|
529 | - |
|
530 | - protected function _set_admin_settings_fields() |
|
531 | - { |
|
532 | - } |
|
533 | - |
|
534 | - |
|
535 | - /** |
|
536 | - * add the "powered by EE" credit link to the HTML receipt and invoice |
|
537 | - * |
|
538 | - * @param string $content |
|
539 | - * @param string $content_again |
|
540 | - * @param EE_message_type $incoming_message_type |
|
541 | - * @return string |
|
542 | - */ |
|
543 | - public function add_powered_by_credit_link_to_receipt_and_invoice( |
|
544 | - string $content, |
|
545 | - string $content_again, |
|
546 | - EE_message_type $incoming_message_type |
|
547 | - ): string { |
|
548 | - if ( |
|
549 | - ($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt') |
|
550 | - && apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true) |
|
551 | - ) { |
|
552 | - $content .= EEH_Template::powered_by_event_espresso( |
|
553 | - 'aln-cntr', |
|
554 | - '', |
|
555 | - ['utm_content' => 'messages_system'] |
|
556 | - ) . EEH_HTML::div(EEH_HTML::p(' ')); |
|
557 | - } |
|
558 | - return $content; |
|
559 | - } |
|
15 | + /** |
|
16 | + * The following are the properties that this messenger requires for displaying the html |
|
17 | + */ |
|
18 | + /** |
|
19 | + * This is the html body generated by the template via the message type. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $_content = ''; |
|
24 | + |
|
25 | + /** |
|
26 | + * This is for the page title that gets displayed. (Why use "subject"? Because the "title" tag in html is |
|
27 | + * equivalent to the "subject" of the page. |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $_subject = ''; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * EE_Html_messenger constructor. |
|
36 | + */ |
|
37 | + public function __construct() |
|
38 | + { |
|
39 | + // set properties |
|
40 | + $this->name = 'html'; |
|
41 | + $this->description = esc_html__( |
|
42 | + 'This messenger outputs a message to a browser for display.', |
|
43 | + 'event_espresso' |
|
44 | + ); |
|
45 | + $this->label = [ |
|
46 | + 'singular' => esc_html__('html', 'event_espresso'), |
|
47 | + 'plural' => esc_html__('html', 'event_espresso'), |
|
48 | + ]; |
|
49 | + $this->activate_on_install = true; |
|
50 | + // add the "powered by EE" credit link to the HTML receipt and invoice |
|
51 | + add_filter( |
|
52 | + 'FHEE__EE_Html_messenger___send_message__main_body', |
|
53 | + [$this, 'add_powered_by_credit_link_to_receipt_and_invoice'], |
|
54 | + 10, |
|
55 | + 3 |
|
56 | + ); |
|
57 | + parent::__construct(); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * HTML Messenger desires execution immediately. |
|
63 | + * |
|
64 | + * @return bool |
|
65 | + * @since 4.9.0 |
|
66 | + * @see parent::send_now() for documentation. |
|
67 | + */ |
|
68 | + public function send_now(): bool |
|
69 | + { |
|
70 | + return true; |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * HTML Messenger allows an empty to field. |
|
76 | + * |
|
77 | + * @return bool |
|
78 | + * @since 4.9.0 |
|
79 | + * @see parent::allow_empty_to_field() for documentation |
|
80 | + */ |
|
81 | + public function allow_empty_to_field(): bool |
|
82 | + { |
|
83 | + return true; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @see abstract declaration in EE_messenger for details. |
|
89 | + */ |
|
90 | + protected function _set_admin_pages() |
|
91 | + { |
|
92 | + $this->admin_registered_pages = ['events_edit' => true]; |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @see abstract declaration in EE_messenger for details. |
|
98 | + */ |
|
99 | + protected function _set_valid_shortcodes() |
|
100 | + { |
|
101 | + $this->_valid_shortcodes = []; |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @see abstract declaration in EE_messenger for details. |
|
107 | + */ |
|
108 | + protected function _set_validator_config() |
|
109 | + { |
|
110 | + $this->_validator_config = [ |
|
111 | + 'subject' => [ |
|
112 | + 'shortcodes' => ['organization', 'primary_registration_details', 'email', 'transaction'], |
|
113 | + ], |
|
114 | + 'content' => [ |
|
115 | + 'shortcodes' => [ |
|
116 | + 'organization', |
|
117 | + 'primary_registration_list', |
|
118 | + 'primary_registration_details', |
|
119 | + 'email', |
|
120 | + 'transaction', |
|
121 | + 'event_list', |
|
122 | + 'payment_list', |
|
123 | + 'venue', |
|
124 | + 'line_item_list', |
|
125 | + 'messenger', |
|
126 | + 'ticket_list', |
|
127 | + ], |
|
128 | + ], |
|
129 | + 'event_list' => [ |
|
130 | + 'shortcodes' => [ |
|
131 | + 'event', |
|
132 | + 'ticket_list', |
|
133 | + 'venue', |
|
134 | + 'primary_registration_details', |
|
135 | + 'primary_registration_list', |
|
136 | + 'event_author', |
|
137 | + ], |
|
138 | + 'required' => ['[EVENT_LIST]'], |
|
139 | + ], |
|
140 | + 'ticket_list' => [ |
|
141 | + 'shortcodes' => [ |
|
142 | + 'attendee_list', |
|
143 | + 'ticket', |
|
144 | + 'datetime_list', |
|
145 | + 'primary_registration_details', |
|
146 | + 'line_item_list', |
|
147 | + 'venue', |
|
148 | + ], |
|
149 | + 'required' => ['[TICKET_LIST]'], |
|
150 | + ], |
|
151 | + 'ticket_line_item_no_pms' => [ |
|
152 | + 'shortcodes' => ['line_item', 'ticket'], |
|
153 | + 'required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
154 | + ], |
|
155 | + 'ticket_line_item_pms' => [ |
|
156 | + 'shortcodes' => ['line_item', 'ticket', 'line_item_list'], |
|
157 | + 'required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
158 | + ], |
|
159 | + 'price_modifier_line_item_list' => [ |
|
160 | + 'shortcodes' => ['line_item'], |
|
161 | + 'required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'], |
|
162 | + ], |
|
163 | + 'datetime_list' => [ |
|
164 | + 'shortcodes' => ['datetime'], |
|
165 | + 'required' => ['[DATETIME_LIST]'], |
|
166 | + ], |
|
167 | + 'attendee_list' => [ |
|
168 | + 'shortcodes' => ['attendee'], |
|
169 | + 'required' => ['[ATTENDEE_LIST]'], |
|
170 | + ], |
|
171 | + 'tax_line_item_list' => [ |
|
172 | + 'shortcodes' => ['line_item'], |
|
173 | + 'required' => ['[TAX_LINE_ITEM_LIST]'], |
|
174 | + ], |
|
175 | + 'additional_line_item_list' => [ |
|
176 | + 'shortcodes' => ['line_item'], |
|
177 | + 'required' => ['[ADDITIONAL_LINE_ITEM_LIST]'], |
|
178 | + ], |
|
179 | + 'payment_list' => [ |
|
180 | + 'shortcodes' => ['payment'], |
|
181 | + 'required' => ['[PAYMENT_LIST_*]'], |
|
182 | + ], |
|
183 | + ]; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger |
|
189 | + * is a different messenger. Child messengers can set hooks for the sending messenger to callback on if necessary |
|
190 | + * (i.e. swap out css files or something else). |
|
191 | + * |
|
192 | + * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed. |
|
193 | + * @return void |
|
194 | + * @since 4.5.0 |
|
195 | + */ |
|
196 | + public function do_secondary_messenger_hooks($sending_messenger_name) |
|
197 | + { |
|
198 | + if ($sending_messenger_name === 'pdf') { |
|
199 | + add_filter('EE_messenger__get_variation__variation', [$this, 'add_html_css'], 10, 8); |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * @param $variation_path |
|
206 | + * @param EE_Messages_Template_Pack $template_pack |
|
207 | + * @param $messenger_name |
|
208 | + * @param $message_type_name |
|
209 | + * @param $url |
|
210 | + * @param $type |
|
211 | + * @param $variation |
|
212 | + * @param $skip_filters |
|
213 | + * @return string |
|
214 | + */ |
|
215 | + public function add_html_css( |
|
216 | + $variation_path, |
|
217 | + EE_Messages_Template_Pack $template_pack, |
|
218 | + $messenger_name, |
|
219 | + $message_type_name, |
|
220 | + $url, |
|
221 | + $type, |
|
222 | + $variation, |
|
223 | + $skip_filters |
|
224 | + ): string { |
|
225 | + return $template_pack->get_variation( |
|
226 | + $this->name, |
|
227 | + $message_type_name, |
|
228 | + $type, |
|
229 | + $variation, |
|
230 | + $url, |
|
231 | + '.css', |
|
232 | + $skip_filters |
|
233 | + ); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * Takes care of enqueuing any necessary scripts or styles for the page. A do_action() so message types using this |
|
239 | + * messenger can add their own js. |
|
240 | + * |
|
241 | + * @return void. |
|
242 | + */ |
|
243 | + public function enqueue_scripts_styles() |
|
244 | + { |
|
245 | + parent::enqueue_scripts_styles(); |
|
246 | + do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles'); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * _set_template_fields |
|
252 | + * This sets up the fields that a messenger requires for the message to go out. |
|
253 | + * |
|
254 | + * @access protected |
|
255 | + * @return void |
|
256 | + */ |
|
257 | + protected function _set_template_fields() |
|
258 | + { |
|
259 | + // any extra template fields that are NOT used by the messenger |
|
260 | + // but will get used by a messenger field for shortcode replacement |
|
261 | + // get added to the 'extra' key in an associated array |
|
262 | + // indexed by the messenger field they relate to. |
|
263 | + // This is important for the Messages_admin to know what fields to display to the user. |
|
264 | + // Also, notice that the "values" are equal to the field type |
|
265 | + // that messages admin will use to know what kind of field to display. |
|
266 | + // The values ALSO have one index labeled "shortcode". |
|
267 | + // The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) |
|
268 | + // is required in order for this extra field to be displayed. |
|
269 | + // If the required shortcode isn't part of the shortcodes array |
|
270 | + // then the field is not needed and will not be displayed/parsed. |
|
271 | + $this->_template_fields = [ |
|
272 | + 'subject' => [ |
|
273 | + 'input' => 'text', |
|
274 | + 'label' => esc_html__('Page Title', 'event_espresso'), |
|
275 | + 'type' => 'string', |
|
276 | + 'required' => true, |
|
277 | + 'validation' => true, |
|
278 | + 'css_class' => 'large-text', |
|
279 | + 'format' => '%s', |
|
280 | + ], |
|
281 | + 'content' => '', |
|
282 | + // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
283 | + 'extra' => [ |
|
284 | + 'content' => [ |
|
285 | + 'main' => [ |
|
286 | + 'input' => 'wp_editor', |
|
287 | + 'label' => esc_html__('Main Content', 'event_espresso'), |
|
288 | + 'type' => 'string', |
|
289 | + 'required' => true, |
|
290 | + 'validation' => true, |
|
291 | + 'format' => '%s', |
|
292 | + 'rows' => '15', |
|
293 | + ], |
|
294 | + 'event_list' => [ |
|
295 | + 'input' => 'wp_editor', |
|
296 | + 'label' => '[EVENT_LIST]', |
|
297 | + 'type' => 'string', |
|
298 | + 'required' => true, |
|
299 | + 'validation' => true, |
|
300 | + 'format' => '%s', |
|
301 | + 'rows' => '15', |
|
302 | + 'shortcodes_required' => ['[EVENT_LIST]'], |
|
303 | + ], |
|
304 | + 'ticket_list' => [ |
|
305 | + 'input' => 'textarea', |
|
306 | + 'label' => '[TICKET_LIST]', |
|
307 | + 'type' => 'string', |
|
308 | + 'required' => true, |
|
309 | + 'validation' => true, |
|
310 | + 'format' => '%s', |
|
311 | + 'css_class' => 'large-text', |
|
312 | + 'rows' => '10', |
|
313 | + 'shortcodes_required' => ['[TICKET_LIST]'], |
|
314 | + ], |
|
315 | + 'ticket_line_item_no_pms' => [ |
|
316 | + 'input' => 'textarea', |
|
317 | + 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
318 | + 'Ticket Line Item List with no Price Modifiers', |
|
319 | + 'event_espresso' |
|
320 | + ), |
|
321 | + 'type' => 'string', |
|
322 | + 'required' => false, |
|
323 | + 'validation' => true, |
|
324 | + 'format' => '%s', |
|
325 | + 'css_class' => 'large-text', |
|
326 | + 'rows' => '5', |
|
327 | + 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
328 | + ], |
|
329 | + 'ticket_line_item_pms' => [ |
|
330 | + 'input' => 'textarea', |
|
331 | + 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
332 | + 'Ticket Line Item List with Price Modifiers', |
|
333 | + 'event_espresso' |
|
334 | + ), |
|
335 | + 'type' => 'string', |
|
336 | + 'required' => false, |
|
337 | + 'validation' => true, |
|
338 | + 'format' => '%s', |
|
339 | + 'css_class' => 'large-text', |
|
340 | + 'rows' => '5', |
|
341 | + 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'], |
|
342 | + ], |
|
343 | + 'price_modifier_line_item_list' => [ |
|
344 | + 'input' => 'textarea', |
|
345 | + 'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]', |
|
346 | + 'type' => 'string', |
|
347 | + 'required' => false, |
|
348 | + 'validation' => true, |
|
349 | + 'format' => '%s', |
|
350 | + 'css_class' => 'large-text', |
|
351 | + 'rows' => '5', |
|
352 | + 'shortcodes_required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'], |
|
353 | + ], |
|
354 | + 'datetime_list' => [ |
|
355 | + 'input' => 'textarea', |
|
356 | + 'label' => '[DATETIME_LIST]', |
|
357 | + 'type' => 'string', |
|
358 | + 'required' => true, |
|
359 | + 'validation' => true, |
|
360 | + 'format' => '%s', |
|
361 | + 'css_class' => 'large-text', |
|
362 | + 'rows' => '5', |
|
363 | + 'shortcodes_required' => ['[DATETIME_LIST]'], |
|
364 | + ], |
|
365 | + 'attendee_list' => [ |
|
366 | + 'input' => 'textarea', |
|
367 | + 'label' => '[ATTENDEE_LIST]', |
|
368 | + 'type' => 'string', |
|
369 | + 'required' => true, |
|
370 | + 'validation' => true, |
|
371 | + 'format' => '%s', |
|
372 | + 'css_class' => 'large-text', |
|
373 | + 'rows' => '5', |
|
374 | + 'shortcodes_required' => ['[ATTENDEE_LIST]'], |
|
375 | + ], |
|
376 | + 'tax_line_item_list' => [ |
|
377 | + 'input' => 'textarea', |
|
378 | + 'label' => '[TAX_LINE_ITEM_LIST]', |
|
379 | + 'type' => 'string', |
|
380 | + 'required' => false, |
|
381 | + 'validation' => true, |
|
382 | + 'format' => '%s', |
|
383 | + 'css_class' => 'large-text', |
|
384 | + 'rows' => '5', |
|
385 | + 'shortcodes_required' => ['[TAX_LINE_ITEM_LIST]'], |
|
386 | + ], |
|
387 | + 'additional_line_item_list' => [ |
|
388 | + 'input' => 'textarea', |
|
389 | + 'label' => '[ADDITIONAL_LINE_ITEM_LIST]', |
|
390 | + 'type' => 'string', |
|
391 | + 'required' => false, |
|
392 | + 'validation' => true, |
|
393 | + 'format' => '%s', |
|
394 | + 'css_class' => 'large-text', |
|
395 | + 'rows' => '5', |
|
396 | + 'shortcodes_required' => ['[ADDITIONAL_LINE_ITEM_LIST]'], |
|
397 | + ], |
|
398 | + 'payment_list' => [ |
|
399 | + 'input' => 'textarea', |
|
400 | + 'label' => '[PAYMENT_LIST]', |
|
401 | + 'type' => 'string', |
|
402 | + 'required' => true, |
|
403 | + 'validation' => true, |
|
404 | + 'format' => '%s', |
|
405 | + 'css_class' => 'large-text', |
|
406 | + 'rows' => '5', |
|
407 | + 'shortcodes_required' => ['[PAYMENT_LIST_*]'], |
|
408 | + ], |
|
409 | + ], |
|
410 | + ], |
|
411 | + ]; |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * @see definition of this method in parent |
|
417 | + * @since 4.5.0 |
|
418 | + */ |
|
419 | + protected function _set_default_message_types() |
|
420 | + { |
|
421 | + $this->_default_message_types = ['receipt', 'invoice']; |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + /** |
|
426 | + * @see definition of this method in parent |
|
427 | + * @since 4.5.0 |
|
428 | + */ |
|
429 | + protected function _set_valid_message_types() |
|
430 | + { |
|
431 | + $this->_valid_message_types = ['receipt', 'invoice']; |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * Displays the message in the browser. |
|
437 | + * |
|
438 | + * @return void. |
|
439 | + * @since 4.5.0 |
|
440 | + */ |
|
441 | + protected function _send_message() |
|
442 | + { |
|
443 | + $this->_template_args = [ |
|
444 | + 'page_title' => $this->_subject, |
|
445 | + 'base_css' => $this->get_variation( |
|
446 | + $this->_tmp_pack, |
|
447 | + $this->_incoming_message_type->name, |
|
448 | + true, |
|
449 | + 'base', |
|
450 | + $this->_variation |
|
451 | + ), |
|
452 | + 'print_css' => $this->get_variation( |
|
453 | + $this->_tmp_pack, |
|
454 | + $this->_incoming_message_type->name, |
|
455 | + true, |
|
456 | + 'print', |
|
457 | + $this->_variation |
|
458 | + ), |
|
459 | + 'main_css' => $this->get_variation( |
|
460 | + $this->_tmp_pack, |
|
461 | + $this->_incoming_message_type->name, |
|
462 | + true, |
|
463 | + 'main', |
|
464 | + $this->_variation |
|
465 | + ), |
|
466 | + 'main_body' => wpautop( |
|
467 | + apply_filters( |
|
468 | + 'FHEE__EE_Html_messenger___send_message__main_body', |
|
469 | + $this->_content, |
|
470 | + $this->_content, |
|
471 | + $this->_incoming_message_type |
|
472 | + ) |
|
473 | + ), |
|
474 | + ]; |
|
475 | + $this->_deregister_wp_hooks(); |
|
476 | + add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_styles']); |
|
477 | + echo '<!doctype html>' . wp_kses($this->_get_main_template(), AllowedTags::getWithFullTags()); |
|
478 | + exit(); |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't |
|
484 | + * interfere with our templates. If users want to add any custom styles or scripts they must use the |
|
485 | + * AHEE__EE_Html_messenger__enqueue_scripts_styles hook. |
|
486 | + * |
|
487 | + * @return void |
|
488 | + * @since 4.5.0 |
|
489 | + */ |
|
490 | + protected function _deregister_wp_hooks() |
|
491 | + { |
|
492 | + remove_all_actions('wp_head'); |
|
493 | + remove_all_actions('wp_footer'); |
|
494 | + remove_all_actions('wp_print_footer_scripts'); |
|
495 | + remove_all_actions('wp_enqueue_scripts'); |
|
496 | + global $wp_scripts, $wp_styles; |
|
497 | + $wp_scripts = $wp_styles = []; |
|
498 | + // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load. |
|
499 | + add_action('wp_footer', 'wp_print_footer_scripts'); |
|
500 | + add_action('wp_print_footer_scripts', '_wp_footer_scripts'); |
|
501 | + add_action('wp_head', 'wp_enqueue_scripts'); |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + /** |
|
506 | + * Overwrite parent _get_main_template for display_html purposes. |
|
507 | + * |
|
508 | + * @param bool $preview |
|
509 | + * @return string |
|
510 | + * @since 4.5.0 |
|
511 | + */ |
|
512 | + protected function _get_main_template($preview = false): string |
|
513 | + { |
|
514 | + $wrapper_template = $this->_tmp_pack->get_wrapper($this->name); |
|
515 | + // include message type as a template arg |
|
516 | + $this->_template_args['message_type'] = $this->_incoming_message_type; |
|
517 | + return EEH_Template::display_template($wrapper_template, $this->_template_args, true); |
|
518 | + } |
|
519 | + |
|
520 | + |
|
521 | + /** |
|
522 | + * @return void |
|
523 | + */ |
|
524 | + protected function _preview() |
|
525 | + { |
|
526 | + $this->_send_message(); |
|
527 | + } |
|
528 | + |
|
529 | + |
|
530 | + protected function _set_admin_settings_fields() |
|
531 | + { |
|
532 | + } |
|
533 | + |
|
534 | + |
|
535 | + /** |
|
536 | + * add the "powered by EE" credit link to the HTML receipt and invoice |
|
537 | + * |
|
538 | + * @param string $content |
|
539 | + * @param string $content_again |
|
540 | + * @param EE_message_type $incoming_message_type |
|
541 | + * @return string |
|
542 | + */ |
|
543 | + public function add_powered_by_credit_link_to_receipt_and_invoice( |
|
544 | + string $content, |
|
545 | + string $content_again, |
|
546 | + EE_message_type $incoming_message_type |
|
547 | + ): string { |
|
548 | + if ( |
|
549 | + ($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt') |
|
550 | + && apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true) |
|
551 | + ) { |
|
552 | + $content .= EEH_Template::powered_by_event_espresso( |
|
553 | + 'aln-cntr', |
|
554 | + '', |
|
555 | + ['utm_content' => 'messages_system'] |
|
556 | + ) . EEH_HTML::div(EEH_HTML::p(' ')); |
|
557 | + } |
|
558 | + return $content; |
|
559 | + } |
|
560 | 560 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | 'This messenger outputs a message to a browser for display.', |
43 | 43 | 'event_espresso' |
44 | 44 | ); |
45 | - $this->label = [ |
|
45 | + $this->label = [ |
|
46 | 46 | 'singular' => esc_html__('html', 'event_espresso'), |
47 | 47 | 'plural' => esc_html__('html', 'event_espresso'), |
48 | 48 | ]; |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | ], |
315 | 315 | 'ticket_line_item_no_pms' => [ |
316 | 316 | 'input' => 'textarea', |
317 | - 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
317 | + 'label' => '[TICKET_LINE_ITEM_LIST] <br>'.esc_html__( |
|
318 | 318 | 'Ticket Line Item List with no Price Modifiers', |
319 | 319 | 'event_espresso' |
320 | 320 | ), |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | ], |
329 | 329 | 'ticket_line_item_pms' => [ |
330 | 330 | 'input' => 'textarea', |
331 | - 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__( |
|
331 | + 'label' => '[TICKET_LINE_ITEM_LIST] <br>'.esc_html__( |
|
332 | 332 | 'Ticket Line Item List with Price Modifiers', |
333 | 333 | 'event_espresso' |
334 | 334 | ), |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | ]; |
475 | 475 | $this->_deregister_wp_hooks(); |
476 | 476 | add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_styles']); |
477 | - echo '<!doctype html>' . wp_kses($this->_get_main_template(), AllowedTags::getWithFullTags()); |
|
477 | + echo '<!doctype html>'.wp_kses($this->_get_main_template(), AllowedTags::getWithFullTags()); |
|
478 | 478 | exit(); |
479 | 479 | } |
480 | 480 | |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | 'aln-cntr', |
554 | 554 | '', |
555 | 555 | ['utm_content' => 'messages_system'] |
556 | - ) . EEH_HTML::div(EEH_HTML::p(' ')); |
|
556 | + ).EEH_HTML::div(EEH_HTML::p(' ')); |
|
557 | 557 | } |
558 | 558 | return $content; |
559 | 559 | } |
@@ -11,566 +11,566 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Venue extends EE_CPT_Base implements AddressInterface |
13 | 13 | { |
14 | - /** |
|
15 | - * |
|
16 | - * @param array $props_n_values incoming values |
|
17 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
18 | - * used.) |
|
19 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
20 | - * date_format and the second value is the time format |
|
21 | - * @return EE_Attendee |
|
22 | - */ |
|
23 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
24 | - { |
|
25 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
26 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
27 | - } |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * @param array $props_n_values incoming values from the database |
|
32 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
33 | - * the website will be used. |
|
34 | - * @return EE_Attendee |
|
35 | - */ |
|
36 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
37 | - { |
|
38 | - return new self($props_n_values, true, $timezone); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * Gets name |
|
44 | - * |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function name() |
|
48 | - { |
|
49 | - return $this->get('VNU_name'); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * Gets phone |
|
55 | - * |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function phone() |
|
59 | - { |
|
60 | - return $this->get('VNU_phone'); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * venue_url |
|
66 | - * |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function venue_url() |
|
70 | - { |
|
71 | - return $this->get('VNU_url'); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * Gets desc |
|
77 | - * |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public function description() |
|
81 | - { |
|
82 | - return $this->get('VNU_desc'); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * Gets short description (AKA: the excerpt) |
|
88 | - * |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function excerpt() |
|
92 | - { |
|
93 | - return $this->get('VNU_short_desc'); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * Gets identifier |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function identifier() |
|
103 | - { |
|
104 | - return $this->get('VNU_identifier'); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Gets address |
|
110 | - * |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function address(): string |
|
114 | - { |
|
115 | - return $this->get('VNU_address'); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Gets address2 |
|
121 | - * |
|
122 | - * @return string |
|
123 | - */ |
|
124 | - public function address2(): string |
|
125 | - { |
|
126 | - return $this->get('VNU_address2'); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Gets city |
|
132 | - * |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - public function city(): string |
|
136 | - { |
|
137 | - return $this->get('VNU_city'); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Gets state |
|
142 | - * |
|
143 | - * @return int |
|
144 | - */ |
|
145 | - public function state_ID(): int |
|
146 | - { |
|
147 | - return $this->get('STA_ID'); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @return string |
|
153 | - */ |
|
154 | - public function state_abbrev(): string |
|
155 | - { |
|
156 | - return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @return string |
|
162 | - */ |
|
163 | - public function state_name(): string |
|
164 | - { |
|
165 | - return $this->state_obj() instanceof EE_State ? $this->state_obj()->name() : ''; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * Gets the state for this venue |
|
171 | - * |
|
172 | - * @return EE_State|null |
|
173 | - */ |
|
174 | - public function state_obj(): ?EE_State |
|
175 | - { |
|
176 | - return $this->get_first_related('State'); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * either displays the state abbreviation or the state name, as determined |
|
182 | - * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
183 | - * defaults to abbreviation |
|
184 | - * |
|
185 | - * @return string |
|
186 | - */ |
|
187 | - public function state(): string |
|
188 | - { |
|
189 | - if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
190 | - return $this->state_abbrev(); |
|
191 | - } else { |
|
192 | - return $this->state_name(); |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * country_ID |
|
199 | - * |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public function country_ID(): string |
|
203 | - { |
|
204 | - return $this->get('CNT_ISO'); |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * @return string |
|
210 | - */ |
|
211 | - public function country_name(): string |
|
212 | - { |
|
213 | - return $this->country_obj() instanceof EE_Country ? $this->country_obj()->name() : ''; |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * Gets the country of this venue |
|
219 | - * |
|
220 | - * @return EE_Country|null |
|
221 | - */ |
|
222 | - public function country_obj(): ?EE_Country |
|
223 | - { |
|
224 | - return $this->get_first_related('Country'); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * either displays the country ISO2 code or the country name, as determined |
|
230 | - * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
231 | - * defaults to abbreviation |
|
232 | - * |
|
233 | - * @return string |
|
234 | - */ |
|
235 | - public function country(): string |
|
236 | - { |
|
237 | - if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
238 | - return $this->country_ID(); |
|
239 | - } else { |
|
240 | - return $this->country_name(); |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * Gets zip |
|
247 | - * |
|
248 | - * @return string |
|
249 | - */ |
|
250 | - public function zip(): string |
|
251 | - { |
|
252 | - return $this->get('VNU_zip'); |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * Gets capacity |
|
258 | - * |
|
259 | - * @return int|string |
|
260 | - * @throws EE_Error |
|
261 | - * @throws ReflectionException |
|
262 | - */ |
|
263 | - public function capacity() |
|
264 | - { |
|
265 | - return $this->get_pretty('VNU_capacity', 'symbol'); |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * Gets created |
|
271 | - * |
|
272 | - * @return string |
|
273 | - */ |
|
274 | - public function created() |
|
275 | - { |
|
276 | - return $this->get('VNU_created'); |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * Gets modified |
|
282 | - * |
|
283 | - * @return string |
|
284 | - */ |
|
285 | - public function modified() |
|
286 | - { |
|
287 | - return $this->get('VNU_modified'); |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * Gets order |
|
293 | - * |
|
294 | - * @return int |
|
295 | - */ |
|
296 | - public function order() |
|
297 | - { |
|
298 | - return $this->get('VNU_order'); |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * Gets wp_user |
|
304 | - * |
|
305 | - * @return int |
|
306 | - */ |
|
307 | - public function wp_user() |
|
308 | - { |
|
309 | - return $this->get('VNU_wp_user'); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * @return string |
|
315 | - */ |
|
316 | - public function virtual_phone() |
|
317 | - { |
|
318 | - return $this->get('VNU_virtual_phone'); |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * @return string |
|
324 | - */ |
|
325 | - public function virtual_url() |
|
326 | - { |
|
327 | - return $this->get('VNU_virtual_url'); |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * @return bool |
|
333 | - */ |
|
334 | - public function enable_for_gmap() |
|
335 | - { |
|
336 | - return $this->get('VNU_enable_for_gmap'); |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * @return string |
|
342 | - */ |
|
343 | - public function google_map_link() |
|
344 | - { |
|
345 | - return $this->get('VNU_google_map_link'); |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * Gets all events happening at this venue. Query parameters can be added to |
|
351 | - * fetch a subset of those events. |
|
352 | - * |
|
353 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
354 | - * @param bool $upcoming |
|
355 | - * @return EE_Event[] |
|
356 | - */ |
|
357 | - public function events($query_params = array(), $upcoming = false) |
|
358 | - { |
|
359 | - if ($upcoming) { |
|
360 | - $query_params = array( |
|
361 | - array( |
|
362 | - 'status' => 'publish', |
|
363 | - 'Datetime.DTT_EVT_start' => array( |
|
364 | - '>', |
|
365 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
366 | - ), |
|
367 | - ), |
|
368 | - ); |
|
369 | - } |
|
370 | - return $this->get_many_related('Event', $query_params); |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * Sets address |
|
376 | - */ |
|
377 | - public function set_address($address = '') |
|
378 | - { |
|
379 | - $this->set('VNU_address', $address); |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * @param string $address2 |
|
385 | - */ |
|
386 | - public function set_address2($address2 = '') |
|
387 | - { |
|
388 | - $this->set('VNU_address2', $address2); |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * @param string $city |
|
394 | - */ |
|
395 | - public function set_city($city = '') |
|
396 | - { |
|
397 | - $this->set('VNU_city', $city); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * @param int $state |
|
403 | - */ |
|
404 | - public function set_state_ID($state = 0) |
|
405 | - { |
|
406 | - $this->set('STA_ID', $state); |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * Sets the state, given either a state id or state object |
|
412 | - * |
|
413 | - * @param EE_State /int $state_id_or_obj |
|
414 | - * @return EE_State |
|
415 | - */ |
|
416 | - public function set_state_obj($state_id_or_obj) |
|
417 | - { |
|
418 | - return $this->_add_relation_to($state_id_or_obj, 'State'); |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * @param int $country_ID |
|
424 | - */ |
|
425 | - public function set_country_ID($country_ID = 0) |
|
426 | - { |
|
427 | - $this->set('CNT_ISO', $country_ID); |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * Sets the country on the venue |
|
433 | - * |
|
434 | - * @param EE_Country /string $country_id_or_obj |
|
435 | - * @return EE_Country |
|
436 | - */ |
|
437 | - public function set_country_obj($country_id_or_obj) |
|
438 | - { |
|
439 | - return $this->_add_relation_to($country_id_or_obj, 'Country'); |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * @param string $zip |
|
445 | - */ |
|
446 | - public function set_zip($zip = '') |
|
447 | - { |
|
448 | - $this->set('VNU_zip', $zip); |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * @param int $capacity |
|
454 | - */ |
|
455 | - public function set_capacity($capacity = 0) |
|
456 | - { |
|
457 | - $this->set('VNU_capacity', $capacity); |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * @param string $created |
|
463 | - */ |
|
464 | - public function set_created($created = '') |
|
465 | - { |
|
466 | - $this->set('VNU_created', $created); |
|
467 | - } |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * @param string $desc |
|
472 | - */ |
|
473 | - public function set_description($desc = '') |
|
474 | - { |
|
475 | - $this->set('VNU_desc', $desc); |
|
476 | - } |
|
477 | - |
|
478 | - |
|
479 | - /** |
|
480 | - * @param string $identifier |
|
481 | - */ |
|
482 | - public function set_identifier($identifier = '') |
|
483 | - { |
|
484 | - $this->set('VNU_identifier', $identifier); |
|
485 | - } |
|
486 | - |
|
487 | - |
|
488 | - /** |
|
489 | - * @param string $modified |
|
490 | - */ |
|
491 | - public function set_modified($modified = '') |
|
492 | - { |
|
493 | - $this->set('VNU_modified', $modified); |
|
494 | - } |
|
495 | - |
|
496 | - |
|
497 | - /** |
|
498 | - * @param string $name |
|
499 | - */ |
|
500 | - public function set_name($name = '') |
|
501 | - { |
|
502 | - $this->set('VNU_name', $name); |
|
503 | - } |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * @param int $order |
|
508 | - */ |
|
509 | - public function set_order($order = 0) |
|
510 | - { |
|
511 | - $this->set('VNU_order', $order); |
|
512 | - } |
|
513 | - |
|
514 | - |
|
515 | - /** |
|
516 | - * @param string $phone |
|
517 | - */ |
|
518 | - public function set_phone($phone = '') |
|
519 | - { |
|
520 | - $this->set('VNU_phone', $phone); |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - /** |
|
525 | - * @param int $wp_user |
|
526 | - */ |
|
527 | - public function set_wp_user($wp_user = 1) |
|
528 | - { |
|
529 | - $this->set('VNU_wp_user', $wp_user); |
|
530 | - } |
|
531 | - |
|
532 | - |
|
533 | - /** |
|
534 | - * @param string $url |
|
535 | - */ |
|
536 | - public function set_venue_url($url = '') |
|
537 | - { |
|
538 | - $this->set('VNU_url', $url); |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - /** |
|
543 | - * @param string $phone |
|
544 | - */ |
|
545 | - public function set_virtual_phone($phone = '') |
|
546 | - { |
|
547 | - $this->set('VNU_virtual_phone', $phone); |
|
548 | - } |
|
549 | - |
|
550 | - |
|
551 | - /** |
|
552 | - * @param string $url |
|
553 | - */ |
|
554 | - public function set_virtual_url($url = '') |
|
555 | - { |
|
556 | - $this->set('VNU_virtual_url', $url); |
|
557 | - } |
|
558 | - |
|
559 | - |
|
560 | - /** |
|
561 | - * @param string $enable |
|
562 | - */ |
|
563 | - public function set_enable_for_gmap($enable = '') |
|
564 | - { |
|
565 | - $this->set('VNU_enable_for_gmap', $enable); |
|
566 | - } |
|
567 | - |
|
568 | - |
|
569 | - /** |
|
570 | - * @param string $google_map_link |
|
571 | - */ |
|
572 | - public function set_google_map_link($google_map_link = '') |
|
573 | - { |
|
574 | - $this->set('VNU_google_map_link', $google_map_link); |
|
575 | - } |
|
14 | + /** |
|
15 | + * |
|
16 | + * @param array $props_n_values incoming values |
|
17 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
18 | + * used.) |
|
19 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
20 | + * date_format and the second value is the time format |
|
21 | + * @return EE_Attendee |
|
22 | + */ |
|
23 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
24 | + { |
|
25 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
26 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
27 | + } |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * @param array $props_n_values incoming values from the database |
|
32 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
33 | + * the website will be used. |
|
34 | + * @return EE_Attendee |
|
35 | + */ |
|
36 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
37 | + { |
|
38 | + return new self($props_n_values, true, $timezone); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * Gets name |
|
44 | + * |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function name() |
|
48 | + { |
|
49 | + return $this->get('VNU_name'); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * Gets phone |
|
55 | + * |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function phone() |
|
59 | + { |
|
60 | + return $this->get('VNU_phone'); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * venue_url |
|
66 | + * |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function venue_url() |
|
70 | + { |
|
71 | + return $this->get('VNU_url'); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * Gets desc |
|
77 | + * |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public function description() |
|
81 | + { |
|
82 | + return $this->get('VNU_desc'); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * Gets short description (AKA: the excerpt) |
|
88 | + * |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function excerpt() |
|
92 | + { |
|
93 | + return $this->get('VNU_short_desc'); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * Gets identifier |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function identifier() |
|
103 | + { |
|
104 | + return $this->get('VNU_identifier'); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Gets address |
|
110 | + * |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function address(): string |
|
114 | + { |
|
115 | + return $this->get('VNU_address'); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Gets address2 |
|
121 | + * |
|
122 | + * @return string |
|
123 | + */ |
|
124 | + public function address2(): string |
|
125 | + { |
|
126 | + return $this->get('VNU_address2'); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Gets city |
|
132 | + * |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + public function city(): string |
|
136 | + { |
|
137 | + return $this->get('VNU_city'); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Gets state |
|
142 | + * |
|
143 | + * @return int |
|
144 | + */ |
|
145 | + public function state_ID(): int |
|
146 | + { |
|
147 | + return $this->get('STA_ID'); |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @return string |
|
153 | + */ |
|
154 | + public function state_abbrev(): string |
|
155 | + { |
|
156 | + return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @return string |
|
162 | + */ |
|
163 | + public function state_name(): string |
|
164 | + { |
|
165 | + return $this->state_obj() instanceof EE_State ? $this->state_obj()->name() : ''; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * Gets the state for this venue |
|
171 | + * |
|
172 | + * @return EE_State|null |
|
173 | + */ |
|
174 | + public function state_obj(): ?EE_State |
|
175 | + { |
|
176 | + return $this->get_first_related('State'); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * either displays the state abbreviation or the state name, as determined |
|
182 | + * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
183 | + * defaults to abbreviation |
|
184 | + * |
|
185 | + * @return string |
|
186 | + */ |
|
187 | + public function state(): string |
|
188 | + { |
|
189 | + if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
190 | + return $this->state_abbrev(); |
|
191 | + } else { |
|
192 | + return $this->state_name(); |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * country_ID |
|
199 | + * |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public function country_ID(): string |
|
203 | + { |
|
204 | + return $this->get('CNT_ISO'); |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * @return string |
|
210 | + */ |
|
211 | + public function country_name(): string |
|
212 | + { |
|
213 | + return $this->country_obj() instanceof EE_Country ? $this->country_obj()->name() : ''; |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * Gets the country of this venue |
|
219 | + * |
|
220 | + * @return EE_Country|null |
|
221 | + */ |
|
222 | + public function country_obj(): ?EE_Country |
|
223 | + { |
|
224 | + return $this->get_first_related('Country'); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * either displays the country ISO2 code or the country name, as determined |
|
230 | + * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
231 | + * defaults to abbreviation |
|
232 | + * |
|
233 | + * @return string |
|
234 | + */ |
|
235 | + public function country(): string |
|
236 | + { |
|
237 | + if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
238 | + return $this->country_ID(); |
|
239 | + } else { |
|
240 | + return $this->country_name(); |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * Gets zip |
|
247 | + * |
|
248 | + * @return string |
|
249 | + */ |
|
250 | + public function zip(): string |
|
251 | + { |
|
252 | + return $this->get('VNU_zip'); |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * Gets capacity |
|
258 | + * |
|
259 | + * @return int|string |
|
260 | + * @throws EE_Error |
|
261 | + * @throws ReflectionException |
|
262 | + */ |
|
263 | + public function capacity() |
|
264 | + { |
|
265 | + return $this->get_pretty('VNU_capacity', 'symbol'); |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * Gets created |
|
271 | + * |
|
272 | + * @return string |
|
273 | + */ |
|
274 | + public function created() |
|
275 | + { |
|
276 | + return $this->get('VNU_created'); |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * Gets modified |
|
282 | + * |
|
283 | + * @return string |
|
284 | + */ |
|
285 | + public function modified() |
|
286 | + { |
|
287 | + return $this->get('VNU_modified'); |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * Gets order |
|
293 | + * |
|
294 | + * @return int |
|
295 | + */ |
|
296 | + public function order() |
|
297 | + { |
|
298 | + return $this->get('VNU_order'); |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * Gets wp_user |
|
304 | + * |
|
305 | + * @return int |
|
306 | + */ |
|
307 | + public function wp_user() |
|
308 | + { |
|
309 | + return $this->get('VNU_wp_user'); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * @return string |
|
315 | + */ |
|
316 | + public function virtual_phone() |
|
317 | + { |
|
318 | + return $this->get('VNU_virtual_phone'); |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * @return string |
|
324 | + */ |
|
325 | + public function virtual_url() |
|
326 | + { |
|
327 | + return $this->get('VNU_virtual_url'); |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * @return bool |
|
333 | + */ |
|
334 | + public function enable_for_gmap() |
|
335 | + { |
|
336 | + return $this->get('VNU_enable_for_gmap'); |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * @return string |
|
342 | + */ |
|
343 | + public function google_map_link() |
|
344 | + { |
|
345 | + return $this->get('VNU_google_map_link'); |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * Gets all events happening at this venue. Query parameters can be added to |
|
351 | + * fetch a subset of those events. |
|
352 | + * |
|
353 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
354 | + * @param bool $upcoming |
|
355 | + * @return EE_Event[] |
|
356 | + */ |
|
357 | + public function events($query_params = array(), $upcoming = false) |
|
358 | + { |
|
359 | + if ($upcoming) { |
|
360 | + $query_params = array( |
|
361 | + array( |
|
362 | + 'status' => 'publish', |
|
363 | + 'Datetime.DTT_EVT_start' => array( |
|
364 | + '>', |
|
365 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
366 | + ), |
|
367 | + ), |
|
368 | + ); |
|
369 | + } |
|
370 | + return $this->get_many_related('Event', $query_params); |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * Sets address |
|
376 | + */ |
|
377 | + public function set_address($address = '') |
|
378 | + { |
|
379 | + $this->set('VNU_address', $address); |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * @param string $address2 |
|
385 | + */ |
|
386 | + public function set_address2($address2 = '') |
|
387 | + { |
|
388 | + $this->set('VNU_address2', $address2); |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * @param string $city |
|
394 | + */ |
|
395 | + public function set_city($city = '') |
|
396 | + { |
|
397 | + $this->set('VNU_city', $city); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * @param int $state |
|
403 | + */ |
|
404 | + public function set_state_ID($state = 0) |
|
405 | + { |
|
406 | + $this->set('STA_ID', $state); |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * Sets the state, given either a state id or state object |
|
412 | + * |
|
413 | + * @param EE_State /int $state_id_or_obj |
|
414 | + * @return EE_State |
|
415 | + */ |
|
416 | + public function set_state_obj($state_id_or_obj) |
|
417 | + { |
|
418 | + return $this->_add_relation_to($state_id_or_obj, 'State'); |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * @param int $country_ID |
|
424 | + */ |
|
425 | + public function set_country_ID($country_ID = 0) |
|
426 | + { |
|
427 | + $this->set('CNT_ISO', $country_ID); |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * Sets the country on the venue |
|
433 | + * |
|
434 | + * @param EE_Country /string $country_id_or_obj |
|
435 | + * @return EE_Country |
|
436 | + */ |
|
437 | + public function set_country_obj($country_id_or_obj) |
|
438 | + { |
|
439 | + return $this->_add_relation_to($country_id_or_obj, 'Country'); |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * @param string $zip |
|
445 | + */ |
|
446 | + public function set_zip($zip = '') |
|
447 | + { |
|
448 | + $this->set('VNU_zip', $zip); |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * @param int $capacity |
|
454 | + */ |
|
455 | + public function set_capacity($capacity = 0) |
|
456 | + { |
|
457 | + $this->set('VNU_capacity', $capacity); |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * @param string $created |
|
463 | + */ |
|
464 | + public function set_created($created = '') |
|
465 | + { |
|
466 | + $this->set('VNU_created', $created); |
|
467 | + } |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * @param string $desc |
|
472 | + */ |
|
473 | + public function set_description($desc = '') |
|
474 | + { |
|
475 | + $this->set('VNU_desc', $desc); |
|
476 | + } |
|
477 | + |
|
478 | + |
|
479 | + /** |
|
480 | + * @param string $identifier |
|
481 | + */ |
|
482 | + public function set_identifier($identifier = '') |
|
483 | + { |
|
484 | + $this->set('VNU_identifier', $identifier); |
|
485 | + } |
|
486 | + |
|
487 | + |
|
488 | + /** |
|
489 | + * @param string $modified |
|
490 | + */ |
|
491 | + public function set_modified($modified = '') |
|
492 | + { |
|
493 | + $this->set('VNU_modified', $modified); |
|
494 | + } |
|
495 | + |
|
496 | + |
|
497 | + /** |
|
498 | + * @param string $name |
|
499 | + */ |
|
500 | + public function set_name($name = '') |
|
501 | + { |
|
502 | + $this->set('VNU_name', $name); |
|
503 | + } |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * @param int $order |
|
508 | + */ |
|
509 | + public function set_order($order = 0) |
|
510 | + { |
|
511 | + $this->set('VNU_order', $order); |
|
512 | + } |
|
513 | + |
|
514 | + |
|
515 | + /** |
|
516 | + * @param string $phone |
|
517 | + */ |
|
518 | + public function set_phone($phone = '') |
|
519 | + { |
|
520 | + $this->set('VNU_phone', $phone); |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + /** |
|
525 | + * @param int $wp_user |
|
526 | + */ |
|
527 | + public function set_wp_user($wp_user = 1) |
|
528 | + { |
|
529 | + $this->set('VNU_wp_user', $wp_user); |
|
530 | + } |
|
531 | + |
|
532 | + |
|
533 | + /** |
|
534 | + * @param string $url |
|
535 | + */ |
|
536 | + public function set_venue_url($url = '') |
|
537 | + { |
|
538 | + $this->set('VNU_url', $url); |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + /** |
|
543 | + * @param string $phone |
|
544 | + */ |
|
545 | + public function set_virtual_phone($phone = '') |
|
546 | + { |
|
547 | + $this->set('VNU_virtual_phone', $phone); |
|
548 | + } |
|
549 | + |
|
550 | + |
|
551 | + /** |
|
552 | + * @param string $url |
|
553 | + */ |
|
554 | + public function set_virtual_url($url = '') |
|
555 | + { |
|
556 | + $this->set('VNU_virtual_url', $url); |
|
557 | + } |
|
558 | + |
|
559 | + |
|
560 | + /** |
|
561 | + * @param string $enable |
|
562 | + */ |
|
563 | + public function set_enable_for_gmap($enable = '') |
|
564 | + { |
|
565 | + $this->set('VNU_enable_for_gmap', $enable); |
|
566 | + } |
|
567 | + |
|
568 | + |
|
569 | + /** |
|
570 | + * @param string $google_map_link |
|
571 | + */ |
|
572 | + public function set_google_map_link($google_map_link = '') |
|
573 | + { |
|
574 | + $this->set('VNU_google_map_link', $google_map_link); |
|
575 | + } |
|
576 | 576 | } |
@@ -25,751 +25,751 @@ |
||
25 | 25 | */ |
26 | 26 | class EE_Attendee extends EE_CPT_Base implements EEI_Contact, AddressInterface, EEI_Admin_Links, EEI_Attendee |
27 | 27 | { |
28 | - /** |
|
29 | - * Sets some dynamic defaults |
|
30 | - * |
|
31 | - * @param array $fieldValues |
|
32 | - * @param bool $bydb |
|
33 | - * @param string $timezone |
|
34 | - * @param array $date_formats |
|
35 | - * @throws EE_Error |
|
36 | - */ |
|
37 | - protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
38 | - { |
|
39 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
40 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
41 | - $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
42 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
43 | - } |
|
44 | - if (! isset($fieldValues['ATT_slug'])) { |
|
45 | - // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
46 | - $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
47 | - } |
|
48 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
49 | - $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
50 | - } |
|
51 | - parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param array $props_n_values incoming values |
|
57 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
58 | - * used.) |
|
59 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
60 | - * date_format and the second value is the time format |
|
61 | - * @return EE_Attendee |
|
62 | - * @throws EE_Error |
|
63 | - */ |
|
64 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
65 | - { |
|
66 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
67 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @param array $props_n_values incoming values from the database |
|
73 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
74 | - * the website will be used. |
|
75 | - * @return EE_Attendee |
|
76 | - */ |
|
77 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
78 | - { |
|
79 | - return new self($props_n_values, true, $timezone); |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * Set Attendee First Name |
|
85 | - * |
|
86 | - * @access public |
|
87 | - * @param string $fname |
|
88 | - * @throws EE_Error |
|
89 | - */ |
|
90 | - public function set_fname($fname = '') |
|
91 | - { |
|
92 | - $this->set('ATT_fname', $fname); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Set Attendee Last Name |
|
98 | - * |
|
99 | - * @access public |
|
100 | - * @param string $lname |
|
101 | - * @throws EE_Error |
|
102 | - */ |
|
103 | - public function set_lname($lname = '') |
|
104 | - { |
|
105 | - $this->set('ATT_lname', $lname); |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * Set Attendee Address |
|
111 | - * |
|
112 | - * @access public |
|
113 | - * @param string $address |
|
114 | - * @throws EE_Error |
|
115 | - */ |
|
116 | - public function set_address($address = '') |
|
117 | - { |
|
118 | - $this->set('ATT_address', $address); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * Set Attendee Address2 |
|
124 | - * |
|
125 | - * @access public |
|
126 | - * @param string $address2 |
|
127 | - * @throws EE_Error |
|
128 | - */ |
|
129 | - public function set_address2($address2 = '') |
|
130 | - { |
|
131 | - $this->set('ATT_address2', $address2); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * Set Attendee City |
|
137 | - * |
|
138 | - * @access public |
|
139 | - * @param string $city |
|
140 | - * @throws EE_Error |
|
141 | - */ |
|
142 | - public function set_city($city = '') |
|
143 | - { |
|
144 | - $this->set('ATT_city', $city); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * Set Attendee State ID |
|
150 | - * |
|
151 | - * @access public |
|
152 | - * @param int $STA_ID |
|
153 | - * @throws EE_Error |
|
154 | - */ |
|
155 | - public function set_state($STA_ID = 0) |
|
156 | - { |
|
157 | - $this->set('STA_ID', $STA_ID); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * Set Attendee Country ISO Code |
|
163 | - * |
|
164 | - * @access public |
|
165 | - * @param string $CNT_ISO |
|
166 | - * @throws EE_Error |
|
167 | - */ |
|
168 | - public function set_country($CNT_ISO = '') |
|
169 | - { |
|
170 | - $this->set('CNT_ISO', $CNT_ISO); |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * Set Attendee Zip/Postal Code |
|
176 | - * |
|
177 | - * @access public |
|
178 | - * @param string $zip |
|
179 | - * @throws EE_Error |
|
180 | - */ |
|
181 | - public function set_zip($zip = '') |
|
182 | - { |
|
183 | - $this->set('ATT_zip', $zip); |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * Set Attendee Email Address |
|
189 | - * |
|
190 | - * @access public |
|
191 | - * @param string $email |
|
192 | - * @throws EE_Error |
|
193 | - */ |
|
194 | - public function set_email($email = '') |
|
195 | - { |
|
196 | - $this->set('ATT_email', $email); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * Set Attendee Phone |
|
202 | - * |
|
203 | - * @access public |
|
204 | - * @param string $phone |
|
205 | - * @throws EE_Error |
|
206 | - */ |
|
207 | - public function set_phone($phone = '') |
|
208 | - { |
|
209 | - $this->set('ATT_phone', $phone); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * set deleted |
|
215 | - * |
|
216 | - * @access public |
|
217 | - * @param bool $ATT_deleted |
|
218 | - * @throws EE_Error |
|
219 | - */ |
|
220 | - public function set_deleted($ATT_deleted = false) |
|
221 | - { |
|
222 | - $this->set('ATT_deleted', $ATT_deleted); |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * Returns the value for the post_author id saved with the cpt |
|
228 | - * |
|
229 | - * @since 4.5.0 |
|
230 | - * @return int |
|
231 | - * @throws EE_Error |
|
232 | - */ |
|
233 | - public function wp_user() |
|
234 | - { |
|
235 | - return $this->get('ATT_author'); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * get Attendee First Name |
|
241 | - * |
|
242 | - * @access public |
|
243 | - * @return string |
|
244 | - * @throws EE_Error |
|
245 | - */ |
|
246 | - public function fname() |
|
247 | - { |
|
248 | - return $this->get('ATT_fname'); |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * echoes out the attendee's first name |
|
254 | - * |
|
255 | - * @return void |
|
256 | - * @throws EE_Error |
|
257 | - */ |
|
258 | - public function e_full_name() |
|
259 | - { |
|
260 | - echo esc_html($this->full_name()); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * Returns the first and last name concatenated together with a space. |
|
266 | - * |
|
267 | - * @param bool $apply_html_entities |
|
268 | - * @return string |
|
269 | - * @throws EE_Error |
|
270 | - */ |
|
271 | - public function full_name($apply_html_entities = false) |
|
272 | - { |
|
273 | - $full_name = array( |
|
274 | - $this->fname(), |
|
275 | - $this->lname(), |
|
276 | - ); |
|
277 | - $full_name = array_filter($full_name); |
|
278 | - $full_name = implode(' ', $full_name); |
|
279 | - return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
285 | - * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
286 | - * attendee. |
|
287 | - * |
|
288 | - * @param bool $apply_html_entities |
|
289 | - * @return string |
|
290 | - * @throws EE_Error |
|
291 | - */ |
|
292 | - public function ATT_full_name($apply_html_entities = false) |
|
293 | - { |
|
294 | - return $apply_html_entities |
|
295 | - ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
296 | - : $this->get('ATT_full_name'); |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * get Attendee Last Name |
|
302 | - * |
|
303 | - * @access public |
|
304 | - * @return string |
|
305 | - * @throws EE_Error |
|
306 | - */ |
|
307 | - public function lname() |
|
308 | - { |
|
309 | - return $this->get('ATT_lname'); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
315 | - * |
|
316 | - * @return array numerically indexed, with each part of the address that is known. |
|
317 | - * Eg, if the user only responded to state and country, |
|
318 | - * it would be array(0=>'Alabama',1=>'USA') |
|
319 | - * @return array |
|
320 | - * @throws EE_Error |
|
321 | - */ |
|
322 | - public function full_address_as_array() |
|
323 | - { |
|
324 | - $full_address_array = array(); |
|
325 | - $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
326 | - foreach ($initial_address_fields as $address_field_name) { |
|
327 | - $address_fields_value = $this->get($address_field_name); |
|
328 | - if (! empty($address_fields_value)) { |
|
329 | - $full_address_array[] = $address_fields_value; |
|
330 | - } |
|
331 | - } |
|
332 | - // now handle state and country |
|
333 | - $state_obj = $this->state_obj(); |
|
334 | - if ($state_obj instanceof EE_State) { |
|
335 | - $full_address_array[] = $state_obj->name(); |
|
336 | - } |
|
337 | - $country_obj = $this->country_obj(); |
|
338 | - if ($country_obj instanceof EE_Country) { |
|
339 | - $full_address_array[] = $country_obj->name(); |
|
340 | - } |
|
341 | - // lastly get the xip |
|
342 | - $zip_value = $this->zip(); |
|
343 | - if (! empty($zip_value)) { |
|
344 | - $full_address_array[] = $zip_value; |
|
345 | - } |
|
346 | - return $full_address_array; |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * get Attendee Address |
|
352 | - * |
|
353 | - * @return string |
|
354 | - * @throws EE_Error |
|
355 | - */ |
|
356 | - public function address(): string |
|
357 | - { |
|
358 | - return $this->get('ATT_address'); |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * get Attendee Address2 |
|
364 | - * |
|
365 | - * @return string |
|
366 | - * @throws EE_Error |
|
367 | - */ |
|
368 | - public function address2(): string |
|
369 | - { |
|
370 | - return $this->get('ATT_address2'); |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * get Attendee City |
|
376 | - * |
|
377 | - * @return string |
|
378 | - * @throws EE_Error |
|
379 | - */ |
|
380 | - public function city(): string |
|
381 | - { |
|
382 | - return $this->get('ATT_city'); |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - /** |
|
387 | - * get Attendee State ID |
|
388 | - * |
|
389 | - * @return int |
|
390 | - * @throws EE_Error |
|
391 | - */ |
|
392 | - public function state_ID(): int |
|
393 | - { |
|
394 | - return $this->get('STA_ID'); |
|
395 | - } |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * @return string |
|
400 | - * @throws EE_Error |
|
401 | - */ |
|
402 | - public function state_abbrev(): string |
|
403 | - { |
|
404 | - return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * Gets the state set to this attendee |
|
410 | - * |
|
411 | - * @return EE_State|null |
|
412 | - * @throws EE_Error |
|
413 | - */ |
|
414 | - public function state_obj(): ?EE_State |
|
415 | - { |
|
416 | - return $this->get_first_related('State'); |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - /** |
|
421 | - * Returns the state's name, otherwise 'Unknown' |
|
422 | - * |
|
423 | - * @return string |
|
424 | - * @throws EE_Error |
|
425 | - */ |
|
426 | - public function state_name(): string |
|
427 | - { |
|
428 | - if ($this->state_obj()) { |
|
429 | - return $this->state_obj()->name(); |
|
430 | - } else { |
|
431 | - return ''; |
|
432 | - } |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * either displays the state abbreviation or the state name, as determined |
|
438 | - * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
439 | - * defaults to abbreviation |
|
440 | - * |
|
441 | - * @return string |
|
442 | - * @throws EE_Error |
|
443 | - */ |
|
444 | - public function state(): string |
|
445 | - { |
|
446 | - if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
447 | - return $this->state_abbrev(); |
|
448 | - } |
|
449 | - return $this->state_name(); |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - /** |
|
454 | - * get Attendee Country ISO Code |
|
455 | - * |
|
456 | - * @return string |
|
457 | - * @throws EE_Error |
|
458 | - */ |
|
459 | - public function country_ID(): string |
|
460 | - { |
|
461 | - return $this->get('CNT_ISO'); |
|
462 | - } |
|
463 | - |
|
464 | - |
|
465 | - /** |
|
466 | - * Gets country set for this attendee |
|
467 | - * |
|
468 | - * @return EE_Country|null |
|
469 | - * @throws EE_Error |
|
470 | - */ |
|
471 | - public function country_obj(): ?EE_Country |
|
472 | - { |
|
473 | - return $this->get_first_related('Country'); |
|
474 | - } |
|
475 | - |
|
476 | - |
|
477 | - /** |
|
478 | - * Returns the country's name if known, otherwise 'Unknown' |
|
479 | - * |
|
480 | - * @return string |
|
481 | - * @throws EE_Error |
|
482 | - */ |
|
483 | - public function country_name(): string |
|
484 | - { |
|
485 | - if ($this->country_obj()) { |
|
486 | - return $this->country_obj()->name(); |
|
487 | - } |
|
488 | - return ''; |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * either displays the country ISO2 code or the country name, as determined |
|
494 | - * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
495 | - * defaults to abbreviation |
|
496 | - * |
|
497 | - * @return string |
|
498 | - * @throws EE_Error |
|
499 | - */ |
|
500 | - public function country(): string |
|
501 | - { |
|
502 | - if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
503 | - return $this->country_ID(); |
|
504 | - } |
|
505 | - return $this->country_name(); |
|
506 | - } |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * get Attendee Zip/Postal Code |
|
511 | - * |
|
512 | - * @return string |
|
513 | - * @throws EE_Error |
|
514 | - */ |
|
515 | - public function zip(): string |
|
516 | - { |
|
517 | - return $this->get('ATT_zip'); |
|
518 | - } |
|
519 | - |
|
520 | - |
|
521 | - /** |
|
522 | - * get Attendee Email Address |
|
523 | - * |
|
524 | - * @return string |
|
525 | - * @throws EE_Error |
|
526 | - */ |
|
527 | - public function email() |
|
528 | - { |
|
529 | - return $this->get('ATT_email'); |
|
530 | - } |
|
531 | - |
|
532 | - |
|
533 | - /** |
|
534 | - * get Attendee Phone # |
|
535 | - * |
|
536 | - * @return string |
|
537 | - * @throws EE_Error |
|
538 | - */ |
|
539 | - public function phone() |
|
540 | - { |
|
541 | - return $this->get('ATT_phone'); |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * get deleted |
|
547 | - * |
|
548 | - * @return bool |
|
549 | - * @throws EE_Error |
|
550 | - */ |
|
551 | - public function deleted() |
|
552 | - { |
|
553 | - return $this->get('ATT_deleted'); |
|
554 | - } |
|
555 | - |
|
556 | - |
|
557 | - /** |
|
558 | - * Gets registrations of this attendee |
|
559 | - * |
|
560 | - * @param array $query_params |
|
561 | - * @return EE_Registration[] |
|
562 | - * @throws EE_Error |
|
563 | - */ |
|
564 | - public function get_registrations($query_params = array()) |
|
565 | - { |
|
566 | - return $this->get_many_related('Registration', $query_params); |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - /** |
|
571 | - * Gets the most recent registration of this attendee |
|
572 | - * |
|
573 | - * @return EE_Registration |
|
574 | - * @throws EE_Error |
|
575 | - */ |
|
576 | - public function get_most_recent_registration() |
|
577 | - { |
|
578 | - return $this->get_first_related( |
|
579 | - 'Registration', |
|
580 | - array('order_by' => array('REG_date' => 'DESC')) |
|
581 | - ); // null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - /** |
|
586 | - * Gets the most recent registration for this attend at this event |
|
587 | - * |
|
588 | - * @param int $event_id |
|
589 | - * @return EE_Registration |
|
590 | - * @throws EE_Error |
|
591 | - */ |
|
592 | - public function get_most_recent_registration_for_event($event_id) |
|
593 | - { |
|
594 | - return $this->get_first_related( |
|
595 | - 'Registration', |
|
596 | - array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')) |
|
597 | - ); |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - /** |
|
602 | - * returns any events attached to this attendee ($_Event property); |
|
603 | - * |
|
604 | - * @return array |
|
605 | - * @throws EE_Error |
|
606 | - */ |
|
607 | - public function events() |
|
608 | - { |
|
609 | - return $this->get_many_related('Event'); |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
615 | - * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
616 | - * used to save the billing info |
|
617 | - * |
|
618 | - * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
619 | - * @return EE_Form_Section_Proper|null |
|
620 | - * @throws EE_Error |
|
621 | - */ |
|
622 | - public function billing_info_for_payment_method($payment_method) |
|
623 | - { |
|
624 | - $pm_type = $payment_method->type_obj(); |
|
625 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
626 | - return null; |
|
627 | - } |
|
628 | - $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
629 | - if (! $billing_info) { |
|
630 | - return null; |
|
631 | - } |
|
632 | - $billing_form = $pm_type->billing_form(); |
|
633 | - // double-check the form isn't totally hidden, in which case pretend there is no form |
|
634 | - $form_totally_hidden = true; |
|
635 | - foreach ($billing_form->inputs_in_subsections() as $input) { |
|
636 | - if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
637 | - $form_totally_hidden = false; |
|
638 | - break; |
|
639 | - } |
|
640 | - } |
|
641 | - if ($form_totally_hidden) { |
|
642 | - return null; |
|
643 | - } |
|
644 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
645 | - $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
646 | - } |
|
647 | - |
|
648 | - return $billing_form; |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - /** |
|
653 | - * Gets the postmeta key that holds this attendee's billing info for the |
|
654 | - * specified payment method |
|
655 | - * |
|
656 | - * @param EE_Payment_Method $payment_method |
|
657 | - * @return string |
|
658 | - * @throws EE_Error |
|
659 | - */ |
|
660 | - public function get_billing_info_postmeta_name($payment_method) |
|
661 | - { |
|
662 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
663 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
664 | - } |
|
665 | - return null; |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - /** |
|
670 | - * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
671 | - * retrieve it |
|
672 | - * |
|
673 | - * @param EE_Billing_Attendee_Info_Form $billing_form |
|
674 | - * @param EE_Payment_Method $payment_method |
|
675 | - * @return boolean |
|
676 | - * @throws EE_Error |
|
677 | - */ |
|
678 | - public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
679 | - { |
|
680 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
681 | - EE_Error::add_error( |
|
682 | - esc_html__('Cannot save billing info because there is none.', 'event_espresso'), |
|
683 | - __FILE__, |
|
684 | - __FUNCTION__, |
|
685 | - __LINE__ |
|
686 | - ); |
|
687 | - return false; |
|
688 | - } |
|
689 | - $billing_form->clean_sensitive_data(); |
|
690 | - return update_post_meta( |
|
691 | - $this->ID(), |
|
692 | - $this->get_billing_info_postmeta_name($payment_method), |
|
693 | - $billing_form->input_values(true) |
|
694 | - ); |
|
695 | - } |
|
696 | - |
|
697 | - |
|
698 | - /** |
|
699 | - * Return the link to the admin details for the object. |
|
700 | - * |
|
701 | - * @return string |
|
702 | - * @throws EE_Error |
|
703 | - * @throws InvalidArgumentException |
|
704 | - * @throws InvalidDataTypeException |
|
705 | - * @throws InvalidInterfaceException |
|
706 | - * @throws ReflectionException |
|
707 | - */ |
|
708 | - public function get_admin_details_link() |
|
709 | - { |
|
710 | - return $this->get_admin_edit_link(); |
|
711 | - } |
|
712 | - |
|
713 | - |
|
714 | - /** |
|
715 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
716 | - * |
|
717 | - * @return string |
|
718 | - * @throws EE_Error |
|
719 | - * @throws InvalidArgumentException |
|
720 | - * @throws ReflectionException |
|
721 | - * @throws InvalidDataTypeException |
|
722 | - * @throws InvalidInterfaceException |
|
723 | - */ |
|
724 | - public function get_admin_edit_link() |
|
725 | - { |
|
726 | - EE_Registry::instance()->load_helper('URL'); |
|
727 | - return EEH_URL::add_query_args_and_nonce( |
|
728 | - array( |
|
729 | - 'page' => 'espresso_registrations', |
|
730 | - 'action' => 'edit_attendee', |
|
731 | - 'post' => $this->ID(), |
|
732 | - ), |
|
733 | - admin_url('admin.php') |
|
734 | - ); |
|
735 | - } |
|
736 | - |
|
737 | - |
|
738 | - /** |
|
739 | - * Returns the link to a settings page for the object. |
|
740 | - * |
|
741 | - * @return string |
|
742 | - * @throws EE_Error |
|
743 | - * @throws InvalidArgumentException |
|
744 | - * @throws InvalidDataTypeException |
|
745 | - * @throws InvalidInterfaceException |
|
746 | - * @throws ReflectionException |
|
747 | - */ |
|
748 | - public function get_admin_settings_link() |
|
749 | - { |
|
750 | - return $this->get_admin_edit_link(); |
|
751 | - } |
|
752 | - |
|
753 | - |
|
754 | - /** |
|
755 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
756 | - * |
|
757 | - * @return string |
|
758 | - * @throws EE_Error |
|
759 | - * @throws InvalidArgumentException |
|
760 | - * @throws ReflectionException |
|
761 | - * @throws InvalidDataTypeException |
|
762 | - * @throws InvalidInterfaceException |
|
763 | - */ |
|
764 | - public function get_admin_overview_link() |
|
765 | - { |
|
766 | - EE_Registry::instance()->load_helper('URL'); |
|
767 | - return EEH_URL::add_query_args_and_nonce( |
|
768 | - array( |
|
769 | - 'page' => 'espresso_registrations', |
|
770 | - 'action' => 'contact_list', |
|
771 | - ), |
|
772 | - admin_url('admin.php') |
|
773 | - ); |
|
774 | - } |
|
28 | + /** |
|
29 | + * Sets some dynamic defaults |
|
30 | + * |
|
31 | + * @param array $fieldValues |
|
32 | + * @param bool $bydb |
|
33 | + * @param string $timezone |
|
34 | + * @param array $date_formats |
|
35 | + * @throws EE_Error |
|
36 | + */ |
|
37 | + protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
38 | + { |
|
39 | + if (! isset($fieldValues['ATT_full_name'])) { |
|
40 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
41 | + $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
42 | + $fieldValues['ATT_full_name'] = $fname . $lname; |
|
43 | + } |
|
44 | + if (! isset($fieldValues['ATT_slug'])) { |
|
45 | + // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
46 | + $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
47 | + } |
|
48 | + if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
49 | + $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
50 | + } |
|
51 | + parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param array $props_n_values incoming values |
|
57 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
58 | + * used.) |
|
59 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
60 | + * date_format and the second value is the time format |
|
61 | + * @return EE_Attendee |
|
62 | + * @throws EE_Error |
|
63 | + */ |
|
64 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
65 | + { |
|
66 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
67 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @param array $props_n_values incoming values from the database |
|
73 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
74 | + * the website will be used. |
|
75 | + * @return EE_Attendee |
|
76 | + */ |
|
77 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
78 | + { |
|
79 | + return new self($props_n_values, true, $timezone); |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * Set Attendee First Name |
|
85 | + * |
|
86 | + * @access public |
|
87 | + * @param string $fname |
|
88 | + * @throws EE_Error |
|
89 | + */ |
|
90 | + public function set_fname($fname = '') |
|
91 | + { |
|
92 | + $this->set('ATT_fname', $fname); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Set Attendee Last Name |
|
98 | + * |
|
99 | + * @access public |
|
100 | + * @param string $lname |
|
101 | + * @throws EE_Error |
|
102 | + */ |
|
103 | + public function set_lname($lname = '') |
|
104 | + { |
|
105 | + $this->set('ATT_lname', $lname); |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * Set Attendee Address |
|
111 | + * |
|
112 | + * @access public |
|
113 | + * @param string $address |
|
114 | + * @throws EE_Error |
|
115 | + */ |
|
116 | + public function set_address($address = '') |
|
117 | + { |
|
118 | + $this->set('ATT_address', $address); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * Set Attendee Address2 |
|
124 | + * |
|
125 | + * @access public |
|
126 | + * @param string $address2 |
|
127 | + * @throws EE_Error |
|
128 | + */ |
|
129 | + public function set_address2($address2 = '') |
|
130 | + { |
|
131 | + $this->set('ATT_address2', $address2); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * Set Attendee City |
|
137 | + * |
|
138 | + * @access public |
|
139 | + * @param string $city |
|
140 | + * @throws EE_Error |
|
141 | + */ |
|
142 | + public function set_city($city = '') |
|
143 | + { |
|
144 | + $this->set('ATT_city', $city); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * Set Attendee State ID |
|
150 | + * |
|
151 | + * @access public |
|
152 | + * @param int $STA_ID |
|
153 | + * @throws EE_Error |
|
154 | + */ |
|
155 | + public function set_state($STA_ID = 0) |
|
156 | + { |
|
157 | + $this->set('STA_ID', $STA_ID); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * Set Attendee Country ISO Code |
|
163 | + * |
|
164 | + * @access public |
|
165 | + * @param string $CNT_ISO |
|
166 | + * @throws EE_Error |
|
167 | + */ |
|
168 | + public function set_country($CNT_ISO = '') |
|
169 | + { |
|
170 | + $this->set('CNT_ISO', $CNT_ISO); |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * Set Attendee Zip/Postal Code |
|
176 | + * |
|
177 | + * @access public |
|
178 | + * @param string $zip |
|
179 | + * @throws EE_Error |
|
180 | + */ |
|
181 | + public function set_zip($zip = '') |
|
182 | + { |
|
183 | + $this->set('ATT_zip', $zip); |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * Set Attendee Email Address |
|
189 | + * |
|
190 | + * @access public |
|
191 | + * @param string $email |
|
192 | + * @throws EE_Error |
|
193 | + */ |
|
194 | + public function set_email($email = '') |
|
195 | + { |
|
196 | + $this->set('ATT_email', $email); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * Set Attendee Phone |
|
202 | + * |
|
203 | + * @access public |
|
204 | + * @param string $phone |
|
205 | + * @throws EE_Error |
|
206 | + */ |
|
207 | + public function set_phone($phone = '') |
|
208 | + { |
|
209 | + $this->set('ATT_phone', $phone); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * set deleted |
|
215 | + * |
|
216 | + * @access public |
|
217 | + * @param bool $ATT_deleted |
|
218 | + * @throws EE_Error |
|
219 | + */ |
|
220 | + public function set_deleted($ATT_deleted = false) |
|
221 | + { |
|
222 | + $this->set('ATT_deleted', $ATT_deleted); |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * Returns the value for the post_author id saved with the cpt |
|
228 | + * |
|
229 | + * @since 4.5.0 |
|
230 | + * @return int |
|
231 | + * @throws EE_Error |
|
232 | + */ |
|
233 | + public function wp_user() |
|
234 | + { |
|
235 | + return $this->get('ATT_author'); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * get Attendee First Name |
|
241 | + * |
|
242 | + * @access public |
|
243 | + * @return string |
|
244 | + * @throws EE_Error |
|
245 | + */ |
|
246 | + public function fname() |
|
247 | + { |
|
248 | + return $this->get('ATT_fname'); |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * echoes out the attendee's first name |
|
254 | + * |
|
255 | + * @return void |
|
256 | + * @throws EE_Error |
|
257 | + */ |
|
258 | + public function e_full_name() |
|
259 | + { |
|
260 | + echo esc_html($this->full_name()); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * Returns the first and last name concatenated together with a space. |
|
266 | + * |
|
267 | + * @param bool $apply_html_entities |
|
268 | + * @return string |
|
269 | + * @throws EE_Error |
|
270 | + */ |
|
271 | + public function full_name($apply_html_entities = false) |
|
272 | + { |
|
273 | + $full_name = array( |
|
274 | + $this->fname(), |
|
275 | + $this->lname(), |
|
276 | + ); |
|
277 | + $full_name = array_filter($full_name); |
|
278 | + $full_name = implode(' ', $full_name); |
|
279 | + return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
285 | + * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
286 | + * attendee. |
|
287 | + * |
|
288 | + * @param bool $apply_html_entities |
|
289 | + * @return string |
|
290 | + * @throws EE_Error |
|
291 | + */ |
|
292 | + public function ATT_full_name($apply_html_entities = false) |
|
293 | + { |
|
294 | + return $apply_html_entities |
|
295 | + ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
296 | + : $this->get('ATT_full_name'); |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * get Attendee Last Name |
|
302 | + * |
|
303 | + * @access public |
|
304 | + * @return string |
|
305 | + * @throws EE_Error |
|
306 | + */ |
|
307 | + public function lname() |
|
308 | + { |
|
309 | + return $this->get('ATT_lname'); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
315 | + * |
|
316 | + * @return array numerically indexed, with each part of the address that is known. |
|
317 | + * Eg, if the user only responded to state and country, |
|
318 | + * it would be array(0=>'Alabama',1=>'USA') |
|
319 | + * @return array |
|
320 | + * @throws EE_Error |
|
321 | + */ |
|
322 | + public function full_address_as_array() |
|
323 | + { |
|
324 | + $full_address_array = array(); |
|
325 | + $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
326 | + foreach ($initial_address_fields as $address_field_name) { |
|
327 | + $address_fields_value = $this->get($address_field_name); |
|
328 | + if (! empty($address_fields_value)) { |
|
329 | + $full_address_array[] = $address_fields_value; |
|
330 | + } |
|
331 | + } |
|
332 | + // now handle state and country |
|
333 | + $state_obj = $this->state_obj(); |
|
334 | + if ($state_obj instanceof EE_State) { |
|
335 | + $full_address_array[] = $state_obj->name(); |
|
336 | + } |
|
337 | + $country_obj = $this->country_obj(); |
|
338 | + if ($country_obj instanceof EE_Country) { |
|
339 | + $full_address_array[] = $country_obj->name(); |
|
340 | + } |
|
341 | + // lastly get the xip |
|
342 | + $zip_value = $this->zip(); |
|
343 | + if (! empty($zip_value)) { |
|
344 | + $full_address_array[] = $zip_value; |
|
345 | + } |
|
346 | + return $full_address_array; |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * get Attendee Address |
|
352 | + * |
|
353 | + * @return string |
|
354 | + * @throws EE_Error |
|
355 | + */ |
|
356 | + public function address(): string |
|
357 | + { |
|
358 | + return $this->get('ATT_address'); |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * get Attendee Address2 |
|
364 | + * |
|
365 | + * @return string |
|
366 | + * @throws EE_Error |
|
367 | + */ |
|
368 | + public function address2(): string |
|
369 | + { |
|
370 | + return $this->get('ATT_address2'); |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * get Attendee City |
|
376 | + * |
|
377 | + * @return string |
|
378 | + * @throws EE_Error |
|
379 | + */ |
|
380 | + public function city(): string |
|
381 | + { |
|
382 | + return $this->get('ATT_city'); |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + /** |
|
387 | + * get Attendee State ID |
|
388 | + * |
|
389 | + * @return int |
|
390 | + * @throws EE_Error |
|
391 | + */ |
|
392 | + public function state_ID(): int |
|
393 | + { |
|
394 | + return $this->get('STA_ID'); |
|
395 | + } |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * @return string |
|
400 | + * @throws EE_Error |
|
401 | + */ |
|
402 | + public function state_abbrev(): string |
|
403 | + { |
|
404 | + return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * Gets the state set to this attendee |
|
410 | + * |
|
411 | + * @return EE_State|null |
|
412 | + * @throws EE_Error |
|
413 | + */ |
|
414 | + public function state_obj(): ?EE_State |
|
415 | + { |
|
416 | + return $this->get_first_related('State'); |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + /** |
|
421 | + * Returns the state's name, otherwise 'Unknown' |
|
422 | + * |
|
423 | + * @return string |
|
424 | + * @throws EE_Error |
|
425 | + */ |
|
426 | + public function state_name(): string |
|
427 | + { |
|
428 | + if ($this->state_obj()) { |
|
429 | + return $this->state_obj()->name(); |
|
430 | + } else { |
|
431 | + return ''; |
|
432 | + } |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * either displays the state abbreviation or the state name, as determined |
|
438 | + * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
439 | + * defaults to abbreviation |
|
440 | + * |
|
441 | + * @return string |
|
442 | + * @throws EE_Error |
|
443 | + */ |
|
444 | + public function state(): string |
|
445 | + { |
|
446 | + if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
447 | + return $this->state_abbrev(); |
|
448 | + } |
|
449 | + return $this->state_name(); |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + /** |
|
454 | + * get Attendee Country ISO Code |
|
455 | + * |
|
456 | + * @return string |
|
457 | + * @throws EE_Error |
|
458 | + */ |
|
459 | + public function country_ID(): string |
|
460 | + { |
|
461 | + return $this->get('CNT_ISO'); |
|
462 | + } |
|
463 | + |
|
464 | + |
|
465 | + /** |
|
466 | + * Gets country set for this attendee |
|
467 | + * |
|
468 | + * @return EE_Country|null |
|
469 | + * @throws EE_Error |
|
470 | + */ |
|
471 | + public function country_obj(): ?EE_Country |
|
472 | + { |
|
473 | + return $this->get_first_related('Country'); |
|
474 | + } |
|
475 | + |
|
476 | + |
|
477 | + /** |
|
478 | + * Returns the country's name if known, otherwise 'Unknown' |
|
479 | + * |
|
480 | + * @return string |
|
481 | + * @throws EE_Error |
|
482 | + */ |
|
483 | + public function country_name(): string |
|
484 | + { |
|
485 | + if ($this->country_obj()) { |
|
486 | + return $this->country_obj()->name(); |
|
487 | + } |
|
488 | + return ''; |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * either displays the country ISO2 code or the country name, as determined |
|
494 | + * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
495 | + * defaults to abbreviation |
|
496 | + * |
|
497 | + * @return string |
|
498 | + * @throws EE_Error |
|
499 | + */ |
|
500 | + public function country(): string |
|
501 | + { |
|
502 | + if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
503 | + return $this->country_ID(); |
|
504 | + } |
|
505 | + return $this->country_name(); |
|
506 | + } |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * get Attendee Zip/Postal Code |
|
511 | + * |
|
512 | + * @return string |
|
513 | + * @throws EE_Error |
|
514 | + */ |
|
515 | + public function zip(): string |
|
516 | + { |
|
517 | + return $this->get('ATT_zip'); |
|
518 | + } |
|
519 | + |
|
520 | + |
|
521 | + /** |
|
522 | + * get Attendee Email Address |
|
523 | + * |
|
524 | + * @return string |
|
525 | + * @throws EE_Error |
|
526 | + */ |
|
527 | + public function email() |
|
528 | + { |
|
529 | + return $this->get('ATT_email'); |
|
530 | + } |
|
531 | + |
|
532 | + |
|
533 | + /** |
|
534 | + * get Attendee Phone # |
|
535 | + * |
|
536 | + * @return string |
|
537 | + * @throws EE_Error |
|
538 | + */ |
|
539 | + public function phone() |
|
540 | + { |
|
541 | + return $this->get('ATT_phone'); |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * get deleted |
|
547 | + * |
|
548 | + * @return bool |
|
549 | + * @throws EE_Error |
|
550 | + */ |
|
551 | + public function deleted() |
|
552 | + { |
|
553 | + return $this->get('ATT_deleted'); |
|
554 | + } |
|
555 | + |
|
556 | + |
|
557 | + /** |
|
558 | + * Gets registrations of this attendee |
|
559 | + * |
|
560 | + * @param array $query_params |
|
561 | + * @return EE_Registration[] |
|
562 | + * @throws EE_Error |
|
563 | + */ |
|
564 | + public function get_registrations($query_params = array()) |
|
565 | + { |
|
566 | + return $this->get_many_related('Registration', $query_params); |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + /** |
|
571 | + * Gets the most recent registration of this attendee |
|
572 | + * |
|
573 | + * @return EE_Registration |
|
574 | + * @throws EE_Error |
|
575 | + */ |
|
576 | + public function get_most_recent_registration() |
|
577 | + { |
|
578 | + return $this->get_first_related( |
|
579 | + 'Registration', |
|
580 | + array('order_by' => array('REG_date' => 'DESC')) |
|
581 | + ); // null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + /** |
|
586 | + * Gets the most recent registration for this attend at this event |
|
587 | + * |
|
588 | + * @param int $event_id |
|
589 | + * @return EE_Registration |
|
590 | + * @throws EE_Error |
|
591 | + */ |
|
592 | + public function get_most_recent_registration_for_event($event_id) |
|
593 | + { |
|
594 | + return $this->get_first_related( |
|
595 | + 'Registration', |
|
596 | + array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')) |
|
597 | + ); |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + /** |
|
602 | + * returns any events attached to this attendee ($_Event property); |
|
603 | + * |
|
604 | + * @return array |
|
605 | + * @throws EE_Error |
|
606 | + */ |
|
607 | + public function events() |
|
608 | + { |
|
609 | + return $this->get_many_related('Event'); |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
615 | + * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
616 | + * used to save the billing info |
|
617 | + * |
|
618 | + * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
619 | + * @return EE_Form_Section_Proper|null |
|
620 | + * @throws EE_Error |
|
621 | + */ |
|
622 | + public function billing_info_for_payment_method($payment_method) |
|
623 | + { |
|
624 | + $pm_type = $payment_method->type_obj(); |
|
625 | + if (! $pm_type instanceof EE_PMT_Base) { |
|
626 | + return null; |
|
627 | + } |
|
628 | + $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
629 | + if (! $billing_info) { |
|
630 | + return null; |
|
631 | + } |
|
632 | + $billing_form = $pm_type->billing_form(); |
|
633 | + // double-check the form isn't totally hidden, in which case pretend there is no form |
|
634 | + $form_totally_hidden = true; |
|
635 | + foreach ($billing_form->inputs_in_subsections() as $input) { |
|
636 | + if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
637 | + $form_totally_hidden = false; |
|
638 | + break; |
|
639 | + } |
|
640 | + } |
|
641 | + if ($form_totally_hidden) { |
|
642 | + return null; |
|
643 | + } |
|
644 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
645 | + $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
646 | + } |
|
647 | + |
|
648 | + return $billing_form; |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + /** |
|
653 | + * Gets the postmeta key that holds this attendee's billing info for the |
|
654 | + * specified payment method |
|
655 | + * |
|
656 | + * @param EE_Payment_Method $payment_method |
|
657 | + * @return string |
|
658 | + * @throws EE_Error |
|
659 | + */ |
|
660 | + public function get_billing_info_postmeta_name($payment_method) |
|
661 | + { |
|
662 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
663 | + return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
664 | + } |
|
665 | + return null; |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + /** |
|
670 | + * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
671 | + * retrieve it |
|
672 | + * |
|
673 | + * @param EE_Billing_Attendee_Info_Form $billing_form |
|
674 | + * @param EE_Payment_Method $payment_method |
|
675 | + * @return boolean |
|
676 | + * @throws EE_Error |
|
677 | + */ |
|
678 | + public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
679 | + { |
|
680 | + if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
681 | + EE_Error::add_error( |
|
682 | + esc_html__('Cannot save billing info because there is none.', 'event_espresso'), |
|
683 | + __FILE__, |
|
684 | + __FUNCTION__, |
|
685 | + __LINE__ |
|
686 | + ); |
|
687 | + return false; |
|
688 | + } |
|
689 | + $billing_form->clean_sensitive_data(); |
|
690 | + return update_post_meta( |
|
691 | + $this->ID(), |
|
692 | + $this->get_billing_info_postmeta_name($payment_method), |
|
693 | + $billing_form->input_values(true) |
|
694 | + ); |
|
695 | + } |
|
696 | + |
|
697 | + |
|
698 | + /** |
|
699 | + * Return the link to the admin details for the object. |
|
700 | + * |
|
701 | + * @return string |
|
702 | + * @throws EE_Error |
|
703 | + * @throws InvalidArgumentException |
|
704 | + * @throws InvalidDataTypeException |
|
705 | + * @throws InvalidInterfaceException |
|
706 | + * @throws ReflectionException |
|
707 | + */ |
|
708 | + public function get_admin_details_link() |
|
709 | + { |
|
710 | + return $this->get_admin_edit_link(); |
|
711 | + } |
|
712 | + |
|
713 | + |
|
714 | + /** |
|
715 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
716 | + * |
|
717 | + * @return string |
|
718 | + * @throws EE_Error |
|
719 | + * @throws InvalidArgumentException |
|
720 | + * @throws ReflectionException |
|
721 | + * @throws InvalidDataTypeException |
|
722 | + * @throws InvalidInterfaceException |
|
723 | + */ |
|
724 | + public function get_admin_edit_link() |
|
725 | + { |
|
726 | + EE_Registry::instance()->load_helper('URL'); |
|
727 | + return EEH_URL::add_query_args_and_nonce( |
|
728 | + array( |
|
729 | + 'page' => 'espresso_registrations', |
|
730 | + 'action' => 'edit_attendee', |
|
731 | + 'post' => $this->ID(), |
|
732 | + ), |
|
733 | + admin_url('admin.php') |
|
734 | + ); |
|
735 | + } |
|
736 | + |
|
737 | + |
|
738 | + /** |
|
739 | + * Returns the link to a settings page for the object. |
|
740 | + * |
|
741 | + * @return string |
|
742 | + * @throws EE_Error |
|
743 | + * @throws InvalidArgumentException |
|
744 | + * @throws InvalidDataTypeException |
|
745 | + * @throws InvalidInterfaceException |
|
746 | + * @throws ReflectionException |
|
747 | + */ |
|
748 | + public function get_admin_settings_link() |
|
749 | + { |
|
750 | + return $this->get_admin_edit_link(); |
|
751 | + } |
|
752 | + |
|
753 | + |
|
754 | + /** |
|
755 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
756 | + * |
|
757 | + * @return string |
|
758 | + * @throws EE_Error |
|
759 | + * @throws InvalidArgumentException |
|
760 | + * @throws ReflectionException |
|
761 | + * @throws InvalidDataTypeException |
|
762 | + * @throws InvalidInterfaceException |
|
763 | + */ |
|
764 | + public function get_admin_overview_link() |
|
765 | + { |
|
766 | + EE_Registry::instance()->load_helper('URL'); |
|
767 | + return EEH_URL::add_query_args_and_nonce( |
|
768 | + array( |
|
769 | + 'page' => 'espresso_registrations', |
|
770 | + 'action' => 'contact_list', |
|
771 | + ), |
|
772 | + admin_url('admin.php') |
|
773 | + ); |
|
774 | + } |
|
775 | 775 | } |
@@ -36,16 +36,16 @@ discard block |
||
36 | 36 | */ |
37 | 37 | protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
38 | 38 | { |
39 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
40 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
39 | + if ( ! isset($fieldValues['ATT_full_name'])) { |
|
40 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'].' ' : ''; |
|
41 | 41 | $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
42 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
42 | + $fieldValues['ATT_full_name'] = $fname.$lname; |
|
43 | 43 | } |
44 | - if (! isset($fieldValues['ATT_slug'])) { |
|
44 | + if ( ! isset($fieldValues['ATT_slug'])) { |
|
45 | 45 | // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
46 | 46 | $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
47 | 47 | } |
48 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
48 | + if ( ! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
49 | 49 | $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
50 | 50 | } |
51 | 51 | parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
326 | 326 | foreach ($initial_address_fields as $address_field_name) { |
327 | 327 | $address_fields_value = $this->get($address_field_name); |
328 | - if (! empty($address_fields_value)) { |
|
328 | + if ( ! empty($address_fields_value)) { |
|
329 | 329 | $full_address_array[] = $address_fields_value; |
330 | 330 | } |
331 | 331 | } |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | } |
341 | 341 | // lastly get the xip |
342 | 342 | $zip_value = $this->zip(); |
343 | - if (! empty($zip_value)) { |
|
343 | + if ( ! empty($zip_value)) { |
|
344 | 344 | $full_address_array[] = $zip_value; |
345 | 345 | } |
346 | 346 | return $full_address_array; |
@@ -622,18 +622,18 @@ discard block |
||
622 | 622 | public function billing_info_for_payment_method($payment_method) |
623 | 623 | { |
624 | 624 | $pm_type = $payment_method->type_obj(); |
625 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
625 | + if ( ! $pm_type instanceof EE_PMT_Base) { |
|
626 | 626 | return null; |
627 | 627 | } |
628 | 628 | $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
629 | - if (! $billing_info) { |
|
629 | + if ( ! $billing_info) { |
|
630 | 630 | return null; |
631 | 631 | } |
632 | 632 | $billing_form = $pm_type->billing_form(); |
633 | 633 | // double-check the form isn't totally hidden, in which case pretend there is no form |
634 | 634 | $form_totally_hidden = true; |
635 | 635 | foreach ($billing_form->inputs_in_subsections() as $input) { |
636 | - if (! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
636 | + if ( ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
637 | 637 | $form_totally_hidden = false; |
638 | 638 | break; |
639 | 639 | } |
@@ -660,7 +660,7 @@ discard block |
||
660 | 660 | public function get_billing_info_postmeta_name($payment_method) |
661 | 661 | { |
662 | 662 | if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
663 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
663 | + return 'billing_info_'.$payment_method->type_obj()->system_name(); |
|
664 | 664 | } |
665 | 665 | return null; |
666 | 666 | } |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | */ |
678 | 678 | public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
679 | 679 | { |
680 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
680 | + if ( ! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
681 | 681 | EE_Error::add_error( |
682 | 682 | esc_html__('Cannot save billing info because there is none.', 'event_espresso'), |
683 | 683 | __FILE__, |
@@ -26,1370 +26,1370 @@ |
||
26 | 26 | */ |
27 | 27 | final class EE_System implements ResettableInterface |
28 | 28 | { |
29 | - /** |
|
30 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
31 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
32 | - */ |
|
33 | - const req_type_normal = 0; |
|
34 | - |
|
35 | - /** |
|
36 | - * Indicates this is a brand new installation of EE so we should install |
|
37 | - * tables and default data etc |
|
38 | - */ |
|
39 | - const req_type_new_activation = 1; |
|
40 | - |
|
41 | - /** |
|
42 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
43 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
44 | - * and that default data is setup too |
|
45 | - */ |
|
46 | - const req_type_reactivation = 2; |
|
47 | - |
|
48 | - /** |
|
49 | - * indicates that EE has been upgraded since its previous request. |
|
50 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
51 | - */ |
|
52 | - const req_type_upgrade = 3; |
|
53 | - |
|
54 | - /** |
|
55 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
56 | - */ |
|
57 | - const req_type_downgrade = 4; |
|
58 | - |
|
59 | - /** |
|
60 | - * @deprecated since version 4.6.0.dev.006 |
|
61 | - * Now whenever a new_activation is detected the request type is still just |
|
62 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
63 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
64 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
65 | - * (Specifically, when the migration manager indicates migrations are finished |
|
66 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
67 | - */ |
|
68 | - const req_type_activation_but_not_installed = 5; |
|
69 | - |
|
70 | - /** |
|
71 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
72 | - */ |
|
73 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
74 | - |
|
75 | - /** |
|
76 | - * @var EE_System $_instance |
|
77 | - */ |
|
78 | - private static $_instance; |
|
79 | - |
|
80 | - /** |
|
81 | - * @var EE_Registry $registry |
|
82 | - */ |
|
83 | - private $registry; |
|
84 | - |
|
85 | - /** |
|
86 | - * @var LoaderInterface $loader |
|
87 | - */ |
|
88 | - private $loader; |
|
89 | - |
|
90 | - /** |
|
91 | - * @var EE_Capabilities $capabilities |
|
92 | - */ |
|
93 | - private $capabilities; |
|
94 | - |
|
95 | - /** |
|
96 | - * @var RequestInterface $request |
|
97 | - */ |
|
98 | - private $request; |
|
99 | - |
|
100 | - /** |
|
101 | - * @var EE_Maintenance_Mode $maintenance_mode |
|
102 | - */ |
|
103 | - private $maintenance_mode; |
|
104 | - |
|
105 | - /** |
|
106 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
107 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
108 | - * |
|
109 | - * @var int $_req_type |
|
110 | - */ |
|
111 | - private $_req_type; |
|
112 | - |
|
113 | - /** |
|
114 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
115 | - * |
|
116 | - * @var boolean $_major_version_change |
|
117 | - */ |
|
118 | - private $_major_version_change = false; |
|
119 | - |
|
120 | - /** |
|
121 | - * A Context DTO dedicated solely to identifying the current request type. |
|
122 | - * |
|
123 | - * @var RequestTypeContextCheckerInterface $request_type |
|
124 | - */ |
|
125 | - private $request_type; |
|
126 | - |
|
127 | - /** |
|
128 | - * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes |
|
129 | - */ |
|
130 | - private $register_custom_post_types; |
|
131 | - |
|
132 | - /** |
|
133 | - * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies |
|
134 | - */ |
|
135 | - private $register_custom_taxonomies; |
|
136 | - |
|
137 | - /** |
|
138 | - * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms |
|
139 | - */ |
|
140 | - private $register_custom_taxonomy_terms; |
|
141 | - |
|
142 | - /** |
|
143 | - * @singleton method used to instantiate class object |
|
144 | - * @param EE_Registry|null $registry |
|
145 | - * @param LoaderInterface|null $loader |
|
146 | - * @param RequestInterface|null $request |
|
147 | - * @param EE_Maintenance_Mode|null $maintenance_mode |
|
148 | - * @return EE_System |
|
149 | - */ |
|
150 | - public static function instance( |
|
151 | - EE_Registry $registry = null, |
|
152 | - LoaderInterface $loader = null, |
|
153 | - RequestInterface $request = null, |
|
154 | - EE_Maintenance_Mode $maintenance_mode = null |
|
155 | - ) { |
|
156 | - // check if class object is instantiated |
|
157 | - if (! self::$_instance instanceof EE_System) { |
|
158 | - self::$_instance = new self($registry, $loader, $request, $maintenance_mode); |
|
159 | - } |
|
160 | - return self::$_instance; |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * resets the instance and returns it |
|
166 | - * |
|
167 | - * @return EE_System |
|
168 | - */ |
|
169 | - public static function reset() |
|
170 | - { |
|
171 | - self::$_instance->_req_type = null; |
|
172 | - // make sure none of the old hooks are left hanging around |
|
173 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
174 | - // we need to reset the migration manager in order for it to detect DMSs properly |
|
175 | - EE_Data_Migration_Manager::reset(); |
|
176 | - self::instance()->detect_activations_or_upgrades(); |
|
177 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
178 | - return self::instance(); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * sets hooks for running rest of system |
|
184 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
185 | - * starting EE Addons from any other point may lead to problems |
|
186 | - * |
|
187 | - * @param EE_Registry $registry |
|
188 | - * @param LoaderInterface $loader |
|
189 | - * @param RequestInterface $request |
|
190 | - * @param EE_Maintenance_Mode $maintenance_mode |
|
191 | - */ |
|
192 | - private function __construct( |
|
193 | - EE_Registry $registry, |
|
194 | - LoaderInterface $loader, |
|
195 | - RequestInterface $request, |
|
196 | - EE_Maintenance_Mode $maintenance_mode |
|
197 | - ) { |
|
198 | - $this->registry = $registry; |
|
199 | - $this->loader = $loader; |
|
200 | - $this->request = $request; |
|
201 | - $this->maintenance_mode = $maintenance_mode; |
|
202 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
203 | - add_action( |
|
204 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
205 | - array($this, 'loadCapabilities'), |
|
206 | - 5 |
|
207 | - ); |
|
208 | - add_action( |
|
209 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
210 | - array($this, 'loadCommandBus'), |
|
211 | - 7 |
|
212 | - ); |
|
213 | - add_action( |
|
214 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
215 | - array($this, 'loadPluginApi'), |
|
216 | - 9 |
|
217 | - ); |
|
218 | - // give caff stuff a chance to play during the activation process too. |
|
219 | - add_action( |
|
220 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
221 | - [$this, 'brewCaffeinated'], |
|
222 | - 9 |
|
223 | - ); |
|
224 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
225 | - add_action( |
|
226 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
227 | - array($this, 'load_espresso_addons') |
|
228 | - ); |
|
229 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
230 | - // because the newly-activated addon didn't get a chance to run at all |
|
231 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
232 | - // detect whether install or upgrade |
|
233 | - add_action( |
|
234 | - 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
235 | - array($this, 'detect_activations_or_upgrades'), |
|
236 | - 3 |
|
237 | - ); |
|
238 | - // load EE_Config, EE_Textdomain, etc |
|
239 | - add_action( |
|
240 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
241 | - array($this, 'load_core_configuration'), |
|
242 | - 5 |
|
243 | - ); |
|
244 | - // load specifications for matching routes to current request |
|
245 | - add_action( |
|
246 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
247 | - array($this, 'loadRouteMatchSpecifications') |
|
248 | - ); |
|
249 | - // load specifications for custom post types |
|
250 | - add_action( |
|
251 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
252 | - array($this, 'loadCustomPostTypes') |
|
253 | - ); |
|
254 | - // load EE_Config, EE_Textdomain, etc |
|
255 | - add_action( |
|
256 | - 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
257 | - array($this, 'register_shortcodes_modules_and_widgets'), |
|
258 | - 7 |
|
259 | - ); |
|
260 | - // you wanna get going? I wanna get going... let's get going! |
|
261 | - add_action( |
|
262 | - 'AHEE__EE_Bootstrap__brew_espresso', |
|
263 | - array($this, 'brew_espresso'), |
|
264 | - 9 |
|
265 | - ); |
|
266 | - // other housekeeping |
|
267 | - // exclude EE critical pages from wp_list_pages |
|
268 | - add_filter( |
|
269 | - 'wp_list_pages_excludes', |
|
270 | - array($this, 'remove_pages_from_wp_list_pages'), |
|
271 | - 10 |
|
272 | - ); |
|
273 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
274 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
275 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * load and setup EE_Capabilities |
|
281 | - * |
|
282 | - * @return void |
|
283 | - * @throws EE_Error |
|
284 | - */ |
|
285 | - public function loadCapabilities() |
|
286 | - { |
|
287 | - $this->capabilities = $this->loader->getShared('EE_Capabilities'); |
|
288 | - add_action( |
|
289 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
290 | - function () { |
|
291 | - LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
292 | - } |
|
293 | - ); |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * create and cache the CommandBus, and also add middleware |
|
299 | - * The CapChecker middleware requires the use of EE_Capabilities |
|
300 | - * which is why we need to load the CommandBus after Caps are set up |
|
301 | - * CommandBus middleware operate FIFO - First In First Out |
|
302 | - * so LocateMovedCommands will run first in order to return any new commands |
|
303 | - * |
|
304 | - * @return void |
|
305 | - * @throws EE_Error |
|
306 | - */ |
|
307 | - public function loadCommandBus() |
|
308 | - { |
|
309 | - $this->loader->getShared( |
|
310 | - 'CommandBusInterface', |
|
311 | - array( |
|
312 | - null, |
|
313 | - apply_filters( |
|
314 | - 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
315 | - array( |
|
316 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\LocateMovedCommands'), |
|
317 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
318 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
319 | - ) |
|
320 | - ), |
|
321 | - ) |
|
322 | - ); |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * @return void |
|
328 | - * @throws EE_Error |
|
329 | - */ |
|
330 | - public function loadPluginApi() |
|
331 | - { |
|
332 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
333 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
334 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
340 | - * that need to be setup before our EE_System launches. |
|
341 | - * |
|
342 | - * @return void |
|
343 | - * @throws DomainException |
|
344 | - * @throws InvalidArgumentException |
|
345 | - * @throws InvalidDataTypeException |
|
346 | - * @throws InvalidInterfaceException |
|
347 | - * @throws InvalidClassException |
|
348 | - * @throws InvalidFilePathException |
|
349 | - * @throws EE_Error |
|
350 | - */ |
|
351 | - public function brewCaffeinated() |
|
352 | - { |
|
353 | - /** @var Domain $domain */ |
|
354 | - $domain = DomainFactory::getShared( |
|
355 | - new FullyQualifiedName( |
|
356 | - 'EventEspresso\core\domain\Domain' |
|
357 | - ), |
|
358 | - [ |
|
359 | - new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
360 | - Version::fromString(espresso_version()), |
|
361 | - ] |
|
362 | - ); |
|
363 | - static $brew; |
|
364 | - if ($domain->isCaffeinated() && ! $brew instanceof EE_Brewing_Regular) { |
|
365 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
366 | - /** @var EE_Brewing_Regular $brew */ |
|
367 | - $brew = LoaderFactory::getLoader()->getShared(EE_Brewing_Regular::class); |
|
368 | - $brew->initializePUE(); |
|
369 | - add_action( |
|
370 | - 'AHEE__EE_System__load_core_configuration__begin', |
|
371 | - [$brew, 'caffeinated'] |
|
372 | - ); |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * @param string $addon_name |
|
379 | - * @param string $version_constant |
|
380 | - * @param string $min_version_required |
|
381 | - * @param string $load_callback |
|
382 | - * @param string $plugin_file_constant |
|
383 | - * @return void |
|
384 | - */ |
|
385 | - private function deactivateIncompatibleAddon( |
|
386 | - $addon_name, |
|
387 | - $version_constant, |
|
388 | - $min_version_required, |
|
389 | - $load_callback, |
|
390 | - $plugin_file_constant |
|
391 | - ) { |
|
392 | - if (! defined($version_constant)) { |
|
393 | - return; |
|
394 | - } |
|
395 | - $addon_version = constant($version_constant); |
|
396 | - if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
|
397 | - remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
|
398 | - if (! function_exists('deactivate_plugins')) { |
|
399 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
400 | - } |
|
401 | - deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
|
402 | - $this->request->unSetRequestParams(['activate', 'activate-multi'], true); |
|
403 | - EE_Error::add_error( |
|
404 | - sprintf( |
|
405 | - esc_html__( |
|
406 | - 'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.', |
|
407 | - 'event_espresso' |
|
408 | - ), |
|
409 | - $addon_name, |
|
410 | - $min_version_required |
|
411 | - ), |
|
412 | - __FILE__, |
|
413 | - __FUNCTION__ . "({$addon_name})", |
|
414 | - __LINE__ |
|
415 | - ); |
|
416 | - EE_Error::get_notices(false, true); |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * load_espresso_addons |
|
423 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
424 | - * this is hooked into both: |
|
425 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
426 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
427 | - * and the WP 'activate_plugin' hook point |
|
428 | - * |
|
429 | - * @access public |
|
430 | - * @return void |
|
431 | - */ |
|
432 | - public function load_espresso_addons() |
|
433 | - { |
|
434 | - $this->deactivateIncompatibleAddon( |
|
435 | - 'Wait Lists', |
|
436 | - 'EE_WAIT_LISTS_VERSION', |
|
437 | - '1.0.0.beta.074', |
|
438 | - 'load_espresso_wait_lists', |
|
439 | - 'EE_WAIT_LISTS_PLUGIN_FILE' |
|
440 | - ); |
|
441 | - $this->deactivateIncompatibleAddon( |
|
442 | - 'Automated Upcoming Event Notifications', |
|
443 | - 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION', |
|
444 | - '1.0.0.beta.091', |
|
445 | - 'load_espresso_automated_upcoming_event_notification', |
|
446 | - 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE' |
|
447 | - ); |
|
448 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
449 | - // if the WP API basic auth plugin isn't already loaded, load it now. |
|
450 | - // We want it for mobile apps. Just include the entire plugin |
|
451 | - // also, don't load the basic auth when a plugin is getting activated, because |
|
452 | - // it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
453 | - // and causes a fatal error |
|
454 | - if ( |
|
455 | - ($this->request->isWordPressApi() || $this->request->isApi()) |
|
456 | - && $this->request->getRequestParam('activate') !== 'true' |
|
457 | - && ! function_exists('json_basic_auth_handler') |
|
458 | - && ! function_exists('json_basic_auth_error') |
|
459 | - && ! in_array( |
|
460 | - $this->request->getRequestParam('action'), |
|
461 | - array('activate', 'activate-selected'), |
|
462 | - true |
|
463 | - ) |
|
464 | - ) { |
|
465 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php'; |
|
466 | - } |
|
467 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - /** |
|
472 | - * detect_activations_or_upgrades |
|
473 | - * Checks for activation or upgrade of core first; |
|
474 | - * then also checks if any registered addons have been activated or upgraded |
|
475 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
476 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
477 | - * |
|
478 | - * @access public |
|
479 | - * @return void |
|
480 | - */ |
|
481 | - public function detect_activations_or_upgrades() |
|
482 | - { |
|
483 | - // first off: let's make sure to handle core |
|
484 | - $this->detect_if_activation_or_upgrade(); |
|
485 | - foreach ($this->registry->addons as $addon) { |
|
486 | - if ($addon instanceof EE_Addon) { |
|
487 | - // detect teh request type for that addon |
|
488 | - $addon->detect_req_type(); |
|
489 | - } |
|
490 | - } |
|
491 | - } |
|
492 | - |
|
493 | - |
|
494 | - /** |
|
495 | - * detect_if_activation_or_upgrade |
|
496 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
497 | - * and either setting up the DB or setting up maintenance mode etc. |
|
498 | - * |
|
499 | - * @access public |
|
500 | - * @return void |
|
501 | - */ |
|
502 | - public function detect_if_activation_or_upgrade() |
|
503 | - { |
|
504 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
505 | - // check if db has been updated, or if its a brand-new installation |
|
506 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
507 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
508 | - // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
509 | - switch ($request_type) { |
|
510 | - case EE_System::req_type_new_activation: |
|
511 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
512 | - $this->_handle_core_version_change($espresso_db_update); |
|
513 | - break; |
|
514 | - case EE_System::req_type_reactivation: |
|
515 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
516 | - $this->_handle_core_version_change($espresso_db_update); |
|
517 | - break; |
|
518 | - case EE_System::req_type_upgrade: |
|
519 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
520 | - // migrations may be required now that we've upgraded |
|
521 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
522 | - $this->_handle_core_version_change($espresso_db_update); |
|
523 | - break; |
|
524 | - case EE_System::req_type_downgrade: |
|
525 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
526 | - // its possible migrations are no longer required |
|
527 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
528 | - $this->_handle_core_version_change($espresso_db_update); |
|
529 | - break; |
|
530 | - case EE_System::req_type_normal: |
|
531 | - default: |
|
532 | - break; |
|
533 | - } |
|
534 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
535 | - } |
|
536 | - |
|
537 | - |
|
538 | - /** |
|
539 | - * Updates the list of installed versions and sets hooks for |
|
540 | - * initializing the database later during the request |
|
541 | - * |
|
542 | - * @param array $espresso_db_update |
|
543 | - */ |
|
544 | - private function _handle_core_version_change($espresso_db_update) |
|
545 | - { |
|
546 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
547 | - // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
548 | - add_action( |
|
549 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
550 | - array($this, 'initialize_db_if_no_migrations_required') |
|
551 | - ); |
|
552 | - } |
|
553 | - |
|
554 | - |
|
555 | - /** |
|
556 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
557 | - * information about what versions of EE have been installed and activated, |
|
558 | - * NOT necessarily the state of the database |
|
559 | - * |
|
560 | - * @param mixed $espresso_db_update the value of the WordPress option. |
|
561 | - * If not supplied, fetches it from the options table |
|
562 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
563 | - */ |
|
564 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
565 | - { |
|
566 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
567 | - if (! $espresso_db_update) { |
|
568 | - $espresso_db_update = get_option('espresso_db_update'); |
|
569 | - } |
|
570 | - // check that option is an array |
|
571 | - if (! is_array($espresso_db_update)) { |
|
572 | - // if option is FALSE, then it never existed |
|
573 | - if ($espresso_db_update === false) { |
|
574 | - // make $espresso_db_update an array and save option with autoload OFF |
|
575 | - $espresso_db_update = array(); |
|
576 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
577 | - } else { |
|
578 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
579 | - $espresso_db_update = array($espresso_db_update => array()); |
|
580 | - update_option('espresso_db_update', $espresso_db_update); |
|
581 | - } |
|
582 | - } else { |
|
583 | - $corrected_db_update = array(); |
|
584 | - // if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
585 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
586 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
587 | - // the key is an int, and the value IS NOT an array |
|
588 | - // so it must be numerically-indexed, where values are versions installed... |
|
589 | - // fix it! |
|
590 | - $version_string = $should_be_array; |
|
591 | - $corrected_db_update[ $version_string ] = array('unknown-date'); |
|
592 | - } else { |
|
593 | - // ok it checks out |
|
594 | - $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
595 | - } |
|
596 | - } |
|
597 | - $espresso_db_update = $corrected_db_update; |
|
598 | - update_option('espresso_db_update', $espresso_db_update); |
|
599 | - } |
|
600 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
601 | - return $espresso_db_update; |
|
602 | - } |
|
603 | - |
|
604 | - |
|
605 | - /** |
|
606 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
607 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
608 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
609 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
610 | - * so that it will be done when migrations are finished |
|
611 | - * |
|
612 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
613 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
614 | - * This is a resource-intensive job |
|
615 | - * so we prefer to only do it when necessary |
|
616 | - * @return void |
|
617 | - * @throws EE_Error |
|
618 | - */ |
|
619 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
620 | - { |
|
621 | - $request_type = $this->detect_req_type(); |
|
622 | - // only initialize system if we're not in maintenance mode. |
|
623 | - if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
624 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
625 | - $rewrite_rules = $this->loader->getShared( |
|
626 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
627 | - ); |
|
628 | - $rewrite_rules->flush(); |
|
629 | - if ($verify_schema) { |
|
630 | - EEH_Activation::initialize_db_and_folders(); |
|
631 | - } |
|
632 | - EEH_Activation::initialize_db_content(); |
|
633 | - EEH_Activation::system_initialization(); |
|
634 | - if ($initialize_addons_too) { |
|
635 | - $this->initialize_addons(); |
|
636 | - } |
|
637 | - } else { |
|
638 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
639 | - } |
|
640 | - if ( |
|
641 | - $request_type === EE_System::req_type_new_activation |
|
642 | - || $request_type === EE_System::req_type_reactivation |
|
643 | - || ( |
|
644 | - $request_type === EE_System::req_type_upgrade |
|
645 | - && $this->is_major_version_change() |
|
646 | - ) |
|
647 | - ) { |
|
648 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
649 | - } |
|
650 | - } |
|
651 | - |
|
652 | - |
|
653 | - /** |
|
654 | - * Initializes the db for all registered addons |
|
655 | - * |
|
656 | - * @throws EE_Error |
|
657 | - */ |
|
658 | - public function initialize_addons() |
|
659 | - { |
|
660 | - // foreach registered addon, make sure its db is up-to-date too |
|
661 | - foreach ($this->registry->addons as $addon) { |
|
662 | - if ($addon instanceof EE_Addon) { |
|
663 | - $addon->initialize_db_if_no_migrations_required(); |
|
664 | - } |
|
665 | - } |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - /** |
|
670 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
671 | - * |
|
672 | - * @param array $version_history |
|
673 | - * @param string $current_version_to_add version to be added to the version history |
|
674 | - * @return boolean success as to whether or not this option was changed |
|
675 | - */ |
|
676 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
677 | - { |
|
678 | - if (! $version_history) { |
|
679 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
680 | - } |
|
681 | - if ($current_version_to_add === null) { |
|
682 | - $current_version_to_add = espresso_version(); |
|
683 | - } |
|
684 | - $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
685 | - // re-save |
|
686 | - return update_option('espresso_db_update', $version_history); |
|
687 | - } |
|
688 | - |
|
689 | - |
|
690 | - /** |
|
691 | - * Detects if the current version indicated in the has existed in the list of |
|
692 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
693 | - * |
|
694 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
695 | - * If not supplied, fetches it from the options table. |
|
696 | - * Also, caches its result so later parts of the code can also know whether |
|
697 | - * there's been an update or not. This way we can add the current version to |
|
698 | - * espresso_db_update, but still know if this is a new install or not |
|
699 | - * @return int one of the constants on EE_System::req_type_ |
|
700 | - */ |
|
701 | - public function detect_req_type($espresso_db_update = null) |
|
702 | - { |
|
703 | - if ($this->_req_type === null) { |
|
704 | - $espresso_db_update = ! empty($espresso_db_update) |
|
705 | - ? $espresso_db_update |
|
706 | - : $this->fix_espresso_db_upgrade_option(); |
|
707 | - $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
708 | - $espresso_db_update, |
|
709 | - 'ee_espresso_activation', |
|
710 | - espresso_version() |
|
711 | - ); |
|
712 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
713 | - $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal); |
|
714 | - } |
|
715 | - return $this->_req_type; |
|
716 | - } |
|
717 | - |
|
718 | - |
|
719 | - /** |
|
720 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
721 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
722 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
723 | - * |
|
724 | - * @param $activation_history |
|
725 | - * @return bool |
|
726 | - */ |
|
727 | - private function _detect_major_version_change($activation_history) |
|
728 | - { |
|
729 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
730 | - $previous_version_parts = explode('.', $previous_version); |
|
731 | - $current_version_parts = explode('.', espresso_version()); |
|
732 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
733 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
734 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
735 | - ); |
|
736 | - } |
|
737 | - |
|
738 | - |
|
739 | - /** |
|
740 | - * Returns true if either the major or minor version of EE changed during this request. |
|
741 | - * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
742 | - * |
|
743 | - * @return bool |
|
744 | - */ |
|
745 | - public function is_major_version_change() |
|
746 | - { |
|
747 | - return $this->_major_version_change; |
|
748 | - } |
|
749 | - |
|
750 | - |
|
751 | - /** |
|
752 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
753 | - * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
754 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
755 | - * just activated to (for core that will always be espresso_version()) |
|
756 | - * |
|
757 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
758 | - * ee plugin. for core that's 'espresso_db_update' |
|
759 | - * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
760 | - * indicate that this plugin was just activated |
|
761 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
762 | - * espresso_version()) |
|
763 | - * @return int one of the constants on EE_System::req_type_* |
|
764 | - */ |
|
765 | - public static function detect_req_type_given_activation_history( |
|
766 | - $activation_history_for_addon, |
|
767 | - $activation_indicator_option_name, |
|
768 | - $version_to_upgrade_to |
|
769 | - ) { |
|
770 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
771 | - if ($activation_history_for_addon) { |
|
772 | - // it exists, so this isn't a completely new install |
|
773 | - // check if this version already in that list of previously installed versions |
|
774 | - if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { |
|
775 | - // it a version we haven't seen before |
|
776 | - if ($version_is_higher === 1) { |
|
777 | - $req_type = EE_System::req_type_upgrade; |
|
778 | - } else { |
|
779 | - $req_type = EE_System::req_type_downgrade; |
|
780 | - } |
|
781 | - delete_option($activation_indicator_option_name); |
|
782 | - } else { |
|
783 | - // its not an update. maybe a reactivation? |
|
784 | - if (get_option($activation_indicator_option_name, false)) { |
|
785 | - if ($version_is_higher === -1) { |
|
786 | - $req_type = EE_System::req_type_downgrade; |
|
787 | - } elseif ($version_is_higher === 0) { |
|
788 | - // we've seen this version before, but it's an activation. must be a reactivation |
|
789 | - $req_type = EE_System::req_type_reactivation; |
|
790 | - } else {// $version_is_higher === 1 |
|
791 | - $req_type = EE_System::req_type_upgrade; |
|
792 | - } |
|
793 | - delete_option($activation_indicator_option_name); |
|
794 | - } else { |
|
795 | - // we've seen this version before and the activation indicate doesn't show it was just activated |
|
796 | - if ($version_is_higher === -1) { |
|
797 | - $req_type = EE_System::req_type_downgrade; |
|
798 | - } elseif ($version_is_higher === 0) { |
|
799 | - // we've seen this version before and it's not an activation. its normal request |
|
800 | - $req_type = EE_System::req_type_normal; |
|
801 | - } else {// $version_is_higher === 1 |
|
802 | - $req_type = EE_System::req_type_upgrade; |
|
803 | - } |
|
804 | - } |
|
805 | - } |
|
806 | - } else { |
|
807 | - // brand new install |
|
808 | - $req_type = EE_System::req_type_new_activation; |
|
809 | - delete_option($activation_indicator_option_name); |
|
810 | - } |
|
811 | - return $req_type; |
|
812 | - } |
|
813 | - |
|
814 | - |
|
815 | - /** |
|
816 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
817 | - * the $activation_history_for_addon |
|
818 | - * |
|
819 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
820 | - * sometimes containing 'unknown-date' |
|
821 | - * @param string $version_to_upgrade_to (current version) |
|
822 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
823 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
824 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
825 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
826 | - */ |
|
827 | - private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
828 | - { |
|
829 | - // find the most recently-activated version |
|
830 | - $most_recently_active_version = |
|
831 | - EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
832 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
833 | - } |
|
834 | - |
|
835 | - |
|
836 | - /** |
|
837 | - * Gets the most recently active version listed in the activation history, |
|
838 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
839 | - * |
|
840 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
841 | - * sometimes containing 'unknown-date' |
|
842 | - * @return string |
|
843 | - */ |
|
844 | - private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
845 | - { |
|
846 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
847 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
848 | - if (is_array($activation_history)) { |
|
849 | - foreach ($activation_history as $version => $times_activated) { |
|
850 | - // check there is a record of when this version was activated. Otherwise, |
|
851 | - // mark it as unknown |
|
852 | - if (! $times_activated) { |
|
853 | - $times_activated = array('unknown-date'); |
|
854 | - } |
|
855 | - if (is_string($times_activated)) { |
|
856 | - $times_activated = array($times_activated); |
|
857 | - } |
|
858 | - foreach ($times_activated as $an_activation) { |
|
859 | - if ( |
|
860 | - $an_activation !== 'unknown-date' |
|
861 | - && $an_activation |
|
862 | - > $most_recently_active_version_activation |
|
863 | - ) { |
|
864 | - $most_recently_active_version = $version; |
|
865 | - $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
866 | - ? '1970-01-01 00:00:00' |
|
867 | - : $an_activation; |
|
868 | - } |
|
869 | - } |
|
870 | - } |
|
871 | - } |
|
872 | - return $most_recently_active_version; |
|
873 | - } |
|
874 | - |
|
875 | - |
|
876 | - /** |
|
877 | - * This redirects to the about EE page after activation |
|
878 | - * |
|
879 | - * @return void |
|
880 | - */ |
|
881 | - public function redirect_to_about_ee() |
|
882 | - { |
|
883 | - $notices = EE_Error::get_notices(false); |
|
884 | - // if current user is an admin and it's not an ajax or rest request |
|
885 | - if ( |
|
886 | - ! isset($notices['errors']) |
|
887 | - && $this->request->isAdmin() |
|
888 | - && apply_filters( |
|
889 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
890 | - $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
891 | - ) |
|
892 | - ) { |
|
893 | - $query_params = array('page' => 'espresso_about'); |
|
894 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
895 | - $query_params['new_activation'] = true; |
|
896 | - } |
|
897 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
898 | - $query_params['reactivation'] = true; |
|
899 | - } |
|
900 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
901 | - wp_safe_redirect($url); |
|
902 | - exit(); |
|
903 | - } |
|
904 | - } |
|
905 | - |
|
906 | - |
|
907 | - /** |
|
908 | - * load_core_configuration |
|
909 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
910 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
911 | - * |
|
912 | - * @return void |
|
913 | - * @throws ReflectionException |
|
914 | - * @throws Exception |
|
915 | - */ |
|
916 | - public function load_core_configuration() |
|
917 | - { |
|
918 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
919 | - $this->loader->getShared('EE_Load_Textdomain'); |
|
920 | - // load textdomain |
|
921 | - EE_Load_Textdomain::load_textdomain(); |
|
922 | - // load and setup EE_Config and EE_Network_Config |
|
923 | - $config = $this->loader->getShared('EE_Config'); |
|
924 | - $this->loader->getShared('EE_Network_Config'); |
|
925 | - // setup autoloaders |
|
926 | - // enable logging? |
|
927 | - $this->loader->getShared('EventEspresso\core\services\orm\TrashLogger'); |
|
928 | - if ($config->admin->use_remote_logging) { |
|
929 | - $this->loader->getShared('EE_Log'); |
|
930 | - } |
|
931 | - // check for activation errors |
|
932 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
933 | - if ($activation_errors) { |
|
934 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
935 | - update_option('ee_plugin_activation_errors', false); |
|
936 | - } |
|
937 | - // get model names |
|
938 | - $this->_parse_model_names(); |
|
939 | - // configure custom post type definitions |
|
940 | - $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'); |
|
941 | - $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'); |
|
942 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
943 | - } |
|
944 | - |
|
945 | - |
|
946 | - /** |
|
947 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
948 | - * |
|
949 | - * @return void |
|
950 | - * @throws ReflectionException |
|
951 | - */ |
|
952 | - private function _parse_model_names() |
|
953 | - { |
|
954 | - // get all the files in the EE_MODELS folder that end in .model.php |
|
955 | - $models = glob(EE_MODELS . '*.model.php'); |
|
956 | - $model_names = array(); |
|
957 | - $non_abstract_db_models = array(); |
|
958 | - foreach ($models as $model) { |
|
959 | - // get model classname |
|
960 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
961 | - $short_name = str_replace('EEM_', '', $classname); |
|
962 | - $reflectionClass = new ReflectionClass($classname); |
|
963 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
964 | - $non_abstract_db_models[ $short_name ] = $classname; |
|
965 | - } |
|
966 | - $model_names[ $short_name ] = $classname; |
|
967 | - } |
|
968 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
969 | - $this->registry->non_abstract_db_models = apply_filters( |
|
970 | - 'FHEE__EE_System__parse_implemented_model_names', |
|
971 | - $non_abstract_db_models |
|
972 | - ); |
|
973 | - } |
|
974 | - |
|
975 | - |
|
976 | - /** |
|
977 | - * @since 4.9.71.p |
|
978 | - * @throws Exception |
|
979 | - */ |
|
980 | - public function loadRouteMatchSpecifications() |
|
981 | - { |
|
982 | - try { |
|
983 | - $this->loader->getShared( |
|
984 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' |
|
985 | - ); |
|
986 | - } catch (Exception $exception) { |
|
987 | - new ExceptionStackTraceDisplay($exception); |
|
988 | - } |
|
989 | - do_action('AHEE__EE_System__loadRouteMatchSpecifications'); |
|
990 | - } |
|
991 | - |
|
992 | - |
|
993 | - /** |
|
994 | - * loading CPT related classes earlier so that their definitions are available |
|
995 | - * but not performing any actual registration with WP core until load_CPTs_and_session() is called |
|
996 | - * |
|
997 | - * @since 4.10.21.p |
|
998 | - */ |
|
999 | - public function loadCustomPostTypes() |
|
1000 | - { |
|
1001 | - $this->register_custom_taxonomies = $this->loader->getShared( |
|
1002 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' |
|
1003 | - ); |
|
1004 | - $this->register_custom_post_types = $this->loader->getShared( |
|
1005 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' |
|
1006 | - ); |
|
1007 | - $this->register_custom_taxonomy_terms = $this->loader->getShared( |
|
1008 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms' |
|
1009 | - ); |
|
1010 | - // integrate WP_Query with the EE models |
|
1011 | - $this->loader->getShared('EE_CPT_Strategy'); |
|
1012 | - // load legacy EE_Request_Handler in case add-ons still need it |
|
1013 | - $this->loader->getShared('EE_Request_Handler'); |
|
1014 | - } |
|
1015 | - |
|
1016 | - |
|
1017 | - /** |
|
1018 | - * register_shortcodes_modules_and_widgets |
|
1019 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
1020 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
1021 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
1022 | - * |
|
1023 | - * @access public |
|
1024 | - * @return void |
|
1025 | - * @throws Exception |
|
1026 | - */ |
|
1027 | - public function register_shortcodes_modules_and_widgets() |
|
1028 | - { |
|
1029 | - if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAjax()) { |
|
1030 | - // load, register, and add shortcodes the new way |
|
1031 | - $this->loader->getShared('EventEspresso\core\services\shortcodes\ShortcodesManager'); |
|
1032 | - } |
|
1033 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
1034 | - // check for addons using old hook point |
|
1035 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
1036 | - $this->_incompatible_addon_error(); |
|
1037 | - } |
|
1038 | - } |
|
1039 | - |
|
1040 | - |
|
1041 | - /** |
|
1042 | - * _incompatible_addon_error |
|
1043 | - * |
|
1044 | - * @access public |
|
1045 | - * @return void |
|
1046 | - */ |
|
1047 | - private function _incompatible_addon_error() |
|
1048 | - { |
|
1049 | - // get array of classes hooking into here |
|
1050 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
1051 | - 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
1052 | - ); |
|
1053 | - if (! empty($class_names)) { |
|
1054 | - $msg = esc_html__( |
|
1055 | - 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
1056 | - 'event_espresso' |
|
1057 | - ); |
|
1058 | - $msg .= '<ul>'; |
|
1059 | - foreach ($class_names as $class_name) { |
|
1060 | - $msg .= '<li><b>Event Espresso - ' |
|
1061 | - . str_replace( |
|
1062 | - array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), |
|
1063 | - '', |
|
1064 | - $class_name |
|
1065 | - ) . '</b></li>'; |
|
1066 | - } |
|
1067 | - $msg .= '</ul>'; |
|
1068 | - $msg .= esc_html__( |
|
1069 | - 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
1070 | - 'event_espresso' |
|
1071 | - ); |
|
1072 | - // save list of incompatible addons to wp-options for later use |
|
1073 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
1074 | - if (is_admin()) { |
|
1075 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1076 | - } |
|
1077 | - } |
|
1078 | - } |
|
1079 | - |
|
1080 | - |
|
1081 | - /** |
|
1082 | - * brew_espresso |
|
1083 | - * begins the process of setting hooks for initializing EE in the correct order |
|
1084 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
1085 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
1086 | - * |
|
1087 | - * @return void |
|
1088 | - */ |
|
1089 | - public function brew_espresso() |
|
1090 | - { |
|
1091 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
1092 | - // load some final core systems |
|
1093 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
1094 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
1095 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
1096 | - add_action('init', array($this, 'load_controllers'), 7); |
|
1097 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
1098 | - add_action('init', array($this, 'initialize'), 10); |
|
1099 | - add_action('init', array($this, 'initialize_last'), 100); |
|
1100 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
1101 | - } |
|
1102 | - |
|
1103 | - |
|
1104 | - /** |
|
1105 | - * set_hooks_for_core |
|
1106 | - * |
|
1107 | - * @access public |
|
1108 | - * @return void |
|
1109 | - * @throws EE_Error |
|
1110 | - */ |
|
1111 | - public function set_hooks_for_core() |
|
1112 | - { |
|
1113 | - $this->_deactivate_incompatible_addons(); |
|
1114 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
1115 | - $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan'); |
|
1116 | - // caps need to be initialized on every request so that capability maps are set. |
|
1117 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
1118 | - $this->registry->CAP->init_caps(); |
|
1119 | - } |
|
1120 | - |
|
1121 | - |
|
1122 | - /** |
|
1123 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
1124 | - * deactivates any addons considered incompatible with the current version of EE |
|
1125 | - */ |
|
1126 | - private function _deactivate_incompatible_addons() |
|
1127 | - { |
|
1128 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
1129 | - if (! empty($incompatible_addons)) { |
|
1130 | - $active_plugins = get_option('active_plugins', array()); |
|
1131 | - foreach ($active_plugins as $active_plugin) { |
|
1132 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
1133 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
1134 | - $this->request->unSetRequestParams(['activate'], true); |
|
1135 | - espresso_deactivate_plugin($active_plugin); |
|
1136 | - } |
|
1137 | - } |
|
1138 | - } |
|
1139 | - } |
|
1140 | - } |
|
1141 | - |
|
1142 | - |
|
1143 | - /** |
|
1144 | - * perform_activations_upgrades_and_migrations |
|
1145 | - * |
|
1146 | - * @access public |
|
1147 | - * @return void |
|
1148 | - */ |
|
1149 | - public function perform_activations_upgrades_and_migrations() |
|
1150 | - { |
|
1151 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
1152 | - } |
|
1153 | - |
|
1154 | - |
|
1155 | - /** |
|
1156 | - * @return void |
|
1157 | - * @throws DomainException |
|
1158 | - */ |
|
1159 | - public function load_CPTs_and_session() |
|
1160 | - { |
|
1161 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
1162 | - $this->register_custom_taxonomies->registerCustomTaxonomies(); |
|
1163 | - $this->register_custom_post_types->registerCustomPostTypes(); |
|
1164 | - $this->register_custom_taxonomy_terms->registerCustomTaxonomyTerms(); |
|
1165 | - // load legacy Custom Post Types and Taxonomies |
|
1166 | - $this->loader->getShared('EE_Register_CPTs'); |
|
1167 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
1168 | - } |
|
1169 | - |
|
1170 | - |
|
1171 | - /** |
|
1172 | - * load_controllers |
|
1173 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
1174 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
1175 | - * time |
|
1176 | - * |
|
1177 | - * @access public |
|
1178 | - * @return void |
|
1179 | - */ |
|
1180 | - public function load_controllers() |
|
1181 | - { |
|
1182 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
1183 | - // let's get it started |
|
1184 | - if ( |
|
1185 | - ! $this->maintenance_mode->level() |
|
1186 | - && ($this->request->isFrontend() || $this->request->isFrontAjax()) |
|
1187 | - ) { |
|
1188 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
1189 | - $this->loader->getShared('EE_Front_Controller'); |
|
1190 | - } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) { |
|
1191 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
1192 | - $this->loader->getShared('EE_Admin'); |
|
1193 | - } elseif ($this->request->isWordPressHeartbeat()) { |
|
1194 | - $this->loader->getShared('EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat'); |
|
1195 | - } |
|
1196 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
1197 | - } |
|
1198 | - |
|
1199 | - |
|
1200 | - /** |
|
1201 | - * core_loaded_and_ready |
|
1202 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
1203 | - * |
|
1204 | - * @access public |
|
1205 | - * @return void |
|
1206 | - * @throws Exception |
|
1207 | - */ |
|
1208 | - public function core_loaded_and_ready() |
|
1209 | - { |
|
1210 | - if ( |
|
1211 | - $this->request->isAdmin() |
|
1212 | - || $this->request->isFrontend() |
|
1213 | - || $this->request->isIframe() |
|
1214 | - || $this->request->isWordPressApi() |
|
1215 | - ) { |
|
1216 | - try { |
|
1217 | - $this->loader->getShared('EventEspresso\core\services\assets\I18nRegistry', [[]]); |
|
1218 | - $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
1219 | - $this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager'); |
|
1220 | - if ($this->canLoadBlocks()) { |
|
1221 | - $this->loader->getShared( |
|
1222 | - 'EventEspresso\core\services\editor\BlockRegistrationManager' |
|
1223 | - ); |
|
1224 | - } |
|
1225 | - } catch (Exception $exception) { |
|
1226 | - new ExceptionStackTraceDisplay($exception); |
|
1227 | - } |
|
1228 | - } |
|
1229 | - if ( |
|
1230 | - $this->request->isAdmin() |
|
1231 | - || $this->request->isEeAjax() |
|
1232 | - || $this->request->isFrontend() |
|
1233 | - ) { |
|
1234 | - $this->loader->getShared('EE_Session'); |
|
1235 | - } |
|
1236 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
1237 | - // always load template tags, because it's faster than checking if it's a front-end request, and many page |
|
1238 | - // builders require these even on the front-end |
|
1239 | - require_once EE_PUBLIC . 'template_tags.php'; |
|
1240 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
1241 | - } |
|
1242 | - |
|
1243 | - |
|
1244 | - /** |
|
1245 | - * initialize |
|
1246 | - * this is the best place to begin initializing client code |
|
1247 | - * |
|
1248 | - * @access public |
|
1249 | - * @return void |
|
1250 | - */ |
|
1251 | - public function initialize() |
|
1252 | - { |
|
1253 | - do_action('AHEE__EE_System__initialize'); |
|
1254 | - add_filter( |
|
1255 | - 'safe_style_css', |
|
1256 | - function ($styles) { |
|
1257 | - $styles[] = 'display'; |
|
1258 | - $styles[] = 'visibility'; |
|
1259 | - $styles[] = 'position'; |
|
1260 | - $styles[] = 'top'; |
|
1261 | - $styles[] = 'right'; |
|
1262 | - $styles[] = 'bottom'; |
|
1263 | - $styles[] = 'left'; |
|
1264 | - $styles[] = 'resize'; |
|
1265 | - $styles[] = 'max-width'; |
|
1266 | - $styles[] = 'max-height'; |
|
1267 | - return $styles; |
|
1268 | - } |
|
1269 | - ); |
|
1270 | - } |
|
1271 | - |
|
1272 | - |
|
1273 | - /** |
|
1274 | - * initialize_last |
|
1275 | - * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
1276 | - * initialize has done so |
|
1277 | - * |
|
1278 | - * @access public |
|
1279 | - * @return void |
|
1280 | - */ |
|
1281 | - public function initialize_last() |
|
1282 | - { |
|
1283 | - do_action('AHEE__EE_System__initialize_last'); |
|
1284 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
1285 | - $rewrite_rules = $this->loader->getShared( |
|
1286 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
1287 | - ); |
|
1288 | - $rewrite_rules->flushRewriteRules(); |
|
1289 | - add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
1290 | - if ( |
|
1291 | - ($this->request->isAjax() || $this->request->isAdmin()) |
|
1292 | - && $this->maintenance_mode->models_can_query() |
|
1293 | - ) { |
|
1294 | - $this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager'); |
|
1295 | - $this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager'); |
|
1296 | - } |
|
1297 | - } |
|
1298 | - |
|
1299 | - |
|
1300 | - /** |
|
1301 | - * @return void |
|
1302 | - * @throws EE_Error |
|
1303 | - */ |
|
1304 | - public function addEspressoToolbar() |
|
1305 | - { |
|
1306 | - $this->loader->getShared( |
|
1307 | - 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
1308 | - array($this->registry->CAP) |
|
1309 | - ); |
|
1310 | - } |
|
1311 | - |
|
1312 | - |
|
1313 | - /** |
|
1314 | - * do_not_cache |
|
1315 | - * sets no cache headers and defines no cache constants for WP plugins |
|
1316 | - * |
|
1317 | - * @access public |
|
1318 | - * @return void |
|
1319 | - */ |
|
1320 | - public static function do_not_cache() |
|
1321 | - { |
|
1322 | - // set no cache constants |
|
1323 | - if (! defined('DONOTCACHEPAGE')) { |
|
1324 | - define('DONOTCACHEPAGE', true); |
|
1325 | - } |
|
1326 | - if (! defined('DONOTCACHCEOBJECT')) { |
|
1327 | - define('DONOTCACHCEOBJECT', true); |
|
1328 | - } |
|
1329 | - if (! defined('DONOTCACHEDB')) { |
|
1330 | - define('DONOTCACHEDB', true); |
|
1331 | - } |
|
1332 | - // add no cache headers |
|
1333 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1334 | - // plus a little extra for nginx and Google Chrome |
|
1335 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1336 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1337 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1338 | - } |
|
1339 | - |
|
1340 | - |
|
1341 | - /** |
|
1342 | - * extra_nocache_headers |
|
1343 | - * |
|
1344 | - * @access public |
|
1345 | - * @param $headers |
|
1346 | - * @return array |
|
1347 | - */ |
|
1348 | - public static function extra_nocache_headers($headers) |
|
1349 | - { |
|
1350 | - // for NGINX |
|
1351 | - $headers['X-Accel-Expires'] = 0; |
|
1352 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1353 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1354 | - return $headers; |
|
1355 | - } |
|
1356 | - |
|
1357 | - |
|
1358 | - /** |
|
1359 | - * nocache_headers |
|
1360 | - * |
|
1361 | - * @access public |
|
1362 | - * @return void |
|
1363 | - */ |
|
1364 | - public static function nocache_headers() |
|
1365 | - { |
|
1366 | - nocache_headers(); |
|
1367 | - } |
|
1368 | - |
|
1369 | - |
|
1370 | - /** |
|
1371 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1372 | - * never returned with the function. |
|
1373 | - * |
|
1374 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
1375 | - * @return array |
|
1376 | - */ |
|
1377 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
1378 | - { |
|
1379 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1380 | - } |
|
1381 | - |
|
1382 | - |
|
1383 | - /** |
|
1384 | - * Return whether blocks can be registered/loaded or not. |
|
1385 | - * @return bool |
|
1386 | - */ |
|
1387 | - private function canLoadBlocks() |
|
1388 | - { |
|
1389 | - return apply_filters('FHEE__EE_System__canLoadBlocks', true) |
|
1390 | - && function_exists('register_block_type') |
|
1391 | - // don't load blocks if in the Divi page builder editor context |
|
1392 | - // @see https://github.com/eventespresso/event-espresso-core/issues/814 |
|
1393 | - && ! $this->request->getRequestParam('et_fb', false); |
|
1394 | - } |
|
29 | + /** |
|
30 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
31 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
32 | + */ |
|
33 | + const req_type_normal = 0; |
|
34 | + |
|
35 | + /** |
|
36 | + * Indicates this is a brand new installation of EE so we should install |
|
37 | + * tables and default data etc |
|
38 | + */ |
|
39 | + const req_type_new_activation = 1; |
|
40 | + |
|
41 | + /** |
|
42 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
43 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
44 | + * and that default data is setup too |
|
45 | + */ |
|
46 | + const req_type_reactivation = 2; |
|
47 | + |
|
48 | + /** |
|
49 | + * indicates that EE has been upgraded since its previous request. |
|
50 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
51 | + */ |
|
52 | + const req_type_upgrade = 3; |
|
53 | + |
|
54 | + /** |
|
55 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
56 | + */ |
|
57 | + const req_type_downgrade = 4; |
|
58 | + |
|
59 | + /** |
|
60 | + * @deprecated since version 4.6.0.dev.006 |
|
61 | + * Now whenever a new_activation is detected the request type is still just |
|
62 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
63 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
64 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
65 | + * (Specifically, when the migration manager indicates migrations are finished |
|
66 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
67 | + */ |
|
68 | + const req_type_activation_but_not_installed = 5; |
|
69 | + |
|
70 | + /** |
|
71 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
72 | + */ |
|
73 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
74 | + |
|
75 | + /** |
|
76 | + * @var EE_System $_instance |
|
77 | + */ |
|
78 | + private static $_instance; |
|
79 | + |
|
80 | + /** |
|
81 | + * @var EE_Registry $registry |
|
82 | + */ |
|
83 | + private $registry; |
|
84 | + |
|
85 | + /** |
|
86 | + * @var LoaderInterface $loader |
|
87 | + */ |
|
88 | + private $loader; |
|
89 | + |
|
90 | + /** |
|
91 | + * @var EE_Capabilities $capabilities |
|
92 | + */ |
|
93 | + private $capabilities; |
|
94 | + |
|
95 | + /** |
|
96 | + * @var RequestInterface $request |
|
97 | + */ |
|
98 | + private $request; |
|
99 | + |
|
100 | + /** |
|
101 | + * @var EE_Maintenance_Mode $maintenance_mode |
|
102 | + */ |
|
103 | + private $maintenance_mode; |
|
104 | + |
|
105 | + /** |
|
106 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
107 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
108 | + * |
|
109 | + * @var int $_req_type |
|
110 | + */ |
|
111 | + private $_req_type; |
|
112 | + |
|
113 | + /** |
|
114 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
115 | + * |
|
116 | + * @var boolean $_major_version_change |
|
117 | + */ |
|
118 | + private $_major_version_change = false; |
|
119 | + |
|
120 | + /** |
|
121 | + * A Context DTO dedicated solely to identifying the current request type. |
|
122 | + * |
|
123 | + * @var RequestTypeContextCheckerInterface $request_type |
|
124 | + */ |
|
125 | + private $request_type; |
|
126 | + |
|
127 | + /** |
|
128 | + * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes |
|
129 | + */ |
|
130 | + private $register_custom_post_types; |
|
131 | + |
|
132 | + /** |
|
133 | + * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies |
|
134 | + */ |
|
135 | + private $register_custom_taxonomies; |
|
136 | + |
|
137 | + /** |
|
138 | + * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms |
|
139 | + */ |
|
140 | + private $register_custom_taxonomy_terms; |
|
141 | + |
|
142 | + /** |
|
143 | + * @singleton method used to instantiate class object |
|
144 | + * @param EE_Registry|null $registry |
|
145 | + * @param LoaderInterface|null $loader |
|
146 | + * @param RequestInterface|null $request |
|
147 | + * @param EE_Maintenance_Mode|null $maintenance_mode |
|
148 | + * @return EE_System |
|
149 | + */ |
|
150 | + public static function instance( |
|
151 | + EE_Registry $registry = null, |
|
152 | + LoaderInterface $loader = null, |
|
153 | + RequestInterface $request = null, |
|
154 | + EE_Maintenance_Mode $maintenance_mode = null |
|
155 | + ) { |
|
156 | + // check if class object is instantiated |
|
157 | + if (! self::$_instance instanceof EE_System) { |
|
158 | + self::$_instance = new self($registry, $loader, $request, $maintenance_mode); |
|
159 | + } |
|
160 | + return self::$_instance; |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * resets the instance and returns it |
|
166 | + * |
|
167 | + * @return EE_System |
|
168 | + */ |
|
169 | + public static function reset() |
|
170 | + { |
|
171 | + self::$_instance->_req_type = null; |
|
172 | + // make sure none of the old hooks are left hanging around |
|
173 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
174 | + // we need to reset the migration manager in order for it to detect DMSs properly |
|
175 | + EE_Data_Migration_Manager::reset(); |
|
176 | + self::instance()->detect_activations_or_upgrades(); |
|
177 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
178 | + return self::instance(); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * sets hooks for running rest of system |
|
184 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
185 | + * starting EE Addons from any other point may lead to problems |
|
186 | + * |
|
187 | + * @param EE_Registry $registry |
|
188 | + * @param LoaderInterface $loader |
|
189 | + * @param RequestInterface $request |
|
190 | + * @param EE_Maintenance_Mode $maintenance_mode |
|
191 | + */ |
|
192 | + private function __construct( |
|
193 | + EE_Registry $registry, |
|
194 | + LoaderInterface $loader, |
|
195 | + RequestInterface $request, |
|
196 | + EE_Maintenance_Mode $maintenance_mode |
|
197 | + ) { |
|
198 | + $this->registry = $registry; |
|
199 | + $this->loader = $loader; |
|
200 | + $this->request = $request; |
|
201 | + $this->maintenance_mode = $maintenance_mode; |
|
202 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
203 | + add_action( |
|
204 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
205 | + array($this, 'loadCapabilities'), |
|
206 | + 5 |
|
207 | + ); |
|
208 | + add_action( |
|
209 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
210 | + array($this, 'loadCommandBus'), |
|
211 | + 7 |
|
212 | + ); |
|
213 | + add_action( |
|
214 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
215 | + array($this, 'loadPluginApi'), |
|
216 | + 9 |
|
217 | + ); |
|
218 | + // give caff stuff a chance to play during the activation process too. |
|
219 | + add_action( |
|
220 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
221 | + [$this, 'brewCaffeinated'], |
|
222 | + 9 |
|
223 | + ); |
|
224 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
225 | + add_action( |
|
226 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
227 | + array($this, 'load_espresso_addons') |
|
228 | + ); |
|
229 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
230 | + // because the newly-activated addon didn't get a chance to run at all |
|
231 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
232 | + // detect whether install or upgrade |
|
233 | + add_action( |
|
234 | + 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
235 | + array($this, 'detect_activations_or_upgrades'), |
|
236 | + 3 |
|
237 | + ); |
|
238 | + // load EE_Config, EE_Textdomain, etc |
|
239 | + add_action( |
|
240 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
241 | + array($this, 'load_core_configuration'), |
|
242 | + 5 |
|
243 | + ); |
|
244 | + // load specifications for matching routes to current request |
|
245 | + add_action( |
|
246 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
247 | + array($this, 'loadRouteMatchSpecifications') |
|
248 | + ); |
|
249 | + // load specifications for custom post types |
|
250 | + add_action( |
|
251 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
252 | + array($this, 'loadCustomPostTypes') |
|
253 | + ); |
|
254 | + // load EE_Config, EE_Textdomain, etc |
|
255 | + add_action( |
|
256 | + 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
257 | + array($this, 'register_shortcodes_modules_and_widgets'), |
|
258 | + 7 |
|
259 | + ); |
|
260 | + // you wanna get going? I wanna get going... let's get going! |
|
261 | + add_action( |
|
262 | + 'AHEE__EE_Bootstrap__brew_espresso', |
|
263 | + array($this, 'brew_espresso'), |
|
264 | + 9 |
|
265 | + ); |
|
266 | + // other housekeeping |
|
267 | + // exclude EE critical pages from wp_list_pages |
|
268 | + add_filter( |
|
269 | + 'wp_list_pages_excludes', |
|
270 | + array($this, 'remove_pages_from_wp_list_pages'), |
|
271 | + 10 |
|
272 | + ); |
|
273 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
274 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
275 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * load and setup EE_Capabilities |
|
281 | + * |
|
282 | + * @return void |
|
283 | + * @throws EE_Error |
|
284 | + */ |
|
285 | + public function loadCapabilities() |
|
286 | + { |
|
287 | + $this->capabilities = $this->loader->getShared('EE_Capabilities'); |
|
288 | + add_action( |
|
289 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
290 | + function () { |
|
291 | + LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
292 | + } |
|
293 | + ); |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * create and cache the CommandBus, and also add middleware |
|
299 | + * The CapChecker middleware requires the use of EE_Capabilities |
|
300 | + * which is why we need to load the CommandBus after Caps are set up |
|
301 | + * CommandBus middleware operate FIFO - First In First Out |
|
302 | + * so LocateMovedCommands will run first in order to return any new commands |
|
303 | + * |
|
304 | + * @return void |
|
305 | + * @throws EE_Error |
|
306 | + */ |
|
307 | + public function loadCommandBus() |
|
308 | + { |
|
309 | + $this->loader->getShared( |
|
310 | + 'CommandBusInterface', |
|
311 | + array( |
|
312 | + null, |
|
313 | + apply_filters( |
|
314 | + 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
315 | + array( |
|
316 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\LocateMovedCommands'), |
|
317 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
318 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
319 | + ) |
|
320 | + ), |
|
321 | + ) |
|
322 | + ); |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * @return void |
|
328 | + * @throws EE_Error |
|
329 | + */ |
|
330 | + public function loadPluginApi() |
|
331 | + { |
|
332 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
333 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
334 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
340 | + * that need to be setup before our EE_System launches. |
|
341 | + * |
|
342 | + * @return void |
|
343 | + * @throws DomainException |
|
344 | + * @throws InvalidArgumentException |
|
345 | + * @throws InvalidDataTypeException |
|
346 | + * @throws InvalidInterfaceException |
|
347 | + * @throws InvalidClassException |
|
348 | + * @throws InvalidFilePathException |
|
349 | + * @throws EE_Error |
|
350 | + */ |
|
351 | + public function brewCaffeinated() |
|
352 | + { |
|
353 | + /** @var Domain $domain */ |
|
354 | + $domain = DomainFactory::getShared( |
|
355 | + new FullyQualifiedName( |
|
356 | + 'EventEspresso\core\domain\Domain' |
|
357 | + ), |
|
358 | + [ |
|
359 | + new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
360 | + Version::fromString(espresso_version()), |
|
361 | + ] |
|
362 | + ); |
|
363 | + static $brew; |
|
364 | + if ($domain->isCaffeinated() && ! $brew instanceof EE_Brewing_Regular) { |
|
365 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
366 | + /** @var EE_Brewing_Regular $brew */ |
|
367 | + $brew = LoaderFactory::getLoader()->getShared(EE_Brewing_Regular::class); |
|
368 | + $brew->initializePUE(); |
|
369 | + add_action( |
|
370 | + 'AHEE__EE_System__load_core_configuration__begin', |
|
371 | + [$brew, 'caffeinated'] |
|
372 | + ); |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * @param string $addon_name |
|
379 | + * @param string $version_constant |
|
380 | + * @param string $min_version_required |
|
381 | + * @param string $load_callback |
|
382 | + * @param string $plugin_file_constant |
|
383 | + * @return void |
|
384 | + */ |
|
385 | + private function deactivateIncompatibleAddon( |
|
386 | + $addon_name, |
|
387 | + $version_constant, |
|
388 | + $min_version_required, |
|
389 | + $load_callback, |
|
390 | + $plugin_file_constant |
|
391 | + ) { |
|
392 | + if (! defined($version_constant)) { |
|
393 | + return; |
|
394 | + } |
|
395 | + $addon_version = constant($version_constant); |
|
396 | + if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
|
397 | + remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
|
398 | + if (! function_exists('deactivate_plugins')) { |
|
399 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
400 | + } |
|
401 | + deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
|
402 | + $this->request->unSetRequestParams(['activate', 'activate-multi'], true); |
|
403 | + EE_Error::add_error( |
|
404 | + sprintf( |
|
405 | + esc_html__( |
|
406 | + 'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.', |
|
407 | + 'event_espresso' |
|
408 | + ), |
|
409 | + $addon_name, |
|
410 | + $min_version_required |
|
411 | + ), |
|
412 | + __FILE__, |
|
413 | + __FUNCTION__ . "({$addon_name})", |
|
414 | + __LINE__ |
|
415 | + ); |
|
416 | + EE_Error::get_notices(false, true); |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * load_espresso_addons |
|
423 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
424 | + * this is hooked into both: |
|
425 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
426 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
427 | + * and the WP 'activate_plugin' hook point |
|
428 | + * |
|
429 | + * @access public |
|
430 | + * @return void |
|
431 | + */ |
|
432 | + public function load_espresso_addons() |
|
433 | + { |
|
434 | + $this->deactivateIncompatibleAddon( |
|
435 | + 'Wait Lists', |
|
436 | + 'EE_WAIT_LISTS_VERSION', |
|
437 | + '1.0.0.beta.074', |
|
438 | + 'load_espresso_wait_lists', |
|
439 | + 'EE_WAIT_LISTS_PLUGIN_FILE' |
|
440 | + ); |
|
441 | + $this->deactivateIncompatibleAddon( |
|
442 | + 'Automated Upcoming Event Notifications', |
|
443 | + 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION', |
|
444 | + '1.0.0.beta.091', |
|
445 | + 'load_espresso_automated_upcoming_event_notification', |
|
446 | + 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE' |
|
447 | + ); |
|
448 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
449 | + // if the WP API basic auth plugin isn't already loaded, load it now. |
|
450 | + // We want it for mobile apps. Just include the entire plugin |
|
451 | + // also, don't load the basic auth when a plugin is getting activated, because |
|
452 | + // it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
453 | + // and causes a fatal error |
|
454 | + if ( |
|
455 | + ($this->request->isWordPressApi() || $this->request->isApi()) |
|
456 | + && $this->request->getRequestParam('activate') !== 'true' |
|
457 | + && ! function_exists('json_basic_auth_handler') |
|
458 | + && ! function_exists('json_basic_auth_error') |
|
459 | + && ! in_array( |
|
460 | + $this->request->getRequestParam('action'), |
|
461 | + array('activate', 'activate-selected'), |
|
462 | + true |
|
463 | + ) |
|
464 | + ) { |
|
465 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php'; |
|
466 | + } |
|
467 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + /** |
|
472 | + * detect_activations_or_upgrades |
|
473 | + * Checks for activation or upgrade of core first; |
|
474 | + * then also checks if any registered addons have been activated or upgraded |
|
475 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
476 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
477 | + * |
|
478 | + * @access public |
|
479 | + * @return void |
|
480 | + */ |
|
481 | + public function detect_activations_or_upgrades() |
|
482 | + { |
|
483 | + // first off: let's make sure to handle core |
|
484 | + $this->detect_if_activation_or_upgrade(); |
|
485 | + foreach ($this->registry->addons as $addon) { |
|
486 | + if ($addon instanceof EE_Addon) { |
|
487 | + // detect teh request type for that addon |
|
488 | + $addon->detect_req_type(); |
|
489 | + } |
|
490 | + } |
|
491 | + } |
|
492 | + |
|
493 | + |
|
494 | + /** |
|
495 | + * detect_if_activation_or_upgrade |
|
496 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
497 | + * and either setting up the DB or setting up maintenance mode etc. |
|
498 | + * |
|
499 | + * @access public |
|
500 | + * @return void |
|
501 | + */ |
|
502 | + public function detect_if_activation_or_upgrade() |
|
503 | + { |
|
504 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
505 | + // check if db has been updated, or if its a brand-new installation |
|
506 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
507 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
508 | + // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
509 | + switch ($request_type) { |
|
510 | + case EE_System::req_type_new_activation: |
|
511 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
512 | + $this->_handle_core_version_change($espresso_db_update); |
|
513 | + break; |
|
514 | + case EE_System::req_type_reactivation: |
|
515 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
516 | + $this->_handle_core_version_change($espresso_db_update); |
|
517 | + break; |
|
518 | + case EE_System::req_type_upgrade: |
|
519 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
520 | + // migrations may be required now that we've upgraded |
|
521 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
522 | + $this->_handle_core_version_change($espresso_db_update); |
|
523 | + break; |
|
524 | + case EE_System::req_type_downgrade: |
|
525 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
526 | + // its possible migrations are no longer required |
|
527 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
528 | + $this->_handle_core_version_change($espresso_db_update); |
|
529 | + break; |
|
530 | + case EE_System::req_type_normal: |
|
531 | + default: |
|
532 | + break; |
|
533 | + } |
|
534 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
535 | + } |
|
536 | + |
|
537 | + |
|
538 | + /** |
|
539 | + * Updates the list of installed versions and sets hooks for |
|
540 | + * initializing the database later during the request |
|
541 | + * |
|
542 | + * @param array $espresso_db_update |
|
543 | + */ |
|
544 | + private function _handle_core_version_change($espresso_db_update) |
|
545 | + { |
|
546 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
547 | + // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
548 | + add_action( |
|
549 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
550 | + array($this, 'initialize_db_if_no_migrations_required') |
|
551 | + ); |
|
552 | + } |
|
553 | + |
|
554 | + |
|
555 | + /** |
|
556 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
557 | + * information about what versions of EE have been installed and activated, |
|
558 | + * NOT necessarily the state of the database |
|
559 | + * |
|
560 | + * @param mixed $espresso_db_update the value of the WordPress option. |
|
561 | + * If not supplied, fetches it from the options table |
|
562 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
563 | + */ |
|
564 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
565 | + { |
|
566 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
567 | + if (! $espresso_db_update) { |
|
568 | + $espresso_db_update = get_option('espresso_db_update'); |
|
569 | + } |
|
570 | + // check that option is an array |
|
571 | + if (! is_array($espresso_db_update)) { |
|
572 | + // if option is FALSE, then it never existed |
|
573 | + if ($espresso_db_update === false) { |
|
574 | + // make $espresso_db_update an array and save option with autoload OFF |
|
575 | + $espresso_db_update = array(); |
|
576 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
577 | + } else { |
|
578 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
579 | + $espresso_db_update = array($espresso_db_update => array()); |
|
580 | + update_option('espresso_db_update', $espresso_db_update); |
|
581 | + } |
|
582 | + } else { |
|
583 | + $corrected_db_update = array(); |
|
584 | + // if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
585 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
586 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
587 | + // the key is an int, and the value IS NOT an array |
|
588 | + // so it must be numerically-indexed, where values are versions installed... |
|
589 | + // fix it! |
|
590 | + $version_string = $should_be_array; |
|
591 | + $corrected_db_update[ $version_string ] = array('unknown-date'); |
|
592 | + } else { |
|
593 | + // ok it checks out |
|
594 | + $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
595 | + } |
|
596 | + } |
|
597 | + $espresso_db_update = $corrected_db_update; |
|
598 | + update_option('espresso_db_update', $espresso_db_update); |
|
599 | + } |
|
600 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
601 | + return $espresso_db_update; |
|
602 | + } |
|
603 | + |
|
604 | + |
|
605 | + /** |
|
606 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
607 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
608 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
609 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
610 | + * so that it will be done when migrations are finished |
|
611 | + * |
|
612 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
613 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
614 | + * This is a resource-intensive job |
|
615 | + * so we prefer to only do it when necessary |
|
616 | + * @return void |
|
617 | + * @throws EE_Error |
|
618 | + */ |
|
619 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
620 | + { |
|
621 | + $request_type = $this->detect_req_type(); |
|
622 | + // only initialize system if we're not in maintenance mode. |
|
623 | + if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
624 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
625 | + $rewrite_rules = $this->loader->getShared( |
|
626 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
627 | + ); |
|
628 | + $rewrite_rules->flush(); |
|
629 | + if ($verify_schema) { |
|
630 | + EEH_Activation::initialize_db_and_folders(); |
|
631 | + } |
|
632 | + EEH_Activation::initialize_db_content(); |
|
633 | + EEH_Activation::system_initialization(); |
|
634 | + if ($initialize_addons_too) { |
|
635 | + $this->initialize_addons(); |
|
636 | + } |
|
637 | + } else { |
|
638 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
639 | + } |
|
640 | + if ( |
|
641 | + $request_type === EE_System::req_type_new_activation |
|
642 | + || $request_type === EE_System::req_type_reactivation |
|
643 | + || ( |
|
644 | + $request_type === EE_System::req_type_upgrade |
|
645 | + && $this->is_major_version_change() |
|
646 | + ) |
|
647 | + ) { |
|
648 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
649 | + } |
|
650 | + } |
|
651 | + |
|
652 | + |
|
653 | + /** |
|
654 | + * Initializes the db for all registered addons |
|
655 | + * |
|
656 | + * @throws EE_Error |
|
657 | + */ |
|
658 | + public function initialize_addons() |
|
659 | + { |
|
660 | + // foreach registered addon, make sure its db is up-to-date too |
|
661 | + foreach ($this->registry->addons as $addon) { |
|
662 | + if ($addon instanceof EE_Addon) { |
|
663 | + $addon->initialize_db_if_no_migrations_required(); |
|
664 | + } |
|
665 | + } |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + /** |
|
670 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
671 | + * |
|
672 | + * @param array $version_history |
|
673 | + * @param string $current_version_to_add version to be added to the version history |
|
674 | + * @return boolean success as to whether or not this option was changed |
|
675 | + */ |
|
676 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
677 | + { |
|
678 | + if (! $version_history) { |
|
679 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
680 | + } |
|
681 | + if ($current_version_to_add === null) { |
|
682 | + $current_version_to_add = espresso_version(); |
|
683 | + } |
|
684 | + $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
685 | + // re-save |
|
686 | + return update_option('espresso_db_update', $version_history); |
|
687 | + } |
|
688 | + |
|
689 | + |
|
690 | + /** |
|
691 | + * Detects if the current version indicated in the has existed in the list of |
|
692 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
693 | + * |
|
694 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
695 | + * If not supplied, fetches it from the options table. |
|
696 | + * Also, caches its result so later parts of the code can also know whether |
|
697 | + * there's been an update or not. This way we can add the current version to |
|
698 | + * espresso_db_update, but still know if this is a new install or not |
|
699 | + * @return int one of the constants on EE_System::req_type_ |
|
700 | + */ |
|
701 | + public function detect_req_type($espresso_db_update = null) |
|
702 | + { |
|
703 | + if ($this->_req_type === null) { |
|
704 | + $espresso_db_update = ! empty($espresso_db_update) |
|
705 | + ? $espresso_db_update |
|
706 | + : $this->fix_espresso_db_upgrade_option(); |
|
707 | + $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
708 | + $espresso_db_update, |
|
709 | + 'ee_espresso_activation', |
|
710 | + espresso_version() |
|
711 | + ); |
|
712 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
713 | + $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal); |
|
714 | + } |
|
715 | + return $this->_req_type; |
|
716 | + } |
|
717 | + |
|
718 | + |
|
719 | + /** |
|
720 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
721 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
722 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
723 | + * |
|
724 | + * @param $activation_history |
|
725 | + * @return bool |
|
726 | + */ |
|
727 | + private function _detect_major_version_change($activation_history) |
|
728 | + { |
|
729 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
730 | + $previous_version_parts = explode('.', $previous_version); |
|
731 | + $current_version_parts = explode('.', espresso_version()); |
|
732 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
733 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
734 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
735 | + ); |
|
736 | + } |
|
737 | + |
|
738 | + |
|
739 | + /** |
|
740 | + * Returns true if either the major or minor version of EE changed during this request. |
|
741 | + * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
742 | + * |
|
743 | + * @return bool |
|
744 | + */ |
|
745 | + public function is_major_version_change() |
|
746 | + { |
|
747 | + return $this->_major_version_change; |
|
748 | + } |
|
749 | + |
|
750 | + |
|
751 | + /** |
|
752 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
753 | + * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
754 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
755 | + * just activated to (for core that will always be espresso_version()) |
|
756 | + * |
|
757 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
758 | + * ee plugin. for core that's 'espresso_db_update' |
|
759 | + * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
760 | + * indicate that this plugin was just activated |
|
761 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
762 | + * espresso_version()) |
|
763 | + * @return int one of the constants on EE_System::req_type_* |
|
764 | + */ |
|
765 | + public static function detect_req_type_given_activation_history( |
|
766 | + $activation_history_for_addon, |
|
767 | + $activation_indicator_option_name, |
|
768 | + $version_to_upgrade_to |
|
769 | + ) { |
|
770 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
771 | + if ($activation_history_for_addon) { |
|
772 | + // it exists, so this isn't a completely new install |
|
773 | + // check if this version already in that list of previously installed versions |
|
774 | + if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { |
|
775 | + // it a version we haven't seen before |
|
776 | + if ($version_is_higher === 1) { |
|
777 | + $req_type = EE_System::req_type_upgrade; |
|
778 | + } else { |
|
779 | + $req_type = EE_System::req_type_downgrade; |
|
780 | + } |
|
781 | + delete_option($activation_indicator_option_name); |
|
782 | + } else { |
|
783 | + // its not an update. maybe a reactivation? |
|
784 | + if (get_option($activation_indicator_option_name, false)) { |
|
785 | + if ($version_is_higher === -1) { |
|
786 | + $req_type = EE_System::req_type_downgrade; |
|
787 | + } elseif ($version_is_higher === 0) { |
|
788 | + // we've seen this version before, but it's an activation. must be a reactivation |
|
789 | + $req_type = EE_System::req_type_reactivation; |
|
790 | + } else {// $version_is_higher === 1 |
|
791 | + $req_type = EE_System::req_type_upgrade; |
|
792 | + } |
|
793 | + delete_option($activation_indicator_option_name); |
|
794 | + } else { |
|
795 | + // we've seen this version before and the activation indicate doesn't show it was just activated |
|
796 | + if ($version_is_higher === -1) { |
|
797 | + $req_type = EE_System::req_type_downgrade; |
|
798 | + } elseif ($version_is_higher === 0) { |
|
799 | + // we've seen this version before and it's not an activation. its normal request |
|
800 | + $req_type = EE_System::req_type_normal; |
|
801 | + } else {// $version_is_higher === 1 |
|
802 | + $req_type = EE_System::req_type_upgrade; |
|
803 | + } |
|
804 | + } |
|
805 | + } |
|
806 | + } else { |
|
807 | + // brand new install |
|
808 | + $req_type = EE_System::req_type_new_activation; |
|
809 | + delete_option($activation_indicator_option_name); |
|
810 | + } |
|
811 | + return $req_type; |
|
812 | + } |
|
813 | + |
|
814 | + |
|
815 | + /** |
|
816 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
817 | + * the $activation_history_for_addon |
|
818 | + * |
|
819 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
820 | + * sometimes containing 'unknown-date' |
|
821 | + * @param string $version_to_upgrade_to (current version) |
|
822 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
823 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
824 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
825 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
826 | + */ |
|
827 | + private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
828 | + { |
|
829 | + // find the most recently-activated version |
|
830 | + $most_recently_active_version = |
|
831 | + EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
832 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
833 | + } |
|
834 | + |
|
835 | + |
|
836 | + /** |
|
837 | + * Gets the most recently active version listed in the activation history, |
|
838 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
839 | + * |
|
840 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
841 | + * sometimes containing 'unknown-date' |
|
842 | + * @return string |
|
843 | + */ |
|
844 | + private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
845 | + { |
|
846 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
847 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
848 | + if (is_array($activation_history)) { |
|
849 | + foreach ($activation_history as $version => $times_activated) { |
|
850 | + // check there is a record of when this version was activated. Otherwise, |
|
851 | + // mark it as unknown |
|
852 | + if (! $times_activated) { |
|
853 | + $times_activated = array('unknown-date'); |
|
854 | + } |
|
855 | + if (is_string($times_activated)) { |
|
856 | + $times_activated = array($times_activated); |
|
857 | + } |
|
858 | + foreach ($times_activated as $an_activation) { |
|
859 | + if ( |
|
860 | + $an_activation !== 'unknown-date' |
|
861 | + && $an_activation |
|
862 | + > $most_recently_active_version_activation |
|
863 | + ) { |
|
864 | + $most_recently_active_version = $version; |
|
865 | + $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
866 | + ? '1970-01-01 00:00:00' |
|
867 | + : $an_activation; |
|
868 | + } |
|
869 | + } |
|
870 | + } |
|
871 | + } |
|
872 | + return $most_recently_active_version; |
|
873 | + } |
|
874 | + |
|
875 | + |
|
876 | + /** |
|
877 | + * This redirects to the about EE page after activation |
|
878 | + * |
|
879 | + * @return void |
|
880 | + */ |
|
881 | + public function redirect_to_about_ee() |
|
882 | + { |
|
883 | + $notices = EE_Error::get_notices(false); |
|
884 | + // if current user is an admin and it's not an ajax or rest request |
|
885 | + if ( |
|
886 | + ! isset($notices['errors']) |
|
887 | + && $this->request->isAdmin() |
|
888 | + && apply_filters( |
|
889 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
890 | + $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
891 | + ) |
|
892 | + ) { |
|
893 | + $query_params = array('page' => 'espresso_about'); |
|
894 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
895 | + $query_params['new_activation'] = true; |
|
896 | + } |
|
897 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
898 | + $query_params['reactivation'] = true; |
|
899 | + } |
|
900 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
901 | + wp_safe_redirect($url); |
|
902 | + exit(); |
|
903 | + } |
|
904 | + } |
|
905 | + |
|
906 | + |
|
907 | + /** |
|
908 | + * load_core_configuration |
|
909 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
910 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
911 | + * |
|
912 | + * @return void |
|
913 | + * @throws ReflectionException |
|
914 | + * @throws Exception |
|
915 | + */ |
|
916 | + public function load_core_configuration() |
|
917 | + { |
|
918 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
919 | + $this->loader->getShared('EE_Load_Textdomain'); |
|
920 | + // load textdomain |
|
921 | + EE_Load_Textdomain::load_textdomain(); |
|
922 | + // load and setup EE_Config and EE_Network_Config |
|
923 | + $config = $this->loader->getShared('EE_Config'); |
|
924 | + $this->loader->getShared('EE_Network_Config'); |
|
925 | + // setup autoloaders |
|
926 | + // enable logging? |
|
927 | + $this->loader->getShared('EventEspresso\core\services\orm\TrashLogger'); |
|
928 | + if ($config->admin->use_remote_logging) { |
|
929 | + $this->loader->getShared('EE_Log'); |
|
930 | + } |
|
931 | + // check for activation errors |
|
932 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
933 | + if ($activation_errors) { |
|
934 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
935 | + update_option('ee_plugin_activation_errors', false); |
|
936 | + } |
|
937 | + // get model names |
|
938 | + $this->_parse_model_names(); |
|
939 | + // configure custom post type definitions |
|
940 | + $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'); |
|
941 | + $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'); |
|
942 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
943 | + } |
|
944 | + |
|
945 | + |
|
946 | + /** |
|
947 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
948 | + * |
|
949 | + * @return void |
|
950 | + * @throws ReflectionException |
|
951 | + */ |
|
952 | + private function _parse_model_names() |
|
953 | + { |
|
954 | + // get all the files in the EE_MODELS folder that end in .model.php |
|
955 | + $models = glob(EE_MODELS . '*.model.php'); |
|
956 | + $model_names = array(); |
|
957 | + $non_abstract_db_models = array(); |
|
958 | + foreach ($models as $model) { |
|
959 | + // get model classname |
|
960 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
961 | + $short_name = str_replace('EEM_', '', $classname); |
|
962 | + $reflectionClass = new ReflectionClass($classname); |
|
963 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
964 | + $non_abstract_db_models[ $short_name ] = $classname; |
|
965 | + } |
|
966 | + $model_names[ $short_name ] = $classname; |
|
967 | + } |
|
968 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
969 | + $this->registry->non_abstract_db_models = apply_filters( |
|
970 | + 'FHEE__EE_System__parse_implemented_model_names', |
|
971 | + $non_abstract_db_models |
|
972 | + ); |
|
973 | + } |
|
974 | + |
|
975 | + |
|
976 | + /** |
|
977 | + * @since 4.9.71.p |
|
978 | + * @throws Exception |
|
979 | + */ |
|
980 | + public function loadRouteMatchSpecifications() |
|
981 | + { |
|
982 | + try { |
|
983 | + $this->loader->getShared( |
|
984 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' |
|
985 | + ); |
|
986 | + } catch (Exception $exception) { |
|
987 | + new ExceptionStackTraceDisplay($exception); |
|
988 | + } |
|
989 | + do_action('AHEE__EE_System__loadRouteMatchSpecifications'); |
|
990 | + } |
|
991 | + |
|
992 | + |
|
993 | + /** |
|
994 | + * loading CPT related classes earlier so that their definitions are available |
|
995 | + * but not performing any actual registration with WP core until load_CPTs_and_session() is called |
|
996 | + * |
|
997 | + * @since 4.10.21.p |
|
998 | + */ |
|
999 | + public function loadCustomPostTypes() |
|
1000 | + { |
|
1001 | + $this->register_custom_taxonomies = $this->loader->getShared( |
|
1002 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' |
|
1003 | + ); |
|
1004 | + $this->register_custom_post_types = $this->loader->getShared( |
|
1005 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' |
|
1006 | + ); |
|
1007 | + $this->register_custom_taxonomy_terms = $this->loader->getShared( |
|
1008 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms' |
|
1009 | + ); |
|
1010 | + // integrate WP_Query with the EE models |
|
1011 | + $this->loader->getShared('EE_CPT_Strategy'); |
|
1012 | + // load legacy EE_Request_Handler in case add-ons still need it |
|
1013 | + $this->loader->getShared('EE_Request_Handler'); |
|
1014 | + } |
|
1015 | + |
|
1016 | + |
|
1017 | + /** |
|
1018 | + * register_shortcodes_modules_and_widgets |
|
1019 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
1020 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
1021 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
1022 | + * |
|
1023 | + * @access public |
|
1024 | + * @return void |
|
1025 | + * @throws Exception |
|
1026 | + */ |
|
1027 | + public function register_shortcodes_modules_and_widgets() |
|
1028 | + { |
|
1029 | + if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAjax()) { |
|
1030 | + // load, register, and add shortcodes the new way |
|
1031 | + $this->loader->getShared('EventEspresso\core\services\shortcodes\ShortcodesManager'); |
|
1032 | + } |
|
1033 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
1034 | + // check for addons using old hook point |
|
1035 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
1036 | + $this->_incompatible_addon_error(); |
|
1037 | + } |
|
1038 | + } |
|
1039 | + |
|
1040 | + |
|
1041 | + /** |
|
1042 | + * _incompatible_addon_error |
|
1043 | + * |
|
1044 | + * @access public |
|
1045 | + * @return void |
|
1046 | + */ |
|
1047 | + private function _incompatible_addon_error() |
|
1048 | + { |
|
1049 | + // get array of classes hooking into here |
|
1050 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
1051 | + 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
1052 | + ); |
|
1053 | + if (! empty($class_names)) { |
|
1054 | + $msg = esc_html__( |
|
1055 | + 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
1056 | + 'event_espresso' |
|
1057 | + ); |
|
1058 | + $msg .= '<ul>'; |
|
1059 | + foreach ($class_names as $class_name) { |
|
1060 | + $msg .= '<li><b>Event Espresso - ' |
|
1061 | + . str_replace( |
|
1062 | + array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), |
|
1063 | + '', |
|
1064 | + $class_name |
|
1065 | + ) . '</b></li>'; |
|
1066 | + } |
|
1067 | + $msg .= '</ul>'; |
|
1068 | + $msg .= esc_html__( |
|
1069 | + 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
1070 | + 'event_espresso' |
|
1071 | + ); |
|
1072 | + // save list of incompatible addons to wp-options for later use |
|
1073 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
1074 | + if (is_admin()) { |
|
1075 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1076 | + } |
|
1077 | + } |
|
1078 | + } |
|
1079 | + |
|
1080 | + |
|
1081 | + /** |
|
1082 | + * brew_espresso |
|
1083 | + * begins the process of setting hooks for initializing EE in the correct order |
|
1084 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
1085 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
1086 | + * |
|
1087 | + * @return void |
|
1088 | + */ |
|
1089 | + public function brew_espresso() |
|
1090 | + { |
|
1091 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
1092 | + // load some final core systems |
|
1093 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
1094 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
1095 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
1096 | + add_action('init', array($this, 'load_controllers'), 7); |
|
1097 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
1098 | + add_action('init', array($this, 'initialize'), 10); |
|
1099 | + add_action('init', array($this, 'initialize_last'), 100); |
|
1100 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
1101 | + } |
|
1102 | + |
|
1103 | + |
|
1104 | + /** |
|
1105 | + * set_hooks_for_core |
|
1106 | + * |
|
1107 | + * @access public |
|
1108 | + * @return void |
|
1109 | + * @throws EE_Error |
|
1110 | + */ |
|
1111 | + public function set_hooks_for_core() |
|
1112 | + { |
|
1113 | + $this->_deactivate_incompatible_addons(); |
|
1114 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
1115 | + $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan'); |
|
1116 | + // caps need to be initialized on every request so that capability maps are set. |
|
1117 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
1118 | + $this->registry->CAP->init_caps(); |
|
1119 | + } |
|
1120 | + |
|
1121 | + |
|
1122 | + /** |
|
1123 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
1124 | + * deactivates any addons considered incompatible with the current version of EE |
|
1125 | + */ |
|
1126 | + private function _deactivate_incompatible_addons() |
|
1127 | + { |
|
1128 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
1129 | + if (! empty($incompatible_addons)) { |
|
1130 | + $active_plugins = get_option('active_plugins', array()); |
|
1131 | + foreach ($active_plugins as $active_plugin) { |
|
1132 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
1133 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
1134 | + $this->request->unSetRequestParams(['activate'], true); |
|
1135 | + espresso_deactivate_plugin($active_plugin); |
|
1136 | + } |
|
1137 | + } |
|
1138 | + } |
|
1139 | + } |
|
1140 | + } |
|
1141 | + |
|
1142 | + |
|
1143 | + /** |
|
1144 | + * perform_activations_upgrades_and_migrations |
|
1145 | + * |
|
1146 | + * @access public |
|
1147 | + * @return void |
|
1148 | + */ |
|
1149 | + public function perform_activations_upgrades_and_migrations() |
|
1150 | + { |
|
1151 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
1152 | + } |
|
1153 | + |
|
1154 | + |
|
1155 | + /** |
|
1156 | + * @return void |
|
1157 | + * @throws DomainException |
|
1158 | + */ |
|
1159 | + public function load_CPTs_and_session() |
|
1160 | + { |
|
1161 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
1162 | + $this->register_custom_taxonomies->registerCustomTaxonomies(); |
|
1163 | + $this->register_custom_post_types->registerCustomPostTypes(); |
|
1164 | + $this->register_custom_taxonomy_terms->registerCustomTaxonomyTerms(); |
|
1165 | + // load legacy Custom Post Types and Taxonomies |
|
1166 | + $this->loader->getShared('EE_Register_CPTs'); |
|
1167 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
1168 | + } |
|
1169 | + |
|
1170 | + |
|
1171 | + /** |
|
1172 | + * load_controllers |
|
1173 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
1174 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
1175 | + * time |
|
1176 | + * |
|
1177 | + * @access public |
|
1178 | + * @return void |
|
1179 | + */ |
|
1180 | + public function load_controllers() |
|
1181 | + { |
|
1182 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
1183 | + // let's get it started |
|
1184 | + if ( |
|
1185 | + ! $this->maintenance_mode->level() |
|
1186 | + && ($this->request->isFrontend() || $this->request->isFrontAjax()) |
|
1187 | + ) { |
|
1188 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
1189 | + $this->loader->getShared('EE_Front_Controller'); |
|
1190 | + } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) { |
|
1191 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
1192 | + $this->loader->getShared('EE_Admin'); |
|
1193 | + } elseif ($this->request->isWordPressHeartbeat()) { |
|
1194 | + $this->loader->getShared('EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat'); |
|
1195 | + } |
|
1196 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
1197 | + } |
|
1198 | + |
|
1199 | + |
|
1200 | + /** |
|
1201 | + * core_loaded_and_ready |
|
1202 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
1203 | + * |
|
1204 | + * @access public |
|
1205 | + * @return void |
|
1206 | + * @throws Exception |
|
1207 | + */ |
|
1208 | + public function core_loaded_and_ready() |
|
1209 | + { |
|
1210 | + if ( |
|
1211 | + $this->request->isAdmin() |
|
1212 | + || $this->request->isFrontend() |
|
1213 | + || $this->request->isIframe() |
|
1214 | + || $this->request->isWordPressApi() |
|
1215 | + ) { |
|
1216 | + try { |
|
1217 | + $this->loader->getShared('EventEspresso\core\services\assets\I18nRegistry', [[]]); |
|
1218 | + $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
1219 | + $this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager'); |
|
1220 | + if ($this->canLoadBlocks()) { |
|
1221 | + $this->loader->getShared( |
|
1222 | + 'EventEspresso\core\services\editor\BlockRegistrationManager' |
|
1223 | + ); |
|
1224 | + } |
|
1225 | + } catch (Exception $exception) { |
|
1226 | + new ExceptionStackTraceDisplay($exception); |
|
1227 | + } |
|
1228 | + } |
|
1229 | + if ( |
|
1230 | + $this->request->isAdmin() |
|
1231 | + || $this->request->isEeAjax() |
|
1232 | + || $this->request->isFrontend() |
|
1233 | + ) { |
|
1234 | + $this->loader->getShared('EE_Session'); |
|
1235 | + } |
|
1236 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
1237 | + // always load template tags, because it's faster than checking if it's a front-end request, and many page |
|
1238 | + // builders require these even on the front-end |
|
1239 | + require_once EE_PUBLIC . 'template_tags.php'; |
|
1240 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
1241 | + } |
|
1242 | + |
|
1243 | + |
|
1244 | + /** |
|
1245 | + * initialize |
|
1246 | + * this is the best place to begin initializing client code |
|
1247 | + * |
|
1248 | + * @access public |
|
1249 | + * @return void |
|
1250 | + */ |
|
1251 | + public function initialize() |
|
1252 | + { |
|
1253 | + do_action('AHEE__EE_System__initialize'); |
|
1254 | + add_filter( |
|
1255 | + 'safe_style_css', |
|
1256 | + function ($styles) { |
|
1257 | + $styles[] = 'display'; |
|
1258 | + $styles[] = 'visibility'; |
|
1259 | + $styles[] = 'position'; |
|
1260 | + $styles[] = 'top'; |
|
1261 | + $styles[] = 'right'; |
|
1262 | + $styles[] = 'bottom'; |
|
1263 | + $styles[] = 'left'; |
|
1264 | + $styles[] = 'resize'; |
|
1265 | + $styles[] = 'max-width'; |
|
1266 | + $styles[] = 'max-height'; |
|
1267 | + return $styles; |
|
1268 | + } |
|
1269 | + ); |
|
1270 | + } |
|
1271 | + |
|
1272 | + |
|
1273 | + /** |
|
1274 | + * initialize_last |
|
1275 | + * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
1276 | + * initialize has done so |
|
1277 | + * |
|
1278 | + * @access public |
|
1279 | + * @return void |
|
1280 | + */ |
|
1281 | + public function initialize_last() |
|
1282 | + { |
|
1283 | + do_action('AHEE__EE_System__initialize_last'); |
|
1284 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
1285 | + $rewrite_rules = $this->loader->getShared( |
|
1286 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
1287 | + ); |
|
1288 | + $rewrite_rules->flushRewriteRules(); |
|
1289 | + add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
1290 | + if ( |
|
1291 | + ($this->request->isAjax() || $this->request->isAdmin()) |
|
1292 | + && $this->maintenance_mode->models_can_query() |
|
1293 | + ) { |
|
1294 | + $this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager'); |
|
1295 | + $this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager'); |
|
1296 | + } |
|
1297 | + } |
|
1298 | + |
|
1299 | + |
|
1300 | + /** |
|
1301 | + * @return void |
|
1302 | + * @throws EE_Error |
|
1303 | + */ |
|
1304 | + public function addEspressoToolbar() |
|
1305 | + { |
|
1306 | + $this->loader->getShared( |
|
1307 | + 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
1308 | + array($this->registry->CAP) |
|
1309 | + ); |
|
1310 | + } |
|
1311 | + |
|
1312 | + |
|
1313 | + /** |
|
1314 | + * do_not_cache |
|
1315 | + * sets no cache headers and defines no cache constants for WP plugins |
|
1316 | + * |
|
1317 | + * @access public |
|
1318 | + * @return void |
|
1319 | + */ |
|
1320 | + public static function do_not_cache() |
|
1321 | + { |
|
1322 | + // set no cache constants |
|
1323 | + if (! defined('DONOTCACHEPAGE')) { |
|
1324 | + define('DONOTCACHEPAGE', true); |
|
1325 | + } |
|
1326 | + if (! defined('DONOTCACHCEOBJECT')) { |
|
1327 | + define('DONOTCACHCEOBJECT', true); |
|
1328 | + } |
|
1329 | + if (! defined('DONOTCACHEDB')) { |
|
1330 | + define('DONOTCACHEDB', true); |
|
1331 | + } |
|
1332 | + // add no cache headers |
|
1333 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1334 | + // plus a little extra for nginx and Google Chrome |
|
1335 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1336 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1337 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1338 | + } |
|
1339 | + |
|
1340 | + |
|
1341 | + /** |
|
1342 | + * extra_nocache_headers |
|
1343 | + * |
|
1344 | + * @access public |
|
1345 | + * @param $headers |
|
1346 | + * @return array |
|
1347 | + */ |
|
1348 | + public static function extra_nocache_headers($headers) |
|
1349 | + { |
|
1350 | + // for NGINX |
|
1351 | + $headers['X-Accel-Expires'] = 0; |
|
1352 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1353 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1354 | + return $headers; |
|
1355 | + } |
|
1356 | + |
|
1357 | + |
|
1358 | + /** |
|
1359 | + * nocache_headers |
|
1360 | + * |
|
1361 | + * @access public |
|
1362 | + * @return void |
|
1363 | + */ |
|
1364 | + public static function nocache_headers() |
|
1365 | + { |
|
1366 | + nocache_headers(); |
|
1367 | + } |
|
1368 | + |
|
1369 | + |
|
1370 | + /** |
|
1371 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1372 | + * never returned with the function. |
|
1373 | + * |
|
1374 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
1375 | + * @return array |
|
1376 | + */ |
|
1377 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
1378 | + { |
|
1379 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1380 | + } |
|
1381 | + |
|
1382 | + |
|
1383 | + /** |
|
1384 | + * Return whether blocks can be registered/loaded or not. |
|
1385 | + * @return bool |
|
1386 | + */ |
|
1387 | + private function canLoadBlocks() |
|
1388 | + { |
|
1389 | + return apply_filters('FHEE__EE_System__canLoadBlocks', true) |
|
1390 | + && function_exists('register_block_type') |
|
1391 | + // don't load blocks if in the Divi page builder editor context |
|
1392 | + // @see https://github.com/eventespresso/event-espresso-core/issues/814 |
|
1393 | + && ! $this->request->getRequestParam('et_fb', false); |
|
1394 | + } |
|
1395 | 1395 | } |
@@ -12,298 +12,298 @@ |
||
12 | 12 | */ |
13 | 13 | class EEH_Schema |
14 | 14 | { |
15 | - /** |
|
16 | - * generates JSON-based linked data for an event |
|
17 | - * |
|
18 | - * @param EE_Event $event |
|
19 | - * @throws EE_Error |
|
20 | - */ |
|
21 | - public static function add_json_linked_data_for_event(EE_Event $event) |
|
22 | - { |
|
23 | - // Check we have a valid datetime for the event |
|
24 | - if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
25 | - return; |
|
26 | - } |
|
27 | - |
|
28 | - $template_args = array( |
|
29 | - 'event_permalink' => '', |
|
30 | - 'event_name' => '', |
|
31 | - 'event_description' => '', |
|
32 | - 'event_start' => '', |
|
33 | - 'event_end' => '', |
|
34 | - 'event_attendance_mode' => '', |
|
35 | - 'event_status' => '', |
|
36 | - 'currency' => '', |
|
37 | - 'event_tickets' => array(), |
|
38 | - 'venue_name' => '', |
|
39 | - 'venue_url' => '', |
|
40 | - 'venue_locality' => '', |
|
41 | - 'venue_region' => '', |
|
42 | - 'venue_address' => '', |
|
43 | - 'event_image' => '', |
|
44 | - ); |
|
45 | - $template_args['event_permalink'] = $event->get_permalink(); |
|
46 | - $template_args['event_name'] = $event->name(); |
|
47 | - $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
48 | - // clone datetime so that date formats don't override those for the original datetime |
|
49 | - $primary_datetime = clone $event->primary_datetime(); |
|
50 | - $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
51 | - $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
52 | - unset($primary_datetime); |
|
53 | - switch ($event->status()) { |
|
54 | - case EEM_Event::cancelled: |
|
55 | - $event_status = 'EventCancelled'; |
|
56 | - break; |
|
57 | - case EEM_Event::postponed: |
|
58 | - $event_status = 'EventPostponed'; |
|
59 | - break; |
|
60 | - default: |
|
61 | - $event_status = 'EventScheduled'; |
|
62 | - } |
|
63 | - $template_args['event_attendance_mode'] = 'OfflineEventAttendanceMode'; |
|
64 | - $template_args['event_status'] = 'https://schema.org/' . $event_status; |
|
65 | - $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
66 | - foreach ($event->tickets() as $original_ticket) { |
|
67 | - // clone tickets so that date formats don't override those for the original ticket |
|
68 | - $ticket = clone $original_ticket; |
|
69 | - $ID = $ticket->ID(); |
|
70 | - $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
71 | - $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
72 | - $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
73 | - $ticket->price(), |
|
74 | - EE_Registry::instance()->CFG->currency->dec_plc, |
|
75 | - EE_Registry::instance()->CFG->currency->dec_mrk, |
|
76 | - '' |
|
77 | - ); |
|
78 | - switch ($ticket->ticket_status()) { |
|
79 | - case 'TKO': |
|
80 | - $availability = 'InStock'; |
|
81 | - break; |
|
82 | - case 'TKS': |
|
83 | - $availability = 'SoldOut'; |
|
84 | - break; |
|
85 | - default: |
|
86 | - $availability = null; |
|
87 | - break; |
|
88 | - } |
|
89 | - $template_args['event_tickets'][ $ID ]['availability'] = $availability; |
|
90 | - unset($ticket); |
|
91 | - } |
|
92 | - $VNU_ID = espresso_venue_id(); |
|
93 | - if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
94 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
95 | - $template_args['venue_name'] = get_the_title($VNU_ID); |
|
96 | - $template_args['venue_url'] = get_permalink($VNU_ID); |
|
97 | - $template_args['venue_locality'] = $venue->city(); |
|
98 | - $template_args['venue_region'] = $venue->state_name(); |
|
99 | - $template_args['venue_address'] = $venue->address(); |
|
100 | - if ($venue->virtual_url() !== '') { |
|
101 | - $template_args['event_attendance_mode'] = 'OnlineEventAttendanceMode'; |
|
102 | - } |
|
103 | - if ($venue->virtual_url() !== '' && $venue->address() !== '') { |
|
104 | - $template_args['event_attendance_mode'] = 'MixedEventAttendanceMode'; |
|
105 | - } |
|
106 | - } |
|
107 | - $template_args['event_image'] = $event->feature_image_url(); |
|
108 | - $template_args = apply_filters( |
|
109 | - 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
110 | - $template_args, |
|
111 | - $event, |
|
112 | - $VNU_ID |
|
113 | - ); |
|
114 | - extract($template_args, EXTR_OVERWRITE); |
|
115 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * location |
|
121 | - * The location of the event, organization or action. |
|
122 | - * Should include the Venue name AND schema formatted address info |
|
123 | - * |
|
124 | - * @access public |
|
125 | - * @param string $location |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - public static function location($location = null) |
|
129 | - { |
|
130 | - return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
131 | - . $location |
|
132 | - . '</div>' : ''; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * name |
|
139 | - * The name of the Event or Venue. |
|
140 | - * |
|
141 | - * @access public |
|
142 | - * @param string $name |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public static function name($name = null) |
|
146 | - { |
|
147 | - return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * streetAddress |
|
154 | - * The street address. For example, 1600 Amphitheatre Pkwy. |
|
155 | - * |
|
156 | - * @access public |
|
157 | - * @param AddressInterface $obj_with_address |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - public static function streetAddress(AddressInterface $obj_with_address = null) |
|
161 | - { |
|
162 | - return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
|
163 | - ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * postOfficeBoxNumber |
|
170 | - * The post office box number for PO box addresses. |
|
171 | - * |
|
172 | - * @access public |
|
173 | - * @param AddressInterface $obj_with_address |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - public static function postOfficeBoxNumber(AddressInterface $obj_with_address = null) |
|
177 | - { |
|
178 | - // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
|
179 | - if ( |
|
180 | - preg_match( |
|
181 | - "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
|
182 | - $obj_with_address->address2() |
|
183 | - ) |
|
184 | - ) { |
|
185 | - return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
|
186 | - ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
187 | - } else { |
|
188 | - return $obj_with_address->address2(); |
|
189 | - } |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * addressLocality |
|
196 | - * The locality (city, town, etc). For example, Mountain View. |
|
197 | - * |
|
198 | - * @access public |
|
199 | - * @param AddressInterface $obj_with_address |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public static function addressLocality(AddressInterface $obj_with_address = null) |
|
203 | - { |
|
204 | - return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
|
205 | - ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * addressRegion |
|
212 | - * The region (state, province, etc). For example, CA. |
|
213 | - * |
|
214 | - * @access public |
|
215 | - * @param AddressInterface $obj_with_address |
|
216 | - * @return string |
|
217 | - */ |
|
218 | - public static function addressRegion(AddressInterface $obj_with_address = null) |
|
219 | - { |
|
220 | - $state = $obj_with_address->state_name(); |
|
221 | - if (! empty($state)) { |
|
222 | - return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
223 | - } else { |
|
224 | - return ''; |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * addressCountry |
|
232 | - * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. |
|
233 | - * |
|
234 | - * @access public |
|
235 | - * @param AddressInterface $obj_with_address |
|
236 | - * @return string |
|
237 | - */ |
|
238 | - public static function addressCountry(AddressInterface $obj_with_address = null) |
|
239 | - { |
|
240 | - $country = $obj_with_address->country_name(); |
|
241 | - if (! empty($country)) { |
|
242 | - return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
243 | - } else { |
|
244 | - return ''; |
|
245 | - } |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * postalCode |
|
252 | - * The postal code. For example, 94043. |
|
253 | - * |
|
254 | - * @access public |
|
255 | - * @param AddressInterface $obj_with_address |
|
256 | - * @return string |
|
257 | - */ |
|
258 | - public static function postalCode(AddressInterface $obj_with_address = null) |
|
259 | - { |
|
260 | - return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
|
261 | - . $obj_with_address->zip() |
|
262 | - . '</span>' : ''; |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * telephone |
|
269 | - * The telephone number. |
|
270 | - * |
|
271 | - * @access public |
|
272 | - * @param string $phone_nmbr |
|
273 | - * @return string |
|
274 | - */ |
|
275 | - public static function telephone($phone_nmbr = null) |
|
276 | - { |
|
277 | - return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
278 | - : ''; |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * URL |
|
285 | - * URL of the item as a clickable link |
|
286 | - * |
|
287 | - * @access public |
|
288 | - * @param string $url - the URL that the link will resolve to |
|
289 | - * @param string $text - the text that will be used for the visible link |
|
290 | - * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
|
291 | - * @return string (link) |
|
292 | - */ |
|
293 | - public static function url($url = null, $text = null, $attributes = array()) |
|
294 | - { |
|
295 | - // Check the URL includes a scheme |
|
296 | - $parsed_url = parse_url($url); |
|
297 | - if (empty($parsed_url['scheme'])) { |
|
298 | - $url = 'https://' . ltrim($url, '/'); |
|
299 | - } |
|
300 | - $atts = ''; |
|
301 | - foreach ($attributes as $attribute => $value) { |
|
302 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
303 | - } |
|
304 | - $text = $text !== null && $text !== '' ? $text : esc_url($url); |
|
305 | - return ! empty($url) |
|
306 | - ? '<a itemprop="url" href="' . esc_url_raw($url) . '"' . $atts . '>' . $text . '</a>' |
|
307 | - : ''; |
|
308 | - } |
|
15 | + /** |
|
16 | + * generates JSON-based linked data for an event |
|
17 | + * |
|
18 | + * @param EE_Event $event |
|
19 | + * @throws EE_Error |
|
20 | + */ |
|
21 | + public static function add_json_linked_data_for_event(EE_Event $event) |
|
22 | + { |
|
23 | + // Check we have a valid datetime for the event |
|
24 | + if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
25 | + return; |
|
26 | + } |
|
27 | + |
|
28 | + $template_args = array( |
|
29 | + 'event_permalink' => '', |
|
30 | + 'event_name' => '', |
|
31 | + 'event_description' => '', |
|
32 | + 'event_start' => '', |
|
33 | + 'event_end' => '', |
|
34 | + 'event_attendance_mode' => '', |
|
35 | + 'event_status' => '', |
|
36 | + 'currency' => '', |
|
37 | + 'event_tickets' => array(), |
|
38 | + 'venue_name' => '', |
|
39 | + 'venue_url' => '', |
|
40 | + 'venue_locality' => '', |
|
41 | + 'venue_region' => '', |
|
42 | + 'venue_address' => '', |
|
43 | + 'event_image' => '', |
|
44 | + ); |
|
45 | + $template_args['event_permalink'] = $event->get_permalink(); |
|
46 | + $template_args['event_name'] = $event->name(); |
|
47 | + $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
48 | + // clone datetime so that date formats don't override those for the original datetime |
|
49 | + $primary_datetime = clone $event->primary_datetime(); |
|
50 | + $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
51 | + $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
52 | + unset($primary_datetime); |
|
53 | + switch ($event->status()) { |
|
54 | + case EEM_Event::cancelled: |
|
55 | + $event_status = 'EventCancelled'; |
|
56 | + break; |
|
57 | + case EEM_Event::postponed: |
|
58 | + $event_status = 'EventPostponed'; |
|
59 | + break; |
|
60 | + default: |
|
61 | + $event_status = 'EventScheduled'; |
|
62 | + } |
|
63 | + $template_args['event_attendance_mode'] = 'OfflineEventAttendanceMode'; |
|
64 | + $template_args['event_status'] = 'https://schema.org/' . $event_status; |
|
65 | + $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
66 | + foreach ($event->tickets() as $original_ticket) { |
|
67 | + // clone tickets so that date formats don't override those for the original ticket |
|
68 | + $ticket = clone $original_ticket; |
|
69 | + $ID = $ticket->ID(); |
|
70 | + $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
71 | + $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
72 | + $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
73 | + $ticket->price(), |
|
74 | + EE_Registry::instance()->CFG->currency->dec_plc, |
|
75 | + EE_Registry::instance()->CFG->currency->dec_mrk, |
|
76 | + '' |
|
77 | + ); |
|
78 | + switch ($ticket->ticket_status()) { |
|
79 | + case 'TKO': |
|
80 | + $availability = 'InStock'; |
|
81 | + break; |
|
82 | + case 'TKS': |
|
83 | + $availability = 'SoldOut'; |
|
84 | + break; |
|
85 | + default: |
|
86 | + $availability = null; |
|
87 | + break; |
|
88 | + } |
|
89 | + $template_args['event_tickets'][ $ID ]['availability'] = $availability; |
|
90 | + unset($ticket); |
|
91 | + } |
|
92 | + $VNU_ID = espresso_venue_id(); |
|
93 | + if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
94 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
95 | + $template_args['venue_name'] = get_the_title($VNU_ID); |
|
96 | + $template_args['venue_url'] = get_permalink($VNU_ID); |
|
97 | + $template_args['venue_locality'] = $venue->city(); |
|
98 | + $template_args['venue_region'] = $venue->state_name(); |
|
99 | + $template_args['venue_address'] = $venue->address(); |
|
100 | + if ($venue->virtual_url() !== '') { |
|
101 | + $template_args['event_attendance_mode'] = 'OnlineEventAttendanceMode'; |
|
102 | + } |
|
103 | + if ($venue->virtual_url() !== '' && $venue->address() !== '') { |
|
104 | + $template_args['event_attendance_mode'] = 'MixedEventAttendanceMode'; |
|
105 | + } |
|
106 | + } |
|
107 | + $template_args['event_image'] = $event->feature_image_url(); |
|
108 | + $template_args = apply_filters( |
|
109 | + 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
110 | + $template_args, |
|
111 | + $event, |
|
112 | + $VNU_ID |
|
113 | + ); |
|
114 | + extract($template_args, EXTR_OVERWRITE); |
|
115 | + include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * location |
|
121 | + * The location of the event, organization or action. |
|
122 | + * Should include the Venue name AND schema formatted address info |
|
123 | + * |
|
124 | + * @access public |
|
125 | + * @param string $location |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + public static function location($location = null) |
|
129 | + { |
|
130 | + return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
131 | + . $location |
|
132 | + . '</div>' : ''; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * name |
|
139 | + * The name of the Event or Venue. |
|
140 | + * |
|
141 | + * @access public |
|
142 | + * @param string $name |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public static function name($name = null) |
|
146 | + { |
|
147 | + return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * streetAddress |
|
154 | + * The street address. For example, 1600 Amphitheatre Pkwy. |
|
155 | + * |
|
156 | + * @access public |
|
157 | + * @param AddressInterface $obj_with_address |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + public static function streetAddress(AddressInterface $obj_with_address = null) |
|
161 | + { |
|
162 | + return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
|
163 | + ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * postOfficeBoxNumber |
|
170 | + * The post office box number for PO box addresses. |
|
171 | + * |
|
172 | + * @access public |
|
173 | + * @param AddressInterface $obj_with_address |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + public static function postOfficeBoxNumber(AddressInterface $obj_with_address = null) |
|
177 | + { |
|
178 | + // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
|
179 | + if ( |
|
180 | + preg_match( |
|
181 | + "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
|
182 | + $obj_with_address->address2() |
|
183 | + ) |
|
184 | + ) { |
|
185 | + return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
|
186 | + ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
187 | + } else { |
|
188 | + return $obj_with_address->address2(); |
|
189 | + } |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * addressLocality |
|
196 | + * The locality (city, town, etc). For example, Mountain View. |
|
197 | + * |
|
198 | + * @access public |
|
199 | + * @param AddressInterface $obj_with_address |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public static function addressLocality(AddressInterface $obj_with_address = null) |
|
203 | + { |
|
204 | + return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
|
205 | + ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * addressRegion |
|
212 | + * The region (state, province, etc). For example, CA. |
|
213 | + * |
|
214 | + * @access public |
|
215 | + * @param AddressInterface $obj_with_address |
|
216 | + * @return string |
|
217 | + */ |
|
218 | + public static function addressRegion(AddressInterface $obj_with_address = null) |
|
219 | + { |
|
220 | + $state = $obj_with_address->state_name(); |
|
221 | + if (! empty($state)) { |
|
222 | + return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
223 | + } else { |
|
224 | + return ''; |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * addressCountry |
|
232 | + * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. |
|
233 | + * |
|
234 | + * @access public |
|
235 | + * @param AddressInterface $obj_with_address |
|
236 | + * @return string |
|
237 | + */ |
|
238 | + public static function addressCountry(AddressInterface $obj_with_address = null) |
|
239 | + { |
|
240 | + $country = $obj_with_address->country_name(); |
|
241 | + if (! empty($country)) { |
|
242 | + return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
243 | + } else { |
|
244 | + return ''; |
|
245 | + } |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * postalCode |
|
252 | + * The postal code. For example, 94043. |
|
253 | + * |
|
254 | + * @access public |
|
255 | + * @param AddressInterface $obj_with_address |
|
256 | + * @return string |
|
257 | + */ |
|
258 | + public static function postalCode(AddressInterface $obj_with_address = null) |
|
259 | + { |
|
260 | + return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
|
261 | + . $obj_with_address->zip() |
|
262 | + . '</span>' : ''; |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * telephone |
|
269 | + * The telephone number. |
|
270 | + * |
|
271 | + * @access public |
|
272 | + * @param string $phone_nmbr |
|
273 | + * @return string |
|
274 | + */ |
|
275 | + public static function telephone($phone_nmbr = null) |
|
276 | + { |
|
277 | + return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
278 | + : ''; |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * URL |
|
285 | + * URL of the item as a clickable link |
|
286 | + * |
|
287 | + * @access public |
|
288 | + * @param string $url - the URL that the link will resolve to |
|
289 | + * @param string $text - the text that will be used for the visible link |
|
290 | + * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
|
291 | + * @return string (link) |
|
292 | + */ |
|
293 | + public static function url($url = null, $text = null, $attributes = array()) |
|
294 | + { |
|
295 | + // Check the URL includes a scheme |
|
296 | + $parsed_url = parse_url($url); |
|
297 | + if (empty($parsed_url['scheme'])) { |
|
298 | + $url = 'https://' . ltrim($url, '/'); |
|
299 | + } |
|
300 | + $atts = ''; |
|
301 | + foreach ($attributes as $attribute => $value) { |
|
302 | + $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
303 | + } |
|
304 | + $text = $text !== null && $text !== '' ? $text : esc_url($url); |
|
305 | + return ! empty($url) |
|
306 | + ? '<a itemprop="url" href="' . esc_url_raw($url) . '"' . $atts . '>' . $text . '</a>' |
|
307 | + : ''; |
|
308 | + } |
|
309 | 309 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | public static function add_json_linked_data_for_event(EE_Event $event) |
22 | 22 | { |
23 | 23 | // Check we have a valid datetime for the event |
24 | - if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
24 | + if ( ! $event->primary_datetime() instanceof EE_Datetime) { |
|
25 | 25 | return; |
26 | 26 | } |
27 | 27 | |
@@ -61,15 +61,15 @@ discard block |
||
61 | 61 | $event_status = 'EventScheduled'; |
62 | 62 | } |
63 | 63 | $template_args['event_attendance_mode'] = 'OfflineEventAttendanceMode'; |
64 | - $template_args['event_status'] = 'https://schema.org/' . $event_status; |
|
64 | + $template_args['event_status'] = 'https://schema.org/'.$event_status; |
|
65 | 65 | $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
66 | 66 | foreach ($event->tickets() as $original_ticket) { |
67 | 67 | // clone tickets so that date formats don't override those for the original ticket |
68 | 68 | $ticket = clone $original_ticket; |
69 | 69 | $ID = $ticket->ID(); |
70 | - $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
71 | - $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
72 | - $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
70 | + $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
71 | + $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
72 | + $template_args['event_tickets'][$ID]['price'] = number_format( |
|
73 | 73 | $ticket->price(), |
74 | 74 | EE_Registry::instance()->CFG->currency->dec_plc, |
75 | 75 | EE_Registry::instance()->CFG->currency->dec_mrk, |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | $availability = null; |
87 | 87 | break; |
88 | 88 | } |
89 | - $template_args['event_tickets'][ $ID ]['availability'] = $availability; |
|
89 | + $template_args['event_tickets'][$ID]['availability'] = $availability; |
|
90 | 90 | unset($ticket); |
91 | 91 | } |
92 | 92 | $VNU_ID = espresso_venue_id(); |
93 | - if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
93 | + if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
94 | 94 | $venue = EEH_Venue_View::get_venue($VNU_ID); |
95 | 95 | $template_args['venue_name'] = get_the_title($VNU_ID); |
96 | 96 | $template_args['venue_url'] = get_permalink($VNU_ID); |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $VNU_ID |
113 | 113 | ); |
114 | 114 | extract($template_args, EXTR_OVERWRITE); |
115 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
115 | + include EE_TEMPLATES.'json_linked_data_for_event.template.php'; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public static function name($name = null) |
146 | 146 | { |
147 | - return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
147 | + return ! empty($name) ? '<span itemprop="name">'.$name.'</span>' : ''; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | public static function streetAddress(AddressInterface $obj_with_address = null) |
161 | 161 | { |
162 | 162 | return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
163 | - ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
163 | + ? '<span itemprop="streetAddress">'.$obj_with_address->address().'</span>' : ''; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | ) |
184 | 184 | ) { |
185 | 185 | return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
186 | - ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
186 | + ? '<span itemprop="postOfficeBoxNumber">'.$obj_with_address->address2().'</span>' : ''; |
|
187 | 187 | } else { |
188 | 188 | return $obj_with_address->address2(); |
189 | 189 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | public static function addressLocality(AddressInterface $obj_with_address = null) |
203 | 203 | { |
204 | 204 | return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
205 | - ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
205 | + ? '<span itemprop="addressLocality">'.$obj_with_address->city().'</span>' : ''; |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | |
@@ -218,8 +218,8 @@ discard block |
||
218 | 218 | public static function addressRegion(AddressInterface $obj_with_address = null) |
219 | 219 | { |
220 | 220 | $state = $obj_with_address->state_name(); |
221 | - if (! empty($state)) { |
|
222 | - return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
221 | + if ( ! empty($state)) { |
|
222 | + return '<span itemprop="addressRegion">'.$state.'</span>'; |
|
223 | 223 | } else { |
224 | 224 | return ''; |
225 | 225 | } |
@@ -238,8 +238,8 @@ discard block |
||
238 | 238 | public static function addressCountry(AddressInterface $obj_with_address = null) |
239 | 239 | { |
240 | 240 | $country = $obj_with_address->country_name(); |
241 | - if (! empty($country)) { |
|
242 | - return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
241 | + if ( ! empty($country)) { |
|
242 | + return '<span itemprop="addressCountry">'.$country.'</span>'; |
|
243 | 243 | } else { |
244 | 244 | return ''; |
245 | 245 | } |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | */ |
275 | 275 | public static function telephone($phone_nmbr = null) |
276 | 276 | { |
277 | - return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
277 | + return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">'.$phone_nmbr.'</span>' |
|
278 | 278 | : ''; |
279 | 279 | } |
280 | 280 | |
@@ -295,15 +295,15 @@ discard block |
||
295 | 295 | // Check the URL includes a scheme |
296 | 296 | $parsed_url = parse_url($url); |
297 | 297 | if (empty($parsed_url['scheme'])) { |
298 | - $url = 'https://' . ltrim($url, '/'); |
|
298 | + $url = 'https://'.ltrim($url, '/'); |
|
299 | 299 | } |
300 | 300 | $atts = ''; |
301 | 301 | foreach ($attributes as $attribute => $value) { |
302 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
302 | + $atts .= ' '.$attribute.'="'.$value.'"'; |
|
303 | 303 | } |
304 | 304 | $text = $text !== null && $text !== '' ? $text : esc_url($url); |
305 | 305 | return ! empty($url) |
306 | - ? '<a itemprop="url" href="' . esc_url_raw($url) . '"' . $atts . '>' . $text . '</a>' |
|
306 | + ? '<a itemprop="url" href="'.esc_url_raw($url).'"'.$atts.'>'.$text.'</a>' |
|
307 | 307 | : ''; |
308 | 308 | } |
309 | 309 | } |
@@ -13,124 +13,124 @@ |
||
13 | 13 | */ |
14 | 14 | class EEH_Address |
15 | 15 | { |
16 | - /** |
|
17 | - * format - output formatted EE object address information |
|
18 | - * |
|
19 | - * @access public |
|
20 | - * @param object AddressInterface $obj_with_address |
|
21 | - * @param string $type how the address is formatted. for example: 'multiline' or 'inline' |
|
22 | - * @param boolean $use_schema whether to apply schema.org formatting to the address |
|
23 | - * @param bool $add_wrapper |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public static function format( |
|
27 | - $obj_with_address = null, |
|
28 | - $type = 'multiline', |
|
29 | - $use_schema = true, |
|
30 | - $add_wrapper = true |
|
31 | - ) { |
|
32 | - // check that incoming object implements the AddressInterface interface |
|
33 | - if (! $obj_with_address instanceof AddressInterface) { |
|
34 | - $msg = esc_html__('The address could not be formatted.', 'event_espresso'); |
|
35 | - $dev_msg = esc_html__( |
|
36 | - 'The Address Formatter requires passed objects to implement the AddressInterface interface.', |
|
37 | - 'event_espresso' |
|
38 | - ); |
|
39 | - EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
40 | - return null; |
|
41 | - } |
|
42 | - // obtain an address formatter |
|
43 | - $formatter = EEH_Address::_get_formatter($type); |
|
44 | - // apply schema.org formatting ? |
|
45 | - $use_schema = ! is_admin() ? $use_schema : false; |
|
46 | - $formatted_address = $use_schema |
|
47 | - ? EEH_Address::_schema_formatting($formatter, $obj_with_address) |
|
48 | - : EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper); |
|
49 | - $formatted_address = $add_wrapper && ! $use_schema |
|
50 | - ? '<div class="espresso-address-dv">' . $formatted_address . '</div>' |
|
51 | - : $formatted_address; |
|
52 | - // return the formatted address |
|
53 | - return $formatted_address; |
|
54 | - } |
|
16 | + /** |
|
17 | + * format - output formatted EE object address information |
|
18 | + * |
|
19 | + * @access public |
|
20 | + * @param object AddressInterface $obj_with_address |
|
21 | + * @param string $type how the address is formatted. for example: 'multiline' or 'inline' |
|
22 | + * @param boolean $use_schema whether to apply schema.org formatting to the address |
|
23 | + * @param bool $add_wrapper |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public static function format( |
|
27 | + $obj_with_address = null, |
|
28 | + $type = 'multiline', |
|
29 | + $use_schema = true, |
|
30 | + $add_wrapper = true |
|
31 | + ) { |
|
32 | + // check that incoming object implements the AddressInterface interface |
|
33 | + if (! $obj_with_address instanceof AddressInterface) { |
|
34 | + $msg = esc_html__('The address could not be formatted.', 'event_espresso'); |
|
35 | + $dev_msg = esc_html__( |
|
36 | + 'The Address Formatter requires passed objects to implement the AddressInterface interface.', |
|
37 | + 'event_espresso' |
|
38 | + ); |
|
39 | + EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
40 | + return null; |
|
41 | + } |
|
42 | + // obtain an address formatter |
|
43 | + $formatter = EEH_Address::_get_formatter($type); |
|
44 | + // apply schema.org formatting ? |
|
45 | + $use_schema = ! is_admin() ? $use_schema : false; |
|
46 | + $formatted_address = $use_schema |
|
47 | + ? EEH_Address::_schema_formatting($formatter, $obj_with_address) |
|
48 | + : EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper); |
|
49 | + $formatted_address = $add_wrapper && ! $use_schema |
|
50 | + ? '<div class="espresso-address-dv">' . $formatted_address . '</div>' |
|
51 | + : $formatted_address; |
|
52 | + // return the formatted address |
|
53 | + return $formatted_address; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * _get_formatter - obtain the requester formatter class |
|
60 | - * |
|
61 | - * @access private |
|
62 | - * @param string $type how the address is formatted. for example: 'multiline' or 'inline' |
|
63 | - * @return AddressFormatterInterface |
|
64 | - */ |
|
65 | - private static function _get_formatter($type) |
|
66 | - { |
|
67 | - switch ($type) { |
|
68 | - case 'multiline': |
|
69 | - return new EventEspresso\core\services\address\formatters\MultiLineAddressFormatter(); |
|
70 | - case 'inline': |
|
71 | - return new EventEspresso\core\services\address\formatters\InlineAddressFormatter(); |
|
72 | - default: |
|
73 | - return new EventEspresso\core\services\address\formatters\NullAddressFormatter(); |
|
74 | - } |
|
75 | - } |
|
58 | + /** |
|
59 | + * _get_formatter - obtain the requester formatter class |
|
60 | + * |
|
61 | + * @access private |
|
62 | + * @param string $type how the address is formatted. for example: 'multiline' or 'inline' |
|
63 | + * @return AddressFormatterInterface |
|
64 | + */ |
|
65 | + private static function _get_formatter($type) |
|
66 | + { |
|
67 | + switch ($type) { |
|
68 | + case 'multiline': |
|
69 | + return new EventEspresso\core\services\address\formatters\MultiLineAddressFormatter(); |
|
70 | + case 'inline': |
|
71 | + return new EventEspresso\core\services\address\formatters\InlineAddressFormatter(); |
|
72 | + default: |
|
73 | + return new EventEspresso\core\services\address\formatters\NullAddressFormatter(); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * _regular_formatting |
|
81 | - * adds formatting to an address |
|
82 | - * |
|
83 | - * @access private |
|
84 | - * @param object AddressInterface_Formatter $formatter |
|
85 | - * @param object AddressInterface $obj_with_address |
|
86 | - * @param bool $add_wrapper |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - private static function _regular_formatting( |
|
90 | - AddressFormatterInterface $formatter, |
|
91 | - AddressInterface $obj_with_address, |
|
92 | - $add_wrapper = true |
|
93 | - ) { |
|
94 | - $formatted_address = $add_wrapper ? '<div>' : ''; |
|
95 | - $formatted_address .= $formatter->format( |
|
96 | - $obj_with_address->address(), |
|
97 | - $obj_with_address->address2(), |
|
98 | - $obj_with_address->city(), |
|
99 | - $obj_with_address->state_name(), |
|
100 | - $obj_with_address->zip(), |
|
101 | - $obj_with_address->country_name(), |
|
102 | - $obj_with_address->country_ID() |
|
103 | - ); |
|
104 | - $formatted_address .= $add_wrapper ? '</div>' : ''; |
|
105 | - // return the formatted address |
|
106 | - return $formatted_address; |
|
107 | - } |
|
79 | + /** |
|
80 | + * _regular_formatting |
|
81 | + * adds formatting to an address |
|
82 | + * |
|
83 | + * @access private |
|
84 | + * @param object AddressInterface_Formatter $formatter |
|
85 | + * @param object AddressInterface $obj_with_address |
|
86 | + * @param bool $add_wrapper |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + private static function _regular_formatting( |
|
90 | + AddressFormatterInterface $formatter, |
|
91 | + AddressInterface $obj_with_address, |
|
92 | + $add_wrapper = true |
|
93 | + ) { |
|
94 | + $formatted_address = $add_wrapper ? '<div>' : ''; |
|
95 | + $formatted_address .= $formatter->format( |
|
96 | + $obj_with_address->address(), |
|
97 | + $obj_with_address->address2(), |
|
98 | + $obj_with_address->city(), |
|
99 | + $obj_with_address->state_name(), |
|
100 | + $obj_with_address->zip(), |
|
101 | + $obj_with_address->country_name(), |
|
102 | + $obj_with_address->country_ID() |
|
103 | + ); |
|
104 | + $formatted_address .= $add_wrapper ? '</div>' : ''; |
|
105 | + // return the formatted address |
|
106 | + return $formatted_address; |
|
107 | + } |
|
108 | 108 | |
109 | 109 | |
110 | 110 | |
111 | - /** |
|
112 | - * _schema_formatting |
|
113 | - * adds schema.org formatting to an address |
|
114 | - * |
|
115 | - * @access private |
|
116 | - * @param object AddressFormatterInterface $formatter |
|
117 | - * @param object AddressInterface $obj_with_address |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - private static function _schema_formatting(AddressFormatterInterface $formatter, AddressInterface $obj_with_address) |
|
121 | - { |
|
122 | - $formatted_address = '<div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">'; |
|
123 | - $formatted_address .= $formatter->format( |
|
124 | - EEH_Schema::streetAddress($obj_with_address), |
|
125 | - EEH_Schema::postOfficeBoxNumber($obj_with_address), |
|
126 | - EEH_Schema::addressLocality($obj_with_address), |
|
127 | - EEH_Schema::addressRegion($obj_with_address), |
|
128 | - EEH_Schema::postalCode($obj_with_address), |
|
129 | - EEH_Schema::addressCountry($obj_with_address), |
|
130 | - $obj_with_address->country_ID() |
|
131 | - ); |
|
132 | - $formatted_address .= '</div>'; |
|
133 | - // return the formatted address |
|
134 | - return $formatted_address; |
|
135 | - } |
|
111 | + /** |
|
112 | + * _schema_formatting |
|
113 | + * adds schema.org formatting to an address |
|
114 | + * |
|
115 | + * @access private |
|
116 | + * @param object AddressFormatterInterface $formatter |
|
117 | + * @param object AddressInterface $obj_with_address |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + private static function _schema_formatting(AddressFormatterInterface $formatter, AddressInterface $obj_with_address) |
|
121 | + { |
|
122 | + $formatted_address = '<div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">'; |
|
123 | + $formatted_address .= $formatter->format( |
|
124 | + EEH_Schema::streetAddress($obj_with_address), |
|
125 | + EEH_Schema::postOfficeBoxNumber($obj_with_address), |
|
126 | + EEH_Schema::addressLocality($obj_with_address), |
|
127 | + EEH_Schema::addressRegion($obj_with_address), |
|
128 | + EEH_Schema::postalCode($obj_with_address), |
|
129 | + EEH_Schema::addressCountry($obj_with_address), |
|
130 | + $obj_with_address->country_ID() |
|
131 | + ); |
|
132 | + $formatted_address .= '</div>'; |
|
133 | + // return the formatted address |
|
134 | + return $formatted_address; |
|
135 | + } |
|
136 | 136 | } |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | $add_wrapper = true |
31 | 31 | ) { |
32 | 32 | // check that incoming object implements the AddressInterface interface |
33 | - if (! $obj_with_address instanceof AddressInterface) { |
|
33 | + if ( ! $obj_with_address instanceof AddressInterface) { |
|
34 | 34 | $msg = esc_html__('The address could not be formatted.', 'event_espresso'); |
35 | 35 | $dev_msg = esc_html__( |
36 | 36 | 'The Address Formatter requires passed objects to implement the AddressInterface interface.', |
37 | 37 | 'event_espresso' |
38 | 38 | ); |
39 | - EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
39 | + EE_Error::add_error($msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
40 | 40 | return null; |
41 | 41 | } |
42 | 42 | // obtain an address formatter |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | ? EEH_Address::_schema_formatting($formatter, $obj_with_address) |
48 | 48 | : EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper); |
49 | 49 | $formatted_address = $add_wrapper && ! $use_schema |
50 | - ? '<div class="espresso-address-dv">' . $formatted_address . '</div>' |
|
50 | + ? '<div class="espresso-address-dv">'.$formatted_address.'</div>' |
|
51 | 51 | : $formatted_address; |
52 | 52 | // return the formatted address |
53 | 53 | return $formatted_address; |
@@ -3,21 +3,21 @@ |
||
3 | 3 | // autoload.php @generated by Composer |
4 | 4 | |
5 | 5 | if (PHP_VERSION_ID < 50600) { |
6 | - if (!headers_sent()) { |
|
7 | - header('HTTP/1.1 500 Internal Server Error'); |
|
8 | - } |
|
9 | - $err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL; |
|
10 | - if (!ini_get('display_errors')) { |
|
11 | - if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { |
|
12 | - fwrite(STDERR, $err); |
|
13 | - } elseif (!headers_sent()) { |
|
14 | - echo $err; |
|
15 | - } |
|
16 | - } |
|
17 | - trigger_error( |
|
18 | - $err, |
|
19 | - E_USER_ERROR |
|
20 | - ); |
|
6 | + if (!headers_sent()) { |
|
7 | + header('HTTP/1.1 500 Internal Server Error'); |
|
8 | + } |
|
9 | + $err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL; |
|
10 | + if (!ini_get('display_errors')) { |
|
11 | + if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { |
|
12 | + fwrite(STDERR, $err); |
|
13 | + } elseif (!headers_sent()) { |
|
14 | + echo $err; |
|
15 | + } |
|
16 | + } |
|
17 | + trigger_error( |
|
18 | + $err, |
|
19 | + E_USER_ERROR |
|
20 | + ); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | require_once __DIR__ . '/composer/autoload_real.php'; |
@@ -3,14 +3,14 @@ discard block |
||
3 | 3 | // autoload.php @generated by Composer |
4 | 4 | |
5 | 5 | if (PHP_VERSION_ID < 50600) { |
6 | - if (!headers_sent()) { |
|
6 | + if ( ! headers_sent()) { |
|
7 | 7 | header('HTTP/1.1 500 Internal Server Error'); |
8 | 8 | } |
9 | 9 | $err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL; |
10 | - if (!ini_get('display_errors')) { |
|
10 | + if ( ! ini_get('display_errors')) { |
|
11 | 11 | if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { |
12 | 12 | fwrite(STDERR, $err); |
13 | - } elseif (!headers_sent()) { |
|
13 | + } elseif ( ! headers_sent()) { |
|
14 | 14 | echo $err; |
15 | 15 | } |
16 | 16 | } |
@@ -20,6 +20,6 @@ discard block |
||
20 | 20 | ); |
21 | 21 | } |
22 | 22 | |
23 | -require_once __DIR__ . '/composer/autoload_real.php'; |
|
23 | +require_once __DIR__.'/composer/autoload_real.php'; |
|
24 | 24 | |
25 | 25 | return ComposerAutoloaderInit400b9a7451a6cbd04853b52d867b55fe::getLoader(); |
@@ -26,42 +26,42 @@ |
||
26 | 26 | */ |
27 | 27 | class CssSelectorConverter |
28 | 28 | { |
29 | - private Translator $translator; |
|
30 | - private array $cache; |
|
29 | + private Translator $translator; |
|
30 | + private array $cache; |
|
31 | 31 | |
32 | - private static array $xmlCache = []; |
|
33 | - private static array $htmlCache = []; |
|
32 | + private static array $xmlCache = []; |
|
33 | + private static array $htmlCache = []; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param bool $html Whether HTML support should be enabled. Disable it for XML documents |
|
37 | - */ |
|
38 | - public function __construct(bool $html = true) |
|
39 | - { |
|
40 | - $this->translator = new Translator(); |
|
35 | + /** |
|
36 | + * @param bool $html Whether HTML support should be enabled. Disable it for XML documents |
|
37 | + */ |
|
38 | + public function __construct(bool $html = true) |
|
39 | + { |
|
40 | + $this->translator = new Translator(); |
|
41 | 41 | |
42 | - if ($html) { |
|
43 | - $this->translator->registerExtension(new HtmlExtension($this->translator)); |
|
44 | - $this->cache = &self::$htmlCache; |
|
45 | - } else { |
|
46 | - $this->cache = &self::$xmlCache; |
|
47 | - } |
|
42 | + if ($html) { |
|
43 | + $this->translator->registerExtension(new HtmlExtension($this->translator)); |
|
44 | + $this->cache = &self::$htmlCache; |
|
45 | + } else { |
|
46 | + $this->cache = &self::$xmlCache; |
|
47 | + } |
|
48 | 48 | |
49 | - $this->translator |
|
50 | - ->registerParserShortcut(new EmptyStringParser()) |
|
51 | - ->registerParserShortcut(new ElementParser()) |
|
52 | - ->registerParserShortcut(new ClassParser()) |
|
53 | - ->registerParserShortcut(new HashParser()) |
|
54 | - ; |
|
55 | - } |
|
49 | + $this->translator |
|
50 | + ->registerParserShortcut(new EmptyStringParser()) |
|
51 | + ->registerParserShortcut(new ElementParser()) |
|
52 | + ->registerParserShortcut(new ClassParser()) |
|
53 | + ->registerParserShortcut(new HashParser()) |
|
54 | + ; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Translates a CSS expression to its XPath equivalent. |
|
59 | - * |
|
60 | - * Optionally, a prefix can be added to the resulting XPath |
|
61 | - * expression with the $prefix parameter. |
|
62 | - */ |
|
63 | - public function toXPath(string $cssExpr, string $prefix = 'descendant-or-self::'): string |
|
64 | - { |
|
65 | - return $this->cache[$prefix][$cssExpr] ??= $this->translator->cssToXPath($cssExpr, $prefix); |
|
66 | - } |
|
57 | + /** |
|
58 | + * Translates a CSS expression to its XPath equivalent. |
|
59 | + * |
|
60 | + * Optionally, a prefix can be added to the resulting XPath |
|
61 | + * expression with the $prefix parameter. |
|
62 | + */ |
|
63 | + public function toXPath(string $cssExpr, string $prefix = 'descendant-or-self::'): string |
|
64 | + { |
|
65 | + return $this->cache[$prefix][$cssExpr] ??= $this->translator->cssToXPath($cssExpr, $prefix); |
|
66 | + } |
|
67 | 67 | } |
@@ -23,35 +23,35 @@ |
||
23 | 23 | */ |
24 | 24 | class PseudoNode extends AbstractNode |
25 | 25 | { |
26 | - private NodeInterface $selector; |
|
27 | - private string $identifier; |
|
28 | - |
|
29 | - public function __construct(NodeInterface $selector, string $identifier) |
|
30 | - { |
|
31 | - $this->selector = $selector; |
|
32 | - $this->identifier = strtolower($identifier); |
|
33 | - } |
|
34 | - |
|
35 | - public function getSelector(): NodeInterface |
|
36 | - { |
|
37 | - return $this->selector; |
|
38 | - } |
|
39 | - |
|
40 | - public function getIdentifier(): string |
|
41 | - { |
|
42 | - return $this->identifier; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function getSpecificity(): Specificity |
|
49 | - { |
|
50 | - return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0)); |
|
51 | - } |
|
52 | - |
|
53 | - public function __toString(): string |
|
54 | - { |
|
55 | - return sprintf('%s[%s:%s]', $this->getNodeName(), $this->selector, $this->identifier); |
|
56 | - } |
|
26 | + private NodeInterface $selector; |
|
27 | + private string $identifier; |
|
28 | + |
|
29 | + public function __construct(NodeInterface $selector, string $identifier) |
|
30 | + { |
|
31 | + $this->selector = $selector; |
|
32 | + $this->identifier = strtolower($identifier); |
|
33 | + } |
|
34 | + |
|
35 | + public function getSelector(): NodeInterface |
|
36 | + { |
|
37 | + return $this->selector; |
|
38 | + } |
|
39 | + |
|
40 | + public function getIdentifier(): string |
|
41 | + { |
|
42 | + return $this->identifier; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function getSpecificity(): Specificity |
|
49 | + { |
|
50 | + return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0)); |
|
51 | + } |
|
52 | + |
|
53 | + public function __toString(): string |
|
54 | + { |
|
55 | + return sprintf('%s[%s:%s]', $this->getNodeName(), $this->selector, $this->identifier); |
|
56 | + } |
|
57 | 57 | } |