@@ -14,474 +14,474 @@ discard block |
||
14 | 14 | class EED_Event_Single extends EED_Module |
15 | 15 | { |
16 | 16 | |
17 | - const EVENT_DETAILS_PRIORITY = 100; |
|
18 | - const EVENT_DATETIMES_PRIORITY = 110; |
|
19 | - const EVENT_TICKETS_PRIORITY = 120; |
|
20 | - const EVENT_VENUES_PRIORITY = 130; |
|
21 | - |
|
22 | - /** |
|
23 | - * @type bool $using_get_the_excerpt |
|
24 | - */ |
|
25 | - protected static $using_get_the_excerpt = false; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * @type EE_Template_Part_Manager $template_parts |
|
30 | - */ |
|
31 | - protected $template_parts; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @return EED_Module|EED_Event_Single |
|
36 | - */ |
|
37 | - public static function instance() |
|
38 | - { |
|
39 | - return parent::get_instance(__CLASS__); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
45 | - * |
|
46 | - * @return void |
|
47 | - * @throws InvalidArgumentException |
|
48 | - * @throws InvalidDataTypeException |
|
49 | - * @throws InvalidInterfaceException |
|
50 | - */ |
|
51 | - public static function set_hooks() |
|
52 | - { |
|
53 | - add_filter('FHEE_run_EE_wp', '__return_true'); |
|
54 | - add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
55 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
56 | - $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
57 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
58 | - ); |
|
59 | - $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
60 | - EE_Config::register_route( |
|
61 | - $custom_post_types['espresso_events']['singular_slug'], |
|
62 | - 'Event_Single', |
|
63 | - 'run' |
|
64 | - ); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
69 | - * |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public static function set_hooks_admin() |
|
73 | - { |
|
74 | - add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * set_definitions |
|
80 | - * |
|
81 | - * @static |
|
82 | - * @return void |
|
83 | - */ |
|
84 | - public static function set_definitions() |
|
85 | - { |
|
86 | - define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
87 | - define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/'); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * set_config |
|
93 | - * |
|
94 | - * @void |
|
95 | - */ |
|
96 | - protected function set_config() |
|
97 | - { |
|
98 | - $this->set_config_section('template_settings'); |
|
99 | - $this->set_config_class('EE_Event_Single_Config'); |
|
100 | - $this->set_config_name('EED_Event_Single'); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * initialize_template_parts |
|
106 | - * |
|
107 | - * @param EE_Config_Base|EE_Event_Single_Config $config |
|
108 | - * @return EE_Template_Part_Manager |
|
109 | - */ |
|
110 | - public function initialize_template_parts(EE_Event_Single_Config $config = null) |
|
111 | - { |
|
112 | - /** @type EE_Event_Single_Config $config */ |
|
113 | - $config = $config instanceof EE_Event_Single_Config ? $config : $this->config(); |
|
114 | - EEH_Autoloader::instance()->register_template_part_autoloaders(); |
|
115 | - $template_parts = new EE_Template_Part_Manager(); |
|
116 | - $template_parts->add_template_part( |
|
117 | - 'tickets', |
|
118 | - esc_html__('Ticket Selector', 'event_espresso'), |
|
119 | - 'content-espresso_events-tickets.php', |
|
120 | - $config->display_order_tickets |
|
121 | - ); |
|
122 | - $template_parts->add_template_part( |
|
123 | - 'datetimes', |
|
124 | - esc_html__('Dates and Times', 'event_espresso'), |
|
125 | - 'content-espresso_events-datetimes.php', |
|
126 | - $config->display_order_datetimes |
|
127 | - ); |
|
128 | - $template_parts->add_template_part( |
|
129 | - 'event', |
|
130 | - esc_html__('Event Description', 'event_espresso'), |
|
131 | - 'content-espresso_events-details.php', |
|
132 | - $config->display_order_event |
|
133 | - ); |
|
134 | - $template_parts->add_template_part( |
|
135 | - 'venue', |
|
136 | - esc_html__('Venue Information', 'event_espresso'), |
|
137 | - 'content-espresso_events-venues.php', |
|
138 | - $config->display_order_venue |
|
139 | - ); |
|
140 | - do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts); |
|
141 | - return $template_parts; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * run - initial module setup |
|
147 | - * |
|
148 | - * @param WP $WP |
|
149 | - * @return void |
|
150 | - */ |
|
151 | - public function run($WP) |
|
152 | - { |
|
153 | - // ensure valid EE_Events_Single_Config() object exists |
|
154 | - $this->set_config(); |
|
155 | - // check what template is loaded |
|
156 | - add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
157 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
158 | - // load css |
|
159 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * template_include |
|
165 | - * |
|
166 | - * @param string $template |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - public function template_include($template) |
|
170 | - { |
|
171 | - global $post; |
|
172 | - /** @type EE_Event_Single_Config $config */ |
|
173 | - $config = $this->config(); |
|
174 | - if ($config->display_status_banner_single) { |
|
175 | - add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2); |
|
176 | - } |
|
177 | - // not a custom template? |
|
178 | - if ( |
|
179 | - ! post_password_required($post) |
|
180 | - && ( |
|
181 | - apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false) |
|
182 | - || EE_Registry::instance() |
|
183 | - ->load_core('Front_Controller') |
|
184 | - ->get_selected_template() !== 'single-espresso_events.php' |
|
185 | - ) |
|
186 | - ) { |
|
187 | - EEH_Template::load_espresso_theme_functions(); |
|
188 | - // then add extra event data via hooks |
|
189 | - add_action('loop_start', array('EED_Event_Single', 'loop_start')); |
|
190 | - add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1); |
|
191 | - add_filter( |
|
192 | - 'the_content', |
|
193 | - array('EED_Event_Single', 'event_details'), |
|
194 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
195 | - ); |
|
196 | - add_action('loop_end', array('EED_Event_Single', 'loop_end')); |
|
197 | - // don't display entry meta because the existing theme will take car of that |
|
198 | - add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
199 | - } |
|
200 | - return $template; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * loop_start |
|
206 | - * |
|
207 | - * @param array $wp_query_array an array containing the WP_Query object |
|
208 | - * @return void |
|
209 | - */ |
|
210 | - public static function loop_start($wp_query_array) |
|
211 | - { |
|
212 | - global $post; |
|
213 | - do_action('AHEE_event_details_before_post', $post, $wp_query_array); |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * the_title |
|
219 | - * |
|
220 | - * @param string $title |
|
221 | - * @param int $id |
|
222 | - * @return string |
|
223 | - */ |
|
224 | - public static function the_title($title = '', $id = 0) |
|
225 | - { |
|
226 | - global $post; |
|
227 | - return ((function_exists('wp_is_block_theme') && wp_is_block_theme()) || in_the_loop()) && $post->ID === (int) $id |
|
228 | - ? espresso_event_status_banner($post->ID) . $title |
|
229 | - : $title; |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * get_the_excerpt |
|
235 | - * kinda hacky, but if a theme is using get_the_excerpt(), |
|
236 | - * then we need to remove our filters on the_content() |
|
237 | - * |
|
238 | - * @param string $excerpt |
|
239 | - * @return string |
|
240 | - */ |
|
241 | - public static function get_the_excerpt($excerpt = '') |
|
242 | - { |
|
243 | - EED_Event_Single::$using_get_the_excerpt = true; |
|
244 | - add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1); |
|
245 | - return $excerpt; |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * end_get_the_excerpt |
|
251 | - * |
|
252 | - * @param string $text |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - public static function end_get_the_excerpt($text = '') |
|
256 | - { |
|
257 | - EED_Event_Single::$using_get_the_excerpt = false; |
|
258 | - return $text; |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * event_details |
|
264 | - * |
|
265 | - * @param string $content |
|
266 | - * @return string |
|
267 | - */ |
|
268 | - public static function event_details($content) |
|
269 | - { |
|
270 | - global $post; |
|
271 | - static $current_post_ID = 0; |
|
272 | - if ( |
|
273 | - $current_post_ID !== $post->ID |
|
274 | - && $post->post_type === 'espresso_events' |
|
275 | - && ! EED_Event_Single::$using_get_the_excerpt |
|
276 | - && ! post_password_required() |
|
277 | - ) { |
|
278 | - // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
279 | - // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
280 | - // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
281 | - // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
282 | - // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
283 | - // so the following allows this filter to be applied multiple times, but only once for real |
|
284 | - $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
285 | - if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) { |
|
286 | - // we need to first remove this callback from being applied to the_content() |
|
287 | - // (otherwise it will recurse and blow up the interweb) |
|
288 | - remove_filter( |
|
289 | - 'the_content', |
|
290 | - array('EED_Event_Single', 'event_details'), |
|
291 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
292 | - ); |
|
293 | - EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts( |
|
294 | - ); |
|
295 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
296 | - $content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content); |
|
297 | - add_filter( |
|
298 | - 'the_content', |
|
299 | - array('EED_Event_Single', 'event_details'), |
|
300 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
301 | - ); |
|
302 | - } else { |
|
303 | - $content = EED_Event_Single::use_filterable_display_order(); |
|
304 | - } |
|
305 | - } |
|
306 | - return $content; |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * use_filterable_display_order |
|
312 | - * |
|
313 | - * @return string |
|
314 | - */ |
|
315 | - protected static function use_filterable_display_order() |
|
316 | - { |
|
317 | - // since the 'content-espresso_events-details.php' template might be used directly from within a theme, |
|
318 | - // it uses the_content() for displaying the $post->post_content |
|
319 | - // so in order to load a template that uses the_content() |
|
320 | - // from within a callback being used to filter the_content(), |
|
321 | - // we need to first remove this callback from being applied to the_content() |
|
322 | - // (otherwise it will recurse and blow up the interweb) |
|
323 | - remove_filter( |
|
324 | - 'the_content', |
|
325 | - array('EED_Event_Single', 'event_details'), |
|
326 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
327 | - ); |
|
328 | - // now add additional content |
|
329 | - add_filter( |
|
330 | - 'the_content', |
|
331 | - array('EED_Event_Single', 'event_datetimes'), |
|
332 | - EED_Event_Single::EVENT_DATETIMES_PRIORITY, |
|
333 | - 1 |
|
334 | - ); |
|
335 | - add_filter( |
|
336 | - 'the_content', |
|
337 | - array('EED_Event_Single', 'event_tickets'), |
|
338 | - EED_Event_Single::EVENT_TICKETS_PRIORITY, |
|
339 | - 1 |
|
340 | - ); |
|
341 | - add_filter( |
|
342 | - 'the_content', |
|
343 | - array('EED_Event_Single', 'event_venues'), |
|
344 | - EED_Event_Single::EVENT_VENUES_PRIORITY, |
|
345 | - 1 |
|
346 | - ); |
|
347 | - do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters'); |
|
348 | - // now load our template |
|
349 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
350 | - // now add our filter back in, plus some others |
|
351 | - add_filter( |
|
352 | - 'the_content', |
|
353 | - array('EED_Event_Single', 'event_details'), |
|
354 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
355 | - ); |
|
356 | - remove_filter( |
|
357 | - 'the_content', |
|
358 | - array('EED_Event_Single', 'event_datetimes'), |
|
359 | - EED_Event_Single::EVENT_DATETIMES_PRIORITY |
|
360 | - ); |
|
361 | - remove_filter( |
|
362 | - 'the_content', |
|
363 | - array('EED_Event_Single', 'event_tickets'), |
|
364 | - EED_Event_Single::EVENT_TICKETS_PRIORITY |
|
365 | - ); |
|
366 | - remove_filter( |
|
367 | - 'the_content', |
|
368 | - array('EED_Event_Single', 'event_venues'), |
|
369 | - EED_Event_Single::EVENT_VENUES_PRIORITY |
|
370 | - ); |
|
371 | - do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters'); |
|
372 | - // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
373 | - return $content; |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * event_datetimes - adds datetimes ABOVE content |
|
379 | - * |
|
380 | - * @param string $content |
|
381 | - * @return string |
|
382 | - */ |
|
383 | - public static function event_datetimes($content) |
|
384 | - { |
|
385 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
391 | - * |
|
392 | - * @param string $content |
|
393 | - * @return string |
|
394 | - */ |
|
395 | - public static function event_tickets($content) |
|
396 | - { |
|
397 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * event_venues |
|
403 | - * |
|
404 | - * @param string $content |
|
405 | - * @return string |
|
406 | - */ |
|
407 | - public static function event_venue($content) |
|
408 | - { |
|
409 | - return EED_Event_Single::event_venues($content); |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * event_venues - adds venues BELOW content |
|
415 | - * |
|
416 | - * @param string $content |
|
417 | - * @return string |
|
418 | - */ |
|
419 | - public static function event_venues($content) |
|
420 | - { |
|
421 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - /** |
|
426 | - * loop_end |
|
427 | - * |
|
428 | - * @param array $wp_query_array an array containing the WP_Query object |
|
429 | - * @return void |
|
430 | - */ |
|
431 | - public static function loop_end($wp_query_array) |
|
432 | - { |
|
433 | - global $post; |
|
434 | - do_action('AHEE_event_details_after_post', $post, $wp_query_array); |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * wp_enqueue_scripts |
|
440 | - * |
|
441 | - * @return void |
|
442 | - */ |
|
443 | - public function wp_enqueue_scripts() |
|
444 | - { |
|
445 | - // get some style |
|
446 | - if ( |
|
447 | - apply_filters('FHEE_enable_default_espresso_css', true) |
|
448 | - && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true) |
|
449 | - ) { |
|
450 | - // first check uploads folder |
|
451 | - if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
452 | - wp_register_style( |
|
453 | - $this->theme, |
|
454 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
455 | - array('dashicons', 'espresso_default') |
|
456 | - ); |
|
457 | - } else { |
|
458 | - wp_register_style( |
|
459 | - $this->theme, |
|
460 | - EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
461 | - array('dashicons', 'espresso_default') |
|
462 | - ); |
|
463 | - } |
|
464 | - wp_enqueue_script($this->theme); |
|
465 | - if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
466 | - add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
467 | - } |
|
468 | - } |
|
469 | - } |
|
470 | - |
|
471 | - |
|
472 | - /** |
|
473 | - * display_venue |
|
474 | - * |
|
475 | - * @return bool |
|
476 | - */ |
|
477 | - public static function display_venue() |
|
478 | - { |
|
479 | - /** @type EE_Event_Single_Config $config */ |
|
480 | - $config = EED_Event_Single::instance()->config(); |
|
481 | - $display_venue = $config->display_venue === null ? true : $config->display_venue; |
|
482 | - $venue_name = EEH_Venue_View::venue_name(); |
|
483 | - return $display_venue && ! empty($venue_name); |
|
484 | - } |
|
17 | + const EVENT_DETAILS_PRIORITY = 100; |
|
18 | + const EVENT_DATETIMES_PRIORITY = 110; |
|
19 | + const EVENT_TICKETS_PRIORITY = 120; |
|
20 | + const EVENT_VENUES_PRIORITY = 130; |
|
21 | + |
|
22 | + /** |
|
23 | + * @type bool $using_get_the_excerpt |
|
24 | + */ |
|
25 | + protected static $using_get_the_excerpt = false; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * @type EE_Template_Part_Manager $template_parts |
|
30 | + */ |
|
31 | + protected $template_parts; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @return EED_Module|EED_Event_Single |
|
36 | + */ |
|
37 | + public static function instance() |
|
38 | + { |
|
39 | + return parent::get_instance(__CLASS__); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
45 | + * |
|
46 | + * @return void |
|
47 | + * @throws InvalidArgumentException |
|
48 | + * @throws InvalidDataTypeException |
|
49 | + * @throws InvalidInterfaceException |
|
50 | + */ |
|
51 | + public static function set_hooks() |
|
52 | + { |
|
53 | + add_filter('FHEE_run_EE_wp', '__return_true'); |
|
54 | + add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
55 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
56 | + $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
57 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
58 | + ); |
|
59 | + $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
60 | + EE_Config::register_route( |
|
61 | + $custom_post_types['espresso_events']['singular_slug'], |
|
62 | + 'Event_Single', |
|
63 | + 'run' |
|
64 | + ); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
69 | + * |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public static function set_hooks_admin() |
|
73 | + { |
|
74 | + add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * set_definitions |
|
80 | + * |
|
81 | + * @static |
|
82 | + * @return void |
|
83 | + */ |
|
84 | + public static function set_definitions() |
|
85 | + { |
|
86 | + define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
87 | + define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/'); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * set_config |
|
93 | + * |
|
94 | + * @void |
|
95 | + */ |
|
96 | + protected function set_config() |
|
97 | + { |
|
98 | + $this->set_config_section('template_settings'); |
|
99 | + $this->set_config_class('EE_Event_Single_Config'); |
|
100 | + $this->set_config_name('EED_Event_Single'); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * initialize_template_parts |
|
106 | + * |
|
107 | + * @param EE_Config_Base|EE_Event_Single_Config $config |
|
108 | + * @return EE_Template_Part_Manager |
|
109 | + */ |
|
110 | + public function initialize_template_parts(EE_Event_Single_Config $config = null) |
|
111 | + { |
|
112 | + /** @type EE_Event_Single_Config $config */ |
|
113 | + $config = $config instanceof EE_Event_Single_Config ? $config : $this->config(); |
|
114 | + EEH_Autoloader::instance()->register_template_part_autoloaders(); |
|
115 | + $template_parts = new EE_Template_Part_Manager(); |
|
116 | + $template_parts->add_template_part( |
|
117 | + 'tickets', |
|
118 | + esc_html__('Ticket Selector', 'event_espresso'), |
|
119 | + 'content-espresso_events-tickets.php', |
|
120 | + $config->display_order_tickets |
|
121 | + ); |
|
122 | + $template_parts->add_template_part( |
|
123 | + 'datetimes', |
|
124 | + esc_html__('Dates and Times', 'event_espresso'), |
|
125 | + 'content-espresso_events-datetimes.php', |
|
126 | + $config->display_order_datetimes |
|
127 | + ); |
|
128 | + $template_parts->add_template_part( |
|
129 | + 'event', |
|
130 | + esc_html__('Event Description', 'event_espresso'), |
|
131 | + 'content-espresso_events-details.php', |
|
132 | + $config->display_order_event |
|
133 | + ); |
|
134 | + $template_parts->add_template_part( |
|
135 | + 'venue', |
|
136 | + esc_html__('Venue Information', 'event_espresso'), |
|
137 | + 'content-espresso_events-venues.php', |
|
138 | + $config->display_order_venue |
|
139 | + ); |
|
140 | + do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts); |
|
141 | + return $template_parts; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * run - initial module setup |
|
147 | + * |
|
148 | + * @param WP $WP |
|
149 | + * @return void |
|
150 | + */ |
|
151 | + public function run($WP) |
|
152 | + { |
|
153 | + // ensure valid EE_Events_Single_Config() object exists |
|
154 | + $this->set_config(); |
|
155 | + // check what template is loaded |
|
156 | + add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
157 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
158 | + // load css |
|
159 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * template_include |
|
165 | + * |
|
166 | + * @param string $template |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + public function template_include($template) |
|
170 | + { |
|
171 | + global $post; |
|
172 | + /** @type EE_Event_Single_Config $config */ |
|
173 | + $config = $this->config(); |
|
174 | + if ($config->display_status_banner_single) { |
|
175 | + add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2); |
|
176 | + } |
|
177 | + // not a custom template? |
|
178 | + if ( |
|
179 | + ! post_password_required($post) |
|
180 | + && ( |
|
181 | + apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false) |
|
182 | + || EE_Registry::instance() |
|
183 | + ->load_core('Front_Controller') |
|
184 | + ->get_selected_template() !== 'single-espresso_events.php' |
|
185 | + ) |
|
186 | + ) { |
|
187 | + EEH_Template::load_espresso_theme_functions(); |
|
188 | + // then add extra event data via hooks |
|
189 | + add_action('loop_start', array('EED_Event_Single', 'loop_start')); |
|
190 | + add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1); |
|
191 | + add_filter( |
|
192 | + 'the_content', |
|
193 | + array('EED_Event_Single', 'event_details'), |
|
194 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
195 | + ); |
|
196 | + add_action('loop_end', array('EED_Event_Single', 'loop_end')); |
|
197 | + // don't display entry meta because the existing theme will take car of that |
|
198 | + add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
199 | + } |
|
200 | + return $template; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * loop_start |
|
206 | + * |
|
207 | + * @param array $wp_query_array an array containing the WP_Query object |
|
208 | + * @return void |
|
209 | + */ |
|
210 | + public static function loop_start($wp_query_array) |
|
211 | + { |
|
212 | + global $post; |
|
213 | + do_action('AHEE_event_details_before_post', $post, $wp_query_array); |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * the_title |
|
219 | + * |
|
220 | + * @param string $title |
|
221 | + * @param int $id |
|
222 | + * @return string |
|
223 | + */ |
|
224 | + public static function the_title($title = '', $id = 0) |
|
225 | + { |
|
226 | + global $post; |
|
227 | + return ((function_exists('wp_is_block_theme') && wp_is_block_theme()) || in_the_loop()) && $post->ID === (int) $id |
|
228 | + ? espresso_event_status_banner($post->ID) . $title |
|
229 | + : $title; |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * get_the_excerpt |
|
235 | + * kinda hacky, but if a theme is using get_the_excerpt(), |
|
236 | + * then we need to remove our filters on the_content() |
|
237 | + * |
|
238 | + * @param string $excerpt |
|
239 | + * @return string |
|
240 | + */ |
|
241 | + public static function get_the_excerpt($excerpt = '') |
|
242 | + { |
|
243 | + EED_Event_Single::$using_get_the_excerpt = true; |
|
244 | + add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1); |
|
245 | + return $excerpt; |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * end_get_the_excerpt |
|
251 | + * |
|
252 | + * @param string $text |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + public static function end_get_the_excerpt($text = '') |
|
256 | + { |
|
257 | + EED_Event_Single::$using_get_the_excerpt = false; |
|
258 | + return $text; |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * event_details |
|
264 | + * |
|
265 | + * @param string $content |
|
266 | + * @return string |
|
267 | + */ |
|
268 | + public static function event_details($content) |
|
269 | + { |
|
270 | + global $post; |
|
271 | + static $current_post_ID = 0; |
|
272 | + if ( |
|
273 | + $current_post_ID !== $post->ID |
|
274 | + && $post->post_type === 'espresso_events' |
|
275 | + && ! EED_Event_Single::$using_get_the_excerpt |
|
276 | + && ! post_password_required() |
|
277 | + ) { |
|
278 | + // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
279 | + // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
280 | + // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
281 | + // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
282 | + // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
283 | + // so the following allows this filter to be applied multiple times, but only once for real |
|
284 | + $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
285 | + if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) { |
|
286 | + // we need to first remove this callback from being applied to the_content() |
|
287 | + // (otherwise it will recurse and blow up the interweb) |
|
288 | + remove_filter( |
|
289 | + 'the_content', |
|
290 | + array('EED_Event_Single', 'event_details'), |
|
291 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
292 | + ); |
|
293 | + EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts( |
|
294 | + ); |
|
295 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
296 | + $content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content); |
|
297 | + add_filter( |
|
298 | + 'the_content', |
|
299 | + array('EED_Event_Single', 'event_details'), |
|
300 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
301 | + ); |
|
302 | + } else { |
|
303 | + $content = EED_Event_Single::use_filterable_display_order(); |
|
304 | + } |
|
305 | + } |
|
306 | + return $content; |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * use_filterable_display_order |
|
312 | + * |
|
313 | + * @return string |
|
314 | + */ |
|
315 | + protected static function use_filterable_display_order() |
|
316 | + { |
|
317 | + // since the 'content-espresso_events-details.php' template might be used directly from within a theme, |
|
318 | + // it uses the_content() for displaying the $post->post_content |
|
319 | + // so in order to load a template that uses the_content() |
|
320 | + // from within a callback being used to filter the_content(), |
|
321 | + // we need to first remove this callback from being applied to the_content() |
|
322 | + // (otherwise it will recurse and blow up the interweb) |
|
323 | + remove_filter( |
|
324 | + 'the_content', |
|
325 | + array('EED_Event_Single', 'event_details'), |
|
326 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
327 | + ); |
|
328 | + // now add additional content |
|
329 | + add_filter( |
|
330 | + 'the_content', |
|
331 | + array('EED_Event_Single', 'event_datetimes'), |
|
332 | + EED_Event_Single::EVENT_DATETIMES_PRIORITY, |
|
333 | + 1 |
|
334 | + ); |
|
335 | + add_filter( |
|
336 | + 'the_content', |
|
337 | + array('EED_Event_Single', 'event_tickets'), |
|
338 | + EED_Event_Single::EVENT_TICKETS_PRIORITY, |
|
339 | + 1 |
|
340 | + ); |
|
341 | + add_filter( |
|
342 | + 'the_content', |
|
343 | + array('EED_Event_Single', 'event_venues'), |
|
344 | + EED_Event_Single::EVENT_VENUES_PRIORITY, |
|
345 | + 1 |
|
346 | + ); |
|
347 | + do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters'); |
|
348 | + // now load our template |
|
349 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
350 | + // now add our filter back in, plus some others |
|
351 | + add_filter( |
|
352 | + 'the_content', |
|
353 | + array('EED_Event_Single', 'event_details'), |
|
354 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
355 | + ); |
|
356 | + remove_filter( |
|
357 | + 'the_content', |
|
358 | + array('EED_Event_Single', 'event_datetimes'), |
|
359 | + EED_Event_Single::EVENT_DATETIMES_PRIORITY |
|
360 | + ); |
|
361 | + remove_filter( |
|
362 | + 'the_content', |
|
363 | + array('EED_Event_Single', 'event_tickets'), |
|
364 | + EED_Event_Single::EVENT_TICKETS_PRIORITY |
|
365 | + ); |
|
366 | + remove_filter( |
|
367 | + 'the_content', |
|
368 | + array('EED_Event_Single', 'event_venues'), |
|
369 | + EED_Event_Single::EVENT_VENUES_PRIORITY |
|
370 | + ); |
|
371 | + do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters'); |
|
372 | + // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
373 | + return $content; |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * event_datetimes - adds datetimes ABOVE content |
|
379 | + * |
|
380 | + * @param string $content |
|
381 | + * @return string |
|
382 | + */ |
|
383 | + public static function event_datetimes($content) |
|
384 | + { |
|
385 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
391 | + * |
|
392 | + * @param string $content |
|
393 | + * @return string |
|
394 | + */ |
|
395 | + public static function event_tickets($content) |
|
396 | + { |
|
397 | + return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * event_venues |
|
403 | + * |
|
404 | + * @param string $content |
|
405 | + * @return string |
|
406 | + */ |
|
407 | + public static function event_venue($content) |
|
408 | + { |
|
409 | + return EED_Event_Single::event_venues($content); |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * event_venues - adds venues BELOW content |
|
415 | + * |
|
416 | + * @param string $content |
|
417 | + * @return string |
|
418 | + */ |
|
419 | + public static function event_venues($content) |
|
420 | + { |
|
421 | + return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + /** |
|
426 | + * loop_end |
|
427 | + * |
|
428 | + * @param array $wp_query_array an array containing the WP_Query object |
|
429 | + * @return void |
|
430 | + */ |
|
431 | + public static function loop_end($wp_query_array) |
|
432 | + { |
|
433 | + global $post; |
|
434 | + do_action('AHEE_event_details_after_post', $post, $wp_query_array); |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * wp_enqueue_scripts |
|
440 | + * |
|
441 | + * @return void |
|
442 | + */ |
|
443 | + public function wp_enqueue_scripts() |
|
444 | + { |
|
445 | + // get some style |
|
446 | + if ( |
|
447 | + apply_filters('FHEE_enable_default_espresso_css', true) |
|
448 | + && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true) |
|
449 | + ) { |
|
450 | + // first check uploads folder |
|
451 | + if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
452 | + wp_register_style( |
|
453 | + $this->theme, |
|
454 | + get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
455 | + array('dashicons', 'espresso_default') |
|
456 | + ); |
|
457 | + } else { |
|
458 | + wp_register_style( |
|
459 | + $this->theme, |
|
460 | + EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
461 | + array('dashicons', 'espresso_default') |
|
462 | + ); |
|
463 | + } |
|
464 | + wp_enqueue_script($this->theme); |
|
465 | + if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
466 | + add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
467 | + } |
|
468 | + } |
|
469 | + } |
|
470 | + |
|
471 | + |
|
472 | + /** |
|
473 | + * display_venue |
|
474 | + * |
|
475 | + * @return bool |
|
476 | + */ |
|
477 | + public static function display_venue() |
|
478 | + { |
|
479 | + /** @type EE_Event_Single_Config $config */ |
|
480 | + $config = EED_Event_Single::instance()->config(); |
|
481 | + $display_venue = $config->display_venue === null ? true : $config->display_venue; |
|
482 | + $venue_name = EEH_Venue_View::venue_name(); |
|
483 | + return $display_venue && ! empty($venue_name); |
|
484 | + } |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | |
@@ -493,5 +493,5 @@ discard block |
||
493 | 493 | */ |
494 | 494 | function espresso_display_venue_in_event_details() |
495 | 495 | { |
496 | - return EED_Event_Single::display_venue(); |
|
496 | + return EED_Event_Single::display_venue(); |
|
497 | 497 | } |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public static function set_definitions() |
85 | 85 | { |
86 | - define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
87 | - define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/'); |
|
86 | + define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__).'assets/'); |
|
87 | + define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__).'templates/'); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | { |
226 | 226 | global $post; |
227 | 227 | return ((function_exists('wp_is_block_theme') && wp_is_block_theme()) || in_the_loop()) && $post->ID === (int) $id |
228 | - ? espresso_event_status_banner($post->ID) . $title |
|
228 | + ? espresso_event_status_banner($post->ID).$title |
|
229 | 229 | : $title; |
230 | 230 | } |
231 | 231 | |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | */ |
383 | 383 | public static function event_datetimes($content) |
384 | 384 | { |
385 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
385 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content; |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | */ |
395 | 395 | public static function event_tickets($content) |
396 | 396 | { |
397 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
397 | + return EEH_Template::locate_template('content-espresso_events-tickets.php').$content; |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | */ |
419 | 419 | public static function event_venues($content) |
420 | 420 | { |
421 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
421 | + return $content.EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | |
@@ -448,16 +448,16 @@ discard block |
||
448 | 448 | && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true) |
449 | 449 | ) { |
450 | 450 | // first check uploads folder |
451 | - if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
451 | + if (is_readable(get_stylesheet_directory().$this->theme.'/style.css')) { |
|
452 | 452 | wp_register_style( |
453 | 453 | $this->theme, |
454 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
454 | + get_stylesheet_directory_uri().$this->theme.'/style.css', |
|
455 | 455 | array('dashicons', 'espresso_default') |
456 | 456 | ); |
457 | 457 | } else { |
458 | 458 | wp_register_style( |
459 | 459 | $this->theme, |
460 | - EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
460 | + EE_TEMPLATES_URL.$this->theme.'/style.css', |
|
461 | 461 | array('dashicons', 'espresso_default') |
462 | 462 | ); |
463 | 463 | } |
@@ -16,1099 +16,1099 @@ discard block |
||
16 | 16 | class EED_Events_Archive extends EED_Module |
17 | 17 | { |
18 | 18 | |
19 | - const EVENT_DETAILS_PRIORITY = 100; |
|
20 | - |
|
21 | - const EVENT_DATETIMES_PRIORITY = 110; |
|
22 | - |
|
23 | - const EVENT_TICKETS_PRIORITY = 120; |
|
24 | - |
|
25 | - const EVENT_VENUES_PRIORITY = 130; |
|
26 | - |
|
27 | - |
|
28 | - public static $espresso_event_list_ID = 0; |
|
29 | - |
|
30 | - public static $espresso_grid_event_lists = array(); |
|
31 | - |
|
32 | - /** |
|
33 | - * @type bool $using_get_the_excerpt |
|
34 | - */ |
|
35 | - protected static $using_get_the_excerpt = false; |
|
36 | - |
|
37 | - /** |
|
38 | - * Used to flag when the event list is being called from an external iframe. |
|
39 | - * |
|
40 | - * @var bool $iframe |
|
41 | - */ |
|
42 | - protected static $iframe = false; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var EventListIframeEmbedButton $_iframe_embed_button |
|
46 | - */ |
|
47 | - private static $_iframe_embed_button; |
|
48 | - |
|
49 | - /** |
|
50 | - * @type EE_Template_Part_Manager $template_parts |
|
51 | - */ |
|
52 | - protected $template_parts; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @return EED_Events_Archive |
|
57 | - */ |
|
58 | - public static function instance() |
|
59 | - { |
|
60 | - return parent::get_instance(__CLASS__); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
66 | - * |
|
67 | - * @return void |
|
68 | - * @throws InvalidArgumentException |
|
69 | - * @throws InvalidDataTypeException |
|
70 | - * @throws InvalidInterfaceException |
|
71 | - */ |
|
72 | - public static function set_hooks() |
|
73 | - { |
|
74 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
75 | - $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
76 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
77 | - ); |
|
78 | - $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
79 | - EE_Config::register_route( |
|
80 | - $custom_post_types['espresso_events']['plural_slug'], |
|
81 | - 'Events_Archive', |
|
82 | - 'run' |
|
83 | - ); |
|
84 | - EE_Config::register_route( |
|
85 | - 'event_list', |
|
86 | - 'Events_Archive', |
|
87 | - 'event_list' |
|
88 | - ); |
|
89 | - EE_Config::register_route( |
|
90 | - 'iframe', |
|
91 | - 'Events_Archive', |
|
92 | - 'event_list_iframe', |
|
93 | - 'event_list' |
|
94 | - ); |
|
95 | - add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
101 | - * |
|
102 | - * @access public |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - public static function set_hooks_admin() |
|
106 | - { |
|
107 | - add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
108 | - // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
109 | - // to load assets for "espresso_events" page on the "default" route (action) |
|
110 | - add_action( |
|
111 | - 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default', |
|
112 | - array('EED_Events_Archive', 'event_list_iframe_embed_button'), |
|
113 | - 10 |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * set_definitions |
|
120 | - * |
|
121 | - * @access public |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - public static function set_definitions() |
|
125 | - { |
|
126 | - define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
127 | - define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * set up EE_Events_Archive_Config |
|
133 | - */ |
|
134 | - protected function set_config() |
|
135 | - { |
|
136 | - $this->set_config_section('template_settings'); |
|
137 | - $this->set_config_class('EE_Events_Archive_Config'); |
|
138 | - $this->set_config_name('EED_Events_Archive'); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @return EventListIframeEmbedButton |
|
144 | - */ |
|
145 | - public static function get_iframe_embed_button() |
|
146 | - { |
|
147 | - if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
148 | - self::$_iframe_embed_button = new EventListIframeEmbedButton(); |
|
149 | - } |
|
150 | - return self::$_iframe_embed_button; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * event_list_iframe_embed_button |
|
156 | - * |
|
157 | - * @return void |
|
158 | - * @throws EE_Error |
|
159 | - */ |
|
160 | - public static function event_list_iframe_embed_button() |
|
161 | - { |
|
162 | - $iframe_embed_button = EED_Events_Archive::get_iframe_embed_button(); |
|
163 | - $iframe_embed_button->addEmbedButton(); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * initialize_template_parts |
|
169 | - * |
|
170 | - * @access public |
|
171 | - * @param EE_Events_Archive_Config $config |
|
172 | - * @return EE_Template_Part_Manager |
|
173 | - */ |
|
174 | - public function initialize_template_parts(EE_Events_Archive_Config $config = null) |
|
175 | - { |
|
176 | - $config = $config instanceof EE_Events_Archive_Config ? $config : $this->config(); |
|
177 | - EEH_Autoloader::instance()->register_template_part_autoloaders(); |
|
178 | - $template_parts = new EE_Template_Part_Manager(); |
|
179 | - $template_parts->add_template_part( |
|
180 | - 'tickets', |
|
181 | - esc_html__('Ticket Selector', 'event_espresso'), |
|
182 | - 'content-espresso_events-tickets.php', |
|
183 | - $config->display_order_tickets |
|
184 | - ); |
|
185 | - $template_parts->add_template_part( |
|
186 | - 'datetimes', |
|
187 | - esc_html__('Dates and Times', 'event_espresso'), |
|
188 | - 'content-espresso_events-datetimes.php', |
|
189 | - $config->display_order_datetimes |
|
190 | - ); |
|
191 | - $template_parts->add_template_part( |
|
192 | - 'event', |
|
193 | - esc_html__('Event Description', 'event_espresso'), |
|
194 | - 'content-espresso_events-details.php', |
|
195 | - $config->display_order_event |
|
196 | - ); |
|
197 | - $template_parts->add_template_part( |
|
198 | - 'venue', |
|
199 | - esc_html__('Venue Information', 'event_espresso'), |
|
200 | - 'content-espresso_events-venues.php', |
|
201 | - $config->display_order_venue |
|
202 | - ); |
|
203 | - do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts); |
|
204 | - return $template_parts; |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * run - initial module setup - this gets called by the EE_Front_Controller if the module route is found in the |
|
210 | - * incoming request |
|
211 | - * |
|
212 | - * @access public |
|
213 | - * @param WP $WP |
|
214 | - * @return void |
|
215 | - */ |
|
216 | - public function run($WP) |
|
217 | - { |
|
218 | - do_action('AHEE__EED_Events_Archive__before_run'); |
|
219 | - // ensure valid EE_Events_Archive_Config() object exists |
|
220 | - $this->set_config(); |
|
221 | - /** @type EE_Events_Archive_Config $config */ |
|
222 | - $config = $this->config(); |
|
223 | - // load other required components |
|
224 | - $this->load_event_list_assets(); |
|
225 | - // filter the WP posts_join, posts_where, and posts_orderby SQL clauses |
|
226 | - // add query filters |
|
227 | - EEH_Event_Query::add_query_filters(); |
|
228 | - // set params that will get used by the filters |
|
229 | - EEH_Event_Query::set_query_params( |
|
230 | - '', // month |
|
231 | - '', // category |
|
232 | - $config->display_expired_events, // show_expired |
|
233 | - 'start_date', // orderby |
|
234 | - 'ASC' // sort |
|
235 | - ); |
|
236 | - // check what template is loaded |
|
237 | - add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting |
|
243 | - * |
|
244 | - * @return void |
|
245 | - */ |
|
246 | - public function event_list() |
|
247 | - { |
|
248 | - // ensure valid EE_Events_Archive_Config() object exists |
|
249 | - $this->set_config(); |
|
250 | - // load other required components |
|
251 | - $this->load_event_list_assets(); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @access public |
|
257 | - * @return void |
|
258 | - * @throws EE_Error |
|
259 | - * @throws DomainException |
|
260 | - */ |
|
261 | - public function event_list_iframe() |
|
262 | - { |
|
263 | - EED_Events_Archive::$iframe = true; |
|
264 | - $event_list_iframe = new EventsArchiveIframe($this); |
|
265 | - $event_list_iframe->display(); |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * @access public |
|
271 | - * @return string |
|
272 | - */ |
|
273 | - public static function is_iframe() |
|
274 | - { |
|
275 | - return EED_Events_Archive::$iframe; |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * @access public |
|
281 | - * @return string |
|
282 | - */ |
|
283 | - public static function link_target() |
|
284 | - { |
|
285 | - return EED_Events_Archive::$iframe ? ' target="_blank"' : ''; |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * template_include |
|
291 | - * |
|
292 | - * @access public |
|
293 | - * @param string $template |
|
294 | - * @return string |
|
295 | - */ |
|
296 | - public function template_include($template = '') |
|
297 | - { |
|
298 | - // don't add content filter for dedicated EE child themes or private posts |
|
299 | - if (! EEH_Template::is_espresso_theme()) { |
|
300 | - /** @type EE_Events_Archive_Config $config */ |
|
301 | - $config = $this->config(); |
|
302 | - // add status banner ? |
|
303 | - if ($config->display_status_banner) { |
|
304 | - add_filter('the_title', array('EED_Events_Archive', 'the_title'), 100, 2); |
|
305 | - } |
|
306 | - // if NOT a custom template |
|
307 | - if ( |
|
308 | - apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false) |
|
309 | - || EE_Registry::instance() |
|
310 | - ->load_core('Front_Controller') |
|
311 | - ->get_selected_template() !== 'archive-espresso_events.php' |
|
312 | - ) { |
|
313 | - // don't display entry meta because the existing theme will take care of that |
|
314 | - add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true'); |
|
315 | - // load functions.php file for the theme (loaded by WP if using child theme) |
|
316 | - EEH_Template::load_espresso_theme_functions(); |
|
317 | - // because we don't know if the theme is using the_excerpt() |
|
318 | - add_filter( |
|
319 | - 'the_excerpt', |
|
320 | - array('EED_Events_Archive', 'event_details'), |
|
321 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
322 | - ); |
|
323 | - // or the_content |
|
324 | - add_filter( |
|
325 | - 'the_content', |
|
326 | - array('EED_Events_Archive', 'event_details'), |
|
327 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
328 | - ); |
|
329 | - // and just in case they are running get_the_excerpt() which DESTROYS things |
|
330 | - add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
331 | - // don't display entry meta because the existing theme will take care of that |
|
332 | - add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
333 | - } |
|
334 | - } |
|
335 | - return $template; |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * get_the_excerpt - kinda hacky, but if a theme is using get_the_excerpt(), then we need to remove our filters |
|
341 | - * on the_content() |
|
342 | - * |
|
343 | - * @access public |
|
344 | - * @param string $excerpt |
|
345 | - * @return string |
|
346 | - */ |
|
347 | - public static function get_the_excerpt($excerpt = '') |
|
348 | - { |
|
349 | - if (post_password_required()) { |
|
350 | - return $excerpt; |
|
351 | - } |
|
352 | - if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) { |
|
353 | - remove_filter( |
|
354 | - 'the_excerpt', |
|
355 | - array('EED_Events_Archive', 'event_details'), |
|
356 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
357 | - ); |
|
358 | - remove_filter( |
|
359 | - 'the_content', |
|
360 | - array('EED_Events_Archive', 'event_details'), |
|
361 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
362 | - ); |
|
363 | - $excerpt = EED_Events_Archive::event_details($excerpt); |
|
364 | - } else { |
|
365 | - EED_Events_Archive::$using_get_the_excerpt = true; |
|
366 | - add_filter('wp_trim_excerpt', array('EED_Events_Archive', 'end_get_the_excerpt'), 999, 1); |
|
367 | - } |
|
368 | - return $excerpt; |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * end_get_the_excerpt |
|
374 | - * |
|
375 | - * @access public |
|
376 | - * @param string $text |
|
377 | - * @return string |
|
378 | - */ |
|
379 | - public static function end_get_the_excerpt($text = '') |
|
380 | - { |
|
381 | - EED_Events_Archive::$using_get_the_excerpt = false; |
|
382 | - return $text; |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - /** |
|
387 | - * the_title |
|
388 | - * |
|
389 | - * @access public |
|
390 | - * @param string $title |
|
391 | - * @param string $id |
|
392 | - * @return string |
|
393 | - */ |
|
394 | - public static function the_title($title = '', $id = '') |
|
395 | - { |
|
396 | - global $post; |
|
397 | - if ($post instanceof WP_Post) { |
|
398 | - return ((function_exists('wp_is_block_theme') && wp_is_block_theme()) || in_the_loop()) && $post->ID == $id |
|
399 | - ? espresso_event_status_banner($post->ID) . $title |
|
400 | - : $title; |
|
401 | - } |
|
402 | - return $title; |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * event_details |
|
408 | - * |
|
409 | - * @access public |
|
410 | - * @param string $content |
|
411 | - * @return string |
|
412 | - */ |
|
413 | - public static function event_details($content) |
|
414 | - { |
|
415 | - global $post; |
|
416 | - static $current_post_ID = 0; |
|
417 | - if ( |
|
418 | - $current_post_ID !== $post->ID |
|
419 | - && $post->post_type === 'espresso_events' |
|
420 | - && ! EED_Events_Archive::$using_get_the_excerpt |
|
421 | - && ! post_password_required() |
|
422 | - && ( |
|
423 | - apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false) |
|
424 | - || ! apply_filters('FHEE__content_espresso_events__template_loaded', false) |
|
425 | - ) |
|
426 | - ) { |
|
427 | - // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
428 | - // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
429 | - // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
430 | - // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
431 | - // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
432 | - // so the following allows this filter to be applied multiple times, but only once for real |
|
433 | - $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
434 | - if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) { |
|
435 | - $content = EED_Events_Archive::use_sortable_display_order(); |
|
436 | - } else { |
|
437 | - $content = EED_Events_Archive::use_filterable_display_order(); |
|
438 | - } |
|
439 | - } |
|
440 | - return $content; |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * use_sortable_display_order |
|
446 | - * |
|
447 | - * @access protected |
|
448 | - * @return string |
|
449 | - */ |
|
450 | - protected static function use_sortable_display_order() |
|
451 | - { |
|
452 | - // no further password checks required atm |
|
453 | - add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true'); |
|
454 | - // we need to first remove this callback from being applied to the_content() or the_excerpt() |
|
455 | - // (otherwise it will recurse and blow up the interweb) |
|
456 | - remove_filter( |
|
457 | - 'the_excerpt', |
|
458 | - array('EED_Events_Archive', 'event_details'), |
|
459 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
460 | - ); |
|
461 | - remove_filter( |
|
462 | - 'the_content', |
|
463 | - array('EED_Events_Archive', 'event_details'), |
|
464 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
465 | - ); |
|
466 | - remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
467 | - // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
468 | - EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts(); |
|
469 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
470 | - $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content); |
|
471 | - // re-add our main filters (or else the next event won't have them) |
|
472 | - add_filter( |
|
473 | - 'the_excerpt', |
|
474 | - array('EED_Events_Archive', 'event_details'), |
|
475 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
476 | - ); |
|
477 | - add_filter( |
|
478 | - 'the_content', |
|
479 | - array('EED_Events_Archive', 'event_details'), |
|
480 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
481 | - ); |
|
482 | - add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
483 | - remove_filter( |
|
484 | - 'FHEE__EED_Events_Archive__event_details__no_post_password_required', |
|
485 | - '__return_true' |
|
486 | - ); |
|
487 | - return $content; |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * use_filterable_display_order |
|
493 | - * |
|
494 | - * @access protected |
|
495 | - * @return string |
|
496 | - */ |
|
497 | - protected static function use_filterable_display_order() |
|
498 | - { |
|
499 | - // we need to first remove this callback from being applied to the_content() |
|
500 | - // (otherwise it will recurse and blow up the interweb) |
|
501 | - remove_filter( |
|
502 | - 'the_excerpt', |
|
503 | - array('EED_Events_Archive', 'event_details'), |
|
504 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
505 | - ); |
|
506 | - remove_filter( |
|
507 | - 'the_content', |
|
508 | - array('EED_Events_Archive', 'event_details'), |
|
509 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
510 | - ); |
|
511 | - remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
512 | - // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
513 | - EED_Events_Archive::_add_additional_excerpt_filters(); |
|
514 | - EED_Events_Archive::_add_additional_content_filters(); |
|
515 | - do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters'); |
|
516 | - // now load our template |
|
517 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
518 | - // re-add our main filters (or else the next event won't have them) |
|
519 | - add_filter( |
|
520 | - 'the_excerpt', |
|
521 | - array('EED_Events_Archive', 'event_details'), |
|
522 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
523 | - ); |
|
524 | - add_filter( |
|
525 | - 'the_content', |
|
526 | - array('EED_Events_Archive', 'event_details'), |
|
527 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
528 | - ); |
|
529 | - add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
530 | - // but remove the other filters so that they don't get applied to the next post |
|
531 | - EED_Events_Archive::_remove_additional_events_archive_filters(); |
|
532 | - do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters'); |
|
533 | - // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
534 | - // return ! empty( $template ) ? $template : $content; |
|
535 | - return $content; |
|
536 | - } |
|
537 | - |
|
538 | - |
|
539 | - /** |
|
540 | - * event_datetimes - adds datetimes ABOVE content |
|
541 | - * |
|
542 | - * @access public |
|
543 | - * @param string $content |
|
544 | - * @return string |
|
545 | - */ |
|
546 | - public static function event_datetimes($content) |
|
547 | - { |
|
548 | - if (post_password_required()) { |
|
549 | - return $content; |
|
550 | - } |
|
551 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
552 | - } |
|
553 | - |
|
554 | - |
|
555 | - /** |
|
556 | - * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
557 | - * |
|
558 | - * @access public |
|
559 | - * @param string $content |
|
560 | - * @return string |
|
561 | - */ |
|
562 | - public static function event_tickets($content) |
|
563 | - { |
|
564 | - if (post_password_required()) { |
|
565 | - return $content; |
|
566 | - } |
|
567 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * event_venues - adds venues BELOW content |
|
573 | - * |
|
574 | - * @access public |
|
575 | - * @param string $content |
|
576 | - * @return string |
|
577 | - */ |
|
578 | - public static function event_venue($content) |
|
579 | - { |
|
580 | - return EED_Events_Archive::event_venues($content); |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * event_venues - adds venues BELOW content |
|
586 | - * |
|
587 | - * @access public |
|
588 | - * @param string $content |
|
589 | - * @return string |
|
590 | - */ |
|
591 | - public static function event_venues($content) |
|
592 | - { |
|
593 | - if (post_password_required()) { |
|
594 | - return $content; |
|
595 | - } |
|
596 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * _add_additional_content_filters |
|
602 | - * |
|
603 | - * @access private |
|
604 | - * @return void |
|
605 | - */ |
|
606 | - private static function _add_additional_excerpt_filters() |
|
607 | - { |
|
608 | - add_filter( |
|
609 | - 'the_excerpt', |
|
610 | - array('EED_Events_Archive', 'event_datetimes'), |
|
611 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
612 | - ); |
|
613 | - add_filter( |
|
614 | - 'the_excerpt', |
|
615 | - array('EED_Events_Archive', 'event_tickets'), |
|
616 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
617 | - ); |
|
618 | - add_filter( |
|
619 | - 'the_excerpt', |
|
620 | - array('EED_Events_Archive', 'event_venues'), |
|
621 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
622 | - ); |
|
623 | - } |
|
624 | - |
|
625 | - |
|
626 | - /** |
|
627 | - * _add_additional_content_filters |
|
628 | - * |
|
629 | - * @access private |
|
630 | - * @return void |
|
631 | - */ |
|
632 | - private static function _add_additional_content_filters() |
|
633 | - { |
|
634 | - add_filter( |
|
635 | - 'the_content', |
|
636 | - array('EED_Events_Archive', 'event_datetimes'), |
|
637 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
638 | - ); |
|
639 | - add_filter( |
|
640 | - 'the_content', |
|
641 | - array('EED_Events_Archive', 'event_tickets'), |
|
642 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
643 | - ); |
|
644 | - add_filter( |
|
645 | - 'the_content', |
|
646 | - array('EED_Events_Archive', 'event_venues'), |
|
647 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
648 | - ); |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - /** |
|
653 | - * _remove_additional_events_archive_filters |
|
654 | - * |
|
655 | - * @access private |
|
656 | - * @return void |
|
657 | - */ |
|
658 | - private static function _remove_additional_events_archive_filters() |
|
659 | - { |
|
660 | - remove_filter( |
|
661 | - 'the_excerpt', |
|
662 | - array('EED_Events_Archive', 'event_datetimes'), |
|
663 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
664 | - ); |
|
665 | - remove_filter( |
|
666 | - 'the_excerpt', |
|
667 | - array('EED_Events_Archive', 'event_tickets'), |
|
668 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
669 | - ); |
|
670 | - remove_filter( |
|
671 | - 'the_excerpt', |
|
672 | - array('EED_Events_Archive', 'event_venues'), |
|
673 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
674 | - ); |
|
675 | - remove_filter( |
|
676 | - 'the_content', |
|
677 | - array('EED_Events_Archive', 'event_datetimes'), |
|
678 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
679 | - ); |
|
680 | - remove_filter( |
|
681 | - 'the_content', |
|
682 | - array('EED_Events_Archive', 'event_tickets'), |
|
683 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
684 | - ); |
|
685 | - remove_filter( |
|
686 | - 'the_content', |
|
687 | - array('EED_Events_Archive', 'event_venues'), |
|
688 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
689 | - ); |
|
690 | - } |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * remove_all_events_archive_filters |
|
695 | - * |
|
696 | - * @access public |
|
697 | - * @return void |
|
698 | - */ |
|
699 | - public static function remove_all_events_archive_filters() |
|
700 | - { |
|
701 | - // remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
|
702 | - remove_filter('the_title', array('EED_Events_Archive', 'the_title'), 1); |
|
703 | - remove_filter( |
|
704 | - 'the_excerpt', |
|
705 | - array('EED_Events_Archive', 'event_details'), |
|
706 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
707 | - ); |
|
708 | - remove_filter( |
|
709 | - 'the_excerpt', |
|
710 | - array('EED_Events_Archive', 'event_datetimes'), |
|
711 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
712 | - ); |
|
713 | - remove_filter( |
|
714 | - 'the_excerpt', |
|
715 | - array('EED_Events_Archive', 'event_tickets'), |
|
716 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
717 | - ); |
|
718 | - remove_filter( |
|
719 | - 'the_excerpt', |
|
720 | - array('EED_Events_Archive', 'event_venues'), |
|
721 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
722 | - ); |
|
723 | - remove_filter( |
|
724 | - 'the_content', |
|
725 | - array('EED_Events_Archive', 'event_details'), |
|
726 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
727 | - ); |
|
728 | - remove_filter( |
|
729 | - 'the_content', |
|
730 | - array('EED_Events_Archive', 'event_datetimes'), |
|
731 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
732 | - ); |
|
733 | - remove_filter( |
|
734 | - 'the_content', |
|
735 | - array('EED_Events_Archive', 'event_tickets'), |
|
736 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
737 | - ); |
|
738 | - remove_filter( |
|
739 | - 'the_content', |
|
740 | - array('EED_Events_Archive', 'event_venues'), |
|
741 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
742 | - ); |
|
743 | - // don't display entry meta because the existing theme will take care of that |
|
744 | - remove_filter( |
|
745 | - 'FHEE__content_espresso_events_details_template__display_entry_meta', |
|
746 | - '__return_false' |
|
747 | - ); |
|
748 | - } |
|
749 | - |
|
750 | - |
|
751 | - /** |
|
752 | - * load_event_list_assets |
|
753 | - * |
|
754 | - * @access public |
|
755 | - * @return void |
|
756 | - */ |
|
757 | - public function load_event_list_assets() |
|
758 | - { |
|
759 | - do_action('AHEE__EED_Events_Archive__before_load_assets'); |
|
760 | - add_filter('FHEE_load_EE_Session', '__return_true'); |
|
761 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
762 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
763 | - if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
764 | - add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
765 | - } |
|
766 | - } |
|
767 | - |
|
768 | - |
|
769 | - /** |
|
770 | - * wp_enqueue_scripts |
|
771 | - * |
|
772 | - * @access public |
|
773 | - * @return void |
|
774 | - */ |
|
775 | - public function wp_enqueue_scripts() |
|
776 | - { |
|
777 | - // get some style |
|
778 | - if (apply_filters('FHEE_enable_default_espresso_css', false)) { |
|
779 | - // first check uploads folder |
|
780 | - if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
781 | - wp_register_style( |
|
782 | - $this->theme, |
|
783 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
784 | - array('dashicons', 'espresso_default') |
|
785 | - ); |
|
786 | - } else { |
|
787 | - } |
|
788 | - wp_enqueue_style($this->theme); |
|
789 | - } |
|
790 | - } |
|
791 | - |
|
792 | - |
|
793 | - /** |
|
794 | - * template_settings_form |
|
795 | - * |
|
796 | - * @access public |
|
797 | - * @static |
|
798 | - * @return string |
|
799 | - */ |
|
800 | - public static function template_settings_form() |
|
801 | - { |
|
802 | - $template_settings = EE_Registry::instance()->CFG->template_settings; |
|
803 | - $template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive) |
|
804 | - ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config(); |
|
805 | - $template_settings->EED_Events_Archive = apply_filters( |
|
806 | - 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', |
|
807 | - $template_settings->EED_Events_Archive |
|
808 | - ); |
|
809 | - $events_archive_settings = array( |
|
810 | - 'display_status_banner' => 0, |
|
811 | - 'display_description' => 1, |
|
812 | - 'display_ticket_selector' => 0, |
|
813 | - 'display_datetimes' => 1, |
|
814 | - 'display_venue' => 0, |
|
815 | - 'display_expired_events' => 0, |
|
816 | - ); |
|
817 | - $events_archive_settings = array_merge( |
|
818 | - $events_archive_settings, |
|
819 | - (array) $template_settings->EED_Events_Archive |
|
820 | - ); |
|
821 | - EEH_Template::display_template( |
|
822 | - EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', |
|
823 | - $events_archive_settings |
|
824 | - ); |
|
825 | - } |
|
826 | - |
|
827 | - |
|
828 | - /** |
|
829 | - * update_template_settings |
|
830 | - * |
|
831 | - * @access public |
|
832 | - * @param EE_Template_Config $CFG |
|
833 | - * @param array $REQ |
|
834 | - * @return EE_Template_Config |
|
835 | - */ |
|
836 | - public static function update_template_settings($CFG, $REQ) |
|
837 | - { |
|
838 | - $CFG->EED_Events_Archive = new EE_Events_Archive_Config(); |
|
839 | - // unless we are resetting the config... |
|
840 | - if ( |
|
841 | - ! isset($REQ['EED_Events_Archive_reset_event_list_settings']) |
|
842 | - || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1 |
|
843 | - ) { |
|
844 | - $CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) |
|
845 | - ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0; |
|
846 | - $CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description']) |
|
847 | - ? absint($REQ['EED_Events_Archive_display_description']) : 1; |
|
848 | - $CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) |
|
849 | - ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0; |
|
850 | - $CFG->EED_Events_Archive->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint( |
|
851 | - $REQ['EED_Events_Archive_display_datetimes'] |
|
852 | - ) : 1; |
|
853 | - $CFG->EED_Events_Archive->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint( |
|
854 | - $REQ['EED_Events_Archive_display_venue'] |
|
855 | - ) : 0; |
|
856 | - $CFG->EED_Events_Archive->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events']) |
|
857 | - ? absint($REQ['EED_Events_Archive_display_expired_events']) : 0; |
|
858 | - } |
|
859 | - return $CFG; |
|
860 | - } |
|
861 | - |
|
862 | - |
|
863 | - /** |
|
864 | - * event_list_css |
|
865 | - * |
|
866 | - * @access public |
|
867 | - * @param string $extra_class |
|
868 | - * @return string |
|
869 | - */ |
|
870 | - public static function event_list_css($extra_class = '') |
|
871 | - { |
|
872 | - $event_list_css = ! empty($extra_class) ? array($extra_class) : array(); |
|
873 | - $event_list_css[] = 'espresso-event-list-event'; |
|
874 | - return implode(' ', $event_list_css); |
|
875 | - } |
|
876 | - |
|
877 | - |
|
878 | - /** |
|
879 | - * event_categories |
|
880 | - * |
|
881 | - * @access public |
|
882 | - * @return array |
|
883 | - */ |
|
884 | - public static function event_categories() |
|
885 | - { |
|
886 | - return EE_Registry::instance()->load_model('Term')->get_all_ee_categories(); |
|
887 | - } |
|
888 | - |
|
889 | - |
|
890 | - /** |
|
891 | - * display_description |
|
892 | - * |
|
893 | - * @access public |
|
894 | - * @param $value |
|
895 | - * @return bool |
|
896 | - */ |
|
897 | - public static function display_description($value) |
|
898 | - { |
|
899 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
900 | - $display_description = isset($config->display_description) ? $config->display_description : 1; |
|
901 | - return $display_description === $value ? true : false; |
|
902 | - } |
|
903 | - |
|
904 | - |
|
905 | - /** |
|
906 | - * display_ticket_selector |
|
907 | - * |
|
908 | - * @access public |
|
909 | - * @return bool |
|
910 | - */ |
|
911 | - public static function display_ticket_selector() |
|
912 | - { |
|
913 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
914 | - return isset($config->display_ticket_selector) && $config->display_ticket_selector ? true : false; |
|
915 | - } |
|
916 | - |
|
917 | - |
|
918 | - /** |
|
919 | - * display_venue |
|
920 | - * |
|
921 | - * @access public |
|
922 | - * @return bool |
|
923 | - */ |
|
924 | - public static function display_venue() |
|
925 | - { |
|
926 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
927 | - return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name() ? true : false; |
|
928 | - } |
|
929 | - |
|
930 | - |
|
931 | - /** |
|
932 | - * display_datetimes |
|
933 | - * |
|
934 | - * @access public |
|
935 | - * @return bool |
|
936 | - */ |
|
937 | - public static function display_datetimes() |
|
938 | - { |
|
939 | - $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
940 | - return isset($config->display_datetimes) && $config->display_datetimes ? true : false; |
|
941 | - } |
|
942 | - |
|
943 | - |
|
944 | - /** |
|
945 | - * event_list_title |
|
946 | - * |
|
947 | - * @access public |
|
948 | - * @return string |
|
949 | - */ |
|
950 | - public static function event_list_title() |
|
951 | - { |
|
952 | - return apply_filters( |
|
953 | - 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
954 | - esc_html__('Upcoming Events', 'event_espresso') |
|
955 | - ); |
|
956 | - } |
|
957 | - |
|
958 | - |
|
959 | - // GRAVEYARD |
|
960 | - |
|
961 | - |
|
962 | - /** |
|
963 | - * @since 4.4.0 |
|
964 | - */ |
|
965 | - public static function _doing_it_wrong_notice($function = '') |
|
966 | - { |
|
967 | - EE_Error::doing_it_wrong( |
|
968 | - __FUNCTION__, |
|
969 | - sprintf( |
|
970 | - esc_html__( |
|
971 | - 'EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s', |
|
972 | - 'event_espresso' |
|
973 | - ), |
|
974 | - $function, |
|
975 | - '<br />', |
|
976 | - '4.6.0' |
|
977 | - ), |
|
978 | - '4.4.0' |
|
979 | - ); |
|
980 | - } |
|
981 | - |
|
982 | - |
|
983 | - /** |
|
984 | - * @deprecated |
|
985 | - * @since 4.4.0 |
|
986 | - */ |
|
987 | - public function get_post_data() |
|
988 | - { |
|
989 | - EEH_Event_Query::set_query_params(); |
|
990 | - } |
|
991 | - |
|
992 | - |
|
993 | - /** |
|
994 | - * @deprecated |
|
995 | - * @since 4.4.0 |
|
996 | - */ |
|
997 | - public function posts_fields($SQL, WP_Query $wp_query) |
|
998 | - { |
|
999 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1000 | - return EEH_Event_Query::posts_fields($SQL, $wp_query); |
|
1001 | - } |
|
1002 | - |
|
1003 | - |
|
1004 | - /** |
|
1005 | - * @deprecated |
|
1006 | - * @since 4.4.0 |
|
1007 | - */ |
|
1008 | - public static function posts_fields_sql_for_orderby($orderby_params = array()) |
|
1009 | - { |
|
1010 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1011 | - return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params); |
|
1012 | - } |
|
1013 | - |
|
1014 | - |
|
1015 | - /** |
|
1016 | - * @deprecated |
|
1017 | - * @since 4.4.0 |
|
1018 | - */ |
|
1019 | - public function posts_join($SQL, WP_Query $wp_query) |
|
1020 | - { |
|
1021 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1022 | - return EEH_Event_Query::posts_join($SQL, $wp_query); |
|
1023 | - } |
|
1024 | - |
|
1025 | - |
|
1026 | - /** |
|
1027 | - * @deprecated |
|
1028 | - * @since 4.4.0 |
|
1029 | - */ |
|
1030 | - public static function posts_join_sql_for_terms($join_terms = null) |
|
1031 | - { |
|
1032 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1033 | - return EEH_Event_Query::posts_join_sql_for_terms($join_terms); |
|
1034 | - } |
|
1035 | - |
|
1036 | - |
|
1037 | - /** |
|
1038 | - * @deprecated |
|
1039 | - * @since 4.4.0 |
|
1040 | - */ |
|
1041 | - public static function posts_join_for_orderby($orderby_params = array()) |
|
1042 | - { |
|
1043 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1044 | - return EEH_Event_Query::posts_join_for_orderby($orderby_params); |
|
1045 | - } |
|
1046 | - |
|
1047 | - |
|
1048 | - /** |
|
1049 | - * @deprecated |
|
1050 | - * @since 4.4.0 |
|
1051 | - */ |
|
1052 | - public function posts_where($SQL, WP_Query $wp_query) |
|
1053 | - { |
|
1054 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1055 | - return EEH_Event_Query::posts_where($SQL, $wp_query); |
|
1056 | - } |
|
1057 | - |
|
1058 | - |
|
1059 | - /** |
|
1060 | - * @deprecated |
|
1061 | - * @since 4.4.0 |
|
1062 | - */ |
|
1063 | - public static function posts_where_sql_for_show_expired($show_expired = false) |
|
1064 | - { |
|
1065 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1066 | - return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired); |
|
1067 | - } |
|
1068 | - |
|
1069 | - |
|
1070 | - /** |
|
1071 | - * @deprecated |
|
1072 | - * @since 4.4.0 |
|
1073 | - */ |
|
1074 | - public static function posts_where_sql_for_event_category_slug($event_category_slug = null) |
|
1075 | - { |
|
1076 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1077 | - return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug); |
|
1078 | - } |
|
1079 | - |
|
1080 | - |
|
1081 | - /** |
|
1082 | - * @deprecated |
|
1083 | - * @since 4.4.0 |
|
1084 | - */ |
|
1085 | - public static function posts_where_sql_for_event_list_month($month = null) |
|
1086 | - { |
|
1087 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1088 | - return EEH_Event_Query::posts_where_sql_for_event_list_month($month); |
|
1089 | - } |
|
1090 | - |
|
1091 | - |
|
1092 | - /** |
|
1093 | - * @deprecated |
|
1094 | - * @since 4.4.0 |
|
1095 | - */ |
|
1096 | - public function posts_orderby($SQL, WP_Query $wp_query) |
|
1097 | - { |
|
1098 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1099 | - return EEH_Event_Query::posts_orderby($SQL, $wp_query); |
|
1100 | - } |
|
1101 | - |
|
1102 | - |
|
1103 | - /** |
|
1104 | - * @deprecated |
|
1105 | - * @since 4.4.0 |
|
1106 | - */ |
|
1107 | - public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') |
|
1108 | - { |
|
1109 | - EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1110 | - return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort); |
|
1111 | - } |
|
19 | + const EVENT_DETAILS_PRIORITY = 100; |
|
20 | + |
|
21 | + const EVENT_DATETIMES_PRIORITY = 110; |
|
22 | + |
|
23 | + const EVENT_TICKETS_PRIORITY = 120; |
|
24 | + |
|
25 | + const EVENT_VENUES_PRIORITY = 130; |
|
26 | + |
|
27 | + |
|
28 | + public static $espresso_event_list_ID = 0; |
|
29 | + |
|
30 | + public static $espresso_grid_event_lists = array(); |
|
31 | + |
|
32 | + /** |
|
33 | + * @type bool $using_get_the_excerpt |
|
34 | + */ |
|
35 | + protected static $using_get_the_excerpt = false; |
|
36 | + |
|
37 | + /** |
|
38 | + * Used to flag when the event list is being called from an external iframe. |
|
39 | + * |
|
40 | + * @var bool $iframe |
|
41 | + */ |
|
42 | + protected static $iframe = false; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var EventListIframeEmbedButton $_iframe_embed_button |
|
46 | + */ |
|
47 | + private static $_iframe_embed_button; |
|
48 | + |
|
49 | + /** |
|
50 | + * @type EE_Template_Part_Manager $template_parts |
|
51 | + */ |
|
52 | + protected $template_parts; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @return EED_Events_Archive |
|
57 | + */ |
|
58 | + public static function instance() |
|
59 | + { |
|
60 | + return parent::get_instance(__CLASS__); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
66 | + * |
|
67 | + * @return void |
|
68 | + * @throws InvalidArgumentException |
|
69 | + * @throws InvalidDataTypeException |
|
70 | + * @throws InvalidInterfaceException |
|
71 | + */ |
|
72 | + public static function set_hooks() |
|
73 | + { |
|
74 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
75 | + $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
76 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
77 | + ); |
|
78 | + $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
79 | + EE_Config::register_route( |
|
80 | + $custom_post_types['espresso_events']['plural_slug'], |
|
81 | + 'Events_Archive', |
|
82 | + 'run' |
|
83 | + ); |
|
84 | + EE_Config::register_route( |
|
85 | + 'event_list', |
|
86 | + 'Events_Archive', |
|
87 | + 'event_list' |
|
88 | + ); |
|
89 | + EE_Config::register_route( |
|
90 | + 'iframe', |
|
91 | + 'Events_Archive', |
|
92 | + 'event_list_iframe', |
|
93 | + 'event_list' |
|
94 | + ); |
|
95 | + add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
101 | + * |
|
102 | + * @access public |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + public static function set_hooks_admin() |
|
106 | + { |
|
107 | + add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
108 | + // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
109 | + // to load assets for "espresso_events" page on the "default" route (action) |
|
110 | + add_action( |
|
111 | + 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default', |
|
112 | + array('EED_Events_Archive', 'event_list_iframe_embed_button'), |
|
113 | + 10 |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * set_definitions |
|
120 | + * |
|
121 | + * @access public |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + public static function set_definitions() |
|
125 | + { |
|
126 | + define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
127 | + define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * set up EE_Events_Archive_Config |
|
133 | + */ |
|
134 | + protected function set_config() |
|
135 | + { |
|
136 | + $this->set_config_section('template_settings'); |
|
137 | + $this->set_config_class('EE_Events_Archive_Config'); |
|
138 | + $this->set_config_name('EED_Events_Archive'); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @return EventListIframeEmbedButton |
|
144 | + */ |
|
145 | + public static function get_iframe_embed_button() |
|
146 | + { |
|
147 | + if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
148 | + self::$_iframe_embed_button = new EventListIframeEmbedButton(); |
|
149 | + } |
|
150 | + return self::$_iframe_embed_button; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * event_list_iframe_embed_button |
|
156 | + * |
|
157 | + * @return void |
|
158 | + * @throws EE_Error |
|
159 | + */ |
|
160 | + public static function event_list_iframe_embed_button() |
|
161 | + { |
|
162 | + $iframe_embed_button = EED_Events_Archive::get_iframe_embed_button(); |
|
163 | + $iframe_embed_button->addEmbedButton(); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * initialize_template_parts |
|
169 | + * |
|
170 | + * @access public |
|
171 | + * @param EE_Events_Archive_Config $config |
|
172 | + * @return EE_Template_Part_Manager |
|
173 | + */ |
|
174 | + public function initialize_template_parts(EE_Events_Archive_Config $config = null) |
|
175 | + { |
|
176 | + $config = $config instanceof EE_Events_Archive_Config ? $config : $this->config(); |
|
177 | + EEH_Autoloader::instance()->register_template_part_autoloaders(); |
|
178 | + $template_parts = new EE_Template_Part_Manager(); |
|
179 | + $template_parts->add_template_part( |
|
180 | + 'tickets', |
|
181 | + esc_html__('Ticket Selector', 'event_espresso'), |
|
182 | + 'content-espresso_events-tickets.php', |
|
183 | + $config->display_order_tickets |
|
184 | + ); |
|
185 | + $template_parts->add_template_part( |
|
186 | + 'datetimes', |
|
187 | + esc_html__('Dates and Times', 'event_espresso'), |
|
188 | + 'content-espresso_events-datetimes.php', |
|
189 | + $config->display_order_datetimes |
|
190 | + ); |
|
191 | + $template_parts->add_template_part( |
|
192 | + 'event', |
|
193 | + esc_html__('Event Description', 'event_espresso'), |
|
194 | + 'content-espresso_events-details.php', |
|
195 | + $config->display_order_event |
|
196 | + ); |
|
197 | + $template_parts->add_template_part( |
|
198 | + 'venue', |
|
199 | + esc_html__('Venue Information', 'event_espresso'), |
|
200 | + 'content-espresso_events-venues.php', |
|
201 | + $config->display_order_venue |
|
202 | + ); |
|
203 | + do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts); |
|
204 | + return $template_parts; |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * run - initial module setup - this gets called by the EE_Front_Controller if the module route is found in the |
|
210 | + * incoming request |
|
211 | + * |
|
212 | + * @access public |
|
213 | + * @param WP $WP |
|
214 | + * @return void |
|
215 | + */ |
|
216 | + public function run($WP) |
|
217 | + { |
|
218 | + do_action('AHEE__EED_Events_Archive__before_run'); |
|
219 | + // ensure valid EE_Events_Archive_Config() object exists |
|
220 | + $this->set_config(); |
|
221 | + /** @type EE_Events_Archive_Config $config */ |
|
222 | + $config = $this->config(); |
|
223 | + // load other required components |
|
224 | + $this->load_event_list_assets(); |
|
225 | + // filter the WP posts_join, posts_where, and posts_orderby SQL clauses |
|
226 | + // add query filters |
|
227 | + EEH_Event_Query::add_query_filters(); |
|
228 | + // set params that will get used by the filters |
|
229 | + EEH_Event_Query::set_query_params( |
|
230 | + '', // month |
|
231 | + '', // category |
|
232 | + $config->display_expired_events, // show_expired |
|
233 | + 'start_date', // orderby |
|
234 | + 'ASC' // sort |
|
235 | + ); |
|
236 | + // check what template is loaded |
|
237 | + add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting |
|
243 | + * |
|
244 | + * @return void |
|
245 | + */ |
|
246 | + public function event_list() |
|
247 | + { |
|
248 | + // ensure valid EE_Events_Archive_Config() object exists |
|
249 | + $this->set_config(); |
|
250 | + // load other required components |
|
251 | + $this->load_event_list_assets(); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * @access public |
|
257 | + * @return void |
|
258 | + * @throws EE_Error |
|
259 | + * @throws DomainException |
|
260 | + */ |
|
261 | + public function event_list_iframe() |
|
262 | + { |
|
263 | + EED_Events_Archive::$iframe = true; |
|
264 | + $event_list_iframe = new EventsArchiveIframe($this); |
|
265 | + $event_list_iframe->display(); |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * @access public |
|
271 | + * @return string |
|
272 | + */ |
|
273 | + public static function is_iframe() |
|
274 | + { |
|
275 | + return EED_Events_Archive::$iframe; |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * @access public |
|
281 | + * @return string |
|
282 | + */ |
|
283 | + public static function link_target() |
|
284 | + { |
|
285 | + return EED_Events_Archive::$iframe ? ' target="_blank"' : ''; |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * template_include |
|
291 | + * |
|
292 | + * @access public |
|
293 | + * @param string $template |
|
294 | + * @return string |
|
295 | + */ |
|
296 | + public function template_include($template = '') |
|
297 | + { |
|
298 | + // don't add content filter for dedicated EE child themes or private posts |
|
299 | + if (! EEH_Template::is_espresso_theme()) { |
|
300 | + /** @type EE_Events_Archive_Config $config */ |
|
301 | + $config = $this->config(); |
|
302 | + // add status banner ? |
|
303 | + if ($config->display_status_banner) { |
|
304 | + add_filter('the_title', array('EED_Events_Archive', 'the_title'), 100, 2); |
|
305 | + } |
|
306 | + // if NOT a custom template |
|
307 | + if ( |
|
308 | + apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false) |
|
309 | + || EE_Registry::instance() |
|
310 | + ->load_core('Front_Controller') |
|
311 | + ->get_selected_template() !== 'archive-espresso_events.php' |
|
312 | + ) { |
|
313 | + // don't display entry meta because the existing theme will take care of that |
|
314 | + add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true'); |
|
315 | + // load functions.php file for the theme (loaded by WP if using child theme) |
|
316 | + EEH_Template::load_espresso_theme_functions(); |
|
317 | + // because we don't know if the theme is using the_excerpt() |
|
318 | + add_filter( |
|
319 | + 'the_excerpt', |
|
320 | + array('EED_Events_Archive', 'event_details'), |
|
321 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
322 | + ); |
|
323 | + // or the_content |
|
324 | + add_filter( |
|
325 | + 'the_content', |
|
326 | + array('EED_Events_Archive', 'event_details'), |
|
327 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
328 | + ); |
|
329 | + // and just in case they are running get_the_excerpt() which DESTROYS things |
|
330 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
331 | + // don't display entry meta because the existing theme will take care of that |
|
332 | + add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
333 | + } |
|
334 | + } |
|
335 | + return $template; |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * get_the_excerpt - kinda hacky, but if a theme is using get_the_excerpt(), then we need to remove our filters |
|
341 | + * on the_content() |
|
342 | + * |
|
343 | + * @access public |
|
344 | + * @param string $excerpt |
|
345 | + * @return string |
|
346 | + */ |
|
347 | + public static function get_the_excerpt($excerpt = '') |
|
348 | + { |
|
349 | + if (post_password_required()) { |
|
350 | + return $excerpt; |
|
351 | + } |
|
352 | + if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) { |
|
353 | + remove_filter( |
|
354 | + 'the_excerpt', |
|
355 | + array('EED_Events_Archive', 'event_details'), |
|
356 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
357 | + ); |
|
358 | + remove_filter( |
|
359 | + 'the_content', |
|
360 | + array('EED_Events_Archive', 'event_details'), |
|
361 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
362 | + ); |
|
363 | + $excerpt = EED_Events_Archive::event_details($excerpt); |
|
364 | + } else { |
|
365 | + EED_Events_Archive::$using_get_the_excerpt = true; |
|
366 | + add_filter('wp_trim_excerpt', array('EED_Events_Archive', 'end_get_the_excerpt'), 999, 1); |
|
367 | + } |
|
368 | + return $excerpt; |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * end_get_the_excerpt |
|
374 | + * |
|
375 | + * @access public |
|
376 | + * @param string $text |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + public static function end_get_the_excerpt($text = '') |
|
380 | + { |
|
381 | + EED_Events_Archive::$using_get_the_excerpt = false; |
|
382 | + return $text; |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + /** |
|
387 | + * the_title |
|
388 | + * |
|
389 | + * @access public |
|
390 | + * @param string $title |
|
391 | + * @param string $id |
|
392 | + * @return string |
|
393 | + */ |
|
394 | + public static function the_title($title = '', $id = '') |
|
395 | + { |
|
396 | + global $post; |
|
397 | + if ($post instanceof WP_Post) { |
|
398 | + return ((function_exists('wp_is_block_theme') && wp_is_block_theme()) || in_the_loop()) && $post->ID == $id |
|
399 | + ? espresso_event_status_banner($post->ID) . $title |
|
400 | + : $title; |
|
401 | + } |
|
402 | + return $title; |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * event_details |
|
408 | + * |
|
409 | + * @access public |
|
410 | + * @param string $content |
|
411 | + * @return string |
|
412 | + */ |
|
413 | + public static function event_details($content) |
|
414 | + { |
|
415 | + global $post; |
|
416 | + static $current_post_ID = 0; |
|
417 | + if ( |
|
418 | + $current_post_ID !== $post->ID |
|
419 | + && $post->post_type === 'espresso_events' |
|
420 | + && ! EED_Events_Archive::$using_get_the_excerpt |
|
421 | + && ! post_password_required() |
|
422 | + && ( |
|
423 | + apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false) |
|
424 | + || ! apply_filters('FHEE__content_espresso_events__template_loaded', false) |
|
425 | + ) |
|
426 | + ) { |
|
427 | + // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
428 | + // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
429 | + // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
430 | + // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
431 | + // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
432 | + // so the following allows this filter to be applied multiple times, but only once for real |
|
433 | + $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
434 | + if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) { |
|
435 | + $content = EED_Events_Archive::use_sortable_display_order(); |
|
436 | + } else { |
|
437 | + $content = EED_Events_Archive::use_filterable_display_order(); |
|
438 | + } |
|
439 | + } |
|
440 | + return $content; |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * use_sortable_display_order |
|
446 | + * |
|
447 | + * @access protected |
|
448 | + * @return string |
|
449 | + */ |
|
450 | + protected static function use_sortable_display_order() |
|
451 | + { |
|
452 | + // no further password checks required atm |
|
453 | + add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true'); |
|
454 | + // we need to first remove this callback from being applied to the_content() or the_excerpt() |
|
455 | + // (otherwise it will recurse and blow up the interweb) |
|
456 | + remove_filter( |
|
457 | + 'the_excerpt', |
|
458 | + array('EED_Events_Archive', 'event_details'), |
|
459 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
460 | + ); |
|
461 | + remove_filter( |
|
462 | + 'the_content', |
|
463 | + array('EED_Events_Archive', 'event_details'), |
|
464 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
465 | + ); |
|
466 | + remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
467 | + // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
468 | + EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts(); |
|
469 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
470 | + $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content); |
|
471 | + // re-add our main filters (or else the next event won't have them) |
|
472 | + add_filter( |
|
473 | + 'the_excerpt', |
|
474 | + array('EED_Events_Archive', 'event_details'), |
|
475 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
476 | + ); |
|
477 | + add_filter( |
|
478 | + 'the_content', |
|
479 | + array('EED_Events_Archive', 'event_details'), |
|
480 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
481 | + ); |
|
482 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
483 | + remove_filter( |
|
484 | + 'FHEE__EED_Events_Archive__event_details__no_post_password_required', |
|
485 | + '__return_true' |
|
486 | + ); |
|
487 | + return $content; |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * use_filterable_display_order |
|
493 | + * |
|
494 | + * @access protected |
|
495 | + * @return string |
|
496 | + */ |
|
497 | + protected static function use_filterable_display_order() |
|
498 | + { |
|
499 | + // we need to first remove this callback from being applied to the_content() |
|
500 | + // (otherwise it will recurse and blow up the interweb) |
|
501 | + remove_filter( |
|
502 | + 'the_excerpt', |
|
503 | + array('EED_Events_Archive', 'event_details'), |
|
504 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
505 | + ); |
|
506 | + remove_filter( |
|
507 | + 'the_content', |
|
508 | + array('EED_Events_Archive', 'event_details'), |
|
509 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
510 | + ); |
|
511 | + remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
512 | + // now add additional content depending on whether event is using the_excerpt() or the_content() |
|
513 | + EED_Events_Archive::_add_additional_excerpt_filters(); |
|
514 | + EED_Events_Archive::_add_additional_content_filters(); |
|
515 | + do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters'); |
|
516 | + // now load our template |
|
517 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
518 | + // re-add our main filters (or else the next event won't have them) |
|
519 | + add_filter( |
|
520 | + 'the_excerpt', |
|
521 | + array('EED_Events_Archive', 'event_details'), |
|
522 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
523 | + ); |
|
524 | + add_filter( |
|
525 | + 'the_content', |
|
526 | + array('EED_Events_Archive', 'event_details'), |
|
527 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
528 | + ); |
|
529 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
530 | + // but remove the other filters so that they don't get applied to the next post |
|
531 | + EED_Events_Archive::_remove_additional_events_archive_filters(); |
|
532 | + do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters'); |
|
533 | + // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
534 | + // return ! empty( $template ) ? $template : $content; |
|
535 | + return $content; |
|
536 | + } |
|
537 | + |
|
538 | + |
|
539 | + /** |
|
540 | + * event_datetimes - adds datetimes ABOVE content |
|
541 | + * |
|
542 | + * @access public |
|
543 | + * @param string $content |
|
544 | + * @return string |
|
545 | + */ |
|
546 | + public static function event_datetimes($content) |
|
547 | + { |
|
548 | + if (post_password_required()) { |
|
549 | + return $content; |
|
550 | + } |
|
551 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
552 | + } |
|
553 | + |
|
554 | + |
|
555 | + /** |
|
556 | + * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
557 | + * |
|
558 | + * @access public |
|
559 | + * @param string $content |
|
560 | + * @return string |
|
561 | + */ |
|
562 | + public static function event_tickets($content) |
|
563 | + { |
|
564 | + if (post_password_required()) { |
|
565 | + return $content; |
|
566 | + } |
|
567 | + return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * event_venues - adds venues BELOW content |
|
573 | + * |
|
574 | + * @access public |
|
575 | + * @param string $content |
|
576 | + * @return string |
|
577 | + */ |
|
578 | + public static function event_venue($content) |
|
579 | + { |
|
580 | + return EED_Events_Archive::event_venues($content); |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * event_venues - adds venues BELOW content |
|
586 | + * |
|
587 | + * @access public |
|
588 | + * @param string $content |
|
589 | + * @return string |
|
590 | + */ |
|
591 | + public static function event_venues($content) |
|
592 | + { |
|
593 | + if (post_password_required()) { |
|
594 | + return $content; |
|
595 | + } |
|
596 | + return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * _add_additional_content_filters |
|
602 | + * |
|
603 | + * @access private |
|
604 | + * @return void |
|
605 | + */ |
|
606 | + private static function _add_additional_excerpt_filters() |
|
607 | + { |
|
608 | + add_filter( |
|
609 | + 'the_excerpt', |
|
610 | + array('EED_Events_Archive', 'event_datetimes'), |
|
611 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
612 | + ); |
|
613 | + add_filter( |
|
614 | + 'the_excerpt', |
|
615 | + array('EED_Events_Archive', 'event_tickets'), |
|
616 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
617 | + ); |
|
618 | + add_filter( |
|
619 | + 'the_excerpt', |
|
620 | + array('EED_Events_Archive', 'event_venues'), |
|
621 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
622 | + ); |
|
623 | + } |
|
624 | + |
|
625 | + |
|
626 | + /** |
|
627 | + * _add_additional_content_filters |
|
628 | + * |
|
629 | + * @access private |
|
630 | + * @return void |
|
631 | + */ |
|
632 | + private static function _add_additional_content_filters() |
|
633 | + { |
|
634 | + add_filter( |
|
635 | + 'the_content', |
|
636 | + array('EED_Events_Archive', 'event_datetimes'), |
|
637 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
638 | + ); |
|
639 | + add_filter( |
|
640 | + 'the_content', |
|
641 | + array('EED_Events_Archive', 'event_tickets'), |
|
642 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
643 | + ); |
|
644 | + add_filter( |
|
645 | + 'the_content', |
|
646 | + array('EED_Events_Archive', 'event_venues'), |
|
647 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
648 | + ); |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + /** |
|
653 | + * _remove_additional_events_archive_filters |
|
654 | + * |
|
655 | + * @access private |
|
656 | + * @return void |
|
657 | + */ |
|
658 | + private static function _remove_additional_events_archive_filters() |
|
659 | + { |
|
660 | + remove_filter( |
|
661 | + 'the_excerpt', |
|
662 | + array('EED_Events_Archive', 'event_datetimes'), |
|
663 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
664 | + ); |
|
665 | + remove_filter( |
|
666 | + 'the_excerpt', |
|
667 | + array('EED_Events_Archive', 'event_tickets'), |
|
668 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
669 | + ); |
|
670 | + remove_filter( |
|
671 | + 'the_excerpt', |
|
672 | + array('EED_Events_Archive', 'event_venues'), |
|
673 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
674 | + ); |
|
675 | + remove_filter( |
|
676 | + 'the_content', |
|
677 | + array('EED_Events_Archive', 'event_datetimes'), |
|
678 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
679 | + ); |
|
680 | + remove_filter( |
|
681 | + 'the_content', |
|
682 | + array('EED_Events_Archive', 'event_tickets'), |
|
683 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
684 | + ); |
|
685 | + remove_filter( |
|
686 | + 'the_content', |
|
687 | + array('EED_Events_Archive', 'event_venues'), |
|
688 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
689 | + ); |
|
690 | + } |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * remove_all_events_archive_filters |
|
695 | + * |
|
696 | + * @access public |
|
697 | + * @return void |
|
698 | + */ |
|
699 | + public static function remove_all_events_archive_filters() |
|
700 | + { |
|
701 | + // remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
|
702 | + remove_filter('the_title', array('EED_Events_Archive', 'the_title'), 1); |
|
703 | + remove_filter( |
|
704 | + 'the_excerpt', |
|
705 | + array('EED_Events_Archive', 'event_details'), |
|
706 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
707 | + ); |
|
708 | + remove_filter( |
|
709 | + 'the_excerpt', |
|
710 | + array('EED_Events_Archive', 'event_datetimes'), |
|
711 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
712 | + ); |
|
713 | + remove_filter( |
|
714 | + 'the_excerpt', |
|
715 | + array('EED_Events_Archive', 'event_tickets'), |
|
716 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
717 | + ); |
|
718 | + remove_filter( |
|
719 | + 'the_excerpt', |
|
720 | + array('EED_Events_Archive', 'event_venues'), |
|
721 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
722 | + ); |
|
723 | + remove_filter( |
|
724 | + 'the_content', |
|
725 | + array('EED_Events_Archive', 'event_details'), |
|
726 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
727 | + ); |
|
728 | + remove_filter( |
|
729 | + 'the_content', |
|
730 | + array('EED_Events_Archive', 'event_datetimes'), |
|
731 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
732 | + ); |
|
733 | + remove_filter( |
|
734 | + 'the_content', |
|
735 | + array('EED_Events_Archive', 'event_tickets'), |
|
736 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
737 | + ); |
|
738 | + remove_filter( |
|
739 | + 'the_content', |
|
740 | + array('EED_Events_Archive', 'event_venues'), |
|
741 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
742 | + ); |
|
743 | + // don't display entry meta because the existing theme will take care of that |
|
744 | + remove_filter( |
|
745 | + 'FHEE__content_espresso_events_details_template__display_entry_meta', |
|
746 | + '__return_false' |
|
747 | + ); |
|
748 | + } |
|
749 | + |
|
750 | + |
|
751 | + /** |
|
752 | + * load_event_list_assets |
|
753 | + * |
|
754 | + * @access public |
|
755 | + * @return void |
|
756 | + */ |
|
757 | + public function load_event_list_assets() |
|
758 | + { |
|
759 | + do_action('AHEE__EED_Events_Archive__before_load_assets'); |
|
760 | + add_filter('FHEE_load_EE_Session', '__return_true'); |
|
761 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
762 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
763 | + if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
764 | + add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
765 | + } |
|
766 | + } |
|
767 | + |
|
768 | + |
|
769 | + /** |
|
770 | + * wp_enqueue_scripts |
|
771 | + * |
|
772 | + * @access public |
|
773 | + * @return void |
|
774 | + */ |
|
775 | + public function wp_enqueue_scripts() |
|
776 | + { |
|
777 | + // get some style |
|
778 | + if (apply_filters('FHEE_enable_default_espresso_css', false)) { |
|
779 | + // first check uploads folder |
|
780 | + if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
781 | + wp_register_style( |
|
782 | + $this->theme, |
|
783 | + get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
784 | + array('dashicons', 'espresso_default') |
|
785 | + ); |
|
786 | + } else { |
|
787 | + } |
|
788 | + wp_enqueue_style($this->theme); |
|
789 | + } |
|
790 | + } |
|
791 | + |
|
792 | + |
|
793 | + /** |
|
794 | + * template_settings_form |
|
795 | + * |
|
796 | + * @access public |
|
797 | + * @static |
|
798 | + * @return string |
|
799 | + */ |
|
800 | + public static function template_settings_form() |
|
801 | + { |
|
802 | + $template_settings = EE_Registry::instance()->CFG->template_settings; |
|
803 | + $template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive) |
|
804 | + ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config(); |
|
805 | + $template_settings->EED_Events_Archive = apply_filters( |
|
806 | + 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', |
|
807 | + $template_settings->EED_Events_Archive |
|
808 | + ); |
|
809 | + $events_archive_settings = array( |
|
810 | + 'display_status_banner' => 0, |
|
811 | + 'display_description' => 1, |
|
812 | + 'display_ticket_selector' => 0, |
|
813 | + 'display_datetimes' => 1, |
|
814 | + 'display_venue' => 0, |
|
815 | + 'display_expired_events' => 0, |
|
816 | + ); |
|
817 | + $events_archive_settings = array_merge( |
|
818 | + $events_archive_settings, |
|
819 | + (array) $template_settings->EED_Events_Archive |
|
820 | + ); |
|
821 | + EEH_Template::display_template( |
|
822 | + EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', |
|
823 | + $events_archive_settings |
|
824 | + ); |
|
825 | + } |
|
826 | + |
|
827 | + |
|
828 | + /** |
|
829 | + * update_template_settings |
|
830 | + * |
|
831 | + * @access public |
|
832 | + * @param EE_Template_Config $CFG |
|
833 | + * @param array $REQ |
|
834 | + * @return EE_Template_Config |
|
835 | + */ |
|
836 | + public static function update_template_settings($CFG, $REQ) |
|
837 | + { |
|
838 | + $CFG->EED_Events_Archive = new EE_Events_Archive_Config(); |
|
839 | + // unless we are resetting the config... |
|
840 | + if ( |
|
841 | + ! isset($REQ['EED_Events_Archive_reset_event_list_settings']) |
|
842 | + || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1 |
|
843 | + ) { |
|
844 | + $CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) |
|
845 | + ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0; |
|
846 | + $CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description']) |
|
847 | + ? absint($REQ['EED_Events_Archive_display_description']) : 1; |
|
848 | + $CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) |
|
849 | + ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0; |
|
850 | + $CFG->EED_Events_Archive->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint( |
|
851 | + $REQ['EED_Events_Archive_display_datetimes'] |
|
852 | + ) : 1; |
|
853 | + $CFG->EED_Events_Archive->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint( |
|
854 | + $REQ['EED_Events_Archive_display_venue'] |
|
855 | + ) : 0; |
|
856 | + $CFG->EED_Events_Archive->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events']) |
|
857 | + ? absint($REQ['EED_Events_Archive_display_expired_events']) : 0; |
|
858 | + } |
|
859 | + return $CFG; |
|
860 | + } |
|
861 | + |
|
862 | + |
|
863 | + /** |
|
864 | + * event_list_css |
|
865 | + * |
|
866 | + * @access public |
|
867 | + * @param string $extra_class |
|
868 | + * @return string |
|
869 | + */ |
|
870 | + public static function event_list_css($extra_class = '') |
|
871 | + { |
|
872 | + $event_list_css = ! empty($extra_class) ? array($extra_class) : array(); |
|
873 | + $event_list_css[] = 'espresso-event-list-event'; |
|
874 | + return implode(' ', $event_list_css); |
|
875 | + } |
|
876 | + |
|
877 | + |
|
878 | + /** |
|
879 | + * event_categories |
|
880 | + * |
|
881 | + * @access public |
|
882 | + * @return array |
|
883 | + */ |
|
884 | + public static function event_categories() |
|
885 | + { |
|
886 | + return EE_Registry::instance()->load_model('Term')->get_all_ee_categories(); |
|
887 | + } |
|
888 | + |
|
889 | + |
|
890 | + /** |
|
891 | + * display_description |
|
892 | + * |
|
893 | + * @access public |
|
894 | + * @param $value |
|
895 | + * @return bool |
|
896 | + */ |
|
897 | + public static function display_description($value) |
|
898 | + { |
|
899 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
900 | + $display_description = isset($config->display_description) ? $config->display_description : 1; |
|
901 | + return $display_description === $value ? true : false; |
|
902 | + } |
|
903 | + |
|
904 | + |
|
905 | + /** |
|
906 | + * display_ticket_selector |
|
907 | + * |
|
908 | + * @access public |
|
909 | + * @return bool |
|
910 | + */ |
|
911 | + public static function display_ticket_selector() |
|
912 | + { |
|
913 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
914 | + return isset($config->display_ticket_selector) && $config->display_ticket_selector ? true : false; |
|
915 | + } |
|
916 | + |
|
917 | + |
|
918 | + /** |
|
919 | + * display_venue |
|
920 | + * |
|
921 | + * @access public |
|
922 | + * @return bool |
|
923 | + */ |
|
924 | + public static function display_venue() |
|
925 | + { |
|
926 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
927 | + return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name() ? true : false; |
|
928 | + } |
|
929 | + |
|
930 | + |
|
931 | + /** |
|
932 | + * display_datetimes |
|
933 | + * |
|
934 | + * @access public |
|
935 | + * @return bool |
|
936 | + */ |
|
937 | + public static function display_datetimes() |
|
938 | + { |
|
939 | + $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
|
940 | + return isset($config->display_datetimes) && $config->display_datetimes ? true : false; |
|
941 | + } |
|
942 | + |
|
943 | + |
|
944 | + /** |
|
945 | + * event_list_title |
|
946 | + * |
|
947 | + * @access public |
|
948 | + * @return string |
|
949 | + */ |
|
950 | + public static function event_list_title() |
|
951 | + { |
|
952 | + return apply_filters( |
|
953 | + 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
954 | + esc_html__('Upcoming Events', 'event_espresso') |
|
955 | + ); |
|
956 | + } |
|
957 | + |
|
958 | + |
|
959 | + // GRAVEYARD |
|
960 | + |
|
961 | + |
|
962 | + /** |
|
963 | + * @since 4.4.0 |
|
964 | + */ |
|
965 | + public static function _doing_it_wrong_notice($function = '') |
|
966 | + { |
|
967 | + EE_Error::doing_it_wrong( |
|
968 | + __FUNCTION__, |
|
969 | + sprintf( |
|
970 | + esc_html__( |
|
971 | + 'EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s', |
|
972 | + 'event_espresso' |
|
973 | + ), |
|
974 | + $function, |
|
975 | + '<br />', |
|
976 | + '4.6.0' |
|
977 | + ), |
|
978 | + '4.4.0' |
|
979 | + ); |
|
980 | + } |
|
981 | + |
|
982 | + |
|
983 | + /** |
|
984 | + * @deprecated |
|
985 | + * @since 4.4.0 |
|
986 | + */ |
|
987 | + public function get_post_data() |
|
988 | + { |
|
989 | + EEH_Event_Query::set_query_params(); |
|
990 | + } |
|
991 | + |
|
992 | + |
|
993 | + /** |
|
994 | + * @deprecated |
|
995 | + * @since 4.4.0 |
|
996 | + */ |
|
997 | + public function posts_fields($SQL, WP_Query $wp_query) |
|
998 | + { |
|
999 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1000 | + return EEH_Event_Query::posts_fields($SQL, $wp_query); |
|
1001 | + } |
|
1002 | + |
|
1003 | + |
|
1004 | + /** |
|
1005 | + * @deprecated |
|
1006 | + * @since 4.4.0 |
|
1007 | + */ |
|
1008 | + public static function posts_fields_sql_for_orderby($orderby_params = array()) |
|
1009 | + { |
|
1010 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1011 | + return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params); |
|
1012 | + } |
|
1013 | + |
|
1014 | + |
|
1015 | + /** |
|
1016 | + * @deprecated |
|
1017 | + * @since 4.4.0 |
|
1018 | + */ |
|
1019 | + public function posts_join($SQL, WP_Query $wp_query) |
|
1020 | + { |
|
1021 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1022 | + return EEH_Event_Query::posts_join($SQL, $wp_query); |
|
1023 | + } |
|
1024 | + |
|
1025 | + |
|
1026 | + /** |
|
1027 | + * @deprecated |
|
1028 | + * @since 4.4.0 |
|
1029 | + */ |
|
1030 | + public static function posts_join_sql_for_terms($join_terms = null) |
|
1031 | + { |
|
1032 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1033 | + return EEH_Event_Query::posts_join_sql_for_terms($join_terms); |
|
1034 | + } |
|
1035 | + |
|
1036 | + |
|
1037 | + /** |
|
1038 | + * @deprecated |
|
1039 | + * @since 4.4.0 |
|
1040 | + */ |
|
1041 | + public static function posts_join_for_orderby($orderby_params = array()) |
|
1042 | + { |
|
1043 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1044 | + return EEH_Event_Query::posts_join_for_orderby($orderby_params); |
|
1045 | + } |
|
1046 | + |
|
1047 | + |
|
1048 | + /** |
|
1049 | + * @deprecated |
|
1050 | + * @since 4.4.0 |
|
1051 | + */ |
|
1052 | + public function posts_where($SQL, WP_Query $wp_query) |
|
1053 | + { |
|
1054 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1055 | + return EEH_Event_Query::posts_where($SQL, $wp_query); |
|
1056 | + } |
|
1057 | + |
|
1058 | + |
|
1059 | + /** |
|
1060 | + * @deprecated |
|
1061 | + * @since 4.4.0 |
|
1062 | + */ |
|
1063 | + public static function posts_where_sql_for_show_expired($show_expired = false) |
|
1064 | + { |
|
1065 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1066 | + return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired); |
|
1067 | + } |
|
1068 | + |
|
1069 | + |
|
1070 | + /** |
|
1071 | + * @deprecated |
|
1072 | + * @since 4.4.0 |
|
1073 | + */ |
|
1074 | + public static function posts_where_sql_for_event_category_slug($event_category_slug = null) |
|
1075 | + { |
|
1076 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1077 | + return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug); |
|
1078 | + } |
|
1079 | + |
|
1080 | + |
|
1081 | + /** |
|
1082 | + * @deprecated |
|
1083 | + * @since 4.4.0 |
|
1084 | + */ |
|
1085 | + public static function posts_where_sql_for_event_list_month($month = null) |
|
1086 | + { |
|
1087 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1088 | + return EEH_Event_Query::posts_where_sql_for_event_list_month($month); |
|
1089 | + } |
|
1090 | + |
|
1091 | + |
|
1092 | + /** |
|
1093 | + * @deprecated |
|
1094 | + * @since 4.4.0 |
|
1095 | + */ |
|
1096 | + public function posts_orderby($SQL, WP_Query $wp_query) |
|
1097 | + { |
|
1098 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1099 | + return EEH_Event_Query::posts_orderby($SQL, $wp_query); |
|
1100 | + } |
|
1101 | + |
|
1102 | + |
|
1103 | + /** |
|
1104 | + * @deprecated |
|
1105 | + * @since 4.4.0 |
|
1106 | + */ |
|
1107 | + public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') |
|
1108 | + { |
|
1109 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1110 | + return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort); |
|
1111 | + } |
|
1112 | 1112 | } |
1113 | 1113 | |
1114 | 1114 | |
@@ -1117,9 +1117,9 @@ discard block |
||
1117 | 1117 | */ |
1118 | 1118 | function espresso_get_event_list_ID() |
1119 | 1119 | { |
1120 | - EED_Events_Archive::$espresso_event_list_ID++; |
|
1121 | - EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID; |
|
1122 | - return EED_Events_Archive::$espresso_event_list_ID; |
|
1120 | + EED_Events_Archive::$espresso_event_list_ID++; |
|
1121 | + EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID; |
|
1122 | + return EED_Events_Archive::$espresso_event_list_ID; |
|
1123 | 1123 | } |
1124 | 1124 | |
1125 | 1125 | /** |
@@ -1127,7 +1127,7 @@ discard block |
||
1127 | 1127 | */ |
1128 | 1128 | function espresso_event_list_title() |
1129 | 1129 | { |
1130 | - return EED_Events_Archive::event_list_title(); |
|
1130 | + return EED_Events_Archive::event_list_title(); |
|
1131 | 1131 | } |
1132 | 1132 | |
1133 | 1133 | /** |
@@ -1136,7 +1136,7 @@ discard block |
||
1136 | 1136 | */ |
1137 | 1137 | function espresso_event_list_css($extra_class = '') |
1138 | 1138 | { |
1139 | - return EED_Events_Archive::event_list_css($extra_class); |
|
1139 | + return EED_Events_Archive::event_list_css($extra_class); |
|
1140 | 1140 | } |
1141 | 1141 | |
1142 | 1142 | /** |
@@ -1144,7 +1144,7 @@ discard block |
||
1144 | 1144 | */ |
1145 | 1145 | function espresso_get_event_categories() |
1146 | 1146 | { |
1147 | - return EED_Events_Archive::event_categories(); |
|
1147 | + return EED_Events_Archive::event_categories(); |
|
1148 | 1148 | } |
1149 | 1149 | |
1150 | 1150 | /** |
@@ -1152,7 +1152,7 @@ discard block |
||
1152 | 1152 | */ |
1153 | 1153 | function espresso_display_full_description_in_event_list() |
1154 | 1154 | { |
1155 | - return EED_Events_Archive::display_description(2); |
|
1155 | + return EED_Events_Archive::display_description(2); |
|
1156 | 1156 | } |
1157 | 1157 | |
1158 | 1158 | /** |
@@ -1160,7 +1160,7 @@ discard block |
||
1160 | 1160 | */ |
1161 | 1161 | function espresso_display_excerpt_in_event_list() |
1162 | 1162 | { |
1163 | - return EED_Events_Archive::display_description(1); |
|
1163 | + return EED_Events_Archive::display_description(1); |
|
1164 | 1164 | } |
1165 | 1165 | |
1166 | 1166 | /** |
@@ -1168,7 +1168,7 @@ discard block |
||
1168 | 1168 | */ |
1169 | 1169 | function espresso_display_ticket_selector_in_event_list() |
1170 | 1170 | { |
1171 | - return EED_Events_Archive::display_ticket_selector(); |
|
1171 | + return EED_Events_Archive::display_ticket_selector(); |
|
1172 | 1172 | } |
1173 | 1173 | |
1174 | 1174 | /** |
@@ -1176,7 +1176,7 @@ discard block |
||
1176 | 1176 | */ |
1177 | 1177 | function espresso_display_venue_in_event_list() |
1178 | 1178 | { |
1179 | - return EED_Events_Archive::display_venue(); |
|
1179 | + return EED_Events_Archive::display_venue(); |
|
1180 | 1180 | } |
1181 | 1181 | |
1182 | 1182 | /** |
@@ -1184,5 +1184,5 @@ discard block |
||
1184 | 1184 | */ |
1185 | 1185 | function espresso_display_datetimes_in_event_list() |
1186 | 1186 | { |
1187 | - return EED_Events_Archive::display_datetimes(); |
|
1187 | + return EED_Events_Archive::display_datetimes(); |
|
1188 | 1188 | } |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | */ |
124 | 124 | public static function set_definitions() |
125 | 125 | { |
126 | - define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
127 | - define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
126 | + define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__).'assets/'); |
|
127 | + define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)).'templates/'); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public static function get_iframe_embed_button() |
146 | 146 | { |
147 | - if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
147 | + if ( ! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
148 | 148 | self::$_iframe_embed_button = new EventListIframeEmbedButton(); |
149 | 149 | } |
150 | 150 | return self::$_iframe_embed_button; |
@@ -227,10 +227,10 @@ discard block |
||
227 | 227 | EEH_Event_Query::add_query_filters(); |
228 | 228 | // set params that will get used by the filters |
229 | 229 | EEH_Event_Query::set_query_params( |
230 | - '', // month |
|
231 | - '', // category |
|
232 | - $config->display_expired_events, // show_expired |
|
233 | - 'start_date', // orderby |
|
230 | + '', // month |
|
231 | + '', // category |
|
232 | + $config->display_expired_events, // show_expired |
|
233 | + 'start_date', // orderby |
|
234 | 234 | 'ASC' // sort |
235 | 235 | ); |
236 | 236 | // check what template is loaded |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | public function template_include($template = '') |
297 | 297 | { |
298 | 298 | // don't add content filter for dedicated EE child themes or private posts |
299 | - if (! EEH_Template::is_espresso_theme()) { |
|
299 | + if ( ! EEH_Template::is_espresso_theme()) { |
|
300 | 300 | /** @type EE_Events_Archive_Config $config */ |
301 | 301 | $config = $this->config(); |
302 | 302 | // add status banner ? |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | global $post; |
397 | 397 | if ($post instanceof WP_Post) { |
398 | 398 | return ((function_exists('wp_is_block_theme') && wp_is_block_theme()) || in_the_loop()) && $post->ID == $id |
399 | - ? espresso_event_status_banner($post->ID) . $title |
|
399 | + ? espresso_event_status_banner($post->ID).$title |
|
400 | 400 | : $title; |
401 | 401 | } |
402 | 402 | return $title; |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | if (post_password_required()) { |
549 | 549 | return $content; |
550 | 550 | } |
551 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
551 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content; |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | if (post_password_required()) { |
565 | 565 | return $content; |
566 | 566 | } |
567 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
567 | + return EEH_Template::locate_template('content-espresso_events-tickets.php').$content; |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | if (post_password_required()) { |
594 | 594 | return $content; |
595 | 595 | } |
596 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
596 | + return $content.EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | |
@@ -777,10 +777,10 @@ discard block |
||
777 | 777 | // get some style |
778 | 778 | if (apply_filters('FHEE_enable_default_espresso_css', false)) { |
779 | 779 | // first check uploads folder |
780 | - if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
780 | + if (EEH_File::is_readable(get_stylesheet_directory().$this->theme.'/style.css')) { |
|
781 | 781 | wp_register_style( |
782 | 782 | $this->theme, |
783 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
783 | + get_stylesheet_directory_uri().$this->theme.'/style.css', |
|
784 | 784 | array('dashicons', 'espresso_default') |
785 | 785 | ); |
786 | 786 | } else { |
@@ -819,7 +819,7 @@ discard block |
||
819 | 819 | (array) $template_settings->EED_Events_Archive |
820 | 820 | ); |
821 | 821 | EEH_Template::display_template( |
822 | - EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', |
|
822 | + EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php', |
|
823 | 823 | $events_archive_settings |
824 | 824 | ); |
825 | 825 | } |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.27.rc.003'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.27.rc.003'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
@@ -16,1350 +16,1350 @@ |
||
16 | 16 | class EED_Messages extends EED_Module |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * This holds the EE_messages controller |
|
21 | - * |
|
22 | - * @deprecated 4.9.0 |
|
23 | - * @var EE_messages $_EEMSG |
|
24 | - */ |
|
25 | - protected static $_EEMSG; |
|
26 | - |
|
27 | - /** |
|
28 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
29 | - */ |
|
30 | - protected static $_message_resource_manager; |
|
31 | - |
|
32 | - /** |
|
33 | - * This holds the EE_Messages_Processor business class. |
|
34 | - * |
|
35 | - * @type EE_Messages_Processor |
|
36 | - */ |
|
37 | - protected static $_MSG_PROCESSOR; |
|
38 | - |
|
39 | - /** |
|
40 | - * holds all the paths for various messages components. |
|
41 | - * Utilized by autoloader registry |
|
42 | - * |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - protected static $_MSG_PATHS; |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * This will hold an array of messages template packs that are registered in the messages system. |
|
50 | - * Format is: |
|
51 | - * array( |
|
52 | - * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
53 | - * ) |
|
54 | - * |
|
55 | - * @var EE_Messages_Template_Pack[] |
|
56 | - */ |
|
57 | - protected static $_TMP_PACKS = array(); |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @return EED_Messages|EED_Module |
|
62 | - * @throws EE_Error |
|
63 | - * @throws ReflectionException |
|
64 | - */ |
|
65 | - public static function instance() |
|
66 | - { |
|
67 | - return parent::get_instance(__CLASS__); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
73 | - * |
|
74 | - * @since 4.5.0 |
|
75 | - * @return void |
|
76 | - */ |
|
77 | - public static function set_hooks() |
|
78 | - { |
|
79 | - // actions |
|
80 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
81 | - add_action( |
|
82 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
83 | - array('EED_Messages', 'maybe_registration'), |
|
84 | - 10, |
|
85 | - 2 |
|
86 | - ); |
|
87 | - // filters |
|
88 | - add_filter( |
|
89 | - 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
90 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
91 | - 10, |
|
92 | - 4 |
|
93 | - ); |
|
94 | - add_filter( |
|
95 | - 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
96 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
97 | - 10, |
|
98 | - 4 |
|
99 | - ); |
|
100 | - // register routes |
|
101 | - self::_register_routes(); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
106 | - * |
|
107 | - * @access public |
|
108 | - * @return void |
|
109 | - */ |
|
110 | - public static function set_hooks_admin() |
|
111 | - { |
|
112 | - // actions |
|
113 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
114 | - add_action( |
|
115 | - 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
116 | - array('EED_Messages', 'payment_reminder'), |
|
117 | - 10 |
|
118 | - ); |
|
119 | - add_action( |
|
120 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
121 | - array('EED_Messages', 'maybe_registration'), |
|
122 | - 10, |
|
123 | - 3 |
|
124 | - ); |
|
125 | - add_action( |
|
126 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
127 | - array('EED_Messages', 'send_newsletter_message'), |
|
128 | - 10, |
|
129 | - 2 |
|
130 | - ); |
|
131 | - add_action( |
|
132 | - 'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
133 | - array('EED_Messages', 'cancelled_registration'), |
|
134 | - 10 |
|
135 | - ); |
|
136 | - add_action( |
|
137 | - 'AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
138 | - array('EED_Messages', 'process_admin_payment'), |
|
139 | - 10, |
|
140 | - 1 |
|
141 | - ); |
|
142 | - // filters |
|
143 | - add_filter( |
|
144 | - 'FHEE__EE_Admin_Page___process_resend_registration__success', |
|
145 | - array('EED_Messages', 'process_resend'), |
|
146 | - 10, |
|
147 | - 2 |
|
148 | - ); |
|
149 | - add_filter( |
|
150 | - 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
151 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
152 | - 10, |
|
153 | - 4 |
|
154 | - ); |
|
155 | - add_filter( |
|
156 | - 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
157 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
158 | - 10, |
|
159 | - 4 |
|
160 | - ); |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * All the message triggers done by route go in here. |
|
166 | - * |
|
167 | - * @since 4.5.0 |
|
168 | - * @return void |
|
169 | - */ |
|
170 | - protected static function _register_routes() |
|
171 | - { |
|
172 | - EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
173 | - EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
174 | - EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
175 | - EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
176 | - do_action('AHEE__EED_Messages___register_routes'); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * This is called when a browser display trigger is executed. |
|
182 | - * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
183 | - * browser. |
|
184 | - * |
|
185 | - * @since 4.9.0 |
|
186 | - * @param WP $WP |
|
187 | - * @throws EE_Error |
|
188 | - * @throws InvalidArgumentException |
|
189 | - * @throws ReflectionException |
|
190 | - * @throws InvalidDataTypeException |
|
191 | - * @throws InvalidInterfaceException |
|
192 | - */ |
|
193 | - public function browser_trigger($WP) |
|
194 | - { |
|
195 | - // ensure controller is loaded |
|
196 | - self::_load_controller(); |
|
197 | - $token = self::getRequest()->getRequestParam('token'); |
|
198 | - try { |
|
199 | - $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
200 | - self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
201 | - } catch (EE_Error $e) { |
|
202 | - $error_msg = esc_html__( |
|
203 | - 'Please note that a system message failed to send due to a technical issue.', |
|
204 | - 'event_espresso' |
|
205 | - ); |
|
206 | - // add specific message for developers if WP_DEBUG in on |
|
207 | - $error_msg .= '||' . $e->getMessage(); |
|
208 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
209 | - } |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * This is called when a browser error trigger is executed. |
|
215 | - * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
216 | - * message and display it. |
|
217 | - * |
|
218 | - * @since 4.9.0 |
|
219 | - * @param $WP |
|
220 | - * @throws EE_Error |
|
221 | - * @throws InvalidArgumentException |
|
222 | - * @throws InvalidDataTypeException |
|
223 | - * @throws InvalidInterfaceException |
|
224 | - */ |
|
225 | - public function browser_error_trigger($WP) |
|
226 | - { |
|
227 | - $token = self::getRequest()->getRequestParam('token'); |
|
228 | - if ($token) { |
|
229 | - $message = EEM_Message::instance()->get_one_by_token($token); |
|
230 | - if ($message instanceof EE_Message) { |
|
231 | - header('HTTP/1.1 200 OK'); |
|
232 | - $error_msg = nl2br($message->error_message()); |
|
233 | - ?> |
|
19 | + /** |
|
20 | + * This holds the EE_messages controller |
|
21 | + * |
|
22 | + * @deprecated 4.9.0 |
|
23 | + * @var EE_messages $_EEMSG |
|
24 | + */ |
|
25 | + protected static $_EEMSG; |
|
26 | + |
|
27 | + /** |
|
28 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
29 | + */ |
|
30 | + protected static $_message_resource_manager; |
|
31 | + |
|
32 | + /** |
|
33 | + * This holds the EE_Messages_Processor business class. |
|
34 | + * |
|
35 | + * @type EE_Messages_Processor |
|
36 | + */ |
|
37 | + protected static $_MSG_PROCESSOR; |
|
38 | + |
|
39 | + /** |
|
40 | + * holds all the paths for various messages components. |
|
41 | + * Utilized by autoloader registry |
|
42 | + * |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + protected static $_MSG_PATHS; |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * This will hold an array of messages template packs that are registered in the messages system. |
|
50 | + * Format is: |
|
51 | + * array( |
|
52 | + * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
53 | + * ) |
|
54 | + * |
|
55 | + * @var EE_Messages_Template_Pack[] |
|
56 | + */ |
|
57 | + protected static $_TMP_PACKS = array(); |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @return EED_Messages|EED_Module |
|
62 | + * @throws EE_Error |
|
63 | + * @throws ReflectionException |
|
64 | + */ |
|
65 | + public static function instance() |
|
66 | + { |
|
67 | + return parent::get_instance(__CLASS__); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
73 | + * |
|
74 | + * @since 4.5.0 |
|
75 | + * @return void |
|
76 | + */ |
|
77 | + public static function set_hooks() |
|
78 | + { |
|
79 | + // actions |
|
80 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
81 | + add_action( |
|
82 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
83 | + array('EED_Messages', 'maybe_registration'), |
|
84 | + 10, |
|
85 | + 2 |
|
86 | + ); |
|
87 | + // filters |
|
88 | + add_filter( |
|
89 | + 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
90 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
91 | + 10, |
|
92 | + 4 |
|
93 | + ); |
|
94 | + add_filter( |
|
95 | + 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
96 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
97 | + 10, |
|
98 | + 4 |
|
99 | + ); |
|
100 | + // register routes |
|
101 | + self::_register_routes(); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
106 | + * |
|
107 | + * @access public |
|
108 | + * @return void |
|
109 | + */ |
|
110 | + public static function set_hooks_admin() |
|
111 | + { |
|
112 | + // actions |
|
113 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
114 | + add_action( |
|
115 | + 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
116 | + array('EED_Messages', 'payment_reminder'), |
|
117 | + 10 |
|
118 | + ); |
|
119 | + add_action( |
|
120 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
121 | + array('EED_Messages', 'maybe_registration'), |
|
122 | + 10, |
|
123 | + 3 |
|
124 | + ); |
|
125 | + add_action( |
|
126 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
127 | + array('EED_Messages', 'send_newsletter_message'), |
|
128 | + 10, |
|
129 | + 2 |
|
130 | + ); |
|
131 | + add_action( |
|
132 | + 'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
133 | + array('EED_Messages', 'cancelled_registration'), |
|
134 | + 10 |
|
135 | + ); |
|
136 | + add_action( |
|
137 | + 'AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
138 | + array('EED_Messages', 'process_admin_payment'), |
|
139 | + 10, |
|
140 | + 1 |
|
141 | + ); |
|
142 | + // filters |
|
143 | + add_filter( |
|
144 | + 'FHEE__EE_Admin_Page___process_resend_registration__success', |
|
145 | + array('EED_Messages', 'process_resend'), |
|
146 | + 10, |
|
147 | + 2 |
|
148 | + ); |
|
149 | + add_filter( |
|
150 | + 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
151 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
152 | + 10, |
|
153 | + 4 |
|
154 | + ); |
|
155 | + add_filter( |
|
156 | + 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
157 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
158 | + 10, |
|
159 | + 4 |
|
160 | + ); |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * All the message triggers done by route go in here. |
|
166 | + * |
|
167 | + * @since 4.5.0 |
|
168 | + * @return void |
|
169 | + */ |
|
170 | + protected static function _register_routes() |
|
171 | + { |
|
172 | + EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
173 | + EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
174 | + EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
175 | + EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
176 | + do_action('AHEE__EED_Messages___register_routes'); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * This is called when a browser display trigger is executed. |
|
182 | + * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
183 | + * browser. |
|
184 | + * |
|
185 | + * @since 4.9.0 |
|
186 | + * @param WP $WP |
|
187 | + * @throws EE_Error |
|
188 | + * @throws InvalidArgumentException |
|
189 | + * @throws ReflectionException |
|
190 | + * @throws InvalidDataTypeException |
|
191 | + * @throws InvalidInterfaceException |
|
192 | + */ |
|
193 | + public function browser_trigger($WP) |
|
194 | + { |
|
195 | + // ensure controller is loaded |
|
196 | + self::_load_controller(); |
|
197 | + $token = self::getRequest()->getRequestParam('token'); |
|
198 | + try { |
|
199 | + $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
200 | + self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
201 | + } catch (EE_Error $e) { |
|
202 | + $error_msg = esc_html__( |
|
203 | + 'Please note that a system message failed to send due to a technical issue.', |
|
204 | + 'event_espresso' |
|
205 | + ); |
|
206 | + // add specific message for developers if WP_DEBUG in on |
|
207 | + $error_msg .= '||' . $e->getMessage(); |
|
208 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
209 | + } |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * This is called when a browser error trigger is executed. |
|
215 | + * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
216 | + * message and display it. |
|
217 | + * |
|
218 | + * @since 4.9.0 |
|
219 | + * @param $WP |
|
220 | + * @throws EE_Error |
|
221 | + * @throws InvalidArgumentException |
|
222 | + * @throws InvalidDataTypeException |
|
223 | + * @throws InvalidInterfaceException |
|
224 | + */ |
|
225 | + public function browser_error_trigger($WP) |
|
226 | + { |
|
227 | + $token = self::getRequest()->getRequestParam('token'); |
|
228 | + if ($token) { |
|
229 | + $message = EEM_Message::instance()->get_one_by_token($token); |
|
230 | + if ($message instanceof EE_Message) { |
|
231 | + header('HTTP/1.1 200 OK'); |
|
232 | + $error_msg = nl2br($message->error_message()); |
|
233 | + ?> |
|
234 | 234 | <!DOCTYPE html> |
235 | 235 | <html> |
236 | 236 | <head></head> |
237 | 237 | <body> |
238 | 238 | <?php echo empty($error_msg) |
239 | - ? esc_html__( |
|
240 | - 'Unfortunately, we were unable to capture the error message for this message.', |
|
241 | - 'event_espresso' |
|
242 | - ) |
|
243 | - : wp_kses( |
|
244 | - $error_msg, |
|
245 | - array( |
|
246 | - 'a' => array( |
|
247 | - 'href' => array(), |
|
248 | - 'title' => array(), |
|
249 | - ), |
|
250 | - 'span' => array(), |
|
251 | - 'div' => array(), |
|
252 | - 'p' => array(), |
|
253 | - 'strong' => array(), |
|
254 | - 'em' => array(), |
|
255 | - 'br' => array(), |
|
256 | - ) |
|
257 | - ); ?> |
|
239 | + ? esc_html__( |
|
240 | + 'Unfortunately, we were unable to capture the error message for this message.', |
|
241 | + 'event_espresso' |
|
242 | + ) |
|
243 | + : wp_kses( |
|
244 | + $error_msg, |
|
245 | + array( |
|
246 | + 'a' => array( |
|
247 | + 'href' => array(), |
|
248 | + 'title' => array(), |
|
249 | + ), |
|
250 | + 'span' => array(), |
|
251 | + 'div' => array(), |
|
252 | + 'p' => array(), |
|
253 | + 'strong' => array(), |
|
254 | + 'em' => array(), |
|
255 | + 'br' => array(), |
|
256 | + ) |
|
257 | + ); ?> |
|
258 | 258 | </body> |
259 | 259 | </html> |
260 | 260 | <?php |
261 | - exit; |
|
262 | - } |
|
263 | - } |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * This runs when the msg_url_trigger route has initiated. |
|
269 | - * |
|
270 | - * @since 4.5.0 |
|
271 | - * @param WP $WP |
|
272 | - * @throws EE_Error |
|
273 | - * @throws InvalidArgumentException |
|
274 | - * @throws ReflectionException |
|
275 | - * @throws InvalidDataTypeException |
|
276 | - * @throws InvalidInterfaceException |
|
277 | - */ |
|
278 | - public function run($WP) |
|
279 | - { |
|
280 | - // ensure controller is loaded |
|
281 | - self::_load_controller(); |
|
282 | - // attempt to process message |
|
283 | - try { |
|
284 | - /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
285 | - $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
286 | - self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
287 | - } catch (EE_Error $e) { |
|
288 | - $error_msg = esc_html__( |
|
289 | - 'Please note that a system message failed to send due to a technical issue.', |
|
290 | - 'event_espresso' |
|
291 | - ); |
|
292 | - // add specific message for developers if WP_DEBUG in on |
|
293 | - $error_msg .= '||' . $e->getMessage(); |
|
294 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
295 | - } |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * This is triggered by the 'msg_cron_trigger' route. |
|
301 | - * |
|
302 | - * @param WP $WP |
|
303 | - */ |
|
304 | - public function execute_batch_request($WP) |
|
305 | - { |
|
306 | - $this->run_cron(); |
|
307 | - header('HTTP/1.1 200 OK'); |
|
308 | - exit(); |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
314 | - * request. |
|
315 | - */ |
|
316 | - public function run_cron() |
|
317 | - { |
|
318 | - self::_load_controller(); |
|
319 | - $request = self::getRequest(); |
|
320 | - // get required vars |
|
321 | - $cron_type = $request->getRequestParam('type'); |
|
322 | - $transient_key = $request->getRequestParam('key'); |
|
323 | - |
|
324 | - // now let's verify transient, if not valid exit immediately |
|
325 | - if (! get_transient($transient_key)) { |
|
326 | - /** |
|
327 | - * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
328 | - * request. |
|
329 | - */ |
|
330 | - trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
331 | - } |
|
332 | - |
|
333 | - // if made it here, lets' delete the transient to keep the db clean |
|
334 | - delete_transient($transient_key); |
|
335 | - |
|
336 | - if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
337 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
338 | - if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
339 | - self::$_MSG_PROCESSOR->$method(); |
|
340 | - } else { |
|
341 | - // no matching task |
|
342 | - /** |
|
343 | - * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
344 | - * request. |
|
345 | - */ |
|
346 | - trigger_error( |
|
347 | - esc_attr( |
|
348 | - sprintf( |
|
349 | - esc_html__('There is no task corresponding to this route %s', 'event_espresso'), |
|
350 | - $cron_type |
|
351 | - ) |
|
352 | - ) |
|
353 | - ); |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - do_action('FHEE__EED_Messages__run_cron__end'); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * This is used to retrieve the template pack for the given name. |
|
363 | - * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
364 | - * the default template pack is returned. |
|
365 | - * |
|
366 | - * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
367 | - * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
368 | - * in generating the Pack class name). |
|
369 | - * @return EE_Messages_Template_Pack |
|
370 | - * @throws EE_Error |
|
371 | - * @throws InvalidArgumentException |
|
372 | - * @throws ReflectionException |
|
373 | - * @throws InvalidDataTypeException |
|
374 | - * @throws InvalidInterfaceException |
|
375 | - */ |
|
376 | - public static function get_template_pack($template_pack_name) |
|
377 | - { |
|
378 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
379 | - return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * Retrieves an array of all template packs. |
|
385 | - * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
386 | - * |
|
387 | - * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
388 | - * @return EE_Messages_Template_Pack[] |
|
389 | - * @throws EE_Error |
|
390 | - * @throws InvalidArgumentException |
|
391 | - * @throws ReflectionException |
|
392 | - * @throws InvalidDataTypeException |
|
393 | - * @throws InvalidInterfaceException |
|
394 | - */ |
|
395 | - public static function get_template_packs() |
|
396 | - { |
|
397 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
398 | - |
|
399 | - // for backward compat, let's make sure this returns in the same format as originally. |
|
400 | - $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
401 | - $template_pack_collection->rewind(); |
|
402 | - $template_packs = array(); |
|
403 | - while ($template_pack_collection->valid()) { |
|
404 | - $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current(); |
|
405 | - $template_pack_collection->next(); |
|
406 | - } |
|
407 | - return $template_packs; |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
413 | - * |
|
414 | - * @since 4.5.0 |
|
415 | - * @return void |
|
416 | - * @throws EE_Error |
|
417 | - */ |
|
418 | - public static function set_autoloaders() |
|
419 | - { |
|
420 | - if (empty(self::$_MSG_PATHS)) { |
|
421 | - self::_set_messages_paths(); |
|
422 | - foreach (self::$_MSG_PATHS as $path) { |
|
423 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
424 | - } |
|
425 | - // add aliases |
|
426 | - EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
427 | - EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
428 | - } |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
434 | - * for use by the Messages Autoloaders |
|
435 | - * |
|
436 | - * @since 4.5.0 |
|
437 | - * @return void. |
|
438 | - */ |
|
439 | - protected static function _set_messages_paths() |
|
440 | - { |
|
441 | - $dir_ref = array( |
|
442 | - 'messages/message_type', |
|
443 | - 'messages/messenger', |
|
444 | - 'messages/defaults', |
|
445 | - 'messages/defaults/email', |
|
446 | - 'messages/data_class', |
|
447 | - 'messages/validators', |
|
448 | - 'messages/validators/email', |
|
449 | - 'messages/validators/html', |
|
450 | - 'shortcodes', |
|
451 | - ); |
|
452 | - $paths = array(); |
|
453 | - foreach ($dir_ref as $index => $dir) { |
|
454 | - $paths[ $index ] = EE_LIBRARIES . $dir; |
|
455 | - } |
|
456 | - self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - /** |
|
461 | - * Takes care of loading dependencies |
|
462 | - * |
|
463 | - * @since 4.5.0 |
|
464 | - * @return void |
|
465 | - * @throws EE_Error |
|
466 | - * @throws InvalidArgumentException |
|
467 | - * @throws ReflectionException |
|
468 | - * @throws InvalidDataTypeException |
|
469 | - * @throws InvalidInterfaceException |
|
470 | - */ |
|
471 | - protected static function _load_controller() |
|
472 | - { |
|
473 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
474 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
475 | - self::set_autoloaders(); |
|
476 | - self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
477 | - self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
478 | - self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
479 | - } |
|
480 | - } |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * @param EE_Transaction $transaction |
|
485 | - * @throws EE_Error |
|
486 | - * @throws InvalidArgumentException |
|
487 | - * @throws InvalidDataTypeException |
|
488 | - * @throws InvalidInterfaceException |
|
489 | - * @throws ReflectionException |
|
490 | - */ |
|
491 | - public static function payment_reminder(EE_Transaction $transaction) |
|
492 | - { |
|
493 | - self::_load_controller(); |
|
494 | - $data = array($transaction, null); |
|
495 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - /** |
|
500 | - * Any messages triggers for after successful gateway payments should go in here. |
|
501 | - * |
|
502 | - * @param EE_Transaction $transaction object |
|
503 | - * @param EE_Payment|null $payment object |
|
504 | - * @return void |
|
505 | - * @throws EE_Error |
|
506 | - * @throws InvalidArgumentException |
|
507 | - * @throws ReflectionException |
|
508 | - * @throws InvalidDataTypeException |
|
509 | - * @throws InvalidInterfaceException |
|
510 | - */ |
|
511 | - public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
|
512 | - { |
|
513 | - // if there's no payment object, then we cannot do a payment type message! |
|
514 | - if (! $payment instanceof EE_Payment) { |
|
515 | - return; |
|
516 | - } |
|
517 | - self::_load_controller(); |
|
518 | - $data = array($transaction, $payment); |
|
519 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
520 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
521 | - // if payment amount is less than 0 then switch to payment_refund message type. |
|
522 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
523 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * @param EE_Transaction $transaction |
|
529 | - * @throws EE_Error |
|
530 | - * @throws InvalidArgumentException |
|
531 | - * @throws InvalidDataTypeException |
|
532 | - * @throws InvalidInterfaceException |
|
533 | - * @throws ReflectionException |
|
534 | - */ |
|
535 | - public static function cancelled_registration(EE_Transaction $transaction) |
|
536 | - { |
|
537 | - self::_load_controller(); |
|
538 | - $data = array($transaction, null); |
|
539 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
540 | - } |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * Trigger for Registration messages |
|
545 | - * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
546 | - * incoming transaction. |
|
547 | - * |
|
548 | - * @param EE_Registration $registration |
|
549 | - * @param array $extra_details |
|
550 | - * @return void |
|
551 | - * @throws EE_Error |
|
552 | - * @throws InvalidArgumentException |
|
553 | - * @throws InvalidDataTypeException |
|
554 | - * @throws InvalidInterfaceException |
|
555 | - * @throws ReflectionException |
|
556 | - * @throws EntityNotFoundException |
|
557 | - */ |
|
558 | - public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
559 | - { |
|
560 | - |
|
561 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
562 | - // no messages please |
|
563 | - return; |
|
564 | - } |
|
565 | - |
|
566 | - // get all non-trashed registrations so we make sure we send messages for the right status. |
|
567 | - $all_registrations = $registration->transaction()->registrations( |
|
568 | - array( |
|
569 | - array('REG_deleted' => false), |
|
570 | - 'order_by' => array( |
|
571 | - 'Event.EVT_name' => 'ASC', |
|
572 | - 'Attendee.ATT_lname' => 'ASC', |
|
573 | - 'Attendee.ATT_fname' => 'ASC', |
|
574 | - ), |
|
575 | - ) |
|
576 | - ); |
|
577 | - // cached array of statuses so we only trigger messages once per status. |
|
578 | - $statuses_sent = array(); |
|
579 | - self::_load_controller(); |
|
580 | - $mtgs = array(); |
|
581 | - |
|
582 | - // loop through registrations and trigger messages once per status. |
|
583 | - foreach ($all_registrations as $reg) { |
|
584 | - // already triggered? |
|
585 | - if (in_array($reg->status_ID(), $statuses_sent)) { |
|
586 | - continue; |
|
587 | - } |
|
588 | - |
|
589 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
590 | - $mtgs = array_merge( |
|
591 | - $mtgs, |
|
592 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
593 | - $message_type, |
|
594 | - array($registration->transaction(), null, $reg->status_ID()) |
|
595 | - ) |
|
596 | - ); |
|
597 | - $statuses_sent[] = $reg->status_ID(); |
|
598 | - } |
|
599 | - |
|
600 | - if (count($statuses_sent) > 1) { |
|
601 | - $mtgs = array_merge( |
|
602 | - $mtgs, |
|
603 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
604 | - 'registration_summary', |
|
605 | - array($registration->transaction(), null) |
|
606 | - ) |
|
607 | - ); |
|
608 | - } |
|
609 | - |
|
610 | - // batch queue and initiate request |
|
611 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
612 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
613 | - } |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * This is a helper method used to very whether a registration notification should be sent or |
|
618 | - * not. Prevents duplicate notifications going out for registration context notifications. |
|
619 | - * |
|
620 | - * @param EE_Registration $registration [description] |
|
621 | - * @param array $extra_details [description] |
|
622 | - * @return bool true = send away, false = nope halt the presses. |
|
623 | - */ |
|
624 | - protected static function _verify_registration_notification_send( |
|
625 | - EE_Registration $registration, |
|
626 | - $extra_details = array() |
|
627 | - ) { |
|
628 | - if (! $registration->is_primary_registrant()) { |
|
629 | - return false; |
|
630 | - } |
|
631 | - $request = self::getRequest(); |
|
632 | - // first we check if we're in admin and not doing front ajax |
|
633 | - if ( |
|
634 | - ($request->isAdmin() || $request->isAdminAjax()) |
|
635 | - && ! $request->isFrontAjax() |
|
636 | - ) { |
|
637 | - $status_change = $request->getRequestParam('txn_reg_status_change', [], 'int', true); |
|
638 | - // make sure appropriate admin params are set for sending messages |
|
639 | - if ( |
|
640 | - ! isset($status_change['send_notifications']) |
|
641 | - || (isset($status_change['send_notifications']) && ! $status_change['send_notifications']) |
|
642 | - ) { |
|
643 | - // no messages sent please. |
|
644 | - return false; |
|
645 | - } |
|
646 | - } else { |
|
647 | - // frontend request (either regular or via AJAX) |
|
648 | - // TXN is NOT finalized ? |
|
649 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
650 | - return false; |
|
651 | - } |
|
652 | - // return visit but nothing changed ??? |
|
653 | - if ( |
|
654 | - isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
655 | - $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
656 | - ) { |
|
657 | - return false; |
|
658 | - } |
|
659 | - // NOT sending messages && reg status is something other than "Not-Approved" |
|
660 | - if ( |
|
661 | - ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
662 | - $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
663 | - ) { |
|
664 | - return false; |
|
665 | - } |
|
666 | - } |
|
667 | - // release the kraken |
|
668 | - return true; |
|
669 | - } |
|
670 | - |
|
671 | - |
|
672 | - /** |
|
673 | - * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
674 | - * status id. |
|
675 | - * |
|
676 | - * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
677 | - * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
678 | - * @param string $reg_status |
|
679 | - * @return array |
|
680 | - * @throws EE_Error |
|
681 | - * @throws InvalidArgumentException |
|
682 | - * @throws ReflectionException |
|
683 | - * @throws InvalidDataTypeException |
|
684 | - * @throws InvalidInterfaceException |
|
685 | - */ |
|
686 | - protected static function _get_reg_status_array($reg_status = '') |
|
687 | - { |
|
688 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
689 | - return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
690 | - ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
691 | - : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
692 | - } |
|
693 | - |
|
694 | - |
|
695 | - /** |
|
696 | - * Simply returns the payment message type for the given payment status. |
|
697 | - * |
|
698 | - * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
699 | - * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
700 | - * @param string $payment_status The payment status being matched. |
|
701 | - * @return bool|string The payment message type slug matching the status or false if no match. |
|
702 | - * @throws EE_Error |
|
703 | - * @throws InvalidArgumentException |
|
704 | - * @throws ReflectionException |
|
705 | - * @throws InvalidDataTypeException |
|
706 | - * @throws InvalidInterfaceException |
|
707 | - */ |
|
708 | - protected static function _get_payment_message_type($payment_status) |
|
709 | - { |
|
710 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
711 | - return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
712 | - ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
713 | - : false; |
|
714 | - } |
|
715 | - |
|
716 | - |
|
717 | - /** |
|
718 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
719 | - * |
|
720 | - * @access public |
|
721 | - * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
722 | - * @return bool success/fail |
|
723 | - * @throws EE_Error |
|
724 | - * @throws InvalidArgumentException |
|
725 | - * @throws InvalidDataTypeException |
|
726 | - * @throws InvalidInterfaceException |
|
727 | - * @throws ReflectionException |
|
728 | - */ |
|
729 | - public static function process_resend(array $req_data = []) |
|
730 | - { |
|
731 | - self::_load_controller(); |
|
732 | - $request = self::getRequest(); |
|
733 | - // if $msgID in this request then skip to the new resend_message |
|
734 | - if ($request->getRequestParam('MSG_ID')) { |
|
735 | - return self::resend_message(); |
|
736 | - } |
|
737 | - |
|
738 | - // make sure any incoming request data is set on the request so that it gets picked up later. |
|
739 | - foreach ((array) $req_data as $request_key => $request_value) { |
|
740 | - if (! $request->requestParamIsSet($request_key)) { |
|
741 | - $request->setRequestParam($request_key, $request_value); |
|
742 | - } |
|
743 | - } |
|
744 | - |
|
745 | - if ( |
|
746 | - ! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request() |
|
747 | - ) { |
|
748 | - return false; |
|
749 | - } |
|
750 | - |
|
751 | - try { |
|
752 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
753 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
754 | - } catch (EE_Error $e) { |
|
755 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
756 | - return false; |
|
757 | - } |
|
758 | - EE_Error::add_success( |
|
759 | - esc_html__('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
760 | - ); |
|
761 | - return true; // everything got queued. |
|
762 | - } |
|
763 | - |
|
764 | - |
|
765 | - /** |
|
766 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
767 | - * |
|
768 | - * @return bool |
|
769 | - * @throws EE_Error |
|
770 | - * @throws InvalidArgumentException |
|
771 | - * @throws InvalidDataTypeException |
|
772 | - * @throws InvalidInterfaceException |
|
773 | - * @throws ReflectionException |
|
774 | - */ |
|
775 | - public static function resend_message() |
|
776 | - { |
|
777 | - self::_load_controller(); |
|
778 | - |
|
779 | - $msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int'); |
|
780 | - if (! $msgID) { |
|
781 | - EE_Error::add_error( |
|
782 | - esc_html__( |
|
783 | - 'Something went wrong because there is no "MSG_ID" value in the request', |
|
784 | - 'event_espresso' |
|
785 | - ), |
|
786 | - __FILE__, |
|
787 | - __FUNCTION__, |
|
788 | - __LINE__ |
|
789 | - ); |
|
790 | - return false; |
|
791 | - } |
|
792 | - |
|
793 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID); |
|
794 | - |
|
795 | - // setup success message. |
|
796 | - $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
797 | - EE_Error::add_success( |
|
798 | - sprintf( |
|
799 | - _n( |
|
800 | - 'There was %d message queued for resending.', |
|
801 | - 'There were %d messages queued for resending.', |
|
802 | - $count_ready_for_resend, |
|
803 | - 'event_espresso' |
|
804 | - ), |
|
805 | - $count_ready_for_resend |
|
806 | - ) |
|
807 | - ); |
|
808 | - return true; |
|
809 | - } |
|
810 | - |
|
811 | - |
|
812 | - /** |
|
813 | - * Message triggers for manual payment applied by admin |
|
814 | - * |
|
815 | - * @param EE_Payment $payment EE_payment object |
|
816 | - * @return bool success/fail |
|
817 | - * @throws EE_Error |
|
818 | - * @throws InvalidArgumentException |
|
819 | - * @throws ReflectionException |
|
820 | - * @throws InvalidDataTypeException |
|
821 | - * @throws InvalidInterfaceException |
|
822 | - */ |
|
823 | - public static function process_admin_payment(EE_Payment $payment) |
|
824 | - { |
|
825 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
826 | - // we need to get the transaction object |
|
827 | - $transaction = $payment->transaction(); |
|
828 | - if ($transaction instanceof EE_Transaction) { |
|
829 | - $data = array($transaction, $payment); |
|
830 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
831 | - |
|
832 | - // if payment amount is less than 0 then switch to payment_refund message type. |
|
833 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
834 | - |
|
835 | - // if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
836 | - $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved |
|
837 | - ? false : $message_type; |
|
838 | - |
|
839 | - self::_load_controller(); |
|
840 | - |
|
841 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
842 | - |
|
843 | - // get count of queued for generation |
|
844 | - $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
845 | - array( |
|
846 | - EEM_Message::status_incomplete, |
|
847 | - EEM_Message::status_idle, |
|
848 | - ) |
|
849 | - ); |
|
850 | - |
|
851 | - if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
852 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
853 | - return true; |
|
854 | - } else { |
|
855 | - $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
856 | - EEM_Message::instance()->stati_indicating_failed_sending() |
|
857 | - ); |
|
858 | - /** |
|
859 | - * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
860 | - * IMMEDIATE generation. |
|
861 | - */ |
|
862 | - if ($count_failed > 0) { |
|
863 | - EE_Error::add_error( |
|
864 | - sprintf( |
|
865 | - _n( |
|
866 | - 'The payment notification generation failed.', |
|
867 | - '%d payment notifications failed being sent.', |
|
868 | - $count_failed, |
|
869 | - 'event_espresso' |
|
870 | - ), |
|
871 | - $count_failed |
|
872 | - ), |
|
873 | - __FILE__, |
|
874 | - __FUNCTION__, |
|
875 | - __LINE__ |
|
876 | - ); |
|
877 | - |
|
878 | - return false; |
|
879 | - } else { |
|
880 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
881 | - return true; |
|
882 | - } |
|
883 | - } |
|
884 | - } else { |
|
885 | - EE_Error::add_error( |
|
886 | - 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
887 | - 'event_espresso' |
|
888 | - ); |
|
889 | - return false; |
|
890 | - } |
|
891 | - } |
|
892 | - |
|
893 | - |
|
894 | - /** |
|
895 | - * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
896 | - * |
|
897 | - * @since 4.3.0 |
|
898 | - * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
899 | - * @param int $grp_id a specific message template group id. |
|
900 | - * @return void |
|
901 | - * @throws EE_Error |
|
902 | - * @throws InvalidArgumentException |
|
903 | - * @throws InvalidDataTypeException |
|
904 | - * @throws InvalidInterfaceException |
|
905 | - * @throws ReflectionException |
|
906 | - */ |
|
907 | - public static function send_newsletter_message($registrations, $grp_id) |
|
908 | - { |
|
909 | - // make sure mtp is id and set it in the request later messages setup. |
|
910 | - self::getRequest()->setRequestParam('GRP_ID', (int) $grp_id); |
|
911 | - self::_load_controller(); |
|
912 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
913 | - } |
|
914 | - |
|
915 | - |
|
916 | - /** |
|
917 | - * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
918 | - * |
|
919 | - * @since 4.3.0 |
|
920 | - * @param string $registration_message_trigger_url |
|
921 | - * @param EE_Registration $registration |
|
922 | - * @param string $messenger |
|
923 | - * @param string $message_type |
|
924 | - * @return string |
|
925 | - * @throws EE_Error |
|
926 | - * @throws InvalidArgumentException |
|
927 | - * @throws InvalidDataTypeException |
|
928 | - * @throws InvalidInterfaceException |
|
929 | - */ |
|
930 | - public static function registration_message_trigger_url( |
|
931 | - $registration_message_trigger_url, |
|
932 | - EE_Registration $registration, |
|
933 | - $messenger = 'html', |
|
934 | - $message_type = 'invoice' |
|
935 | - ) { |
|
936 | - // whitelist $messenger |
|
937 | - switch ($messenger) { |
|
938 | - case 'pdf': |
|
939 | - $sending_messenger = 'pdf'; |
|
940 | - $generating_messenger = 'html'; |
|
941 | - break; |
|
942 | - case 'html': |
|
943 | - default: |
|
944 | - $sending_messenger = 'html'; |
|
945 | - $generating_messenger = 'html'; |
|
946 | - break; |
|
947 | - } |
|
948 | - // whitelist $message_type |
|
949 | - switch ($message_type) { |
|
950 | - case 'receipt': |
|
951 | - $message_type = 'receipt'; |
|
952 | - break; |
|
953 | - case 'invoice': |
|
954 | - default: |
|
955 | - $message_type = 'invoice'; |
|
956 | - break; |
|
957 | - } |
|
958 | - // verify that both the messenger AND the message type are active |
|
959 | - if ( |
|
960 | - EEH_MSG_Template::is_messenger_active($sending_messenger) |
|
961 | - && EEH_MSG_Template::is_mt_active($message_type) |
|
962 | - ) { |
|
963 | - // need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
964 | - $template_query_params = array( |
|
965 | - 'MTP_is_active' => true, |
|
966 | - 'MTP_messenger' => $generating_messenger, |
|
967 | - 'MTP_message_type' => $message_type, |
|
968 | - 'Event.EVT_ID' => $registration->event_ID(), |
|
969 | - ); |
|
970 | - // get the message template group. |
|
971 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
972 | - // if we don't have an EE_Message_Template_Group then return |
|
973 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
974 | - // remove EVT_ID from query params so that global templates get picked up |
|
975 | - unset($template_query_params['Event.EVT_ID']); |
|
976 | - // get global template as the fallback |
|
977 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
978 | - } |
|
979 | - // if we don't have an EE_Message_Template_Group then return |
|
980 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
981 | - return ''; |
|
982 | - } |
|
983 | - // generate the URL |
|
984 | - $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
985 | - $sending_messenger, |
|
986 | - $generating_messenger, |
|
987 | - 'purchaser', |
|
988 | - $message_type, |
|
989 | - $registration, |
|
990 | - $msg_template_group->ID(), |
|
991 | - $registration->transaction_ID() |
|
992 | - ); |
|
993 | - } |
|
994 | - return $registration_message_trigger_url; |
|
995 | - } |
|
996 | - |
|
997 | - |
|
998 | - /** |
|
999 | - * Use to generate and return a message preview! |
|
1000 | - * |
|
1001 | - * @param string $type This should correspond with a valid message type |
|
1002 | - * @param string $context This should correspond with a valid context for the message type |
|
1003 | - * @param string $messenger This should correspond with a valid messenger. |
|
1004 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
1005 | - * preview |
|
1006 | - * @return bool|string The body of the message or if send is requested, sends. |
|
1007 | - * @throws EE_Error |
|
1008 | - * @throws InvalidArgumentException |
|
1009 | - * @throws InvalidDataTypeException |
|
1010 | - * @throws InvalidInterfaceException |
|
1011 | - * @throws ReflectionException |
|
1012 | - */ |
|
1013 | - public static function preview_message($type, $context, $messenger, $send = false) |
|
1014 | - { |
|
1015 | - self::_load_controller(); |
|
1016 | - $mtg = new EE_Message_To_Generate( |
|
1017 | - $messenger, |
|
1018 | - $type, |
|
1019 | - array(), |
|
1020 | - $context, |
|
1021 | - true |
|
1022 | - ); |
|
1023 | - $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
1024 | - if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
1025 | - // loop through all content for the preview and remove any persisted records. |
|
1026 | - $content = ''; |
|
1027 | - foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
1028 | - $content = $message->content(); |
|
1029 | - if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
1030 | - $message->delete(); |
|
1031 | - } |
|
1032 | - } |
|
1033 | - return $content; |
|
1034 | - } else { |
|
1035 | - return $generated_preview_queue; |
|
1036 | - } |
|
1037 | - } |
|
1038 | - |
|
1039 | - |
|
1040 | - /** |
|
1041 | - * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
1042 | - * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
1043 | - * content found in the EE_Message objects in the queue. |
|
1044 | - * |
|
1045 | - * @since 4.9.0 |
|
1046 | - * @param string $messenger a string matching a valid active messenger in the system |
|
1047 | - * @param string $message_type Although it seems contrary to the name of the method, a message |
|
1048 | - * type name is still required to send along the message type to the |
|
1049 | - * messenger because this is used for determining what specific |
|
1050 | - * variations might be loaded for the generated message. |
|
1051 | - * @param EE_Messages_Queue $queue |
|
1052 | - * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
1053 | - * aggregate EE_Message object. |
|
1054 | - * @return bool success or fail. |
|
1055 | - * @throws EE_Error |
|
1056 | - * @throws InvalidArgumentException |
|
1057 | - * @throws ReflectionException |
|
1058 | - * @throws InvalidDataTypeException |
|
1059 | - * @throws InvalidInterfaceException |
|
1060 | - */ |
|
1061 | - public static function send_message_with_messenger_only( |
|
1062 | - $messenger, |
|
1063 | - $message_type, |
|
1064 | - EE_Messages_Queue $queue, |
|
1065 | - $custom_subject = '' |
|
1066 | - ) { |
|
1067 | - self::_load_controller(); |
|
1068 | - /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
1069 | - $message_to_generate = EE_Registry::instance()->load_lib( |
|
1070 | - 'Message_To_Generate_From_Queue', |
|
1071 | - array( |
|
1072 | - $messenger, |
|
1073 | - $message_type, |
|
1074 | - $queue, |
|
1075 | - $custom_subject, |
|
1076 | - ) |
|
1077 | - ); |
|
1078 | - return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
1079 | - } |
|
1080 | - |
|
1081 | - |
|
1082 | - /** |
|
1083 | - * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
1084 | - * |
|
1085 | - * @since 4.9.0 |
|
1086 | - * @param array $message_ids An array of message ids |
|
1087 | - * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
1088 | - * messages. |
|
1089 | - * @throws EE_Error |
|
1090 | - * @throws InvalidArgumentException |
|
1091 | - * @throws InvalidDataTypeException |
|
1092 | - * @throws InvalidInterfaceException |
|
1093 | - * @throws ReflectionException |
|
1094 | - */ |
|
1095 | - public static function generate_now($message_ids) |
|
1096 | - { |
|
1097 | - self::_load_controller(); |
|
1098 | - $messages = EEM_Message::instance()->get_all( |
|
1099 | - array( |
|
1100 | - 0 => array( |
|
1101 | - 'MSG_ID' => array('IN', $message_ids), |
|
1102 | - 'STS_ID' => EEM_Message::status_incomplete, |
|
1103 | - ), |
|
1104 | - ) |
|
1105 | - ); |
|
1106 | - $generated_queue = false; |
|
1107 | - if ($messages) { |
|
1108 | - $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
1109 | - } |
|
1110 | - |
|
1111 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
1112 | - EE_Error::add_error( |
|
1113 | - esc_html__( |
|
1114 | - 'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
1115 | - 'event_espresso' |
|
1116 | - ), |
|
1117 | - __FILE__, |
|
1118 | - __FUNCTION__, |
|
1119 | - __LINE__ |
|
1120 | - ); |
|
1121 | - } |
|
1122 | - return $generated_queue; |
|
1123 | - } |
|
1124 | - |
|
1125 | - |
|
1126 | - /** |
|
1127 | - * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
1128 | - * EEM_Message::status_idle |
|
1129 | - * |
|
1130 | - * @since 4.9.0 |
|
1131 | - * @param $message_ids |
|
1132 | - * @return bool|EE_Messages_Queue false if no messages sent. |
|
1133 | - * @throws EE_Error |
|
1134 | - * @throws InvalidArgumentException |
|
1135 | - * @throws InvalidDataTypeException |
|
1136 | - * @throws InvalidInterfaceException |
|
1137 | - * @throws ReflectionException |
|
1138 | - */ |
|
1139 | - public static function send_now($message_ids) |
|
1140 | - { |
|
1141 | - self::_load_controller(); |
|
1142 | - $messages = EEM_Message::instance()->get_all( |
|
1143 | - array( |
|
1144 | - 0 => array( |
|
1145 | - 'MSG_ID' => array('IN', $message_ids), |
|
1146 | - 'STS_ID' => array( |
|
1147 | - 'IN', |
|
1148 | - array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
1149 | - ), |
|
1150 | - ), |
|
1151 | - ) |
|
1152 | - ); |
|
1153 | - $sent_queue = false; |
|
1154 | - if ($messages) { |
|
1155 | - $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
1156 | - } |
|
1157 | - |
|
1158 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
1159 | - EE_Error::add_error( |
|
1160 | - esc_html__( |
|
1161 | - 'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
1162 | - 'event_espresso' |
|
1163 | - ), |
|
1164 | - __FILE__, |
|
1165 | - __FUNCTION__, |
|
1166 | - __LINE__ |
|
1167 | - ); |
|
1168 | - } else { |
|
1169 | - // can count how many sent by using the messages in the queue |
|
1170 | - $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
1171 | - if ($sent_count > 0) { |
|
1172 | - EE_Error::add_success( |
|
1173 | - sprintf( |
|
1174 | - _n( |
|
1175 | - 'There was %d message successfully sent.', |
|
1176 | - 'There were %d messages successfully sent.', |
|
1177 | - $sent_count, |
|
1178 | - 'event_espresso' |
|
1179 | - ), |
|
1180 | - $sent_count |
|
1181 | - ) |
|
1182 | - ); |
|
1183 | - } else { |
|
1184 | - EE_Error::overwrite_errors(); |
|
1185 | - EE_Error::add_error( |
|
1186 | - esc_html__( |
|
1187 | - 'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
261 | + exit; |
|
262 | + } |
|
263 | + } |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * This runs when the msg_url_trigger route has initiated. |
|
269 | + * |
|
270 | + * @since 4.5.0 |
|
271 | + * @param WP $WP |
|
272 | + * @throws EE_Error |
|
273 | + * @throws InvalidArgumentException |
|
274 | + * @throws ReflectionException |
|
275 | + * @throws InvalidDataTypeException |
|
276 | + * @throws InvalidInterfaceException |
|
277 | + */ |
|
278 | + public function run($WP) |
|
279 | + { |
|
280 | + // ensure controller is loaded |
|
281 | + self::_load_controller(); |
|
282 | + // attempt to process message |
|
283 | + try { |
|
284 | + /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
285 | + $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
286 | + self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
287 | + } catch (EE_Error $e) { |
|
288 | + $error_msg = esc_html__( |
|
289 | + 'Please note that a system message failed to send due to a technical issue.', |
|
290 | + 'event_espresso' |
|
291 | + ); |
|
292 | + // add specific message for developers if WP_DEBUG in on |
|
293 | + $error_msg .= '||' . $e->getMessage(); |
|
294 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
295 | + } |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * This is triggered by the 'msg_cron_trigger' route. |
|
301 | + * |
|
302 | + * @param WP $WP |
|
303 | + */ |
|
304 | + public function execute_batch_request($WP) |
|
305 | + { |
|
306 | + $this->run_cron(); |
|
307 | + header('HTTP/1.1 200 OK'); |
|
308 | + exit(); |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
314 | + * request. |
|
315 | + */ |
|
316 | + public function run_cron() |
|
317 | + { |
|
318 | + self::_load_controller(); |
|
319 | + $request = self::getRequest(); |
|
320 | + // get required vars |
|
321 | + $cron_type = $request->getRequestParam('type'); |
|
322 | + $transient_key = $request->getRequestParam('key'); |
|
323 | + |
|
324 | + // now let's verify transient, if not valid exit immediately |
|
325 | + if (! get_transient($transient_key)) { |
|
326 | + /** |
|
327 | + * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
328 | + * request. |
|
329 | + */ |
|
330 | + trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
331 | + } |
|
332 | + |
|
333 | + // if made it here, lets' delete the transient to keep the db clean |
|
334 | + delete_transient($transient_key); |
|
335 | + |
|
336 | + if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
337 | + $method = 'batch_' . $cron_type . '_from_queue'; |
|
338 | + if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
339 | + self::$_MSG_PROCESSOR->$method(); |
|
340 | + } else { |
|
341 | + // no matching task |
|
342 | + /** |
|
343 | + * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
344 | + * request. |
|
345 | + */ |
|
346 | + trigger_error( |
|
347 | + esc_attr( |
|
348 | + sprintf( |
|
349 | + esc_html__('There is no task corresponding to this route %s', 'event_espresso'), |
|
350 | + $cron_type |
|
351 | + ) |
|
352 | + ) |
|
353 | + ); |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + do_action('FHEE__EED_Messages__run_cron__end'); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * This is used to retrieve the template pack for the given name. |
|
363 | + * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
364 | + * the default template pack is returned. |
|
365 | + * |
|
366 | + * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
367 | + * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
368 | + * in generating the Pack class name). |
|
369 | + * @return EE_Messages_Template_Pack |
|
370 | + * @throws EE_Error |
|
371 | + * @throws InvalidArgumentException |
|
372 | + * @throws ReflectionException |
|
373 | + * @throws InvalidDataTypeException |
|
374 | + * @throws InvalidInterfaceException |
|
375 | + */ |
|
376 | + public static function get_template_pack($template_pack_name) |
|
377 | + { |
|
378 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
379 | + return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * Retrieves an array of all template packs. |
|
385 | + * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
386 | + * |
|
387 | + * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
388 | + * @return EE_Messages_Template_Pack[] |
|
389 | + * @throws EE_Error |
|
390 | + * @throws InvalidArgumentException |
|
391 | + * @throws ReflectionException |
|
392 | + * @throws InvalidDataTypeException |
|
393 | + * @throws InvalidInterfaceException |
|
394 | + */ |
|
395 | + public static function get_template_packs() |
|
396 | + { |
|
397 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
398 | + |
|
399 | + // for backward compat, let's make sure this returns in the same format as originally. |
|
400 | + $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
401 | + $template_pack_collection->rewind(); |
|
402 | + $template_packs = array(); |
|
403 | + while ($template_pack_collection->valid()) { |
|
404 | + $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current(); |
|
405 | + $template_pack_collection->next(); |
|
406 | + } |
|
407 | + return $template_packs; |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
413 | + * |
|
414 | + * @since 4.5.0 |
|
415 | + * @return void |
|
416 | + * @throws EE_Error |
|
417 | + */ |
|
418 | + public static function set_autoloaders() |
|
419 | + { |
|
420 | + if (empty(self::$_MSG_PATHS)) { |
|
421 | + self::_set_messages_paths(); |
|
422 | + foreach (self::$_MSG_PATHS as $path) { |
|
423 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
424 | + } |
|
425 | + // add aliases |
|
426 | + EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
427 | + EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
428 | + } |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
434 | + * for use by the Messages Autoloaders |
|
435 | + * |
|
436 | + * @since 4.5.0 |
|
437 | + * @return void. |
|
438 | + */ |
|
439 | + protected static function _set_messages_paths() |
|
440 | + { |
|
441 | + $dir_ref = array( |
|
442 | + 'messages/message_type', |
|
443 | + 'messages/messenger', |
|
444 | + 'messages/defaults', |
|
445 | + 'messages/defaults/email', |
|
446 | + 'messages/data_class', |
|
447 | + 'messages/validators', |
|
448 | + 'messages/validators/email', |
|
449 | + 'messages/validators/html', |
|
450 | + 'shortcodes', |
|
451 | + ); |
|
452 | + $paths = array(); |
|
453 | + foreach ($dir_ref as $index => $dir) { |
|
454 | + $paths[ $index ] = EE_LIBRARIES . $dir; |
|
455 | + } |
|
456 | + self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + /** |
|
461 | + * Takes care of loading dependencies |
|
462 | + * |
|
463 | + * @since 4.5.0 |
|
464 | + * @return void |
|
465 | + * @throws EE_Error |
|
466 | + * @throws InvalidArgumentException |
|
467 | + * @throws ReflectionException |
|
468 | + * @throws InvalidDataTypeException |
|
469 | + * @throws InvalidInterfaceException |
|
470 | + */ |
|
471 | + protected static function _load_controller() |
|
472 | + { |
|
473 | + if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
474 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
475 | + self::set_autoloaders(); |
|
476 | + self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
477 | + self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
478 | + self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
479 | + } |
|
480 | + } |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * @param EE_Transaction $transaction |
|
485 | + * @throws EE_Error |
|
486 | + * @throws InvalidArgumentException |
|
487 | + * @throws InvalidDataTypeException |
|
488 | + * @throws InvalidInterfaceException |
|
489 | + * @throws ReflectionException |
|
490 | + */ |
|
491 | + public static function payment_reminder(EE_Transaction $transaction) |
|
492 | + { |
|
493 | + self::_load_controller(); |
|
494 | + $data = array($transaction, null); |
|
495 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + /** |
|
500 | + * Any messages triggers for after successful gateway payments should go in here. |
|
501 | + * |
|
502 | + * @param EE_Transaction $transaction object |
|
503 | + * @param EE_Payment|null $payment object |
|
504 | + * @return void |
|
505 | + * @throws EE_Error |
|
506 | + * @throws InvalidArgumentException |
|
507 | + * @throws ReflectionException |
|
508 | + * @throws InvalidDataTypeException |
|
509 | + * @throws InvalidInterfaceException |
|
510 | + */ |
|
511 | + public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
|
512 | + { |
|
513 | + // if there's no payment object, then we cannot do a payment type message! |
|
514 | + if (! $payment instanceof EE_Payment) { |
|
515 | + return; |
|
516 | + } |
|
517 | + self::_load_controller(); |
|
518 | + $data = array($transaction, $payment); |
|
519 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
520 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
521 | + // if payment amount is less than 0 then switch to payment_refund message type. |
|
522 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
523 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * @param EE_Transaction $transaction |
|
529 | + * @throws EE_Error |
|
530 | + * @throws InvalidArgumentException |
|
531 | + * @throws InvalidDataTypeException |
|
532 | + * @throws InvalidInterfaceException |
|
533 | + * @throws ReflectionException |
|
534 | + */ |
|
535 | + public static function cancelled_registration(EE_Transaction $transaction) |
|
536 | + { |
|
537 | + self::_load_controller(); |
|
538 | + $data = array($transaction, null); |
|
539 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
540 | + } |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * Trigger for Registration messages |
|
545 | + * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
546 | + * incoming transaction. |
|
547 | + * |
|
548 | + * @param EE_Registration $registration |
|
549 | + * @param array $extra_details |
|
550 | + * @return void |
|
551 | + * @throws EE_Error |
|
552 | + * @throws InvalidArgumentException |
|
553 | + * @throws InvalidDataTypeException |
|
554 | + * @throws InvalidInterfaceException |
|
555 | + * @throws ReflectionException |
|
556 | + * @throws EntityNotFoundException |
|
557 | + */ |
|
558 | + public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
559 | + { |
|
560 | + |
|
561 | + if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
562 | + // no messages please |
|
563 | + return; |
|
564 | + } |
|
565 | + |
|
566 | + // get all non-trashed registrations so we make sure we send messages for the right status. |
|
567 | + $all_registrations = $registration->transaction()->registrations( |
|
568 | + array( |
|
569 | + array('REG_deleted' => false), |
|
570 | + 'order_by' => array( |
|
571 | + 'Event.EVT_name' => 'ASC', |
|
572 | + 'Attendee.ATT_lname' => 'ASC', |
|
573 | + 'Attendee.ATT_fname' => 'ASC', |
|
574 | + ), |
|
575 | + ) |
|
576 | + ); |
|
577 | + // cached array of statuses so we only trigger messages once per status. |
|
578 | + $statuses_sent = array(); |
|
579 | + self::_load_controller(); |
|
580 | + $mtgs = array(); |
|
581 | + |
|
582 | + // loop through registrations and trigger messages once per status. |
|
583 | + foreach ($all_registrations as $reg) { |
|
584 | + // already triggered? |
|
585 | + if (in_array($reg->status_ID(), $statuses_sent)) { |
|
586 | + continue; |
|
587 | + } |
|
588 | + |
|
589 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
590 | + $mtgs = array_merge( |
|
591 | + $mtgs, |
|
592 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
593 | + $message_type, |
|
594 | + array($registration->transaction(), null, $reg->status_ID()) |
|
595 | + ) |
|
596 | + ); |
|
597 | + $statuses_sent[] = $reg->status_ID(); |
|
598 | + } |
|
599 | + |
|
600 | + if (count($statuses_sent) > 1) { |
|
601 | + $mtgs = array_merge( |
|
602 | + $mtgs, |
|
603 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
604 | + 'registration_summary', |
|
605 | + array($registration->transaction(), null) |
|
606 | + ) |
|
607 | + ); |
|
608 | + } |
|
609 | + |
|
610 | + // batch queue and initiate request |
|
611 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
612 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
613 | + } |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * This is a helper method used to very whether a registration notification should be sent or |
|
618 | + * not. Prevents duplicate notifications going out for registration context notifications. |
|
619 | + * |
|
620 | + * @param EE_Registration $registration [description] |
|
621 | + * @param array $extra_details [description] |
|
622 | + * @return bool true = send away, false = nope halt the presses. |
|
623 | + */ |
|
624 | + protected static function _verify_registration_notification_send( |
|
625 | + EE_Registration $registration, |
|
626 | + $extra_details = array() |
|
627 | + ) { |
|
628 | + if (! $registration->is_primary_registrant()) { |
|
629 | + return false; |
|
630 | + } |
|
631 | + $request = self::getRequest(); |
|
632 | + // first we check if we're in admin and not doing front ajax |
|
633 | + if ( |
|
634 | + ($request->isAdmin() || $request->isAdminAjax()) |
|
635 | + && ! $request->isFrontAjax() |
|
636 | + ) { |
|
637 | + $status_change = $request->getRequestParam('txn_reg_status_change', [], 'int', true); |
|
638 | + // make sure appropriate admin params are set for sending messages |
|
639 | + if ( |
|
640 | + ! isset($status_change['send_notifications']) |
|
641 | + || (isset($status_change['send_notifications']) && ! $status_change['send_notifications']) |
|
642 | + ) { |
|
643 | + // no messages sent please. |
|
644 | + return false; |
|
645 | + } |
|
646 | + } else { |
|
647 | + // frontend request (either regular or via AJAX) |
|
648 | + // TXN is NOT finalized ? |
|
649 | + if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
650 | + return false; |
|
651 | + } |
|
652 | + // return visit but nothing changed ??? |
|
653 | + if ( |
|
654 | + isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
655 | + $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
656 | + ) { |
|
657 | + return false; |
|
658 | + } |
|
659 | + // NOT sending messages && reg status is something other than "Not-Approved" |
|
660 | + if ( |
|
661 | + ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
662 | + $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
663 | + ) { |
|
664 | + return false; |
|
665 | + } |
|
666 | + } |
|
667 | + // release the kraken |
|
668 | + return true; |
|
669 | + } |
|
670 | + |
|
671 | + |
|
672 | + /** |
|
673 | + * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
674 | + * status id. |
|
675 | + * |
|
676 | + * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
677 | + * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
678 | + * @param string $reg_status |
|
679 | + * @return array |
|
680 | + * @throws EE_Error |
|
681 | + * @throws InvalidArgumentException |
|
682 | + * @throws ReflectionException |
|
683 | + * @throws InvalidDataTypeException |
|
684 | + * @throws InvalidInterfaceException |
|
685 | + */ |
|
686 | + protected static function _get_reg_status_array($reg_status = '') |
|
687 | + { |
|
688 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
689 | + return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
690 | + ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
691 | + : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
692 | + } |
|
693 | + |
|
694 | + |
|
695 | + /** |
|
696 | + * Simply returns the payment message type for the given payment status. |
|
697 | + * |
|
698 | + * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
699 | + * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
700 | + * @param string $payment_status The payment status being matched. |
|
701 | + * @return bool|string The payment message type slug matching the status or false if no match. |
|
702 | + * @throws EE_Error |
|
703 | + * @throws InvalidArgumentException |
|
704 | + * @throws ReflectionException |
|
705 | + * @throws InvalidDataTypeException |
|
706 | + * @throws InvalidInterfaceException |
|
707 | + */ |
|
708 | + protected static function _get_payment_message_type($payment_status) |
|
709 | + { |
|
710 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
711 | + return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
712 | + ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
713 | + : false; |
|
714 | + } |
|
715 | + |
|
716 | + |
|
717 | + /** |
|
718 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
719 | + * |
|
720 | + * @access public |
|
721 | + * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
722 | + * @return bool success/fail |
|
723 | + * @throws EE_Error |
|
724 | + * @throws InvalidArgumentException |
|
725 | + * @throws InvalidDataTypeException |
|
726 | + * @throws InvalidInterfaceException |
|
727 | + * @throws ReflectionException |
|
728 | + */ |
|
729 | + public static function process_resend(array $req_data = []) |
|
730 | + { |
|
731 | + self::_load_controller(); |
|
732 | + $request = self::getRequest(); |
|
733 | + // if $msgID in this request then skip to the new resend_message |
|
734 | + if ($request->getRequestParam('MSG_ID')) { |
|
735 | + return self::resend_message(); |
|
736 | + } |
|
737 | + |
|
738 | + // make sure any incoming request data is set on the request so that it gets picked up later. |
|
739 | + foreach ((array) $req_data as $request_key => $request_value) { |
|
740 | + if (! $request->requestParamIsSet($request_key)) { |
|
741 | + $request->setRequestParam($request_key, $request_value); |
|
742 | + } |
|
743 | + } |
|
744 | + |
|
745 | + if ( |
|
746 | + ! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request() |
|
747 | + ) { |
|
748 | + return false; |
|
749 | + } |
|
750 | + |
|
751 | + try { |
|
752 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
753 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
754 | + } catch (EE_Error $e) { |
|
755 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
756 | + return false; |
|
757 | + } |
|
758 | + EE_Error::add_success( |
|
759 | + esc_html__('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
760 | + ); |
|
761 | + return true; // everything got queued. |
|
762 | + } |
|
763 | + |
|
764 | + |
|
765 | + /** |
|
766 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
767 | + * |
|
768 | + * @return bool |
|
769 | + * @throws EE_Error |
|
770 | + * @throws InvalidArgumentException |
|
771 | + * @throws InvalidDataTypeException |
|
772 | + * @throws InvalidInterfaceException |
|
773 | + * @throws ReflectionException |
|
774 | + */ |
|
775 | + public static function resend_message() |
|
776 | + { |
|
777 | + self::_load_controller(); |
|
778 | + |
|
779 | + $msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int'); |
|
780 | + if (! $msgID) { |
|
781 | + EE_Error::add_error( |
|
782 | + esc_html__( |
|
783 | + 'Something went wrong because there is no "MSG_ID" value in the request', |
|
784 | + 'event_espresso' |
|
785 | + ), |
|
786 | + __FILE__, |
|
787 | + __FUNCTION__, |
|
788 | + __LINE__ |
|
789 | + ); |
|
790 | + return false; |
|
791 | + } |
|
792 | + |
|
793 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID); |
|
794 | + |
|
795 | + // setup success message. |
|
796 | + $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
797 | + EE_Error::add_success( |
|
798 | + sprintf( |
|
799 | + _n( |
|
800 | + 'There was %d message queued for resending.', |
|
801 | + 'There were %d messages queued for resending.', |
|
802 | + $count_ready_for_resend, |
|
803 | + 'event_espresso' |
|
804 | + ), |
|
805 | + $count_ready_for_resend |
|
806 | + ) |
|
807 | + ); |
|
808 | + return true; |
|
809 | + } |
|
810 | + |
|
811 | + |
|
812 | + /** |
|
813 | + * Message triggers for manual payment applied by admin |
|
814 | + * |
|
815 | + * @param EE_Payment $payment EE_payment object |
|
816 | + * @return bool success/fail |
|
817 | + * @throws EE_Error |
|
818 | + * @throws InvalidArgumentException |
|
819 | + * @throws ReflectionException |
|
820 | + * @throws InvalidDataTypeException |
|
821 | + * @throws InvalidInterfaceException |
|
822 | + */ |
|
823 | + public static function process_admin_payment(EE_Payment $payment) |
|
824 | + { |
|
825 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
826 | + // we need to get the transaction object |
|
827 | + $transaction = $payment->transaction(); |
|
828 | + if ($transaction instanceof EE_Transaction) { |
|
829 | + $data = array($transaction, $payment); |
|
830 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
831 | + |
|
832 | + // if payment amount is less than 0 then switch to payment_refund message type. |
|
833 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
834 | + |
|
835 | + // if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
836 | + $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved |
|
837 | + ? false : $message_type; |
|
838 | + |
|
839 | + self::_load_controller(); |
|
840 | + |
|
841 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
842 | + |
|
843 | + // get count of queued for generation |
|
844 | + $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
845 | + array( |
|
846 | + EEM_Message::status_incomplete, |
|
847 | + EEM_Message::status_idle, |
|
848 | + ) |
|
849 | + ); |
|
850 | + |
|
851 | + if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
852 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
853 | + return true; |
|
854 | + } else { |
|
855 | + $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
856 | + EEM_Message::instance()->stati_indicating_failed_sending() |
|
857 | + ); |
|
858 | + /** |
|
859 | + * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
860 | + * IMMEDIATE generation. |
|
861 | + */ |
|
862 | + if ($count_failed > 0) { |
|
863 | + EE_Error::add_error( |
|
864 | + sprintf( |
|
865 | + _n( |
|
866 | + 'The payment notification generation failed.', |
|
867 | + '%d payment notifications failed being sent.', |
|
868 | + $count_failed, |
|
869 | + 'event_espresso' |
|
870 | + ), |
|
871 | + $count_failed |
|
872 | + ), |
|
873 | + __FILE__, |
|
874 | + __FUNCTION__, |
|
875 | + __LINE__ |
|
876 | + ); |
|
877 | + |
|
878 | + return false; |
|
879 | + } else { |
|
880 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
881 | + return true; |
|
882 | + } |
|
883 | + } |
|
884 | + } else { |
|
885 | + EE_Error::add_error( |
|
886 | + 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
887 | + 'event_espresso' |
|
888 | + ); |
|
889 | + return false; |
|
890 | + } |
|
891 | + } |
|
892 | + |
|
893 | + |
|
894 | + /** |
|
895 | + * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
896 | + * |
|
897 | + * @since 4.3.0 |
|
898 | + * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
899 | + * @param int $grp_id a specific message template group id. |
|
900 | + * @return void |
|
901 | + * @throws EE_Error |
|
902 | + * @throws InvalidArgumentException |
|
903 | + * @throws InvalidDataTypeException |
|
904 | + * @throws InvalidInterfaceException |
|
905 | + * @throws ReflectionException |
|
906 | + */ |
|
907 | + public static function send_newsletter_message($registrations, $grp_id) |
|
908 | + { |
|
909 | + // make sure mtp is id and set it in the request later messages setup. |
|
910 | + self::getRequest()->setRequestParam('GRP_ID', (int) $grp_id); |
|
911 | + self::_load_controller(); |
|
912 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
913 | + } |
|
914 | + |
|
915 | + |
|
916 | + /** |
|
917 | + * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
918 | + * |
|
919 | + * @since 4.3.0 |
|
920 | + * @param string $registration_message_trigger_url |
|
921 | + * @param EE_Registration $registration |
|
922 | + * @param string $messenger |
|
923 | + * @param string $message_type |
|
924 | + * @return string |
|
925 | + * @throws EE_Error |
|
926 | + * @throws InvalidArgumentException |
|
927 | + * @throws InvalidDataTypeException |
|
928 | + * @throws InvalidInterfaceException |
|
929 | + */ |
|
930 | + public static function registration_message_trigger_url( |
|
931 | + $registration_message_trigger_url, |
|
932 | + EE_Registration $registration, |
|
933 | + $messenger = 'html', |
|
934 | + $message_type = 'invoice' |
|
935 | + ) { |
|
936 | + // whitelist $messenger |
|
937 | + switch ($messenger) { |
|
938 | + case 'pdf': |
|
939 | + $sending_messenger = 'pdf'; |
|
940 | + $generating_messenger = 'html'; |
|
941 | + break; |
|
942 | + case 'html': |
|
943 | + default: |
|
944 | + $sending_messenger = 'html'; |
|
945 | + $generating_messenger = 'html'; |
|
946 | + break; |
|
947 | + } |
|
948 | + // whitelist $message_type |
|
949 | + switch ($message_type) { |
|
950 | + case 'receipt': |
|
951 | + $message_type = 'receipt'; |
|
952 | + break; |
|
953 | + case 'invoice': |
|
954 | + default: |
|
955 | + $message_type = 'invoice'; |
|
956 | + break; |
|
957 | + } |
|
958 | + // verify that both the messenger AND the message type are active |
|
959 | + if ( |
|
960 | + EEH_MSG_Template::is_messenger_active($sending_messenger) |
|
961 | + && EEH_MSG_Template::is_mt_active($message_type) |
|
962 | + ) { |
|
963 | + // need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
964 | + $template_query_params = array( |
|
965 | + 'MTP_is_active' => true, |
|
966 | + 'MTP_messenger' => $generating_messenger, |
|
967 | + 'MTP_message_type' => $message_type, |
|
968 | + 'Event.EVT_ID' => $registration->event_ID(), |
|
969 | + ); |
|
970 | + // get the message template group. |
|
971 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
972 | + // if we don't have an EE_Message_Template_Group then return |
|
973 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
974 | + // remove EVT_ID from query params so that global templates get picked up |
|
975 | + unset($template_query_params['Event.EVT_ID']); |
|
976 | + // get global template as the fallback |
|
977 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
978 | + } |
|
979 | + // if we don't have an EE_Message_Template_Group then return |
|
980 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
981 | + return ''; |
|
982 | + } |
|
983 | + // generate the URL |
|
984 | + $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
985 | + $sending_messenger, |
|
986 | + $generating_messenger, |
|
987 | + 'purchaser', |
|
988 | + $message_type, |
|
989 | + $registration, |
|
990 | + $msg_template_group->ID(), |
|
991 | + $registration->transaction_ID() |
|
992 | + ); |
|
993 | + } |
|
994 | + return $registration_message_trigger_url; |
|
995 | + } |
|
996 | + |
|
997 | + |
|
998 | + /** |
|
999 | + * Use to generate and return a message preview! |
|
1000 | + * |
|
1001 | + * @param string $type This should correspond with a valid message type |
|
1002 | + * @param string $context This should correspond with a valid context for the message type |
|
1003 | + * @param string $messenger This should correspond with a valid messenger. |
|
1004 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
1005 | + * preview |
|
1006 | + * @return bool|string The body of the message or if send is requested, sends. |
|
1007 | + * @throws EE_Error |
|
1008 | + * @throws InvalidArgumentException |
|
1009 | + * @throws InvalidDataTypeException |
|
1010 | + * @throws InvalidInterfaceException |
|
1011 | + * @throws ReflectionException |
|
1012 | + */ |
|
1013 | + public static function preview_message($type, $context, $messenger, $send = false) |
|
1014 | + { |
|
1015 | + self::_load_controller(); |
|
1016 | + $mtg = new EE_Message_To_Generate( |
|
1017 | + $messenger, |
|
1018 | + $type, |
|
1019 | + array(), |
|
1020 | + $context, |
|
1021 | + true |
|
1022 | + ); |
|
1023 | + $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
1024 | + if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
1025 | + // loop through all content for the preview and remove any persisted records. |
|
1026 | + $content = ''; |
|
1027 | + foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
1028 | + $content = $message->content(); |
|
1029 | + if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
1030 | + $message->delete(); |
|
1031 | + } |
|
1032 | + } |
|
1033 | + return $content; |
|
1034 | + } else { |
|
1035 | + return $generated_preview_queue; |
|
1036 | + } |
|
1037 | + } |
|
1038 | + |
|
1039 | + |
|
1040 | + /** |
|
1041 | + * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
1042 | + * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
1043 | + * content found in the EE_Message objects in the queue. |
|
1044 | + * |
|
1045 | + * @since 4.9.0 |
|
1046 | + * @param string $messenger a string matching a valid active messenger in the system |
|
1047 | + * @param string $message_type Although it seems contrary to the name of the method, a message |
|
1048 | + * type name is still required to send along the message type to the |
|
1049 | + * messenger because this is used for determining what specific |
|
1050 | + * variations might be loaded for the generated message. |
|
1051 | + * @param EE_Messages_Queue $queue |
|
1052 | + * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
1053 | + * aggregate EE_Message object. |
|
1054 | + * @return bool success or fail. |
|
1055 | + * @throws EE_Error |
|
1056 | + * @throws InvalidArgumentException |
|
1057 | + * @throws ReflectionException |
|
1058 | + * @throws InvalidDataTypeException |
|
1059 | + * @throws InvalidInterfaceException |
|
1060 | + */ |
|
1061 | + public static function send_message_with_messenger_only( |
|
1062 | + $messenger, |
|
1063 | + $message_type, |
|
1064 | + EE_Messages_Queue $queue, |
|
1065 | + $custom_subject = '' |
|
1066 | + ) { |
|
1067 | + self::_load_controller(); |
|
1068 | + /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
1069 | + $message_to_generate = EE_Registry::instance()->load_lib( |
|
1070 | + 'Message_To_Generate_From_Queue', |
|
1071 | + array( |
|
1072 | + $messenger, |
|
1073 | + $message_type, |
|
1074 | + $queue, |
|
1075 | + $custom_subject, |
|
1076 | + ) |
|
1077 | + ); |
|
1078 | + return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
1079 | + } |
|
1080 | + |
|
1081 | + |
|
1082 | + /** |
|
1083 | + * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
1084 | + * |
|
1085 | + * @since 4.9.0 |
|
1086 | + * @param array $message_ids An array of message ids |
|
1087 | + * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
1088 | + * messages. |
|
1089 | + * @throws EE_Error |
|
1090 | + * @throws InvalidArgumentException |
|
1091 | + * @throws InvalidDataTypeException |
|
1092 | + * @throws InvalidInterfaceException |
|
1093 | + * @throws ReflectionException |
|
1094 | + */ |
|
1095 | + public static function generate_now($message_ids) |
|
1096 | + { |
|
1097 | + self::_load_controller(); |
|
1098 | + $messages = EEM_Message::instance()->get_all( |
|
1099 | + array( |
|
1100 | + 0 => array( |
|
1101 | + 'MSG_ID' => array('IN', $message_ids), |
|
1102 | + 'STS_ID' => EEM_Message::status_incomplete, |
|
1103 | + ), |
|
1104 | + ) |
|
1105 | + ); |
|
1106 | + $generated_queue = false; |
|
1107 | + if ($messages) { |
|
1108 | + $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
1109 | + } |
|
1110 | + |
|
1111 | + if (! $generated_queue instanceof EE_Messages_Queue) { |
|
1112 | + EE_Error::add_error( |
|
1113 | + esc_html__( |
|
1114 | + 'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
1115 | + 'event_espresso' |
|
1116 | + ), |
|
1117 | + __FILE__, |
|
1118 | + __FUNCTION__, |
|
1119 | + __LINE__ |
|
1120 | + ); |
|
1121 | + } |
|
1122 | + return $generated_queue; |
|
1123 | + } |
|
1124 | + |
|
1125 | + |
|
1126 | + /** |
|
1127 | + * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
1128 | + * EEM_Message::status_idle |
|
1129 | + * |
|
1130 | + * @since 4.9.0 |
|
1131 | + * @param $message_ids |
|
1132 | + * @return bool|EE_Messages_Queue false if no messages sent. |
|
1133 | + * @throws EE_Error |
|
1134 | + * @throws InvalidArgumentException |
|
1135 | + * @throws InvalidDataTypeException |
|
1136 | + * @throws InvalidInterfaceException |
|
1137 | + * @throws ReflectionException |
|
1138 | + */ |
|
1139 | + public static function send_now($message_ids) |
|
1140 | + { |
|
1141 | + self::_load_controller(); |
|
1142 | + $messages = EEM_Message::instance()->get_all( |
|
1143 | + array( |
|
1144 | + 0 => array( |
|
1145 | + 'MSG_ID' => array('IN', $message_ids), |
|
1146 | + 'STS_ID' => array( |
|
1147 | + 'IN', |
|
1148 | + array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
1149 | + ), |
|
1150 | + ), |
|
1151 | + ) |
|
1152 | + ); |
|
1153 | + $sent_queue = false; |
|
1154 | + if ($messages) { |
|
1155 | + $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
1156 | + } |
|
1157 | + |
|
1158 | + if (! $sent_queue instanceof EE_Messages_Queue) { |
|
1159 | + EE_Error::add_error( |
|
1160 | + esc_html__( |
|
1161 | + 'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
1162 | + 'event_espresso' |
|
1163 | + ), |
|
1164 | + __FILE__, |
|
1165 | + __FUNCTION__, |
|
1166 | + __LINE__ |
|
1167 | + ); |
|
1168 | + } else { |
|
1169 | + // can count how many sent by using the messages in the queue |
|
1170 | + $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
1171 | + if ($sent_count > 0) { |
|
1172 | + EE_Error::add_success( |
|
1173 | + sprintf( |
|
1174 | + _n( |
|
1175 | + 'There was %d message successfully sent.', |
|
1176 | + 'There were %d messages successfully sent.', |
|
1177 | + $sent_count, |
|
1178 | + 'event_espresso' |
|
1179 | + ), |
|
1180 | + $sent_count |
|
1181 | + ) |
|
1182 | + ); |
|
1183 | + } else { |
|
1184 | + EE_Error::overwrite_errors(); |
|
1185 | + EE_Error::add_error( |
|
1186 | + esc_html__( |
|
1187 | + 'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
1188 | 1188 | If there was an error, you can look at the messages in the message activity list table for any error messages.', |
1189 | - 'event_espresso' |
|
1190 | - ), |
|
1191 | - __FILE__, |
|
1192 | - __FUNCTION__, |
|
1193 | - __LINE__ |
|
1194 | - ); |
|
1195 | - } |
|
1196 | - } |
|
1197 | - return $sent_queue; |
|
1198 | - } |
|
1199 | - |
|
1200 | - |
|
1201 | - /** |
|
1202 | - * Generate and send immediately from the given $message_ids |
|
1203 | - * |
|
1204 | - * @param array $message_ids EE_Message entity ids. |
|
1205 | - * @throws EE_Error |
|
1206 | - * @throws InvalidArgumentException |
|
1207 | - * @throws InvalidDataTypeException |
|
1208 | - * @throws InvalidInterfaceException |
|
1209 | - * @throws ReflectionException |
|
1210 | - */ |
|
1211 | - public static function generate_and_send_now(array $message_ids) |
|
1212 | - { |
|
1213 | - $generated_queue = self::generate_now($message_ids); |
|
1214 | - // now let's just trigger sending immediately from this queue. |
|
1215 | - $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
1216 | - ? $generated_queue->execute() |
|
1217 | - : 0; |
|
1218 | - if ($messages_sent) { |
|
1219 | - EE_Error::add_success( |
|
1220 | - esc_html( |
|
1221 | - sprintf( |
|
1222 | - _n( |
|
1223 | - 'There was %d message successfully generated and sent.', |
|
1224 | - 'There were %d messages successfully generated and sent.', |
|
1225 | - $messages_sent, |
|
1226 | - 'event_espresso' |
|
1227 | - ), |
|
1228 | - $messages_sent |
|
1229 | - ) |
|
1230 | - ) |
|
1231 | - ); |
|
1232 | - // errors would be added via the generate_now method. |
|
1233 | - } |
|
1234 | - } |
|
1235 | - |
|
1236 | - |
|
1237 | - /** |
|
1238 | - * This will queue the incoming message ids for resending. |
|
1239 | - * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
1240 | - * |
|
1241 | - * @since 4.9.0 |
|
1242 | - * @param array $message_ids An array of EE_Message IDs |
|
1243 | - * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
1244 | - * resending. |
|
1245 | - * @throws EE_Error |
|
1246 | - * @throws InvalidArgumentException |
|
1247 | - * @throws InvalidDataTypeException |
|
1248 | - * @throws InvalidInterfaceException |
|
1249 | - * @throws ReflectionException |
|
1250 | - */ |
|
1251 | - public static function queue_for_resending($message_ids) |
|
1252 | - { |
|
1253 | - self::_load_controller(); |
|
1254 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
1255 | - |
|
1256 | - // get queue and count |
|
1257 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
1258 | - |
|
1259 | - if ( |
|
1260 | - $queue_count > 0 |
|
1261 | - ) { |
|
1262 | - EE_Error::add_success( |
|
1263 | - sprintf( |
|
1264 | - _n( |
|
1265 | - '%d message successfully queued for resending.', |
|
1266 | - '%d messages successfully queued for resending.', |
|
1267 | - $queue_count, |
|
1268 | - 'event_espresso' |
|
1269 | - ), |
|
1270 | - $queue_count |
|
1271 | - ) |
|
1272 | - ); |
|
1273 | - /** |
|
1274 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
1275 | - */ |
|
1276 | - } elseif ( |
|
1277 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
1278 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
1279 | - ) { |
|
1280 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
1281 | - if ($queue_count > 0) { |
|
1282 | - EE_Error::add_success( |
|
1283 | - sprintf( |
|
1284 | - _n( |
|
1285 | - '%d message successfully sent.', |
|
1286 | - '%d messages successfully sent.', |
|
1287 | - $queue_count, |
|
1288 | - 'event_espresso' |
|
1289 | - ), |
|
1290 | - $queue_count |
|
1291 | - ) |
|
1292 | - ); |
|
1293 | - } else { |
|
1294 | - EE_Error::add_error( |
|
1295 | - esc_html__( |
|
1296 | - 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1297 | - 'event_espresso' |
|
1298 | - ), |
|
1299 | - __FILE__, |
|
1300 | - __FUNCTION__, |
|
1301 | - __LINE__ |
|
1302 | - ); |
|
1303 | - } |
|
1304 | - } else { |
|
1305 | - EE_Error::add_error( |
|
1306 | - esc_html__( |
|
1307 | - 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1308 | - 'event_espresso' |
|
1309 | - ), |
|
1310 | - __FILE__, |
|
1311 | - __FUNCTION__, |
|
1312 | - __LINE__ |
|
1313 | - ); |
|
1314 | - } |
|
1315 | - return (bool) $queue_count; |
|
1316 | - } |
|
1317 | - |
|
1318 | - |
|
1319 | - /** |
|
1320 | - * debug |
|
1321 | - * |
|
1322 | - * @param string $class |
|
1323 | - * @param string $func |
|
1324 | - * @param string $line |
|
1325 | - * @param \EE_Transaction $transaction |
|
1326 | - * @param array $info |
|
1327 | - * @param bool $display_request |
|
1328 | - * @throws EE_Error |
|
1329 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
1330 | - */ |
|
1331 | - protected static function log( |
|
1332 | - $class = '', |
|
1333 | - $func = '', |
|
1334 | - $line = '', |
|
1335 | - EE_Transaction $transaction, |
|
1336 | - $info = array(), |
|
1337 | - $display_request = false |
|
1338 | - ) { |
|
1339 | - if (defined('EE_DEBUG') && EE_DEBUG) { |
|
1340 | - if ($transaction instanceof EE_Transaction) { |
|
1341 | - // don't serialize objects |
|
1342 | - $info = EEH_Debug_Tools::strip_objects($info); |
|
1343 | - $info['TXN_status'] = $transaction->status_ID(); |
|
1344 | - $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
1345 | - if ($transaction->ID()) { |
|
1346 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1347 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
1348 | - } |
|
1349 | - } |
|
1350 | - } |
|
1351 | - } |
|
1352 | - |
|
1353 | - |
|
1354 | - /** |
|
1355 | - * Resets all the static properties in this class when called. |
|
1356 | - */ |
|
1357 | - public static function reset() |
|
1358 | - { |
|
1359 | - self::$_EEMSG = null; |
|
1360 | - self::$_message_resource_manager = null; |
|
1361 | - self::$_MSG_PROCESSOR = null; |
|
1362 | - self::$_MSG_PATHS = null; |
|
1363 | - self::$_TMP_PACKS = array(); |
|
1364 | - } |
|
1189 | + 'event_espresso' |
|
1190 | + ), |
|
1191 | + __FILE__, |
|
1192 | + __FUNCTION__, |
|
1193 | + __LINE__ |
|
1194 | + ); |
|
1195 | + } |
|
1196 | + } |
|
1197 | + return $sent_queue; |
|
1198 | + } |
|
1199 | + |
|
1200 | + |
|
1201 | + /** |
|
1202 | + * Generate and send immediately from the given $message_ids |
|
1203 | + * |
|
1204 | + * @param array $message_ids EE_Message entity ids. |
|
1205 | + * @throws EE_Error |
|
1206 | + * @throws InvalidArgumentException |
|
1207 | + * @throws InvalidDataTypeException |
|
1208 | + * @throws InvalidInterfaceException |
|
1209 | + * @throws ReflectionException |
|
1210 | + */ |
|
1211 | + public static function generate_and_send_now(array $message_ids) |
|
1212 | + { |
|
1213 | + $generated_queue = self::generate_now($message_ids); |
|
1214 | + // now let's just trigger sending immediately from this queue. |
|
1215 | + $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
1216 | + ? $generated_queue->execute() |
|
1217 | + : 0; |
|
1218 | + if ($messages_sent) { |
|
1219 | + EE_Error::add_success( |
|
1220 | + esc_html( |
|
1221 | + sprintf( |
|
1222 | + _n( |
|
1223 | + 'There was %d message successfully generated and sent.', |
|
1224 | + 'There were %d messages successfully generated and sent.', |
|
1225 | + $messages_sent, |
|
1226 | + 'event_espresso' |
|
1227 | + ), |
|
1228 | + $messages_sent |
|
1229 | + ) |
|
1230 | + ) |
|
1231 | + ); |
|
1232 | + // errors would be added via the generate_now method. |
|
1233 | + } |
|
1234 | + } |
|
1235 | + |
|
1236 | + |
|
1237 | + /** |
|
1238 | + * This will queue the incoming message ids for resending. |
|
1239 | + * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
1240 | + * |
|
1241 | + * @since 4.9.0 |
|
1242 | + * @param array $message_ids An array of EE_Message IDs |
|
1243 | + * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
1244 | + * resending. |
|
1245 | + * @throws EE_Error |
|
1246 | + * @throws InvalidArgumentException |
|
1247 | + * @throws InvalidDataTypeException |
|
1248 | + * @throws InvalidInterfaceException |
|
1249 | + * @throws ReflectionException |
|
1250 | + */ |
|
1251 | + public static function queue_for_resending($message_ids) |
|
1252 | + { |
|
1253 | + self::_load_controller(); |
|
1254 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
1255 | + |
|
1256 | + // get queue and count |
|
1257 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
1258 | + |
|
1259 | + if ( |
|
1260 | + $queue_count > 0 |
|
1261 | + ) { |
|
1262 | + EE_Error::add_success( |
|
1263 | + sprintf( |
|
1264 | + _n( |
|
1265 | + '%d message successfully queued for resending.', |
|
1266 | + '%d messages successfully queued for resending.', |
|
1267 | + $queue_count, |
|
1268 | + 'event_espresso' |
|
1269 | + ), |
|
1270 | + $queue_count |
|
1271 | + ) |
|
1272 | + ); |
|
1273 | + /** |
|
1274 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
1275 | + */ |
|
1276 | + } elseif ( |
|
1277 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
1278 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
1279 | + ) { |
|
1280 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
1281 | + if ($queue_count > 0) { |
|
1282 | + EE_Error::add_success( |
|
1283 | + sprintf( |
|
1284 | + _n( |
|
1285 | + '%d message successfully sent.', |
|
1286 | + '%d messages successfully sent.', |
|
1287 | + $queue_count, |
|
1288 | + 'event_espresso' |
|
1289 | + ), |
|
1290 | + $queue_count |
|
1291 | + ) |
|
1292 | + ); |
|
1293 | + } else { |
|
1294 | + EE_Error::add_error( |
|
1295 | + esc_html__( |
|
1296 | + 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1297 | + 'event_espresso' |
|
1298 | + ), |
|
1299 | + __FILE__, |
|
1300 | + __FUNCTION__, |
|
1301 | + __LINE__ |
|
1302 | + ); |
|
1303 | + } |
|
1304 | + } else { |
|
1305 | + EE_Error::add_error( |
|
1306 | + esc_html__( |
|
1307 | + 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
1308 | + 'event_espresso' |
|
1309 | + ), |
|
1310 | + __FILE__, |
|
1311 | + __FUNCTION__, |
|
1312 | + __LINE__ |
|
1313 | + ); |
|
1314 | + } |
|
1315 | + return (bool) $queue_count; |
|
1316 | + } |
|
1317 | + |
|
1318 | + |
|
1319 | + /** |
|
1320 | + * debug |
|
1321 | + * |
|
1322 | + * @param string $class |
|
1323 | + * @param string $func |
|
1324 | + * @param string $line |
|
1325 | + * @param \EE_Transaction $transaction |
|
1326 | + * @param array $info |
|
1327 | + * @param bool $display_request |
|
1328 | + * @throws EE_Error |
|
1329 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
1330 | + */ |
|
1331 | + protected static function log( |
|
1332 | + $class = '', |
|
1333 | + $func = '', |
|
1334 | + $line = '', |
|
1335 | + EE_Transaction $transaction, |
|
1336 | + $info = array(), |
|
1337 | + $display_request = false |
|
1338 | + ) { |
|
1339 | + if (defined('EE_DEBUG') && EE_DEBUG) { |
|
1340 | + if ($transaction instanceof EE_Transaction) { |
|
1341 | + // don't serialize objects |
|
1342 | + $info = EEH_Debug_Tools::strip_objects($info); |
|
1343 | + $info['TXN_status'] = $transaction->status_ID(); |
|
1344 | + $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
1345 | + if ($transaction->ID()) { |
|
1346 | + $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1347 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
1348 | + } |
|
1349 | + } |
|
1350 | + } |
|
1351 | + } |
|
1352 | + |
|
1353 | + |
|
1354 | + /** |
|
1355 | + * Resets all the static properties in this class when called. |
|
1356 | + */ |
|
1357 | + public static function reset() |
|
1358 | + { |
|
1359 | + self::$_EEMSG = null; |
|
1360 | + self::$_message_resource_manager = null; |
|
1361 | + self::$_MSG_PROCESSOR = null; |
|
1362 | + self::$_MSG_PATHS = null; |
|
1363 | + self::$_TMP_PACKS = array(); |
|
1364 | + } |
|
1365 | 1365 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | 'event_espresso' |
205 | 205 | ); |
206 | 206 | // add specific message for developers if WP_DEBUG in on |
207 | - $error_msg .= '||' . $e->getMessage(); |
|
207 | + $error_msg .= '||'.$e->getMessage(); |
|
208 | 208 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
209 | 209 | } |
210 | 210 | } |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | 'event_espresso' |
291 | 291 | ); |
292 | 292 | // add specific message for developers if WP_DEBUG in on |
293 | - $error_msg .= '||' . $e->getMessage(); |
|
293 | + $error_msg .= '||'.$e->getMessage(); |
|
294 | 294 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
295 | 295 | } |
296 | 296 | } |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | $transient_key = $request->getRequestParam('key'); |
323 | 323 | |
324 | 324 | // now let's verify transient, if not valid exit immediately |
325 | - if (! get_transient($transient_key)) { |
|
325 | + if ( ! get_transient($transient_key)) { |
|
326 | 326 | /** |
327 | 327 | * trigger error so this gets in the error logs. This is important because it happens on a non-user |
328 | 328 | * request. |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | delete_transient($transient_key); |
335 | 335 | |
336 | 336 | if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
337 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
337 | + $method = 'batch_'.$cron_type.'_from_queue'; |
|
338 | 338 | if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
339 | 339 | self::$_MSG_PROCESSOR->$method(); |
340 | 340 | } else { |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | $template_pack_collection->rewind(); |
402 | 402 | $template_packs = array(); |
403 | 403 | while ($template_pack_collection->valid()) { |
404 | - $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current(); |
|
404 | + $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
405 | 405 | $template_pack_collection->next(); |
406 | 406 | } |
407 | 407 | return $template_packs; |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | ); |
452 | 452 | $paths = array(); |
453 | 453 | foreach ($dir_ref as $index => $dir) { |
454 | - $paths[ $index ] = EE_LIBRARIES . $dir; |
|
454 | + $paths[$index] = EE_LIBRARIES.$dir; |
|
455 | 455 | } |
456 | 456 | self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
457 | 457 | } |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | */ |
471 | 471 | protected static function _load_controller() |
472 | 472 | { |
473 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
473 | + if ( ! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
474 | 474 | EE_Registry::instance()->load_core('Request_Handler'); |
475 | 475 | self::set_autoloaders(); |
476 | 476 | self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
512 | 512 | { |
513 | 513 | // if there's no payment object, then we cannot do a payment type message! |
514 | - if (! $payment instanceof EE_Payment) { |
|
514 | + if ( ! $payment instanceof EE_Payment) { |
|
515 | 515 | return; |
516 | 516 | } |
517 | 517 | self::_load_controller(); |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
559 | 559 | { |
560 | 560 | |
561 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
561 | + if ( ! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
562 | 562 | // no messages please |
563 | 563 | return; |
564 | 564 | } |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | EE_Registration $registration, |
626 | 626 | $extra_details = array() |
627 | 627 | ) { |
628 | - if (! $registration->is_primary_registrant()) { |
|
628 | + if ( ! $registration->is_primary_registrant()) { |
|
629 | 629 | return false; |
630 | 630 | } |
631 | 631 | $request = self::getRequest(); |
@@ -646,7 +646,7 @@ discard block |
||
646 | 646 | } else { |
647 | 647 | // frontend request (either regular or via AJAX) |
648 | 648 | // TXN is NOT finalized ? |
649 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
649 | + if ( ! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
650 | 650 | return false; |
651 | 651 | } |
652 | 652 | // return visit but nothing changed ??? |
@@ -737,7 +737,7 @@ discard block |
||
737 | 737 | |
738 | 738 | // make sure any incoming request data is set on the request so that it gets picked up later. |
739 | 739 | foreach ((array) $req_data as $request_key => $request_value) { |
740 | - if (! $request->requestParamIsSet($request_key)) { |
|
740 | + if ( ! $request->requestParamIsSet($request_key)) { |
|
741 | 741 | $request->setRequestParam($request_key, $request_value); |
742 | 742 | } |
743 | 743 | } |
@@ -777,7 +777,7 @@ discard block |
||
777 | 777 | self::_load_controller(); |
778 | 778 | |
779 | 779 | $msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int'); |
780 | - if (! $msgID) { |
|
780 | + if ( ! $msgID) { |
|
781 | 781 | EE_Error::add_error( |
782 | 782 | esc_html__( |
783 | 783 | 'Something went wrong because there is no "MSG_ID" value in the request', |
@@ -970,14 +970,14 @@ discard block |
||
970 | 970 | // get the message template group. |
971 | 971 | $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
972 | 972 | // if we don't have an EE_Message_Template_Group then return |
973 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
973 | + if ( ! $msg_template_group instanceof EE_Message_Template_Group) { |
|
974 | 974 | // remove EVT_ID from query params so that global templates get picked up |
975 | 975 | unset($template_query_params['Event.EVT_ID']); |
976 | 976 | // get global template as the fallback |
977 | 977 | $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
978 | 978 | } |
979 | 979 | // if we don't have an EE_Message_Template_Group then return |
980 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
980 | + if ( ! $msg_template_group instanceof EE_Message_Template_Group) { |
|
981 | 981 | return ''; |
982 | 982 | } |
983 | 983 | // generate the URL |
@@ -1108,7 +1108,7 @@ discard block |
||
1108 | 1108 | $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
1109 | 1109 | } |
1110 | 1110 | |
1111 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
1111 | + if ( ! $generated_queue instanceof EE_Messages_Queue) { |
|
1112 | 1112 | EE_Error::add_error( |
1113 | 1113 | esc_html__( |
1114 | 1114 | 'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
@@ -1155,7 +1155,7 @@ discard block |
||
1155 | 1155 | $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
1156 | 1156 | } |
1157 | 1157 | |
1158 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
1158 | + if ( ! $sent_queue instanceof EE_Messages_Queue) { |
|
1159 | 1159 | EE_Error::add_error( |
1160 | 1160 | esc_html__( |
1161 | 1161 | 'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
@@ -1343,7 +1343,7 @@ discard block |
||
1343 | 1343 | $info['TXN_status'] = $transaction->status_ID(); |
1344 | 1344 | $info['TXN_reg_steps'] = $transaction->reg_steps(); |
1345 | 1345 | if ($transaction->ID()) { |
1346 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
1346 | + $index = 'EE_Transaction: '.$transaction->ID(); |
|
1347 | 1347 | EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
1348 | 1348 | } |
1349 | 1349 | } |