@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | * there's a single shared message template group among all the events. Otherwise it returns null. |
444 | 444 | * |
445 | 445 | * @param array $event_ids |
446 | - * @return EE_Message_Template_Group|null |
|
446 | + * @return null|EE_Base_Class |
|
447 | 447 | * @throws EE_Error |
448 | 448 | */ |
449 | 449 | protected function _get_shared_message_template_for_events(array $event_ids) |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | /** |
477 | 477 | * Retrieves the global message template group for the current messenger and message type. |
478 | 478 | * |
479 | - * @return EE_Message_Template_Group|null |
|
479 | + * @return null|EE_Base_Class |
|
480 | 480 | * @throws EE_Error |
481 | 481 | */ |
482 | 482 | protected function _get_global_message_template_group_for_current_messenger_and_message_type() |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | * @param EE_Messages_Addressee $recipient |
618 | 618 | * @param array $templates formatted array of templates used for parsing data. |
619 | 619 | * @param EE_Message_Template_Group $message_template_group |
620 | - * @return bool|EE_Message |
|
620 | + * @return EE_Message |
|
621 | 621 | * @throws EE_Error |
622 | 622 | */ |
623 | 623 | protected function _setup_message_object( |
@@ -13,935 +13,935 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * @type EE_Messages_Data_Handler_Collection |
|
18 | - */ |
|
19 | - protected $_data_handler_collection; |
|
20 | - |
|
21 | - /** |
|
22 | - * @type EE_Message_Template_Group_Collection |
|
23 | - */ |
|
24 | - protected $_template_collection; |
|
25 | - |
|
26 | - /** |
|
27 | - * This will hold the data handler for the current EE_Message being generated. |
|
28 | - * |
|
29 | - * @type EE_Messages_incoming_data |
|
30 | - */ |
|
31 | - protected $_current_data_handler; |
|
32 | - |
|
33 | - /** |
|
34 | - * This holds the EE_Messages_Queue that contains the messages to generate. |
|
35 | - * |
|
36 | - * @type EE_Messages_Queue |
|
37 | - */ |
|
38 | - protected $_generation_queue; |
|
39 | - |
|
40 | - /** |
|
41 | - * This holds the EE_Messages_Queue that will store the generated EE_Message objects. |
|
42 | - * |
|
43 | - * @type EE_Messages_Queue |
|
44 | - */ |
|
45 | - protected $_ready_queue; |
|
46 | - |
|
47 | - /** |
|
48 | - * This is a container for any error messages that get created through the generation |
|
49 | - * process. |
|
50 | - * |
|
51 | - * @type array |
|
52 | - */ |
|
53 | - protected $_error_msg = array(); |
|
54 | - |
|
55 | - /** |
|
56 | - * Flag used to set when the current EE_Message in the generation queue has been verified. |
|
57 | - * |
|
58 | - * @type bool |
|
59 | - */ |
|
60 | - protected $_verified = false; |
|
61 | - |
|
62 | - /** |
|
63 | - * This will hold the current messenger object corresponding with the current EE_Message in the generation queue. |
|
64 | - * |
|
65 | - * @type EE_messenger |
|
66 | - */ |
|
67 | - protected $_current_messenger; |
|
68 | - |
|
69 | - /** |
|
70 | - * This will hold the current message type object corresponding with the current EE_Message in the generation queue. |
|
71 | - * |
|
72 | - * @type EE_message_type |
|
73 | - */ |
|
74 | - protected $_current_message_type; |
|
75 | - |
|
76 | - /** |
|
77 | - * @type EEH_Parse_Shortcodes |
|
78 | - */ |
|
79 | - protected $_shortcode_parser; |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @param EE_Messages_Queue $generation_queue |
|
84 | - * @param \EE_Messages_Queue $ready_queue |
|
85 | - * @param \EE_Messages_Data_Handler_Collection $data_handler_collection |
|
86 | - * @param \EE_Message_Template_Group_Collection $template_collection |
|
87 | - * @param \EEH_Parse_Shortcodes $shortcode_parser |
|
88 | - */ |
|
89 | - public function __construct( |
|
90 | - EE_Messages_Queue $generation_queue, |
|
91 | - EE_Messages_Queue $ready_queue, |
|
92 | - EE_Messages_Data_Handler_Collection $data_handler_collection, |
|
93 | - EE_Message_Template_Group_Collection $template_collection, |
|
94 | - EEH_Parse_Shortcodes $shortcode_parser |
|
95 | - ) { |
|
96 | - $this->_generation_queue = $generation_queue; |
|
97 | - $this->_ready_queue = $ready_queue; |
|
98 | - $this->_data_handler_collection = $data_handler_collection; |
|
99 | - $this->_template_collection = $template_collection; |
|
100 | - $this->_shortcode_parser = $shortcode_parser; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @return EE_Messages_Queue |
|
106 | - */ |
|
107 | - public function generation_queue() |
|
108 | - { |
|
109 | - return $this->_generation_queue; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * This iterates through the provided queue and generates the EE_Message objects. |
|
115 | - * When iterating through the queue, the queued item that served as the base for generating other EE_Message |
|
116 | - * objects gets removed and the new EE_Message objects get added to a NEW queue. The NEW queue is then returned |
|
117 | - * for the caller to decide what to do with it. |
|
118 | - * |
|
119 | - * @param bool $save Whether to save the EE_Message objects in the new queue or just return. |
|
120 | - * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. |
|
121 | - */ |
|
122 | - public function generate($save = true) |
|
123 | - { |
|
124 | - //iterate through the messages in the queue, generate, and add to new queue. |
|
125 | - $this->_generation_queue->get_message_repository()->rewind(); |
|
126 | - while ($this->_generation_queue->get_message_repository()->valid()) { |
|
127 | - //reset "current" properties |
|
128 | - $this->_reset_current_properties(); |
|
129 | - |
|
130 | - /** @type EE_Message $msg */ |
|
131 | - $msg = $this->_generation_queue->get_message_repository()->current(); |
|
132 | - |
|
133 | - /** |
|
134 | - * need to get the next object and capture it for setting manually after deletes. The reason is that when |
|
135 | - * an object is removed from the repo then valid for the next object will fail. |
|
136 | - */ |
|
137 | - $this->_generation_queue->get_message_repository()->next(); |
|
138 | - $next_msg = $this->_generation_queue->get_message_repository()->current(); |
|
139 | - //restore pointer to current item |
|
140 | - $this->_generation_queue->get_message_repository()->set_current($msg); |
|
141 | - |
|
142 | - //skip and delete if the current $msg is NOT incomplete (queued for generation) |
|
143 | - if ($msg->STS_ID() !== EEM_Message::status_incomplete) { |
|
144 | - //we keep this item in the db just remove from the repo. |
|
145 | - $this->_generation_queue->get_message_repository()->remove($msg); |
|
146 | - //next item |
|
147 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
148 | - continue; |
|
149 | - } |
|
150 | - |
|
151 | - if ($this->_verify()) { |
|
152 | - //let's get generating! |
|
153 | - $this->_generate(); |
|
154 | - } |
|
155 | - |
|
156 | - //don't persist debug_only messages if the messages system is not in debug mode. |
|
157 | - if ($msg->STS_ID() === EEM_Message::status_debug_only |
|
158 | - && ! EEM_Message::debug() |
|
159 | - ) { |
|
160 | - do_action( |
|
161 | - 'AHEE__EE_Messages_Generator__generate__before_debug_delete', |
|
162 | - $msg, |
|
163 | - $this->_error_msg, |
|
164 | - $this->_current_messenger, |
|
165 | - $this->_current_message_type, |
|
166 | - $this->_current_data_handler |
|
167 | - ); |
|
168 | - $this->_generation_queue->get_message_repository()->delete(); |
|
169 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
170 | - continue; |
|
171 | - } |
|
172 | - |
|
173 | - //if there are error messages then let's set the status and the error message. |
|
174 | - if ($this->_error_msg) { |
|
175 | - //if the status is already debug only, then let's leave it at that. |
|
176 | - if ($msg->STS_ID() !== EEM_Message::status_debug_only) { |
|
177 | - $msg->set_STS_ID(EEM_Message::status_failed); |
|
178 | - } |
|
179 | - do_action( |
|
180 | - 'AHEE__EE_Messages_Generator__generate__processing_failed_message', |
|
181 | - $msg, |
|
182 | - $this->_error_msg, |
|
183 | - $this->_current_messenger, |
|
184 | - $this->_current_message_type, |
|
185 | - $this->_current_data_handler |
|
186 | - ); |
|
187 | - $msg->set_error_message( |
|
188 | - esc_html__('Message failed to generate for the following reasons: ', 'event_espresso') |
|
189 | - . "\n" |
|
190 | - . implode("\n", $this->_error_msg) |
|
191 | - ); |
|
192 | - $msg->set_modified(time()); |
|
193 | - } else { |
|
194 | - do_action( |
|
195 | - 'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete', |
|
196 | - $msg, |
|
197 | - $this->_error_msg, |
|
198 | - $this->_current_messenger, |
|
199 | - $this->_current_message_type, |
|
200 | - $this->_current_data_handler |
|
201 | - ); |
|
202 | - //remove from db |
|
203 | - $this->_generation_queue->get_message_repository()->delete(); |
|
204 | - } |
|
205 | - //next item |
|
206 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
207 | - } |
|
208 | - |
|
209 | - //generation queue is ALWAYS saved to record any errors in the generation process. |
|
210 | - $this->_generation_queue->save(); |
|
211 | - |
|
212 | - /** |
|
213 | - * save _ready_queue if flag set. |
|
214 | - * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method. This |
|
215 | - * means if a field was added that is not a valid database column. The EE_Message was already saved to the db |
|
216 | - * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is |
|
217 | - * irrelevant. |
|
218 | - */ |
|
219 | - if ($save) { |
|
220 | - $this->_ready_queue->save(); |
|
221 | - } |
|
222 | - |
|
223 | - //final reset of properties |
|
224 | - $this->_reset_current_properties(); |
|
225 | - |
|
226 | - return $this->_ready_queue; |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * This resets all the properties used for holding "current" values corresponding to the current EE_Message object |
|
232 | - * in the generation queue. |
|
233 | - */ |
|
234 | - protected function _reset_current_properties() |
|
235 | - { |
|
236 | - $this->_verified = false; |
|
237 | - //make sure any _data value in the current message type is reset |
|
238 | - if ($this->_current_message_type instanceof EE_message_type) { |
|
239 | - $this->_current_message_type->reset_data(); |
|
240 | - } |
|
241 | - $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null; |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * This proceeds with the actual generation of a message. By the time this is called, there should already be a |
|
247 | - * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the |
|
248 | - * _generating_queue. |
|
249 | - * |
|
250 | - * @return bool Whether the message was successfully generated or not. |
|
251 | - * @throws EE_Error |
|
252 | - */ |
|
253 | - protected function _generate() |
|
254 | - { |
|
255 | - //double check verification has run and that everything is ready to work with (saves us having to validate |
|
256 | - // everything again). |
|
257 | - if (! $this->_verified) { |
|
258 | - return false; //get out because we don't have a valid setup to work with. |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - try { |
|
263 | - $addressees = $this->_current_message_type->get_addressees( |
|
264 | - $this->_current_data_handler, |
|
265 | - $this->_generation_queue->get_message_repository()->current()->context() |
|
266 | - ); |
|
267 | - } catch (EE_Error $e) { |
|
268 | - $this->_error_msg[] = $e->getMessage(); |
|
269 | - return false; |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - //if no addressees then get out because there is nothing to generation (possible bad data). |
|
274 | - if (! $this->_valid_addressees($addressees)) { |
|
275 | - do_action( |
|
276 | - 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
|
277 | - $this->_generation_queue->get_message_repository()->current(), |
|
278 | - $addressees, |
|
279 | - $this->_current_messenger, |
|
280 | - $this->_current_message_type, |
|
281 | - $this->_current_data_handler |
|
282 | - ); |
|
283 | - $this->_generation_queue->get_message_repository()->current()->set_STS_ID( |
|
284 | - EEM_Message::status_debug_only |
|
285 | - ); |
|
286 | - $this->_error_msg[] = esc_html__( |
|
287 | - 'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.', |
|
288 | - 'event_espresso' |
|
289 | - ); |
|
290 | - return false; |
|
291 | - } |
|
292 | - |
|
293 | - $message_template_group = $this->_get_message_template_group(); |
|
294 | - |
|
295 | - //in the unlikely event there is no EE_Message_Template_Group available, get out! |
|
296 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
297 | - $this->_error_msg[] = esc_html__( |
|
298 | - 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
|
299 | - 'event_espresso' |
|
300 | - ); |
|
301 | - return false; |
|
302 | - } |
|
303 | - |
|
304 | - //get formatted templates for using to parse and setup EE_Message objects. |
|
305 | - $templates = $this->_get_templates($message_template_group); |
|
306 | - |
|
307 | - |
|
308 | - //setup new EE_Message objects (and add to _ready_queue) |
|
309 | - return $this->_assemble_messages($addressees, $templates, $message_template_group); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * Retrieves the message template group being used for generating messages. |
|
315 | - * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times. |
|
316 | - * |
|
317 | - * @return EE_Message_Template_Group|null |
|
318 | - * @throws EE_Error |
|
319 | - */ |
|
320 | - protected function _get_message_template_group() |
|
321 | - { |
|
322 | - //first see if there is a specific message template group requested (current message in the queue has a specific |
|
323 | - //GRP_ID |
|
324 | - $message_template_group = $this->_specific_message_template_group_from_queue(); |
|
325 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
326 | - return $message_template_group; |
|
327 | - } |
|
328 | - |
|
329 | - //get event_ids from the datahandler so we can check to see if there's already a message template group for them |
|
330 | - //in the collection. |
|
331 | - $event_ids = $this->_get_event_ids_from_current_data_handler(); |
|
332 | - $message_template_group = $this->_template_collection->get_by_key( |
|
333 | - $this->_template_collection->getKey( |
|
334 | - $this->_current_messenger->name, |
|
335 | - $this->_current_message_type->name, |
|
336 | - $event_ids |
|
337 | - ) |
|
338 | - ); |
|
339 | - |
|
340 | - //if we have a message template group then no need to hit the database, just return it. |
|
341 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
342 | - return $message_template_group; |
|
343 | - } |
|
344 | - |
|
345 | - //okay made it here, so let's get the global group first for this messenger and message type to ensure |
|
346 | - //there is no override set. |
|
347 | - $global_message_template_group = $this->_get_global_message_template_group_for_current_messenger_and_message_type(); |
|
348 | - |
|
349 | - if ($global_message_template_group instanceof EE_Message_Template_Group |
|
350 | - && $global_message_template_group->get('MTP_is_override') |
|
351 | - ) { |
|
352 | - return $global_message_template_group; |
|
353 | - } |
|
354 | - |
|
355 | - //if we're still here, that means there was no message template group for the events in the collection and |
|
356 | - //the global message template group for the messenger and message type is not set for override. So next step is |
|
357 | - //to see if there is a common shared custom message template group for this set of events. |
|
358 | - $message_template_group = $this->_get_shared_message_template_for_events($event_ids); |
|
359 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
360 | - return $message_template_group; |
|
361 | - } |
|
362 | - |
|
363 | - //STILL here? Okay that means the fallback is to just use the global message template group for this event set. |
|
364 | - //So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request) |
|
365 | - //and return it. |
|
366 | - if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
367 | - $this->_template_collection->add( |
|
368 | - $global_message_template_group, |
|
369 | - $event_ids |
|
370 | - ); |
|
371 | - return $global_message_template_group; |
|
372 | - } |
|
373 | - |
|
374 | - //if we land here that means there's NO active message template group for this set. |
|
375 | - //TODO this will be a good target for some optimization down the road. Whenever there is no active message |
|
376 | - //template group for a given event set then cache that result so we don't repeat the logic. However, for now, |
|
377 | - //this should likely bit hit rarely enough that it's not a significant issue. |
|
378 | - return null; |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * This checks the current message in the queue and determines if there is a specific Message Template Group |
|
384 | - * requested for that message. |
|
385 | - * |
|
386 | - * @return EE_Message_Template_Group|null |
|
387 | - */ |
|
388 | - protected function _specific_message_template_group_from_queue() |
|
389 | - { |
|
390 | - //is there a GRP_ID already on the EE_Message object? If there is, then a specific template has been requested |
|
391 | - //so let's use that. |
|
392 | - $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID(); |
|
393 | - |
|
394 | - if ($GRP_ID) { |
|
395 | - //attempt to retrieve from repo first |
|
396 | - $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
|
397 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
398 | - return $message_template_group; //got it! |
|
399 | - } |
|
400 | - |
|
401 | - //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
|
402 | - //is not valid, so we'll continue on in the code assuming there's NO GRP_ID. |
|
403 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
404 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
405 | - $this->_template_collection->add($message_template_group); |
|
406 | - return $message_template_group; |
|
407 | - } |
|
408 | - } |
|
409 | - return null; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * Returns whether the event ids passed in all share the same message template group for the current message type |
|
415 | - * and messenger. |
|
416 | - * |
|
417 | - * @param array $event_ids |
|
418 | - * @return bool true means they DO share the same message template group, false means they don't. |
|
419 | - * @throws EE_Error |
|
420 | - */ |
|
421 | - protected function _queue_shares_same_message_template_group_for_events(array $event_ids) |
|
422 | - { |
|
423 | - foreach ($this->_current_data_handler->events as $event) { |
|
424 | - $event_ids[$event['ID']] = $event['ID']; |
|
425 | - } |
|
426 | - $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count( |
|
427 | - array( |
|
428 | - array( |
|
429 | - 'Event.EVT_ID' => array('IN', $event_ids), |
|
430 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
431 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
432 | - ), |
|
433 | - ), |
|
434 | - 'GRP_ID', |
|
435 | - true |
|
436 | - ); |
|
437 | - return $count_of_message_template_groups === 1; |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - /** |
|
442 | - * This will get the shared message template group for events that are in the current data handler but ONLY if |
|
443 | - * there's a single shared message template group among all the events. Otherwise it returns null. |
|
444 | - * |
|
445 | - * @param array $event_ids |
|
446 | - * @return EE_Message_Template_Group|null |
|
447 | - * @throws EE_Error |
|
448 | - */ |
|
449 | - protected function _get_shared_message_template_for_events(array $event_ids) |
|
450 | - { |
|
451 | - $message_template_group = null; |
|
452 | - if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) { |
|
453 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
454 | - array( |
|
455 | - array( |
|
456 | - 'Event.EVT_ID' => array('IN', $event_ids), |
|
457 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
458 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
459 | - 'MTP_is_active' => true, |
|
460 | - ), |
|
461 | - 'group_by' => 'GRP_ID', |
|
462 | - ) |
|
463 | - ); |
|
464 | - //store this in the collection if its valid |
|
465 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
466 | - $this->_template_collection->add( |
|
467 | - $message_template_group, |
|
468 | - $event_ids |
|
469 | - ); |
|
470 | - } |
|
471 | - } |
|
472 | - return $message_template_group; |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * Retrieves the global message template group for the current messenger and message type. |
|
478 | - * |
|
479 | - * @return EE_Message_Template_Group|null |
|
480 | - * @throws EE_Error |
|
481 | - */ |
|
482 | - protected function _get_global_message_template_group_for_current_messenger_and_message_type() |
|
483 | - { |
|
484 | - //first check the collection (we use an array with 0 in it to represent global groups). |
|
485 | - $global_message_template_group = $this->_template_collection->get_by_key( |
|
486 | - $this->_template_collection->getKey( |
|
487 | - $this->_current_messenger->name, |
|
488 | - $this->_current_message_type->name, |
|
489 | - array(0) |
|
490 | - ) |
|
491 | - ); |
|
492 | - |
|
493 | - //if we don't have a group lets hit the db. |
|
494 | - if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
495 | - $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
496 | - array( |
|
497 | - array( |
|
498 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
499 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
500 | - 'MTP_is_active' => true, |
|
501 | - 'MTP_is_global' => true, |
|
502 | - ), |
|
503 | - ) |
|
504 | - ); |
|
505 | - //if we have a group, add it to the collection. |
|
506 | - if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
507 | - $this->_template_collection->add( |
|
508 | - $global_message_template_group, |
|
509 | - array(0) |
|
510 | - ); |
|
511 | - } |
|
512 | - } |
|
513 | - return $global_message_template_group; |
|
514 | - } |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * Returns an array of event ids for all the events within the current data handler. |
|
519 | - * |
|
520 | - * @return array |
|
521 | - */ |
|
522 | - protected function _get_event_ids_from_current_data_handler() |
|
523 | - { |
|
524 | - $event_ids = array(); |
|
525 | - foreach ($this->_current_data_handler->events as $event) { |
|
526 | - $event_ids[$event['ID']] = $event['ID']; |
|
527 | - } |
|
528 | - return $event_ids; |
|
529 | - } |
|
530 | - |
|
531 | - |
|
532 | - /** |
|
533 | - * Retrieves formatted array of template information for each context specific to the given |
|
534 | - * EE_Message_Template_Group |
|
535 | - * |
|
536 | - * @param EE_Message_Template_Group $message_template_group |
|
537 | - * @return array The returned array is in this structure: |
|
538 | - * array( |
|
539 | - * 'field_name' => array( |
|
540 | - * 'context' => 'content' |
|
541 | - * ) |
|
542 | - * ) |
|
543 | - * @throws EE_Error |
|
544 | - */ |
|
545 | - protected function _get_templates(EE_Message_Template_Group $message_template_group) |
|
546 | - { |
|
547 | - $templates = array(); |
|
548 | - $context_templates = $message_template_group->context_templates(); |
|
549 | - foreach ($context_templates as $context => $template_fields) { |
|
550 | - foreach ($template_fields as $template_field => $template_obj) { |
|
551 | - if (! $template_obj instanceof EE_Message_Template) { |
|
552 | - continue; |
|
553 | - } |
|
554 | - $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
|
555 | - } |
|
556 | - } |
|
557 | - return $templates; |
|
558 | - } |
|
559 | - |
|
560 | - |
|
561 | - /** |
|
562 | - * Assembles new fully generated EE_Message objects and adds to _ready_queue |
|
563 | - * |
|
564 | - * @param array $addressees Array of EE_Messages_Addressee objects indexed by message type |
|
565 | - * context. |
|
566 | - * @param array $templates formatted array of templates used for parsing data. |
|
567 | - * @param EE_Message_Template_Group $message_template_group |
|
568 | - * @return bool true if message generation went a-ok. false if some sort of exception occurred. Note: The |
|
569 | - * method will attempt to generate ALL EE_Message objects and add to |
|
570 | - * the _ready_queue. Successfully generated messages get added to the |
|
571 | - * queue with EEM_Message::status_idle, unsuccessfully generated |
|
572 | - * messages will get added to the queue as EEM_Message::status_failed. |
|
573 | - * Very rarely should "false" be returned from this method. |
|
574 | - */ |
|
575 | - protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group) |
|
576 | - { |
|
577 | - |
|
578 | - //if templates are empty then get out because we can't generate anything. |
|
579 | - if (! $templates) { |
|
580 | - $this->_error_msg[] = esc_html__( |
|
581 | - 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
|
582 | - 'event_espresso' |
|
583 | - ); |
|
584 | - return false; |
|
585 | - } |
|
586 | - |
|
587 | - //We use this as the counter for generated messages because don't forget we may be executing this inside of a |
|
588 | - //generation_queue. So _ready_queue may have generated EE_Message objects already. |
|
589 | - $generated_count = 0; |
|
590 | - foreach ($addressees as $context => $recipients) { |
|
591 | - foreach ($recipients as $recipient) { |
|
592 | - $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group); |
|
593 | - if ($message instanceof EE_Message) { |
|
594 | - $this->_ready_queue->add( |
|
595 | - $message, |
|
596 | - array(), |
|
597 | - $this->_generation_queue->get_message_repository()->is_preview(), |
|
598 | - $this->_generation_queue->get_message_repository()->is_test_send() |
|
599 | - ); |
|
600 | - $generated_count++; |
|
601 | - } |
|
602 | - |
|
603 | - //if the current MSG being generated is for a test send then we'll only use ONE message in the generation. |
|
604 | - if ($this->_generation_queue->get_message_repository()->is_test_send()) { |
|
605 | - break 2; |
|
606 | - } |
|
607 | - } |
|
608 | - } |
|
609 | - |
|
610 | - //if there are no generated messages then something else fatal went wrong. |
|
611 | - return $generated_count > 0; |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - /** |
|
616 | - * @param string $context The context for the generated message. |
|
617 | - * @param EE_Messages_Addressee $recipient |
|
618 | - * @param array $templates formatted array of templates used for parsing data. |
|
619 | - * @param EE_Message_Template_Group $message_template_group |
|
620 | - * @return bool|EE_Message |
|
621 | - * @throws EE_Error |
|
622 | - */ |
|
623 | - protected function _setup_message_object( |
|
624 | - $context, |
|
625 | - EE_Messages_Addressee $recipient, |
|
626 | - $templates, |
|
627 | - EE_Message_Template_Group $message_template_group |
|
628 | - ) { |
|
629 | - //stuff we already know |
|
630 | - $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0; |
|
631 | - $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
632 | - ? $this->_current_data_handler->txn->ID() |
|
633 | - : $transaction_id; |
|
634 | - $message_fields = array( |
|
635 | - 'GRP_ID' => $message_template_group->ID(), |
|
636 | - 'TXN_ID' => $transaction_id, |
|
637 | - 'MSG_messenger' => $this->_current_messenger->name, |
|
638 | - 'MSG_message_type' => $this->_current_message_type->name, |
|
639 | - 'MSG_context' => $context, |
|
640 | - ); |
|
641 | - |
|
642 | - //recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab |
|
643 | - // the info from the att_obj found in the EE_Messages_Addressee object. |
|
644 | - if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) { |
|
645 | - $message_fields['MSG_recipient_ID'] = $recipient->att_obj instanceof EE_Attendee |
|
646 | - ? $recipient->att_obj->ID() |
|
647 | - : 0; |
|
648 | - $message_fields['MSG_recipient_type'] = 'Attendee'; |
|
649 | - } else { |
|
650 | - $message_fields['MSG_recipient_ID'] = $recipient->recipient_id; |
|
651 | - $message_fields['MSG_recipient_type'] = $recipient->recipient_type; |
|
652 | - } |
|
653 | - $message = EE_Message_Factory::create($message_fields); |
|
654 | - |
|
655 | - //grab valid shortcodes for shortcode parser |
|
656 | - $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes(); |
|
657 | - $m_shortcodes = $this->_current_messenger->get_valid_shortcodes(); |
|
658 | - |
|
659 | - //if the 'to' field is empty (messages will ALWAYS have a "to" field, then we get out because that means this |
|
660 | - //context is turned off) EXCEPT if we're previewing |
|
661 | - if (empty($templates['to'][$context]) |
|
662 | - && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
663 | - && ! $this->_current_messenger->allow_empty_to_field() |
|
664 | - ) { |
|
665 | - //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" |
|
666 | - //field. |
|
667 | - return false; |
|
668 | - } |
|
669 | - $error_msg = array(); |
|
670 | - foreach ($templates as $field => $field_context) { |
|
671 | - $error_msg = array(); |
|
672 | - //let's setup the valid shortcodes for the incoming context. |
|
673 | - $valid_shortcodes = $mt_shortcodes[$context]; |
|
674 | - //merge in valid shortcodes for the field. |
|
675 | - $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
|
676 | - if (isset($templates[$field][$context])) { |
|
677 | - //prefix field. |
|
678 | - $column_name = 'MSG_' . $field; |
|
679 | - try { |
|
680 | - $content = $this->_shortcode_parser->parse_message_template( |
|
681 | - $templates[$field][$context], |
|
682 | - $recipient, |
|
683 | - $shortcodes, |
|
684 | - $this->_current_message_type, |
|
685 | - $this->_current_messenger, |
|
686 | - $message |
|
687 | - ); |
|
688 | - $message->set_field_or_extra_meta($column_name, $content); |
|
689 | - } catch (EE_Error $e) { |
|
690 | - $error_msg[] = sprintf( |
|
691 | - esc_html__( |
|
692 | - 'There was a problem generating the content for the field %s: %s', |
|
693 | - 'event_espresso' |
|
694 | - ), |
|
695 | - $field, |
|
696 | - $e->getMessage() |
|
697 | - ); |
|
698 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
699 | - } |
|
700 | - } |
|
701 | - } |
|
702 | - |
|
703 | - if ($message->STS_ID() === EEM_Message::status_failed) { |
|
704 | - $error_msg = esc_html__('There were problems generating this message:', 'event_espresso') |
|
705 | - . "\n" |
|
706 | - . implode("\n", $error_msg); |
|
707 | - $message->set_error_message($error_msg); |
|
708 | - } else { |
|
709 | - $message->set_STS_ID(EEM_Message::status_idle); |
|
710 | - } |
|
711 | - return $message; |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - /** |
|
716 | - * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate |
|
717 | - * error message if either is missing. |
|
718 | - * |
|
719 | - * @return bool true means there were no errors, false means there were errors. |
|
720 | - */ |
|
721 | - protected function _verify() |
|
722 | - { |
|
723 | - //reset error message to an empty array. |
|
724 | - $this->_error_msg = array(); |
|
725 | - $valid = true; |
|
726 | - $valid = $valid ? $this->_validate_messenger_and_message_type() : $valid; |
|
727 | - $valid = $valid ? $this->_validate_and_setup_data() : $valid; |
|
728 | - |
|
729 | - //set the verified flag so we know everything has been validated. |
|
730 | - $this->_verified = $valid; |
|
731 | - |
|
732 | - return $valid; |
|
733 | - } |
|
734 | - |
|
735 | - |
|
736 | - /** |
|
737 | - * This accepts an array and validates that it is an array indexed by context with each value being an array of |
|
738 | - * EE_Messages_Addressee objects. |
|
739 | - * |
|
740 | - * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[] |
|
741 | - * @return bool |
|
742 | - */ |
|
743 | - protected function _valid_addressees($addressees) |
|
744 | - { |
|
745 | - if (! $addressees || ! is_array($addressees)) { |
|
746 | - return false; |
|
747 | - } |
|
748 | - |
|
749 | - foreach ($addressees as $addressee_array) { |
|
750 | - foreach ($addressee_array as $addressee) { |
|
751 | - if (! $addressee instanceof EE_Messages_Addressee) { |
|
752 | - return false; |
|
753 | - } |
|
754 | - } |
|
755 | - } |
|
756 | - return true; |
|
757 | - } |
|
758 | - |
|
759 | - |
|
760 | - /** |
|
761 | - * This validates the messenger, message type, and presences of generation data for the current EE_Message in the |
|
762 | - * queue. This process sets error messages if something is wrong. |
|
763 | - * |
|
764 | - * @return bool true is if there are no errors. false is if there is. |
|
765 | - */ |
|
766 | - protected function _validate_messenger_and_message_type() |
|
767 | - { |
|
768 | - |
|
769 | - //first are there any existing error messages? If so then return. |
|
770 | - if ($this->_error_msg) { |
|
771 | - return false; |
|
772 | - } |
|
773 | - /** @type EE_Message $message */ |
|
774 | - $message = $this->_generation_queue->get_message_repository()->current(); |
|
775 | - try { |
|
776 | - $this->_current_messenger = $message->valid_messenger(true) |
|
777 | - ? $message->messenger_object() |
|
778 | - : null; |
|
779 | - } catch (Exception $e) { |
|
780 | - $this->_error_msg[] = $e->getMessage(); |
|
781 | - } |
|
782 | - try { |
|
783 | - $this->_current_message_type = $message->valid_message_type(true) |
|
784 | - ? $message->message_type_object() |
|
785 | - : null; |
|
786 | - } catch (Exception $e) { |
|
787 | - $this->_error_msg[] = $e->getMessage(); |
|
788 | - } |
|
789 | - |
|
790 | - /** |
|
791 | - * Check if there is any generation data, but only if this is not for a preview. |
|
792 | - */ |
|
793 | - if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
794 | - && ( |
|
795 | - ! $this->_generation_queue->get_message_repository()->is_preview() |
|
796 | - && $this->_generation_queue->get_message_repository()->get_data_handler() |
|
797 | - !== 'EE_Messages_Preview_incoming_data' |
|
798 | - ) |
|
799 | - ) { |
|
800 | - $this->_error_msg[] = esc_html__( |
|
801 | - 'There is no generation data for this message. Unable to generate.', |
|
802 | - 'event_espresso' |
|
803 | - ); |
|
804 | - } |
|
805 | - |
|
806 | - return empty($this->_error_msg); |
|
807 | - } |
|
808 | - |
|
809 | - |
|
810 | - /** |
|
811 | - * This method retrieves the expected data handler for the message type and validates the generation data for that |
|
812 | - * data handler. |
|
813 | - * |
|
814 | - * @return bool true means there are no errors. false means there were errors (and handler did not get setup). |
|
815 | - */ |
|
816 | - protected function _validate_and_setup_data() |
|
817 | - { |
|
818 | - |
|
819 | - //First, are there any existing error messages? If so, return because if there were errors elsewhere this can't |
|
820 | - //be used anyways. |
|
821 | - if ($this->_error_msg) { |
|
822 | - return false; |
|
823 | - } |
|
824 | - |
|
825 | - $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data(); |
|
826 | - |
|
827 | - /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually */ |
|
828 | - $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
|
829 | - ? $this->_generation_queue->get_message_repository()->get_data_handler() |
|
830 | - : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
831 | - |
|
832 | - //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
|
833 | - if ($this->_generation_queue->get_message_repository()->is_preview()) { |
|
834 | - $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
835 | - } |
|
836 | - |
|
837 | - //First get the class name for the data handler (and also verifies it exists. |
|
838 | - if (! class_exists($data_handler_class_name)) { |
|
839 | - $this->_error_msg[] = sprintf( |
|
840 | - esc_html__( |
|
841 | - 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
|
842 | - 'event_espresso' |
|
843 | - ), |
|
844 | - 'EE_Messages_incoming_data', |
|
845 | - $data_handler_class_name |
|
846 | - ); |
|
847 | - return false; |
|
848 | - } |
|
849 | - |
|
850 | - //convert generation_data for data_handler_instantiation. |
|
851 | - $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data); |
|
852 | - |
|
853 | - //note, this may set error messages as well. |
|
854 | - $this->_set_data_handler($generation_data, $data_handler_class_name); |
|
855 | - |
|
856 | - return empty($this->_error_msg); |
|
857 | - } |
|
858 | - |
|
859 | - |
|
860 | - /** |
|
861 | - * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and |
|
862 | - * adds it to the _data repository. |
|
863 | - * |
|
864 | - * @param mixed $generating_data This is data expected by the instantiated data handler. |
|
865 | - * @param string $data_handler_class_name This is the reference string indicating what data handler is being |
|
866 | - * instantiated. |
|
867 | - * @return void . |
|
868 | - * @throws EE_Error |
|
869 | - * @throws ReflectionException |
|
870 | - */ |
|
871 | - protected function _set_data_handler($generating_data, $data_handler_class_name) |
|
872 | - { |
|
873 | - //valid classname for the data handler. Now let's setup the key for the data handler repository to see if there |
|
874 | - //is already a ready data handler in the repository. |
|
875 | - $this->_current_data_handler = $this->_data_handler_collection->get_by_key( |
|
876 | - $this->_data_handler_collection->get_key( |
|
877 | - $data_handler_class_name, |
|
878 | - $generating_data |
|
879 | - ) |
|
880 | - ); |
|
881 | - if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
882 | - //no saved data_handler in the repo so let's set one up and add it to the repo. |
|
883 | - try { |
|
884 | - $this->_current_data_handler = new $data_handler_class_name($generating_data); |
|
885 | - $this->_data_handler_collection->add($this->_current_data_handler, $generating_data); |
|
886 | - } catch (EE_Error $e) { |
|
887 | - $this->_error_msg[] = $e->get_error(); |
|
888 | - } |
|
889 | - } |
|
890 | - } |
|
891 | - |
|
892 | - |
|
893 | - /** |
|
894 | - * The queued EE_Message for generation does not save the data used for generation as objects |
|
895 | - * because serialization of those objects could be problematic if the data is saved to the db. |
|
896 | - * So this method calls the static method on the associated data_handler for the given message_type |
|
897 | - * and that preps the data for later instantiation when generating. |
|
898 | - * |
|
899 | - * @param EE_Message_To_Generate $message_to_generate |
|
900 | - * @param bool $preview Indicate whether this is being used for a preview or not. |
|
901 | - * @return mixed Prepped data for persisting to the queue. false is returned if unable to prep data. |
|
902 | - */ |
|
903 | - protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview) |
|
904 | - { |
|
905 | - /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
|
906 | - $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
|
907 | - if (! $message_to_generate->valid()) { |
|
908 | - return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
|
909 | - } |
|
910 | - return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
|
911 | - } |
|
912 | - |
|
913 | - |
|
914 | - /** |
|
915 | - * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue. |
|
916 | - * |
|
917 | - * @param EE_Message_To_Generate $message_to_generate |
|
918 | - * @param bool $test_send Whether this is just a test send or not. Typically used for previews. |
|
919 | - */ |
|
920 | - public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
921 | - { |
|
922 | - //prep data |
|
923 | - $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview()); |
|
924 | - |
|
925 | - $message = $message_to_generate->get_EE_Message(); |
|
926 | - |
|
927 | - //is there a GRP_ID in the request? |
|
928 | - if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) { |
|
929 | - $message->set_GRP_ID($GRP_ID); |
|
930 | - } |
|
931 | - |
|
932 | - if ($data === false) { |
|
933 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
934 | - $message->set_error_message( |
|
935 | - esc_html__( |
|
936 | - 'Unable to prepare data for persistence to the database.', |
|
937 | - 'event_espresso' |
|
938 | - ) |
|
939 | - ); |
|
940 | - } else { |
|
941 | - //make sure that the data handler is cached on the message as well |
|
942 | - $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name(); |
|
943 | - } |
|
944 | - |
|
945 | - $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send); |
|
946 | - } |
|
16 | + /** |
|
17 | + * @type EE_Messages_Data_Handler_Collection |
|
18 | + */ |
|
19 | + protected $_data_handler_collection; |
|
20 | + |
|
21 | + /** |
|
22 | + * @type EE_Message_Template_Group_Collection |
|
23 | + */ |
|
24 | + protected $_template_collection; |
|
25 | + |
|
26 | + /** |
|
27 | + * This will hold the data handler for the current EE_Message being generated. |
|
28 | + * |
|
29 | + * @type EE_Messages_incoming_data |
|
30 | + */ |
|
31 | + protected $_current_data_handler; |
|
32 | + |
|
33 | + /** |
|
34 | + * This holds the EE_Messages_Queue that contains the messages to generate. |
|
35 | + * |
|
36 | + * @type EE_Messages_Queue |
|
37 | + */ |
|
38 | + protected $_generation_queue; |
|
39 | + |
|
40 | + /** |
|
41 | + * This holds the EE_Messages_Queue that will store the generated EE_Message objects. |
|
42 | + * |
|
43 | + * @type EE_Messages_Queue |
|
44 | + */ |
|
45 | + protected $_ready_queue; |
|
46 | + |
|
47 | + /** |
|
48 | + * This is a container for any error messages that get created through the generation |
|
49 | + * process. |
|
50 | + * |
|
51 | + * @type array |
|
52 | + */ |
|
53 | + protected $_error_msg = array(); |
|
54 | + |
|
55 | + /** |
|
56 | + * Flag used to set when the current EE_Message in the generation queue has been verified. |
|
57 | + * |
|
58 | + * @type bool |
|
59 | + */ |
|
60 | + protected $_verified = false; |
|
61 | + |
|
62 | + /** |
|
63 | + * This will hold the current messenger object corresponding with the current EE_Message in the generation queue. |
|
64 | + * |
|
65 | + * @type EE_messenger |
|
66 | + */ |
|
67 | + protected $_current_messenger; |
|
68 | + |
|
69 | + /** |
|
70 | + * This will hold the current message type object corresponding with the current EE_Message in the generation queue. |
|
71 | + * |
|
72 | + * @type EE_message_type |
|
73 | + */ |
|
74 | + protected $_current_message_type; |
|
75 | + |
|
76 | + /** |
|
77 | + * @type EEH_Parse_Shortcodes |
|
78 | + */ |
|
79 | + protected $_shortcode_parser; |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @param EE_Messages_Queue $generation_queue |
|
84 | + * @param \EE_Messages_Queue $ready_queue |
|
85 | + * @param \EE_Messages_Data_Handler_Collection $data_handler_collection |
|
86 | + * @param \EE_Message_Template_Group_Collection $template_collection |
|
87 | + * @param \EEH_Parse_Shortcodes $shortcode_parser |
|
88 | + */ |
|
89 | + public function __construct( |
|
90 | + EE_Messages_Queue $generation_queue, |
|
91 | + EE_Messages_Queue $ready_queue, |
|
92 | + EE_Messages_Data_Handler_Collection $data_handler_collection, |
|
93 | + EE_Message_Template_Group_Collection $template_collection, |
|
94 | + EEH_Parse_Shortcodes $shortcode_parser |
|
95 | + ) { |
|
96 | + $this->_generation_queue = $generation_queue; |
|
97 | + $this->_ready_queue = $ready_queue; |
|
98 | + $this->_data_handler_collection = $data_handler_collection; |
|
99 | + $this->_template_collection = $template_collection; |
|
100 | + $this->_shortcode_parser = $shortcode_parser; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @return EE_Messages_Queue |
|
106 | + */ |
|
107 | + public function generation_queue() |
|
108 | + { |
|
109 | + return $this->_generation_queue; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * This iterates through the provided queue and generates the EE_Message objects. |
|
115 | + * When iterating through the queue, the queued item that served as the base for generating other EE_Message |
|
116 | + * objects gets removed and the new EE_Message objects get added to a NEW queue. The NEW queue is then returned |
|
117 | + * for the caller to decide what to do with it. |
|
118 | + * |
|
119 | + * @param bool $save Whether to save the EE_Message objects in the new queue or just return. |
|
120 | + * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. |
|
121 | + */ |
|
122 | + public function generate($save = true) |
|
123 | + { |
|
124 | + //iterate through the messages in the queue, generate, and add to new queue. |
|
125 | + $this->_generation_queue->get_message_repository()->rewind(); |
|
126 | + while ($this->_generation_queue->get_message_repository()->valid()) { |
|
127 | + //reset "current" properties |
|
128 | + $this->_reset_current_properties(); |
|
129 | + |
|
130 | + /** @type EE_Message $msg */ |
|
131 | + $msg = $this->_generation_queue->get_message_repository()->current(); |
|
132 | + |
|
133 | + /** |
|
134 | + * need to get the next object and capture it for setting manually after deletes. The reason is that when |
|
135 | + * an object is removed from the repo then valid for the next object will fail. |
|
136 | + */ |
|
137 | + $this->_generation_queue->get_message_repository()->next(); |
|
138 | + $next_msg = $this->_generation_queue->get_message_repository()->current(); |
|
139 | + //restore pointer to current item |
|
140 | + $this->_generation_queue->get_message_repository()->set_current($msg); |
|
141 | + |
|
142 | + //skip and delete if the current $msg is NOT incomplete (queued for generation) |
|
143 | + if ($msg->STS_ID() !== EEM_Message::status_incomplete) { |
|
144 | + //we keep this item in the db just remove from the repo. |
|
145 | + $this->_generation_queue->get_message_repository()->remove($msg); |
|
146 | + //next item |
|
147 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
148 | + continue; |
|
149 | + } |
|
150 | + |
|
151 | + if ($this->_verify()) { |
|
152 | + //let's get generating! |
|
153 | + $this->_generate(); |
|
154 | + } |
|
155 | + |
|
156 | + //don't persist debug_only messages if the messages system is not in debug mode. |
|
157 | + if ($msg->STS_ID() === EEM_Message::status_debug_only |
|
158 | + && ! EEM_Message::debug() |
|
159 | + ) { |
|
160 | + do_action( |
|
161 | + 'AHEE__EE_Messages_Generator__generate__before_debug_delete', |
|
162 | + $msg, |
|
163 | + $this->_error_msg, |
|
164 | + $this->_current_messenger, |
|
165 | + $this->_current_message_type, |
|
166 | + $this->_current_data_handler |
|
167 | + ); |
|
168 | + $this->_generation_queue->get_message_repository()->delete(); |
|
169 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
170 | + continue; |
|
171 | + } |
|
172 | + |
|
173 | + //if there are error messages then let's set the status and the error message. |
|
174 | + if ($this->_error_msg) { |
|
175 | + //if the status is already debug only, then let's leave it at that. |
|
176 | + if ($msg->STS_ID() !== EEM_Message::status_debug_only) { |
|
177 | + $msg->set_STS_ID(EEM_Message::status_failed); |
|
178 | + } |
|
179 | + do_action( |
|
180 | + 'AHEE__EE_Messages_Generator__generate__processing_failed_message', |
|
181 | + $msg, |
|
182 | + $this->_error_msg, |
|
183 | + $this->_current_messenger, |
|
184 | + $this->_current_message_type, |
|
185 | + $this->_current_data_handler |
|
186 | + ); |
|
187 | + $msg->set_error_message( |
|
188 | + esc_html__('Message failed to generate for the following reasons: ', 'event_espresso') |
|
189 | + . "\n" |
|
190 | + . implode("\n", $this->_error_msg) |
|
191 | + ); |
|
192 | + $msg->set_modified(time()); |
|
193 | + } else { |
|
194 | + do_action( |
|
195 | + 'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete', |
|
196 | + $msg, |
|
197 | + $this->_error_msg, |
|
198 | + $this->_current_messenger, |
|
199 | + $this->_current_message_type, |
|
200 | + $this->_current_data_handler |
|
201 | + ); |
|
202 | + //remove from db |
|
203 | + $this->_generation_queue->get_message_repository()->delete(); |
|
204 | + } |
|
205 | + //next item |
|
206 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
207 | + } |
|
208 | + |
|
209 | + //generation queue is ALWAYS saved to record any errors in the generation process. |
|
210 | + $this->_generation_queue->save(); |
|
211 | + |
|
212 | + /** |
|
213 | + * save _ready_queue if flag set. |
|
214 | + * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method. This |
|
215 | + * means if a field was added that is not a valid database column. The EE_Message was already saved to the db |
|
216 | + * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is |
|
217 | + * irrelevant. |
|
218 | + */ |
|
219 | + if ($save) { |
|
220 | + $this->_ready_queue->save(); |
|
221 | + } |
|
222 | + |
|
223 | + //final reset of properties |
|
224 | + $this->_reset_current_properties(); |
|
225 | + |
|
226 | + return $this->_ready_queue; |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * This resets all the properties used for holding "current" values corresponding to the current EE_Message object |
|
232 | + * in the generation queue. |
|
233 | + */ |
|
234 | + protected function _reset_current_properties() |
|
235 | + { |
|
236 | + $this->_verified = false; |
|
237 | + //make sure any _data value in the current message type is reset |
|
238 | + if ($this->_current_message_type instanceof EE_message_type) { |
|
239 | + $this->_current_message_type->reset_data(); |
|
240 | + } |
|
241 | + $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null; |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * This proceeds with the actual generation of a message. By the time this is called, there should already be a |
|
247 | + * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the |
|
248 | + * _generating_queue. |
|
249 | + * |
|
250 | + * @return bool Whether the message was successfully generated or not. |
|
251 | + * @throws EE_Error |
|
252 | + */ |
|
253 | + protected function _generate() |
|
254 | + { |
|
255 | + //double check verification has run and that everything is ready to work with (saves us having to validate |
|
256 | + // everything again). |
|
257 | + if (! $this->_verified) { |
|
258 | + return false; //get out because we don't have a valid setup to work with. |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + try { |
|
263 | + $addressees = $this->_current_message_type->get_addressees( |
|
264 | + $this->_current_data_handler, |
|
265 | + $this->_generation_queue->get_message_repository()->current()->context() |
|
266 | + ); |
|
267 | + } catch (EE_Error $e) { |
|
268 | + $this->_error_msg[] = $e->getMessage(); |
|
269 | + return false; |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + //if no addressees then get out because there is nothing to generation (possible bad data). |
|
274 | + if (! $this->_valid_addressees($addressees)) { |
|
275 | + do_action( |
|
276 | + 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
|
277 | + $this->_generation_queue->get_message_repository()->current(), |
|
278 | + $addressees, |
|
279 | + $this->_current_messenger, |
|
280 | + $this->_current_message_type, |
|
281 | + $this->_current_data_handler |
|
282 | + ); |
|
283 | + $this->_generation_queue->get_message_repository()->current()->set_STS_ID( |
|
284 | + EEM_Message::status_debug_only |
|
285 | + ); |
|
286 | + $this->_error_msg[] = esc_html__( |
|
287 | + 'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.', |
|
288 | + 'event_espresso' |
|
289 | + ); |
|
290 | + return false; |
|
291 | + } |
|
292 | + |
|
293 | + $message_template_group = $this->_get_message_template_group(); |
|
294 | + |
|
295 | + //in the unlikely event there is no EE_Message_Template_Group available, get out! |
|
296 | + if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
297 | + $this->_error_msg[] = esc_html__( |
|
298 | + 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
|
299 | + 'event_espresso' |
|
300 | + ); |
|
301 | + return false; |
|
302 | + } |
|
303 | + |
|
304 | + //get formatted templates for using to parse and setup EE_Message objects. |
|
305 | + $templates = $this->_get_templates($message_template_group); |
|
306 | + |
|
307 | + |
|
308 | + //setup new EE_Message objects (and add to _ready_queue) |
|
309 | + return $this->_assemble_messages($addressees, $templates, $message_template_group); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * Retrieves the message template group being used for generating messages. |
|
315 | + * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times. |
|
316 | + * |
|
317 | + * @return EE_Message_Template_Group|null |
|
318 | + * @throws EE_Error |
|
319 | + */ |
|
320 | + protected function _get_message_template_group() |
|
321 | + { |
|
322 | + //first see if there is a specific message template group requested (current message in the queue has a specific |
|
323 | + //GRP_ID |
|
324 | + $message_template_group = $this->_specific_message_template_group_from_queue(); |
|
325 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
326 | + return $message_template_group; |
|
327 | + } |
|
328 | + |
|
329 | + //get event_ids from the datahandler so we can check to see if there's already a message template group for them |
|
330 | + //in the collection. |
|
331 | + $event_ids = $this->_get_event_ids_from_current_data_handler(); |
|
332 | + $message_template_group = $this->_template_collection->get_by_key( |
|
333 | + $this->_template_collection->getKey( |
|
334 | + $this->_current_messenger->name, |
|
335 | + $this->_current_message_type->name, |
|
336 | + $event_ids |
|
337 | + ) |
|
338 | + ); |
|
339 | + |
|
340 | + //if we have a message template group then no need to hit the database, just return it. |
|
341 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
342 | + return $message_template_group; |
|
343 | + } |
|
344 | + |
|
345 | + //okay made it here, so let's get the global group first for this messenger and message type to ensure |
|
346 | + //there is no override set. |
|
347 | + $global_message_template_group = $this->_get_global_message_template_group_for_current_messenger_and_message_type(); |
|
348 | + |
|
349 | + if ($global_message_template_group instanceof EE_Message_Template_Group |
|
350 | + && $global_message_template_group->get('MTP_is_override') |
|
351 | + ) { |
|
352 | + return $global_message_template_group; |
|
353 | + } |
|
354 | + |
|
355 | + //if we're still here, that means there was no message template group for the events in the collection and |
|
356 | + //the global message template group for the messenger and message type is not set for override. So next step is |
|
357 | + //to see if there is a common shared custom message template group for this set of events. |
|
358 | + $message_template_group = $this->_get_shared_message_template_for_events($event_ids); |
|
359 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
360 | + return $message_template_group; |
|
361 | + } |
|
362 | + |
|
363 | + //STILL here? Okay that means the fallback is to just use the global message template group for this event set. |
|
364 | + //So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request) |
|
365 | + //and return it. |
|
366 | + if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
367 | + $this->_template_collection->add( |
|
368 | + $global_message_template_group, |
|
369 | + $event_ids |
|
370 | + ); |
|
371 | + return $global_message_template_group; |
|
372 | + } |
|
373 | + |
|
374 | + //if we land here that means there's NO active message template group for this set. |
|
375 | + //TODO this will be a good target for some optimization down the road. Whenever there is no active message |
|
376 | + //template group for a given event set then cache that result so we don't repeat the logic. However, for now, |
|
377 | + //this should likely bit hit rarely enough that it's not a significant issue. |
|
378 | + return null; |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * This checks the current message in the queue and determines if there is a specific Message Template Group |
|
384 | + * requested for that message. |
|
385 | + * |
|
386 | + * @return EE_Message_Template_Group|null |
|
387 | + */ |
|
388 | + protected function _specific_message_template_group_from_queue() |
|
389 | + { |
|
390 | + //is there a GRP_ID already on the EE_Message object? If there is, then a specific template has been requested |
|
391 | + //so let's use that. |
|
392 | + $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID(); |
|
393 | + |
|
394 | + if ($GRP_ID) { |
|
395 | + //attempt to retrieve from repo first |
|
396 | + $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
|
397 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
398 | + return $message_template_group; //got it! |
|
399 | + } |
|
400 | + |
|
401 | + //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
|
402 | + //is not valid, so we'll continue on in the code assuming there's NO GRP_ID. |
|
403 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
404 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
405 | + $this->_template_collection->add($message_template_group); |
|
406 | + return $message_template_group; |
|
407 | + } |
|
408 | + } |
|
409 | + return null; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * Returns whether the event ids passed in all share the same message template group for the current message type |
|
415 | + * and messenger. |
|
416 | + * |
|
417 | + * @param array $event_ids |
|
418 | + * @return bool true means they DO share the same message template group, false means they don't. |
|
419 | + * @throws EE_Error |
|
420 | + */ |
|
421 | + protected function _queue_shares_same_message_template_group_for_events(array $event_ids) |
|
422 | + { |
|
423 | + foreach ($this->_current_data_handler->events as $event) { |
|
424 | + $event_ids[$event['ID']] = $event['ID']; |
|
425 | + } |
|
426 | + $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count( |
|
427 | + array( |
|
428 | + array( |
|
429 | + 'Event.EVT_ID' => array('IN', $event_ids), |
|
430 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
431 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
432 | + ), |
|
433 | + ), |
|
434 | + 'GRP_ID', |
|
435 | + true |
|
436 | + ); |
|
437 | + return $count_of_message_template_groups === 1; |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + /** |
|
442 | + * This will get the shared message template group for events that are in the current data handler but ONLY if |
|
443 | + * there's a single shared message template group among all the events. Otherwise it returns null. |
|
444 | + * |
|
445 | + * @param array $event_ids |
|
446 | + * @return EE_Message_Template_Group|null |
|
447 | + * @throws EE_Error |
|
448 | + */ |
|
449 | + protected function _get_shared_message_template_for_events(array $event_ids) |
|
450 | + { |
|
451 | + $message_template_group = null; |
|
452 | + if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) { |
|
453 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
454 | + array( |
|
455 | + array( |
|
456 | + 'Event.EVT_ID' => array('IN', $event_ids), |
|
457 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
458 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
459 | + 'MTP_is_active' => true, |
|
460 | + ), |
|
461 | + 'group_by' => 'GRP_ID', |
|
462 | + ) |
|
463 | + ); |
|
464 | + //store this in the collection if its valid |
|
465 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
466 | + $this->_template_collection->add( |
|
467 | + $message_template_group, |
|
468 | + $event_ids |
|
469 | + ); |
|
470 | + } |
|
471 | + } |
|
472 | + return $message_template_group; |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * Retrieves the global message template group for the current messenger and message type. |
|
478 | + * |
|
479 | + * @return EE_Message_Template_Group|null |
|
480 | + * @throws EE_Error |
|
481 | + */ |
|
482 | + protected function _get_global_message_template_group_for_current_messenger_and_message_type() |
|
483 | + { |
|
484 | + //first check the collection (we use an array with 0 in it to represent global groups). |
|
485 | + $global_message_template_group = $this->_template_collection->get_by_key( |
|
486 | + $this->_template_collection->getKey( |
|
487 | + $this->_current_messenger->name, |
|
488 | + $this->_current_message_type->name, |
|
489 | + array(0) |
|
490 | + ) |
|
491 | + ); |
|
492 | + |
|
493 | + //if we don't have a group lets hit the db. |
|
494 | + if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
495 | + $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
496 | + array( |
|
497 | + array( |
|
498 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
499 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
500 | + 'MTP_is_active' => true, |
|
501 | + 'MTP_is_global' => true, |
|
502 | + ), |
|
503 | + ) |
|
504 | + ); |
|
505 | + //if we have a group, add it to the collection. |
|
506 | + if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
507 | + $this->_template_collection->add( |
|
508 | + $global_message_template_group, |
|
509 | + array(0) |
|
510 | + ); |
|
511 | + } |
|
512 | + } |
|
513 | + return $global_message_template_group; |
|
514 | + } |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * Returns an array of event ids for all the events within the current data handler. |
|
519 | + * |
|
520 | + * @return array |
|
521 | + */ |
|
522 | + protected function _get_event_ids_from_current_data_handler() |
|
523 | + { |
|
524 | + $event_ids = array(); |
|
525 | + foreach ($this->_current_data_handler->events as $event) { |
|
526 | + $event_ids[$event['ID']] = $event['ID']; |
|
527 | + } |
|
528 | + return $event_ids; |
|
529 | + } |
|
530 | + |
|
531 | + |
|
532 | + /** |
|
533 | + * Retrieves formatted array of template information for each context specific to the given |
|
534 | + * EE_Message_Template_Group |
|
535 | + * |
|
536 | + * @param EE_Message_Template_Group $message_template_group |
|
537 | + * @return array The returned array is in this structure: |
|
538 | + * array( |
|
539 | + * 'field_name' => array( |
|
540 | + * 'context' => 'content' |
|
541 | + * ) |
|
542 | + * ) |
|
543 | + * @throws EE_Error |
|
544 | + */ |
|
545 | + protected function _get_templates(EE_Message_Template_Group $message_template_group) |
|
546 | + { |
|
547 | + $templates = array(); |
|
548 | + $context_templates = $message_template_group->context_templates(); |
|
549 | + foreach ($context_templates as $context => $template_fields) { |
|
550 | + foreach ($template_fields as $template_field => $template_obj) { |
|
551 | + if (! $template_obj instanceof EE_Message_Template) { |
|
552 | + continue; |
|
553 | + } |
|
554 | + $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
|
555 | + } |
|
556 | + } |
|
557 | + return $templates; |
|
558 | + } |
|
559 | + |
|
560 | + |
|
561 | + /** |
|
562 | + * Assembles new fully generated EE_Message objects and adds to _ready_queue |
|
563 | + * |
|
564 | + * @param array $addressees Array of EE_Messages_Addressee objects indexed by message type |
|
565 | + * context. |
|
566 | + * @param array $templates formatted array of templates used for parsing data. |
|
567 | + * @param EE_Message_Template_Group $message_template_group |
|
568 | + * @return bool true if message generation went a-ok. false if some sort of exception occurred. Note: The |
|
569 | + * method will attempt to generate ALL EE_Message objects and add to |
|
570 | + * the _ready_queue. Successfully generated messages get added to the |
|
571 | + * queue with EEM_Message::status_idle, unsuccessfully generated |
|
572 | + * messages will get added to the queue as EEM_Message::status_failed. |
|
573 | + * Very rarely should "false" be returned from this method. |
|
574 | + */ |
|
575 | + protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group) |
|
576 | + { |
|
577 | + |
|
578 | + //if templates are empty then get out because we can't generate anything. |
|
579 | + if (! $templates) { |
|
580 | + $this->_error_msg[] = esc_html__( |
|
581 | + 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
|
582 | + 'event_espresso' |
|
583 | + ); |
|
584 | + return false; |
|
585 | + } |
|
586 | + |
|
587 | + //We use this as the counter for generated messages because don't forget we may be executing this inside of a |
|
588 | + //generation_queue. So _ready_queue may have generated EE_Message objects already. |
|
589 | + $generated_count = 0; |
|
590 | + foreach ($addressees as $context => $recipients) { |
|
591 | + foreach ($recipients as $recipient) { |
|
592 | + $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group); |
|
593 | + if ($message instanceof EE_Message) { |
|
594 | + $this->_ready_queue->add( |
|
595 | + $message, |
|
596 | + array(), |
|
597 | + $this->_generation_queue->get_message_repository()->is_preview(), |
|
598 | + $this->_generation_queue->get_message_repository()->is_test_send() |
|
599 | + ); |
|
600 | + $generated_count++; |
|
601 | + } |
|
602 | + |
|
603 | + //if the current MSG being generated is for a test send then we'll only use ONE message in the generation. |
|
604 | + if ($this->_generation_queue->get_message_repository()->is_test_send()) { |
|
605 | + break 2; |
|
606 | + } |
|
607 | + } |
|
608 | + } |
|
609 | + |
|
610 | + //if there are no generated messages then something else fatal went wrong. |
|
611 | + return $generated_count > 0; |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + /** |
|
616 | + * @param string $context The context for the generated message. |
|
617 | + * @param EE_Messages_Addressee $recipient |
|
618 | + * @param array $templates formatted array of templates used for parsing data. |
|
619 | + * @param EE_Message_Template_Group $message_template_group |
|
620 | + * @return bool|EE_Message |
|
621 | + * @throws EE_Error |
|
622 | + */ |
|
623 | + protected function _setup_message_object( |
|
624 | + $context, |
|
625 | + EE_Messages_Addressee $recipient, |
|
626 | + $templates, |
|
627 | + EE_Message_Template_Group $message_template_group |
|
628 | + ) { |
|
629 | + //stuff we already know |
|
630 | + $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0; |
|
631 | + $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
632 | + ? $this->_current_data_handler->txn->ID() |
|
633 | + : $transaction_id; |
|
634 | + $message_fields = array( |
|
635 | + 'GRP_ID' => $message_template_group->ID(), |
|
636 | + 'TXN_ID' => $transaction_id, |
|
637 | + 'MSG_messenger' => $this->_current_messenger->name, |
|
638 | + 'MSG_message_type' => $this->_current_message_type->name, |
|
639 | + 'MSG_context' => $context, |
|
640 | + ); |
|
641 | + |
|
642 | + //recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab |
|
643 | + // the info from the att_obj found in the EE_Messages_Addressee object. |
|
644 | + if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) { |
|
645 | + $message_fields['MSG_recipient_ID'] = $recipient->att_obj instanceof EE_Attendee |
|
646 | + ? $recipient->att_obj->ID() |
|
647 | + : 0; |
|
648 | + $message_fields['MSG_recipient_type'] = 'Attendee'; |
|
649 | + } else { |
|
650 | + $message_fields['MSG_recipient_ID'] = $recipient->recipient_id; |
|
651 | + $message_fields['MSG_recipient_type'] = $recipient->recipient_type; |
|
652 | + } |
|
653 | + $message = EE_Message_Factory::create($message_fields); |
|
654 | + |
|
655 | + //grab valid shortcodes for shortcode parser |
|
656 | + $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes(); |
|
657 | + $m_shortcodes = $this->_current_messenger->get_valid_shortcodes(); |
|
658 | + |
|
659 | + //if the 'to' field is empty (messages will ALWAYS have a "to" field, then we get out because that means this |
|
660 | + //context is turned off) EXCEPT if we're previewing |
|
661 | + if (empty($templates['to'][$context]) |
|
662 | + && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
663 | + && ! $this->_current_messenger->allow_empty_to_field() |
|
664 | + ) { |
|
665 | + //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" |
|
666 | + //field. |
|
667 | + return false; |
|
668 | + } |
|
669 | + $error_msg = array(); |
|
670 | + foreach ($templates as $field => $field_context) { |
|
671 | + $error_msg = array(); |
|
672 | + //let's setup the valid shortcodes for the incoming context. |
|
673 | + $valid_shortcodes = $mt_shortcodes[$context]; |
|
674 | + //merge in valid shortcodes for the field. |
|
675 | + $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
|
676 | + if (isset($templates[$field][$context])) { |
|
677 | + //prefix field. |
|
678 | + $column_name = 'MSG_' . $field; |
|
679 | + try { |
|
680 | + $content = $this->_shortcode_parser->parse_message_template( |
|
681 | + $templates[$field][$context], |
|
682 | + $recipient, |
|
683 | + $shortcodes, |
|
684 | + $this->_current_message_type, |
|
685 | + $this->_current_messenger, |
|
686 | + $message |
|
687 | + ); |
|
688 | + $message->set_field_or_extra_meta($column_name, $content); |
|
689 | + } catch (EE_Error $e) { |
|
690 | + $error_msg[] = sprintf( |
|
691 | + esc_html__( |
|
692 | + 'There was a problem generating the content for the field %s: %s', |
|
693 | + 'event_espresso' |
|
694 | + ), |
|
695 | + $field, |
|
696 | + $e->getMessage() |
|
697 | + ); |
|
698 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
699 | + } |
|
700 | + } |
|
701 | + } |
|
702 | + |
|
703 | + if ($message->STS_ID() === EEM_Message::status_failed) { |
|
704 | + $error_msg = esc_html__('There were problems generating this message:', 'event_espresso') |
|
705 | + . "\n" |
|
706 | + . implode("\n", $error_msg); |
|
707 | + $message->set_error_message($error_msg); |
|
708 | + } else { |
|
709 | + $message->set_STS_ID(EEM_Message::status_idle); |
|
710 | + } |
|
711 | + return $message; |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + /** |
|
716 | + * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate |
|
717 | + * error message if either is missing. |
|
718 | + * |
|
719 | + * @return bool true means there were no errors, false means there were errors. |
|
720 | + */ |
|
721 | + protected function _verify() |
|
722 | + { |
|
723 | + //reset error message to an empty array. |
|
724 | + $this->_error_msg = array(); |
|
725 | + $valid = true; |
|
726 | + $valid = $valid ? $this->_validate_messenger_and_message_type() : $valid; |
|
727 | + $valid = $valid ? $this->_validate_and_setup_data() : $valid; |
|
728 | + |
|
729 | + //set the verified flag so we know everything has been validated. |
|
730 | + $this->_verified = $valid; |
|
731 | + |
|
732 | + return $valid; |
|
733 | + } |
|
734 | + |
|
735 | + |
|
736 | + /** |
|
737 | + * This accepts an array and validates that it is an array indexed by context with each value being an array of |
|
738 | + * EE_Messages_Addressee objects. |
|
739 | + * |
|
740 | + * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[] |
|
741 | + * @return bool |
|
742 | + */ |
|
743 | + protected function _valid_addressees($addressees) |
|
744 | + { |
|
745 | + if (! $addressees || ! is_array($addressees)) { |
|
746 | + return false; |
|
747 | + } |
|
748 | + |
|
749 | + foreach ($addressees as $addressee_array) { |
|
750 | + foreach ($addressee_array as $addressee) { |
|
751 | + if (! $addressee instanceof EE_Messages_Addressee) { |
|
752 | + return false; |
|
753 | + } |
|
754 | + } |
|
755 | + } |
|
756 | + return true; |
|
757 | + } |
|
758 | + |
|
759 | + |
|
760 | + /** |
|
761 | + * This validates the messenger, message type, and presences of generation data for the current EE_Message in the |
|
762 | + * queue. This process sets error messages if something is wrong. |
|
763 | + * |
|
764 | + * @return bool true is if there are no errors. false is if there is. |
|
765 | + */ |
|
766 | + protected function _validate_messenger_and_message_type() |
|
767 | + { |
|
768 | + |
|
769 | + //first are there any existing error messages? If so then return. |
|
770 | + if ($this->_error_msg) { |
|
771 | + return false; |
|
772 | + } |
|
773 | + /** @type EE_Message $message */ |
|
774 | + $message = $this->_generation_queue->get_message_repository()->current(); |
|
775 | + try { |
|
776 | + $this->_current_messenger = $message->valid_messenger(true) |
|
777 | + ? $message->messenger_object() |
|
778 | + : null; |
|
779 | + } catch (Exception $e) { |
|
780 | + $this->_error_msg[] = $e->getMessage(); |
|
781 | + } |
|
782 | + try { |
|
783 | + $this->_current_message_type = $message->valid_message_type(true) |
|
784 | + ? $message->message_type_object() |
|
785 | + : null; |
|
786 | + } catch (Exception $e) { |
|
787 | + $this->_error_msg[] = $e->getMessage(); |
|
788 | + } |
|
789 | + |
|
790 | + /** |
|
791 | + * Check if there is any generation data, but only if this is not for a preview. |
|
792 | + */ |
|
793 | + if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
794 | + && ( |
|
795 | + ! $this->_generation_queue->get_message_repository()->is_preview() |
|
796 | + && $this->_generation_queue->get_message_repository()->get_data_handler() |
|
797 | + !== 'EE_Messages_Preview_incoming_data' |
|
798 | + ) |
|
799 | + ) { |
|
800 | + $this->_error_msg[] = esc_html__( |
|
801 | + 'There is no generation data for this message. Unable to generate.', |
|
802 | + 'event_espresso' |
|
803 | + ); |
|
804 | + } |
|
805 | + |
|
806 | + return empty($this->_error_msg); |
|
807 | + } |
|
808 | + |
|
809 | + |
|
810 | + /** |
|
811 | + * This method retrieves the expected data handler for the message type and validates the generation data for that |
|
812 | + * data handler. |
|
813 | + * |
|
814 | + * @return bool true means there are no errors. false means there were errors (and handler did not get setup). |
|
815 | + */ |
|
816 | + protected function _validate_and_setup_data() |
|
817 | + { |
|
818 | + |
|
819 | + //First, are there any existing error messages? If so, return because if there were errors elsewhere this can't |
|
820 | + //be used anyways. |
|
821 | + if ($this->_error_msg) { |
|
822 | + return false; |
|
823 | + } |
|
824 | + |
|
825 | + $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data(); |
|
826 | + |
|
827 | + /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually */ |
|
828 | + $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
|
829 | + ? $this->_generation_queue->get_message_repository()->get_data_handler() |
|
830 | + : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
831 | + |
|
832 | + //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
|
833 | + if ($this->_generation_queue->get_message_repository()->is_preview()) { |
|
834 | + $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
835 | + } |
|
836 | + |
|
837 | + //First get the class name for the data handler (and also verifies it exists. |
|
838 | + if (! class_exists($data_handler_class_name)) { |
|
839 | + $this->_error_msg[] = sprintf( |
|
840 | + esc_html__( |
|
841 | + 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
|
842 | + 'event_espresso' |
|
843 | + ), |
|
844 | + 'EE_Messages_incoming_data', |
|
845 | + $data_handler_class_name |
|
846 | + ); |
|
847 | + return false; |
|
848 | + } |
|
849 | + |
|
850 | + //convert generation_data for data_handler_instantiation. |
|
851 | + $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data); |
|
852 | + |
|
853 | + //note, this may set error messages as well. |
|
854 | + $this->_set_data_handler($generation_data, $data_handler_class_name); |
|
855 | + |
|
856 | + return empty($this->_error_msg); |
|
857 | + } |
|
858 | + |
|
859 | + |
|
860 | + /** |
|
861 | + * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and |
|
862 | + * adds it to the _data repository. |
|
863 | + * |
|
864 | + * @param mixed $generating_data This is data expected by the instantiated data handler. |
|
865 | + * @param string $data_handler_class_name This is the reference string indicating what data handler is being |
|
866 | + * instantiated. |
|
867 | + * @return void . |
|
868 | + * @throws EE_Error |
|
869 | + * @throws ReflectionException |
|
870 | + */ |
|
871 | + protected function _set_data_handler($generating_data, $data_handler_class_name) |
|
872 | + { |
|
873 | + //valid classname for the data handler. Now let's setup the key for the data handler repository to see if there |
|
874 | + //is already a ready data handler in the repository. |
|
875 | + $this->_current_data_handler = $this->_data_handler_collection->get_by_key( |
|
876 | + $this->_data_handler_collection->get_key( |
|
877 | + $data_handler_class_name, |
|
878 | + $generating_data |
|
879 | + ) |
|
880 | + ); |
|
881 | + if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
882 | + //no saved data_handler in the repo so let's set one up and add it to the repo. |
|
883 | + try { |
|
884 | + $this->_current_data_handler = new $data_handler_class_name($generating_data); |
|
885 | + $this->_data_handler_collection->add($this->_current_data_handler, $generating_data); |
|
886 | + } catch (EE_Error $e) { |
|
887 | + $this->_error_msg[] = $e->get_error(); |
|
888 | + } |
|
889 | + } |
|
890 | + } |
|
891 | + |
|
892 | + |
|
893 | + /** |
|
894 | + * The queued EE_Message for generation does not save the data used for generation as objects |
|
895 | + * because serialization of those objects could be problematic if the data is saved to the db. |
|
896 | + * So this method calls the static method on the associated data_handler for the given message_type |
|
897 | + * and that preps the data for later instantiation when generating. |
|
898 | + * |
|
899 | + * @param EE_Message_To_Generate $message_to_generate |
|
900 | + * @param bool $preview Indicate whether this is being used for a preview or not. |
|
901 | + * @return mixed Prepped data for persisting to the queue. false is returned if unable to prep data. |
|
902 | + */ |
|
903 | + protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview) |
|
904 | + { |
|
905 | + /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
|
906 | + $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
|
907 | + if (! $message_to_generate->valid()) { |
|
908 | + return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
|
909 | + } |
|
910 | + return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
|
911 | + } |
|
912 | + |
|
913 | + |
|
914 | + /** |
|
915 | + * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue. |
|
916 | + * |
|
917 | + * @param EE_Message_To_Generate $message_to_generate |
|
918 | + * @param bool $test_send Whether this is just a test send or not. Typically used for previews. |
|
919 | + */ |
|
920 | + public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
921 | + { |
|
922 | + //prep data |
|
923 | + $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview()); |
|
924 | + |
|
925 | + $message = $message_to_generate->get_EE_Message(); |
|
926 | + |
|
927 | + //is there a GRP_ID in the request? |
|
928 | + if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) { |
|
929 | + $message->set_GRP_ID($GRP_ID); |
|
930 | + } |
|
931 | + |
|
932 | + if ($data === false) { |
|
933 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
934 | + $message->set_error_message( |
|
935 | + esc_html__( |
|
936 | + 'Unable to prepare data for persistence to the database.', |
|
937 | + 'event_espresso' |
|
938 | + ) |
|
939 | + ); |
|
940 | + } else { |
|
941 | + //make sure that the data handler is cached on the message as well |
|
942 | + $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name(); |
|
943 | + } |
|
944 | + |
|
945 | + $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send); |
|
946 | + } |
|
947 | 947 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | { |
255 | 255 | //double check verification has run and that everything is ready to work with (saves us having to validate |
256 | 256 | // everything again). |
257 | - if (! $this->_verified) { |
|
257 | + if ( ! $this->_verified) { |
|
258 | 258 | return false; //get out because we don't have a valid setup to work with. |
259 | 259 | } |
260 | 260 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | |
272 | 272 | |
273 | 273 | //if no addressees then get out because there is nothing to generation (possible bad data). |
274 | - if (! $this->_valid_addressees($addressees)) { |
|
274 | + if ( ! $this->_valid_addressees($addressees)) { |
|
275 | 275 | do_action( |
276 | 276 | 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
277 | 277 | $this->_generation_queue->get_message_repository()->current(), |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | $message_template_group = $this->_get_message_template_group(); |
294 | 294 | |
295 | 295 | //in the unlikely event there is no EE_Message_Template_Group available, get out! |
296 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
296 | + if ( ! $message_template_group instanceof EE_Message_Template_Group) { |
|
297 | 297 | $this->_error_msg[] = esc_html__( |
298 | 298 | 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
299 | 299 | 'event_espresso' |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | //attempt to retrieve from repo first |
396 | 396 | $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
397 | 397 | if ($message_template_group instanceof EE_Message_Template_Group) { |
398 | - return $message_template_group; //got it! |
|
398 | + return $message_template_group; //got it! |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | ); |
492 | 492 | |
493 | 493 | //if we don't have a group lets hit the db. |
494 | - if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
494 | + if ( ! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
495 | 495 | $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
496 | 496 | array( |
497 | 497 | array( |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | $context_templates = $message_template_group->context_templates(); |
549 | 549 | foreach ($context_templates as $context => $template_fields) { |
550 | 550 | foreach ($template_fields as $template_field => $template_obj) { |
551 | - if (! $template_obj instanceof EE_Message_Template) { |
|
551 | + if ( ! $template_obj instanceof EE_Message_Template) { |
|
552 | 552 | continue; |
553 | 553 | } |
554 | 554 | $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | { |
577 | 577 | |
578 | 578 | //if templates are empty then get out because we can't generate anything. |
579 | - if (! $templates) { |
|
579 | + if ( ! $templates) { |
|
580 | 580 | $this->_error_msg[] = esc_html__( |
581 | 581 | 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
582 | 582 | 'event_espresso' |
@@ -675,7 +675,7 @@ discard block |
||
675 | 675 | $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
676 | 676 | if (isset($templates[$field][$context])) { |
677 | 677 | //prefix field. |
678 | - $column_name = 'MSG_' . $field; |
|
678 | + $column_name = 'MSG_'.$field; |
|
679 | 679 | try { |
680 | 680 | $content = $this->_shortcode_parser->parse_message_template( |
681 | 681 | $templates[$field][$context], |
@@ -742,13 +742,13 @@ discard block |
||
742 | 742 | */ |
743 | 743 | protected function _valid_addressees($addressees) |
744 | 744 | { |
745 | - if (! $addressees || ! is_array($addressees)) { |
|
745 | + if ( ! $addressees || ! is_array($addressees)) { |
|
746 | 746 | return false; |
747 | 747 | } |
748 | 748 | |
749 | 749 | foreach ($addressees as $addressee_array) { |
750 | 750 | foreach ($addressee_array as $addressee) { |
751 | - if (! $addressee instanceof EE_Messages_Addressee) { |
|
751 | + if ( ! $addressee instanceof EE_Messages_Addressee) { |
|
752 | 752 | return false; |
753 | 753 | } |
754 | 754 | } |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | /** |
791 | 791 | * Check if there is any generation data, but only if this is not for a preview. |
792 | 792 | */ |
793 | - if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
793 | + if ( ! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
794 | 794 | && ( |
795 | 795 | ! $this->_generation_queue->get_message_repository()->is_preview() |
796 | 796 | && $this->_generation_queue->get_message_repository()->get_data_handler() |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually */ |
828 | 828 | $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
829 | 829 | ? $this->_generation_queue->get_message_repository()->get_data_handler() |
830 | - : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
830 | + : 'EE_Messages_'.$this->_current_message_type->get_data_handler($generation_data).'_incoming_data'; |
|
831 | 831 | |
832 | 832 | //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
833 | 833 | if ($this->_generation_queue->get_message_repository()->is_preview()) { |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | } |
836 | 836 | |
837 | 837 | //First get the class name for the data handler (and also verifies it exists. |
838 | - if (! class_exists($data_handler_class_name)) { |
|
838 | + if ( ! class_exists($data_handler_class_name)) { |
|
839 | 839 | $this->_error_msg[] = sprintf( |
840 | 840 | esc_html__( |
841 | 841 | 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
@@ -878,7 +878,7 @@ discard block |
||
878 | 878 | $generating_data |
879 | 879 | ) |
880 | 880 | ); |
881 | - if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
881 | + if ( ! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
882 | 882 | //no saved data_handler in the repo so let's set one up and add it to the repo. |
883 | 883 | try { |
884 | 884 | $this->_current_data_handler = new $data_handler_class_name($generating_data); |
@@ -904,7 +904,7 @@ discard block |
||
904 | 904 | { |
905 | 905 | /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
906 | 906 | $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
907 | - if (! $message_to_generate->valid()) { |
|
907 | + if ( ! $message_to_generate->valid()) { |
|
908 | 908 | return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
909 | 909 | } |
910 | 910 | return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
@@ -18,14 +18,14 @@ discard block |
||
18 | 18 | $event_one_link = $event_two_link = $event_three_link = ''; |
19 | 19 | |
20 | 20 | $I->wantTo( |
21 | - 'Test that when registrations for multiple events are completed, and those events share the same custom' |
|
22 | - . 'template, that that custom template will be used.' |
|
21 | + 'Test that when registrations for multiple events are completed, and those events share the same custom' |
|
22 | + . 'template, that that custom template will be used.' |
|
23 | 23 | ); |
24 | 24 | |
25 | 25 | //need the MER plugin active for this test (we'll deactivate it after). |
26 | 26 | $I->ensurePluginActive( |
27 | - 'event-espresso-mer-multi-event-registration', |
|
28 | - 'activated' |
|
27 | + 'event-espresso-mer-multi-event-registration', |
|
28 | + 'activated' |
|
29 | 29 | ); |
30 | 30 | |
31 | 31 | $I->loginAsAdmin(); |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | |
84 | 84 | |
85 | 85 | $test_registration_details = array( |
86 | - 'fname' => 'CTGuy', |
|
87 | - 'lname' => 'Dude', |
|
88 | - 'email' => '[email protected]' |
|
86 | + 'fname' => 'CTGuy', |
|
87 | + 'lname' => 'Dude', |
|
88 | + 'email' => '[email protected]' |
|
89 | 89 | ); |
90 | 90 | |
91 | 91 | $I->amGoingTo('Register for Event One and Event Two and verify Custom Template A was used.'); |
@@ -111,24 +111,24 @@ discard block |
||
111 | 111 | $I->loginAsAdmin(); |
112 | 112 | $I->amOnMessagesActivityListTablePage(); |
113 | 113 | $I->viewMessageInMessagesListTableFor( |
114 | - 'Registration Approved', |
|
115 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
116 | - 'Email', |
|
117 | - 'Registrant' |
|
114 | + 'Registration Approved', |
|
115 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
116 | + 'Email', |
|
117 | + 'Registrant' |
|
118 | 118 | ); |
119 | 119 | $I->seeTextInViewMessageModal($custom_template_a_label); |
120 | 120 | //closes view window |
121 | 121 | $I->click('#espresso-admin-page-overlay-dv'); |
122 | 122 | $I->deleteMessageInMessagesListTableFor( |
123 | - 'Registration Approved', |
|
124 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
125 | - 'Email', |
|
126 | - 'Registrant' |
|
123 | + 'Registration Approved', |
|
124 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
125 | + 'Email', |
|
126 | + 'Registrant' |
|
127 | 127 | ); |
128 | 128 | |
129 | 129 | //verify admin context |
130 | 130 | $I->viewMessageInMessagesListTableFor( |
131 | - 'Registration Approved' |
|
131 | + 'Registration Approved' |
|
132 | 132 | ); |
133 | 133 | $I->seeTextInViewMessageModal($custom_template_a_label); |
134 | 134 | $I->click('#espresso-admin-page-overlay-dv'); |
@@ -157,10 +157,10 @@ discard block |
||
157 | 157 | $I->loginAsAdmin(); |
158 | 158 | $I->amOnMessagesActivityListTablePage(); |
159 | 159 | $I->viewMessageInMessagesListTableFor( |
160 | - 'Registration Approved', |
|
161 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
162 | - 'Email', |
|
163 | - 'Registrant' |
|
160 | + 'Registration Approved', |
|
161 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
162 | + 'Email', |
|
163 | + 'Registrant' |
|
164 | 164 | ); |
165 | 165 | $I->waitForElementVisible(MessagesAdmin::MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR); |
166 | 166 | $I->dontSeeTextInViewMessageModal($custom_template_a_label); |
@@ -168,15 +168,15 @@ discard block |
||
168 | 168 | //closes view window |
169 | 169 | $I->click('#espresso-admin-page-overlay-dv'); |
170 | 170 | $I->deleteMessageInMessagesListTableFor( |
171 | - 'Registration Approved', |
|
172 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
173 | - 'Email', |
|
174 | - 'Registrant' |
|
171 | + 'Registration Approved', |
|
172 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
173 | + 'Email', |
|
174 | + 'Registrant' |
|
175 | 175 | ); |
176 | 176 | |
177 | 177 | //verify admin context |
178 | 178 | $I->viewMessageInMessagesListTableFor( |
179 | - 'Registration Approved' |
|
179 | + 'Registration Approved' |
|
180 | 180 | ); |
181 | 181 | $I->waitForElementVisible(MessagesAdmin::MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR); |
182 | 182 | $I->dontSee($custom_template_a_label); |
@@ -188,6 +188,6 @@ discard block |
||
188 | 188 | |
189 | 189 | //deactivate MER plugin so its not active for future tests |
190 | 190 | $I->ensurePluginDeactivated( |
191 | - 'event-espresso-mer-multi-event-registration', |
|
192 | - 'Plugin deactivated' |
|
191 | + 'event-espresso-mer-multi-event-registration', |
|
192 | + 'Plugin deactivated' |
|
193 | 193 | ); |
194 | 194 | \ No newline at end of file |
@@ -14,115 +14,115 @@ |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * EE_Message_Template_Group_Collection constructor. |
|
19 | - */ |
|
20 | - public function __construct() |
|
21 | - { |
|
22 | - $this->interface = 'EE_Message_Template_Group'; |
|
23 | - } |
|
17 | + /** |
|
18 | + * EE_Message_Template_Group_Collection constructor. |
|
19 | + */ |
|
20 | + public function __construct() |
|
21 | + { |
|
22 | + $this->interface = 'EE_Message_Template_Group'; |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Adds the Message Template Group object to the repository. |
|
28 | - * |
|
29 | - * @param $message_template_group |
|
30 | - * @param array|int $EVT_ID Some templates are specific to EVT, so this is provided as a way of |
|
31 | - * indexing the template by key. If this template is shared among multiple events then |
|
32 | - * include the events as an array. |
|
33 | - * @return bool |
|
34 | - */ |
|
35 | - public function add($message_template_group, $EVT_ID = array()) |
|
36 | - { |
|
37 | - $EVT_ID = is_array($EVT_ID) ? $EVT_ID : (array) $EVT_ID; |
|
38 | - if ($message_template_group instanceof $this->interface) { |
|
39 | - $data['key'] = $this->getKey( |
|
40 | - $message_template_group->messenger(), |
|
41 | - $message_template_group->message_type(), |
|
42 | - $EVT_ID |
|
43 | - ); |
|
44 | - return parent::add($message_template_group, $data); |
|
45 | - } |
|
46 | - return false; |
|
47 | - } |
|
26 | + /** |
|
27 | + * Adds the Message Template Group object to the repository. |
|
28 | + * |
|
29 | + * @param $message_template_group |
|
30 | + * @param array|int $EVT_ID Some templates are specific to EVT, so this is provided as a way of |
|
31 | + * indexing the template by key. If this template is shared among multiple events then |
|
32 | + * include the events as an array. |
|
33 | + * @return bool |
|
34 | + */ |
|
35 | + public function add($message_template_group, $EVT_ID = array()) |
|
36 | + { |
|
37 | + $EVT_ID = is_array($EVT_ID) ? $EVT_ID : (array) $EVT_ID; |
|
38 | + if ($message_template_group instanceof $this->interface) { |
|
39 | + $data['key'] = $this->getKey( |
|
40 | + $message_template_group->messenger(), |
|
41 | + $message_template_group->message_type(), |
|
42 | + $EVT_ID |
|
43 | + ); |
|
44 | + return parent::add($message_template_group, $data); |
|
45 | + } |
|
46 | + return false; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * This retrieves any EE_Message_Template_Group in the repo by its ID. |
|
52 | - * |
|
53 | - * @param $GRP_ID |
|
54 | - * @return EE_Message_Template_Group | null |
|
55 | - */ |
|
56 | - public function get_by_ID($GRP_ID) |
|
57 | - { |
|
58 | - $this->rewind(); |
|
59 | - while ($this->valid()) { |
|
60 | - if ($this->current()->ID() === $GRP_ID) { |
|
61 | - /** @var EE_Message_Template_Group $message_template_group */ |
|
62 | - $message_template_group = $this->current(); |
|
63 | - $this->rewind(); |
|
64 | - return $message_template_group; |
|
65 | - } |
|
66 | - $this->next(); |
|
67 | - } |
|
68 | - return null; |
|
69 | - } |
|
50 | + /** |
|
51 | + * This retrieves any EE_Message_Template_Group in the repo by its ID. |
|
52 | + * |
|
53 | + * @param $GRP_ID |
|
54 | + * @return EE_Message_Template_Group | null |
|
55 | + */ |
|
56 | + public function get_by_ID($GRP_ID) |
|
57 | + { |
|
58 | + $this->rewind(); |
|
59 | + while ($this->valid()) { |
|
60 | + if ($this->current()->ID() === $GRP_ID) { |
|
61 | + /** @var EE_Message_Template_Group $message_template_group */ |
|
62 | + $message_template_group = $this->current(); |
|
63 | + $this->rewind(); |
|
64 | + return $message_template_group; |
|
65 | + } |
|
66 | + $this->next(); |
|
67 | + } |
|
68 | + return null; |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * Generates a hash used to identify a given Message Template Group. |
|
74 | - * |
|
75 | - * @param string $messenger The EE_messenger->name |
|
76 | - * @param string $message_type The EE_message_type->name |
|
77 | - * @param int $EVT_ID Optional. If the template is for a specific EVT then that should be included. |
|
78 | - * @deprecated 4.9.40.rc.017 Use getKey instead. |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function get_key($messenger, $message_type, $EVT_ID = 0) |
|
82 | - { |
|
83 | - $EVT_ID = (array) $EVT_ID; |
|
84 | - return $this->getKey($messenger, $message_type, $EVT_ID); |
|
85 | - } |
|
72 | + /** |
|
73 | + * Generates a hash used to identify a given Message Template Group. |
|
74 | + * |
|
75 | + * @param string $messenger The EE_messenger->name |
|
76 | + * @param string $message_type The EE_message_type->name |
|
77 | + * @param int $EVT_ID Optional. If the template is for a specific EVT then that should be included. |
|
78 | + * @deprecated 4.9.40.rc.017 Use getKey instead. |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function get_key($messenger, $message_type, $EVT_ID = 0) |
|
82 | + { |
|
83 | + $EVT_ID = (array) $EVT_ID; |
|
84 | + return $this->getKey($messenger, $message_type, $EVT_ID); |
|
85 | + } |
|
86 | 86 | |
87 | 87 | |
88 | - /** |
|
89 | - * Generates a hash used to identify a given Message Template Group |
|
90 | - * @param string $messenger The EE_messenger->name |
|
91 | - * @param string $message_type The EE_message_type->name |
|
92 | - * @param array $EVT_ID Optional. If the template is for a specific EVT_ID (or events) then that should |
|
93 | - * be included. |
|
94 | - * @since 4.9.40.rc.017 |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function getKey($messenger, $message_type, array $EVT_ID = array()) |
|
98 | - { |
|
99 | - sort($EVT_ID); |
|
100 | - $EVT_ID = implode(',', array_unique($EVT_ID)); |
|
101 | - return md5($messenger . $message_type . $EVT_ID); |
|
102 | - } |
|
88 | + /** |
|
89 | + * Generates a hash used to identify a given Message Template Group |
|
90 | + * @param string $messenger The EE_messenger->name |
|
91 | + * @param string $message_type The EE_message_type->name |
|
92 | + * @param array $EVT_ID Optional. If the template is for a specific EVT_ID (or events) then that should |
|
93 | + * be included. |
|
94 | + * @since 4.9.40.rc.017 |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function getKey($messenger, $message_type, array $EVT_ID = array()) |
|
98 | + { |
|
99 | + sort($EVT_ID); |
|
100 | + $EVT_ID = implode(',', array_unique($EVT_ID)); |
|
101 | + return md5($messenger . $message_type . $EVT_ID); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | |
105 | - /** |
|
106 | - * This returns a saved EE_Message_Template_Group object if there is one in the repository indexed by a key matching |
|
107 | - * the given string. |
|
108 | - * |
|
109 | - * @param string $key @see EE_Message_Template_Group::get_key() to setup a key formatted for searching. |
|
110 | - * @return null|EE_Message_Template_Group |
|
111 | - */ |
|
112 | - public function get_by_key($key) |
|
113 | - { |
|
114 | - $this->rewind(); |
|
115 | - while ($this->valid()) { |
|
116 | - $data = $this->getInfo(); |
|
117 | - if (isset($data['key']) && $data['key'] === $key) { |
|
118 | - /** @var EE_Message_Template_Group $message_template_group */ |
|
119 | - $message_template_group = $this->current(); |
|
120 | - $this->rewind(); |
|
121 | - return $message_template_group; |
|
122 | - } |
|
123 | - $this->next(); |
|
124 | - } |
|
125 | - return null; |
|
126 | - } |
|
105 | + /** |
|
106 | + * This returns a saved EE_Message_Template_Group object if there is one in the repository indexed by a key matching |
|
107 | + * the given string. |
|
108 | + * |
|
109 | + * @param string $key @see EE_Message_Template_Group::get_key() to setup a key formatted for searching. |
|
110 | + * @return null|EE_Message_Template_Group |
|
111 | + */ |
|
112 | + public function get_by_key($key) |
|
113 | + { |
|
114 | + $this->rewind(); |
|
115 | + while ($this->valid()) { |
|
116 | + $data = $this->getInfo(); |
|
117 | + if (isset($data['key']) && $data['key'] === $key) { |
|
118 | + /** @var EE_Message_Template_Group $message_template_group */ |
|
119 | + $message_template_group = $this->current(); |
|
120 | + $this->rewind(); |
|
121 | + return $message_template_group; |
|
122 | + } |
|
123 | + $this->next(); |
|
124 | + } |
|
125 | + return null; |
|
126 | + } |
|
127 | 127 | |
128 | 128 | } |
@@ -98,7 +98,7 @@ |
||
98 | 98 | { |
99 | 99 | sort($EVT_ID); |
100 | 100 | $EVT_ID = implode(',', array_unique($EVT_ID)); |
101 | - return md5($messenger . $message_type . $EVT_ID); |
|
101 | + return md5($messenger.$message_type.$EVT_ID); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.42.rc.002'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.42.rc.002'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |
@@ -39,14 +39,14 @@ |
||
39 | 39 | * @return void |
40 | 40 | */ |
41 | 41 | public static function set_hooks() { |
42 | - $post_type = get_post_type_object('espresso_venues'); |
|
43 | - $custom_post_types = EE_Register_CPTs::get_CPTs(); |
|
44 | - EE_Config::register_route( |
|
45 | - $custom_post_types['espresso_venues']['plural_slug'], |
|
46 | - 'Venues_Archive', |
|
47 | - 'run' |
|
48 | - ); |
|
49 | - } |
|
42 | + $post_type = get_post_type_object('espresso_venues'); |
|
43 | + $custom_post_types = EE_Register_CPTs::get_CPTs(); |
|
44 | + EE_Config::register_route( |
|
45 | + $custom_post_types['espresso_venues']['plural_slug'], |
|
46 | + 'Venues_Archive', |
|
47 | + 'run' |
|
48 | + ); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @return EED_Venues_Archive |
28 | 28 | */ |
29 | 29 | public static function instance() { |
30 | - return parent::get_instance( __CLASS__ ); |
|
30 | + return parent::get_instance(__CLASS__); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | * @access public |
66 | 66 | * @param \WP $WP |
67 | 67 | */ |
68 | - public function run( $WP ) { |
|
68 | + public function run($WP) { |
|
69 | 69 | // check what template is loaded |
70 | - add_filter( 'template_include', array( $this, 'template_include' ), 999, 1 ); |
|
71 | - add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 ); |
|
70 | + add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
71 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | |
@@ -80,18 +80,18 @@ discard block |
||
80 | 80 | * @param string $template |
81 | 81 | * @return string |
82 | 82 | */ |
83 | - public function template_include( $template ) { |
|
83 | + public function template_include($template) { |
|
84 | 84 | // not a custom template? |
85 | - if ( EE_Registry::instance()->load_core( 'Front_Controller', array(), false, true )->get_selected_template() != 'archive-espresso_venues.php' ) { |
|
85 | + if (EE_Registry::instance()->load_core('Front_Controller', array(), false, true)->get_selected_template() != 'archive-espresso_venues.php') { |
|
86 | 86 | EEH_Template::load_espresso_theme_functions(); |
87 | 87 | // then add extra event data via hooks |
88 | - add_filter( 'the_title', array( $this, 'the_title' ), 100, 1 ); |
|
88 | + add_filter('the_title', array($this, 'the_title'), 100, 1); |
|
89 | 89 | // don't know if theme uses the_excerpt |
90 | - add_filter( 'the_excerpt', array( $this, 'venue_details' ), 100 ); |
|
90 | + add_filter('the_excerpt', array($this, 'venue_details'), 100); |
|
91 | 91 | // or the_content |
92 | - add_filter( 'the_content', array( $this, 'venue_details' ), 100 ); |
|
92 | + add_filter('the_content', array($this, 'venue_details'), 100); |
|
93 | 93 | // don't display entry meta because the existing theme will take care of that |
94 | - add_filter( 'FHEE__content_espresso_venues_details_template__display_entry_meta', '__return_false' ); |
|
94 | + add_filter('FHEE__content_espresso_venues_details_template__display_entry_meta', '__return_false'); |
|
95 | 95 | } |
96 | 96 | return $template; |
97 | 97 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @param string $title |
106 | 106 | * @return string |
107 | 107 | */ |
108 | - public function the_title( $title = '' ) { |
|
108 | + public function the_title($title = '') { |
|
109 | 109 | return $title; |
110 | 110 | } |
111 | 111 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @param string $content |
118 | 118 | * @return string |
119 | 119 | */ |
120 | - public function venue_details( $content ) { |
|
120 | + public function venue_details($content) { |
|
121 | 121 | global $post; |
122 | 122 | if ( |
123 | 123 | $post->post_type == 'espresso_venues' |
@@ -127,22 +127,22 @@ discard block |
||
127 | 127 | // it uses the_content() for displaying the $post->post_content |
128 | 128 | // so in order to load a template that uses the_content() from within a callback being used to filter the_content(), |
129 | 129 | // we need to first remove this callback from being applied to the_content() (otherwise it will recurse and blow up the interweb) |
130 | - remove_filter( 'the_excerpt', array( $this, 'venue_details' ), 100 ); |
|
131 | - remove_filter( 'the_content', array( $this, 'venue_details' ), 100 ); |
|
130 | + remove_filter('the_excerpt', array($this, 'venue_details'), 100); |
|
131 | + remove_filter('the_content', array($this, 'venue_details'), 100); |
|
132 | 132 | // add filters we want |
133 | - add_filter( 'the_content', array( $this, 'venue_location' ), 110 ); |
|
134 | - add_filter( 'the_excerpt', array( $this, 'venue_location' ), 110 ); |
|
133 | + add_filter('the_content', array($this, 'venue_location'), 110); |
|
134 | + add_filter('the_excerpt', array($this, 'venue_location'), 110); |
|
135 | 135 | // now load our template |
136 | - $template = EEH_Template::locate_template( 'content-espresso_venues-details.php' ); |
|
136 | + $template = EEH_Template::locate_template('content-espresso_venues-details.php'); |
|
137 | 137 | //now add our filter back in, plus some others |
138 | - add_filter( 'the_excerpt', array( $this, 'venue_details' ), 100 ); |
|
139 | - add_filter( 'the_content', array( $this, 'venue_details' ), 100 ); |
|
138 | + add_filter('the_excerpt', array($this, 'venue_details'), 100); |
|
139 | + add_filter('the_content', array($this, 'venue_details'), 100); |
|
140 | 140 | // remove other filters we added so they won't get applied to the next post |
141 | - remove_filter( 'the_content', array( $this, 'venue_location' ), 110 ); |
|
142 | - remove_filter( 'the_excerpt', array( $this, 'venue_location' ), 110 ); |
|
141 | + remove_filter('the_content', array($this, 'venue_location'), 110); |
|
142 | + remove_filter('the_excerpt', array($this, 'venue_location'), 110); |
|
143 | 143 | // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
144 | 144 | } |
145 | - return ! empty( $template ) ? $template : $content; |
|
145 | + return ! empty($template) ? $template : $content; |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | * @param string $content |
155 | 155 | * @return string |
156 | 156 | */ |
157 | - public function venue_location( $content ) { |
|
158 | - return $content . EEH_Template::locate_template( 'content-espresso_venues-location.php' ); |
|
157 | + public function venue_location($content) { |
|
158 | + return $content.EEH_Template::locate_template('content-espresso_venues-location.php'); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | |
@@ -169,14 +169,14 @@ discard block |
||
169 | 169 | */ |
170 | 170 | public function wp_enqueue_scripts() { |
171 | 171 | // get some style |
172 | - if ( apply_filters( 'FHEE_enable_default_espresso_css', TRUE ) && is_archive() ) { |
|
172 | + if (apply_filters('FHEE_enable_default_espresso_css', TRUE) && is_archive()) { |
|
173 | 173 | // first check theme folder |
174 | - if ( is_readable( get_stylesheet_directory() . $this->theme . DS . 'style.css' )) { |
|
175 | - wp_register_style( $this->theme, get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', array( 'dashicons', 'espresso_default' ) ); |
|
176 | - } else if ( is_readable( EE_TEMPLATES . $this->theme . DS . 'style.css' )) { |
|
177 | - wp_register_style( $this->theme, EE_TEMPLATES_URL . $this->theme . DS . 'style.css', array( 'dashicons', 'espresso_default' ) ); |
|
174 | + if (is_readable(get_stylesheet_directory().$this->theme.DS.'style.css')) { |
|
175 | + wp_register_style($this->theme, get_stylesheet_directory_uri().$this->theme.DS.'style.css', array('dashicons', 'espresso_default')); |
|
176 | + } else if (is_readable(EE_TEMPLATES.$this->theme.DS.'style.css')) { |
|
177 | + wp_register_style($this->theme, EE_TEMPLATES_URL.$this->theme.DS.'style.css', array('dashicons', 'espresso_default')); |
|
178 | 178 | } |
179 | - wp_enqueue_style( $this->theme ); |
|
179 | + wp_enqueue_style($this->theme); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 |
@@ -32,20 +32,20 @@ |
||
32 | 32 | |
33 | 33 | |
34 | 34 | |
35 | - /** |
|
35 | + /** |
|
36 | 36 | * set_hooks - for hooking into EE Core, other modules, etc |
37 | 37 | * |
38 | 38 | * @access public |
39 | 39 | * @return void |
40 | 40 | */ |
41 | 41 | public static function set_hooks() { |
42 | - $custom_post_types = EE_Register_CPTs::get_CPTs(); |
|
43 | - EE_Config::register_route( |
|
44 | - $custom_post_types['espresso_venues']['singular_slug'], |
|
45 | - 'Venue_Single', |
|
46 | - 'run' |
|
47 | - ); |
|
48 | - } |
|
42 | + $custom_post_types = EE_Register_CPTs::get_CPTs(); |
|
43 | + EE_Config::register_route( |
|
44 | + $custom_post_types['espresso_venues']['singular_slug'], |
|
45 | + 'Venue_Single', |
|
46 | + 'run' |
|
47 | + ); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @return EED_Venue_Single |
28 | 28 | */ |
29 | 29 | public static function instance() { |
30 | - return parent::get_instance( __CLASS__ ); |
|
30 | + return parent::get_instance(__CLASS__); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | * @access public |
65 | 65 | * @param \WP $WP |
66 | 66 | */ |
67 | - public function run( $WP ) { |
|
67 | + public function run($WP) { |
|
68 | 68 | // check what template is loaded |
69 | - add_filter( 'template_include', array( $this, 'template_include' ), 999, 1 ); |
|
70 | - add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 ); |
|
69 | + add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
70 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | |
@@ -79,15 +79,15 @@ discard block |
||
79 | 79 | * @param string $template |
80 | 80 | * @return string |
81 | 81 | */ |
82 | - public function template_include( $template ) { |
|
82 | + public function template_include($template) { |
|
83 | 83 | // not a custom template? |
84 | - if ( EE_Registry::instance()->load_core( 'Front_Controller', array(), false, true )->get_selected_template() != 'single-espresso_venues.php' ) { |
|
84 | + if (EE_Registry::instance()->load_core('Front_Controller', array(), false, true)->get_selected_template() != 'single-espresso_venues.php') { |
|
85 | 85 | EEH_Template::load_espresso_theme_functions(); |
86 | 86 | // then add extra event data via hooks |
87 | - add_filter( 'the_title', array( $this, 'the_title' ), 100, 1 ); |
|
88 | - add_filter( 'the_content', array( $this, 'venue_details' ), 100 ); |
|
87 | + add_filter('the_title', array($this, 'the_title'), 100, 1); |
|
88 | + add_filter('the_content', array($this, 'venue_details'), 100); |
|
89 | 89 | // don't display entry meta because the existing theme will take car of that |
90 | - add_filter( 'FHEE__content_espresso_venues_details_template__display_entry_meta', '__return_false' ); |
|
90 | + add_filter('FHEE__content_espresso_venues_details_template__display_entry_meta', '__return_false'); |
|
91 | 91 | } |
92 | 92 | return $template; |
93 | 93 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @param string $title |
102 | 102 | * @return string |
103 | 103 | */ |
104 | - public function the_title( $title = '' ) { |
|
104 | + public function the_title($title = '') { |
|
105 | 105 | return $title; |
106 | 106 | } |
107 | 107 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @param string $content |
114 | 114 | * @return string |
115 | 115 | */ |
116 | - public function venue_details( $content ) { |
|
116 | + public function venue_details($content) { |
|
117 | 117 | global $post; |
118 | 118 | if ( |
119 | 119 | $post->post_type == 'espresso_venues' |
@@ -123,16 +123,16 @@ discard block |
||
123 | 123 | // it uses the_content() for displaying the $post->post_content |
124 | 124 | // so in order to load a template that uses the_content() from within a callback being used to filter the_content(), |
125 | 125 | // we need to first remove this callback from being applied to the_content() (otherwise it will recurse and blow up the interweb) |
126 | - remove_filter( 'the_content', array( $this, 'venue_details' ), 100 ); |
|
126 | + remove_filter('the_content', array($this, 'venue_details'), 100); |
|
127 | 127 | // add filters we want |
128 | - add_filter( 'the_content', array( $this, 'venue_location' ), 110 ); |
|
128 | + add_filter('the_content', array($this, 'venue_location'), 110); |
|
129 | 129 | // now load our template |
130 | - $template = EEH_Template::locate_template( 'content-espresso_venues-details.php' ); |
|
130 | + $template = EEH_Template::locate_template('content-espresso_venues-details.php'); |
|
131 | 131 | // remove other filters we added so they won't get applied to the next post |
132 | - remove_filter( 'the_content', array( $this, 'venue_location' ), 110 ); |
|
132 | + remove_filter('the_content', array($this, 'venue_location'), 110); |
|
133 | 133 | } |
134 | 134 | // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
135 | - return ! empty( $template ) ? $template : $content; |
|
135 | + return ! empty($template) ? $template : $content; |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | |
@@ -144,8 +144,8 @@ discard block |
||
144 | 144 | * @param string $content |
145 | 145 | * @return string |
146 | 146 | */ |
147 | - public function venue_location( $content ) { |
|
148 | - return $content . EEH_Template::locate_template( 'content-espresso_venues-location.php' ); |
|
147 | + public function venue_location($content) { |
|
148 | + return $content.EEH_Template::locate_template('content-espresso_venues-location.php'); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | |
@@ -158,16 +158,16 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function wp_enqueue_scripts() { |
160 | 160 | // get some style |
161 | - if ( apply_filters( 'FHEE_enable_default_espresso_css', TRUE ) && is_single() ) { |
|
161 | + if (apply_filters('FHEE_enable_default_espresso_css', TRUE) && is_single()) { |
|
162 | 162 | // first check theme folder |
163 | - if ( is_readable( get_stylesheet_directory() . $this->theme . DS . 'style.css' )) { |
|
164 | - wp_register_style( $this->theme, get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', array( 'dashicons', 'espresso_default' ) ); |
|
165 | - } else if ( is_readable( EE_TEMPLATES . $this->theme . DS . 'style.css' )) { |
|
166 | - wp_register_style( $this->theme, EE_TEMPLATES_URL . $this->theme . DS . 'style.css', array( 'dashicons', 'espresso_default' ) ); |
|
163 | + if (is_readable(get_stylesheet_directory().$this->theme.DS.'style.css')) { |
|
164 | + wp_register_style($this->theme, get_stylesheet_directory_uri().$this->theme.DS.'style.css', array('dashicons', 'espresso_default')); |
|
165 | + } else if (is_readable(EE_TEMPLATES.$this->theme.DS.'style.css')) { |
|
166 | + wp_register_style($this->theme, EE_TEMPLATES_URL.$this->theme.DS.'style.css', array('dashicons', 'espresso_default')); |
|
167 | 167 | } |
168 | - wp_enqueue_style( $this->theme ); |
|
169 | - if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) { |
|
170 | - add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 ); |
|
168 | + wp_enqueue_style($this->theme); |
|
169 | + if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
170 | + add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | } |
@@ -13,467 +13,467 @@ discard block |
||
13 | 13 | class EED_Event_Single extends EED_Module |
14 | 14 | { |
15 | 15 | |
16 | - const EVENT_DETAILS_PRIORITY = 100; |
|
17 | - const EVENT_DATETIMES_PRIORITY = 110; |
|
18 | - const EVENT_TICKETS_PRIORITY = 120; |
|
19 | - const EVENT_VENUES_PRIORITY = 130; |
|
20 | - |
|
21 | - /** |
|
22 | - * @type bool $using_get_the_excerpt |
|
23 | - */ |
|
24 | - protected static $using_get_the_excerpt = false; |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * @type EE_Template_Part_Manager $template_parts |
|
29 | - */ |
|
30 | - protected $template_parts; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @return EED_Module|EED_Event_Single |
|
35 | - */ |
|
36 | - public static function instance() |
|
37 | - { |
|
38 | - return parent::get_instance(__CLASS__); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
44 | - * |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - public static function set_hooks() |
|
48 | - { |
|
49 | - add_filter('FHEE_run_EE_wp', '__return_true'); |
|
50 | - add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
51 | - $custom_post_types = EE_Register_CPTs::get_CPTs(); |
|
52 | - EE_Config::register_route( |
|
53 | - $custom_post_types['espresso_events']['singular_slug'], |
|
54 | - 'Event_Single', |
|
55 | - 'run' |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
61 | - * |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - public static function set_hooks_admin() |
|
65 | - { |
|
66 | - add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * set_definitions |
|
72 | - * |
|
73 | - * @static |
|
74 | - * @return void |
|
75 | - */ |
|
76 | - public static function set_definitions() |
|
77 | - { |
|
78 | - define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
79 | - define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates' . DS); |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * set_config |
|
85 | - * |
|
86 | - * @void |
|
87 | - */ |
|
88 | - protected function set_config() |
|
89 | - { |
|
90 | - $this->set_config_section('template_settings'); |
|
91 | - $this->set_config_class('EE_Event_Single_Config'); |
|
92 | - $this->set_config_name('EED_Event_Single'); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * initialize_template_parts |
|
98 | - * |
|
99 | - * @param EE_Config_Base|EE_Event_Single_Config $config |
|
100 | - * @return EE_Template_Part_Manager |
|
101 | - */ |
|
102 | - public function initialize_template_parts(EE_Event_Single_Config $config = null) |
|
103 | - { |
|
104 | - /** @type EE_Event_Single_Config $config */ |
|
105 | - $config = $config instanceof EE_Event_Single_Config ? $config : $this->config(); |
|
106 | - EEH_Autoloader::instance()->register_template_part_autoloaders(); |
|
107 | - $template_parts = new EE_Template_Part_Manager(); |
|
108 | - $template_parts->add_template_part( |
|
109 | - 'tickets', |
|
110 | - __('Ticket Selector', 'event_espresso'), |
|
111 | - 'content-espresso_events-tickets.php', |
|
112 | - $config->display_order_tickets |
|
113 | - ); |
|
114 | - $template_parts->add_template_part( |
|
115 | - 'datetimes', |
|
116 | - __('Dates and Times', 'event_espresso'), |
|
117 | - 'content-espresso_events-datetimes.php', |
|
118 | - $config->display_order_datetimes |
|
119 | - ); |
|
120 | - $template_parts->add_template_part( |
|
121 | - 'event', |
|
122 | - __('Event Description', 'event_espresso'), |
|
123 | - 'content-espresso_events-details.php', |
|
124 | - $config->display_order_event |
|
125 | - ); |
|
126 | - $template_parts->add_template_part( |
|
127 | - 'venue', |
|
128 | - __('Venue Information', 'event_espresso'), |
|
129 | - 'content-espresso_events-venues.php', |
|
130 | - $config->display_order_venue |
|
131 | - ); |
|
132 | - do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts); |
|
133 | - return $template_parts; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * run - initial module setup |
|
139 | - * |
|
140 | - * @param WP $WP |
|
141 | - * @return void |
|
142 | - */ |
|
143 | - public function run($WP) |
|
144 | - { |
|
145 | - // ensure valid EE_Events_Single_Config() object exists |
|
146 | - $this->set_config(); |
|
147 | - // check what template is loaded |
|
148 | - add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
149 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
150 | - // load css |
|
151 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * template_include |
|
157 | - * |
|
158 | - * @param string $template |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function template_include($template) |
|
162 | - { |
|
163 | - global $post; |
|
164 | - /** @type EE_Event_Single_Config $config */ |
|
165 | - $config = $this->config(); |
|
166 | - if ($config->display_status_banner_single) { |
|
167 | - add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2); |
|
168 | - } |
|
169 | - // not a custom template? |
|
170 | - if ( |
|
171 | - !post_password_required($post) |
|
172 | - && ( |
|
173 | - apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false) |
|
174 | - || EE_Registry::instance() |
|
175 | - ->load_core('Front_Controller') |
|
176 | - ->get_selected_template() !== 'single-espresso_events.php' |
|
177 | - ) |
|
178 | - |
|
179 | - ) { |
|
180 | - EEH_Template::load_espresso_theme_functions(); |
|
181 | - // then add extra event data via hooks |
|
182 | - add_action('loop_start', array('EED_Event_Single', 'loop_start')); |
|
183 | - add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1); |
|
184 | - add_filter( |
|
185 | - 'the_content', |
|
186 | - array('EED_Event_Single', 'event_details'), |
|
187 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
188 | - ); |
|
189 | - add_action('loop_end', array('EED_Event_Single', 'loop_end')); |
|
190 | - // don't display entry meta because the existing theme will take car of that |
|
191 | - add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
192 | - } |
|
193 | - return $template; |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * loop_start |
|
199 | - * |
|
200 | - * @param array $wp_query_array an array containing the WP_Query object |
|
201 | - * @return void |
|
202 | - */ |
|
203 | - public static function loop_start($wp_query_array) |
|
204 | - { |
|
205 | - global $post; |
|
206 | - do_action('AHEE_event_details_before_post', $post, $wp_query_array); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * the_title |
|
212 | - * |
|
213 | - * @param string $title |
|
214 | - * @param int $id |
|
215 | - * @return string |
|
216 | - */ |
|
217 | - public static function the_title($title = '', $id = 0) |
|
218 | - { |
|
219 | - global $post; |
|
220 | - return in_the_loop() && $post->ID === (int)$id |
|
221 | - ? espresso_event_status_banner($post->ID) . $title |
|
222 | - : $title; |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * get_the_excerpt |
|
228 | - * kinda hacky, but if a theme is using get_the_excerpt(), |
|
229 | - * then we need to remove our filters on the_content() |
|
230 | - * |
|
231 | - * @param string $excerpt |
|
232 | - * @return string |
|
233 | - */ |
|
234 | - public static function get_the_excerpt($excerpt = '') |
|
235 | - { |
|
236 | - EED_Event_Single::$using_get_the_excerpt = true; |
|
237 | - add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1); |
|
238 | - return $excerpt; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * end_get_the_excerpt |
|
244 | - * |
|
245 | - * @param string $text |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - public static function end_get_the_excerpt($text = '') |
|
249 | - { |
|
250 | - EED_Event_Single::$using_get_the_excerpt = false; |
|
251 | - return $text; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * event_details |
|
257 | - * |
|
258 | - * @param string $content |
|
259 | - * @return string |
|
260 | - */ |
|
261 | - public static function event_details($content) |
|
262 | - { |
|
263 | - global $post; |
|
264 | - static $current_post_ID = 0; |
|
265 | - if ( |
|
266 | - $current_post_ID !== $post->ID |
|
267 | - && $post->post_type === 'espresso_events' |
|
268 | - && !EED_Event_Single::$using_get_the_excerpt |
|
269 | - && !post_password_required() |
|
270 | - ) { |
|
271 | - // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
272 | - // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
273 | - // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
274 | - // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
275 | - // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
276 | - // so the following allows this filter to be applied multiple times, but only once for real |
|
277 | - $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
278 | - if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) { |
|
279 | - // we need to first remove this callback from being applied to the_content() |
|
280 | - // (otherwise it will recurse and blow up the interweb) |
|
281 | - remove_filter( |
|
282 | - 'the_content', |
|
283 | - array('EED_Event_Single', 'event_details'), |
|
284 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
285 | - ); |
|
286 | - EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts(); |
|
287 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
288 | - $content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content); |
|
289 | - add_filter( |
|
290 | - 'the_content', |
|
291 | - array('EED_Event_Single', 'event_details'), |
|
292 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
293 | - ); |
|
294 | - } else { |
|
295 | - $content = EED_Event_Single::use_filterable_display_order(); |
|
296 | - } |
|
297 | - } |
|
298 | - return $content; |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * use_filterable_display_order |
|
304 | - * |
|
305 | - * @return string |
|
306 | - */ |
|
307 | - protected static function use_filterable_display_order() |
|
308 | - { |
|
309 | - // since the 'content-espresso_events-details.php' template might be used directly from within a theme, |
|
310 | - // it uses the_content() for displaying the $post->post_content |
|
311 | - // so in order to load a template that uses the_content() |
|
312 | - // from within a callback being used to filter the_content(), |
|
313 | - // we need to first remove this callback from being applied to the_content() |
|
314 | - // (otherwise it will recurse and blow up the interweb) |
|
315 | - remove_filter( |
|
316 | - 'the_content', |
|
317 | - array('EED_Event_Single', 'event_details'), |
|
318 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
319 | - ); |
|
320 | - //now add additional content |
|
321 | - add_filter( |
|
322 | - 'the_content', |
|
323 | - array('EED_Event_Single', 'event_datetimes'), |
|
324 | - EED_Event_Single::EVENT_DATETIMES_PRIORITY, |
|
325 | - 1 |
|
326 | - ); |
|
327 | - add_filter( |
|
328 | - 'the_content', |
|
329 | - array('EED_Event_Single', 'event_tickets'), |
|
330 | - EED_Event_Single::EVENT_TICKETS_PRIORITY, |
|
331 | - 1 |
|
332 | - ); |
|
333 | - add_filter( |
|
334 | - 'the_content', |
|
335 | - array('EED_Event_Single', 'event_venues'), |
|
336 | - EED_Event_Single::EVENT_VENUES_PRIORITY, |
|
337 | - 1 |
|
338 | - ); |
|
339 | - do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters'); |
|
340 | - // now load our template |
|
341 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
342 | - //now add our filter back in, plus some others |
|
343 | - add_filter( |
|
344 | - 'the_content', |
|
345 | - array('EED_Event_Single', 'event_details'), |
|
346 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
347 | - ); |
|
348 | - remove_filter( |
|
349 | - 'the_content', |
|
350 | - array('EED_Event_Single', 'event_datetimes'), |
|
351 | - EED_Event_Single::EVENT_DATETIMES_PRIORITY |
|
352 | - ); |
|
353 | - remove_filter( |
|
354 | - 'the_content', |
|
355 | - array('EED_Event_Single', 'event_tickets'), |
|
356 | - EED_Event_Single::EVENT_TICKETS_PRIORITY |
|
357 | - ); |
|
358 | - remove_filter( |
|
359 | - 'the_content', |
|
360 | - array('EED_Event_Single', 'event_venues'), |
|
361 | - EED_Event_Single::EVENT_VENUES_PRIORITY |
|
362 | - ); |
|
363 | - do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters'); |
|
364 | - // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
365 | - return $content; |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * event_datetimes - adds datetimes ABOVE content |
|
371 | - * |
|
372 | - * @param string $content |
|
373 | - * @return string |
|
374 | - */ |
|
375 | - public static function event_datetimes($content) |
|
376 | - { |
|
377 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
383 | - * |
|
384 | - * @param string $content |
|
385 | - * @return string |
|
386 | - */ |
|
387 | - public static function event_tickets($content) |
|
388 | - { |
|
389 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * event_venues |
|
395 | - * |
|
396 | - * @param string $content |
|
397 | - * @return string |
|
398 | - */ |
|
399 | - public static function event_venue($content) |
|
400 | - { |
|
401 | - return EED_Event_Single::event_venues($content); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * event_venues - adds venues BELOW content |
|
407 | - * |
|
408 | - * @param string $content |
|
409 | - * @return string |
|
410 | - */ |
|
411 | - public static function event_venues($content) |
|
412 | - { |
|
413 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * loop_end |
|
419 | - * |
|
420 | - * @param array $wp_query_array an array containing the WP_Query object |
|
421 | - * @return void |
|
422 | - */ |
|
423 | - public static function loop_end($wp_query_array) |
|
424 | - { |
|
425 | - global $post; |
|
426 | - do_action('AHEE_event_details_after_post', $post, $wp_query_array); |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - /** |
|
431 | - * wp_enqueue_scripts |
|
432 | - * |
|
433 | - * @return void |
|
434 | - */ |
|
435 | - public function wp_enqueue_scripts() |
|
436 | - { |
|
437 | - // get some style |
|
438 | - if ( |
|
439 | - apply_filters('FHEE_enable_default_espresso_css', TRUE) |
|
440 | - && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', TRUE) |
|
441 | - ) { |
|
442 | - // first check uploads folder |
|
443 | - if (is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) { |
|
444 | - wp_register_style( |
|
445 | - $this->theme, |
|
446 | - get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', |
|
447 | - array('dashicons', 'espresso_default') |
|
448 | - ); |
|
449 | - } else { |
|
450 | - wp_register_style( |
|
451 | - $this->theme, |
|
452 | - EE_TEMPLATES_URL . $this->theme . DS . 'style.css', |
|
453 | - array('dashicons', 'espresso_default') |
|
454 | - ); |
|
455 | - } |
|
456 | - wp_enqueue_script($this->theme); |
|
457 | - if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
458 | - add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
459 | - } |
|
460 | - } |
|
461 | - } |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * display_venue |
|
466 | - * |
|
467 | - * @return bool |
|
468 | - */ |
|
469 | - public static function display_venue() |
|
470 | - { |
|
471 | - /** @type EE_Event_Single_Config $config */ |
|
472 | - $config = EED_Event_Single::instance()->config(); |
|
473 | - $display_venue = $config->display_venue === null ? true : $config->display_venue; |
|
474 | - $venue_name = EEH_Venue_View::venue_name(); |
|
475 | - return $display_venue && !empty($venue_name); |
|
476 | - } |
|
16 | + const EVENT_DETAILS_PRIORITY = 100; |
|
17 | + const EVENT_DATETIMES_PRIORITY = 110; |
|
18 | + const EVENT_TICKETS_PRIORITY = 120; |
|
19 | + const EVENT_VENUES_PRIORITY = 130; |
|
20 | + |
|
21 | + /** |
|
22 | + * @type bool $using_get_the_excerpt |
|
23 | + */ |
|
24 | + protected static $using_get_the_excerpt = false; |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * @type EE_Template_Part_Manager $template_parts |
|
29 | + */ |
|
30 | + protected $template_parts; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @return EED_Module|EED_Event_Single |
|
35 | + */ |
|
36 | + public static function instance() |
|
37 | + { |
|
38 | + return parent::get_instance(__CLASS__); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
44 | + * |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + public static function set_hooks() |
|
48 | + { |
|
49 | + add_filter('FHEE_run_EE_wp', '__return_true'); |
|
50 | + add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
51 | + $custom_post_types = EE_Register_CPTs::get_CPTs(); |
|
52 | + EE_Config::register_route( |
|
53 | + $custom_post_types['espresso_events']['singular_slug'], |
|
54 | + 'Event_Single', |
|
55 | + 'run' |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
61 | + * |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + public static function set_hooks_admin() |
|
65 | + { |
|
66 | + add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * set_definitions |
|
72 | + * |
|
73 | + * @static |
|
74 | + * @return void |
|
75 | + */ |
|
76 | + public static function set_definitions() |
|
77 | + { |
|
78 | + define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
79 | + define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates' . DS); |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * set_config |
|
85 | + * |
|
86 | + * @void |
|
87 | + */ |
|
88 | + protected function set_config() |
|
89 | + { |
|
90 | + $this->set_config_section('template_settings'); |
|
91 | + $this->set_config_class('EE_Event_Single_Config'); |
|
92 | + $this->set_config_name('EED_Event_Single'); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * initialize_template_parts |
|
98 | + * |
|
99 | + * @param EE_Config_Base|EE_Event_Single_Config $config |
|
100 | + * @return EE_Template_Part_Manager |
|
101 | + */ |
|
102 | + public function initialize_template_parts(EE_Event_Single_Config $config = null) |
|
103 | + { |
|
104 | + /** @type EE_Event_Single_Config $config */ |
|
105 | + $config = $config instanceof EE_Event_Single_Config ? $config : $this->config(); |
|
106 | + EEH_Autoloader::instance()->register_template_part_autoloaders(); |
|
107 | + $template_parts = new EE_Template_Part_Manager(); |
|
108 | + $template_parts->add_template_part( |
|
109 | + 'tickets', |
|
110 | + __('Ticket Selector', 'event_espresso'), |
|
111 | + 'content-espresso_events-tickets.php', |
|
112 | + $config->display_order_tickets |
|
113 | + ); |
|
114 | + $template_parts->add_template_part( |
|
115 | + 'datetimes', |
|
116 | + __('Dates and Times', 'event_espresso'), |
|
117 | + 'content-espresso_events-datetimes.php', |
|
118 | + $config->display_order_datetimes |
|
119 | + ); |
|
120 | + $template_parts->add_template_part( |
|
121 | + 'event', |
|
122 | + __('Event Description', 'event_espresso'), |
|
123 | + 'content-espresso_events-details.php', |
|
124 | + $config->display_order_event |
|
125 | + ); |
|
126 | + $template_parts->add_template_part( |
|
127 | + 'venue', |
|
128 | + __('Venue Information', 'event_espresso'), |
|
129 | + 'content-espresso_events-venues.php', |
|
130 | + $config->display_order_venue |
|
131 | + ); |
|
132 | + do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts); |
|
133 | + return $template_parts; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * run - initial module setup |
|
139 | + * |
|
140 | + * @param WP $WP |
|
141 | + * @return void |
|
142 | + */ |
|
143 | + public function run($WP) |
|
144 | + { |
|
145 | + // ensure valid EE_Events_Single_Config() object exists |
|
146 | + $this->set_config(); |
|
147 | + // check what template is loaded |
|
148 | + add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
149 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
150 | + // load css |
|
151 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * template_include |
|
157 | + * |
|
158 | + * @param string $template |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function template_include($template) |
|
162 | + { |
|
163 | + global $post; |
|
164 | + /** @type EE_Event_Single_Config $config */ |
|
165 | + $config = $this->config(); |
|
166 | + if ($config->display_status_banner_single) { |
|
167 | + add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2); |
|
168 | + } |
|
169 | + // not a custom template? |
|
170 | + if ( |
|
171 | + !post_password_required($post) |
|
172 | + && ( |
|
173 | + apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false) |
|
174 | + || EE_Registry::instance() |
|
175 | + ->load_core('Front_Controller') |
|
176 | + ->get_selected_template() !== 'single-espresso_events.php' |
|
177 | + ) |
|
178 | + |
|
179 | + ) { |
|
180 | + EEH_Template::load_espresso_theme_functions(); |
|
181 | + // then add extra event data via hooks |
|
182 | + add_action('loop_start', array('EED_Event_Single', 'loop_start')); |
|
183 | + add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1); |
|
184 | + add_filter( |
|
185 | + 'the_content', |
|
186 | + array('EED_Event_Single', 'event_details'), |
|
187 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
188 | + ); |
|
189 | + add_action('loop_end', array('EED_Event_Single', 'loop_end')); |
|
190 | + // don't display entry meta because the existing theme will take car of that |
|
191 | + add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
192 | + } |
|
193 | + return $template; |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * loop_start |
|
199 | + * |
|
200 | + * @param array $wp_query_array an array containing the WP_Query object |
|
201 | + * @return void |
|
202 | + */ |
|
203 | + public static function loop_start($wp_query_array) |
|
204 | + { |
|
205 | + global $post; |
|
206 | + do_action('AHEE_event_details_before_post', $post, $wp_query_array); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * the_title |
|
212 | + * |
|
213 | + * @param string $title |
|
214 | + * @param int $id |
|
215 | + * @return string |
|
216 | + */ |
|
217 | + public static function the_title($title = '', $id = 0) |
|
218 | + { |
|
219 | + global $post; |
|
220 | + return in_the_loop() && $post->ID === (int)$id |
|
221 | + ? espresso_event_status_banner($post->ID) . $title |
|
222 | + : $title; |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * get_the_excerpt |
|
228 | + * kinda hacky, but if a theme is using get_the_excerpt(), |
|
229 | + * then we need to remove our filters on the_content() |
|
230 | + * |
|
231 | + * @param string $excerpt |
|
232 | + * @return string |
|
233 | + */ |
|
234 | + public static function get_the_excerpt($excerpt = '') |
|
235 | + { |
|
236 | + EED_Event_Single::$using_get_the_excerpt = true; |
|
237 | + add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1); |
|
238 | + return $excerpt; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * end_get_the_excerpt |
|
244 | + * |
|
245 | + * @param string $text |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + public static function end_get_the_excerpt($text = '') |
|
249 | + { |
|
250 | + EED_Event_Single::$using_get_the_excerpt = false; |
|
251 | + return $text; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * event_details |
|
257 | + * |
|
258 | + * @param string $content |
|
259 | + * @return string |
|
260 | + */ |
|
261 | + public static function event_details($content) |
|
262 | + { |
|
263 | + global $post; |
|
264 | + static $current_post_ID = 0; |
|
265 | + if ( |
|
266 | + $current_post_ID !== $post->ID |
|
267 | + && $post->post_type === 'espresso_events' |
|
268 | + && !EED_Event_Single::$using_get_the_excerpt |
|
269 | + && !post_password_required() |
|
270 | + ) { |
|
271 | + // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
272 | + // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
273 | + // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
274 | + // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
275 | + // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
276 | + // so the following allows this filter to be applied multiple times, but only once for real |
|
277 | + $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
278 | + if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) { |
|
279 | + // we need to first remove this callback from being applied to the_content() |
|
280 | + // (otherwise it will recurse and blow up the interweb) |
|
281 | + remove_filter( |
|
282 | + 'the_content', |
|
283 | + array('EED_Event_Single', 'event_details'), |
|
284 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
285 | + ); |
|
286 | + EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts(); |
|
287 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
288 | + $content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content); |
|
289 | + add_filter( |
|
290 | + 'the_content', |
|
291 | + array('EED_Event_Single', 'event_details'), |
|
292 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
293 | + ); |
|
294 | + } else { |
|
295 | + $content = EED_Event_Single::use_filterable_display_order(); |
|
296 | + } |
|
297 | + } |
|
298 | + return $content; |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * use_filterable_display_order |
|
304 | + * |
|
305 | + * @return string |
|
306 | + */ |
|
307 | + protected static function use_filterable_display_order() |
|
308 | + { |
|
309 | + // since the 'content-espresso_events-details.php' template might be used directly from within a theme, |
|
310 | + // it uses the_content() for displaying the $post->post_content |
|
311 | + // so in order to load a template that uses the_content() |
|
312 | + // from within a callback being used to filter the_content(), |
|
313 | + // we need to first remove this callback from being applied to the_content() |
|
314 | + // (otherwise it will recurse and blow up the interweb) |
|
315 | + remove_filter( |
|
316 | + 'the_content', |
|
317 | + array('EED_Event_Single', 'event_details'), |
|
318 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
319 | + ); |
|
320 | + //now add additional content |
|
321 | + add_filter( |
|
322 | + 'the_content', |
|
323 | + array('EED_Event_Single', 'event_datetimes'), |
|
324 | + EED_Event_Single::EVENT_DATETIMES_PRIORITY, |
|
325 | + 1 |
|
326 | + ); |
|
327 | + add_filter( |
|
328 | + 'the_content', |
|
329 | + array('EED_Event_Single', 'event_tickets'), |
|
330 | + EED_Event_Single::EVENT_TICKETS_PRIORITY, |
|
331 | + 1 |
|
332 | + ); |
|
333 | + add_filter( |
|
334 | + 'the_content', |
|
335 | + array('EED_Event_Single', 'event_venues'), |
|
336 | + EED_Event_Single::EVENT_VENUES_PRIORITY, |
|
337 | + 1 |
|
338 | + ); |
|
339 | + do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters'); |
|
340 | + // now load our template |
|
341 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
342 | + //now add our filter back in, plus some others |
|
343 | + add_filter( |
|
344 | + 'the_content', |
|
345 | + array('EED_Event_Single', 'event_details'), |
|
346 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
347 | + ); |
|
348 | + remove_filter( |
|
349 | + 'the_content', |
|
350 | + array('EED_Event_Single', 'event_datetimes'), |
|
351 | + EED_Event_Single::EVENT_DATETIMES_PRIORITY |
|
352 | + ); |
|
353 | + remove_filter( |
|
354 | + 'the_content', |
|
355 | + array('EED_Event_Single', 'event_tickets'), |
|
356 | + EED_Event_Single::EVENT_TICKETS_PRIORITY |
|
357 | + ); |
|
358 | + remove_filter( |
|
359 | + 'the_content', |
|
360 | + array('EED_Event_Single', 'event_venues'), |
|
361 | + EED_Event_Single::EVENT_VENUES_PRIORITY |
|
362 | + ); |
|
363 | + do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters'); |
|
364 | + // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
365 | + return $content; |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * event_datetimes - adds datetimes ABOVE content |
|
371 | + * |
|
372 | + * @param string $content |
|
373 | + * @return string |
|
374 | + */ |
|
375 | + public static function event_datetimes($content) |
|
376 | + { |
|
377 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
383 | + * |
|
384 | + * @param string $content |
|
385 | + * @return string |
|
386 | + */ |
|
387 | + public static function event_tickets($content) |
|
388 | + { |
|
389 | + return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * event_venues |
|
395 | + * |
|
396 | + * @param string $content |
|
397 | + * @return string |
|
398 | + */ |
|
399 | + public static function event_venue($content) |
|
400 | + { |
|
401 | + return EED_Event_Single::event_venues($content); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * event_venues - adds venues BELOW content |
|
407 | + * |
|
408 | + * @param string $content |
|
409 | + * @return string |
|
410 | + */ |
|
411 | + public static function event_venues($content) |
|
412 | + { |
|
413 | + return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * loop_end |
|
419 | + * |
|
420 | + * @param array $wp_query_array an array containing the WP_Query object |
|
421 | + * @return void |
|
422 | + */ |
|
423 | + public static function loop_end($wp_query_array) |
|
424 | + { |
|
425 | + global $post; |
|
426 | + do_action('AHEE_event_details_after_post', $post, $wp_query_array); |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + /** |
|
431 | + * wp_enqueue_scripts |
|
432 | + * |
|
433 | + * @return void |
|
434 | + */ |
|
435 | + public function wp_enqueue_scripts() |
|
436 | + { |
|
437 | + // get some style |
|
438 | + if ( |
|
439 | + apply_filters('FHEE_enable_default_espresso_css', TRUE) |
|
440 | + && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', TRUE) |
|
441 | + ) { |
|
442 | + // first check uploads folder |
|
443 | + if (is_readable(get_stylesheet_directory() . $this->theme . DS . 'style.css')) { |
|
444 | + wp_register_style( |
|
445 | + $this->theme, |
|
446 | + get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', |
|
447 | + array('dashicons', 'espresso_default') |
|
448 | + ); |
|
449 | + } else { |
|
450 | + wp_register_style( |
|
451 | + $this->theme, |
|
452 | + EE_TEMPLATES_URL . $this->theme . DS . 'style.css', |
|
453 | + array('dashicons', 'espresso_default') |
|
454 | + ); |
|
455 | + } |
|
456 | + wp_enqueue_script($this->theme); |
|
457 | + if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
458 | + add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
459 | + } |
|
460 | + } |
|
461 | + } |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * display_venue |
|
466 | + * |
|
467 | + * @return bool |
|
468 | + */ |
|
469 | + public static function display_venue() |
|
470 | + { |
|
471 | + /** @type EE_Event_Single_Config $config */ |
|
472 | + $config = EED_Event_Single::instance()->config(); |
|
473 | + $display_venue = $config->display_venue === null ? true : $config->display_venue; |
|
474 | + $venue_name = EEH_Venue_View::venue_name(); |
|
475 | + return $display_venue && !empty($venue_name); |
|
476 | + } |
|
477 | 477 | |
478 | 478 | |
479 | 479 | } |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | */ |
488 | 488 | function espresso_display_venue_in_event_details() |
489 | 489 | { |
490 | - return EED_Event_Single::display_venue(); |
|
490 | + return EED_Event_Single::display_venue(); |
|
491 | 491 | } |
492 | 492 | |
493 | 493 |
@@ -14,13 +14,13 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class EED_Events_Archive extends EED_Module { |
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; |
|
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 | 21 | |
22 | 22 | |
23 | - public static $espresso_event_list_ID = 0; |
|
23 | + public static $espresso_event_list_ID = 0; |
|
24 | 24 | public static $espresso_grid_event_lists = array(); |
25 | 25 | |
26 | 26 | /** |
@@ -28,19 +28,19 @@ discard block |
||
28 | 28 | */ |
29 | 29 | protected static $using_get_the_excerpt = false; |
30 | 30 | |
31 | - /** |
|
32 | - * Used to flag when the event list is being called from an external iframe. |
|
33 | - * |
|
34 | - * @var bool $iframe |
|
35 | - */ |
|
36 | - protected static $iframe = false; |
|
31 | + /** |
|
32 | + * Used to flag when the event list is being called from an external iframe. |
|
33 | + * |
|
34 | + * @var bool $iframe |
|
35 | + */ |
|
36 | + protected static $iframe = false; |
|
37 | 37 | |
38 | - /** |
|
38 | + /** |
|
39 | 39 | * @var \EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton $_iframe_embed_button |
40 | 40 | */ |
41 | 41 | private static $_iframe_embed_button; |
42 | 42 | |
43 | - /** |
|
43 | + /** |
|
44 | 44 | * @type EE_Template_Part_Manager $template_parts |
45 | 45 | */ |
46 | 46 | protected $template_parts; |
@@ -63,24 +63,24 @@ discard block |
||
63 | 63 | * @return void |
64 | 64 | */ |
65 | 65 | public static function set_hooks() { |
66 | - $custom_post_types = EE_Register_CPTs::get_CPTs(); |
|
67 | - EE_Config::register_route( |
|
68 | - $custom_post_types['espresso_events']['plural_slug'], |
|
69 | - 'Events_Archive', |
|
70 | - 'run' |
|
71 | - ); |
|
72 | - EE_Config::register_route( |
|
73 | - 'event_list', |
|
74 | - 'Events_Archive', |
|
75 | - 'event_list' |
|
76 | - ); |
|
77 | - EE_Config::register_route( |
|
78 | - 'iframe', |
|
79 | - 'Events_Archive', |
|
80 | - 'event_list_iframe', |
|
81 | - 'event_list' |
|
82 | - ); |
|
83 | - add_action( 'wp_loaded', array( 'EED_Events_Archive', 'set_definitions' ), 2 ); |
|
66 | + $custom_post_types = EE_Register_CPTs::get_CPTs(); |
|
67 | + EE_Config::register_route( |
|
68 | + $custom_post_types['espresso_events']['plural_slug'], |
|
69 | + 'Events_Archive', |
|
70 | + 'run' |
|
71 | + ); |
|
72 | + EE_Config::register_route( |
|
73 | + 'event_list', |
|
74 | + 'Events_Archive', |
|
75 | + 'event_list' |
|
76 | + ); |
|
77 | + EE_Config::register_route( |
|
78 | + 'iframe', |
|
79 | + 'Events_Archive', |
|
80 | + 'event_list_iframe', |
|
81 | + 'event_list' |
|
82 | + ); |
|
83 | + add_action( 'wp_loaded', array( 'EED_Events_Archive', 'set_definitions' ), 2 ); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -224,9 +224,9 @@ discard block |
||
224 | 224 | |
225 | 225 | |
226 | 226 | /** |
227 | - * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting |
|
228 | - * |
|
229 | - * @return void |
|
227 | + * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting |
|
228 | + * |
|
229 | + * @return void |
|
230 | 230 | */ |
231 | 231 | public function event_list() { |
232 | 232 | // ensure valid EE_Events_Archive_Config() object exists |
@@ -237,36 +237,36 @@ discard block |
||
237 | 237 | |
238 | 238 | |
239 | 239 | |
240 | - /** |
|
241 | - * @access public |
|
242 | - * @return void |
|
243 | - * @throws \EE_Error |
|
244 | - * @throws \DomainException |
|
245 | - */ |
|
240 | + /** |
|
241 | + * @access public |
|
242 | + * @return void |
|
243 | + * @throws \EE_Error |
|
244 | + * @throws \DomainException |
|
245 | + */ |
|
246 | 246 | public function event_list_iframe() { |
247 | - \EED_Events_Archive::$iframe = true; |
|
247 | + \EED_Events_Archive::$iframe = true; |
|
248 | 248 | $event_list_iframe = new EventsArchiveIframe( $this ); |
249 | 249 | $event_list_iframe->display(); |
250 | 250 | } |
251 | 251 | |
252 | 252 | |
253 | 253 | |
254 | - /** |
|
255 | - * @access public |
|
256 | - * @return string |
|
257 | - */ |
|
254 | + /** |
|
255 | + * @access public |
|
256 | + * @return string |
|
257 | + */ |
|
258 | 258 | public static function is_iframe() { |
259 | - return \EED_Events_Archive::$iframe; |
|
259 | + return \EED_Events_Archive::$iframe; |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | |
263 | 263 | |
264 | - /** |
|
265 | - * @access public |
|
266 | - * @return string |
|
267 | - */ |
|
264 | + /** |
|
265 | + * @access public |
|
266 | + * @return string |
|
267 | + */ |
|
268 | 268 | public static function link_target() { |
269 | - return \EED_Events_Archive::$iframe ? ' target="_blank"' : ''; |
|
269 | + return \EED_Events_Archive::$iframe ? ' target="_blank"' : ''; |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | |
@@ -294,10 +294,10 @@ discard block |
||
294 | 294 | } |
295 | 295 | // if NOT a custom template |
296 | 296 | if ( |
297 | - apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false) |
|
297 | + apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false) |
|
298 | 298 | || EE_Registry::instance() |
299 | - ->load_core( 'Front_Controller' ) |
|
300 | - ->get_selected_template() !== 'archive-espresso_events.php' |
|
299 | + ->load_core( 'Front_Controller' ) |
|
300 | + ->get_selected_template() !== 'archive-espresso_events.php' |
|
301 | 301 | ) { |
302 | 302 | // don't display entry meta because the existing theme will take care of that |
303 | 303 | add_filter( 'FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true' ); |
@@ -305,16 +305,16 @@ discard block |
||
305 | 305 | EEH_Template::load_espresso_theme_functions(); |
306 | 306 | // because we don't know if the theme is using the_excerpt() |
307 | 307 | add_filter( |
308 | - 'the_excerpt', |
|
309 | - array( 'EED_Events_Archive', 'event_details' ), |
|
310 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
311 | - ); |
|
308 | + 'the_excerpt', |
|
309 | + array( 'EED_Events_Archive', 'event_details' ), |
|
310 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
311 | + ); |
|
312 | 312 | // or the_content |
313 | 313 | add_filter( |
314 | - 'the_content', |
|
315 | - array( 'EED_Events_Archive', 'event_details' ), |
|
316 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
317 | - ); |
|
314 | + 'the_content', |
|
315 | + array( 'EED_Events_Archive', 'event_details' ), |
|
316 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
317 | + ); |
|
318 | 318 | // and just in case they are running get_the_excerpt() which DESTROYS things |
319 | 319 | add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 ); |
320 | 320 | // don't display entry meta because the existing theme will take care of that |
@@ -339,15 +339,15 @@ discard block |
||
339 | 339 | } |
340 | 340 | if ( apply_filters( 'FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false ) ) { |
341 | 341 | remove_filter( |
342 | - 'the_excerpt', |
|
343 | - array( 'EED_Events_Archive', 'event_details' ), |
|
344 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
345 | - ); |
|
342 | + 'the_excerpt', |
|
343 | + array( 'EED_Events_Archive', 'event_details' ), |
|
344 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
345 | + ); |
|
346 | 346 | remove_filter( |
347 | - 'the_content', |
|
348 | - array( 'EED_Events_Archive', 'event_details' ), |
|
349 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
350 | - ); |
|
347 | + 'the_content', |
|
348 | + array( 'EED_Events_Archive', 'event_details' ), |
|
349 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
350 | + ); |
|
351 | 351 | $excerpt = EED_Events_Archive::event_details( $excerpt ); |
352 | 352 | } else { |
353 | 353 | EED_Events_Archive::$using_get_the_excerpt = true; |
@@ -438,17 +438,17 @@ discard block |
||
438 | 438 | // no further password checks required atm |
439 | 439 | add_filter( 'FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true' ); |
440 | 440 | // we need to first remove this callback from being applied to the_content() or the_excerpt() |
441 | - // (otherwise it will recurse and blow up the interweb) |
|
441 | + // (otherwise it will recurse and blow up the interweb) |
|
442 | 442 | remove_filter( |
443 | - 'the_excerpt', |
|
444 | - array( 'EED_Events_Archive', 'event_details' ), |
|
445 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
446 | - ); |
|
443 | + 'the_excerpt', |
|
444 | + array( 'EED_Events_Archive', 'event_details' ), |
|
445 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
446 | + ); |
|
447 | 447 | remove_filter( |
448 | - 'the_content', |
|
449 | - array( 'EED_Events_Archive', 'event_details' ), |
|
450 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
451 | - ); |
|
448 | + 'the_content', |
|
449 | + array( 'EED_Events_Archive', 'event_details' ), |
|
450 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
451 | + ); |
|
452 | 452 | remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
453 | 453 | // now add additional content depending on whether event is using the_excerpt() or the_content() |
454 | 454 | EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts(); |
@@ -456,20 +456,20 @@ discard block |
||
456 | 456 | $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters( $content ); |
457 | 457 | // re-add our main filters (or else the next event won't have them) |
458 | 458 | add_filter( |
459 | - 'the_excerpt', |
|
460 | - array( 'EED_Events_Archive', 'event_details' ), |
|
461 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
462 | - ); |
|
459 | + 'the_excerpt', |
|
460 | + array( 'EED_Events_Archive', 'event_details' ), |
|
461 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
462 | + ); |
|
463 | 463 | add_filter( |
464 | - 'the_content', |
|
465 | - array( 'EED_Events_Archive', 'event_details' ), |
|
466 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
467 | - ); |
|
464 | + 'the_content', |
|
465 | + array( 'EED_Events_Archive', 'event_details' ), |
|
466 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
467 | + ); |
|
468 | 468 | add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 ); |
469 | 469 | remove_filter( |
470 | - 'FHEE__EED_Events_Archive__event_details__no_post_password_required', |
|
471 | - '__return_true' |
|
472 | - ); |
|
470 | + 'FHEE__EED_Events_Archive__event_details__no_post_password_required', |
|
471 | + '__return_true' |
|
472 | + ); |
|
473 | 473 | return $content; |
474 | 474 | } |
475 | 475 | |
@@ -485,15 +485,15 @@ discard block |
||
485 | 485 | // we need to first remove this callback from being applied to the_content() |
486 | 486 | // (otherwise it will recurse and blow up the interweb) |
487 | 487 | remove_filter( |
488 | - 'the_excerpt', |
|
489 | - array( 'EED_Events_Archive', 'event_details' ), |
|
490 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
491 | - ); |
|
488 | + 'the_excerpt', |
|
489 | + array( 'EED_Events_Archive', 'event_details' ), |
|
490 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
491 | + ); |
|
492 | 492 | remove_filter( |
493 | - 'the_content', |
|
494 | - array( 'EED_Events_Archive', 'event_details' ), |
|
495 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
496 | - ); |
|
493 | + 'the_content', |
|
494 | + array( 'EED_Events_Archive', 'event_details' ), |
|
495 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
496 | + ); |
|
497 | 497 | remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
498 | 498 | //now add additional content depending on whether event is using the_excerpt() or the_content() |
499 | 499 | EED_Events_Archive::_add_additional_excerpt_filters(); |
@@ -503,15 +503,15 @@ discard block |
||
503 | 503 | $content = EEH_Template::locate_template( 'content-espresso_events-details.php' ); |
504 | 504 | // re-add our main filters (or else the next event won't have them) |
505 | 505 | add_filter( |
506 | - 'the_excerpt', |
|
507 | - array( 'EED_Events_Archive', 'event_details' ), |
|
508 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
509 | - ); |
|
506 | + 'the_excerpt', |
|
507 | + array( 'EED_Events_Archive', 'event_details' ), |
|
508 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
509 | + ); |
|
510 | 510 | add_filter( |
511 | - 'the_content', |
|
512 | - array( 'EED_Events_Archive', 'event_details' ), |
|
513 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
514 | - ); |
|
511 | + 'the_content', |
|
512 | + array( 'EED_Events_Archive', 'event_details' ), |
|
513 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
514 | + ); |
|
515 | 515 | add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 ); |
516 | 516 | // but remove the other filters so that they don't get applied to the next post |
517 | 517 | EED_Events_Archive::_remove_additional_events_archive_filters(); |
@@ -588,20 +588,20 @@ discard block |
||
588 | 588 | */ |
589 | 589 | private static function _add_additional_excerpt_filters() { |
590 | 590 | add_filter( |
591 | - 'the_excerpt', |
|
592 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
593 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
594 | - ); |
|
591 | + 'the_excerpt', |
|
592 | + array( 'EED_Events_Archive', 'event_datetimes' ), |
|
593 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
594 | + ); |
|
595 | 595 | add_filter( |
596 | - 'the_excerpt', |
|
597 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
598 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
599 | - ); |
|
596 | + 'the_excerpt', |
|
597 | + array( 'EED_Events_Archive', 'event_tickets' ), |
|
598 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
599 | + ); |
|
600 | 600 | add_filter( |
601 | - 'the_excerpt', |
|
602 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
603 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
604 | - ); |
|
601 | + 'the_excerpt', |
|
602 | + array( 'EED_Events_Archive', 'event_venues' ), |
|
603 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
604 | + ); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | |
@@ -614,20 +614,20 @@ discard block |
||
614 | 614 | */ |
615 | 615 | private static function _add_additional_content_filters() { |
616 | 616 | add_filter( |
617 | - 'the_content', |
|
618 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
619 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
620 | - ); |
|
617 | + 'the_content', |
|
618 | + array( 'EED_Events_Archive', 'event_datetimes' ), |
|
619 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
620 | + ); |
|
621 | 621 | add_filter( |
622 | - 'the_content', |
|
623 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
624 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
625 | - ); |
|
622 | + 'the_content', |
|
623 | + array( 'EED_Events_Archive', 'event_tickets' ), |
|
624 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
625 | + ); |
|
626 | 626 | add_filter( |
627 | - 'the_content', |
|
628 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
629 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
630 | - ); |
|
627 | + 'the_content', |
|
628 | + array( 'EED_Events_Archive', 'event_venues' ), |
|
629 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
630 | + ); |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | |
@@ -640,35 +640,35 @@ discard block |
||
640 | 640 | */ |
641 | 641 | private static function _remove_additional_events_archive_filters() { |
642 | 642 | remove_filter( |
643 | - 'the_excerpt', |
|
644 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
645 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
646 | - ); |
|
643 | + 'the_excerpt', |
|
644 | + array( 'EED_Events_Archive', 'event_datetimes' ), |
|
645 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
646 | + ); |
|
647 | 647 | remove_filter( |
648 | - 'the_excerpt', |
|
649 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
650 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
651 | - ); |
|
648 | + 'the_excerpt', |
|
649 | + array( 'EED_Events_Archive', 'event_tickets' ), |
|
650 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
651 | + ); |
|
652 | 652 | remove_filter( |
653 | - 'the_excerpt', |
|
654 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
655 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
656 | - ); |
|
653 | + 'the_excerpt', |
|
654 | + array( 'EED_Events_Archive', 'event_venues' ), |
|
655 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
656 | + ); |
|
657 | 657 | remove_filter( |
658 | - 'the_content', |
|
659 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
660 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
661 | - ); |
|
658 | + 'the_content', |
|
659 | + array( 'EED_Events_Archive', 'event_datetimes' ), |
|
660 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
661 | + ); |
|
662 | 662 | remove_filter( |
663 | - 'the_content', |
|
664 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
665 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
666 | - ); |
|
663 | + 'the_content', |
|
664 | + array( 'EED_Events_Archive', 'event_tickets' ), |
|
665 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
666 | + ); |
|
667 | 667 | remove_filter( |
668 | - 'the_content', |
|
669 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
670 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
671 | - ); |
|
668 | + 'the_content', |
|
669 | + array( 'EED_Events_Archive', 'event_venues' ), |
|
670 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
671 | + ); |
|
672 | 672 | } |
673 | 673 | |
674 | 674 | |
@@ -683,50 +683,50 @@ discard block |
||
683 | 683 | //remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
684 | 684 | remove_filter( 'the_title', array( 'EED_Events_Archive', 'the_title' ), 1 ); |
685 | 685 | remove_filter( |
686 | - 'the_excerpt', |
|
687 | - array( 'EED_Events_Archive', 'event_details' ), |
|
688 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
689 | - ); |
|
686 | + 'the_excerpt', |
|
687 | + array( 'EED_Events_Archive', 'event_details' ), |
|
688 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
689 | + ); |
|
690 | 690 | remove_filter( |
691 | - 'the_excerpt', |
|
692 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
693 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
694 | - ); |
|
691 | + 'the_excerpt', |
|
692 | + array( 'EED_Events_Archive', 'event_datetimes' ), |
|
693 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
694 | + ); |
|
695 | 695 | remove_filter( |
696 | - 'the_excerpt', |
|
697 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
698 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
699 | - ); |
|
696 | + 'the_excerpt', |
|
697 | + array( 'EED_Events_Archive', 'event_tickets' ), |
|
698 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
699 | + ); |
|
700 | 700 | remove_filter( |
701 | - 'the_excerpt', |
|
702 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
703 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
704 | - ); |
|
701 | + 'the_excerpt', |
|
702 | + array( 'EED_Events_Archive', 'event_venues' ), |
|
703 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
704 | + ); |
|
705 | 705 | remove_filter( |
706 | - 'the_content', |
|
707 | - array( 'EED_Events_Archive', 'event_details' ), |
|
708 | - EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
709 | - ); |
|
706 | + 'the_content', |
|
707 | + array( 'EED_Events_Archive', 'event_details' ), |
|
708 | + EED_Events_Archive::EVENT_DETAILS_PRIORITY |
|
709 | + ); |
|
710 | 710 | remove_filter( |
711 | - 'the_content', |
|
712 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
713 | - EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
714 | - ); |
|
711 | + 'the_content', |
|
712 | + array( 'EED_Events_Archive', 'event_datetimes' ), |
|
713 | + EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
|
714 | + ); |
|
715 | 715 | remove_filter( |
716 | - 'the_content', |
|
717 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
718 | - EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
719 | - ); |
|
716 | + 'the_content', |
|
717 | + array( 'EED_Events_Archive', 'event_tickets' ), |
|
718 | + EED_Events_Archive::EVENT_TICKETS_PRIORITY |
|
719 | + ); |
|
720 | 720 | remove_filter( |
721 | - 'the_content', |
|
722 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
723 | - EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
724 | - ); |
|
721 | + 'the_content', |
|
722 | + array( 'EED_Events_Archive', 'event_venues' ), |
|
723 | + EED_Events_Archive::EVENT_VENUES_PRIORITY |
|
724 | + ); |
|
725 | 725 | // don't display entry meta because the existing theme will take care of that |
726 | 726 | remove_filter( |
727 | - 'FHEE__content_espresso_events_details_template__display_entry_meta', |
|
728 | - '__return_false' |
|
729 | - ); |
|
727 | + 'FHEE__content_espresso_events_details_template__display_entry_meta', |
|
728 | + '__return_false' |
|
729 | + ); |
|
730 | 730 | } |
731 | 731 | |
732 | 732 | |
@@ -741,7 +741,7 @@ discard block |
||
741 | 741 | * @return void |
742 | 742 | */ |
743 | 743 | public function load_event_list_assets() { |
744 | - do_action( 'AHEE__EED_Events_Archive__before_load_assets' ); |
|
744 | + do_action( 'AHEE__EED_Events_Archive__before_load_assets' ); |
|
745 | 745 | add_filter( 'FHEE_load_EE_Session', '__return_true' ); |
746 | 746 | add_filter( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true' ); |
747 | 747 | add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 ); |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton; |
4 | 4 | use EventEspresso\modules\events_archive\EventsArchiveIframe; |
5 | 5 | |
6 | -defined( 'EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed'); |
|
6 | +defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed'); |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Event List |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * @return EED_Events_Archive |
52 | 52 | */ |
53 | 53 | public static function instance() { |
54 | - return parent::get_instance( __CLASS__ ); |
|
54 | + return parent::get_instance(__CLASS__); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | 'event_list_iframe', |
81 | 81 | 'event_list' |
82 | 82 | ); |
83 | - add_action( 'wp_loaded', array( 'EED_Events_Archive', 'set_definitions' ), 2 ); |
|
83 | + add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | * @return void |
91 | 91 | */ |
92 | 92 | public static function set_hooks_admin() { |
93 | - add_action( 'wp_loaded', array( 'EED_Events_Archive', 'set_definitions' ), 2 ); |
|
93 | + add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2); |
|
94 | 94 | // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
95 | 95 | // to load assets for "espresso_events" page on the "default" route (action) |
96 | 96 | add_action( |
97 | 97 | 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default', |
98 | - array( 'EED_Events_Archive', 'event_list_iframe_embed_button' ), |
|
98 | + array('EED_Events_Archive', 'event_list_iframe_embed_button'), |
|
99 | 99 | 10 |
100 | 100 | ); |
101 | 101 | } |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | * @return void |
111 | 111 | */ |
112 | 112 | public static function set_definitions() { |
113 | - define( 'EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS ); |
|
114 | - define( 'EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS ); |
|
113 | + define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
114 | + define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | |
@@ -119,10 +119,10 @@ discard block |
||
119 | 119 | /** |
120 | 120 | * set up EE_Events_Archive_Config |
121 | 121 | */ |
122 | - protected function set_config(){ |
|
123 | - $this->set_config_section( 'template_settings' ); |
|
124 | - $this->set_config_class( 'EE_Events_Archive_Config' ); |
|
125 | - $this->set_config_name( 'EED_Events_Archive' ); |
|
122 | + protected function set_config() { |
|
123 | + $this->set_config_section('template_settings'); |
|
124 | + $this->set_config_class('EE_Events_Archive_Config'); |
|
125 | + $this->set_config_name('EED_Events_Archive'); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * @return EventListIframeEmbedButton |
132 | 132 | */ |
133 | 133 | public static function get_iframe_embed_button() { |
134 | - if ( ! self::$_iframe_embed_button instanceof EventListIframeEmbedButton ) { |
|
134 | + if ( ! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) { |
|
135 | 135 | self::$_iframe_embed_button = new EventListIframeEmbedButton(); |
136 | 136 | } |
137 | 137 | return self::$_iframe_embed_button; |
@@ -157,35 +157,35 @@ discard block |
||
157 | 157 | * @param \EE_Events_Archive_Config $config |
158 | 158 | * @return \EE_Template_Part_Manager |
159 | 159 | */ |
160 | - public function initialize_template_parts( EE_Events_Archive_Config $config = null ) { |
|
160 | + public function initialize_template_parts(EE_Events_Archive_Config $config = null) { |
|
161 | 161 | $config = $config instanceof EE_Events_Archive_Config ? $config : $this->config(); |
162 | 162 | EEH_Autoloader::instance()->register_template_part_autoloaders(); |
163 | 163 | $template_parts = new EE_Template_Part_Manager(); |
164 | 164 | $template_parts->add_template_part( |
165 | 165 | 'tickets', |
166 | - __( 'Ticket Selector', 'event_espresso' ), |
|
166 | + __('Ticket Selector', 'event_espresso'), |
|
167 | 167 | 'content-espresso_events-tickets.php', |
168 | 168 | $config->display_order_tickets |
169 | 169 | ); |
170 | 170 | $template_parts->add_template_part( |
171 | 171 | 'datetimes', |
172 | - __( 'Dates and Times', 'event_espresso' ), |
|
172 | + __('Dates and Times', 'event_espresso'), |
|
173 | 173 | 'content-espresso_events-datetimes.php', |
174 | 174 | $config->display_order_datetimes |
175 | 175 | ); |
176 | 176 | $template_parts->add_template_part( |
177 | 177 | 'event', |
178 | - __( 'Event Description', 'event_espresso' ), |
|
178 | + __('Event Description', 'event_espresso'), |
|
179 | 179 | 'content-espresso_events-details.php', |
180 | 180 | $config->display_order_event |
181 | 181 | ); |
182 | 182 | $template_parts->add_template_part( |
183 | 183 | 'venue', |
184 | - __( 'Venue Information', 'event_espresso' ), |
|
184 | + __('Venue Information', 'event_espresso'), |
|
185 | 185 | 'content-espresso_events-venues.php', |
186 | 186 | $config->display_order_venue |
187 | 187 | ); |
188 | - do_action( 'AHEE__EED_Event_Archive__initialize_template_parts', $template_parts ); |
|
188 | + do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts); |
|
189 | 189 | return $template_parts; |
190 | 190 | } |
191 | 191 | |
@@ -198,8 +198,8 @@ discard block |
||
198 | 198 | * @param WP $WP |
199 | 199 | * @return void |
200 | 200 | */ |
201 | - public function run( $WP ) { |
|
202 | - do_action( 'AHEE__EED_Events_Archive__before_run' ); |
|
201 | + public function run($WP) { |
|
202 | + do_action('AHEE__EED_Events_Archive__before_run'); |
|
203 | 203 | // ensure valid EE_Events_Archive_Config() object exists |
204 | 204 | $this->set_config(); |
205 | 205 | /** @type EE_Events_Archive_Config $config */ |
@@ -211,14 +211,14 @@ discard block |
||
211 | 211 | EEH_Event_Query::add_query_filters(); |
212 | 212 | // set params that will get used by the filters |
213 | 213 | EEH_Event_Query::set_query_params( |
214 | - '', // month |
|
215 | - '', // category |
|
216 | - $config->display_expired_events, // show_expired |
|
217 | - 'start_date', // orderby |
|
214 | + '', // month |
|
215 | + '', // category |
|
216 | + $config->display_expired_events, // show_expired |
|
217 | + 'start_date', // orderby |
|
218 | 218 | 'ASC' // sort |
219 | 219 | ); |
220 | 220 | // check what template is loaded |
221 | - add_filter( 'template_include', array( $this, 'template_include' ), 999, 1 ); |
|
221 | + add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | */ |
246 | 246 | public function event_list_iframe() { |
247 | 247 | \EED_Events_Archive::$iframe = true; |
248 | - $event_list_iframe = new EventsArchiveIframe( $this ); |
|
248 | + $event_list_iframe = new EventsArchiveIframe($this); |
|
249 | 249 | $event_list_iframe->display(); |
250 | 250 | } |
251 | 251 | |
@@ -283,42 +283,42 @@ discard block |
||
283 | 283 | * @param string $template |
284 | 284 | * @return string |
285 | 285 | */ |
286 | - public function template_include( $template = '' ) { |
|
286 | + public function template_include($template = '') { |
|
287 | 287 | // don't add content filter for dedicated EE child themes or private posts |
288 | - if ( ! EEH_Template::is_espresso_theme() ) { |
|
288 | + if ( ! EEH_Template::is_espresso_theme()) { |
|
289 | 289 | /** @type EE_Events_Archive_Config $config */ |
290 | 290 | $config = $this->config(); |
291 | 291 | // add status banner ? |
292 | - if ( $config->display_status_banner ) { |
|
293 | - add_filter( 'the_title', array( 'EED_Events_Archive', 'the_title' ), 100, 2 ); |
|
292 | + if ($config->display_status_banner) { |
|
293 | + add_filter('the_title', array('EED_Events_Archive', 'the_title'), 100, 2); |
|
294 | 294 | } |
295 | 295 | // if NOT a custom template |
296 | 296 | if ( |
297 | 297 | apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false) |
298 | 298 | || EE_Registry::instance() |
299 | - ->load_core( 'Front_Controller' ) |
|
299 | + ->load_core('Front_Controller') |
|
300 | 300 | ->get_selected_template() !== 'archive-espresso_events.php' |
301 | 301 | ) { |
302 | 302 | // don't display entry meta because the existing theme will take care of that |
303 | - add_filter( 'FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true' ); |
|
303 | + add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true'); |
|
304 | 304 | // load functions.php file for the theme (loaded by WP if using child theme) |
305 | 305 | EEH_Template::load_espresso_theme_functions(); |
306 | 306 | // because we don't know if the theme is using the_excerpt() |
307 | 307 | add_filter( |
308 | 308 | 'the_excerpt', |
309 | - array( 'EED_Events_Archive', 'event_details' ), |
|
309 | + array('EED_Events_Archive', 'event_details'), |
|
310 | 310 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
311 | 311 | ); |
312 | 312 | // or the_content |
313 | 313 | add_filter( |
314 | 314 | 'the_content', |
315 | - array( 'EED_Events_Archive', 'event_details' ), |
|
315 | + array('EED_Events_Archive', 'event_details'), |
|
316 | 316 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
317 | 317 | ); |
318 | 318 | // and just in case they are running get_the_excerpt() which DESTROYS things |
319 | - add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 ); |
|
319 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
320 | 320 | // don't display entry meta because the existing theme will take care of that |
321 | - add_filter( 'FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false' ); |
|
321 | + add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
322 | 322 | } |
323 | 323 | } |
324 | 324 | return $template; |
@@ -333,25 +333,25 @@ discard block |
||
333 | 333 | * @param string $excerpt |
334 | 334 | * @return string |
335 | 335 | */ |
336 | - public static function get_the_excerpt( $excerpt = '' ) { |
|
337 | - if ( post_password_required() ) { |
|
336 | + public static function get_the_excerpt($excerpt = '') { |
|
337 | + if (post_password_required()) { |
|
338 | 338 | return $excerpt; |
339 | 339 | } |
340 | - if ( apply_filters( 'FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false ) ) { |
|
340 | + if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) { |
|
341 | 341 | remove_filter( |
342 | 342 | 'the_excerpt', |
343 | - array( 'EED_Events_Archive', 'event_details' ), |
|
343 | + array('EED_Events_Archive', 'event_details'), |
|
344 | 344 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
345 | 345 | ); |
346 | 346 | remove_filter( |
347 | 347 | 'the_content', |
348 | - array( 'EED_Events_Archive', 'event_details' ), |
|
348 | + array('EED_Events_Archive', 'event_details'), |
|
349 | 349 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
350 | 350 | ); |
351 | - $excerpt = EED_Events_Archive::event_details( $excerpt ); |
|
351 | + $excerpt = EED_Events_Archive::event_details($excerpt); |
|
352 | 352 | } else { |
353 | 353 | EED_Events_Archive::$using_get_the_excerpt = true; |
354 | - add_filter( 'wp_trim_excerpt', array( 'EED_Events_Archive', 'end_get_the_excerpt' ), 999, 1 ); |
|
354 | + add_filter('wp_trim_excerpt', array('EED_Events_Archive', 'end_get_the_excerpt'), 999, 1); |
|
355 | 355 | } |
356 | 356 | return $excerpt; |
357 | 357 | } |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | * @param string $text |
366 | 366 | * @return string |
367 | 367 | */ |
368 | - public static function end_get_the_excerpt( $text = '' ) { |
|
368 | + public static function end_get_the_excerpt($text = '') { |
|
369 | 369 | EED_Events_Archive::$using_get_the_excerpt = false; |
370 | 370 | return $text; |
371 | 371 | } |
@@ -380,10 +380,10 @@ discard block |
||
380 | 380 | * @param string $id |
381 | 381 | * @return string |
382 | 382 | */ |
383 | - public static function the_title( $title = '', $id = '' ) { |
|
383 | + public static function the_title($title = '', $id = '') { |
|
384 | 384 | global $post; |
385 | - if ( $post instanceof WP_Post ) { |
|
386 | - return in_the_loop() && $post->ID == $id ? espresso_event_status_banner( $post->ID ) . $title : $title; |
|
385 | + if ($post instanceof WP_Post) { |
|
386 | + return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID).$title : $title; |
|
387 | 387 | } |
388 | 388 | return $title; |
389 | 389 | } |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | * @param string $content |
398 | 398 | * @return string |
399 | 399 | */ |
400 | - public static function event_details( $content ) { |
|
400 | + public static function event_details($content) { |
|
401 | 401 | global $post; |
402 | 402 | static $current_post_ID = 0; |
403 | 403 | if ( |
@@ -406,8 +406,8 @@ discard block |
||
406 | 406 | && ! EED_Events_Archive::$using_get_the_excerpt |
407 | 407 | && ! post_password_required() |
408 | 408 | && ( |
409 | - apply_filters( 'FHEE__EES_Espresso_Events__process_shortcode__true', false ) |
|
410 | - || ! apply_filters( 'FHEE__content_espresso_events__template_loaded', false ) |
|
409 | + apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false) |
|
410 | + || ! apply_filters('FHEE__content_espresso_events__template_loaded', false) |
|
411 | 411 | ) |
412 | 412 | ) { |
413 | 413 | // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | // We want to allow those plugins to still do their thing and have access to our content, but depending on |
417 | 417 | // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
418 | 418 | // so the following allows this filter to be applied multiple times, but only once for real |
419 | - $current_post_ID = did_action( 'loop_start' ) ? $post->ID : 0; |
|
420 | - if ( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order ) { |
|
419 | + $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
420 | + if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) { |
|
421 | 421 | $content = \EED_Events_Archive::use_sortable_display_order(); |
422 | 422 | } else { |
423 | 423 | $content = \EED_Events_Archive::use_filterable_display_order(); |
@@ -436,36 +436,36 @@ discard block |
||
436 | 436 | */ |
437 | 437 | protected static function use_sortable_display_order() { |
438 | 438 | // no further password checks required atm |
439 | - add_filter( 'FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true' ); |
|
439 | + add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true'); |
|
440 | 440 | // we need to first remove this callback from being applied to the_content() or the_excerpt() |
441 | 441 | // (otherwise it will recurse and blow up the interweb) |
442 | 442 | remove_filter( |
443 | 443 | 'the_excerpt', |
444 | - array( 'EED_Events_Archive', 'event_details' ), |
|
444 | + array('EED_Events_Archive', 'event_details'), |
|
445 | 445 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
446 | 446 | ); |
447 | 447 | remove_filter( |
448 | 448 | 'the_content', |
449 | - array( 'EED_Events_Archive', 'event_details' ), |
|
449 | + array('EED_Events_Archive', 'event_details'), |
|
450 | 450 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
451 | 451 | ); |
452 | - remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
|
452 | + remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
453 | 453 | // now add additional content depending on whether event is using the_excerpt() or the_content() |
454 | 454 | EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts(); |
455 | - $content = EEH_Template::locate_template( 'content-espresso_events-details.php' ); |
|
456 | - $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters( $content ); |
|
455 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
456 | + $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content); |
|
457 | 457 | // re-add our main filters (or else the next event won't have them) |
458 | 458 | add_filter( |
459 | 459 | 'the_excerpt', |
460 | - array( 'EED_Events_Archive', 'event_details' ), |
|
460 | + array('EED_Events_Archive', 'event_details'), |
|
461 | 461 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
462 | 462 | ); |
463 | 463 | add_filter( |
464 | 464 | 'the_content', |
465 | - array( 'EED_Events_Archive', 'event_details' ), |
|
465 | + array('EED_Events_Archive', 'event_details'), |
|
466 | 466 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
467 | 467 | ); |
468 | - add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 ); |
|
468 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
469 | 469 | remove_filter( |
470 | 470 | 'FHEE__EED_Events_Archive__event_details__no_post_password_required', |
471 | 471 | '__return_true' |
@@ -486,36 +486,36 @@ discard block |
||
486 | 486 | // (otherwise it will recurse and blow up the interweb) |
487 | 487 | remove_filter( |
488 | 488 | 'the_excerpt', |
489 | - array( 'EED_Events_Archive', 'event_details' ), |
|
489 | + array('EED_Events_Archive', 'event_details'), |
|
490 | 490 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
491 | 491 | ); |
492 | 492 | remove_filter( |
493 | 493 | 'the_content', |
494 | - array( 'EED_Events_Archive', 'event_details' ), |
|
494 | + array('EED_Events_Archive', 'event_details'), |
|
495 | 495 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
496 | 496 | ); |
497 | - remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
|
497 | + remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1); |
|
498 | 498 | //now add additional content depending on whether event is using the_excerpt() or the_content() |
499 | 499 | EED_Events_Archive::_add_additional_excerpt_filters(); |
500 | 500 | EED_Events_Archive::_add_additional_content_filters(); |
501 | - do_action( 'AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters' ); |
|
501 | + do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters'); |
|
502 | 502 | // now load our template |
503 | - $content = EEH_Template::locate_template( 'content-espresso_events-details.php' ); |
|
503 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
504 | 504 | // re-add our main filters (or else the next event won't have them) |
505 | 505 | add_filter( |
506 | 506 | 'the_excerpt', |
507 | - array( 'EED_Events_Archive', 'event_details' ), |
|
507 | + array('EED_Events_Archive', 'event_details'), |
|
508 | 508 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
509 | 509 | ); |
510 | 510 | add_filter( |
511 | 511 | 'the_content', |
512 | - array( 'EED_Events_Archive', 'event_details' ), |
|
512 | + array('EED_Events_Archive', 'event_details'), |
|
513 | 513 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
514 | 514 | ); |
515 | - add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 ); |
|
515 | + add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1); |
|
516 | 516 | // but remove the other filters so that they don't get applied to the next post |
517 | 517 | EED_Events_Archive::_remove_additional_events_archive_filters(); |
518 | - do_action( 'AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters' ); |
|
518 | + do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters'); |
|
519 | 519 | // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
520 | 520 | //return ! empty( $template ) ? $template : $content; |
521 | 521 | return $content; |
@@ -530,11 +530,11 @@ discard block |
||
530 | 530 | * @param string $content |
531 | 531 | * @return string |
532 | 532 | */ |
533 | - public static function event_datetimes( $content ) { |
|
534 | - if ( post_password_required() ) { |
|
533 | + public static function event_datetimes($content) { |
|
534 | + if (post_password_required()) { |
|
535 | 535 | return $content; |
536 | 536 | } |
537 | - return EEH_Template::locate_template( 'content-espresso_events-datetimes.php' ) . $content; |
|
537 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content; |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | /** |
@@ -544,11 +544,11 @@ discard block |
||
544 | 544 | * @param string $content |
545 | 545 | * @return string |
546 | 546 | */ |
547 | - public static function event_tickets( $content ) { |
|
548 | - if ( post_password_required() ) { |
|
547 | + public static function event_tickets($content) { |
|
548 | + if (post_password_required()) { |
|
549 | 549 | return $content; |
550 | 550 | } |
551 | - return EEH_Template::locate_template( 'content-espresso_events-tickets.php' ) . $content; |
|
551 | + return EEH_Template::locate_template('content-espresso_events-tickets.php').$content; |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | |
@@ -560,8 +560,8 @@ discard block |
||
560 | 560 | * @param string $content |
561 | 561 | * @return string |
562 | 562 | */ |
563 | - public static function event_venue( $content ) { |
|
564 | - return EED_Events_Archive::event_venues( $content ); |
|
563 | + public static function event_venue($content) { |
|
564 | + return EED_Events_Archive::event_venues($content); |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | /** |
@@ -571,11 +571,11 @@ discard block |
||
571 | 571 | * @param string $content |
572 | 572 | * @return string |
573 | 573 | */ |
574 | - public static function event_venues( $content ) { |
|
575 | - if ( post_password_required() ) { |
|
574 | + public static function event_venues($content) { |
|
575 | + if (post_password_required()) { |
|
576 | 576 | return $content; |
577 | 577 | } |
578 | - return $content . EEH_Template::locate_template( 'content-espresso_events-venues.php' ); |
|
578 | + return $content.EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | |
@@ -589,17 +589,17 @@ discard block |
||
589 | 589 | private static function _add_additional_excerpt_filters() { |
590 | 590 | add_filter( |
591 | 591 | 'the_excerpt', |
592 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
592 | + array('EED_Events_Archive', 'event_datetimes'), |
|
593 | 593 | EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
594 | 594 | ); |
595 | 595 | add_filter( |
596 | 596 | 'the_excerpt', |
597 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
597 | + array('EED_Events_Archive', 'event_tickets'), |
|
598 | 598 | EED_Events_Archive::EVENT_TICKETS_PRIORITY |
599 | 599 | ); |
600 | 600 | add_filter( |
601 | 601 | 'the_excerpt', |
602 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
602 | + array('EED_Events_Archive', 'event_venues'), |
|
603 | 603 | EED_Events_Archive::EVENT_VENUES_PRIORITY |
604 | 604 | ); |
605 | 605 | } |
@@ -615,17 +615,17 @@ discard block |
||
615 | 615 | private static function _add_additional_content_filters() { |
616 | 616 | add_filter( |
617 | 617 | 'the_content', |
618 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
618 | + array('EED_Events_Archive', 'event_datetimes'), |
|
619 | 619 | EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
620 | 620 | ); |
621 | 621 | add_filter( |
622 | 622 | 'the_content', |
623 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
623 | + array('EED_Events_Archive', 'event_tickets'), |
|
624 | 624 | EED_Events_Archive::EVENT_TICKETS_PRIORITY |
625 | 625 | ); |
626 | 626 | add_filter( |
627 | 627 | 'the_content', |
628 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
628 | + array('EED_Events_Archive', 'event_venues'), |
|
629 | 629 | EED_Events_Archive::EVENT_VENUES_PRIORITY |
630 | 630 | ); |
631 | 631 | } |
@@ -641,32 +641,32 @@ discard block |
||
641 | 641 | private static function _remove_additional_events_archive_filters() { |
642 | 642 | remove_filter( |
643 | 643 | 'the_excerpt', |
644 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
644 | + array('EED_Events_Archive', 'event_datetimes'), |
|
645 | 645 | EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
646 | 646 | ); |
647 | 647 | remove_filter( |
648 | 648 | 'the_excerpt', |
649 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
649 | + array('EED_Events_Archive', 'event_tickets'), |
|
650 | 650 | EED_Events_Archive::EVENT_TICKETS_PRIORITY |
651 | 651 | ); |
652 | 652 | remove_filter( |
653 | 653 | 'the_excerpt', |
654 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
654 | + array('EED_Events_Archive', 'event_venues'), |
|
655 | 655 | EED_Events_Archive::EVENT_VENUES_PRIORITY |
656 | 656 | ); |
657 | 657 | remove_filter( |
658 | 658 | 'the_content', |
659 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
659 | + array('EED_Events_Archive', 'event_datetimes'), |
|
660 | 660 | EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
661 | 661 | ); |
662 | 662 | remove_filter( |
663 | 663 | 'the_content', |
664 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
664 | + array('EED_Events_Archive', 'event_tickets'), |
|
665 | 665 | EED_Events_Archive::EVENT_TICKETS_PRIORITY |
666 | 666 | ); |
667 | 667 | remove_filter( |
668 | 668 | 'the_content', |
669 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
669 | + array('EED_Events_Archive', 'event_venues'), |
|
670 | 670 | EED_Events_Archive::EVENT_VENUES_PRIORITY |
671 | 671 | ); |
672 | 672 | } |
@@ -681,45 +681,45 @@ discard block |
||
681 | 681 | */ |
682 | 682 | public static function remove_all_events_archive_filters() { |
683 | 683 | //remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 ); |
684 | - remove_filter( 'the_title', array( 'EED_Events_Archive', 'the_title' ), 1 ); |
|
684 | + remove_filter('the_title', array('EED_Events_Archive', 'the_title'), 1); |
|
685 | 685 | remove_filter( |
686 | 686 | 'the_excerpt', |
687 | - array( 'EED_Events_Archive', 'event_details' ), |
|
687 | + array('EED_Events_Archive', 'event_details'), |
|
688 | 688 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
689 | 689 | ); |
690 | 690 | remove_filter( |
691 | 691 | 'the_excerpt', |
692 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
692 | + array('EED_Events_Archive', 'event_datetimes'), |
|
693 | 693 | EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
694 | 694 | ); |
695 | 695 | remove_filter( |
696 | 696 | 'the_excerpt', |
697 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
697 | + array('EED_Events_Archive', 'event_tickets'), |
|
698 | 698 | EED_Events_Archive::EVENT_TICKETS_PRIORITY |
699 | 699 | ); |
700 | 700 | remove_filter( |
701 | 701 | 'the_excerpt', |
702 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
702 | + array('EED_Events_Archive', 'event_venues'), |
|
703 | 703 | EED_Events_Archive::EVENT_VENUES_PRIORITY |
704 | 704 | ); |
705 | 705 | remove_filter( |
706 | 706 | 'the_content', |
707 | - array( 'EED_Events_Archive', 'event_details' ), |
|
707 | + array('EED_Events_Archive', 'event_details'), |
|
708 | 708 | EED_Events_Archive::EVENT_DETAILS_PRIORITY |
709 | 709 | ); |
710 | 710 | remove_filter( |
711 | 711 | 'the_content', |
712 | - array( 'EED_Events_Archive', 'event_datetimes' ), |
|
712 | + array('EED_Events_Archive', 'event_datetimes'), |
|
713 | 713 | EED_Events_Archive::EVENT_DATETIMES_PRIORITY |
714 | 714 | ); |
715 | 715 | remove_filter( |
716 | 716 | 'the_content', |
717 | - array( 'EED_Events_Archive', 'event_tickets' ), |
|
717 | + array('EED_Events_Archive', 'event_tickets'), |
|
718 | 718 | EED_Events_Archive::EVENT_TICKETS_PRIORITY |
719 | 719 | ); |
720 | 720 | remove_filter( |
721 | 721 | 'the_content', |
722 | - array( 'EED_Events_Archive', 'event_venues' ), |
|
722 | + array('EED_Events_Archive', 'event_venues'), |
|
723 | 723 | EED_Events_Archive::EVENT_VENUES_PRIORITY |
724 | 724 | ); |
725 | 725 | // don't display entry meta because the existing theme will take care of that |
@@ -741,12 +741,12 @@ discard block |
||
741 | 741 | * @return void |
742 | 742 | */ |
743 | 743 | public function load_event_list_assets() { |
744 | - do_action( 'AHEE__EED_Events_Archive__before_load_assets' ); |
|
745 | - add_filter( 'FHEE_load_EE_Session', '__return_true' ); |
|
746 | - add_filter( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true' ); |
|
747 | - add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 ); |
|
748 | - if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) { |
|
749 | - add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 ); |
|
744 | + do_action('AHEE__EED_Events_Archive__before_load_assets'); |
|
745 | + add_filter('FHEE_load_EE_Session', '__return_true'); |
|
746 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
747 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
748 | + if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
749 | + add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
750 | 750 | } |
751 | 751 | } |
752 | 752 | |
@@ -763,13 +763,13 @@ discard block |
||
763 | 763 | */ |
764 | 764 | public function wp_enqueue_scripts() { |
765 | 765 | // get some style |
766 | - if ( apply_filters( 'FHEE_enable_default_espresso_css', FALSE ) ) { |
|
766 | + if (apply_filters('FHEE_enable_default_espresso_css', FALSE)) { |
|
767 | 767 | // first check uploads folder |
768 | - if ( EEH_File::is_readable( get_stylesheet_directory() . $this->theme . DS . 'style.css' )) { |
|
769 | - wp_register_style( $this->theme, get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', array( 'dashicons', 'espresso_default' )); |
|
768 | + if (EEH_File::is_readable(get_stylesheet_directory().$this->theme.DS.'style.css')) { |
|
769 | + wp_register_style($this->theme, get_stylesheet_directory_uri().$this->theme.DS.'style.css', array('dashicons', 'espresso_default')); |
|
770 | 770 | } else { |
771 | 771 | } |
772 | - wp_enqueue_style( $this->theme ); |
|
772 | + wp_enqueue_style($this->theme); |
|
773 | 773 | |
774 | 774 | } |
775 | 775 | } |
@@ -787,8 +787,8 @@ discard block |
||
787 | 787 | */ |
788 | 788 | public static function template_settings_form() { |
789 | 789 | $template_settings = EE_Registry::instance()->CFG->template_settings; |
790 | - $template_settings->EED_Events_Archive = isset( $template_settings->EED_Events_Archive ) ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config(); |
|
791 | - $template_settings->EED_Events_Archive = apply_filters( 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', $template_settings->EED_Events_Archive ); |
|
790 | + $template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive) ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config(); |
|
791 | + $template_settings->EED_Events_Archive = apply_filters('FHEE__EED_Events_Archive__template_settings_form__event_list_config', $template_settings->EED_Events_Archive); |
|
792 | 792 | $events_archive_settings = array( |
793 | 793 | 'display_status_banner' => 0, |
794 | 794 | 'display_description' => 1, |
@@ -797,8 +797,8 @@ discard block |
||
797 | 797 | 'display_venue' => 0, |
798 | 798 | 'display_expired_events' => 0 |
799 | 799 | ); |
800 | - $events_archive_settings = array_merge( $events_archive_settings, (array)$template_settings->EED_Events_Archive ); |
|
801 | - EEH_Template::display_template( EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $events_archive_settings ); |
|
800 | + $events_archive_settings = array_merge($events_archive_settings, (array) $template_settings->EED_Events_Archive); |
|
801 | + EEH_Template::display_template(EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php', $events_archive_settings); |
|
802 | 802 | } |
803 | 803 | |
804 | 804 | |
@@ -814,16 +814,16 @@ discard block |
||
814 | 814 | * @param EE_Request_Handler $REQ |
815 | 815 | * @return EE_Template_Config |
816 | 816 | */ |
817 | - public static function update_template_settings( $CFG, $REQ ) { |
|
817 | + public static function update_template_settings($CFG, $REQ) { |
|
818 | 818 | $CFG->EED_Events_Archive = new EE_Events_Archive_Config(); |
819 | 819 | // unless we are resetting the config... |
820 | - if ( ! isset( $REQ['EED_Events_Archive_reset_event_list_settings'] ) || absint( $REQ['EED_Events_Archive_reset_event_list_settings'] ) !== 1 ) { |
|
821 | - $CFG->EED_Events_Archive->display_status_banner = isset( $REQ['EED_Events_Archive_display_status_banner'] ) ? absint( $REQ['EED_Events_Archive_display_status_banner'] ) : 0; |
|
822 | - $CFG->EED_Events_Archive->display_description = isset( $REQ['EED_Events_Archive_display_description'] ) ? absint( $REQ['EED_Events_Archive_display_description'] ) : 1; |
|
823 | - $CFG->EED_Events_Archive->display_ticket_selector = isset( $REQ['EED_Events_Archive_display_ticket_selector'] ) ? absint( $REQ['EED_Events_Archive_display_ticket_selector'] ) : 0; |
|
824 | - $CFG->EED_Events_Archive->display_datetimes = isset( $REQ['EED_Events_Archive_display_datetimes'] ) ? absint( $REQ['EED_Events_Archive_display_datetimes'] ) : 1; |
|
825 | - $CFG->EED_Events_Archive->display_venue = isset( $REQ['EED_Events_Archive_display_venue'] ) ? absint( $REQ['EED_Events_Archive_display_venue'] ) : 0; |
|
826 | - $CFG->EED_Events_Archive->display_expired_events = isset( $REQ['EED_Events_Archive_display_expired_events'] ) ? absint( $REQ['EED_Events_Archive_display_expired_events'] ) : 0; } |
|
820 | + if ( ! isset($REQ['EED_Events_Archive_reset_event_list_settings']) || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1) { |
|
821 | + $CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0; |
|
822 | + $CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description']) ? absint($REQ['EED_Events_Archive_display_description']) : 1; |
|
823 | + $CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0; |
|
824 | + $CFG->EED_Events_Archive->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint($REQ['EED_Events_Archive_display_datetimes']) : 1; |
|
825 | + $CFG->EED_Events_Archive->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint($REQ['EED_Events_Archive_display_venue']) : 0; |
|
826 | + $CFG->EED_Events_Archive->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events']) ? absint($REQ['EED_Events_Archive_display_expired_events']) : 0; } |
|
827 | 827 | return $CFG; |
828 | 828 | } |
829 | 829 | |
@@ -836,10 +836,10 @@ discard block |
||
836 | 836 | * @param string $extra_class |
837 | 837 | * @return string |
838 | 838 | */ |
839 | - public static function event_list_css( $extra_class = '' ) { |
|
840 | - $event_list_css = ! empty( $extra_class ) ? array( $extra_class ) : array(); |
|
839 | + public static function event_list_css($extra_class = '') { |
|
840 | + $event_list_css = ! empty($extra_class) ? array($extra_class) : array(); |
|
841 | 841 | $event_list_css[] = 'espresso-event-list-event'; |
842 | - return implode( ' ', $event_list_css ); |
|
842 | + return implode(' ', $event_list_css); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | |
@@ -866,9 +866,9 @@ discard block |
||
866 | 866 | * @param $value |
867 | 867 | * @return bool |
868 | 868 | */ |
869 | - public static function display_description( $value ) { |
|
869 | + public static function display_description($value) { |
|
870 | 870 | $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
871 | - $display_description= isset( $config->display_description ) ? $config->display_description : 1; |
|
871 | + $display_description = isset($config->display_description) ? $config->display_description : 1; |
|
872 | 872 | return $display_description === $value ? TRUE : FALSE; |
873 | 873 | } |
874 | 874 | |
@@ -881,7 +881,7 @@ discard block |
||
881 | 881 | */ |
882 | 882 | public static function display_ticket_selector() { |
883 | 883 | $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
884 | - return isset( $config->display_ticket_selector ) && $config->display_ticket_selector ? TRUE : FALSE; |
|
884 | + return isset($config->display_ticket_selector) && $config->display_ticket_selector ? TRUE : FALSE; |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | |
@@ -894,7 +894,7 @@ discard block |
||
894 | 894 | */ |
895 | 895 | public static function display_venue() { |
896 | 896 | $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
897 | - return isset( $config->display_venue ) && $config->display_venue && EEH_Venue_View::venue_name() ? TRUE : FALSE; |
|
897 | + return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name() ? TRUE : FALSE; |
|
898 | 898 | } |
899 | 899 | |
900 | 900 | |
@@ -906,7 +906,7 @@ discard block |
||
906 | 906 | */ |
907 | 907 | public static function display_datetimes() { |
908 | 908 | $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive; |
909 | - return isset( $config->display_datetimes ) && $config->display_datetimes ? TRUE : FALSE; |
|
909 | + return isset($config->display_datetimes) && $config->display_datetimes ? TRUE : FALSE; |
|
910 | 910 | } |
911 | 911 | |
912 | 912 | |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | * @return string |
922 | 922 | */ |
923 | 923 | public static function event_list_title() { |
924 | - return apply_filters( 'FHEE__archive_espresso_events_template__upcoming_events_h1', __( 'Upcoming Events', 'event_espresso' )); |
|
924 | + return apply_filters('FHEE__archive_espresso_events_template__upcoming_events_h1', __('Upcoming Events', 'event_espresso')); |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | |
@@ -930,11 +930,11 @@ discard block |
||
930 | 930 | /** |
931 | 931 | * @since 4.4.0 |
932 | 932 | */ |
933 | - public static function _doing_it_wrong_notice( $function = '' ) { |
|
933 | + public static function _doing_it_wrong_notice($function = '') { |
|
934 | 934 | EE_Error::doing_it_wrong( |
935 | 935 | __FUNCTION__, |
936 | 936 | sprintf( |
937 | - __( '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', 'event_espresso' ), |
|
937 | + __('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', 'event_espresso'), |
|
938 | 938 | $function, |
939 | 939 | '<br />', |
940 | 940 | '4.6.0' |
@@ -956,89 +956,89 @@ discard block |
||
956 | 956 | * @deprecated |
957 | 957 | * @since 4.4.0 |
958 | 958 | */ |
959 | - public function posts_fields( $SQL, WP_Query $wp_query ) { |
|
960 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
961 | - return EEH_Event_Query::posts_fields( $SQL, $wp_query ); |
|
959 | + public function posts_fields($SQL, WP_Query $wp_query) { |
|
960 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
961 | + return EEH_Event_Query::posts_fields($SQL, $wp_query); |
|
962 | 962 | } |
963 | 963 | /** |
964 | 964 | * @deprecated |
965 | 965 | * @since 4.4.0 |
966 | 966 | */ |
967 | - public static function posts_fields_sql_for_orderby( $orderby_params = array() ) { |
|
968 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
969 | - return EEH_Event_Query::posts_fields_sql_for_orderby( $orderby_params ); |
|
967 | + public static function posts_fields_sql_for_orderby($orderby_params = array()) { |
|
968 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
969 | + return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params); |
|
970 | 970 | } |
971 | 971 | /** |
972 | 972 | * @deprecated |
973 | 973 | * @since 4.4.0 |
974 | 974 | */ |
975 | - public function posts_join( $SQL, WP_Query $wp_query ) { |
|
976 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
977 | - return EEH_Event_Query::posts_join( $SQL, $wp_query ); |
|
975 | + public function posts_join($SQL, WP_Query $wp_query) { |
|
976 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
977 | + return EEH_Event_Query::posts_join($SQL, $wp_query); |
|
978 | 978 | } |
979 | 979 | /** |
980 | 980 | * @deprecated |
981 | 981 | * @since 4.4.0 |
982 | 982 | */ |
983 | - public static function posts_join_sql_for_terms( $join_terms = NULL ) { |
|
984 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
985 | - return EEH_Event_Query::posts_join_sql_for_terms( $join_terms ); |
|
983 | + public static function posts_join_sql_for_terms($join_terms = NULL) { |
|
984 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
985 | + return EEH_Event_Query::posts_join_sql_for_terms($join_terms); |
|
986 | 986 | } |
987 | 987 | /** |
988 | 988 | * @deprecated |
989 | 989 | * @since 4.4.0 |
990 | 990 | */ |
991 | - public static function posts_join_for_orderby( $orderby_params = array() ) { |
|
992 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
993 | - return EEH_Event_Query::posts_join_for_orderby( $orderby_params ); |
|
991 | + public static function posts_join_for_orderby($orderby_params = array()) { |
|
992 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
993 | + return EEH_Event_Query::posts_join_for_orderby($orderby_params); |
|
994 | 994 | } |
995 | 995 | /** |
996 | 996 | * @deprecated |
997 | 997 | * @since 4.4.0 |
998 | 998 | */ |
999 | - public function posts_where( $SQL, WP_Query $wp_query ) { |
|
1000 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
1001 | - return EEH_Event_Query::posts_where( $SQL, $wp_query ); |
|
999 | + public function posts_where($SQL, WP_Query $wp_query) { |
|
1000 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1001 | + return EEH_Event_Query::posts_where($SQL, $wp_query); |
|
1002 | 1002 | } |
1003 | 1003 | /** |
1004 | 1004 | * @deprecated |
1005 | 1005 | * @since 4.4.0 |
1006 | 1006 | */ |
1007 | - public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) { |
|
1008 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
1009 | - return EEH_Event_Query::posts_where_sql_for_show_expired( $show_expired ); |
|
1007 | + public static function posts_where_sql_for_show_expired($show_expired = FALSE) { |
|
1008 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1009 | + return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired); |
|
1010 | 1010 | } |
1011 | 1011 | /** |
1012 | 1012 | * @deprecated |
1013 | 1013 | * @since 4.4.0 |
1014 | 1014 | */ |
1015 | - public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) { |
|
1016 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
1017 | - return EEH_Event_Query::posts_where_sql_for_event_category_slug( $event_category_slug ); |
|
1015 | + public static function posts_where_sql_for_event_category_slug($event_category_slug = NULL) { |
|
1016 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1017 | + return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug); |
|
1018 | 1018 | } |
1019 | 1019 | /** |
1020 | 1020 | * @deprecated |
1021 | 1021 | * @since 4.4.0 |
1022 | 1022 | */ |
1023 | - public static function posts_where_sql_for_event_list_month( $month = NULL ) { |
|
1024 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
1025 | - return EEH_Event_Query::posts_where_sql_for_event_list_month( $month ); |
|
1023 | + public static function posts_where_sql_for_event_list_month($month = NULL) { |
|
1024 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1025 | + return EEH_Event_Query::posts_where_sql_for_event_list_month($month); |
|
1026 | 1026 | } |
1027 | 1027 | /** |
1028 | 1028 | * @deprecated |
1029 | 1029 | * @since 4.4.0 |
1030 | 1030 | */ |
1031 | - public function posts_orderby( $SQL, WP_Query $wp_query ) { |
|
1032 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
1033 | - return EEH_Event_Query::posts_orderby( $SQL, $wp_query ); |
|
1031 | + public function posts_orderby($SQL, WP_Query $wp_query) { |
|
1032 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1033 | + return EEH_Event_Query::posts_orderby($SQL, $wp_query); |
|
1034 | 1034 | } |
1035 | 1035 | /** |
1036 | 1036 | * @deprecated |
1037 | 1037 | * @since 4.4.0 |
1038 | 1038 | */ |
1039 | - public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) { |
|
1040 | - EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ ); |
|
1041 | - return EEH_Event_Query::posts_orderby_sql( $orderby_params, $sort ); |
|
1039 | + public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') { |
|
1040 | + EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__); |
|
1041 | + return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort); |
|
1042 | 1042 | } |
1043 | 1043 | |
1044 | 1044 | |
@@ -1069,8 +1069,8 @@ discard block |
||
1069 | 1069 | * @param string $extra_class |
1070 | 1070 | * @return string |
1071 | 1071 | */ |
1072 | -function espresso_event_list_css( $extra_class = '' ) { |
|
1073 | - return EED_Events_Archive::event_list_css( $extra_class ); |
|
1072 | +function espresso_event_list_css($extra_class = '') { |
|
1073 | + return EED_Events_Archive::event_list_css($extra_class); |
|
1074 | 1074 | } |
1075 | 1075 | |
1076 | 1076 | /** |
@@ -1084,14 +1084,14 @@ discard block |
||
1084 | 1084 | * @return bool |
1085 | 1085 | */ |
1086 | 1086 | function espresso_display_full_description_in_event_list() { |
1087 | - return EED_Events_Archive::display_description( 2 ); |
|
1087 | + return EED_Events_Archive::display_description(2); |
|
1088 | 1088 | } |
1089 | 1089 | |
1090 | 1090 | /** |
1091 | 1091 | * @return bool |
1092 | 1092 | */ |
1093 | 1093 | function espresso_display_excerpt_in_event_list() { |
1094 | - return EED_Events_Archive::display_description( 1 ); |
|
1094 | + return EED_Events_Archive::display_description(1); |
|
1095 | 1095 | } |
1096 | 1096 | |
1097 | 1097 | /** |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -14,604 +14,604 @@ discard block |
||
14 | 14 | class EE_Register_CPTs |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * This property is used to hold an array of EE_default_term objects assigned to a custom post type when the post |
|
19 | - * for that post type is published with no terms set for the taxonomy. |
|
20 | - * |
|
21 | - * @var array of EE_Default_Term objects |
|
22 | - */ |
|
23 | - protected $_default_terms = array(); |
|
24 | - |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * constructor |
|
29 | - * instantiated at init priority 5 |
|
30 | - */ |
|
31 | - public function __construct() |
|
32 | - { |
|
33 | - // register taxonomies |
|
34 | - $taxonomies = self::get_taxonomies(); |
|
35 | - foreach ($taxonomies as $taxonomy => $tax) { |
|
36 | - $this->register_taxonomy($taxonomy, $tax['singular_name'], $tax['plural_name'], $tax['args']); |
|
37 | - } |
|
38 | - // register CPTs |
|
39 | - $CPTs = self::get_CPTs(); |
|
40 | - foreach ($CPTs as $CPT_name => $CPT) { |
|
41 | - $this->register_CPT($CPT_name, $CPT['singular_name'], $CPT['plural_name'], $CPT['args'], |
|
42 | - $CPT['singular_slug'], $CPT['plural_slug']); |
|
43 | - } |
|
44 | - // setup default terms in any of our taxonomies (but only if we're in admin). |
|
45 | - // Why not added via register_activation_hook? |
|
46 | - // Because it's possible that in future iterations of EE we may add new defaults for specialized taxonomies |
|
47 | - // (think event_types) and register_activation_hook only reliably runs when a user manually activates the plugin. |
|
48 | - // Keep in mind that this will READ these terms if they are deleted by the user. Hence MUST use terms. |
|
49 | - // if ( is_admin() ) { |
|
50 | - // $this->set_must_use_event_types(); |
|
51 | - // } |
|
52 | - //set default terms |
|
53 | - $this->set_default_term('espresso_event_type', 'single-event', array('espresso_events')); |
|
54 | - add_action('AHEE__EE_System__initialize_last', array(__CLASS__, 'maybe_flush_rewrite_rules'), 10); |
|
55 | - // hook into save_post so that we can make sure that the default terms get saved on publish of registered cpts |
|
56 | - // IF they don't have a term for that taxonomy set. |
|
57 | - add_action('save_post', array($this, 'save_default_term'), 100, 2); |
|
58 | - // remove no html restrictions from core wp saving of term descriptions. |
|
59 | - // Note. this will affect only registered EE taxonomies. |
|
60 | - $this->_allow_html_descriptions_for_ee_taxonomies(); |
|
61 | - do_action('AHEE__EE_Register_CPTs__construct_end', $this); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * This will flush rewrite rules on demand. This actually gets called around wp init priority level 100. |
|
68 | - * |
|
69 | - * @since 4.5.0 |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public static function maybe_flush_rewrite_rules() |
|
73 | - { |
|
74 | - if (get_option('ee_flush_rewrite_rules', true)) { |
|
75 | - flush_rewrite_rules(); |
|
76 | - update_option('ee_flush_rewrite_rules', false); |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * By default, WordPress strips all html from term taxonomy description content. The purpose of this method is to |
|
84 | - * remove that restriction and ensure that we still run ee term taxonomy descriptions through some full html |
|
85 | - * sanitization equivalent to the post content field. |
|
86 | - * |
|
87 | - * @since 4.7.8 |
|
88 | - */ |
|
89 | - protected function _allow_html_descriptions_for_ee_taxonomies() |
|
90 | - { |
|
91 | - // first remove default filter for term description but we have to do this earlier |
|
92 | - // before wp sets their own filter |
|
93 | - // because they just set a global filter on all term descriptions before the custom term description filter. |
|
94 | - // Really sux. |
|
95 | - add_filter('pre_term_description', array($this, 'ee_filter_ee_term_description_not_wp'), 1, 2); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * Callback for pre_term_description hook. |
|
102 | - * |
|
103 | - * @param string $description The description content. |
|
104 | - * @param string $taxonomy The taxonomy name for the taxonomy being filtered. |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function ee_filter_ee_term_description_not_wp($description, $taxonomy) |
|
108 | - { |
|
109 | - //get a list of EE taxonomies |
|
110 | - $ee_taxonomies = array_keys(self::get_taxonomies()); |
|
111 | - //only do our own thing if the taxonomy listed is an ee taxonomy. |
|
112 | - if (in_array($taxonomy, $ee_taxonomies, true)) { |
|
113 | - //remove default wp filter |
|
114 | - remove_filter('pre_term_description', 'wp_filter_kses'); |
|
115 | - //sanitize THIS content. |
|
116 | - $description = wp_kses($description, wp_kses_allowed_html('post')); |
|
117 | - } |
|
118 | - return $description; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * get_taxonomies |
|
125 | - * |
|
126 | - * @access public |
|
127 | - * @return array |
|
128 | - */ |
|
129 | - public static function get_taxonomies() |
|
130 | - { |
|
131 | - // define taxonomies |
|
132 | - return apply_filters('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array( |
|
133 | - 'espresso_event_categories' => array( |
|
134 | - 'singular_name' => __("Event Category", "event_espresso"), |
|
135 | - 'plural_name' => __("Event Categories", "event_espresso"), |
|
136 | - 'args' => array( |
|
137 | - 'public' => true, |
|
138 | - 'show_in_nav_menus' => true, |
|
139 | - 'show_in_rest' => true, |
|
140 | - 'capabilities' => array( |
|
141 | - 'manage_terms' => 'ee_manage_event_categories', |
|
142 | - 'edit_terms' => 'ee_edit_event_category', |
|
143 | - 'delete_terms' => 'ee_delete_event_category', |
|
144 | - 'assign_terms' => 'ee_assign_event_category', |
|
145 | - ), |
|
146 | - 'rewrite' => array('slug' => __('event-category', 'event_espresso')), |
|
147 | - ), |
|
148 | - ), |
|
149 | - 'espresso_venue_categories' => array( |
|
150 | - 'singular_name' => __("Venue Category", "event_espresso"), |
|
151 | - 'plural_name' => __("Venue Categories", "event_espresso"), |
|
152 | - 'args' => array( |
|
153 | - 'public' => true, |
|
154 | - 'show_in_nav_menus' => false, //by default this doesn't show for decaf |
|
155 | - 'show_in_rest' => true, |
|
156 | - 'capabilities' => array( |
|
157 | - 'manage_terms' => 'ee_manage_venue_categories', |
|
158 | - 'edit_terms' => 'ee_edit_venue_category', |
|
159 | - 'delete_terms' => 'ee_delete_venue_category', |
|
160 | - 'assign_terms' => 'ee_assign_venue_category', |
|
161 | - ), |
|
162 | - 'rewrite' => array('slug' => __('venue-category', 'event_espresso')), |
|
163 | - ), |
|
164 | - ), |
|
165 | - 'espresso_event_type' => array( |
|
166 | - 'singular_name' => __("Event Type", "event_espresso"), |
|
167 | - 'plural_name' => __("Event Types", "event_espresso"), |
|
168 | - 'args' => array( |
|
169 | - 'public' => true, |
|
170 | - 'show_ui' => false, |
|
171 | - 'show_in_rest' => true, |
|
172 | - 'capabilities' => array( |
|
173 | - 'manage_terms' => 'ee_read_event_type', |
|
174 | - 'edit_terms' => 'ee_edit_event_type', |
|
175 | - 'delete_terms' => 'ee_delete_event_type', |
|
176 | - 'assign_terms' => 'ee_assign_event_type', |
|
177 | - ), |
|
178 | - 'rewrite' => array('slug' => __('event-type', 'event_espresso')), |
|
179 | - 'hierarchical' => true, |
|
180 | - ), |
|
181 | - ), |
|
182 | - )); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * This returns the corresponding model name for cpts registered by EE. |
|
189 | - * |
|
190 | - * @since 4.6.16.rc.000 |
|
191 | - * @param string $post_type_slug If a slug is included, then attempt to retrieve the model name for |
|
192 | - * the given cpt slug. Otherwise if empty, then we'll return all cpt |
|
193 | - * model names for cpts registered in EE. |
|
194 | - * @return array Empty array if no matching model names for the given slug or an array of model |
|
195 | - * names indexed by post type slug. |
|
196 | - */ |
|
197 | - public static function get_cpt_model_names($post_type_slug = '') |
|
198 | - { |
|
199 | - $cpts = self::get_CPTs(); |
|
200 | - //first if slug passed in... |
|
201 | - if ( ! empty($post_type_slug)) { |
|
202 | - //match? |
|
203 | - if ( |
|
204 | - ! isset($cpts[$post_type_slug]) |
|
205 | - || (isset($cpts[$post_type_slug]) && empty($cpts[$post_type_slug]['class_name'])) |
|
206 | - ) { |
|
207 | - return array(); |
|
208 | - } |
|
209 | - //k let's get the model name for this cpt. |
|
210 | - return array($post_type_slug => str_replace('EE', 'EEM', $cpts[$post_type_slug]['class_name'])); |
|
211 | - } |
|
212 | - //if we made it here then we're returning an array of cpt model names indexed by post_type_slug. |
|
213 | - $cpt_models = array(); |
|
214 | - foreach ($cpts as $slug => $args) { |
|
215 | - if ( ! empty($args['class_name'])) { |
|
216 | - $cpt_models[$slug] = str_replace('EE', 'EEM', $args['class_name']); |
|
217 | - } |
|
218 | - } |
|
219 | - return $cpt_models; |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * This instantiates cpt models related to the cpts registered via EE. |
|
226 | - * |
|
227 | - * @since 4.6.16.rc.000 |
|
228 | - * @param string $post_type_slug If valid slug is provided, then will instantiate the model only for |
|
229 | - * the cpt matching the given slug. Otherwise all cpt models will be |
|
230 | - * instantiated (if possible). |
|
231 | - * @return EEM_CPT_Base[] successful instantiation will return an array of successfully instantiated |
|
232 | - * EEM models indexed by post slug. |
|
233 | - */ |
|
234 | - public static function instantiate_cpt_models($post_type_slug = '') |
|
235 | - { |
|
236 | - $cpt_model_names = self::get_cpt_model_names($post_type_slug); |
|
237 | - $instantiated = array(); |
|
238 | - foreach ($cpt_model_names as $slug => $model_name) { |
|
239 | - $instance = EE_Registry::instance()->load_model(str_replace('EEM_', '', $model_name)); |
|
240 | - if ($instance instanceof EEM_CPT_Base) { |
|
241 | - $instantiated[$slug] = $instance; |
|
242 | - } |
|
243 | - } |
|
244 | - return $instantiated; |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * get_CPTs |
|
251 | - * |
|
252 | - * @access public |
|
253 | - * @return array |
|
254 | - */ |
|
255 | - public static function get_CPTs() |
|
256 | - { |
|
257 | - // define CPTs |
|
258 | - // NOTE the ['args']['page_templates'] array index is something specific to our CPTs |
|
259 | - // and not part of the WP custom post type api. |
|
260 | - return apply_filters('FHEE__EE_Register_CPTs__get_CPTs__cpts', array( |
|
261 | - 'espresso_events' => array( |
|
262 | - 'singular_name' => __("Event", "event_espresso"), |
|
263 | - 'plural_name' => __("Events", "event_espresso"), |
|
264 | - 'singular_slug' => __("event", "event_espresso"), |
|
265 | - 'plural_slug' => EE_Registry::instance()->CFG->core->event_cpt_slug, |
|
266 | - 'class_name' => 'EE_Event', |
|
267 | - 'args' => array( |
|
268 | - 'public' => true, |
|
269 | - 'show_in_nav_menus' => true, |
|
270 | - 'capability_type' => 'event', |
|
271 | - 'capabilities' => array( |
|
272 | - 'edit_post' => 'ee_edit_event', |
|
273 | - 'read_post' => 'ee_read_event', |
|
274 | - 'delete_post' => 'ee_delete_event', |
|
275 | - 'edit_posts' => 'ee_edit_events', |
|
276 | - 'edit_others_posts' => 'ee_edit_others_events', |
|
277 | - 'publish_posts' => 'ee_publish_events', |
|
278 | - 'read_private_posts' => 'ee_read_private_events', |
|
279 | - 'delete_posts' => 'ee_delete_events', |
|
280 | - 'delete_private_posts' => 'ee_delete_private_events', |
|
281 | - 'delete_published_posts' => 'ee_delete_published_events', |
|
282 | - 'delete_others_posts' => 'ee_delete_others_events', |
|
283 | - 'edit_private_posts' => 'ee_edit_private_events', |
|
284 | - 'edit_published_posts' => 'ee_edit_published_events', |
|
285 | - ), |
|
286 | - 'taxonomies' => array( |
|
287 | - 'espresso_event_categories', |
|
288 | - 'espresso_event_type', |
|
289 | - 'post_tag', |
|
290 | - ), |
|
291 | - 'page_templates' => true, |
|
292 | - ), |
|
293 | - ), |
|
294 | - 'espresso_venues' => array( |
|
295 | - 'singular_name' => __("Venue", "event_espresso"), |
|
296 | - 'plural_name' => __("Venues", "event_espresso"), |
|
297 | - 'singular_slug' => __("venue", "event_espresso"), |
|
298 | - 'plural_slug' => __("venues", "event_espresso"), |
|
299 | - 'class_name' => 'EE_Venue', |
|
300 | - 'args' => array( |
|
301 | - 'public' => true, |
|
302 | - 'show_in_nav_menus' => false, //by default this doesn't show for decaf, |
|
303 | - 'capability_type' => 'venue', |
|
304 | - 'capabilities' => array( |
|
305 | - 'edit_post' => 'ee_edit_venue', |
|
306 | - 'read_post' => 'ee_read_venue', |
|
307 | - 'delete_post' => 'ee_delete_venue', |
|
308 | - 'edit_posts' => 'ee_edit_venues', |
|
309 | - 'edit_others_posts' => 'ee_edit_others_venues', |
|
310 | - 'publish_posts' => 'ee_publish_venues', |
|
311 | - 'read_private_posts' => 'ee_read_private_venues', |
|
312 | - 'delete_posts' => 'ee_delete_venues', |
|
313 | - 'delete_private_posts' => 'ee_delete_private_venues', |
|
314 | - 'delete_published_posts' => 'ee_delete_published_venues', |
|
315 | - 'delete_others_posts' => 'ee_edit_others_venues', |
|
316 | - 'edit_private_posts' => 'ee_edit_private_venues', |
|
317 | - 'edit_published_posts' => 'ee_edit_published_venues', |
|
318 | - ), |
|
319 | - 'taxonomies' => array( |
|
320 | - 'espresso_venue_categories', |
|
321 | - 'post_tag', |
|
322 | - ), |
|
323 | - 'page_templates' => true, |
|
324 | - ), |
|
325 | - ), |
|
326 | - 'espresso_attendees' => array( |
|
327 | - 'singular_name' => __("Contact", "event_espresso"), |
|
328 | - 'plural_name' => __("Contacts", "event_espresso"), |
|
329 | - 'singular_slug' => __("contact", "event_espresso"), |
|
330 | - 'plural_slug' => __("contacts", "event_espresso"), |
|
331 | - 'class_name' => 'EE_Attendee', |
|
332 | - 'args' => array( |
|
333 | - 'public' => false, |
|
334 | - 'publicly_queryable' => false, |
|
335 | - 'hierarchical' => false, |
|
336 | - 'has_archive' => false, |
|
337 | - 'taxonomies' => array('post_tag'), |
|
338 | - 'capability_type' => 'contact', |
|
339 | - 'capabilities' => array( |
|
340 | - 'edit_post' => 'ee_edit_contact', |
|
341 | - 'read_post' => 'ee_read_contact', |
|
342 | - 'delete_post' => 'ee_delete_contact', |
|
343 | - 'edit_posts' => 'ee_edit_contacts', |
|
344 | - 'edit_others_posts' => 'ee_edit_contacts', |
|
345 | - 'publish_posts' => 'ee_edit_contacts', |
|
346 | - 'read_private_posts' => 'ee_edit_contacts', |
|
347 | - 'delete_posts' => 'ee_delete_contacts', |
|
348 | - 'delete_private_posts' => 'ee_delete_contacts', |
|
349 | - 'delete_published_posts' => 'ee_delete_contacts', |
|
350 | - 'delete_others_posts' => 'ee_delete_contacts', |
|
351 | - 'edit_private_posts' => 'ee_edit_contacts', |
|
352 | - 'edit_published_posts' => 'ee_edit_contacts', |
|
353 | - ), |
|
354 | - 'supports' => array('editor', 'thumbnail', 'excerpt', 'custom-fields', 'comments'), |
|
355 | - ), |
|
356 | - ), |
|
357 | - )); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * This basically goes through the CPT array and returns only CPT's |
|
364 | - * that have the ['args']['public'] option set as false |
|
365 | - * |
|
366 | - * @return array |
|
367 | - */ |
|
368 | - public static function get_private_CPTs() |
|
369 | - { |
|
370 | - $CPTs = self::get_CPTs(); |
|
371 | - $private_CPTs = array(); |
|
372 | - foreach ($CPTs as $CPT => $details) { |
|
373 | - if (empty($details['args']['public'])) { |
|
374 | - $private_CPTs[$CPT] = $details; |
|
375 | - } |
|
376 | - } |
|
377 | - return $private_CPTs; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * Registers a custom taxonomy. Should be called before registering custom post types, |
|
384 | - * otherwise you should link the taxonomy to the custom post type using 'register_taxonomy_for_object_type'. |
|
385 | - * |
|
386 | - * @param string $taxonomy_name , eg 'books' |
|
387 | - * @param string $singular_name internationalized singular name |
|
388 | - * @param string $plural_name internationalized plural name |
|
389 | - * @param array $override_args like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy |
|
390 | - */ |
|
391 | - public function register_taxonomy($taxonomy_name, $singular_name, $plural_name, $override_args = array()) |
|
392 | - { |
|
393 | - $args = array( |
|
394 | - 'hierarchical' => true, |
|
395 | - 'labels' => array( |
|
396 | - 'name' => $plural_name, |
|
397 | - 'singular_name' => $singular_name, |
|
398 | - ), |
|
399 | - 'show_ui' => true, |
|
400 | - 'show_ee_ui' => true, |
|
401 | - 'show_admin_column' => true, |
|
402 | - 'query_var' => true, |
|
403 | - 'show_in_nav_menus' => false, |
|
404 | - 'map_meta_cap' => true |
|
405 | - //'rewrite' => array( 'slug' => 'genre' ), |
|
406 | - ); |
|
407 | - if ($override_args) { |
|
408 | - if (isset($override_args['labels'])) { |
|
409 | - $labels = array_merge($args['labels'], $override_args['labels']); |
|
410 | - $args['labels'] = $labels; |
|
411 | - } |
|
412 | - $args = array_merge($args, $override_args); |
|
413 | - } |
|
414 | - register_taxonomy($taxonomy_name, null, $args); |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * Registers a new custom post type. Sets default settings given only the following params. |
|
421 | - * |
|
422 | - * @param string $post_type the actual post type name |
|
423 | - * (VERY IMPORTANT: this much match what the slug is for admin pages related to this |
|
424 | - * cpt Also any models must use this slug as well) |
|
425 | - * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
426 | - * @param string $plural_name a pre-internalized string for the plural name of the objects |
|
427 | - * @param array $override_args exactly like $args as described in |
|
428 | - * http://codex.wordpress.org/Function_Reference/register_post_type The default values |
|
429 | - * set in this function will be overridden by whatever you set in $override_args |
|
430 | - * @param string $singular_slug |
|
431 | - * @param string $plural_slug |
|
432 | - * @return void , but registers the custom post type |
|
433 | - */ |
|
434 | - public function register_CPT( |
|
435 | - $post_type, |
|
436 | - $singular_name, |
|
437 | - $plural_name, |
|
438 | - $override_args = array(), |
|
439 | - $singular_slug = '', |
|
440 | - $plural_slug = '' |
|
441 | - ) { |
|
442 | - $labels = array( |
|
443 | - 'name' => $plural_name, |
|
444 | - 'singular_name' => $singular_name, |
|
445 | - 'singular_slug' => $singular_slug, |
|
446 | - 'plural_slug' => $plural_slug, |
|
447 | - 'add_new' => sprintf(__("Add %s", "event_espresso"), $singular_name), |
|
448 | - 'add_new_item' => sprintf(__("Add New %s", "event_espresso"), $singular_name), |
|
449 | - 'edit_item' => sprintf(__("Edit %s", "event_espresso"), $singular_name), |
|
450 | - 'new_item' => sprintf(__("New %s", "event_espresso"), $singular_name), |
|
451 | - 'all_items' => sprintf(__("All %s", "event_espresso"), $plural_name), |
|
452 | - 'view_item' => sprintf(__("View %s", "event_espresso"), $singular_name), |
|
453 | - 'search_items' => sprintf(__("Search %s", "event_espresso"), $plural_name), |
|
454 | - 'not_found' => sprintf(__("No %s found", "event_espresso"), $plural_name), |
|
455 | - 'not_found_in_trash' => sprintf(__("No %s found in Trash", "event_espresso"), $plural_name), |
|
456 | - 'parent_item_colon' => '', |
|
457 | - 'menu_name' => sprintf(__("%s", "event_espresso"), $plural_name), |
|
458 | - ); |
|
459 | - //verify plural slug and singular slug, if they aren't we'll use $singular_name and $plural_name |
|
460 | - // $singular_slug = ! empty($singular_slug) ? $singular_slug : $singular_name; |
|
461 | - $plural_slug = ! empty($plural_slug) ? $plural_slug : $plural_name; |
|
462 | - //note the page_templates arg in the supports index is something specific to EE. |
|
463 | - // WordPress doesn't actually have that in their register_post_type api. |
|
464 | - $args = array( |
|
465 | - 'labels' => $labels, |
|
466 | - 'public' => true, |
|
467 | - 'publicly_queryable' => true, |
|
468 | - 'show_ui' => false, |
|
469 | - 'show_ee_ui' => true, |
|
470 | - 'show_in_menu' => false, |
|
471 | - 'show_in_nav_menus' => false, |
|
472 | - 'query_var' => true, |
|
473 | - 'rewrite' => apply_filters( |
|
474 | - 'FHEE__EE_Register_CPTs__register_CPT__rewrite', |
|
475 | - array('slug' => $plural_slug), |
|
476 | - $post_type |
|
477 | - ), |
|
478 | - 'capability_type' => 'post', |
|
479 | - 'map_meta_cap' => true, |
|
480 | - 'has_archive' => true, |
|
481 | - 'hierarchical' => false, |
|
482 | - 'menu_position' => null, |
|
483 | - 'supports' => array( |
|
484 | - 'title', |
|
485 | - 'editor', |
|
486 | - 'author', |
|
487 | - 'thumbnail', |
|
488 | - 'excerpt', |
|
489 | - 'custom-fields', |
|
490 | - 'comments', |
|
491 | - ), |
|
492 | - ); |
|
493 | - if ($override_args) { |
|
494 | - if (isset($override_args['labels'])) { |
|
495 | - $labels = array_merge($args['labels'], $override_args['labels']); |
|
496 | - } |
|
497 | - $args = array_merge($args, $override_args); |
|
498 | - $args['labels'] = $labels; |
|
499 | - } |
|
500 | - register_post_type($post_type, $args); |
|
501 | - } |
|
502 | - |
|
503 | - |
|
504 | - |
|
505 | - public function set_must_use_event_types() |
|
506 | - { |
|
507 | - $term_details = array( |
|
508 | - //Attendee's register for the first date-time only |
|
509 | - 'single-event' => array( |
|
510 | - __('Single Event', 'event_espresso'), |
|
511 | - __('A single event that spans one or more consecutive days.', 'event_espresso'), |
|
512 | - ), |
|
513 | - //example: a party or two-day long workshop |
|
514 | - //Attendee's can register for any of the date-times |
|
515 | - 'multi-event' => array( |
|
516 | - __('Multi Event', 'event_espresso'), |
|
517 | - __('Multiple, separate, but related events that occur on consecutive days.', 'event_espresso'), |
|
518 | - ), |
|
519 | - //example: a three day music festival or week long conference |
|
520 | - //Attendee's register for the first date-time only |
|
521 | - 'event-series' => array( |
|
522 | - __('Event Series', 'event_espresso'), |
|
523 | - __(' Multiple events that occur over multiple non-consecutive days.', 'event_espresso'), |
|
524 | - ), |
|
525 | - //example: an 8 week introduction to basket weaving course |
|
526 | - //Attendee's can register for any of the date-times. |
|
527 | - 'recurring-event' => array( |
|
528 | - __('Recurring Event', 'event_espresso'), |
|
529 | - __('Multiple events that occur over multiple non-consecutive days.', 'event_espresso'), |
|
530 | - ), |
|
531 | - //example: a yoga class |
|
532 | - 'ongoing' => array( |
|
533 | - __('Ongoing Event', 'event_espresso'), |
|
534 | - __('An "event" that people can purchase tickets to gain access for anytime for this event regardless of date times on the event', |
|
535 | - 'event_espresso'), |
|
536 | - ) |
|
537 | - //example: access to a museum |
|
538 | - //'walk-in' => array( __('Walk In', 'event_espresso'), __('Single datetime and single entry recurring events. Attendees register for one or multiple datetimes individually.', 'event_espresso') ), |
|
539 | - //'reservation' => array( __('Reservation', 'event_espresso'), __('Reservations are created by specifying available datetimes and quantities. Attendees choose from the available datetimes and specify the quantity available (if the maximum is greater than 1)') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1 |
|
540 | - // 'multiple-session' => array( __('Multiple Session', 'event_espresso'), __('Multiple event, multiple datetime, hierarchically organized, custom entry events. Attendees may be required to register for a parent event before being allowed to register for child events. Attendees can register for any combination of child events as long as the datetimes do not conflict. Parent and child events may have additional fees or registration questions.') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1 |
|
541 | - //'appointment' => array( __('Appointments', 'event_espresso'), __('Time slotted events where datetimes are generally in hours or minutes. For example, attendees can register for a single 15 minute or 1 hour time slot and this type of availability frequently reoccurs.', 'event_espresso') ) |
|
542 | - ); |
|
543 | - $this->set_must_use_terms('espresso_event_type', $term_details); |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - |
|
548 | - /** |
|
549 | - * wrapper method for handling the setting up of initial terms in the db (if they don't already exist). |
|
550 | - * Note this should ONLY be used for terms that always must be present. Be aware that if an initial term is |
|
551 | - * deleted then it WILL be recreated. |
|
552 | - * |
|
553 | - * @param string $taxonomy The name of the taxonomy |
|
554 | - * @param array $term_details An array of term details indexed by slug and containing Name of term, and |
|
555 | - * description as the elements in the array |
|
556 | - * @return void |
|
557 | - */ |
|
558 | - public function set_must_use_terms($taxonomy, $term_details) |
|
559 | - { |
|
560 | - $term_details = (array)$term_details; |
|
561 | - foreach ($term_details as $slug => $details) { |
|
562 | - if ( ! term_exists($slug, $taxonomy)) { |
|
563 | - $insert_arr = array( |
|
564 | - 'slug' => $slug, |
|
565 | - 'description' => $details[1], |
|
566 | - ); |
|
567 | - wp_insert_term($details[0], $taxonomy, $insert_arr); |
|
568 | - } |
|
569 | - } |
|
570 | - } |
|
571 | - |
|
572 | - |
|
573 | - |
|
574 | - /** |
|
575 | - * Allows us to set what the default will be for terms when a cpt is PUBLISHED. |
|
576 | - * |
|
577 | - * @param string $taxonomy The taxonomy we're using for the default term |
|
578 | - * @param string $term_slug The slug of the term that will be the default. |
|
579 | - * @param array $cpt_slugs An array of custom post types we want the default assigned to |
|
580 | - */ |
|
581 | - public function set_default_term($taxonomy, $term_slug, $cpt_slugs = array()) |
|
582 | - { |
|
583 | - $this->_default_terms[][$term_slug] = new EE_Default_Term($taxonomy, $term_slug, $cpt_slugs); |
|
584 | - } |
|
585 | - |
|
586 | - |
|
587 | - |
|
588 | - /** |
|
589 | - * hooked into the wp 'save_post' action hook for setting our default terms found in the $_default_terms property |
|
590 | - * |
|
591 | - * @param int $post_id ID of CPT being saved |
|
592 | - * @param object $post Post object |
|
593 | - * @return void |
|
594 | - */ |
|
595 | - public function save_default_term($post_id, $post) |
|
596 | - { |
|
597 | - if (empty($this->_default_terms)) { |
|
598 | - return; |
|
599 | - } //no default terms set so lets just exit. |
|
600 | - foreach ($this->_default_terms as $defaults) { |
|
601 | - foreach ($defaults as $default_obj) { |
|
602 | - if ($post->post_status === 'publish' && in_array($post->post_type, $default_obj->cpt_slugs, true)) { |
|
603 | - //note some error proofing going on here to save unnecessary db queries |
|
604 | - $taxonomies = get_object_taxonomies($post->post_type); |
|
605 | - foreach ((array)$taxonomies as $taxonomy) { |
|
606 | - $terms = wp_get_post_terms($post_id, $taxonomy); |
|
607 | - if (empty($terms) && $taxonomy === $default_obj->taxonomy) { |
|
608 | - wp_set_object_terms($post_id, array($default_obj->term_slug), $taxonomy); |
|
609 | - } |
|
610 | - } |
|
611 | - } |
|
612 | - } |
|
613 | - } |
|
614 | - } |
|
17 | + /** |
|
18 | + * This property is used to hold an array of EE_default_term objects assigned to a custom post type when the post |
|
19 | + * for that post type is published with no terms set for the taxonomy. |
|
20 | + * |
|
21 | + * @var array of EE_Default_Term objects |
|
22 | + */ |
|
23 | + protected $_default_terms = array(); |
|
24 | + |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * constructor |
|
29 | + * instantiated at init priority 5 |
|
30 | + */ |
|
31 | + public function __construct() |
|
32 | + { |
|
33 | + // register taxonomies |
|
34 | + $taxonomies = self::get_taxonomies(); |
|
35 | + foreach ($taxonomies as $taxonomy => $tax) { |
|
36 | + $this->register_taxonomy($taxonomy, $tax['singular_name'], $tax['plural_name'], $tax['args']); |
|
37 | + } |
|
38 | + // register CPTs |
|
39 | + $CPTs = self::get_CPTs(); |
|
40 | + foreach ($CPTs as $CPT_name => $CPT) { |
|
41 | + $this->register_CPT($CPT_name, $CPT['singular_name'], $CPT['plural_name'], $CPT['args'], |
|
42 | + $CPT['singular_slug'], $CPT['plural_slug']); |
|
43 | + } |
|
44 | + // setup default terms in any of our taxonomies (but only if we're in admin). |
|
45 | + // Why not added via register_activation_hook? |
|
46 | + // Because it's possible that in future iterations of EE we may add new defaults for specialized taxonomies |
|
47 | + // (think event_types) and register_activation_hook only reliably runs when a user manually activates the plugin. |
|
48 | + // Keep in mind that this will READ these terms if they are deleted by the user. Hence MUST use terms. |
|
49 | + // if ( is_admin() ) { |
|
50 | + // $this->set_must_use_event_types(); |
|
51 | + // } |
|
52 | + //set default terms |
|
53 | + $this->set_default_term('espresso_event_type', 'single-event', array('espresso_events')); |
|
54 | + add_action('AHEE__EE_System__initialize_last', array(__CLASS__, 'maybe_flush_rewrite_rules'), 10); |
|
55 | + // hook into save_post so that we can make sure that the default terms get saved on publish of registered cpts |
|
56 | + // IF they don't have a term for that taxonomy set. |
|
57 | + add_action('save_post', array($this, 'save_default_term'), 100, 2); |
|
58 | + // remove no html restrictions from core wp saving of term descriptions. |
|
59 | + // Note. this will affect only registered EE taxonomies. |
|
60 | + $this->_allow_html_descriptions_for_ee_taxonomies(); |
|
61 | + do_action('AHEE__EE_Register_CPTs__construct_end', $this); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * This will flush rewrite rules on demand. This actually gets called around wp init priority level 100. |
|
68 | + * |
|
69 | + * @since 4.5.0 |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public static function maybe_flush_rewrite_rules() |
|
73 | + { |
|
74 | + if (get_option('ee_flush_rewrite_rules', true)) { |
|
75 | + flush_rewrite_rules(); |
|
76 | + update_option('ee_flush_rewrite_rules', false); |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * By default, WordPress strips all html from term taxonomy description content. The purpose of this method is to |
|
84 | + * remove that restriction and ensure that we still run ee term taxonomy descriptions through some full html |
|
85 | + * sanitization equivalent to the post content field. |
|
86 | + * |
|
87 | + * @since 4.7.8 |
|
88 | + */ |
|
89 | + protected function _allow_html_descriptions_for_ee_taxonomies() |
|
90 | + { |
|
91 | + // first remove default filter for term description but we have to do this earlier |
|
92 | + // before wp sets their own filter |
|
93 | + // because they just set a global filter on all term descriptions before the custom term description filter. |
|
94 | + // Really sux. |
|
95 | + add_filter('pre_term_description', array($this, 'ee_filter_ee_term_description_not_wp'), 1, 2); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * Callback for pre_term_description hook. |
|
102 | + * |
|
103 | + * @param string $description The description content. |
|
104 | + * @param string $taxonomy The taxonomy name for the taxonomy being filtered. |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function ee_filter_ee_term_description_not_wp($description, $taxonomy) |
|
108 | + { |
|
109 | + //get a list of EE taxonomies |
|
110 | + $ee_taxonomies = array_keys(self::get_taxonomies()); |
|
111 | + //only do our own thing if the taxonomy listed is an ee taxonomy. |
|
112 | + if (in_array($taxonomy, $ee_taxonomies, true)) { |
|
113 | + //remove default wp filter |
|
114 | + remove_filter('pre_term_description', 'wp_filter_kses'); |
|
115 | + //sanitize THIS content. |
|
116 | + $description = wp_kses($description, wp_kses_allowed_html('post')); |
|
117 | + } |
|
118 | + return $description; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * get_taxonomies |
|
125 | + * |
|
126 | + * @access public |
|
127 | + * @return array |
|
128 | + */ |
|
129 | + public static function get_taxonomies() |
|
130 | + { |
|
131 | + // define taxonomies |
|
132 | + return apply_filters('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array( |
|
133 | + 'espresso_event_categories' => array( |
|
134 | + 'singular_name' => __("Event Category", "event_espresso"), |
|
135 | + 'plural_name' => __("Event Categories", "event_espresso"), |
|
136 | + 'args' => array( |
|
137 | + 'public' => true, |
|
138 | + 'show_in_nav_menus' => true, |
|
139 | + 'show_in_rest' => true, |
|
140 | + 'capabilities' => array( |
|
141 | + 'manage_terms' => 'ee_manage_event_categories', |
|
142 | + 'edit_terms' => 'ee_edit_event_category', |
|
143 | + 'delete_terms' => 'ee_delete_event_category', |
|
144 | + 'assign_terms' => 'ee_assign_event_category', |
|
145 | + ), |
|
146 | + 'rewrite' => array('slug' => __('event-category', 'event_espresso')), |
|
147 | + ), |
|
148 | + ), |
|
149 | + 'espresso_venue_categories' => array( |
|
150 | + 'singular_name' => __("Venue Category", "event_espresso"), |
|
151 | + 'plural_name' => __("Venue Categories", "event_espresso"), |
|
152 | + 'args' => array( |
|
153 | + 'public' => true, |
|
154 | + 'show_in_nav_menus' => false, //by default this doesn't show for decaf |
|
155 | + 'show_in_rest' => true, |
|
156 | + 'capabilities' => array( |
|
157 | + 'manage_terms' => 'ee_manage_venue_categories', |
|
158 | + 'edit_terms' => 'ee_edit_venue_category', |
|
159 | + 'delete_terms' => 'ee_delete_venue_category', |
|
160 | + 'assign_terms' => 'ee_assign_venue_category', |
|
161 | + ), |
|
162 | + 'rewrite' => array('slug' => __('venue-category', 'event_espresso')), |
|
163 | + ), |
|
164 | + ), |
|
165 | + 'espresso_event_type' => array( |
|
166 | + 'singular_name' => __("Event Type", "event_espresso"), |
|
167 | + 'plural_name' => __("Event Types", "event_espresso"), |
|
168 | + 'args' => array( |
|
169 | + 'public' => true, |
|
170 | + 'show_ui' => false, |
|
171 | + 'show_in_rest' => true, |
|
172 | + 'capabilities' => array( |
|
173 | + 'manage_terms' => 'ee_read_event_type', |
|
174 | + 'edit_terms' => 'ee_edit_event_type', |
|
175 | + 'delete_terms' => 'ee_delete_event_type', |
|
176 | + 'assign_terms' => 'ee_assign_event_type', |
|
177 | + ), |
|
178 | + 'rewrite' => array('slug' => __('event-type', 'event_espresso')), |
|
179 | + 'hierarchical' => true, |
|
180 | + ), |
|
181 | + ), |
|
182 | + )); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * This returns the corresponding model name for cpts registered by EE. |
|
189 | + * |
|
190 | + * @since 4.6.16.rc.000 |
|
191 | + * @param string $post_type_slug If a slug is included, then attempt to retrieve the model name for |
|
192 | + * the given cpt slug. Otherwise if empty, then we'll return all cpt |
|
193 | + * model names for cpts registered in EE. |
|
194 | + * @return array Empty array if no matching model names for the given slug or an array of model |
|
195 | + * names indexed by post type slug. |
|
196 | + */ |
|
197 | + public static function get_cpt_model_names($post_type_slug = '') |
|
198 | + { |
|
199 | + $cpts = self::get_CPTs(); |
|
200 | + //first if slug passed in... |
|
201 | + if ( ! empty($post_type_slug)) { |
|
202 | + //match? |
|
203 | + if ( |
|
204 | + ! isset($cpts[$post_type_slug]) |
|
205 | + || (isset($cpts[$post_type_slug]) && empty($cpts[$post_type_slug]['class_name'])) |
|
206 | + ) { |
|
207 | + return array(); |
|
208 | + } |
|
209 | + //k let's get the model name for this cpt. |
|
210 | + return array($post_type_slug => str_replace('EE', 'EEM', $cpts[$post_type_slug]['class_name'])); |
|
211 | + } |
|
212 | + //if we made it here then we're returning an array of cpt model names indexed by post_type_slug. |
|
213 | + $cpt_models = array(); |
|
214 | + foreach ($cpts as $slug => $args) { |
|
215 | + if ( ! empty($args['class_name'])) { |
|
216 | + $cpt_models[$slug] = str_replace('EE', 'EEM', $args['class_name']); |
|
217 | + } |
|
218 | + } |
|
219 | + return $cpt_models; |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * This instantiates cpt models related to the cpts registered via EE. |
|
226 | + * |
|
227 | + * @since 4.6.16.rc.000 |
|
228 | + * @param string $post_type_slug If valid slug is provided, then will instantiate the model only for |
|
229 | + * the cpt matching the given slug. Otherwise all cpt models will be |
|
230 | + * instantiated (if possible). |
|
231 | + * @return EEM_CPT_Base[] successful instantiation will return an array of successfully instantiated |
|
232 | + * EEM models indexed by post slug. |
|
233 | + */ |
|
234 | + public static function instantiate_cpt_models($post_type_slug = '') |
|
235 | + { |
|
236 | + $cpt_model_names = self::get_cpt_model_names($post_type_slug); |
|
237 | + $instantiated = array(); |
|
238 | + foreach ($cpt_model_names as $slug => $model_name) { |
|
239 | + $instance = EE_Registry::instance()->load_model(str_replace('EEM_', '', $model_name)); |
|
240 | + if ($instance instanceof EEM_CPT_Base) { |
|
241 | + $instantiated[$slug] = $instance; |
|
242 | + } |
|
243 | + } |
|
244 | + return $instantiated; |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * get_CPTs |
|
251 | + * |
|
252 | + * @access public |
|
253 | + * @return array |
|
254 | + */ |
|
255 | + public static function get_CPTs() |
|
256 | + { |
|
257 | + // define CPTs |
|
258 | + // NOTE the ['args']['page_templates'] array index is something specific to our CPTs |
|
259 | + // and not part of the WP custom post type api. |
|
260 | + return apply_filters('FHEE__EE_Register_CPTs__get_CPTs__cpts', array( |
|
261 | + 'espresso_events' => array( |
|
262 | + 'singular_name' => __("Event", "event_espresso"), |
|
263 | + 'plural_name' => __("Events", "event_espresso"), |
|
264 | + 'singular_slug' => __("event", "event_espresso"), |
|
265 | + 'plural_slug' => EE_Registry::instance()->CFG->core->event_cpt_slug, |
|
266 | + 'class_name' => 'EE_Event', |
|
267 | + 'args' => array( |
|
268 | + 'public' => true, |
|
269 | + 'show_in_nav_menus' => true, |
|
270 | + 'capability_type' => 'event', |
|
271 | + 'capabilities' => array( |
|
272 | + 'edit_post' => 'ee_edit_event', |
|
273 | + 'read_post' => 'ee_read_event', |
|
274 | + 'delete_post' => 'ee_delete_event', |
|
275 | + 'edit_posts' => 'ee_edit_events', |
|
276 | + 'edit_others_posts' => 'ee_edit_others_events', |
|
277 | + 'publish_posts' => 'ee_publish_events', |
|
278 | + 'read_private_posts' => 'ee_read_private_events', |
|
279 | + 'delete_posts' => 'ee_delete_events', |
|
280 | + 'delete_private_posts' => 'ee_delete_private_events', |
|
281 | + 'delete_published_posts' => 'ee_delete_published_events', |
|
282 | + 'delete_others_posts' => 'ee_delete_others_events', |
|
283 | + 'edit_private_posts' => 'ee_edit_private_events', |
|
284 | + 'edit_published_posts' => 'ee_edit_published_events', |
|
285 | + ), |
|
286 | + 'taxonomies' => array( |
|
287 | + 'espresso_event_categories', |
|
288 | + 'espresso_event_type', |
|
289 | + 'post_tag', |
|
290 | + ), |
|
291 | + 'page_templates' => true, |
|
292 | + ), |
|
293 | + ), |
|
294 | + 'espresso_venues' => array( |
|
295 | + 'singular_name' => __("Venue", "event_espresso"), |
|
296 | + 'plural_name' => __("Venues", "event_espresso"), |
|
297 | + 'singular_slug' => __("venue", "event_espresso"), |
|
298 | + 'plural_slug' => __("venues", "event_espresso"), |
|
299 | + 'class_name' => 'EE_Venue', |
|
300 | + 'args' => array( |
|
301 | + 'public' => true, |
|
302 | + 'show_in_nav_menus' => false, //by default this doesn't show for decaf, |
|
303 | + 'capability_type' => 'venue', |
|
304 | + 'capabilities' => array( |
|
305 | + 'edit_post' => 'ee_edit_venue', |
|
306 | + 'read_post' => 'ee_read_venue', |
|
307 | + 'delete_post' => 'ee_delete_venue', |
|
308 | + 'edit_posts' => 'ee_edit_venues', |
|
309 | + 'edit_others_posts' => 'ee_edit_others_venues', |
|
310 | + 'publish_posts' => 'ee_publish_venues', |
|
311 | + 'read_private_posts' => 'ee_read_private_venues', |
|
312 | + 'delete_posts' => 'ee_delete_venues', |
|
313 | + 'delete_private_posts' => 'ee_delete_private_venues', |
|
314 | + 'delete_published_posts' => 'ee_delete_published_venues', |
|
315 | + 'delete_others_posts' => 'ee_edit_others_venues', |
|
316 | + 'edit_private_posts' => 'ee_edit_private_venues', |
|
317 | + 'edit_published_posts' => 'ee_edit_published_venues', |
|
318 | + ), |
|
319 | + 'taxonomies' => array( |
|
320 | + 'espresso_venue_categories', |
|
321 | + 'post_tag', |
|
322 | + ), |
|
323 | + 'page_templates' => true, |
|
324 | + ), |
|
325 | + ), |
|
326 | + 'espresso_attendees' => array( |
|
327 | + 'singular_name' => __("Contact", "event_espresso"), |
|
328 | + 'plural_name' => __("Contacts", "event_espresso"), |
|
329 | + 'singular_slug' => __("contact", "event_espresso"), |
|
330 | + 'plural_slug' => __("contacts", "event_espresso"), |
|
331 | + 'class_name' => 'EE_Attendee', |
|
332 | + 'args' => array( |
|
333 | + 'public' => false, |
|
334 | + 'publicly_queryable' => false, |
|
335 | + 'hierarchical' => false, |
|
336 | + 'has_archive' => false, |
|
337 | + 'taxonomies' => array('post_tag'), |
|
338 | + 'capability_type' => 'contact', |
|
339 | + 'capabilities' => array( |
|
340 | + 'edit_post' => 'ee_edit_contact', |
|
341 | + 'read_post' => 'ee_read_contact', |
|
342 | + 'delete_post' => 'ee_delete_contact', |
|
343 | + 'edit_posts' => 'ee_edit_contacts', |
|
344 | + 'edit_others_posts' => 'ee_edit_contacts', |
|
345 | + 'publish_posts' => 'ee_edit_contacts', |
|
346 | + 'read_private_posts' => 'ee_edit_contacts', |
|
347 | + 'delete_posts' => 'ee_delete_contacts', |
|
348 | + 'delete_private_posts' => 'ee_delete_contacts', |
|
349 | + 'delete_published_posts' => 'ee_delete_contacts', |
|
350 | + 'delete_others_posts' => 'ee_delete_contacts', |
|
351 | + 'edit_private_posts' => 'ee_edit_contacts', |
|
352 | + 'edit_published_posts' => 'ee_edit_contacts', |
|
353 | + ), |
|
354 | + 'supports' => array('editor', 'thumbnail', 'excerpt', 'custom-fields', 'comments'), |
|
355 | + ), |
|
356 | + ), |
|
357 | + )); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * This basically goes through the CPT array and returns only CPT's |
|
364 | + * that have the ['args']['public'] option set as false |
|
365 | + * |
|
366 | + * @return array |
|
367 | + */ |
|
368 | + public static function get_private_CPTs() |
|
369 | + { |
|
370 | + $CPTs = self::get_CPTs(); |
|
371 | + $private_CPTs = array(); |
|
372 | + foreach ($CPTs as $CPT => $details) { |
|
373 | + if (empty($details['args']['public'])) { |
|
374 | + $private_CPTs[$CPT] = $details; |
|
375 | + } |
|
376 | + } |
|
377 | + return $private_CPTs; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * Registers a custom taxonomy. Should be called before registering custom post types, |
|
384 | + * otherwise you should link the taxonomy to the custom post type using 'register_taxonomy_for_object_type'. |
|
385 | + * |
|
386 | + * @param string $taxonomy_name , eg 'books' |
|
387 | + * @param string $singular_name internationalized singular name |
|
388 | + * @param string $plural_name internationalized plural name |
|
389 | + * @param array $override_args like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy |
|
390 | + */ |
|
391 | + public function register_taxonomy($taxonomy_name, $singular_name, $plural_name, $override_args = array()) |
|
392 | + { |
|
393 | + $args = array( |
|
394 | + 'hierarchical' => true, |
|
395 | + 'labels' => array( |
|
396 | + 'name' => $plural_name, |
|
397 | + 'singular_name' => $singular_name, |
|
398 | + ), |
|
399 | + 'show_ui' => true, |
|
400 | + 'show_ee_ui' => true, |
|
401 | + 'show_admin_column' => true, |
|
402 | + 'query_var' => true, |
|
403 | + 'show_in_nav_menus' => false, |
|
404 | + 'map_meta_cap' => true |
|
405 | + //'rewrite' => array( 'slug' => 'genre' ), |
|
406 | + ); |
|
407 | + if ($override_args) { |
|
408 | + if (isset($override_args['labels'])) { |
|
409 | + $labels = array_merge($args['labels'], $override_args['labels']); |
|
410 | + $args['labels'] = $labels; |
|
411 | + } |
|
412 | + $args = array_merge($args, $override_args); |
|
413 | + } |
|
414 | + register_taxonomy($taxonomy_name, null, $args); |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * Registers a new custom post type. Sets default settings given only the following params. |
|
421 | + * |
|
422 | + * @param string $post_type the actual post type name |
|
423 | + * (VERY IMPORTANT: this much match what the slug is for admin pages related to this |
|
424 | + * cpt Also any models must use this slug as well) |
|
425 | + * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
426 | + * @param string $plural_name a pre-internalized string for the plural name of the objects |
|
427 | + * @param array $override_args exactly like $args as described in |
|
428 | + * http://codex.wordpress.org/Function_Reference/register_post_type The default values |
|
429 | + * set in this function will be overridden by whatever you set in $override_args |
|
430 | + * @param string $singular_slug |
|
431 | + * @param string $plural_slug |
|
432 | + * @return void , but registers the custom post type |
|
433 | + */ |
|
434 | + public function register_CPT( |
|
435 | + $post_type, |
|
436 | + $singular_name, |
|
437 | + $plural_name, |
|
438 | + $override_args = array(), |
|
439 | + $singular_slug = '', |
|
440 | + $plural_slug = '' |
|
441 | + ) { |
|
442 | + $labels = array( |
|
443 | + 'name' => $plural_name, |
|
444 | + 'singular_name' => $singular_name, |
|
445 | + 'singular_slug' => $singular_slug, |
|
446 | + 'plural_slug' => $plural_slug, |
|
447 | + 'add_new' => sprintf(__("Add %s", "event_espresso"), $singular_name), |
|
448 | + 'add_new_item' => sprintf(__("Add New %s", "event_espresso"), $singular_name), |
|
449 | + 'edit_item' => sprintf(__("Edit %s", "event_espresso"), $singular_name), |
|
450 | + 'new_item' => sprintf(__("New %s", "event_espresso"), $singular_name), |
|
451 | + 'all_items' => sprintf(__("All %s", "event_espresso"), $plural_name), |
|
452 | + 'view_item' => sprintf(__("View %s", "event_espresso"), $singular_name), |
|
453 | + 'search_items' => sprintf(__("Search %s", "event_espresso"), $plural_name), |
|
454 | + 'not_found' => sprintf(__("No %s found", "event_espresso"), $plural_name), |
|
455 | + 'not_found_in_trash' => sprintf(__("No %s found in Trash", "event_espresso"), $plural_name), |
|
456 | + 'parent_item_colon' => '', |
|
457 | + 'menu_name' => sprintf(__("%s", "event_espresso"), $plural_name), |
|
458 | + ); |
|
459 | + //verify plural slug and singular slug, if they aren't we'll use $singular_name and $plural_name |
|
460 | + // $singular_slug = ! empty($singular_slug) ? $singular_slug : $singular_name; |
|
461 | + $plural_slug = ! empty($plural_slug) ? $plural_slug : $plural_name; |
|
462 | + //note the page_templates arg in the supports index is something specific to EE. |
|
463 | + // WordPress doesn't actually have that in their register_post_type api. |
|
464 | + $args = array( |
|
465 | + 'labels' => $labels, |
|
466 | + 'public' => true, |
|
467 | + 'publicly_queryable' => true, |
|
468 | + 'show_ui' => false, |
|
469 | + 'show_ee_ui' => true, |
|
470 | + 'show_in_menu' => false, |
|
471 | + 'show_in_nav_menus' => false, |
|
472 | + 'query_var' => true, |
|
473 | + 'rewrite' => apply_filters( |
|
474 | + 'FHEE__EE_Register_CPTs__register_CPT__rewrite', |
|
475 | + array('slug' => $plural_slug), |
|
476 | + $post_type |
|
477 | + ), |
|
478 | + 'capability_type' => 'post', |
|
479 | + 'map_meta_cap' => true, |
|
480 | + 'has_archive' => true, |
|
481 | + 'hierarchical' => false, |
|
482 | + 'menu_position' => null, |
|
483 | + 'supports' => array( |
|
484 | + 'title', |
|
485 | + 'editor', |
|
486 | + 'author', |
|
487 | + 'thumbnail', |
|
488 | + 'excerpt', |
|
489 | + 'custom-fields', |
|
490 | + 'comments', |
|
491 | + ), |
|
492 | + ); |
|
493 | + if ($override_args) { |
|
494 | + if (isset($override_args['labels'])) { |
|
495 | + $labels = array_merge($args['labels'], $override_args['labels']); |
|
496 | + } |
|
497 | + $args = array_merge($args, $override_args); |
|
498 | + $args['labels'] = $labels; |
|
499 | + } |
|
500 | + register_post_type($post_type, $args); |
|
501 | + } |
|
502 | + |
|
503 | + |
|
504 | + |
|
505 | + public function set_must_use_event_types() |
|
506 | + { |
|
507 | + $term_details = array( |
|
508 | + //Attendee's register for the first date-time only |
|
509 | + 'single-event' => array( |
|
510 | + __('Single Event', 'event_espresso'), |
|
511 | + __('A single event that spans one or more consecutive days.', 'event_espresso'), |
|
512 | + ), |
|
513 | + //example: a party or two-day long workshop |
|
514 | + //Attendee's can register for any of the date-times |
|
515 | + 'multi-event' => array( |
|
516 | + __('Multi Event', 'event_espresso'), |
|
517 | + __('Multiple, separate, but related events that occur on consecutive days.', 'event_espresso'), |
|
518 | + ), |
|
519 | + //example: a three day music festival or week long conference |
|
520 | + //Attendee's register for the first date-time only |
|
521 | + 'event-series' => array( |
|
522 | + __('Event Series', 'event_espresso'), |
|
523 | + __(' Multiple events that occur over multiple non-consecutive days.', 'event_espresso'), |
|
524 | + ), |
|
525 | + //example: an 8 week introduction to basket weaving course |
|
526 | + //Attendee's can register for any of the date-times. |
|
527 | + 'recurring-event' => array( |
|
528 | + __('Recurring Event', 'event_espresso'), |
|
529 | + __('Multiple events that occur over multiple non-consecutive days.', 'event_espresso'), |
|
530 | + ), |
|
531 | + //example: a yoga class |
|
532 | + 'ongoing' => array( |
|
533 | + __('Ongoing Event', 'event_espresso'), |
|
534 | + __('An "event" that people can purchase tickets to gain access for anytime for this event regardless of date times on the event', |
|
535 | + 'event_espresso'), |
|
536 | + ) |
|
537 | + //example: access to a museum |
|
538 | + //'walk-in' => array( __('Walk In', 'event_espresso'), __('Single datetime and single entry recurring events. Attendees register for one or multiple datetimes individually.', 'event_espresso') ), |
|
539 | + //'reservation' => array( __('Reservation', 'event_espresso'), __('Reservations are created by specifying available datetimes and quantities. Attendees choose from the available datetimes and specify the quantity available (if the maximum is greater than 1)') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1 |
|
540 | + // 'multiple-session' => array( __('Multiple Session', 'event_espresso'), __('Multiple event, multiple datetime, hierarchically organized, custom entry events. Attendees may be required to register for a parent event before being allowed to register for child events. Attendees can register for any combination of child events as long as the datetimes do not conflict. Parent and child events may have additional fees or registration questions.') ), //@TODO to avoid confusion we'll implement this in a later iteration > EE4.1 |
|
541 | + //'appointment' => array( __('Appointments', 'event_espresso'), __('Time slotted events where datetimes are generally in hours or minutes. For example, attendees can register for a single 15 minute or 1 hour time slot and this type of availability frequently reoccurs.', 'event_espresso') ) |
|
542 | + ); |
|
543 | + $this->set_must_use_terms('espresso_event_type', $term_details); |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + |
|
548 | + /** |
|
549 | + * wrapper method for handling the setting up of initial terms in the db (if they don't already exist). |
|
550 | + * Note this should ONLY be used for terms that always must be present. Be aware that if an initial term is |
|
551 | + * deleted then it WILL be recreated. |
|
552 | + * |
|
553 | + * @param string $taxonomy The name of the taxonomy |
|
554 | + * @param array $term_details An array of term details indexed by slug and containing Name of term, and |
|
555 | + * description as the elements in the array |
|
556 | + * @return void |
|
557 | + */ |
|
558 | + public function set_must_use_terms($taxonomy, $term_details) |
|
559 | + { |
|
560 | + $term_details = (array)$term_details; |
|
561 | + foreach ($term_details as $slug => $details) { |
|
562 | + if ( ! term_exists($slug, $taxonomy)) { |
|
563 | + $insert_arr = array( |
|
564 | + 'slug' => $slug, |
|
565 | + 'description' => $details[1], |
|
566 | + ); |
|
567 | + wp_insert_term($details[0], $taxonomy, $insert_arr); |
|
568 | + } |
|
569 | + } |
|
570 | + } |
|
571 | + |
|
572 | + |
|
573 | + |
|
574 | + /** |
|
575 | + * Allows us to set what the default will be for terms when a cpt is PUBLISHED. |
|
576 | + * |
|
577 | + * @param string $taxonomy The taxonomy we're using for the default term |
|
578 | + * @param string $term_slug The slug of the term that will be the default. |
|
579 | + * @param array $cpt_slugs An array of custom post types we want the default assigned to |
|
580 | + */ |
|
581 | + public function set_default_term($taxonomy, $term_slug, $cpt_slugs = array()) |
|
582 | + { |
|
583 | + $this->_default_terms[][$term_slug] = new EE_Default_Term($taxonomy, $term_slug, $cpt_slugs); |
|
584 | + } |
|
585 | + |
|
586 | + |
|
587 | + |
|
588 | + /** |
|
589 | + * hooked into the wp 'save_post' action hook for setting our default terms found in the $_default_terms property |
|
590 | + * |
|
591 | + * @param int $post_id ID of CPT being saved |
|
592 | + * @param object $post Post object |
|
593 | + * @return void |
|
594 | + */ |
|
595 | + public function save_default_term($post_id, $post) |
|
596 | + { |
|
597 | + if (empty($this->_default_terms)) { |
|
598 | + return; |
|
599 | + } //no default terms set so lets just exit. |
|
600 | + foreach ($this->_default_terms as $defaults) { |
|
601 | + foreach ($defaults as $default_obj) { |
|
602 | + if ($post->post_status === 'publish' && in_array($post->post_type, $default_obj->cpt_slugs, true)) { |
|
603 | + //note some error proofing going on here to save unnecessary db queries |
|
604 | + $taxonomies = get_object_taxonomies($post->post_type); |
|
605 | + foreach ((array)$taxonomies as $taxonomy) { |
|
606 | + $terms = wp_get_post_terms($post_id, $taxonomy); |
|
607 | + if (empty($terms) && $taxonomy === $default_obj->taxonomy) { |
|
608 | + wp_set_object_terms($post_id, array($default_obj->term_slug), $taxonomy); |
|
609 | + } |
|
610 | + } |
|
611 | + } |
|
612 | + } |
|
613 | + } |
|
614 | + } |
|
615 | 615 | |
616 | 616 | } |
617 | 617 | |
@@ -625,27 +625,27 @@ discard block |
||
625 | 625 | { |
626 | 626 | |
627 | 627 | |
628 | - //props holding the items |
|
629 | - public $taxonomy = ''; |
|
628 | + //props holding the items |
|
629 | + public $taxonomy = ''; |
|
630 | 630 | |
631 | - public $cpt_slugs = array(); |
|
631 | + public $cpt_slugs = array(); |
|
632 | 632 | |
633 | - public $term_slug = ''; |
|
633 | + public $term_slug = ''; |
|
634 | 634 | |
635 | 635 | |
636 | 636 | |
637 | - /** |
|
638 | - * constructor |
|
639 | - * |
|
640 | - * @param string $taxonomy The taxonomy the default term belongs to |
|
641 | - * @param string $term_slug The slug of the term that will be the default. |
|
642 | - * @param array $cpt_slugs The custom post type the default term gets saved with |
|
643 | - */ |
|
644 | - public function __construct($taxonomy, $term_slug, $cpt_slugs = array()) |
|
645 | - { |
|
646 | - $this->taxonomy = $taxonomy; |
|
647 | - $this->cpt_slugs = (array)$cpt_slugs; |
|
648 | - $this->term_slug = $term_slug; |
|
649 | - } |
|
637 | + /** |
|
638 | + * constructor |
|
639 | + * |
|
640 | + * @param string $taxonomy The taxonomy the default term belongs to |
|
641 | + * @param string $term_slug The slug of the term that will be the default. |
|
642 | + * @param array $cpt_slugs The custom post type the default term gets saved with |
|
643 | + */ |
|
644 | + public function __construct($taxonomy, $term_slug, $cpt_slugs = array()) |
|
645 | + { |
|
646 | + $this->taxonomy = $taxonomy; |
|
647 | + $this->cpt_slugs = (array)$cpt_slugs; |
|
648 | + $this->term_slug = $term_slug; |
|
649 | + } |
|
650 | 650 | |
651 | 651 | } |